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 // TRANS: Title for profile design page.
75 return _('Profile design');
79 * Instructions for use
81 * @return instructions for use
83 function getInstructions()
85 // TRANS: Instructions for Profile design page.
86 return _('Customize the way your profile looks ' .
87 'with a background image and a colour palette of your choice.');
91 * Get the design we want to edit
95 function getWorkingDesign()
97 $user = common_current_user();
98 $design = $user->getDesign();
103 * Content area of the page
105 * Shows a form for changing the design
109 function showContent()
111 $design = $this->getWorkingDesign();
113 if (empty($design)) {
114 $design = Design::siteDesign();
117 $this->showDesignForm($design);
121 * Shows the design settings form
123 * @param Design $design a working design to show
128 function showDesignForm($design)
130 $form = new UserDesignForm($this, $design, $this->submitaction);
135 * Save or update the user's design settings
139 function saveDesign()
141 $this->saveDesignPreferences();
143 foreach ($this->args as $key => $val) {
144 if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
151 $bgcolor = new WebColor($this->trimmed('design_background'));
152 $ccolor = new WebColor($this->trimmed('design_content'));
153 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
154 $tcolor = new WebColor($this->trimmed('design_text'));
155 $lcolor = new WebColor($this->trimmed('design_links'));
156 } catch (WebColorException $e) {
157 $this->showForm($e->getMessage());
161 $onoff = $this->arg('design_background-image_onoff');
167 if ($onoff == 'on') {
173 $repeat = $this->boolean('design_background-image_repeat');
179 $user = common_current_user();
181 $design = $user->getDesign();
183 if (!empty($design)) {
184 $original = clone($design);
186 $design->backgroundcolor = $bgcolor->intValue();
187 $design->contentcolor = $ccolor->intValue();
188 $design->sidebarcolor = $sbcolor->intValue();
189 $design->textcolor = $tcolor->intValue();
190 $design->linkcolor = $lcolor->intValue();
192 $design->setDisposition($on, $off, $tile);
194 $result = $design->update($original);
196 if ($result === false) {
197 common_log_db_error($design, 'UPDATE', __FILE__);
198 // TRANS: Form validation error on Profile design page when updating design settings has failed.
199 $this->showForm(_('Could not update your design.'));
204 $user->query('BEGIN');
207 $design = new Design();
209 $design->backgroundcolor = $bgcolor->intValue();
210 $design->contentcolor = $ccolor->intValue();
211 $design->sidebarcolor = $sbcolor->intValue();
212 $design->textcolor = $tcolor->intValue();
213 $design->linkcolor = $lcolor->intValue();
215 $design->setDisposition($on, $off, $tile);
217 $id = $design->insert();
220 common_log_db_error($id, 'INSERT', __FILE__);
221 // TRANS: Form validation error on Profile design page when saving design settings has failed.
222 $this->showForm(_('Unable to save your design settings.'));
226 $original = clone($user);
227 $user->design_id = $id;
228 $result = $user->update($original);
230 if (empty($result)) {
231 common_log_db_error($original, 'UPDATE', __FILE__);
232 // TRANS: Form validation error on Profile design page when saving design settings has failed.
233 $this->showForm(_('Unable to save your design settings.'));
234 $user->query('ROLLBACK');
238 $user->query('COMMIT');
242 $this->saveBackgroundImage($design);
244 // TRANS: Confirmation message on Profile design page when saving design settings has succeeded.
245 $this->showForm(_('Design preferences saved.'), true);
249 * Alternate default colors
255 $user = common_current_user();
256 $design = $user->getDesign();
258 $user->query('BEGIN');
261 $design = new Design();
263 $design->backgroundcolor = 16184329;
264 $design->contentcolor = 16059904;
265 $design->sidebarcolor = 16059904;
266 $design->textcolor = 0;
267 $design->linkcolor = 16777215;
269 $design->setDisposition(false, true, false);
271 $id = $design->insert();
274 common_log_db_error($id, 'INSERT', __FILE__);
275 // TRANS: Form validation error on Profile design page when saving design settings has failed.
276 $this->showForm(_('Unable to save your design settings.'));
280 $original = clone($user);
281 $user->design_id = $id;
282 $result = $user->update($original);
284 if (empty($result)) {
285 common_log_db_error($original, 'UPDATE', __FILE__);
286 // TRANS: Form validation error on Profile design page when updating design settings has failed.
287 $this->showForm(_('Unable to save your design settings.'));
288 $user->query('ROLLBACK');
292 $user->query('COMMIT');
294 $this->saveBackgroundImage($design);
296 // TRANS: Succes message on Profile design page when finding an easter egg.
297 $this->showForm(_('Enjoy your hotdog!'), true);
300 function saveDesignPreferences()
302 $viewdesigns = $this->boolean('viewdesigns');
304 $user = common_current_user();
306 $original = clone($user);
308 $user->viewdesigns = $viewdesigns;
310 $result = $user->update($original);
312 if ($result === false) {
313 common_log_db_error($user, 'UPDATE', __FILE__);
314 // TRANS: Server exception thrown on Profile design page when updating design settings fails.
315 throw new ServerException(_('Could not update user.'));
320 class UserDesignForm extends DesignForm
322 function __construct($out, $design, $actionurl)
324 parent::__construct($out, $design, $actionurl);
332 function formLegend()
334 // TRANS: Form legend on Profile design page.
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 // TRANS: Checkbox label on Profile design page.
351 $this->out->checkbox('viewdesigns', _('View profile designs'),
352 // TRANS: Title for checkbox on Profile design page.
353 - $user->viewdesigns, _('Show or hide profile designs.'));
354 $this->out->elementEnd('li');
355 $this->out->elementEnd('ul');
357 $this->out->elementEnd('fieldset');
359 $this->out->elementStart('fieldset');
360 // TRANS: Form legend on Profile design page for form to choose a background image.
361 $this->out->element('legend', null, _('Background file'));