use SVG icons for media file links

The dokuwiki template should probably be adjusted a bit. Old png files
are not yet removed as they may be used elsewhere still.
This commit is contained in:
Andreas Gohr 2021-01-07 11:17:25 +01:00
parent 9453716dc4
commit 24115d4272
3 changed files with 31 additions and 12 deletions

View File

@ -357,30 +357,26 @@ function css_filetypes(){
// default style
echo '.mediafile {';
echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
echo ' padding-left: 18px;';
echo ' padding-bottom: 1px;';
echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/svg/file.svg) 0px 1px no-repeat;';
echo ' background-size: 1.2em;';
echo ' padding-left: 1.5em;';
echo '}';
// additional styles when icon available
// scan directory for all icons
$exts = array();
if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
if($dh = opendir(DOKU_INC.'lib/images/fileicons/svg')){
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;
}
if(preg_match('/(.*?)\.svg$/i',$file, $match)){
$exts[] = strtolower($match[1]);
}
}
closedir($dh);
}
foreach($exts as $ext=>$type){
foreach($exts as $ext){
$class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
echo ".mf_$class {";
echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/svg/'.$ext.'.svg)';
echo '}';
}
}

View File

@ -0,0 +1 @@
Icons come from https://fileicons.org/

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>Filetype icons</title>
<style>
body {
background-color: #fff;
font-family: Arial;
}
</style>
</head>
<body>
<?php
foreach (glob('*.svg') as $img) {
echo '<img src="'.$img.'" alt="'.$img.'" width="32" height="32" title="'.$img.'" /> ';
}
?>
</body>
</html>