/** * Constructor * * Please do not call directly. Use Template::construct_template(). * * @param string $template_id the template ID * */ function Smarty_Template($template_id) { //FIXME: find a way to test that this is ONLY ever called // from parent's construct_template() method (I doubt it // is worth the trouble to parse the current stack trace) // if (???) // trigger_error('Please do not use default Smarty_Template() constructor. Instead, use Template::construct_template().', E_USER_ERROR); parent::Template($template_id); // load smarty settings // // instantiate and set up Smarty object // $smarty_path = Template::get_template_config($this->template_set_id, 'smarty_path'); require $smarty_path; $this->smarty_template = new Smarty(); $this->smarty_template->compile_dir = Template::get_template_config($this->template_set_id, 'smarty_compile_dir'); $this->smarty_template->cache_dir = Template::get_template_config($this->template_set_id, 'smarty_cache_dir'); $this->smarty_template->config_dir = Template::get_template_config($this->template_set_id, 'smarty_config_dir'); // note that we do not use Smarty's template_dir // because SquirrelMail has its own method of // determining template file paths // //$this->smarty_template->template_dir = }
/** * Traverse template hierarchy and catalogue all template * files (for storing in cache). * * Paths to all files in all parent, grand-parent, great grand * parent, etc. template sets (including the fallback template) * are catalogued; for identically named files, the file earlier * in the hierarchy (closest to this template set) is used. * * Refuses to traverse directories called ".svn" * * @param string $template_set_id The template set in which to * search for files * @param array $file_list The file list so far to be added * to (allows recursive behavior) * (optional; default empty array). * @param string $directory The directory in which to search for * files (must be given as full path). * If empty, starts at top-level template * set directory (optional; default empty). * NOTE! Use with care, as behavior is * unpredictable if directory given is not * part of correct template set. * * @return mixed The top-level caller will have an array of template * files returned to it; recursive calls to this function * do not receive any return value at all. The format * of the template file array is as described for the * Template class attribute $template_file_cache * * @static * */ function catalog_template_files($template_set_id, $file_list = array(), $directory = '') { $template_base_dir = SM_PATH . Template::calculate_template_file_directory($template_set_id); if (empty($directory)) { $directory = $template_base_dir; } // bail if we have been asked to traverse a Subversion directory // if (strpos($directory, '/.svn') === strlen($directory) - 5) { return $file_list; } $files_and_dirs = list_files($directory, '', FALSE, TRUE, FALSE, TRUE); // recurse for all the subdirectories in the template set // foreach ($files_and_dirs['DIRECTORIES'] as $dir) { $file_list = Template::catalog_template_files($template_set_id, $file_list, $dir); } // place all found files in the cache // FIXME: assuming PHP template engine may not necessarily be a good thing // $engine = Template::get_template_config($template_set_id, 'template_engine', SQ_PHP_TEMPLATE); foreach ($files_and_dirs['FILES'] as $file) { // remove the part of the file path corresponding to the // template set's base directory // $relative_file = substr($file, strlen($template_base_dir)); /** * only put file in cache if not already found in earlier template * PATH should be relative to SquirrelMail top directory */ if (!isset($file_list[$relative_file])) { $file_list[$relative_file] = array('PATH' => substr($file, strlen(SM_PATH)), 'SET_ID' => $template_set_id, 'ENGINE' => $engine); } } // now if we are currently at the top-level of the template // set base directory, we need to move on to the parent // template set, if any // if ($directory == $template_base_dir) { // use fallback when we run out of parents // $fallback_id = Template::get_fallback_template_set(); $parent_id = Template::get_template_config($template_set_id, 'parent_template_set', $fallback_id); // were we already all the way to the last level? just exit // // note that this code allows the fallback set to have // a parent, too, but can result in endless loops // if ($parent_id == $template_set_id) { // if ($fallback_id == $template_set_id) { return $file_list; } $file_list = Template::catalog_template_files($parent_id, $file_list); } return $file_list; }