Hide disabled smiley categories in inline editor
authorMatthias Schmidt <gravatronics@live.com>
Sun, 1 Mar 2015 17:52:02 +0000 (18:52 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 1 Mar 2015 17:52:02 +0000 (18:52 +0100)
com.woltlab.wcf/templates/messageFormSmilies.tpl
com.woltlab.wcf/templates/messageFormTabsInline.tpl
wcfsetup/install/files/lib/data/smiley/SmileyCache.class.php
wcfsetup/install/files/lib/form/MessageForm.class.php

index 38fe26a612b95962be73b09df9ef06090bdb64a4..114b9fc960800657fab6bb0bcecab5080e1d5444 100644 (file)
                </nav>
                
                {foreach from=$smileyCategories item=smileyCategory}
-                       {if !$smileyCategory->isDisabled}
-                               <div id="smilies-{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}-{@$smileyCategory->categoryID}">
-                                       {if !$smileyCategory->categoryID}{@$__defaultSmilies}{/if}
-                               </div>
-                       {/if}
+                       <div id="smilies-{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}-{@$smileyCategory->categoryID}">
+                               {if !$smileyCategory->categoryID}{@$__defaultSmilies}{/if}
+                       </div>
                {/foreach}
                
                <script data-relocate="true">
index 913ac9eada2e2a536470cad5af94bd86b5d4a536..a92ac33e26fd446f7fc17499d2f87444b8c10275 100644 (file)
@@ -1,4 +1,4 @@
-{assign var=smileyCategories value=$__wcf->getSmileyCache()->getCategories()}
+{assign var=smileyCategories value=$__wcf->getSmileyCache()->getVisibleCategories()}
 {if !$permissionCanUseSmilies|isset}{assign var=permissionCanUseSmilies value='user.message.canUseSmilies'}{/if}
 {if !$wysiwygContainerID|isset}{assign var=wysiwygContainerID value='text'}{/if}
 
@@ -29,4 +29,4 @@
                $('.messageTabMenu').messageTabMenu();
        });
        //]]>
-</script>
\ No newline at end of file
+</script>
index ebac87653d05151437bbc55cb1cdb9c678938b64..513b1d961e43802c8301dc7aa3e7e5e1227e169f 100644 (file)
@@ -29,6 +29,12 @@ class SmileyCache extends SingletonFactory {
         */
        protected $cachedCategories = array();
        
+       /**
+        * enabled smiley categories with at least one smiley
+        * @var array<\wcf\data\smiley\category\SmileyCategory>
+        */
+       protected $visibleCategories = null;
+       
        /**
         * @see \wcf\system\SingletonFactory::init()
         */
@@ -69,6 +75,29 @@ class SmileyCache extends SingletonFactory {
                return $this->cachedCategories;
        }
        
+       /**
+        * Returns all enabled smiley categories with at least one smiley.
+        * 
+        * @return      array<\wcf\data\smiley\category\SmileyCategory>
+        */
+       public function getVisibleCategories() {
+               if ($this->visibleCategories === null) {
+                       $this->visibleCategories = array();
+                       
+                       foreach ($this->cachedCategories as $key => $category) {
+                               if (!$category->isDisabled) {
+                                       $category->loadSmilies();
+                                       
+                                       if (count($category)) {
+                                               $this->visibleCategories[$key] = $category;
+                                       }
+                               }
+                       }
+               }
+               
+               return $this->visibleCategories;
+       }
+       
        /**
         * Returns all the smilies of a category.
         * 
index a7ad830e88544f337281b01fa86a0cbca7d63d4a..9da2da41d1b4bffad098b1a6998bd78ac8039c93 100644 (file)
@@ -341,15 +341,7 @@ abstract class MessageForm extends AbstractCaptchaForm {
                
                // get default smilies
                if (MODULE_SMILEY) {
-                       $this->smileyCategories = SmileyCache::getInstance()->getCategories();
-                       foreach ($this->smileyCategories as $index => $category) {
-                               $category->loadSmilies();
-                               
-                               // remove empty categories
-                               if (!count($category) || $category->isDisabled) {
-                                       unset($this->smileyCategories[$index]);
-                               }
-                       }
+                       $this->smileyCategories = SmileyCache::getInstance()->getVisibleCategories();
                        
                        $firstCategory = reset($this->smileyCategories);
                        if ($firstCategory) {