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()
99 $user = common_current_user();
100 $design = $user->getDesign();
105 * Content area of the page
107 * Shows a form for changing the design
112 function showContent()
114 $design = $this->getWorkingDesign();
116 if (empty($design)) {
117 $design = Design::siteDesign();
120 $this->showDesignForm($design);
124 * Shows the design settings form
126 * @param Design $design a working design to show
131 function showDesignForm($design)
133 $form = new UserDesignForm($this, $design, $this->submitaction);
138 * Save or update the user's design settings
143 function saveDesign()
145 $this->saveDesignPreferences();
147 foreach ($this->args as $key => $val) {
148 if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
155 $bgcolor = new WebColor($this->trimmed('design_background'));
156 $ccolor = new WebColor($this->trimmed('design_content'));
157 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
158 $tcolor = new WebColor($this->trimmed('design_text'));
159 $lcolor = new WebColor($this->trimmed('design_links'));
160 } catch (WebColorException $e) {
161 $this->showForm($e->getMessage());
165 $onoff = $this->arg('design_background-image_onoff');
171 if ($onoff == 'on') {
177 $repeat = $this->boolean('design_background-image_repeat');
183 $user = common_current_user();
185 $design = $user->getDesign();
187 if (!empty($design)) {
189 $original = clone($design);
191 $design->backgroundcolor = $bgcolor->intValue();
192 $design->contentcolor = $ccolor->intValue();
193 $design->sidebarcolor = $sbcolor->intValue();
194 $design->textcolor = $tcolor->intValue();
195 $design->linkcolor = $lcolor->intValue();
197 $design->setDisposition($on, $off, $tile);
199 $result = $design->update($original);
201 if ($result === false) {
202 common_log_db_error($design, 'UPDATE', __FILE__);
203 $this->showForm(_('Couldn\'t update your design.'));
210 $user->query('BEGIN');
213 $design = new Design();
215 $design->backgroundcolor = $bgcolor->intValue();
216 $design->contentcolor = $ccolor->intValue();
217 $design->sidebarcolor = $sbcolor->intValue();
218 $design->textcolor = $tcolor->intValue();
219 $design->linkcolor = $lcolor->intValue();
221 $design->setDisposition($on, $off, $tile);
223 $id = $design->insert();
226 common_log_db_error($id, 'INSERT', __FILE__);
227 $this->showForm(_('Unable to save your design settings.'));
231 $original = clone($user);
232 $user->design_id = $id;
233 $result = $user->update($original);
235 if (empty($result)) {
236 common_log_db_error($original, 'UPDATE', __FILE__);
237 $this->showForm(_('Unable to save your design settings.'));
238 $user->query('ROLLBACK');
242 $user->query('COMMIT');
246 $this->saveBackgroundImage($design);
248 $this->showForm(_('Design preferences saved.'), true);
252 * Alternate default colors
260 $user = common_current_user();
261 $design = $user->getDesign();
263 $user->query('BEGIN');
266 $design = new Design();
268 $design->backgroundcolor = 16184329;
269 $design->contentcolor = 16059904;
270 $design->sidebarcolor = 16059904;
271 $design->textcolor = 0;
272 $design->linkcolor = 16777215;
274 $design->setDisposition(false, true, false);
276 $id = $design->insert();
279 common_log_db_error($id, 'INSERT', __FILE__);
280 $this->showForm(_('Unable to save your design settings.'));
284 $original = clone($user);
285 $user->design_id = $id;
286 $result = $user->update($original);
288 if (empty($result)) {
289 common_log_db_error($original, 'UPDATE', __FILE__);
290 $this->showForm(_('Unable to save your design settings.'));
291 $user->query('ROLLBACK');
295 $user->query('COMMIT');
297 $this->saveBackgroundImage($design);
299 $this->showForm(_('Enjoy your hotdog!'), true);
302 function saveDesignPreferences()
304 $viewdesigns = $this->boolean('viewdesigns');
306 $user = common_current_user();
308 $original = clone($user);
310 $user->viewdesigns = $viewdesigns;
312 $result = $user->update($original);
314 if ($result === false) {
315 common_log_db_error($user, 'UPDATE', __FILE__);
316 throw new ServerException(_('Couldn\'t update user.'));
321 class UserDesignForm extends DesignForm
323 function __construct($out, $design, $actionurl)
325 parent::__construct($out, $design, $actionurl);
333 function formLegend()
335 $this->out->element('legend', null, _('Design settings'));
339 * Data elements of the form
346 $user = common_current_user();
348 $this->out->elementStart('ul', 'form_data');
349 $this->out->elementStart('li');
350 $this->out->checkbox('viewdesigns', _('View profile designs'),
351 - $user->viewdesigns, _('Show or hide profile designs.'));
352 $this->out->elementEnd('li');
353 $this->out->elementEnd('ul');
355 $this->out->elementEnd('fieldset');
357 $this->out->elementStart('fieldset');
358 $this->out->element('legend', null, _('Background file'));