PMA\libraries\plugins\transformations\abs\DateFormatTransformationsPlugin::applyTransformation PHP Метод

applyTransformation() публичный Метод

Does the actual work of each specific transformations plugin.
public applyTransformation ( string $buffer, array $options = [], string $meta = '' ) : string
$buffer string text to be transformed
$options array transformation options
$meta string meta information
Результат string
    public function applyTransformation($buffer, $options = array(), $meta = '')
    {
        // possibly use a global transform and feed it with special options
        // further operations on $buffer using the $options[] array.
        if (empty($options[0])) {
            $options[0] = 0;
        }
        if (empty($options[2])) {
            $options[2] = 'local';
        } else {
            $options[2] = mb_strtolower($options[2]);
        }
        if (empty($options[1])) {
            if ($options[2] == 'local') {
                $options[1] = __('%B %d, %Y at %I:%M %p');
            } else {
                $options[1] = 'Y-m-d  H:i:s';
            }
        }
        $timestamp = -1;
        // INT columns will be treated as UNIX timestamps
        // and need to be detected before the verification for
        // MySQL TIMESTAMP
        if ($meta->type == 'int') {
            $timestamp = $buffer;
            // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
            // TIMESTAMP (2 | 4) not supported here.
            // (Note: prior to MySQL 4.1, TIMESTAMP has a display size
            // for example TIMESTAMP(8) means YYYYMMDD)
        } else {
            if (preg_match('/^(\\d{2}){3,7}$/', $buffer)) {
                if (mb_strlen($buffer) == 14 || mb_strlen($buffer) == 8) {
                    $offset = 4;
                } else {
                    $offset = 2;
                }
                $aDate = array();
                $aDate['year'] = (int) mb_substr($buffer, 0, $offset);
                $aDate['month'] = (int) mb_substr($buffer, $offset, 2);
                $aDate['day'] = (int) mb_substr($buffer, $offset + 2, 2);
                $aDate['hour'] = (int) mb_substr($buffer, $offset + 4, 2);
                $aDate['minute'] = (int) mb_substr($buffer, $offset + 6, 2);
                $aDate['second'] = (int) mb_substr($buffer, $offset + 8, 2);
                if (checkdate($aDate['month'], $aDate['day'], $aDate['year'])) {
                    $timestamp = mktime($aDate['hour'], $aDate['minute'], $aDate['second'], $aDate['month'], $aDate['day'], $aDate['year']);
                }
                // If all fails, assume one of the dozens of valid strtime() syntaxes
                // (https://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
            } else {
                if (preg_match('/^[0-9]\\d{1,9}$/', $buffer)) {
                    $timestamp = (int) $buffer;
                } else {
                    $timestamp = strtotime($buffer);
                }
            }
        }
        // If all above failed, maybe it's a Unix timestamp already?
        if ($timestamp < 0 && preg_match('/^[1-9]\\d{1,9}$/', $buffer)) {
            $timestamp = $buffer;
        }
        // Reformat a valid timestamp
        if ($timestamp >= 0) {
            $timestamp -= $options[0] * 60 * 60;
            $source = $buffer;
            if ($options[2] == 'local') {
                $text = PMA\libraries\Util::localisedDate($timestamp, $options[1]);
            } elseif ($options[2] == 'utc') {
                $text = gmdate($options[1], $timestamp);
            } else {
                $text = 'INVALID DATE TYPE';
            }
            return '<dfn onclick="alert(\'' . Sanitize::jsFormat($source, false) . '\');" title="' . htmlspecialchars($source) . '">' . htmlspecialchars($text) . '</dfn>';
        } else {
            return htmlspecialchars($buffer);
        }
    }
DateFormatTransformationsPlugin