function smarty_function_mtcanonicalurl($args, &$ctx)
{
    $blog = $ctx->stash('blog');
    if (empty($args['current_mapping'])) {
        $url = $ctx->stash('preferred_mapping_url');
    }
    if (empty($url)) {
        $url = $ctx->stash('current_mapping_url');
    }
    if (empty($url)) {
        return '';
    }
    return empty($args['with_index']) ? _strip_index($url, $blog) : $url;
}
function smarty_function_mtlink($args, &$ctx)
{
    // status: incomplete
    // parameters: template, entry_id
    static $_template_links = array();
    $curr_blog = $ctx->stash('blog');
    if (isset($args['template'])) {
        if (!empty($args['blog_id'])) {
            $blog = $ctx->mt->db()->fetch_blog($args['blog_id']);
        } else {
            $blog = $ctx->stash('blog');
        }
        $name = $args['template'];
        $cache_key = $blog->id . ';' . $name;
        if (isset($_template_links[$cache_key])) {
            $link = $_template_links[$cache_key];
        } else {
            $tmpl = $ctx->mt->db()->load_index_template($ctx, $name);
            $site_url = $blog->site_url();
            if (!preg_match('!/$!', $site_url)) {
                $site_url .= '/';
            }
            $link = $site_url . $tmpl->template_outfile;
            $_template_links[$cache_key] = $link;
        }
        if (!$args['with_index']) {
            $link = _strip_index($link, $curr_blog);
        }
        return $link;
    } elseif (isset($args['entry_id'])) {
        $arg = array('entry_id' => $args['entry_id']);
        list($entry) = $ctx->mt->db()->fetch_entries($arg);
        $ctx->localize(array('entry'));
        $ctx->stash('entry', $entry);
        $link = $ctx->tag('EntryPermalink', $args);
        $ctx->restore(array('entry'));
        if ($args['with_index'] && preg_match('/\\/(#.*)$/', $link)) {
            $index = $ctx->mt->config('IndexBasename');
            $ext = $curr_blog->blog_file_extension;
            if ($ext) {
                $ext = '.' . $ext;
            }
            $index .= $ext;
            $link = preg_replace('/\\/(#.*)?$/', "/{$index}\$1", $link);
        }
        return $link;
    }
    return '';
}
function smarty_function_mtindexlink($args, &$ctx)
{
    $tmpl = $ctx->stash('index_templates');
    $counter = $ctx->stash('index_templates_counter');
    $idx = $tmpl[$counter];
    if (!$idx) {
        return '';
    }
    $blog = $ctx->stash('blog');
    $site_url = $blog['blog_site_url'];
    if (!preg_match('!/$!', $site_url)) {
        $site_url .= '/';
    }
    $link = $site_url . $idx['template_outfile'];
    if (!$args['with_index']) {
        $link = _strip_index($link, $blog);
    }
    return $link;
}
示例#4
0
 function &get_archive_list($ctx, $args)
 {
     global $mt;
     list($results, $hi, $low) = $this->get_archive_list_data($args);
     if (is_array($results)) {
         $blog_id = $args['blog_id'];
         $range = "'{$low}' and '{$hi}'";
         $at = $ctx->stash('current_archive_type');
         $link_cache_sql = "\n                select fileinfo_startdate, fileinfo_url, blog_site_url, blog_file_extension\n                  from mt_fileinfo, mt_templatemap, mt_blog\n                 where fileinfo_startdate between {$range}\n                   and fileinfo_archive_type = '{$at}'\n                   and blog_id = {$blog_id}\n                   and fileinfo_blog_id = blog_id\n                   and templatemap_id = fileinfo_templatemap_id\n                   and templatemap_is_preferred = 1\n            ";
         $cache_results = $mt->db->get_results($link_cache_sql, ARRAY_N);
         if (is_array($cache_results)) {
             foreach ($cache_results as $row) {
                 $date = $ctx->mt->db->db2ts($row[0]);
                 $blog_url = $row[2];
                 $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);
                 $url = $blog_url . $row[1];
                 $url = _strip_index($url, array('blog_file_extension' => $row[3]));
                 $mt->db->_archive_link_cache[$date . ';' . $at] = $url;
             }
         }
     }
     return $results;
 }
示例#5
0
 function &get_archive_list($args)
 {
     $blog_id = $args['blog_id'];
     $at = $args['archive_type'];
     $group_sql = $this->archive_list_sql($args);
     $results = $this->get_results($group_sql, ARRAY_N);
     if (is_array($results)) {
         if ($at == 'Daily') {
             $hi = sprintf("%04d%02d%02d", $results[0][1], $results[0][2], $results[0][3]);
             $low = sprintf("%04d%02d%02d", $results[count($results) - 1][1], $results[count($results) - 1][2], $results[count($results) - 1][3]);
         } elseif ($at == 'Weekly') {
             require_once "MTUtil.php";
             $week_yr = substr($results[0][1], 0, 4);
             $week_num = substr($results[0][1], 4);
             list($y, $m, $d) = week2ymd($week_yr, $week_num);
             $hi = sprintf("%04d%02d%02d", $y, $m, $d);
             $week_yr = substr($results[count($results) - 1][1], 0, 4);
             $week_num = substr($results[count($results) - 1][1], 4);
             list($y, $m, $d) = week2ymd($week_yr, $week_num);
             $low = sprintf("%04d%02d%02d", $y, $m, $d);
         } elseif ($at == 'Monthly') {
             $hi = sprintf("%04d%02d32", $results[0][1], $results[0][2]);
             $low = sprintf("%04d%02d00", $results[count($results) - 1][1], $results[count($results) - 1][2]);
         } elseif ($at == 'Yearly') {
             $hi = sprintf("%04d0000", $results[0][1]);
             $low = sprintf("%04d0000", $results[count($results) - 1][1]);
         } elseif ($at == 'Individual') {
             $hi = $results[0][1];
             $low = $results[count($results) - 1][1];
         }
         $range = "'{$low}' and '{$hi}'";
         $link_cache_sql = "\n                select fileinfo_startdate, fileinfo_url, blog_site_url, blog_file_extension, blog_archive_url\n                  from mt_fileinfo, mt_templatemap, mt_blog\n                 where fileinfo_startdate between {$range}\n                   and fileinfo_archive_type = '{$at}'\n                   and blog_id = {$blog_id}\n                   and fileinfo_blog_id = blog_id\n                   and templatemap_id = fileinfo_templatemap_id\n                   and templatemap_is_preferred = 1\n            ";
         $cache_results = $this->get_results($link_cache_sql, ARRAY_N);
         if (is_array($cache_results)) {
             foreach ($cache_results as $row) {
                 $date = $this->db2ts($row[0]);
                 if ($at == 'Page') {
                     $blog_url = $row[2];
                 } else {
                     $blog_url = $row[4];
                     $blog_url or $blog_url = $row[2];
                 }
                 $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);
                 $url = $blog_url . $row[1];
                 $url = _strip_index($url, array('blog_file_extension' => $row[3]));
                 $this->_archive_link_cache[$date . ';' . $at] = $url;
             }
         }
     }
     return $results;
 }
示例#6
0
 public function update_archive_link_cache($args)
 {
     $blog_id = $args['blog_id'];
     $at = $args['archive_type'];
     $where = isset($args['where']) ? $args['where'] : '';
     if (isset($args['hi']) && isset($args['low'])) {
         $hi = $args['hi'];
         $low = $args['low'];
         $range = " and fileinfo_startdate between '{$low}' and '{$hi}'";
     }
     $sql = "\n            fileinfo_archive_type = '{$at}'\n            and fileinfo_blog_id = {$blog_id}\n            and templatemap_is_preferred = 1\n            {$range}\n            {$where}";
     $extras['join']['mt_templatemap'] = array('condition' => "templatemap_id = fileinfo_templatemap_id");
     require_once 'class.mt_fileinfo.php';
     $fileinfo = new FileInfo();
     $finfos = $fileinfo->Find($sql, false, false, $extras);
     if (!empty($finfos)) {
         $mt = MT::get_instance();
         foreach ($finfos as $finfo) {
             $date = $this->db2ts($finfo->fileinfo_startdate);
             if ($at == 'Page') {
                 $blog_url = $finfo->blog()->site_url();
             } else {
                 $blog_url = $finfo->blog()->archive_url();
                 $blog_url or $blog_url = $finfo->blog()->site_url();
             }
             $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);
             $url = $blog_url . $finfo->url;
             $url = _strip_index($url, array('blog_file_extension' => $finfo->blog()->blog_file_extension));
             $this->_archive_link_cache[$date . ';' . $at] = $url;
         }
     }
     return true;
 }