tstaerk / mediasyntax

Mediasyntax is a plugin for Dokuwiki that enables Mediawiki syntax.
http://www.staerk.de/thorsten/Mediasyntax
GNU General Public License v2.0
10 stars 6 forks source link

Links to non-image files only work for pdf #21

Closed renatoram closed 8 years ago

renatoram commented 8 years ago

Hi, I was wondering how to insert a link to an xls file and noticed in the code that this apparently only works for pdfs (sorry if I got this wrong, but it doesn't look like that).

So I made this tiny change to media.php to insert image links only for image extensions, and regular A links to everything else.

--- media.php.orig      2016-02-29 16:22:38.630324609 +0000
+++ media.php   2016-02-29 16:28:04.376905032 +0000
@@ -59,15 +59,17 @@
     $extension=preg_replace("/.*\./","",$filename); // e.g. png
     $pipe=preg_replace("/.*\|/","",$start);  // e.g. 50px

+    $img_exts = array("png", "jpg", "jpeg", "gif");
+
     if($mode == 'xhtml')
     {
-      if ($extension == "pdf") 
+      if (in_array(strtolower($extension), $img_exts)) 
       {
-        $renderer->doc.= '<a href="'.DOKU_BASE.'lib/exe/fetch.php?media='.$filename.'">File:'.$filename.'</a>';
+        $renderer->doc.= '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.$filename.'" width='.$pipe.' />';
       }
       else
       { 
-        $renderer->doc.= '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.$filename.'" width='.$pipe.' />';
+        $renderer->doc.= '<a href="'.DOKU_BASE.'lib/exe/fetch.php?media='.$filename.'">File:'.$filename.'</a>';
       }
     }
     return false;
renatoram commented 8 years ago

Hi, I just opened a pull request with this code.

22

tstaerk commented 8 years ago

I merged it some time ago. Today I tested it. Works as expected, thanks for the patch!