123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- defined('GNUSOCIAL') || die();
- class OverwriteThemeBackgroundAdminPanelAction extends AdminPanelAction
- {
-
- public function title(): string
- {
- return _m('Overwrite Theme Background');
- }
-
- public function getInstructions(): string
- {
- return _m('Customize your theme\'s background easily');
- }
-
- public function showForm()
- {
- $form = new OverwriteThemeBackgroundAdminPanelForm($this);
- $form->show();
- return;
- }
-
- public function saveSettings()
- {
- static $settings = [
- 'overwritethemebackground' => [
- 'background-color',
- 'background-image',
- 'sslbackground-image',
- 'background-repeat',
- 'background-attachment',
- 'background-position'
- ]
- ];
- $values = [];
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- $values[$section][$setting] = $this->trimmed($setting);
- }
- }
-
- $this->validate($values);
-
- $config = new Config();
- $config->query('START TRANSACTION');
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- Config::save($section, $setting, $values[$section][$setting]);
- }
- }
- $config->query('COMMIT');
- return;
- }
-
- public function validate(&$values)
- {
-
- if (!empty($values['overwritethemebackground']['background-image']) &&
- !common_valid_http_url($values['overwritethemebackground']['background-image'])) {
-
- $this->clientError(_m('Invalid background URL.'));
- }
- if (!empty($values['overwritethemebackground']['sslbackground-image']) &&
- !common_valid_http_url($values['overwritethemebackground']['sslbackground-image'], true)) {
-
- $this->clientError(_m('Invalid SSL background URL.'));
- }
- }
- }
- class OverwriteThemeBackgroundAdminPanelForm extends AdminForm
- {
-
- public function id()
- {
- return 'form_site_admin_panel';
- }
-
- public function formClass()
- {
- return 'form_settings';
- }
-
- public function action()
- {
- return common_local_url('overwritethemebackgroundAdminPanel');
- }
-
- public function formData()
- {
- $this->out->elementStart('fieldset', ['id' => 'settings_site_background']);
-
- $this->out->element('legend', null, _m('Background'));
- $this->out->elementStart('ul', 'form_data');
-
- $this->li();
- $this->input(
- 'background-color',
-
- _m('Site background color'),
-
- 'Background color for the site (hexadecimal with #).',
- 'overwritethemebackground'
- );
- $this->unli();
-
- $this->li();
- $this->input(
- 'background-image',
-
- _m('Site background'),
-
- 'Background for the site (full URL).',
- 'overwritethemebackground'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslbackground-image',
-
- _m('SSL background'),
-
- 'Background to show on SSL pages (full URL).',
- 'overwritethemebackground'
- );
- $this->unli();
-
- $this->li();
-
- $this->out->dropdown(
- 'background-repeat',
- _m('Background repeat'),
-
- ['Repeat horizontally and vertically', 'Repeat Horizontally', 'Repeat Vertically', 'Don\'t repeat'],
- _m('repeat horizontally and/or vertically'),
- false,
- common_config('overwritethemebackground', 'background-repeat') ?? 'repeat'
- );
- $this->unli();
-
- $this->li();
-
- $this->out->dropdown(
- 'background-attachment',
- _m('Background attachment'),
-
- ['Scroll with page', 'Stay fixed'],
- _m('Whether the background image should scroll or be fixed (will not scroll with the rest of the page)'),
- false,
- common_config('overwritethemebackground', 'background-attachment') ?? 'scroll'
- );
- $this->unli();
-
- $background_position_options = [
- 'initial',
- 'left top',
- 'left center',
- 'left bottom',
- 'right top',
- 'right center',
- 'right bottom',
- 'center top',
- 'center center',
- 'center bottom'
- ];
- $this->li();
-
- $this->out->dropdown(
- 'background-position',
- _m('Background position'),
-
- $background_position_options,
- _m('Sets the starting position of a background image'),
- false,
- common_config('overwritethemebackground', 'background-attachment') ?? 'initial'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- }
-
- public function formActions()
- {
- $this->out->submit(
- 'submit',
-
- _m('BUTTON', 'Save'),
- 'submit',
- null,
-
- _m('Save the site settings.')
- );
- }
- }
|