source: extensions/ContactForm/classes/cf_log.class.php @ 3748

Last change on this file since 3748 was 3748, checked in by Criss, 15 years ago

Add configuration option to define template variable or not

File size: 2.3 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4class CF_Log {
5  const infos = 'infos';
6  const errors = 'errors';
7  const debug = 'debug';
8  static $messages=array( CF_Log::infos   => array(),
9                          CF_Log::errors  => array(),
10                          CF_Log::debug   => array());
11 
12  static function show_debug() {
13    if (!defined('CF_DEBUG_ACTIVE') or !CF_DEBUG_ACTIVE) {
14      return;
15    }
16   
17    global $template;
18    $template->assign('contact_form_debug', CF_Log::$messages['debug']);
19    $template->set_filenames(array(
20        'contact_form_debug' => realpath(cf_get_template('cf_debug.tpl')),
21      ));
22    $template->assign_var_from_handle('CF_DEBUG', 'contact_form_debug');
23  }
24
25  static function add_debug($variable, $label=null, $append=true) {
26    $value = print_r($variable, true);
27    if (null == $label) {
28      $label = 'CF_Debug';
29    }
30    if (array_key_exists($label, CF_Log::$messages['debug']) && $append) {
31      array_push(CF_Log::$messages['debug'], $value);
32    } else {
33      CF_Log::$messages['debug'][$label] = array($value);
34    }
35  }
36
37  static function reset_messages() {
38    CF_Log::$messages = array(CF_Log::infos  => array(),
39                              CF_Log::errors => array(),
40                              CF_Log::debug  => array());
41  }
42  static function add_error($error) {
43    CF_Log::add_message($error, CF_Log::errors);
44  }
45  static function add_message($message, $type=CF_Log::infos) {
46    switch($type) {
47      case CF_Log::infos:
48      case CF_Log::errors:
49        $prefix = '<span class="cf-log-' . $type . '">';
50        $suffix = '</span>';
51        array_push(CF_Log::$messages[$type], $prefix . $message . $suffix);
52        break;
53      case CF_Log::debug:
54        CF_Log::add_debug($message);
55        break;
56      default:
57        return;
58    }
59  }
60
61  static function show_messages() {
62    global $page;
63    if (count(CF_Log::$messages[CF_Log::infos]) > 0) {
64      $page['infos'] = array_merge($page['infos'],
65                                   CF_Log::$messages[CF_Log::infos]);
66    }
67    if (count(CF_Log::$messages[CF_Log::errors]) > 0) {
68      $page['errors'] = array_merge($page['errors'],
69                                    CF_Log::$messages[CF_Log::errors]);
70    }
71    CF_Log::show_debug();
72    CF_Log::reset_messages();
73  }
74   
75    //<span class="cf-log-saved">
76}
77?>
Note: See TracBrowser for help on using the repository browser.