summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-11-19 11:55:07 -0800
committerZach Copley <zach@status.net>2009-11-19 11:55:07 -0800
commitb8de14af2c91eb50b62e352a5a66ee3ee474d7a0 (patch)
tree86acc378f9bea557f6e8ac0ee6c025f3ad33ed91 /actions
parent640bb39891c7e36886ff0cc3b2599e75f9c691be (diff)
Moved most path and server settings to a new paths admin panel
Diffstat (limited to 'actions')
-rw-r--r--actions/designadminpanel.php134
-rw-r--r--actions/pathsadminpanel.php320
-rw-r--r--actions/siteadminpanel.php19
3 files changed, 336 insertions, 137 deletions
diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php
index 7c71c032a..8bc8c4450 100644
--- a/actions/designadminpanel.php
+++ b/actions/designadminpanel.php
@@ -129,19 +129,14 @@ class DesignadminpanelAction extends AdminPanelAction
$bgimage = $this->saveBackgroundImage();
- static $settings = array(
- 'site' => array('theme', 'logo'),
- 'theme' => array('server', 'dir', 'path'),
- 'avatar' => array('server', 'dir', 'path'),
- 'background' => array('server', 'dir', 'path')
- );
+ common_debug("background image: $bgimage");
+
+ static $settings = array('theme', 'logo');
$values = array();
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- $values[$section][$setting] = $this->trimmed("$section-$setting");
- }
+ foreach ($settings as $setting) {
+ $values[$setting] = $this->trimmed($setting);
}
$this->validate($values);
@@ -171,10 +166,8 @@ class DesignadminpanelAction extends AdminPanelAction
$config->query('BEGIN');
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- Config::save($section, $setting, $values[$section][$setting]);
- }
+ foreach ($settings as $setting) {
+ Config::save('site', $setting, $values[$setting]);
}
if (isset($bgimage)) {
@@ -272,48 +265,13 @@ class DesignadminpanelAction extends AdminPanelAction
function validate(&$values)
{
-
- if (!empty($values['site']['logo']) &&
- !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) {
+ if (!empty($values['logo']) &&
+ !Validate::uri($values['logo'], array('allowed_schemes' => array('http', 'https')))) {
$this->clientError(_("Invalid logo URL."));
}
- if (!in_array($values['site']['theme'], Theme::listAvailable())) {
- $this->clientError(sprintf(_("Theme not available: %s"), $values['site']['theme']));
- }
-
- // Make sure the directories are there
-
- 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['background']['dir']) || !is_writable($values['background']['dir'])) {
- $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir']));
- }
-
- // Do we need to do anything else but validate the
- // other fields for length? Design settings are
- // validated elsewhere --Z
-
- static $settings = array(
- 'theme' => array('server', 'path'),
- 'avatar' => array('server', 'path'),
- 'background' => array('server', 'path')
- );
-
- foreach ($settings as $section => $parts) {
- foreach ($parts as $setting) {
- if (mb_strlen($values[$section][$setting]) > 255) {
- $this->clientError(sprintf(_("Max length for %s %s is 255 characters."),
- $section, $setting));
- return;
- }
- }
+ if (!in_array($values['theme'], Theme::listAvailable())) {
+ $this->clientError(sprintf(_("Theme not available: %s"), $values['theme']));
}
}
@@ -414,7 +372,7 @@ class DesignAdminPanelForm extends AdminForm
$this->out->elementStart('ul', 'form_data');
$this->li();
- $this->input('logo', _('Site logo'), 'Logo for the site (full URL)', 'site');
+ $this->input('logo', _('Site logo'), 'Logo for the site (full URL)');
$this->unli();
$this->out->elementEnd('ul');
@@ -438,41 +396,9 @@ class DesignAdminPanelForm extends AdminForm
$themes = array_combine($themes, $themes);
$this->li();
- $this->out->dropdown('site-theme', _('Site theme'),
+ $this->out->dropdown('theme', _('Site theme'),
$themes, _('Theme for the site.'),
- false, $this->value('theme', 'site'));
- $this->unli();
-
- $this->li();
- $this->input('server', _('Theme server'), 'Server for themes', 'theme');
- $this->unli();
-
- $this->li();
- $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
- $this->unli();
-
- $this->li();
- $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
- $this->unli();
-
- $this->out->elementEnd('ul');
-
- $this->out->elementEnd('fieldset');
- $this->out->elementStart('fieldset', array('id' => 'settings_design_avatar'));
- $this->out->element('legend', null, _('Avatar Settings'));
-
- $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');
+ false, $this->value('theme'));
$this->unli();
$this->out->elementEnd('ul');
@@ -550,18 +476,6 @@ class DesignAdminPanelForm extends AdminForm
$this->unli();
}
- $this->li();
- $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
- $this->unli();
-
- $this->li();
- $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
- $this->unli();
-
- $this->li();
- $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
- $this->unli();
-
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
@@ -668,24 +582,4 @@ class DesignAdminPanelForm extends AdminForm
'save', _('Save design'));
}
-
- /**
- * Utility to simplify some of the duplicated code around
- * params and settings. Overriding the input() in the base class
- * to handle a whole bunch of cases of settings with the same
- * name under different sections.
- *
- * @param string $setting Name of the setting
- * @param string $title Title to use for the input
- * @param string $instructions Instructions for this field
- * @param string $section config section, default = 'site'
- *
- * @return void
- */
-
- function input($setting, $title, $instructions, $section='site')
- {
- $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
- }
-
}
diff --git a/actions/pathsadminpanel.php b/actions/pathsadminpanel.php
new file mode 100644
index 000000000..c4ab18c00
--- /dev/null
+++ b/actions/pathsadminpanel.php
@@ -0,0 +1,320 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Paths administration panel
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Settings
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Zach Copley <zach@status.net>
+ * @author Sarven Capadisli <csarven@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+/**
+ * Paths settings
+ *
+ * @category Admin
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Zach Copley <zach@status.net>
+ * @author Sarven Capadisli <csarven@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class PathsadminpanelAction extends AdminPanelAction
+{
+
+ /**
+ * Returns the page title
+ *
+ * @return string page title
+ */
+
+ function title()
+ {
+ return _('Paths');
+ }
+
+ /**
+ * Instructions for using this form.
+ *
+ * @return string instructions
+ */
+
+ function getInstructions()
+ {
+ return _('Path and server settings for this StatusNet site.');
+ }
+
+ /**
+ * Show the paths admin panel form
+ *
+ * @return void
+ */
+
+ function showForm()
+ {
+ $form = new PathsAdminPanelForm($this);
+ $form->show();
+ return;
+ }
+
+ /**
+ * Save settings from the form
+ *
+ * @return void
+ */
+
+ function saveSettings()
+ {
+ static $settings = array(
+ 'site' => array('path', 'locale_path'),
+ 'theme' => array('server', 'dir', 'path'),
+ 'avatar' => array('server', 'dir', 'path'),
+ 'background' => array('server', 'dir', 'path')
+ );
+
+ $values = array();
+
+ foreach ($settings as $section => $parts) {
+ foreach ($parts as $setting) {
+ $values[$section][$setting] = $this->trimmed("$section-$setting");
+ }
+ }
+
+ $this->validate($values);
+
+ // assert(all values are valid);
+
+ $config = new Config();
+
+ $config->query('BEGIN');
+
+ foreach ($settings as $section => $parts) {
+ foreach ($parts as $setting) {
+ Config::save($section, $setting, $values[$section][$setting]);
+ }
+ }
+
+ $config->query('COMMIT');
+
+ return;
+ }
+
+ /**
+ * Attempt to validate setting values
+ *
+ * @return void
+ */
+
+ function validate(&$values)
+ {
+
+ // Validate theme dir
+
+ if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) {
+ $this->clientError(sprintf(_("Theme directory not readable: %s"), $values['theme']['dir']));
+ }
+
+ // Validate avatar dir
+
+ if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) {
+ $this->clientError(sprintf(_("Avatar directory not writable: %s"), $values['avatar']['dir']));
+ }
+
+ // Validate background dir
+
+ if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) {
+ $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir']));
+ }
+
+ // Validate locales dir
+
+ // XXX: What else do we need to validate for lacales path here? --Z
+
+ if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
+ $this->clientError(sprintf(_("Locales directory not readable: %s"), $values['site']['locale_path']));
+ }
+
+ }
+
+}
+
+class PathsAdminPanelForm extends AdminForm
+{
+
+ /**
+ * ID of the form
+ *
+ * @return int ID of the form
+ */
+
+ function id()
+ {
+ return 'form_paths_admin_panel';
+ }
+
+ /**
+ * class of the form
+ *
+ * @return string class of the form
+ */
+
+ function formClass()
+ {
+ return 'form_settings';
+ }
+
+ /**
+ * Action of the form
+ *
+ * @return string URL of the action
+ */
+
+ function action()
+ {
+ return common_local_url('pathsadminpanel');
+ }
+
+ /**
+ * Data elements of the form
+ *
+ * @return void
+ */
+
+ 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('path', _('Path'), _('Site path'));
+ $this->unli();
+
+ $this->li();
+ $this->input('locale_path', _('Path to locales'), _('Directory path to locales'), 'site');
+ $this->unli();
+
+ $this->out->elementEnd('ul');
+ $this->out->elementEnd('fieldset');
+
+ $this->out->elementStart('fieldset', array('id' => 'settings_paths_theme'));
+ $this->out->element('legend', null, _('Theme'));
+
+ $this->out->elementStart('ul', 'form_data');
+
+ $this->li();
+ $this->input('server', _('Theme server'), 'Server for themes', 'theme');
+ $this->unli();
+
+ $this->li();
+ $this->input('path', _('Theme path'), 'Web path to themes', 'theme');
+ $this->unli();
+
+ $this->li();
+ $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme');
+ $this->unli();
+
+ $this->out->elementEnd('ul');
+
+ $this->out->elementEnd('fieldset');
+ $this->out->elementStart('fieldset', array('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', array('id' =>
+ 'settings_design_background-paths'));
+ $this->out->element('legend', null, _('Backgrounds'));
+ $this->out->elementStart('ul', 'form_data');
+
+ $this->li();
+ $this->input('server', _('Background server'), 'Server for backgrounds', 'background');
+ $this->unli();
+
+ $this->li();
+ $this->input('path', _('Background path'), 'Web path to backgrounds', 'background');
+ $this->unli();
+
+ $this->li();
+ $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background');
+ $this->unli();
+
+ $this->out->elementEnd('ul');
+ $this->out->elementEnd('fieldset');
+ }
+
+ /**
+ * Action elements
+ *
+ * @return void
+ */
+
+ function formActions()
+ {
+ $this->out->submit('save', _('Save'), 'submit form_action-secondary',
+ 'save', _('Save paths'));
+ }
+
+
+ /**
+ * Utility to simplify some of the duplicated code around
+ * params and settings. Overriding the input() in the base class
+ * to handle a whole bunch of cases of settings with the same
+ * name under different sections.
+ *
+ * @param string $setting Name of the setting
+ * @param string $title Title to use for the input
+ * @param string $instructions Instructions for this field
+ * @param string $section config section, default = 'site'
+ *
+ * @return void
+ */
+
+ function input($setting, $title, $instructions, $section='site')
+ {
+ $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions);
+ }
+
+}
diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php
index 916b9ebfb..40197d6e2 100644
--- a/actions/siteadminpanel.php
+++ b/actions/siteadminpanel.php
@@ -92,8 +92,8 @@ class SiteadminpanelAction extends AdminPanelAction
{
static $settings = array('site' => array('name', 'broughtby', 'broughtbyurl',
'email', 'timezone', 'language',
- 'ssl', 'sslserver', 'site', 'path',
- 'textlimit', 'dupelimit', 'locale_path'),
+ 'ssl', 'sslserver', 'site',
+ 'textlimit', 'dupelimit'),
'snapshot' => array('run', 'reporturl', 'frequency'));
static $booleans = array('site' => array('private', 'inviteonly', 'closed', 'fancy'));
@@ -216,14 +216,6 @@ class SiteadminpanelAction extends AdminPanelAction
$this->clientError(_("Dupe limit must 1 or more seconds."));
}
- // Validate locales path
-
- // XXX: What else do we need to validate for lacales path here? --Z
-
- if (!empty($values['site']['locale_path']) && !is_readable($values['site']['locale_path'])) {
- $this->clientError(sprintf(_("Locales directory not readable: %s"), $values['site']['locale_path']));
- }
-
}
}
@@ -317,9 +309,6 @@ class SiteAdminPanelForm extends AdminForm
false, $this->value('language'));
$this->unli();
- $this->li();
- $this->input('locale_path', _('Path to locales'), _('Directory path to locales'));
- $this->unli();
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
@@ -331,10 +320,6 @@ class SiteAdminPanelForm extends AdminForm
$this->unli();
$this->li();
- $this->input('path', _('Path'), _('Site path'));
- $this->unli();
-
- $this->li();
$this->out->checkbox('fancy', _('Fancy URLs'),
(bool) $this->value('fancy'),
_('Use fancy (more readable and memorable) URLs?'));