/** * Init template engine * * @return boolean always true */ function fn_init_templater($area = AREA) { $auth = Tygh::$app['session']['auth']; $view = new SmartyCore(); \SmartyException::$escape = false; /** * Change templater pre-init parameters * * @param object $view Templater object */ fn_set_hook('init_templater', $view); $view->_dir_perms = DEFAULT_DIR_PERMISSIONS; $view->_file_perms = DEFAULT_FILE_PERMISSIONS; $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource()); // resource for shared templates loaded from backend $view->registerResource('backend', new Tygh\SmartyEngine\BackendResource()); if ($area == 'A') { if (!empty($auth['user_id'])) { // Auto-tooltips for admin panel $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip')); if (fn_allowed_for('ULTIMATE')) { // Enable sharing for objects $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing')); } } $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preScript')); } if ($area == 'C') { $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper')); if (Registry::get('runtime.customization_mode.design')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds')); } if (Registry::get('runtime.customization_mode.live_editor')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputLiveEditorWrapper')); } $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputScript')); } if (Embedded::isEnabled()) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl')); } // CSRF form protection if (fn_is_csrf_protection_enabled($auth)) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash')); } // Language variable retrieval optimization $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation')); $smarty_plugins_dir = $view->getPluginsDir(); $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins'); $view->addPluginsDir($smarty_plugins_dir); $view->error_reporting = E_ALL & ~E_NOTICE; $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler')); $view->setArea($area); $view->use_sub_dirs = false; $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || fn_is_development() ? true : false; $view->setLanguage(CART_LANGUAGE); $view->assign('ldelim', '{'); $view->assign('rdelim', '}'); $view->assign('currencies', Registry::get('currencies'), false); $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view->assign('languages', Registry::get('languages')); if ($area == 'A') { $view->assign('addon_permissions_text', fn_get_addon_permissions_text()); } if (!fn_allowed_for('ULTIMATE:FREE')) { $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true)); if (defined('CART_LOCALIZATION')) { $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } } if (defined('THEMES_PANEL')) { if (fn_allowed_for('ULTIMATE')) { $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies'); Registry::set('demo_theme.storefronts', $storefronts); } $view->assign('demo_theme', Registry::get('demo_theme')); } Tygh::$app['view'] = $view; /** * Change templater parameters * * @param object $view Templater object */ fn_set_hook('init_templater_post', $view); return array(INIT_STATUS_OK); }
/** * @var string $root * @var string $theme * @var string $path */ function __construct($root = ".", $theme = "", $path = "template") { global $conf, $lang_info; SmartyException::$escape = false; $this->scriptLoader = new ScriptLoader(); $this->cssLoader = new CssLoader(); $this->smarty = new Smarty(); $this->smarty->debugging = $conf['debug_template']; if (!$this->smarty->debugging) { $this->smarty->error_reporting = error_reporting() & ~E_NOTICE; } $this->smarty->compile_check = $conf['template_compile_check']; $this->smarty->force_compile = $conf['template_force_compile']; if (!isset($conf['data_dir_checked'])) { $dir = PHPWG_ROOT_PATH . $conf['data_location']; mkgetdir($dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR); if (!is_writable($dir)) { load_language('admin.lang'); fatal_error(l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation', $conf['data_location']), l10n('an error happened'), false); } if (function_exists('pwg_query')) { conf_update_param('data_dir_checked', 1); } } $compile_dir = PHPWG_ROOT_PATH . $conf['data_location'] . 'templates_c'; mkgetdir($compile_dir); $this->smarty->setCompileDir($compile_dir); $this->smarty->assign('pwg', new PwgTemplateAdapter()); $this->smarty->registerPlugin('modifiercompiler', 'translate', array('Template', 'modcompiler_translate')); $this->smarty->registerPlugin('modifiercompiler', 'translate_dec', array('Template', 'modcompiler_translate_dec')); $this->smarty->registerPlugin('modifier', 'explode', array('Template', 'mod_explode')); $this->smarty->registerPlugin('modifier', 'ternary', array('Template', 'mod_ternary')); $this->smarty->registerPlugin('modifier', 'get_extent', array($this, 'get_extent')); $this->smarty->registerPlugin('block', 'html_head', array($this, 'block_html_head')); $this->smarty->registerPlugin('block', 'html_style', array($this, 'block_html_style')); $this->smarty->registerPlugin('function', 'combine_script', array($this, 'func_combine_script')); $this->smarty->registerPlugin('function', 'get_combined_scripts', array($this, 'func_get_combined_scripts')); $this->smarty->registerPlugin('function', 'combine_css', array($this, 'func_combine_css')); $this->smarty->registerPlugin('function', 'define_derivative', array($this, 'func_define_derivative')); $this->smarty->registerPlugin('compiler', 'get_combined_css', array($this, 'func_get_combined_css')); $this->smarty->registerPlugin('block', 'footer_script', array($this, 'block_footer_script')); $this->smarty->registerFilter('pre', array('Template', 'prefilter_white_space')); if ($conf['compiled_template_cache_language']) { $this->smarty->registerFilter('post', array('Template', 'postfilter_language')); } $this->smarty->setTemplateDir(array()); if (!empty($theme)) { $this->set_theme($root, $theme, $path); if (!defined('IN_ADMIN')) { $this->set_prefilter('header', array('Template', 'prefilter_local_css')); } } else { $this->set_template_dir($root); } if (isset($lang_info['code']) and !isset($lang_info['jquery_code'])) { $lang_info['jquery_code'] = $lang_info['code']; } if (isset($lang_info['jquery_code']) and !isset($lang_info['plupload_code'])) { $lang_info['plupload_code'] = str_replace('-', '_', $lang_info['jquery_code']); } $this->smarty->assign('lang_info', $lang_info); if (!defined('IN_ADMIN') and isset($conf['extents_for_templates'])) { $tpl_extents = unserialize($conf['extents_for_templates']); $this->set_extents($tpl_extents, './template-extension/', true, $theme); } }
/** * Init template engine * * @return boolean always true */ function fn_init_templater($area = AREA) { $view = new SmartyCore(); \SmartyException::$escape = false; /** * Change templater pre-init parameters * * @param object $view Templater object */ fn_set_hook('init_templater', $view); $view->registerResource('tygh', new Tygh\SmartyEngine\FileResource()); if ($area == 'A' && !empty($_SESSION['auth']['user_id'])) { // Auto-tooltips for admin panel $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preFormTooltip')); } // Customization mode if ($area == 'C') { $view->registerFilter('pre', array('Tygh\\SmartyEngine\\Filters', 'preTemplateWrapper')); if (Registry::get('runtime.customization_mode.design')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTemplateIds')); } } if (Registry::get('config.tweaks.anti_csrf') == true) { // CSRF form protection $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSecurityHash')); } if (Embedded::isEnabled()) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputEmbeddedUrl')); } if (fn_allowed_for('ULTIMATE')) { // Enable sharing for objects $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputSharing')); } // Language variable retrieval optimization $view->registerFilter('post', array('Tygh\\SmartyEngine\\Filters', 'postTranslation')); // Translation mode if (Registry::get('runtime.customization_mode.translation')) { $view->registerFilter('output', array('Tygh\\SmartyEngine\\Filters', 'outputTranslateWrapper')); } if (Registry::get('settings.General.debugging_console') == 'Y') { if (empty($_SESSION['debugging_console']) && !empty($_SESSION['auth']['user_id'])) { $user_type = db_get_field("SELECT user_type FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']); if ($user_type == 'A') { $_SESSION['debugging_console'] = true; } } if (isset($_SESSION['debugging_console']) && $_SESSION['debugging_console'] == true) { error_reporting(0); $view->debugging = true; } } $smarty_plugins_dir = $view->getPluginsDir(); $view->setPluginsDir(Registry::get('config.dir.functions') . 'smarty_plugins'); $view->addPluginsDir($smarty_plugins_dir); $view->error_reporting = E_ALL & ~E_NOTICE; $view->registerDefaultPluginHandler(array('Tygh\\SmartyEngine\\Filters', 'smartyDefaultHandler')); $view->setArea($area); $view->use_sub_dirs = false; $view->compile_check = Development::isEnabled('compile_check') || Debugger::isActive() || defined('DEVELOPMENT') ? true : false; $view->setLanguage(CART_LANGUAGE); $view->assign('ldelim', '{'); $view->assign('rdelim', '}'); $view->assign('currencies', Registry::get('currencies'), false); $view->assign('primary_currency', CART_PRIMARY_CURRENCY, false); $view->assign('secondary_currency', CART_SECONDARY_CURRENCY, false); $view->assign('languages', Registry::get('languages')); if ($area == 'A') { $view->assign('addon_permissions_text', fn_get_addon_permissions_text()); } if (!fn_allowed_for('ULTIMATE:FREE')) { $view->assign('localizations', fn_get_localizations(CART_LANGUAGE, true)); if (defined('CART_LOCALIZATION')) { $view->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } } if (defined('THEMES_PANEL')) { if (fn_allowed_for('ULTIMATE')) { $storefronts = db_get_array('SELECT storefront, company, company_id FROM ?:companies'); Registry::set('demo_theme.storefronts', $storefronts); } $view->assign('demo_theme', Registry::get('demo_theme')); } Registry::set('view', $view); /** * Change templater parameters * * @param object $view Templater object */ fn_set_hook('init_templater_post', $view); return array(INIT_STATUS_OK); }