1<?php
2/**
3 * Mikio Syntax Plugin: Blockquote
4 *
5 * @link    http://github.com/nomadjimbob/mikioplugin
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author  James Collins <james.collins@outlook.com.au>
8 */
9if (!defined('DOKU_INC')) { die();
10}
11if (!defined('DOKU_PLUGIN')) { define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12}
13require_once dirname(__FILE__).'/core.php';
14
15class syntax_plugin_mikioplugin_blockquote extends syntax_plugin_mikioplugin_core
16{
17    public $tag                 = 'blockquote';
18    public $hasEndTag           = true;
19    public $options             = array(
20        'footer'                => array('type' => 'text',      'default'   => ''),
21        'cite'                  => array('type' => 'text',      'default'   => ''),
22    );
23
24    public function __construct()
25    {
26        $this->addCommonOptions('text-align');
27    }
28
29    public function getAllowedTypes()
30    {
31        return array('formatting', 'substition', 'disabled', 'container', 'protected');
32    }
33    public function getPType()
34    {
35        return 'normal';
36    }
37
38    public function render_lexer_enter(Doku_Renderer $renderer, $data)
39    {
40        $classes = $this->buildClass($data);
41
42        $renderer->doc .= '<blockquote class="' . $this->elemClass . ' ' . $this->classPrefix . 'blockquote' . $classes . '"><p>';
43    }
44
45
46    public function render_lexer_exit(Doku_Renderer $renderer, $data)
47    {
48        $renderer->doc .= '</p>';
49
50        if($data['footer'] != '') {
51            $footer = $data['footer'];
52
53            if($data['cite'] != '') {
54                $i = strripos($footer, $data['cite']);
55                if($i !== false) {
56                    $cite = substr($footer, $i, strlen($data['cite']));
57                    $footer = substr($footer, 0, $i) . '<cite class="' . $this->elemClass . ' ' . $this->classPrefix . 'cite" title="' . $cite . '">' . substr($footer, $i, strlen($cite)) . '</cite>' . substr($footer, $i + strlen($cite));
58                }
59            }
60
61            $renderer->doc .= '<footer class="' . $this->elemClass . ' ' . $this->classPrefix . 'blockquote-footer">';
62            $renderer->doc .= $footer;
63            $renderer->doc .= '</footer>';
64        }
65
66        $renderer->doc .= '</blockquote>';
67    }
68}
69?>