示例#1
0
 /**
  * Constructor
  *
  * @param array The hash of CMSMS config settings
  */
 public function __construct()
 {
     parent::__construct();
     global $CMS_ADMIN_PAGE;
     // <- Still needed?
     global $CMS_INSTALL_PAGE;
     $config = cmsms()->GetConfig();
     // Do not allow any absolute paths in template resolution.
     $this->no_absolute_templates = TRUE;
     // Set template_c and cache dirs
     $this->setCompileDir(TMP_TEMPLATES_C_LOCATION);
     $this->setCacheDir(TMP_CACHE_LOCATION);
     $this->assign('app_name', 'CMS');
     if ($config["debug"] == true) {
         $this->force_compile = true;
         $this->debugging = false;
     }
     // Set plugins dirs
     $this->addPluginsDir(cms_join_path($config['root_path'], 'plugins'));
     // common resources.
     $this->registerResource('module_db_tpl', new CMSModuleDbTemplateResource());
     $this->registerResource('module_file_tpl', new CMSModuleFileTemplateResource());
     $this->registerResource('template', new CMSPageTemplateResource());
     // <- Should proably be global and removed from parser?
     // Load User Defined Tags
     if (!cmsms()->test_state(CmsApp::STATE_INSTALL)) {
         $utops = cmsms()->GetUserTagOperations();
         $usertags = $utops->ListUserTags();
         $caching = false;
         if (get_site_preference('smarty_cacheudt', 'never') == 'always' && cmsms()->is_frontend_request()) {
             $caching = true;
         }
         foreach ($usertags as $id => $udt_name) {
             $function = $utops->CreateTagFunction($udt_name);
             $this->registerPlugin('function', $udt_name, $function, $caching);
         }
     }
     // register default plugin handler
     $this->registerDefaultPluginHandler(array(&$this, 'defaultPluginHandler'));
     if (cmsms()->is_frontend_request()) {
         $this->setTemplateDir(cms_join_path($config['root_path'], 'tmp', 'templates'));
         $this->setConfigDir(cms_join_path($config['root_path'], 'tmp', 'templates'));
         // Check if we are at install page, don't register anything if so, cause nothing below is needed.
         if (isset($CMS_INSTALL_PAGE)) {
             return;
         }
         if (is_sitedown()) {
             $this->setCaching(false);
             $this->force_compile = true;
         }
         // Load resources
         $this->registerResource('tpl_top', new CMSPageTemplateResource('top'));
         $this->registerResource('tpl_head', new CMSPageTemplateResource('head'));
         $this->registerResource('tpl_body', new CMSPageTemplateResource('body'));
         $this->registerResource('content', new CMSContentTemplateResource());
         //$this->registerResource('htmlblob',new CMSGlobalContentTemplateResource());
         $this->registerResource('globalcontent', new CMSGlobalContentTemplateResource());
         // just for frontend actions.
         $this->registerPlugin('compiler', 'content', array('CMS_Content_Block', 'smarty_compile_fecontentblock'), false);
         $this->registerPlugin('function', 'content_image', 'CMS_Content_Block::smarty_fetch_imageblock', false);
         $this->registerPlugin('function', 'content_module', 'CMS_Content_Block::smarty_fetch_moduleblock', false);
         $this->registerPlugin('function', 'process_pagedata', 'CMS_Content_Block::smarty_fetch_pagedata', false);
         // Autoload filters
         $this->autoloadFilters();
         // compile check can only be enabled, if using smarty cache... just for safety.
         if (get_site_preference('use_smartycache', 0)) {
             if (version_compare(phpversion(), '5.3') >= 0) {
                 $this->setCompileCheck(get_site_preference('use_smartycompilecheck', 1));
             }
         }
     } else {
         if (cmsms()->test_state(CmsApp::STATE_ADMIN_PAGE)) {
             $this->setCaching(false);
             $this->force_compile = true;
             $this->setTemplateDir(cms_join_path($config['root_path'], $config['admin_dir'], 'templates'));
             $this->setConfigDir(cms_join_path($config['root_path'], $config['admin_dir'], 'configs'));
             $this->registerResource('globalcontent', new CMSNullTemplateResource());
         }
     }
     $this->AddTemplateDir(cms_join_path($config['root_path'], 'lib', 'smarty', 'libs'));
     // Enable security object
     // Note: Buggy, disabled prior to release of CMSMS 1.11
     //$this->enableSecurity('CMSSmartySecurityPolicy');
 }
 protected function fetch($name, &$source, &$mtime)
 {
     if (is_sitedown() && cmsms()->is_frontend_request()) {
         $source = '';
         $mtime = time();
         if ($this->_section == 'body') {
             header('HTTP/1.0 503 Service Unavailable');
             header('Status: 503 Service Unavailable');
             $source = get_site_preference('sitedownmessage');
         }
         return;
     }
     if ($name == 'notemplate') {
         $source = '{content}';
         $mtime = time();
         // never cache...
         return;
     } else {
         if (startswith($name, 'appdata;')) {
             $name = substr($name, 8);
             $source = cms_utils::get_app_data($name);
             $mtime = time();
             return;
         }
     }
     $source = '';
     $mtime = null;
     $tpl = $this->get_template($name);
     if (!is_object($tpl)) {
         return;
     }
     // Get section, do magic.
     switch ($this->_section) {
         case 'top':
             $mtime = $tpl->modified_date;
             $pos1 = stripos($tpl->content, '<head');
             $pos2 = stripos($tpl->content, '<header');
             if ($pos1 === FALSE || $pos1 == $pos2) {
                 return;
             }
             $source = substr($tpl->content, 0, $pos1);
             return;
         case 'head':
             $mtime = $tpl->modified_date;
             $pos1 = stripos($tpl->content, '<head');
             $pos1a = stripos($tpl->content, '<header');
             $pos2 = stripos($tpl->content, '</head>');
             if ($pos1 === FALSE || $pos1 == $pos1a || $pos2 === FALSE) {
                 return;
             }
             $source = substr($tpl->content, $pos1, $pos2 - $pos1 + 7);
             return;
         case 'body':
             $mtime = $tpl->modified_date;
             $pos = stripos($tpl->content, '</head>');
             if ($pos !== FALSE) {
                 $source = substr($tpl->content, $pos + 7);
             } else {
                 $source = $tpl->content;
             }
             return;
         default:
             $source = $tpl->content;
             $mtime = $tpl->modified_date;
             return;
     }
 }
 /**
  * Given a page template name, return it's modification date.
  *
  * @access private
  * @param string The page template name.
  * @param  int (returned) The database template modification time.
  * @param  object The smarty object.
  * @return boolean
  */
 function template_get_timestamp($tpl_name, &$tpl_timestamp, $smarty_obj)
 {
     $gCms = cmsms();
     if (is_sitedown() || $tpl_name == 'notemplate') {
         $tpl_timestamp = time();
         return true;
     } else {
         if (isset($_GET['id']) && isset($_GET[$_GET['id'] . 'showtemplate']) && $_GET[$_GET['id'] . 'showtemplate'] == 'false') {
             $tpl_timestamp = time();
             return true;
         } else {
             if (isset($_GET['print'])) {
                 $tpl_timestamp = time();
                 return true;
             } else {
                 $contentobj = $gCms->variables['content_obj'];
                 $templateops =& $gCms->GetTemplateOperations();
                 $templateobj =& $templateops->LoadTemplateByID($contentobj->TemplateId());
                 if (isset($templateobj) && $templateobj !== FALSE) {
                     $tpl_timestamp = $templateobj->modified_date;
                     return true;
                 }
             }
         }
     }
 }
示例#4
0
    $memory = function_exists('memory_get_usage') ? memory_get_usage() : 0;
    $memory = $memory - $orig_memory;
    $memory_peak = function_exists('memory_get_peak_usage') ? memory_get_peak_usage() : 0;
    if (!is_sitedown() && $config["debug"] == true) {
        echo "<p>Generated in " . microtime_diff($starttime, $endtime) . " seconds by CMS Made Simple using " . (isset($db->query_count) ? $db->query_count : '') . " SQL queries and {$memory} bytes of memory (peak memory usage was {$memory_peak})</p>";
    } else {
        if (isset($config['show_performance_info']) && $showtemplate == true) {
            $txt = microtime_diff($starttime, $endtime) . " / " . (isset($db->query_count) ? $db->query_count : '') . " / {$memory} / {$memory_peak}";
            debug_display($txt);
            echo '<!-- ' . $txt . " -->\n";
        }
    }
}
if (is_sitedown() || $config['debug'] == true) {
    $smarty->clear_compiled_tpl();
}
if (!is_sitedown() && $config["debug"] == true) {
    #$db->LogSQL(false); // turn off logging
    # output summary of SQL logging results
    #$perf = NewPerfMonitor($db);
    #echo $perf->SuspiciousSQL();
    #echo $perf->ExpensiveSQL();
    #echo $sql_queries;
    foreach ($gCms->errors as $error) {
        echo $error;
    }
}
if ($page == '__CMS_PREVIEW_PAGE__' && isset($_SESSION['cms_preview'])) {
    unset($_SESSION['cms_preview']);
}
# vim:ts=4 sw=4 noet
示例#5
0
 /**
  * Given a page template name, return it's modification date.
  *
  * @access private
  * @param string The page template name.
  * @param  int (returned) The database template modification time.
  * @param  object The smarty object.
  * @return boolean
  */
 function template_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 {
     global $gCms;
     if (is_sitedown() || $tpl_name == 'notemplate') {
         $tpl_timestamp = time();
         return true;
     } else {
         if (isset($_GET['id']) && isset($_GET[$_GET['id'] . 'showtemplate']) && $_GET[$_GET['id'] . 'showtemplate'] == 'false') {
             $tpl_timestamp = time();
             return true;
         } else {
             if (isset($_GET['print'])) {
                 $tpl_timestamp = time();
                 return true;
             } else {
                 $pageinfo =& $gCms->variables['pageinfo'];
                 $tpl_timestamp = $pageinfo->template_modified_date;
                 return true;
             }
         }
     }
 }