]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupdesignsettings.php
define LACONICA and accept LACONICA for backwards compatibility
[quix0rs-gnu-social.git] / actions / groupdesignsettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Change user password
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/designsettings.php';
36
37 /**
38  * Set a group's design
39  *
40  * Saves a design for a given group
41  *
42  * @category Settings
43  * @package  StatusNet
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/
48  */
49
50 class GroupDesignSettingsAction extends DesignSettingsAction
51 {
52     var $group = null;
53
54     /**
55      * Sets the right action for the form, and passes request args into
56      * the base action
57      *
58      * @param array $args misc. arguments
59      *
60      * @return boolean true
61      */
62
63     function prepare($args)
64     {
65         parent::prepare($args);
66
67         if (!common_config('inboxes', 'enabled')) {
68             $this->serverError(_('Inboxes must be enabled for groups to work'));
69             return false;
70         }
71
72         if (!common_logged_in()) {
73             $this->clientError(_('You must be logged in to edit a group.'));
74             return false;
75         }
76
77         $nickname_arg = $this->trimmed('nickname');
78         $nickname     = common_canonical_nickname($nickname_arg);
79
80         // Permanent redirect on non-canonical nickname
81
82         if ($nickname_arg != $nickname) {
83             $args = array('nickname' => $nickname);
84             common_redirect(common_local_url('groupdesignsettings', $args), 301);
85             return false;
86         }
87
88         if (!$nickname) {
89             $this->clientError(_('No nickname'), 404);
90             return false;
91         }
92
93         $groupid = $this->trimmed('groupid');
94
95         if ($groupid) {
96             $this->group = User_group::staticGet('id', $groupid);
97         } else {
98             $this->group = User_group::staticGet('nickname', $nickname);
99         }
100
101         if (!$this->group) {
102             $this->clientError(_('No such group'), 404);
103             return false;
104         }
105
106         $cur = common_current_user();
107
108         if (!$cur->isAdmin($this->group)) {
109             $this->clientError(_('You must be an admin to edit the group'), 403);
110             return false;
111         }
112
113         $this->submitaction = common_local_url('groupdesignsettings',
114             array('nickname' => $this->group->nickname));
115
116         return true;
117     }
118
119     /**
120      * A design for this action
121      *
122      * if the group attribute has been set, returns that group's
123      * design.
124      *
125      * @return Design a design object to use
126      */
127
128     function getDesign()
129     {
130
131         if (empty($this->group)) {
132             return null;
133         }
134
135         return $this->group->getDesign();
136     }
137
138     /**
139      * Title of the page
140      *
141      * @return string Title of the page
142      */
143
144     function title()
145     {
146         return _('Group design');
147     }
148
149     /**
150      * Instructions for use
151      *
152      * @return instructions for use
153      */
154
155     function getInstructions()
156     {
157         return _('Customize the way your group looks ' .
158         'with a background image and a colour palette of your choice.');
159     }
160
161     /**
162      * Override to show group nav stuff
163      *
164      * @return nothing
165      */
166
167     function showLocalNav()
168     {
169         $nav = new GroupNav($this, $this->group);
170         $nav->show();
171     }
172
173     /**
174      * Get the design we want to edit
175      *
176      * @return Design
177      */
178
179     function getWorkingDesign()
180     {
181
182         $design = null;
183
184         if (isset($this->group)) {
185             $design = $this->group->getDesign();
186         }
187
188         if (empty($design)) {
189             $design = $this->defaultDesign();
190         }
191
192         return $design;
193     }
194
195     /**
196      * Content area of the page
197      *
198      * Shows a form for changing the design
199      *
200      * @return void
201      */
202
203     function showContent()
204     {
205         $this->showDesignForm($this->getWorkingDesign());
206     }
207
208     /**
209      * Save or update the group's design settings
210      *
211      * @return void
212      */
213
214     function saveDesign()
215     {
216         try {
217
218             $bgcolor = new WebColor($this->trimmed('design_background'));
219             $ccolor  = new WebColor($this->trimmed('design_content'));
220             $sbcolor = new WebColor($this->trimmed('design_sidebar'));
221             $tcolor  = new WebColor($this->trimmed('design_text'));
222             $lcolor  = new WebColor($this->trimmed('design_links'));
223
224         } catch (WebColorException $e) {
225             $this->showForm($e->getMessage());
226             return;
227         }
228
229         $onoff = $this->arg('design_background-image_onoff');
230
231         $on   = false;
232         $off  = false;
233         $tile = false;
234
235         if ($onoff == 'on') {
236             $on = true;
237         } else {
238             $off = true;
239         }
240
241         $repeat = $this->boolean('design_background-image_repeat');
242
243         if ($repeat) {
244             $tile = true;
245         }
246
247         $design = $this->group->getDesign();
248
249         if (!empty($design)) {
250
251             // update design
252
253             $original = clone($design);
254
255             $design->backgroundcolor = $bgcolor->intValue();
256             $design->contentcolor    = $ccolor->intValue();
257             $design->sidebarcolor    = $sbcolor->intValue();
258             $design->textcolor       = $tcolor->intValue();
259             $design->linkcolor       = $lcolor->intValue();
260
261             $design->setDisposition($on, $off, $tile);
262
263             $result = $design->update($original);
264
265             if ($result === false) {
266                 common_log_db_error($design, 'UPDATE', __FILE__);
267                 $this->showForm(_('Couldn\'t update your design.'));
268                 return;
269             }
270
271         } else {
272
273             $this->group->query('BEGIN');
274
275             // save new design
276
277             $design = new Design();
278
279             $design->backgroundcolor = $bgcolor->intValue();
280             $design->contentcolor    = $ccolor->intValue();
281             $design->sidebarcolor    = $sbcolor->intValue();
282             $design->textcolor       = $tcolor->intValue();
283             $design->linkcolor       = $lcolor->intValue();
284
285             $design->setDisposition($on, $off, $tile);
286
287             $id = $design->insert();
288
289             if (empty($id)) {
290                 common_log_db_error($id, 'INSERT', __FILE__);
291                 $this->showForm(_('Unable to save your design settings!'));
292                 return;
293             }
294
295             $original               = clone($this->group);
296             $this->group->design_id = $id;
297             $result                 = $this->group->update($original);
298
299             if (empty($result)) {
300                 common_log_db_error($original, 'UPDATE', __FILE__);
301                 $this->showForm(_('Unable to save your design settings!'));
302                 $this->group->query('ROLLBACK');
303                 return;
304             }
305
306             $this->group->query('COMMIT');
307
308         }
309
310         $this->saveBackgroundImage($design);
311
312         $this->showForm(_('Design preferences saved.'), true);
313     }
314
315 }