Index: commentrss.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/commentrss/commentrss.module,v retrieving revision 1.12.2.2.2.6.2.10 diff -u -p -r1.12.2.2.2.6.2.10 commentrss.module --- commentrss.module 21 Sep 2009 16:50:55 -0000 1.12.2.2.2.6.2.10 +++ commentrss.module 13 Apr 2010 08:57:04 -0000 @@ -89,12 +89,23 @@ function commentrss_node_feed_access($no } /** - * Implementation of hook_init(). +* Implementation of hook_theme_registry_alter(). +*/ +function commentrss_theme_registry_alter(&$theme_registry) { + // Makes sure commentrss_early_preprocess_page function gets called first + // or drupal_add_feed() and similar will not work. + array_unshift($theme_registry['page']['preprocess functions'], 'commentrss_early_preprocess_page'); +} + +/** + * A modified implementation of hook_preprocess_page(). + * + * Slightly different name to avoid auto-detection by the theme registry. + * Manually added to the theme registry by commentrss_theme_registry_alter(). */ -function commentrss_init() { - // This hook gets called for offline pages and breaks the theme, so - // skip running in that case to avoid interfering with that operation. - if (variable_get('site_offline', 0) || !user_access('access comments')) { +function commentrss_early_preprocess_page(&$variables) { + // Skip running on admin pages and for users without access to comments. + if (arg(0) == 'admin' || !user_access('access comments')) { return; } @@ -123,17 +134,6 @@ function commentrss_init() { break; } - // Expose node feed on node view page. - if (preg_match('%^node/\d+$%', $_GET['q'])) { - $node = node_load(arg(1)); - if ($node && variable_get('commentrss_node', TRUE) && commentrss_node_feed_access($node)) { - drupal_add_feed( - url('crss/node/'. $node->nid, array('absolute' => TRUE)), - t('Comments for "@title"', array('@title' => $node->title)) - ); - } - } - // Expose term feed on term view page. //if (preg_match('%^taxonomy/term/\d+$%', $_GET['q']) && variable_get('commentrss_term', FALSE)) { // $term = taxonomy_get_term(arg(2)); @@ -149,18 +149,28 @@ function commentrss_init() { /** * Implementation of hook_nodeapi(). */ -function commentrss_nodeapi(&$node, $op) { - if ($op == 'rss item') { - // Add a wfw:commentRss element to node feed entries if: - // node comments are enabled for the node - // comment feeds for individual nodes are enabled - if ($node->comment != COMMENT_NODE_DISABLED && variable_get('commentrss_node', TRUE)) { - // The "wfw" namespace is added to each element due to a bug in node_feed(). - // See http://drupal.org/node/157709 - return array(array( - 'key' => 'wfw:commentRss', - 'attributes' => array('xmlns:wfw' => 'http://wellformedweb.org/CommentAPI/'), - 'value' => url('crss/node/'. $node->nid, array('absolute' => TRUE)))); - } +function commentrss_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { + switch ($op) { + case 'view': + // Expose node feed on node view page. + if ($page && variable_get('commentrss_node', TRUE) && ($node->comment != COMMENT_NODE_DISABLED)) { + drupal_add_feed( + url('crss/node/'. $node->nid, array('absolute' => TRUE)), + t('Comments for "@title"', array('@title' => $node->title)) + ); + } + break; + case 'rss item': + // Add a wfw:commentRss element to node feed entries if: + // node comments are enabled for the node + // comment feeds for individual nodes are enabled + if ($node->comment != COMMENT_NODE_DISABLED && variable_get('commentrss_node', TRUE)) { + // The "wfw" namespace is added to each element due to a bug in node_feed(). + // See http://drupal.org/node/157709 + return array(array( + 'key' => 'wfw:commentRss', + 'attributes' => array('xmlns:wfw' => 'http://wellformedweb.org/CommentAPI/'), + 'value' => url('crss/node/'. $node->nid, array('absolute' => TRUE)))); + } } }