XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
common.php
Go to the documentation of this file.
1 <?php
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 
24 
28 defined('DS') or define('DS', DIRECTORY_SEPARATOR);
29 defined('NWLINE')or define('NWLINE', "\n");
30 
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 
41 require_once XOOPS_ROOT_PATH . DS . 'class' . DS . 'xoopsload.php';
42 
49 XoopsLoad::load('preload');
50 $xoopsPreload =& XoopsPreload::getInstance();
51 $xoopsPreload->triggerEvent('core.include.common.start');
52 
60 XoopsLoad::load('xoopskernel');
62 $xoops->pathTranslation();
63 $xoopsRequestUri =& $_SERVER['REQUEST_URI'];// Deprecated (use the corrected $_SERVER variable now)
64 
68 XoopsLoad::load('xoopssecurity');
70 $xoopsSecurity->checkSuperglobals();
71 
75 XoopsLoad::load('xoopslogger');
76 $xoopsLogger =& XoopsLogger::getInstance();
77 $xoopsErrorHandler =& XoopsLogger::getInstance();
78 $xoopsLogger->startTime();
79 $xoopsLogger->startTime('XOOPS Boot');
80 
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 
96 //define('XOOPS_COOKIE_DOMAIN', ($domain = xoops_getBaseDomain(XOOPS_URL)) == 'localhost' ? '' : '.' . $domain);
97 //When you don't use Localhost but your "computer name" as domain you can't use session cookies
98 define('XOOPS_COOKIE_DOMAIN', (strpos($domain = xoops_getBaseDomain(XOOPS_URL),'.')) === FALSE ? '' : '.' . $domain); //by arion92fr
99 
104 if ($_SERVER['REQUEST_METHOD'] != 'POST' || ! $xoopsSecurity->checkReferer(XOOPS_DB_CHKREF)) {
105  define('XOOPS_DB_PROXY', 1);
106 }
107 
112 include_once $xoops->path('class/database/databasefactory.php');
114 
121 
125 if (file_exists($file = $GLOBALS['xoops']->path('var/configs/xoopsconfig.php'))) {
126  $fileConfigs = include $file;
127  $xoopsConfig = array_merge($xoopsConfig, (array) $fileConfigs);
128  unset($fileConfigs, $file);
129 } else {
130  trigger_error('File Path Error: ' . 'var/configs/xoopsconfig.php' . ' does not exist.');
131 }
132 
133 //check if user set a local timezone (from XavierS)
134 // $xoops_server_timezone="Etc/GMT";
135 // if ($xoopsConfig["server_TZ"]>0) {
136  // $xoops_server_timezone .="+".$xoopsConfig["server_TZ"]; } else{
137  // $xoops_server_timezone .=$xoopsConfig["server_TZ"]; } date_default_timezone_set($xoops_server_timezone);
138 
139 
144 $xoops->gzipCompression();
145 
149 if ($xoopsConfig['debug_mode'] == 1 || $xoopsConfig['debug_mode'] == 2) {
150  xoops_loadLanguage('logger');
151  error_reporting(E_ALL);
152  $xoopsLogger->enableRendering();
153  $xoopsLogger->usePopup = ($xoopsConfig['debug_mode'] == 2);
154 } else {
155  error_reporting(0);
156  $xoopsLogger->activated = false;
157 }
158 
162 $xoopsSecurity->checkBadips();
163 
167 $xoopsPreload->triggerEvent('core.include.common.language');
168 xoops_loadLanguage('global');
169 xoops_loadLanguage('errors');
170 xoops_loadLanguage('pagetype');
171 
178 $sess_handler =& xoops_gethandler('session');
179 if ($xoopsConfig['use_ssl']
180  && isset($_POST[$xoopsConfig['sslpost_name']])
181  && $_POST[$xoopsConfig['sslpost_name']] != ''
182 ) {
183  session_id($_POST[$xoopsConfig['sslpost_name']]);
184 } else if ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && $xoopsConfig['session_expire'] > 0) {
185  if (isset($_COOKIE[$xoopsConfig['session_name']])) {
186  session_id($_COOKIE[$xoopsConfig['session_name']]);
187  }
188  if (function_exists('session_cache_expire')) {
189  session_cache_expire($xoopsConfig['session_expire']);
190  }
191  @ini_set('session.gc_maxlifetime', $xoopsConfig['session_expire'] * 60);
192 }
193 session_set_save_handler(array(&$sess_handler, 'open'),
194  array(&$sess_handler, 'close'),
195  array(&$sess_handler, 'read'),
196  array(&$sess_handler, 'write'),
197  array(&$sess_handler, 'destroy'),
198  array(&$sess_handler, 'gc'));
199 session_start();
200 
204 if ($xoopsConfig['use_mysession']
205  && $xoopsConfig['session_name'] != ''
206  && !isset($_COOKIE[$xoopsConfig['session_name']])
207  && !empty($_SESSION['xoopsUserId'])
208 ) {
209  unset($_SESSION['xoopsUserId']);
210 }
211 
215 if (empty($_SESSION['xoopsUserId'])
216  && !empty($xoopsConfig['usercookie'])
217  && !empty($_COOKIE[$xoopsConfig['usercookie']])
218 ) {
219  $hash_data = @explode("{-}", $_COOKIE[$xoopsConfig['usercookie']], 2);
220  list($_SESSION['xoopsUserId'], $hash_login) = array($hash_data[0], strval(@$hash_data[1]));
221  unset($hash_data);
222 }
223 
227 if (!empty($_SESSION['xoopsUserId'])) {
228  $xoopsUser =& $member_handler->getUser($_SESSION['xoopsUserId']);
229  if (!is_object($xoopsUser) || (isset($hash_login) && md5($xoopsUser->getVar('pass') . XOOPS_DB_NAME . XOOPS_DB_PASS . XOOPS_DB_PREFIX) != $hash_login)) {
230  $xoopsUser = '';
231  $_SESSION = array();
232  session_destroy();
233  setcookie($xoopsConfig['usercookie'], 0, - 1, '/');
234  } else {
235  if ((intval($xoopsUser->getVar('last_login')) + 60 * 5) < time()) {
236  $sql = "UPDATE " . $xoopsDB->prefix('users')
237  . " SET last_login = '" . time()
238  . "' WHERE uid = " . $_SESSION['xoopsUserId'];
239  @$xoopsDB->queryF($sql);
240  }
241  $sess_handler->update_cookie();
242  if (isset($_SESSION['xoopsUserGroups'])) {
243  $xoopsUser->setGroups($_SESSION['xoopsUserGroups']);
244  } else {
245  $_SESSION['xoopsUserGroups'] = $xoopsUser->getGroups();
246  }
247  $xoopsUserIsAdmin = $xoopsUser->isAdmin();
248  }
249 }
250 
258 if ($xoopsLogger->activated) {
259  $level = isset($xoopsConfig['debugLevel']) ? intval($xoopsConfig['debugLevel']) : 0;
260  if (($level == 2 && empty($xoopsUserIsAdmin)) || ($level == 1 && !$xoopsUser)) {
261  error_reporting(0);
262  $xoopsLogger->activated = false;
263  }
264  unset($level);
265 }
266 
273 $xoops->themeSelect();
274 
278 if ($xoopsConfig['closesite'] == 1) {
279  include_once $xoops->path('include/site-closed.php');
280 }
281 
285 if (file_exists('./xoops_version.php')) {
286  $url_arr = explode('/', strstr($_SERVER['PHP_SELF'], '/modules/'));
287  $module_handler =& xoops_gethandler( 'module' );
288  $xoopsModule =& $module_handler->getByDirname($url_arr[2]);
289  unset($url_arr);
290 
291  if (!$xoopsModule || !$xoopsModule->getVar('isactive')) {
292  include_once $xoops->path('header.php');
293  echo '<h4>' . _MODULENOEXIST . '</h4>';
294  include_once $xoops->path('footer.php');
295  exit();
296  }
297 
298  $moduleperm_handler =& xoops_gethandler('groupperm');
299  if ($xoopsUser) {
300  if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), $xoopsUser->getGroups())) {
301  redirect_header(XOOPS_URL, 1, _NOPERM, false);
302  exit();
303  }
304  $xoopsUserIsAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
305  } else {
306  if (!$moduleperm_handler->checkRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS)) {
307  redirect_header(XOOPS_URL . '/user.php?from=' . $xoopsModule->getVar('dirname', 'n'), 1, _NOPERM);
308  exit();
309  }
310  }
311 
312  if ($xoopsModule->getVar('dirname', 'n') != 'system') {
313  if (file_exists($file = $xoops->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/language/' . $xoopsConfig['language'] . '/main.php'))) {
314  include_once $file;
315  } else if (file_exists($file = $xoops->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/language/english/main.php'))) {
316  include_once $file;
317  }
318  unset($file);
319  }
320 
321  if ($xoopsModule->getVar('hasconfig') == 1 || $xoopsModule->getVar('hascomments') == 1 || $xoopsModule->getVar('hasnotification') == 1 ) {
322  $xoopsModuleConfig = $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
323  }
324 } else if ($xoopsUser) {
325  $xoopsUserIsAdmin = $xoopsUser->isAdmin(1);
326 }
327 
331 //Creates 'system_modules_active' cache file if it has been deleted.
333 
334 $xoopsLogger->stopTime('XOOPS Boot');
335 $xoopsLogger->startTime('Module init');
336 
337 $xoopsPreload->triggerEvent('core.include.common.end');
338 ?>