1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Saito - The Threaded Web Forum |
6
|
|
|
* |
7
|
|
|
* @copyright Copyright (c) the Saito Project Developers |
8
|
|
|
* @link https://github.com/Schlaefer/Saito |
9
|
|
|
* @license http://opensource.org/licenses/MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BbcodeParser\Lib\jBBCode\Visitors; |
13
|
|
|
|
14
|
|
|
use Cake\View\Helper; |
15
|
|
|
use JBBCode\NodeVisitor; |
16
|
|
|
use Saito\Markup\MarkupSettings; |
17
|
|
|
|
18
|
|
|
abstract class JbbCodeTextVisitor implements NodeVisitor |
19
|
|
|
{ |
20
|
|
|
protected $_disallowedTags = ['code']; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Cake\View\Helper calling CakePHP helper |
24
|
|
|
*/ |
25
|
|
|
protected $_sHelper; |
26
|
|
|
|
27
|
|
|
protected $_sOptions; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Helper $Helper, MarkupSettings $_sOptions) |
33
|
|
|
{ |
34
|
|
|
$this->_sOptions = $_sOptions; |
35
|
|
|
$this->_sHelper = $Helper; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
|
|
public function __get($name) |
42
|
|
|
{ |
43
|
|
|
if (is_object($this->_sHelper->$name)) { |
44
|
|
|
return $this->_sHelper->{$name}; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
|
|
public function visitDocumentElement( |
52
|
|
|
\JBBCode\DocumentElement $documentElement |
53
|
|
|
) { |
54
|
|
|
foreach ($documentElement->getChildren() as $child) { |
55
|
|
|
$child->accept($this); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
|
|
public function visitTextNode(\JBBCode\TextNode $textNode) |
63
|
|
|
{ |
64
|
|
|
$textNode->setValue( |
65
|
|
|
$this->_processTextNode($textNode->getValue(), $textNode) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function visitElementNode(\JBBCode\ElementNode $elementNode) |
73
|
|
|
{ |
74
|
|
|
$tagName = $elementNode->getTagName(); |
75
|
|
|
if (in_array($tagName, $this->_disallowedTags)) { |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/* We only want to visit text nodes within elements if the element's |
80
|
|
|
* code definition allows for its content to be parsed. |
81
|
|
|
*/ |
82
|
|
|
$isParsedContentNode = $elementNode->getCodeDefinition()->parseContent( |
83
|
|
|
); |
84
|
|
|
if (!$isParsedContentNode) { |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
foreach ($elementNode->getChildren() as $child) { |
89
|
|
|
$child->accept($this); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritDoc} |
95
|
|
|
*/ |
96
|
|
|
abstract protected function _processTextNode($text, $textNode); |
97
|
|
|
} |
98
|
|
|
|