Index: advanced_forum.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/advanced_forum/advanced_forum.module,v retrieving revision 1.57 diff -u -p -w -r1.57 advanced_forum.module --- advanced_forum.module 28 May 2008 21:01:03 -0000 1.57 +++ advanced_forum.module 29 May 2008 01:47:20 -0000 @@ -80,18 +80,65 @@ function advanced_forum_settings_page() * D5 compatability wrapper for node/comment preprocess functions. */ function advanced_forum_addvars($hook, $vars) { + _advanced_forum_load_preprocessors(); switch ($hook) { case 'node': - advanced_forum_preprocess_node($vars); - break; case 'comment': - advanced_forum_preprocess_comment($vars); + advanced_forum_call_preprocess($hook, $vars); break; } return $vars; } + +/** + * Load advanced forum preprocessors includes on behalf of modules. + */ +function _advanced_forum_load_preprocessors() { + static $finished = FALSE; + if ($finished) { + return; + } + advanced_forum_include('forum.inc'); +} + +/** + * Load advanced forum files on behalf of modules. + * + * Blatent rip of views include system. + */ +function advanced_forum_include($file) { + $cache = cache_get('advforum_includes', 'cache'); + if (isset($cache->data) && $cache->data) { + $includes = unserialize($cache->data); + } + else { + $advanced_forum_path = drupal_get_path('module', 'advanced_forum') . '/modules'; + foreach (module_list() as $module) { + $module_path = drupal_get_path('module', $module); + if (file_exists("$module_path/$module.$file")) { + $includes[] = "./$module_path/$module.$file"; + } + else if (file_exists("$module_path/includes/$module.$file")) { + $includes[] = "./$module_path/includes/$module.$file"; + } + else if (file_exists("$advanced_forum_path/$module.$file")) { + $includes[] = "./$advanced_forum_path/$module.$file"; + } + } + cache_set('advforum_includes', 'cache', serialize($includes)); + } + foreach ($includes as $include) { + require_once $include; + } +} + +/** + * Implementation of hook_preprocess_node(). + * + * Provide additional templates and variables to forum nodes. + */ function advanced_forum_preprocess_node(&$vars) { if (advanced_forum_treat_as_forum_post('node', $vars)) { $forum_theme = advanced_forum_get_forum_theme_directory(); @@ -249,7 +296,7 @@ function theme_forum_user($account) { $variables['account'] = $account; // Call our preprocess function to create all the variables - template_preprocess_forum_user($variables); + advanced_forum_call_preprocess('forum_user', $variables); // Send the variables to the advf-forum-user.tpl.php $forum_theme = advanced_forum_get_forum_theme_directory(); @@ -297,99 +344,6 @@ function template_preprocess_forum_user( $variables['online_text'] = t('Offline'); $variables['online_status'] = '
' . $variables['online_icon'] . ' ' . $variables['online_text'] . '
'; } - - // Profile - if (module_exists('profile')) { - $variables['profile'] = profile_view_profile($account); - } - - // Points - if (module_exists('userpoints')) { - $variables['points_raw'] = userpoints_get_current_points($accountid); - $variables['points'] = '
' . t('Points: ') . '' . $variables['points_raw'] . '
'; - } - - // Posts / IP - if (module_exists('user_stats')) { - $variables['posts_raw'] = user_stats_get_stats('post_count', $accountid); - $variables['posts'] = '
' . t('Posts: ') . '' . $variables['posts_raw'] . '
'; - - // IP is only visible if the viewer has access, so do an extra check - $ip = user_stats_get_stats('ip_address', $accountid); - if (!empty($ip)) { - $variables['ip_raw'] = $ip; - $variables['ip'] = '
' . t('IP: ') . '' . $variables['ip_raw'] . '
'; - } - } - - // Title - if (module_exists('user_titles')) { - $variables['user_title_raw'] = user_titles_get_user_title($accountid); - $variables['user_title'] = '
' . $variables['user_title_raw'] . '
'; - } - - // Badges - if (module_exists('user_badges')) { - $variables['user_badges_raw'] = user_badges_for_uid($accountid); - $variables['user_badges'] = '
' . $variables['user_badges_raw'] . '
'; - } - - // Contact user - if (module_exists('contact') && ($account->contact) && ($account->uid != $user->uid) && ($user->uid != 0)) { - $variables['contact_class'] = "contact"; - $variables['contact_icon'] = theme('image', advanced_forum_theme_path() . '/' . $themedir . "/images/email.png", 'Email', 'Email', NULL, TRUE); - $variables['contact_text'] = t('Email'); - $variables['contact_link'] = 'user/'. $accountid . '/contact'; - $variables['contact'] = '
' . - l($variables['contact_icon'] . ' ' . $variables['contact_text'], $variables['contact_link'], NULL, NULL, NULL, NULL, TRUE) . - '
'; - } - - // Send private message - if (module_exists('privatemsg') && - ($account->uid != $user->uid) && - user_access('access private messages') && - (isset($account->privatemsg_allow) ? $account->privatemsg_allow : 1)) { - $variables['privatemsg_icon'] = theme('image', advanced_forum_theme_path() . '/' . $themedir . "/images/user_comment.png", 'Private Message', 'Private Message', NULL, TRUE); - $variables['privatemsg_text'] = t('Send PM'); - $variables['privatemsg_link'] = 'privatemsg/new/'. $accountid; - $variables['privatemsg'] = '
' . - l($variables['privatemsg_icon'] . ' ' . - $variables['privatemsg_text'], $variables['privatemsg_link'],NULL,NULL,NULL,NULL,TRUE) . '
'; - } - - // Add / remove from buddylist - if (module_exists('buddylist')) { - - if (user_access('maintain buddy list') && @in_array($accountid, array_keys(buddylist_get_buddies($user->uid)))) { - // Remove buddy - $variables['buddylist_class'] = "buddy-remove"; - $variables['buddylist_icon'] = theme('image', advanced_forum_theme_path() . '/' . $themedir . "/images/group_delete.png", 'Remove Buddy', 'Remove Buddy', NULL, TRUE); - $variables['buddylist_text'] = t('Remove buddy'); - $variables['buddylist_link'] = 'buddy/delete/'. $accountid; - } else { - // Add buddy - if ($accountid != $user->uid && user_access('maintain buddy list')) { - $variables['buddylist_class'] = "buddy-add"; - $variables['buddylist_icon'] = theme('image', advanced_forum_theme_path() . '/' . $themedir . "/images/group_add.png", 'Add to buddy list', 'Add to buddy list', NULL, TRUE); - $variables['buddylist_text'] = t('Add buddy'); - $variables['buddylist_link'] = 'buddy/add/'. $accountid; - } - } - - $variables['buddylist'] = '
' . - l($variables['buddylist_icon'] . ' ' . $variables['buddylist_text'], $variables['buddylist_link'],NULL,NULL,NULL,NULL,TRUE) . - '
'; - } - // Subscribe to user's posts - // D6 alert: this assumes forum type. - if (module_exists('subscriptions')) { - if (user_access('subscribe to content types')) { - $variables['subscribe_link'] = "subscriptions/add/type/forum/" . $account->uid; - $variables['subscribe'] = l(t("Subscribe"), $variables['subscribe_link'], array('title' => 'Subscribe to forum posts by this user')); - } - } - } /********************** FORUM MODULE THEME OVERRIDES *************************/ @@ -409,11 +363,8 @@ function phptemplate_forum_display($foru $variables['sortby'] = $sortby; $variables['forum_per_page'] = $forum_per_page; - // Pass the parameters into the D6 preprocess function - template_preprocess_forums($variables); - // Pass the parameters into our preprocess function - advanced_forum_preprocess_forums($variables); + advanced_forum_call_preprocess('forums', $variables); // Look for the .tpl file in the theme. If found, use it. If not found, default // to the stock forum code and put up a warning. @@ -462,11 +413,8 @@ function phptemplate_forum_list($forums, $variables['parents'] = $parents; $variables['tid'] = $tid; - // Pass the parameters into the D6 preprocess function - template_preprocess_forum_list($variables); - // Pass the parameters into our preprocess function - advanced_forum_preprocess_forum_list($variables); + advanced_forum_call_preprocess('forum_list', $variables); // Look for the .tpl file in the theme. If found, use it. If not found, default // to the stock forum code and put up a warning. @@ -496,11 +444,8 @@ function phptemplate_forum_submitted($to // Create a $variables array from the parameters $variables['topic'] = $topic; - // Pass the parameters into the D6 preprocess function - template_preprocess_forum_submitted($variables); - // Pass the parameters into our preprocess function - advanced_forum_preprocess_forum_submitted($variables); + advanced_forum_call_preprocess('forum_submitted', $variables); // Look for the .tpl file in the theme. If found, use it. If not found, // just warn because there is no stock code to default to. @@ -531,11 +476,8 @@ function phptemplate_forum_topic_list($t $variables['sortby'] = $sortby; $variables['forum_per_page'] = $forum_per_page; - // Pass the parameters into the D6 preprocess function - template_preprocess_forum_topic_list($variables); - // Pass the parameters into our preprocess function - advanced_forum_preprocess_forum_topic_list($variables); + advanced_forum_call_preprocess('forum_topic_list', $variables); // Look for the .tpl file in the theme. If found, use it. If not found, default // to the stock forum code and put up a warning. @@ -691,11 +633,9 @@ function phptemplate_forum_icon($new_pos $variables['sticky'] = $sticky; $variables['topic_id'] = $topic_id; - // Pass the parameters into the D6 preprocess function - template_preprocess_forum_icon($variables); // Pass the parameters into our preprocess function - advanced_forum_preprocess_forum_icon($variables); + advanced_forum_call_preprocess('forum_icon', $variables); // Look for the .tpl file in the theme. If found, use it. If not found, default // to the stock forum code and put up a warning. Index: d6_compat.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/advanced_forum/d6_compat.inc,v retrieving revision 1.4 diff -u -p -w -r1.4 d6_compat.inc --- d6_compat.inc 23 Mar 2008 02:22:38 -0000 1.4 +++ d6_compat.inc 29 May 2008 01:47:21 -0000 @@ -337,3 +337,91 @@ function comment_new_page_count($num_com } return $pagenum; } + +/*****************************************************************************/ +/**************************** Preprocessor ***********************************/ +/*****************************************************************************/ + +/** + * Call preprocess functions for a theme hook. + * + * By calling this in a theme function prior to calling the template callback, + * we emulate the theme registry and preprocessor hooks of D6. + * @param $hook + * A theme hook that need preprocessing. + * @param $variables + * The theme variables array. This is used to return by reference. + * @return + * Return by reference the $variables array + */ +function advanced_forum_call_preprocess($hook, &$variables) { + $functions = advanced_forum_get_preprocess($hook); + $args = array(&$variables, $hook); + foreach ($functions as $function) { + call_user_func_array($function, $args); + } +} + +/** + * Get a list of preprocess functions for a given hook. + * + * @param $hook + * A theme hook that need preprocessing. + * @return + * An array or preprocessor function. + */ +function advanced_forum_get_preprocess($hook) { + static $registry; + + if (!isset($registry)) { + global $theme; + // Check the theme registry cache; if it exists, use it. + $cache = cache_get("advforum_registry:$theme", 'cache'); + if (isset($cache->data) && $cache->data) { + $registry = unserialize($cache->data); + } + else { + // We'll build it below. + $registry = array(); + } + } + + // If we don't have registry or don't have an entry, build one and cache it. + // This will build the registry as needed so unused functions won't be poluting it. + if (empty($registry) || !isset($registry[$hook])) { + global $theme; + $registry[$hook] = _advanced_forum_build_preprocess($hook); + cache_set("advforum_registry:$theme", 'cache', serialize($registry)); + } + + return $registry[$hook]; +} + +/** + * Helper function that does the leg work of finding preprocessor functions for a given hook. + * + * @param $hook + * A theme hook that need preprocessing. + * @return + * An array of preprocessor functions. + */ +function _advanced_forum_build_preprocess($hook) { + + $return = array(); + // Default preprocessor prefix. + $prefixes[] = 'template'; + // Add all modules so they can intervene with their own preprocessors. This allows them + // to provide preprocess functions even if they are not the owner of the current hook. + $prefixes += module_list(); + + foreach ($prefixes as $prefix) { + if (function_exists($prefix .'_preprocess')) { + $return[] = $prefix .'_preprocess'; + } + if (function_exists($prefix .'_preprocess_'. $hook)) { + $return[] = $prefix .'_preprocess_'. $hook; + } + } + return $return; +} +