function advanced_forum_theme_registry_alter in Advanced Forum 6.2
Same name and namespace in other branches
- 6 advanced_forum.module \advanced_forum_theme_registry_alter()
- 7.2 advanced_forum.module \advanced_forum_theme_registry_alter()
Implementation of hook_theme_registry_alter().
File
- ./
advanced_forum.module, line 218 - Enables the look and feel of other popular forum software.
Code
function advanced_forum_theme_registry_alter(&$theme_registry) {
advanced_forum_load_style_includes();
// Garland's phptemplate_comment_wrapper really sucks. Chances are, a theme
// does NOT want to control this on forum nodes anyway, so we're going to take
// it over:
if (isset($theme_registry['comment_wrapper']['function']) && $theme_registry['comment_wrapper']['function'] == 'phptemplate_comment_wrapper') {
$theme_registry['comment_wrapper']['function'] = 'advanced_forum_comment_wrapper';
}
// Optionally kill the next/previous forum topic navigation links because
// it is a nasty query that can slow down the forums.
if (!variable_get('advanced_forum_use_topic_navigation', FALSE)) {
foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
if ($value == 'template_preprocess_forum_topic_navigation') {
unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);
}
}
}
// Don't let core do its basic preprocess for forums, as we want to do
// other stuff now.
foreach ($theme_registry['forums']['preprocess functions'] as $key => $value) {
if ($value == 'template_preprocess_forums') {
unset($theme_registry['forums']['preprocess functions'][$key]);
}
}
// We duplicate all of core's forum list preprocessing so no need to run
// it twice. Running twice also causes problems with & in forum name.
foreach ($theme_registry['forum_list']['preprocess functions'] as $key => $value) {
if ($value == 'template_preprocess_forum_list') {
unset($theme_registry['forum_list']['preprocess functions'][$key]);
}
}
// Views handles the topic list pages so remove the core template preprocess.
foreach ($theme_registry['forum_topic_list']['preprocess functions'] as $key => $value) {
if ($value == 'template_preprocess_forum_topic_list') {
unset($theme_registry['forum_topic_list']['preprocess functions'][$key]);
}
}
// --- The following section manipulates the theme registry so the .tpl files
// --- for the given templates can be found first in the (sub)theme directory
// --- then in ancestor themes, if any, then in the active style directory
// --- for advanced forum or any ancestor styles.
// Affected templates
$templates = array(
'node',
'comment',
'comment_wrapper',
'forums',
'forum_list',
'forum_topic_list',
'forum_icon',
'forum_submitted',
'forum_topic_navigation',
'author_pane',
'advanced_forum_statistics',
'advanced_forum_search_forum',
'advanced_forum_search_topic',
'advanced_forum_search_result',
'advanced_forum_topic_list_view',
'views_view_fields__advanced_forum_search',
'views_view_fields__advanced_forum_search_topic',
'views_view_forum_topic_list__advanced_forum_topic_list',
'views_view_forum_topic_list__advanced_forum_group_topic_list',
'views_view__advanced_forum_topic_list',
'views_view__advanced_forum_group_topic_list',
'advanced_forum_topic_legend',
'advanced_forum_forum_legend',
'advanced_forum_topic_header',
'advanced_forum_active_poster',
);
// Find all our ancestor themes and put them in an array.
global $theme;
$themes = list_themes();
$ancestor_paths = array();
$ancestor = $theme;
while ($ancestor && isset($themes[$ancestor]->base_theme)) {
array_unshift($ancestor_paths, dirname($themes[$themes[$ancestor]->base_theme]->filename));
$ancestor = $themes[$ancestor]->base_theme;
}
// Get the sequence of styles to look in for templates
$lineage = advanced_forum_style_lineage();
if (!array_key_exists('naked', $lineage)) {
// Add naked in at the end of the line to prevent problems if a style
// doesn't include all needed templates.
$lineage['naked'] = drupal_get_path('module', 'advanced_forum') . '/styles/naked';
}
foreach ($templates as $template) {
// Sanity check in case the template is not being used.
if (!empty($theme_registry[$template])) {
// If there was a path in there, store it.
$existing_path = array_shift($theme_registry[$template]['theme paths']);
// Add paths for our style and ancestors before the existing path, if any.
foreach ($lineage as $style => $style_path) {
array_unshift($theme_registry[$template]['theme paths'], $existing_path, $style_path);
$existing_path = array_shift($theme_registry[$template]['theme paths']);
}
// If there are any ancestor paths (ie: we are in a subtheme, add those)
foreach ($ancestor_paths as $ancestor_path) {
$theme_registry[$template]['theme paths'][] = $ancestor_path;
}
// Put the active theme's path last since that takes precidence.
$theme_registry[$template]['theme paths'][] = advanced_forum_path_to_theme();
// Add preprocess functions if our style has them.
$preprocess = array();
foreach ($lineage as $key => $path) {
if (function_exists('advanced_forum_' . $key . '_preprocess_' . $template)) {
$preprocess[] = 'advanced_forum_' . $key . '_preprocess_' . $template;
}
}
// There are preprocess functions to add, so figure out where we want to add
// them.
if ($preprocess) {
$position = 0;
foreach ($theme_registry[$template]['preprocess functions'] as $function) {
$position++;
// If we see either of these items, that means we can place our
// preprocess functions after this.
if (substr($function, 0, 25) == 'advanced_forum_preprocess' || substr($function, 0, 34) == 'template_preprocess_advanced_forum') {
break;
}
}
// Add in our new preprocess functions:
array_splice($theme_registry[$template]['preprocess functions'], $position, 0, $preprocess);
}
}
}
}