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/accountsettingsaction.php';
36 require_once INSTALLDIR . '/lib/webcolor.php';
39 * Base class for setting a user or group design
41 * Shows the design setting form and also handles some things like saving
42 * background images, and fetching a default design
46 * @author Zach Copley <zach@status.net>
47 * @author Sarven Capadisli <csarven@status.net>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://status.net/
51 class DesignSettingsAction extends AccountSettingsAction
53 var $submitaction = null;
58 * @return string Title of the page
62 // TRANS: Page title for profile design page.
63 return _('Profile design');
67 * Instructions for use
69 * @return instructions for use
71 function getInstructions()
73 // TRANS: Instructions for profile design page.
74 return _('Customize the way your profile looks ' .
75 'with a background image and a colour palette of your choice.');
79 * Shows the design settings form
81 * @param Design $design a working design to show
85 function showDesignForm($design)
87 $form = new DesignForm($this, $design, $this->selfUrl());
95 * Validate input and save changes. Reload the form with a success
100 function handlePost()
102 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
104 // Workaround for PHP returning empty $_POST and $_FILES when POST
105 // length > post_max_size in php.ini
109 && ($_SERVER['CONTENT_LENGTH'] > 0)
111 // TRANS: Form validation error in design settings form. POST should remain untranslated.
112 $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
113 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
114 intval($_SERVER['CONTENT_LENGTH']));
116 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
122 $token = $this->trimmed('token');
123 if (!$token || $token != common_session_token()) {
124 $this->showForm(_('There was a problem with your session token. '.
125 'Try again, please.'));
129 if ($this->arg('save')) {
131 } else if ($this->arg('defaults')) {
132 $this->restoreDefaults();
134 // TRANS: Unknown form validation error in design settings form.
135 $this->showForm(_('Unexpected form submission.'));
140 * Add the Farbtastic stylesheet
144 function showStylesheets()
146 parent::showStylesheets();
147 $this->cssLink('js/farbtastic/farbtastic.css',null,'screen, projection, tv');
151 * Add the Farbtastic scripts
155 function showScripts()
157 parent::showScripts();
159 $this->script('farbtastic/farbtastic.js');
160 $this->script('userdesign.go.js');
162 $this->autofocus('design_background-image_file');
166 * Save the background image, if any, and set its disposition
168 * @param Design $design a working design to attach the img to
172 function saveBackgroundImage($design)
174 // Now that we have a Design ID we can add a file to the design.
175 // XXX: This is an additional DB hit, but figured having the image
176 // associated with the Design rather than the User was worth
179 if (array_key_exists('design_background-image_file', $_FILES) &&
180 $_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) {
185 $imagefile = ImageFile::fromUpload('design_background-image_file');
186 } catch (Exception $e) {
187 $this->showForm($e->getMessage());
191 $filename = Design::filename($design->id,
192 image_type_to_extension($imagefile->type),
195 $filepath = Design::path($filename);
197 move_uploaded_file($imagefile->filepath, $filepath);
199 // delete any old backround img laying around
201 if (isset($design->backgroundimage)) {
202 @unlink(Design::path($design->backgroundimage));
205 $original = clone($design);
207 $design->backgroundimage = $filename;
209 // default to on, no tile
211 $design->setDisposition(true, false, false);
213 $result = $design->update($original);
215 if ($result === false) {
216 common_log_db_error($design, 'UPDATE', __FILE__);
217 // TRANS: Error message displayed if design settings could not be saved.
218 $this->showForm(_('Couldn\'t update your design.'));
225 * Restore the user or group design to system defaults
229 function restoreDefaults()
231 $design = $this->getWorkingDesign();
233 if (!empty($design)) {
235 $result = $design->delete();
237 if ($result === false) {
238 common_log_db_error($design, 'DELETE', __FILE__);
239 // TRANS: Error message displayed if design settings could not be saved after clicking "Use defaults".
240 $this->showForm(_('Couldn\'t update your design.'));
245 // TRANS: Success message displayed if design settings were saved after clicking "Use defaults".
246 $this->showForm(_('Design defaults restored.'), true);