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')) {
36 * Base class for setting a user or group design
38 * Shows the design setting form and also handles some things like saving
39 * background images, and fetching a default design
43 * @author Zach Copley <zach@status.net>
44 * @author Sarven Capadisli <csarven@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 class DesignSettingsAction extends SettingsAction
51 var $submitaction = null;
56 * @return string Title of the page
60 // TRANS: Page title for profile design page.
61 return _('Profile design');
65 * Instructions for use
67 * @return instructions for use
69 function getInstructions()
71 // TRANS: Instructions for profile design page.
72 return _('Customize the way your profile looks ' .
73 'with a background image and a colour palette of your choice.');
77 * Shows the design settings form
79 * @param Design $design a working design to show
83 function showDesignForm($design)
85 $form = new DesignForm($this, $design, $this->selfUrl());
93 * Validate input and save changes. Reload the form with a success
100 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
102 // Workaround for PHP returning empty $_POST and $_FILES when POST
103 // length > post_max_size in php.ini
107 && ($_SERVER['CONTENT_LENGTH'] > 0)
109 // TRANS: Form validation error in design settings form. POST should remain untranslated.
110 $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
111 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
112 intval($_SERVER['CONTENT_LENGTH']));
114 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
120 $token = $this->trimmed('token');
121 if (!$token || $token != common_session_token()) {
122 // TRANS: Client error displayed when the session token does not match or is not given.
123 $this->showForm(_('There was a problem with your session token. '.
124 'Try again, please.'));
128 if ($this->arg('save')) {
130 } else if ($this->arg('defaults')) {
131 $this->restoreDefaults();
133 // TRANS: Unknown form validation error in design settings form.
134 $this->showForm(_('Unexpected form submission.'));
139 * Add the Farbtastic stylesheet
143 function showStylesheets()
145 parent::showStylesheets();
146 $this->cssLink('js/farbtastic/farbtastic.css',null,'screen, projection, tv');
150 * Add the Farbtastic scripts
154 function showScripts()
156 parent::showScripts();
158 $this->script('farbtastic/farbtastic.js');
159 $this->script('userdesign.go.js');
161 $this->autofocus('design_background-image_file');
165 * Save the background image, if any, and set its disposition
167 * @param Design $design a working design to attach the img to
171 function saveBackgroundImage($design)
173 // Now that we have a Design ID we can add a file to the design.
174 // XXX: This is an additional DB hit, but figured having the image
175 // associated with the Design rather than the User was worth
178 if (array_key_exists('design_background-image_file', $_FILES) &&
179 $_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) {
184 $imagefile = ImageFile::fromUpload('design_background-image_file');
185 } catch (Exception $e) {
186 $this->showForm($e->getMessage());
190 $filename = Design::filename($design->id,
191 image_type_to_extension($imagefile->type),
194 $filepath = Design::path($filename);
196 move_uploaded_file($imagefile->filepath, $filepath);
198 // delete any old backround img laying around
200 if (isset($design->backgroundimage)) {
201 @unlink(Design::path($design->backgroundimage));
204 $original = clone($design);
206 $design->backgroundimage = $filename;
208 // default to on, no tile
210 $design->setDisposition(true, false, false);
212 $result = $design->update($original);
214 if ($result === false) {
215 common_log_db_error($design, 'UPDATE', __FILE__);
216 // TRANS: Error message displayed if design settings could not be saved.
217 $this->showForm(_('Could not update your design.'));
224 * Restore the user or group design to system defaults
228 function restoreDefaults()
230 $design = $this->getWorkingDesign();
232 if (!empty($design)) {
234 $result = $design->delete();
236 if ($result === false) {
237 common_log_db_error($design, 'DELETE', __FILE__);
238 // TRANS: Error message displayed if design settings could not be saved after clicking "Use defaults".
239 $this->showForm(_('Could not update your design.'));
244 // TRANS: Success message displayed if design settings were saved after clicking "Use defaults".
245 $this->showForm(_('Design defaults restored.'), true);