01: <?php
02:
03: defined ('VARIABLE') or die;
04:
05: /*
06: ** Create a list of required hooks according to current one's dependencies
07: ** $id : id of current hook in global $gl_hooks array
08: ** $chain : list of already required hooks to avoid circular references
09: ** $result : output array containing hooks to be included
10: */
11: function hookRequire ($id, $chain, &$result)
12: {
13: global $gl_hooks;
14:
15: // Browse hooks required by current one
16: $hook = &$gl_hooks[$id];
17:
18: foreach ($hook['ref'] as $ref => $needed)
19: {
20: // Check for circular references
21: if (isset ($chain[$ref]))
22: showError (tra ('error.internal_hook_circular', array ('source' => $id, 'target' => $ref)));
23:
24: // Check for required hook availability and dependencies
25: if (isset ($gl_hooks[$ref]))
26: hookRequire ($ref, $chain + array ($ref => 0), $result);
27: else if ($needed)
28: showError (tra ('error.internal_hook_needed', array ('source' => $id, 'target' => $ref)));
29: }
30:
31: // Check if hook has already been registered
32: foreach ($result as $i => $item)
33: {
34: if ($item['id'] == $id)
35: return;
36: }
37:
38: // Insert hook regarding its weights and already included dependencies
39: if (is_file ($hook['path']))
40: {
41: $min = -1;
42:
43: foreach ($hook['ref'] as $ref => $null)
44: foreach ($result as $i => $item)
45: if ($item['id'] == $ref)
46: $min = max ($min, $i);
47:
48: for ($index = count ($result); $index > $min + 1 && $result[$index - 1]['weight'] > $hook['weight']; )
49: --$index;
50:
51: array_splice ($result, $index, 0, array (array
52: (
53: 'access' => $hook['access'],
54: 'id' => $id,
55: 'module' => $hook['module'],
56: 'path' => $hook['path'],
57: 'weight' => $hook['weight']
58: )));
59: }
60: else
61: showError (tra ('error.internal_hook_file', array ('file' => $hook['file'], 'module' => tra ($hook['module'], array (), false))));
62: }
63:
64: ?>