1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
/** |
12
|
|
|
* userlog module |
13
|
|
|
* |
14
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
15
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
16
|
|
|
* @package userlog include |
17
|
|
|
* @since 1 |
18
|
|
|
* @author irmtfan ([email protected]) |
19
|
|
|
* @author XOOPS Project <www.xoops.org> <www.xoops.ir> |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
23
|
|
|
// to insure include only once |
24
|
|
|
if (defined('USERLOG_LOG_DEFINED')) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
define('USERLOG_LOG_DEFINED', true); |
28
|
|
|
|
29
|
|
|
require_once __DIR__ . '/common.php'; |
30
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
31
|
|
|
$userlog = Userlog::getInstance(); |
32
|
|
|
if (!$userlog->getConfig('status')) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
$logsetObj = UserlogSetting::getInstance(); |
36
|
|
|
$statsObj = UserlogStats::getInstance(); |
37
|
|
|
$setting = $scope = ''; |
38
|
|
|
list($setting, $scope) = $logsetObj->getSet(); |
39
|
|
|
|
40
|
|
|
// if there is a setting and setting is active |
41
|
|
|
if (!empty($setting) && strpos($setting, 'active')) { |
42
|
|
|
// check scope |
43
|
|
|
if (!empty($scope)) { // empty scope means ALL |
44
|
|
|
$scope_arr = explode(',', $scope); |
45
|
|
|
// if this URI is not in scope return |
46
|
|
|
if (!in_array($userlog->getLogModule()->dirname(), $scope_arr)) { |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// get log values |
52
|
|
|
$tolog = $logsetObj->getOptions($setting, 'value'); |
53
|
|
|
// check if all values are empty |
54
|
|
|
if (empty($tolog)) { |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// if there is referer option inside/outside |
59
|
|
|
if ((empty($tolog['outside']) || empty($tolog['inside'])) && !empty($_SERVER['HTTP_REFERER'])) { |
60
|
|
|
// if referer is outside |
61
|
|
|
if (false === strpos($_SERVER['HTTP_REFERER'], XOOPS_URL)) { |
62
|
|
|
if (empty($tolog['outside'])) { |
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
} else { |
66
|
|
|
if (empty($tolog['inside'])) { |
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
if ('system-root' === $userlog->getLogModule()->dirname()) { |
72
|
|
|
$userlog->getLogModule()->setVar('dirname', 'system'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// create log |
76
|
|
|
$logObj = $userlog->getHandler('log')->create(); |
77
|
|
|
|
78
|
|
|
// store: 0,1->db 2->file 3->both |
|
|
|
|
79
|
|
|
$logObj->store = !empty($tolog['store_db']) ? $tolog['store_db'] : 0; |
80
|
|
|
if (!empty($tolog['store_file'])) { |
81
|
|
|
$logObj->store += $tolog['store_file'] * 2; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// logger |
85
|
|
|
if (!empty($tolog['logger'])) { |
86
|
|
|
xoops_loadLanguage('logger'); |
87
|
|
|
$GLOBALS['xoopsLogger']->activated = true; |
88
|
|
|
//$GLOBALS['xoopsLogger']->enableRendering(); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// set item in db for views |
92
|
|
|
if (!empty($tolog['views'])) { |
93
|
|
|
$logObj->setVar('script', $tolog['script']); |
94
|
|
|
$logObj->setItem(); |
95
|
|
|
// add to save for file |
96
|
|
|
$tolog['item_name'] = $logObj->item_name(); |
97
|
|
|
$tolog['item_id'] = $logObj->item_id(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// remove used settings that should not be logged |
101
|
|
|
unset($tolog['active'], $tolog['inside'], $tolog['outside'], $tolog['unset_pass'], $tolog['store_db'], $tolog['store_file'], $tolog['views']); |
102
|
|
|
|
103
|
|
|
// store log |
104
|
|
|
$logObj->store($tolog, true); |
105
|
|
|
// update all time stats |
106
|
|
|
$statsObj->updateAll('log', $userlog->getConfig('probstats')); // default prob = 10 |
107
|
|
|
} |
108
|
|
|
// update all time stats |
109
|
|
|
$statsObj->updateAll('log', $userlog->getConfig('probstatsallhit')); // default prob = 1 |
110
|
|
|
|
111
|
|
|
// START to log redirects when $xoopsConfig['redirect_message_ajax'] = true |
112
|
|
|
// We need to shift the position of userlog to the top of 'system_modules_active' cache file list. |
113
|
|
|
// because to log redirect pages when $xoopsConfig['redirect_message_ajax'] = true IF eventCoreIncludeFunctionsRedirectheader in system module runs first it will exit() |
114
|
|
|
// IMO It is a bug in XOOPS255/modules/system/preloads/core.php |
115
|
|
|
// IMO exit() should be commented or we should find some way to make sure all eventCoreIncludeFunctionsRedirectheader events will run before any exit(); |
116
|
|
|
/* |
117
|
|
|
if (!headers_sent() && isset($xoopsConfig['redirect_message_ajax']) && $xoopsConfig['redirect_message_ajax']) { |
118
|
|
|
$_SESSION['redirect_message'] = $args[2]; |
119
|
|
|
header("Location: " . preg_replace("/[&]amp;/i", '&', $url)); |
120
|
|
|
exit(); // IMO exit() should be commented |
121
|
|
|
} |
122
|
|
|
*/ |
123
|
|
|
if ($modules_list = XoopsCache::read('system_modules_active')) { |
124
|
|
|
$key = array_search(USERLOG_DIRNAME, $modules_list); |
125
|
|
|
// if userlog is not in the top |
126
|
|
|
if (0 != $key) { |
127
|
|
|
unset($modules_list[$key]); |
128
|
|
|
array_unshift($modules_list, USERLOG_DIRNAME); |
129
|
|
|
XoopsCache::write('system_modules_active', $modules_list); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
// END to log redirects when $xoopsConfig['redirect_message_ajax'] = true |
133
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.