set_up_template($template_id); } /** * Construct Template * * This method should always be called instead of trying * to get a Template object from the normal/default constructor, * and is necessary in order to control the return value. * * @param string $template_id the template ID * * @return object The correct Template object for the given template set * */ function construct_template($template_id) { $template = new Template($template_id); return $template->get_template_engine_subclass(); } /** * Set up internal attributes * * This method does most of the work for setting up * newly constructed objects. * * @param string $template_id the template ID * */ function set_up_template($template_id) { // FIXME: do we want to place any restrictions on the ID like // making sure no slashes included? // get template ID // $this->template_id = $template_id; // FIXME: do we want to place any restrictions on the ID like // making sure no slashes included? // get default template ID // global $templateset_default, $aTemplateSet; $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) ? array() : $aTemplateSet); $templateset_default = (!isset($templateset_default) ? 0 : $templateset_default); $this->default_template_id = (!empty($aTemplateSet[$templateset_default]['ID']) ? $aTemplateSet[$templateset_default]['ID'] : 'default'); // set up template directories // $this->template_dir = Template::calculate_template_file_directory($this->template_id); $this->default_template_dir = Template::calculate_template_file_directory($this->default_template_id); // pull in the template config file and load javascript and // css files needed for this template set // $template_config_file = SM_PATH . $this->get_template_file_directory() . 'config.php'; if (!file_exists($template_config_file)) { trigger_error('No template configuration file was found where expected: ("' . $template_config_file . '")', E_USER_ERROR); } else { require($template_config_file); $this->required_js_files = is_array($required_js_files) ? $required_js_files : array(); } // determine template engine // if (empty($template_engine)) { trigger_error('No template engine ($template_engine) was specified in template configuration file: ("' . $template_config_file . '")', E_USER_ERROR); } else { $this->template_engine = $template_engine; } } /** * Instantiate and return correct subclass for this template * set's templating engine. * * @return object The Template subclass object for the template engine. * */ function get_template_engine_subclass() { $engine_class_file = SM_PATH . 'class/template/' . $this->template_engine . 'Template.class.php'; if (!file_exists($engine_class_file)) { trigger_error('Unknown template engine (' . $this->template_engine . ') was specified in template configuration file', E_USER_ERROR); } $engine_class = $this->template_engine . 'Template'; require($engine_class_file); return new $engine_class($this->template_id); } /** * Determine the relative template directory path for * the given template ID. * * @param string $template_id The template ID from which to build * the directory path * * @return string The relative template path (based off of SM_PATH) * */ function calculate_template_file_directory($template_id) { return 'templates/' . $template_id . '/'; } /** * Determine the relative images directory path for * the given template ID. * * @param string $template_id The template ID from which to build * the directory path * * @return string The relative images path (based off of SM_PATH) * */ function calculate_template_images_directory($template_id) { return 'templates/' . $template_id . '/images/'; } /** * Return the relative template directory path for this template set. * * @return string The relative path to the template directory based * from the main SquirrelMail directory (SM_PATH). * */ function get_template_file_directory() { return $this->template_dir; } /** * Return the relative template directory path for the DEFAULT template set. * * @return string The relative path to the default template directory based * from the main SquirrelMail directory (SM_PATH). * */ function get_default_template_file_directory() { return $this->default_template_dir; } /** * Find the right template file. * * Templates are expected to be found in the template set directory, * for example: * SM_PATH/templates/