3 * StatusNet, the distributed open-source microblogging tool
5 * Saves a design for a given group.
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/
49 class GroupDesignSettingsAction extends DesignSettingsAction
54 * Sets the right action for the form, and passes request args into
57 * @param array $args misc. arguments
59 * @return boolean true
61 function prepare($args)
63 parent::prepare($args);
65 if (!common_logged_in()) {
66 // TRANS: Client error displayed trying to change group design settings while not logged in.
67 $this->clientError(_('You must be logged in to edit a group.'));
71 $nickname_arg = $this->trimmed('nickname');
72 $nickname = common_canonical_nickname($nickname_arg);
74 // Permanent redirect on non-canonical nickname
76 if ($nickname_arg != $nickname) {
77 $args = array('nickname' => $nickname);
78 common_redirect(common_local_url('groupdesignsettings', $args), 301);
83 // TRANS: Client error displayed trying to change group design settings without providing a group nickname.
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 // TRANS: Client error displayed trying to change group design settings while providing a nickname for a non-existing group.
101 $this->clientError(_('No such group.'), 404);
105 $cur = common_current_user();
107 if (!$cur->isAdmin($this->group)) {
108 // TRANS: Client error displayed trying to change group design settings without being a (group) admin.
109 $this->clientError(_('You must be an admin to edit the group.'), 403);
113 $this->submitaction = common_local_url('groupdesignsettings',
114 array('nickname' => $this->group->nickname));
120 * A design for this action
122 * if the group attribute has been set, returns that group's
125 * @return Design a design object to use
130 if (empty($this->group)) {
134 return $this->group->getDesign();
140 * @return string Title of the page
145 // TRANS: Title group design settings page.
146 return _('Group design');
150 * Instructions for use
152 * @return instructions for use
154 function getInstructions()
156 // TRANS: Instructions for group design settings page.
157 return _('Customize the way your group looks ' .
158 'with a background image and a colour palette of your choice.');
162 * Override to show group nav stuff
166 function showLocalNav()
168 $nav = new GroupNav($this, $this->group);
173 * 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
195 function showContent()
197 $design = $this->getWorkingDesign();
199 if (empty($design)) {
200 $design = Design::siteDesign();
203 $this->showDesignForm($design);
207 * Save or update the group's design settings
211 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'));
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)) {
247 $original = clone($design);
249 $design->backgroundcolor = $bgcolor->intValue();
250 $design->contentcolor = $ccolor->intValue();
251 $design->sidebarcolor = $sbcolor->intValue();
252 $design->textcolor = $tcolor->intValue();
253 $design->linkcolor = $lcolor->intValue();
255 $design->setDisposition($on, $off, $tile);
257 $result = $design->update($original);
259 if ($result === false) {
260 common_log_db_error($design, 'UPDATE', __FILE__);
261 // TRANS: Form validation error displayed when group design settings could not be updated because of an application issue.
262 $this->showForm(_('Unable to update your design settings.'));
266 $this->group->query('BEGIN');
270 $design = new Design();
272 $design->backgroundcolor = $bgcolor->intValue();
273 $design->contentcolor = $ccolor->intValue();
274 $design->sidebarcolor = $sbcolor->intValue();
275 $design->textcolor = $tcolor->intValue();
276 $design->linkcolor = $lcolor->intValue();
278 $design->setDisposition($on, $off, $tile);
280 $id = $design->insert();
283 common_log_db_error($id, 'INSERT', __FILE__);
284 // TRANS: Form validation error displayed when group design settings could not be saved because of an application issue.
285 $this->showForm(_('Unable to save your design settings.'));
289 $original = clone($this->group);
290 $this->group->design_id = $id;
291 $result = $this->group->update($original);
293 if (empty($result)) {
294 common_log_db_error($original, 'UPDATE', __FILE__);
295 // TRANS: Form validation error displayed when group design settings could not be saved because of an application issue.
296 $this->showForm(_('Unable to save your design settings.'));
297 $this->group->query('ROLLBACK');
301 $this->group->query('COMMIT');
304 $this->saveBackgroundImage($design);
306 // TRANS: Form text to confirm saved group design settings.
307 $this->showForm(_('Design preferences saved.'), true);