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();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(dirname(__FILE__).'/core.php');
12
13class syntax_plugin_mikioplugin_blockquote extends syntax_plugin_mikioplugin_core {
14    public $tag                 = 'blockquote';
15    public $hasEndTag           = true;
16    public $options             = array(
17        'footer'                => array('type' => 'text',      'default'   => ''),
18        'cite'                  => array('type' => 'text',      'default'   => ''),
19    );
20
21    public function __construct() {
22        $this->addCommonOptions('text-align');
23    }
24
25    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'container'); }
26    public function getPType() { return 'normal'; }
27
28    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
29        $classes = $this->buildClass($data);
30
31        $renderer->doc .= '<blockquote class="' . $this->elemClass . ' ' . $this->classPrefix . 'blockquote' . $classes . '"><p>';
32    }
33
34
35    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
36        $renderer->doc .= '</p>';
37
38        if($data['footer'] != '') {
39            $footer = $data['footer'];
40
41            if($data['cite'] != '') {
42                $i = strripos($footer, $data['cite']);
43                if($i !== FALSE) {
44                    $cite = substr($footer, $i, strlen($data['cite']));
45                    $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));
46                }
47            }
48
49            $renderer->doc .= '<footer class="' . $this->elemClass . ' ' . $this->classPrefix . 'blockquote-footer">';
50            $renderer->doc .= $footer;
51            $renderer->doc .= '</footer>';
52        }
53
54        $renderer->doc .= '</blockquote>';
55    }
56}
57?>