From ee99a8ef50a61a5a8d8b001c336536f23a855119 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Nov 2009 19:18:22 -0500 Subject: [PATCH 01/22] superclass for adminpanel actions --- lib/adminpanelaction.php | 206 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 lib/adminpanelaction.php diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php new file mode 100644 index 0000000000..2e9261711b --- /dev/null +++ b/lib/adminpanelaction.php @@ -0,0 +1,206 @@ +. + * + * @category UI + * @package StatusNet + * @author Evan Prodromou + * @copyright 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); +} + +/** + * superclass for admin panel actions + * + * Common code for all admin panel actions. + * + * @category UI + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @todo Find some commonalities with SettingsAction and combine + */ + +class AdminPanelAction extends Action +{ + var $success = true; + var $msg = null; + + /** + * Prepare for the action + * + * We check to see that the user is logged in, has + * authenticated in this session, and has the right + * to configure the site. + * + * @param array $args Array of arguments from Web driver + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + + // User must be logged in. + + if (!common_logged_in()) { + $this->clientError(_('Not logged in.')); + return; + } + + $user = common_current_user(); + + // It must be a "real" login, not saved cookie login + + if (!common_is_real_login()) { + // Cookie theft is too easy; we require automatic + // logins to re-authenticate before admining the site + common_set_returnto($this->selfUrl()); + if (Event::handle('RedirectToLogin', array($this, $user))) { + common_redirect(common_local_url('login'), 303); + } + } + + // User must have the right to change admin settings + + $user = common_current_user(); + + if (!$user->hasRight(Right::CONFIGURESITE)) { + $this->clientError(_('You cannot make changes to this site.')); + return; + } + + return true; + } + + /** + * handle the action + * + * Check session token and try to save the settings if this is a + * POST. Otherwise, show the form. + * + * @param array $args unused. + * + * @return void + */ + + function handle($args) + { + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->checkSessionToken(); + try { + $this->saveSettings(); + + $this->success = true; + $this->msg = _('Settings saved.'); + } catch (Exception $e) { + $this->success = false; + $this->msg = $e->getMessage(); + } + } + $this->showPage(); + } + + /** + * Show the content section of the page + * + * Here, we show the admin panel's form. + * + * @return void. + */ + + function showContent() + { + $this->showForm(); + } + + /** + * show human-readable instructions for the page, or + * a success/failure on save. + * + * @return void + */ + + function showPageNotice() + { + if ($this->msg) { + $this->element('div', ($this->success) ? 'success' : 'error', + $this->msg); + } else { + $inst = $this->getInstructions(); + $output = common_markup_to_html($inst); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } + + /** + * Show the admin panel form + * + * Sub-classes should overload this. + * + * @return void + */ + + function showForm() + { + $this->clientError(_('showForm() not implemented.')); + return; + } + + /** + * Instructions for using this form. + * + * String with instructions for using the form. + * + * Subclasses should overload this. + * + * @return void + */ + + function getInstructions() + { + return ''; + } + + /** + * Save settings from the form + * + * Validate and save the settings from the user. + * + * @return void + */ + + function saveSettings() + { + $this->clientError(_('saveSettings() not implemented.')); + return; + } +} From 144f8171099aa6d1f3807554443573195c26f986 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Nov 2009 23:15:59 -0500 Subject: [PATCH 02/22] add a break to switch in hasRight() --- classes/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/User.php b/classes/User.php index 546406f71e..6162f83b88 100644 --- a/classes/User.php +++ b/classes/User.php @@ -710,6 +710,7 @@ class User extends Memcached_DataObject break; case Right::CONFIGURESITE: $result = $this->hasRole(User_role::ADMINISTRATOR); + break; default: $result = false; break; From dd9fa0e6833432b1936a6375e4cb411fe340dec8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Nov 2009 23:16:34 -0500 Subject: [PATCH 03/22] only load user once, reload settings in admin panel --- lib/adminpanelaction.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php index 2e9261711b..fa3272f8aa 100644 --- a/lib/adminpanelaction.php +++ b/lib/adminpanelaction.php @@ -75,6 +75,10 @@ class AdminPanelAction extends Action $user = common_current_user(); + // ...because they're logged in + + assert(!empty($user)); + // It must be a "real" login, not saved cookie login if (!common_is_real_login()) { @@ -88,8 +92,6 @@ class AdminPanelAction extends Action // User must have the right to change admin settings - $user = common_current_user(); - if (!$user->hasRight(Right::CONFIGURESITE)) { $this->clientError(_('You cannot make changes to this site.')); return; @@ -116,6 +118,10 @@ class AdminPanelAction extends Action try { $this->saveSettings(); + // Reload settings + + Config::loadSettings(); + $this->success = true; $this->msg = _('Settings saved.'); } catch (Exception $e) { From 408510f527be0a1a22fa564369fad48938b7bd02 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Nov 2009 23:16:59 -0500 Subject: [PATCH 04/22] pkeyGet() and save() methods for Config --- classes/Config.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/classes/Config.php b/classes/Config.php index 92f237d7f2..390d75381a 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -120,6 +120,35 @@ class Config extends Memcached_DataObject return $result; } + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Config', $kv); + } + + static function save($section, $setting, $value) + { + $result = null; + + $config = Config::pkeyGet(array('section' => $section, + 'setting' => $setting)); + + if (!empty($config)) { + $orig = clone($config); + $config->value = $value; + $result = $config->update($orig); + } else { + $config = new Config(); + + $config->section = $section; + $config->setting = $setting; + $config->value = $value; + + $result = $config->insert(); + } + + return $result; + } + function _blowSettingsCache() { $c = self::memcache(); From d0466da80bfd50df4bbfe470e4bb6eed6e73b3e8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Nov 2009 23:17:52 -0500 Subject: [PATCH 05/22] add site admin panel --- actions/siteadminpanel.php | 166 +++++++++++++++++++++++++++++++++++++ lib/router.php | 2 + 2 files changed, 168 insertions(+) create mode 100644 actions/siteadminpanel.php diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php new file mode 100644 index 0000000000..8a15458385 --- /dev/null +++ b/actions/siteadminpanel.php @@ -0,0 +1,166 @@ +. + * + * @category Settings + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @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); +} + +/** + * Administer site settings + * + * @category Admin + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class SiteadminpanelAction extends AdminPanelAction +{ + /** + * Returns the page title + * + * @return string page title + */ + + function title() + { + return _('Site'); + } + + /** + * Instructions for using this form. + * + * @return string instructions + */ + + function getInstructions() + { + return _('Basic settings for this StatusNet site.'); + } + + /** + * Show the site admin panel form + * + * @return void + */ + + function showForm() + { + $form = new SiteAdminPanelForm($this); + $form->show(); + return; + } + + /** + * Save settings from the form + * + * @return void + */ + + function saveSettings() + { + $name = $this->trimmed('name'); + + $config = new Config(); + + $config->query('BEGIN'); + + Config::save('site', 'name', $name); + + $config->query('COMMIT'); + + return; + } +} + +class SiteAdminPanelForm extends Form +{ + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'siteadminpanel'; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_site_admin_panel'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('siteadminpanel'); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->input('name', _('Site name'), + ($this->out->arg('name')) ? $this->out->arg('name') : + common_config('site', 'name'), + _('The name of your site, like "Yourcompany Microblog"')); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings')); + } +} diff --git a/lib/router.php b/lib/router.php index db9fdb4704..27ad54c198 100644 --- a/lib/router.php +++ b/lib/router.php @@ -573,6 +573,8 @@ class Router $m->connect('api/search.json', array('action' => 'twitapisearchjson')); $m->connect('api/trends.json', array('action' => 'twitapitrends')); + $m->connect('admin/site', array('action' => 'siteadminpanel')); + $m->connect('getfile/:filename', array('action' => 'getfile'), array('filename' => '[A-Za-z0-9._-]+')); From 2f770cecf9c44d465b2f88cb3ab9ed11e5626501 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 15:48:05 -0500 Subject: [PATCH 06/22] add some more fields to site admin panel --- actions/siteadminpanel.php | 70 ++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 8a15458385..2c7382e43b 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -90,18 +90,52 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { - $name = $this->trimmed('name'); + static $settings = array('name', 'broughtby', 'broughtbyurl', 'email'); + + $values = array(); + + foreach ($settings as $setting) { + $values[$setting] = $this->trimmed($setting); + } + + // This throws an exception on validation errors + + $this->validate($values); + + // assert(all values are valid); $config = new Config(); $config->query('BEGIN'); - Config::save('site', 'name', $name); + foreach ($settings as $setting) { + Config::save('site', $setting, $values['setting']); + } $config->query('COMMIT'); return; } + + function validate(&$values) + { + // Validate site name + + if (empty($values['name'])) { + $this->clientError(_("Site name must have non-zero length.")); + } + + // Validate email + + $values['email'] = common_canonical_email($values['email']); + + if (empty($values['email'])) { + $this->clientError(_('You must have a valid contact email address')); + } + if (!Validate::email($values['email'], common_config('email', 'check_domain'))) { + $this->clientError(_('Not a valid email address')); + } + } } class SiteAdminPanelForm extends Form @@ -147,10 +181,34 @@ class SiteAdminPanelForm extends Form function formData() { - $this->out->input('name', _('Site name'), - ($this->out->arg('name')) ? $this->out->arg('name') : - common_config('site', 'name'), - _('The name of your site, like "Yourcompany Microblog"')); + $this->input('name', _('Site name'), + _('The name of your site, like "Yourcompany Microblog"')); + $this->input('broughtby', _('Brought by'), + _('Text used for credits link in footer of each page')); + $this->input('broughtbyurl', _('Brought by URL'), + _('URL used for credits link in footer of each page')); + $this->input('email', _('Email'), + _('contact email address for your site')); + } + + /** + * Utility to simplify some of the duplicated code around + * params and settings. + * + * @param string $setting Name of the setting + * @param string $title Title to use for the input + * @param string $instructions Instructions for this field + * + * @return void + */ + + function input($setting, $title, $instructions) + { + $value = $this->out->trimmed($setting); + if (empty($value)) { + $value = common_config('site', $setting); + } + $this->out->input($setting, $title, $value, $instructions); } /** From 7ee9737ef67fded89fb51602b06c8f77fba97bb1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 16:27:19 -0500 Subject: [PATCH 07/22] incorrectly saving wrong values in siteadminpanel --- actions/siteadminpanel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 2c7382e43b..460567c224 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -109,7 +109,7 @@ class SiteadminpanelAction extends AdminPanelAction $config->query('BEGIN'); foreach ($settings as $setting) { - Config::save('site', $setting, $values['setting']); + Config::save('site', $setting, $values[$setting]); } $config->query('COMMIT'); From 977d5d6f8569437a8d8a7f9616f4de6afc0dc509 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 22:03:34 -0500 Subject: [PATCH 08/22] add default timezone to site admin panel --- actions/siteadminpanel.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 460567c224..f66aa855c0 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -90,7 +90,7 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { - static $settings = array('name', 'broughtby', 'broughtbyurl', 'email'); + static $settings = array('name', 'broughtby', 'broughtbyurl', 'email', 'timezone'); $values = array(); @@ -135,6 +135,14 @@ class SiteadminpanelAction extends AdminPanelAction if (!Validate::email($values['email'], common_config('email', 'check_domain'))) { $this->clientError(_('Not a valid email address')); } + + // Validate timezone + + if (is_null($values['timezone']) || + !in_array($values['timezone'], DateTimeZone::listIdentifiers())) { + $this->clientError(_('Timezone not selected.')); + return; + } } } @@ -189,6 +197,18 @@ class SiteAdminPanelForm extends Form _('URL used for credits link in footer of each page')); $this->input('email', _('Email'), _('contact email address for your site')); + + $timezones = array(); + + foreach (DateTimeZone::listIdentifiers() as $k => $v) { + $timezones[$v] = $v; + } + + asort($timezones); + + $this->out->dropdown('timezone', _('Default timezone'), + $timezones, _('Default timezone for the site; usually UTC.'), + true, $this->value('timezone')); } /** @@ -203,12 +223,25 @@ class SiteAdminPanelForm extends Form */ function input($setting, $title, $instructions) + { + $this->out->input($setting, $title, $this->value($setting), $instructions); + } + + /** + * Utility to simplify getting the posted-or-stored setting value + * + * @param string $setting Name of the setting + * + * @return string param value if posted, or current config value + */ + + function value($setting) { $value = $this->out->trimmed($setting); if (empty($value)) { $value = common_config('site', $setting); } - $this->out->input($setting, $title, $value, $instructions); + return $value; } /** From 33f931d5277e0d72f5c9082d176a1a574f033e87 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 22:12:12 -0500 Subject: [PATCH 09/22] add default language to site admin panel --- actions/siteadminpanel.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index f66aa855c0..2da26e4bd6 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -90,7 +90,8 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { - static $settings = array('name', 'broughtby', 'broughtbyurl', 'email', 'timezone'); + static $settings = array('name', 'broughtby', 'broughtbyurl', + 'email', 'timezone', 'language'); $values = array(); @@ -143,6 +144,12 @@ class SiteadminpanelAction extends AdminPanelAction $this->clientError(_('Timezone not selected.')); return; } + + // Validate language + + if (!is_null($language) && !in_array($language, array_keys(get_nice_language_list()))) { + $this->clientError(sprintf(_('Unknown language "%s"'), $language)); + } } } @@ -209,6 +216,10 @@ class SiteAdminPanelForm extends Form $this->out->dropdown('timezone', _('Default timezone'), $timezones, _('Default timezone for the site; usually UTC.'), true, $this->value('timezone')); + + $this->out->dropdown('language', _('Language'), + get_nice_language_list(), _('Default site language'), + false, $this->value('language')); } /** From badd8ccccadb4eb3697c8d68619e4ec931b947c5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 22:21:28 -0500 Subject: [PATCH 10/22] add registration restrictions and privacy to site admin panel --- actions/siteadminpanel.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 2da26e4bd6..358c0b15fa 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -91,7 +91,8 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { static $settings = array('name', 'broughtby', 'broughtbyurl', - 'email', 'timezone', 'language'); + 'email', 'timezone', 'language', + 'closed', 'inviteonly', 'private'); $values = array(); @@ -220,6 +221,18 @@ class SiteAdminPanelForm extends Form $this->out->dropdown('language', _('Language'), get_nice_language_list(), _('Default site language'), false, $this->value('language')); + + $this->out->checkbox('closed', _('Closed'), + (bool) $this->value('closed'), + _('Is registration on this site prohibited?')); + + $this->out->checkbox('inviteonly', _('Invite-only'), + (bool) $this->value('inviteonly'), + _('Is registration on this site only open to invited users?')); + + $this->out->checkbox('private', _('Private'), + (bool) $this->value('private'), + _('Prohibit anonymous users (not logged in) from viewing site?')); } /** From a4905c03ba3df2cd07b2886880391e1534f24392 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 22:31:19 -0500 Subject: [PATCH 11/22] add site admin to global primary nav --- lib/action.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/action.php b/lib/action.php index 80f398fbd7..edb70c3d9d 100644 --- a/lib/action.php +++ b/lib/action.php @@ -434,6 +434,10 @@ class Action extends HTMLOutputter // lawsuit $this->menuItem(common_local_url($connect), _('Connect'), _('Connect to services'), false, 'nav_connect'); } + if ($user->hasRight(Right::CONFIGURESITE)) { + $this->menuItem(common_local_url('siteadminpanel'), + _('Admin'), _('Change site configuration'), false, 'nav_admin'); + } if (common_config('invite', 'enabled')) { $this->menuItem(common_local_url('invite'), _('Invite'), From 348b155376eac2130150cd041bca9fd4799334cf Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 9 Nov 2009 13:40:37 -0500 Subject: [PATCH 12/22] add nav menu for admin panel --- lib/adminpanelaction.php | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php index fa3272f8aa..6d4b974c37 100644 --- a/lib/adminpanelaction.php +++ b/lib/adminpanelaction.php @@ -132,6 +132,21 @@ class AdminPanelAction extends Action $this->showPage(); } + /** + * Show tabset for this page + * + * Uses the AdminPanelNav widget + * + * @return void + * @see AdminPanelNav + */ + + function showLocalNav() + { + $nav = new AdminPanelNav($this); + $nav->show(); + } + /** * Show the content section of the page * @@ -210,3 +225,120 @@ class AdminPanelAction extends Action return; } } + +/** + * Menu for public group of actions + * + * @category Output + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see Widget + */ + +class AdminPanelNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $action_name = $this->action->trimmed('action'); + + $this->action->elementStart('ul', array('class' => 'nav')); + + if (Event::handle('StartAdminPanelNav', array($this))) { + + $this->out->menuItem(common_local_url('siteadminpanel'), _('Site'), + _('Basic site configuration'), $action_name == 'siteadminpanel', 'nav_site_admin_panel'); + + Event::handle('EndAdminPanelNav', array($this)); + } + $this->action->elementEnd('ul'); + } +} + +/** + * Menu for admin group of actions + * + * @category Output + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see Widget + */ + +class PublicGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $action_name = $this->action->trimmed('action'); + + $this->action->elementStart('ul', array('class' => 'nav')); + + if (Event::handle('StartPublicGroupNav', array($this))) { + $this->out->menuItem(common_local_url('public'), _('Public'), + _('Public timeline'), $action_name == 'public', 'nav_timeline_public'); + + $this->out->menuItem(common_local_url('groups'), _('Groups'), + _('User groups'), $action_name == 'groups', 'nav_groups'); + + $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'), + _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags'); + + if (count(common_config('nickname', 'featured')) > 0) { + $this->out->menuItem(common_local_url('featured'), _('Featured'), + _('Featured users'), $action_name == 'featured', 'nav_featured'); + } + + $this->out->menuItem(common_local_url('favorited'), _('Popular'), + _("Popular notices"), $action_name == 'favorited', 'nav_timeline_favorited'); + + Event::handle('EndPublicGroupNav', array($this)); + } + $this->action->elementEnd('ul'); + } +} From b2145a6e4c739578e03d3d1fda6b415f2a830462 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Nov 2009 01:00:41 -0500 Subject: [PATCH 13/22] use
  • s in form data for site admin panel --- actions/siteadminpanel.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 358c0b15fa..6dae12e08c 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -197,15 +197,25 @@ class SiteAdminPanelForm extends Form function formData() { + $this->out->elementStart('ul', 'form_data'); + $this->li(); $this->input('name', _('Site name'), _('The name of your site, like "Yourcompany Microblog"')); + $this->unli(); + $this->li(); $this->input('broughtby', _('Brought by'), _('Text used for credits link in footer of each page')); + $this->unli(); + $this->li(); $this->input('broughtbyurl', _('Brought by URL'), _('URL used for credits link in footer of each page')); + $this->unli(); + $this->li(); $this->input('email', _('Email'), _('contact email address for your site')); + $this->unli(); + $timezones = array(); foreach (DateTimeZone::listIdentifiers() as $k => $v) { @@ -214,25 +224,43 @@ class SiteAdminPanelForm extends Form asort($timezones); + $this->li(); + $this->out->dropdown('timezone', _('Default timezone'), $timezones, _('Default timezone for the site; usually UTC.'), true, $this->value('timezone')); + $this->unli(); + $this->li(); + $this->out->dropdown('language', _('Language'), get_nice_language_list(), _('Default site language'), false, $this->value('language')); + $this->unli(); + $this->li(); + $this->out->checkbox('closed', _('Closed'), (bool) $this->value('closed'), _('Is registration on this site prohibited?')); + $this->unli(); + $this->li(); + $this->out->checkbox('inviteonly', _('Invite-only'), (bool) $this->value('inviteonly'), _('Is registration on this site only open to invited users?')); + $this->unli(); + $this->li(); + $this->out->checkbox('private', _('Private'), (bool) $this->value('private'), _('Prohibit anonymous users (not logged in) from viewing site?')); + + $this->unli(); + + $this->out->elementEnd('ul'); } /** @@ -268,6 +296,16 @@ class SiteAdminPanelForm extends Form return $value; } + function li() + { + $this->out->elementStart('li'); + } + + function unli() + { + $this->out->elementEnd('li'); + } + /** * Action elements * From 4258f99d2f44aebb9794a354e9614733a97e43c4 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Nov 2009 01:09:40 -0500 Subject: [PATCH 14/22] Add design admin panel --- actions/designadminpanel.php | 231 +++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 actions/designadminpanel.php diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php new file mode 100644 index 0000000000..30af76ff5b --- /dev/null +++ b/actions/designadminpanel.php @@ -0,0 +1,231 @@ +. + * + * @category Settings + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @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); +} + +/** + * Administer design settings + * + * @category Admin + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class DesignadminpanelAction extends AdminPanelAction +{ + /** + * Returns the page title + * + * @return string page title + */ + + function title() + { + return _('Design'); + } + + /** + * Instructions for using this form. + * + * @return string instructions + */ + + function getInstructions() + { + return _('Design settings for this StatusNet site.'); + } + + /** + * Show the site admin panel form + * + * @return void + */ + + function showForm() + { + $form = new DesignAdminPanelForm($this); + $form->show(); + return; + } + + /** + * Save settings from the form + * + * @return void + */ + + function saveSettings() + { + static $settings = array('theme'); + + $values = array(); + + foreach ($settings as $setting) { + $values[$setting] = $this->trimmed($setting); + } + + // This throws an exception on validation errors + + $this->validate($values); + + // assert(all values are valid); + + $config = new Config(); + + $config->query('BEGIN'); + + foreach ($settings as $setting) { + Config::save('site', $setting, $values[$setting]); + } + + $config->query('COMMIT'); + + return; + } + + function validate(&$values) + { + if (!in_array($values['theme'], Theme::listAvailable())) { + $this->clientError(sprintf(_("Theme not available: %s"), $values['theme'])); + } + } +} + +class DesignAdminPanelForm extends Form +{ + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'designadminpanel'; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_design_admin_panel'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('designadminpanel'); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $themes = Theme::listAvailable(); + + asort($themes); + + $themes = array_combine($themes, $themes); + + $this->out->elementStart('ul'); + $this->out->elementStart('li'); + + $this->out->dropdown('theme', _('Theme'), + $themes, _('Theme for the site.'), + true, $this->value('theme')); + + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } + + /** + * Utility to simplify some of the duplicated code around + * params and settings. + * + * @param string $setting Name of the setting + * @param string $title Title to use for the input + * @param string $instructions Instructions for this field + * + * @return void + */ + + function input($setting, $title, $instructions) + { + $this->out->input($setting, $title, $this->value($setting), $instructions); + } + + /** + * Utility to simplify getting the posted-or-stored setting value + * + * @param string $setting Name of the setting + * + * @return string param value if posted, or current config value + */ + + function value($setting) + { + $value = $this->out->trimmed($setting); + if (empty($value)) { + $value = common_config('site', $setting); + } + return $value; + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings')); + } +} From 220f8771c6570849e2ffd510b14ea4b6197e2366 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Nov 2009 01:43:34 -0500 Subject: [PATCH 15/22] store boolean values correctly in siteadminpanel --- actions/siteadminpanel.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 6dae12e08c..e4deea9620 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -91,8 +91,8 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { static $settings = array('name', 'broughtby', 'broughtbyurl', - 'email', 'timezone', 'language', - 'closed', 'inviteonly', 'private'); + 'email', 'timezone', 'language'); + static $booleans = array('closed', 'inviteonly', 'private'); $values = array(); @@ -100,6 +100,10 @@ class SiteadminpanelAction extends AdminPanelAction $values[$setting] = $this->trimmed($setting); } + foreach ($booleans as $setting) { + $values[$setting] = ($this->boolean($setting)) ? 1 : 0; + } + // This throws an exception on validation errors $this->validate($values); @@ -110,7 +114,7 @@ class SiteadminpanelAction extends AdminPanelAction $config->query('BEGIN'); - foreach ($settings as $setting) { + foreach (array_merge($settings, $booleans) as $setting) { Config::save('site', $setting, $values[$setting]); } From bcb0447eda21cc997fd447b2be3343cb1454bb33 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Nov 2009 01:43:56 -0500 Subject: [PATCH 16/22] add designadminpanel to router --- lib/router.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/router.php b/lib/router.php index 321b4273e7..b143cd5379 100644 --- a/lib/router.php +++ b/lib/router.php @@ -586,6 +586,7 @@ class Router $m->connect('api/trends.json', array('action' => 'twitapitrends')); $m->connect('admin/site', array('action' => 'siteadminpanel')); + $m->connect('admin/design', array('action' => 'designadminpanel')); $m->connect('getfile/:filename', array('action' => 'getfile'), From 494a06f3883f7950a9ca15af3b41e446683f5509 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Nov 2009 01:44:24 -0500 Subject: [PATCH 17/22] add designadminpanel to admin panel tabset --- lib/adminpanelaction.php | 68 ++-------------------------------------- 1 file changed, 3 insertions(+), 65 deletions(-) diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php index 6d4b974c37..33b210da34 100644 --- a/lib/adminpanelaction.php +++ b/lib/adminpanelaction.php @@ -272,73 +272,11 @@ class AdminPanelNav extends Widget $this->out->menuItem(common_local_url('siteadminpanel'), _('Site'), _('Basic site configuration'), $action_name == 'siteadminpanel', 'nav_site_admin_panel'); + $this->out->menuItem(common_local_url('designadminpanel'), _('Design'), + _('Design configuration'), $action_name == 'designadminpanel', 'nav_design_admin_panel'); + Event::handle('EndAdminPanelNav', array($this)); } $this->action->elementEnd('ul'); } } - -/** - * Menu for admin group of actions - * - * @category Output - * @package StatusNet - * @author Evan Prodromou - * @author Sarven Capadisli - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - * - * @see Widget - */ - -class PublicGroupNav extends Widget -{ - var $action = null; - - /** - * Construction - * - * @param Action $action current action, used for output - */ - - function __construct($action=null) - { - parent::__construct($action); - $this->action = $action; - } - - /** - * Show the menu - * - * @return void - */ - - function show() - { - $action_name = $this->action->trimmed('action'); - - $this->action->elementStart('ul', array('class' => 'nav')); - - if (Event::handle('StartPublicGroupNav', array($this))) { - $this->out->menuItem(common_local_url('public'), _('Public'), - _('Public timeline'), $action_name == 'public', 'nav_timeline_public'); - - $this->out->menuItem(common_local_url('groups'), _('Groups'), - _('User groups'), $action_name == 'groups', 'nav_groups'); - - $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'), - _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags'); - - if (count(common_config('nickname', 'featured')) > 0) { - $this->out->menuItem(common_local_url('featured'), _('Featured'), - _('Featured users'), $action_name == 'featured', 'nav_featured'); - } - - $this->out->menuItem(common_local_url('favorited'), _('Popular'), - _("Popular notices"), $action_name == 'favorited', 'nav_timeline_favorited'); - - Event::handle('EndPublicGroupNav', array($this)); - } - $this->action->elementEnd('ul'); - } -} From 9f8eedd5a3549fe5a4e6baa864d7f4e007d6076f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 14:37:35 +0100 Subject: [PATCH 18/22] add panels.txt to remember what to add where --- actions/useradminpanel.php | 228 +++++++++++++++++++++++++++++++++++++ panels.txt | 175 ++++++++++++++++++++++++++++ 2 files changed, 403 insertions(+) create mode 100644 actions/useradminpanel.php create mode 100644 panels.txt diff --git a/actions/useradminpanel.php b/actions/useradminpanel.php new file mode 100644 index 0000000000..de475a27bf --- /dev/null +++ b/actions/useradminpanel.php @@ -0,0 +1,228 @@ +. + * + * @category Settings + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @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); +} + +/** + * Administer user settings + * + * @category Admin + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class UseradminpanelAction extends AdminPanelAction +{ + /** + * Returns the page title + * + * @return string page title + */ + + function title() + { + return _('User'); + } + + /** + * Instructions for using this form. + * + * @return string instructions + */ + + function getInstructions() + { + return _('User settings for this StatusNet site.'); + } + + /** + * Show the site admin panel form + * + * @return void + */ + + function showForm() + { + $form = new UserAdminPanelForm($this); + $form->show(); + return; + } + + /** + * Save settings from the form + * + * @return void + */ + + function saveSettings() + { + static $settings = array('theme'); + static $booleans = array('closed', 'inviteonly', 'private'); + + $values = array(); + + foreach ($settings as $setting) { + $values[$setting] = $this->trimmed($setting); + } + + // This throws an exception on validation errors + + $this->validate($values); + + // assert(all values are valid); + + $config = new Config(); + + $config->query('BEGIN'); + + foreach ($settings as $setting) { + Config::save('site', $setting, $values[$setting]); + } + + $config->query('COMMIT'); + + return; + } + + function validate(&$values) + { + } +} + +class UserAdminPanelForm extends Form +{ + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'useradminpanel'; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_user_admin_panel'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('useradminpanel'); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->li(); + + $this->out->checkbox('closed', _('Closed'), + (bool) $this->value('closed'), + _('Is registration on this site prohibited?')); + + $this->unli(); + $this->li(); + + $this->out->checkbox('inviteonly', _('Invite-only'), + (bool) $this->value('inviteonly'), + _('Is registration on this site only open to invited users?')); + + $this->unli(); + } + + /** + * Utility to simplify some of the duplicated code around + * params and settings. + * + * @param string $setting Name of the setting + * @param string $title Title to use for the input + * @param string $instructions Instructions for this field + * + * @return void + */ + + function input($setting, $title, $instructions) + { + $this->out->input($setting, $title, $this->value($setting), $instructions); + } + + /** + * Utility to simplify getting the posted-or-stored setting value + * + * @param string $setting Name of the setting + * + * @return string param value if posted, or current config value + */ + + function value($cat, $setting) + { + $value = $this->out->trimmed($setting); + if (empty($value)) { + $value = common_config($cat, $setting); + } + return $value; + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save'), 'submit', null, _('Save site settings')); + } +} diff --git a/panels.txt b/panels.txt new file mode 100644 index 0000000000..3787eb1900 --- /dev/null +++ b/panels.txt @@ -0,0 +1,175 @@ +servicesadminpanel + +- ping notify +- syslog priority +- syslog appname +- syslog facility +- memcached enabled +- memcached base +- memcached server +- memcached port +- search type +- site logdebug +- site logfile + +twitteradminpanel + +- twitterimport enabled +- integration taguri +- integration source +- twitter consumer_secret +- twitter consumer_key +- twitter enabled + +(none) + +- inboxes enabled +- profile banned +- nickname blacklist + +useradminpanel + +- invite enabled +- profile biolimit +- nickname featured +- newuser welcome +- newuser default +- sessions debug +- sessions handle +- site closed +- site inviteonly + +emailadminpanel + +- emailpost enabled +- mail params +- mail domain_check +- mail backend + +(not sure) + +- tag dropoff +- popular dropoff +- message contentlimit + +locationadminpanel + +- location namespace + +groupadminpanel + +- group desclimit +- group maxaliases + +noticeadminpanel + +- notice contentlimit +- throttle enabled +- throttle count +- throttle timespan +- public autosource +- public blacklist +- public localonly +- site shorturllength +- site dupelimit + +siteadminpanel + ++ site broughtbyurl ++ site broughtby +- site private +- site fancy ++ site email ++ site name ++ site timezone ++ site language +- site ssl +- site textlimit +- site languages +- site sslserver +- site path +- site server +- site locale_path +- license title +- license url +- license image +- snapshot reporturl +- snapshot run +- snapshot frequency + +designadminpanel + +- site theme +- site logo +- theme path +- theme dir +- theme server +- background server +- background path +- background dir +- avatar server +- avatar path +- avatar dir +- design backgroundimage +- design disposition +- design linkcolor +- design textcolor +- design contentcolor +- design sidebarcolor +- design backgroundcolor + +daemonadminpanel + +- daemon group +- daemon user +- daemon piddir +- queue stomp_password +- queue stomp_username +- queue stomp_server +- queue enabled +- queue subsystem +- queue queue_basename + +attachmentadminpanel + +- oohembed endpoint +- attachments server +- attachments uploads +- attachments path +- attachments filecommand +- attachments dir +- attachments file_quota +- attachments monthly_quota +- attachments user_quota +- attachments supported + +xmppadminpanel + +- xmpp enabled +- xmpp host +- xmpp debug +- xmpp password +- xmpp public +- xmpp encryption +- xmpp server +- xmpp resource +- xmpp user +- xmpp port + +dbadminpanel + +- db mirror +- db class_location +- db database +- db require_prefix +- db quote_identifiers +- db class_prefix +- db schema_location +- db db_driver +- db type +- db schemacheck +- db utf8 + +smsadminpanel + +- sms enabled From 9a1a83e8ebe5ad39838e6363f1537a1a5232b9cb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 15 Nov 2009 14:37:47 +0100 Subject: [PATCH 19/22] Move some user-related stuff to useradminpanel from siteadminpanel --- actions/siteadminpanel.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index e4deea9620..1cf70362d7 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -92,7 +92,6 @@ class SiteadminpanelAction extends AdminPanelAction { static $settings = array('name', 'broughtby', 'broughtbyurl', 'email', 'timezone', 'language'); - static $booleans = array('closed', 'inviteonly', 'private'); $values = array(); @@ -244,20 +243,6 @@ class SiteAdminPanelForm extends Form $this->unli(); $this->li(); - $this->out->checkbox('closed', _('Closed'), - (bool) $this->value('closed'), - _('Is registration on this site prohibited?')); - - $this->unli(); - $this->li(); - - $this->out->checkbox('inviteonly', _('Invite-only'), - (bool) $this->value('inviteonly'), - _('Is registration on this site only open to invited users?')); - - $this->unli(); - $this->li(); - $this->out->checkbox('private', _('Private'), (bool) $this->value('private'), _('Prohibit anonymous users (not logged in) from viewing site?')); From 42d6c696916d545047339c77d36df2192555662b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 17 Nov 2009 10:59:50 -0500 Subject: [PATCH 20/22] add private flag back into site admin panel --- actions/siteadminpanel.php | 1 + panels.txt | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index 1cf70362d7..cd33d5adb1 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -92,6 +92,7 @@ class SiteadminpanelAction extends AdminPanelAction { static $settings = array('name', 'broughtby', 'broughtbyurl', 'email', 'timezone', 'language'); + static $booleans = array('private'); $values = array(); diff --git a/panels.txt b/panels.txt index 3787eb1900..030e3ddc72 100644 --- a/panels.txt +++ b/panels.txt @@ -52,10 +52,6 @@ emailadminpanel - popular dropoff - message contentlimit -locationadminpanel - -- location namespace - groupadminpanel - group desclimit From 4bbaa193d58a95906f0729d68d2af80ae235870e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 17 Nov 2009 14:50:54 -0500 Subject: [PATCH 21/22] remove panels.txt, move to http://status.net/wiki/Settings_by_panel --- panels.txt | 171 ----------------------------------------------------- 1 file changed, 171 deletions(-) delete mode 100644 panels.txt diff --git a/panels.txt b/panels.txt deleted file mode 100644 index 030e3ddc72..0000000000 --- a/panels.txt +++ /dev/null @@ -1,171 +0,0 @@ -servicesadminpanel - -- ping notify -- syslog priority -- syslog appname -- syslog facility -- memcached enabled -- memcached base -- memcached server -- memcached port -- search type -- site logdebug -- site logfile - -twitteradminpanel - -- twitterimport enabled -- integration taguri -- integration source -- twitter consumer_secret -- twitter consumer_key -- twitter enabled - -(none) - -- inboxes enabled -- profile banned -- nickname blacklist - -useradminpanel - -- invite enabled -- profile biolimit -- nickname featured -- newuser welcome -- newuser default -- sessions debug -- sessions handle -- site closed -- site inviteonly - -emailadminpanel - -- emailpost enabled -- mail params -- mail domain_check -- mail backend - -(not sure) - -- tag dropoff -- popular dropoff -- message contentlimit - -groupadminpanel - -- group desclimit -- group maxaliases - -noticeadminpanel - -- notice contentlimit -- throttle enabled -- throttle count -- throttle timespan -- public autosource -- public blacklist -- public localonly -- site shorturllength -- site dupelimit - -siteadminpanel - -+ site broughtbyurl -+ site broughtby -- site private -- site fancy -+ site email -+ site name -+ site timezone -+ site language -- site ssl -- site textlimit -- site languages -- site sslserver -- site path -- site server -- site locale_path -- license title -- license url -- license image -- snapshot reporturl -- snapshot run -- snapshot frequency - -designadminpanel - -- site theme -- site logo -- theme path -- theme dir -- theme server -- background server -- background path -- background dir -- avatar server -- avatar path -- avatar dir -- design backgroundimage -- design disposition -- design linkcolor -- design textcolor -- design contentcolor -- design sidebarcolor -- design backgroundcolor - -daemonadminpanel - -- daemon group -- daemon user -- daemon piddir -- queue stomp_password -- queue stomp_username -- queue stomp_server -- queue enabled -- queue subsystem -- queue queue_basename - -attachmentadminpanel - -- oohembed endpoint -- attachments server -- attachments uploads -- attachments path -- attachments filecommand -- attachments dir -- attachments file_quota -- attachments monthly_quota -- attachments user_quota -- attachments supported - -xmppadminpanel - -- xmpp enabled -- xmpp host -- xmpp debug -- xmpp password -- xmpp public -- xmpp encryption -- xmpp server -- xmpp resource -- xmpp user -- xmpp port - -dbadminpanel - -- db mirror -- db class_location -- db database -- db require_prefix -- db quote_identifiers -- db class_prefix -- db schema_location -- db db_driver -- db type -- db schemacheck -- db utf8 - -smsadminpanel - -- sms enabled From cb4acd40bf6bedd32f8352e73654e0fbff730cf8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 17 Nov 2009 14:51:17 -0500 Subject: [PATCH 22/22] more snapshot stuff in siteadminpanel --- actions/siteadminpanel.php | 106 +++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/actions/siteadminpanel.php b/actions/siteadminpanel.php index cd33d5adb1..2623e48edb 100644 --- a/actions/siteadminpanel.php +++ b/actions/siteadminpanel.php @@ -90,18 +90,24 @@ class SiteadminpanelAction extends AdminPanelAction function saveSettings() { - static $settings = array('name', 'broughtby', 'broughtbyurl', - 'email', 'timezone', 'language'); - static $booleans = array('private'); + static $settings = array('site' => array('name', 'broughtby', 'broughtbyurl', + 'email', 'timezone', 'language'), + 'snapshot' => array('run', 'reporturl', 'frequency')); + + static $booleans = array('site' => array('private')); $values = array(); - foreach ($settings as $setting) { - $values[$setting] = $this->trimmed($setting); + foreach ($settings as $section => $parts) { + foreach ($parts as $setting) { + $values[$section][$setting] = $this->trimmed($setting); + } } - foreach ($booleans as $setting) { - $values[$setting] = ($this->boolean($setting)) ? 1 : 0; + foreach ($booleans as $section => $parts) { + foreach ($parts as $setting) { + $values[$section][$setting] = ($this->boolean($setting)) ? 1 : 0; + } } // This throws an exception on validation errors @@ -114,8 +120,16 @@ class SiteadminpanelAction extends AdminPanelAction $config->query('BEGIN'); - foreach (array_merge($settings, $booleans) as $setting) { - Config::save('site', $setting, $values[$setting]); + 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'); @@ -127,34 +141,55 @@ class SiteadminpanelAction extends AdminPanelAction { // Validate site name - if (empty($values['name'])) { + if (empty($values['site']['name'])) { $this->clientError(_("Site name must have non-zero length.")); } // Validate email - $values['email'] = common_canonical_email($values['email']); + $values['site']['email'] = common_canonical_email($values['site']['email']); - if (empty($values['email'])) { + if (empty($values['site']['email'])) { $this->clientError(_('You must have a valid contact email address')); } - if (!Validate::email($values['email'], common_config('email', 'check_domain'))) { + if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) { $this->clientError(_('Not a valid email address')); } // Validate timezone - if (is_null($values['timezone']) || - !in_array($values['timezone'], DateTimeZone::listIdentifiers())) { + if (is_null($values['site']['timezone']) || + !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) { $this->clientError(_('Timezone not selected.')); return; } // Validate language - if (!is_null($language) && !in_array($language, array_keys(get_nice_language_list()))) { - $this->clientError(sprintf(_('Unknown language "%s"'), $language)); + if (!is_null($values['site']['language']) && + !in_array($values['site']['language'], array_keys(get_nice_language_list()))) { + $this->clientError(sprintf(_('Unknown language "%s"'), $values['site']['language'])); } + + // Validate report URL + + if (!is_null($values['snapshot']['reporturl']) && + !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) { + $this->clientError(_("Invalid snapshot report URL.")); + } + + // Validate snapshot run value + + if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) { + $this->clientError(_("Invalid snapshot run value.")); + } + + // Validate snapshot run value + + if (!Validate::number($values['snapshot']['frequency'])) { + $this->clientError(_("Snapshot frequency must be a number.")); + } + } } @@ -250,6 +285,33 @@ class SiteAdminPanelForm extends Form $this->unli(); + $this->li(); + + $snapshot = array('web' => _('Randomly during Web hit'), + 'cron' => _('In a scheduled job'), + 'never' => _('Never')); + + $this->out->dropdown('run', _('Data snapshots'), + $snapshot, _('When to send statistical data to status.net servers'), + false, $this->value('run', 'snapshot')); + + $this->unli(); + $this->li(); + + $this->input('frequency', _('Frequency'), + _('Snapshots will be sent once every N Web hits'), + 'snapshot'); + + $this->unli(); + + $this->li(); + + $this->input('reporturl', _('Report URL'), + _('Snapshots will be sent to this URL'), + 'snapshot'); + + $this->unli(); + $this->out->elementEnd('ul'); } @@ -260,28 +322,30 @@ class SiteAdminPanelForm extends Form * @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) + function input($setting, $title, $instructions, $section='site') { - $this->out->input($setting, $title, $this->value($setting), $instructions); + $this->out->input($setting, $title, $this->value($setting, $section), $instructions); } /** * Utility to simplify getting the posted-or-stored setting value * * @param string $setting Name of the setting + * @param string $main configuration section, default = 'site' * * @return string param value if posted, or current config value */ - function value($setting) + function value($setting, $main='site') { $value = $this->out->trimmed($setting); if (empty($value)) { - $value = common_config('site', $setting); + $value = common_config($main, $setting); } return $value; }