function smarty_resource_mt_source($tpl_name, &$tpl_source, &$ctx)
{
    $blog_id = $ctx->stash('blog_id');
    if (intval($tpl_name) > 0) {
        $query = "template_blog_id = {$blog_id}\n                  and template_id = {$tpl_name}";
    } else {
        $tpl_name = $ctx->mt->db()->escape($tpl_name);
        $query = "template_blog_id = {$blog_id}\n                  and template_name='{$tpl_name}'";
    }
    require_once 'class.mt_template.php';
    $tmpl = new Template();
    $tmpls = $tmpl->Find($query);
    if (!empty($tmpls)) {
        $tmpl = $tmpls[0];
        $file = trim($tmpl->linked_file);
        $text = $tmpl->text;
        if ($file) {
            if (!file_exists($file)) {
                $blog = $ctx->stash('blog');
                $path = $blog->site_path();
                if (!preg_match('![\\/]$!', $path)) {
                    $path .= '/';
                }
                $path .= $file;
                if (is_file($path) && is_readable($path)) {
                    $file = $path;
                } else {
                    $file = '';
                }
            }
            if ($file) {
                $mtime = $tmpl->linked_file_mtime;
                $size = $tmpl->linked_file_size;
                if (filemtime($file) > $mtime || filesize($file) != $size) {
                    $contents = @file($file);
                    $text = implode('', $contents);
                }
            }
        }
        $tpl_source = $text;
        return true;
    } else {
        return false;
    }
}
Example #2
0
 public function fetch_template_meta($type, $name, $blog_id, $global)
 {
     if ($type === 'identifier') {
         $col = 'template_identifier';
         $type_filter = "";
     } else {
         $col = 'template_name';
         $type_filter = "and template_type='{$type}'";
     }
     if (!isset($global)) {
         $blog_filter = "and template_blog_id in (" . $this->escape($blog_id) . ",0)";
     } elseif ($global) {
         $blog_filter = "and template_blog_id=0";
     } else {
         $blog_filter = "and template_blog_id=" . $this->escape($blog_id);
     }
     $tmpl_name = $this->escape($name);
     $where = "{$col} = '{$tmpl_name}'\n                  {$blog_filter}\n                  {$type_filter}\n                  order by\n                      template_blog_id desc";
     require_once 'class.mt_template.php';
     $tmpl = new Template();
     $tmpls = $tmpl->Find($where);
     if (empty($tmpls)) {
         $tmpl = null;
     } else {
         $tmpl = $tmpls[0];
     }
     return $tmpl;
 }