first part of plugin setting

This commit is contained in:
Haitem 2020-12-09 14:30:41 +01:00
parent 42443c8b58
commit ee0ebff76a
3 changed files with 40 additions and 11 deletions

View File

@ -5,11 +5,20 @@ ini_set( 'display_errors','1');
//setup
parse_str($_SERVER['QUERY_STRING'], $params);
if (defined ("BASEDIR")) {
$urlSes = BASEDIR;
} else {
$urlSes = str_replace((!empty ($params['url']) ? $params['url'] : ""), "", str_replace('https://' . $_SERVER['HTTP_HOST'], "", $_SERVER['REQUEST_URI']));
}
if (defined ("BASEDIR") && defined ("BASEURL")) {
$domain = str_replace("http://", "", str_replace("https://", "", str_replace(BASEDIR, "", BASEURL)));
} else {
$domain = str_replace("/var/www/", "", $_SERVER['DOCUMENT_ROOT']);
}
session_set_cookie_params(
1209600,
$urlSes,
str_replace("/var/www/", "", $_SERVER['DOCUMENT_ROOT']),
$domain,
true,
true
);

View File

@ -4,20 +4,20 @@ class SettingsManager{
return Db::loadAll ("SELECT * FROM settings");
}
static function getByName($settingName, $group = '') {
if ($group != '') return Db::loadOne("SELECT * FROM settings WHERE name = ? AND group = ?", array($settingName, $group));
static function getByName($settingName, $type = '') {
if ($type != '') return Db::loadOne("SELECT * FROM settings WHERE name = ? AND type = ?", array($settingName, $type));
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
}
static function getSettingGroup($group) {
return Db::loadAll("SELECT * FROM settings WHERE group = ?", array($group));
static function getSettingGroup($type) {
return Db::loadAll("SELECT * FROM settings WHERE type=?", array($type));
}
public static function create ($name, $value, $group = '') {
public static function create ($name, $value, $type = '') {
$setting = array (
'name' => $name,
'value' => $value,
'group' => $group,
'type' => $type,
);
try {
Db::add ('settings', $setting);
@ -27,9 +27,9 @@ class SettingsManager{
}
}
public static function update ($name, $value, $group = '') {
if ($this.getByName($name)){
$this->create($name, $value, $group);
public static function update ($name, $value, $type = '') {
if (self::getByName($name)){
self::create($name, $value, $type);
} else {
try {
Db::edit ('settings', [

View File

@ -56,7 +56,27 @@ class Setting extends Template
$rooms = RoomManager::getAllRooms();
$template->prepare('rooms', $rooms);
$settingsManager = new SettingsManager();
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
$pluginsFiles = array_diff (scandir ($dir), ['..', '.']);
$plugins = array ();
foreach ($pluginsFiles as $key => $pluginFile) {
$status = (strpos ($pluginFile, "!") !== false ? false : true);
if ($status) {
$plugins[$key]['name'] = str_replace ("!", "", str_replace (".php", "", $pluginFile));
$plugins[$key]['slug'] = strtolower ($plugins[$key]['name']);
$result = $settingsManager->getSettingGroup($plugins[$key]['slug']);
if (count ($result) > 0) {
$plugins[$key]['settings'] = $result;
}
}
}
$plugins = Utilities::sortArrayByKey($plugins, 'slug', "desc");
$template->prepare('pluginsSettings', $plugins);
$template->render();
}