1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4
5require_once(DOKU_PLUGIN.'formatplus2/formatting.php');
6
7class syntax_plugin_formatplus2_blockquoteplus extends FormattingPlus_Syntax_Plugin {
8
9  var $disabled = false;
10
11  function _getName() {
12    return 'BlockQuote+';
13  }
14  function _getDesc() {
15    return 'Create block quotes with optional citation.
16            Syntax: <quote cite>Block quote</quote>';
17  }
18  function _getConfig() {
19    return 'blockquote';
20  }
21
22  function _getFormatting() {
23    return array();
24  }
25
26  function getSort() {
27    return 107;
28  }
29
30  function getType() {
31    return 'container';
32  }
33
34  function getAllowedTypes() {
35    return array('container','paragraphs','formatting','substition','disabled','protected');
36  }
37
38  function getPType() {
39    return 'stack';
40  }
41
42  function preConnect() {
43    if ($this->_disabledSyntax($this->_getConfig()))
44      $this->disabled = true;
45  }
46
47  function connectTo($mode) {
48    if (!$this->disabled) {
49      $this->Lexer->addEntryPattern('<quote>(?=.*</quote>)', $mode, 'plugin_formatplus2_blockquoteplus');
50      $this->Lexer->addEntryPattern('<quote [^>\r\n]+?>(?=.*</quote>)', $mode, 'plugin_formatplus2_blockquoteplus');
51    }
52  }
53
54  function postConnect() {
55    if (!$this->disabled) {
56      $this->Lexer->addExitPattern('</quote>', 'plugin_formatplus2_blockquoteplus');
57    }
58  }
59
60  function handle($match, $state, $pos, Doku_Handler $handler){
61    switch ($state) {
62      case DOKU_LEXER_ENTER:
63        $output = trim(substr($match,6,-1));
64      break;
65      case DOKU_LEXER_EXIT:
66        $output = '';
67      break;
68      case DOKU_LEXER_UNMATCHED:
69        $output = $match;
70      break;
71    }
72    return array($state,$output);
73  }
74
75  function render($format, Doku_Renderer $renderer, $data) {
76    list($state,$output) = $data;
77    if (substr($format,0,5) == 'xhtml'){
78      switch ($state) {
79        case DOKU_LEXER_ENTER:
80          if (!empty($output)) {
81            $renderer->doc .= '<blockquote class="citation" title="'.$renderer->_xmlEntities($output).'">';
82          } else {
83            $renderer->doc .= '<blockquote class="citation">';
84          }
85        break;
86        case DOKU_LEXER_EXIT:
87          $renderer->doc .= '</blockquote>'.DOKU_LF;
88        break;
89        case DOKU_LEXER_UNMATCHED:
90          $renderer->doc .= $renderer->_xmlEntities($output);
91        break;
92      }
93      return true;
94    } elseif ($format == 'metadata') {
95      switch ($state) {
96        case DOKU_LEXER_ENTER:
97          if ($renderer->capture){
98            $renderer->doc .= DOKU_LF;
99            if(!empty($output)){
100              $renderer->doc .= $output.':';
101            }
102          }
103          break;
104        case DOKU_LEXER_EXIT:
105          if ($renderer->capture) {
106            $renderer->doc .= DOKU_LF;
107            if (strlen($renderer->doc) > 250) $renderer->capture = false;
108          }
109          break;
110        case DOKU_LEXER_UNMATCHED:
111          if ($renderer->capture) $renderer->doc .= $output;
112          break;
113      }
114      return true;
115    }
116    return false;
117  }
118}
119