source: trunk/plugins/event_tracer/main.inc.php @ 1907

Last change on this file since 1907 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
File size: 2.4 KB
Line 
1<?php /*
2Plugin Name: Event tracer
3Version: 1.0
4Description: For developers. Shows all calls to trigger_event.
5Plugin URI: http://www.phpwebgallery.net
6Author: PhpWebGallery team
7Author URI: http://www.phpwebgallery.net
8*/
9if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
10
11class EventTracer
12{
13  var $me_working;
14  var $my_config;
15 
16  function EventTracer()
17  {
18    $this->me_working=0;
19  }
20
21  function load_config()
22  {
23    $x = @file_get_contents( dirname(__FILE__).'/data.dat' );
24    if ($x!==false)
25    {
26      $c = unserialize($x);
27      // do some more tests here
28      $this->my_config = $c;
29    }
30    if ( !isset($this->my_config)
31        or empty($this->my_config['filters']) )
32    {
33      $this->my_config['filters'] = array( '.*' );
34      $this->my_config['show_args'] = false;
35      $this->save_config();
36    }
37  }
38
39  function save_config()
40  {
41    $file = fopen( dirname(__FILE__).'/data.dat', 'w' );
42    fwrite($file, serialize($this->my_config) );
43    fclose( $file );
44  }
45
46  function on_pre_trigger_event($event_info)
47  {
48    $this->dump('pre_trigger_event', $event_info);
49  }
50  function on_post_trigger_event($event_info)
51  {
52    $this->dump('post_trigger_event', $event_info);
53  }
54
55  function on_trigger_action($event_info)
56  {
57    $this->dump('trigger_action', $event_info);
58  }
59
60  function dump($event, $event_info)
61  {
62    foreach( $this->my_config['filters'] as $filter)
63    {
64      if ( preg_match( '/'.$filter.'/', $event_info['event'] ) )
65      {
66        if ($this->my_config['show_args'])
67        {
68          $s = '<pre>';
69          $s .= htmlspecialchars( var_export( $event_info['data'], true ) );
70          $s .= '</pre>';
71        }
72        else
73          $s = '';
74        pwg_debug($event.' "'.$event_info['event'].'" '.($s) );
75        break;
76      }
77    }
78  }
79
80  function plugin_admin_menu($menu)
81  {
82    array_push($menu,
83        array(
84          'NAME' => 'Event Tracer',
85          'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php')
86        )
87      );
88    return $menu;
89  }
90}
91
92$obj = new EventTracer();
93$obj->load_config();
94
95add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
96add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') );
97add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') );
98add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') );
99set_plugin_data($plugin['id'], $obj);
100?>
Note: See TracBrowser for help on using the repository browser.