function for setting-search

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-03-06 10:59:55 +01:00
parent a3a33c0da4
commit 3f9769103b
2 changed files with 174 additions and 130 deletions

View File

@@ -4,6 +4,7 @@ namespace Froxlor\Ajax;
use Exception;
use Froxlor\Http\HttpClient;
use Froxlor\PhpHelper;
use Froxlor\Settings;
use Froxlor\UI\Panel\UI;
@@ -49,7 +50,9 @@ class Ajax
case 'newsfeed':
return $this->getNewsfeed();
case 'updatecheck':
return $this->getUpdateCheck($session);
return $this->getUpdateCheck();
case 'searchsetting':
return $this->searchSetting();
default:
return $this->errorResponse('Action not found!');
}
@@ -160,7 +163,7 @@ class Ajax
}
}
private function getUpdateCheck(array $session)
private function getUpdateCheck()
{
UI::initTwig();
UI::twig()->addGlobal('s', $this->session);
@@ -180,4 +183,32 @@ class Ajax
\Froxlor\UI\Response::dynamic_error($e->getMessage());
}
}
private function searchSetting()
{
$searchtext = isset($_POST['searchtext']) ? $_POST['searchtext'] : "";
$result = [];
if (strlen($searchtext) > 2) {
$settings_data = PhpHelper::loadConfigArrayDir(\Froxlor\Froxlor::getInstallDir() . '/actions/admin/settings/');
$results = array();
PhpHelper::recursive_array_search($searchtext, $settings_data, $results);
$processed_setting = array();
foreach ($results as $pathkey) {
$pk = explode(".", $pathkey);
if (count($pk) > 4) {
$settingkey = $pk[0] . '.' . $pk[1] . '.' . $pk[2] . '.' . $pk[3];
if (!array_key_exists($settingkey, $processed_setting)) {
$processed_setting[$settingkey] = true;
$sresult = $settings_data[$pk[0]][$pk[1]][$pk[2]][$pk[3]];
$result[] = [
'href' => 'admin_settings.php?page=overview&part=' . $pk[1] . '&em=' . $pk[3],
'title' => (is_array($sresult['label']) ? $sresult['label']['title'] : $sresult['label'])
];
}
}
}
}
echo json_encode($result);
}
}

View File

@@ -409,6 +409,19 @@ class PhpHelper
return $returnval;
}
public static function recursive_array_search($needle, $haystack, &$keys = array(), $currentKey = '')
{
foreach ($haystack as $key => $value) {
$pathkey = empty($currentKey) ? $key : $currentKey . '.' . $key;
if (is_array($value)) {
self::recursive_array_search($needle, $value, $keys, $pathkey);
} else if (stripos($value, $needle) !== false) {
$keys[] = $pathkey;
}
}
return true;
}
/**
* function to check a super-global passed by reference
* so it gets automatically updated