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