From 164b40fef388f15e3a7f4420ac8797722c0aa7b3 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Mon, 16 Dec 2013 10:43:38 +0100 Subject: [PATCH] fix wrong language-string in settings/180.dkim.php, implemented Settings::Add() for updates later (much better than a manual query etc.), added new php-errorhandler so we can display php errors/warnings/notices (whatever is activated) in a nicer way Signed-off-by: Michael Kaufmann (d00p) --- actions/admin/settings/180.dkim.php | 2 +- lib/classes/settings/class.Settings.php | 44 +++++++++++++++++-- .../froxlor/function.phpErrHandler.php | 37 ++++++++++++++++ lib/init.php | 3 +- templates/Froxlor/misc/phperrornice.tpl | 9 ++++ templates/Sparkle/misc/phperrornice.tpl | 11 +++++ 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 lib/functions/froxlor/function.phpErrHandler.php create mode 100644 templates/Froxlor/misc/phperrornice.tpl create mode 100644 templates/Sparkle/misc/phperrornice.tpl diff --git a/actions/admin/settings/180.dkim.php b/actions/admin/settings/180.dkim.php index 0857764d..79b2879e 100644 --- a/actions/admin/settings/180.dkim.php +++ b/actions/admin/settings/180.dkim.php @@ -81,7 +81,7 @@ return array( 'dkim_keylength' => array( 'label' => array( 'title' => $lng['dkim']['dkim_keylength']['title'], - 'description' => sprintf($lng['dkim_keylength']['label']['description'], Settings::Get('dkim.dkim_prefix')) + 'description' => sprintf($lng['dkim']['dkim_keylength']['description'], Settings::Get('dkim.dkim_prefix')) ), 'settinggroup' => 'dkim', 'varname' => 'dkim_keylength', diff --git a/lib/classes/settings/class.Settings.php b/lib/classes/settings/class.Settings.php index 8820af5d..7461d0ca 100644 --- a/lib/classes/settings/class.Settings.php +++ b/lib/classes/settings/class.Settings.php @@ -79,9 +79,9 @@ class Settings { */ private function _readSettings() { $result_stmt = Database::query(" - SELECT `settingid`, `settinggroup`, `varname`, `value` - FROM `" . TABLE_PANEL_SETTINGS . "` - "); + SELECT `settingid`, `settinggroup`, `varname`, `value` + FROM `" . TABLE_PANEL_SETTINGS . "` + "); self::$_data = array(); while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { self::$_data[$row['settinggroup']][$row['varname']] = $row['value']; @@ -136,6 +136,9 @@ class Settings { if (Settings::Get($setting) !== null) { // set new value in array $sstr = explode(".", $setting); + if (!isset($sstr[1])) { + return false; + } self::$_data[$sstr[0]][$sstr[1]] = $value; // should we store to db instantly? if ($instant_save) { @@ -151,6 +154,41 @@ class Settings { return false; } + /** + * add a new setting to the database (mainly used in updater) + * + * @param string $setting a group and a varname separated by a dot (group.varname) + * @param string $value + * + * @return boolean + */ + public function pAddNew($setting = null, $value = null) { + + // first check if it doesn't exist + if (Settings::Get($setting) === null) { + // validate parameter + $sstr = explode(".", $setting); + if (!isset($sstr[1])) { + return false; + } + // prepare statement + $ins_stmt = Database::prepare(" + INSERT INTO `".TABLE_PANEL_SETTINGS."` SET + `settinggroup` = :group, + `varname` = :varname, + `value` = :value + "); + $ins_data = array( + 'settinggroup' => $sstr[0], + 'varname' => $sstr[1], + 'value' => $value + ); + Database::pexecute($ins_stmt, $ins_data); + return true; + } + return false; + } + /** * Store all un-saved changes to the database and * re-read in all settings diff --git a/lib/functions/froxlor/function.phpErrHandler.php b/lib/functions/froxlor/function.phpErrHandler.php new file mode 100644 index 00000000..f5c3d584 --- /dev/null +++ b/lib/functions/froxlor/function.phpErrHandler.php @@ -0,0 +1,37 @@ +", '#'.$errno.' '.$errstr, $err_hint); + $err_hint = str_replace("", $errfile.':'.$errline, $err_hint); + + // show + echo $err_hint; + // return true to ignore php standard error-handler + return true; + } + + // of on shell, use the php standard error-handler + return false; +} diff --git a/lib/init.php b/lib/init.php index a9fe74a2..74124bd2 100644 --- a/lib/init.php +++ b/lib/init.php @@ -106,6 +106,7 @@ if (!isset($sql) * Includes the Functions */ require FROXLOR_INSTALL_DIR.'/lib/functions.php'; +@set_error_handler('phpErrHandler'); /** * Includes the MySQL-Tabledefinitions etc. @@ -121,7 +122,7 @@ $idna_convert = new idna_convert_wrapper(); * disable magic_quotes_runtime if enabled */ if (get_magic_quotes_runtime()) { - //Deactivate + // deactivate set_magic_quotes_runtime(false); } diff --git a/templates/Froxlor/misc/phperrornice.tpl b/templates/Froxlor/misc/phperrornice.tpl new file mode 100644 index 00000000..f5db5856 --- /dev/null +++ b/templates/Froxlor/misc/phperrornice.tpl @@ -0,0 +1,9 @@ +
+
+
PHP warning/error
+
+

+
+
+
+
diff --git a/templates/Sparkle/misc/phperrornice.tpl b/templates/Sparkle/misc/phperrornice.tpl new file mode 100644 index 00000000..11450caf --- /dev/null +++ b/templates/Sparkle/misc/phperrornice.tpl @@ -0,0 +1,11 @@ +
+
+
PHP warning/error
+
+

+

 

+
+

 

+
+
+