1<?php 2/** 3 * svgImage Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14require_once(DOKU_PLUGIN.'action.php'); 15 16class action_plugin_svgimg extends DokuWiki_Action_Plugin { 17 18 var $functions = null; 19 20 function getInfo(){ 21 return confToHash(dirname(__FILE__).'/info.txt'); 22 } 23 24 function register(&$controller) { 25 26 $controller->register_hook('MEDIA_SENDFILE', 'BEFORE', $this, 'svgimg__convert'); 27 } 28 29 function svgimg__convert(&$event, $args) { 30 31 /* Filename for reflect Image */ 32 $data = $event->data; 33 $ext = $data['ext']; 34 if ( strtolower($ext) != 'svg' ) { return false; } 35 if (!$functions=& plugin_load('helper', 'svgimg')) return false; 36 37 // get Output Format 38 $ext = empty( $_REQUEST['return_type'] ) ? $this->getConf('return_type') : (in_array( hsc($_REQUEST['return_type']), array('png', 'jpg', 'jpeg') ) ? hsc($_REQUEST['return_type']) : $this->getConf('return_type')); 39 $data['mime'] = "image/$ext"; 40 41 // get width and height 42 if ( $data['width'] == 0 ) { $data['width'] = null; } 43 if ( $data['height'] == 0 ) { $data['height'] = null; } 44 45 // get Background-Color 46 $data['background'] = $functions->_calc_bgcolor($_REQUEST['bgc']); 47 48 // check the CacheFile 49 $cacheFile = $functions->_get_cache_file($data, $ext); 50 $mtime = @filemtime($cacheFile); // 0 if not exists 51 if( ($mtime == 0) || // cache does not exist 52 ($data['cache'] != -1 && $mtime < time()-$data['cache']) ) { // 'recache' and cache has expired 53 // Create Image 54 if ( $functions->create_svg_image( $data, $ext, $cacheFile) ) { 55 56 // If all done, ok. 57 // If all done, ok. 58 } else { 59 $event->preventDefault(); 60 msg('Could not transfrom svg to output format.', -1); 61 } 62 } 63 64 $data['file'] = $cacheFile; 65 $event->data = $data; 66 } 67 68 69}