-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathCommentResponse.class.php
More file actions
184 lines (161 loc) · 5.13 KB
/
CommentResponse.class.php
File metadata and controls
184 lines (161 loc) · 5.13 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace wcf\data\comment\response;
use wcf\data\comment\Comment;
use wcf\data\DatabaseObject;
use wcf\data\IMessage;
use wcf\data\TUserContent;
use wcf\system\comment\CommentHandler;
use wcf\system\comment\manager\ICommentManager;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\util\StringUtil;
/**
* Represents a comment response.
*
* @author Alexander Ebert
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @property-read int $responseID unique id of the comment response
* @property-read int $commentID id of the comment the comment response belongs to
* @property-read int $time timestamp at which the comment response has been written
* @property-read ?int $userID id of the user who wrote the comment response or `null` if the user does not exist anymore or if the comment response has been written by a guest
* @property-read string $username name of the user or guest who wrote the comment response
* @property-read string $message comment response message
* @property-read 0|1 $enableHtml is `1` if HTML will rendered in the comment response, otherwise `0`
* @property-read 0|1 $isDisabled is `1` if the comment response is disabled, otherwise `0`
* @property-read 0|1 $hasEmbeddedObjects is `1` if there are embedded objects in the comment response, otherwise `0`
*/
class CommentResponse extends DatabaseObject implements IMessage
{
use TUserContent;
/**
* comment object
* @var Comment
*/
protected $comment;
/**
* @inheritDoc
*/
public function getFormattedMessage()
{
$processor = new HtmlOutputProcessor();
$processor->process($this->message, 'com.woltlab.wcf.comment.response', $this->responseID);
return $processor->getHtml();
}
/**
* Returns a simplified version of the formatted message.
*
* @return string
*/
public function getSimplifiedFormattedMessage()
{
$processor = new HtmlOutputProcessor();
$processor->setOutputType('text/simplified-html');
$processor->process($this->message, 'com.woltlab.wcf.comment.response', $this->responseID);
return $processor->getHtml();
}
/**
* @since 6.1
*/
public function getPlainTextMessage(): string
{
$processor = new HtmlOutputProcessor();
$processor->setOutputType('text/plain');
$processor->process($this->message, 'com.woltlab.wcf.comment.response', $this->responseID);
return $processor->getHtml();
}
/**
* Returns a version of this message optimized for use in emails.
*
* @param string $mimeType Either 'text/plain' or 'text/html'
* @return string
*/
public function getMailText($mimeType = 'text/plain')
{
if ($this->hasEmbeddedObjects) {
MessageEmbeddedObjectManager::getInstance()->loadObjects(
'com.woltlab.wcf.comment.response',
[$this->responseID]
);
}
switch ($mimeType) {
case 'text/plain':
return $this->getPlainTextMessage();
case 'text/html':
return $this->getSimplifiedFormattedMessage();
}
throw new \LogicException('Unreachable');
}
/**
* @inheritDoc
*/
public function getExcerpt(int $maxLength = 255)
{
return StringUtil::truncateHTML($this->getSimplifiedFormattedMessage(), $maxLength);
}
/**
* @inheritDoc
*/
public function getMessage()
{
return $this->message;
}
/**
* Returns comment object related to this response.
*
* @return Comment
*/
public function getComment()
{
if ($this->comment === null) {
$this->comment = new Comment($this->commentID);
}
return $this->comment;
}
/**
* Sets related comment object.
*
* @return void
*/
public function setComment(Comment $comment)
{
if ($this->commentID == $comment->commentID) {
$this->comment = $comment;
}
}
/**
* @inheritDoc
*/
public function getLink(): string
{
/** @var ICommentManager $processor */
$processor = CommentHandler::getInstance()->getObjectType($this->getComment()->objectTypeID)->getProcessor();
return $processor->getResponseLink($this);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return CommentHandler::getInstance()->getObjectType($this->getComment()->objectTypeID)->getProcessor()->getTitle(
$this->getComment()->objectTypeID,
$this->getComment()->objectID,
true
);
}
/**
* @inheritDoc
*/
public function isVisible()
{
return true;
}
/**
* @inheritDoc
*/
public function __toString(): string
{
return $this->getFormattedMessage();
}
}