summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/designsettings.php227
-rw-r--r--actions/invite.php2
-rw-r--r--actions/replies.php3
-rw-r--r--actions/usergroups.php3
4 files changed, 131 insertions, 104 deletions
diff --git a/actions/designsettings.php b/actions/designsettings.php
index 5774b8537..8595cbc4c 100644
--- a/actions/designsettings.php
+++ b/actions/designsettings.php
@@ -22,6 +22,7 @@
* @category Settings
* @package Laconica
* @author Sarven Capadisli <csarven@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
* @copyright 2008-2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
@@ -33,8 +34,6 @@ if (!defined('LACONICA')) {
require_once INSTALLDIR.'/lib/accountsettingsaction.php';
-
-
class DesignsettingsAction extends AccountSettingsAction
{
/**
@@ -100,61 +99,82 @@ class DesignsettingsAction extends AccountSettingsAction
$this->element('legend', null, _('Change colours'));
$this->elementStart('ul', 'form_data');
- //This is a JSON object in the DB field. Here for testing. Remove later.
- $userSwatch = '{"body":{"background-color":"#F0F2F5"},
- "#content":{"background-color":"#FFFFFF"},
- "#aside_primary":{"background-color":"#CEE1E9"},
- "html body":{"color":"#000000"},
- "a":{"color":"#002E6E"}}';
-
- //Default theme swatch -- Where should this be stored?
- $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'),
- '#content' => array('background-color' => '#FFFFFF'),
- '#aside_primary' => array('background-color' => '#CEE1E9'),
- 'html body' => array('color' => '#000000'),
- 'a' => array('color' => '#002E6E'));
-
- $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
-
- $s = 0;
- $labelSwatch = array('Background',
- 'Content',
- 'Sidebar',
- 'Text',
- 'Links');
- foreach($userSwatch as $propertyvalue => $value) {
- $foo = array_values($value);
- $this->elementStart('li');
- $this->element('label', array('for' => 'swatch-'.$s), _($labelSwatch[$s]));
- $this->element('input', array('name' => 'swatch-'.$s, //prefer swatch[$s] ?
- 'type' => 'text',
- 'id' => 'swatch-'.$s,
- 'class' => 'swatch',
- 'maxlength' => '7',
- 'size' => '7',
- 'value' => $foo[0]));
- $this->elementEnd('li');
- $s++;
+ $design = $user->getDesign();
+
+ if (empty($design)) {
+ $design = $this->defaultDesign();
}
- $this->elementEnd('ul');
- $this->elementEnd('fieldset');
+ $this->elementStart('li');
+ $this->element('label', array('for' => 'swatch-5'), _('Background'));
+ $this->element('input', array('name' => 'design_background',
+ 'type' => 'text',
+ 'id' => 'swatch-5',
+ 'class' => 'swatch',
+ 'maxlength' => '7',
+ 'size' => '7',
+ 'value' => $design->backgroundcolor));
+ $this->elementEnd('li');
+
+ $this->elementStart('li');
+ $this->element('label', array('for' => 'swatch-1'), _('Content'));
+ $this->element('input', array('name' => 'design_content',
+ 'type' => 'text',
+ 'id' => 'swatch-1',
+ 'class' => 'swatch',
+ 'maxlength' => '7',
+ 'size' => '7',
+ 'value' => $design->contentcolor));
+ $this->elementEnd('li');
+
+ $this->elementStart('li');
+ $this->element('label', array('for' => 'swatch-2'), _('Sidebar'));
+ $this->element('input', array('name' => 'design_sidebar',
+ 'type' => 'text',
+ 'id' => 'swatch-2',
+ 'class' => 'swatch',
+ 'maxlength' => '7',
+ 'size' => '7',
+ 'value' => $design->sidebarcolor));
+ $this->elementEnd('li');
+
+ $this->elementStart('li');
+ $this->element('label', array('for' => 'swatch-3'), _('Text'));
+ $this->element('input', array('name' => 'design_text',
+ 'type' => 'text',
+ 'id' => 'swatch-3',
+ 'class' => 'swatch',
+ 'maxlength' => '7',
+ 'size' => '7',
+ 'value' => $design->textcolor));
+ $this->elementEnd('li');
+
+ $this->elementStart('li');
+ $this->element('label', array('for' => 'swatch-4'), _('Links'));
+ $this->element('input', array('name' => 'design_links',
+ 'type' => 'text',
+ 'id' => 'swatch-4',
+ 'class' => 'swatch',
+ 'maxlength' => '7',
+ 'size' => '7',
+ 'value' => $design->linkcolor));
+
+ $this->elementEnd('li');
+
+ $this->elementEnd('ul');
+ $this->elementEnd('fieldset');
+
+ $this->element('input', array('id' => 'settings_design_reset',
+ 'type' => 'reset',
+ 'value' => 'Reset',
+ 'class' => 'submit form_action-primary',
+ 'title' => _('Reset back to default')));
+
+ $this->submit('save', _('Save'), 'submit form_action-secondary',
+ 'save', _('Save design'));
- $this->element('input', array('id' => 'settings_design_reset',
- 'type' => 'reset',
- 'value' => 'Reset',
- 'class' => 'submit form_action-primary',
- 'title' => _('Reset back to default')));
- $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design'));
-
-/*TODO: Check submitted form values:
-json_encode(form values)
-if submitted Swatch == DefaultSwatch, don't store in DB.
-else store in BD
-*/
$this->elementEnd('fieldset');
$this->elementEnd('form');
-
}
/**
@@ -168,63 +188,23 @@ else store in BD
function handlePost()
{
- /*
// CSRF protection
-
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. '.
- 'Try again, please.'));
- return;
- }
-
- $user = common_current_user();
- assert(!is_null($user)); // should already be checked
-
- // FIXME: scrub input
-
- $newpassword = $this->arg('newpassword');
- $confirm = $this->arg('confirm');
-
- # Some validation
-
- if (strlen($newpassword) < 6) {
- $this->showForm(_('Password must be 6 or more characters.'));
- return;
- } else if (0 != strcmp($newpassword, $confirm)) {
- $this->showForm(_('Passwords don\'t match.'));
- return;
- }
-
- if ($user->password) {
- $oldpassword = $this->arg('oldpassword');
-
- if (!common_check_user($user->nickname, $oldpassword)) {
- $this->showForm(_('Incorrect old password'));
- return;
- }
- }
-
- $original = clone($user);
-
- $user->password = common_munge_password($newpassword, $user->id);
-
- $val = $user->validate();
- if ($val !== true) {
- $this->showForm(_('Error saving user; invalid.'));
+ 'Try again, please.'));
return;
}
- if (!$user->update($original)) {
- $this->serverError(_('Can\'t save new password.'));
- return;
+ if ($this->arg('save')) {
+ $this->saveDesign();
+ } else if ($this->arg('reset')) {
+ $this->resetDesign();
+ } else {
+ $this->showForm(_('Unexpected form submission.'));
}
-
- $this->showForm(_('Password saved.'), true);
- */
}
-
/**
* Add the Farbtastic stylesheet
*
@@ -261,4 +241,53 @@ else store in BD
$this->element('script', array('type' => 'text/javascript',
'src' => $farbtasticGo));
}
+
+ /**
+ * Get a default user design
+ *
+ * @return Design design
+ */
+
+ function defaultDesign()
+ {
+ $defaults = common_config('site', 'design');
+
+ $design = new Design();
+ $design->backgroundcolor = $defaults['backgroundcolor'];
+ $design->contentcolor = $defaults['contentcolor'];
+ $design->sidebarcolor = $defaults['sidebarcolor'];
+ $design->textcolor = $defaults['textcolor'];
+ $design->linkcolor = $defaults['linkcolor'];
+ $design->backgroundimage = $defaults['backgroundimage'];
+
+ return $design;
+ }
+
+ /**
+ * Save the user's design settings
+ *
+ * @return void
+ */
+
+ function saveDesign()
+ {
+ $user = common_current_user();
+
+
+
+ $this->showForm(_('Design preferences saved.'), true);
+ }
+
+ /**
+ * Reset design settings to previous saved value if any, or
+ * the defaults
+ *
+ * @return void
+ */
+
+ function resetDesign()
+ {
+ $this->showForm(_('Design preferences reset.'), true);
+ }
+
}
diff --git a/actions/invite.php b/actions/invite.php
index 7e52cdbcc..c793f5824 100644
--- a/actions/invite.php
+++ b/actions/invite.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-class InviteAction extends Action
+class InviteAction extends CurrentUserDesignAction
{
var $mode = null;
var $error = null;
diff --git a/actions/replies.php b/actions/replies.php
index eac4d0a3a..d7ed440e9 100644
--- a/actions/replies.php
+++ b/actions/replies.php
@@ -45,9 +45,8 @@ require_once INSTALLDIR.'/lib/feedlist.php';
* @link http://laconi.ca/
*/
-class RepliesAction extends Action
+class RepliesAction extends OwnerDesignAction
{
- var $user = null;
var $page = null;
/**
diff --git a/actions/usergroups.php b/actions/usergroups.php
index e3088dcbd..7ead6e6e4 100644
--- a/actions/usergroups.php
+++ b/actions/usergroups.php
@@ -46,9 +46,8 @@ require_once INSTALLDIR.'/lib/grouplist.php';
* @link http://laconi.ca/
*/
-class UsergroupsAction extends Action
+class UsergroupsAction extends OwnerDesignAction
{
- var $user = null;
var $page = null;
var $profile = null;