XOOPS  2.6.0
preload.php
Go to the documentation of this file.
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 
14 
28 {
29  private static $registry = array();
30 
31  private static $configs = null;
32 
38  private static function getConfigs()
39  {
41  if (array_key_exists('monolog_default_configs', self::$configs)
42  && self::$configs['monolog_default_configs'] == true) {
43  self::$configs = $xoops->getModuleConfigs('monolog');
44  }
45  /*
46  if (!array_key_exists('phpfire_enable', self::$configs)) {
47  $user_groups = $xoops->getUserGroups();
48  $moduleperm_handler = $xoops->getHandlerGroupperm();
49  $helper = $xoops->getModuleHelper('monolog');
50  $mid = $helper->getModule()->getVar('mid');
51  self::$configs['phpfire_enable'] = false;
52 
53  if ($moduleperm_handler->checkRight('use_monolog', 0, $user_groups, $mid)) {
54  // only other settings are in user config
55  $uchelper = $xoops->getModuleHelper('userconfigs');
56  if ($xoops->isUser() && $uchelper) {
57  $config_handler = $uchelper->getHandlerConfig();
58  $user_configs =
59  $config_handler->getConfigsByUser($xoops->user->getVar('uid'), $mid);
60  if (array_key_exists('phpfire_enable', $user_configs)) {
61  self::$configs['phpfire_enable'] = $user_configs['phpfire_enable'];
62  }
63  }
64  } else {
65  // user has no permissions, turn everything off
66  self::$configs['phpfire_enable'] = false;
67  }
68  }
69  */
70 
71  return self::$configs;
72  }
73 
81  public static function eventCoreException($e)
82  {
83  MonologLogger::getInstance()->addException($e);
84  }
85 
93  public static function eventCoreIncludeCommonClassmaps($args)
94  {
95  $path = dirname(__DIR__);
96  XoopsLoad::addMap(array(
97  'monologlogger' => $path . '/class/monologlogger.php',
98  ));
99  }
100 
108  public static function eventCoreIncludeCommonSecurity($args)
109  {
110  $cache = \Xoops::getInstance()->cache();
111  $key = 'system/module/configs/monolog';
112 
113  self::$configs=array();
114  self::$configs['monolog_enable'] = false;
115  self::$configs['monolog_default_configs']=true;
116 
117  // we will not regenerate this on a miss - will wait until auth is complete
118  $monolog_configs = $cache->read($key);
119  if ($monolog_configs!==false) {
120  self::$configs = $monolog_configs;
121  }
122  $logger = MonologLogger::getInstance();
123 
124  if (self::$configs['monolog_enable']) {
125  $logger->setConfigs(self::$configs);
126  $logger->enable();
127  } else {
128  // turn everything off
129  self::$configs['include_blocks'] = false;
130  self::$configs['include_deprecated'] = false;
131  self::$configs['include_extra'] = false;
132  self::$configs['include_queries'] = false;
133  self::$configs['include_timers'] = false;
134  $logger->setConfigs(self::$configs);
135  }
136  $logger->startTime();
137  $logger->startTime('XOOPS Boot');
138  }
139 
147  public static function eventCoreDatabaseNoconn($args)
148  {
149  if (class_exists('MonologLogger')) {
150  /* @var $db Xoops\Core\Database\Connection */
151  $db = $args[0];
152  MonologLogger::getInstance()->log(LogLevel::ALERT, $db->error(), array('errno' => $db->errno()));
153  }
154  }
155 
163  public static function eventCoreDatabaseNodb($args)
164  {
165  if (class_exists('MonologLogger')) {
166  /* @var $db Xoops\Core\Database\Connection */
167  $db = $args[0];
168  MonologLogger::getInstance()->log(LogLevel::ALERT, $db->error(), array('errno' => $db->errno()));
169  }
170  }
171 
179  public static function eventCoreDatabaseQueryComplete($args)
180  {
181  $sql = $args['sql'];
182  $context = array(
183  'channel'=>'Queries',
184  'query_time'=>$args['executionMS'],
185  'params'=>$args['params'],
186  'types'=>$args['types'],
187  );
188 
189  MonologLogger::getInstance()->log(LogLevel::INFO, $sql, $context);
190  }
191 
199  public static function eventCoreIncludeCommonConfigsSuccess($args)
200  {
202  $xoops->loadLocale();
203  $xoops->loadLanguage('main', 'monolog');
204  }
205 
211  public static function eventCoreIncludeCommonAuthSuccess()
212  {
213  $logger = MonologLogger::getInstance();
214  $configs = self::getConfigs();
215  $logger->setConfigs($configs);
216  if ($configs['monolog_enable']) {
217  $logger->enable();
218  } else {
219  $logger->disable();
220  }
221  }
222 
230  public static function eventCoreIncludeCommonEnd($args)
231  {
232  $logger = MonologLogger::getInstance();
233  $logger->stopTime('XOOPS Boot');
234  $logger->startTime('Module init');
235  }
236 
244  public static function eventCoreTemplateConstructStart($args)
245  {
246  /*
247  $tpl = $args[0];
248 
249  $configs = self::getConfigs();
250  if ($configs['debugbar_enable']) {
251  $tpl->debugging_ctrl = 'URL';
252  }
253  if ($configs['debug_smarty_enable']) {
254  $tpl->debugging = true;
255  }
256  */
257  }
258 
266  public static function eventCoreThemeRenderStart($args)
267  {
268  MonologLogger::getInstance()->startTime('Page rendering');
269  }
270 
278  public static function eventCoreThemeRenderEnd($args)
279  {
280  MonologLogger::getInstance()->stopTime('Page rendering');
281  }
282 
290  public static function eventCoreThemeCheckcacheSuccess($args)
291  {
292  $template = $args[0];
293  $theme = $args[1];
294  MonologLogger::getInstance()->addExtra(
295  $template,
296  sprintf('Cached (regenerates every %d seconds)', $theme->contentCacheLifetime)
297  );
298  }
299 
307  public static function eventCoreThemeblocksBuildblockStart($args)
308  {
309  /* @var $block XoopsBlock */
310  $block = $args[0];
311  $isCached= $args[1];
312  $context = array('channel'=>'Blocks', 'cached'=>$isCached, 'cachetime'=>$block->getVar('bcachetime'));
313  MonologLogger::getInstance()->log(LogLevel::INFO, $block->getVar('name'), $context);
314 
315  }
316 
324  public static function eventCoreDeprecated($args)
325  {
326  $message = $args[0];
327  MonologLogger::getInstance()->log(LogLevel::WARNING, $message, array('channel'=>'Deprecated'));
328  }
329 
337  public static function eventCoreDisableerrorreporting($args)
338  {
339  MonologLogger::getInstance()->disable();
340  }
341 
349  public static function eventCoreHeaderStart($args)
350  {
351  $logger = MonologLogger::getInstance();
352  $logger->stopTime('Module init');
353  $logger->startTime('XOOPS output init');
354  }
355 
363  public static function eventCoreHeaderEnd($args)
364  {
365  $logger = MonologLogger::getInstance();
366  $logger->stopTime('XOOPS output init');
367  $logger->startTime('Module display');
368  }
369 
377  public static function eventCoreFooterStart($args)
378  {
379  $logger = MonologLogger::getInstance();
380  $logger->stopTime('Module display');
381  $logger->addExtra(
383  sprintf(
385  (float) memory_get_usage(true)/1000000,
386  (float) memory_get_peak_usage(true)/1000000
387  )
388  );
389  $logger->addExtra(
391  sprintf(_MD_MONOLOG_FILES, count(get_included_files()))
392  );
393  $logger->stopTime();
394  }
395 
403  public static function eventCoreFooterEnd($args)
404  {
405  //$logger = MonologLogger::getInstance();
406 
407  //$logger->stopTime();
408  }
409 
417  public static function eventCoreSecurityValidatetokenEnd($args)
418  {
419  $logger = MonologLogger::getInstance();
420  $logs = $args[0];
421  foreach ($logs as $log) {
422  $context = array('channel'=>'Extra', 'name'=>$log[0]);
423  $logger->log(LogLevel::INFO, $log[1], $context);
424  }
425  }
426 
434  public static function eventCoreModuleAddlog($args)
435  {
436  $context = array('channel'=>'Extra', 'name'=>$args[0]);
437  MonologLogger::getInstance()->log(LogLevel::DEBUG, $args[1], $context);
438 
439  }
440 
448  public static function eventSystemPreferencesSave($args)
449  {
450  $configs = array();
451  $cache = \Xoops::getInstance()->cache();
452  $key = 'system/module/configs/monolog';
453 
454  if (isset($_REQUEST['monolog_enable'])) {
455  $cache->delete($key);
456 
457  $helper = \Xoops::getInstance()->getModuleHelper('monolog');
458  $configs['monolog_enable'] = (bool) $helper->getConfig('monolog_enable');
459  $configs['include_blocks'] = (bool) $helper->getConfig('include_blocks');
460  $configs['include_deprecated'] = (bool) $helper->getConfig('include_deprecated');
461  $configs['include_extra'] = (bool) $helper->getConfig('include_extra');
462  $configs['include_queries'] = (bool) $helper->getConfig('include_queries');
463  $configs['include_timers'] = (bool) $helper->getConfig('include_timers');
464  $configs['logging_threshold'] = $helper->getConfig('logging_threshold');
465  $configs['log_file_path'] = $helper->getConfig('log_file_path');
466  $configs['max_versions'] = (int) $helper->getConfig('max_versions');
467 
468  $cache->write($key, $configs);
469  }
470 
471  }
472 }
static eventCoreHeaderEnd($args)
Definition: preload.php:363
static eventCoreModuleAddlog($args)
Definition: preload.php:434
$path
Definition: execute.php:31
const _MD_MONOLOG_MEM_USAGE
Definition: main.php:22
static eventCoreFooterEnd($args)
Definition: preload.php:403
static getInstance()
Definition: Xoops.php:160
static eventCoreHeaderStart($args)
Definition: preload.php:349
static eventCoreDatabaseQueryComplete($args)
Definition: preload.php:179
static eventCoreThemeRenderStart($args)
Definition: preload.php:266
static eventCoreDatabaseNoconn($args)
Definition: preload.php:147
static eventSystemPreferencesSave($args)
Definition: preload.php:448
const _MD_MONOLOG_INCLUDED_FILES
Definition: main.php:20
static eventCoreDatabaseNodb($args)
Definition: preload.php:163
static eventCoreThemeCheckcacheSuccess($args)
Definition: preload.php:290
$xoops
Definition: admin.php:25
const _MD_MONOLOG_FILES
Definition: main.php:21
static eventCoreThemeblocksBuildblockStart($args)
Definition: preload.php:307
static eventCoreFooterStart($args)
Definition: preload.php:377
static $configs
Definition: preload.php:31
static eventCoreIncludeCommonSecurity($args)
Definition: preload.php:108
static eventCoreSecurityValidatetokenEnd($args)
Definition: preload.php:417
static eventCoreDisableerrorreporting($args)
Definition: preload.php:337
const _MD_MONOLOG_MEMORY
Definition: main.php:23
static getConfigs()
Definition: preload.php:38
static eventCoreIncludeCommonAuthSuccess()
Definition: preload.php:211
static eventCoreThemeRenderEnd($args)
Definition: preload.php:278
$configs
Definition: config.php:27
static eventCoreDeprecated($args)
Definition: preload.php:324
$sql
Definition: pda.php:32
$helper
const WARNING
Definition: install.php:39
static eventCoreTemplateConstructStart($args)
Definition: preload.php:244
static eventCoreIncludeCommonEnd($args)
Definition: preload.php:230
static eventCoreIncludeCommonConfigsSuccess($args)
Definition: preload.php:199
static eventCoreException($e)
Definition: preload.php:81
static $registry
Definition: preload.php:29
static getInstance()
static addMap(array $map)
Definition: xoopsload.php:40
static eventCoreIncludeCommonClassmaps($args)
Definition: preload.php:93