/** * smarty插件入口 * * @param null $tmplPath * @param array $extraParams * @throws Exception * @throws \SmartyException */ public function __construct($tmplPath = null, $extraParams = array()) { $this->_smarty = new \Smarty(); $this->_smarty->registerPlugin("function", 'assets', "\\Utils\\Func::assets"); if (null !== $tmplPath) { $this->setScriptPath($tmplPath); } foreach ($extraParams as $key => $value) { $this->_smarty->{$key} = $value; } }
/** * Singleton instance * @return Smarty * @throws SmartyException */ private function getSmarty() { if (!isset($this->smarty)) { $smarty = new Smarty(); $smarty->addTemplateDir(VIEWS_DIR); $smarty->setCompileDir(BASE_DIR . '/cache/templates'); $smarty->registerPlugin('modifier', 'lang', array('View', 'translate')); // translations $smarty->registerPlugin('function', 'profiler', array('Profiler', 'show')); // profiler $smarty->force_compile = true; $this->smarty = $smarty; } return $this->smarty; }
public function __construct($templateName) { $this->_smarty = new \Smarty(); // The smarty instance should be accessible before $smartyDir = ROOT . DS . 'app' . DS . 'views' . DS . 'smarty' . DS; $this->_smarty->template_dir = $smartyDir . 'templates' . DS; $this->_smarty->compile_dir = $smartyDir . 'compiled_templates' . DS; $this->_smarty->config_dir = $smartyDir . 'configs' . DS; $this->_smarty->cache_dir = $smartyDir . 'cache' . DS; $templatePath = ROOT . DS . 'app' . DS . 'views' . DS . 'smarty' . DS . 'templates' . DS . $templateName; if (!file_exists($templatePath)) { throw new \pff\ViewException('Template file ' . $templatePath . ' does not exist'); } parent::__construct($templateName); $this->_smarty->registerPlugin('function', 'renderAction', array($this, 'smarty_plugin_renderAction')); }
/** * @inheritdoc */ public function register(\Smarty $smarty) { if ($this->isPlugin()) { $smarty->registerPlugin($this->getExtensionType(), $this->getExtensionName(), [$this, 'process']); } elseif ($this->getExtensionType() === static::EXTENSION_TYPE_FILTER) { $smarty->registerFilter($this->getExtensionName(), [$this, 'process']); } }
/** * Used to register a plugin class to the view * @param unknown_type */ public function registerPlugin($pluginClass) { $class_methods = get_class_methods($pluginClass); foreach ($class_methods as $method_name) { $length = strlen($method_name); $types = array('function', 'block', 'modifier', 'compiler'); foreach ($types as $type) { $lenType = strlen($type); $pos = strpos($method_name, ucfirst($type)); if ($pos === $length - $lenType) { $tagName = substr($method_name, 0, $pos); Debug::add(get_class($pluginClass) . '::' . $method_name, "Smarty_plugins", $tagName); $this->smarty->registerPlugin($type, $tagName, array($pluginClass, $method_name)); } } } }
/** * Constructor of the class */ public function __construct($tpl_name = null) { $smarty = new Smarty(); // TODO: remove "APP_LOCAL_PATH" from the list in 2.4.1 $smarty->setTemplateDir(array(APP_LOCAL_PATH . '/templates', APP_LOCAL_PATH, APP_TPL_PATH)); $smarty->setCompileDir(APP_TPL_COMPILE_PATH); $smarty->addPluginsDir(array(APP_INC_PATH . '/smarty')); $smarty->registerPlugin('modifier', 'activateLinks', array('Link_Filter', 'activateLinks')); $smarty->registerPlugin('modifier', 'activateAttachmentLinks', array('Link_Filter', 'activateAttachmentLinks')); $smarty->registerPlugin('modifier', 'formatCustomValue', array('Custom_Field', 'formatValue')); $smarty->registerPlugin('modifier', 'bool', array('Misc', 'getBooleanDisplayValue')); $smarty->registerPlugin('modifier', 'format_date', array('Date_Helper', 'getFormattedDate')); $smarty->registerPlugin('modifier', 'timeago', array('Date_Helper', 'formatTimeAgo')); // Fixes problem with CRM API and dynamic includes. // See https://code.google.com/p/smarty-php/source/browse/trunk/distribution/3.1.16_RELEASE_NOTES.txt?spec=svn4800&r=4800 if (isset($smarty->inheritance_merge_compiled_includes)) { $smarty->inheritance_merge_compiled_includes = false; } // this avoids loading it twice when using composer if (function_exists('smarty_block_t')) { $smarty->registerPlugin('block', 't', 'smarty_block_t'); } if ($tpl_name) { $this->setTemplate($tpl_name); } $this->smarty = $smarty; }
public function init() { include_once 'includes/smarty/Smarty.class.php'; include_once 'includes/Label.php'; include_once 'includes/Url.php'; $smarty = new Smarty(); $smarty->template_dir = 'template/'; $smarty->compile_dir = 'data/templates_c/'; $smarty->config_dir = '/data/configs/'; $smarty->cache_dir = '/data/cache/'; //注册标签方法 $smarty->registerPlugin('function', 'label', array('Label', 'show')); $smarty->registerPlugin('function', 'url', array('Url', 'createUrl')); $this->smarty =& $smarty; $this->assign('smarty', $this->smarty); $this->initTheme(); $this->initStatics(); }
private function getSmarty() { \Smarty::$_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'; $smarty = new \Smarty(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $smarty->default_modifiers = array('escape:"html"'); $smarty->compile_dir = HIANO_APP_PATH . '/Cache/smarty/templates_c/'; $smarty->cache_dir = HIANO_APP_PATH . '/Cache/smarty/cache/'; $smarty->registerPlugin('function', 'url', array($this, 'function_url')); $smarty->registerPlugin('function', 'link', array($this, 'function_link')); $smarty->registerPlugin('block', 'form', array($this, 'block_form')); $plugins_dir = HIANO_APP_PATH . '/Plugin/Smarty'; if (file_exists($plugins_dir)) { $smarty->addPluginsDir($plugins_dir); } return $smarty; }
private function registerCompiler(\Smarty $smarty) { $names = array(); foreach ($this->helpers->getRegisteredServices() as $services) { $names = array_merge($names, $services); } $names = array_flip($names); $names = array_keys($names); foreach ($names as $name) { $smarty->registerPlugin('compiler', $name, array(__CLASS__, $name)); } }
public function temp() { $smarty = new Smarty(); $this->obj = $smarty; $smarty->caching = false; $smarty->template_dir = Temp . $this->TP_PATH; $smarty->compile_dir = Temp . $this->TP_PATH . "/" . TP_CACHE_NAME; @chmod(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME, 0777); @($handler = opendir(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME)); if ($handler) { while (($file = readdir($handler)) !== false) { if (strlen($file) > 8) { @chmod(Temp . $this->TP_PATH . "/" . TP_CACHE_NAME . "/" . $file, 0777); } } } $smarty->registerPlugin("function", "path", "sourcepath"); $smarty->registerPlugin("function", "App", "App"); $smarty->registerPlugin("function", "js", "scripts"); $smarty->registerPlugin("function", "URL", "URL"); $smarty->registerPlugin("function", "import", "import"); $smarty->registerPlugin("function", "nocache", "smarty_block_nocache"); if (!DEBUG) { $smarty->caching = true; $smarty->compile_dir = Temp . $this->TP_PATH . "/" . TP_CACHE_NAME; $smarty->cache_lifetime = TP_CACHE_TIME; $smarty->tp_path = Temp . $this->TP_PATH . "/RunTime"; $smarty->debugging = TP_DEBUG; } if (TP_PHP) { //$smarty->php_handling = SMARTY_PHP_ALLOW; } }
/** * show frontend widget * * @param array $vars settings * * @return string html */ function MP3_frontendWidget($vars = null) { $db = dbRow('select fields,template from mp3_plugin where id=' . $vars->id); $files = json_decode($db['fields'], true); if (count($files) == 0) { return 'No files yet'; } // { if template doesnt exist, create it $template = USERBASE . '/ww.cache/mp3/'; if (!is_dir($template)) { mkdir($template); } $template .= $vars->id; if (!file_exists($template)) { file_put_contents($template, $db['template']); } // } // { display the template require_once SCRIPTBASE . 'ww.incs/vendor/Smarty-3.1.19/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->compile_dir = USERBASE . '/ww.cache/templates_c'; if (!file_exists(USERBASE . '/ww.cache/templates_c')) { mkdir(USERBASE . '/ww.cache/templates_c'); } if (!file_exists(USERBASE . '/ww.cache/templates_c/image-gallery')) { mkdir(USERBASE . '/ww.cache/templates_c/image-gallery'); } $smarty->registerPlugin('function', 'LIST', 'MP3_list'); $smarty->registerPlugin('function', 'PLAY', 'mp3_play'); $smarty->registerPlugin('function', 'PROGRESS', 'MP3_progress'); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $smarty->smarty->tpl_vars['mp3_files']->value = $files; $html = $smarty->fetch(USERBASE . '/ww.cache/mp3/' . $vars->id); WW_addScript('mp3/frontend/jwplayer.js'); WW_addScript('mp3/frontend/widget.js'); // } return $html; }
/** * Основной метод, вызываемый для регистрации плагинов, предоставляемых данным классом для выполнения смарти-функций */ public final function registerPlugins(Smarty $smarty) { $this->LOGGER->info('Регистрируем плагины класса [{}]', $this->CLASS); foreach ($this->getPlugins() as $tagName => $pluginType) { PSSmartyTools::checkFunctionType($pluginType); if (array_key_exists($pluginType, $smarty->registered_plugins) && array_key_exists($tagName, $smarty->registered_plugins[$pluginType])) { $this->LOGGER->info('Не зарeгистрирован плагин [{}]', 'smarty_' . $pluginType . '_' . $tagName); } else { $smarty->registerPlugin($pluginType, $tagName, array($this, 'do_' . $pluginType . '_' . $tagName)); $this->LOGGER->info('Зарeгистрирован плагин [{}]', 'smarty_' . $pluginType . '_' . $tagName); } } }
public function init() { $smarty = new Smarty(); $smarty->template_dir = 'templates/'; $smarty->compile_dir = 'data/templates_c/'; $smarty->config_dir = '/data/configs/'; $smarty->cache_dir = '/data/cache/'; //注册标签方法 $smarty->registerPlugin('function', 'label', array('Label', 'show')); $this->smarty = $smarty; $this->assign('smarty', $this->smarty); $this->initTheme(); $this->initStatics(); }
/** * @return \Smarty */ public static function getSmarty() { if (!static::$smarty) { require_once DOCROOT . '../vendor/smarty/smarty/libs/Smarty.class.php'; $smarty = new \Smarty(); $smarty->template_dir = DOCROOT . '../app/views'; $smarty->compile_dir = DOCROOT . '../templates_c'; $smarty->error_reporting = E_ALL & ~E_NOTICE; $smarty->error_unassigned = false; //$smarty->force_compile = true; // Странно что это вообще понядобилось $smarty->muteExpectedErrors(); $smarty->registerPlugin('modifier', 'e', 'htmlspecialchars'); $smarty->assign(array('url' => DI::getDefault()->get('url'))); static::$smarty = $smarty; } return static::$smarty; }
/** * Constructor * * @access public */ public function __construct() { $this->smarty = new \Smarty(); $this->smarty->compile_dir = TMP_PATH . '/templates_c/'; $this->smarty->setCacheDir(TMP_PATH . '/templates_t/'); $this->smarty->registerPlugin('block', 't', 'smarty_block_translation'); $this->smarty->registerPlugin('modifier', 'date_format', 'smarty_modifier_datetime_format'); $this->smarty->registerPlugin('modifier', 'datetime_format', 'smarty_modifier_datetime_format'); $this->smarty->registerPlugin('function', 'snippet', 'smarty_function_snippet'); $this->smarty->registerPlugin('modifier', 'markdown', 'smarty_modifier_markdown'); $this->smarty->debugging = Config::$debug; $this->smarty->error_reporting = Config::$error_reporting; }
public function getSmarty() { $smarty = new \Smarty(); $finder = $this->app['view.finder']; $extension = $this->app['config']->get('smartyview::extension', 'tpl'); $escapeHTML = $this->app['config']->get('smartyview::escape_html', true); $allowOtherTemplateTypes = $this->app['config']->get('smartyview::allow_other_template_types', true); $errorReporting = $this->app['config']->get('smartyview::error_reporting', 0); $shouldCache = $this->app['config']->get('smartyview::cache', false); $compileDir = $this->app['path.storage'] . '/views/smarty/compile'; $cacheDir = $this->app['path.storage'] . '/views/smarty/cache'; $delimiters = $this->app['config']->get('smartyview::delimiters', array('left' => '{', 'right' => '}')); $plugins = $this->app['config']->get('smartyview::plugins', array('url' => new URLPlugin(), 'localize' => new LocalizePlugin())); $resources = $this->app['config']->get('smartyview::resources', array('laravel' => new LaravelResource($finder, $extension))); $defaultResource = $this->app['config']->get('smartyview::default_resource', empty($resources) ? null : key($resources)); $smarty->escape_html = $escapeHTML; $smarty->error_reporting = $errorReporting; $smarty->setCompileDir($compileDir); $smarty->setCacheDir($cacheDir); $smarty->left_delimiter = $delimiters['left']; $smarty->right_delimiter = $delimiters['right']; if ($shouldCache) { $smarty->compile_check = true; $smarty->caching = \Smarty::CACHING_LIFETIME_SAVED; } foreach ($plugins as $name => $plugin) { $smarty->registerPlugin($plugin->getType(), $name, array($plugin, 'pluginCallback')); } foreach ($resources as $name => $resource) { $smarty->registerResource($name, $resource); } if (!is_null($defaultResource)) { $smarty->default_resource_type = $defaultResource; } if ($allowOtherTemplateTypes) { $smarty->template_class = '\\SmartyView\\Smarty\\Template\\Laravel'; } $this->app['events']->fire('smartyview.smarty', array('smarty' => $smarty)); return $smarty; }
/** * 注册Smarty模板调用函数 * * @param string function 模板调用函数的名称 * @param string|array function 调用函数 * @return Oray_View_Smarty */ public function registFunction($function, $functionImpl) { $this->_smarty->registerPlugin('function', $function, $functionImpl); return $this; }
/** * set up Smarty with common functions * * @param string $compile_dir the caching directory to use * * @return object the Smarty object */ function Core_smartySetup($compile_dir) { global $DBVARS, $PLUGINS, $PAGEDATA; require_once SCRIPTBASE . '/ww.incs/vendor/Smarty-3.1.19/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $smarty->assign('WEBSITE_TITLE', htmlspecialchars($DBVARS['site_title'])); $smarty->assign('WEBSITE_SUBTITLE', htmlspecialchars($DBVARS['site_subtitle'])); $smarty->assign('GLOBALS', $GLOBALS); $smarty->assign('LANGUAGE', @$_SESSION['language']); $smarty->assign('LOCATIONNAME', @$_SESSION['location']['name']); $smarty->registerPlugin('function', 'BREADCRUMBS', 'Template_breadcrumbs'); $smarty->registerPlugin('function', 'LANGUAGES', 'Core_languagesGetUi'); $smarty->registerPlugin('function', 'LOCATIONSELECTOR', 'Core_locationsGetUi'); $smarty->registerPlugin('function', 'LOGO', 'Template_logoDisplay'); $smarty->registerPlugin('function', 'MENU', 'menuDisplay'); $smarty->registerPlugin('function', 'STATSVALUE', 'Template_statsValue'); $smarty->assign('QRCODE', '/a/f=qrCode/id=' . $PAGEDATA->id); $smarty->registerPlugin('function', 'nuMENU', 'Core_menuShowFg'); foreach ($PLUGINS as $pname => $plugin) { if (isset($plugin['frontend']['template_functions'])) { foreach ($plugin['frontend']['template_functions'] as $fname => $vals) { $smarty->registerPlugin('function', $fname, $vals['function']); } } } $smarty->compile_dir = $compile_dir; return $smarty; }
/** * Return smarty instance * * @return Smarty */ public function getSmarty() { static $oSmarty; if (!$oSmarty) { //create smarty object require_once 'Smarty.class.php'; $oSmarty = new Smarty(); foreach ($this->_aSmartyProperties as $sName => $mValue) { $oSmarty->{$sName} = substr($sName, -4) == '_dir' ? Volcano_Tools::fixPath($mValue) : $mValue; } foreach ($this->_aCustomFunctions as $sType => $aItems) { foreach ($aItems as $aItem) { if (substr($oSmarty->_version, 0, 1) != '2') { //bad code, but smarty3 has version like 'Smarty3-SVN$Rev: 3286 $' if ($sType == 'modifier' || $sType == 'function') { $oSmarty->registerPlugin($sType, $aItem[1], $aItem[0]); } elseif ($sType == 'outputfilter') { $oSmarty->registerFilter('output', $aItem[0]); } elseif ($sType == 'postfilter') { $oSmarty->registerFilter('post', $aItem[0]); } elseif ($sType == 'prefilter') { $oSmarty->registerFilter('pre', $aItem[0]); } } else { if ($sType == 'modifier') { $oSmarty->register_modifier($aItem[1], $aItem[0]); } elseif ($sType == 'function') { $oSmarty->register_function($aItem[1], $aItem[0]); } elseif ($sType == 'outputfilter') { $oSmarty->register_outputfilter($aItem[0]); } elseif ($sType == 'postfilter') { $oSmarty->register_postfilter($aItem[0]); } elseif ($sType == 'prefilter') { $oSmarty->register_prefilter($aItem[0]); } } } } } $oSmarty->error_reporting = error_reporting() & ~E_NOTICE; return $oSmarty; }
if (file_exists(BASE_PATH . '../../../../../.mebb')) { //this is just for the our framework. just ignore this. the else block is relevant for you :) include_once BASE_PATH . '../../../../smarty/Smarty.class.php'; include_once BASE_PATH . '../../../../../app/core/web/smarty/functions/locale.php'; } else { print 'PLEASE INCLUDE YOUR SMARTY CLASS IN FILE ' . __FILE__ . ' line ' . __LINE__ . ' AND REMOVE THE exit() STATEMENT IN LINE ' . (__LINE__ + 2) . PHP_EOL; include realpath(BASE_PATH . '../../../mebb_i18n_smarty_function_locale.php'); exit; } //1. SETUP SMARTY AS YOU USUALLY DO, i.e. DON'T JUST COPY THE BELOW, UNLESS IT FITS YOUR NEEDS //LOAD ALL THE MODIFIERS, FILTER, ETC. THAT YOU USE IN YOUR TEMPLATES, OTHERWISE, YOU'LL //ENCOUNTER A LOT OF COMPILE ERRORS :D $smarty = new \Smarty(); $smarty->setTemplateDir(BASE_PATH . 'templates'); $smarty->setCompileDir(BASE_PATH . 'compile'); $smarty->setCacheDir(BASE_PATH . 'compile'); $smarty->setConfigDir(BASE_PATH . 'compile'); //2. INTEGRATE THE CUSTOM LOCALES FUNCTION. ACTUALLY THAT'S THE ONLY THING YOU REALLY HAVE TO DO $smarty->registerPlugin('function', 'locale', '\\mebb\\app\\core\\web\\smarty\\functions\\locale'); //3. SOMEWHERE IN YOUR APPLICATION YOU SET: // -- THE PATH FOR THE LOCALE FILES $smarty->assign('path', BASE_PATH . 'locale'); //4. SOMEWHERE IN YOUR APPLICATION BEFORE THE FETCH/DISPLAY FUNCTION CALL // SET THE LOCALE TO USE. PROBABLY YOU ARE DOING THIS ANYWAYS ALREADY // IF YOU ARE USING GETTEXT IN YOUR PHP APPLICATION ALREADY // N.B.: for a tutorial consider http://onlamp.com/pub/a/php/2002/06/13/php.html $language = isset($argv[1]) ? trim($argv[1]) : 'de_DE'; putenv("LANG={$language}"); setlocale(LC_ALL, $language); //DONE! THE REST IST JUST FOR DEMONSTRATION PURPOSES print $smarty->fetch('example_01.tpl');
/** * show the ImageGallery widget * * @param array $vars parameters * * @return html */ function GalleryWidget_show($vars) { if (!isset($vars->id) || !$vars->id) { return ''; } $id = $vars->id; // { get data from widget db $vars = dbRow('select * from image_gallery_widget where id="' . $id . '"'); // } // { check to see if there are files in the directory $hasImages = false; $dirname = USERBASE . '/f/' . $vars['directory']; if (file_exists($dirname)) { $dir = new DirectoryIterator($dirname); foreach ($dir as $file) { if ($file->isDot()) { continue; } $hasImages = true; break; } } // } if ($hasImages) { // { if template doesn't exist, create it $template = USERBASE . '/ww.cache/image-gallery-widget/'; @mkdir($template, 0777, true); $template .= $id; if (!file_exists($template)) { if (!$vars['gallery_type']) { $vars['gallery_type'] = 'grid'; } $thtml = file_get_contents(SCRIPTBASE . 'ww.plugins/image-gallery/admin/types/' . strtolower($vars['gallery_type']) . '.tpl'); if (!$thtml) { $thtml = file_get_contents(dirname(__FILE__) . '/../admin/types/list.tpl'); } file_put_contents($template, $thtml); } // } // { display the template require_once SCRIPTBASE . 'ww.incs/vendor/Smarty-3.1.19/libs/Smarty.class.php'; require_once SCRIPTBASE . 'ww.plugins/image-gallery/frontend/template-functions.php'; $smarty = new Smarty(); $smarty->compile_dir = USERBASE . '/ww.cache/templates_c'; @mkdir(USERBASE . '/ww.cache/templates_c'); @mkdir(USERBASE . '/ww.cache/templates_c/image-gallery-widget'); $smarty->registerPlugin('function', 'GALLERY_IMAGE', 'ImageGallery_templateImage'); $smarty->registerPlugin('function', 'GALLERY_IMAGES', 'ImageGallery_templateImages'); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $c .= $smarty->fetch($template); // { quick hack to add the options rather than // writing a whole new function in php $script = ' Gallery.options.directory="' . (int) $vars['directory'] . '"; Gallery.options.thumbsize=' . (int) $vars['thumbsize'] . '; Gallery.options.imageWidth=' . (int) $vars['image_size'] . '; Gallery.options.imageHeight=' . (int) $vars['image_size'] . '; Gallery.gallery() .attr("cols","' . $vars['columns'] . '") .attr("rows","' . $vars['rows'] . '"); '; // } WW_addScript('image-gallery/frontend/gallery.js'); WW_addInlineScript($script); WW_addCSS('/ww.plugins/image-gallery/frontend/gallery.css'); // } return $c; } else { $dir = $vars['directory']; return '<em>' . __('gallery "%1" not found or empty.', array($dir), 'core') . '</em>'; } }
/** * @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); } }
/** * Sets up all of the functions this extension makes available. */ public function __construct(\Smarty $smarty) { $smarty->registerPlugin('function', 'fuel_version', array($this, 'fuel_version')); $smarty->registerPlugin('function', 'url', array($this, 'url')); $smarty->registerPlugin('function', 'base_url', array('Uri', 'base')); $smarty->registerPlugin('function', 'current_url', array('Uri', 'current')); $smarty->registerPlugin('function', 'uri_segment', array($this, 'uri_segment')); $smarty->registerPlugin('function', 'uri_segments', array('Uri', 'segments')); $smarty->registerPlugin('function', 'config', array($this, 'config_get')); $smarty->registerPlugin('function', 'lang', array($this, 'lang_get')); $smarty->registerPlugin('block', 'form', array($this, 'form')); $smarty->registerPlugin('function', 'form_input', array($this, 'form_input')); $smarty->registerPlugin('function', 'form_password', array($this, 'form_password')); $smarty->registerPlugin('function', 'form_hidden', array($this, 'form_hidden')); $smarty->registerPlugin('function', 'form_button', array($this, 'form_button')); $smarty->registerPlugin('function', 'form_reset', array($this, 'form_reset')); $smarty->registerPlugin('function', 'form_submit', array($this, 'form_submit')); $smarty->registerPlugin('function', 'form_textarea', array($this, 'form_textarea')); $smarty->registerPlugin('block', 'form_fieldset', array($this, 'form_fieldset')); $smarty->registerPlugin('function', 'form_label', array($this, 'form_label')); $smarty->registerPlugin('function', 'form_checkbox', array($this, 'form_checkbox')); $smarty->registerPlugin('function', 'form_radio', array($this, 'form_radio')); $smarty->registerPlugin('function', 'form_file', array($this, 'form_file')); $smarty->registerPlugin('function', 'form_select', array($this, 'form_select')); $smarty->registerPlugin('function', 'form_val', array($this, 'form_val')); $smarty->registerPlugin('function', 'input_get', array($this, 'input_get')); $smarty->registerPlugin('function', 'input_post', array($this, 'input_post')); $smarty->registerPlugin('function', 'asset_add_path', array($this, 'asset_add_path')); $smarty->registerPlugin('function', 'asset_css', array($this, 'asset_css')); $smarty->registerPlugin('function', 'asset_js', array($this, 'asset_js')); $smarty->registerPlugin('function', 'asset_img', array($this, 'asset_img')); $smarty->registerPlugin('function', 'asset_render', array($this, 'asset_render')); $smarty->registerPlugin('function', 'asset_find_file', array($this, 'asset_find_file')); $smarty->registerPlugin('function', 'html_anchor', array($this, 'html_anchor')); $smarty->registerPlugin('function', 'session_get_flash', array($this, 'session_get_flash')); $smarty->registerPlugin('block', 'markdown', array($this, 'markdown_parse')); $smarty->registerPlugin('function', 'auth_has_access', array($this, 'auth_has_access')); $smarty->registerPlugin('function', 'auth_check', array($this, 'auth_check')); }
/** * Регистрируем плагины в переданном экземпляре smarty * * @param Smarty $smarty */ public static function registerPlugins(Smarty $smarty) { $smarty->registerPlugin('block', 'sf_changeState', array('CStatefullFormSmartyPlugin', 'StatefullForm_ChangeState')); $smarty->registerPlugin('block', 'sf_showIfVisible', array('CStatefullFormSmartyPlugin', 'StatefullForm_ShowIfVisible')); $smarty->registerPlugin('block', 'sf_showIfEditable', array('CStatefullFormSmartyPlugin', 'StatefullForm_ShowIfEditable')); $smarty->registerPlugin('function', 'sf_toggleVisible', array('CStatefullFormSmartyPlugin', 'StatefullForm_ToggleVisible')); $smarty->registerPlugin('function', 'sf_toggleEdit', array('CStatefullFormSmartyPlugin', 'StatefullForm_ToggleEdit')); $smarty->registerPlugin('function', 'sf_toggleDelete', array('CStatefullFormSmartyPlugin', 'StatefullForm_ToggleDelete')); $smarty->registerPlugin('function', 'sf_showByDefault', array('CStatefullFormSmartyPlugin', 'StatefullForm_ShowByDefault')); $smarty->registerPlugin('function', 'sf_input', array('CStatefullFormWidgets', 'input')); $smarty->registerPlugin('function', 'sf_hidden', array('CStatefullFormWidgets', 'hidden')); $smarty->registerPlugin('function', 'sf_select', array('CStatefullFormWidgets', 'select')); $smarty->registerPlugin('function', 'sf_submit', array('CStatefullFormWidgets', 'submit')); $smarty->registerPlugin('function', 'sf_text', array('CStatefullFormWidgets', 'text')); }
$templateResult = $db->get($db->query("SELECT * FROM cms_template WHERE ID='" . $tempID . "' AND enabled='1' AND status='N'")); $template->tempName = $templateResult['folder']; $template->menuID = $menuID; $template->langID = $langID; $template->tempID = $tempID; if ($templateResult && $layout == false) { $path = '../../templates/' . $user->domainName . '/' . $templateResult['folder'] . '/'; /*Smarty*/ if (!defined('CACHE_LIFETIME')) { define('CACHE_LIFETIME', 60 * 60 * 24 * 7); // secs (60*60*24*7 = 1 week) } require_once SITE_ROOT . SITE_FOLDER . '/Smarty/Smarty.class.php'; require_once SITE_ROOT . SITE_FOLDER . '/Smarty/plugins/function.sumo_admin_panel.php'; $smarty = new Smarty(); $smarty->registerPlugin('function', 'panel', 'sumo_admin_panel'); $smarty->template_dir = ''; if ($user->developer == "1") { $smarty->caching = 0; } else { $smarty->caching = 2; $smarty->cache_lifetime = 4 * 24 * 60 * 60; } $smarty->config_dir = SITE_ROOT . SITE_FOLDER . '/Smarty/'; if (!is_dir($path . 'templates_c/')) { mkdir($path . 'templates_c/', PER_FOLDER); chmod($path . 'templates_c/', PER_FOLDER); } $smarty->compile_dir = $path . 'templates_c/'; if (!is_dir($path . 'cache/')) { mkdir($path . 'cache/', PER_FOLDER);
// Establishing modules. $module_dev = new Modules(); // Establishing users. $users = new Users(); // Establishing Smarty and templates. $smarty = new Smarty(); $smarty->template_dir = 'style'; $smarty->compile_dir = '../cache'; $tmpl = new Templates(); $tmpl->check(); $smarty->assign('settings', $settings); $smarty->assign('lang', $lang); $smarty->assign('module_dev', $module_dev); $smarty->assign('foxy_version', FOXY_VERSION); //menu icons function $smarty->registerPlugin('function', 'menu_icon', 'set_menu_icon'); function set_menu_icon($params, $smarty) { if (!empty($params['is_module'])) { $menu_icon = ''; } else { $menu_icon = "style=\"background-image: url('style/images/menu_icons/{$params['icon']}');background-repeat: no-repeat;background-position: 10px center;background-size:22px;\""; } return $menu_icon; } $current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $smarty->assign('current_url', $current_url); $smarty->assign('date', date("d/m/Y", time())); // Modules in Main menu $modules = $db->fetch('modules'); $final_modules = array();
<?php /* IMPORTANTE: Se supone que previamente a la inclusión de este script se ha realizado la inclusión del script de 'config.php' que está en el directorio configuracion. */ require $config_urls['BASE_PATH'] . 'smarty/libs/Smarty.class.php'; $oSmarty = new Smarty(); // Definimos el directorio de plantillas. $oSmarty->setTemplateDir(APP_TEMPLATES_DIR . 'www/templates'); // Definimos los directorios de compilación y de cahé. $oSmarty->setCompileDir(APP_ROOT . 'smarty/templates_c'); $oSmarty->setCacheDir(APP_ROOT . 'smarty/cache'); // Establecemos los parámetros necesarios. $oSmarty->allow_php_templates = true; $oSmarty->force_compile = true; //$oSmarty->force_compile = false; $oSmarty->caching = false; //$oSmarty->caching = true; $oSmarty->cache_lifetime = 100; $oSmarty->debugging = DEBUG_SMARTY; //Registramos el plugin de idiomas en smarty $oSmarty->registerPlugin('block', 'translate', array('Localizer', 'translate'), true); $oSmarty->assign('ID_ROL_ADMINISTRADOR', ID_ROL_ADMINISTRADOR); $oSmarty->assign('ID_ROL_USUARIO', ID_ROL_USUARIO); if (empty($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = getenv('HTTP_REFERER'); }
require_once $root . 'libs' . DS . 'extend.php'; //Initialisation des mails require_once $root . 'libs' . DS . 'phpmailer' . DS . 'class.phpmailer.php'; //Initialisation du captcha require_once $root . 'libs' . DS . 'securimage' . DS . 'securimage.php'; //Initialisation du PDO $pdo = new PDO($dsn, $db_user, $db_pass); // Initialisation du système de template /** * Chargement du moteur de template Smarty */ include $root . 'libs' . DS . 'Smarty' . DS . 'Smarty.class.php'; $tpl = new Smarty(); $tpl->compile_dir = $tmpdir; $tpl->template_dir = $root . 'templates'; $tpl->registerPlugin('function', 'mkurl', 'mkurl_smarty'); $tpl->registerPlugin('function', 'mkmenu', 'mkmenu_smarty'); $tpl->registerPlugin('block', 'acl', 'acl_smarty'); if (!is_dir($tpl->compile_dir)) { @mkdir($tpl->compile_dir, 0777); } if (!is_writable($tpl->compile_dir)) { chmod($tpl->compile_dir, 0777); } // Etape 1, on charge la configuration sur l'environnement présent. $cfg = get_configs(); $config = array(); foreach ($cfg as $cfgPart) { $config[$cfgPart['name']] = array(); foreach ($cfgPart['fields'] as $field) { $config[$cfgPart['name']][$field['name']] = isset($field['default']) ? $field['default'] : null;
$smarty = new Smarty(); $smarty->debugging = false; $smarty->cache_lifetime = 0; // Set paths for Smarty $smarty->setTemplateDir(realpath(dirname(APPLICATION_PATH) . '/sys/templates/')); $smarty->setCacheDir(realpath(APPLICATION_PATH . '/tmp/cache/')); $smarty->setCompileDir(realpath(APPLICATION_PATH . '/tmp/cache/')); //adds own smarty plugins $smarty->addPluginsDir(dirname(__FILE__) . '/smarty_plugins/'); //add stripslash smarty function $smarty->registerPlugin('modifier', 'unescape', 'stripslashes'); $smarty->registerPlugin('modifier', 'capitalise', 'ucwords'); $smarty->registerPlugin('modifier', "siLocal_number", array("siLocal", "number")); $smarty->registerPlugin('modifier', "siLocal_number_clean", array("siLocal", "number_clean")); $smarty->registerPlugin('modifier', "siLocal_number_trim", array("siLocal", "number_trim")); $smarty->registerPlugin('modifier', "siLocal_number_formatted", array("siLocal", "number_formatted")); $smarty->registerPlugin('modifier', "siLocal_date", array("siLocal", "date")); $smarty->registerPlugin('modifier', 'htmlsafe', 'htmlsafe'); $smarty->registerPlugin('modifier', 'urlsafe', 'urlsafe'); $smarty->registerPlugin('modifier', 'urlencode', 'urlencode'); $smarty->registerPlugin('modifier', 'outhtml', 'outhtml'); $smarty->registerPlugin('modifier', 'htmlout', 'outhtml'); //common typo $smarty->registerPlugin('modifier', 'urlescape', 'urlencode'); //common typo
$smarty->assign('sEmpty', ''); $smarty->assign('nullVar', null); $smarty->assign('textWithHTML', '<span style="color:red;"><i><b>foo</b></i></span>'); $smarty->assign('textWithHTMLEntities', 'Germans use "mlauts" and pay in €uro'); $smarty->assign('testPath', dirname(__DIR__) . '/templates'); $smarty->assign('escapeHtml', '<span style="color:red;"><i><b>foo</b></i></span>'); $smarty->assign('books', array(array('title' => 'JavaScript: The Definitive Guide', 'author' => 'David Flanagan', 'price' => '31.18'), array('title' => 'Murach JavaScript and DOM Scripting', 'author' => 'Ray Harris', 'price' => ''), array('title' => 'Head First JavaScript', 'author' => 'Michael Morrison', 'price' => '29.54'))); function sayHello($params, $template) { $s = 'Hello '; if (array_key_exists('to', $params)) { $s .= $params['to']; } return $s; } $smarty->registerPlugin('function', 'sayHello', 'sayHello'); function replaceStr($params, $content, $template, &$repeat) { return str_replace($params['from'], $params['to'], $content); } $smarty->registerPlugin('block', 'replaceStr', 'replaceStr'); function isEmptyStr($params, $template) { return strlen($params['s']) == 0; } $smarty->registerPlugin('function', 'isEmptyStr', 'isEmptyStr'); function strayFunc($v1, $v2) { return $v1 . ',' . $v2; } function strayNoArgs()