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
11if (!defined('DOKU_INC')) die();
12
13/**
14 * Class syntax_plugin_blogtng_readmore
15 */
16class syntax_plugin_blogtng_readmore extends DokuWiki_Syntax_Plugin {
17
18    /**
19     * Syntax Type
20     *
21     * @return string
22     */
23    function getType() { return 'substition'; }
24
25    /**
26     * Paragraph Type
27     *
28     * @return string
29     */
30    function getPType() { return 'normal'; }
31
32    /**
33     * Sort for applying this mode
34     *
35     * @return int
36     */
37    function getSort() { return 300; }
38
39    /**
40     * Register the ~~READMORE~~ syntax
41     *
42     * @param string $mode
43     */
44    function connectTo($mode) {
45        $this->Lexer->addSpecialPattern('~~READMORE~~', $mode, 'plugin_blogtng_readmore');
46    }
47
48    /**
49     * Handler to prepare matched data for the rendering process
50     *
51     * @param   string       $match   The text matched by the patterns
52     * @param   int          $state   The lexer state for the match
53     * @param   int          $pos     The character position of the matched text
54     * @param   Doku_Handler $handler The Doku_Handler object
55     * @return  bool|array Return an array with all data you want to use in render, false don't add an instruction
56     */
57    function handle($match, $state, $pos, Doku_Handler $handler) {
58        // we only return an empty array here, the only purpose is to place
59        // an instruction in the instruction list
60        return array();
61    }
62
63    /**
64     * Renders a simple anchor in XHTML code for the readmore jump point.
65     *
66     * @param string $mode
67     * @param Doku_Renderer $renderer
68     * @param array $indata
69     * @return bool
70     */
71    function render($mode, Doku_Renderer $renderer, $indata) {
72        if ($mode == 'xhtml') {
73            global $ID;
74            // render a simple anchor
75            $renderer->doc .= '<a name="readmore_'.str_replace(':', '_', $ID).'"></a>';
76            return true;
77        }
78
79        // unsupported mode
80        return false;
81    }
82}
83
84// vim:ts=4:sw=4:et:
85