1<?php 2/** 3 * snap plugin : Affiche un lien sous forme de miniature. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Etienne M. <emauvaisfr@yahoo.fr> 7 */ 8 9// based on http://wiki.splitbrain.org/plugin:tutorial 10 11// must be run within Dokuwiki 12if (!defined('DOKU_INC')) die(); 13 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 15require_once(DOKU_PLUGIN . 'syntax.php'); 16 17/** 18 * All DokuWiki plugins to extend the parser/rendering mechanism 19 * need to inherit from this class 20 */ 21class syntax_plugin_snap extends DokuWiki_Syntax_Plugin { 22 function getInfo() { 23 return array( 24 'author' => 'Etienne M.', 25 'email' => 'emauvaisfr@yahoo.fr', 26 'date' => @file_get_contents(DOKU_PLUGIN.'snap/VERSION'), 27 'name' => 'snap Plugin', 28 'desc' => html_entity_decode($this->getLang('snap_description')), 29 'url' => 'http://www.dokuwiki.org/plugin:snap' 30 ); 31 } 32 33 function connectTo($mode) { $this->Lexer->addEntryPattern('{{\[\[(?=.*?\]\]}})',$mode,'plugin_snap'); } 34 function postConnect() { $this->Lexer->addExitPattern('\]\]}}','plugin_snap'); } 35 36 function getType() { return 'disabled'; } 37 38 function getSort() { return 100; } 39 40 /** 41 * Handle the match 42 */ 43 function handle($match, $state, $pos, &$handler){ 44 if ($state == DOKU_LEXER_ENTER){ 45 $match = trim(substr($match,4,-1)); // strip markup 46 $handler->status['plugin_snap'] = true; 47 } 48 return array($state, $match); 49 } 50 51 /** 52 * Create output 53 */ 54 function render($mode, &$renderer, $data) { 55 list($state, $cdata) = $data; 56 57 if($mode == 'xhtml') { 58 switch ($state){ 59 case DOKU_LEXER_ENTER: 60 break; 61 62 case DOKU_LEXER_UNMATCHED: 63 $param=$cdata; 64 65 //Recuperation des options 66 //(ex : url ou url|larg ou url|xhaut ou url|largxhaut; + un ! pour forcer la capture sans recherche dans le cache) 67 $param=explode("|",$param); 68 if ($param) $url=$param[0]; 69 else { 70 //FIXME !!! 71 $renderer->doc .= "<b>SNAP :</b> Erreur de syntaxe<br />"; 72 return false; 73 } 74 if (isset($param[1])) $options=$param[1]; 75 $param=$url; 76 77 if (preg_match("/!/",$options)) { 78 $checkCache=false; 79 $options=preg_replace("/!/","",$options); 80 } 81 82 if ($options) $options=explode("x",$options); 83 if ($options[0]) $larg=$options[0]*1; 84 if ($options[1]) $haut=$options[1]*1; 85 86 $snap=plugin_load('helper','snap'); 87 if (!$snap) { 88 //FIXME !!! 89 $renderer->doc .= "<b>SNAP :</b> Snap helper non trouvé<br />"; 90 return false; 91 } 92 93 list($imagePath, $titrePage, $target)=$snap->getSnap($param, $larg, $haut, $checkCache); 94 if (!$snap->succeed || !$imagePath) { 95 //FIXME !!! 96 $renderer->doc .= "<b>SNAP :</b> Probleme lors du snap de $param<br />"; 97 return false; 98 } 99 100 if ($titrePage) $titrePage=" - ".$titrePage; 101 if ($snap->snapTimeFormatted) $titrePage.=" (".$snap->snapTimeFormatted.")"; 102 103 $renderer->doc .= "<a href=\"".$snap->url."\" title=\"$param$titrePage\" $target>"; 104 $renderer->doc .= "<img src=\"".DOKU_URL."lib/plugins/snap/image.php?image=".rawurlencode($imagePath)."\" style=\"border:1px solid #C0C0C0; margin:2px;\" />"; 105 $renderer->doc .= "</a>"; 106 break; 107 108 case DOKU_LEXER_EXIT: 109 break; 110 } 111 return true; 112 } 113 return false; 114 } 115} 116?> 117