use wcf\data\DatabaseObject;
use wcf\data\IMessage;
use wcf\data\TUserContent;
-use wcf\system\bbcode\SimpleMessageParser;
use wcf\system\comment\CommentHandler;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\util\StringUtil;
* @property-read integer $responses number of responses on the comment
* @property-read string $responseIDs serialized array with the ids of the five latest comment responses
* @property-read integer $enableHtml is 1 if HTML will rendered in the comment, otherwise 0
+ * @property-read integer $hasEmbeddedObjects number of embedded objects in the comment
*/
class Comment extends DatabaseObject implements IMessage {
use TUserContent;
use wcf\data\comment\response\CommentResponseEditor;
use wcf\data\comment\response\CommentResponseList;
use wcf\data\comment\response\StructuredCommentResponse;
+use wcf\data\IMessageInlineEditorAction;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\exception\UserInputException;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\like\LikeHandler;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\user\activity\event\UserActivityEventHandler;
use wcf\system\user\notification\object\type\ICommentUserNotificationObjectType;
use wcf\system\user\notification\object\type\IMultiRecipientCommentUserNotificationObjectType;
* @method CommentEditor[] getObjects()
* @method CommentEditor getSingleObject()
*/
-class CommentAction extends AbstractDatabaseObjectAction {
+class CommentAction extends AbstractDatabaseObjectAction implements IMessageInlineEditorAction {
/**
* @inheritDoc
*/
'enableHtml' => 1
]);
+ // save embedded objects
+ $htmlInputProcessor->setObjectID($this->createdComment->commentID);
+ if (MessageEmbeddedObjectManager::getInstance()->registerObjects($htmlInputProcessor)) {
+ (new CommentEditor($this->createdComment))->update(['hasEmbeddedObjects' => 1]);
+ $this->createdComment = new Comment($this->createdComment->commentID);
+ }
+
// update counter
$this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1);
];
}
+ /**
+ * @inheritDoc
+ */
public function validateBeginEdit() {
$this->comment = $this->getSingleObject();
}
}
+ /**
+ * @inheritDoc
+ */
public function beginEdit() {
WCF::getTPL()->assign([
'comment' => $this->comment,
];
}
+ /**
+ * @inheritDoc
+ */
public function validateSave() {
$this->validateBeginEdit();
$this->validateMessage(true);
}
+ /**
+ * @inheritDoc
+ */
public function save() {
/** @var HtmlInputProcessor $htmlInputProcessor */
$htmlInputProcessor = $this->parameters['htmlInputProcessor'];
]);
$action->executeAction();
+ if ($this->comment->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects($htmlInputProcessor)) {
+ /** @noinspection PhpUndefinedMethodInspection */
+ $this->comment->update([
+ 'hasEmbeddedObjects' => $this->comment->hasEmbeddedObjects ? 0 : 1
+ ]);
+ }
+
+ // load embedded objects
+ MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.comment', [$this->comment->commentID]);
+
return [
'actionName' => 'save',
'message' => (new Comment($this->comment->commentID))->getFormattedMessage()
* @return string
*/
protected function renderComment(Comment $comment) {
+ if ($comment->hasEmbeddedObjects) {
+ MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.comment', [$comment->commentID]);
+ }
+
$comment = new StructuredComment($comment);
$comment->setIsDeletable($this->commentProcessor->canDeleteComment($comment->getDecoratedObject()));
$comment->setIsEditable($this->commentProcessor->canEditComment($comment->getDecoratedObject()));
if ($isComment) {
$this->setDisallowedBBCodes();
- $htmlInputProcessor = $this->getHtmlInputProcessor($this->parameters['data']['message']);
+ $htmlInputProcessor = $this->getHtmlInputProcessor($this->parameters['data']['message'], ($this->comment !== null ? $this->comment->commentID : 0));
// search for disallowed bbcodes
$disallowedBBCodes = $htmlInputProcessor->validate();
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\comment\manager\ICommentManager;
use wcf\system\like\LikeHandler;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
/**
* Provides a structured comment list fetching last responses for every comment.
*/
public $sqlOrderBy = 'comment.time DESC';
+ /**
+ * enables/disables the loading of responses
+ * @var boolean
+ */
+ public $responseLoading = true;
+
+ /**
+ * enables/disables the loading of embedded objects
+ * @var boolean
+ */
+ protected $embeddedObjectLoading = true;
+
+ /**
+ * ids of the comments with embedded objects
+ * @var integer[]
+ */
+ protected $embeddedObjectCommentIDs = [];
+
/**
* Creates a new structured comment list.
*
// fetch response ids
$responseIDs = $userIDs = [];
+ /** @var Comment $comment */
foreach ($this->objects as $comment) {
if (!$this->minCommentTime || $comment->time < $this->minCommentTime) $this->minCommentTime = $comment->time;
- $commentResponseIDs = $comment->getResponseIDs();
- foreach ($commentResponseIDs as $responseID) {
- $this->responseIDs[] = $responseID;
- $responseIDs[$responseID] = $comment->commentID;
+
+ if ($this->responseLoading) {
+ $commentResponseIDs = $comment->getResponseIDs();
+ foreach ($commentResponseIDs as $responseID) {
+ $this->responseIDs[] = $responseID;
+ $responseIDs[$responseID] = $comment->commentID;
+ }
+ }
+
+ if ($this->embeddedObjectLoading && $comment->hasEmbeddedObjects) {
+ $this->embeddedObjectCommentIDs[] = $comment->commentID;
}
if ($comment->userID) {
}
// fetch last responses
- if (!empty($responseIDs)) {
+ if ( !empty($responseIDs)) {
$responseList = new CommentResponseList();
$responseList->setObjectIDs(array_keys($responseIDs));
$responseList->readObjects();
if (!empty($userIDs)) {
UserProfileRuntimeCache::getInstance()->cacheObjectIDs(array_unique($userIDs));
}
+
+ if ($this->embeddedObjectLoading) {
+ $this->readEmbeddedObjects();
+ }
}
/**
public function getCommentManager() {
return $this->commentManager;
}
+
+ /**
+ * Reads the embedded objects of the posts in the list.
+ */
+ public function readEmbeddedObjects() {
+ if (!empty($this->embeddedObjectCommentIDs)) {
+ // load embedded objects
+ MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.comment', $this->embeddedObjectCommentIDs);
+ }
+ }
}
responses MEDIUMINT(7) NOT NULL DEFAULT '0',
responseIDs VARCHAR(255) NOT NULL DEFAULT '',
enableHtml TINYINT(1) NOT NULL DEFAULT 0,
+ hasEmbeddedObjects TINYINT(1) NOT NULL DEFAULT 0,
KEY (objectTypeID, objectID, time),
KEY lastCommentTime (userID, time)