3 * StatusNet, 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@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/designsettings.php';
40 * Saves a design for a given user
44 * @author Zach Copley <zach@status.net>
45 * @author Sarven Capadisli <csarven@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
50 class UserDesignSettingsAction extends DesignSettingsAction
53 * Sets the right action for the form, and passes request args into
56 * @param array $args misc. arguments
58 * @return boolean true
61 function prepare($args)
63 parent::prepare($args);
64 $this->submitaction = common_local_url('userdesignsettings');
71 * @return string Title of the page
76 return _('Profile design');
80 * Instructions for use
82 * @return instructions for use
85 function getInstructions()
87 return _('Customize the way your profile looks ' .
88 'with a background image and a colour palette of your choice.');
92 * Get the design we want to edit
97 function getWorkingDesign()
100 $user = common_current_user();
101 $design = $user->getDesign();
103 if (empty($design)) {
104 $design = $this->defaultDesign();
111 * Content area of the page
113 * Shows a form for changing the design
118 function showContent()
120 $this->showDesignForm($this->getWorkingDesign());
124 * Save or update the user's design settings
129 function saveDesign()
131 foreach ($this->args as $key => $val) {
132 if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
139 $bgcolor = new WebColor($this->trimmed('design_background'));
140 $ccolor = new WebColor($this->trimmed('design_content'));
141 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
142 $tcolor = new WebColor($this->trimmed('design_text'));
143 $lcolor = new WebColor($this->trimmed('design_links'));
144 } catch (WebColorException $e) {
145 $this->showForm($e->getMessage());
149 $onoff = $this->arg('design_background-image_onoff');
155 if ($onoff == 'on') {
161 $repeat = $this->boolean('design_background-image_repeat');
167 $user = common_current_user();
168 $design = $user->getDesign();
170 if (!empty($design)) {
172 $original = clone($design);
174 $design->backgroundcolor = $bgcolor->intValue();
175 $design->contentcolor = $ccolor->intValue();
176 $design->sidebarcolor = $sbcolor->intValue();
177 $design->textcolor = $tcolor->intValue();
178 $design->linkcolor = $lcolor->intValue();
180 $design->setDisposition($on, $off, $tile);
182 $result = $design->update($original);
184 if ($result === false) {
185 common_log_db_error($design, 'UPDATE', __FILE__);
186 $this->showForm(_('Couldn\'t update your design.'));
193 $user->query('BEGIN');
196 $design = new Design();
198 $design->backgroundcolor = $bgcolor->intValue();
199 $design->contentcolor = $ccolor->intValue();
200 $design->sidebarcolor = $sbcolor->intValue();
201 $design->textcolor = $tcolor->intValue();
202 $design->linkcolor = $lcolor->intValue();
204 $design->setDisposition($on, $off, $tile);
206 $id = $design->insert();
209 common_log_db_error($id, 'INSERT', __FILE__);
210 $this->showForm(_('Unable to save your design settings!'));
214 $original = clone($user);
215 $user->design_id = $id;
216 $result = $user->update($original);
218 if (empty($result)) {
219 common_log_db_error($original, 'UPDATE', __FILE__);
220 $this->showForm(_('Unable to save your design settings!'));
221 $user->query('ROLLBACK');
225 $user->query('COMMIT');
229 $this->saveBackgroundImage($design);
231 $this->showForm(_('Design preferences saved.'), true);
235 * Alternate default colors
243 $user = common_current_user();
244 $design = $user->getDesign();
246 $user->query('BEGIN');
249 $design = new Design();
251 $design->backgroundcolor = 16184329;
252 $design->contentcolor = 16059904;
253 $design->sidebarcolor = 16059904;
254 $design->textcolor = 0;
255 $design->linkcolor = 16777215;
257 $design->setDisposition(false, true, false);
259 $id = $design->insert();
262 common_log_db_error($id, 'INSERT', __FILE__);
263 $this->showForm(_('Unable to save your design settings!'));
267 $original = clone($user);
268 $user->design_id = $id;
269 $result = $user->update($original);
271 if (empty($result)) {
272 common_log_db_error($original, 'UPDATE', __FILE__);
273 $this->showForm(_('Unable to save your design settings!'));
274 $user->query('ROLLBACK');
278 $user->query('COMMIT');
280 $this->saveBackgroundImage($design);
282 $this->showForm(_('Enjoy your hotdog!'), true);