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, Doku_Handler $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 $p1 = Doku_Handler_Parse_Media($orig); 54 return array(trim($id), $w, $h, $orig, $p1); 55 } 56 57 function render($mode, Doku_Renderer $renderer, $data) { 58 global $ID, $conf, $JSINFO; 59 60 list($id, $w, $h, $orig) = $data; 61 list($id, $w, $h, $orig, $p1) = $data; 62 if ( empty($id) ) { $exists = false; } else 63 { 64 $id = cleanID($id); 65 $page = resolve_id(getNS($ID),$id); 66 $file = mediaFN($page); 67 $exists = @file_exists($file) && @is_file($file); 68 } 69 70 if ($mode == 'xhtml') { 71 72 $params = ''; $params2 = ''; 73 74 if ( $exists ) { 75 // is Media 76 77 $p1 = Doku_Handler_Parse_Media($orig); 78 $scID = sectionID(noNs($id), $this->headers); 79 80 $p = array(); 81 $p['alt'] = $id; 82 $p['class'] = 'magnifierImage'; 83 $p['id'] = 'magnifierimage_' . $scID; 84 $p['magnifierImage'] = ml($id); 85 if ($p1['width']) $p['width'] = $p1['width']; 86 if ($p1['height']) $p['height'] = $p1['height']; 87 if ($p1['title'] && !$p['title']) { $p['title'] = $p1['title']; $p['alt'] = $p1['title']; } 88 if ($p1['align']) $p['class'] .= ' media' . $p1['align']; 89 90 $p2 = buildAttributes($p); 91 $renderer->doc .= '<img src="' . ml($id, array( 'w' => $p['width'], 'h' => $p['height'] ) ) . '" '.$p2.'/>'; 92 93 return true; 94 } 95 } 96 return false; 97 } 98 99 function _renderFinalPopupImage($id, $exists, $more, $name, $isImageMap, $script, $class='') { 100 101 $more .= ' class="wikilink' . ($exists?1:2) . (!empty($class) ? ' ' . $class : '' ). '"'; 102 $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))); 103 104 if ( !is_array($isImageMap) ) { 105 return '<a href="'.$id.'" ' . $more . ' >' . $name . '</a>' . $script; 106 } else { 107 $return = '<area href="'.$id.'" ' . $more . ''; 108 $return .= ' title="'.$name.'" alt="'.$name.'"'; 109 $return .= ' shape="'.$isImageMap['shape'].'" coords="'.$isImageMap['coords'].'" />' . $script; 110 111 return $return; 112 } 113 } 114} 115// vim:ts=4:sw=4:et:enc=utf-8: 116