3 * Laconica, 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@controlyourself.ca>
25 * @author Zach Copley <zach@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/designsettings.php';
37 class GroupDesignSettingsAction extends DesignSettingsAction
45 function prepare($args)
47 parent::prepare($args);
49 if (!common_config('inboxes','enabled')) {
50 $this->serverError(_('Inboxes must be enabled for groups to work'));
54 if (!common_logged_in()) {
55 $this->clientError(_('You must be logged in to edit a group.'));
59 $nickname_arg = $this->trimmed('nickname');
60 $nickname = common_canonical_nickname($nickname_arg);
62 // Permanent redirect on non-canonical nickname
64 if ($nickname_arg != $nickname) {
65 $args = array('nickname' => $nickname);
66 common_redirect(common_local_url('groupdesignsettings', $args), 301);
71 $this->clientError(_('No nickname'), 404);
75 $groupid = $this->trimmed('groupid');
78 $this->group = User_group::staticGet('id', $groupid);
80 $this->group = User_group::staticGet('nickname', $nickname);
84 $this->clientError(_('No such group'), 404);
88 $cur = common_current_user();
90 if (!$cur->isAdmin($this->group)) {
91 $this->clientError(_('You must be an admin to edit the group'), 403);
95 $this->submitaction = common_local_url('groupdesignsettings',
96 array('nickname' => $this->group->nickname));
102 * A design for this action
104 * if the group attribute has been set, returns that group's
107 * @return Design a design object to use
113 if (empty($this->group)) {
117 return $this->group->getDesign();
123 * @return string Title of the page
128 return _('Group design');
132 * Instructions for use
134 * @return instructions for use
137 function getInstructions()
139 return _('Customize the way your group looks ' .
140 'with a background image and a colour palette of your choice.');
144 * Override to show group nav stuff
149 function showLocalNav()
151 $nav = new GroupNav($this, $this->group);
156 * Get the design we want to edit
161 function getWorkingDesign() {
165 if (isset($this->group)) {
166 $design = $this->group->getDesign();
169 if (empty($design)) {
170 $design = $this->defaultDesign();
177 * Content area of the page
179 * Shows a form for changing the design
184 function showContent()
186 $this->showDesignForm($this->getWorkingDesign());
190 * Save or update the group's design settings
195 function saveDesign()
199 $bgcolor = new WebColor($this->trimmed('design_background'));
200 $ccolor = new WebColor($this->trimmed('design_content'));
201 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
202 $tcolor = new WebColor($this->trimmed('design_text'));
203 $lcolor = new WebColor($this->trimmed('design_links'));
205 } catch (WebColorException $e) {
206 $this->showForm($e->getMessage());
210 $onoff = $this->arg('design_background-image_onoff');
216 if ($onoff == 'on') {
222 $repeat = $this->boolean('design_background-image_repeat');
228 $design = $this->group->getDesign();
230 if (!empty($design)) {
234 $original = clone($design);
236 $design->backgroundcolor = $bgcolor->intValue();
237 $design->contentcolor = $ccolor->intValue();
238 $design->sidebarcolor = $sbcolor->intValue();
239 $design->textcolor = $tcolor->intValue();
240 $design->linkcolor = $lcolor->intValue();
242 $design->setDisposition($on, $off, $tile);
244 $result = $design->update($original);
246 if ($result === false) {
247 common_log_db_error($design, 'UPDATE', __FILE__);
248 $this->showForm(_('Couldn\'t update your design.'));
254 $this->group->query('BEGIN');
258 $design = new Design();
260 $design->backgroundcolor = $bgcolor->intValue();
261 $design->contentcolor = $ccolor->intValue();
262 $design->sidebarcolor = $sbcolor->intValue();
263 $design->textcolor = $tcolor->intValue();
264 $design->linkcolor = $lcolor->intValue();
266 $design->setDisposition($on, $off, $tile);
268 $id = $design->insert();
271 common_log_db_error($id, 'INSERT', __FILE__);
272 $this->showForm(_('Unable to save your design settings!'));
276 $original = clone($this->group);
277 $this->group->design_id = $id;
278 $result = $this->group->update($original);
280 if (empty($result)) {
281 common_log_db_error($original, 'UPDATE', __FILE__);
282 $this->showForm(_('Unable to save your design settings!'));
283 $this->group->query('ROLLBACK');
287 $this->group->query('COMMIT');
291 $this->saveBackgroundImage($design);
293 $this->showForm(_('Design preferences saved.'), true);
297 * Handle input and output a page (overrided)
299 * @param array $args $_REQUEST arguments
304 function handle($args)
306 parent::handle($args);
307 if (!common_logged_in()) {
308 $this->clientError(_('Not logged in.'));
310 } else if (!common_is_real_login()) {
311 // Cookie theft means that automatic logins can't
312 // change important settings or see private info, and
313 // _all_ our settings are important
314 common_set_returnto($this->selfUrl());
315 $user = common_current_user();
316 if ($user->hasOpenID()) {
317 common_redirect(common_local_url('openidlogin'), 303);
319 common_redirect(common_local_url('login'), 303);
321 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {