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/
52 class DesignSettingsAction extends AccountSettingsAction
55 var $submitaction = null;
60 * @return string Title of the page
65 return _('Profile design');
69 * Instructions for use
71 * @return instructions for use
74 function getInstructions()
76 return _('Customize the way your profile looks ' .
77 'with a background image and a colour palette of your choice.');
81 * Shows the design settings form
83 * @param Design $design a working design to show
88 function showDesignForm($design)
90 $form = new DesignForm($this, $design, $this->selfUrl());
97 * Validate input and save changes. Reload the form with a success
103 function handlePost()
105 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
107 // Workaround for PHP returning empty $_POST and $_FILES when POST
108 // length > post_max_size in php.ini
112 && ($_SERVER['CONTENT_LENGTH'] > 0)
114 $msg = _('The server was unable to handle that much POST ' .
115 'data (%s bytes) due to its current configuration.');
117 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
123 $token = $this->trimmed('token');
124 if (!$token || $token != common_session_token()) {
125 $this->showForm(_('There was a problem with your session token. '.
126 'Try again, please.'));
130 if ($this->arg('save')) {
132 } else if ($this->arg('defaults')) {
133 $this->restoreDefaults();
135 $this->showForm(_('Unexpected form submission.'));
140 * Add the Farbtastic stylesheet
145 function showStylesheets()
147 parent::showStylesheets();
148 $this->cssLink('js/farbtastic/farbtastic.css',null,'screen, projection, tv');
152 * Add the Farbtastic scripts
157 function showScripts()
159 parent::showScripts();
161 $this->script('farbtastic/farbtastic.js');
162 $this->script('userdesign.go.js');
164 $this->autofocus('design_background-image_file');
168 * Save the background image, if any, and set its disposition
170 * @param Design $design a working design to attach the img to
175 function saveBackgroundImage($design)
178 // Now that we have a Design ID we can add a file to the design.
179 // XXX: This is an additional DB hit, but figured having the image
180 // associated with the Design rather than the User was worth
183 if ($_FILES['design_background-image_file']['error'] ==
190 ImageFile::fromUpload('design_background-image_file');
191 } catch (Exception $e) {
192 $this->showForm($e->getMessage());
196 $filename = Design::filename($design->id,
197 image_type_to_extension($imagefile->type),
200 $filepath = Design::path($filename);
202 move_uploaded_file($imagefile->filepath, $filepath);
204 // delete any old backround img laying around
206 if (isset($design->backgroundimage)) {
207 @unlink(Design::path($design->backgroundimage));
210 $original = clone($design);
212 $design->backgroundimage = $filename;
214 // default to on, no tile
216 $design->setDisposition(true, false, false);
218 $result = $design->update($original);
220 if ($result === false) {
221 common_log_db_error($design, 'UPDATE', __FILE__);
222 $this->showForm(_('Couldn\'t update your design.'));
229 * Restore the user or group design to system defaults
234 function restoreDefaults()
236 $design = $this->getWorkingDesign();
238 if (!empty($design)) {
240 $result = $design->delete();
242 if ($result === false) {
243 common_log_db_error($design, 'DELETE', __FILE__);
244 $this->showForm(_('Couldn\'t update your design.'));
249 $this->showForm(_('Design defaults restored.'), true);