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 29 Oct 2008 16:25:21 -0000 @@ -293,3 +293,75 @@ 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 + $extra = module_invoke_all('piclens_rss_item_media', $node); + if ($ns) { + $extra[0]['namespace'] = array('xmlns:media="http://search.yahoo.com/mrss/"'); + $ns = FALSE; + } + return $extra; +} + +/** + * Test piclens_nodeapi_rss_item module hook - TODO. Make file attachment handling an optional setting or a sub module +*/ +function piclens_piclens_rss_item_media($node) { + return array(_piclens_media_attachment($node, 'thumbnail'), _piclens_media_attachment($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_attachment($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