--- aggregation/aggregation.module	2008-03-26 00:46:43.000000000 -0400
+++ aggregation.module	2008-03-24 12:55:19.000000000 -0400
@@ -21,9 +21,9 @@
 /**
  * Implementation of hook_help
  */
-function aggregation_help($section)
+function aggregation_help($path, $arg)
 {
-	switch ($section)
+	switch ($path)
 	{
 		case 'admin/help#aggregation':
 			$output = '<p>'. t('The aggregation module is a module that is responsible for aggregating any XML feed, custom feeds need a feed_handler. Check the accompanying readme file.') .'</p>';
@@ -57,19 +57,18 @@
  * Implementation of hook_menu().
  *
  */
-function aggregation_menu($may_cache)
+function aggregation_menu()
 {
 	$items = array();
 
 	if (!$may_cache)
 	{
-		$items[] = array(
-		'path' => 'admin/settings/aggregation',
+		$items['admin/settings/aggregation'] = array(
 		'title' => t('Aggregation'),
 		'description' => t('These options control the general behavior of the aggregation module.'),
-		'callback' => 'drupal_get_form',
-		'callback arguments' => array('aggregation_admin_settings'),
-		'access' => user_access('administer site configuration'),
+		'page callback' => 'drupal_get_form',
+		'page arguments' => array('aggregation_admin_settings'),
+		'access arguments' => array('administer site configuration'),
 		'type' => MENU_NORMAL_ITEM);
 	}
 
@@ -232,7 +231,7 @@
 			}
 		}
 		catch (Exception $e) {
-			watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR, l(t('view'), "node/$feed->nid"));
+			watchdog('aggregation', $e->getMessage(), NULL, WATCHDOG_ERROR, l(t('view'), "node/$feed->nid"));
 		}
 	}
 
@@ -246,7 +245,7 @@
  * Implementation of hook_access().
  */
 
-function aggregation_feed_access($op, $node)
+function aggregation_feed_access($op, $node, $account)
 {
 	return user_access('manage aggregation feeds');
 }
@@ -476,15 +475,18 @@
 
 	$fakeform = array();
 	$fakeform['#node'] = new stdClass();
+  $fakeform_state = array();
 
-	if ($node->item_categories)
+	if ($node->item_categories) {
 		$fakeform['#node']->taxonomy = $node->item_categories;
+    $fakeform_state['values']['taxonomy'] = $node->item_categories;
+  }
 
 	// This part will trick taxonomy into believing it's dealing with an aggregation_item
 	$fakeform['type']['#value'] = 'aggregation_item';
 	$fakeform['#node']->type = 'aggregation_item';
 
-	taxonomy_form_alter('aggregation_item_node_form', $fakeform);
+	taxonomy_form_alter(&$fakeform, $fakeform_state, 'aggregation_item_node_form');
 
 	$form['item_taxonomies']['item_categories'] = $fakeform['taxonomy'];
 
@@ -511,8 +513,10 @@
 
 /**
  * Implementation of hook_submit().
+ * 
+ * In drupal 6.x, hook_submit() has been removed. We call this function
+ * through the 'presave' op in _nodeapi function.
  */
-
 function aggregation_feed_submit(&$node)
 {
 	$node->title = $node->title;
@@ -630,15 +634,13 @@
  * Implementation of hook_access().
  */
 
-function aggregation_item_access($op, $node)
+function aggregation_item_access($op, $node, $account)
 {
-	global $user;
-
 	if ($op == 'create') return user_access('manage aggregation items');
 	if ($op == 'update' || $op == 'delete')
 	{
 	    if (user_access('manage feed items')) return TRUE;
-	   return (user_access('manage own feed items') && ($user->uid == $node->uid));
+	   return (user_access('manage own feed items') && ($account->uid == $node->uid));
 	}
 	if ($op == 'view') return user_access('view aggregation items');
 }
@@ -758,15 +760,13 @@
 	$feeds = db_query('SELECT n.nid, n.title FROM {node} n, {aggregation_feed} af '.
 		'WHERE n.nid = af.nid');
 
-	if (db_num_rows($feeds) != 0)
-	{
 		$feed_array = array();
-
-		$feed_array[0] = '<none>';
-
 		while ($feed = db_fetch_object($feeds))
 			$feed_array[$feed->nid] = $feed->title;
 
+  if (count($feed_array)) {
+    $feed_array = array_merge ('<none>', $feed_array);
+
 		$form['fid'] = array (
 			'#type' => 'select',
 			'#default_value' => $node->fid,
@@ -799,8 +799,10 @@
 
 /**
  * Implementation of hook_submit().
+ * 
+ * In drupal 6.x, hook_submit() has been removed. We call this function
+ * through the 'presave' op in _nodeapi function.
  */
-
 function aggregation_item_submit(&$node)
 {
 	$node->title = $node->title;
@@ -821,6 +823,9 @@
 		$node->story_guid = '';
 		
   $node->aggregation_item_options = serialize($node->aggregation_item_options);
+
+  if (isset($node->feed_guid)) 
+    $node->story_guid = $node->feed_guid;
 }
 
 /**
@@ -1166,7 +1171,7 @@
 
 	if ($data === FALSE)
 	{
-		watchdog('aggregation', t("Feed \"%s\" was not modified since last refresh", array('%s' => $feed->title)));
+		watchdog('aggregation', "Feed \"%s\" was not modified since last refresh", array('%s' => $feed->title));
 		return NULL;
 	}
 
@@ -1235,24 +1240,23 @@
 	$guid = sprintf('%u', crc32($guid));
 	if (!$interval_check)
 	{
-	 	$nid = db_query("SELECT nid FROM {aggregation_item} WHERE ".
+	 	$result = db_query("SELECT nid FROM {aggregation_item} WHERE ".
 							 		"story_guid = '%s' AND fid = %d", $guid, $feed->nid);
-		
-		if (db_num_rows($nid) > 0)
-		  $nid = db_fetch_object($nid)->nid;
+    if ($r = db_fetch_array($result)) 
+      $nid = $r['nid'];
 		else
 		  $nid = 0;
 		  
 	}
 	else // since no real guid is available (neither unique guid nor url), we resort to checking the title or body
 	{
-	 	$nid = db_query("SELECT n.nid AS nid FROM {node} n, {aggregation_item} ai ".
+	 	$result = db_query("SELECT n.nid AS nid FROM {node} n, {aggregation_item} ai ".
 			"WHERE ai.nid = n.nid AND ai.story_guid = %s AND UNIX_TIMESTAMP() - n.created ".
 			($feed->title_as_guid_interval == 0 ? ">=" : "<=")." %d",
 			$guid, $feed->title_as_guid_interval * 60 * 60);
 		
-		if (db_num_rows($nid) > 0)
-		  $nid = db_fetch_object($nid)->nid;
+		if ($r = db_fetch_array($result)) 
+		  $nid = $r['nid'];
 		else
 		  $nid = 0;
 	}
@@ -1277,6 +1281,7 @@
 		$item_object->aggregation_item_options['link_to_original_url'] = $feed->aggregation_feed_options['link_items_to_original_urls'] ? 1 : 0;
 		$item_object->aggregation_item_options['link_to_original_comment'] = $feed->aggregation_feed_options['link_items_to_original_comments'] ? 1 : 0;
 		unset($item_object->nid);
+		unset($item_object->vid);
 	}
 	
 	$item_object->taxonomy = $item_object->item_categories;
@@ -1328,8 +1333,11 @@
 				$image_result_array = _aggregation_create_image($image, $title, $feed, $item_object);
 				if ($image_result_array === FALSE)
 				{
-					watchdog('aggregation',"Image with URL \"".$image_array['url']."\" from feed \"{$feed->title}\"".
-						" was not retrieved.");
+					watchdog('aggregation',
+              'Image with URL "!image_url" from feed "{!feed_title}" was not retrieved.',
+              array(
+                '!image_url' => $image_array['url'], 
+                'feed_title' => $feed->title));
 					$image_nid = 0;
 					$image_guid = 0;
 				} else
@@ -1361,15 +1369,16 @@
 		 foreach ($other AS $key => $val)
 		 		$item_object->$key = $val;
 	
-	aggregation_item_submit($item_object);
-	
 	// this will undo the corruption that happened in the submit call
-	$item_object->story_guid = (!is_null($guid) && !empty($guid)) ? $guid : '';
+//	$item_object->story_guid = (!is_null($guid) && !empty($guid)) ? $guid : '';
+
+  // set this to make the submit call to set story_guid to this value
+	$item_object->feed_guid = (!is_null($guid) && !empty($guid)) ? $guid : '';
 	
 	node_save($item_object);
 	if (variable_get('aggregation_enable_logging', TRUE))
-			if (!$prexisting) watchdog('aggregation', "Added item \"$item_object->title\" from feed \"$feed->title\"", WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid"));
-			else watchdog('aggregation', "Updated item \"$item_object->title\" from feed \"$feed->title\"", WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid"));
+			if (!$prexisting) watchdog('aggregation', "Added item \"$item_object->title\" from feed \"$feed->title\"", NULL, WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid"));
+			else watchdog('aggregation', "Updated item \"$item_object->title\" from feed \"$feed->title\"", NULL, WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid"));
 	if (variable_get('aggregation_feed_refresh_cooldown', 0) > 0)
 		sleep(variable_get('aggregation_feed_refresh_cooldown', 0));
 }
@@ -1393,7 +1402,8 @@
 
 	$image_exists =
 		db_query("SELECT ai.image_id FROM {aggregation_item} ai WHERE ai.image_guid = %s", $numeric_guid);
-	if (db_num_rows($image_exists) > 0) return array(db_fetch_object($image_exists)->image_id, $numeric_guid);
+	if ($r = db_fetch_object($image_exists)) 
+    return array($r->image_id, $numeric_guid);
 
 	$filename = substr($image_array['url'], strrpos($image_array['url'], '/') + 1);
 
@@ -1408,7 +1418,7 @@
 			throw new Exception('Could not write to file! Maybe permissions?', COULD_NOT_WRITE_TO_FILE);
 	}
 	catch (Exception $e) {
-		watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR);
+		watchdog('aggregation', $e->getMessage(), NULL, WATCHDOG_ERROR);
 		return 0;
 	}
 
@@ -1441,8 +1451,8 @@
 function _aggregation_add_vocab($name)
 {
 	$vid = db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", $name);
-	if (db_num_rows($vid) != 0)
-		return db_fetch_object($vid)->vid;
+	if ($r = db_fetch_object($vid))
+		return $r->vid;
 
 	$vocab = array();
 
@@ -1470,8 +1480,8 @@
 function _aggregation_add_term($vid, $name)
 {
 	$tid = db_query("SELECT tid FROM {term_data} WHERE vid = %d AND name = '%s'", $vid, $name);
-	if (db_num_rows($tid) != 0)
-		return db_fetch_object($tid)->tid;
+	if ($r = db_fetch_object($tid))
+		return $r->tid;
 
 	$term = array();
 
@@ -1484,3 +1494,38 @@
 
 	return $term['tid'];
 }
\ No newline at end of file
+
+/**
+  * Implementation of hook_theme()
+  */
+function aggregation_theme() {
+  return array(
+      'aggregation_image_render' => array(
+        'arguments' => array('image'),
+        ),
+      'aggregation_body_render' => array(
+        'arguments' => array('body'),
+        ),
+      'aggregation_item_render' => array(
+        'arguments' => array('image_render', 'body_render'),
+        ),
+      );
+}
+
+/**
+  * Implementation of hook_nodeapi()
+  */
+function aggregation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  switch ($op) {
+    case 'presave':
+      switch ($node->type) {
+        case 'aggregation_feed':
+          aggregation_feed_submit($node);
+          break;
+        case 'aggregation_item':
+          aggregation_item_submit($node);
+          break;
+      }
+      break;
+  }
+}
