Index: piclens.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/piclens/piclens.module,v
retrieving revision 1.1.2.30
diff -u -p -r1.1.2.30 piclens.module
--- piclens.module	15 Oct 2008 14:56:20 -0000	1.1.2.30
+++ piclens.module	27 Oct 2008 19:17:06 -0000
@@ -293,3 +293,79 @@ function return_display_check() {
   }
   return $display;
 }
+
+/**
+ * Implementation of hook_nodeapi().
+ * Formats and dispatches appropriate handler function if it exists
+*/
+function piclens_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  $op = str_replace(' ', '_', $op); //$op = delete revision, rss item, etc.
+  $function = "piclens_nodeapi_" . $op;
+  if (function_exists($function))
+    return $function($node, $a3, $a4);
+}
+
+/**
+ * piclens_nodeapi() - 'rss item' operation handler.
+ * 'rss item' is called by core anytime node_feed is used to create a feed.  While modules could, and still can respond to nodeapi directly
+ * this simplifies the interface for modules that are just interested in adding piclens required rss tags
+*/
+function piclens_nodeapi_rss_item(&$node, $a3, $a4) {
+  static $ns = TRUE;  //Work around for duplicate namespace bug in drupal node_feed - see http://drupal.org/node/326773
+  $thumb = module_invoke_all('piclens_rss_item_media_thumbnail', $node);
+  if ($ns) {
+    $thumb['namespace'] = array('xmlns:media="http://search.yahoo.com/mrss/"');
+    $ns = FALSE;
+  }
+  $content = module_invoke_all('piclens_rss_item_media_content', $node);
+  return array($thumb, $content);
+}
+
+/**
+ * Test piclens_nodeapi_rss_item module hooks - TODO.  Make file attachment handling an optional setting or a sub module
+*/
+function piclens_piclens_rss_item_media_thumbnail($node) {
+  return _piclens_media_attachmnent($node, 'thumbnail');
+}
+function piclens_piclens_rss_item_media_content($node) {
+  return _piclens_media_attachmnent($node, 'content');
+}
+
+/**
+ * Scans the nodes attachments looking for cooliris compatible media an formats the request tag information 
+ * in the suitable format for format_rss_item
+ */
+function _piclens_media_attachmnent($node, $tag) {
+  if (is_array($node->files)) {
+    $files = array();
+    foreach ($node->files as $file) {
+      if ($file->list && piclens_check_mimetype($file->filemime)) {
+        $files[] = $file;
+      }
+    }
+    if (count($files) > 0) {
+      // RSS only allows one enclosure per item
+      $file = array_shift($files);
+      $element = array(
+        'key' => "media:$tag",
+        'attributes' => array(
+          'url' => file_create_url($file->filepath)
+        )
+      );
+      
+      return $element;
+    }
+  }
+
+  return array();
+}
+
+function piclens_check_mimetype($mimetype) {
+  //TODO - add all supported mimetypes for cooliris
+  static $mimetypes = array(
+    'image/jpeg',
+    'image/png'
+  );
+  
+  return in_array($mimetype, $mimetypes);
+}
\ No newline at end of file
