| [ Index ] |
PHP Cross Reference of Xoops v2.4.5 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * XOOPS common initialization file 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 13 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 14 * @package kernel 15 * @version $Id: common.php 4897 2010-06-19 02:55:48Z phppp $ 16 */ 17 defined('XOOPS_MAINFILE_INCLUDED') or die('Restricted access'); 18 19 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 20 set_magic_quotes_runtime(0); 21 } 22 23 global $xoops, $xoopsPreload, $xoopsLogger, $xoopsErrorHandler, $xoopsSecurity, $sess_handler; 24 25 /** 26 * YOU SHOULD NEVER USE THE FOLLOWING TO CONSTANTS, THEY WILL BE REMOVED 27 */ 28 defined('DS') or define('DS', DIRECTORY_SEPARATOR); 29 defined('NWLINE')or define('NWLINE', "\n"); 30 31 /** 32 * Include files with definitions 33 */ 34 include_once XOOPS_ROOT_PATH . DS . 'include' . DS . 'defines.php'; 35 include_once XOOPS_ROOT_PATH . DS . 'include' . DS . 'version.php'; 36 include_once XOOPS_ROOT_PATH . DS . 'include' . DS . 'license.php'; 37 38 /** 39 * Include XoopsLoad 40 */ 41 require_once XOOPS_ROOT_PATH . DS . 'class' . DS . 'xoopsload.php'; 42 43 /** 44 * YOU SHOULD BE CAREFUL WITH THE PRELOAD METHODS IN 2.4*, THEY WILL BE DEPRECATED AND IMPLEMENTED IN A DIFFERENT WAY 45 */ 46 /** 47 * Create Instance of Preload Object 48 */ 49 XoopsLoad::load('preload'); 50 $xoopsPreload =& XoopsPreload::getInstance(); 51 $xoopsPreload->triggerEvent('core.include.common.start'); 52 53 /** 54 * YOU SHOULD BE CAREFUL WITH THE {@xos_kernel_Xoops2}, MOST METHODS WILL BE DEPRECATED 55 */ 56 /** 57 * Create Instance of xos_kernel_Xoops2 Object 58 * Atention, not all methods can be used at this point 59 */ 60 XoopsLoad::load('xoopskernel'); 61 $xoops = new xos_kernel_Xoops2(); 62 $xoops->pathTranslation(); 63 $xoopsRequestUri =& $_SERVER['REQUEST_URI'];// Deprecated (use the corrected $_SERVER variable now) 64 65 /** 66 * Create Instance of xoopsSecurity Object and check Supergolbals 67 */ 68 XoopsLoad::load('xoopssecurity'); 69 $xoopsSecurity = new XoopsSecurity(); 70 $xoopsSecurity->checkSuperglobals(); 71 72 /** 73 * Create Instantance XoopsLogger Object 74 */ 75 XoopsLoad::load('xoopslogger'); 76 $xoopsLogger =& XoopsLogger::getInstance(); 77 $xoopsErrorHandler =& XoopsLogger::getInstance(); 78 $xoopsLogger->startTime(); 79 $xoopsLogger->startTime('XOOPS Boot'); 80 81 /** 82 * Include Required Files 83 */ 84 include_once $xoops->path('kernel/object.php'); 85 include_once $xoops->path('class/criteria.php'); 86 include_once $xoops->path('class/module.textsanitizer.php'); 87 include_once $xoops->path('include/functions.php'); 88 89 /** 90 * YOU SHOULD NEVER USE THE FOLLOWING CONSTANT, IT WILL BE REMOVED 91 */ 92 /** 93 * Set cookie dope for multiple subdomains remove the '.'. to use top level dope for session cookie; 94 * Requires functions 95 */ 96 define('XOOPS_COOKIE_DOMAIN', ($domain = xoops_getBaseDomain(XOOPS_URL)) == 'localhost' ? '' : '.' . $domain); 97 98 /** 99 * Check Proxy; 100 * Requires functions 101 */ 102 if ($_SERVER['REQUEST_METHOD'] != 'POST' || ! $xoopsSecurity->checkReferer(XOOPS_DB_CHKREF)) { 103 define('XOOPS_DB_PROXY', 1); 104 } 105 106 /** 107 * Get database for making it global 108 * Requires XoopsLogger, XOOPS_DB_PROXY; 109 */ 110 include_once $xoops->path('class/database/databasefactory.php'); 111 $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection(); 112 113 /** 114 * Get xoops configs 115 * Requires functions and database loaded 116 */ 117 $config_handler =& xoops_gethandler('config'); 118 $xoopsConfig = $config_handler->getConfigsByCat(XOOPS_CONF); 119 120 /** 121 * Merge file and db configs. 122 */ 123 if (file_exists($file = $GLOBALS['xoops']->path('var/configs/xoopsconfig.php'))) { 124 $fileConfigs = include $file; 125 $xoopsConfig = array_merge($xoopsConfig, (array) $fileConfigs); 126 unset($fileConfigs, $file); 127 } else { 128 trigger_error('File Path Error: ' . 'var/configs/xoopsconfig.php' . ' does not exist.'); 129 } 130 131 /** 132 * Enable Gzip compression, r 133 * Requires configs loaded and should go before any output 134 */ 135 $xoops->gzipCompression(); 136 137 /** 138 * Start of Error Reportings. 139 */ 140 if ($xoopsConfig['debug_mode'] == 1 || $xoopsConfig['debug_mode'] == 2) { 141 xoops_loadLanguage('logger'); 142 error_reporting(E_ALL); 143 $xoopsLogger->enableRendering(); 144 $xoopsLogger->usePopup = ($xoopsConfig['debug_mode'] == 2); 145 } else { 146 error_reporting(0); 147 $xoopsLogger->activated = false; 148 } 149 150 /** 151 * Check Bad Ip Addressed against database and block bad ones, requires configs loaded 152 */ 153 $xoopsSecurity->checkBadips(); 154 155 /** 156 * Load Language settings and defines 157 */ 158 $xoopsPreload->triggerEvent('core.include.common.language'); 159 xoops_loadLanguage('global'); 160 xoops_loadLanguage('errors'); 161 xoops_loadLanguage('pagetype'); 162 163 /** 164 * User Sessions 165 */ 166 $xoopsUser = ''; 167 $xoopsUserIsAdmin = false; 168 $member_handler =& xoops_gethandler('member'); 169 $sess_handler =& xoops_gethandler('session'); 170 if ($xoopsConfig['use_ssl'] 171 && isset($_POST[$xoopsConfig['sslpost_name']]) 172 && $_POST[$xoopsConfig['sslpost_name']] != '' 173 ) { 174 session_id($_POST[$xoopsConfig['sslpost_name']]); 175 } else if ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && $xoopsConfig['session_expire'] > 0) { 176 if (isset($_COOKIE[$xoopsConfig['session_name']])) { 177 session_id($_COOKIE[$xoopsConfig['session_name']]); 178 } 179 if (function_exists('session_cache_expire')) { 180 session_cache_expire($xoopsConfig['session_expire']); 181 } 182 @ini_set('session.gc_maxlifetime', $xoopsConfig['session_expire'] * 60); 183 } 184 session_set_save_handler(array(&$sess_handler, 'open'), 185 array(&$sess_handler, 'close'), 186 array(&$sess_handler, 'read'), 187 array(&$sess_handler, 'write'), 188 array(&$sess_handler, 'destroy'), 189 array(&$sess_handler, 'gc')); 190 session_start(); 191 192 /** 193 * Remove expired session for xoopsUserId 194 */ 195 if ($xoopsConfig['use_mysession'] 196 && $xoopsConfig['session_name'] != '' 197 && !isset($_COOKIE[$xoopsConfig['session_name']]) 198 && !empty($_SESSION['xoopsUserId']) 199 ) { 200 unset($_SESSION['xoopsUserId']); 201 } 202 203 /** 204 * Load xoopsUserId from cookie if "Remember me" is enabled. 205 */ 206 if (empty($_SESSION['xoopsUserId']) 207 && !empty($xoopsConfig['usercookie']) 208 && !empty($_COOKIE[$xoopsConfig['usercookie']]) 209 ) { 210 $hash_data = @explode("-", $_COOKIE[$xoopsConfig['usercookie']], 2); 211 list($_SESSION['xoopsUserId'], $hash_login) = array($hash_data[0], strval(@$hash_data[1])); 212 unset($hash_data); 213 } 214 215 /** 216 * Log user is and deal with Sessions and Cookies 217 */ 218 if (!empty($_SESSION['xoopsUserId'])) { 219 $xoopsUser =& $member_handler->getUser($_SESSION['xoopsUserId']); 220 if (!is_object($xoopsUser) || (isset($hash_login) && md5($xoopsUser->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX) != $hash_login)) { 221 $xoopsUser = ''; 222 $_SESSION = array(); 223 session_destroy(); 224 setcookie($xoopsConfig['usercookie'], 0, - 1, '/'); 225 } else { 226 if ((intval($xoopsUser->getVar('last_login')) + 60 * 5) < time()) { 227 $sql = "UPDATE " . $xoopsDB->prefix('users') 228 . " SET last_login = '" . time() 229 . "' WHERE uid = " . $_SESSION['xoopsUserId']; 230 @$xoopsDB->queryF($sql); 231 } 232 $sess_handler->update_cookie(); 233 if (isset($_SESSION['xoopsUserGroups'])) { 234 $xoopsUser->setGroups($_SESSION['xoopsUserGroups']); 235 } else { 236 $_SESSION['xoopsUserGroups'] = $xoopsUser->getGroups(); 237 } 238 $xoopsUserIsAdmin = $xoopsUser->isAdmin(); 239 } 240 } 241 242 /** 243 * *#@+ 244 * Debug level for XOOPS 245 * Check /xoops_data/configs/xoopsconfig.php for details 246 * 247 * Note: temporary solution only. Will be re-designed in XOOPS 3.0 248 */ 249 if ($xoopsLogger->activated) { 250 $level = isset($xoopsConfig['debugLevel']) ? intval($xoopsConfig['debugLevel']) : 0; 251 if (($level == 2 && empty($xoopsUserIsAdmin)) || ($level == 1 && !$xoopsUser)) { 252 error_reporting(0); 253 $xoopsLogger->activated = false; 254 } 255 unset($level); 256 } 257 258 /** 259 * YOU SHOULD NEVER USE THE FOLLOWING METHOD, IT WILL BE REMOVED 260 */ 261 /** 262 * Theme Selection 263 */ 264 $xoops->themeSelect(); 265 266 /** 267 * Closed Site 268 */ 269 if ($xoopsConfig['closesite'] == 1) { 270 include_once $xoops->path('include/site-closed.php'); 271 } 272 273 /** 274 * Load Xoops Module 275 */ 276 if (file_exists('./xoops_version.php')) { 277 $url_arr = explode('/', strstr($_SERVER['PHP_SELF'], '/modules/')); 278 $module_handler =& xoops_gethandler( 'module' ); 279 $xoopsModule =& $module_handler->getByDirname($url_arr[2]); 280 unset($url_arr); 281 282 if (!$xoopsModule || !$xoopsModule->getVar('isactive')) { 283 include_once $xoops->path('header.php'); 284 echo '<h4>' . _MODULENOEXIST . '</h4>'; 285 include_once $xoops->path('footer.php'); 286 exit(); 287 } 288 289 $moduleperm_handler =& xoops_gethandler('groupperm'); 290 if ($xoopsUser) { 291 if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), $xoopsUser->getGroups())) { 292 redirect_header(XOOPS_URL, 1, _NOPERM, false); 293 exit(); 294 } 295 $xoopsUserIsAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid')); 296 } else { 297 if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS)) { 298 redirect_header(XOOPS_URL . '/user.php?from=' . $xoopsModule->getVar('dirname', 'n'), 1, _NOPERM); 299 exit(); 300 } 301 } 302 303 if ($xoopsModule->getVar('dirname', 'n') != 'system') { 304 if (file_exists($file = $xoops->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/language/' . $xoopsConfig['language'] . '/main.php'))) { 305 include_once $file; 306 } else if (file_exists($file = $xoops->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/language/english/main.php'))) { 307 include_once $file; 308 } 309 unset($file); 310 } 311 312 if ($xoopsModule->getVar('hasconfig') == 1 || $xoopsModule->getVar('hascomments') == 1 || $xoopsModule->getVar('hasnotification') == 1 ) { 313 $xoopsModuleConfig = $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid')); 314 } 315 } else if ($xoopsUser) { 316 $xoopsUserIsAdmin = $xoopsUser->isAdmin(1); 317 } 318 319 /** 320 * YOU SHOULD AVOID USING THE FOLLOWING FUNCTION, IT WILL BE REMOVED 321 */ 322 //Creates 'system_modules_active' cache file if it has been deleted. 323 xoops_getActiveModules(); 324 325 $xoopsLogger->stopTime('XOOPS Boot'); 326 $xoopsLogger->startTime('Module init'); 327 328 $xoopsPreload->triggerEvent('core.include.common.end'); 329 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 01:39:09 2010 |