From: Marcel Werk Date: Fri, 24 Jun 2016 17:12:19 +0000 (+0200) Subject: Added support for enclosure tags in rss feeds X-Git-Tag: 3.0.0_Beta_1~1356^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9cc0c52aae718708a580d4faa20dce6574c3942a;p=GitHub%2FWoltLab%2FWCF.git Added support for enclosure tags in rss feeds --- diff --git a/com.woltlab.wcf/templates/rssFeed.tpl b/com.woltlab.wcf/templates/rssFeed.tpl index 93e8549d51..46a7817acf 100644 --- a/com.woltlab.wcf/templates/rssFeed.tpl +++ b/com.woltlab.wcf/templates/rssFeed.tpl @@ -29,6 +29,7 @@ {/foreach} {hascontent}getFormattedMessage()|escapeCDATA}{/content}]]>{/hascontent} + {if $supportsEnclosure && $item->getEnclosure()}{/if} getComments()|escapeCDATA}]]>{* *}{event name='itemFields'} diff --git a/wcfsetup/install/files/lib/data/IFeedEntryWithEnclosure.class.php b/wcfsetup/install/files/lib/data/IFeedEntryWithEnclosure.class.php new file mode 100644 index 0000000000..d9cccf9801 --- /dev/null +++ b/wcfsetup/install/files/lib/data/IFeedEntryWithEnclosure.class.php @@ -0,0 +1,20 @@ + + * @package WoltLabSuite\Core\Data + */ +interface IFeedEntryWithEnclosure extends IFeedEntry { + /** + * Returns the enclosure object + * + * @return FeedEnclosure|null + */ + public function getEnclosure(); +} diff --git a/wcfsetup/install/files/lib/data/article/FeedArticle.class.php b/wcfsetup/install/files/lib/data/article/FeedArticle.class.php index 4fef3890a1..09d748215c 100644 --- a/wcfsetup/install/files/lib/data/article/FeedArticle.class.php +++ b/wcfsetup/install/files/lib/data/article/FeedArticle.class.php @@ -1,8 +1,8 @@ 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; + } } diff --git a/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php b/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php index 81d6a67ac5..ae5cc0ad06 100644 --- a/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractFeedPage.class.php @@ -54,7 +54,8 @@ abstract class AbstractFeedPage extends AbstractAuthedPage { WCF::getTPL()->assign([ 'items' => $this->items, - 'title' => $this->title + 'title' => $this->title, + 'supportsEnclosure' => false ]); } diff --git a/wcfsetup/install/files/lib/page/ArticleFeedPage.class.php b/wcfsetup/install/files/lib/page/ArticleFeedPage.class.php index 390ee7519e..714e93ca72 100644 --- a/wcfsetup/install/files/lib/page/ArticleFeedPage.class.php +++ b/wcfsetup/install/files/lib/page/ArticleFeedPage.class.php @@ -65,4 +65,15 @@ class ArticleFeedPage extends AbstractFeedPage { $this->title = WCF::getLanguage()->get('wcf.article.articles'); } } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'supportsEnclosure' => true + ]); + } } diff --git a/wcfsetup/install/files/lib/system/feed/enclosure/FeedEnclosure.class.php b/wcfsetup/install/files/lib/system/feed/enclosure/FeedEnclosure.class.php new file mode 100644 index 0000000000..1163af35bb --- /dev/null +++ b/wcfsetup/install/files/lib/system/feed/enclosure/FeedEnclosure.class.php @@ -0,0 +1,70 @@ + + * @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; + } +}