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()
179 if (isset($this->group)) {
180 $design = $this->group->getDesign();
183 if (empty($design)) {
184 $design = $this->defaultDesign();
191 * Content area of the page
193 * Shows a form for changing the design
198 function showContent()
200 $this->showDesignForm($this->getWorkingDesign());
204 * Save or update the group's design settings
209 function saveDesign()
213 $bgcolor = new WebColor($this->trimmed('design_background'));
214 $ccolor = new WebColor($this->trimmed('design_content'));
215 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
216 $tcolor = new WebColor($this->trimmed('design_text'));
217 $lcolor = new WebColor($this->trimmed('design_links'));
219 } catch (WebColorException $e) {
220 $this->showForm($e->getMessage());
224 $onoff = $this->arg('design_background-image_onoff');
230 if ($onoff == 'on') {
236 $repeat = $this->boolean('design_background-image_repeat');
242 $design = $this->group->getDesign();
244 if (!empty($design)) {
248 $original = clone($design);
250 $design->backgroundcolor = $bgcolor->intValue();
251 $design->contentcolor = $ccolor->intValue();
252 $design->sidebarcolor = $sbcolor->intValue();
253 $design->textcolor = $tcolor->intValue();
254 $design->linkcolor = $lcolor->intValue();
256 $design->setDisposition($on, $off, $tile);
258 $result = $design->update($original);
260 if ($result === false) {
261 common_log_db_error($design, 'UPDATE', __FILE__);
262 $this->showForm(_('Couldn\'t update your design.'));
268 $this->group->query('BEGIN');
272 $design = new Design();
274 $design->backgroundcolor = $bgcolor->intValue();
275 $design->contentcolor = $ccolor->intValue();
276 $design->sidebarcolor = $sbcolor->intValue();
277 $design->textcolor = $tcolor->intValue();
278 $design->linkcolor = $lcolor->intValue();
280 $design->setDisposition($on, $off, $tile);
282 $id = $design->insert();
285 common_log_db_error($id, 'INSERT', __FILE__);
286 $this->showForm(_('Unable to save your design settings!'));
290 $original = clone($this->group);
291 $this->group->design_id = $id;
292 $result = $this->group->update($original);
294 if (empty($result)) {
295 common_log_db_error($original, 'UPDATE', __FILE__);
296 $this->showForm(_('Unable to save your design settings!'));
297 $this->group->query('ROLLBACK');
301 $this->group->query('COMMIT');
305 $this->saveBackgroundImage($design);
307 $this->showForm(_('Design preferences saved.'), true);