Set plugins directory
public setPluginsDir ( string | array $plugins_dir ) : Smarty | ||
$plugins_dir | string | array | directory(s) of plugins |
return | Smarty | current Smarty instance for chaining |
/** * 构造方法 * * @return void */ protected function __construct() { \Yaf_Loader::import(APP_PATH . 'library/Thirdpart/Smarty/libs/Smarty.class.php'); $this->_smarty = new \Smarty(); $this->_smarty->setTemplateDir(''); $this->_smarty->setCompileDir(TMP_PATH . 'smarty-compile/'); $this->_smarty->setCacheDir(TMP_PATH . 'smarty-cache/'); $this->_smarty->setPluginsDir(APP_PATH . 'library/Smarty/Plugins/'); $this->_smarty->left_delimiter = '<!--{'; $this->_smarty->right_delimiter = '}-->'; $this->_smarty->enableSecurity('Comm\\Smarty_Security_Policy'); }
function renderEntries(Search_ResultSet $entries) { global $tikipath; $smarty = new Smarty(); $smarty->setCompileDir($tikipath . 'templates_c'); $smarty->setTemplateDir(null); $smarty->setTemplateDir(dirname($this->templateFile)); $smarty->setPluginsDir(array($tikipath . TIKI_SMARTY_DIR, SMARTY_DIR . 'plugins')); $secpol = new Tiki_Security_Policy($smarty); $secpol->secure_dir[] = dirname($this->templateFile); $smarty->enableSecurity($secpol); if ($this->changeDelimiters) { $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; } foreach ($this->data as $key => $value) { $smarty->assign($key, $value); } $smarty->assign('results', $entries); $smarty->assign('facets', array_map(function ($facet) { return array('name' => $facet->getName(), 'label' => $facet->getLabel(), 'options' => $facet->getOptions()); }, $entries->getFacets())); $smarty->assign('count', count($entries)); $smarty->assign('offset', $entries->getOffset()); $smarty->assign('offsetplusone', $entries->getOffset() + 1); $smarty->assign('offsetplusmaxRecords', $entries->getOffset() + $entries->getMaxRecords()); $smarty->assign('maxRecords', $entries->getMaxRecords()); return $smarty->fetch($this->templateFile); }
/** * Initialise the template system */ private function initSmarty() { $this->smarty = new \Smarty(); $this->smarty->setTemplateDir(APP_DIR . 'templates'); $this->smarty->setCompileDir(APP_DIR . 'templates/compiled'); $pluginDirectories = $this->smarty->getPluginsDir(); $pluginDirectories[] = SYSTEM_DIR . 'Smarty'; $this->smarty->setPluginsDir($pluginDirectories); }
/** * Инициализация модуля * */ public function Init($bLocal = false) { $this->Hook_Run('viewer_init_start', compact('bLocal')); /** * Load template config */ if (!$bLocal) { if (file_exists($sFile = Config::Get('path.smarty.template') . '/settings/config/config.php')) { Config::LoadFromFile($sFile, false); } } /** * Заголовок HTML страницы */ $this->sHtmlTitle = Config::Get('view.name'); /** * SEO ключевые слова страницы */ $this->sHtmlKeywords = Config::Get('view.keywords'); /** * SEO описание страницы */ $this->sHtmlDescription = Config::Get('view.description'); /** * Создаём объект Smarty и устанавливаем необходиму параметры */ $this->oSmarty = new lsSmarty(); $this->oSmarty->error_reporting = E_ALL ^ E_NOTICE; // подавляем NOTICE ошибки - в этом вся прелесть смарти ) $this->oSmarty->setTemplateDir(array_merge((array) Config::Get('path.smarty.template'), array(Config::Get('path.root.server') . '/plugins/'))); /** * Для каждого скина устанавливаем свою директорию компиляции шаблонов */ $sCompilePath = Config::Get('path.smarty.compiled') . '/' . Config::Get('view.skin'); if (!is_dir($sCompilePath)) { @mkdir($sCompilePath); } $this->oSmarty->setCompileDir($sCompilePath); $this->oSmarty->setCacheDir(Config::Get('path.smarty.cache')); $this->oSmarty->setPluginsDir(array_merge(array(Config::Get('path.smarty.plug'), 'plugins'), $this->oSmarty->getPluginsDir())); /** * Получаем настройки блоков из конфигов */ $this->InitBlockParams(); /** * Добавляем блоки по предзагруженным правилам из конфигов */ $this->BuildBlocks(); /** * Получаем настройки JS, CSS файлов */ $this->InitFileParams(); $this->sCacheDir = Config::Get('path.smarty.cache'); }
/** * Init smarty templates */ function init() { $smarty = new Smarty(); $smarty->setTemplateDir(VIEW_DIR); $smarty->setCompileDir(COMPILE_DIR); $smarty->setPluginsDir([BOOTSTRAP_DIR . '/view/assets/Plugins', APP_DIR . '/view/assets/Plugins']); $smarty->assign(['basePath' => BASE_PATH, 'isDebug' => DEBUG]); $smarty->autoload_filters = ['output' => ['striphtml']]; $smarty->debugging = DEBUG; $this->smarty = $smarty; }
public function __construct() { parent::__construct(); $this->javascript_files = array(); $this->javascript_texts = array(); $file_path = dirname(__FILE__) . '/'; $smarty_dir = $file_path . '../smarty/'; parent::setTemplateDir($smarty_dir . 'templates/'); parent::setCompileDir($smarty_dir . 'dev/template_c/'); parent::setCacheDir($smarty_dir . 'dev/cache/'); parent::setConfigDir($smarty_dir . 'configs/'); $smarty_install_path = $file_path . '../../third_party/Smarty_3_1_0/'; parent::setPluginsDir($smarty_install_path . 'libs/plugins'); parent::addPluginsDir($smarty_install_path . 'libs/sysplugins'); }
/** * @return Smarty */ private function _getSmarty() { if (!isset(self::$_smarty)) { self::$_smarty = new Smarty(); self::$_smarty->setTemplateDir(DIR_ROOT); self::$_smarty->setCompileDir(CM_Bootloader::getInstance()->getDirTmp() . 'smarty/'); self::$_smarty->_file_perms = 0666; self::$_smarty->_dir_perms = 0777; self::$_smarty->compile_check = CM_Bootloader::getInstance()->isDebug(); self::$_smarty->caching = false; self::$_smarty->error_reporting = error_reporting(); } $pluginDirs = array(SMARTY_PLUGINS_DIR); foreach ($this->getSite()->getModules() as $moduleName) { $pluginDirs[] = CM_Util::getModulePath($moduleName) . 'library/' . $moduleName . '/SmartyPlugins'; } self::$_smarty->setPluginsDir($pluginDirs); self::$_smarty->loadFilter('pre', 'translate'); return self::$_smarty; }
/** * 获取模版对象 * @return void */ private static function getTemplate() { if (null == self::$mTemplate) { $smarty = new Smarty(); $smarty->setTemplateDir(TEMPLATE_DIR); //$smarty->template_dir = TEMPLATE_DIR; $smarty->setCompileDir(TEMPLATE_COMPILED); //$smarty->compile_dir = TEMPLATE_COMPILED; $smarty->setConfigDir(TEMPLATE_CONFIGS); //$smarty->config_dir = TEMPLATE_CONFIGS; $smarty->setCacheDir(TEMPLATE_CACHE); //$smarty->cache_dir = TEMPLATE_CACHE; $smarty->setPluginsDir(TEMPLATE_PLUGINS); //$smarty->plugins_dir = TEMPLATE_PLUGINS; $smarty->left_delimiter = '<{'; $smarty->right_delimiter = '}>'; self::$mTemplate = $smarty; } return self::$mTemplate; }
<?php require_once 'smarty/libs/Smarty.class.php'; require_once 'libs/medoo/defaultDb.php'; date_default_timezone_set("Asia/Shanghai"); $smarty = new Smarty(); //$smarty->force_compile = true; //$smarty->debugging = true; $smarty->caching = false; $smarty->cache_lifetime = 0; $smarty->left_delimiter = "{#"; $smarty->right_delimiter = "#}"; $smarty->setTemplateDir("./smarty/templates"); $smarty->setCacheDir("./smarty/cache"); $smarty->setConfigDir("./smarty/configs"); $smarty->setCompileDir("./smarty/templates_c"); $smarty->setPluginsDir("./smarty/plugins"); $base_path = "smarty/templates/"; $smarty->assign("base_path", $base_path);
<?php // PHP 是世界上最好的语言之一 date_default_timezone_set('Asia/Shanghai'); define('ROOT', dirname(__FILE__)); require ROOT . '/smarty/Smarty.class.php'; $MIMEType = array('bmp' => 'image/bmp', 'css' => 'text/css', 'doc' => 'application/msword', 'dtd' => 'text/xml', 'gif' => 'image/gif', 'hta' => 'application/hta', 'htc' => 'text/x-component', 'htm' => 'text/html', 'html' => 'text/html', 'xhtml' => 'text/html', 'ico' => 'image/x-icon', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'js' => 'text/javascript', 'json' => 'application/json', 'mocha' => 'text/javascript', 'mp3' => 'audio/mp3', 'mp4' => 'video/mpeg4', 'mpeg' => 'video/mpg', 'mpg' => 'video/mpg', 'manifest' => 'text/cache-manifest', 'pdf' => 'application/pdf', 'png' => 'image/png', 'ppt' => 'application/vnd.ms-powerpoint', 'rmvb' => 'application/vnd.rn-realmedia-vbr', 'rm' => 'application/vnd.rn-realmedia', 'rtf' => 'application/msword', 'svg' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'txt' => 'text/plain', 'vml' => 'text/xml', 'vxml' => 'text/xml', 'wav' => 'audio/wav', 'wma' => 'audio/x-ms-wma', 'wmv' => 'video/x-ms-wmv', 'woff' => 'image/woff', 'xml' => 'text/xml', 'xls' => 'application/vnd.ms-excel', 'xq' => 'text/xml', 'xql' => 'text/xml', 'xquery' => 'text/xml', 'xsd' => 'text/xml', 'xsl' => 'text/xml', 'xslt' => 'text/xml'); $uri = $_SERVER['REQUEST_URI']; $script = preg_replace('@\\?.*@', '', $uri); if (preg_match('@\\.([a-z]+)@i', $script, $m)) { $ext = $m[1]; if (isset($MIMEType[$ext])) { header('Content-Type: ' . $MIMEType[$ext]); } if (file_exists(ROOT . $script)) { echo file_get_contents(ROOT . $script); exit(0); } } $smarty = new Smarty(); $smarty->setPluginsDir(array(ROOT . '/plugin')); $smarty->setTemplateDir(ROOT . '/template'); $smarty->setCompileDir(ROOT . '/templates_c'); $smarty->setConfigDir(ROOT . '/config'); $smarty->display('page/index.tpl'); // 从 template_dir 下寻找
/** * @param $plugins_dir String Plugins directory to set */ public function setPluginsDir($plugins_dir) { $this->smarty->setPluginsDir($plugins_dir); }
<?php require_once "config_root.php"; require_once SMARTY_DIR . '/Smarty.class.php'; function minify_html($tpl_output, Smarty_Internal_Template $template) { $tpl_output = preg_replace('![\\t ]*[\\r\\n]+[\\t ]*!', '', $tpl_output); return $tpl_output; } $smarty = new Smarty(); $smarty->setPluginsDir(SMARTY_PLUGIN); $smarty->cache_dir = CACHE_SMARTY_DIR; $smarty->template_dir = TEMPLATE_DIR; $smarty->compile_dir = CACHE_SMARTY_COMPILE; $smarty->config_dir = CONFIG_DIR; if (COMPRESSED_FILES_MOD) { $smarty->registerFilter("output", "minify_html"); } $configRoot = array("root_url" => ROOT_URL, "root" => ROOT_DIR, "config" => CONFIG_DIR, "class" => CLASS_DIR, "smarty" => SMARTY_DIR, "smarty_sysplugins" => SMARTY_SYSPLUGINS_DIR, "smary_plugin" => SMARTY_PLUGIN, "cache" => CACHE_DIR, "cache_smarty" => CACHE_SMARTY_DIR, "cache_smarty_c" => CACHE_SMARTY_COMPILE, "template" => TEMPLATE_DIR, "img" => IMG_DIR, "js" => JS_DIR, "css" => CSS_DIR, "adm" => ADM_DIR); $configUrl = array("root_url" => ROOT_URL, "root" => ROOT_URL, "config" => ROOT_URL . CONFIG_DIR, "class" => ROOT_URL . CLASS_DIR, "smarty" => ROOT_URL . SMARTY_DIR, "smarty_sysplugins" => ROOT_URL . SMARTY_SYSPLUGINS_DIR, "smary_plugin" => ROOT_URL . SMARTY_PLUGIN, "cache" => ROOT_URL . CACHE_DIR, "cache_smarty" => ROOT_URL . CACHE_SMARTY_DIR, "cache_smarty_c" => ROOT_URL . CACHE_SMARTY_COMPILE, "template" => ROOT_URL . TEMPLATE_DIR, "img" => ROOT_URL . IMG_DIR, "js" => ROOT_URL . JS_DIR, "css" => ROOT_URL . CSS_DIR, "adm" => ROOT_URL . ADM_DIR); $configMod = array("dev" => DEV_MOD, "compressed_files" => COMPRESSED_FILES_MOD); $smarty->assign("url", $configUrl); $smarty->assign("dir", $configRoot); $smarty->assign("mod", $configMod);
<?php //Smarty PHP configuration date_default_timezone_set("PRC"); define('REAL_PATH', dirname(dirname(__FILE__))); require_once REAL_PATH . '/smarty/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setCacheDir(REAL_PATH . '\\cache'); $smarty->setConfigDir(REAL_PATH . '\\configs'); $smarty->setPluginsDir(REAL_PATH . '\\plugins'); $smarty->setTemplateDir(REAL_PATH . '\\tpl'); $smarty->setCompileDir(REAL_PATH . '\\templates_c'); //添加Smarty自带的插件库 $smarty->addPluginsDir(REAL_PATH . '\\smarty\\plugins'); //检测Smarty目录结构配置是否有效 // $smarty->testInstall();
} $languages[$i] = $languages[$i] . '.UTF-8'; } } } $current_lang = setlocale(LC_ALL, $languages); if (isset($_GET['mobile']) && $_GET['mobile']) { $theme = 'mobile'; } else { $theme = Config::$default_theme; } bindtextdomain('garmonbozia', $themesroot . $theme . '/locale/'); textdomain('garmonbozia'); $smarty = new \Smarty(); $smarty->setTemplateDir(array($themesroot . $theme . '/templates/', $themesroot . 'garmonbozia/templates/')); $smarty->setPluginsDir(array(SMARTY_DIR . '/plugins/', $themesroot . $theme . '/plugins/', $themesroot . 'garmonbozia/plugins/')); $smarty->setCompileDir($themesroot . $theme . '/templates_c/'); $smarty->setCacheDir($root . '/cache/'); $smarty->setConfigDir(array($themesroot . $theme . '/config/', $themesroot . 'garmonbozia/config/')); $current_lang = preg_replace('/.UTF-8/', '', $current_lang); $smarty->assign('lang_selector_array', array($current_lang => 1)); $smarty->assign('base_url', Config::$base_url); $smarty->assign('default_theme', Config::$default_theme); $smarty->assign('site_name', Config::$site_name); $smarty->assign('img_url', Config::$base_url . '/themes/' . $theme . '/img/'); $smarty->assign('this_page', $_SERVER['REQUEST_URI']); $smarty->assign('this_page_absolute', (empty($_SERVER['HTTPS']) ? 'http://' : 'http://') . (empty($_SERVER['HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HOST']) . ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']) . $_SERVER['REQUEST_URI']); if (isset($logged_in) && $logged_in) { $smarty->assign('logged_in', true); // Pre-fix this user's details with 'this_' to avoid confusion with other users $smarty->assign('this_user', $this_user);
/** * Opens a window for the Smarty Debugging Console and display the data * * @param Smarty_Internal_Template|Smarty $obj object to debug * @param bool $full */ public function display_debug($obj, $full = false) { if (!$full) { $this->offset++; $savedIndex = $this->index; $this->index = 9999; } if ($obj->_objType == 1) { $smarty = $obj; } else { $smarty = $obj->smarty; } // create fresh instance of smarty for displaying the debug console // to avoid problems if the application did overload the Smarty class $debObj = new Smarty(); // copy the working dirs from application $debObj->setCompileDir($smarty->getCompileDir()); // init properties by hand as user may have edited the original Smarty class $debObj->setPluginsDir(is_dir(__DIR__ . '/../plugins') ? __DIR__ . '/../plugins' : $smarty->getPluginsDir()); $debObj->force_compile = false; $debObj->compile_check = true; $debObj->left_delimiter = '{'; $debObj->right_delimiter = '}'; $debObj->security_policy = null; $debObj->debugging = false; $debObj->debugging_ctrl = 'NONE'; $debObj->error_reporting = E_ALL & ~E_NOTICE; $debObj->debug_tpl = isset($smarty->debug_tpl) ? $smarty->debug_tpl : 'file:' . __DIR__ . '/../debug.tpl'; $debObj->registered_plugins = array(); $debObj->registered_resources = array(); $debObj->registered_filters = array(); $debObj->autoload_filters = array(); $debObj->default_modifiers = array(); $debObj->escape_html = true; $debObj->caching = false; $debObj->compile_id = null; $debObj->cache_id = null; // prepare information of assigned variables $ptr = $this->get_debug_vars($obj); $_assigned_vars = $ptr->tpl_vars; ksort($_assigned_vars); $_config_vars = $ptr->config_vars; ksort($_config_vars); $debugging = $smarty->debugging; $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); if ($obj->_objType == 2) { $_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); } if ($obj->_objType == 1 || $full) { $_template->assign('template_data', $this->template_data[$this->index]); } else { $_template->assign('template_data', null); } $_template->assign('assigned_vars', $_assigned_vars); $_template->assign('config_vars', $_config_vars); $_template->assign('execution_time', microtime(true) - $smarty->start_time); $_template->assign('display_mode', $debugging == 2 || !$full); $_template->assign('offset', $this->offset * 50); echo $_template->fetch(); if (isset($full)) { $this->index--; } if (!$full) { $this->index = $savedIndex; } }
} $languages[$i] = $languages[$i] . '.UTF-8'; } } } $current_lang = setlocale(LC_ALL, $languages); if (isset($_GET['mobile']) && $_GET['mobile']) { $theme = 'mobile'; } else { $theme = $default_theme; } bindtextdomain('nixtape', $install_path . '/themes/' . $theme . '/locale/'); textdomain('nixtape'); $smarty = new Smarty(); $smarty->setTemplateDir(array($install_path . '/themes/' . $theme . '/templates/', $install_path . '/themes/thelist/templates/')); $smarty->setPluginsDir(array(SMARTY_DIR . '/plugins/', $install_path . '/themes/' . $theme . '/plugins/', $install_path . '/themes/thelist/plugins/')); $smarty->setCompileDir($install_path . '/themes/' . $theme . '/templates_c/'); $smarty->setCacheDir($install_path . '/cache/'); $smarty->setConfigDir(array($install_path . '/themes/' . $theme . '/config/', $install_path . '/themes/thelist/config/')); $current_lang = preg_replace('/.UTF-8/', '', $current_lang); $smarty->assign('casauth', $auth); if ($auth) { $casuid = phpCAS::getUser(); $smarty->assign('userid', phpCAS::getUser()); $attr = phpCAS::getAttributes(); $nickname = $attr['nickname']; $smarty->assign('handle', $nickname); $user = new User($casuid); $userid = $user->id; $makerid = $user->makerid; $smarty->assign('makerid', $makerid);
<?php //Smarty PHP configuration define('REAL_PATH', dirname(__FILE__)); require REAL_PATH . '/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->setCacheDir(REAL_PATH . '/cache'); $smarty->setConfigDir(REAL_PATH . '/configs'); $smarty->setPluginsDir(REAL_PATH . '/libs/plugins'); $smarty->setTemplateDir(REAL_PATH . '/templates'); $smarty->setCompileDir(REAL_PATH . '/templates_c'); //添加Smarty自带的插件库 $smarty->addPluginsDir(REAL_PATH . '/libs/plugins'); //检测Smarty目录结构配置是否有效 // $smarty->testInstall();