source: tags/build-Alligator02/plugins/event_tracer/main.inc.php @ 26319

Last change on this file since 26319 was 1731, checked in by rvelices, 17 years ago

plugin simplification: adding admin links does not require the plugin_id anymore...

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