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