1<?php 2/** 3 * DokuWiki Syntax Plugin Uparrow 4 * 5 * Shows an arrow image which links to the top of the page. 6 * The image can be defined via the configuration manager. 7 * 8 * Syntax: ~~UP~~ 9 * 10 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 11 * @author Michael Klier <chi@chimeric.de> 12 */ 13// must be run within DokuWiki 14if(!defined('DOKU_INC')) die(); 15 16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17require_once(DOKU_PLUGIN.'syntax.php'); 18 19if(!defined('DW_LF')) define('DW_LF',"\n"); 20 21/** 22 * All DokuWiki plugins to extend the parser/rendering mechanism 23 * need to inherit from this class 24 */ 25class syntax_plugin_uparrow extends DokuWiki_Syntax_Plugin { 26 27 /** 28 * return some info 29 */ 30 function getInfo(){ 31 return array( 32 'author' => 'Michael Klier', 33 'email' => 'chi@chimeric.de', 34 'date' => @file_get_contents(DOKU_PLUGIN.'uparrow/VERSION'), 35 'name' => 'Plugin UpArrow (syntax component)', 36 'desc' => 'Shows an arrow image which links to top of the page.', 37 'url' => 'http://dokuwiki.org/plugin:uparrow', 38 ); 39 } 40 41 /** 42 * Syntax Type 43 * 44 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 45 */ 46 function getType() { return 'substition'; } 47 function getPType() { return 'block'; } 48 function getSort() { return 304; } 49 50 /** 51 * Connect pattern to lexer 52 */ 53 function connectTo($mode) { $this->Lexer->addSpecialPattern('~~UP~~',$mode,'plugin_uparrow'); } 54 55 /** 56 * Handle the match 57 */ 58 function handle($match, $state, $pos, &$handler){ 59 if($match == '~~UP~~') { 60 $image = $this->getConf('image'); 61 if(!@file_exists(DOKU_PLUGIN.'uparrow/images/' . $image)) { 62 $src = DOKU_URL.'lib/plugins/uparrow/images/tango-big.png'; 63 } else { 64 $src = DOKU_URL.'lib/plugins/uparrow/images/' . $image; 65 } 66 return array($src); 67 } 68 } 69 70 /** 71 * Create output 72 */ 73 function render($mode, &$renderer, $data) { 74 global $lang; 75 76 if($mode == 'xhtml'){ 77 $renderer->doc .= '<div class="plugin_uparrow">' . DW_LF; 78 $renderer->doc .= ' <a href="#" title="' . $lang['btn_top'] . '">' . DW_LF; 79 $renderer->doc .= ' <img src="' . $data[0] . '" alt="' . $lang['btn_top'] . '"/>' . DW_LF; 80 $renderer->doc .= ' </a>' . DW_LF; 81 $renderer->doc .= '</div>' . DW_LF; 82 return true; 83 } else { 84 return false; 85 } 86 } 87} 88// vim:ts=4:sw=4:et:enc=utf-8: 89