<category><![CDATA[{@$category|escapeCDATA}]]></category>
{/foreach}
{hascontent}<content:encoded><![CDATA[{content}{@$item->getFormattedMessage()|escapeCDATA}{/content}]]></content:encoded>{/hascontent}
+ {if $supportsEnclosure && $item->getEnclosure()}<enclosure length="{@$item->getEnclosure()->getLength()}" type="{$item->getEnclosure()->getType()}" url="{$item->getEnclosure()->getURL()}" />{/if}
<slash:comments><![CDATA[{@$item->getComments()|escapeCDATA}]]></slash:comments>{*
*}{event name='itemFields'}
</item>
--- /dev/null
+<?php
+namespace wcf\data;
+use wcf\system\feed\enclosure\FeedEnclosure;
+
+/**
+ * Every feed entry that supports enclosure tags should implement this interface.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data
+ */
+interface IFeedEntryWithEnclosure extends IFeedEntry {
+ /**
+ * Returns the enclosure object
+ *
+ * @return FeedEnclosure|null
+ */
+ public function getEnclosure();
+}
<?php
namespace wcf\data\article;
-use wcf\data\IFeedEntry;
+use wcf\data\IFeedEntryWithEnclosure;
use wcf\data\TUserContent;
-use wcf\system\request\LinkHandler;
+use wcf\system\feed\enclosure\FeedEnclosure;
use wcf\util\StringUtil;
/**
* @package WoltLabSuite\Core\Data\Article
* @since 3.0
*/
-class FeedArticle extends ViewableArticle implements IFeedEntry {
+class FeedArticle extends ViewableArticle implements IFeedEntryWithEnclosure {
use TUserContent;
+ /**
+ * @var FeedEnclosure
+ */
+ protected $enclosure;
+
/** @noinspection PhpMissingParentCallCommonInspection */
/**
* @inheritDoc
public function isVisible() {
return $this->canRead();
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getEnclosure() {
+ if ($this->enclosure === null) {
+ if ($this->getImage() !== null) {
+ $this->enclosure = new FeedEnclosure($this->getImage()->getThumbnailLink('small'), $this->getImage()->smallThumbnailType, $this->getImage()->smallThumbnailSize);
+ }
+ }
+
+ return $this->enclosure;
+ }
}
WCF::getTPL()->assign([
'items' => $this->items,
- 'title' => $this->title
+ 'title' => $this->title,
+ 'supportsEnclosure' => false
]);
}
$this->title = WCF::getLanguage()->get('wcf.article.articles');
}
}
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'supportsEnclosure' => true
+ ]);
+ }
}
--- /dev/null
+<?php
+namespace wcf\system\feed\enclosure;
+
+/**
+ * Represents an enclosure in a rss feed.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Feed\Enclosure
+ */
+class FeedEnclosure {
+ /**
+ * url to the enclosure
+ * @var string
+ */
+ protected $url = '';
+
+ /**
+ * enclosure's MIME type
+ * @var string
+ */
+ protected $type = '';
+
+ /**
+ * size of the enclosure in bytes
+ * @var integer
+ */
+ protected $length = 0;
+
+ /**
+ * Creates a new FeedEnclosure object.
+ *
+ * @param string $url url to the enclosure
+ * @param string $type enclosure's MIME type
+ * @param integer $length size of the enclosure in bytes
+ */
+ public function __construct($url, $type, $length) {
+ $this->url = $url;
+ $this->type = $type;
+ $this->length = $length;
+ }
+
+ /**
+ * Returns the url to the enclosure.
+ *
+ * @return string
+ */
+ public function getURL() {
+ return $this->url;
+ }
+
+ /**
+ * Returns the enclosure's MIME type.
+ *
+ * @return string
+ */
+ public function getType() {
+ return $this->type;
+ }
+
+ /**
+ * Returns the size of the enclosure in bytes.
+ *
+ * @return integer
+ */
+ public function getLength() {
+ return $this->length;
+ }
+}