/** * Initialize the Smarty framework for use in Serendipity * * @access public * @return null */ function serendipity_smarty_init($vars = array()) { global $serendipity, $template_config, $template_global_config, $template_config_groups; if (!isset($serendipity['smarty'])) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']; if (!defined('IN_serendipity_admin') && file_exists($template_dir . '/template.inc.php')) { // If this file exists, a custom template engine will be loaded. // Beware: Smarty is used in the Admin backend, despite of this. include_once $template_dir . '/template.inc.php'; } else { // Backend template overwritten here (NOT earlier due to frontend specific check) if (defined('IN_serendipity_admin')) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template_backend']; } // Set a session variable if Smarty fails: $prev_smarty = $_SESSION['no_smarty']; $_SESSION['no_smarty'] = true; if (LANG_CHARSET != 'UTF-8') { @define('SMARTY_MBSTRING', false); @define('SMARTY_RESOURCE_CHAR_SET', LANG_CHARSET); } // define cache resources to load with smarty - see smarty cache readme - needs enabled cache! #@define('APC_EXTENSION_LOADED', extension_loaded('apc') && ini_get('apc.enabled')); #@define('MEMCACHE_EXTENSION_LOADED', (class_exists('Memcached',false) || class_exists('Memcache',false)) && (extension_loaded("memcached") || extension_loaded("memcache"))); // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { include_once SMARTY_DIR . 'Smarty.class.php'; } if (!class_exists('Smarty')) { return false; } // include the serendipity smarty constructor if (!class_exists('Serendipity_Smarty')) { include_once S9Y_INCLUDE_PATH . '/include/serendipity_smarty_class.inc.php'; } if (!class_exists('Serendipity_Smarty')) { return false; } // set smarty instance #$serendipity['smarty'] = new Serendipity_Smarty; // initialize smarty object by instance $serendipity['smarty'] = Serendipity_Smarty::getInstance(); // debug moved to class // Hooray for Smarty: $_SESSION['no_smarty'] = $prev_smarty; // enable security policy by instance of the Smarty_Security class $serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy'); // debugging... #echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit; #$serendipity['smarty']->testInstall();exit; // extreme debugging with undocumented internal flag which enables a trace output from the parser during debugging #$serendipity['smarty']->_parserdebug = true; // be careful! /** * ToDo: Check for possible API changes in Smarty 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (in class)] * smarty_modifier_foobar(Smarty $smarty, $string, ...) vs. smarty_modifier_foobar($string, ...) **/ $serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename'); $serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->registerPlugin('modifier', 'formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->registerPlugin('modifier', 'ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->registerPlugin('modifier', 'checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_html5time', 'serendipity_smarty_html5time'); $serendipity['smarty']->registerPlugin('modifier', 'rewriteURL', 'serendipity_rewriteURL'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); $serendipity['smarty']->registerPlugin('function', 'serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); $serendipity['smarty']->registerPlugin('function', 'serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getConfigVar', 'serendipity_smarty_getConfigVar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_setFormToken', 'serendipity_smarty_setFormToken'); $serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars'); } if (!isset($serendipity['smarty_file'])) { $serendipity['smarty_file'] = 'index.tpl'; } $category = false; $category_info = array(); if (isset($serendipity['GET']['category'])) { $category = (int) $serendipity['GET']['category']; if (isset($GLOBALS['cInfo'])) { $category_info = $GLOBALS['cInfo']; } else { $category_info = serendipity_fetchCategoryInfo($category); } } if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) { $serendipity['smarty_vars']['head_link_stylesheet_frontend'] = serendipity_rewriteURL('serendipity.css'); if (IN_serendipity_admin === true) { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity_admin.css'); } else { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css'); } // When templates are switched, append a specific version string to make sure the browser does not cache the CSS if (strstr($serendipity['smarty_vars']['head_link_stylesheet'], '?')) { $serendipity['smarty_vars']['head_link_stylesheet'] .= '&v=' . $serendipity['last_template_change']; $serendipity['smarty_vars']['head_link_stylesheet_frontend'] .= '&v=' . $serendipity['last_template_change']; } else { $serendipity['smarty_vars']['head_link_stylesheet'] .= '?v=' . $serendipity['last_template_change']; $serendipity['smarty_vars']['head_link_stylesheet_frontend'] .= '?v=' . $serendipity['last_template_change']; } } if (!isset($serendipity['smarty_vars']['head_link_script'])) { if (IN_serendipity_admin === true) { $serendipity['smarty_vars']['head_link_script'] = serendipity_rewriteURL('serendipity_admin.js'); } else { $serendipity['smarty_vars']['head_link_script'] = serendipity_rewriteURL('serendipity.js'); } if (strstr($serendipity['smarty_vars']['head_link_script'], '?')) { $serendipity['smarty_vars']['head_link_script'] .= '&v=' . $serendipity['last_template_change']; } else { $serendipity['smarty_vars']['head_link_script'] .= '?v=' . $serendipity['last_template_change']; } } $wysiwyg_customPlugin = $wysiwyg_customConfig = null; if (defined('IN_serendipity_admin') && $serendipity['wysiwyg']) { // check force internal toolbar config file if (strpos($serendipity['wysiwygToolbar'], 'NOCC-') !== false) { $serendipity['wysiwygToolbar'] = substr($serendipity['wysiwygToolbar'], 5); $force_internal_toolbar = true; } // check ckeditor custom plugin file $ccp = serendipity_getTemplateFile('admin/ckeditor_custom_plugin.js', 'serendipityHTTPPath', true); $wysiwyg_customPlugin = !empty($ccp) && !$force_internal_toolbar ? $ccp : $serendipity['serendipityHTTPPath'] . 'htmlarea/ckeditor_s9y_plugin.js'; // check ckeditor custom config file $ccc = serendipity_getTemplateFile('admin/ckeditor_custom_config.js', 'serendipityHTTPPath', true); $wysiwyg_customConfig = !empty($ccc) && !$force_internal_toolbar ? $ccc : $serendipity['serendipityHTTPPath'] . 'htmlarea/ckeditor_s9y_config.js'; } $_force_backendpopups = explode(',', $serendipity['enableBackendPopupGranular']); $force_backendpopups = array(); foreach ($_force_backendpopups as $fbp_key => $fbp_val) { $fbp_val = trim($fbp_val); if (empty($fbp_val)) { continue; } $force_backendpopups[$fbp_val] = $fbp_val; } $serendipity['smarty']->assign(array('head_charset' => LANG_CHARSET, 'head_version' => $serendipity['version'], 'head_title' => $serendipity['head_title'], 'head_subtitle' => $serendipity['head_subtitle'], 'head_link_stylesheet' => $serendipity['smarty_vars']['head_link_stylesheet'], 'head_link_script' => $serendipity['smarty_vars']['head_link_script'], 'head_link_stylesheet_frontend' => $serendipity['smarty_vars']['head_link_stylesheet_frontend'], 'is_xhtml' => true, 'use_popups' => $serendipity['enablePopup'], 'use_backendpopups' => $serendipity['enableBackendPopup'], 'force_backendpopups' => $force_backendpopups, 'is_embedded' => !$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false ? false : true, 'is_raw_mode' => $serendipity['smarty_raw_mode'], 'is_logged_in' => serendipity_userLoggedIn(), 'entry_id' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']) ? $serendipity['GET']['id'] : false, 'is_single_entry' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']), 'blogTitle' => $serendipity['blogTitle'], 'blogSubTitle' => !empty($serendipity['blogSubTitle']) ? $serendipity['blogSubTitle'] : '', 'blogDescription' => $serendipity['blogDescription'], 'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'], 'serendipityDefaultBaseURL' => $serendipity['defaultBaseURL'], 'serendipityBaseURL' => $serendipity['baseURL'], 'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '', 'serendipityIndexFile' => $serendipity['indexFile'], 'serendipityVersion' => $serendipity['expose_s9y'] ? $serendipity['version'] : '', 'lang' => $serendipity['lang'], 'category' => $category, 'category_info' => $category_info, 'template' => $serendipity['template'], 'template_backend' => $serendipity['template_backend'], 'wysiwygToolbar' => $serendipity['wysiwygToolbar'], 'wysiwyg_customPlugin' => $wysiwyg_customPlugin, 'wysiwyg_customConfig' => $wysiwyg_customConfig, 'use_autosave' => serendipity_db_bool($serendipity['use_autosave']) ? 'true' : 'false', 'dateRange' => !empty($serendipity['range']) ? $serendipity['range'] : array())); if (count($vars) > 0) { $serendipity['smarty']->assign($vars); } // For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. // If a template engine is defined we need that config.inc.php file as well. The template's actual file is loaded after that to be able to overwrite config. if (isset($serendipity['template_engine']) && $serendipity['template_engine'] != null) { $p = explode(',', $serendipity['template_engine']); foreach ($p as $te) { $config = $serendipity['serendipityPath'] . $serendipity['templatePath'] . trim($te) . '/config.inc.php'; if (file_exists($config)) { include_once $config; } } } // FIRST: Load config of the currently configured FRONTEND template. We might actually need this in the backend (sidebar configuration, IPTC options, some others). // SECOND: Load config of the currently set template, which can also be the BACKEND template, or be the same as before. include_once takes care of only including the file once. $config = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template'] . '/config.inc.php'; if (file_exists($config)) { include_once $config; } $config = $serendipity['smarty']->getConfigDir(0) . '/config.inc.php'; if (file_exists($config)) { include_once $config; } if (is_array($template_loaded_config)) { $template_vars =& $template_loaded_config; $serendipity['smarty']->assignByRef('template_option', $template_vars); } elseif (is_array($template_config)) { $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']); $serendipity['smarty']->assignByRef('template_option', $template_vars); } } return true; }
/** * Initialize the Smarty framework for use in Serendipity * * @access public * @return null */ function serendipity_smarty_init($vars = array()) { global $serendipity, $template_config, $template_global_config, $template_config_groups; if (!isset($serendipity['smarty'])) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']; if (!defined('IN_serendipity_admin') && file_exists($template_dir . '/template.inc.php')) { // If this file exists, a custom template engine will be loaded. // Beware: Smarty is used in the Admin backend, despite of this. include $template_dir . '/template.inc.php'; } else { // Set a session variable if Smarty fails: $prev_smarty = $_SESSION['no_smarty']; $_SESSION['no_smarty'] = true; // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { include SMARTY_DIR . 'Smarty.class.php'; } if (!class_exists('Smarty')) { return false; } // Load serendipity smarty class loading class if (!class_exists('Serendipity_Smarty')) { include 'serendipity_smarty_class.inc.php'; } if (!class_exists('Serendipity_Smarty')) { return false; } // set smarty instance #$serendipity['smarty'] = new Serendipity_Smarty; // initialize smarty object by instance $serendipity['smarty'] = Serendipity_Smarty::getInstance(); // debug moved to class // Hooray for Smarty: $_SESSION['no_smarty'] = $prev_smarty; // enable security policy by instance of the Smarty_Security class $serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy'); // debugging... #echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit; #$serendipity['smarty']->testInstall();exit; /** * prüfe auf eventuelle API Änderungen in 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (siehe class) ] * smarty_modifier_foobar(Smarty $smarty, $string, …) vs. smarty_modifier_foobar($string, …) **/ $serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename'); $serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->registerPlugin('modifier', 'formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->registerPlugin('modifier', 'ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->registerPlugin('modifier', 'checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); $serendipity['smarty']->registerPlugin('function', 'serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); $serendipity['smarty']->registerPlugin('function', 'serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars'); } if (!isset($serendipity['smarty_raw_mode'])) { if (file_exists($serendipity['smarty']->getConfigDir(0) . '/layout.php') && $serendipity['template'] != 'default') { $serendipity['smarty_raw_mode'] = true; } else { $serendipity['smarty_raw_mode'] = false; } } if (!isset($serendipity['smarty_file'])) { $serendipity['smarty_file'] = 'index.tpl'; } $category = false; $category_info = array(); if (isset($serendipity['GET']['category'])) { $category = (int) $serendipity['GET']['category']; if (isset($GLOBALS['cInfo'])) { $category_info = $GLOBALS['cInfo']; } else { $category_info = serendipity_fetchCategoryInfo($category); } } if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css'); } $serendipity['smarty']->assign(array('head_charset' => LANG_CHARSET, 'head_version' => $serendipity['version'], 'head_title' => $serendipity['head_title'], 'head_subtitle' => $serendipity['head_subtitle'], 'head_link_stylesheet' => $serendipity['smarty_vars']['head_link_stylesheet'], 'is_xhtml' => true, 'use_popups' => $serendipity['enablePopup'], 'is_embedded' => !$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false ? false : true, 'is_raw_mode' => $serendipity['smarty_raw_mode'], 'is_logged_in' => serendipity_userLoggedIn(), 'entry_id' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']) ? $serendipity['GET']['id'] : false, 'is_single_entry' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']), 'blogTitle' => $serendipity['blogTitle'], 'blogSubTitle' => !empty($serendipity['blogSubTitle']) ? $serendipity['blogSubTitle'] : '', 'blogDescription' => $serendipity['blogDescription'], 'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'], 'serendipityDefaultBaseURL' => $serendipity['defaultBaseURL'], 'serendipityBaseURL' => $serendipity['baseURL'], 'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '', 'serendipityIndexFile' => $serendipity['indexFile'], 'serendipityVersion' => $serendipity['expose_s9y'] ? $serendipity['version'] : '', 'lang' => $serendipity['lang'], 'category' => $category, 'category_info' => $category_info, 'template' => $serendipity['template'], 'dateRange' => !empty($serendipity['range']) ? $serendipity['range'] : array())); if (count($vars) > 0) { $serendipity['smarty']->assign($vars); } // For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. @(include_once $serendipity['smarty']->getConfigDir(0) . '/config.inc.php'); if (is_array($template_loaded_config)) { $template_vars =& $template_loaded_config; $serendipity['smarty']->assignByRef('template_option', $template_vars); } elseif (is_array($template_config)) { $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']); $serendipity['smarty']->assignByRef('template_option', $template_vars); } } return true; }