diff options
-rw-r--r-- | CHANGELOG.txt | 2 | ||||
-rw-r--r-- | includes/common.inc | 19 | ||||
-rw-r--r-- | modules/node.module | 5 | ||||
-rw-r--r-- | modules/node/node.module | 5 | ||||
-rw-r--r-- | modules/taxonomy.module | 17 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 17 | ||||
-rw-r--r-- | modules/upload.module | 20 | ||||
-rw-r--r-- | modules/upload/upload.module | 20 |
8 files changed, 98 insertions, 7 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c6d4a1f62..1adf7c5ea 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,6 +7,8 @@ Drupal x.x.x, xxxx-xx-xx * improved search output. - syndication: * made the ping module ping pingomatic.com which, in turn, will ping all the major ping services. + * added categories to RSS feeds. + * added enclosures to RSS feeds. - flood control mechanism: * added a mechanism to throttle certain operations. - usability: diff --git a/includes/common.inc b/includes/common.inc index 084bc5e1e..8a45ff94a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -689,7 +689,24 @@ function format_rss_item($title, $link, $description, $args = array()) { $output .= ' <link>'. drupal_specialchars(strip_tags($link)) ."</link>\n"; $output .= ' <description>'. drupal_specialchars($description) ."</description>\n"; foreach ($args as $key => $value) { - $output .= ' <'. $key .'>'. drupal_specialchars(strip_tags($value)) ."</$key>\n"; + if (is_array($value)) { + if ($value['key']) { + $output .= ' <'. $value['key']; + if (is_array($value['attributes'])) { + $output .= drupal_attributes($value['attributes']); + } + + if ($value['value']) { + $output .= '>'. $value['value'] .'</'. $value['key'] .">\n"; + } + else { + $output .= " />\n"; + } + } + } + else { + $output .= ' <'. $key .'>'. drupal_specialchars(strip_tags($value)) ."</$key>\n"; + } } $output .= "</item>\n"; diff --git a/modules/node.module b/modules/node.module index 0fd24ae6d..4bf11ae4d 100644 --- a/modules/node.module +++ b/modules/node.module @@ -1041,7 +1041,10 @@ function node_feed($nodes = 0, $channel = array()) { // Allow modules to change $node->body before viewing. node_invoke_nodeapi($item, 'view', false, false); - $items .= format_rss_item($item->title, $link, $item->teaser, array('pubDate' => date('r', $item->changed))); + // Allow modules to add additional item fields + $extra = node_invoke_nodeapi($item, 'rss item'); + $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->changed)))); + $items .= format_rss_item($item->title, $link, $item->teaser, $extra); } $channel_defaults = array( diff --git a/modules/node/node.module b/modules/node/node.module index 0fd24ae6d..4bf11ae4d 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1041,7 +1041,10 @@ function node_feed($nodes = 0, $channel = array()) { // Allow modules to change $node->body before viewing. node_invoke_nodeapi($item, 'view', false, false); - $items .= format_rss_item($item->title, $link, $item->teaser, array('pubDate' => date('r', $item->changed))); + // Allow modules to add additional item fields + $extra = node_invoke_nodeapi($item, 'rss item'); + $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->changed)))); + $items .= format_rss_item($item->title, $link, $item->teaser, $extra); } $channel_defaults = array( diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 54f3131b1..d69f988db 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -885,6 +885,9 @@ function taxonomy_nodeapi($node, $op, $arg = 0) { case 'delete': taxonomy_node_delete($node->nid); break; + case 'rss item': + return taxonomy_rss_item($node); + break; } } @@ -1015,6 +1018,20 @@ function taxonomy_admin() { } /** + * Provides category information for rss feeds + */ +function taxonomy_rss_item($node) { + $output = array(); + $terms = taxonomy_node_get_terms($node->nid); + foreach ($terms as $term) { + $output[] = array('key' => 'category', + 'value' => $term->name, + 'attributes' => array('domain' => url('taxonomy/term/'.$term->tid, NULL, NULL, TRUE))); + } + return $output; +} + +/** * Implementation of hook_help(). */ function taxonomy_help($section) { diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 54f3131b1..d69f988db 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -885,6 +885,9 @@ function taxonomy_nodeapi($node, $op, $arg = 0) { case 'delete': taxonomy_node_delete($node->nid); break; + case 'rss item': + return taxonomy_rss_item($node); + break; } } @@ -1015,6 +1018,20 @@ function taxonomy_admin() { } /** + * Provides category information for rss feeds + */ +function taxonomy_rss_item($node) { + $output = array(); + $terms = taxonomy_node_get_terms($node->nid); + foreach ($terms as $term) { + $output[] = array('key' => 'category', + 'value' => $term->name, + 'attributes' => array('domain' => url('taxonomy/term/'.$term->tid, NULL, NULL, TRUE))); + } + return $output; +} + +/** * Implementation of hook_help(). */ function taxonomy_help($section) { diff --git a/modules/upload.module b/modules/upload.module index 1a3348e65..c1fc08641 100644 --- a/modules/upload.module +++ b/modules/upload.module @@ -265,6 +265,22 @@ function upload_nodeapi(&$node, $op, $arg) { break; case 'search result': return $node->files ? format_plural(count($node->files), '1 attachment', '%count attachments') : null; + case 'rss item': + $files = array(); + foreach ($node->files as $file) { + if ($file->list) { + $files[] = $file; + } + } + if (count($files) > 0) { + // RSS only allows one enclosure per item + $file = array_shift($files); + return array(array('key' => 'enclosure', + 'attributes' => array('url' => file_create_url($file->filepath), + 'length' => $file->filesize, + 'type' => $file->filemime))); + } + break; } return $output; @@ -332,14 +348,14 @@ function upload_form($node) { } if (count($node->files)) { - $output = form_item('', theme('table', $header, $rows), t('Note: changes made to the attachments are not permanent until you save this post.')); + $output = theme('table', $header, $rows); } if (user_access('upload files')) { $output .= form_file(t('Attach new file'), "upload", 40); $output .= form_button(t('Attach'), 'fileop'); } - return '<div class="attachments">'. form_group(t('Attachments'), $output) . '</div>'; + return '<div class="attachments">'. form_group(t('Attachments'), $output, t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.')) .'</div>'; } function upload_load($node) { diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 1a3348e65..c1fc08641 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -265,6 +265,22 @@ function upload_nodeapi(&$node, $op, $arg) { break; case 'search result': return $node->files ? format_plural(count($node->files), '1 attachment', '%count attachments') : null; + case 'rss item': + $files = array(); + foreach ($node->files as $file) { + if ($file->list) { + $files[] = $file; + } + } + if (count($files) > 0) { + // RSS only allows one enclosure per item + $file = array_shift($files); + return array(array('key' => 'enclosure', + 'attributes' => array('url' => file_create_url($file->filepath), + 'length' => $file->filesize, + 'type' => $file->filemime))); + } + break; } return $output; @@ -332,14 +348,14 @@ function upload_form($node) { } if (count($node->files)) { - $output = form_item('', theme('table', $header, $rows), t('Note: changes made to the attachments are not permanent until you save this post.')); + $output = theme('table', $header, $rows); } if (user_access('upload files')) { $output .= form_file(t('Attach new file'), "upload", 40); $output .= form_button(t('Attach'), 'fileop'); } - return '<div class="attachments">'. form_group(t('Attachments'), $output) . '</div>'; + return '<div class="attachments">'. form_group(t('Attachments'), $output, t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.')) .'</div>'; } function upload_load($node) { |