123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- <?php
- defined('GNUSOCIAL') || die();
- class PathsadminpanelAction extends AdminPanelAction
- {
-
- public function title()
- {
-
- return _('Paths');
- }
-
- public function getInstructions()
- {
-
- return _('Path and server settings for this StatusNet site');
- }
-
- public function showForm()
- {
- $form = new PathsAdminPanelForm($this);
- $form->show();
- return;
- }
-
- public function saveSettings()
- {
- static $settings = [
- 'site' => ['path', 'locale_path', 'ssl', 'sslserver'],
- 'theme' => ['server', 'dir', 'path', 'sslserver', 'sslpath'],
- 'avatar' => ['server', 'dir', 'path'],
- 'attachments' => ['server', 'dir', 'path', 'sslserver', 'sslpath'],
- ];
-
-
- static $booleans = array('site' => array('fancy'));
- $values = array();
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- $values[$section][$setting] = $this->trimmed("$section-$setting");
- }
- }
- foreach ($booleans as $section => $parts) {
- foreach ($parts as $setting) {
- $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0;
- }
- }
- $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]);
- }
- }
- foreach ($booleans 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['theme']['dir']) && !is_readable($values['theme']['dir'])) {
-
-
- $this->clientError(sprintf(_('Theme directory not readable: %s.'), $values['theme']['dir']));
- }
-
- if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
-
-
- $this->clientError(sprintf(_('Avatar directory not writable: %s.'), $values['avatar']['dir']));
- }
-
-
- if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
-
-
- $this->clientError(sprintf(_('Locales directory not readable: %s.'), $values['site']['locale_path']));
- }
-
- if (mb_strlen($values['site']['sslserver']) > 255) {
-
-
- $this->clientError(_('Invalid SSL server. The maximum length is 255 characters.'));
- }
- }
- }
- class PathsAdminPanelForm extends AdminForm
- {
-
- public function id()
- {
- return 'form_paths_admin_panel';
- }
-
- public function formClass()
- {
- return 'form_settings';
- }
-
- public function action()
- {
- return common_local_url('pathsadminpanel');
- }
-
- public function formData()
- {
- $this->out->elementStart('fieldset', array('id' => 'settings_paths_locale'));
-
- $this->out->element('legend', null, _('Site'), 'site');
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->input(
- 'server',
-
- _('Server'),
-
- _('Site\'s server hostname.')
- );
- $this->unli();
- $this->li();
- $this->input(
- 'path',
-
- _('Path'),
-
- _('Site path.')
- );
- $this->unli();
- $this->li();
- $this->input(
- 'locale_path',
-
- _('Locale directory'),
-
- _('Directory path to locales.'),
- 'site'
- );
- $this->unli();
- $this->li();
- $this->out->checkbox(
- 'fancy',
-
- _('Fancy URLs'),
- (bool) $this->value('fancy'),
-
- _('Use fancy URLs (more readable and memorable)?')
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
-
- $this->out->element('legend', null, _m('LEGEND', 'Theme'));
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->input(
- 'server',
-
- _('Server'),
-
- _('Server for themes.'),
- 'theme'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'path',
-
- _('Path'),
-
- _('Web path to themes.'),
- 'theme'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslserver',
-
- _('SSL server'),
-
- _('SSL server for themes (default: SSL server).'),
- 'theme'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslpath',
-
- _('SSL path'),
-
- _('SSL path to themes (default: /theme/).'),
- 'theme'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'dir',
-
- _('Directory'),
-
- _('Directory where themes are located.'),
- 'theme'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- $this->out->elementStart(
- 'fieldset',
- ['id' => 'settings_avatar-paths']
- );
-
- $this->out->element('legend', null, _('Avatars'));
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->input(
- 'server',
-
- _('Avatar server'),
-
- _('Server for avatars.'),
- 'avatar'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'path',
-
- _('Avatar path'),
-
- _('Web path to avatars.'),
- 'avatar'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'dir',
-
- _('Avatar directory'),
-
- _('Directory where avatars are located.'),
- 'avatar'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- $this->out->elementStart(
- 'fieldset',
- ['id' => 'settings_attachments-paths']
- );
-
- $this->out->element('legend', null, _('Attachments'));
- $this->out->elementStart('ul', 'form_data');
- $this->li();
- $this->input(
- 'server',
-
- _('Server'),
-
- _('Server for attachments.'),
- 'attachments'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'path',
-
- _('Path'),
-
- _('Web path to attachments.'),
- 'attachments'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslserver',
-
- _('SSL server'),
-
- _('Server for attachments on SSL pages.'),
- 'attachments'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslpath',
-
- _('SSL path'),
-
- _('Web path to attachments on SSL pages.'),
- 'attachments'
- );
- $this->unli();
- $this->li();
- $this->input(
- 'dir',
-
- _('Directory'),
-
- _('Directory where attachments are located.'),
- 'attachments'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- $this->out->elementStart('fieldset', array('id' => 'settings_admin_ssl'));
-
- $this->out->element('legend', null, _m('LEGEND', 'SSL'));
- $this->out->elementStart('ul', 'form_data');
- $this->li();
-
- $ssl = [
- 'never' => _('Never'),
-
- 'always' => _('Always'),
- ];
- $this->out->dropdown(
- 'site-ssl',
-
- _('Use SSL'),
-
- $ssl,
- _('When to use SSL.'),
- false,
- $this->value('ssl', 'site')
- );
- $this->unli();
- $this->li();
- $this->input(
- 'sslserver',
-
- _('SSL server'),
-
- _('Server to direct SSL requests to.'),
- 'site'
- );
- $this->unli();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('fieldset');
- }
-
- public function formActions()
- {
-
- $this->out->submit(
- 'save',
- _m('BUTTON', 'Save'),
- 'submit',
-
- 'save',
- _('Save path settings.')
- );
- }
-
- public function input($setting, $title, $instructions, $section='site')
- {
- $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
- }
- }
|