[ 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: Module.class.php 229 2007-07-03 17:33:41Z matthieu_ $ 11 12 require_once INCLUDE_PATH . '/core/include/TemplateEngine.php'; 13 require_once INCLUDE_PATH . '/core/include/functions.php'; 14 require_once INCLUDE_PATH . '/core/include/Site.class.php'; 15 16 class Module 17 { 18 var $defaultAction = "showAll"; 19 20 var $actions; 21 22 var $tpl; 23 24 var $viewTemplate = ''; 25 26 var $request; 27 28 var $site; 29 30 /** 31 * Constructor 32 */ 33 function Module() 34 { 35 } 36 37 38 /** 39 * factory method, take care of loading the appropriate module 40 * 41 * @param string $moduleName 42 * @return object module 43 */ 44 function factory($moduleName) 45 { 46 //$className = camelize($moduleName); 47 48 $modulePath = array( 'core/modules', 49 'core/views', 50 'core/admin', 51 'core/install', 52 'core/graphs', 53 'plugins/modules', 54 'plugins' 55 ); 56 57 $classPathTab = getClassAndPathModule ($moduleName); 58 $className = $classPathTab[0]; 59 60 foreach($modulePath as $path) 61 { 62 if (is_file(INCLUDE_PATH . '/' . $path . '/' . $classPathTab[1] . $className . '.class.php')) 63 { 64 require_once INCLUDE_PATH . '/' . $path . '/' . $classPathTab[1] . $className . '.class.php'; 65 break; 66 } 67 } 68 69 if(!class_exists($className)) 70 { 71 trigger_error('Unable to load class ' . $className . ' for module', E_USER_ERROR); 72 } 73 $module =& new $className; 74 75 return $module; 76 } 77 78 /** 79 * module initialization tasks 80 * 81 * @param object $request 82 * @param object $tpl Template instance 83 * 84 * @return void 85 */ 86 function init(&$request, $tpl = null) 87 { 88 $this->request =& $request; 89 90 if (!isset($this->site) 91 && !Request::isCurrentModuleAnInstallModule() ) 92 { 93 //site could be setted if ViewRss is called for multiple sites 94 $site = $this->request->getSiteId(); 95 96 if ($site) 97 { 98 if (get_class ($this) != "adminupdate") { 99 $this->site = new Site($site); 100 } 101 } 102 } 103 104 if(!Request::isCurrentModuleAGraphModule()) 105 { 106 if (!is_null($tpl)) 107 { 108 $this->tpl =& $tpl; 109 } 110 else 111 { 112 if (isset($this->site)) { 113 $this->tpl =& new TemplateEngine($this->viewTemplate, $this->site->getPathTheme()); 114 } 115 else { 116 $this->tpl =& new TemplateEngine($this->viewTemplate); 117 } 118 } 119 120 } 121 122 } 123 124 /** 125 * Main job 126 * parse the request, try to find a valid action param 127 * if none found, load the defaultAction 128 * 129 * @return void 130 */ 131 function doAction() 132 { 133 134 if (isset($this->request)){ 135 $actionName = $this->request->getActionName(); 136 137 if ($actionName 138 && isset($this->actions) 139 && is_array($this->actions) 140 && array_key_exists($actionName, $this->actions)) 141 { 142 $method = $this->actions[$actionName]; 143 } else { 144 $method = $this->defaultAction; 145 } 146 } 147 if (method_exists($this, $method)) 148 { 149 $this->$method(); 150 } else { 151 trigger_error('Unable to find any valid action for module: ' . get_class($this)); 152 } 153 } 154 155 /** 156 * wrapper around template engine is cached method 157 */ 158 function isCached() 159 { 160 if ( !SMARTY_DEBUG 161 && $this->tpl->is_cached($this->tpl->mainTemplate, SMARTY_CACHE_ID, $this->tpl->compile_id)) 162 { 163 return true; 164 } 165 return false; 166 } 167 168 /** 169 * Default display action 170 * 171 * @return void 172 */ 173 function display() 174 { 175 // case it's a ViewModule and so there may be specific data to compute 176 if(isset($this->data)) 177 { 178 $this->tpl->render($this->site, $this->data); 179 } 180 // case it is a simple Module 181 else 182 { 183 $this->tpl->render($this->site); 184 } 185 } 186 187 /** 188 * fetch les donn�es du module 189 * 190 * @return string populated template 191 */ 192 function fetch($contentPage, $request = null, $cacheDiscriminant = null) 193 { 194 if( get_class($this) === 'ViewVisitsRss') 195 { 196 if($this->data->getContent('nb_vis') == 0) 197 { 198 $this->tpl->assign("mod", "rss"); 199 $contentPage = "common/error.tpl"; 200 } 201 } 202 203 return $this->tpl->processAndFetch($contentPage, $this->site, $this->data, $request, $cacheDiscriminant); 204 } 205 } 206 ?>
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 |
![]() |