Added box for article categories
authorMarcel Werk <burntime@woltlab.com>
Wed, 15 Jun 2016 13:54:06 +0000 (15:54 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 15 Jun 2016 13:54:14 +0000 (15:54 +0200)
com.woltlab.wcf/box.xml
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/templates/boxArticleCategories.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/data/article/category/ArticleCategoryNode.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/article/category/ArticleCategoryNodeTree.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/page/ArticlePage.class.php
wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php [new file with mode: 0644]
wcfsetup/setup/template/stepConfigureDirectories.tpl

index 0536699c423cefb5f5574da5ad040034dab4b925..0762f43ecfb03f14da34c34e63518929117f9816 100644 (file)
                                <title>Comments</title>
                        </content>
                </box>
+               
+               <box identifier="com.woltlab.wcf.ArticleCategories">
+                       <name language="de">Kategorien (Artikel)</name>
+                       <name language="en">Categories (Articles)</name>
+                       <boxType>system</boxType>
+                       <objectType>com.woltlab.wcf.articleCategories</objectType>
+                       <position>sidebarRight</position>
+                       <showHeader>1</showHeader>
+                       <visibleEverywhere>0</visibleEverywhere>
+                       <visibilityExceptions>
+                               <page>com.woltlab.wcf.ArticleList</page>
+                               <page>com.woltlab.wcf.CategoryArticleList</page>
+                               <page>com.woltlab.wcf.Article</page>
+                       </visibilityExceptions>
+                       
+                       <content language="de">
+                               <title>Kategorien</title>
+                       </content>
+                       <content language="en">
+                               <title>Categories</title>
+                       </content>
+               </box>
        </import>
 </data>
index 15679a9145105e0b07c7882335fe6c5065a705d7..645096dc6ac774fffcadfa9f679fad1402f4ff48 100644 (file)
                        <definitionname>com.woltlab.wcf.boxController</definitionname>
                        <classname>wcf\system\box\PageCommentListBoxController</classname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.articleCategories</name>
+                       <definitionname>com.woltlab.wcf.boxController</definitionname>
+                       <classname>wcf\system\box\ArticleCategoriesBoxController</classname>
+               </type>
                <!-- /box controllers -->
                
                <!-- deprecated -->
diff --git a/com.woltlab.wcf/templates/boxArticleCategories.tpl b/com.woltlab.wcf/templates/boxArticleCategories.tpl
new file mode 100644 (file)
index 0000000..5c06add
--- /dev/null
@@ -0,0 +1,27 @@
+<ol class="boxMenu">
+       {foreach from=$categoryList item=categoryItem}
+               <li{if $activeCategory && $activeCategory->categoryID == $categoryItem->categoryID} class="active"{/if} data-category-id="{@$categoryItem->categoryID}">
+                       <a href="{@$categoryItem->getLink()}" class="boxMenuLink">{$categoryItem->getTitle()}</a>
+                       
+                       {if $activeCategory && ($activeCategory->categoryID == $categoryItem->categoryID || $activeCategory->isParentCategory($categoryItem->getDecoratedObject())) && $categoryItem->hasChildren()}
+                               <ol class="boxMenuDepth1">
+                                       {foreach from=$categoryItem item=subCategoryItem}
+                                               <li{if $activeCategory && $activeCategory->categoryID == $subCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subCategoryItem->categoryID}">
+                                                       <a href="{@$subCategoryItem->getLink()}" class="boxMenuLink">{$subCategoryItem->getTitle()}</a>
+                                                       
+                                                       {if $activeCategory && ($activeCategory->categoryID == $subCategoryItem->categoryID || $activeCategory->parentCategoryID == $subCategoryItem->categoryID) && $subCategoryItem->hasChildren()}
+                                                               <ol class="boxMenuDepth2">
+                                                                       {foreach from=$subCategoryItem item=subSubCategoryItem}
+                                                                               <li{if $activeCategory && $activeCategory->categoryID == $subSubCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subSubCategoryItem->categoryID}">
+                                                                                       <a href="{@$subSubCategoryItem->getLink()}" class="boxMenuLink">{$subSubCategoryItem->getTitle()}</a>
+                                                                               </li>
+                                                                       {/foreach}
+                                                               </ol>
+                                                       {/if}
+                                               </li>
+                                       {/foreach}
+                               </ol>
+                       {/if}
+               </li>
+       {/foreach}
+</ol>
diff --git a/wcfsetup/install/files/lib/data/article/category/ArticleCategoryNode.class.php b/wcfsetup/install/files/lib/data/article/category/ArticleCategoryNode.class.php
new file mode 100644 (file)
index 0000000..b3c1242
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace wcf\data\article\category;
+use wcf\data\category\CategoryNode;
+
+/**
+ * Represents an article category node.
+ *
+ * @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\Article\Category
+ * @since      3.0
+ * 
+ * @method     ArticleCategory getDecoratedObject()
+ * @mixin      ArticleCategory
+ */
+class ArticleCategoryNode extends CategoryNode {
+       /**
+        * @inheritDoc
+        */
+       protected static $baseClass = ArticleCategory::class;
+}
diff --git a/wcfsetup/install/files/lib/data/article/category/ArticleCategoryNodeTree.class.php b/wcfsetup/install/files/lib/data/article/category/ArticleCategoryNodeTree.class.php
new file mode 100644 (file)
index 0000000..c8be7ac
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+namespace wcf\data\article\category;
+use wcf\data\category\CategoryNode;
+use wcf\data\category\CategoryNodeTree;
+
+/**
+ * Represents a list of article category nodes.
+ *
+ * @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\Article\Category
+ * @since      3.0
+ */
+class ArticleCategoryNodeTree extends CategoryNodeTree {
+       /**
+        * name of the category node class
+        * @var string
+        */
+       protected $nodeClassName = ArticleCategoryNode::class;
+       
+       /**
+        * @inheritDoc
+        */
+       public function isIncluded(CategoryNode $categoryNode) {
+               /** @var ArticleCategoryNode $categoryNode */
+               
+               return parent::isIncluded($categoryNode) && $categoryNode->isAccessible();
+       }
+}
index 6feec1495dfe8860a7124a7f31a9344ad2a5ff51..414f34f05c79887563b323da4f720c6566097287 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\page;
+use wcf\data\article\category\ArticleCategory;
 use wcf\data\article\content\ViewableArticleContent;
 use wcf\data\article\AccessibleArticleList;
 use wcf\data\article\ArticleEditor;
@@ -102,6 +103,12 @@ class ArticlePage extends AbstractPage {
         */
        public $articleLikeData = [];
        
+       /**
+        * category object
+        * @var ArticleCategory
+        */
+       public $category;
+       
        /**
         * @inheritDoc
         */
@@ -115,6 +122,7 @@ class ArticlePage extends AbstractPage {
                }
                $this->article = ViewableArticle::getArticle($this->articleContent->articleID);
                $this->canonicalURL = $this->articleContent->getLink();
+               $this->category = $this->article->getCategory();
        }
        
        /**
diff --git a/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php b/wcfsetup/install/files/lib/system/box/ArticleCategoriesBoxController.class.php
new file mode 100644 (file)
index 0000000..12dfda5
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\box;
+use wcf\data\article\category\ArticleCategoryNodeTree;
+use wcf\page\ArticlePage;
+use wcf\page\CategoryArticleListPage;
+use wcf\system\request\RequestHandler;
+use wcf\system\WCF;
+
+/**
+ * Box for article categories.
+ *
+ * @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\Box
+ * @since      3.0
+ */
+class ArticleCategoriesBoxController extends AbstractBoxController {
+       /**
+        * @inheritDoc
+        */
+       protected $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight', 'contentTop', 'contentBottom', 'footer'];
+       
+       /**
+        * @inheritDoc
+        */
+       protected function loadContent() {
+               // get categories
+               $categoryTree = new ArticleCategoryNodeTree('com.woltlab.wcf.article.category');
+               $categoryList = $categoryTree->getIterator();
+               $categoryList->setMaxDepth(0);
+               
+               if (iterator_count($categoryList)) {
+                       // get active category
+                       $activeCategory = null;
+                       if (RequestHandler::getInstance()->getActiveRequest()->getRequestObject() instanceof CategoryArticleListPage || RequestHandler::getInstance()->getActiveRequest()->getRequestObject() instanceof ArticlePage) {
+                               if (RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->category !== null) {
+                                       $activeCategory = RequestHandler::getInstance()->getActiveRequest()->getRequestObject()->category;
+                               }
+                       }
+                       
+                       $this->content = WCF::getTPL()->fetch('boxArticleCategories', 'wcf', ['categoryList' => $categoryList, 'activeCategory' => $activeCategory]);
+               }       
+       }
+}
index 4972405fda77b918afa90c90e883be5c0fef0766..d3c6bc09b64903e2105c5526b64c7bf0ebaf7b58 100644 (file)
@@ -14,7 +14,7 @@
                {foreach from=$showOrder item=$application}
                        <dl{if $errors[$application]|isset} class="formError"{/if}>
                                <dt>
-                                       <label for="application_{$application}">{'/^WoltLab Suite /'|preg_replace:'':$packages[$application][packageName]}</label>
+                                       <label for="application_{$application}">{$packages[$application][packageName]}</label>
                                </dt>
                                <dd>
                                        <input type="text" id="application_{$application}" class="long jsApplicationDirectory" name="directories[{$application}]" value="{$directories[$application]}">