-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathHtmlOutputNodeWoltlabQuote.class.php
More file actions
117 lines (104 loc) · 4.01 KB
/
HtmlOutputNodeWoltlabQuote.class.php
File metadata and controls
117 lines (104 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace wcf\system\html\output\node;
use wcf\data\user\UserProfile;
use wcf\system\application\ApplicationHandler;
use wcf\system\html\node\AbstractHtmlNodeProcessor;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\request\RouteHandler;
use wcf\system\WCF;
use wcf\util\DOMUtil;
use wcf\util\StringUtil;
/**
* Processes quotes.
*
* @author Alexander Ebert
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 3.0
*/
class HtmlOutputNodeWoltlabQuote extends AbstractHtmlOutputNode
{
/**
* @inheritDoc
*/
protected $tagName = 'woltlab-quote';
/**
* @inheritDoc
*/
public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor)
{
/** @var \DOMElement $element */
foreach ($elements as $element) {
switch ($this->outputType) {
case 'text/html':
$collapse = false;
// try to predict long content
if (
$element->getElementsByTagName('p')->length > 5
|| $element->getElementsByTagName('br')->length > 5
) {
$collapse = true;
}
$link = $element->getAttribute('data-link');
if (\str_starts_with($link, 'index.php')) {
$link = WCF::getPath() . $link;
}
[$nodeIdentifier, $tagName] = $htmlNodeProcessor->getWcfNodeIdentifier();
$htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
'author' => $element->getAttribute('data-author'),
'collapse' => $collapse,
'url' => $link,
]);
$htmlNodeProcessor->renameTag($element, $tagName);
break;
case 'text/simplified-html':
case 'text/plain':
// check if this quote is within another
if (DOMUtil::hasParent($element, 'woltlab-quote')) {
DOMUtil::removeNode($element);
} else {
$htmlNodeProcessor->replaceElementWithText(
$element,
WCF::getLanguage()->getDynamicVariable(
'wcf.bbcode.quote.simplified',
['cite' => $element->getAttribute('data-author')]
),
true
);
}
break;
}
}
}
/**
* @inheritDoc
*/
public function replaceTag(array $data)
{
$externalQuoteLink = false;
if (!empty($data['url'])) {
$externalQuoteLink = !ApplicationHandler::getInstance()->isInternalURL($data['url']);
}
if (!$externalQuoteLink) {
$data['url'] = \preg_replace('~^https://~', RouteHandler::getProtocol(), $data['url']);
}
$quoteAuthorObject = null;
if ($data['author'] && !$externalQuoteLink) {
$quoteAuthorLC = \mb_strtolower(StringUtil::decodeHTML($data['author']));
foreach (MessageEmbeddedObjectManager::getInstance()->getObjects('com.woltlab.wcf.quote') as $user) {
\assert($user instanceof UserProfile);
if (\mb_strtolower($user->username) == $quoteAuthorLC) {
$quoteAuthorObject = $user;
break;
}
}
}
return WCF::getTPL()->render('wcf', 'shared_quoteMetaCode', [
'collapseQuote' => $data['collapse'],
'quoteLink' => $data['url'],
'quoteAuthor' => $data['author'],
'quoteAuthorObject' => $quoteAuthorObject,
'isExternalQuoteLink' => $externalQuoteLink,
]);
}
}