From 8d96495d8880eb71f06925d65ec8f3d5cce9639c Mon Sep 17 00:00:00 2001 From: TravisCarden Date: Sat, 31 Mar 2012 14:27:15 -0500 Subject: [PATCH] Issue #1512434: Fixed coding standards issues in aggregator module. --- core/modules/aggregator/aggregator-item.tpl.php | 2 +- core/modules/aggregator/aggregator.admin.inc | 141 +++++++++++++++++----- core/modules/aggregator/aggregator.api.php | 18 ++-- core/modules/aggregator/aggregator.fetcher.inc | 4 +- core/modules/aggregator/aggregator.pages.inc | 65 ++++++---- core/modules/aggregator/aggregator.parser.inc | 58 +++++++-- core/modules/aggregator/aggregator.processor.inc | 53 ++++++-- core/modules/aggregator/aggregator.theme.css | 2 +- 8 files changed, 249 insertions(+), 94 deletions(-) diff --git a/core/modules/aggregator/aggregator-item.tpl.php b/core/modules/aggregator/aggregator-item.tpl.php index 74b2284..d3b8449 100644 --- a/core/modules/aggregator/aggregator-item.tpl.php +++ b/core/modules/aggregator/aggregator-item.tpl.php @@ -42,6 +42,6 @@
:
- + diff --git a/core/modules/aggregator/aggregator.admin.inc b/core/modules/aggregator/aggregator.admin.inc index 09da1cf..025c9d3 100644 --- a/core/modules/aggregator/aggregator.admin.inc +++ b/core/modules/aggregator/aggregator.admin.inc @@ -17,7 +17,7 @@ function aggregator_admin_overview() { /** * Displays the aggregator administration page. * - * @return + * @return string * The page HTML. */ function aggregator_view() { @@ -25,7 +25,13 @@ function aggregator_view() { $output = '

' . t('Feed overview') . '

'; - $header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), array('data' => t('Operations'), 'colspan' => '3')); + $header = array( + t('Title'), + t('Items'), + t('Last update'), + t('Next update'), + array('data' => t('Operations'), 'colspan' => '3'), + ); $rows = array(); foreach ($result as $feed) { $rows[] = array( @@ -38,7 +44,16 @@ function aggregator_view() { l(t('update items'), "admin/config/services/aggregator/update/$feed->fid", array('query' => array('token' => drupal_get_token("aggregator/update/$feed->fid")))), ); } - $output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No feeds available. Add feed.', array('@link' => url('admin/config/services/aggregator/add/feed'))))); + $output .= theme( + 'table', + array( + 'header' => $header, + 'rows' => $rows, + 'empty' => t('No feeds available. Add feed.', array( + '@link' => url('admin/config/services/aggregator/add/feed'), + )), + ) + ); $result = db_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title'); @@ -47,9 +62,22 @@ function aggregator_view() { $header = array(t('Title'), t('Items'), t('Operations')); $rows = array(); foreach ($result as $category) { - $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), format_plural($category->items, '1 item', '@count items'), l(t('edit'), "admin/config/services/aggregator/edit/category/$category->cid")); + $rows[] = array( + l($category->title, "aggregator/categories/$category->cid"), + format_plural($category->items, '1 item', '@count items'), + l(t('edit'), 'admin/config/services/aggregator/edit/category/' . $category->cid), + ); } - $output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No categories available. Add category.', array('@link' => url('admin/config/services/aggregator/add/category'))))); + $output .= theme( + 'table', + array( + 'header' => $header, + 'rows' => $rows, + 'empty' => t('No categories available. Add category.', array( + '@link' => url('admin/config/services/aggregator/add/category'), + )), + ) + ); return $output; } @@ -57,7 +85,7 @@ function aggregator_view() { /** * Form constructor for adding and editing feed sources. * - * @param $feed + * @param object|null $feed * If editing a feed, the feed to edit as a PHP stdClass value; if adding a * new feed, NULL. * @@ -67,10 +95,28 @@ function aggregator_view() { * @see aggregator_form_feed_submit() */ function aggregator_form_feed($form, &$form_state, stdClass $feed = NULL) { - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $period = array( + 900, + 1800, + 3600, + 7200, + 10800, + 21600, + 32400, + 43200, + 64800, + 86400, + 172800, + 259200, + 604800, + 1209600, + 2419200, + ); + $period = drupal_map_assoc($period, 'format_interval'); $period[AGGREGATOR_CLEAR_NEVER] = t('Never'); - $form['title'] = array('#type' => 'textfield', + $form['title'] = array( + '#type' => 'textfield', '#title' => t('Title'), '#default_value' => isset($feed->title) ? $feed->title : '', '#maxlength' => 255, @@ -85,26 +131,30 @@ function aggregator_form_feed($form, &$form_state, stdClass $feed = NULL) { '#description' => t('The fully-qualified URL of the feed.'), '#required' => TRUE, ); - $form['refresh'] = array('#type' => 'select', + $form['refresh'] = array( + '#type' => 'select', '#title' => t('Update interval'), '#default_value' => isset($feed->refresh) ? $feed->refresh : 3600, '#options' => $period, '#description' => t('The length of time between feed updates. Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); - $form['block'] = array('#type' => 'select', + $form['block'] = array( + '#type' => 'select', '#title' => t('News items in block'), '#default_value' => isset($feed->block) ? $feed->block : 5, - '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), + '#options' => drupal_map_assoc(range(0, 20)), '#description' => t("Drupal can make a block with the most recent news items of this feed. You can configure blocks to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in this feed's block. If you choose '0' this feed's block will be disabled.", array('@block-admin' => url('admin/structure/block'))), ); - // Handling of categories. + // Handle categories. $options = array(); $values = array(); $categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = :fid ORDER BY title', array(':fid' => isset($feed->fid) ? $feed->fid : NULL)); foreach ($categories as $category) { $options[$category->cid] = check_plain($category->title); - if ($category->fid) $values[] = $category->cid; + if ($category->fid) { + $values[] = $category->cid; + } } if ($options) { @@ -145,10 +195,23 @@ function aggregator_form_feed_validate($form, &$form_state) { if ($form_state['values']['op'] == t('Save')) { // Check for duplicate titles. if (isset($form_state['values']['fid'])) { - $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = :title OR url = :url) AND fid <> :fid", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url'], ':fid' => $form_state['values']['fid'])); + $result = db_query( + "SELECT title, url FROM {aggregator_feed} WHERE (title = :title OR url = :url) AND fid <> :fid", + array( + ':title' => $form_state['values']['title'], + ':url' => $form_state['values']['url'], + ':fid' => $form_state['values']['fid'], + ) + ); } else { - $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url'])); + $result = db_query( + "SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", + array( + ':title' => $form_state['values']['title'], + ':url' => $form_state['values']['url'], + ) + ); } foreach ($result as $feed) { if (strcasecmp($feed->title, $form_state['values']['title']) == 0) { @@ -208,7 +271,7 @@ function aggregator_form_feed_submit($form, &$form_state) { /** * Page callback: Deletes a feed. * - * @param $feed + * @param array $feed * An associative array describing the feed to be cleared. * * @see aggregator_admin_remove_feed_submit() @@ -249,7 +312,24 @@ function aggregator_admin_remove_feed_submit($form, &$form_state) { * @see aggregator_form_opml_submit() */ function aggregator_form_opml($form, &$form_state) { - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $period = array( + 900, + 1800, + 3600, + 7200, + 10800, + 21600, + 32400, + 43200, + 64800, + 86400, + 172800, + 259200, + 604800, + 1209600, + 2419200, + ); + $period = drupal_map_assoc($period, 'format_interval'); $form['upload'] = array( '#type' => 'file', @@ -269,14 +349,15 @@ function aggregator_form_opml($form, &$form_state) { '#options' => $period, '#description' => t('The length of time between feed updates. Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); - $form['block'] = array('#type' => 'select', + $form['block'] = array( + '#type' => 'select', '#title' => t('News items in block'), '#default_value' => 5, - '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), + '#options' => drupal_map_assoc(range(0, 20)), '#description' => t("Drupal can make a block with the most recent news items of a feed. You can configure blocks to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in a feed's block. If you choose '0' these feeds' blocks will be disabled.", array('@block-admin' => url('admin/structure/block'))), ); - // Handling of categories. + // Handle categories. $options = array_map('check_plain', db_query("SELECT cid, title FROM {aggregator_category} ORDER BY title")->fetchAllKeyed()); if ($options) { $form['category'] = array( @@ -289,7 +370,7 @@ function aggregator_form_opml($form, &$form_state) { $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Import') + '#value' => t('Import'), ); return $form; @@ -367,10 +448,10 @@ function aggregator_form_opml_submit($form, &$form_state) { * Feeds are recognized as elements with the attributes "text" and * "xmlurl" set. * - * @param $opml + * @param string $opml * The complete contents of an OPML document. * - * @return + * @return array|null * An array of feeds, each an associative array with a "title" and a "url" * element, or NULL if the OPML document failed to be parsed. An empty array * will be returned if the document is valid but contains no feeds, as some @@ -397,7 +478,7 @@ function _aggregator_parse_opml($opml) { /** * Page callback: Refreshes a feed, then redirects to the overview page. * - * @param $feed + * @param object $feed * An object describing the feed to be refreshed. * * @see aggregator_menu() @@ -506,7 +587,7 @@ function aggregator_admin_form($form, $form_state) { '#description' => t('For most aggregation tasks, the default settings are fine.'), '#collapsible' => TRUE, '#collapsed' => FALSE, - ); + ); $form['basic_conf'] += $basic_conf; } @@ -535,7 +616,7 @@ function aggregator_admin_form_submit($form, &$form_state) { /** * Form constructor to add/edit/delete aggregator categories. * - * @param $edit + * @param array $edit * An associative array containing: * - title: A string to use for the category title. * - description: A string to use for the category description. @@ -547,13 +628,15 @@ function aggregator_admin_form_submit($form, &$form_state) { * @see aggregator_form_category_submit() */ function aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL)) { - $form['title'] = array('#type' => 'textfield', + $form['title'] = array( + '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $edit['title'], '#maxlength' => 64, '#required' => TRUE, ); - $form['description'] = array('#type' => 'textarea', + $form['description'] = array( + '#type' => 'textarea', '#title' => t('Description'), '#default_value' => $edit['description'], ); @@ -574,7 +657,7 @@ function aggregator_form_category($form, &$form_state, $edit = array('title' => */ function aggregator_form_category_validate($form, &$form_state) { if ($form_state['values']['op'] == t('Save')) { - // Check for duplicate titles + // Check for duplicate titles. if (isset($form_state['values']['cid'])) { $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => $form_state['values']['title'], ':cid' => $form_state['values']['cid']))->fetchObject(); } diff --git a/core/modules/aggregator/aggregator.api.php b/core/modules/aggregator/aggregator.api.php index 0f708eb..e8c2c75 100644 --- a/core/modules/aggregator/aggregator.api.php +++ b/core/modules/aggregator/aggregator.api.php @@ -22,12 +22,12 @@ * Modules that define this hook can be set as active fetcher on * admin/config/services/aggregator. Only one fetcher can be active at a time. * - * @param $feed + * @param object $feed * A feed object representing the resource to be downloaded. $feed->url * contains the link to the feed. Download the data at the URL and expose it * to other modules by attaching it to $feed->source_string. * - * @return + * @return bool * TRUE if fetching was successful, FALSE otherwise. * * @see hook_aggregator_fetch_info() @@ -52,7 +52,7 @@ function hook_aggregator_fetch($feed) { * If this hook is not implemented aggregator will use your module's file name * as title and there will be no description. * - * @return + * @return array * An associative array defining a title and a description string. * * @see hook_aggregator_fetch() @@ -78,7 +78,7 @@ function hook_aggregator_fetch_info() { * Modules that define this hook can be set as the active parser on * admin/config/services/aggregator. Only one parser can be active at a time. * - * @param $feed + * @param object $feed * An object describing the resource to be parsed. $feed->source_string * contains the raw feed data. The hook implementation should parse this data * and add the following properties to the $feed object: @@ -99,7 +99,7 @@ function hook_aggregator_fetch_info() { * the item. * - link: A full URL to the individual feed item. * - * @return + * @return bool * TRUE if parsing was successful, FALSE otherwise. * * @see hook_aggregator_parse_info() @@ -128,7 +128,7 @@ function hook_aggregator_parse($feed) { * If this hook is not implemented aggregator will use your module's file name * as title and there will be no description. * - * @return + * @return array * An associative array defining a title and a description string. * * @see hook_aggregator_parse() @@ -154,7 +154,7 @@ function hook_aggregator_parse_info() { * Modules that define this hook can be activated as processor on * admin/config/services/aggregator. * - * @param $feed + * @param object $feed * A feed object representing the resource to be processed. $feed->items * contains an array of feed items downloaded and parsed at the parsing stage. * See hook_aggregator_parse() for the basic format of a single item in the @@ -185,7 +185,7 @@ function hook_aggregator_process($feed) { * If this hook is not implemented aggregator will use your module's file name * as title and there will be no description. * - * @return + * @return array * An associative array defining a title and a description string. * * @see hook_aggregator_process() @@ -209,7 +209,7 @@ function hook_aggregator_process_info($feed) { * is recommended to implement this hook and to remove data related to $feed * when called. * - * @param $feed + * @param object $feed * The $feed object whose items are being removed. * * @ingroup aggregator diff --git a/core/modules/aggregator/aggregator.fetcher.inc b/core/modules/aggregator/aggregator.fetcher.inc index 831ea78..94de5da 100644 --- a/core/modules/aggregator/aggregator.fetcher.inc +++ b/core/modules/aggregator/aggregator.fetcher.inc @@ -11,7 +11,7 @@ function aggregator_aggregator_fetch_info() { return array( 'title' => t('Default fetcher'), - 'description' => t('Downloads data from a URL using Drupal\'s HTTP request handler.'), + 'description' => t("Downloads data from a URL using Drupal's HTTP request handler."), ); } @@ -37,6 +37,7 @@ function aggregator_aggregator_fetch($feed) { switch ($result->code) { case 304: break; + case 301: $feed->url = $result->redirect_url; // Do not break here. @@ -52,6 +53,7 @@ function aggregator_aggregator_fetch($feed) { $feed->source_string = $result->data; $feed->http_headers = $result->headers; break; + default: watchdog('aggregator', 'The feed from %site seems to be broken due to "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING); drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error))); diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index ebb561b..e121225 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -21,7 +21,7 @@ function aggregator_page_last() { /** * Page callback: Displays all the items captured from a particular feed. * - * @param $feed + * @param object $feed * The feed for which to display all items. * * @see aggregator_menu() @@ -40,7 +40,7 @@ function aggregator_page_source($feed) { /** * Form constructor to show all items captured from a feed. * - * @param $feed + * @param object $feed * The feed for which to list all the aggregated items. * * @see aggregator_menu() @@ -54,7 +54,7 @@ function aggregator_page_source_form($form, $form_state, $feed) { /** * Form constructor to list items aggregated in a category. * - * @param $category + * @param array $category * The category for which to list all the aggregated items. * * @see aggregator_menu() @@ -73,7 +73,7 @@ function aggregator_page_category($category) { /** * Form constructor to list items aggregated in a category. * - * @param $category + * @param array $category * The category for which to list all the aggregated items. * * @see aggregator_menu() @@ -87,13 +87,13 @@ function aggregator_page_category_form($form, $form_state, $category) { /** * Loads and optionally filters feed items. * - * @param $type + * @param string $type * The type of filter for the items. Possible values are: * - sum: No filtering. * - source: Filter the feed items, limiting the result to items from a * single source. * - category: Filter the feed items by category. - * @param $data + * @param object|array $data * Feed or category data used for filtering. The type and value of $data * depends on $type: * - source: $data is an object with $data->fid identifying the feed used to @@ -102,7 +102,7 @@ function aggregator_page_category_form($form, $form_state, $category) { * filter on. * The $data parameter is not used when $type is 'sum'. * - * @return + * @return array * An array of the feed items. */ function aggregator_load_feed_items($type, $data = NULL) { @@ -115,12 +115,14 @@ function aggregator_load_feed_items($type, $data = NULL) { $query->addField('f', 'title', 'ftitle'); $query->addField('f', 'link', 'flink'); break; + case 'source': $query = db_select('aggregator_item', 'i'); $query ->fields('i') ->condition('i.fid', $data->fid); break; + case 'category': $query = db_select('aggregator_category_item', 'c'); $query->leftJoin('aggregator_item', 'i', 'c.iid = i.iid'); @@ -153,15 +155,15 @@ function aggregator_load_feed_items($type, $data = NULL) { * * Various menu callbacks use this function to print their feeds. * - * @param $items + * @param array $items * The items to be listed. - * @param $op + * @param string $op * Which form should be added to the items. Only 'categorize' is now * recognized. - * @param $feed_source + * @param string $feed_source * The feed source URL. * - * @return + * @return string * The rendered list of items for a feed. */ function _aggregator_page_list($items, $op, $feed_source = '') { @@ -184,9 +186,9 @@ function _aggregator_page_list($items, $op, $feed_source = '') { /** * Form constructor to build the page list form. * - * @param $items + * @param array $items * An array of the feed items. - * @param $feed_source + * @param string $feed_source * The feed source URL. * * @ingroup forms @@ -223,7 +225,7 @@ function aggregator_categorize_items($items, $feed_source = '') { '#default_value' => $selected, '#options' => $categories, '#size' => 10, - '#multiple' => TRUE + '#multiple' => TRUE, ); } $form['actions'] = array('#type' => 'actions'); @@ -263,7 +265,7 @@ function aggregator_categorize_items_submit($form, &$form_state) { /** * Returns HTML for the aggregator page list form for assigning categories. * - * @param $variables + * @param array $variables * An associative array containing: * - form: A render element representing the form. * @@ -282,7 +284,13 @@ function theme_aggregator_categorize_items($variables) { ); } } - $output .= theme('table', array('header' => array('', t('Categorize')), 'rows' => $rows)); + $output .= theme( + 'table', + array( + 'header' => array('', t('Categorize')), + 'rows' => $rows, + ) + ); $output .= drupal_render($form['submit']); $output .= drupal_render_children($form); @@ -292,7 +300,7 @@ function theme_aggregator_categorize_items($variables) { /** * Default theme implementation to present a linked feed item for summaries. * - * @param $variables + * @param array $variables * An associative array containing: * - item_link: Link to item. * - item_age: Age of the item. @@ -419,13 +427,11 @@ function aggregator_page_rss() { /** * Prints the RSS page for a feed. * - * @param $variables + * @param array $variables * An associative array containing: * - feeds: An array of the feeds to theme. * - category: A common category, if any, for all the feeds. * - * @return void - * * @ingroup themeable */ function theme_aggregator_page_rss($variables) { @@ -445,6 +451,7 @@ function theme_aggregator_page_rss($variables) { } $feed->description = $summary; break; + case 'title': $feed->description = ''; break; @@ -467,7 +474,7 @@ function theme_aggregator_page_rss($variables) { /** * Page callback: Generates an OPML representation of all feeds. * - * @param $cid + * @param int $cid * If set, feeds are exported only from a category with this ID. Otherwise, * all feeds are exported. * @@ -488,12 +495,10 @@ function aggregator_page_opml($cid = NULL) { /** * Prints the OPML page for a feed. * - * @param $variables + * @param array $variables * An associative array containing: * - feeds: An array of the feeds to theme. * - * @return void - * * @ingroup themeable */ function theme_aggregator_page_opml($variables) { @@ -538,13 +543,13 @@ function template_preprocess_aggregator_summary_item(&$variables) { $variables['item_url'] = l(check_plain($item->title), check_url(url($item->link, array('absolute' => TRUE))), array( 'attributes' => array( - 'class' => array('feed-item-url',), + 'class' => array('feed-item-url'), ), )); $variables['item_age'] = theme('datetime', array( 'attributes' => array( 'datetime' => format_date($item->timestamp, 'html_datetime', '', 'UTC'), - 'class' => array('feed-item-age',), + 'class' => array('feed-item-age'), ), 'text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->timestamp))), 'html' => TRUE, @@ -559,7 +564,13 @@ function template_preprocess_aggregator_summary_item(&$variables) { function template_preprocess_aggregator_feed_source(&$variables) { $feed = $variables['feed']; - $variables['source_icon'] = theme('feed_icon', array('url' => $feed->url, 'title' => t('!title feed', array('!title' => $feed->title)))); + $variables['source_icon'] = theme( + 'feed_icon', + array( + 'url' => $feed->url, + 'title' => t('!title feed', array('!title' => $feed->title)), + ) + ); if (!empty($feed->image) && !empty($feed->title) && !empty($feed->link)) { $variables['source_image'] = l(theme('image', array('path' => $feed->image, 'alt' => $feed->title)), $feed->link, array('html' => TRUE, 'attributes' => array('class' => 'feed-image'))); diff --git a/core/modules/aggregator/aggregator.parser.inc b/core/modules/aggregator/aggregator.parser.inc index 0f594d4..9a55158 100644 --- a/core/modules/aggregator/aggregator.parser.inc +++ b/core/modules/aggregator/aggregator.parser.inc @@ -56,12 +56,12 @@ function aggregator_aggregator_parse($feed) { /** * Parses a feed and stores its items. * - * @param $data + * @param string $data * The feed data. - * @param $feed + * @param object $feed * An object describing the feed to be parsed. * - * @return + * @return bool * FALSE on error, TRUE otherwise. */ function aggregator_parse_feed(&$data, $feed) { @@ -79,8 +79,13 @@ function aggregator_parse_feed(&$data, $feed) { xml_set_character_data_handler($xml_parser, 'aggregator_element_data'); if (!xml_parse($xml_parser, $data, 1)) { - watchdog('aggregator', 'The feed from %site seems to be broken due to an error "%error" on line %line.', array('%site' => $feed->title, '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)), WATCHDOG_WARNING); - drupal_set_message(t('The feed from %site seems to be broken because of error "%error" on line %line.', array('%site' => $feed->title, '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error'); + $message_variables = array( + '%site' => $feed->title, + '%error' => xml_error_string(xml_get_error_code($xml_parser)), + '%line' => xml_get_current_line_number($xml_parser), + ); + watchdog('aggregator', 'The feed from %site seems to be broken due to an error "%error" on line %line.', $message_variables, WATCHDOG_WARNING); + drupal_set_message(t('The feed from %site seems to be broken due to an error "%error" on line %line.', $message_variables), 'error'); return FALSE; } xml_parser_free($xml_parser); @@ -124,7 +129,8 @@ function aggregator_parse_feed(&$data, $feed) { $item['guid'] = isset($item['id']) ? $item['id'] : ''; } - // Atom feeds have a content and/or summary tag instead of a description tag. + // Atom feeds have a content and/or summary tag instead of a description + // tag. if (!empty($item['content:encoded'])) { $item['description'] = $item['content:encoded']; } @@ -137,7 +143,19 @@ function aggregator_parse_feed(&$data, $feed) { // Try to resolve and parse the item's publication date. $date = ''; - foreach (array('pubdate', 'dc:date', 'dcterms:issued', 'dcterms:created', 'dcterms:modified', 'issued', 'created', 'modified', 'published', 'updated') as $key) { + $keys = array( + 'pubdate', + 'dc:date', + 'dcterms:issued', + 'dcterms:created', + 'dcterms:modified', + 'issued', + 'created', + 'modified', + 'published', + 'updated', + ); + foreach ($keys as $key) { if (!empty($item[$key])) { $date = $item[$key]; break; @@ -147,7 +165,8 @@ function aggregator_parse_feed(&$data, $feed) { $item['timestamp'] = strtotime($date); if ($item['timestamp'] === FALSE) { - $item['timestamp'] = aggregator_parse_w3cdtf($date); // Aggregator_parse_w3cdtf() returns FALSE on failure. + // aggregator_parse_w3cdtf() returns FALSE on failure. + $item['timestamp'] = aggregator_parse_w3cdtf($date); } // Resolve dc:creator tag as the item author if author tag is not set. @@ -157,7 +176,8 @@ function aggregator_parse_feed(&$data, $feed) { $item += array('author' => '', 'description' => ''); - // Store on $feed object. This is where processors will look for parsed items. + // Store on $feed object. This is where processors will look for parsed + // items. $feed->items[] = $item; } @@ -183,6 +203,7 @@ function aggregator_element_start($parser, $name, $attributes) { case 'info': $element = $name; break; + case 'id': case 'content': if ($element != 'item') { @@ -201,10 +222,12 @@ function aggregator_element_start($parser, $name, $attributes) { } } break; + case 'item': $element = $name; $item += 1; break; + case 'entry': $element = 'item'; $item += 1; @@ -230,6 +253,7 @@ function aggregator_element_end($parser, $name) { case 'info': $element = ''; break; + case 'id': case 'content': if ($element == $name) { @@ -251,36 +275,43 @@ function aggregator_element_data($parser, $data) { $items[$item] += array($tag => ''); $items[$item][$tag] .= $data; break; + case 'image': case 'logo': $image += array($tag => ''); $image[$tag] .= $data; break; + case 'link': if ($data) { $items[$item] += array($tag => ''); $items[$item][$tag] .= $data; } break; + case 'content': $items[$item] += array('content' => ''); $items[$item]['content'] .= $data; break; + case 'summary': $items[$item] += array('summary' => ''); $items[$item]['summary'] .= $data; break; + case 'tagline': case 'subtitle': $channel += array('description' => ''); $channel['description'] .= $data; break; + case 'info': case 'id': case 'textinput': // The sub-element is not supported. However, we must recognize // it or its contents will end up in the item array. break; + default: $channel += array($tag => ''); $channel[$tag] .= $data; @@ -294,18 +325,19 @@ function aggregator_element_data($parser, $data) { * http://www.w3.org/TR/NOTE-datetime for more information. Originally from * MagpieRSS (http://magpierss.sourceforge.net/). * - * @param $date_str + * @param string $date_str * A string with a potentially W3C DTF date. * - * @return + * @return int|bool * A timestamp if parsed successfully or FALSE if not. */ function aggregator_parse_w3cdtf($date_str) { if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) { - list($year, $month, $day, $hours, $minutes, $seconds) = array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); + list( , $year, $month, $day, $hours, $minutes, $seconds) = $match; // Calculate the epoch for current date assuming GMT. $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year); - if ($match[10] != 'Z') { // Z is zulu time, aka GMT + // Z is Zulu time, which is the same as GMT. + if ($match[10] != 'Z') { list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]); // Zero out the variables. if (!$tz_hour) { diff --git a/core/modules/aggregator/aggregator.processor.inc b/core/modules/aggregator/aggregator.processor.inc index 7fa86a9..2da4a60 100644 --- a/core/modules/aggregator/aggregator.processor.inc +++ b/core/modules/aggregator/aggregator.processor.inc @@ -22,9 +22,9 @@ function aggregator_aggregator_process($feed) { if (is_object($feed)) { if (is_array($feed->items)) { foreach ($feed->items as $item) { - // Save this item. Try to avoid duplicate entries as much as possible. If - // we find a duplicate entry, we resolve it and pass along its ID is such - // that we can update it if needed. + // Save this item. Try to avoid duplicate entries as much as possible. + // If we find a duplicate entry, we resolve it and pass along its ID is + // such that we can update it if needed. if (!empty($item['guid'])) { $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND guid = :guid", array(':fid' => $feed->fid, ':guid' => $item['guid']))->fetchObject(); } @@ -40,7 +40,16 @@ function aggregator_aggregator_process($feed) { // Make sure the item title fits in 255 varchar column. $item['title'] = truncate_utf8($item['title'], 255, TRUE, TRUE); - aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid : ''), 'fid' => $feed->fid, 'timestamp' => $item['timestamp'], 'title' => $item['title'], 'link' => $item['link'], 'author' => $item['author'], 'description' => $item['description'], 'guid' => $item['guid'])); + aggregator_save_item(array( + 'iid' => (isset($entry->iid) ? $entry->iid : ''), + 'fid' => $feed->fid, + 'timestamp' => $item['timestamp'], + 'title' => $item['title'], + 'link' => $item['link'], + 'author' => $item['author'], + 'description' => $item['description'], + 'guid' => $item['guid'], + )); } } } @@ -73,7 +82,22 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { if (in_array('aggregator', variable_get('aggregator_processors', array('aggregator')))) { $info = module_invoke('aggregator', 'aggregator_process', 'info'); $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items'); - $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); + $period = array( + 3600, + 10800, + 21600, + 32400, + 43200, + 86400, + 172800, + 259200, + 604800, + 1209600, + 2419200, + 4838400, + 9676800, + ); + $period = drupal_map_assoc($period, 'format_interval'); $period[AGGREGATOR_CLEAR_NEVER] = t('Never'); // Only wrap into a collapsible fieldset if there is a basic configuration. @@ -110,16 +134,18 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { '#type' => 'radios', '#title' => t('Select categories using'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'), - '#options' => array('checkboxes' => t('checkboxes'), - 'select' => t('multiple selector')), + '#options' => array( + 'checkboxes' => t('checkboxes'), + 'select' => t('multiple selector'), + ), '#description' => t('For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.'), ); $form['modules']['aggregator']['aggregator_teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed description'), '#default_value' => variable_get('aggregator_teaser_length', 600), - '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_aggregator_characters'), - '#description' => t("The maximum number of characters used in the trimmed version of content.") + '#options' => drupal_map_assoc(range(0, 2000, 200), '_aggregator_characters'), + '#description' => t("The maximum number of characters used in the trimmed version of content."), ); } @@ -138,7 +164,7 @@ function _aggregator_characters($length) { /** * Adds/edits/deletes an aggregator item. * - * @param $edit + * @param array $edit * An associative array describing the item to be added/edited/deleted. */ function aggregator_save_item($edit) { @@ -164,7 +190,7 @@ function aggregator_save_item($edit) { ->execute(); } elseif ($edit['title'] && $edit['link']) { - // file the items in the categories indicated by the feed + // File the items in the categories indicated by the feed. $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $edit['fid'])); foreach ($result as $category) { db_merge('aggregator_category_item') @@ -180,8 +206,9 @@ function aggregator_save_item($edit) { /** * Expires items from a feed depending on expiration settings. * - * @param $feed - * Object describing feed. + * @param object $feed + * An object containing: + * - fid: The aggregator_feed.fid to which the item belongs. */ function aggregator_expire($feed) { $aggregator_clear = variable_get('aggregator_clear', 9676800); diff --git a/core/modules/aggregator/aggregator.theme.css b/core/modules/aggregator/aggregator.theme.css index e2182ac..0f5cb2f 100644 --- a/core/modules/aggregator/aggregator.theme.css +++ b/core/modules/aggregator/aggregator.theme.css @@ -1,4 +1,4 @@ .aggregator .feed-icon { - float: right; /* LTR */ display: block; + float: right; /* LTR */ } -- 1.7.4.1