- Patch #256793 by Senpai and flobruit: code clean up.
							parent
							
								
									7cd8427f65
								
							
						
					
					
						commit
						6b88e61700
					
				| 
						 | 
				
			
			@ -2,10 +2,10 @@
 | 
			
		|||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file aggregator-feed-source.tpl.php
 | 
			
		||||
 * @file
 | 
			
		||||
 * Default theme implementation to present the source of the feed.
 | 
			
		||||
 *
 | 
			
		||||
 * The contents are render above feed listings when browsing source feeds.
 | 
			
		||||
 * The contents are rendered above feed listings when browsing source feeds.
 | 
			
		||||
 * For example, "example.com/aggregator/sources/1".
 | 
			
		||||
 *
 | 
			
		||||
 * Available variables:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file aggregator-item.tpl.php
 | 
			
		||||
 * @file
 | 
			
		||||
 * Default theme implementation to format an individual feed item for display
 | 
			
		||||
 * on the aggregator page.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file aggregator-summary-item.tpl.php
 | 
			
		||||
 * @file
 | 
			
		||||
 * Default theme implementation to present a linked feed item for summaries.
 | 
			
		||||
 *
 | 
			
		||||
 * Available variables:
 | 
			
		||||
| 
						 | 
				
			
			@ -16,4 +16,9 @@
 | 
			
		|||
 * @see template_preprocess_aggregator_summary_item()
 | 
			
		||||
 */
 | 
			
		||||
?>
 | 
			
		||||
<a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a> <span class="age"><?php print $feed_age; ?></span><?php if ($source_url) : ?>, <span class="source"><a href="<?php print $source_url; ?>"><?php print $source_title; ?></a></span><?php endif; ?>
 | 
			
		||||
<a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a>
 | 
			
		||||
<span class="age"><?php print $feed_age; ?></span>
 | 
			
		||||
 | 
			
		||||
<?php if ($source_url) : ?>,
 | 
			
		||||
<span class="source"><a href="<?php print $source_url; ?>"><?php print $source_title; ?></a></span>
 | 
			
		||||
<?php endif; ?>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file aggregator-summary-items.tpl.php
 | 
			
		||||
 * @file
 | 
			
		||||
 * Default theme implementation to present feeds as list items.
 | 
			
		||||
 *
 | 
			
		||||
 * Each iteration generates a single feed source or category.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file comment-wrapper.tpl.php
 | 
			
		||||
 * @file
 | 
			
		||||
 * Default theme implementation to wrap aggregator content.
 | 
			
		||||
 *
 | 
			
		||||
 * Available variables:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,7 +80,7 @@ function aggregator_form_feed(&$form_state, $edit = array('refresh' => 900, 'tit
 | 
			
		|||
    '#description' => t('The length of time between feed updates. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Handling of categories:
 | 
			
		||||
  // Handling of 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 = %d ORDER BY title', $edit['fid']);
 | 
			
		||||
| 
						 | 
				
			
			@ -89,25 +89,35 @@ function aggregator_form_feed(&$form_state, $edit = array('refresh' => 900, 'tit
 | 
			
		|||
    if ($category->fid) $values[] = $category->cid;
 | 
			
		||||
  }
 | 
			
		||||
  if ($options) {
 | 
			
		||||
    $form['category'] = array('#type' => 'checkboxes',
 | 
			
		||||
    $form['category'] = array(
 | 
			
		||||
      '#type' => 'checkboxes',
 | 
			
		||||
      '#title' => t('Categorize news items'),
 | 
			
		||||
      '#default_value' => $values,
 | 
			
		||||
      '#options' => $options,
 | 
			
		||||
      '#description' => t('New feed items are automatically filed in the checked categories.'),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
 | 
			
		||||
  $form['submit'] = array(
 | 
			
		||||
    '#type' => 'submit',
 | 
			
		||||
    '#value' => t('Save'),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  if ($edit['fid']) {
 | 
			
		||||
    $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
 | 
			
		||||
    $form['fid'] = array('#type' => 'hidden', '#value' => $edit['fid']);
 | 
			
		||||
    $form['delete'] = array(
 | 
			
		||||
      '#type' => 'submit',
 | 
			
		||||
      '#value' => t('Delete'),
 | 
			
		||||
    );
 | 
			
		||||
    $form['fid'] = array(
 | 
			
		||||
      '#type' => 'hidden',
 | 
			
		||||
      '#value' => $edit['fid'],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return $form;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Validate aggregator_form_feed form submissions.
 | 
			
		||||
 * Validate aggregator_form_feed() form submissions.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_form_feed_validate($form, &$form_state) {
 | 
			
		||||
  if ($form_state['values']['op'] == t('Save')) {
 | 
			
		||||
| 
						 | 
				
			
			@ -134,14 +144,14 @@ function aggregator_form_feed_validate($form, &$form_state) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Process aggregator_form_feed form submissions.
 | 
			
		||||
 * Process aggregator_form_feed() form submissions.
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Add delete confirmation dialog.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_form_feed_submit($form, &$form_state) {
 | 
			
		||||
  if ($form_state['values']['op'] == t('Delete')) {
 | 
			
		||||
    $title = $form_state['values']['title'];
 | 
			
		||||
    // Unset the title:
 | 
			
		||||
    // Unset the title.
 | 
			
		||||
    unset($form_state['values']['title']);
 | 
			
		||||
  }
 | 
			
		||||
  aggregator_save_feed($form_state['values']);
 | 
			
		||||
| 
						 | 
				
			
			@ -227,25 +237,25 @@ function aggregator_admin_settings() {
 | 
			
		|||
  $form['aggregator_allowed_html_tags'] = array(
 | 
			
		||||
    '#type' => 'textfield', '#title' => t('Allowed HTML tags'), '#size' => 80, '#maxlength' => 255,
 | 
			
		||||
    '#default_value' => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
 | 
			
		||||
    '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. (Tags in this list are not removed by Drupal.)')
 | 
			
		||||
    '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. (Tags in this list are not removed by Drupal.)'),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  $form['aggregator_summary_items'] = array(
 | 
			
		||||
    '#type' => 'select', '#title' => t('Items shown in sources and categories pages') ,
 | 
			
		||||
    '#default_value' => variable_get('aggregator_summary_items', 3), '#options' => $items,
 | 
			
		||||
    '#description' => t('Number of feed items displayed in feed and category summary pages.')
 | 
			
		||||
    '#description' => t('Number of feed items displayed in feed and category summary pages.'),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  $form['aggregator_clear'] = array(
 | 
			
		||||
    '#type' => 'select', '#title' => t('Discard items older than'),
 | 
			
		||||
    '#default_value' => variable_get('aggregator_clear', 9676800), '#options' => $period,
 | 
			
		||||
    '#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status')))
 | 
			
		||||
    '#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  $form['aggregator_category_selector'] = array(
 | 
			
		||||
    '#type' => 'radios', '#title' => t('Category selection type'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),
 | 
			
		||||
    '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')),
 | 
			
		||||
    '#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector work well with large numbers of categories.)')
 | 
			
		||||
    '#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector work well with large numbers of categories.)'),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  return system_settings_form($form);
 | 
			
		||||
| 
						 | 
				
			
			@ -305,7 +315,7 @@ function aggregator_form_category_validate($form, &$form_state) {
 | 
			
		|||
function aggregator_form_category_submit($form, &$form_state) {
 | 
			
		||||
  if ($form_state['values']['op'] == t('Delete')) {
 | 
			
		||||
    $title = $form_state['values']['title'];
 | 
			
		||||
    // Unset the title:
 | 
			
		||||
    // Unset the title.
 | 
			
		||||
    unset($form_state['values']['title']);
 | 
			
		||||
  }
 | 
			
		||||
  aggregator_save_category($form_state['values']);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
; $Id$
 | 
			
		||||
 | 
			
		||||
name = Aggregator
 | 
			
		||||
description = "Aggregates syndicated content (RSS, RDF, and Atom feeds)."
 | 
			
		||||
package = Core - optional
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -230,7 +230,7 @@ function aggregator_schema() {
 | 
			
		|||
      'timestamp' => array(
 | 
			
		||||
        'type' => 'int',
 | 
			
		||||
        'not null' => FALSE,
 | 
			
		||||
        'description' => t('Post date of feed item, as a Unix timestamp.'),
 | 
			
		||||
        'description' => t('Posted date of the feed item, as a Unix timestamp.'),
 | 
			
		||||
      ),
 | 
			
		||||
      'guid' => array(
 | 
			
		||||
        'type' => 'varchar',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,7 +28,7 @@ function aggregator_help($path, $arg) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implementation of hook_theme()
 | 
			
		||||
 * Implementation of hook_theme().
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_theme() {
 | 
			
		||||
  return array(
 | 
			
		||||
| 
						 | 
				
			
			@ -370,7 +370,7 @@ function aggregator_save_category($edit) {
 | 
			
		|||
    }
 | 
			
		||||
  }
 | 
			
		||||
  elseif (!empty($edit['title'])) {
 | 
			
		||||
    // A single unique id for bundles and feeds, to use in blocks
 | 
			
		||||
    // A single unique id for bundles and feeds, to use in blocks.
 | 
			
		||||
    db_query("INSERT INTO {aggregator_category} (title, description, block) VALUES ('%s', '%s', 5)", $edit['title'], $edit['description']);
 | 
			
		||||
    $link_path .= db_last_insert_id('aggregator', 'cid');
 | 
			
		||||
    $op = 'insert';
 | 
			
		||||
| 
						 | 
				
			
			@ -408,7 +408,7 @@ function aggregator_save_feed($edit) {
 | 
			
		|||
  }
 | 
			
		||||
  elseif (!empty($edit['title'])) {
 | 
			
		||||
    db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block, description, image) VALUES ('%s', '%s', %d, 5, '', '')", $edit['title'], $edit['url'], $edit['refresh']);
 | 
			
		||||
    // A single unique id for bundles and feeds, to use in blocks.
 | 
			
		||||
    // A single unique ID for bundles and feeds, to use in blocks.
 | 
			
		||||
    $edit['fid'] = db_last_insert_id('aggregator_feed', 'fid');
 | 
			
		||||
  }
 | 
			
		||||
  if (!empty($edit['title'])) {
 | 
			
		||||
| 
						 | 
				
			
			@ -443,7 +443,7 @@ function aggregator_remove($feed) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Call-back function used by the XML parser.
 | 
			
		||||
 * Callback function used by the XML parser.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_element_start($parser, $name, $attributes) {
 | 
			
		||||
  global $item, $element, $tag, $items, $channel;
 | 
			
		||||
| 
						 | 
				
			
			@ -509,7 +509,7 @@ function aggregator_element_end($parser, $name) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Call-back function used by the XML parser.
 | 
			
		||||
 * Callback function used by the XML parser.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_element_data($parser, $data) {
 | 
			
		||||
  global $channel, $element, $items, $item, $image, $tag;
 | 
			
		||||
| 
						 | 
				
			
			@ -585,11 +585,11 @@ function aggregator_refresh($feed) {
 | 
			
		|||
    case 301:
 | 
			
		||||
      $feed['url'] = $result->redirect_url;
 | 
			
		||||
      watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url']));
 | 
			
		||||
      // Deliberate no break.
 | 
			
		||||
      // Do not break here.
 | 
			
		||||
    case 200:
 | 
			
		||||
    case 302:
 | 
			
		||||
    case 307:
 | 
			
		||||
      // Filter the input data:
 | 
			
		||||
      // Filter the input data.
 | 
			
		||||
      if (aggregator_parse_feed($result->data, $feed)) {
 | 
			
		||||
        $modified = empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -604,7 +604,8 @@ function aggregator_refresh($feed) {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        if (!empty($image['LINK']) && !empty($image['URL']) && !empty($image['TITLE'])) {
 | 
			
		||||
          // Note, we should really use theme_image() here but that only works with local images it won't work with images fetched with a URL unless PHP version > 5
 | 
			
		||||
          // TODO: we should really use theme_image() here, but that only works with
 | 
			
		||||
          // local images. It won't work with images fetched with a URL unless PHP version > 5.
 | 
			
		||||
          $image = '<a href="' . check_url($image['LINK']) . '" class="feed-image"><img src="' . check_url($image['URL']) . '" alt="' . check_plain($image['TITLE']) . '" /></a>';
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
| 
						 | 
				
			
			@ -623,7 +624,7 @@ function aggregator_refresh($feed) {
 | 
			
		|||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      $result->error = t('feed not parseable');
 | 
			
		||||
      // Deliberate no break.
 | 
			
		||||
      // Do not break here..
 | 
			
		||||
    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)));
 | 
			
		||||
| 
						 | 
				
			
			@ -632,8 +633,9 @@ function aggregator_refresh($feed) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing
 | 
			
		||||
 * functions do not handle this format.
 | 
			
		||||
 * Parse the W3C date/time format, a subset of ISO 8601.
 | 
			
		||||
 *
 | 
			
		||||
 * PHP date parsing functions do not handle this format.
 | 
			
		||||
 * See http://www.w3.org/TR/NOTE-datetime for more information.
 | 
			
		||||
 * Originally from MagpieRSS (http://magpierss.sourceforge.net/).
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -645,11 +647,11 @@ function aggregator_refresh($feed) {
 | 
			
		|||
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]);
 | 
			
		||||
    // calc epoch for current date assuming GMT
 | 
			
		||||
    // 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
 | 
			
		||||
      list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]);
 | 
			
		||||
      // zero out the variables
 | 
			
		||||
      // Zero out the variables.
 | 
			
		||||
      if (!$tz_hour) {
 | 
			
		||||
        $tz_hour = 0;
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -657,7 +659,7 @@ function aggregator_parse_w3cdtf($date_str) {
 | 
			
		|||
        $tz_min = 0;
 | 
			
		||||
      }
 | 
			
		||||
      $offset_secs = (($tz_hour * 60) + $tz_min) * 60;
 | 
			
		||||
      // is timezone ahead of GMT?  then subtract offset
 | 
			
		||||
      // Is timezone ahead of GMT?  If yes, subtract offset.
 | 
			
		||||
      if ($tz_mod == '+') {
 | 
			
		||||
        $offset_secs *= -1;
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -683,13 +685,13 @@ function aggregator_parse_w3cdtf($date_str) {
 | 
			
		|||
function aggregator_parse_feed(&$data, $feed) {
 | 
			
		||||
  global $items, $image, $channel;
 | 
			
		||||
 | 
			
		||||
  // Unset the global variables before we use them:
 | 
			
		||||
  // Unset the global variables before we use them.
 | 
			
		||||
  unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']);
 | 
			
		||||
  $items = array();
 | 
			
		||||
  $image = array();
 | 
			
		||||
  $channel = array();
 | 
			
		||||
 | 
			
		||||
  // parse the data:
 | 
			
		||||
  // Parse the data.
 | 
			
		||||
  $xml_parser = drupal_xml_parser_create($data);
 | 
			
		||||
  xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end');
 | 
			
		||||
  xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
 | 
			
		||||
| 
						 | 
				
			
			@ -716,7 +718,7 @@ function aggregator_parse_feed(&$data, $feed) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Resolve the item's title. If no title is found, we use up to 40
 | 
			
		||||
    // characters of the description ending at a word boundary but not
 | 
			
		||||
    // characters of the description ending at a word boundary, but not
 | 
			
		||||
    // splitting potential entities.
 | 
			
		||||
    if (!empty($item['TITLE'])) {
 | 
			
		||||
      $title = $item['TITLE'];
 | 
			
		||||
| 
						 | 
				
			
			@ -749,7 +751,7 @@ function aggregator_parse_feed(&$data, $feed) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Try to resolve and parse the item's publication date. If no date is
 | 
			
		||||
    // found, we use the current date instead.
 | 
			
		||||
    // found, use the current date instead.
 | 
			
		||||
    $date = 'now';
 | 
			
		||||
    foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) {
 | 
			
		||||
      if (!empty($item[$key])) {
 | 
			
		||||
| 
						 | 
				
			
			@ -759,10 +761,12 @@ function aggregator_parse_feed(&$data, $feed) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    $timestamp = strtotime($date); // As of PHP 5.1.0, strtotime returns FALSE on failure instead of -1.
 | 
			
		||||
 | 
			
		||||
    if ($timestamp <= 0) {
 | 
			
		||||
      $timestamp = aggregator_parse_w3cdtf($date); // Returns FALSE on failure
 | 
			
		||||
      $timestamp = aggregator_parse_w3cdtf($date); // Aggregator_parse_w3cdtf() returns FALSE on failure.
 | 
			
		||||
      if (!$timestamp) {
 | 
			
		||||
        $timestamp = time(); // better than nothing
 | 
			
		||||
        // Better than nothing.
 | 
			
		||||
        $timestamp = time();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -838,6 +842,7 @@ function aggregator_feed_load($fid) {
 | 
			
		|||
  if (!isset($feeds[$fid])) {
 | 
			
		||||
    $feeds[$fid] = db_fetch_array(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', $fid));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return $feeds[$fid];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -854,6 +859,7 @@ function aggregator_category_load($cid) {
 | 
			
		|||
  if (!isset($categories[$cid])) {
 | 
			
		||||
    $categories[$cid] = db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return $categories[$cid];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ function aggregator_page_last() {
 | 
			
		|||
 * @param $arg2
 | 
			
		||||
 *   If there are two arguments then $arg2 is feed.
 | 
			
		||||
 * @return
 | 
			
		||||
 *   The items HTML.
 | 
			
		||||
 *   The item's HTML.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_page_source($arg1, $arg2 = NULL) {
 | 
			
		||||
  // If there are two arguments then this function is the categorize form, and
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +95,7 @@ function aggregator_feed_items_load($sql) {
 | 
			
		|||
      $items[$item->iid] = $item;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return $items;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -125,6 +126,7 @@ function _aggregator_page_list($items, $op, $feed_source = '') {
 | 
			
		|||
    }
 | 
			
		||||
    $output = theme('aggregator_wrapper', $output);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return $output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -145,11 +147,15 @@ function aggregator_categorize_items($items, $feed_source = '') {
 | 
			
		|||
  $form['#submit'][] = 'aggregator_categorize_items_submit';
 | 
			
		||||
  $form['#validate'][] = 'aggregator_categorize_items_validate';
 | 
			
		||||
  $form['#theme'] = 'aggregator_categorize_items';
 | 
			
		||||
  $form['feed_source'] = array('#value' => $feed_source);
 | 
			
		||||
  $form['feed_source'] = array(
 | 
			
		||||
    '#value' => $feed_source,
 | 
			
		||||
  );
 | 
			
		||||
  $categories = array();
 | 
			
		||||
  $done = FALSE;
 | 
			
		||||
  $form['items'] = array();
 | 
			
		||||
  $form['categories'] = array('#tree' => TRUE);
 | 
			
		||||
  $form['categories'] = array(
 | 
			
		||||
    '#tree' => TRUE,
 | 
			
		||||
  );
 | 
			
		||||
  foreach ($items as $item) {
 | 
			
		||||
    $form['items'][$item->iid] = array('#value' => theme('aggregator_item', $item));
 | 
			
		||||
    $form['categories'][$item->iid] = array();
 | 
			
		||||
| 
						 | 
				
			
			@ -178,7 +184,7 @@ function aggregator_categorize_items($items, $feed_source = '') {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Validate aggregator_categorize_items form submissions.
 | 
			
		||||
 * Validate aggregator_categorize_items() form submissions.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_categorize_items_validate($form, &$form_state) {
 | 
			
		||||
  if (!user_access('administer news feeds')) {
 | 
			
		||||
| 
						 | 
				
			
			@ -187,7 +193,7 @@ function aggregator_categorize_items_validate($form, &$form_state) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Process aggregator_categorize_items form submissions.
 | 
			
		||||
 * Process aggregator_categorize_items() form submissions.
 | 
			
		||||
 */
 | 
			
		||||
function aggregator_categorize_items_submit($form, &$form_state) {
 | 
			
		||||
  if (!empty($form_state['values']['categories'])) {
 | 
			
		||||
| 
						 | 
				
			
			@ -228,6 +234,7 @@ function theme_aggregator_categorize_items($form) {
 | 
			
		|||
  $output .= theme('table', array('', t('Categorize')), $rows);
 | 
			
		||||
  $output .= drupal_render($form['submit']);
 | 
			
		||||
  $output .= drupal_render($form);
 | 
			
		||||
 | 
			
		||||
  return theme('aggregator_wrapper', $output);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -322,13 +329,13 @@ function aggregator_page_categories() {
 | 
			
		|||
 */
 | 
			
		||||
function aggregator_page_rss() {
 | 
			
		||||
  $result = NULL;
 | 
			
		||||
  // arg(2) is the passed cid, only select for that category
 | 
			
		||||
  // arg(2) is the passed cid, only select for that category.
 | 
			
		||||
  if (arg(2)) {
 | 
			
		||||
    $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2)));
 | 
			
		||||
    $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, i.iid DESC';
 | 
			
		||||
    $result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
 | 
			
		||||
  }
 | 
			
		||||
  // or, get the default aggregator items
 | 
			
		||||
  // Or, get the default aggregator items.
 | 
			
		||||
  else {
 | 
			
		||||
    $category = NULL;
 | 
			
		||||
    $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC';
 | 
			
		||||
| 
						 | 
				
			
			@ -339,6 +346,7 @@ function aggregator_page_rss() {
 | 
			
		|||
  while ($item = db_fetch_object($result)) {
 | 
			
		||||
    $feeds[] = $item;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return theme('aggregator_page_rss', $feeds, $category);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -416,7 +424,6 @@ function aggregator_page_opml($cid = NULL) {
 | 
			
		|||
 * @ingroup themeable
 | 
			
		||||
 */
 | 
			
		||||
function theme_aggregator_page_opml($feeds) {
 | 
			
		||||
 | 
			
		||||
  drupal_set_header('Content-Type: text/xml; charset=utf-8');
 | 
			
		||||
 | 
			
		||||
  $output  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,18 +60,18 @@ class AggregatorTestCase extends DrupalWebTestCase {
 | 
			
		|||
   * @param object $feed Feed object representing the feed.
 | 
			
		||||
   */
 | 
			
		||||
  function updateFeedItems(&$feed) {
 | 
			
		||||
    // First, let's ensure we could get to the rss xml
 | 
			
		||||
    // First, let's ensure we can get to the rss xml.
 | 
			
		||||
    $this->drupalGet('rss.xml');
 | 
			
		||||
    $this->assertResponse(200, t('rss.xml is reachable.'));
 | 
			
		||||
 | 
			
		||||
    // our tests are based off of rss.xml, so let's find out how many elements should be related
 | 
			
		||||
    // Our tests are based off of rss.xml, so let's find out how many elements should be related.
 | 
			
		||||
    $feed_count = db_result(db_query_range(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1'), 0, variable_get('feed_default_items', 10)));
 | 
			
		||||
    $feed_count = $feed_count > 10 ? 10 : $feed_count;
 | 
			
		||||
 | 
			
		||||
    // refresh the feed (simulated link click)
 | 
			
		||||
    // Refresh the feed (simulated link click).
 | 
			
		||||
    $this->drupalGet('admin/content/aggregator/update/'. $feed->fid);
 | 
			
		||||
 | 
			
		||||
    // ensure we have the right number of items
 | 
			
		||||
    // Ensure we have the right number of items.
 | 
			
		||||
    $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $feed->fid);
 | 
			
		||||
    $items = array();
 | 
			
		||||
    $feed->items = array();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue