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';
38 * Set a group's design
40 * Saves a design for a given group
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/
50 class GroupDesignSettingsAction extends DesignSettingsAction
55 * Sets the right action for the form, and passes request args into
58 * @param array $args misc. arguments
60 * @return boolean true
63 function prepare($args)
65 parent::prepare($args);
67 if (!common_logged_in()) {
68 $this->clientError(_('You must be logged in to edit a group.'));
72 $nickname_arg = $this->trimmed('nickname');
73 $nickname = common_canonical_nickname($nickname_arg);
75 // Permanent redirect on non-canonical nickname
77 if ($nickname_arg != $nickname) {
78 $args = array('nickname' => $nickname);
79 common_redirect(common_local_url('groupdesignsettings', $args), 301);
84 $this->clientError(_('No nickname.'), 404);
88 $groupid = $this->trimmed('groupid');
91 $this->group = User_group::staticGet('id', $groupid);
93 $local = Local_group::staticGet('nickname', $nickname);
95 $this->group = User_group::staticGet('id', $local->group_id);
100 $this->clientError(_('No such group.'), 404);
104 $cur = common_current_user();
106 if (!$cur->isAdmin($this->group)) {
107 $this->clientError(_('You must be an admin to edit the group.'), 403);
111 $this->submitaction = common_local_url('groupdesignsettings',
112 array('nickname' => $this->group->nickname));
118 * A design for this action
120 * if the group attribute has been set, returns that group's
123 * @return Design a design object to use
129 if (empty($this->group)) {
133 return $this->group->getDesign();
139 * @return string Title of the page
144 return _('Group design');
148 * Instructions for use
150 * @return instructions for use
153 function getInstructions()
155 return _('Customize the way your group looks ' .
156 'with a background image and a colour palette of your choice.');
160 * Override to show group nav stuff
165 function showLocalNav()
167 $nav = new GroupNav($this, $this->group);
172 * Get the design we want to edit
177 function getWorkingDesign()
181 if (isset($this->group)) {
182 $design = $this->group->getDesign();
189 * Content area of the page
191 * Shows a form for changing the design
196 function showContent()
198 $design = $this->getWorkingDesign();
200 if (empty($design)) {
201 $design = Design::siteDesign();
204 $this->showDesignForm($design);
208 * Save or update the group's design settings
213 function saveDesign()
217 $bgcolor = new WebColor($this->trimmed('design_background'));
218 $ccolor = new WebColor($this->trimmed('design_content'));
219 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
220 $tcolor = new WebColor($this->trimmed('design_text'));
221 $lcolor = new WebColor($this->trimmed('design_links'));
223 } catch (WebColorException $e) {
224 $this->showForm($e->getMessage());
228 $onoff = $this->arg('design_background-image_onoff');
234 if ($onoff == 'on') {
240 $repeat = $this->boolean('design_background-image_repeat');
246 $design = $this->group->getDesign();
248 if (!empty($design)) {
252 $original = clone($design);
254 $design->backgroundcolor = $bgcolor->intValue();
255 $design->contentcolor = $ccolor->intValue();
256 $design->sidebarcolor = $sbcolor->intValue();
257 $design->textcolor = $tcolor->intValue();
258 $design->linkcolor = $lcolor->intValue();
260 $design->setDisposition($on, $off, $tile);
262 $result = $design->update($original);
264 if ($result === false) {
265 common_log_db_error($design, 'UPDATE', __FILE__);
266 $this->showForm(_('Couldn\'t update your design.'));
272 $this->group->query('BEGIN');
276 $design = new Design();
278 $design->backgroundcolor = $bgcolor->intValue();
279 $design->contentcolor = $ccolor->intValue();
280 $design->sidebarcolor = $sbcolor->intValue();
281 $design->textcolor = $tcolor->intValue();
282 $design->linkcolor = $lcolor->intValue();
284 $design->setDisposition($on, $off, $tile);
286 $id = $design->insert();
289 common_log_db_error($id, 'INSERT', __FILE__);
290 $this->showForm(_('Unable to save your design settings.'));
294 $original = clone($this->group);
295 $this->group->design_id = $id;
296 $result = $this->group->update($original);
298 if (empty($result)) {
299 common_log_db_error($original, 'UPDATE', __FILE__);
300 $this->showForm(_('Unable to save your design settings.'));
301 $this->group->query('ROLLBACK');
305 $this->group->query('COMMIT');
309 $this->saveBackgroundImage($design);
311 $this->showForm(_('Design preferences saved.'), true);