[ 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: ApplicationController.php 232 2007-07-06 09:31:19Z matthieu_ $ 11 12 require_once INCLUDE_PATH . '/core/include/Request.class.php'; 13 require_once INCLUDE_PATH . '/core/include/Module.class.php'; 14 require_once INCLUDE_PATH . '/core/include/Lang.class.php'; 15 require_once INCLUDE_PATH . '/config.inc.php'; 16 require_once INCLUDE_PATH . '/core/include/User.class.php'; 17 18 class ApplicationController 19 { 20 21 var $module; 22 23 var $defaultModuleName = 'index'; 24 25 var $request; 26 27 var $lang; 28 29 30 /** 31 * Constructeur 32 */ 33 function ApplicationController(){} 34 35 36 /** 37 * Singleton 38 */ 39 function &getInstance() 40 { 41 static $instance; 42 43 if (!isset($instance)){ 44 $c = __CLASS__; 45 $instance = new $c; 46 } 47 return $instance; 48 } 49 50 /** 51 * Point d'entr�e de l'application 52 * 53 */ 54 function init() 55 { 56 57 $c =& PmvConfig::getInstance(); 58 $Lang =& Lang::getInstance(); 59 60 // id used for caching 61 define('SMARTY_CACHE_ID', md5( 62 @$_SERVER['SERVER_NAME']. // if server changes, must regenerate cache 63 64 $_SERVER['PHP_SELF']. 65 66 serialize($_GET). // one cache per distinct URL 67 68 serialize($_POST). // idem for POST 69 70 // one cache per user 71 (isset($_COOKIE[COOKIE_NAME_SESSION]) 72 ? serialize($_COOKIE[COOKIE_NAME_SESSION]) 73 : '' ). 74 75 // file name of the language file 76 $Lang->getFileName() . 77 78 // one cache per day 79 date("Y-m-d"). 80 81 TIME_BEFORE_NEW_DAY_ARCHIVE. 82 PHPMV_VERSION. 83 INTERNAL_STATS 84 ) 85 ); 86 87 setIncludePath(); 88 89 $db =& Db::getInstance(); 90 91 if(defined( 'DB_HOST' )) 92 { 93 $db->connect(); 94 } 95 96 // try to set memory limit to MEMORY_LIMIT 97 setMemoryLimit(); 98 99 $controller =& ApplicationController::getInstance(); 100 101 $controller->loadLang(); 102 103 $controller->parseRequest(); 104 105 $controller->loadModule(); 106 107 $controller->executeAction(); 108 } 109 110 /** 111 * Analyse et definit la requete utilisateur 112 * 113 */ 114 function parseRequest() 115 { 116 $this->request =& Request::getInstance(); 117 if (!is_a( $this->request , 'Request')) 118 trigger_error('Unable to parse current request... error', E_USER_ERROR); 119 120 } 121 122 /** 123 * retourne la request 124 * 125 */ 126 function &getRequest() 127 { 128 return $this->request; 129 } 130 131 132 function loadLang() 133 { 134 $this->lang =& Lang::getInstance(); 135 } 136 137 function &getLang() 138 { 139 return $this->lang; 140 } 141 142 /** 143 * Charge le module demand� 144 * 145 */ 146 function loadModule() 147 { 148 $moduleName = $this->request->getModuleName(); 149 $db =& Db::getInstance(); 150 151 if(ereg('admin', $moduleName) ) 152 { 153 $this->lang->reloadLangFile(); 154 } 155 if (!$moduleName) 156 { 157 $moduleName = $this->defaultModuleName; 158 } 159 160 161 if($moduleName == 'list_logos') 162 { 163 $authorized = true; 164 } 165 else 166 { 167 $b_writeDir = checkDirWritable( ); 168 169 /** 170 * very first : logo selection is allowed 171 */ 172 /** 173 * first look if installation is needed 174 */ 175 if(!is_file( INCLUDE_PATH . "/config/config.php") 176 || !defined('DB_HOST') 177 || !defined('SU_LOGIN') 178 || !defined('INSTALL_OK')) 179 { 180 if( !Request::isCurrentModuleAnInstallModule() ) 181 { 182 Request::redirectToModule('install_welcome'); 183 } 184 $authorized = true; 185 } 186 187 /** 188 * second, look if database configuration only is needed 189 */ 190 else if(!$db->isReady() 191 && substr_count( Request::getCurrentCompleteUrl(), 'mod=login' ) === 0 192 && substr_count( Request::getCurrentCompleteUrl(), 'mod=logout' ) === 0 193 ) 194 { 195 Request::redirectToModule('admin_db_config'); 196 } 197 198 /** 199 * third, look if there is a problem relative to writable directories 200 */ 201 else if( $b_writeDir === false) 202 { 203 // case there is a write problem, we load server_info page to indicate the user the problem 204 $moduleName = 'admin_server_info'; 205 $authorized = true; 206 } 207 else if($db->isReady()) 208 { 209 if( version_compare($db->getVersion(), PHPMV_VERSION) == -1) 210 { 211 $moduleName = 'admin_update'; 212 $authorized = true; 213 } 214 else if( version_compare($db->getVersion(), PHPMV_VERSION) == 1) 215 { 216 trigger_error("There is a problem : your database is more recent than your phpMyVisites files! Try to upload the last release of phpMyVisites on your server.", E_USER_ERROR); 217 } 218 } 219 } 220 /** 221 * else it's ok! Load module 222 */ 223 224 // update module in the object request, used for hidden field in the login form 225 $this->request->setModuleName($moduleName); 226 227 // manage the user, is he authorized to see this module ? 228 $me =& User::getInstance(); 229 230 231 if( isset($authorized) 232 || $me->isAuthorized( $moduleName ) 233 || $this->request->isCrontabAllowed() 234 ) 235 { 236 $module = Module::factory($moduleName); 237 } 238 else 239 { 240 $module = Module::factory('login'); 241 } 242 243 if (!is_subclass_of($module, 'Module')) 244 trigger_error('Unable to load: ' . $moduleName . ' module', E_USER_ERROR); 245 246 $module->init($this->request, null); 247 248 $this->module =& $module; 249 } 250 251 252 function executeAction() 253 { 254 255 $this->module->doAction(); 256 } 257 } 258 ?>
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 |
![]() |