use wcf\data\language\Language;
use wcf\data\DatabaseObject;
use wcf\data\ILinkableObject;
+use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\html\output\AmpHtmlOutputProcessor;
use wcf\system\html\output\HtmlOutputProcessor;
*/
public function getFormattedContent() {
$processor = new HtmlOutputProcessor();
- $processor->process($this->content, 'com.woltlab.wcf.article.content', $this->articleContentID);
+ $processor->process($this->content, 'com.woltlab.wcf.article.content', $this->articleContentID, false, $this->languageID);
return $processor->getHtml();
}
// load embedded objects
if (!empty($embeddedObjectPostIDs)) {
- MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs);
+ $contentLanguageID = null;
+ if (count($embeddedObjectPostIDs) === 1) $contentLanguageID = reset($this->objects)->languageID;
+
+ MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.article.content', $embeddedObjectPostIDs, $contentLanguageID);
}
}
}
* @property-read string|null $altText alternative text of the media file in the active user's language or `null` if object has not been fetched via `ViewableMediaList`
*/
class ViewableMedia extends DatabaseObjectDecorator {
+ /**
+ * force localized content by language id
+ * @var integer
+ */
+ protected $forceLanguageID;
+
+ /**
+ * localized content per language id
+ * @var string[][]
+ */
+ protected $localizedContent = [];
+
/**
* user profile of the user who uploaded the media file
* @var UserProfile
*/
protected static $baseClass = Media::class;
+ /**
+ * Registers localized content by language id.
+ *
+ * @param integer $languageID
+ * @param string[] $content
+ */
+ public function setLocalizedContent($languageID, array $content) {
+ $this->localizedContent[$languageID] = $content;
+ }
+
+ /**
+ * Returns an instance of this class with localized versions.
+ *
+ * @param integer $languageID
+ * @return ViewableMedia
+ */
+ public function getLocalizedVersion($languageID) {
+ if (isset($this->localizedContent[$languageID])) {
+ $localized = clone $this;
+ $localized->forceLanguageID($languageID);
+
+ return $localized;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Forces the localized values by language id.
+ *
+ * @param integer $languageID
+ */
+ protected function forceLanguageID($languageID) {
+ $this->forceLanguageID = $languageID;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function __get($name) {
+ if ($this->forceLanguageID !== null && isset($this->localizedContent[$this->forceLanguageID][$name])) {
+ return $this->localizedContent[$this->forceLanguageID][$name];
+ }
+
+ return $this->object->__get($name);
+ }
+
/**
* @inheritDoc
*/
parent::__construct();
// fetch content data
- $this->sqlSelects .= "media_content.*";
+ $this->sqlSelects .= "media_content.*, COALESCE(media.languageID, ".WCF::getLanguage()->languageID.") AS localizedLanguageID";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_media_content media_content ON (media_content.mediaID = media.mediaID AND media_content.languageID = COALESCE(media.languageID, ".WCF::getLanguage()->languageID."))";
}
}
<?php
namespace wcf\system\bbcode;
-use wcf\data\media\Media;
+use wcf\data\media\ViewableMedia;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\WCF;
use wcf\util\StringUtil;
return '';
}
- /** @var Media $media */
+ /** @var ViewableMedia $media */
$media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $mediaID);
-
if ($media !== null && $media->isAccessible()) {
if ($media->isImage) {
$thumbnailSize = (!empty($openingTag['attributes'][1])) ? $openingTag['attributes'][1] : 'original';
WCF::getTPL()->assign([
'float' => $float,
- 'media' => $media,
+ 'media' => $media->getLocalizedVersion(MessageEmbeddedObjectManager::getInstance()->getActiveMessageLanguageID()),
'thumbnailSize' => $thumbnailSize
]);
*/
protected $htmlOutputNodeProcessor;
+ /**
+ * content language id
+ * @var integer
+ */
+ protected $languageID;
+
/**
* desired output type
* @var string
* @param string $html html string
* @param string $objectType object type identifier
* @param integer $objectID object id
- * @param boolean $doKeywordHighlighting
+ * @param boolean $doKeywordHighlighting enable keyword highlighting
+ * @param integer $languageID content language id
*/
- public function process($html, $objectType, $objectID, $doKeywordHighlighting = true) {
+ public function process($html, $objectType, $objectID, $doKeywordHighlighting = true, $languageID = null) {
+ $this->languageID = $languageID;
$this->setContext($objectType, $objectID);
$this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType);
public function setContext($objectType, $objectID) {
parent::setContext($objectType, $objectID);
- MessageEmbeddedObjectManager::getInstance()->setActiveMessage($objectType, $objectID);
+ MessageEmbeddedObjectManager::getInstance()->setActiveMessage($objectType, $objectID, $this->languageID);
}
/**
use wcf\data\media\Media;
use wcf\data\media\MediaList;
use wcf\system\cache\runtime\ViewableMediaRuntimeCache;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\html\input\HtmlInputProcessor;
+use wcf\system\WCF;
use wcf\util\ArrayUtil;
/**
* @inheritDoc
*/
public function loadObjects(array $objectIDs) {
- return ViewableMediaRuntimeCache::getInstance()->getObjects($objectIDs);
+ $viewableMedia = ViewableMediaRuntimeCache::getInstance()->getObjects($objectIDs);
+ $contentLanguageID = MessageEmbeddedObjectManager::getInstance()->getContentLanguageID();
+ if ($contentLanguageID !== null) {
+ $mediaIDs = [];
+ foreach ($viewableMedia as $media) {
+ if ($media->localizedLanguageID != $contentLanguageID) {
+ $mediaIDs[] = $media->getDecoratedObject()->mediaID;
+ }
+ }
+
+ if (!empty($mediaIDs)) {
+ $conditions = new PreparedStatementConditionBuilder();
+ $conditions->add("mediaID IN (?)", [$mediaIDs]);
+ $conditions->add("languageID = ?", [$contentLanguageID]);
+
+ $sql = "SELECT *
+ FROM wcf".WCF_N."_media_content
+ ".$conditions;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditions->getParameters());
+ while ($row = $statement->fetchArray()) {
+ $viewableMedia[$row['mediaID']]->setLocalizedContent($row['languageID'], $row);
+ }
+ }
+ }
+
+ return $viewableMedia;
}
/**
*/
protected $activeMessageID;
+ /**
+ * language id of the active message
+ * @var integer
+ */
+ protected $activeMessageLanguageID;
+
/**
* list of embedded object handlers
* @var array
*/
protected $embeddedObjectHandlers;
+ /**
+ * content language id
+ * @var integer
+ */
+ protected $contentLanguageID;
+
/**
* Registers the embedded objects found in given message.
*
*
* @param string $messageObjectType
* @param integer[] $messageIDs
+ * @param integer $contentLanguageID
* @throws InvalidObjectTypeException
*/
- public function loadObjects($messageObjectType, array $messageIDs) {
+ public function loadObjects($messageObjectType, array $messageIDs, $contentLanguageID = null) {
$messageObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType);
if ($messageObjectTypeID === null) {
throw new InvalidObjectTypeException($messageObjectType, 'com.woltlab.wcf.message');
$this->messageEmbeddedObjects[$row['messageObjectTypeID']][$row['messageID']][$row['embeddedObjectTypeID']][] = $row['embeddedObjectID'];
}
+ $this->contentLanguageID = $contentLanguageID;
+
// load objects
foreach ($embeddedObjects as $embeddedObjectTypeID => $objectIDs) {
if (!isset($this->embeddedObjects[$embeddedObjectTypeID])) $this->embeddedObjects[$embeddedObjectTypeID] = [];
$this->embeddedObjects[$embeddedObjectTypeID][$objectID] = $object;
}
}
+
+ $this->contentLanguageID = null;
+ }
+
+ /**
+ * Returns the content language id or null.
+ *
+ * @return integer
+ */
+ public function getContentLanguageID() {
+ return $this->contentLanguageID;
}
/**
* @param string $messageObjectType
* @param integer $messageID
*/
- public function setActiveMessage($messageObjectType, $messageID) {
+ public function setActiveMessage($messageObjectType, $messageID, $languageID = null) {
$this->activeMessageObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType);
$this->activeMessageID = $messageID;
+ $this->activeMessageLanguageID = $languageID;
+ }
+
+ /**
+ * Returns the language id of the active message.
+ *
+ * @return integer
+ */
+ public function getActiveMessageLanguageID() {
+ return $this->activeMessageLanguageID;
}
/**