1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Allows modules to contribute styles.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
13c3c9b4
|
Assos Assos
|
* Fetch an advanced forum style plugin.
|
10 |
85ad3d82
|
Assos Assos
|
*
|
11 |
13c3c9b4
|
Assos Assos
|
* @param string $style
|
12 |
85ad3d82
|
Assos Assos
|
* Name of the style plugin
|
13 |
|
|
*
|
14 |
13c3c9b4
|
Assos Assos
|
* @return array
|
15 |
85ad3d82
|
Assos Assos
|
* An array with information about the requested style plugin.
|
16 |
|
|
*/
|
17 |
|
|
function advanced_forum_get_style($style) {
|
18 |
|
|
return advanced_forum_get_plugins('styles', 'advanced_forum_styles', $style);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Collate information about all available advanced_forum styles.
|
23 |
|
|
*
|
24 |
13c3c9b4
|
Assos Assos
|
* @return array
|
25 |
85ad3d82
|
Assos Assos
|
* An array with information about the requested forum style.
|
26 |
|
|
*/
|
27 |
|
|
function advanced_forum_get_styles() {
|
28 |
|
|
return advanced_forum_get_plugins('styles', 'advanced_forum_styles');
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
// -----------------------------------------------------------------------
|
32 |
13c3c9b4
|
Assos Assos
|
// MASTER HANDLER.
|
33 |
85ad3d82
|
Assos Assos
|
/**
|
34 |
|
|
* Fetch a group of plugins by name.
|
35 |
|
|
*
|
36 |
13c3c9b4
|
Assos Assos
|
* @param string $plugin
|
37 |
85ad3d82
|
Assos Assos
|
* This is the name of the plugin, and also the name of the directory.
|
38 |
13c3c9b4
|
Assos Assos
|
*
|
39 |
|
|
* @param string $hook
|
40 |
85ad3d82
|
Assos Assos
|
* This is the hook to call to get the info for the plugin.
|
41 |
|
|
*
|
42 |
13c3c9b4
|
Assos Assos
|
* @return array
|
43 |
85ad3d82
|
Assos Assos
|
* An array of information arrays about the plugins received.
|
44 |
|
|
*/
|
45 |
|
|
function advanced_forum_get_plugins($plugin, $hook, $id = NULL) {
|
46 |
|
|
static $plugins = array();
|
47 |
|
|
static $all_hooks = array();
|
48 |
|
|
|
49 |
|
|
// Always load all hooks if we need them.
|
50 |
|
|
if (!isset($all_hooks[$plugin])) {
|
51 |
|
|
$all_hooks[$plugin] = TRUE;
|
52 |
|
|
$plugins[$plugin] = advanced_forum_load_hooks($hook);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
// If a specific plugin $id is being requested, return it.
|
56 |
|
|
if ($id && array_key_exists($id, $plugins[$plugin])) {
|
57 |
|
|
return $plugins[$plugin][$id];
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
// If no $id was requested, return the lot.
|
61 |
|
|
if (!$id) {
|
62 |
|
|
return $plugins[$plugin];
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
13c3c9b4
|
Assos Assos
|
* Load plugin info for all hooks; this is handled separately from plugins from files.
|
68 |
85ad3d82
|
Assos Assos
|
*
|
69 |
13c3c9b4
|
Assos Assos
|
* @param string $hook
|
70 |
85ad3d82
|
Assos Assos
|
* The hook being invoked.
|
71 |
|
|
*
|
72 |
13c3c9b4
|
Assos Assos
|
* @return array
|
73 |
85ad3d82
|
Assos Assos
|
* An array of info supplied by any hook implementations.
|
74 |
|
|
*/
|
75 |
|
|
function advanced_forum_load_hooks($hook) {
|
76 |
|
|
$info = array();
|
77 |
|
|
foreach (module_implements($hook) as $module) {
|
78 |
|
|
$result = _advanced_forum_process_plugin($module, $module, drupal_get_path('module', $module), $hook);
|
79 |
|
|
if (is_array($result)) {
|
80 |
|
|
$info = array_merge($info, $result);
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
return $info;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Process a single hook implementation of a advanced_forum plugin.
|
88 |
|
|
*
|
89 |
13c3c9b4
|
Assos Assos
|
* @param string $module
|
90 |
85ad3d82
|
Assos Assos
|
* The module that owns the hook.
|
91 |
13c3c9b4
|
Assos Assos
|
*
|
92 |
|
|
* @param string $identifier
|
93 |
85ad3d82
|
Assos Assos
|
* Either the module or 'advanced_forum_' . $file->name
|
94 |
13c3c9b4
|
Assos Assos
|
*
|
95 |
|
|
* @param string $hook
|
96 |
85ad3d82
|
Assos Assos
|
* The name of the hook being invoked.
|
97 |
13c3c9b4
|
Assos Assos
|
*
|
98 |
|
|
* @return array|null
|
99 |
|
|
* Data about module.
|
100 |
85ad3d82
|
Assos Assos
|
*/
|
101 |
|
|
function _advanced_forum_process_plugin($module, $identifier, $path, $hook) {
|
102 |
|
|
$function = $identifier . '_' . $hook;
|
103 |
|
|
if (!function_exists($function)) {
|
104 |
|
|
return NULL;
|
105 |
|
|
}
|
106 |
|
|
$result = $function();
|
107 |
|
|
if (!isset($result) || !is_array($result)) {
|
108 |
|
|
return NULL;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
// Fill in defaults.
|
112 |
|
|
foreach ($result as $name => $plugin) {
|
113 |
|
|
if (!is_dir($path . '/' . $plugin['directory'])) {
|
114 |
|
|
unset($result[$name]);
|
115 |
|
|
continue;
|
116 |
|
|
}
|
117 |
|
|
$result[$name] += array(
|
118 |
|
|
'module' => $module,
|
119 |
|
|
'name' => $name,
|
120 |
|
|
'path' => $path . '/' . $plugin['directory'],
|
121 |
|
|
);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
return !empty($result) ? $result : NULL;
|
125 |
13c3c9b4
|
Assos Assos
|
} |