// 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
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()) {
$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;
+ }
}