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 
29 {
30  private static $registry = array();
31 
37  private static function getConfigs()
38  {
39  static $configs = null;
40 
41  if (is_null($configs)) {
43  $user_groups = $xoops->getUserGroups();
44  $moduleperm_handler = $xoops->getHandlerGroupperm();
45  $helper = $xoops->getModuleHelper('debugbar');
46  $mid = $helper->getModule()->getVar('mid');
47  if ($moduleperm_handler->checkRight('use_debugbar', 0, $user_groups, $mid)) {
48  // get default settings
49  $configs['debugbar_enable'] = $helper->getConfig('debugbar_enable');
50  $configs['debug_smarty_enable'] = $helper->getConfig('debug_smarty_enable');
51  // override with settings
52  $uchelper = $xoops->getModuleHelper('userconfigs');
53  if ($xoops->isUser() && $uchelper) {
54  $config_handler = $uchelper->getHandlerConfig();
55  $user_configs =
56  $config_handler->getConfigsByUser($xoops->user->getVar('uid'), $mid);
57  if (array_key_exists('debugbar_enable', $user_configs)) {
58  $configs['debugbar_enable'] = $user_configs['debugbar_enable'];
59  }
60  if (array_key_exists('debug_smarty_enable', $user_configs)) {
61  $configs['debug_smarty_enable'] = $user_configs['debug_smarty_enable'];
62  }
63  }
64  } else {
65  // user has no permissions, turn everything off
66  $configs['debugbar_enable'] = 0;
67  $configs['debug_smarty_enable'] = 0;
68  }
69  }
70 
71  return $configs;
72  }
73 
81  public static function eventCoreException($e)
82  {
83  DebugbarLogger::getInstance()->addException($e);
84  }
85 
93  public static function eventCoreIncludeCommonClassmaps($args)
94  {
95  $path = dirname(__DIR__);
96  XoopsLoad::addMap(array(
97  'debugbarlogger' => $path . '/class/debugbarlogger.php',
98  ));
99  }
100 
108  public static function eventCoreIncludeCommonStart($args)
109  {
110  $logger = DebugbarLogger::getInstance();
111 
112  $logger->enable();//until we get a db connection debug is enabled
113  //if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
114  // $logger->getDebugbar()['time']->addMeasure('Loading', $_SERVER['REQUEST_TIME_FLOAT'], microtime(true));
115  //}
116  $logger->startTime();
117  $logger->startTime('XOOPS Boot');
118  }
119 
127  public static function eventCoreDatabaseNoconn($args)
128  {
129  if (class_exists('DebugbarLogger')) {
130  /* @var $db Xoops\Core\Database\Connection */
131  $db = $args[0];
132  DebugbarLogger::getInstance()->log(LogLevel::ALERT, $db->error(), array('errno' => $db->errno()));
133  }
134  }
135 
143  public static function eventCoreDatabaseNodb($args)
144  {
145  if (class_exists('DebugbarLogger')) {
146  /* @var $db Xoops\Core\Database\Connection */
147  $db = $args[0];
148  DebugbarLogger::getInstance()->log(LogLevel::ALERT, $db->error(), array('errno' => $db->errno()));
149  }
150  }
151 
157  public static function eventCoreIncludeCommonAuthSuccess()
158  {
160  $logger = DebugbarLogger::getInstance();
161  $configs = self::getConfigs();
162  if ($configs['debugbar_enable']) {
163  $xoops->loadLocale();
164  $xoops->loadLanguage('main', 'debugbar');
165  $logger->enable();
166  } else {
167  $logger->disable();
168  }
169  }
170 
178  public static function eventCoreIncludeCommonEnd($args)
179  {
180  $logger = DebugbarLogger::getInstance();
181  $logger->stopTime('XOOPS Boot');
182  $logger->startTime('Module init');
183  }
184 
192  public static function eventCoreTemplateConstructStart($args)
193  {
194  $tpl = $args[0];
195  $configs = self::getConfigs();
196  if ($configs['debugbar_enable']) {
197  $tpl->debugging_ctrl = 'URL';
198  }
199  if ($configs['debug_smarty_enable']) {
200  $tpl->debugging = true;
201  }
202  }
203 
211  public static function eventCoreThemeRenderStart($args)
212  {
213  DebugbarLogger::getInstance()->startTime('Page rendering');
214  }
215 
223  public static function eventCoreThemeRenderEnd($args)
224  {
225  DebugbarLogger::getInstance()->stopTime('Page rendering');
226  DebugbarLogger::getInstance()->addSmarty();
227  }
228 
236  public static function eventCoreThemeCheckcacheSuccess($args)
237  {
238  $template = $args[0];
239  $theme = $args[1];
240  DebugbarLogger::getInstance()->addExtra(
241  $template,
242  sprintf('Cached (regenerates every %d seconds)', $theme->contentCacheLifetime)
243  );
244  }
245 
253  public static function eventCoreThemeblocksBuildblockStart($args)
254  {
255  /* @var $block XoopsBlock */
256  $block = $args[0];
257  $isCached= $args[1];
258  //Logger::getInstance()->addBlock($block->getVar('name'), $isCached, $block->getVar('bcachetime'));
259  $context = array('channel'=>'Blocks', 'cached'=>$isCached, 'cachetime'=>$block->getVar('bcachetime'));
260  DebugbarLogger::getInstance()->log(LogLevel::INFO, $block->getVar('name'), $context);
261 
262  }
263 
271  public static function eventCoreDeprecated($args)
272  {
273  $message = $args[0];
274  DebugbarLogger::getInstance()->log(LogLevel::WARNING, $message, array('channel'=>'Deprecated'));
275  }
276 
284  public static function eventCoreDisableerrorreporting($args)
285  {
286  DebugbarLogger::getInstance()->disable();
287  }
288 
296  public static function eventCoreHeaderStart($args)
297  {
298  $logger = DebugbarLogger::getInstance();
299  $logger->stopTime('Module init');
300  $logger->startTime('XOOPS output init');
301  }
302 
310  public static function eventCoreHeaderEnd($args)
311  {
312  $logger = DebugbarLogger::getInstance();
313  $logger->stopTime('XOOPS output init');
314  $logger->startTime('Module display');
315  }
316 
324  public static function eventCoreFooterStart($args)
325  {
326  $logger = DebugbarLogger::getInstance();
327  $logger->stopTime('Module display');
328  }
329 
337  public static function eventCoreFooterEnd($args)
338  {
339  $logger = DebugbarLogger::getInstance();
340  $logger->stopTime();
341  }
342 
350  public static function eventCoreIncludeFunctionsRedirectheaderStart($args)
351  {
352  DebugbarLogger::getInstance()->stackData();
353  }
354 
362  public static function eventCoreSecurityValidatetokenEnd($args)
363  {
364  $logger = DebugbarLogger::getInstance();
365  $logs = $args[0];
366  foreach ($logs as $log) {
367  $context = array('channel'=>'Extra', 'name'=>$log[0]);
368  $logger->log(LogLevel::INFO, $log[1], $context);
369  }
370  }
371 
379  public static function eventCoreModuleAddlog($args)
380  {
381  $context = array('channel'=>'Extra', 'name'=>$args[0]);
382  DebugbarLogger::getInstance()->log(LogLevel::DEBUG, $args[1], $context);
383 
384  }
385 
393  public static function eventDebugLog($args)
394  {
395  DebugbarLogger::getInstance()->dump($args);
396  }
397 
405  public static function eventDebugTimerStart($args)
406  {
407  DebugbarLogger::getInstance()->startTime($args[0], $args[1]);
408  }
409 
417  public static function eventDebugTimerStop($args)
418  {
419  DebugbarLogger::getInstance()->stopTime($args);
420  }
421 }
$mid
Definition: index.php:39
$tpl
Definition: backend.php:39
$path
Definition: execute.php:31
static eventCoreDisableerrorreporting($args)
Definition: preload.php:284
static getInstance()
Definition: Xoops.php:160
static eventCoreTemplateConstructStart($args)
Definition: preload.php:192
static eventCoreIncludeCommonClassmaps($args)
Definition: preload.php:93
static eventCoreDatabaseNoconn($args)
Definition: preload.php:127
static eventCoreThemeRenderEnd($args)
Definition: preload.php:223
static getInstance()
static eventCoreIncludeCommonAuthSuccess()
Definition: preload.php:157
static eventDebugLog($args)
Definition: preload.php:393
static eventDebugTimerStart($args)
Definition: preload.php:405
$xoops
Definition: admin.php:25
static eventCoreHeaderEnd($args)
Definition: preload.php:310
static eventCoreDatabaseNodb($args)
Definition: preload.php:143
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
static eventCoreHeaderStart($args)
Definition: preload.php:296
$configs
Definition: config.php:27
static eventCoreSecurityValidatetokenEnd($args)
Definition: preload.php:362
static getConfigs()
Definition: preload.php:37
static eventCoreFooterStart($args)
Definition: preload.php:324
static $registry
Definition: preload.php:30
$helper
const WARNING
Definition: install.php:39
static eventCoreIncludeFunctionsRedirectheaderStart($args)
Definition: preload.php:350
static eventDebugTimerStop($args)
Definition: preload.php:417
static eventCoreException($e)
Definition: preload.php:81
static eventCoreThemeRenderStart($args)
Definition: preload.php:211
static eventCoreIncludeCommonEnd($args)
Definition: preload.php:178
static eventCoreThemeCheckcacheSuccess($args)
Definition: preload.php:236
static eventCoreIncludeCommonStart($args)
Definition: preload.php:108
static eventCoreFooterEnd($args)
Definition: preload.php:337
static eventCoreThemeblocksBuildblockStart($args)
Definition: preload.php:253
$moduleperm_handler
Definition: cp_header.php:31
static addMap(array $map)
Definition: xoopsload.php:40
static eventCoreModuleAddlog($args)
Definition: preload.php:379
static eventCoreDeprecated($args)
Definition: preload.php:271