<classname>wcf\system\search\ArticleSearch</classname>
<searchindex>wcf1_article_search_index</searchindex>
</type>
+ <type>
+ <name>com.woltlab.wcf.article.content</name>
+ <definitionname>com.woltlab.wcf.message</definitionname>
+ </type>
<!-- /articles -->
<type>
use wcf\data\user\User;
use wcf\form\AbstractForm;
use wcf\system\exception\UserInputException;
+use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\language\LanguageFactory;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
*/
public $content = [];
+ /**
+ * @var HtmlInputProcessor[]
+ */
+ public $htmlInputProcessors = [];
+
/**
* image ids
* @var integer[]
if (empty($this->content[$language->languageID])) {
throw new UserInputException('content'.$language->languageID);
}
+
+ $this->htmlInputProcessors[$language->languageID] = new HtmlInputProcessor();
+ $this->htmlInputProcessors[$language->languageID]->process($this->content[$language->languageID]);
}
}
else {
if (empty($this->content[0])) {
throw new UserInputException('content');
}
+
+ $this->htmlInputProcessors[0] = new HtmlInputProcessor();
+ $this->htmlInputProcessors[0]->process($this->content[0]);
}
}
'tags' => (!empty($this->tags[$language->languageID]) ? $this->tags[$language->languageID] : []),
'teaser' => (!empty($this->teaser[$language->languageID]) ? $this->teaser[$language->languageID] : ''),
'content' => (!empty($this->content[$language->languageID]) ? $this->content[$language->languageID] : ''),
+ 'htmlInputProcessor' => (isset($this->htmlInputProcessors[$language->languageID]) ? $this->htmlInputProcessors[$language->languageID] : null),
'imageID' => (!empty($this->imageID[$language->languageID]) ? $this->imageID[$language->languageID] : null)
];
}
'tags' => (!empty($this->tags[0]) ? $this->tags[0] : []),
'teaser' => (!empty($this->teaser[0]) ? $this->teaser[0] : ''),
'content' => (!empty($this->content[0]) ? $this->content[0] : ''),
+ 'htmlInputProcessor' => (isset($this->htmlInputProcessors[0]) ? $this->htmlInputProcessors[0] : null),
'imageID' => (!empty($this->imageID[0]) ? $this->imageID[0] : null)
];
}
'tags' => (!empty($this->tags[$language->languageID]) ? $this->tags[$language->languageID] : []),
'teaser' => (!empty($this->teaser[$language->languageID]) ? $this->teaser[$language->languageID] : ''),
'content' => (!empty($this->content[$language->languageID]) ? $this->content[$language->languageID] : ''),
+ 'htmlInputProcessor' => (isset($this->htmlInputProcessors[$language->languageID]) ? $this->htmlInputProcessors[$language->languageID] : null),
'imageID' => (!empty($this->imageID[$language->languageID]) ? $this->imageID[$language->languageID] : null)
];
}
'tags' => (!empty($this->tags[0]) ? $this->tags[0] : []),
'teaser' => (!empty($this->teaser[0]) ? $this->teaser[0] : ''),
'content' => (!empty($this->content[0]) ? $this->content[0] : ''),
+ 'htmlInputProcessor' => (isset($this->htmlInputProcessors[0]) ? $this->htmlInputProcessors[0] : null),
'imageID' => (!empty($this->imageID[0]) ? $this->imageID[0] : null)
];
}
* @property-read integer $enableComments
* @property-read integer $comments
* @property-read integer $views
- * @todo
+ * @property-read integer $cumulativeLikes
*/
class Article extends DatabaseObject implements ILinkableObject {
/**
use wcf\system\comment\CommentHandler;
use wcf\system\language\LanguageFactory;
use wcf\system\like\LikeHandler;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\search\SearchIndexManager;
use wcf\system\tagging\TagEngine;
// save article content
if (!empty($this->parameters['content'])) {
foreach ($this->parameters['content'] as $languageID => $content) {
+ if (!empty($content['htmlInputProcessor'])) {
+ /** @noinspection PhpUndefinedMethodInspection */
+ $content['content'] = $content['htmlInputProcessor']->getHtml();
+ }
+
/** @var ArticleContent $articleContent */
$articleContent = ArticleContentEditor::create([
'articleID' => $article->articleID,
'content' => $content['content'],
'imageID' => $content['imageID']
]);
+ $articleContentEditor = new ArticleContentEditor($articleContent);
// save tags
if (!empty($content['tags'])) {
// update search index
SearchIndexManager::getInstance()->add('com.woltlab.wcf.article', $articleContent->articleContentID, $articleContent->content, $articleContent->title, $article->time, $article->userID, $article->username, ($languageID ?: null), $articleContent->teaser);
+
+ // save embedded objects
+ if (!empty($content['htmlInputProcessor'])) {
+ if (MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'], 'com.woltlab.wcf.article.content', $articleContent->articleContentID)) {
+ $articleContentEditor->update(['hasEmbeddedObjects' => 1]);
+ }
+ }
}
}
if (!empty($this->parameters['content'])) {
foreach ($this->getObjects() as $article) {
foreach ($this->parameters['content'] as $languageID => $content) {
+ if (!empty($content['htmlInputProcessor'])) {
+ /** @noinspection PhpUndefinedMethodInspection */
+ $content['content'] = $content['htmlInputProcessor']->getHtml();
+ }
+
$articleContent = ArticleContent::getArticleContent($article->articleID, ($languageID ?: null));
+ $articleContentEditor = null;
if ($articleContent !== null) {
// update
- $editor = new ArticleContentEditor($articleContent);
- $editor->update([
+ $articleContentEditor = new ArticleContentEditor($articleContent);
+ $articleContentEditor->update([
'title' => $content['title'],
'teaser' => $content['teaser'],
'content' => $content['content'],
}
}
else {
+ /** @var ArticleContent $articleContent */
$articleContent = ArticleContentEditor::create([
'articleID' => $article->articleID,
'languageID' => ($languageID ?: null),
'content' => $content['content'],
'imageID' => $content['imageID']
]);
+ $articleContentEditor = new ArticleContentEditor($articleContent);
}
// save tags
// update search index
SearchIndexManager::getInstance()->add('com.woltlab.wcf.article', $articleContent->articleContentID, $articleContent->content, $articleContent->title, $article->time, $article->userID, $article->username, ($languageID ?: null), $articleContent->teaser);
+
+ // save embedded objects
+ if (!empty($content['htmlInputProcessor'])) {
+ if ($articleContent->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects($content['htmlInputProcessor'], 'com.woltlab.wcf.article.content', $articleContent->articleContentID)) {
+ $articleContentEditor->update(['hasEmbeddedObjects' => ($articleContent->hasEmbeddedObjects ? 0 : 1)]);
+ }
+ }
}
}
}
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
-use wcf\util\MessageUtil;
use wcf\util\StringUtil;
/**
* @property-read string $content
* @property-read string $teaser
* @property-read integer $imageID
+ * @property-read integer $hasEmbeddedObjects
*/
class ArticleContent extends DatabaseObject implements ILinkableObject, IRouteController {
/**
*/
public function getFormattedContent() {
// assign embedded objects
- MessageEmbeddedObjectManager::getInstance()->setActiveMessage('com.woltlab.wcf.article', $this->articleContentID);
+ MessageEmbeddedObjectManager::getInstance()->setActiveMessage('com.woltlab.wcf.article.content', $this->articleContentID);
// TODO
return (new HtmlOutputProcessor())->process($this->content);
return null;
}
+
public static function getArticleContent($articleID, $languageID) {
if ($languageID !== null) {
$sql = "SELECT *
<?php
namespace wcf\data\article\content;
use wcf\data\media\ViewableMediaList;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
/**
* Represents a list of viewable article contents.
public function readObjects() {
parent::readObjects();
- $imageIDs = [];
+ $imageIDs = $embeddedObjectPostIDs = [];
foreach ($this->getObjects() as $articleContent) {
if ($articleContent->imageID) {
$imageIDs[] = $articleContent->imageID;
}
+ if ($articleContent->hasEmbeddedObjects) {
+ $embeddedObjectPostIDs[] = $articleContent->articleContentID;
+ }
}
// cache images
$mediaList->readObjects();
$images = $mediaList->getObjects();
+ /** @var ViewableArticleContent $articleContent */
foreach ($this->getObjects() as $articleContent) {
if ($articleContent->imageID && isset($images[$articleContent->imageID])) {
$articleContent->setImage($images[$articleContent->imageID]);
}
}
}
+
+ // load embedded objects
+ if (!empty($embeddedObjectPostIDs)) {
+ MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs);
+ }
}
}
comments SMALLINT(5) NOT NULL DEFAULT 0,
views MEDIUMINT(7) NOT NULL DEFAULT 0,
cumulativeLikes MEDIUMINT(7) NOT NULL DEFAULT 0,
- hasEmbeddedObjects TINYINT(1) NOT NULL DEFAULT 0,
KEY (time)
);
teaser TEXT,
content MEDIUMTEXT,
imageID INT(10),
+ hasEmbeddedObjects TINYINT(1) NOT NULL DEFAULT 0,
UNIQUE KEY (articleID, languageID)
);