Enhanced ACP search
authorAlexander Ebert <ebert@woltlab.com>
Wed, 15 Aug 2012 23:01:03 +0000 (01:01 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 15 Aug 2012 23:01:03 +0000 (01:01 +0200)
wcfsetup/install/files/lib/system/cache/builder/ACPSearchProviderCacheBuilder.class.php
wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php

index a2d180245f15df59ed6116192b4afb2ab01c5e5f..7c7802b5dc7392b623307c173c1a697cee57c2a1 100644 (file)
@@ -18,8 +18,6 @@ class ACPSearchProviderCacheBuilder implements ICacheBuilder {
         * @see wcf\system\cache\ICacheBuilder::getData()
         */
        public function getData(array $cacheResource) {
-               list($cache, $packageID) = explode('-', $cacheResource['cache']);
-               
                $providerList = new ACPSearchProviderList();
                $providerList->getConditionBuilder()->add("acp_search_provider.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
                $providerList->sqlLimit = 0;
index abafea3f1415efdc8aaf4316b0d7580595f2e9f9..5f5019befda5f459f41626e6152702143949eb31 100644 (file)
@@ -37,12 +37,15 @@ class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInsta
                        WHERE           providerName = ?
                                        AND packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
+               
+               WCF::getDB()->beginTransaction();
                foreach ($items as $item) {
                        $statement->execute(array(
                                $item['attributes']['name'],
                                $this->installation->getPackageID()
                        ));
                }
+               WCF::getDB()->commitTransaction();
        }
        
        /**
index 3d2b1f9c8d92c33e8ed1b72c85d76a3db5b4b94e..9272e553050b1b48124a2f0593483f1fe17b3acc 100644 (file)
@@ -26,7 +26,8 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider {
                // search by language item
                $conditions = new PreparedStatementConditionBuilder();
                $conditions->add("languageID = ?", array(WCF::getLanguage()->languageID));
-               $conditions->add("languageItem LIKE ?", array('wcf.acp.option.'.$query.'%'));
+               $conditions->add("languageItem LIKE ?", array('wcf.acp.option.%'));
+               $conditions->add("languageItemValue LIKE ?", array($query.'%'));
                $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
                
                // get available abbrevations
@@ -51,7 +52,7 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider {
                        FROM            wcf".WCF_N."_language_item
                        ".$conditions."
                        ORDER BY        languageItemValue ASC";
-               $statement = WCF::getDB()->prepareStatement($sql, ($limit * 2)); // use double limit here since categories are matched too
+               $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
                $statement->execute($conditions->getParameters());
                $languageItems = array();
                while ($row = $statement->fetchArray()) {
@@ -66,16 +67,62 @@ class MenuItemACPSearchResultProvider implements IACPSearchResultProvider {
                $conditions->add("menuItem IN (?)", array(array_keys($languageItems)));
                $conditions->add("menuItemLink <> ''");
                
-               $sql = "SELECT  menuItem, menuItemLink
+               $sql = "SELECT  menuItem, menuItemLink, permissions, options
                        FROM    wcf".WCF_N."_acp_menu_item
                        ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql, $limit);
+               $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
                $statement->execute($conditions->getParameters());
                
+               $count = 0;
                while ($row = $statement->fetchArray()) {
-                       $results[] = new ACPSearchResult($languageItems[$row['menuItem']], $row['menuItemLink']);
+                       if ($count == $limit) {
+                               break;
+                       }
+                       
+                       if ($this->checkMenuItem($row)) {
+                               $results[] = new ACPSearchResult($languageItems[$row['menuItem']], $row['menuItemLink']);
+                               $count++;
+                       }
                }
                
                return $results;
        }
+       
+       /**
+        * Validates options and permissions for a given menu item.
+        * 
+        * @param       array           $row
+        * @return      boolean
+        */
+       protected function checkMenuItem(array $row) {
+               // check the options of this item
+               $hasEnabledOption = true;
+               if (!empty($row['options'])) {
+                       $hasEnabledOption = false;
+                       $options = explode(',', strtoupper($row['options']));
+                       foreach ($options as $option) {
+                               if (defined($option) && constant($option)) {
+                                       $hasEnabledOption = true;
+                                       break;
+                               }
+                       }
+               }
+               if (!$hasEnabledOption) return false;
+               
+               // check the permission of this item for the active user
+               $hasPermission = true;
+               if (!empty($row['permissions'])) {
+                       $hasPermission = false;
+                       $permissions = explode(',', $row['permissions']);
+                       foreach ($permissions as $permission) {
+                               if (WCF::getSession()->getPermission($permission)) {
+                                       $hasPermission = true;
+                                       break;
+                               }
+                       }
+               }
+               if (!$hasPermission) return false;
+               
+               return true;
+       }
 }