Index: commentrss.module =================================================================== RCS file: /cvs/drupal/contributions/modules/commentrss/commentrss.module,v retrieving revision 1.12.2.2 diff -u -r1.12.2.2 commentrss.module --- commentrss.module 16 Jul 2007 04:19:11 -0000 1.12.2.2 +++ commentrss.module 10 Oct 2007 06:40:42 -0000 @@ -50,24 +50,24 @@ if (arg(0) == 'node' && is_numeric(arg(1)) && variable_get('commentrss_node', TRUE)) { $node = node_load(arg(1)); if ($node->nid && $node->comment != COMMENT_NODE_DISABLED) { - drupal_add_feed(url('crss/node/'. $node->nid), - t('Comments for @title', array('@title' => $node->title))); + commentrss_add_feed(url('crss/node/'. $node->nid), + t('Comments for @title', array('@title' => $node->title))); } } elseif (arg(0) == 'node' && variable_get('commentrss_site', TRUE)) { - drupal_add_feed(url('crss'), + commentrss_add_feed(url('crss'), t('@site - All comments', array('@site' => variable_get('site_name', 'Drupal')))); } elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && variable_get('commentrss_term', FALSE)) { $term = taxonomy_get_term(arg(2)); if ($term->tid) { - drupal_add_feed(url('crss/term/'. $term->tid), + commentrss_add_feed(url('crss/term/'. $term->tid), t('Comments for category "@title"', array('@title' => $term->name))); } } elseif (arg(0) == 'taxonomy' && arg(1) == 'vocabulary' && is_numeric(arg(2)) && variable_get('commentrss_node', FALSE)) { // vocabulary_list module is serving this page - drupal_add_feed(url('crss/vocab/'. arg(2)), t('Comments for this vocabulary')); + commentrss_add_feed(url('crss/vocab/'. arg(2)), t('Comments for this vocabulary')); } } return $items; @@ -275,6 +275,85 @@ '#title' => t('Node comments for a vocabulary'), '#default_value' => variable_get('commentrss_vocab', FALSE)); } + $form['commentrss_showheader'] = array('#type' => 'checkbox', + '#title' => t('Add feeds to header'), + '#default_value' => variable_get('commentrss_showheader', TRUE)); return system_settings_form($form); } + +/** + * Implementation of hook_block() + */ +function commentrss_block($op = 'list', $delta = 0, $edit = array()) { + switch ($op) { + + case 'list': + $blocks[0]['info'] = t('Commentrss: Block for comment rss feeds'); + return $blocks; + + case 'configure': + $form = array(); + return $form; + + case 'save': + return; + + case 'view': default: + switch ($delta) { + case 0: + $feeds = commentrss_get_feeds("\n", "
  • ", "
  • "); + if ($feeds != "") + { + $block['subject'] = t('Comment Feeds'); + $block['content'] = "\n"; + } + break; + } + return $block; + + } +} + +/** + * Add a feed URL for the commentrss block. Also basically acts as a wrapper + * around drupal_add_feed() if the commentrss_showheader variable is set to + * true. + * + * @param $url + * The url for the feed + * @param $title + * The title of the feed + */ +function commentrss_add_feed($url = NULL, $title = '') { + static $commentrss_feed_links = array(); + + if (!is_null($url)) { + $commentrss_feed_links[$url] = ' $url)) . ">{$title}"; + + if (variable_get('commentrss_showheader', TRUE)) { + drupal_add_feed($url, $title); + } + } + return $commentrss_feed_links; +} + +/** + * Get the feed URLs for the commentrss block. + * + * @param $delimiter + * The delimiter to split feeds by + * @param $prefix + * What to prefix each feed link with + * @param $suffix + * What to suffix each feed link with + */ +function commentrss_get_feeds($delimiter = "\n", $prefix = "", $suffix = "") { + $feeds = commentrss_add_feed(); + foreach ($feeds as $key => $value) + { + $feeds[$key] = $prefix . $value . $suffix; + } + return implode($feeds, $delimiter); +} \ No newline at end of file