1<?php 2/** 3 * magnifier 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(); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14class syntax_plugin_magnifier extends DokuWiki_Syntax_Plugin { 15 16 private $headers = array(); 17 18 function getInfo(){ 19 return array_merge(confToHash(dirname(__FILE__).'/plugin.info.txt'), array()); 20 } 21 22 function getType() { return 'substition'; } 23 function getPType() { return 'normal'; } 24 function getSort() { return 98; } 25 26 function connectTo($mode) { 27 28 $this->Lexer->addSpecialPattern('{{magnifier>[^}]+}}', $mode, 'plugin_magnifier'); 29 } 30 31 function handle($match, $state, $pos, Doku_Handler $handler) { 32 33 // {{magnifier>:image:test.png?widthxheight}} 34 35 $orig = substr($match, 12, -2); 36 37 list($id, $param) = explode('?', $orig, 2); // find ID + Params 38 list($w, $h) = explode('x', $param, 2); // find Size 39 40 $p1 = Doku_Handler_Parse_Media($orig); 41 return array(trim($id), $w, $h, $orig, $p1); 42 } 43 44 function render($mode, Doku_Renderer $renderer, $data) { 45 global $ID, $conf, $JSINFO; 46 47 list($id, $w, $h, $orig, $p1) = $data; 48 if ( empty($id) ) { $exists = false; } else 49 { 50 $id = cleanID($id); 51 $page = resolve_id(getNS($ID),$id); 52 $file = mediaFN($page); 53 $exists = @file_exists($file) && @is_file($file); 54 } 55 56 if ($mode == 'xhtml') { 57 58 $params = ''; $params2 = ''; 59 60 if ( $exists ) { 61 // is Media 62 63 $scID = sectionID(noNs($id), $this->headers); 64 65 $p = array(); 66 $p['alt'] = $id; 67 $p['class'] = 'magnifierImage'; 68 $p['id'] = 'magnifierimage_' . $scID; 69 $p['magnifierImage'] = ml($id); 70 if ($p1['width']) $p['width'] = $p1['width']; 71 if ($p1['height']) $p['height'] = $p1['height']; 72 if ($p1['title'] && !$p['title']) { $p['title'] = $p1['title']; $p['alt'] = $p1['title']; } 73 if ($p1['align']) $p['class'] .= ' media' . $p1['align']; 74 75 $p2 = buildAttributes($p); 76 $renderer->doc .= '<img src="' . ml($id, array( 'w' => $p['width'], 'h' => $p['height'] ) ) . '" '.$p2.'/>'; 77 78 return true; 79 } 80 } 81 return false; 82 } 83 84 function _renderFinalPopupImage($id, $exists, $more, $name, $isImageMap, $script, $class='') { 85 86 $more .= ' class="wikilink' . ($exists?1:2) . (!empty($class) ? ' ' . $class : '' ). '"'; 87 $name = trim(preg_replace("%^(\s|\r|\n)*?<a.+?>(.*)?</a>(\s|\r|\n)*?$%is", "$2", preg_replace("%^(\s|\r|\n)*?<p.*?>(.*)?</p>(\s|\r|\n)*?$%is", "$2", $name))); 88 89 if ( !is_array($isImageMap) ) { 90 return '<a href="'.$id.'" ' . $more . ' >' . $name . '</a>' . $script; 91 } else { 92 $return = '<area href="'.$id.'" ' . $more . ''; 93 $return .= ' title="'.$name.'" alt="'.$name.'"'; 94 $return .= ' shape="'.$isImageMap['shape'].'" coords="'.$isImageMap['coords'].'" />' . $script; 95 96 return $return; 97 } 98 } 99} 100// vim:ts=4:sw=4:et:enc=utf-8: 101