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/
49 class UserDesignSettingsAction extends DesignSettingsAction
52 * Sets the right action for the form, and passes request args into
55 * @param array $args misc. arguments
57 * @return boolean true
60 function prepare($args)
62 parent::prepare($args);
63 $this->submitaction = common_local_url('userdesignsettings');
70 * @return string Title of the page
74 return _('Profile design');
78 * Instructions for use
80 * @return instructions for use
82 function getInstructions()
84 return _('Customize the way your profile looks ' .
85 'with a background image and a colour palette of your choice.');
89 * Get the design we want to edit
93 function getWorkingDesign()
95 $user = common_current_user();
96 $design = $user->getDesign();
101 * Content area of the page
103 * Shows a form for changing the design
107 function showContent()
109 $design = $this->getWorkingDesign();
111 if (empty($design)) {
112 $design = Design::siteDesign();
115 $this->showDesignForm($design);
119 * Shows the design settings form
121 * @param Design $design a working design to show
126 function showDesignForm($design)
128 $form = new UserDesignForm($this, $design, $this->submitaction);
133 * Save or update the user's design settings
137 function saveDesign()
139 $this->saveDesignPreferences();
141 foreach ($this->args as $key => $val) {
142 if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
149 $bgcolor = new WebColor($this->trimmed('design_background'));
150 $ccolor = new WebColor($this->trimmed('design_content'));
151 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
152 $tcolor = new WebColor($this->trimmed('design_text'));
153 $lcolor = new WebColor($this->trimmed('design_links'));
154 } catch (WebColorException $e) {
155 $this->showForm($e->getMessage());
159 $onoff = $this->arg('design_background-image_onoff');
165 if ($onoff == 'on') {
171 $repeat = $this->boolean('design_background-image_repeat');
177 $user = common_current_user();
179 $design = $user->getDesign();
181 if (!empty($design)) {
182 $original = clone($design);
184 $design->backgroundcolor = $bgcolor->intValue();
185 $design->contentcolor = $ccolor->intValue();
186 $design->sidebarcolor = $sbcolor->intValue();
187 $design->textcolor = $tcolor->intValue();
188 $design->linkcolor = $lcolor->intValue();
190 $design->setDisposition($on, $off, $tile);
192 $result = $design->update($original);
194 if ($result === false) {
195 common_log_db_error($design, 'UPDATE', __FILE__);
196 $this->showForm(_('Could not update your design.'));
201 $user->query('BEGIN');
204 $design = new Design();
206 $design->backgroundcolor = $bgcolor->intValue();
207 $design->contentcolor = $ccolor->intValue();
208 $design->sidebarcolor = $sbcolor->intValue();
209 $design->textcolor = $tcolor->intValue();
210 $design->linkcolor = $lcolor->intValue();
212 $design->setDisposition($on, $off, $tile);
214 $id = $design->insert();
217 common_log_db_error($id, 'INSERT', __FILE__);
218 $this->showForm(_('Unable to save your design settings.'));
222 $original = clone($user);
223 $user->design_id = $id;
224 $result = $user->update($original);
226 if (empty($result)) {
227 common_log_db_error($original, 'UPDATE', __FILE__);
228 $this->showForm(_('Unable to save your design settings.'));
229 $user->query('ROLLBACK');
233 $user->query('COMMIT');
237 $this->saveBackgroundImage($design);
239 $this->showForm(_('Design preferences saved.'), true);
243 * Alternate default colors
250 $user = common_current_user();
251 $design = $user->getDesign();
253 $user->query('BEGIN');
256 $design = new Design();
258 $design->backgroundcolor = 16184329;
259 $design->contentcolor = 16059904;
260 $design->sidebarcolor = 16059904;
261 $design->textcolor = 0;
262 $design->linkcolor = 16777215;
264 $design->setDisposition(false, true, false);
266 $id = $design->insert();
269 common_log_db_error($id, 'INSERT', __FILE__);
270 $this->showForm(_('Unable to save your design settings.'));
274 $original = clone($user);
275 $user->design_id = $id;
276 $result = $user->update($original);
278 if (empty($result)) {
279 common_log_db_error($original, 'UPDATE', __FILE__);
280 $this->showForm(_('Unable to save your design settings.'));
281 $user->query('ROLLBACK');
285 $user->query('COMMIT');
287 $this->saveBackgroundImage($design);
289 $this->showForm(_('Enjoy your hotdog!'), true);
292 function saveDesignPreferences()
294 $viewdesigns = $this->boolean('viewdesigns');
296 $user = common_current_user();
298 $original = clone($user);
300 $user->viewdesigns = $viewdesigns;
302 $result = $user->update($original);
304 if ($result === false) {
305 common_log_db_error($user, 'UPDATE', __FILE__);
306 throw new ServerException(_('Couldn\'t update user.'));
311 class UserDesignForm extends DesignForm
313 function __construct($out, $design, $actionurl)
315 parent::__construct($out, $design, $actionurl);
323 function formLegend()
325 $this->out->element('legend', null, _('Design settings'));
329 * Data elements of the form
336 $user = common_current_user();
338 $this->out->elementStart('ul', 'form_data');
339 $this->out->elementStart('li');
340 $this->out->checkbox('viewdesigns', _('View profile designs'),
341 - $user->viewdesigns, _('Show or hide profile designs.'));
342 $this->out->elementEnd('li');
343 $this->out->elementEnd('ul');
345 $this->out->elementEnd('fieldset');
347 $this->out->elementStart('fieldset');
348 $this->out->element('legend', null, _('Background file'));