Overhauled article teasers
authorMarcel Werk <burntime@woltlab.com>
Thu, 16 Jun 2016 16:41:12 +0000 (18:41 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 16 Jun 2016 16:41:12 +0000 (18:41 +0200)
com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/templates/articleListItems.tpl
wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php
wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php
wcfsetup/install/files/lib/data/article/Article.class.php
wcfsetup/install/files/lib/data/article/ArticleAction.class.php
wcfsetup/install/files/lib/data/article/ViewableArticle.class.php
wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php
wcfsetup/install/files/lib/system/user/activity/event/LikeableArticleUserActivityEvent.class.php

index 204ffbdbc61bddb15bdcba7ef5dca94e2d474b54..1b3b1cf899ab18be4693b03557cad24ff34ac77d 100644 (file)
@@ -96,7 +96,7 @@
 >
        <div class="htmlContent">
                {if $articleContent->teaser}
-                       <p class="articleTeaser">{$articleContent->teaser}</p>
+                       <p class="articleTeaser">{@$articleContent->getFormattedTeaser()}</p>
                {/if}
        
                {@$articleContent->getFormattedContent()}
                                                                        </li>
                                                                        
                                                                        {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike')}
-                                                                               <li>
+                                                                               <li class="wcfLikeCounter{if $relatedArticle->cumulativeLikes > 0} likeCounterLiked{elseif $relatedArticle->cumulativeLikes < 0}likeCounterDisliked{/if}">
                                                                                        {if $relatedArticle->likes || $relatedArticle->dislikes}
-                                                                                               <span class="icon icon16 fa-thumbs-o-{if $relatedArticle->cumulativeLikes < 0}down{else}up{/if} jsTooltip" title="{lang likes=$relatedArticle->likes dislikes=$relatedArticle->dislikes}wcf.like.tooltip{/lang}"></span>
-                                                                                               {if $relatedArticle->cumulativeLikes > 0}+{elseif $relatedArticle->cumulativeLikes == 0}&plusmn;{/if}{#$relatedArticle->cumulativeLikes}
+                                                                                               <span class="icon icon16 fa-thumbs-o-{if $relatedArticle->cumulativeLikes < 0}down{else}up{/if} jsTooltip" title="{lang likes=$relatedArticle->likes dislikes=$relatedArticle->dislikes}wcf.like.tooltip{/lang}"></span>{if $relatedArticle->cumulativeLikes > 0}+{elseif $relatedArticle->cumulativeLikes == 0}&plusmn;{/if}{#$relatedArticle->cumulativeLikes}
                                                                                        {/if}
                                                                                </li>
                                                                        {/if}
                                                        </div>
                                                        
                                                        <div class="containerContent articleListTeaser">
-                                                               {$relatedArticle->getTeaser()}
+                                                               {@$relatedArticle->getFormattedTeaser()}
                                                        </div>
                                                </div>
                                                
index 1935b63afdcb6c4ee86c2ef51e81e5819f2857b9..e8d4ee5e50a3389929ceb3538a447707df1d33d9 100644 (file)
@@ -3,9 +3,9 @@
                <li>
                        <a href="{$article->getLink()}">
                                {if $article->getImage()}
-                               <div class="box128">
-                                       <div class="articleListImage">{@$article->getImage()->getThumbnailTag('tiny')}</div>
-                                       {/if}
+                                       <div class="box128">
+                                               <div class="articleListImage">{@$article->getImage()->getThumbnailTag('tiny')}</div>
+                               {/if}
                                        
                                        <div>
                                                <div class="containerHeadline">
                                                </div>
                                                
                                                <div class="containerContent articleListTeaser">
-                                                       {$article->getTeaser()}
+                                                       {@$article->getFormattedTeaser()}
                                                </div>
                                        </div>
                                        
-                                       {if $article->getImage()}
-                               </div>
+                               {if $article->getImage()}
+                                       </div>
                                {/if}
                        </a>
                </li>
index e4bf31111cb1546fdc14932f9cf1f98b85ce6355..ad437df0f7261330a639fb824b397ad5fdf2250f 100644 (file)
@@ -274,10 +274,6 @@ class ArticleAddForm extends AbstractForm {
                                if (empty($this->title[$language->languageID])) {
                                        throw new UserInputException('title'.$language->languageID);
                                }
-                               // teaser
-                               if (empty($this->teaser[$language->languageID])) {
-                                       throw new UserInputException('teaser'.$language->languageID);
-                               }
                                // content
                                if (empty($this->content[$language->languageID])) {
                                        throw new UserInputException('content'.$language->languageID);
@@ -289,10 +285,6 @@ class ArticleAddForm extends AbstractForm {
                        if (empty($this->title[0])) {
                                throw new UserInputException('title');
                        }
-                       // teaser
-                       if (empty($this->teaser[0])) {
-                               throw new UserInputException('teaser');
-                       }
                        // content
                        if (empty($this->content[0])) {
                                throw new UserInputException('content');
index 316afa4b349638479ced1dced20a65de5960024d..c89afc91d4b8a3430e21da196c2fa8d9fdaf5849 100644 (file)
@@ -110,7 +110,7 @@ class ArticleEditForm extends ArticleAddForm {
         */
        public function readData() {
                if (!empty($_POST) && !WCF::getSession()->getPermission('admin.content.cms.canUseMedia')) {
-                       foreach ($this->article->getArticleContent() as $languageID => $content) {
+                       foreach ($this->article->getArticleContents() as $languageID => $content) {
                                $this->imageID[$languageID] = $content['imageID'];
                        }
                        
@@ -133,7 +133,7 @@ class ArticleEditForm extends ArticleAddForm {
                                $this->publicationDate = $dateTime->format('c');
                        }
                        
-                       foreach ($this->article->getArticleContent() as $languageID => $content) {
+                       foreach ($this->article->getArticleContents() as $languageID => $content) {
                                $this->title[$languageID] = $content->title;
                                $this->teaser[$languageID] = $content->teaser;
                                $this->content[$languageID] = $content->content;
index 224fad68d1b4672948ab0c3d7ea41e7bd2eb820e..2402bc291a471238ea7719fc6aaad49b87419b87 100644 (file)
@@ -59,7 +59,7 @@ class Article extends DatabaseObject implements ILinkableObject {
         * article content grouped by language id
         * @var ArticleContent[]
         */
-       public $articleContent;
+       public $articleContents;
        
        /**
         * language links
@@ -103,16 +103,8 @@ class Article extends DatabaseObject implements ILinkableObject {
         * @inheritDoc
         */
        public function getLink() {
-               $this->getArticleContent();
-               if ($this->isMultilingual) {
-                       if (isset($this->articleContent[WCF::getLanguage()->languageID])) {
-                               return $this->articleContent[WCF::getLanguage()->languageID]->getLink();
-                       }
-               }
-               else {
-                       if (isset($this->articleContent[0])) {
-                               return $this->articleContent[0]->getLink();
-                       }
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getLink();
                }
                
                return '';
@@ -121,40 +113,37 @@ class Article extends DatabaseObject implements ILinkableObject {
        /**
         * Returns the article's title.
         *
-        * @return string
+        * @return      string
         */
        public function getTitle() {
-               $this->getArticleContent();
-               if ($this->isMultilingual) {
-                       if (isset($this->articleContent[WCF::getLanguage()->languageID])) {
-                               return $this->articleContent[WCF::getLanguage()->languageID]->getTitle();
-                       }
-               }
-               else {
-                       if (isset($this->articleContent[0])) {
-                               return $this->articleContent[0]->getTitle();
-                       }
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getTitle();
                }
                
                return '';
        }
        
        /**
-        * Returns the article's teaser.
+        * Returns the article's unformatted teaser.
         *
-        * @return string
+        * @return      string
         */
        public function getTeaser() {
-               $this->getArticleContent();
-               if ($this->isMultilingual) {
-                       if (isset($this->articleContent[WCF::getLanguage()->languageID])) {
-                               return $this->articleContent[WCF::getLanguage()->languageID]->teaser;
-                       }
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getTeaser();
                }
-               else {
-                       if (isset($this->articleContent[0])) {
-                               return $this->articleContent[0]->teaser;
-                       }
+               
+               return '';
+       }
+       
+       /**
+        * Returns the article's formatted teaser.
+        *
+        * @return      string
+        */
+       public function getFormattedTeaser() {
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getFormattedTeaser();
                }
                
                return '';
@@ -163,39 +152,32 @@ class Article extends DatabaseObject implements ILinkableObject {
        /**
         * Returns the article's formatted content.
         *
-        * @return string
+        * @return      string
         */
        public function getFormattedContent() {
-               $this->getArticleContent();
-               if ($this->isMultilingual) {
-                       if (isset($this->articleContent[WCF::getLanguage()->languageID])) {
-                               return $this->articleContent[WCF::getLanguage()->languageID]->getFormattedContent();
-                       }
-               }
-               else {
-                       if (isset($this->articleContent[0])) {
-                               return $this->articleContent[0]->getFormattedContent();
-                       }
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getFormattedContent();
                }
                
                return '';
        }
        
        /**
-        * Returns the article's image.
+        * Returns the active content version.
         *
-        * @return ViewableMedia
+        * @return      ArticleContent|null
         */
-       public function getImage() {
-               $this->getArticleContent();
+       public function getArticleContent() {
+               $this->getArticleContents();
+               
                if ($this->isMultilingual) {
-                       if (isset($this->articleContent[WCF::getLanguage()->languageID])) {
-                               return $this->articleContent[WCF::getLanguage()->languageID]->getImage();
+                       if (isset($this->articleContents[WCF::getLanguage()->languageID])) {
+                               return $this->articleContents[WCF::getLanguage()->languageID];
                        }
                }
                else {
-                       if (!empty($this->articleContent[0])) {
-                               return $this->articleContent[0]->getImage();
+                       if (!empty($this->articleContents[0])) {
+                               return $this->articleContents[0];
                        }
                }
                
@@ -207,9 +189,9 @@ class Article extends DatabaseObject implements ILinkableObject {
         *
         * @return      ArticleContent[]
         */
-       public function getArticleContent() {
-               if ($this->articleContent === null) {
-                       $this->articleContent = [];
+       public function getArticleContents() {
+               if ($this->articleContents === null) {
+                       $this->articleContents = [];
                        
                        $sql = "SELECT  *
                                FROM    wcf" . WCF_N . "_article_content
@@ -217,11 +199,11 @@ class Article extends DatabaseObject implements ILinkableObject {
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute([$this->articleID]);
                        while ($row = $statement->fetchArray()) {
-                               $this->articleContent[($row['languageID'] ?: 0)] = new ArticleContent(null, $row);
+                               $this->articleContents[($row['languageID'] ?: 0)] = new ArticleContent(null, $row);
                        }
                }
                
-               return $this->articleContent;
+               return $this->articleContents;
        }
        
        /**
index fa0d88b25c30c44bcdba625b55a06fc5968f4594..c40ac0f3056718f7b19f4ab7d7f42af179520281 100644 (file)
@@ -138,7 +138,7 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                $articleIDs = $articleContentIDs = [];
                foreach ($this->getObjects() as $article) {
                        $articleIDs[] = $article->articleID;
-                       foreach ($article->getArticleContent() as $articleContent) {
+                       foreach ($article->getArticleContents() as $articleContent) {
                                $articleContentIDs[] = $articleContent->articleContentID;
                        }
                }
index cf5ecd486815482b73e24d38d565ddf77fe5dae6..78fe7714f8d54671f21fcde7543db3ea5027c2e3 100644 (file)
@@ -71,10 +71,23 @@ class ViewableArticle extends DatabaseObjectDecorator {
         * @param       ViewableArticleContent  $articleContent
         */
        public function setArticleContent(ViewableArticleContent $articleContent) {
-               if ($this->getDecoratedObject()->articleContent === null) {
-                       $this->getDecoratedObject()->articleContent = [];
+               if ($this->getDecoratedObject()->articleContents === null) {
+                       $this->getDecoratedObject()->articleContents = [];
                }
                
-               $this->getDecoratedObject()->articleContent[($articleContent->languageID ?: 0)] = $articleContent;
+               $this->getDecoratedObject()->articleContents[($articleContent->languageID ?: 0)] = $articleContent;
+       }
+       
+       /**
+        * Returns the article's image.
+        *
+        * @return      ViewableMedia|null
+        */
+       public function getImage() {
+               if ($this->getArticleContent() !== null) {
+                       return $this->getArticleContent()->getImage();
+               }
+               
+               return null;
        }
 }
index e886cd73a785e71980a329a44692058c8ffcb3c8..fa6408e17df814bdd857588fd7380622fac1980f 100644 (file)
@@ -10,6 +10,8 @@ use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\request\IRouteController;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
+use wcf\util\MessageUtil;
+use wcf\util\StringUtil;
 
 /**
  * Represents an article content.
@@ -62,10 +64,33 @@ class ArticleContent extends DatabaseObject implements ILinkableObject, IRouteCo
                return $this->title;
        }
        
+       /**
+        * Returns the article's unformatted content.
+        *
+        * @return      string
+        */
+       public function getTeaser() {
+               return $this->teaser;
+       }
+       
+       /**
+        * Returns the article's formatted content.
+        *
+        * @return      string
+        */
+       public function getFormattedTeaser() {
+               if ($this->teaser) {
+                       return StringUtil::encodeHTML($this->teaser);
+               }
+               else {
+                       return StringUtil::truncateHTML(StringUtil::stripHTML($this->getFormattedContent()));
+               }
+       }
+       
        /**
         * Returns the article's formatted content.
         *
-        * @return string
+        * @return      string
         */
        public function getFormattedContent() {
                // assign embedded objects
index 09ff8f3bf902895c1333b75c2aedcd5844d3a297..1e987d3481d473d189d11636ab39691299fc3473 100644 (file)
@@ -45,7 +45,7 @@ class LikeableArticleUserActivityEvent extends SingletonFactory implements IUser
                                $event->setTitle($text);
                                
                                // output
-                               $event->setDescription($article->getTeaser());
+                               $event->setDescription($article->getFormattedTeaser());
                        }
                        else {
                                $event->setIsOrphaned();