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

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

plugins last modifications + events are triggered now from picture.php

  • 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()
80  {
81    add_plugin_admin_menu( "Event Tracer", array(&$this, 'do_admin') );
82  }
83
84  function do_admin($my_url)
85  {
86    include( dirname(__FILE__).'/tracer_admin.php' );
87  }
88
89}
90
91$eventTracer = new EventTracer();
92$eventTracer->load_config();
93
94add_event_handler('plugin_admin_menu', array(&$eventTracer, 'plugin_admin_menu') );
95add_event_handler('pre_trigger_event', array(&$eventTracer, 'on_pre_trigger_event') );
96add_event_handler('post_trigger_event', array(&$eventTracer, 'on_post_trigger_event') );
97add_event_handler('trigger_action', array(&$eventTracer, 'on_trigger_action') );
98?>
Note: See TracBrowser for help on using the repository browser.