/** * Initialise Twig * * @return void */ protected function initTemplateEngine() { $this->loader = new \Smarty(); $this->loader->muteExpectedErrors(); $this->loader->setTemplateDir($this->getTemplateDir()); $this->loader->addPluginsDir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'SmartyPlugins'); $this->initSmartyCache(); Logger::debug("Smarty Cache: " . $this->loader->getCacheDir()); }
public static function run($action) { ConfigurationChecks::loadChecks(); ConfigurationChecks::performChecks(); $smarty = new Smarty(); $smarty->muteExpectedErrors(); $smarty->setCacheDir(SYSTEM_ROOT . '/classes/smarty/cache/'); $smarty->setCompileDir(SYSTEM_ROOT . '/classes/smarty/templates_c/'); $smarty->setTemplateDir(SYSTEM_ROOT . '/install/view/'); $smarty->caching = Smarty::CACHING_OFF; $smarty->force_compile = true; $smarty->assign('title', 'Installation'); switch ($action) { case 'tables': self::insertTables($smarty); break; case 'user': self::createUser($smarty); break; case 'success': self::success($smarty); break; default: self::checkRequirements($smarty); break; } }
protected function _muteErrors() { if ($this->nMuteErrorsCnt <= 0) { $this->oSmarty->muteExpectedErrors(); $this->nMuteErrorsCnt++; } }
/** * populate Source Object with timestamp and exists from Resource * * @param Smarty_Template_Source $source source object * @return void */ public function populateTimestamp(Smarty_Template_Source $source) { Smarty::muteExpectedErrors(); $source->timestamp = @filemtime($source->filepath); Smarty::unmuteExpectedErrors(); $source->exists = !!$source->timestamp; }
/** * populate Cached Object with timestamp and exists from Resource * * @param Smarty_Template_Cached $cached cached object * @return void */ public function populateTimestamp(Smarty_Template_Cached $cached) { Smarty::muteExpectedErrors(); $cached->timestamp = @filemtime($cached->filepath); Smarty::unmuteExpectedErrors(); $cached->exists = !!$cached->timestamp; }
public function render(string $path, array $attributes) : string { $smarty = new \Smarty(); $smarty->setCompileDir($this->tempPath . "/smarty/templates_c/")->setCacheDir($this->tempPath . "/smarty/cache/")->error_reporting = E_ALL & ~E_NOTICE; \Smarty::muteExpectedErrors(); $smarty->assign($attributes); $result = $smarty->fetch($path); return $result; }
public function __construct() { ob_start(); $logErrors = (new Config())->get('dev'); if ($logErrors) { set_error_handler(function ($errNo, $errStr, $errFile, $errLine) { self::addError("{$errStr} occurred on {$errFile}:{$errLine}"); }); set_exception_handler(function ($exception) { self::addError($exception->__toString()); }); \Smarty::muteExpectedErrors(); } }
public function testMutedCaching() { $this->_errors = array(); set_error_handler(array($this, 'error_handler')); Smarty::muteExpectedErrors(); $this->smarty->caching = true; $this->smarty->clearCache('default.tpl'); $this->smarty->clearCompiledTemplate('default.tpl'); $this->smarty->fetch('default.tpl'); $this->assertEquals($this->_errors, array()); @filemtime('ckxladanwijicajscaslyxck'); $error = array(__FILE__ . ' line ' . (__LINE__ - 1)); $this->assertEquals($error, $this->_errors); Smarty::unmuteExpectedErrors(); restore_error_handler(); }
/** * @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; }
public static function run($action = '') { $smarty = new Smarty(); $smarty->muteExpectedErrors(); $smarty->setCacheDir(SYSTEM_ROOT . '/classes/smarty/cache/'); $smarty->setCompileDir(SYSTEM_ROOT . '/classes/smarty/templates_c/'); $smarty->setTemplateDir(SYSTEM_ROOT . '/upgrade/view/'); $smarty->caching = Smarty::CACHING_OFF; $smarty->force_compile = true; $smarty->assign('title', 'Upgrade'); switch ($action) { case 'success': self::success($smarty); break; default: self::selectUpgrade($smarty); break; } }
public function __construct() { parent::__construct(); // Store the Codeigniter super global instance... whatever $CI = get_instance(); // Load the Smarty config file $CI->load->config('smarty'); // Turn on/off debug $this->debugging = $CI->config->item('smarty.smarty_debug'); // Set some pretty standard Smarty directories $this->setCompileDir($CI->config->item('smarty.compile_directory')); $this->setCacheDir($CI->config->item('smarty.cache_directory')); $this->setConfigDir($CI->config->item('smarty.config_directory')); // Default template extension $this->template_ext = $CI->config->item('smarty.template_ext'); // How long to cache templates for $this->cache_lifetime = $CI->config->item('smarty.cache_lifetime'); // Disable Smarty security policy $this->disableSecurity(); // If caching is enabled, then disable force compile and enable cache if ($CI->config->item('smarty.cache_status') === TRUE) { $this->enable_caching(); } else { $this->disable_caching(); } // Set the error reporting level $this->error_reporting = $CI->config->item('smarty.template_error_reporting'); // This will fix various issues like filemtime errors that some people experience // The cause of this is most likely setting the error_reporting value above // This is a static function in the main Smarty class Smarty::muteExpectedErrors(); // Should let us access Codeigniter stuff in views // This means we can go for example {$this->session->userdata('item')} // just like we normally would in standard CI views $this->assign("this", $CI); }
function __construct($path) { $this->path = $path; Gongo_Locator::load($this->libraryPath, 'Smarty'); Smarty::muteExpectedErrors(); }
/** * get a Compiled Object of this source * * @param Smarty_Internal_Template $_template template objet * @return Smarty_Template_Compiled compiled object */ public function getCompiled(Smarty_Internal_Template $_template) { // check runtime cache $_cache_key_dir = join(DIRECTORY_SEPARATOR, $_template->smarty->getTemplateDir()); $_cache_key = $_template->template_resource . '#' . $_template->compile_id; if (!isset(Smarty_Resource::$compileds[$_cache_key_dir])) { Smarty_Resource::$compileds[$_cache_key_dir] = array(); } if (isset(Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key])) { return Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key]; } $compiled = new Smarty_Template_Compiled($this); $this->handler->populateCompiledFilepath($compiled, $_template); Smarty::muteExpectedErrors(); $compiled->timestamp = @filemtime($compiled->filepath); Smarty::unmuteExpectedErrors(); $compiled->exists = !!$compiled->timestamp; // runtime cache Smarty_Resource::$compileds[$_cache_key_dir][$_cache_key] = $compiled; return $compiled; }
private function _parse($pid) { $tpl = new Template(); $template = $tpl->getTemplateDefinitionByPageId($pid); if ((int) $template->templatetype != 1) { throw $this->throwException(7008); } $_SESSION['language'] = 'tpl'; $page = new Page(); $opage = $page->getPageById($pid, false, true); $tn = new OTreeNode(); $tn->page = $opage; $tname = $template->itemtype; if (!file_exists(BASEPATH . '/bright/site/views/' . $tname . 'View.php')) { throw $this->throwException(7010, array($tname . 'View')); } // include_once('views/' . $tname . 'View.php'); $viewclass = $tname . 'View'; $view = new $viewclass($tn); // Simplify page for parsing // @deprecated Should not be used anymore foreach ($opage->content as $cfield => $value) { $opage->{$cfield} = $value; } $deactivationlink = BASEURL . 'bright/'; if (defined('USEACTIONDIR') && USEACTIONDIR) { $deactivationlink .= 'actions/'; } $deactivationlink .= 'registration.php?action=deactivate&email={email}&code={code}'; $view->deactivationlink = $deactivationlink; define('DEACTIVATIONLINK', $deactivationlink); if (method_exists($view, 'parseTemplate')) { // Bright parser $parsed = $view->parseTemplate($view, $template->itemtype); } else { // Smarty parser \Smarty::muteExpectedErrors(); $parsed = $view->output(); \Smarty::unmuteExpectedErrors(); } $parsed = preg_replace_callback('/<img([^>]*)src="\\/([^"]*)"([^>]*)\\/>/ism', array($this, '_replaceImage'), $parsed); $result = new \stdClass(); $result->page = $opage; $result->parsed = $parsed; return $result; }
/** * Empty cache for a specific template * * @param string $template_name template name * @param string $cache_id cache id * @param string $compile_id compile id * @param integer $exp_time expiration time * @param string $type resource type * @return integer number of cache files deleted */ public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) { Smarty::muteExpectedErrors(); // load cache resource and call clear $_cache_resource = Smarty_CacheResource::load($this, $type); Smarty_CacheResource::invalidLoadedCache($this); $t = $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time); Smarty::unmuteExpectedErrors(); return $t; }
/** * Constructor. * * @param \Smarty $smarty A \Smarty instance * @param TemplateLocator $locator A TemplateLocator instance * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance * @param LoaderInterface $loader A LoaderInterface instance * @param array $options An array of \Smarty properties * @param GlobalVariables|null $globals A GlobalVariables instance or null * @param LoggerInterface|null $logger A LoggerInterface instance or null */ public function __construct(\Smarty $smarty, TemplateLocator $locator, TemplateNameParserInterface $parser, LoaderInterface $loader, array $options = array(), GlobalVariables $globals = null, LoggerInterface $logger = null) { $this->smarty = $smarty; $this->locator = $locator; $this->parser = $parser; $this->loader = $loader; $this->globals = array(); $this->logger = null; // There are no default extensions. $this->extensions = array(); /* * Register an handler for 'logical' filenames of the type: * <code>file:Application:index:index.html.smarty</code> */ $this->smarty->default_template_handler_func = array($this, 'smartyDefaultTemplateHandler'); /* * Define a set of template dirs to look for. This will allow the * usage of the following syntax: * <code>file:[Application]/index/index.html.tpl</code> * * See {@link http://www.smarty.net/docs/en/resources.tpl} for details */ $this->smarty->setTemplateDir($this->locator->getAppPath()); $this->smarty->addTemplateDir($this->locator->getModulesPath()); foreach ($options as $property => $value) { $this->smarty->{$this->smartyPropertyToSetter($property)}($value); } if (null !== $globals) { $this->addGlobal('app', $globals); } /* * @note muteExpectedErrors() was activated to workaround the following issue: * * <code>Warning: filemtime(): stat failed for /path/to/smarty/cache/3ab50a623e65185c49bf17c63c90cc56070ea85c.one.tpl.php * in /path/to/smarty/libs/sysplugins/smarty_resource.php</code> * * This means that your application registered a custom error hander * (using set_error_handler()) which is not respecting the given $errno * as it should. If, for whatever reason, this is the desired behaviour * of your custom error handler, please call muteExpectedErrors() after * you've registered your custom error handler. * * muteExpectedErrors() registers a custom error handler using * set_error_handler(). The error handler merely inspects $errno and * $errfile to determine if the given error was produced deliberately * and must be ignored, or should be passed on to the next error handler. */ $smarty->muteExpectedErrors(); }
include_once $thisSite->DOS_BASE_LIB . "mobile_detect.php"; $Mobile_Detect = new Mobile_Detect(); } // Initialisation Smarty include_once $thisSite->DOS_BASE_LIB . "Smarty/libs/" . "Smarty.class.php"; $smarty = new Smarty(); $smarty->setTemplateDir($racine_smarty . "smarty/templates/"); $smarty->setCompileDir($racine_smarty . "smarty/templates_c/"); $smarty->setCacheDir($racine_smarty . "smarty/cache/"); $smarty->caching = $thisSite->SMARTY_CACHING; $smarty->cache_lifetime = $thisSite->CACHE_LIFETIME; $smarty->compile_check = FALSE; $smarty->force_compile = TRUE; $smarty->debugging = FALSE; $smarty->error_reporting = E_ALL & ~E_NOTICE; $smarty->muteExpectedErrors(); // // Traitement des GET et POST $__GET = array(); $__POST = array(); if (isset($_GET)) { foreach ($_GET as $k => $v) { $__GET[$k] = ctr_global($v, "strip_tags"); } } if (isset($_POST)) { foreach ($_POST as $k => $v) { $__POST[$k] = ctr_global($v); } } $smarty->assign("__GET", $__GET);
@file_put_contents(RUNTIME_PATH . '/install.write', 'install.write'); if ('install.write' != @file_get_contents(RUNTIME_PATH . '/install.write')) { die('错误:[' . RUNTIME_PATH . ']必须有读写权限'); } unlink(RUNTIME_PATH . '/install.write'); // ---------------------------------------- 3. 开启系统日志 -------------------------------------- // 设置一个 fileLogger 方便查看所有的日志输出 $fileLogger = new \Core\Log\File('install.log'); $logger->addLogger($fileLogger); unset($fileLogger); /* * **************** 如果是调试模式,在这里设置调试 ************************ */ if ($f3->get('DEBUG')) { // 调试模式,关闭缓存 $f3->set('CACHE', false); // 把 smarty 的一些错误警告关闭,不然会影响我们的调试 Smarty::muteExpectedErrors(); // 使用自定义的调试框架 if ($f3->get('USERDEBUG')) { require_once PROTECTED_PATH . '/Framework/Debug/BzfDebug.php'; // 开启 debug 功能 BzfDebug::enableDebug(); // 开启 Smarty Web Log BzfDebug::enableSmartyWebLog(); } } // ---------------------------------------- 4. 设置工程环境 -------------------------------------- // 设置代码路径 \Core\Plugin\SystemHelper::addAutoloadPath(INSTALL_PATH . '/Code', true); // 设置路由,这样用户就能访问到我们的程序了 $f3->config(INSTALL_PATH . '/route.cfg'); // 增加 smarty 模板搜索路径
public function boot() { \Smarty::muteExpectedErrors(); }