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

Last change on this file since 2472 was 2342, checked in by rub, 17 years ago

Change some PhpWebGallery to Piwigo. (2/2)

All phpwebgallery.net are not changed!

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 Piwigo team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/*
25Plugin Name: Event tracer
26Version: 1.8.a
27Description: For developers. Shows all calls to trigger_event.
28Plugin URI: http://piwigo.org
29Author: Piwigo team
30Author URI: http://piwigo.org
31*/
32
33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
34
35class EventTracer
36{
37  var $me_working;
38  var $my_config;
39 
40  function EventTracer()
41  {
42    $this->me_working=0;
43  }
44
45  function get_config_file_dir()
46  {
47    global $conf;
48    return $conf['local_data_dir'].'/plugins/';
49  }
50
51  function get_config_file_name()
52  {
53    return basename(dirname(__FILE__)).'.dat';
54  }
55
56  function load_config()
57  {
58    $x = @file_get_contents( $this->get_config_file_dir().$this->get_config_file_name() );
59    if ($x!==false)
60    {
61      $c = unserialize($x);
62      // do some more tests here
63      $this->my_config = $c;
64    }
65    if ( !isset($this->my_config)
66        or empty($this->my_config['filters']) )
67    {
68      $this->my_config['filters'] = array( '.*' );
69      $this->my_config['show_args'] = false;
70      $this->save_config();
71    }
72  }
73
74  function save_config()
75  {
76    $dir = $this->get_config_file_dir();
77    @mkdir($dir);
78    $file = fopen( $dir.$this->get_config_file_name(), 'w' );
79    fwrite($file, serialize($this->my_config) );
80    fclose( $file );
81  }
82
83  function on_pre_trigger_event($event_info)
84  {
85    $this->dump('pre_trigger_event', $event_info);
86  }
87  function on_post_trigger_event($event_info)
88  {
89    $this->dump('post_trigger_event', $event_info);
90  }
91
92  function on_trigger_action($event_info)
93  {
94    $this->dump('trigger_action', $event_info);
95  }
96
97  function dump($event, $event_info)
98  {
99    foreach( $this->my_config['filters'] as $filter)
100    {
101      if ( preg_match( '/'.$filter.'/', $event_info['event'] ) )
102      {
103        if ($this->my_config['show_args'])
104        {
105          $s = '<pre>';
106          $s .= htmlspecialchars( var_export( $event_info['data'], true ) );
107          $s .= '</pre>';
108        }
109        else
110          $s = '';
111        pwg_debug($event.' "'.$event_info['event'].'" '.($s) );
112        break;
113      }
114    }
115  }
116
117  function plugin_admin_menu($menu)
118  {
119    array_push($menu,
120        array(
121          'NAME' => 'Event Tracer',
122          'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php')
123        )
124      );
125    return $menu;
126  }
127}
128
129$obj = new EventTracer();
130$obj->load_config();
131
132add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
133add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') );
134add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') );
135add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') );
136set_plugin_data($plugin['id'], $obj);
137?>
Note: See TracBrowser for help on using the repository browser.