Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
index.php
001 <?php
002 /**
003 *
004 * @package phpBB3
005 * @version $Id$
006 * @copyright (c) 2007 phpBB Group
007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008 *
009 */
010
011 /**
012 * @ignore
013 */
014 if (!defined('IN_PHPBB'))
015 {
016 exit;
017 }
018
019 /**
020 * phpBB Hook Class
021 * @package phpBB3
022 */
023 class phpbb_hook
024 {
025 /**
026 * Registered hooks
027 */
028 var $hooks = array();
029
030 /**
031 * Results returned by functions called
032 */
033 var $hook_result = array();
034
035 /**
036 * internal pointer
037 */
038 var $current_hook = NULL;
039
040 /**
041 * Initialize hook class.
042 *
043 * @param array $valid_hooks array containing the hookable functions/methods
044 */
045 function phpbb_hook($valid_hooks)
046 {
047 foreach ($valid_hooks as $_null => $method)
048 {
049 $this->add_hook($method);
050 }
051
052 if (function_exists('phpbb_hook_register'))
053 {
054 phpbb_hook_register($this);
055 }
056 }
057
058 /**
059 * Register function/method to be called within hook
060 * This function is normally called by the modification/application to attach/register the functions.
061 *
062 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
063 * @param mixed $hook The replacement function/method to be called. Passing function name or array with object/class definition
064 * @param string $mode Specify the priority/chain mode. 'normal' -> hook gets appended to the chain. 'standalone' -> only the specified hook gets called - later hooks are not able to overwrite this (E_NOTICE is triggered then). 'first' -> hook is called as the first one within the chain. 'last' -> hook is called as the last one within the chain.
065 */
066 function register($definition, $hook, $mode = 'normal')
067 {
068 $class = (!is_array($definition)) ? '__global' : $definition[0];
069 $function = (!is_array($definition)) ? $definition : $definition[1];
070
071 // Method able to be hooked?
072 if (isset($this->hooks[$class][$function]))
073 {
074 switch ($mode)
075 {
076 case 'standalone':
077 if (!isset($this->hooks[$class][$function]['standalone']))
078 {
079 $this->hooks[$class][$function] = array('standalone' => $hook);
080 }
081 else
082 {
083 trigger_error('Hook not able to be called standalone, previous hook already standalone.', E_NOTICE);
084 }
085 break;
086
087 case 'first':
088 case 'last':
089 $this->hooks[$class][$function][$mode][] = $hook;
090 break;
091
092 case 'normal':
093 default:
094 $this->hooks[$class][$function]['normal'][] = $hook;
095 break;
096 }
097 }
098 }
099
100 /**
101 * Calling all functions/methods attached to a specified hook.
102 * Called by the function allowing hooks...
103 *
104 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
105 * @return bool False if no hook got executed, true otherwise
106 */
107 function call_hook($definition)
108 {
109 $class = (!is_array($definition)) ? '__global' : $definition[0];
110 $function = (!is_array($definition)) ? $definition : $definition[1];
111
112 if (!empty($this->hooks[$class][$function]))
113 {
114 // Developer tries to call a hooked function within the hooked function...
115 if ($this->current_hook !== NULL && $this->current_hook['class'] === $class && $this->current_hook['function'] === $function)
116 {
117 return false;
118 }
119
120 // Call the hook with the arguments attached and store result
121 $arguments = func_get_args();
122 $this->current_hook = array('class' => $class, 'function' => $function);
123 $arguments[0] = &$this;
124
125 // Call the hook chain...
126 if (isset($this->hooks[$class][$function]['standalone']))
127 {
128 $this->hook_result[$class][$function] = call_user_func_array($this->hooks[$class][$function]['standalone'], $arguments);
129 }
130 else
131 {
132 foreach (array('first', 'normal', 'last') as $mode)
133 {
134 if (!isset($this->hooks[$class][$function][$mode]))
135 {
136 continue;
137 }
138
139 foreach ($this->hooks[$class][$function][$mode] as $hook)
140 {
141 $this->hook_result[$class][$function] = call_user_func_array($hook, $arguments);
142 }
143 }
144 }
145
146 $this->current_hook = NULL;
147 return true;
148 }
149
150 $this->current_hook = NULL;
151 return false;
152 }
153
154 /**
155 * Get result from previously called functions/methods for the same hook
156 *
157 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
158 * @return mixed False if nothing returned if there is no result, else array('result' => ... )
159 */
160 function previous_hook_result($definition)
161 {
162 $class = (!is_array($definition)) ? '__global' : $definition[0];
163 $function = (!is_array($definition)) ? $definition : $definition[1];
164
165 if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
166 {
167 return array('result' => $this->hook_result[$class][$function]);
168 }
169
170 return false;
171 }
172
173 /**
174 * Check if the called functions/methods returned something.
175 *
176 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
177 * @return bool True if results are there, false if not
178 */
179 function hook_return($definition)
180 {
181 $class = (!is_array($definition)) ? '__global' : $definition[0];
182 $function = (!is_array($definition)) ? $definition : $definition[1];
183
184 if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
185 {
186 return true;
187 }
188
189 return false;
190 }
191
192 /**
193 * Give actual result from called functions/methods back.
194 *
195 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
196 * @return mixed The result
197 */
198 function hook_return_result($definition)
199 {
200 $class = (!is_array($definition)) ? '__global' : $definition[0];
201 $function = (!is_array($definition)) ? $definition : $definition[1];
202
203 if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
204 {
205 $result = $this->hook_result[$class][$function];
206 unset($this->hook_result[$class][$function]);
207 return $result;
208 }
209
210 return;
211 }
212
213 /**
214 * Add new function to the allowed hooks.
215 *
216 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
217 */
218 function add_hook($definition)
219 {
220 if (!is_array($definition))
221 {
222 $definition = array('__global', $definition);
223 }
224
225 $this->hooks[$definition[0]][$definition[1]] = array();
226 }
227
228 /**
229 * Remove function from the allowed hooks.
230 *
231 * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
232 */
233 function remove_hook($definition)
234 {
235 $class = (!is_array($definition)) ? '__global' : $definition[0];
236 $function = (!is_array($definition)) ? $definition : $definition[1];
237
238 if (isset($this->hooks[$class][$function]))
239 {
240 unset($this->hooks[$class][$function]);
241
242 if (isset($this->hook_result[$class][$function]))
243 {
244 unset($this->hook_result[$class][$function]);
245 }
246 }
247 }
248 }
249
250 ?>