Index: aggregator.install =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.install,v retrieving revision 1.8 diff -u -p -r1.8 aggregator.install --- aggregator.install 26 Sep 2006 14:19:00 -0000 1.8 +++ aggregator.install 29 Mar 2007 01:28:25 -0000 @@ -41,6 +41,7 @@ function aggregator_install() { etag varchar(255) NOT NULL default '', modified int NOT NULL default '0', block tinyint NOT NULL default '0', + block_create tinyint NOT NULL default '0', PRIMARY KEY (fid), UNIQUE KEY link (url), UNIQUE KEY title (title) @@ -94,6 +95,7 @@ function aggregator_install() { etag varchar(255) NOT NULL default '', modified int NOT NULL default '0', block smallint NOT NULL default '0', + block_create smallint NOT NULL default '0', PRIMARY KEY (fid), UNIQUE (url), UNIQUE (title) @@ -130,3 +132,20 @@ function aggregator_uninstall() { variable_del('aggregator_clear'); variable_del('aggregator_category_selector'); } + +/** + * Implementation of hook_update + */ +function aggregator_update_1() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("ALTER TABLE {aggregator_feed} ADD block_create tinyint NOT NULL default '0';"); + break; + case 'pgsql': + $ret[] = update_sql("ALTER TABLE {aggregator_feed} ADD block_create tinyint NOT NULL default '0';"); + break; + } + return $ret; +} \ No newline at end of file Index: aggregator.module =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.module,v retrieving revision 1.333 diff -u -p -r1.333 aggregator.module --- aggregator.module 27 Mar 2007 05:13:53 -0000 1.333 +++ aggregator.module 29 Mar 2007 01:28:27 -0000 @@ -213,6 +213,12 @@ function aggregator_admin_settings() { '#description' => t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.') ); + $form['aggregator_block_create'] = array( + '#type' => 'radios', '#title' => t('Feed block creation rules'), '#default_value' => variable_get('aggregator_block_create', 0), + '#options' => array(0 => t('do not create blocks for new feeds'), 1 => t('create blocks for new feeds')), + '#description' => t('When adding feeds, the default setting will create a new block or not. This value can be changed for each feed.') + ); + return system_settings_form($form); } @@ -247,7 +253,7 @@ function aggregator_block($op = 'list', while ($category = db_fetch_object($result)) { $block['category-'. $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title)); } - $result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid'); + $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block_create = 1 ORDER BY fid'); while ($feed = db_fetch_object($result)) { $block['feed-'. $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title)); } @@ -258,7 +264,7 @@ function aggregator_block($op = 'list', $value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id)); } else { - $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id)); + $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d AND block_create = 1', $id)); } $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))); return $form; @@ -443,6 +449,7 @@ function aggregator_form_feed($edit = ar while ($category = db_fetch_object($categories)) { $options[$category->cid] = check_plain($category->title); if ($category->fid) $values[] = $category->cid; + $fid = $category->fid; } if ($options) { $form['category'] = array('#type' => 'checkboxes', @@ -452,6 +459,32 @@ function aggregator_form_feed($edit = ar '#description' => t('New items in this feed will be automatically filed in the checked categories as they are received.'), ); } + + // Handling of block creation. Set $rehash to zero or to the current value. + if (!empty($fid)) { + $block = db_fetch_object(db_query("SELECT block_create FROM {aggregator_feed} WHERE fid = %d", $fid)); + $edit['block_create'] = $block->block_create; + $rehash = $block->block_create; + } + else { + $edit['block_create'] = variable_get('aggregator_block_create', 0); + $rehash = 0; + } + // Show the form to privleged users, or print a hidden element. + if (user_access('administer blocks')) { + $form['block_create'] = array( + '#title' => t('Create block'), + '#default_value' => $edit['block_create'], + '#type' => 'radios', + '#options' => array(0 => t('do not create a block for this feed'), 1 => t('create a block for this feed')), + '#description' => t('Block creation options for this feed.'), + '#required' => TRUE, + ); + } + else { + $form['block_create'] = array('#type' => 'hidden', '#value' => $edit['block_create']); + } + $form['block_rehash'] = array('#type' => 'hidden', '#value' => $rehash); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); if ($edit['fid']) { @@ -497,6 +530,7 @@ function aggregator_form_feed_submit($fo } aggregator_save_feed($form_values); menu_rebuild(); + if (isset($form_values['fid'])) { if (isset($form_values['title'])) { drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_values['title']))); @@ -533,7 +567,7 @@ function aggregator_save_feed($edit) { db_query('DELETE FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']); } if ($edit['fid'] && $edit['title']) { - db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['fid']); + db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d, block_create = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['block_create'], $edit['fid']); } else if ($edit['fid']) { $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']); @@ -549,7 +583,7 @@ function aggregator_save_feed($edit) { else if ($edit['title']) { // A single unique id for bundles and feeds, to use in blocks. $edit['fid'] = db_next_id('{aggregator_feed}_fid'); - db_query("INSERT INTO {aggregator_feed} (fid, title, url, refresh, block) VALUES (%d, '%s', '%s', %d, 5)", $edit['fid'], $edit['title'], $edit['url'], $edit['refresh']); + db_query("INSERT INTO {aggregator_feed} (fid, title, url, refresh, block, block_create) VALUES (%d, '%s', '%s', %d, 5, %d)", $edit['fid'], $edit['title'], $edit['url'], $edit['refresh'], $edit['block_create']); } if ($edit['title']) { // The feed is being saved, save the categories as well. @@ -561,6 +595,10 @@ function aggregator_save_feed($edit) { } } } + // If the block settings have changed, update the blocks table. + if ($edit['block_create'] != $edit['block_rehash']) { + _block_rehash(); + } } function aggregator_remove($feed) {