From 3a44885b7ffcdcbb1b5cc8e972a3f89dd02b4c74 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 20:50:08 -0400 Subject: [PATCH 01/56] reformat designsettings.php --- actions/designsettings.php | 84 +++++++------------------------------- 1 file changed, 14 insertions(+), 70 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 315e5a199c..8d8e5bad88 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -33,8 +33,6 @@ if (!defined('LACONICA')) { require_once INSTALLDIR.'/lib/accountsettingsaction.php'; - - class DesignsettingsAction extends AccountSettingsAction { /** @@ -82,8 +80,8 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('legend', null, _('Change background image')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - $this->element('label', array('for' => 'design_ background-image_file'), - _('Upload file')); + $this->element('label', array('for' => 'design_ background-image_file'), + _('Upload file')); $this->element('input', array('name' => 'design_background-image_file', 'type' => 'file', 'id' => 'design_background-image_file')); @@ -101,11 +99,11 @@ class DesignsettingsAction extends AccountSettingsAction $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"}}'; + $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'), @@ -147,14 +145,13 @@ class DesignsettingsAction extends AccountSettingsAction '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 -*/ + /*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 +165,10 @@ 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.')); - return; - } - - if (!$user->update($original)) { - $this->serverError(_('Can\'t save new password.')); - return; - } - - $this->showForm(_('Password saved.'), true); - */ + // TODO: implement this + return; } - /** * Add the Farbtastic stylesheet * From 2f0fe8e33ae29557911a0d1896a2c1b9725b5e55 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 20:54:07 -0400 Subject: [PATCH 02/56] add design table to DB --- db/laconica.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db/laconica.sql b/db/laconica.sql index 0b20bc172c..d42c20e2a1 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -482,3 +482,13 @@ create table file_to_post ( unique(file_id, post_id) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table design ( + id integer primary key auto_increment comment 'design ID', + backgroundcolor integer comment 'main background color', + contentcolor integer comment 'content area background color', + sidebarcolor integer comment 'sidebar background color', + textcolor integer comment 'text color', + linkcolor integer comment 'link color', + backgroundimage varchar(255) comment 'background image, if any' +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; From c63622f05e1a29c6739952e626965c18c913829c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 21:10:00 -0400 Subject: [PATCH 03/56] add design classes --- classes/Design.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ classes/laconica.ini | 12 +++++++++++ 2 files changed, 59 insertions(+) create mode 100755 classes/Design.php diff --git a/classes/Design.php b/classes/Design.php new file mode 100755 index 0000000000..cca41ce0cb --- /dev/null +++ b/classes/Design.php @@ -0,0 +1,47 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +/** + * Table Definition for design + */ + +require_once 'classes/Memcached_DataObject'; + +class Design extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'design'; // table name + public $id; // int(4) primary_key not_null + public $backgroundcolor; // int(4) + public $contentcolor; // int(4) + public $sidebarcolor; // int(4) + public $textcolor; // int(4) + public $linkcolor; // int(4) + public $backgroundimage; // varchar(255) + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/laconica.ini b/classes/laconica.ini index 92bbb35d4c..105bc9ec84 100644 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -37,6 +37,18 @@ modified = 384 [consumer__keys] consumer_key = K +[design] +id = 129 +backgroundcolor = 1 +contentcolor = 1 +sidebarcolor = 1 +textcolor = 1 +linkcolor = 1 +backgroundimage = 2 + +[design__keys] +id = N + [fave] notice_id = 129 user_id = 129 From 21aad16b58e98f61aded9c102adaef7616a6728f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 21:10:27 -0400 Subject: [PATCH 04/56] fix x bit on Design.php --- classes/Design.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 classes/Design.php diff --git a/classes/Design.php b/classes/Design.php old mode 100755 new mode 100644 From 748c744a02ab12f36a275d9020c1b2b5ead9f002 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 23:13:09 -0400 Subject: [PATCH 05/56] add a method to Design to show custom CSS --- classes/Design.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/classes/Design.php b/classes/Design.php index cca41ce0cb..c1b6f73e03 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -44,4 +44,14 @@ class Design extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + function showCSS($out) + { + $out->element('stylesheet', array('type' => 'text/css'), + 'body { background-color: #' . dechex($this->backgroundcolor) . '} '."\n". + '#content { background-color #' . dechex($this->contentcolor) . '} '."\n". + '#aside_primary { background-color #'. dechex($this->sidebarcolor) .'} '."\n". + 'html body { color: #'. dechex($this->textcolor) .'} '."\n". + 'a { color: #' . dechex($this->linkcolor) . '} '."\n"); + } } From 3f5252c168de7c0a1ffb9625e3926543c5586c6e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 23:43:08 -0400 Subject: [PATCH 06/56] add fields to support designs for users --- classes/laconica.ini | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 classes/laconica.ini diff --git a/classes/laconica.ini b/classes/laconica.ini old mode 100644 new mode 100755 index 105bc9ec84..450af36215 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -1,3 +1,4 @@ + [avatar] profile_id = 129 original = 17 @@ -425,6 +426,8 @@ urlshorteningservice = 2 inboxed = 17 created = 142 modified = 384 +design_id = 1 +viewdesigns = 17 [user__keys] id = K From 78564c21d46d56a2cf413b9ba804d5a60430f06e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 May 2009 23:43:38 -0400 Subject: [PATCH 07/56] schema changes for user support of designs --- db/laconica.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/laconica.sql b/db/laconica.sql index d42c20e2a1..c87340e8e0 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -41,6 +41,7 @@ create table sms_carrier ( /* local users */ create table user ( + id integer primary key comment 'foreign key to profile table' references profile (id), nickname varchar(64) unique key comment 'nickname or username, duped in profile', password varchar(255) comment 'salted password, can be null for OpenID users', @@ -71,6 +72,8 @@ create table user ( inboxed tinyint default 0 comment 'has an inbox been created for this user?', created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified', + design_id integer comment 'id of a design' references design(id), + viewdesigns tinyint default 1 comment 'whether to view user-provided designs', index user_smsemail_idx (smsemail) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; From d92a018cd2b199213cbd66f27dbabb460d3d55c9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 22:44:01 -0400 Subject: [PATCH 08/56] get a design for each page --- lib/action.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/action.php b/lib/action.php index 6a69d26518..e8aba5b89a 100644 --- a/lib/action.php +++ b/lib/action.php @@ -224,6 +224,16 @@ class Action extends HTMLOutputter // lawsuit 'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" />getDesign(); + if (!empty($design)) { + $cur = common_current_user(); + if (empty($cur) || $cur->viewdesigns) { + $design->showCSS($this); + } + } + Event::handle('EndShowDesign', array($this, $design)); + } Event::handle('EndShowStyles', array($this)); } } @@ -248,7 +258,6 @@ class Action extends HTMLOutputter // lawsuit 'src' => common_path('js/jquery.joverlay.min.js')), ' '); - Event::handle('EndShowJQueryScripts', array($this)); } if (Event::handle('StartShowLaconicaScripts', array($this))) { @@ -1095,4 +1104,19 @@ class Action extends HTMLOutputter // lawsuit 'title' => _('Previous'))); } } + + /** + * A design for this action + * + * A design (colors and background) for the current page. May be + * the user's design, or a group's design, or a site design. + * + * @return array Feed object to show in head and links + */ + + function getDesign() + { + // XXX: return site design by default + return null; + } } From 4ec5ea510cd5be39c13c2cf3bc9f9c1c8ac5df82 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:09:01 -0400 Subject: [PATCH 09/56] fix return value documentation for getDesign --- lib/action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/action.php b/lib/action.php index e8aba5b89a..55fb7c0896 100644 --- a/lib/action.php +++ b/lib/action.php @@ -1111,7 +1111,7 @@ class Action extends HTMLOutputter // lawsuit * A design (colors and background) for the current page. May be * the user's design, or a group's design, or a site design. * - * @return array Feed object to show in head and links + * @return Design a design object to use */ function getDesign() From eaac0f8e58774a67fd9257ee0cd46c786cb5718b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:09:33 -0400 Subject: [PATCH 10/56] add an action base class for actions that show the owner's design --- lib/ownerdesignaction.php | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/ownerdesignaction.php diff --git a/lib/ownerdesignaction.php b/lib/ownerdesignaction.php new file mode 100644 index 0000000000..c47633bdb2 --- /dev/null +++ b/lib/ownerdesignaction.php @@ -0,0 +1,72 @@ +. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @copyright 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/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for actions that use the page owner's design + * + * Some pages have a clear "owner" -- like the profile page, subscriptions + * pages, etc. This superclass uses that owner's chosen design for the page + * design. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + */ + +class OwnerDesignAction extends Action { + + /** The user for this page. */ + + var $user = null; + + /** + * A design for this action + * + * if the user attribute has been set, returns that user's + * design. + * + * @return Design a design object to use + */ + + function getDesign() + { + if (empty($this->user)) { + return null; + } + + return $this->user->getDesign(); + } +} From 63ad980767fc10053eea5a5ca009dda65af42de8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:11:36 -0400 Subject: [PATCH 11/56] current user design action --- lib/currentuserdesignaction.php | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lib/currentuserdesignaction.php diff --git a/lib/currentuserdesignaction.php b/lib/currentuserdesignaction.php new file mode 100644 index 0000000000..2975256557 --- /dev/null +++ b/lib/currentuserdesignaction.php @@ -0,0 +1,69 @@ +. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @copyright 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/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for actions that use the current user's design + * + * Some pages (settings in particular) use the current user's chosen + * design. This superclass returns that design. + * + * @category Action + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + */ + +class CurrentUserDesignAction extends Action +{ + /** + * A design for this action + * + * if the user attribute has been set, returns that user's + * design. + * + * @return Design a design object to use + */ + + function getDesign() + { + $cur = common_current_user(); + + if (empty($cur)) { + return null; + } + + return $cur->getDesign(); + } +} From b0e92c75cc19a91e1ea4bbb8009f6f66dc56231b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:16:52 -0400 Subject: [PATCH 12/56] move design items before timestamps --- db/laconica.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/laconica.sql b/db/laconica.sql index c87340e8e0..2ad482abac 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -70,11 +70,12 @@ create table user ( autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us', urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs', inboxed tinyint default 0 comment 'has an inbox been created for this user?', - created datetime not null comment 'date this record was created', - modified timestamp comment 'date this record was modified', design_id integer comment 'id of a design' references design(id), viewdesigns tinyint default 1 comment 'whether to view user-provided designs', + created datetime not null comment 'date this record was created', + modified timestamp comment 'date this record was modified', + index user_smsemail_idx (smsemail) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; From 91fc1e36bc268aa2bd7345206cd0e520d91aac26 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:26:29 -0400 Subject: [PATCH 13/56] update User.php with new design-related fields --- classes/User.php | 7 +++---- classes/laconica.ini | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/classes/User.php b/classes/User.php index ea8ba40817..22090b9867 100644 --- a/classes/User.php +++ b/classes/User.php @@ -62,14 +62,13 @@ class User extends Memcached_DataObject public $autosubscribe; // tinyint(1) public $urlshorteningservice; // varchar(50) default_ur1.ca public $inboxed; // tinyint(1) + public $design_id; // int(4) + public $viewdesigns; // tinyint(1) default_1 public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) - { - return Memcached_DataObject::staticGet('User',$k,$v); - } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/laconica.ini b/classes/laconica.ini index 450af36215..07aa016fef 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -424,10 +424,10 @@ uri = 2 autosubscribe = 17 urlshorteningservice = 2 inboxed = 17 -created = 142 -modified = 384 design_id = 1 viewdesigns = 17 +created = 142 +modified = 384 [user__keys] id = K From 705abf31ee65b821f1c64921005f1814cc83733c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:27:42 -0400 Subject: [PATCH 14/56] add getDesign to User --- classes/User.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/User.php b/classes/User.php index 22090b9867..8cc8285f1e 100644 --- a/classes/User.php +++ b/classes/User.php @@ -684,4 +684,9 @@ class User extends Memcached_DataObject return ($cnt > 0); } + + function getDesign() + { + return Design::staticGet('id', $this->design_id); + } } From d7e3bab0b81fa7cd7f120e4ff53f89c70c18bad5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:34:05 -0400 Subject: [PATCH 15/56] fix require_once in Design.php --- classes/Design.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Design.php b/classes/Design.php index c1b6f73e03..bb1e917e3e 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -23,7 +23,7 @@ if (!defined('LACONICA')) { exit(1); } * Table Definition for design */ -require_once 'classes/Memcached_DataObject'; +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; class Design extends Memcached_DataObject { From 9c2f04afc6e70032da5aeb0441e6e0a9b0ffe253 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:35:04 -0400 Subject: [PATCH 16/56] make some of the actions show the user's design --- actions/replies.php | 3 +-- actions/showfavorites.php | 5 +---- actions/usergroups.php | 3 +-- lib/galleryaction.php | 3 +-- lib/profileaction.php | 3 +-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/actions/replies.php b/actions/replies.php index dfb520d649..5d84f6428c 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/showfavorites.php b/actions/showfavorites.php index eed62a2ab3..839f083dd4 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -45,10 +45,8 @@ require_once INSTALLDIR.'/lib/feedlist.php'; * @link http://laconi.ca/ */ -class ShowfavoritesAction extends Action +class ShowfavoritesAction extends OwnerDesignAction { - /** User we're getting the faves of */ - var $user = null; /** Page of the faves we're on */ var $page = null; @@ -161,7 +159,6 @@ class ShowfavoritesAction extends Action $this->page, 'showfavorites', array('nickname' => $this->user->nickname)); } - /** * show the personal group nav * diff --git a/actions/usergroups.php b/actions/usergroups.php index e3088dcbd8..7ead6e6e49 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; diff --git a/lib/galleryaction.php b/lib/galleryaction.php index 8fa11a7562..498c828514 100644 --- a/lib/galleryaction.php +++ b/lib/galleryaction.php @@ -27,10 +27,9 @@ require_once INSTALLDIR.'/lib/profilelist.php'; define('AVATARS_PER_PAGE', 80); -class GalleryAction extends Action +class GalleryAction extends OwnerDesignAction { var $profile = null; - var $user = null; var $page = null; var $tag = null; diff --git a/lib/profileaction.php b/lib/profileaction.php index a3437ff4dd..a14d3846e6 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -47,9 +47,8 @@ require_once INSTALLDIR.'/lib/groupminilist.php'; * @link http://laconi.ca/ */ -class ProfileAction extends Action +class ProfileAction extends OwnerDesignAction { - var $user = null; var $page = null; var $profile = null; var $tag = null; From 91e088d341bc51a41ec310502f85bf0d2398bd90 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:40:11 -0400 Subject: [PATCH 17/56] make some actions CurrentUserDesignActions --- lib/mailbox.php | 8 ++++---- lib/settingsaction.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mailbox.php b/lib/mailbox.php index 01bbf5721a..766510a47b 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -47,11 +47,11 @@ define('MESSAGES_PER_PAGE', 20); * @see OutboxAction */ -class MailboxAction extends PersonalAction +class MailboxAction extends CurrentUserDesignAction { var $page = null; - function prepare($args) + function prepare($args) { parent::prepare($args); @@ -265,12 +265,12 @@ class MailboxAction extends PersonalAction * Returns either the name (and link) of the API client that posted the notice, * or one of other other channels. * - * @param string $source the source of the message + * @param string $source the source of the message * * @return void */ - function showSource($source) + function showSource($source) { $source_name = _($source); switch ($source) { diff --git a/lib/settingsaction.php b/lib/settingsaction.php index db20c58043..17d3a2f64d 100644 --- a/lib/settingsaction.php +++ b/lib/settingsaction.php @@ -43,7 +43,7 @@ if (!defined('LACONICA')) { * @see Widget */ -class SettingsAction extends Action +class SettingsAction extends CurrentUserDesignAction { /** * A message for the user. From d60c399d825dc373630042d12f90c01886cc32f5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:40:27 -0400 Subject: [PATCH 18/56] remove old, unused PersonalAction and StreamAction --- lib/attachmentlist.php | 2 -- lib/noticelist.php | 2 -- lib/personal.php | 60 ------------------------------------------ lib/stream.php | 32 ---------------------- 4 files changed, 96 deletions(-) delete mode 100644 lib/personal.php delete mode 100644 lib/stream.php diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 9485fe3d65..8d6d19f2aa 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -46,7 +46,6 @@ if (!defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ * @see Notice - * @see StreamAction * @see NoticeListItem * @see ProfileNoticeList */ @@ -203,7 +202,6 @@ class AttachmentListItem extends Widget if ($this->attachment->url !== $this->title()) $this->out->element('span', null, " ({$this->attachment->url})"); - $this->out->elementEnd('h4'); } diff --git a/lib/noticelist.php b/lib/noticelist.php index a521321719..ba35265096 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -49,7 +49,6 @@ require_once INSTALLDIR.'/lib/disfavorform.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ * @see Notice - * @see StreamAction * @see NoticeListItem * @see ProfileNoticeList */ @@ -231,7 +230,6 @@ else $this->out->elementStart('p', array('class' => 'entry-attachments', 'style' => "float: right; width: $width_att; background: url($clip) no-repeat; text-align: right; height: $height;")); $this->out->element('a', array('class' => $att_class, 'style' => "text-decoration: none; padding-top: $top; display: block; height: $height;", 'href' => $href, 'title' => "# of attachments: $count"), $count === 1 ? '' : $count); - $this->out->elementEnd('p'); } diff --git a/lib/personal.php b/lib/personal.php deleted file mode 100644 index f92732375b..0000000000 --- a/lib/personal.php +++ /dev/null @@ -1,60 +0,0 @@ -. - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @author Sarven Capadisli - * @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/ - */ - -if (!defined('LACONICA')) { - exit(1); -} - -/** - * Base class for user profile page - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class PersonalAction extends Action -{ - - var $user = null; - - function isReadOnly($args) - { - return true; - } - - function handle($args) - { - parent::handle($args); - } - -} diff --git a/lib/stream.php b/lib/stream.php deleted file mode 100644 index 0cb9e0bf4f..0000000000 --- a/lib/stream.php +++ /dev/null @@ -1,32 +0,0 @@ -. - */ - -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/personal.php'); -require_once(INSTALLDIR.'/lib/noticelist.php'); - -class StreamAction extends PersonalAction -{ - function show_notice_list($notice) - { - $nl = new NoticeList($notice); - return $nl->show(); - } -} From 6335c9cf59b384da24506c4a3f799315fbbc4b09 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 23 May 2009 23:42:19 -0400 Subject: [PATCH 19/56] make invite use the current user's design --- actions/invite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/invite.php b/actions/invite.php index 7e52cdbcc6..c793f58249 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; From b3628b78448266fda2368f1317e70d1cca45ac17 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 27 May 2009 14:49:20 -0400 Subject: [PATCH 20/56] start using design object --- actions/designsettings.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 8d8e5bad88..da88940427 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -98,28 +98,18 @@ 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"}}'; + $design = $user->getDesign(); - //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')); + if (empty($design)) { + $design = $this->defaultDesign(); + } - $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'); @@ -150,6 +140,7 @@ class DesignsettingsAction extends AccountSettingsAction if submitted Swatch == DefaultSwatch, don't store in DB. else store in BD */ + $this->elementEnd('fieldset'); $this->elementEnd('form'); } From 946d016df2a5e0af5e1b4b983b30c113dd02b4ea Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 14 Jun 2009 02:03:50 -0700 Subject: [PATCH 21/56] Reworked output for design settings page --- actions/designsettings.php | 162 +++++++++++++++++++++++++++++-------- lib/common.php | 7 ++ 2 files changed, 135 insertions(+), 34 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 66476e6777..8595cbc4c6 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -22,6 +22,7 @@ * @category Settings * @package Laconica * @author Sarven Capadisli + * @author Zach Copley * @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/ @@ -104,42 +105,73 @@ class DesignsettingsAction extends AccountSettingsAction $design = $this->defaultDesign(); } - $labelSwatch = array('Background', - 'Content', - 'Sidebar', - 'Text', - 'Links'); + $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'); - 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++; - } + $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->elementEnd('ul'); - $this->elementEnd('fieldset'); + $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->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->elementEnd('li'); - /*TODO: Check submitted form values: - json_encode(form values) - if submitted Swatch == DefaultSwatch, don't store in DB. - else store in BD - */ + $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->elementEnd('fieldset'); $this->elementEnd('form'); @@ -156,8 +188,21 @@ class DesignsettingsAction extends AccountSettingsAction function handlePost() { - // TODO: implement this - return; + // 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; + } + + if ($this->arg('save')) { + $this->saveDesign(); + } else if ($this->arg('reset')) { + $this->resetDesign(); + } else { + $this->showForm(_('Unexpected form submission.')); + } } /** @@ -196,4 +241,53 @@ class DesignsettingsAction extends AccountSettingsAction $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/lib/common.php b/lib/common.php index 5aafdfe0ee..a55fb264e1 100644 --- a/lib/common.php +++ b/lib/common.php @@ -72,6 +72,13 @@ $config = 'server' => $_server, 'theme' => 'default', 'skin' => 'default', + 'design' => + array('backgroundcolor' => '#F0F2F5', + 'contentcolor' => '#FFFFFF', + 'sidebarcolor' => '#CEE1E9', + 'textcolor' => '#000000', + 'linkcolor' => '#002E6E', + 'backgroundimage' => null), 'path' => $_path, 'logfile' => null, 'logo' => null, From 807d84d448fb453de777d7a1ef938150bb03de3e Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 12:57:08 -0700 Subject: [PATCH 22/56] Small fix to correct the order of defined color prefs --- actions/designsettings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 8595cbc4c6..dba983fdf7 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -106,10 +106,10 @@ class DesignsettingsAction extends AccountSettingsAction } $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-5'), _('Background')); + $this->element('label', array('for' => 'swatch-0'), _('Background')); $this->element('input', array('name' => 'design_background', 'type' => 'text', - 'id' => 'swatch-5', + 'id' => 'swatch-0', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', From 2f693c4c9453fc61bea960ba8767fdf68e5130cd Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 15 Jun 2009 21:02:12 +0000 Subject: [PATCH 23/56] Updated swatch numbering --- actions/designsettings.php | 21 ++++++++++----------- js/farbtastic/farbtastic.go.js | 12 ++++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index dba983fdf7..46a5843f87 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -106,10 +106,10 @@ class DesignsettingsAction extends AccountSettingsAction } $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-0'), _('Background')); + $this->element('label', array('for' => 'swatch-1'), _('Background')); $this->element('input', array('name' => 'design_background', 'type' => 'text', - 'id' => 'swatch-0', + 'id' => 'swatch-1', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -117,10 +117,10 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('li'); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-1'), _('Content')); + $this->element('label', array('for' => 'swatch-2'), _('Content')); $this->element('input', array('name' => 'design_content', 'type' => 'text', - 'id' => 'swatch-1', + 'id' => 'swatch-2', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -128,10 +128,10 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('li'); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-2'), _('Sidebar')); + $this->element('label', array('for' => 'swatch-3'), _('Sidebar')); $this->element('input', array('name' => 'design_sidebar', 'type' => 'text', - 'id' => 'swatch-2', + 'id' => 'swatch-3', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -139,10 +139,10 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('li'); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-3'), _('Text')); + $this->element('label', array('for' => 'swatch-4'), _('Text')); $this->element('input', array('name' => 'design_text', 'type' => 'text', - 'id' => 'swatch-3', + 'id' => 'swatch-4', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -150,15 +150,14 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('li'); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-4'), _('Links')); + $this->element('label', array('for' => 'swatch-5'), _('Links')); $this->element('input', array('name' => 'design_links', 'type' => 'text', - 'id' => 'swatch-4', + 'id' => 'swatch-5', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', 'value' => $design->linkcolor)); - $this->elementEnd('li'); $this->elementEnd('ul'); diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 0149eca7d9..4e0493b40a 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -10,19 +10,19 @@ $(document).ready(function() { function UpdateColors(S) { C = $(S).val(); switch (parseInt(S.id.slice(-1))) { - case 0: default: + case 1: default: $('body').css({'background-color':C}); break; - case 1: + case 2: $('#content').css({'background-color':C}); break; - case 2: + case 3: $('#aside_primary').css({'background-color':C}); break; - case 3: - $('body').css({'color':C}); - break; case 4: + $('html body').css({'color':C}); + break; + case 5: $('a').css({'color':C}); break; } From bd8f9a979acb1607e00499dfba223a51b57596af Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 16 Jun 2009 02:33:10 +0000 Subject: [PATCH 24/56] Converts user entry in the form of '#1B2' into '#11BB22' for user design swatches --- js/farbtastic/farbtastic.go.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 4e0493b40a..2f202ced1f 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -59,7 +59,9 @@ $(document).ready(function() { swatches .each(SynchColors) .blur(function() { - $(this).val($(this).val().toUpperCase()); + tv = $(this).val(); + $(this).val(tv.toUpperCase()); + (tv.length == 4) ? ((tv[0] == '#') ? $(this).val('#'+tv[1]+tv[1]+tv[2]+tv[2]+tv[3]+tv[3]) : '') : ''; }) .focus(function() { $('#color-picker').show(); From 20d93508776398627f5aff64b83bd20a362cb45d Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 20:21:33 -0700 Subject: [PATCH 25/56] User design setting save now --- actions/designsettings.php | 250 ++++++++++++++++++++++++++----------- lib/webcolor.php | 191 ++++++++++++++++++++++++++++ 2 files changed, 370 insertions(+), 71 deletions(-) create mode 100644 lib/webcolor.php diff --git a/actions/designsettings.php b/actions/designsettings.php index dba983fdf7..0f7c271946 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -32,7 +32,8 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/accountsettingsaction.php'; +require_once INSTALLDIR . '/lib/accountsettingsaction.php'; +require_once INSTALLDIR . '/lib/WebColor.php'; class DesignsettingsAction extends AccountSettingsAction { @@ -81,7 +82,7 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('legend', null, _('Change background image')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - $this->element('label', array('for' => 'design_background-image_file'), + $this->element('label', array('for' => 'design_background-image_file'), _('Upload file')); $this->element('input', array('name' => 'design_background-image_file', 'type' => 'file', @@ -105,61 +106,79 @@ class DesignsettingsAction extends AccountSettingsAction $design = $this->defaultDesign(); } - $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-0'), _('Background')); - $this->element('input', array('name' => 'design_background', - 'type' => 'text', - 'id' => 'swatch-0', - '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'); + try { - $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'); + $bgcolor = new WebColor($design->backgroundcolor); - $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->elementStart('li'); + $this->element('label', array('for' => 'swatch-0'), _('Background')); + $this->element('input', array('name' => 'design_background', + 'type' => 'text', + 'id' => 'swatch-0', + 'class' => 'swatch', + 'maxlength' => '7', + 'size' => '7', + 'value' => '#' . $bgcolor->hexValue())); + $this->elementEnd('li'); - $this->elementEnd('li'); + + $ccolor = new WebColor($design->contentcolor); + + $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' => '#' . $ccolor->hexValue())); + $this->elementEnd('li'); + + $sbcolor = new WebColor($design->sidebarcolor); + + $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' => '#' . $sbcolor->hexValue())); + $this->elementEnd('li'); + + $tcolor = new WebColor($design->textcolor); + + $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' => '#' . $tcolor->hexValue())); + $this->elementEnd('li'); + + $lcolor = new WebColor($design->linkcolor); + + $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' => '#' . $lcolor->hexValue())); + + $this->elementEnd('li'); + + } catch (WebColorException $e) { + common_log(LOG_ERR, 'Bad color values in design ID: ' . + $design->id); + } $this->elementEnd('ul'); $this->elementEnd('fieldset'); @@ -169,7 +188,7 @@ class DesignsettingsAction extends AccountSettingsAction 'value' => 'Reset', 'class' => 'submit form_action-primary', 'title' => _('Reset back to default'))); - + $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design')); @@ -241,40 +260,129 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('script', array('type' => 'text/javascript', 'src' => $farbtasticGo)); } - + /** * Get a default user design * - * @return Design 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']; + + try { + + $color = new WebColor(); + + $color->parseColor($defaults['backgroundcolor']); + $design->backgroundcolor = $color->intValue(); + + $color->parseColor($defaults['contentcolor']); + $design->contentcolor = $color->intValue(); + + $color->parseColor($defaults['sidebarcolor']); + $design->sidebarcolor = $color->intValue(); + + $color->parseColor($defaults['textcolor']); + $design->sidebarcolor = $color->intValue(); + + $color->parseColor($defaults['linkcolor']); + $design->linkcolor = $color->intValue(); + + $design->backgroundimage = $defaults['backgroundimage']; + + } catch (WebColorException $e) { + common_log(LOG_ERR, _('Bad default color settings: ' . + $e->getMessage())); + } return $design; } /** - * Save the user's design settings + * Save or update the user's design settings * * @return void */ - + function saveDesign() { $user = common_current_user(); - - - + + try { + + $bgcolor = new WebColor($this->trimmed('design_background')); + $ccolor = new WebColor($this->trimmed('design_content')); + $sbcolor = new WebColor($this->trimmed('design_sidebar')); + $tcolor = new WebColor($this->trimmed('design_text')); + $lcolor = new WebColor($this->trimmed('design_links')); + + } catch (WebColorException $e) { + $this->showForm($e->getMessage()); + return; + } + + $design = User::getDesign(); + + if (!isset($design)) { + + $original = clone($design); + + $original->backgroundcolor = $bgcolor->intValue(); + $original->contentcolor = $ccolor->intValue(); + $original->sidebarcolor = $sbcolor->intValue(); + $original->textcolor = $tcolor->intValue(); + $original->linkcolor = $lcolor->intValue(); + + $result = $design->update($original); + + if ($result === false) { + common_log_db_error($design, 'UPDATE', __FILE__); + $this->showForm(_('Couldn\'t update your design.')); + return; + } + + // update design + } else { + + $user->query('BEGIN'); + + // save new design + $design = new Design(); + + $design->backgroundcolor = $bgcolor->intValue(); + $design->contentcolor = $ccolor->intValue(); + $design->sidebarcolor = $sbcolor->intValue(); + $design->textcolor = $tcolor->intValue(); + $design->linkcolor = $lcolor->intValue(); + $design->backgroundimage = $defaults['backgroundimage']; + + $id = $design->insert(); + + if (empty($id)) { + common_log_db_error($id, 'INSERT', __FILE__); + $this->showForm(_('Unable to save your design settings!')); + return; + } + + $original = clone($user); + $user->design_id = $id; + $result = $user->update($original); + + if (empty($result)) { + common_log_db_error($original, 'UPDATE', __FILE__); + $this->showForm(_('Unable to save your design settings!')); + $user->query('ROLLBACK'); + return; + } + + $user->query('COMMIT'); + + } + $this->showForm(_('Design preferences saved.'), true); } @@ -282,9 +390,9 @@ class DesignsettingsAction extends AccountSettingsAction * Reset design settings to previous saved value if any, or * the defaults * - * @return void + * @return void */ - + function resetDesign() { $this->showForm(_('Design preferences reset.'), true); diff --git a/lib/webcolor.php b/lib/webcolor.php new file mode 100644 index 0000000000..65713d26ef --- /dev/null +++ b/lib/webcolor.php @@ -0,0 +1,191 @@ +. + * + * @category Personal + * @package Laconica + * @author Zach Copley + * @copyright 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/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +class WebColor { + + // XXX: Maybe make getters and setters for r,g,b values and tuples, + // e.g.: to support this kinda CSS representation: rgb(255,0,0) + // http://www.w3.org/TR/CSS21/syndata.html#color-units + + var $red = 0; + var $green = 0; + var $blue = 0; + + /** + * Constructor + * + * @return nothing + */ + + function __construct($color = null) + { + if (isset($color)) { + $this->parseColor($color); + } + } + + /** + * Parses input to and tries to determine whether the color + * is being specified via an integer or hex tuple and sets + * the RGB instance variables accordingly. + * + * XXX: Maybe support (r,g,b) style, and array? + * + * @param mixed $color + * + * @return nothing + */ + + function parseColor($color) { + + if (is_numeric($color)) { + $this->setIntColor($color); + } else { + + // XXX named colors + + // XXX: probably should do even more validation + + if (preg_match('/(#([0-9A-Fa-f]{3,6})\b)/u', $color) > 0) { + $this->setHexColor($color); + } else { + $errmsg = _('%s is not a valid color!'); + throw new WebColorException(sprintf($errmsg, $color)); + } + } + } + + /** + * @param string $name + * + * @return nothing + */ + + function setNamedColor($name) + { + // XXX Implement this + } + + + /** + * Sets the RGB color values from a a hex tuple + * + * @param string $hexcolor + * + * @return nothing + */ + + function setHexColor($hexcolor) { + + if ($hexcolor[0] == '#') { + $hexcolor = substr($hexcolor, 1); + } + + if (strlen($hexcolor) == 6) { + list($r, $g, $b) = array($hexcolor[0].$hexcolor[1], + $hexcolor[2].$hexcolor[3], + $hexcolor[4].$hexcolor[5]); + } elseif (strlen($hexcolor) == 3) { + list($r, $g, $b) = array($hexcolor[0].$hexcolor[0], + $hexcolor[1].$hexcolor[1], + $hexcolor[2].$hexcolor[2]); + } else { + return false; + } + + $this->red = hexdec($r); + $this->green = hexdec($g); + $this->blue = hexdec($b); + + } + + /** + * Sets the RGB color values from a 24-bit integer + * + * @param int $intcolor + * + * @return nothing + */ + + function setIntColor($intcolor) + { + // We could do 32 bit and have an alpha channel because + // Sarven wants one real bad, but nah. + + $this->red = $intcolor >> 16; + $this->green = $intcolor >> 8 & 0xFF; + $this->blue = $intcolor & 0xFF; + + } + + /** + * Returns a hex tuple of the RGB color useful for output in HTML + * + * @return string + */ + + function hexValue() { + + $hexcolor = (strlen(dechex($this->red)) < 2 ? '0' : '' ) . + dechex($this->red); + $hexcolor .= (strlen(dechex($this->green)) < 2 ? '0' : '') . + dechex($this->green); + $hexcolor .= (strlen(dechex($this->blue)) < 2 ? '0' : '') . + dechex($this->blue); + + return $hexcolor; + + } + + /** + * Returns a 24-bit packed integer representation of the RGB color + * for convenient storage in the DB + * + * XXX: probably could just use hexdec() instead + * + * @return int + */ + + function intValue() + { + $intcolor = 256 * 256 * $this->red + 256 * $this->green + $this->blue; + return $intcolor; + } + +} + +class WebColorException extends Exception +{ +} + +?> \ No newline at end of file From 94fec28610a62fcf6d33c6ec1f451dadb5ca9b18 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 20:29:30 -0700 Subject: [PATCH 26/56] User design setting save --- actions/designsettings.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 0f7c271946..dedf19db83 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -111,10 +111,10 @@ class DesignsettingsAction extends AccountSettingsAction $bgcolor = new WebColor($design->backgroundcolor); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-0'), _('Background')); + $this->element('label', array('for' => 'swatch-1'), _('Background')); $this->element('input', array('name' => 'design_background', 'type' => 'text', - 'id' => 'swatch-0', + 'id' => 'swatch-1', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -125,10 +125,10 @@ class DesignsettingsAction extends AccountSettingsAction $ccolor = new WebColor($design->contentcolor); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-1'), _('Content')); + $this->element('label', array('for' => 'swatch-2'), _('Content')); $this->element('input', array('name' => 'design_content', 'type' => 'text', - 'id' => 'swatch-1', + 'id' => 'swatch-2', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -138,10 +138,10 @@ class DesignsettingsAction extends AccountSettingsAction $sbcolor = new WebColor($design->sidebarcolor); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-2'), _('Sidebar')); + $this->element('label', array('for' => 'swatch-3'), _('Sidebar')); $this->element('input', array('name' => 'design_sidebar', 'type' => 'text', - 'id' => 'swatch-2', + 'id' => 'swatch-3', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -151,10 +151,10 @@ class DesignsettingsAction extends AccountSettingsAction $tcolor = new WebColor($design->textcolor); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-3'), _('Text')); + $this->element('label', array('for' => 'swatch-4'), _('Text')); $this->element('input', array('name' => 'design_text', 'type' => 'text', - 'id' => 'swatch-3', + 'id' => 'swatch-4', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', @@ -164,10 +164,10 @@ class DesignsettingsAction extends AccountSettingsAction $lcolor = new WebColor($design->linkcolor); $this->elementStart('li'); - $this->element('label', array('for' => 'swatch-4'), _('Links')); + $this->element('label', array('for' => 'swatch-5'), _('Links')); $this->element('input', array('name' => 'design_links', 'type' => 'text', - 'id' => 'swatch-4', + 'id' => 'swatch-5', 'class' => 'swatch', 'maxlength' => '7', 'size' => '7', From 2c7f0534ca26b9c9461d920bb23765b282e6fdbc Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 16 Jun 2009 04:03:08 +0000 Subject: [PATCH 27/56] Typo/lowercased WebColor to webcolor in required_once --- actions/designsettings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index dedf19db83..b7f9cda987 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -33,7 +33,7 @@ if (!defined('LACONICA')) { } require_once INSTALLDIR . '/lib/accountsettingsaction.php'; -require_once INSTALLDIR . '/lib/WebColor.php'; +require_once INSTALLDIR . '/lib/webcolor.php'; class DesignsettingsAction extends AccountSettingsAction { From e7e3709ae0294b8400b85d87f2ebeade5b31858d Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 21:21:33 -0700 Subject: [PATCH 28/56] Throw an WebColorException if wrong # of hex chars --- lib/webcolor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/webcolor.php b/lib/webcolor.php index 65713d26ef..aaf31d9903 100644 --- a/lib/webcolor.php +++ b/lib/webcolor.php @@ -120,7 +120,8 @@ class WebColor { $hexcolor[1].$hexcolor[1], $hexcolor[2].$hexcolor[2]); } else { - return false; + $errmsg = _('%s is not a valid color! Use 3 or 6 hex chars.'); + throw new WebColorException(sprintf($errmsg, $hexcolor)); } $this->red = hexdec($r); From ef99f83963ba598b1e52224ce80a7d8a8e84a96f Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 22:13:35 -0700 Subject: [PATCH 29/56] Output custom stylesheets on design sub-Actions --- classes/Design.php | 2 +- lib/currentuserdesignaction.php | 16 ++++++++++++++++ lib/ownerdesignaction.php | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/classes/Design.php b/classes/Design.php index bb1e917e3e..4f6b2a8449 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -47,7 +47,7 @@ class Design extends Memcached_DataObject function showCSS($out) { - $out->element('stylesheet', array('type' => 'text/css'), + $out->element('style', array('type' => 'text/css'), 'body { background-color: #' . dechex($this->backgroundcolor) . '} '."\n". '#content { background-color #' . dechex($this->contentcolor) . '} '."\n". '#aside_primary { background-color #'. dechex($this->sidebarcolor) .'} '."\n". diff --git a/lib/currentuserdesignaction.php b/lib/currentuserdesignaction.php index 2975256557..40502bc776 100644 --- a/lib/currentuserdesignaction.php +++ b/lib/currentuserdesignaction.php @@ -47,6 +47,20 @@ if (!defined('LACONICA')) { class CurrentUserDesignAction extends Action { + + /** + * Show the user's design stylesheet + * + * @return nothing + */ + function showStylesheets() + { + parent::showStylesheets(); + + $design = $this->getDesign(); + $design->showCSS($this); + } + /** * A design for this action * @@ -66,4 +80,6 @@ class CurrentUserDesignAction extends Action return $cur->getDesign(); } + + } diff --git a/lib/ownerdesignaction.php b/lib/ownerdesignaction.php index c47633bdb2..b6b30a6065 100644 --- a/lib/ownerdesignaction.php +++ b/lib/ownerdesignaction.php @@ -52,6 +52,19 @@ class OwnerDesignAction extends Action { var $user = null; + /** + * Show the owner's design stylesheet + * + * @return nothing + */ + function showStylesheets() + { + parent::showStylesheets(); + + $design = $this->getDesign(); + $design->showCSS($this); + } + /** * A design for this action * From 4652f316cf9cb94fb5f0ae8003d7bb9e2bdcdaee Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 22:27:59 -0700 Subject: [PATCH 30/56] Design class now uses WebColor class for outputting hex colors --- classes/Design.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/classes/Design.php b/classes/Design.php index 4f6b2a8449..9bfdcd1c35 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -17,13 +17,16 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} /** * Table Definition for design */ -require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; +require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; +require_once INSTALLDIR . '/lib/webcolor.php'; class Design extends Memcached_DataObject { @@ -47,11 +50,25 @@ class Design extends Memcached_DataObject function showCSS($out) { + try { + + $bgcolor = new WebColor($this->backgroundcolor); + $ccolor = new WebColor($this->contentcolor); + $sbcolor = new WebColor($this->sidebarcolor); + $tcolor = new WebColor($this->textcolor); + $lcolor = new WebColor($this->linkcolor); + + } catch (WebColorException $e) { + // This shouldn't happen + common_log(LOG_ERR, "Unable to create color for design $id.", + __FILE__); + } + $out->element('style', array('type' => 'text/css'), - 'body { background-color: #' . dechex($this->backgroundcolor) . '} '."\n". - '#content { background-color #' . dechex($this->contentcolor) . '} '."\n". - '#aside_primary { background-color #'. dechex($this->sidebarcolor) .'} '."\n". - 'html body { color: #'. dechex($this->textcolor) .'} '."\n". - 'a { color: #' . dechex($this->linkcolor) . '} '."\n"); + 'body { background-color: #' . $bgcolor->hexValue() . '} '."\n". + '#content { background-color #' . $ccolor->hexValue() . '} '."\n". + '#aside_primary { background-color #'. $sbcolor->hexValue() .'} '."\n". + 'html body { color: #'. $tcolor->hexValue() .'} '."\n". + 'a { color: #' . $lcolor->hexValue() . '} '."\n"); } } From f3199c1369bb017d5e1548343a0fd56bededb69b Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 22:39:53 -0700 Subject: [PATCH 31/56] Some fixups to the CSS output of showCSS() --- classes/Design.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/Design.php b/classes/Design.php index 9bfdcd1c35..f4128ee396 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -65,9 +65,9 @@ class Design extends Memcached_DataObject } $out->element('style', array('type' => 'text/css'), - 'body { background-color: #' . $bgcolor->hexValue() . '} '."\n". - '#content { background-color #' . $ccolor->hexValue() . '} '."\n". - '#aside_primary { background-color #'. $sbcolor->hexValue() .'} '."\n". + 'html, body { background-color: #' . $bgcolor->hexValue() . '} '."\n". + '#content { background-color: #' . $ccolor->hexValue() . '} '."\n". + '#aside_primary { background-color: #'. $sbcolor->hexValue() .'} '."\n". 'html body { color: #'. $tcolor->hexValue() .'} '."\n". 'a { color: #' . $lcolor->hexValue() . '} '."\n"); } From 37cafad2e071bbfe8a733bba22fb68bbf5220051 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 22:43:06 -0700 Subject: [PATCH 32/56] Another minor tweak to showCSS() CSS output --- classes/Design.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/Design.php b/classes/Design.php index f4128ee396..8bb5277619 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -66,7 +66,8 @@ class Design extends Memcached_DataObject $out->element('style', array('type' => 'text/css'), 'html, body { background-color: #' . $bgcolor->hexValue() . '} '."\n". - '#content { background-color: #' . $ccolor->hexValue() . '} '."\n". + '#content, #site_nav_local_views .current a { background-color: #' . + $ccolor->hexValue() . '} '."\n". '#aside_primary { background-color: #'. $sbcolor->hexValue() .'} '."\n". 'html body { color: #'. $tcolor->hexValue() .'} '."\n". 'a { color: #' . $lcolor->hexValue() . '} '."\n"); From c3c30aa0eafd42cf6544cb32614ffe164bfd9ca2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 23:18:54 -0700 Subject: [PATCH 33/56] Check to make sure a design exists before trying to display it --- lib/currentuserdesignaction.php | 5 ++++- lib/ownerdesignaction.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/currentuserdesignaction.php b/lib/currentuserdesignaction.php index 40502bc776..7c2520cf67 100644 --- a/lib/currentuserdesignaction.php +++ b/lib/currentuserdesignaction.php @@ -58,7 +58,10 @@ class CurrentUserDesignAction extends Action parent::showStylesheets(); $design = $this->getDesign(); - $design->showCSS($this); + + if (!empty($design)) { + $design->showCSS($this); + } } /** diff --git a/lib/ownerdesignaction.php b/lib/ownerdesignaction.php index b6b30a6065..424474f429 100644 --- a/lib/ownerdesignaction.php +++ b/lib/ownerdesignaction.php @@ -62,7 +62,10 @@ class OwnerDesignAction extends Action { parent::showStylesheets(); $design = $this->getDesign(); - $design->showCSS($this); + + if (!empty($design)) { + $design->showCSS($this); + } } /** From 93205cac099e143b7e5dd22a17f6eda6a82d49cf Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 16 Jun 2009 06:24:29 +0000 Subject: [PATCH 34/56] Connects html, body and content, navigation background colors --- js/farbtastic/farbtastic.go.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 2f202ced1f..9bf7408259 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -11,10 +11,10 @@ $(document).ready(function() { C = $(S).val(); switch (parseInt(S.id.slice(-1))) { case 1: default: - $('body').css({'background-color':C}); + $('html, body').css({'background-color':C}); break; case 2: - $('#content').css({'background-color':C}); + $('#content, #site_nav_local_views .current a').css({'background-color':C}); break; case 3: $('#aside_primary').css({'background-color':C}); From 6d5d0b3472038b0a2cbe86c7df5f062853164dec Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 00:56:32 -0700 Subject: [PATCH 35/56] Update wasn't ever getting called --- actions/designsettings.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index b7f9cda987..c5aa8c1d37 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -325,17 +325,17 @@ class DesignsettingsAction extends AccountSettingsAction return; } - $design = User::getDesign(); + $design = $user->getDesign(); - if (!isset($design)) { + if (!empty($design)) { $original = clone($design); - $original->backgroundcolor = $bgcolor->intValue(); - $original->contentcolor = $ccolor->intValue(); - $original->sidebarcolor = $sbcolor->intValue(); - $original->textcolor = $tcolor->intValue(); - $original->linkcolor = $lcolor->intValue(); + $design->backgroundcolor = $bgcolor->intValue(); + $design->contentcolor = $ccolor->intValue(); + $design->sidebarcolor = $sbcolor->intValue(); + $design->textcolor = $tcolor->intValue(); + $design->linkcolor = $lcolor->intValue(); $result = $design->update($original); From bc1f877f6e84929b7f2722f57858cfad8508fea5 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 19:17:37 -0700 Subject: [PATCH 36/56] Design settings now save and displays backgrounds --- actions/designsettings.php | 69 ++++++++++++++++++++++++++++++++++---- classes/Design.php | 63 ++++++++++++++++++++++++++++++---- lib/common.php | 4 +++ 3 files changed, 122 insertions(+), 14 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index c5aa8c1d37..aa6915b98e 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -56,7 +56,8 @@ class DesignsettingsAction extends AccountSettingsAction function getInstructions() { - return _('Customize the way your profile looks with a background image and a colour palette of your choice.'); + return _('Customize the way your profile looks ' . + 'with a background image and a colour palette of your choice.'); } /** @@ -71,14 +72,16 @@ class DesignsettingsAction extends AccountSettingsAction { $user = common_current_user(); $this->elementStart('form', array('method' => 'post', + 'enctype' => 'multipart/form-data', 'id' => 'form_settings_design', 'class' => 'form_settings', 'action' => - common_local_url('designsettings'))); + common_local_url('designsettings'))); $this->elementStart('fieldset'); $this->hidden('token', common_session_token()); - $this->elementStart('fieldset', array('id' => 'settings_design_background-image')); + $this->elementStart('fieldset', array('id' => + 'settings_design_background-image')); $this->element('legend', null, _('Change background image')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); @@ -87,7 +90,8 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('input', array('name' => 'design_background-image_file', 'type' => 'file', 'id' => 'design_background-image_file')); - $this->element('p', 'form_guide', _('You can upload your personal background image. The maximum file size is 2Mb.')); + $this->element('p', 'form_guide', _('You can upload your personal ' . + 'background image. The maximum file size is 2Mb.')); $this->element('input', array('name' => 'MAX_FILE_SIZE', 'type' => 'hidden', 'id' => 'MAX_FILE_SIZE', @@ -207,6 +211,20 @@ class DesignsettingsAction extends AccountSettingsAction function handlePost() { + // XXX: Robin's workaround for a bug in PHP where $_POST + // and $_FILE are empty in the case that the uploaded + // file is bigger than PHP is configured to handle. + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) { + + $msg = _('The server was unable to handle that much POST ' . + 'data (%s bytes) due to its current configuration.'); + + $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); + } + } + // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { @@ -310,8 +328,6 @@ class DesignsettingsAction extends AccountSettingsAction function saveDesign() { - $user = common_current_user(); - try { $bgcolor = new WebColor($this->trimmed('design_background')); @@ -325,6 +341,7 @@ class DesignsettingsAction extends AccountSettingsAction return; } + $user = common_current_user(); $design = $user->getDesign(); if (!empty($design)) { @@ -336,6 +353,7 @@ class DesignsettingsAction extends AccountSettingsAction $design->sidebarcolor = $sbcolor->intValue(); $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); + $design->backgroundimage = $filepath; $result = $design->update($original); @@ -358,7 +376,7 @@ class DesignsettingsAction extends AccountSettingsAction $design->sidebarcolor = $sbcolor->intValue(); $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); - $design->backgroundimage = $defaults['backgroundimage']; + $design->backgroundimage = $filepath; $id = $design->insert(); @@ -383,6 +401,43 @@ class DesignsettingsAction extends AccountSettingsAction } + // Now that we have a Design ID we can add a file to the design. + // XXX: This is an additional DB hit, but figured having the image + // associated with the Design rather than the User was worth + // it. -- Zach + + if ($_FILES['design_background-image_file']['error'] == + UPLOAD_ERR_OK) { + + $filepath = null; + + try { + $imagefile = + ImageFile::fromUpload('design_background-image_file'); + } catch (Exception $e) { + $this->showForm($e->getMessage()); + return; + } + + $filename = Design::filename($design->id, + image_type_to_extension($imagefile->type), + common_timestamp()); + + $filepath = Design::path($filename); + + move_uploaded_file($imagefile->filepath, $filepath); + + $original = clone($design); + $design->backgroundimage = $filename; + $result = $design->update($original); + + if ($result === false) { + common_log_db_error($design, 'UPDATE', __FILE__); + $this->showForm(_('Couldn\'t update your design.')); + return; + } + } + $this->showForm(_('Design preferences saved.'), true); } diff --git a/classes/Design.php b/classes/Design.php index 8bb5277619..f5c87b489c 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -64,12 +64,61 @@ class Design extends Memcached_DataObject __FILE__); } - $out->element('style', array('type' => 'text/css'), - 'html, body { background-color: #' . $bgcolor->hexValue() . '} '."\n". - '#content, #site_nav_local_views .current a { background-color: #' . - $ccolor->hexValue() . '} '."\n". - '#aside_primary { background-color: #'. $sbcolor->hexValue() .'} '."\n". - 'html body { color: #'. $tcolor->hexValue() .'} '."\n". - 'a { color: #' . $lcolor->hexValue() . '} '."\n"); + $css = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n"; + $css .= '#content, #site_nav_local_views .current a { background-color: #'; + $css .= $ccolor->hexValue() . '} '."\n"; + $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n"; + $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n"; + $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n"; + + if (!empty($this->backgroundimage)) { + + $css .= 'body { background-image:url(' . + Design::url($this->backgroundimage) . + '); background-repeat:no-repeat; }' . "\n"; + } + + $out->element('style', array('type' => 'text/css'), $css); + } + + static function filename($id, $extension, $extra=null) + { + return $id . (($extra) ? ('-' . $extra) : '') . $extension; + } + + static function path($filename) + { + $dir = common_config('background', 'dir'); + + if ($dir[strlen($dir)-1] != '/') { + $dir .= '/'; + } + + return $dir . $filename; + } + + static function url($filename) + { + $path = common_config('background', 'path'); + + if ($path[strlen($path)-1] != '/') { + $path .= '/'; + } + + if ($path[0] != '/') { + $path = '/'.$path; + } + + $server = common_config('background', 'server'); + + if (empty($server)) { + $server = common_config('site', 'server'); + } + + // XXX: protocol + + return 'http://'.$server.$path.$filename; + } + } diff --git a/lib/common.php b/lib/common.php index 1381d80477..0e710625c7 100644 --- a/lib/common.php +++ b/lib/common.php @@ -119,6 +119,10 @@ $config = array('server' => null, 'dir' => INSTALLDIR . '/avatar/', 'path' => $_path . '/avatar/'), + 'background' => + array('server' => null, + 'dir' => INSTALLDIR . '/background/', + 'path' => $_path . '/background/'), 'public' => array('localonly' => true, 'blacklist' => array(), From 90344e55d46f07e69ff0800552d28ea90b11764a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 19:23:06 -0700 Subject: [PATCH 37/56] Add background dir --- .gitignore | 1 + background/.gitignore | 0 2 files changed, 1 insertion(+) create mode 100644 background/.gitignore diff --git a/.gitignore b/.gitignore index 3418d8ee54..8a7f5c65c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ avatar/* +background/* files/* file/* _darcs/* diff --git a/background/.gitignore b/background/.gitignore new file mode 100644 index 0000000000..e69de29bb2 From bea2fa15060e03d818db043122bf9529d2b77662 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 04:09:30 +0000 Subject: [PATCH 38/56] Added form option to tile background image and to turn it on and off --- actions/designsettings.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/actions/designsettings.php b/actions/designsettings.php index aa6915b98e..e97d01ceb7 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -97,6 +97,34 @@ class DesignsettingsAction extends AccountSettingsAction 'id' => 'MAX_FILE_SIZE', 'value' => ImageFile::maxFileSizeInt())); $this->elementEnd('li'); + + $this->elementStart('li', array('id' => 'design_background-image_onoff')); + $this->element('input', array('name' => 'design_background-image_onoff', + 'type' => 'radio', + 'id' => 'design_background-image_on', + 'class' => 'radio', + 'value' => 'true', + 'checked'=> 'checked')); + $this->element('label', array('for' => 'design_background-image_on', + 'class' => 'radio'), + _('On')); + $this->element('input', array('name' => 'design_background-image_onoff', + 'type' => 'radio', + 'id' => 'design_background-image_off', + 'class' => 'radio', + 'value' => 'false')); + $this->element('label', array('for' => 'design_background-image_off', + 'class' => 'radio'), + _('Off')); + $this->element('p', 'form_guide', _('Turn background image on or off.')); + $this->elementEnd('li'); + + $this->elementStart('li'); + $this->checkbox('design_background-image_repeat', + _('Tile background image'), + false, null, true, false); + $this->elementEnd('li'); + $this->elementEnd('ul'); $this->elementEnd('fieldset'); From a592ee6b99596d16da513c0ce8174aae3f3063cd Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 04:33:01 +0000 Subject: [PATCH 39/56] Init styles for tile and image use on/off for user design settings --- theme/base/css/display.css | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 0cbd0d774a..5b69b4f3d5 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -77,7 +77,8 @@ margin:0 0 18px 0; form label { font-weight:bold; } -input.checkbox { +input.checkbox, +input.radio { position:relative; top:2px; left:0; @@ -168,7 +169,8 @@ margin-bottom:0; margin-bottom:11px; } -.form_settings input.checkbox { +.form_settings input.checkbox, +.form_settings input.radio { margin-top:3px; margin-left:0; } @@ -180,13 +182,19 @@ margin-left:11px; float:left; width:90%; } - +.form_settings label.radio { +margin-top:0; +margin-right:47px; +margin-left:11px; +width:auto; +} #form_login p.form_guide, #form_register #settings_rememberme p.form_guide, #form_openid_login #settings_rememberme p.form_guide, #settings_twitter_remove p.form_guide, -#form_search ul.form_data #q { +#form_search ul.form_data #q, +#design_background-image_onoff p.form_guide { margin-left:0; } From 7b7f11942885666bfe1f03dd6f34e36a82a08484 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 21:36:15 -0700 Subject: [PATCH 40/56] Added background image tile flag to Design --- classes/Design.php | 19 ++++++++++--------- classes/laconica.ini | 1 + db/laconica.sql | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/classes/Design.php b/classes/Design.php index f5c87b489c..acc94d1969 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -41,6 +41,7 @@ class Design extends Memcached_DataObject public $textcolor; // int(4) public $linkcolor; // int(4) public $backgroundimage; // varchar(255) + public $tile; // tinyint(1) /* Static get */ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); } @@ -63,23 +64,23 @@ class Design extends Memcached_DataObject common_log(LOG_ERR, "Unable to create color for design $id.", __FILE__); } - + $css = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n"; $css .= '#content, #site_nav_local_views .current a { background-color: #'; $css .= $ccolor->hexValue() . '} '."\n"; $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n"; $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n"; $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n"; - + if (!empty($this->backgroundimage)) { - - $css .= 'body { background-image:url(' . - Design::url($this->backgroundimage) . + + $css .= 'body { background-image:url(' . + Design::url($this->backgroundimage) . '); background-repeat:no-repeat; }' . "\n"; } - + $out->element('style', array('type' => 'text/css'), $css); - + } static function filename($id, $extension, $extra=null) @@ -97,7 +98,7 @@ class Design extends Memcached_DataObject return $dir . $filename; } - + static function url($filename) { $path = common_config('background', 'path'); @@ -120,5 +121,5 @@ class Design extends Memcached_DataObject return 'http://'.$server.$path.$filename; } - + } diff --git a/classes/laconica.ini b/classes/laconica.ini index c04ae758f4..5696819848 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -46,6 +46,7 @@ sidebarcolor = 1 textcolor = 1 linkcolor = 1 backgroundimage = 2 +tile = 17 [design__keys] id = N diff --git a/db/laconica.sql b/db/laconica.sql index bd95d1ade6..1f302de167 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -495,7 +495,8 @@ create table design ( sidebarcolor integer comment 'sidebar background color', textcolor integer comment 'text color', linkcolor integer comment 'link color', - backgroundimage varchar(255) comment 'background image, if any' + backgroundimage varchar(255) comment 'background image, if any', + tile tinyint default 0 comment 'tile background image' ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; create table group_block ( From d1ae3176b638a8342f0d3cfb4ac071623c639575 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 22:18:25 -0700 Subject: [PATCH 41/56] Enable tiling of background imgs for Designs --- actions/designsettings.php | 20 +++++++++++++------- classes/Design.php | 25 ++++++++++++++----------- lib/common.php | 3 ++- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index e97d01ceb7..866d8aaeb7 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -71,6 +71,12 @@ class DesignsettingsAction extends AccountSettingsAction function showContent() { $user = common_current_user(); + $design = $user->getDesign(); + + if (empty($design)) { + $design = $this->defaultDesign(); + } + $this->elementStart('form', array('method' => 'post', 'enctype' => 'multipart/form-data', 'id' => 'form_settings_design', @@ -122,7 +128,7 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementStart('li'); $this->checkbox('design_background-image_repeat', _('Tile background image'), - false, null, true, false); + $design->tile); $this->elementEnd('li'); $this->elementEnd('ul'); @@ -132,12 +138,6 @@ class DesignsettingsAction extends AccountSettingsAction $this->element('legend', null, _('Change colours')); $this->elementStart('ul', 'form_data'); - $design = $user->getDesign(); - - if (empty($design)) { - $design = $this->defaultDesign(); - } - try { $bgcolor = new WebColor($design->backgroundcolor); @@ -340,6 +340,8 @@ class DesignsettingsAction extends AccountSettingsAction $design->backgroundimage = $defaults['backgroundimage']; + $deisng->tile = $defaults['tile']; + } catch (WebColorException $e) { common_log(LOG_ERR, _('Bad default color settings: ' . $e->getMessage())); @@ -369,6 +371,8 @@ class DesignsettingsAction extends AccountSettingsAction return; } + $tile = $this->boolean('design_background-image_repeat'); + $user = common_current_user(); $design = $user->getDesign(); @@ -382,6 +386,7 @@ class DesignsettingsAction extends AccountSettingsAction $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); $design->backgroundimage = $filepath; + $design->tile = $tile; $result = $design->update($original); @@ -405,6 +410,7 @@ class DesignsettingsAction extends AccountSettingsAction $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); $design->backgroundimage = $filepath; + $design->tile = $tile; $id = $design->insert(); diff --git a/classes/Design.php b/classes/Design.php index acc94d1969..4ea176677b 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -41,7 +41,7 @@ class Design extends Memcached_DataObject public $textcolor; // int(4) public $linkcolor; // int(4) public $backgroundimage; // varchar(255) - public $tile; // tinyint(1) + public $tile; // tinyint(1) /* Static get */ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); } @@ -64,23 +64,26 @@ class Design extends Memcached_DataObject common_log(LOG_ERR, "Unable to create color for design $id.", __FILE__); } - + $css = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n"; $css .= '#content, #site_nav_local_views .current a { background-color: #'; $css .= $ccolor->hexValue() . '} '."\n"; $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n"; $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n"; $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n"; - + if (!empty($this->backgroundimage)) { - - $css .= 'body { background-image:url(' . - Design::url($this->backgroundimage) . - '); background-repeat:no-repeat; }' . "\n"; + + $repeat = ($this->tile) ? 'background-repeat:repeat;' : + 'background-repeat:no-repeat;'; + + $css .= 'body { background-image:url(' . + Design::url($this->backgroundimage) . + '); ' . $repeat . ' }' . "\n"; } - + $out->element('style', array('type' => 'text/css'), $css); - + } static function filename($id, $extension, $extra=null) @@ -98,7 +101,7 @@ class Design extends Memcached_DataObject return $dir . $filename; } - + static function url($filename) { $path = common_config('background', 'path'); @@ -121,5 +124,5 @@ class Design extends Memcached_DataObject return 'http://'.$server.$path.$filename; } - + } diff --git a/lib/common.php b/lib/common.php index 0e710625c7..629fee25b2 100644 --- a/lib/common.php +++ b/lib/common.php @@ -78,7 +78,8 @@ $config = 'sidebarcolor' => '#CEE1E9', 'textcolor' => '#000000', 'linkcolor' => '#002E6E', - 'backgroundimage' => null), + 'backgroundimage' => null, + 'tile' => true), 'path' => $_path, 'logfile' => null, 'logo' => null, From 9aebcf442616c5b39ac2ea19ef011c2347a3bec3 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 05:18:59 +0000 Subject: [PATCH 42/56] IE7/8 CSS update for user design --- theme/base/css/ie.css | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/theme/base/css/ie.css b/theme/base/css/ie.css index d1b0558ec8..da200388eb 100644 --- a/theme/base/css/ie.css +++ b/theme/base/css/ie.css @@ -1,8 +1,6 @@ /* IE specific styles */ -legend { -margin-left:-7px; -} -input.checkbox { +input.checkbox, +input.radio { top:0; } #form_notice textarea { From a0618b0e33e20700b243d696f2bf139f1167ec93 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Jun 2009 22:57:28 -0700 Subject: [PATCH 43/56] Show a background img in settings form --- actions/designsettings.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actions/designsettings.php b/actions/designsettings.php index 866d8aaeb7..a97235e678 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -105,6 +105,12 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('li'); $this->elementStart('li', array('id' => 'design_background-image_onoff')); + + if (!empty($design->backgroundimage)) { + $this->element('img', array('src' => + Design::url($design->backgroundimage))); + } + $this->element('input', array('name' => 'design_background-image_onoff', 'type' => 'radio', 'id' => 'design_background-image_on', From 7148ea86dff5754fcf0c28023cff52137843f2d9 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 06:23:57 +0000 Subject: [PATCH 44/56] Dynamically tile background image and turn background image on or off in user design --- actions/designsettings.php | 4 +- js/farbtastic/farbtastic.js | 329 ------------------ .../farbtastic.go.js => userdesign.go.js} | 20 +- 3 files changed, 18 insertions(+), 335 deletions(-) delete mode 100644 js/farbtastic/farbtastic.js rename js/{farbtastic/farbtastic.go.js => userdesign.go.js} (81%) diff --git a/actions/designsettings.php b/actions/designsettings.php index a97235e678..fbec3fc67f 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -305,12 +305,12 @@ class DesignsettingsAction extends AccountSettingsAction parent::showScripts(); $farbtasticPack = common_path('js/farbtastic/farbtastic.js'); - $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js'); + $userDesignGo = common_path('js/userdesign.go.js'); $this->element('script', array('type' => 'text/javascript', 'src' => $farbtasticPack)); $this->element('script', array('type' => 'text/javascript', - 'src' => $farbtasticGo)); + 'src' => $userDesignGo)); } /** diff --git a/js/farbtastic/farbtastic.js b/js/farbtastic/farbtastic.js deleted file mode 100644 index 24a377803c..0000000000 --- a/js/farbtastic/farbtastic.js +++ /dev/null @@ -1,329 +0,0 @@ -// $Id: farbtastic.js,v 1.2 2007/01/08 22:53:01 unconed Exp $ -// Farbtastic 1.2 - -jQuery.fn.farbtastic = function (callback) { - $.farbtastic(this, callback); - return this; -}; - -jQuery.farbtastic = function (container, callback) { - var container = $(container).get(0); - return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback)); -} - -jQuery._farbtastic = function (container, callback) { - // Store farbtastic object - var fb = this; - - // Insert markup - $(container).html('
'); - var e = $('.farbtastic', container); - fb.wheel = $('.wheel', container).get(0); - // Dimensions - fb.radius = 84; - fb.square = 100; - fb.width = 194; - - // Fix background PNGs in IE6 - if (navigator.appVersion.match(/MSIE [0-6]\./)) { - $('*', e).each(function () { - if (this.currentStyle.backgroundImage != 'none') { - var image = this.currentStyle.backgroundImage; - image = this.currentStyle.backgroundImage.substring(5, image.length - 2); - $(this).css({ - 'backgroundImage': 'none', - 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" - }); - } - }); - } - - /** - * Link to the given element(s) or callback. - */ - fb.linkTo = function (callback) { - // Unbind previous nodes - if (typeof fb.callback == 'object') { - $(fb.callback).unbind('keyup', fb.updateValue); - } - - // Reset color - fb.color = null; - - // Bind callback or elements - if (typeof callback == 'function') { - fb.callback = callback; - } - else if (typeof callback == 'object' || typeof callback == 'string') { - fb.callback = $(callback); - fb.callback.bind('keyup', fb.updateValue); - if (fb.callback.get(0).value) { - fb.setColor(fb.callback.get(0).value); - } - } - return this; - } - fb.updateValue = function (event) { - if (this.value && this.value != fb.color) { - fb.setColor(this.value); - } - } - - /** - * Change color with HTML syntax #123456 - */ - fb.setColor = function (color) { - var unpack = fb.unpack(color); - if (fb.color != color && unpack) { - fb.color = color; - fb.rgb = unpack; - fb.hsl = fb.RGBToHSL(fb.rgb); - fb.updateDisplay(); - } - return this; - } - - /** - * Change color with HSL triplet [0..1, 0..1, 0..1] - */ - fb.setHSL = function (hsl) { - fb.hsl = hsl; - fb.rgb = fb.HSLToRGB(hsl); - fb.color = fb.pack(fb.rgb); - fb.updateDisplay(); - return this; - } - - ///////////////////////////////////////////////////// - - /** - * Retrieve the coordinates of the given event relative to the center - * of the widget. - */ - fb.widgetCoords = function (event) { - var x, y; - var el = event.target || event.srcElement; - var reference = fb.wheel; - - if (typeof event.offsetX != 'undefined') { - // Use offset coordinates and find common offsetParent - var pos = { x: event.offsetX, y: event.offsetY }; - - // Send the coordinates upwards through the offsetParent chain. - var e = el; - while (e) { - e.mouseX = pos.x; - e.mouseY = pos.y; - pos.x += e.offsetLeft; - pos.y += e.offsetTop; - e = e.offsetParent; - } - - // Look for the coordinates starting from the wheel widget. - var e = reference; - var offset = { x: 0, y: 0 } - while (e) { - if (typeof e.mouseX != 'undefined') { - x = e.mouseX - offset.x; - y = e.mouseY - offset.y; - break; - } - offset.x += e.offsetLeft; - offset.y += e.offsetTop; - e = e.offsetParent; - } - - // Reset stored coordinates - e = el; - while (e) { - e.mouseX = undefined; - e.mouseY = undefined; - e = e.offsetParent; - } - } - else { - // Use absolute coordinates - var pos = fb.absolutePosition(reference); - x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x; - y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y; - } - // Subtract distance to middle - return { x: x - fb.width / 2, y: y - fb.width / 2 }; - } - - /** - * Mousedown handler - */ - fb.mousedown = function (event) { - // Capture mouse - if (!document.dragging) { - $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); - document.dragging = true; - } - - // Check which area is being dragged - var pos = fb.widgetCoords(event); - fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square; - - // Process - fb.mousemove(event); - return false; - } - - /** - * Mousemove handler - */ - fb.mousemove = function (event) { - // Get coordinates relative to color picker center - var pos = fb.widgetCoords(event); - - // Set new HSL parameters - if (fb.circleDrag) { - var hue = Math.atan2(pos.x, -pos.y) / 6.28; - if (hue < 0) hue += 1; - fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]); - } - else { - var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5)); - var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5)); - fb.setHSL([fb.hsl[0], sat, lum]); - } - return false; - } - - /** - * Mouseup handler - */ - fb.mouseup = function () { - // Uncapture mouse - $(document).unbind('mousemove', fb.mousemove); - $(document).unbind('mouseup', fb.mouseup); - document.dragging = false; - } - - /** - * Update the markers and styles - */ - fb.updateDisplay = function () { - // Markers - var angle = fb.hsl[0] * 6.28; - $('.h-marker', e).css({ - left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px', - top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px' - }); - - $('.sl-marker', e).css({ - left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px', - top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px' - }); - - // Saturation/Luminance gradient - $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); - - // Linked elements or callback - if (typeof fb.callback == 'object') { - // Set background/foreground color - $(fb.callback).css({ - backgroundColor: fb.color, - color: fb.hsl[2] > 0.5 ? '#000' : '#fff' - }); - - // Change linked value - $(fb.callback).each(function() { - if (this.value && this.value != fb.color) { - this.value = fb.color; - } - }); - } - else if (typeof fb.callback == 'function') { - fb.callback.call(fb, fb.color); - } - } - - /** - * Get absolute position of element - */ - fb.absolutePosition = function (el) { - var r = { x: el.offsetLeft, y: el.offsetTop }; - // Resolve relative to offsetParent - if (el.offsetParent) { - var tmp = fb.absolutePosition(el.offsetParent); - r.x += tmp.x; - r.y += tmp.y; - } - return r; - }; - - /* Various color utility functions */ - fb.pack = function (rgb) { - var r = Math.round(rgb[0] * 255); - var g = Math.round(rgb[1] * 255); - var b = Math.round(rgb[2] * 255); - return '#' + (r < 16 ? '0' : '') + r.toString(16) + - (g < 16 ? '0' : '') + g.toString(16) + - (b < 16 ? '0' : '') + b.toString(16); - } - - fb.unpack = function (color) { - if (color.length == 7) { - return [parseInt('0x' + color.substring(1, 3)) / 255, - parseInt('0x' + color.substring(3, 5)) / 255, - parseInt('0x' + color.substring(5, 7)) / 255]; - } - else if (color.length == 4) { - return [parseInt('0x' + color.substring(1, 2)) / 15, - parseInt('0x' + color.substring(2, 3)) / 15, - parseInt('0x' + color.substring(3, 4)) / 15]; - } - } - - fb.HSLToRGB = function (hsl) { - var m1, m2, r, g, b; - var h = hsl[0], s = hsl[1], l = hsl[2]; - m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s; - m1 = l * 2 - m2; - return [this.hueToRGB(m1, m2, h+0.33333), - this.hueToRGB(m1, m2, h), - this.hueToRGB(m1, m2, h-0.33333)]; - } - - fb.hueToRGB = function (m1, m2, h) { - h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h); - if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; - if (h * 2 < 1) return m2; - if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; - return m1; - } - - fb.RGBToHSL = function (rgb) { - var min, max, delta, h, s, l; - var r = rgb[0], g = rgb[1], b = rgb[2]; - min = Math.min(r, Math.min(g, b)); - max = Math.max(r, Math.max(g, b)); - delta = max - min; - l = (min + max) / 2; - s = 0; - if (l > 0 && l < 1) { - s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l)); - } - h = 0; - if (delta > 0) { - if (max == r && max != g) h += (g - b) / delta; - if (max == g && max != b) h += (2 + (b - r) / delta); - if (max == b && max != r) h += (4 + (r - g) / delta); - h /= 6; - } - return [h, s, l]; - } - - // Install mousedown handler (the others are set on the document on-demand) - $('*', e).mousedown(fb.mousedown); - - // Init color - fb.setColor('#000000'); - - // Set linked elements/callback - if (callback) { - fb.linkTo(callback); - } -} \ No newline at end of file diff --git a/js/farbtastic/farbtastic.go.js b/js/userdesign.go.js similarity index 81% rename from js/farbtastic/farbtastic.go.js rename to js/userdesign.go.js index 9bf7408259..b54b492cce 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/userdesign.go.js @@ -49,7 +49,7 @@ $(document).ready(function() { } } - function Init() { + function InitFarbtastic() { $('#settings_design_color').append('
'); $('#color-picker').hide(); @@ -75,13 +75,25 @@ $(document).ready(function() { } var f, swatches; - Init(); + InitFarbtastic(); $('#form_settings_design').bind('reset', function(){ setTimeout(function(){ swatches.each(function(){UpdateColors(this);}); $('#color-picker').remove(); swatches.unbind(); - Init(); + InitFarbtastic(); },10); }); -}); + + $('#design_background-image_off').focus(function() { + $('body').css({'background-image':'none'}); + }); + $('#design_background-image_on').focus(function() { + var bis = $('#design_background-image_onoff img')[0].src; + $('body').css({'background-image':'url('+bis+')'}); + }); + + $('#design_background-image_repeat').click(function() { + ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'}); + }); +}); \ No newline at end of file From ea5d46a94d377675eb06dc57757d0e4c743f8a54 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 06:38:21 +0000 Subject: [PATCH 45/56] It was accidently removed --- js/farbtastic/farbtastic.js | 345 ++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 js/farbtastic/farbtastic.js diff --git a/js/farbtastic/farbtastic.js b/js/farbtastic/farbtastic.js new file mode 100644 index 0000000000..d8b5ad9cdf --- /dev/null +++ b/js/farbtastic/farbtastic.js @@ -0,0 +1,345 @@ +/** + * Farbtastic Color Picker 1.2 + * © 2008 Steven Wittens + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +jQuery.fn.farbtastic = function (callback) { + $.farbtastic(this, callback); + return this; +}; + +jQuery.farbtastic = function (container, callback) { + var container = $(container).get(0); + return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback)); +} + +jQuery._farbtastic = function (container, callback) { + // Store farbtastic object + var fb = this; + + // Insert markup + $(container).html('
'); + var e = $('.farbtastic', container); + fb.wheel = $('.wheel', container).get(0); + // Dimensions + fb.radius = 84; + fb.square = 100; + fb.width = 194; + + // Fix background PNGs in IE6 + if (navigator.appVersion.match(/MSIE [0-6]\./)) { + $('*', e).each(function () { + if (this.currentStyle.backgroundImage != 'none') { + var image = this.currentStyle.backgroundImage; + image = this.currentStyle.backgroundImage.substring(5, image.length - 2); + $(this).css({ + 'backgroundImage': 'none', + 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" + }); + } + }); + } + + /** + * Link to the given element(s) or callback. + */ + fb.linkTo = function (callback) { + // Unbind previous nodes + if (typeof fb.callback == 'object') { + $(fb.callback).unbind('keyup', fb.updateValue); + } + + // Reset color + fb.color = null; + + // Bind callback or elements + if (typeof callback == 'function') { + fb.callback = callback; + } + else if (typeof callback == 'object' || typeof callback == 'string') { + fb.callback = $(callback); + fb.callback.bind('keyup', fb.updateValue); + if (fb.callback.get(0).value) { + fb.setColor(fb.callback.get(0).value); + } + } + return this; + } + fb.updateValue = function (event) { + if (this.value && this.value != fb.color) { + fb.setColor(this.value); + } + } + + /** + * Change color with HTML syntax #123456 + */ + fb.setColor = function (color) { + var unpack = fb.unpack(color); + if (fb.color != color && unpack) { + fb.color = color; + fb.rgb = unpack; + fb.hsl = fb.RGBToHSL(fb.rgb); + fb.updateDisplay(); + } + return this; + } + + /** + * Change color with HSL triplet [0..1, 0..1, 0..1] + */ + fb.setHSL = function (hsl) { + fb.hsl = hsl; + fb.rgb = fb.HSLToRGB(hsl); + fb.color = fb.pack(fb.rgb); + fb.updateDisplay(); + return this; + } + + ///////////////////////////////////////////////////// + + /** + * Retrieve the coordinates of the given event relative to the center + * of the widget. + */ + fb.widgetCoords = function (event) { + var x, y; + var el = event.target || event.srcElement; + var reference = fb.wheel; + + if (typeof event.offsetX != 'undefined') { + // Use offset coordinates and find common offsetParent + var pos = { x: event.offsetX, y: event.offsetY }; + + // Send the coordinates upwards through the offsetParent chain. + var e = el; + while (e) { + e.mouseX = pos.x; + e.mouseY = pos.y; + pos.x += e.offsetLeft; + pos.y += e.offsetTop; + e = e.offsetParent; + } + + // Look for the coordinates starting from the wheel widget. + var e = reference; + var offset = { x: 0, y: 0 } + while (e) { + if (typeof e.mouseX != 'undefined') { + x = e.mouseX - offset.x; + y = e.mouseY - offset.y; + break; + } + offset.x += e.offsetLeft; + offset.y += e.offsetTop; + e = e.offsetParent; + } + + // Reset stored coordinates + e = el; + while (e) { + e.mouseX = undefined; + e.mouseY = undefined; + e = e.offsetParent; + } + } + else { + // Use absolute coordinates + var pos = fb.absolutePosition(reference); + x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x; + y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y; + } + // Subtract distance to middle + return { x: x - fb.width / 2, y: y - fb.width / 2 }; + } + + /** + * Mousedown handler + */ + fb.mousedown = function (event) { + // Capture mouse + if (!document.dragging) { + $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); + document.dragging = true; + } + + // Check which area is being dragged + var pos = fb.widgetCoords(event); + fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square; + + // Process + fb.mousemove(event); + return false; + } + + /** + * Mousemove handler + */ + fb.mousemove = function (event) { + // Get coordinates relative to color picker center + var pos = fb.widgetCoords(event); + + // Set new HSL parameters + if (fb.circleDrag) { + var hue = Math.atan2(pos.x, -pos.y) / 6.28; + if (hue < 0) hue += 1; + fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]); + } + else { + var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5)); + var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5)); + fb.setHSL([fb.hsl[0], sat, lum]); + } + return false; + } + + /** + * Mouseup handler + */ + fb.mouseup = function () { + // Uncapture mouse + $(document).unbind('mousemove', fb.mousemove); + $(document).unbind('mouseup', fb.mouseup); + document.dragging = false; + } + + /** + * Update the markers and styles + */ + fb.updateDisplay = function () { + // Markers + var angle = fb.hsl[0] * 6.28; + $('.h-marker', e).css({ + left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px', + top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px' + }); + + $('.sl-marker', e).css({ + left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px', + top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px' + }); + + // Saturation/Luminance gradient + $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); + + // Linked elements or callback + if (typeof fb.callback == 'object') { + // Set background/foreground color + $(fb.callback).css({ + backgroundColor: fb.color, + color: fb.hsl[2] > 0.5 ? '#000' : '#fff' + }); + + // Change linked value + $(fb.callback).each(function() { + if (this.value && this.value != fb.color) { + this.value = fb.color; + } + }); + } + else if (typeof fb.callback == 'function') { + fb.callback.call(fb, fb.color); + } + } + + /** + * Get absolute position of element + */ + fb.absolutePosition = function (el) { + var r = { x: el.offsetLeft, y: el.offsetTop }; + // Resolve relative to offsetParent + if (el.offsetParent) { + var tmp = fb.absolutePosition(el.offsetParent); + r.x += tmp.x; + r.y += tmp.y; + } + return r; + }; + + /* Various color utility functions */ + fb.pack = function (rgb) { + var r = Math.round(rgb[0] * 255); + var g = Math.round(rgb[1] * 255); + var b = Math.round(rgb[2] * 255); + return '#' + (r < 16 ? '0' : '') + r.toString(16) + + (g < 16 ? '0' : '') + g.toString(16) + + (b < 16 ? '0' : '') + b.toString(16); + } + + fb.unpack = function (color) { + if (color.length == 7) { + return [parseInt('0x' + color.substring(1, 3)) / 255, + parseInt('0x' + color.substring(3, 5)) / 255, + parseInt('0x' + color.substring(5, 7)) / 255]; + } + else if (color.length == 4) { + return [parseInt('0x' + color.substring(1, 2)) / 15, + parseInt('0x' + color.substring(2, 3)) / 15, + parseInt('0x' + color.substring(3, 4)) / 15]; + } + } + + fb.HSLToRGB = function (hsl) { + var m1, m2, r, g, b; + var h = hsl[0], s = hsl[1], l = hsl[2]; + m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s; + m1 = l * 2 - m2; + return [this.hueToRGB(m1, m2, h+0.33333), + this.hueToRGB(m1, m2, h), + this.hueToRGB(m1, m2, h-0.33333)]; + } + + fb.hueToRGB = function (m1, m2, h) { + h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h); + if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; + if (h * 2 < 1) return m2; + if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; + return m1; + } + + fb.RGBToHSL = function (rgb) { + var min, max, delta, h, s, l; + var r = rgb[0], g = rgb[1], b = rgb[2]; + min = Math.min(r, Math.min(g, b)); + max = Math.max(r, Math.max(g, b)); + delta = max - min; + l = (min + max) / 2; + s = 0; + if (l > 0 && l < 1) { + s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l)); + } + h = 0; + if (delta > 0) { + if (max == r && max != g) h += (g - b) / delta; + if (max == g && max != b) h += (2 + (b - r) / delta); + if (max == b && max != r) h += (4 + (r - g) / delta); + h /= 6; + } + return [h, s, l]; + } + + // Install mousedown handler (the others are set on the document on-demand) + $('*', e).mousedown(fb.mousedown); + + // Init color + fb.setColor('#000000'); + + // Set linked elements/callback + if (callback) { + fb.linkTo(callback); + } +} \ No newline at end of file From 76cbeff33c9659cacbb57943056aabcb1517ca5c Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 02:35:51 -0700 Subject: [PATCH 46/56] Update background image settings to use bitflags --- actions/designsettings.php | 100 ++++++++++++++++++++++--------------- classes/Design.php | 33 ++++++++++-- classes/laconica.ini | 2 +- db/laconica.sql | 2 +- lib/common.php | 2 +- 5 files changed, 93 insertions(+), 46 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index fbec3fc67f..3dfaddd7bb 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -104,37 +104,52 @@ class DesignsettingsAction extends AccountSettingsAction 'value' => ImageFile::maxFileSizeInt())); $this->elementEnd('li'); - $this->elementStart('li', array('id' => 'design_background-image_onoff')); - if (!empty($design->backgroundimage)) { + + $this->elementStart('li', array('id' => 'design_background-image_onoff')); + $this->element('img', array('src' => Design::url($design->backgroundimage))); - } - $this->element('input', array('name' => 'design_background-image_onoff', - 'type' => 'radio', - 'id' => 'design_background-image_on', - 'class' => 'radio', - 'value' => 'true', - 'checked'=> 'checked')); - $this->element('label', array('for' => 'design_background-image_on', - 'class' => 'radio'), - _('On')); - $this->element('input', array('name' => 'design_background-image_onoff', - 'type' => 'radio', - 'id' => 'design_background-image_off', - 'class' => 'radio', - 'value' => 'false')); - $this->element('label', array('for' => 'design_background-image_off', - 'class' => 'radio'), - _('Off')); - $this->element('p', 'form_guide', _('Turn background image on or off.')); - $this->elementEnd('li'); + $attrs = array('name' => 'design_background-image_onoff', + 'type' => 'radio', + 'id' => 'design_background-image_on', + 'class' => 'radio', + 'value' => 'on'); + + if ($design->disposition & BACKGROUND_ON) { + $attrs['checked'] = 'checked'; + } + + $this->element('input', $attrs); + + $this->element('label', array('for' => 'design_background-image_on', + 'class' => 'radio'), + _('On')); + + $attrs = array('name' => 'design_background-image_onoff', + 'type' => 'radio', + 'id' => 'design_background-image_off', + 'class' => 'radio', + 'value' => 'off'); + + if ($design->disposition & BACKGROUND_OFF) { + $attrs['checked'] = 'checked'; + } + + $this->element('input', $attrs); + + $this->element('label', array('for' => 'design_background-image_off', + 'class' => 'radio'), + _('Off')); + $this->element('p', 'form_guide', _('Turn background image on or off.')); + $this->elementEnd('li'); + } $this->elementStart('li'); $this->checkbox('design_background-image_repeat', _('Tile background image'), - $design->tile); + ($design->disposition & BACKGROUND_TILE) ? true : false ); $this->elementEnd('li'); $this->elementEnd('ul'); @@ -159,7 +174,6 @@ class DesignsettingsAction extends AccountSettingsAction 'value' => '#' . $bgcolor->hexValue())); $this->elementEnd('li'); - $ccolor = new WebColor($design->contentcolor); $this->elementStart('li'); @@ -346,7 +360,7 @@ class DesignsettingsAction extends AccountSettingsAction $design->backgroundimage = $defaults['backgroundimage']; - $deisng->tile = $defaults['tile']; + $deisng->disposition = $defaults['disposition']; } catch (WebColorException $e) { common_log(LOG_ERR, _('Bad default color settings: ' . @@ -377,7 +391,23 @@ class DesignsettingsAction extends AccountSettingsAction return; } - $tile = $this->boolean('design_background-image_repeat'); + $onoff = $this->arg('design_background-image_onoff'); + + $on = false; + $off = false; + $tile = false; + + if ($onoff == 'on') { + $on = true; + } else { + $off = true; + } + + $repeat = $this->boolean('design_background-image_repeat'); + + if ($repeat) { + $tile = true; + } $user = common_current_user(); $design = $user->getDesign(); @@ -392,7 +422,8 @@ class DesignsettingsAction extends AccountSettingsAction $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); $design->backgroundimage = $filepath; - $design->tile = $tile; + + $design->setDisposition($on, $off, $tile); $result = $design->update($original); @@ -416,7 +447,8 @@ class DesignsettingsAction extends AccountSettingsAction $design->textcolor = $tcolor->intValue(); $design->linkcolor = $lcolor->intValue(); $design->backgroundimage = $filepath; - $design->tile = $tile; + + $design->setDisposition($on, $off, $tile); $id = $design->insert(); @@ -481,16 +513,4 @@ class DesignsettingsAction extends AccountSettingsAction $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/classes/Design.php b/classes/Design.php index 4ea176677b..5b28bf014a 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -21,6 +21,10 @@ if (!defined('LACONICA')) { exit(1); } +define('BACKGROUND_ON', 1); +define('BACKGROUND_OFF', 2); +define('BACKGROUND_TILE', 4); + /** * Table Definition for design */ @@ -41,7 +45,7 @@ class Design extends Memcached_DataObject public $textcolor; // int(4) public $linkcolor; // int(4) public $backgroundimage; // varchar(255) - public $tile; // tinyint(1) + public $disposition; // tinyint(1) default_1 /* Static get */ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); } @@ -72,9 +76,11 @@ class Design extends Memcached_DataObject $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n"; $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n"; - if (!empty($this->backgroundimage)) { + if (!empty($this->backgroundimage) && + $this->disposition & BACKGROUND_ON) { - $repeat = ($this->tile) ? 'background-repeat:repeat;' : + $repeat = ($this->disposition & BACKGROUND_TILE) ? + 'background-repeat:repeat;' : 'background-repeat:no-repeat;'; $css .= 'body { background-image:url(' . @@ -125,4 +131,25 @@ class Design extends Memcached_DataObject return 'http://'.$server.$path.$filename; } + function setDisposition($on, $off, $tile) + { + if ($on) { + $this->disposition |= BACKGROUND_ON; + } else { + $this->disposition &= ~BACKGROUND_ON; + } + + if ($off) { + $this->disposition |= BACKGROUND_OFF; + } else { + $this->disposition &= ~BACKGROUND_OFF; + } + + if ($tile) { + $this->disposition |= BACKGROUND_TILE; + } else { + $this->disposition &= ~BACKGROUND_TILE; + } + } + } diff --git a/classes/laconica.ini b/classes/laconica.ini index 5696819848..1a650aba55 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -46,7 +46,7 @@ sidebarcolor = 1 textcolor = 1 linkcolor = 1 backgroundimage = 2 -tile = 17 +disposition = 17 [design__keys] id = N diff --git a/db/laconica.sql b/db/laconica.sql index 1f302de167..b018afec8e 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -496,7 +496,7 @@ create table design ( textcolor integer comment 'text color', linkcolor integer comment 'link color', backgroundimage varchar(255) comment 'background image, if any', - tile tinyint default 0 comment 'tile background image' + disposition tinyint default 1 comment 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image' ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; create table group_block ( diff --git a/lib/common.php b/lib/common.php index 629fee25b2..bcf2e5d0c7 100644 --- a/lib/common.php +++ b/lib/common.php @@ -79,7 +79,7 @@ $config = 'textcolor' => '#000000', 'linkcolor' => '#002E6E', 'backgroundimage' => null, - 'tile' => true), + 'disposition' => 1), 'path' => $_path, 'logfile' => null, 'logo' => null, From 2866d00517b1ccfd7585f5fc2da1ed2fcf52bdfd Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 02:58:35 -0700 Subject: [PATCH 47/56] Fix sidebar color bug default design --- actions/designsettings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index 3dfaddd7bb..adc09c7b06 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -353,14 +353,14 @@ class DesignsettingsAction extends AccountSettingsAction $design->sidebarcolor = $color->intValue(); $color->parseColor($defaults['textcolor']); - $design->sidebarcolor = $color->intValue(); + $design->textcolor = $color->intValue(); $color->parseColor($defaults['linkcolor']); $design->linkcolor = $color->intValue(); $design->backgroundimage = $defaults['backgroundimage']; - $deisng->disposition = $defaults['disposition']; + $design->disposition = $defaults['disposition']; } catch (WebColorException $e) { common_log(LOG_ERR, _('Bad default color settings: ' . From ac3cccefb53579b01618d5ef728e883dae752fd2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 03:02:43 -0700 Subject: [PATCH 48/56] Default to image being on, no tile after upload --- actions/designsettings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/designsettings.php b/actions/designsettings.php index adc09c7b06..047059e04b 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -501,6 +501,7 @@ class DesignsettingsAction extends AccountSettingsAction $original = clone($design); $design->backgroundimage = $filename; + $design->setDisposition(true, false, false); $result = $design->update($original); if ($result === false) { From af4b18b1e2ef8aded26fc4788c571012da04d1cf Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 03:05:48 -0700 Subject: [PATCH 49/56] Uppercase hex color values --- lib/webcolor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webcolor.php b/lib/webcolor.php index aaf31d9903..f3ca6e94a8 100644 --- a/lib/webcolor.php +++ b/lib/webcolor.php @@ -164,7 +164,7 @@ class WebColor { $hexcolor .= (strlen(dechex($this->blue)) < 2 ? '0' : '') . dechex($this->blue); - return $hexcolor; + return strtoupper($hexcolor); } From 4fc4c0a74bd08f568a55d65660ca2e5170165905 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 17:13:59 -0700 Subject: [PATCH 50/56] Remove stale reference to deprecated personal.php --- lib/mailbox.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mailbox.php b/lib/mailbox.php index 766510a47b..b282ce3687 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -31,8 +31,6 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/personal.php'; - define('MESSAGES_PER_PAGE', 20); /** From b0591cd98219cf523d35884015ee9f82c2aa9e09 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 17:29:57 -0700 Subject: [PATCH 51/56] Make MailboxAction read only --- lib/mailbox.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/mailbox.php b/lib/mailbox.php index b282ce3687..f1f6e98c19 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -295,4 +295,17 @@ class MailboxAction extends CurrentUserDesignAction return; } + /** + * Mailbox actions are read only + * + * @param array $args other arguments + * + * @return boolean + */ + + function isReadOnly($args) + { + return true; + } + } From 5854fe194a35e1bbf2feb6db415f54f33def2dd9 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 18 Jun 2009 01:04:12 +0000 Subject: [PATCH 52/56] Placed a check to make sure there is a reply button in a notice before applying the dynamic action --- js/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/util.js b/js/util.js index ce0c20d31b..854d250609 100644 --- a/js/util.js +++ b/js/util.js @@ -235,7 +235,7 @@ $(document).ready(function(){ }); function NoticeReply() { - if ($('#notice_data-text').length > 0) { + if ($('#notice_data-text').length > 0 && $('.notice_reply').length > 0) { $('#content .notice').each(function() { var notice = $(this)[0]; $($('.notice_reply', notice)[0]).click(function() { @@ -308,4 +308,4 @@ function NoticeAttachments() { $(this).closest(".entry-title").removeClass('ov'); } ); -} \ No newline at end of file +} From 06240450ef4818a8a74748ada297d1d55d18b967 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 18:05:12 -0700 Subject: [PATCH 53/56] Have user favorites page show user's design --- actions/showfavorites.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 865045337a..01f38a8927 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -45,7 +45,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; * @link http://laconi.ca/ */ -class ShowfavoritesAction extends Action +class ShowfavoritesAction extends CurrentUserDesignAction { /** User we're getting the faves of */ var $user = null; From 77185dd4c67761afbe670a15928c523f4de2842b Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 18 Jun 2009 01:10:48 +0000 Subject: [PATCH 54/56] A little more specific selector for notice reply --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util.js b/js/util.js index 854d250609..17ae4c0719 100644 --- a/js/util.js +++ b/js/util.js @@ -235,7 +235,7 @@ $(document).ready(function(){ }); function NoticeReply() { - if ($('#notice_data-text').length > 0 && $('.notice_reply').length > 0) { + if ($('#notice_data-text').length > 0 && $('#content .notice_reply').length > 0) { $('#content .notice').each(function() { var notice = $(this)[0]; $($('.notice_reply', notice)[0]).click(function() { From d8b0fcbc50248e493dfda288fe538ea58ef66acf Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 18 Jun 2009 01:28:02 +0000 Subject: [PATCH 55/56] Removed height:100% for better background image repetition --- theme/base/css/display.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 2153ce9a01..99f2d9ece7 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -12,7 +12,7 @@ img { display:block; border:0; } a abbr { cursor: pointer; border-bottom:0; } table { border-collapse:collapse; } ol { list-style-position:inside; } -html { font-size: 87.5%; background-color:#fff; height:100%; } +html { font-size: 87.5%; background-color:#fff; } body { background-color:#fff; color:#000; From 00736bddd199b2a43820367c3476b9e9ec84c0db Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 18 Jun 2009 01:39:37 +0000 Subject: [PATCH 56/56] Fix for background image repetition for various page heights --- classes/Design.php | 8 ++++---- theme/base/css/display.css | 4 ++-- theme/default/css/display.css | 1 - theme/identica/css/display.css | 1 - 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/classes/Design.php b/classes/Design.php index 5b28bf014a..da4b670be0 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -69,12 +69,12 @@ class Design extends Memcached_DataObject __FILE__); } - $css = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n"; + $css = 'body { background-color: #' . $bgcolor->hexValue() . ' }' . "\n"; $css .= '#content, #site_nav_local_views .current a { background-color: #'; $css .= $ccolor->hexValue() . '} '."\n"; - $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n"; - $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n"; - $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n"; + $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . ' }' . "\n"; + $css .= 'html body { color: #'. $tcolor->hexValue() . ' }'. "\n"; + $css .= 'a { color: #' . $lcolor->hexValue() . ' }' . "\n"; if (!empty($this->backgroundimage) && $this->disposition & BACKGROUND_ON) { diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 99f2d9ece7..e1b92edce0 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -12,9 +12,9 @@ img { display:block; border:0; } a abbr { cursor: pointer; border-bottom:0; } table { border-collapse:collapse; } ol { list-style-position:inside; } -html { font-size: 87.5%; background-color:#fff; } +html { font-size: 87.5%; height:100%; } body { -background-color:#fff; +background-color:#FFFFFF; color:#000; font-family:sans-serif; font-size:1em; diff --git a/theme/default/css/display.css b/theme/default/css/display.css index 935116a74f..881e264da8 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -9,7 +9,6 @@ @import url(../../base/css/display.css); -html, body, a:active { background-color:#C3D6DF; diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 6845fda5f9..ad57a0f0e4 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -9,7 +9,6 @@ @import url(../../base/css/display.css); -html, body, a:active { background-color:#F0F2F5;