--- inline.module-orig 2007-04-18 13:22:27.000000000 +0200 +++ inline.module 2007-06-19 10:28:19.172927250 +0200 @@ -214,7 +214,9 @@ function _inline_fileobj(&$node, $id) { return NULL; } else { - foreach ($node->files as $file) { + // when several attachments have the same file name + // then return the last occurance + foreach ( array_reverse($node->files,TRUE) as $file) { $file = (object)$file; if ($file->filename == $id) { return $file; @@ -281,6 +283,24 @@ function theme_inline_img($file, $field) return $html; } + + /** + * for each file type supported there must exist a function + * to create the viewable output + **/ +function theme_inline_xls($file, $field) { + + $xlhtml_path= '/usr/bin/xlhtml'; + $iconv_path = '/usr/bin/iconv'; + $xlhtml_parm= ' -nh -fw '; + $iconv_parm = ' -f ISO8859-2 -t UTF8'; + + $html = shell_exec($xlhtml_path . $xlhtml_parm . $file->filepath . ' | ' . $iconv_path . $iconv_parm); + + return $html; +} + + function theme_inline_add_to_teaser($node, $file, $field) { return theme('inline_img', $file, $field) . $node->teaser; } @@ -351,12 +371,18 @@ function _inline_substitute_tags(&$node, $replace = ""; if ($file->fid != NULL) { //decide if we should show a link or an img tag - if (_inline_decide_img_tag($file)) { - $replace = theme('inline_img', $file, $field); - } - else { - $replace = theme('inline_as_link', $file); - } + + // _inline_decide_inline_tag now returns some kind of document type + switch( _inline_decide_inline_tag($file) ) { + case 'img': + $replace = theme('inline_img', $file, $field); + break; + case 'xls': + $replace = theme('inline_xls', $file, $field); + break; + default: + $replace = theme('inline_as_link', $file); + } } else { $replace = "NOT FOUND: $value"; @@ -439,3 +465,27 @@ function _inline_decide_img_tag($file) { return FALSE; } + + +/** + * Decides if a inline tag or a link to a file should be rendered + * + * @param $file a file object + * + * @return type of file found or '' if unknown: + * currently the following type are supported + * 'img' for inlinable images + * 'xls' for MS excle sheet + */ +function _inline_decide_inline_tag($file) { + if (_inline_decide_img_tag($file)) { + return 'img'; + } else { + $inlined = array('xls', 'vnd.ms-excel'); + $mime = array_pop(explode('/', $file->filemime)); + if (in_array($mime, $inlined)) { + return 'xls'; + } + return ''; + } +}