Esempio n. 1
0
    function _hdlr_date($args, &$ctx)
    {
        $ts = null;
        if (isset($args['ts'])) {
            $ts = $args['ts'];
        }
        $ts or $ts = $ctx->stash('current_timestamp');
        $ts = preg_replace('![^0-9]!', '', $ts);
        $blog = $ctx->stash('blog');
        if ($ts == '') {
            $t = time();
            if ($args['utc']) {
                $ts = gmtime($t);
            } else {
                $ts = offset_time_list($t, $blog);
            }
            $ts = sprintf("%04d%02d%02d%02d%02d%02d", $ts[5] + 1900, $ts[4] + 1, $ts[3], $ts[2], $ts[1], $ts[0]);
        }
        if (isset($args['utc'])) {
            if (!is_object($blog)) {
                $blog = $ctx->mt->db()->fetch_blog($blog);
            }
            preg_match('/(\\d\\d\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)/', $ts, $matches);
            list($all, $y, $mo, $d, $h, $m, $s) = $matches;
            $so = $blog->blog_server_offset;
            $timelocal = mktime($h, $m, $s, $mo, $d, $y);
            $localtime = localtime($timelocal);
            if ($localtime[8]) {
                $so += 1;
            }
            $partial_hour_offset = 60 * abs($so - intval($so));
            $four_digit_offset = sprintf('%s%02d%02d', $so < 0 ? '-' : '+', abs($so), $partial_hour_offset);
            $ts = gmdate('YmdHis', strtotime("{$y}-{$mo}-{$d} {$h}:{$m}:{$s} {$four_digit_offset}"));
        }
        if (isset($args['format_name'])) {
            if ($format = $args['format_name']) {
                $tz = 'Z';
                if (!$args['utc']) {
                    $blog = $ctx->stash('blog');
                    if (!is_object($blog)) {
                        $blog = $ctx->mt->db()->fetch_blog($blog);
                    }
                    $so = $blog->blog_server_offset;
                    $partial_hour_offset = 60 * abs($so - intval($so));
                    if ($format == 'rfc822') {
                        $tz = sprintf("%s%02d%02d", $so < 0 ? '-' : '+', abs($so), $partial_hour_offset);
                    } elseif ($format == 'iso8601') {
                        $tz = sprintf("%s%02d:%02d", $so < 0 ? '-' : '+', abs($so), $partial_hour_offset);
                    }
                }
                if ($format == 'rfc822') {
                    $args['format'] = '%a, %d %b %Y %H:%M:%S ' . $tz;
                    $args['language'] = 'en';
                } elseif ($format == 'iso8601') {
                    $args['format'] = '%Y-%m-%dT%H:%M:%S' . $tz;
                }
            }
        }
        if (!isset($args['format'])) {
            $args['format'] = null;
        }
        require_once "MTUtil.php";
        $fds = format_ts($args['format'], $ts, $blog, isset($args['language']) ? $args['language'] : null);
        if (isset($args['relative'])) {
            if ($args['relative'] == 'js') {
                preg_match('/(\\d\\d\\d\\d)[^\\d]?(\\d\\d)[^\\d]?(\\d\\d)[^\\d]?(\\d\\d)[^\\d]?(\\d\\d)[^\\d]?(\\d\\d)/', $ts, $match);
                list($xx, $y, $mo, $d, $h, $m, $s) = $match;
                $mo--;
                $js = <<<EOT
<script type="text/javascript">
/* <![CDATA[ */
document.write(mtRelativeDate(new Date({$y},{$mo},{$d},{$h},{$m},{$s}), '{$fds}'));
/* ]]> */
</script><noscript>{$fds}</noscript>
EOT;
                return $js;
            } else {
                preg_match('/(\\d\\d\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)/', $ts, $matches);
                list($all, $y, $mo, $d, $h, $m, $s) = $matches;
                $unix_ts = offset_time(gmmktime($h, $m, $s, $mo, $d, $y), $blog, '-');
                $now_ts = time();
                $relative = $this->relative_date($unix_ts, $now_ts, $args['relative'], $blog);
                if (is_array($relative)) {
                    return format_ts($relate['format'], $ts, $blog, isset($args['language']) ? $args['language'] : null);
                } elseif ($relative) {
                    return $relative;
                }
            }
        }
        return $fds;
    }
function customfield_html_datetime(&$ctx, $param)
{
    extract($param);
    require_once "MTUtil.php";
    $blog =& $ctx->stash('blog');
    $field_name = encode_html($field_name);
    $field_value = encode_html($field_value);
    $ts = $field_value;
    $ts = preg_replace('/\\D/', '', $ts);
    if ($ts != '') {
        $date = format_ts("%Y-%m-%d", $ts, $blog);
        $time = format_ts("%H:%M:%S", $ts, $blog);
    }
    if ($field_options != 'time') {
        $html1 = <<<EOT
<input id="d_{$field_name}" class="entry-date" name="d_{$field_name}" value="{$date}" />
EOT;
    } else {
        $html1 = <<<EOT
<input type="hidden" id="d_{$field_name}" name="d_{$field_name}" value="" />
EOT;
    }
    if ($field_options != 'date') {
        $html2 = <<<EOT
<input class="entry-time" name="t_{$field_name}" value="{$time}" />
EOT;
    } else {
        $html2 = <<<EOT
<input type="hidden" id="t_{$field_name}" name="t_{$field_name}" value="" />
EOT;
    }
    return <<<EOT
<span class="date-time-fields">
{$html1}
{$html2}
</span>
EOT;
}
Esempio n. 3
0
function get_thumbnail_file($asset, $blog, $args)
{
    # Parse args
    $width = 0;
    $height = 0;
    $scale = 0;
    $square = false;
    $format = '%f-thumb-%wx%h-%i%x';
    if (isset($args['width'])) {
        $width = $args['width'];
    }
    if (isset($args['height'])) {
        $height = $args['height'];
    }
    if (isset($args['scale'])) {
        $scale = $args['scale'];
    }
    if (isset($args['format'])) {
        $format = $args['format'];
    }
    if (isset($args['square'])) {
        $square = (int) $args['square'] == 1 ? true : false;
    }
    # Get parameter
    $site_path = $blog['blog_site_path'];
    $site_path = preg_replace('/\\/$/', '', $site_path);
    $filename = asset_path($asset['asset_file_path'], $blog);
    # Retrieve thumbnail
    global $mt;
    $path_parts = pathinfo($filename);
    $cache_path = $mt->config('AssetCacheDir');
    $ts = preg_replace('![^0-9]!', '', $asset['asset_created_on']);
    $date_stamp = format_ts('%Y/%m', $ts, $blog);
    $base_path = $site_path;
    if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_path'])) {
        $base_path = $blog['blog_archive_path'];
        $base_path = preg_replace('/\\/$/', '', $base_path);
    }
    $cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
    $thumb_name = $cache_dir . $format;
    # generate thumbnail
    require_once 'thumbnail_lib.php';
    $thumb = new Thumbnail($filename);
    $thumb_w = $width;
    $thumb_h = $height;
    $dest;
    if (!$thumb->get_thumbnail($dest, $thumb_w, $thumb_h, $asset['asset_id'], $scale, $thumb_name, 'auto', $square)) {
        return '';
    }
    # make url
    $basename = basename($dest);
    $base_url = $blog['blog_site_url'];
    if (preg_match('/^%a/', $asset['asset_file_path']) && !empty($blog['blog_archive_url'])) {
        $base_url = $blog['blog_archive_url'];
    }
    if (!preg_match('!/$!', $base_url)) {
        $base_url .= '/';
    }
    $thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename;
    return array($thumb_url, $thumb_w, $thumb_h, $thumb_name);
}
Esempio n. 4
0
function get_thumbnail_file($asset, $blog, $args)
{
    # Parse args
    $format = '%f-thumb-%wx%h-%i%x';
    if (isset($args['format'])) {
        $format = $args['format'];
    }
    # Get parameter
    $site_path = $blog->site_path();
    $site_path = preg_replace('/\\/$/', '', $site_path);
    $filename = asset_path($asset->asset_file_path, $blog);
    # Retrieve thumbnail
    $mt = MT::get_instance();
    $path_parts = pathinfo($filename);
    $cache_path = $mt->config('AssetCacheDir');
    $ts = preg_replace('![^0-9]!', '', $asset->asset_created_on);
    $date_stamp = format_ts('%Y/%m', $ts, $blog);
    $base_path = $site_path;
    $archive_path = $blog->archive_path();
    if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_path)) {
        $base_path = $blog->archive_path();
        $base_path = preg_replace('/\\/$/', '', $base_path);
    }
    $cache_dir = $base_path . DIRECTORY_SEPARATOR . $cache_path . DIRECTORY_SEPARATOR . $date_stamp . DIRECTORY_SEPARATOR;
    $thumb_name = $cache_dir . $format;
    # generate thumbnail
    require_once 'thumbnail_lib.php';
    $thumb = new Thumbnail($filename);
    $thumb->id($asset->id);
    $thumb->format($thumb_name);
    $thumb->type('auto');
    if (isset($args['width'])) {
        $thumb->width($args['width']);
    }
    if (isset($args['height'])) {
        $thumb->height($args['height']);
    }
    if (isset($args['scale'])) {
        $thumb->scale($args['scale']);
    }
    if (isset($args['square'])) {
        $thumb->square($args['square'] ? true : false);
    }
    if (!$thumb->get_thumbnail()) {
        return '';
    }
    # make url
    $basename = basename($thumb->dest());
    $base_url = $blog->site_url();
    $archive_url = $blog->archive_url();
    if (preg_match('/^%a/', $asset->asset_file_path) && !empty($archive_url)) {
        $base_url = $blog->archive_url();
    }
    if (!preg_match('!/$!', $base_url)) {
        $base_url .= '/';
    }
    if (DIRECTORY_SEPARATOR != '/') {
        $cache_path = str_replace(DIRECTORY_SEPARATOR, '/', $cache_path);
    }
    $thumb_url = $base_url . $cache_path . '/' . $date_stamp . '/' . $basename;
    return array($thumb_url, $thumb->width(), $thumb->height(), $thumb->dest());
}