[ Index ] |
PHP Cross Reference of Eventum |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */ 3 // +----------------------------------------------------------------------+ 4 // | Eventum - Issue Tracking System | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB | 7 // | | 8 // | This program is free software; you can redistribute it and/or modify | 9 // | it under the terms of the GNU General Public License as published by | 10 // | the Free Software Foundation; either version 2 of the License, or | 11 // | (at your option) any later version. | 12 // | | 13 // | This program is distributed in the hope that it will be useful, | 14 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 // | GNU General Public License for more details. | 17 // | | 18 // | You should have received a copy of the GNU General Public License | 19 // | along with this program; if not, write to: | 20 // | | 21 // | Free Software Foundation, Inc. | 22 // | 59 Temple Place - Suite 330 | 23 // | Boston, MA 02111-1307, USA. | 24 // +----------------------------------------------------------------------+ 25 // | Authors: João Prado Maia <jpm@mysql.com> | 26 // +----------------------------------------------------------------------+ 27 // 28 // @(#) $Id: class.template.php 3474 2007-11-15 07:38:43Z balsdorf $ 29 // 30 31 require_once(APP_PEAR_PATH . "Net/UserAgent/Detect.php"); 32 require_once(APP_SMARTY_PATH . "Smarty.class.php"); 33 require_once (APP_INC_PATH . "class.project.php"); 34 require_once (APP_INC_PATH . "class.auth.php"); 35 require_once (APP_INC_PATH . "class.user.php"); 36 require_once (APP_INC_PATH . "class.setup.php"); 37 require_once (APP_INC_PATH . "class.link_filter.php"); 38 require_once (APP_INC_PATH . "class.custom_field.php"); 39 40 /** 41 * Class used to abstract the backend template system used by the site. This 42 * is especially useful to be able to change template backends in the future 43 * without having to rewrite all PHP based scripts. 44 * 45 * @version 1.0 46 * @author João Prado Maia <jpm@mysql.com> 47 */ 48 49 class Template_API 50 { 51 var $smarty; 52 var $tpl_name = ""; 53 54 /** 55 * Constructor of the class 56 * 57 * @access public 58 */ 59 function Template_API() 60 { 61 $this->smarty = new Smarty; 62 $this->smarty->template_dir = APP_TPL_PATH; 63 $this->smarty->compile_dir = APP_TPL_COMPILE_PATH; 64 $this->smarty->config_dir = ''; 65 $this->smarty->register_modifier("activateLinks", array('Link_Filter', 'activateLinks')); 66 $this->smarty->register_modifier("formatCustomValue", array('Custom_Field', 'formatValue')); 67 } 68 69 70 /** 71 * Sets the internal template filename for the current PHP script 72 * 73 * @access public 74 * @param string $tpl_name The filename of the template 75 */ 76 function setTemplate($tpl_name) 77 { 78 $this->tpl_name = $tpl_name; 79 } 80 81 82 /** 83 * Assigns variables to specific placeholders on the target template 84 * 85 * @access public 86 * @param string $var_name Placeholder on the template 87 * @param string $value Value to be assigned to this placeholder 88 */ 89 function assign($var_name, $value = "") 90 { 91 if (!is_array($var_name)) { 92 $this->smarty->assign($var_name, $value); 93 } else { 94 $this->smarty->assign($var_name); 95 } 96 } 97 98 99 /** 100 * Assigns variables to specific placeholders on the target template 101 * 102 * @access public 103 * @param array $array Array with the PLACEHOLDER=>VALUE pairs to be assigned 104 */ 105 function bulkAssign($array) 106 { 107 while (list($key, $value) = each($array)) { 108 $this->smarty->assign($key, $value); 109 } 110 } 111 112 113 /** 114 * Prints the actual parsed template. 115 * 116 * @access public 117 */ 118 function displayTemplate() 119 { 120 if (APP_BENCHMARK) { 121 // stop the benchmarking 122 $GLOBALS["bench"]->stop(); 123 $profiling = $GLOBALS["bench"]->getProfiling(); 124 // last minute check on the benchmarking results 125 $this->assign(array("benchmark_total" => sprintf("%.4f", $profiling[count($profiling)-1]["total"]), 126 "benchmark_results" => base64_encode(serialize($profiling)))); 127 } 128 $this->processTemplate(); 129 // finally display the parsed template 130 $this->smarty->display($this->tpl_name); 131 } 132 133 134 /** 135 * Returns the contents of the parsed template 136 * 137 * @access public 138 * @return string The contents of the parsed template 139 */ 140 function getTemplateContents() 141 { 142 $this->processTemplate(); 143 return $this->smarty->fetch($this->tpl_name); 144 } 145 146 147 /** 148 * Processes the template and assigns common variables automatically. 149 * 150 * @access private 151 */ 152 function processTemplate() 153 { 154 // determine the correct CSS file to use 155 if (ereg('MSIE ([0-9].[0-9]{1,2})', @$_SERVER["HTTP_USER_AGENT"], $log_version)) { 156 $user_agent = 'ie'; 157 } else { 158 $user_agent = 'other'; 159 } 160 $this->assign("user_agent", $user_agent); 161 // create the list of projects 162 $usr_id = Auth::getUserID(); 163 if ($usr_id != '') { 164 $prj_id = Auth::getCurrentProject(); 165 if (!empty($prj_id)) { 166 $role_id = User::getRoleByUser($usr_id, $prj_id); 167 $this->assign("current_project", $prj_id); 168 $this->assign("current_project_name", Auth::getCurrentProjectName()); 169 $has_customer_integration = Customer::hasCustomerIntegration($prj_id); 170 $this->assign("has_customer_integration", $has_customer_integration); 171 if ($has_customer_integration) { 172 $this->assign("customer_backend_name", Customer::getBackendImplementationName($prj_id)); 173 } 174 if (($role_id == User::getRoleID('administrator')) || ($role_id == User::getRoleID('manager'))) { 175 $this->assign("show_admin_link", true); 176 } 177 if ($role_id > 0) { 178 $this->assign("current_role", (integer) $role_id); 179 $this->assign("current_role_name", User::getRole($role_id)); 180 } 181 } 182 $info = User::getNameEmail($usr_id); 183 $this->assign("active_projects", Project::getAssocList($usr_id)); 184 $this->assign("current_full_name", $info["usr_full_name"]); 185 $this->assign("current_email", $info["usr_email"]); 186 $this->assign("current_user_id", $usr_id); 187 $this->assign("is_current_user_clocked_in", User::isClockedIn($usr_id)); 188 $this->assign("roles", User::getAssocRoleIDs()); 189 } 190 $this->assign('app_path', APP_PATH); 191 $this->assign("app_setup", Setup::load()); 192 $this->assign("app_config_path", APP_CONFIG_PATH); 193 $this->assign("app_setup_file", APP_SETUP_FILE); 194 195 $this->assign("application_version", APP_VERSION); 196 $this->assign("application_title", APP_NAME); 197 $this->assign("app_base_url", APP_BASE_URL); 198 $this->assign("rel_url", APP_RELATIVE_URL); 199 200 // now for the browser detection stuff 201 Net_UserAgent_Detect::detect(); 202 $this->assign("browser", Net_UserAgent_Detect::_getStaticProperty('browser')); 203 $this->assign("os", Net_UserAgent_Detect::_getStaticProperty('os')); 204 205 // this is only used by the textarea resize script 206 $js_script_name = str_replace('/', '_', str_replace('.php', '', $_SERVER['PHP_SELF'])); 207 $this->assign("js_script_name", $js_script_name); 208 209 $this->assign("total_queries", $GLOBALS['TOTAL_QUERIES']); 210 211 $this->assign(array( 212 "cell_color" => APP_CELL_COLOR, 213 "light_color" => APP_LIGHT_COLOR, 214 "middle_color" => APP_MIDDLE_COLOR, 215 "dark_color" => APP_DARK_COLOR, 216 "cycle" => APP_CYCLE_COLORS, 217 "internal_color" => APP_INTERNAL_COLOR 218 )); 219 } 220 } 221 222 // benchmarking the included file (aka setup time) 223 if (APP_BENCHMARK) { 224 $GLOBALS['bench']->setMarker('Included Template Class'); 225 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 19 21:21:33 2007 | Cross-referenced by PHPXref 0.7 |