1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\PreloadItem;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class LoggerPreload extends PreloadItem
28: {
29: 30: 31: 32: 33:
34: private static function getConfigs()
35: {
36: static $configs = null;
37:
38: if (is_null($configs)) {
39: $xoops = Xoops::getInstance();
40: $user_groups = $xoops->getUserGroups();
41: $moduleperm_handler = $xoops->getHandlerGroupPermission();
42: $helper = $xoops->getModuleHelper('logger');
43: $mid = $helper->getModule()->getVar('mid');
44: if ($moduleperm_handler->checkRight('use_logger', 0, $user_groups, $mid)) {
45:
46: $configs['logger_enable'] = $helper->getConfig('logger_enable');
47: $configs['logger_popup'] = $helper->getConfig('logger_popup');
48: $configs['debug_smarty_enable'] = $helper->getConfig('debug_smarty_enable');
49:
50: $uchelper = $xoops->getModuleHelper('userconfigs');
51: if ($xoops->isUser() && $uchelper) {
52: $config_handler = $uchelper->getHandlerConfig();
53: $user_configs =
54: $config_handler->getConfigsByUser($xoops->user->getVar('uid'), $mid);
55: if (array_key_exists('logger_enable', $user_configs)) {
56: $configs['logger_enable'] = $user_configs['logger_enable'];
57: }
58: if (array_key_exists('logger_popup', $user_configs)) {
59: $configs['logger_popup'] = $user_configs['logger_popup'];
60: }
61: if (array_key_exists('debug_smarty_enable', $user_configs)) {
62: $configs['debug_smarty_enable'] = $user_configs['debug_smarty_enable'];
63: }
64: }
65: } else {
66:
67: $configs['logger_enable'] = 0;
68: $configs['logger_popup'] = 0;
69: $configs['debug_smarty_enable'] = 0;
70: }
71: }
72:
73: return $configs;
74: }
75:
76: 77: 78: 79: 80: 81: 82:
83: public static function eventCoreException($e)
84: {
85: LegacyLogger::getInstance()->addException($e);
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95:
96: public static function eventCoreIncludeCommonClassmaps($args)
97: {
98: $path = dirname(__DIR__);
99: XoopsLoad::addMap(array(
100: 'legacylogger' => $path . '/class/legacylogger.php',
101: ));
102: }
103:
104: 105: 106: 107: 108: 109: 110:
111: public static function eventCoreIncludeCommonStart($args)
112: {
113: if (class_exists('LegacyLogger')) {
114: LegacyLogger::getInstance()->enable();
115: LegacyLogger::getInstance()->startTime();
116: LegacyLogger::getInstance()->startTime('XOOPS Boot');
117: }
118: }
119:
120: 121: 122: 123: 124: 125: 126:
127: public static function eventCoreDatabaseNoconn($args)
128: {
129: if (!class_exists('LegacyLogger')) {
130: return;
131: }
132:
133: $db = $args[0];
134: LegacyLogger::getInstance()->addQuery('', $db->error(), $db->errno());
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: public static function eventCoreDatabaseNodb($args)
145: {
146: if (!class_exists('LegacyLogger')) {
147: return;
148: }
149:
150: $db = $args[0];
151: LegacyLogger::getInstance()->addQuery('', $db->error(), $db->errno());
152: }
153:
154: 155: 156: 157: 158: 159: 160:
161: public static function eventCoreDatabaseQueryComplete($args)
162: {
163: $sql = $args['sql'];
164:
165: LegacyLogger::getInstance()->addQuery($sql, null, null, $args['executionMS']);
166: }
167:
168: 169: 170: 171: 172: 173: 174:
175: public static function eventCoreIncludeCommonConfigsSuccess($args)
176: {
177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188:
189: }
190:
191: 192: 193: 194: 195:
196: public static function eventCoreIncludeCommonAuthSuccess()
197: {
198: $xoops = Xoops::getInstance();
199: $logger = LegacyLogger::getInstance();
200: $configs = self::getConfigs();
201: if ($configs['logger_enable']) {
202: $xoops->loadLocale();
203: $xoops->loadLanguage('main', 'logger');
204: $logger->setConfigs($configs);
205: $logger->enable();
206: } else {
207: $logger->disable();
208: }
209: }
210:
211: 212: 213: 214: 215: 216: 217:
218: public static function eventCoreIncludeCommonEnd($args)
219: {
220: $logger = LegacyLogger::getInstance();
221: $logger->stopTime('XOOPS Boot');
222: $logger->startTime('Module init');
223: }
224:
225: 226: 227: 228: 229: 230: 231:
232: public static function eventCoreTemplateConstructStart($args)
233: {
234: $tpl = $args[0];
235: $configs = self::getConfigs();
236: if ($configs['logger_enable']) {
237: $tpl->debugging_ctrl = 'URL';
238: }
239: if ($configs['debug_smarty_enable']) {
240: $tpl->debugging = true;
241: }
242: }
243:
244: 245: 246: 247: 248: 249: 250:
251: public static function eventCoreThemeRenderStart($args)
252: {
253: LegacyLogger::getInstance()->startTime('Page rendering');
254: }
255:
256: 257: 258: 259: 260: 261: 262:
263: public static function eventCoreThemeRenderEnd($args)
264: {
265: LegacyLogger::getInstance()->stopTime('Page rendering');
266: }
267:
268: 269: 270: 271: 272: 273: 274:
275: public static function eventCoreThemeCheckcacheSuccess($args)
276: {
277: $template = $args[0];
278: $theme = $args[1];
279: LegacyLogger::getInstance()
280: ->addExtra($template, sprintf('Cached (regenerates every %d seconds)', $theme->contentCacheLifetime));
281: }
282:
283: 284: 285: 286: 287: 288: 289:
290: public static function eventCoreThemeblocksBuildblockStart($args)
291: {
292:
293: $block = $args[0];
294: $isCached= $args[1];
295: LegacyLogger::getInstance()->addBlock($block->getVar('name'), $isCached, $block->getVar('bcachetime'));
296: }
297:
298: 299: 300: 301: 302: 303: 304:
305: public static function eventCoreDeprecated($args)
306: {
307: $message = $args[0];
308: LegacyLogger::getInstance()->addDeprecated($message);
309: }
310:
311: 312: 313: 314: 315: 316: 317:
318: public static function eventCoreDisableerrorreporting($args)
319: {
320: LegacyLogger::getInstance()->disable();
321: }
322:
323: 324: 325: 326: 327: 328: 329:
330: public static function eventCoreHeaderStart($args)
331: {
332: $logger = LegacyLogger::getInstance();
333: $logger->stopTime('Module init');
334: $logger->startTime('XOOPS output init');
335: }
336:
337: 338: 339: 340: 341: 342: 343:
344: public static function eventCoreHeaderEnd($args)
345: {
346: $logger = LegacyLogger::getInstance();
347: $logger->stopTime('XOOPS output init');
348: $logger->startTime('Module display');
349: }
350:
351: 352: 353: 354: 355: 356: 357:
358: public static function eventCoreFooterStart($args)
359: {
360: $logger = LegacyLogger::getInstance();
361: $logger->stopTime('Module display');
362: }
363:
364: 365: 366: 367: 368: 369: 370:
371: public static function eventCoreFooterEnd($args)
372: {
373: $logger = LegacyLogger::getInstance();
374: $logger->stopTime();
375: }
376:
377: 378: 379: 380: 381: 382: 383:
384: public static function eventCoreIncludeFunctionsRedirectheaderEnd($args)
385: {
386: $xoops = Xoops::getInstance();
387: $logger = LegacyLogger::getInstance();
388: $debug_mode = $xoops->getModuleConfig('debug_mode', 'logger');
389: if ($debug_mode == 2) {
390:
391:
392: $xoops->tpl()->assign('xoops_logdump', $logger->dump());
393: }
394: }
395:
396: 397: 398: 399: 400: 401: 402:
403: public static function eventCoreSecurityValidatetokenEnd($args)
404: {
405: $logger = LegacyLogger::getInstance();
406: $logs = $args[0];
407: foreach ($logs as $log) {
408: $logger->addExtra($log[0], $log[1]);
409: }
410: }
411:
412: 413: 414: 415: 416: 417: 418:
419: public static function eventCoreModuleAddlog($args)
420: {
421: LegacyLogger::getInstance()->addExtra($args[0], $args[1]);
422: }
423:
424: 425: 426: 427: 428: 429: 430:
431: public static function eventSystemPreferencesSave($args)
432: {
433: XoopsLoad::addMap(array('legacylogger' => dirname(__DIR__) . '/class/legacylogger.php'));
434: }
435: }
436: