1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Allows modules to contribute styles.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Fetch an advanced forum style plugin.
|
10
|
*
|
11
|
* @param string $style
|
12
|
* Name of the style plugin
|
13
|
*
|
14
|
* @return array
|
15
|
* 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
|
* @return array
|
25
|
* 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
|
// MASTER HANDLER.
|
33
|
/**
|
34
|
* Fetch a group of plugins by name.
|
35
|
*
|
36
|
* @param string $plugin
|
37
|
* This is the name of the plugin, and also the name of the directory.
|
38
|
*
|
39
|
* @param string $hook
|
40
|
* This is the hook to call to get the info for the plugin.
|
41
|
*
|
42
|
* @return array
|
43
|
* 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
|
* Load plugin info for all hooks; this is handled separately from plugins from files.
|
68
|
*
|
69
|
* @param string $hook
|
70
|
* The hook being invoked.
|
71
|
*
|
72
|
* @return array
|
73
|
* 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
|
* @param string $module
|
90
|
* The module that owns the hook.
|
91
|
*
|
92
|
* @param string $identifier
|
93
|
* Either the module or 'advanced_forum_' . $file->name
|
94
|
*
|
95
|
* @param string $hook
|
96
|
* The name of the hook being invoked.
|
97
|
*
|
98
|
* @return array|null
|
99
|
* Data about module.
|
100
|
*/
|
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
|
}
|