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()
109 foreach ($this->args as $key => $val) {
110 if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
117 $bgcolor = new WebColor($this->trimmed('design_background'));
118 $ccolor = new WebColor($this->trimmed('design_content'));
119 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
120 $tcolor = new WebColor($this->trimmed('design_text'));
121 $lcolor = new WebColor($this->trimmed('design_links'));
122 } catch (WebColorException $e) {
123 $this->showForm($e->getMessage());
127 $onoff = $this->arg('design_background-image_onoff');
133 if ($onoff == 'on') {
139 $repeat = $this->boolean('design_background-image_repeat');
145 $user = common_current_user();
146 $design = $user->getDesign();
148 if (!empty($design)) {
150 $original = clone($design);
152 $design->backgroundcolor = $bgcolor->intValue();
153 $design->contentcolor = $ccolor->intValue();
154 $design->sidebarcolor = $sbcolor->intValue();
155 $design->textcolor = $tcolor->intValue();
156 $design->linkcolor = $lcolor->intValue();
158 $design->setDisposition($on, $off, $tile);
160 $result = $design->update($original);
162 if ($result === false) {
163 common_log_db_error($design, 'UPDATE', __FILE__);
164 $this->showForm(_('Couldn\'t update your design.'));
171 $user->query('BEGIN');
174 $design = new Design();
176 $design->backgroundcolor = $bgcolor->intValue();
177 $design->contentcolor = $ccolor->intValue();
178 $design->sidebarcolor = $sbcolor->intValue();
179 $design->textcolor = $tcolor->intValue();
180 $design->linkcolor = $lcolor->intValue();
182 $design->setDisposition($on, $off, $tile);
184 $id = $design->insert();
187 common_log_db_error($id, 'INSERT', __FILE__);
188 $this->showForm(_('Unable to save your design settings!'));
192 $original = clone($user);
193 $user->design_id = $id;
194 $result = $user->update($original);
196 if (empty($result)) {
197 common_log_db_error($original, 'UPDATE', __FILE__);
198 $this->showForm(_('Unable to save your design settings!'));
199 $user->query('ROLLBACK');
203 $user->query('COMMIT');
207 $this->saveBackgroundImage($design);
209 $this->showForm(_('Design preferences saved.'), true);
213 * Alternate default colors
220 $user = common_current_user();
221 $design = $user->getDesign();
223 $user->query('BEGIN');
226 $design = new Design();
228 $design->backgroundcolor = 16184329;
229 $design->contentcolor = 16059904;
230 $design->sidebarcolor = 16059904;
231 $design->textcolor = 0;
232 $design->linkcolor = 16777215;
234 $design->setDisposition(false, true, false);
236 $id = $design->insert();
239 common_log_db_error($id, 'INSERT', __FILE__);
240 $this->showForm(_('Unable to save your design settings!'));
244 $original = clone($user);
245 $user->design_id = $id;
246 $result = $user->update($original);
248 if (empty($result)) {
249 common_log_db_error($original, 'UPDATE', __FILE__);
250 $this->showForm(_('Unable to save your design settings!'));
251 $user->query('ROLLBACK');
255 $user->query('COMMIT');
257 $this->saveBackgroundImage($design);
259 $this->showForm(_('Enjoy your hotdog!'), true);