Index: modules/aggregator/aggregator.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.admin.inc,v retrieving revision 1.14 diff -u -p -r1.14 aggregator.admin.inc --- modules/aggregator/aggregator.admin.inc 16 Aug 2008 14:48:17 -0000 1.14 +++ modules/aggregator/aggregator.admin.inc 19 Aug 2008 20:13:03 -0000 @@ -393,33 +393,43 @@ function aggregator_admin_refresh_feed($ * @see system_settings_form() */ function aggregator_admin_settings() { - $items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items'); - $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); - - $form['aggregator_allowed_html_tags'] = array( - '#type' => 'textfield', '#title' => t('Allowed HTML tags'), '#size' => 80, '#maxlength' => 255, - '#default_value' => variable_get('aggregator_allowed_html_tags', '
      • '), - '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. (Tags in this list are not removed by Drupal.)'), - ); - - $form['aggregator_summary_items'] = array( - '#type' => 'select', '#title' => t('Items shown in sources and categories pages') , - '#default_value' => variable_get('aggregator_summary_items', 3), '#options' => $items, - '#description' => t('Number of feed items displayed in feed and category summary pages.'), - ); - - $form['aggregator_clear'] = array( - '#type' => 'select', '#title' => t('Discard items older than'), - '#default_value' => variable_get('aggregator_clear', 9676800), '#options' => $period, - '#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))), - ); - - $form['aggregator_category_selector'] = array( - '#type' => 'radios', '#title' => t('Category selection type'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'), - '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')), - '#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector work well with large numbers of categories.)'), + $period = array('-1' => t('none')); + $period += drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $parsers = module_implements('aggregator_parse'); + foreach ($parsers as $k => $v) { + $info = module_invoke($v, 'aggregator_parse', 'info'); + unset($parsers[$k]); + $parsers[$v] = $info['title'] . ' ' . $info['description'] .''; + } + $processors = module_implements('aggregator_process'); + foreach ($processors as $k => $v) { + $info = module_invoke($v, 'aggregator_process', 'info'); + unset($processors[$k]); + $processors[$v] = $info['title'] . ' ' . $info['description'] .''; + } + $form['aggregator_parser'] = array( + '#type' => 'radios', + '#title' => t('Parser'), + '#description' => t('Parsers retrieve and parse feed data. Choose one suitable for the type of feeds you would like to aggregate.'), + '#options' => $parsers, + '#default_value' => variable_get('aggregator_parser', array_pop(array_flip($parsers))), + ); + $form['aggregator_processors'] = array( + '#type' => 'checkboxes', + '#title' => t('Processors'), + '#description' => t('Processors act on parsed feed data, for example they store feed items. Pick the processors suitable for your task.'), + '#options' => $processors, + '#default_value' => variable_get('aggregator_processor', array_slice(array_flip($processors), 0, 1)), + ); + $form['aggregator_refresh'] = array( + '#type' => 'select', + '#title' => t('Update interval'), + '#default_value' => variable_get('aggregator_refresh', 3600), + '#options' => $period, + '#description' => t('Approximate time between checking feeds. Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); - + $form['modules'] = array(); + return system_settings_form($form); } @@ -511,3 +521,51 @@ function aggregator_form_category_submit drupal_set_message(t('The category %category has been added.', array('%category' => $form_state['values']['title']))); } } + +/** + * Implementation of hook_form_alter(). + */ +function aggregator_form_alter(&$form, $form_state, $form_id) { + if ($form_id == 'aggregator_admin_settings') { + if (aggregator_is_enabled('aggregator')) { + $types = node_get_types(); + $types_select = array(); + foreach ($types as $type) { + // Do not allow a content-type for both the items and the feeds + if (!variable_get('aggregator_feed_' . $type->type, FALSE)) { + $types_select[$type->type] = $type->name; + } + } + $info = module_invoke('aggregator', 'aggregator_process', 'info'); + $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); + $items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items'); + + $form['modules']['aggregator'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced Aggregator Light settings'), + '#description' => $info['description'], + '#collapsible' => TRUE, + '#collapsed' => !aggregator_is_enabled('aggregator', $type), + ); + + + $form['modules']['aggregator']['aggregator_summary_items'] = array( + '#type' => 'select', '#title' => t('Items shown in sources and categories pages') , + '#default_value' => variable_get('aggregator_summary_items', 3), '#options' => $items, + '#description' => t('Number of feed items displayed in feed and category summary pages.'), + ); + + $form['modules']['aggregator']['aggregator_clear'] = array( + '#type' => 'select', '#title' => t('Discard items older than'), + '#default_value' => variable_get('aggregator_clear', 9676800), '#options' => $period, + '#description' => t('The length of time to retain feed items before discarding. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))), + ); + + $form['modules']['aggregator']['aggregator_category_selector'] = array( + '#type' => 'radios', '#title' => t('Category selection type'), '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'), + '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')), + '#description' => t('The type of category selection widget displayed on categorization pages. (For a small number of categories, checkboxes are easier to use, while a multiple selector work well with large numbers of categories.)'), + ); + } + } +} \ No newline at end of file Index: modules/aggregator/aggregator.module =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.module,v retrieving revision 1.389 diff -u -p -r1.389 aggregator.module --- modules/aggregator/aggregator.module 16 Aug 2008 14:48:17 -0000 1.389 +++ modules/aggregator/aggregator.module 19 Aug 2008 20:13:05 -0000 @@ -281,9 +281,23 @@ function aggregator_perm() { * Checks news feeds for updates once their refresh interval has elapsed. */ function aggregator_cron() { - $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d', time()); - while ($feed = db_fetch_array($result)) { - aggregator_refresh($feed); + $ready = FALSE; + if (drupal_function_exists('_aggregator_light_delete_expired')) { + _aggregator_light_delete_expired(); + } + // Query the feeds which should be refreshed and do the refresh. + $start = time(); + while(_aggregator_cron_time() || !$ready) { + $sql = "SELECT * FROM {aggregator_feed} WHERE checked <= %d AND (%d - checked) < %d ORDER BY checked"; + $result = db_query_range($sql, $start, variable_get('aggregator_refresh', 3600), 0, 2); + $feed_count = 0; + while ($feed = db_fetch_array($result)) { + aggregator_refresh($feed); + ++$feed_count; + } + if ($feed_count == 0) { + $ready = TRUE; + } } } @@ -359,6 +373,123 @@ function aggregator_block($op = 'list', } /** + * Implementation of hook_aggregator_process(). + * + * @param $op + * 'save' The feed items should be updated or saved. + * 'info' Metadata about the processor + * @param $channel + * The data + */ +function aggregator_aggregator_process($op, $feed = NULL) { + switch ($op) { + case 'save': + $new = FALSE; + foreach ($feed['items'] as $k => $item) { + $new = ($new || is_numeric($item['unique']['aggregator']) ? FALSE : TRUE); + aggregator_save_item(array('iid' => $item['unique']['aggregator'], 'fid' => $feed['fid'], 'timestamp' => $item['timestamp'], 'title' => $item['title'], 'link' => $item['link'], 'author' => $item['author'], 'description' => $item['description'], 'guid' => $item['guid'])); + } + if ($new) { + watchdog('aggregator', 'There is new syndicated content from %site.', array('%site' => $feed['title'])); + drupal_set_message(t('There is new syndicated content from %site.', array('%site' => $feed['title']))); + } + return $feed; + break; + case 'unique': + foreach ($feed['items'] as $k => $item) { + if (!empty($item['guid'])) { + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $item['guid'])); + } + else if ($item['link'] && $item['link'] != $feed['link'] && $item['link'] != $feed['url']) { + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $item['link'])); + } + else { + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $item['title'])); + } + $feed['items'][$k]['unique'] = array(); + $feed['items'][$k]['unique']['aggregator'] = (!isset($entry->iid) ? TRUE : $entry->iid); + } + return $feed; + break; + case 'info': + return array( + 'title' => t('Aggregator Light'), + 'description' => t('Creates lightweight records of feed items.'), + ); + } +} + +/** + * Implementation of hook_parse(). + * + * @param $op + * 'parse' Parse the feed-nodes + * 'info' Metadata about the processor + * @param $data + * Raw downloaded data + */ +function aggregator_aggregator_parse($op, $feed = NULL) { + switch ($op) { + case 'parse': + // Generate conditional GET headers. + $headers = array(); + if ($feed['etag']) { + $headers['If-None-Match'] = $feed['etag']; + } + if ($feed['modified']) { + $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) . ' GMT'; + } + + // Request feed. + $result = drupal_http_request($feed['url'], $headers); + + // Process HTTP response code. + switch ($result->code) { + case 304: + return TRUE; + break; + case 301: + $feed['url'] = $result->redirect_url; + + if (isset($result->redirect_url)) { + watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url'])); + } + // Do not break here. + case 200: + case 302: + case 307: + // We store the md5 hash of feed data in the database. When refreshing a + // feed we compare stored hash and new hash calculated from downloaded + // data. If both are equal we say that feed is not updated. + $feed['md5'] = md5($result->data); + if ($feed['hash'] == $feed['md5']) { + return TRUE; + } + return array_merge( + array( + 'md5' => $feed['md5'], + 'modified' => empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']), + 'etag' => empty($result->headers['ETag']) ? '' : $result->headers['ETag'], + ), + aggregator_parse_feed($result->data, $feed)); + break; + default: + watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING); + drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed['title'], '%error' => $result->code . ' ' . $result->error))); + module_invoke('system', 'check_http_request'); + return FALSE; + } + break; + case 'info': + return array( + 'title' => t('Built-in Parser'), + 'description' => t('Default parser for RSS, Atom and RDF feeds.'), + ); + + } +} + +/** * Add/edit/delete aggregator categories. * * @param $edit @@ -406,16 +537,11 @@ function aggregator_save_feed($edit) { db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d, block = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['block'], $edit['fid']); } elseif (!empty($edit['fid'])) { - $items = array(); - $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']); - while ($item = db_fetch_object($result)) { - $items[] = "iid = $item->iid"; - } - if (!empty($items)) { - db_query('DELETE FROM {aggregator_category_item} WHERE ' . implode(' OR ', $items)); + $processors = variable_get('aggregator_processor', array()); + foreach ($processors as $processor) { + module_invoke($processor, 'aggregator_process', 'delete', $edit); } db_query('DELETE FROM {aggregator_feed} WHERE fid = %d', $edit['fid']); - db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']); // Make sure there is no active block for this feed. db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'feed-' . $edit['fid']); } @@ -562,9 +688,6 @@ function aggregator_element_data($parser // The sub-element is not supported. However, we must recognize // it or its contents will end up in the item array. break; - default: - $channel += array($tag => ''); - $channel[$tag] .= $data; } } @@ -575,84 +698,58 @@ function aggregator_element_data($parser * An associative array describing the feed to be refreshed. */ function aggregator_refresh($feed) { - global $channel, $image; - // Generate conditional GET headers. - $headers = array(); - if ($feed['etag']) { - $headers['If-None-Match'] = $feed['etag']; - } - if ($feed['modified']) { - $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) . ' GMT'; - } - - // Request feed. - $result = drupal_http_request($feed['url'], $headers); - - // Process HTTP response code. - switch ($result->code) { - case 304: - db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']); - drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title']))); - break; - case 301: - $feed['url'] = $result->redirect_url; - // Do not break here. - case 200: - case 302: - case 307: - // We store the md5 hash of feed data in the database. When refreshing a - // feed we compare stored hash and new hash calculated from downloaded - // data. If both are equal we say that feed is not updated. - $md5 = md5($result->data); - if ($feed['hash'] == $md5) { - db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']); - drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title']))); - break; - } - - // Filter the input data. - if (aggregator_parse_feed($result->data, $feed)) { - $modified = empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']); - - // Prepare the channel data. - foreach ($channel as $key => $value) { - $channel[$key] = trim($value); - } + $parser = variable_get('aggregator_parser', 'aggregator'); + $channel = module_invoke($parser, 'aggregator_parse', 'parse', $feed); + if ($channel === TRUE) { + db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']); + drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title']))); + return; + } + if ($channel === FALSE) { + return; + } + $channel = array_merge($channel, $feed); + if (is_array($channel)) { + $processors = variable_get('aggregator_processor', array()); + foreach ($processors as $processor) { + $channel = module_invoke($processor, 'aggregator_process', 'unique', $channel); + } + foreach ($processors as $processor) { + $channel = module_invoke($processor, 'aggregator_process', 'save', $channel); + } - // Prepare the image data (if any). - foreach ($image as $key => $value) { - $image[$key] = trim($value); - } + $image = $channel['image']; - if (!empty($image['LINK']) && !empty($image['URL']) && !empty($image['TITLE'])) { - // TODO: we should really use theme_image() here, but that only works with - // local images. It won't work with images fetched with a URL unless PHP version > 5. - $image = '' . check_plain($image['TITLE']) . ''; - } - else { - $image = NULL; - } + // Prepare the channel data. + foreach ($channel as $key => $value) { + if (!is_array($value)) { + $channel[$key] = trim($value); + } + } - $etag = empty($result->headers['ETag']) ? '' : $result->headers['ETag']; - // Update the feed data. - db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', hash = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $md5, $etag, $modified, $feed['fid']); + // Prepare the image data (if any). + if (is_array($image)) { + foreach ($image as $key => $value) { + $image[$key] = trim($value); + } + } - // Clear the cache. - cache_clear_all(); + if (!empty($image['LINK']) && !empty($image['URL']) && !empty($image['TITLE'])) { + // TODO: we should really use theme_image() here, but that only works with + // local images. It won't work with images fetched with a URL unless PHP version > 5. + $image = '' . check_plain($image['TITLE']) . ''; + } + else { + $image = NULL; + } - if (isset($result->redirect_url)) { - watchdog('aggregator', 'Updated URL for feed %title to %url.', array('%title' => $feed['title'], '%url' => $feed['url'])); - } + // Update the feed data. + db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', hash = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['link'], $channel['description'], $image, $channel['md5'], $channel['etag'], $channel['modified'], $feed['fid']); - watchdog('aggregator', 'There is new syndicated content from %site.', array('%site' => $feed['title'])); - drupal_set_message(t('There is new syndicated content from %site.', array('%site' => $feed['title']))); - } - break; - default: - watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed['title'], '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING); - drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed['title'], '%error' => $result->code . ' ' . $result->error))); - module_invoke('system', 'check_http_request'); + // Clear the cache. + cache_clear_all(); + } } @@ -704,9 +801,9 @@ function aggregator_parse_w3cdtf($date_s * @param $feed * An associative array describing the feed to be parsed. * @return - * FALSE on error, TRUE otherwise. + * FALSE on error, the parsed feed otherwise */ -function aggregator_parse_feed(&$data, $feed) { +function aggregator_parse_feed($data, $feed) { global $items, $image, $channel; // Unset the global variables before we use them. @@ -714,6 +811,7 @@ function aggregator_parse_feed(&$data, $ $items = array(); $image = array(); $channel = array(); + $channel['items'] = array(); // Parse the data. $xml_parser = drupal_xml_parser_create($data); @@ -731,53 +829,44 @@ function aggregator_parse_feed(&$data, $ // item first. In the database, the newest item should be at the top. $items = array_reverse($items); - // Initialize variables. - $title = $link = $author = $description = $guid = NULL; foreach ($items as $item) { - unset($title, $link, $author, $description, $guid); // Prepare the item: foreach ($item as $key => $value) { - $item[$key] = trim($value); - } - - // Resolve the item's title. If no title is found, we use up to 40 - // characters of the description ending at a word boundary, but not - // splitting potential entities. - if (!empty($item['TITLE'])) { - $title = $item['TITLE']; - } - elseif (!empty($item['DESCRIPTION'])) { - $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40)); - } - else { - $title = ''; + $item[strtolower($key)] = trim($value); } // Resolve the items link. - if (!empty($item['LINK'])) { - $link = $item['LINK']; + if (empty($item['link'])) { + $item['link'] = $feed['link']; } - else { - $link = $feed['link']; - } - $guid = isset($item['GUID']) ? $item['GUID'] : ''; + $item['guid'] = isset($item['guid']) ? $item['guid'] : ''; // Atom feeds have a CONTENT and/or SUMMARY tag instead of a DESCRIPTION tag. - if (!empty($item['CONTENT:ENCODED'])) { - $item['DESCRIPTION'] = $item['CONTENT:ENCODED']; + if (!empty($item['content:encoded'])) { + $item['description'] = $item['content:encoded']; + } + elseif (!empty($item['summary'])) { + $item['description'] = $item['summary']; } - elseif (!empty($item['SUMMARY'])) { - $item['DESCRIPTION'] = $item['SUMMARY']; + elseif (!empty($item['content'])) { + $item['description'] = $item['content']; } - elseif (!empty($item['CONTENT'])) { - $item['DESCRIPTION'] = $item['CONTENT']; + elseif (empty($item['description'])) { + continue; + } + + // Resolve the item's title. If no title is found, we use up to 40 + // characters of the description ending at a word boundary, but not + // splitting potential entities. + if (empty($item['title'])) { + $item['title'] = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['description'], 40)); } // Try to resolve and parse the item's publication date. If no date is // found, use the current date instead. $date = 'now'; - foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) { + foreach (array('pubdate', 'dc:date', 'dcterms:issued', 'dcterms:created', 'dcterms:modified', 'issued', 'created', 'modified', 'published', 'updated') as $key) { if (!empty($item[$key])) { $date = $item[$key]; break; @@ -793,39 +882,13 @@ function aggregator_parse_feed(&$data, $ $timestamp = time(); } } - - // Save this item. Try to avoid duplicate entries as much as possible. If - // we find a duplicate entry, we resolve it and pass along its ID is such - // that we can update it if needed. - if (!empty($guid)) { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND guid = '%s'", $feed['fid'], $guid)); - } - else if ($link && $link != $feed['link'] && $link != $feed['url']) { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link)); - } - else { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title)); - } - $item += array('AUTHOR' => '', 'DESCRIPTION' => ''); - 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)); - } - - // Remove all items that are older than flush item timer. - $age = time() - variable_get('aggregator_clear', 9676800); - $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); - - $items = array(); - $num_rows = FALSE; - while ($item = db_fetch_object($result)) { - $items[] = $item->iid; - $num_rows = TRUE; - } - if ($num_rows) { - db_query('DELETE FROM {aggregator_category_item} WHERE iid IN (' . implode(', ', $items) . ')'); - db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); - } - - return TRUE; + $item['timestamp'] = $timestamp; + $item += array('author' => ''); + $channel['items'][] = $item; + } + $channel['image'] = $image; + + return $channel; } /** @@ -835,10 +898,10 @@ function aggregator_parse_feed(&$data, $ * An associative array describing the item to be added/edited/deleted. */ function aggregator_save_item($edit) { - if ($edit['iid'] && $edit['title']) { + if (is_numeric($edit['iid']) && $edit['title']) { 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']); } - elseif ($edit['iid']) { + elseif (is_numeric($edit['iid'])) { db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']); db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']); } @@ -871,6 +934,25 @@ function aggregator_feed_load($fid) { } /** + * Tells if the given module is enabled (as parser or as processor). + * + * @param $module + * The name of the module. + * @return + * TRUE if enabled, FALSE if disabled. + */ +function aggregator_is_enabled($module) { + if ($module == variable_get('aggregator_parser', '')) { + return TRUE; + } + $processors = array_values(variable_get('aggregator_processors', array())); + if (in_array($module, $processors, TRUE)) { + return TRUE; + } + return FALSE; +} + +/** * Load an aggregator category. * * @param $cid @@ -937,3 +1019,17 @@ function aggregator_filter_xss($value) { function _aggregator_items($count) { return format_plural($count, '1 item', '@count items'); } + +/** + * Checks for time limits in cron processing. + */ +function _aggregator_cron_time() { + static $time_limit; + $execute_percentage = 0.5; + if (!$time_limit) { + $time_limit = time() + ($execute_percentage / 100) * ini_get('max_execution_time'); + // However, check for left time, maybe some other cron processing already occured. + $time_limit = min($time_limit, variable_get('cron_semaphore', 0) + ini_get('max_execution_time')); + } + return max($time_limit - time(), 0); +}