XOOPS  2.6.0
common.php
Go to the documentation of this file.
1 <?php
18 
26 if (!class_exists('XoopsLoad', false)) {
27  require_once dirname(__DIR__). '/class/XoopsBaseConfig.php';
29  $delayedWarning = 'Patch mainfile.php for XoopsBaseConfig';
30 }
31 
32 global $xoops;
33 $GLOBALS['xoops'] =& $xoops;
34 
35 //Legacy support
36 global $xoopsDB;
37 $GLOBALS['xoopsDB'] =& $xoopsDB;
41 defined('DS') or define('DS', DIRECTORY_SEPARATOR);
42 defined('NWLINE')or define('NWLINE', "\n");
43 
47 include_once __DIR__ . '/defines.php';
48 // include_once __DIR__ . '/version.php';
49 
53 \Patchwork\Utf8\Bootup::initAll(); // Enables the portablity layer and configures PHP for UTF-8
54 \Patchwork\Utf8\Bootup::filterRequestUri(); // Redirects to an UTF-8 encoded URL if it's not already the case
55 \Patchwork\Utf8\Bootup::filterRequestInputs(); // Normalizes HTTP inputs to UTF-8 NFC
56 
61 $xoops = Xoops::getInstance();
62 
63 $xoops->option =& $GLOBALS['xoopsOption'];
64 
68 $xoopsLogger = $xoops->logger();
69 
73 $xoops->events()->initializeListeners();
74 
75 $psr4loader = new \Xoops\Core\Psr4ClassLoader();
76 $psr4loader->register();
77 // listeners respond with $arg->addNamespace($namespace, $directory);
78 $xoops->events()->triggerEvent('core.include.common.psr4loader', $psr4loader);
79 $xoops->events()->triggerEvent('core.include.common.classmaps');
80 
84 $xoops->events()->triggerEvent('core.include.common.security');
85 $xoopsSecurity = $xoops->security();
86 
92 if (!defined('XOOPS_XMLRPC')) {
93  define('XOOPS_DB_CHKREF', 1);
94 } else {
95  define('XOOPS_DB_CHKREF', 0);
96 }
97 
98 if ($_SERVER['REQUEST_METHOD'] != 'POST' || !$xoopsSecurity->checkReferer(XOOPS_DB_CHKREF)) {
99  define ('XOOPS_DB_PROXY', 1);
100 }
101 
107 $xoops->db();
108 //For Legacy support
110 
111 $xoops->events()->triggerEvent('core.include.common.start');
112 
116 if (isset($delayedWarning)) {
117  trigger_error($delayedWarning);
118 }
119 
123 include_once $xoops->path('include/functions.php');
124 
129 $xoops->getConfigs();
130 $xoopsConfig =& $xoops->config;
131 
135 if (XoopsLoad::fileExists($file = $xoops->path('var/configs/system_configs.php'))) {
136  $xoops->addConfigs(include $file);
137  unset($file);
138 } else {
139  trigger_error('File Path Error: ' . 'var/configs/system_configs.php' . ' does not exist.');
140 }
141 
142 $xoops->events()->triggerEvent('core.include.common.configs.success');
143 
148 $xoops->gzipCompression();
149 
153 $xFrameOptions = isset($xoopsConfig['xFrameOptions']) ? $xoopsConfig['xFrameOptions'] : 'sameorigin';
154 $xoops->events()->triggerEvent('core.include.common.xframeoption');
155 if (!headers_sent() && !empty($xFrameOptions)) {
156  header('X-Frame-Options: ' .$xFrameOptions);
157 }
158 
162 $xoops->security()->checkBadips();
163 
167 $xoops->loadLocale();
168 //For legacy
169 $xoops->setConfig('language', XoopsLocale::getLegacyLanguage());
170 
171 date_default_timezone_set(XoopsLocale::getTimezone());
172 setlocale(LC_ALL, XoopsLocale::getLocale());
173 
177 $member_handler = $xoops->getHandlerMember();
178 
179 $xoops->session()->sessionStart();
180 
184 if ($xoops->session()->has('xoopsUserId')) {
185  $uid = $xoops->session()->get('xoopsUserId');
186  $xoops->user = $member_handler->getUser($uid);
187  if ($xoops->user instanceof \XoopsUser) {
188  if ((intval($xoops->user->getVar('last_login')) + 60 * 5) < time()) {
189  $user_handler = $xoops->getHandlerUser();
190  $criteria = new Criteria('uid', $uid);
191  $user_handler->updateAll('last_login', time(), $criteria, true);
192  unset($criteria);
193  }
194  $xoops->userIsAdmin = $xoops->user->isAdmin();
195  }
196 }
197 
198 $xoops->events()->triggerEvent('core.include.common.auth.success');
199 
203 $xoops->themeSelect();
204 
208 if ($xoops->getConfig('closesite') == 1) {
209  include_once $xoops->path('include/site-closed.php');
210 }
211 
216 $xoops->moduleDirname = 'system';
217 if (XoopsLoad::fileExists('./xoops_version.php')) {
218  $url_arr = explode('/', strstr($_SERVER['PHP_SELF'], '/modules/'));
219  $module_handler = $xoops->getHandlerModule();
220  $xoops->module = $xoops->getModuleByDirname($url_arr[2]);
221  $xoops->moduleDirname = $url_arr[2];
222  unset($url_arr);
223 
224  if (!$xoops->module || !$xoops->module->getVar('isactive')) {
225  $xoops->redirect($xoops_url, 3, XoopsLocale::E_NO_MODULE);
226  exit();
227  }
228  $moduleperm_handler = $xoops->getHandlerGroupperm();
229  if ($xoops->isUser()) {
230  if (!$moduleperm_handler->checkRight('module_read', $xoops->module->getVar('mid'), $xoops->user->getGroups())) {
231  $xoops->redirect($xoops_url, 1, XoopsLocale::E_NO_ACCESS_PERMISSION, false);
232  }
233  $xoops->userIsAdmin = $xoops->user->isAdmin($xoops->module->getVar('mid'));
234  } else {
235  if (!$moduleperm_handler->checkRight('module_read', $xoops->module->getVar('mid'), FixedGroups::ANONYMOUS)) {
236  $xoops->redirect(
237  $xoops_url . '/user.php?from=' . $xoops->module->getVar('dirname', 'n'),
238  1,
240  );
241  }
242  }
243 
244  if ($xoops->module->getVar('dirname', 'n') != 'system') {
245  $xoops->loadLanguage('main', $xoops->module->getVar('dirname', 'n'));
246  $xoops->loadLocale($xoops->module->getVar('dirname', 'n'));
247  }
248 
249  if ($xoops->module->getVar('hasconfig') == 1
250  || $xoops->module->getVar('hascomments') == 1
251  || $xoops->module->getVar('hasnotification') == 1
252  ) {
253  $xoops->getModuleConfigs();
254  }
255 } else {
256  if ($xoops->isUser()) {
257  $xoops->userIsAdmin = $xoops->user->isAdmin(1);
258  }
259 }
260 
261 $xoopsTpl = $xoops->tpl();
262 $xoTheme = null;
263 $xoopsUser =& $xoops->user;
264 $xoopsModule =& $xoops->module;
265 $xoopsUserIsAdmin =& $xoops->userIsAdmin;
266 $xoopsModuleConfig =& $xoops->moduleConfig;
267 
268 //Creates 'system_modules_active' cache file if it has been deleted.
269 $xoops->getActiveModules();
270 
271 $xoops->events()->triggerEvent('core.include.common.end');
static getLegacyLanguage()
Definition: Abstract.php:76
$xoTheme
Definition: common.php:262
$user_handler
Definition: findusers.php:52
$xoopsModuleConfig
Definition: common.php:266
$xoopsModule
Definition: common.php:264
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$_SERVER['REQUEST_URI']
$xoopsTpl
Definition: xoops_code.php:45
if(!class_exists('XoopsLoad', false)) global $xoops
Definition: common.php:26
exit
Definition: browse.php:104
static bootstrapTransition()
$xoopsUserIsAdmin
Definition: common.php:265
$xFrameOptions
Definition: common.php:153
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
if($xoops->getConfig('closesite')==1) $xoops_url
Definition: common.php:215
$xoopsUser
Definition: common.php:263
static fileExists($file)
Definition: xoopsload.php:506
$xoopsLogger
Definition: common.php:68
defined('NWLINE') or define('NWLINE' n
Definition: common.php:42
const E_NO_MODULE
Definition: en_US.php:353
static get($name)
static getTimezone()
Definition: Abstract.php:84
global $xoopsDB
Definition: common.php:36
if(!$xoops->isUser()) $uid
Definition: index.php:31
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$psr4loader
Definition: common.php:75
$GLOBALS['xoops']
Definition: common.php:33
$criteria
$module_handler
Definition: main.php:55
if(isset($delayedWarning))
Definition: common.php:116
$xoopsSecurity
Definition: common.php:85
$moduleperm_handler
Definition: cp_header.php:31
$member_handler
Definition: common.php:177
$xoopsConfig
Definition: common.php:130
$xoops option
Definition: common.php:63