/** * Initialize Smarty * * @param Project $project * @param Theme $theme * @return Smarty * @throws TempNotFoundError * @throws \SmartyException */ public static function &initSmarty(Project &$project, Theme $theme) { if (self::$smarty === false) { self::$smarty = new Smarty(); $temp_path = $project->getTempPath(); if (is_dir($temp_path)) { self::$smarty->setCompileDir($temp_path); } else { throw new TempNotFoundError($temp_path); } self::$smarty->setTemplateDir($theme->getPath() . '/templates'); self::$smarty->compile_check = true; self::$smarty->left_delimiter = '<{'; self::$smarty->right_delimiter = '}>'; self::$smarty->registerFilter('variable', '\\ActiveCollab\\Shade::clean'); // {$foo nofilter} $helper_class = new ReflectionClass('\\ActiveCollab\\Shade\\SmartyHelpers'); foreach ($helper_class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC) as $method) { $method_name = $method->getName(); if (substr($method_name, 0, 6) === 'block_') { self::$smarty->registerPlugin('block', substr($method_name, 6), ['\\ActiveCollab\\Shade\\SmartyHelpers', $method_name]); } elseif (substr($method_name, 0, 9) === 'function_') { self::$smarty->registerPlugin('function', substr($method_name, 9), ['\\ActiveCollab\\Shade\\SmartyHelpers', $method_name]); } } SmartyHelpers::setDefaultLocale($project->getDefaultLocale()); self::$smarty->assign(['project' => $project, 'default_locale' => $project->getDefaultLocale(), 'copyright' => $project->getConfigurationOption('copyright', '--UNKNOWN--'), 'copyright_since' => $project->getConfigurationOption('copyright_since'), 'page_level' => 0, 'plugins' => self::getPlugins($project)]); } return self::$smarty; }