3 * Laconica, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Sarven Capadisli <csarven@controlyourself.ca>
25 * @author Zach Copley <zach@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/designsettings.php';
37 class UserDesignSettingsAction extends DesignSettingsAction
40 function prepare($args)
42 parent::prepare($args);
43 $this->submitaction = common_local_url('userdesignsettings');
50 * @return string Title of the page
55 return _('Profile design');
59 * Instructions for use
61 * @return instructions for use
64 function getInstructions()
66 return _('Customize the way your profile looks ' .
67 'with a background image and a colour palette of your choice.');
71 * Get the design we want to edit
76 function getWorkingDesign() {
78 $user = common_current_user();
79 $design = $user->getDesign();
82 $design = $this->defaultDesign();
89 * Content area of the page
91 * Shows a form for changing the design
96 function showContent()
98 $this->showDesignForm($this->getWorkingDesign());
102 * Save or update the user's design settings
107 function saveDesign()
111 $bgcolor = new WebColor($this->trimmed('design_background'));
112 $ccolor = new WebColor($this->trimmed('design_content'));
113 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
114 $tcolor = new WebColor($this->trimmed('design_text'));
115 $lcolor = new WebColor($this->trimmed('design_links'));
117 } catch (WebColorException $e) {
118 $this->showForm($e->getMessage());
122 $onoff = $this->arg('design_background-image_onoff');
128 if ($onoff == 'on') {
134 $repeat = $this->boolean('design_background-image_repeat');
140 $user = common_current_user();
141 $design = $user->getDesign();
143 if (!empty($design)) {
145 $original = clone($design);
147 $design->backgroundcolor = $bgcolor->intValue();
148 $design->contentcolor = $ccolor->intValue();
149 $design->sidebarcolor = $sbcolor->intValue();
150 $design->textcolor = $tcolor->intValue();
151 $design->linkcolor = $lcolor->intValue();
152 $design->backgroundimage = $filepath;
154 $design->setDisposition($on, $off, $tile);
156 $result = $design->update($original);
158 if ($result === false) {
159 common_log_db_error($design, 'UPDATE', __FILE__);
160 $this->showForm(_('Couldn\'t update your design.'));
167 $user->query('BEGIN');
170 $design = new Design();
172 $design->backgroundcolor = $bgcolor->intValue();
173 $design->contentcolor = $ccolor->intValue();
174 $design->sidebarcolor = $sbcolor->intValue();
175 $design->textcolor = $tcolor->intValue();
176 $design->linkcolor = $lcolor->intValue();
177 $design->backgroundimage = $filepath;
179 $design->setDisposition($on, $off, $tile);
181 $id = $design->insert();
184 common_log_db_error($id, 'INSERT', __FILE__);
185 $this->showForm(_('Unable to save your design settings!'));
189 $original = clone($user);
190 $user->design_id = $id;
191 $result = $user->update($original);
193 if (empty($result)) {
194 common_log_db_error($original, 'UPDATE', __FILE__);
195 $this->showForm(_('Unable to save your design settings!'));
196 $user->query('ROLLBACK');
200 $user->query('COMMIT');
204 $this->saveBackgroundImage($design);
206 $this->showForm(_('Design preferences saved.'), true);