root/dev/common/class.event.php @ 181

Revision 181, 2.6 KB (checked in by exi, 14 years ago)

Changed admin/options to show the actual page as page title.
admin_menu.php now also loads settings from mods.
Added event manager and the first 2 events (comment/killmail added).
Changed config to be in a separate file and modified it to be called static with config::get().
http_request now stores the socket status in $this->status.
Changed MapView? to store pictures based on KB_SITE so it doesnt show a map with wrong colors for the current killboard on a multi-site installation.
Changed options to handle element options (like 'edit:size:40').
Changed options to use the static calls to config.
Changed Page to use the static calls to config.
Changed Session to use session_name() to determine if it should start a session.
index.php now loads module-init-scripts.
Changed post.php to use config and it should now also use the mailserver configuration directive to send emails.
Added a mail_forward-mod to show how easy it can be to develop mods once there are enough events listed.
Fixed 2 typos in battle_overview.tpl.

Line 
1<?php
2
3class event
4{
5    function event()
6    {
7        trigger_error('The class "event" may only be invoked statically.', E_USER_ERROR);
8    }
9
10    function register($event, $callback)
11    {
12        if (is_array($callback))
13        {
14            if (is_object($callback[0]))
15            {
16                trigger_error('The supplied callback has to point to a static method.', E_USER_WARNING);
17                return;
18            }
19
20            // store callbacks as 'object::function'
21            $callback = $callback[0].'::'.$callback[1];
22        }
23        if (!strpos($callback, '::'))
24        {
25            trigger_error('The supplied callback "'.$callback.'" has to point to a static method.', E_USER_WARNING);
26            return;
27        }
28
29        // we store the event callbacks reverse so you need one function for every event
30        event::_put($callback, $event);
31    }
32
33    function call($event, &$object)
34    {
35        $cache = &event::_getCache();
36        foreach ($cache as $callback => $c_event)
37        {
38            // if the callback registered to the calling event we'll try to use his callback
39            if ($event == $c_event)
40            {
41                $cb = explode('::', $callback);
42                if (is_callable($cb))
43                {
44                    if (is_object($object))
45                    {
46                        call_user_func($cb, &$object);
47                    }
48                    else
49                    {
50                        call_user_func($cb, null);
51                    }
52                }
53                else
54                {
55                    trigger_error('The stored event handler "'.$c_event.'" is not callable (CB: "'.$callback.'").', E_USER_WARNING);
56                }
57            }
58        }
59    }
60
61    function add($event)
62    {
63
64    }
65
66    function init()
67    {
68//        $db = new DBQuery();
69//        $db->execute('select rol_name, rol_descr from kb3_roles where rol_site=\''.KB_SITE."'");
70//        while ($row = $db->getRow())
71//        {
72//            role::_put($row['rol_name'], $row['rol_descr']);
73//        }
74    }
75
76    function &_getCache()
77    {
78        static $cache;
79
80        if (!isset($cache))
81        {
82            $cache = array();
83        }
84        return $cache;
85    }
86
87    function _put($key, $data)
88    {
89        $cache = &event::_getCache();
90        $cache[$key] = $data;
91    }
92
93    function _get($key)
94    {
95        $cache = &event::_getCache();
96
97        if (!isset($cache[$key]))
98        {
99            return null;
100        }
101        return $cache[$key];
102    }
103}
104?>
Note: See TracBrowser for help on using the browser.