summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom N Harris <tnharris@whoopdedo.org>2009-09-26 01:17:46 +0200
committerTom N Harris <tnharris@whoopdedo.org>2009-09-26 01:17:46 +0200
commit27bf79241161079d1d15f8fe1927682ec562835f (patch)
treea3bd8fee282dd481a4e4dd78aa445369b602b9d2
parent66b23ce9f134c838f393fa452c450f8b6fc147c3 (diff)
downloadrpg-27bf79241161079d1d15f8fe1927682ec562835f.tar.gz
rpg-27bf79241161079d1d15f8fe1927682ec562835f.tar.bz2
Use all available icons for file links (FS#1759)
All PNG and GIF images in the lib/images/fileicons directory will be used for media file links. The conf/mime.conf file continues to restrict which file types may be uploaded. File types not in the configuration list are download-only. darcs-hash:20090925231746-6942e-299a52772f67e265a8702bda3686f495e4337a8f.gz
-rw-r--r--inc/confutils.php22
-rw-r--r--inc/media.php2
-rw-r--r--inc/parser/xhtml.php19
-rw-r--r--lib/exe/css.php29
-rw-r--r--lib/exe/fetch.php2
5 files changed, 46 insertions, 28 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index aab0be4be..5ad8385c4 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -10,21 +10,31 @@
/**
* Returns the (known) extension and mimetype of a given filename
*
+ * If $knownonly is true (the default), then only known extensions
+ * are returned.
+ *
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function mimetype($file){
+function mimetype($file, $knownonly=true){
$ret = array(false,false,false); // return array
$mtypes = getMimeTypes(); // known mimetypes
$exts = join('|',array_keys($mtypes)); // known extensions (regexp)
+ if(!$knownonly){
+ $exts = $exts.'|[_\-A-Za-z0-9]+'; // any extension
+ }
if(preg_match('#\.('.$exts.')$#i',$file,$matches)){
$ext = strtolower($matches[1]);
}
- if($ext && $mtypes[$ext]){
- if($mtypes[$ext][0] == '!'){
- $ret = array($ext, substr($mtypes[$ext],1), true);
- }else{
- $ret = array($ext, $mtypes[$ext], false);
+ if($ext){
+ if (isset($mtypes[$ext])){
+ if($mtypes[$ext][0] == '!'){
+ $ret = array($ext, substr($mtypes[$ext],1), true);
+ }else{
+ $ret = array($ext, $mtypes[$ext], false);
+ }
+ elseif(!$knownonly){
+ $ret = array($ext, 'application/octet-stream', true);
}
}
diff --git a/inc/media.php b/inc/media.php
index f1b6ea62e..4ad7047b2 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -555,7 +555,7 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){
}
// Prepare fileicons
- list($ext,$mime,$dl) = mimetype($item['file']);
+ list($ext,$mime,$dl) = mimetype($item['file'],false);
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$class = 'select mediafile mf_'.$class;
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 665307d45..e67deacd6 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -390,7 +390,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if($filename){
// add icon
- list($ext) = mimetype($filename);
+ list($ext) = mimetype($filename,false);
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$class = 'mediafile mf_'.$class;
@@ -710,7 +710,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$render = ($linking == 'linkonly') ? false : true;
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
- list($ext,$mime,$dl) = mimetype($src);
+ list($ext,$mime,$dl) = mimetype($src,false);
if(substr($mime,0,5) == 'image' && $render){
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
}elseif($mime == 'application/x-shockwave-flash' && $render){
@@ -743,16 +743,17 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['url'] = ml($src,array('cache'=>$cache));
- list($ext,$mime,$dl) = mimetype($src);
+ list($ext,$mime,$dl) = mimetype($src,false);
if(substr($mime,0,5) == 'image' && $render){
- // link only jpeg images
- // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
+ // link only jpeg images
+ // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
}elseif($mime == 'application/x-shockwave-flash' && $render){
- // don't link flash movies
- $noLink = true;
+ // don't link flash movies
+ $noLink = true;
}else{
- // add file icons
- $link['class'] .= ' mediafile mf_'.$ext;
+ // add file icons
+ $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
+ $link['class'] .= ' mediafile mf_'.$class;
}
if($hash) $link['url'] .= '#'.$hash;
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 2517db38d..6216df6e5 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -238,18 +238,25 @@ function css_filetypes(){
echo '}';
// additional styles when icon available
- $mimes = getMimeTypes();
- foreach(array_keys($mimes) as $mime){
- $class = preg_replace('/[^_\-a-z0-9]+/i','_',$mime);
- if(@file_exists(DOKU_INC.'lib/images/fileicons/'.$mime.'.png')){
- echo "a.mf_$class {";
- echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$mime.'.png)';
- echo '}';
- }elseif(@file_exists(DOKU_INC.'lib/images/fileicons/'.$mime.'.gif')){
- echo "a.mf_$class {";
- echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$mime.'.gif)';
- echo '}';
+ // scan directory for all icons
+ $exts = array();
+ if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
+ while(false !== ($file = readdir($dh))){
+ if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){
+ $ext = strtolower($match[1]);
+ $type = '.'.strtolower($match[2]);
+ if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){
+ $exts[$ext] = $type;
+ }
+ }
}
+ closedir($dh);
+ }
+ foreach($exts as $ext=>$type){
+ $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
+ echo "a.mf_$class {";
+ echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
+ echo '}';
}
}
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 728b0b448..78c130081 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -26,7 +26,7 @@
$CACHE = calc_cache($_REQUEST['cache']);
$WIDTH = (int) $_REQUEST['w'];
$HEIGHT = (int) $_REQUEST['h'];
- list($EXT,$MIME,$DL) = mimetype($MEDIA);
+ list($EXT,$MIME,$DL) = mimetype($MEDIA,false);
if($EXT === false){
$EXT = 'unknown';
$MIME = 'application/octet-stream';