web/drupal/modules/aggregator/aggregator.module
author cavaliet@caf4f556-3d62-0410-8435-a86758001935
Fri, 21 Aug 2009 16:26:26 +0000
branchdrupal
changeset 74 0ff3ba646492
permissions -rw-r--r--
Create branch for drupal with first commit from local working copy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     2
// $Id: aggregator.module,v 1.374.2.5 2009/03/30 12:15:53 goba Exp $
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     3
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     4
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
 * @file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
 * Used to aggregate syndicated content (RSS, RDF, and Atom).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     7
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     8
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     9
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    10
 * Implementation of hook_help().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    11
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    12
function aggregator_help($path, $arg) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
  switch ($path) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
    case 'admin/help#aggregator':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    15
      $output = '<p>'. t('The aggregator is a powerful on-site syndicator and news reader that gathers fresh content from RSS-, RDF-, and Atom-based feeds made available across the web. Thousands of sites (particularly news sites and blogs) publish their latest headlines and posts in feeds, using a number of standardized XML-based formats. Formats supported by the aggregator include <a href="@rss">RSS</a>, <a href="@rdf">RDF</a>, and <a href="@atom">Atom</a>.', array('@rss' => 'http://cyber.law.harvard.edu/rss/', '@rdf' => 'http://www.w3.org/RDF/', '@atom' => 'http://www.atomenabled.org')) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    16
      $output .= '<p>'. t('Feeds contain feed items, or individual posts published by the site providing the feed. Feeds may be grouped in categories, generally by topic. Users view feed items in the <a href="@aggregator">main aggregator display</a> or by <a href="@aggregator-sources">their source</a>. Administrators can <a href="@feededit">add, edit and delete feeds</a> and choose how often to check each feed for newly updated items. The most recent items in either a feed or category can be displayed as a block through the <a href="@admin-block">blocks administration page</a>. A <a href="@aggregator-opml">machine-readable OPML file</a> of all feeds is available. A correctly configured <a href="@cron">cron maintenance task</a> is required to update feeds automatically.', array('@aggregator' => url('aggregator'), '@aggregator-sources' => url('aggregator/sources'), '@feededit' => url('admin/content/aggregator'), '@admin-block' => url('admin/build/block'), '@aggregator-opml' => url('aggregator/opml'), '@cron' => url('admin/reports/status'))) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    17
      $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@aggregator">Aggregator module</a>.', array('@aggregator' => 'http://drupal.org/handbook/modules/aggregator/')) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    18
      return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    19
    case 'admin/content/aggregator':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
      $output = '<p>'. t('Thousands of sites (particularly news sites and blogs) publish their latest headlines and posts in feeds, using a number of standardized XML-based formats. Formats supported by the aggregator include <a href="@rss">RSS</a>, <a href="@rdf">RDF</a>, and <a href="@atom">Atom</a>.', array('@rss' => 'http://cyber.law.harvard.edu/rss/', '@rdf' => 'http://www.w3.org/RDF/', '@atom' => 'http://www.atomenabled.org')) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    21
      $output .= '<p>'. t('Current feeds are listed below, and <a href="@addfeed">new feeds may be added</a>. For each feed or feed category, the <em>latest items</em> block may be enabled at the <a href="@block">blocks administration page</a>.', array('@addfeed' => url('admin/content/aggregator/add/feed'), '@block' => url('admin/build/block'))) .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    22
      return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    23
    case 'admin/content/aggregator/add/feed':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    24
      return '<p>'. t('Add a feed in RSS, RDF or Atom format. A feed may only have one entry.') .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    25
    case 'admin/content/aggregator/add/category':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    26
      return '<p>'. t('Categories allow feed items from different feeds to be grouped together. For example, several sport-related feeds may belong to a category named <em>Sports</em>. Feed items may be grouped automatically (by selecting a category when creating or editing a feed) or manually (via the <em>Categorize</em> page available from feed item listings). Each category provides its own feed page and block.') .'</p>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    27
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    28
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    29
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    30
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    31
 * Implementation of hook_theme()
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    32
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    33
function aggregator_theme() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    34
  return array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    35
    'aggregator_wrapper' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    36
      'arguments' => array('content' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    37
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    38
      'template' => 'aggregator-wrapper',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    39
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    40
    'aggregator_categorize_items' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
      'arguments' => array('form' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
    'aggregator_feed_source' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
      'arguments' => array('feed' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    46
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    47
      'template' => 'aggregator-feed-source',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    48
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    49
    'aggregator_block_item' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    50
      'arguments' => array('item' => NULL, 'feed' => 0),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    51
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    52
    'aggregator_summary_items' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    53
      'arguments' => array('summary_items' => NULL, 'source' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
      'template' => 'aggregator-summary-items',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
    'aggregator_summary_item' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
      'arguments' => array('item' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
      'template' => 'aggregator-summary-item',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
    'aggregator_item' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
      'arguments' => array('item' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
      'template' => 'aggregator-item',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
    'aggregator_page_opml' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
      'arguments' => array('feeds' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
    'aggregator_page_rss' => array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
      'arguments' => array('feeds' => NULL, 'category' => NULL),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    73
      'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
    ),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    79
 * Implementation of hook_menu().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    80
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    81
function aggregator_menu() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    82
  $items['admin/content/aggregator'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    83
    'title' => 'Feed aggregator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    84
    'description' => "Configure which content your site aggregates from other sites, how often it polls them, and how they're categorized.",
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    85
    'page callback' => 'aggregator_admin_overview',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    86
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    87
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    88
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    89
  $items['admin/content/aggregator/add/feed'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    90
    'title' => 'Add feed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    91
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    92
    'page arguments' => array('aggregator_form_feed'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    93
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    94
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    95
    'parent' => 'admin/content/aggregator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    96
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    97
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    98
  $items['admin/content/aggregator/add/category'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    99
    'title' => 'Add category',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
    'page arguments' => array('aggregator_form_category'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
    'parent' => 'admin/content/aggregator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   105
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   106
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   107
  $items['admin/content/aggregator/remove/%aggregator_feed'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   108
    'title' => 'Remove items',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   109
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
    'page arguments' => array('aggregator_admin_remove_feed', 4),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   112
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   113
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   114
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   115
  $items['admin/content/aggregator/update/%aggregator_feed'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   116
    'title' => 'Update items',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   117
    'page callback' => 'aggregator_admin_refresh_feed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   118
    'page arguments' => array(4),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   119
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   120
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   121
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   122
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   123
  $items['admin/content/aggregator/list'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   124
    'title' => 'List',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   125
    'type' => MENU_DEFAULT_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   126
    'weight' => -10,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   127
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   128
  $items['admin/content/aggregator/settings'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   129
    'title' => 'Settings',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   130
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   131
    'page arguments' => array('aggregator_admin_settings'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   132
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   133
    'weight' => 10,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   134
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   135
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   136
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   137
  $items['aggregator'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   138
    'title' => 'Feed aggregator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   139
    'page callback' => 'aggregator_page_last',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   140
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   141
    'weight' => 5,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   142
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   143
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   144
  $items['aggregator/sources'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   145
    'title' => 'Sources',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   146
    'page callback' => 'aggregator_page_sources',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   147
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   148
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   149
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   150
  $items['aggregator/categories'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   151
    'title' => 'Categories',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   152
    'page callback' => 'aggregator_page_categories',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   153
    'access callback' => '_aggregator_has_categories',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   154
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   155
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   156
  $items['aggregator/rss'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   157
    'title' => 'RSS feed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   158
    'page callback' => 'aggregator_page_rss',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   159
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   160
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   161
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   162
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   163
  $items['aggregator/opml'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   164
    'title' => 'OPML feed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   165
    'page callback' => 'aggregator_page_opml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   166
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   167
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   168
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   169
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   170
  $items['aggregator/categories/%aggregator_category'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   171
    'title callback' => '_aggregator_category_title',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   172
    'title arguments' => array(2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   173
    'page callback' => 'aggregator_page_category',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   174
    'page arguments' => array(2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   175
    'access callback' => 'user_access',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   176
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   177
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   178
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   179
  $items['aggregator/categories/%aggregator_category/view'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   180
    'title' => 'View',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   181
    'type' => MENU_DEFAULT_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   182
    'weight' => -10,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   183
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   184
  $items['aggregator/categories/%aggregator_category/categorize'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   185
    'title' => 'Categorize',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   186
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   187
    'page arguments' => array('aggregator_page_category', 2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   188
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   189
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   190
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   191
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   192
  $items['aggregator/categories/%aggregator_category/configure'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   193
    'title' => 'Configure',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   194
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   195
    'page arguments' => array('aggregator_form_category', 2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   196
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   197
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   198
    'weight' => 1,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   199
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   200
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   201
  $items['aggregator/sources/%aggregator_feed'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   202
    'page callback' => 'aggregator_page_source',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   203
    'page arguments' => array(2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   204
    'access arguments' => array('access news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   205
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   206
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   207
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   208
  $items['aggregator/sources/%aggregator_feed/view'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   209
    'title' => 'View',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   210
    'type' => MENU_DEFAULT_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   211
    'weight' => -10,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   212
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   213
  $items['aggregator/sources/%aggregator_feed/categorize'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   214
    'title' => 'Categorize',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   215
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   216
    'page arguments' => array('aggregator_page_source', 2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   217
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   218
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   219
    'file' => 'aggregator.pages.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   220
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   221
  $items['aggregator/sources/%aggregator_feed/configure'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   222
    'title' => 'Configure',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   223
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   224
    'page arguments' => array('aggregator_form_feed', 2),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   225
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   226
    'type' => MENU_LOCAL_TASK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   227
    'weight' => 1,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   228
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   229
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   230
  $items['admin/content/aggregator/edit/feed/%aggregator_feed'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   231
    'title' => 'Edit feed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   232
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   233
    'page arguments' => array('aggregator_form_feed', 5),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   234
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   235
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   236
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   237
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   238
  $items['admin/content/aggregator/edit/category/%aggregator_category'] = array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   239
    'title' => 'Edit category',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   240
    'page callback' => 'drupal_get_form',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   241
    'page arguments' => array('aggregator_form_category', 5),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   242
    'access arguments' => array('administer news feeds'),
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   243
    'type' => MENU_CALLBACK,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   244
    'file' => 'aggregator.admin.inc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   245
  );
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   246
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   247
  return $items;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   248
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   249
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   250
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   251
 * Menu callback.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   252
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   253
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   254
 *   An aggregator category title.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   255
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   256
function _aggregator_category_title($category) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   257
  return $category['title'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   258
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   259
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   260
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   261
 * Implementation of hook_init().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   262
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   263
function aggregator_init() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   264
  drupal_add_css(drupal_get_path('module', 'aggregator') .'/aggregator.css');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   265
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   266
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   267
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   268
 * Find out whether there are any aggregator categories.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   269
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   270
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   271
 *   TRUE if there is at least one category and the user has access to them, FALSE otherwise.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   272
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   273
function _aggregator_has_categories() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   274
  return user_access('access news feeds') && db_result(db_query('SELECT COUNT(*) FROM {aggregator_category}'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   275
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   276
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   277
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   278
 * Implementation of hook_perm().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   279
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   280
function aggregator_perm() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   281
  return array('administer news feeds', 'access news feeds');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   282
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   283
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   284
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   285
 * Implementation of hook_cron().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   286
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   287
 * Checks news feeds for updates once their refresh interval has elapsed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   288
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   289
function aggregator_cron() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   290
  $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d', time());
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   291
  while ($feed = db_fetch_array($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   292
    aggregator_refresh($feed);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   293
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   294
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   295
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   296
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   297
 * Implementation of hook_block().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   298
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   299
 * Generates blocks for the latest news items in each category and feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   300
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   301
function aggregator_block($op = 'list', $delta = 0, $edit = array()) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   302
  if (user_access('access news feeds')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   303
    if ($op == 'list') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   304
      $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   305
      while ($category = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   306
        $block['category-'. $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   307
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   308
      $result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   309
      while ($feed = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   310
        $block['feed-'. $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   311
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   312
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   313
    else if ($op == 'configure') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   314
      list($type, $id) = explode('-', $delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   315
      if ($type == 'category') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   316
        $value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   317
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   318
      else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   319
        $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   320
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   321
      $form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   322
      return $form;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   323
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   324
    else if ($op == 'save') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   325
      list($type, $id) = explode('-', $delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   326
      if ($type == 'category') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   327
        $value = db_query('UPDATE {aggregator_category} SET block = %d WHERE cid = %d', $edit['block'], $id);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   328
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   329
      else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   330
        $value = db_query('UPDATE {aggregator_feed} SET block = %d WHERE fid = %d', $edit['block'], $id);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   331
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   332
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   333
    else if ($op == 'view') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   334
      list($type, $id) = explode('-', $delta);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   335
      switch ($type) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   336
        case 'feed':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   337
          if ($feed = db_fetch_object(db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE fid = %d', $id))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   338
            $block['subject'] = check_plain($feed->title);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   339
            $result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, $feed->block);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   340
            $read_more = theme('more_link', url('aggregator/sources/'. $feed->fid), t("View this feed's recent news."));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   341
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   342
          break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   343
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   344
        case 'category':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   345
          if ($category = db_fetch_object(db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = %d', $id))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   346
            $block['subject'] = check_plain($category->title);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   347
            $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = %d ORDER BY i.timestamp DESC, i.iid DESC', $category->cid, 0, $category->block);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   348
            $read_more = theme('more_link', url('aggregator/categories/'. $category->cid), t("View this category's recent news."));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   349
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   350
          break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   351
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   352
      $items = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   353
      while ($item = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   354
        $items[] = theme('aggregator_block_item', $item);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   355
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   356
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   357
      // Only display the block if there are items to show.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   358
      if (count($items) > 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   359
        $block['content'] = theme('item_list', $items) . $read_more;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   360
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   361
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   362
    if (isset($block)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   363
      return $block;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   364
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   365
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   366
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   367
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   368
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   369
 * Add/edit/delete aggregator categories.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   370
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   371
 * @param $edit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   372
 *   An associative array describing the category to be added/edited/deleted.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   373
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   374
function aggregator_save_category($edit) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   375
  $link_path = 'aggregator/categories/';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   376
  if (!empty($edit['cid'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   377
    $link_path .= $edit['cid'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   378
    if (!empty($edit['title'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   379
      db_query("UPDATE {aggregator_category} SET title = '%s', description = '%s' WHERE cid = %d", $edit['title'], $edit['description'], $edit['cid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   380
      $op = 'update';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   381
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   382
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   383
      db_query('DELETE FROM {aggregator_category} WHERE cid = %d', $edit['cid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   384
      // Make sure there is no active block for this category.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   385
      db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'category-' . $edit['cid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   386
      $edit['title'] = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   387
      $op = 'delete';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   388
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   389
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   390
  else if (!empty($edit['title'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   391
    // A single unique id for bundles and feeds, to use in blocks
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   392
    db_query("INSERT INTO {aggregator_category} (title, description, block) VALUES ('%s', '%s', 5)", $edit['title'], $edit['description']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   393
    $link_path .= db_last_insert_id('aggregator_category', 'cid');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   394
    $op = 'insert';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   395
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   396
  if (isset($op)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   397
    menu_link_maintain('aggregator', $op, $link_path, $edit['title']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   398
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   399
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   400
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   401
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   402
 * Add/edit/delete an aggregator feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   403
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   404
 * @param $edit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   405
 *   An associative array describing the feed to be added/edited/deleted.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   406
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   407
function aggregator_save_feed($edit) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   408
  if (!empty($edit['fid'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   409
    // An existing feed is being modified, delete the category listings.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   410
    db_query('DELETE FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   411
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   412
  if (!empty($edit['fid']) && !empty($edit['title'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   413
    db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   414
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   415
  else if (!empty($edit['fid'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   416
    $items = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   417
    $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   418
    while ($item = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   419
      $items[] = "iid = $item->iid";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   420
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   421
    if (!empty($items)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   422
      db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   423
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   424
    db_query('DELETE FROM {aggregator_feed} WHERE fid = %d', $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   425
    db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   426
    // Make sure there is no active block for this feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   427
    db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'feed-' . $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   428
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   429
  else if (!empty($edit['title'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   430
    db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block, description, image) VALUES ('%s', '%s', %d, 5, '', '')", $edit['title'], $edit['url'], $edit['refresh']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   431
    // A single unique id for bundles and feeds, to use in blocks.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   432
    $edit['fid'] = db_last_insert_id('aggregator_feed', 'fid');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   433
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   434
  if (!empty($edit['title'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   435
    // The feed is being saved, save the categories as well.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   436
    if (!empty($edit['category'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   437
      foreach ($edit['category'] as $cid => $value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   438
        if ($value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   439
          db_query('INSERT INTO {aggregator_category_feed} (fid, cid) VALUES (%d, %d)', $edit['fid'], $cid);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   440
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   441
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   442
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   443
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   444
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   445
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   446
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   447
 * Removes all items from a feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   448
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   449
 * @param $feed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   450
 *   An associative array describing the feed to be cleared.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   451
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   452
function aggregator_remove($feed) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   453
  $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   454
  while ($item = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   455
    $items[] = "iid = $item->iid";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   456
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   457
  if (!empty($items)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   458
    db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   459
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   460
  db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   461
  db_query("UPDATE {aggregator_feed} SET checked = 0, etag = '', modified = 0 WHERE fid = %d", $feed['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   462
  drupal_set_message(t('The news items from %site have been removed.', array('%site' => $feed['title'])));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   463
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   464
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   465
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   466
 * Call-back function used by the XML parser.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   467
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   468
function aggregator_element_start($parser, $name, $attributes) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   469
  global $item, $element, $tag, $items, $channel;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   470
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   471
  switch ($name) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   472
    case 'IMAGE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   473
    case 'TEXTINPUT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   474
    case 'CONTENT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   475
    case 'SUMMARY':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   476
    case 'TAGLINE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   477
    case 'SUBTITLE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   478
    case 'LOGO':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   479
    case 'INFO':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   480
      $element = $name;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   481
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   482
    case 'ID':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   483
      if ($element != 'ITEM') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   484
        $element = $name;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   485
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   486
    case 'LINK':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   487
      if (!empty($attributes['REL']) && $attributes['REL'] == 'alternate') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   488
        if ($element == 'ITEM') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   489
          $items[$item]['LINK'] = $attributes['HREF'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   490
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   491
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   492
          $channel['LINK'] = $attributes['HREF'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   493
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   494
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   495
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   496
    case 'ITEM':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   497
      $element = $name;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   498
      $item += 1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   499
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   500
    case 'ENTRY':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   501
      $element = 'ITEM';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   502
      $item += 1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   503
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   504
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   505
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   506
  $tag = $name;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   507
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   508
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   509
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   510
 * Call-back function used by the XML parser.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   511
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   512
function aggregator_element_end($parser, $name) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   513
  global $element;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   514
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   515
  switch ($name) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   516
    case 'IMAGE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   517
    case 'TEXTINPUT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   518
    case 'ITEM':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   519
    case 'ENTRY':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   520
    case 'CONTENT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   521
    case 'INFO':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   522
      $element = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   523
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   524
    case 'ID':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   525
      if ($element == 'ID') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   526
        $element = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   527
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   528
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   529
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   530
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   531
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   532
 * Call-back function used by the XML parser.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   533
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   534
function aggregator_element_data($parser, $data) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   535
  global $channel, $element, $items, $item, $image, $tag;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   536
  $items += array($item => array());
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   537
  switch ($element) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   538
    case 'ITEM':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   539
      $items[$item] += array($tag => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   540
      $items[$item][$tag] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   541
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   542
    case 'IMAGE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   543
    case 'LOGO':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   544
      $image += array($tag => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   545
      $image[$tag] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   546
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   547
    case 'LINK':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   548
      if ($data) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   549
        $items[$item] += array($tag => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   550
        $items[$item][$tag] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   551
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   552
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   553
    case 'CONTENT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   554
      $items[$item] += array('CONTENT' => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   555
      $items[$item]['CONTENT'] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   556
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   557
    case 'SUMMARY':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   558
      $items[$item] += array('SUMMARY' => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   559
      $items[$item]['SUMMARY'] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   560
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   561
    case 'TAGLINE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   562
    case 'SUBTITLE':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   563
      $channel += array('DESCRIPTION' => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   564
      $channel['DESCRIPTION'] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   565
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   566
    case 'INFO':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   567
    case 'ID':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   568
    case 'TEXTINPUT':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   569
      // The sub-element is not supported. However, we must recognize
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   570
      // it or its contents will end up in the item array.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   571
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   572
    default:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   573
      $channel += array($tag => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   574
      $channel[$tag] .= $data;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   575
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   576
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   577
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   578
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   579
 * Checks a news feed for new items.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   580
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   581
 * @param $feed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   582
 *   An associative array describing the feed to be refreshed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   583
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   584
function aggregator_refresh($feed) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   585
  global $channel, $image;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   586
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   587
  // Generate conditional GET headers.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   588
  $headers = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   589
  if ($feed['etag']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   590
    $headers['If-None-Match'] = $feed['etag'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   591
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   592
  if ($feed['modified']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   593
    $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) .' GMT';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   594
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   595
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   596
  // Request feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   597
  $result = drupal_http_request($feed['url'], $headers);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   598
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   599
  // Process HTTP response code.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   600
  switch ($result->code) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   601
    case 304:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   602
      db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   603
      drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title'])));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   604
      break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   605
    case 301:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   606
      $feed['url'] = $result->redirect_url;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   607
      watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url']));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   608
      // Deliberate no break.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   609
    case 200:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   610
    case 302:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   611
    case 307:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   612
      // Filter the input data:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   613
      if (aggregator_parse_feed($result->data, $feed)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   614
        $modified = empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   615
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   616
        // Prepare the channel data.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   617
        foreach ($channel as $key => $value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   618
          $channel[$key] = trim($value);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   619
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   620
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   621
        // Prepare the image data (if any).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   622
        foreach ($image as $key => $value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   623
          $image[$key] = trim($value);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   624
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   625
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   626
        if (!empty($image['LINK']) && !empty($image['URL']) && !empty($image['TITLE'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   627
          // 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
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   628
          $image = '<a href="'. check_url($image['LINK']) .'" class="feed-image"><img src="'. check_url($image['URL']) .'" alt="'. check_plain($image['TITLE']) .'" /></a>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   629
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   630
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   631
          $image = NULL;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   632
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   633
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   634
        $etag = empty($result->headers['ETag']) ? '' : $result->headers['ETag'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   635
        // Update the feed data.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   636
        db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $etag, $modified, $feed['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   637
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   638
        // Clear the cache.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   639
        cache_clear_all();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   640
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   641
        watchdog('aggregator', 'There is new syndicated content from %site.', array('%site' => $feed['title']));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   642
        drupal_set_message(t('There is new syndicated content from %site.', array('%site' => $feed['title'])));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   643
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   644
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   645
      $result->error = t('feed not parseable');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   646
      // Deliberate no break.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   647
    default:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   648
      watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error), WATCHDOG_WARNING);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   649
      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)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   650
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   651
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   652
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   653
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   654
 * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   655
 * functions do not handle this format.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   656
 * See http://www.w3.org/TR/NOTE-datetime for more information.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   657
 * Originally from MagpieRSS (http://magpierss.sourceforge.net/).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   658
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   659
 * @param $date_str
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   660
 *   A string with a potentially W3C DTF date.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   661
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   662
 *   A timestamp if parsed successfully or FALSE if not.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   663
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   664
function aggregator_parse_w3cdtf($date_str) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   665
  if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   666
    list($year, $month, $day, $hours, $minutes, $seconds) = array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   667
    // calc epoch for current date assuming GMT
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   668
    $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   669
    if ($match[10] != 'Z') { // Z is zulu time, aka GMT
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   670
      list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   671
      // zero out the variables
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   672
      if (!$tz_hour) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   673
        $tz_hour = 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   674
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   675
      if (!$tz_min) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   676
        $tz_min = 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   677
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   678
      $offset_secs = (($tz_hour * 60) + $tz_min) * 60;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   679
      // is timezone ahead of GMT?  then subtract offset
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   680
      if ($tz_mod == '+') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   681
        $offset_secs *= -1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   682
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   683
      $epoch += $offset_secs;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   684
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   685
    return $epoch;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   686
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   687
  else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   688
    return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   689
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   690
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   691
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   692
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   693
 * Parse a feed and store its items.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   694
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   695
 * @param $data
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   696
 *   The feed data.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   697
 * @param $feed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   698
 *   An associative array describing the feed to be parsed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   699
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   700
 *   0 on error, 1 otherwise.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   701
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   702
function aggregator_parse_feed(&$data, $feed) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   703
  global $items, $image, $channel;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   704
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   705
  // Unset the global variables before we use them:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   706
  unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   707
  $items = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   708
  $image = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   709
  $channel = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   710
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   711
  // parse the data:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   712
  $xml_parser = drupal_xml_parser_create($data);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   713
  xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   714
  xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   715
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   716
  if (!xml_parse($xml_parser, $data, 1)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   717
    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);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   718
    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');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   719
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   720
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   721
  xml_parser_free($xml_parser);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   722
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   723
  // We reverse the array such that we store the first item last, and the last
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   724
  // item first. In the database, the newest item should be at the top.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   725
  $items = array_reverse($items);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   726
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   727
  // Initialize variables.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   728
  $title = $link = $author = $description = $guid = NULL;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   729
  foreach ($items as $item) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   730
    unset($title, $link, $author, $description, $guid);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   731
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   732
    // Prepare the item:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   733
    foreach ($item as $key => $value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   734
      $item[$key] = trim($value);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   735
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   736
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   737
    // Resolve the item's title. If no title is found, we use up to 40
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   738
    // characters of the description ending at a word boundary but not
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   739
    // splitting potential entities.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   740
    if (!empty($item['TITLE'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   741
      $title = $item['TITLE'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   742
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   743
    elseif (!empty($item['DESCRIPTION'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   744
      $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   745
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   746
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   747
      $title = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   748
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   749
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   750
    // Resolve the items link.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   751
    if (!empty($item['LINK'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   752
      $link = $item['LINK'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   753
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   754
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   755
      $link = $feed['link'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   756
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   757
    $guid = isset($item['GUID']) ? $item['GUID'] : '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   758
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   759
    // Atom feeds have a CONTENT and/or SUMMARY tag instead of a DESCRIPTION tag.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   760
    if (!empty($item['CONTENT:ENCODED'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   761
      $item['DESCRIPTION'] = $item['CONTENT:ENCODED'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   762
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   763
    else if (!empty($item['SUMMARY'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   764
      $item['DESCRIPTION'] = $item['SUMMARY'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   765
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   766
    else if (!empty($item['CONTENT'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   767
      $item['DESCRIPTION'] = $item['CONTENT'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   768
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   769
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   770
    // Try to resolve and parse the item's publication date. If no date is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   771
    // found, we use the current date instead.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   772
    $date = 'now';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   773
    foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   774
      if (!empty($item[$key])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   775
        $date = $item[$key];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   776
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   777
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   778
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   779
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   780
    $timestamp = strtotime($date); // As of PHP 5.1.0, strtotime returns FALSE on failure instead of -1.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   781
    if ($timestamp <= 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   782
      $timestamp = aggregator_parse_w3cdtf($date); // Returns FALSE on failure
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   783
      if (!$timestamp) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   784
        $timestamp = time(); // better than nothing
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   785
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   786
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   787
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   788
    // Save this item. Try to avoid duplicate entries as much as possible. If
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   789
    // we find a duplicate entry, we resolve it and pass along its ID is such
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   790
    // that we can update it if needed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   791
    if (!empty($guid)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   792
      $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $guid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   793
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   794
    else if ($link && $link != $feed['link'] && $link != $feed['url']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   795
      $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   796
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   797
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   798
      $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   799
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   800
    $item += array('AUTHOR' => '', 'DESCRIPTION' => '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   801
    aggregator_save_item(array('iid' => (isset($entry->iid) ? $entry->iid:  ''), 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'], 'guid' => $guid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   802
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   803
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   804
  // Remove all items that are older than flush item timer.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   805
  $age = time() - variable_get('aggregator_clear', 9676800);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   806
  $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   807
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   808
  $items = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   809
  $num_rows = FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   810
  while ($item = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   811
    $items[] = $item->iid;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   812
    $num_rows = TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   813
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   814
  if ($num_rows) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   815
    db_query('DELETE FROM {aggregator_category_item} WHERE iid IN ('. implode(', ', $items) .')');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   816
    db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   817
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   818
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   819
  return 1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   820
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   821
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   822
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   823
 * Add/edit/delete an aggregator item.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   824
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   825
 * @param $edit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   826
 *   An associative array describing the item to be added/edited/deleted.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   827
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   828
function aggregator_save_item($edit) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   829
  if ($edit['iid'] && $edit['title']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   830
    db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s', guid = '%s', timestamp = %d WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['guid'], $edit['timestamp'], $edit['iid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   831
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   832
  else if ($edit['iid']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   833
    db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   834
    db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   835
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   836
  else if ($edit['title'] && $edit['link']) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   837
    db_query("INSERT INTO {aggregator_item} (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp'], $edit['guid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   838
    $edit['iid'] = db_last_insert_id('aggregator_item', 'iid');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   839
    // file the items in the categories indicated by the feed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   840
    $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   841
    while ($category = db_fetch_object($categories)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   842
      db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $category->cid, $edit['iid']);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   843
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   844
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   845
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   846
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   847
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   848
 * Load an aggregator feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   849
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   850
 * @param $fid
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   851
 *   The feed id.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   852
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   853
 *   An associative array describing the feed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   854
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   855
function aggregator_feed_load($fid) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   856
  static $feeds;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   857
  if (!isset($feeds[$fid])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   858
    $feeds[$fid] = db_fetch_array(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', $fid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   859
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   860
  return $feeds[$fid];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   861
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   862
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   863
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   864
 * Load an aggregator category.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   865
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   866
 * @param $cid
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   867
 *   The category id.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   868
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   869
 *   An associative array describing the category.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   870
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   871
function aggregator_category_load($cid) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   872
  static $categories;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   873
  if (!isset($categories[$cid])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   874
    $categories[$cid] = db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   875
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   876
  return $categories[$cid];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   877
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   878
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   879
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   880
 * Format an individual feed item for display in the block.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   881
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   882
 * @param $item
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   883
 *   The item to be displayed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   884
 * @param $feed
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   885
 *   Not used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   886
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   887
 *   The item HTML.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   888
 * @ingroup themeable
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   889
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   890
function theme_aggregator_block_item($item, $feed = 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   891
  global $user;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   892
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   893
  $output = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   894
  if ($user->uid && module_exists('blog') && user_access('create blog entries')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   895
    if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   896
      $output .= '<div class="icon">'. l($image, 'node/add/blog', array('attributes' => array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), 'query' => "iid=$item->iid", 'html' => TRUE)) .'</div>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   897
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   898
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   899
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   900
  // Display the external link to the item.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   901
  $output .= '<a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a>\n";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   902
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   903
  return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   904
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   905
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   906
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   907
 * Safely render HTML content, as allowed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   908
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   909
 * @param $value
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   910
 *   The content to be filtered.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   911
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   912
 *   The filtered content.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   913
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   914
function aggregator_filter_xss($value) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   915
  return filter_xss($value, preg_split('/\s+|<|>/', variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), -1, PREG_SPLIT_NO_EMPTY));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   916
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   917
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   918
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   919
 * Helper function for drupal_map_assoc.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   920
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   921
 * @param $count
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   922
 *   Items count.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   923
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   924
 *   Plural-formatted "@count items"
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   925
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   926
function _aggregator_items($count) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   927
  return format_plural($count, '1 item', '@count items');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   928
}