From: Marcel Werk Date: Thu, 16 Jun 2016 16:41:12 +0000 (+0200) Subject: Overhauled article teasers X-Git-Tag: 3.0.0_Beta_1~1413 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0c968ac8adaab9f72281f672f005556f14fd194b;p=GitHub%2FWoltLab%2FWCF.git Overhauled article teasers --- diff --git a/com.woltlab.wcf/templates/article.tpl b/com.woltlab.wcf/templates/article.tpl index 204ffbdbc6..1b3b1cf899 100644 --- a/com.woltlab.wcf/templates/article.tpl +++ b/com.woltlab.wcf/templates/article.tpl @@ -96,7 +96,7 @@ >
{if $articleContent->teaser} - + {/if} {@$articleContent->getFormattedContent()} @@ -245,10 +245,9 @@ {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike')} -
  • +
  • {if $relatedArticle->likes || $relatedArticle->dislikes} - - {if $relatedArticle->cumulativeLikes > 0}+{elseif $relatedArticle->cumulativeLikes == 0}±{/if}{#$relatedArticle->cumulativeLikes} + {if $relatedArticle->cumulativeLikes > 0}+{elseif $relatedArticle->cumulativeLikes == 0}±{/if}{#$relatedArticle->cumulativeLikes} {/if}
  • {/if} @@ -256,7 +255,7 @@
    - {$relatedArticle->getTeaser()} + {@$relatedArticle->getFormattedTeaser()}
    diff --git a/com.woltlab.wcf/templates/articleListItems.tpl b/com.woltlab.wcf/templates/articleListItems.tpl index 1935b63afd..e8d4ee5e50 100644 --- a/com.woltlab.wcf/templates/articleListItems.tpl +++ b/com.woltlab.wcf/templates/articleListItems.tpl @@ -3,9 +3,9 @@
  • {if $article->getImage()} -
    -
    {@$article->getImage()->getThumbnailTag('tiny')}
    - {/if} +
    +
    {@$article->getImage()->getThumbnailTag('tiny')}
    + {/if}
    @@ -32,12 +32,12 @@
    - {$article->getTeaser()} + {@$article->getFormattedTeaser()}
    - {if $article->getImage()} -
    + {if $article->getImage()} +
    {/if}
  • diff --git a/wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php index e4bf31111c..ad437df0f7 100644 --- a/wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php @@ -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'); diff --git a/wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php b/wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php index 316afa4b34..c89afc91d4 100644 --- a/wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/data/article/Article.class.php b/wcfsetup/install/files/lib/data/article/Article.class.php index 224fad68d1..2402bc291a 100644 --- a/wcfsetup/install/files/lib/data/article/Article.class.php +++ b/wcfsetup/install/files/lib/data/article/Article.class.php @@ -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; } /** diff --git a/wcfsetup/install/files/lib/data/article/ArticleAction.class.php b/wcfsetup/install/files/lib/data/article/ArticleAction.class.php index fa0d88b25c..c40ac0f305 100644 --- a/wcfsetup/install/files/lib/data/article/ArticleAction.class.php +++ b/wcfsetup/install/files/lib/data/article/ArticleAction.class.php @@ -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; } } diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php index cf5ecd4868..78fe7714f8 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticle.class.php @@ -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; } } diff --git a/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php b/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php index e886cd73a7..fa6408e17d 100644 --- a/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php +++ b/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/user/activity/event/LikeableArticleUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/LikeableArticleUserActivityEvent.class.php index 09ff8f3bf9..1e987d3481 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/LikeableArticleUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/LikeableArticleUserActivityEvent.class.php @@ -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();