1<?php
2/**
3 * Provides a syntax for defining arbitrary locations for a "readmore" Link
4 * in a blog post.
5 *
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author  Gina Haeussge <osd@foosel.net>
8 * @author  Michael Klier <chi@chimeric.de>
9 */
10
11/**
12 * Class syntax_plugin_blogtng_readmore
13 */
14class syntax_plugin_blogtng_readmore extends DokuWiki_Syntax_Plugin {
15
16    /**
17     * Syntax Type
18     *
19     * @return string
20     */
21    function getType() { return 'substition'; }
22
23    /**
24     * Paragraph Type
25     *
26     * @return string
27     */
28    function getPType() { return 'normal'; }
29
30    /**
31     * Sort for applying this mode
32     *
33     * @return int
34     */
35    function getSort() { return 300; }
36
37    /**
38     * Register the ~~READMORE~~ syntax
39     *
40     * @param string $mode
41     */
42    function connectTo($mode) {
43        $this->Lexer->addSpecialPattern('~~READMORE~~', $mode, 'plugin_blogtng_readmore');
44    }
45
46    /**
47     * Handler to prepare matched data for the rendering process
48     *
49     * @param   string       $match   The text matched by the patterns
50     * @param   int          $state   The lexer state for the match
51     * @param   int          $pos     The character position of the matched text
52     * @param   Doku_Handler $handler The Doku_Handler object
53     * @return  bool|array Return an array with all data you want to use in render, false don't add an instruction
54     */
55    function handle($match, $state, $pos, Doku_Handler $handler) {
56        // we only return an empty array here, the only purpose is to place
57        // an instruction in the instruction list
58        return array();
59    }
60
61    /**
62     * Renders a simple anchor in XHTML code for the readmore jump point.
63     *
64     * @param string $format
65     * @param Doku_Renderer $renderer
66     * @param array $data
67     * @return bool
68     */
69    function render($format, Doku_Renderer $renderer, $data) {
70        if ($format == 'xhtml') {
71            global $ID;
72            // render a simple anchor
73            $renderer->doc .= '<a name="readmore_'.str_replace(':', '_', $ID).'"></a>';
74            return true;
75        }
76
77        // unsupported mode
78        return false;
79    }
80}
81