From: Marcel Werk Date: Mon, 20 Jun 2016 11:50:17 +0000 (+0200) Subject: Improved amp implementation X-Git-Tag: 3.0.0_Beta_1~1390 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9f8005850bdc0ffa22b9e66890ddaeb77833eecf;p=GitHub%2FWoltLab%2FWCF.git Improved amp implementation --- diff --git a/com.woltlab.wcf/templates/ampArticle.tpl b/com.woltlab.wcf/templates/ampArticle.tpl index 87f49b04f6..396506e337 100644 --- a/com.woltlab.wcf/templates/ampArticle.tpl +++ b/com.woltlab.wcf/templates/ampArticle.tpl @@ -64,5 +64,49 @@ {@$articleContent->getFormattedContent()} - + +{hascontent} +
+

{lang}wcf.article.moreArticles{/lang}

+ + + {content} + {foreach from=$additionalArticles item='additionalArticle'} + {if $additionalArticle->getImage()} + +
+ +
{$additionalArticle->getTitle()}
+
+
+ {/if} + {/foreach} + {/content} +
+
+{/hascontent} + +{if $relatedArticles|count} + {hascontent} +
+

{lang}wcf.article.relatedArticles{/lang}

+ + + {content} + {foreach from=$relatedArticles item='relatedArticle'} + {if $relatedArticle->getImage()} + +
+ +
{$relatedArticle->getTitle()}
+
+
+ {/if} + {/foreach} + {/content} +
+
+ {/hascontent} +{/if} + {include file='ampFooter'} diff --git a/com.woltlab.wcf/templates/ampHeader.tpl b/com.woltlab.wcf/templates/ampHeader.tpl index 9aa993198a..6f68c6dbc6 100644 --- a/com.woltlab.wcf/templates/ampHeader.tpl +++ b/com.woltlab.wcf/templates/ampHeader.tpl @@ -84,6 +84,17 @@ padding: 30px 10px; } + .section { + margin-top: 30px; + } + + .sectionTitle { + font-weight: 300; + font-size: 23px; + line-height: 1.05; + margin: 0; + } + .article .articleTitle { font-weight: 300; font-size: 23px; @@ -109,6 +120,17 @@ color: rgb(125, 130, 135); } + .article .articleImage { + margin: 0; + } + + .article .articleImage figcaption { + color: rgb(125, 130, 135); + font-size: smaller; + margin-top: 5px; + text-align: center; + } + .article .articleImage, .article .articleContent, .article .articleTeaser { @@ -166,6 +188,20 @@ padding: 7px 7px 7px 0; } + amp-carousel { + margin-top: 20px; + } + + amp-carousel figcaption { + background-color: rgba(0,0,0,.6); + bottom: 0; + color: #fff; + left: 0; + padding: 10px; + position: absolute; + right: 0; + } + .breadcrumbs li:nth-child(2) { padding-left: 20px; } @@ -177,6 +213,7 @@ } {literal}{/literal} + diff --git a/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php new file mode 100644 index 0000000000..4f40f476ac --- /dev/null +++ b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php @@ -0,0 +1,178 @@ + + * @package WoltLabSuite\Core\Page + * @since 3.0 + */ +abstract class AbstractArticlePage extends AbstractPage { + /** + * @inheritDoc + */ + public $neededModules = ['MODULE_ARTICLE']; + + /** + * article content id + * @var integer + */ + public $articleContentID = 0; + + /** + * article content object + * @var ViewableArticleContent + */ + public $articleContent; + + /** + * article object + * @var ViewableArticle + */ + public $article; + + /** + * list of tags + * @var Tag[] + */ + public $tags = []; + + /** + * category object + * @var ArticleCategory + */ + public $category; + + /** + * list of related articles + * @var AccessibleArticleList + */ + public $relatedArticles; + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->articleContentID = intval($_REQUEST['id']); + $this->articleContent = ViewableArticleContent::getArticleContent($this->articleContentID); + if ($this->articleContent === null) { + throw new IllegalLinkException(); + } + $this->article = ViewableArticle::getArticle($this->articleContent->articleID); + $this->category = $this->article->getCategory(); + } + + /** + * @inheritDoc + */ + public function checkPermissions() { + parent::checkPermissions(); + + if (!$this->article->canRead()) { + throw new PermissionDeniedException(); + } + } + + /** + * @inheritDoc + */ + public function readData() { + parent::readData(); + + // update view count + $articleEditor = new ArticleEditor($this->article->getDecoratedObject()); + $articleEditor->updateCounters([ + 'views' => 1 + ]); + + // get tags + if (MODULE_TAGGING && WCF::getSession()->getPermission('user.tag.canViewTag')) { + $this->tags = TagEngine::getInstance()->getObjectTags( + 'com.woltlab.wcf.article', + $this->articleContent->articleContentID, + [($this->articleContent->languageID ?: LanguageFactory::getInstance()->getDefaultLanguageID())] + ); + } + + // get related articles + if (MODULE_TAGGING && ARTICLE_RELATED_ARTICLES) { + if (!empty($this->tags)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('objectTypeID = ?', [TagEngine::getInstance()->getObjectTypeID('com.woltlab.wcf.article')]); + $conditionBuilder->add('tagID IN (?)', [array_keys($this->tags)]); + $conditionBuilder->add('objectID <> ?', [$this->articleContentID]); + $sql = "SELECT objectID, COUNT(*) AS count + FROM wcf" . WCF_N . "_tag_to_object + " . $conditionBuilder . " + GROUP BY objectID + HAVING COUNT(*) > " . (round(count($this->tags) * (ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD / 100))) . " + ORDER BY count DESC"; + $statement = WCF::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES); + $statement->execute($conditionBuilder->getParameters()); + $articleContentIDs = []; + while ($row = $statement->fetchArray()) { + $articleContentIDs[] = $row['objectID']; + } + + if (!empty($articleContentIDs)) { + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('articleContentID IN (?)', [$articleContentIDs]); + $sql = "SELECT articleID + FROM wcf" . WCF_N . "_article_content + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $articleIDs = []; + while ($row = $statement->fetchArray()) { + $articleIDs[] = $row['articleID']; + } + + $this->relatedArticles = new AccessibleArticleList(); + $this->relatedArticles->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]); + $this->relatedArticles->sqlOrderBy = 'article.time'; + $this->relatedArticles->readObjects(); + } + } + } + + // set location + PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article->categoryID, $this->article->getCategory()); + foreach ($this->article->getCategory()->getParentCategories() as $parentCategory) { + PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID, $parentCategory); + } + PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.ArticleList'); + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'articleContentID' => $this->articleContentID, + 'articleContent' => $this->articleContent, + 'article' => $this->article, + 'category' => $this->category, + 'relatedArticles' => $this->relatedArticles, + 'tags' => $this->tags + ]); + } +} diff --git a/wcfsetup/install/files/lib/page/ArticleAmpPage.class.php b/wcfsetup/install/files/lib/page/ArticleAmpPage.class.php index b318184067..c3aac9334f 100644 --- a/wcfsetup/install/files/lib/page/ArticleAmpPage.class.php +++ b/wcfsetup/install/files/lib/page/ArticleAmpPage.class.php @@ -1,11 +1,8 @@ articleContentID = intval($_REQUEST['id']); - $this->articleContent = ViewableArticleContent::getArticleContent($this->articleContentID); - if ($this->articleContent === null) { - throw new IllegalLinkException(); - } - $this->article = ViewableArticle::getArticle($this->articleContent->articleID); - } - - /** - * @inheritDoc - */ - public function checkPermissions() { - parent::checkPermissions(); - - if (!$this->article->canRead()) { - throw new PermissionDeniedException(); - } + $this->canonicalURL = LinkHandler::getInstance()->getLink('ArticleAmp', ['object' => $this->articleContent]); } /** @@ -77,18 +41,18 @@ class ArticleAmpPage extends AbstractPage { public function readData() { parent::readData(); - // update view count - $articleEditor = new ArticleEditor($this->article->getDecoratedObject()); - $articleEditor->updateCounters([ - 'views' => 1 - ]); - - // set location - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article->categoryID, $this->article->getCategory()); - foreach ($this->article->getCategory()->getParentCategories() as $parentCategory) { - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID, $parentCategory); - } - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.ArticleList'); + // get next/previous articles + $nextArticleList = new CategoryArticleList($this->article->categoryID); + $nextArticleList->getConditionBuilder()->add('article.time > ?', [$this->article->time]); + $nextArticleList->sqlOrderBy = 'article.time'; + $nextArticleList->sqlLimit = 3; + $nextArticleList->readObjects(); + $previousArticleList = new CategoryArticleList($this->article->categoryID); + $previousArticleList->getConditionBuilder()->add('article.time < ?', [$this->article->time]); + $previousArticleList->sqlOrderBy = 'article.time DESC'; + $previousArticleList->sqlLimit = 3; + $previousArticleList->readObjects(); + $this->additionalArticles = array_merge($nextArticleList->getObjects(), $previousArticleList->getObjects()); } /** @@ -98,11 +62,8 @@ class ArticleAmpPage extends AbstractPage { parent::assignVariables(); WCF::getTPL()->assign([ - 'articleContentID' => $this->articleContentID, - 'articleContent' => $this->articleContent, - 'article' => $this->article, - 'category' => $this->article->getCategory(), - 'regularCanonicalURL' => $this->articleContent->getLink() + 'regularCanonicalURL' => $this->articleContent->getLink(), + 'additionalArticles' => $this->additionalArticles ]); } } diff --git a/wcfsetup/install/files/lib/page/ArticlePage.class.php b/wcfsetup/install/files/lib/page/ArticlePage.class.php index 414f34f05c..9ff432749b 100644 --- a/wcfsetup/install/files/lib/page/ArticlePage.class.php +++ b/wcfsetup/install/files/lib/page/ArticlePage.class.php @@ -1,24 +1,13 @@ articleContentID = intval($_REQUEST['id']); - $this->articleContent = ViewableArticleContent::getArticleContent($this->articleContentID); - if ($this->articleContent === null) { - throw new IllegalLinkException(); - } - $this->article = ViewableArticle::getArticle($this->articleContent->articleID); $this->canonicalURL = $this->articleContent->getLink(); - $this->category = $this->article->getCategory(); - } - - /** - * @inheritDoc - */ - public function checkPermissions() { - parent::checkPermissions(); - - if (!$this->article->canRead()) { - throw new PermissionDeniedException(); - } } /** @@ -142,12 +72,6 @@ class ArticlePage extends AbstractPage { public function readData() { parent::readData(); - // update view count - $articleEditor = new ArticleEditor($this->article->getDecoratedObject()); - $articleEditor->updateCounters([ - 'views' => 1 - ]); - // get comments if ($this->article->enableComments) { $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment'); @@ -155,7 +79,7 @@ class ArticlePage extends AbstractPage { $this->commentList = CommentHandler::getInstance()->getCommentList($this->commentManager, $this->commentObjectTypeID, $this->articleContent->articleContentID); } - // get next entry + // get next article $articleList = new CategoryArticleList($this->article->categoryID); $articleList->getConditionBuilder()->add('article.time > ?', [$this->article->time]); $articleList->sqlOrderBy = 'article.time'; @@ -163,64 +87,14 @@ class ArticlePage extends AbstractPage { $articleList->readObjects(); foreach ($articleList as $article) $this->nextArticle = $article; - // get previous entry + // get previous article $articleList = new CategoryArticleList($this->article->categoryID); $articleList->getConditionBuilder()->add('article.time < ?', [$this->article->time]); - $articleList->sqlOrderBy = 'article.time'; + $articleList->sqlOrderBy = 'article.time DESC'; $articleList->sqlLimit = 1; $articleList->readObjects(); foreach ($articleList as $article) $this->previousArticle = $article; - // get tags - if (MODULE_TAGGING && WCF::getSession()->getPermission('user.tag.canViewTag')) { - $this->tags = TagEngine::getInstance()->getObjectTags( - 'com.woltlab.wcf.article', - $this->articleContent->articleContentID, - [($this->articleContent->languageID ?: LanguageFactory::getInstance()->getDefaultLanguageID())] - ); - } - - // get related articles - if (MODULE_TAGGING && ARTICLE_RELATED_ARTICLES) { - if (!empty($this->tags)) { - $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add('objectTypeID = ?', [TagEngine::getInstance()->getObjectTypeID('com.woltlab.wcf.article')]); - $conditionBuilder->add('tagID IN (?)', [array_keys($this->tags)]); - $conditionBuilder->add('objectID <> ?', [$this->articleContentID]); - $sql = "SELECT objectID, COUNT(*) AS count - FROM wcf" . WCF_N . "_tag_to_object - " . $conditionBuilder . " - GROUP BY objectID - HAVING COUNT(*) > " . (round(count($this->tags) * (ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD / 100))) . " - ORDER BY count DESC"; - $statement = WCF::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES); - $statement->execute($conditionBuilder->getParameters()); - $articleContentIDs = []; - while ($row = $statement->fetchArray()) { - $articleContentIDs[] = $row['objectID']; - } - - if (!empty($articleContentIDs)) { - $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add('articleContentID IN (?)', [$articleContentIDs]); - $sql = "SELECT articleID - FROM wcf" . WCF_N . "_article_content - " . $conditionBuilder; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditionBuilder->getParameters()); - $articleIDs = []; - while ($row = $statement->fetchArray()) { - $articleIDs[] = $row['articleID']; - } - - $this->relatedArticles = new AccessibleArticleList(); - $this->relatedArticles->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]); - $this->relatedArticles->sqlOrderBy = 'article.time'; - $this->relatedArticles->readObjects(); - } - } - } - // fetch likes if (MODULE_LIKE) { $objectType = LikeHandler::getInstance()->getObjectType('com.woltlab.wcf.likeableArticle'); @@ -228,13 +102,6 @@ class ArticlePage extends AbstractPage { $this->articleLikeData = LikeHandler::getInstance()->getLikeObjects($objectType); } - // set location - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $this->article->categoryID, $this->article->getCategory()); - foreach ($this->article->getCategory()->getParentCategories() as $parentCategory) { - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.CategoryArticleList', $parentCategory->categoryID, $parentCategory); - } - PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.ArticleList'); - // add meta/og tags MetaTagHandler::getInstance()->addTag('og:title', 'og:title', $this->articleContent->getTitle() . ' - ' . WCF::getLanguage()->get(PAGE_TITLE), true); MetaTagHandler::getInstance()->addTag('og:url', 'og:url', LinkHandler::getInstance()->getLink('Article', ['object' => $this->articleContent, 'appendSession' => false]), true); @@ -265,10 +132,6 @@ class ArticlePage extends AbstractPage { parent::assignVariables(); WCF::getTPL()->assign([ - 'articleContentID' => $this->articleContentID, - 'articleContent' => $this->articleContent, - 'article' => $this->article, - 'category' => $this->article->getCategory(), 'previousArticle' => $this->previousArticle, 'nextArticle' => $this->nextArticle, 'commentCanAdd' => WCF::getSession()->getPermission('user.article.canAddComment'), @@ -276,8 +139,6 @@ class ArticlePage extends AbstractPage { 'commentObjectTypeID' => $this->commentObjectTypeID, 'lastCommentTime' => ($this->commentList ? $this->commentList->getMinCommentTime() : 0), 'likeData' => ((MODULE_LIKE && $this->commentList) ? $this->commentList->getLikeData() : []), - 'relatedArticles' => $this->relatedArticles, - 'tags' => $this->tags, 'articleLikeData' => $this->articleLikeData ]); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7b696fc559..c805561669 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1737,6 +1737,7 @@ Sie können jetzt den vollen Funktionsumfang der Seite nutzen.]]> + comments} Kommentar{if $article->comments != 1}e{/if}]]> views} mal gelesen]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 63472ec81a..db8a1cb096 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1744,6 +1744,7 @@ You can now fully access the website.]]> + comments} Comment{if $article->comments != 1}s{/if}]]> views} View{if $article->views != 1}s{/if}]]>