[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /* 3 * phpMyVisites : website statistics and audience measurements 4 * Copyright (C) 2002 - 2006 5 * http://www.phpmyvisites.net/ 6 * phpMyVisites is free software (license GNU/GPL) 7 * Authors : phpMyVisites team 8 */ 9 10 // $Id: TemplateEngine.php 216 2007-05-04 15:34:17Z matthieu_ $ 11 12 require_once INCLUDE_PATH."/libs/smarty/Smarty.class.php"; 13 require_once INCLUDE_PATH . "/core/include/PdfConfigDb.class.php"; 14 15 class TemplateEngine extends Smarty 16 { 17 /** 18 * central zone template name 19 * 20 * @var string template 21 */ 22 var $template; 23 24 /** 25 * main template name 26 * 27 * @var string mainTemplate 28 */ 29 var $mainTemplate = 'common/structure.tpl'; 30 31 32 33 /** 34 * Constructor 35 * initialize the smarty template engine 36 * 37 * @param string template 38 */ 39 function TemplateEngine($template, $p_theme = THEME_DEFAULT) 40 { 41 42 if( !defined('THEME') ) 43 { 44 //define('THEME', THEME_DEFAULT); 45 define('THEME', $p_theme); 46 } 47 $templateSet = THEME; 48 49 parent::Smarty(); 50 51 $this->template_dir = array (INCLUDE_PATH .'/themes/' . $templateSet .'/', INCLUDE_PATH .'/themes/'.THEME_DEFAULT.'/', PLUGINS_PATH); 52 $this->compile_dir = INCLUDE_PATH .'/datas/tpl_compiled/'; 53 $this->cache_dir = INCLUDE_PATH .'/datas/cache_smarty/'; 54 $this->config_dir =INCLUDE_PATH .'/themes/' . $templateSet .'/smarty_config/'; 55 $this->plugins_dir = array( INCLUDE_PATH . '/libs/smarty/plugins', INCLUDE_PATH . '/core/include/smarty_plugins'); 56 $this->cache_lifetime = CACHE_SMARTY; 57 $this->compile_id = $templateSet . PHPMV_VERSION . INTERNAL_STATS; 58 59 if (defined('SMARTY_DEBUG') && SMARTY_DEBUG) 60 { 61 $this->caching = 0; 62 $this->force_compile = 1; 63 $this->compile_check = 1; 64 } 65 else 66 { 67 $this->caching = 1; 68 $this->force_compile = 0; 69 $this->compile_check = 0; 70 $this->load_filter('output','trimwhitespace'); 71 } 72 73 $this->clear_all_cache( CACHE_SMARTY ); 74 75 if(mt_rand(0, 5000) === 0) 76 { 77 $this->clear_all_cache(); 78 } 79 80 $this->setTemplate($template); 81 } 82 83 /** 84 * define the central zone template name 85 * 86 * @param string templatename 87 * 88 * @return void 89 */ 90 function setTemplate($templateName) 91 { 92 $this->template = $templateName; 93 } 94 95 /** 96 * Define main template name 97 * 98 * @param string mainTplName 99 * @return void 100 */ 101 function setMainTemplate($mainTplName) 102 { 103 $this->mainTemplate = $mainTplName; 104 } 105 106 /** 107 * Big job, assign all vars... 108 * Too much vars, those tasks should be splitted into more atomic methods 109 * 110 * @param object o_site 111 * @param object o_data 112 * @param object request 113 * 114 * @return void 115 */ 116 function processDatas( &$o_site, &$o_data, $request = null) 117 { 118 $ctrl =& ApplicationController::getInstance(); 119 120 if (is_null($request)) 121 { 122 $o_request =& $ctrl->getRequest(); 123 } 124 else 125 { 126 $o_request =& $request; 127 } 128 129 $o_lang =& $ctrl->getLang(); 130 131 if(!is_a($o_data, "DataModel")) 132 { 133 //trigger_error("\$o_data is not an object DataModel! Maybe its because this is not a 134 //ViewModule and so you don't really need DataModel, you have to do without it..."); 135 } 136 printTime('Begin Smarty display'); 137 138 /* 139 * @todo , extact this from method!! 140 */ 141 $ajax_views = array( 142 "common/data_array_details.tpl", 143 "common/data_array_interest.tpl", 144 "common/data_array.tpl" 145 ); 146 147 // Add path to theme 148 $this->assign("PMV_THEME", $this->template_dir[0]); 149 $this->assign("PMV_THEME_DEFAULT", $this->template_dir[1]); 150 $this->assign("PMV_STAT_ID_SITE", PMV_STAT_ID_SITE); 151 $this->assign("PMV_STAT_SAVE_USER", PMV_STAT_SAVE_USER); 152 153 // case we load a subtemplate with AJAX 154 if(in_array($this->template, $ajax_views)) 155 { 156 $this->mainTemplate = $this->template; 157 } 158 // case we load a pages zoomed group with AJAX 159 elseif($o_request->isCategoryZoom()) 160 { 161 $this->mainTemplate = "common/viewpages_details.tpl"; 162 // printDebug($this->get_template_vars( "zoom")); 163 $t = $this->get_template_vars( "zoomsorted"); 164 //printDebug($t); 165 $this->assign("zoom", $t); 166 } 167 else 168 { 169 // case there are no visit for this period 170 if(is_a($o_data, "DataModel") 171 && $o_request->getModuleName() !== 'view_sites_summary' 172 && $o_data->getContent('nb_vis') == 0) 173 { 174 $this->setTemplate("common/error.tpl"); 175 if($o_request->getModuleName() !== 'view_visits_rss' ) 176 { 177 $this->assign("error_message_bis", 178 sprintf($GLOBALS['lang']['generique_help_novisits'], "<a href='index.php?mod=admin_site_javascript_code'>","</a>") 179 ); 180 } 181 } 182 183 // assign period, used in pages table to print the period text 184 $this->assign("period", $o_request->getPeriod()); 185 186 if(is_a( $o_site, 'Site')) 187 { 188 // compute and assign calendar 189 $o_dasked = new Date($o_request->getDate()); 190 $o_minDay = $o_site->getMinDay(); 191 if($o_dasked->getTimestamp() < $o_minDay->getTimestamp()) 192 { 193 $s_dateAsked = $o_minDay->get(); 194 } 195 else 196 { 197 $s_dateAsked = $o_dasked->get(); 198 } 199 $a_calendar = getTemplateArrayCalendar( 200 $o_minDay, 201 $s_dateAsked, 202 $o_request->getPeriod()); 203 $this->assign("calendar", $a_calendar); 204 205 // first day letters for calendar first line 206 if (!defined('MONDAY_FIRST') || MONDAY_FIRST == 'yes' ) 207 { 208 $dayFirstLetter = $GLOBALS['lang']['calendrier_jours']; 209 } 210 else 211 { 212 for($i = 0; $i < 7; $i++) 213 { 214 $dayFirstLetter[$i == 6 ? 0 : $i + 1] = $GLOBALS['lang']['calendrier_jours'][$i]; 215 } 216 ksort($dayFirstLetter); 217 } 218 $this->assign("day_first_letter", $dayFirstLetter); 219 220 // litteral date for display below the menu 221 $this->assign("date_litteral", getLiteralDate($o_request->getPeriod(), $s_dateAsked)); 222 $this->assign("date_ask", $s_dateAsked); 223 224 // months info for SELECT months generation 225 $months_info = getTemplateArrayMonth($o_site->getMinDay(), $o_request); 226 $this->assign("months_available", $months_info[0]); 227 $this->assign("month_selected", $months_info[1]); 228 229 // sites info for SELECT sites generation 230 $this->assign("sites_view_available", $o_site->getAllowedSites( 'view' ) ); 231 $this->assign("sites_admin_available", $o_site->getAllowedSites( 'admin' ) ); 232 $this->assign("site_selected", $o_request->getSiteId( false ) ); 233 $this->assign("site_selected_name", $o_site->getName() ); 234 235 // pdf list 236 $pdfConf = new PdfConfigDb ($o_request->getSiteId(false), true); 237 $this->assign("site_pdf_list", $pdfConf->getListPdf() ); 238 } 239 240 // langs info for SELECT langs generation 241 $this->assign("langs_available", $o_lang->getArrayLangs()); 242 $this->assign("lang_selected", $o_lang->getFileName()); 243 244 // require menu definition and assign for menu display 245 $menu=array(); 246 if (is_file(INCLUDE_PATH .'/themes/' . THEME .'/datas/MenuDefinition.php')) 247 { 248 require INCLUDE_PATH .'/themes/' . THEME .'/datas/MenuDefinition.php'; 249 } 250 else 251 { 252 require INCLUDE_PATH .'/themes/' . THEME_DEFAULT .'/datas/MenuDefinition.php'; 253 } 254 //require INCLUDE_PATH . "/core/include/MenuDefinition.php"; 255 256 // Add plugin menus 257 $installedPlugin = new PmvConfig("plugin.php", false); 258 foreach ($installedPlugin->content as $key => $value) { 259 // Load lang for plugin 260 if ((isset($value['langPath'])) && ($value['langPath'] != "")) { 261 Lang::addPluginLangFile ($key."/".$value['langPath'], $value['defaultLang']); 262 } 263 if ($value['type'] == "menu") { 264 // Set plugin in menu list 265 $menuModName = $value['menuModName']; 266 for ($i=0; $i < count($menu); $i++) { 267 if ($menu[$i]['modname'] == $menuModName) { 268 $menu[$i]['plugins'][$key] = $value; 269 } 270 } 271 } 272 } 273 274 $this->assign("menu", $menu); 275 276 // To select menu 277 $this->assign("page",$o_request->getModuleName()); 278 279 } 280 281 282 // interest sorting info 283 if(is_a($o_data, "DataModel")) 284 { 285 //printDebug($o_request->getArrayInfoSort( $o_data->arraySumInfo)); 286 $this->assign("info_sort", $o_request->getArrayInfoSort( $o_data->arraySumInfo )); 287 } 288 289 290 /** 291 * display a previous assigned template variable 292 */ 293 //printDebug($this->get_template_vars( "countries")); 294 295 // url with main variables 296 $this->assign("url", $o_request->getUrl()); 297 298 // current exact url 299 $this->assign("url_current", $o_request->getCurrentUrl() ); 300 301 // url without offset info 302 $this->assign("url_offset", $o_request->getUrl('offset')); 303 304 // url without interest info 305 $this->assign("url_a_int_sort", $o_request->getUrl('a_int_sort')); 306 $this->assign("url_a_exit_sort", $o_request->getUrl('a_exit_sort')); 307 $this->assign("url_a_entry_sort", $o_request->getUrl('a_entry_sort')); 308 309 // url without module 310 $this->assign("url_mod", $o_request->getUrl(array('mod', 'a_int_sort'))); 311 312 // url without site 313 $this->assign("url_site", $o_request->getUrl('site')); 314 315 // url without date 316 $this->assign("url_date", $o_request->getUrl('date')); 317 318 // url without period 319 $this->assign("url_period", $o_request->getUrl('period')); 320 321 // url without lang 322 // $this->assign("url_lang", Request::getCurrentCompleteUrl()); 323 $this->assign("url_lang", $o_request->getUrl('lang')); 324 325 // url without mod & site, used for summary SELECT choice (because we change mod=viewsummary and site=-1) 326 $this->assign("url_mod_site", $o_request->getUrl(array('mod', 'a_int_sort', 'site'))); 327 328 329 $this->assign("url_pages_details",$o_request->getUrl('mod_sort_means_details')); 330 331 // if there is an "error" message to print in red 332 if(isset($GLOBALS['content_message_tpl'])) 333 { 334 // assign the message 335 $this->assign("content_message", $GLOBALS['content_message_tpl']); 336 337 // and the content template, error.tpl which will print in red the message 338 $this->setTemplate('common/error.tpl'); 339 } 340 341 // assign an header message (archive ok, archive temp, etc.) 342 $this->assign("header_message", $GLOBALS['header_message_tpl']); 343 344 // assign an error header message 345 $this->assign("header_error_message", $GLOBALS['header_error_message_tpl']); 346 347 // assign text direction info (rtl, ltr) 348 $this->assign("dir", $GLOBALS['lang']['text_dir']); 349 350 // assign footer info 351 //$time = getMicrotime()-$GLOBALS['time_start']; 352 //$this->assign("generation_time", $time); 353 //$this->assign("query_count", $GLOBALS['query_count']); 354 355 // image dir 356 //$this->assign("img_dir", DIR_IMG_THEMES); 357 $this->assign("img_dir", $this->template_dir . "images/"); 358 359 360 // links for the documentation 361 $this->assign("link_doc", array( HREF_DOC_OPEN, HREF_DOC_CLOSE)); 362 363 // phpmyvisites version to print in meta and footer 364 $this->assign("PHPMV_VERSION", PHPMV_VERSION); 365 $this->assign("PHP_VERSION_NEEDED", PHP_VERSION_NEEDED); 366 367 $this->assign("PARAM_URL_NEWSLETTER", PARAM_URL_NEWSLETTER); 368 $this->assign("PARAM_URL_PARTNER", PARAM_URL_PARTNER); 369 370 //should we include internal stats in the application footer 371 if (defined('INTERNAL_STATS') && INTERNAL_STATS == 1) 372 { 373 $this->assign('internal_stats', true); 374 } 375 if (defined('INTERNAL_CLICKHEAT') && INTERNAL_CLICKHEAT == 1) 376 { 377 $this->assign('internal_clickheat', true); 378 } 379 380 $user =& User::getInstance(); 381 382 $this->assign('user_alias', $user->getAlias()); 383 $this->assign('user_login', $user->getLogin()); 384 $this->assign('user_is_su', $user->suPermission); 385 $this->assign('user_is_admin_site', $user->isSiteAllowedAdmin($o_request->getSiteId( false ))); 386 387 $this->assign("rss_hash", $user->getRssHash()); 388 389 $this->assign('a_link_phpmv', array('<a class="bleu" link="web statistics" href="http://www.phpmyvisites.us/">','</a>')); 390 391 $this->assign("contentpage", $this->template); 392 393 printTime('After Smarty pre computing'); 394 } 395 396 397 /** 398 * Render method 399 * called if a template have to be displayed 400 * 401 * @param object o_site 402 * @param object o_data 403 * 404 * @return void 405 */ 406 function render($o_site = null, $o_data = null) 407 { 408 if (!$this->is_cached($this->mainTemplate, SMARTY_CACHE_ID, $this->compile_id)) 409 { 410 $this->processDatas($o_site, $o_data); 411 if(DEBUG) 412 echo 'Template is NOT cached'; 413 } 414 else 415 { 416 if(DEBUG) 417 echo 'Template is cached'; 418 } 419 header('Content-Type: text/html; charset=utf-8'); 420 if( !empty($GLOBALS['header_message_tpl']) 421 && Request::moduleIsNotAStrangeModule()) 422 { 423 //Message à passer en variable dans le template header.tpl 424 //print("<p class='archive'>".$GLOBALS['header_message_tpl']."</p>"); 425 } 426 $this->display($this->mainTemplate, SMARTY_CACHE_ID, $this->compile_id); 427 } 428 429 /** 430 * Fetch method 431 * called if a template have to be fetched and include in an other template 432 * 433 * @param string template 434 * @param object o_site 435 * @param object o_data 436 * @param object request 437 * 438 * @return void 439 */ 440 function processAndFetch($template, &$o_site, &$o_data, $request = null, $cacheDiscriminant = null) 441 { 442 $this->setTemplate($template); 443 $cache_id = (!is_null($cacheDiscriminant)) 444 ? md5(SMARTY_CACHE_ID . $cacheDiscriminant) 445 : SMARTY_CACHE_ID; 446 447 if (!$this->is_cached($template, $cache_id, $this->compile_id)) 448 { 449 $this->processDatas($o_site, $o_data, $request); 450 } 451 452 return $this->fetch($this->template, $cache_id, $this->compile_id); 453 } 454 455 } 456 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |