From 518ec202ab9f9d4b5f7c30c7e39bd2feae26656f Mon Sep 17 00:00:00 2001 From: Daniel Schmitz Date: Wed, 7 Jul 2021 13:26:15 +0800 Subject: [PATCH] wip --- .gitignore | 3 +- actions/admin/settings/100.panel.php | 18 ++++++ install/froxlor.sql | 6 +- .../updates/froxlor/0.10/update_0.10.inc.php | 12 +++- lib/Froxlor/SImExporter.php | 6 +- lib/Froxlor/Settings/Store.php | 58 +++++++++++++++++++ lib/Froxlor/UI/Data.php | 6 ++ lib/Froxlor/UI/Fields.php | 9 +++ lib/init.php | 10 +--- lng/english.lng.php | 6 ++ .../admin/settings/settings_form_begin.tpl | 2 +- templates/Sparkle/assets/css/main.css | 6 ++ templates/Sparkle/formfields/image.tpl | 11 ++++ 13 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 templates/Sparkle/formfields/image.tpl diff --git a/.gitignore b/.gitignore index 4e37d749..1b91d454 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,9 @@ logs/* .well-known .idea *.iml +img/ !templates/Froxlor/ !templates/Sparkle/ !templates/misc/ -templates/Sparkle/assets/img/logo_custom.png -templates/Sparkle/assets/img/logo_custom_login.png vendor/ diff --git a/actions/admin/settings/100.panel.php b/actions/admin/settings/100.panel.php index 3485bbdf..e73c5183 100644 --- a/actions/admin/settings/100.panel.php +++ b/actions/admin/settings/100.panel.php @@ -296,6 +296,24 @@ return array( 'default' => '', 'save_method' => 'storeSettingField' ), + 'panel_logo_image_header' => array( + 'label' => $lng['serversettings']['logo_image_header'], + 'settinggroup' => 'panel', + 'varname' => 'logo_image_header', + 'type' => 'image', + 'image_name' => 'logo_header', + 'default' => '', + 'save_method' => 'storeSettingImage' + ), + 'panel_logo_image_login' => array( + 'label' => $lng['serversettings']['logo_image_login'], + 'settinggroup' => 'panel', + 'varname' => 'logo_image_login', + 'type' => 'image', + 'image_name' => 'logo_login', + 'default' => '', + 'save_method' => 'storeSettingImage' + ), ) ) ) diff --git a/install/froxlor.sql b/install/froxlor.sql index 64db3116..763a1fec 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -715,8 +715,10 @@ opcache.interned_strings_buffer'), ('panel', 'imprint_url', ''), ('panel', 'terms_url', ''), ('panel', 'privacy_url', ''), + ('panel', 'logo_image_header', ''), + ('panel', 'logo_image_login', ''), ('panel', 'version', '0.10.26'), - ('panel', 'db_version', '202106270'); + ('panel', 'db_version', '202107070'); DROP TABLE IF EXISTS `panel_tasks`; @@ -933,7 +935,7 @@ CREATE TABLE IF NOT EXISTS `ftp_quotalimits` ( -INSERT INTO `ftp_quotalimits` (`name`, `quota_type`, `per_session`, `limit_type`, `bytes_in_avail`, `bytes_out_avail`, `bytes_xfer_avail`, `files_in_avail`, `files_out_avail`, `files_xfer_avail`) VALUES +INSERT INTO `ftp_quotalimits` (`name`, `quota_type`, `per_session`, `limit_type`, `bytes_in_avail`, `bytes_out_avail`, `bytes_xfer_avail`, `files_in_avail`, `files_out_avail`, `files_xfer_avail`) VALUES ('froxlor', 'user', 'false', 'hard', 0, 0, 0, 0, 0, 0); diff --git a/install/updates/froxlor/0.10/update_0.10.inc.php b/install/updates/froxlor/0.10/update_0.10.inc.php index 3f03dff2..278f6c43 100644 --- a/install/updates/froxlor/0.10/update_0.10.inc.php +++ b/install/updates/froxlor/0.10/update_0.10.inc.php @@ -14,7 +14,7 @@ use Froxlor\Settings; * @author Froxlor team (2010-) * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @package Install - * + * */ if (! defined('_CRON_UPDATE')) { if (! defined('AREA') || (defined('AREA') && AREA != 'admin') || ! isset($userinfo['loginname']) || (isset($userinfo['loginname']) && $userinfo['loginname'] == '')) { @@ -825,3 +825,13 @@ if (\Froxlor\Froxlor::isDatabaseVersion('202106160')) { \Froxlor\Froxlor::updateToDbVersion('202106270'); } + +if (\Froxlor\Froxlor::isDatabaseVersion('202107070')) { + + showUpdateStep("Adding custom logo image settings", true); + Settings::AddNew("panel.logo_image_header", ''); + Settings::AddNew("panel.logo_image_login", ''); + lastStepStatus(0); + + \Froxlor\Froxlor::updateToDbVersion('202107070'); +} diff --git a/lib/Froxlor/SImExporter.php b/lib/Froxlor/SImExporter.php index 7120aaad..aca4dea7 100644 --- a/lib/Froxlor/SImExporter.php +++ b/lib/Froxlor/SImExporter.php @@ -16,9 +16,9 @@ use Froxlor\Database\Database; * @author Froxlor team (2018-) * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @package Classes - * + * * @since 0.9.39 - * + * */ /** @@ -70,12 +70,14 @@ class SImExporter $_data[$index] = $row['value']; } } + // add checksum for validation $_data['_sha'] = sha1(var_export($_data, true)); $_export = json_encode($_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); if (! $_export) { throw new \Exception("Error exporting settings: " . json_last_error_msg()); } + return $_export; } diff --git a/lib/Froxlor/Settings/Store.php b/lib/Froxlor/Settings/Store.php index e4a8035e..2441cdc6 100644 --- a/lib/Froxlor/Settings/Store.php +++ b/lib/Froxlor/Settings/Store.php @@ -367,4 +367,62 @@ class Store return $returnvalue; } + + public static function storeSettingImage($fieldname, $fielddata) + { + if (isset($fielddata['settinggroup'], $fielddata['varname']) && is_array($fielddata) && $fielddata['settinggroup'] !== '' && $fielddata['varname'] !== '') { + $save_to = null; + $path = \Froxlor\Froxlor::getInstallDir().'/img/'; + + // New file? + if ($_FILES[$fieldname]['tmp_name']) { + // Make sure upload directory exists + if (!is_dir($path) && !mkdir($path, '0775')) { + throw new \Exception("img directory does not exist and cannot be created"); + } + + // Make sure we can write to the upload directory + if (!is_writable($path)) { + if (!chmod($path, '0775')) { + throw new \Exception("Cannot write to img directory"); + } + } + + // Determine file extension + $spl = explode('.', $_FILES[$fieldname]['name']); + $file_extension = strtolower(array_pop($spl)); + unset($spl); + + // Move file + if (!move_uploaded_file($_FILES[$fieldname]['tmp_name'], $path.$fielddata['image_name'].'.'.$file_extension)) { + throw new \Exception("Unable to save image to img folder"); + } + + $save_to = 'img/'.$fielddata['image_name'].'.'.$file_extension.'?v='.time(); + } + + // Delete file? + if ($fielddata['value'] !== "" && array_key_exists($fieldname.'_delete', $_POST) && $_POST[$fieldname.'_delete']) { + @unlink($path . explode('?', $fielddata['value'], 2)[0]); + $save_to = ''; + } + + // Nothing changed + if ($save_to === null) { + return array( + $fielddata['settinggroup'] . '.' . $fielddata['varname'] => $fielddata['value'] + ); + } + + if (Settings::Set($fielddata['settinggroup'] . '.' . $fielddata['varname'], $save_to) === false) { + return false; + } + + return array( + $fielddata['settinggroup'] . '.' . $fielddata['varname'] => $save_to + ); + } + + return false; + } } diff --git a/lib/Froxlor/UI/Data.php b/lib/Froxlor/UI/Data.php index a32ffa31..ee34f012 100644 --- a/lib/Froxlor/UI/Data.php +++ b/lib/Froxlor/UI/Data.php @@ -52,6 +52,12 @@ class Data return $newfieldvalue; } + public static function getFormFieldDataImage($fieldname, $fielddata, $input) + { + // We always make the system think we have new data to trigger the save function where we actually check everything + return time(); + } + public static function manipulateFormFieldDataDate($fieldname, $fielddata, $newfieldvalue) { if (isset($fielddata['date_timestamp']) && $fielddata['date_timestamp'] === true) { diff --git a/lib/Froxlor/UI/Fields.php b/lib/Froxlor/UI/Fields.php index c138538a..681e701c 100644 --- a/lib/Froxlor/UI/Fields.php +++ b/lib/Froxlor/UI/Fields.php @@ -89,6 +89,15 @@ class Fields return $returnvalue; } + public static function getFormFieldOutputImage($fieldname, $fielddata, $do_show = true) + { + global $lng; + $label = $fielddata['label']; + $value = htmlentities($fielddata['value']); + eval("\$returnvalue = \"" . \Froxlor\UI\Template::getTemplate("formfields/image", true) . "\";"); + return $returnvalue; + } + public static function getFormFieldOutputDate($fieldname, $fielddata, $do_show = true) { if (isset($fielddata['date_timestamp']) && $fielddata['date_timestamp'] === true) { diff --git a/lib/init.php b/lib/init.php index 7a9e9de5..f34565c1 100644 --- a/lib/init.php +++ b/lib/init.php @@ -380,14 +380,8 @@ if (! array_key_exists('variants', $_themeoptions) || ! array_key_exists($themev // check for custom header-graphic $hl_path = 'templates/' . $theme . '/assets/img'; -$header_logo = $header_logo_login = $hl_path . '/logo.png'; - -if (file_exists($hl_path . '/logo_custom.png')) { - $header_logo = $hl_path . '/logo_custom.png'; -} -if (file_exists($hl_path . '/logo_custom_login.png')) { - $header_logo_login = $hl_path . '/logo_custom_login.png'; -} +$header_logo = Settings::Get('panel.logo_image_header') ?: $hl_path . '/logo.png'; +$header_logo_login = Settings::Get('panel.logo_image_login') ?: $hl_path . '/logo.png'; /** * Redirects to index.php (login page) if no session exists diff --git a/lng/english.lng.php b/lng/english.lng.php index 117690d6..c8336b01 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2117,3 +2117,9 @@ $lng['privacy'] = 'Privacy policy'; $lng['serversettings']['privacy_url']['title'] = 'URL to privacy policy'; $lng['serversettings']['privacy_url']['description'] = 'Specify an URL to your privacy policy site / imprint site. The link will be visible on the login screen and on the footer when logged in.'; $lng['admin']['domaindefaultalias'] = 'Default ServerAlias value for new domains'; + +$lng['serversettings']['logo_image_header']['title'] = 'Logo Image (Header)'; +$lng['serversettings']['logo_image_header']['description'] = 'Upload your own logo image to be shown in the header after login (recommended height 50px)'; +$lng['serversettings']['logo_image_login']['title'] = 'Logo Image (Login)'; +$lng['serversettings']['logo_image_login']['description'] = 'Upload your own logo image to be shown during login'; +$lng['panel']['image_field_delete'] = 'Delete the existing current image'; diff --git a/templates/Sparkle/admin/settings/settings_form_begin.tpl b/templates/Sparkle/admin/settings/settings_form_begin.tpl index 87a16c57..792b8af1 100644 --- a/templates/Sparkle/admin/settings/settings_form_begin.tpl +++ b/templates/Sparkle/admin/settings/settings_form_begin.tpl @@ -1,5 +1,5 @@ $header -
+ diff --git a/templates/Sparkle/assets/css/main.css b/templates/Sparkle/assets/css/main.css index 127f360b..e88099cf 100644 --- a/templates/Sparkle/assets/css/main.css +++ b/templates/Sparkle/assets/css/main.css @@ -1745,3 +1745,9 @@ td.size-50 { .footer-link:last-child:after { content: ""; } + +.field-image-preview { + max-width: 300px; + max-height: 500px; + margin-bottom: 10px; +} diff --git a/templates/Sparkle/formfields/image.tpl b/templates/Sparkle/formfields/image.tpl new file mode 100644 index 00000000..2c72f8dd --- /dev/null +++ b/templates/Sparkle/formfields/image.tpl @@ -0,0 +1,11 @@ + + {$label} + + + Current Image
+ {$lng['panel']['image_field_delete']} +

+
+ disabled="disabled" type="file" class="file" name="{$fieldname}" accept=".jpg, .jpeg, .png" /> + +