diff --git a/modules/aggregator/aggregator.admin.inc b/modules/aggregator/aggregator.admin.inc index 9f92a67..1b4f6fa 100644 --- a/modules/aggregator/aggregator.admin.inc +++ b/modules/aggregator/aggregator.admin.inc @@ -87,11 +87,10 @@ function aggregator_form_feed($form, &$form_state, stdClass $feed = NULL) { '#options' => $period, '#description' => t('The length of time between feed updates. Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); - $form['block'] = array('#type' => 'select', - '#title' => t('News items in block'), - '#default_value' => isset($feed->block) ? $feed->block : 5, - '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), - '#description' => t("Drupal can make a block with the most recent news items of this feed. You can configure blocks to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in this feed's block. If you choose '0' this feed's block will be disabled.", array('@block-admin' => url('admin/structure/block'))), + $form['block'] = array('#type' => 'checkbox', + '#title' => t('Create block of feed items'), + '#default_value' => isset($feed->block) ? $feed->block : 1, + '#description' => t("Drupal can make a block with the most recent news items of this feed. You can configure blocks to be displayed in the sidebar of your page.", array('@block-admin' => url('admin/structure/block'))), ); // Handling of categories. diff --git a/modules/aggregator/aggregator.install b/modules/aggregator/aggregator.install index f19d7de..2a44e14 100644 --- a/modules/aggregator/aggregator.install +++ b/modules/aggregator/aggregator.install @@ -49,7 +49,7 @@ function aggregator_schema() { 'not null' => TRUE, 'default' => 0, 'size' => 'tiny', - 'description' => 'The number of recent items to show within the category block.', + 'description' => 'Boolean indicating if there should be a corresponding block for this feed.', ) ), 'primary key' => array('cid'), diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 686f424..b06866a 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -373,6 +373,15 @@ function aggregator_block_configure($delta = '') { ); return $form; } + if ($type == 'feed') { + $form['aggregator_block_items'] = array( + '#type' => 'select', + '#title' => t('Number of news items in block'), + '#default_value' => variable_get('aggregator_block_items' . $id , 5), + '#options' => drupal_map_assoc(range(1, 20)), + ); + return $form; + } } /** @@ -386,6 +395,9 @@ function aggregator_block_save($delta = '', $edit = array()) { ->condition('cid', $id) ->execute(); } + if ($type == 'feed') { + variable_set('aggregator_block_items' . $id, $edit['aggregator_block_items']); + } } /** @@ -400,9 +412,9 @@ function aggregator_block_view($delta = '') { $result = FALSE; switch ($type) { case 'feed': - if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { + if ($feed = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { $block['subject'] = check_plain($feed->title); - $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $feed->block, array(':fid' => $id)); + $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, variable_get('aggregator_block_items' . $id, 5), array(':fid' => $id)); $read_more = theme('more_link', array('url' => 'aggregator/sources/' . $feed->fid, 'title' => t("View this feed's recent news."))); } break; @@ -505,6 +517,14 @@ function aggregator_save_feed($edit) { 'block' => $edit['block'], )) ->execute(); + if (!$edit['block']) { + // Make sure there is no active block for this feed. + db_delete('block') + ->condition('module', 'aggregator') + ->condition('delta', 'feed-' . $edit['fid']) + ->execute(); + variable_del('aggregator_block_items' . $edit['fid']); + } } elseif (!empty($edit['fid'])) { $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $edit['fid']))->fetchCol();