function for setting-search
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Froxlor\Ajax;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Froxlor\Http\HttpClient;
|
use Froxlor\Http\HttpClient;
|
||||||
|
use Froxlor\PhpHelper;
|
||||||
use Froxlor\Settings;
|
use Froxlor\Settings;
|
||||||
use Froxlor\UI\Panel\UI;
|
use Froxlor\UI\Panel\UI;
|
||||||
|
|
||||||
@@ -49,7 +50,9 @@ class Ajax
|
|||||||
case 'newsfeed':
|
case 'newsfeed':
|
||||||
return $this->getNewsfeed();
|
return $this->getNewsfeed();
|
||||||
case 'updatecheck':
|
case 'updatecheck':
|
||||||
return $this->getUpdateCheck($session);
|
return $this->getUpdateCheck();
|
||||||
|
case 'searchsetting':
|
||||||
|
return $this->searchSetting();
|
||||||
default:
|
default:
|
||||||
return $this->errorResponse('Action not found!');
|
return $this->errorResponse('Action not found!');
|
||||||
}
|
}
|
||||||
@@ -160,7 +163,7 @@ class Ajax
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUpdateCheck(array $session)
|
private function getUpdateCheck()
|
||||||
{
|
{
|
||||||
UI::initTwig();
|
UI::initTwig();
|
||||||
UI::twig()->addGlobal('s', $this->session);
|
UI::twig()->addGlobal('s', $this->session);
|
||||||
@@ -180,4 +183,32 @@ class Ajax
|
|||||||
\Froxlor\UI\Response::dynamic_error($e->getMessage());
|
\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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,6 +409,19 @@ class PhpHelper
|
|||||||
return $returnval;
|
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
|
* function to check a super-global passed by reference
|
||||||
* so it gets automatically updated
|
* so it gets automatically updated
|
||||||
|
|||||||
Reference in New Issue
Block a user