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 $this->showForm(_('There was a problem with your session token. '.
123 'Try again, please.'));
127 if ($this->arg('save')) {
129 } else if ($this->arg('defaults')) {
130 $this->restoreDefaults();
132 // TRANS: Unknown form validation error in design settings form.
133 $this->showForm(_('Unexpected form submission.'));
138 * Add the Farbtastic stylesheet
142 function showStylesheets()
144 parent::showStylesheets();
145 $this->cssLink('js/farbtastic/farbtastic.css',null,'screen, projection, tv');
149 * Add the Farbtastic scripts
153 function showScripts()
155 parent::showScripts();
157 $this->script('farbtastic/farbtastic.js');
158 $this->script('userdesign.go.js');
160 $this->autofocus('design_background-image_file');
164 * Save the background image, if any, and set its disposition
166 * @param Design $design a working design to attach the img to
170 function saveBackgroundImage($design)
172 // Now that we have a Design ID we can add a file to the design.
173 // XXX: This is an additional DB hit, but figured having the image
174 // associated with the Design rather than the User was worth
177 if (array_key_exists('design_background-image_file', $_FILES) &&
178 $_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) {
183 $imagefile = ImageFile::fromUpload('design_background-image_file');
184 } catch (Exception $e) {
185 $this->showForm($e->getMessage());
189 $filename = Design::filename($design->id,
190 image_type_to_extension($imagefile->type),
193 $filepath = Design::path($filename);
195 move_uploaded_file($imagefile->filepath, $filepath);
197 // delete any old backround img laying around
199 if (isset($design->backgroundimage)) {
200 @unlink(Design::path($design->backgroundimage));
203 $original = clone($design);
205 $design->backgroundimage = $filename;
207 // default to on, no tile
209 $design->setDisposition(true, false, false);
211 $result = $design->update($original);
213 if ($result === false) {
214 common_log_db_error($design, 'UPDATE', __FILE__);
215 // TRANS: Error message displayed if design settings could not be saved.
216 $this->showForm(_('Couldn\'t update your design.'));
223 * Restore the user or group design to system defaults
227 function restoreDefaults()
229 $design = $this->getWorkingDesign();
231 if (!empty($design)) {
233 $result = $design->delete();
235 if ($result === false) {
236 common_log_db_error($design, 'DELETE', __FILE__);
237 // TRANS: Error message displayed if design settings could not be saved after clicking "Use defaults".
238 $this->showForm(_('Couldn\'t update your design.'));
243 // TRANS: Success message displayed if design settings were saved after clicking "Use defaults".
244 $this->showForm(_('Design defaults restored.'), true);