1<?php
2 /**
3 * DokuWiki Plugin tagfilter (Syntax Component)
4 *
5 * Usage: ~~PAGEIMAGE:xxx~~
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  lisps
9 */
10
11// must be run within Dokuwiki
12if (!defined('DOKU_INC')) die();
13
14if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
15if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
16if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17require_once(DOKU_PLUGIN.'syntax.php');
18
19class syntax_plugin_pageimage extends DokuWiki_Syntax_Plugin {
20
21    var $tags   = array();
22
23    function getType() { return 'substition'; }
24    function getSort() { return 305; }
25    function getPType() { return 'block';}
26
27    function connectTo($mode) {
28        $this->Lexer->addSpecialPattern('~~PAGEIMAGE:.*?~~', $mode, 'plugin_pageimage');
29    }
30
31    function handle($match, $state, $pos, Doku_Handler $handler) {
32        $image = trim(substr($match, 12, -2));     // strip markup & whitespace
33        $image = cleanID($image);
34        if(!$image) return false;
35        return $image;
36    }
37
38    /**
39    * Render xhtml output or metadata
40    *
41    * @param string         $mode      Renderer mode (supported modes: xhtml and metadata)
42    * @param Doku_Renderer  $renderer  The renderer
43    * @param array          $data      The data from the handler function
44    * @return bool If rendering was successful.
45    */
46    function render($mode, Doku_Renderer $renderer, $data) {
47        if ($data === false) return false;
48
49        // XHTML output
50        if ($mode == 'xhtml') {
51            //$renderer->doc .= $data;
52            return false;
53        // for metadata renderer
54        } elseif ($mode == 'metadata') {
55            $renderer->meta['pageimage'] = $data;
56            return true;
57        }
58        return false;
59    }
60}
61// vim:ts=4:sw=4:et:
62