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 $this->group = User_group::staticGet('nickname', $nickname);
97 $this->clientError(_('No such group'), 404);
101 $cur = common_current_user();
103 if (!$cur->isAdmin($this->group)) {
104 $this->clientError(_('You must be an admin to edit the group'), 403);
108 $this->submitaction = common_local_url('groupdesignsettings',
109 array('nickname' => $this->group->nickname));
115 * A design for this action
117 * if the group attribute has been set, returns that group's
120 * @return Design a design object to use
126 if (empty($this->group)) {
130 return $this->group->getDesign();
136 * @return string Title of the page
141 return _('Group design');
145 * Instructions for use
147 * @return instructions for use
150 function getInstructions()
152 return _('Customize the way your group looks ' .
153 'with a background image and a colour palette of your choice.');
157 * Override to show group nav stuff
162 function showLocalNav()
164 $nav = new GroupNav($this, $this->group);
169 * Get the design we want to edit
174 function getWorkingDesign()
178 if (isset($this->group)) {
179 $design = $this->group->getDesign();
186 * Content area of the page
188 * Shows a form for changing the design
193 function showContent()
195 $design = $this->getWorkingDesign();
197 if (empty($design)) {
198 $design = Design::siteDesign();
201 $this->showDesignForm($design);
205 * Save or update the group's design settings
210 function saveDesign()
214 $bgcolor = new WebColor($this->trimmed('design_background'));
215 $ccolor = new WebColor($this->trimmed('design_content'));
216 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
217 $tcolor = new WebColor($this->trimmed('design_text'));
218 $lcolor = new WebColor($this->trimmed('design_links'));
220 } catch (WebColorException $e) {
221 $this->showForm($e->getMessage());
225 $onoff = $this->arg('design_background-image_onoff');
231 if ($onoff == 'on') {
237 $repeat = $this->boolean('design_background-image_repeat');
243 $design = $this->group->getDesign();
245 if (!empty($design)) {
249 $original = clone($design);
251 $design->backgroundcolor = $bgcolor->intValue();
252 $design->contentcolor = $ccolor->intValue();
253 $design->sidebarcolor = $sbcolor->intValue();
254 $design->textcolor = $tcolor->intValue();
255 $design->linkcolor = $lcolor->intValue();
257 $design->setDisposition($on, $off, $tile);
259 $result = $design->update($original);
261 if ($result === false) {
262 common_log_db_error($design, 'UPDATE', __FILE__);
263 $this->showForm(_('Couldn\'t update your design.'));
269 $this->group->query('BEGIN');
273 $design = new Design();
275 $design->backgroundcolor = $bgcolor->intValue();
276 $design->contentcolor = $ccolor->intValue();
277 $design->sidebarcolor = $sbcolor->intValue();
278 $design->textcolor = $tcolor->intValue();
279 $design->linkcolor = $lcolor->intValue();
281 $design->setDisposition($on, $off, $tile);
283 $id = $design->insert();
286 common_log_db_error($id, 'INSERT', __FILE__);
287 $this->showForm(_('Unable to save your design settings!'));
291 $original = clone($this->group);
292 $this->group->design_id = $id;
293 $result = $this->group->update($original);
295 if (empty($result)) {
296 common_log_db_error($original, 'UPDATE', __FILE__);
297 $this->showForm(_('Unable to save your design settings!'));
298 $this->group->query('ROLLBACK');
302 $this->group->query('COMMIT');
306 $this->saveBackgroundImage($design);
308 $this->showForm(_('Design preferences saved.'), true);