]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupdesignsettings.php
Translator comments added
[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_logged_in()) {
68             $this->clientError(_('You must be logged in to edit a group.'));
69             return false;
70         }
71
72         $nickname_arg = $this->trimmed('nickname');
73         $nickname     = common_canonical_nickname($nickname_arg);
74
75         // Permanent redirect on non-canonical nickname
76
77         if ($nickname_arg != $nickname) {
78             $args = array('nickname' => $nickname);
79             common_redirect(common_local_url('groupdesignsettings', $args), 301);
80             return false;
81         }
82
83         if (!$nickname) {
84             $this->clientError(_('No nickname.'), 404);
85             return false;
86         }
87
88         $groupid = $this->trimmed('groupid');
89
90         if ($groupid) {
91             $this->group = User_group::staticGet('id', $groupid);
92         } else {
93             $local = Local_group::staticGet('nickname', $nickname);
94             if ($local) {
95                 $this->group = User_group::staticGet('id', $local->group_id);
96             }
97         }
98
99         if (!$this->group) {
100             $this->clientError(_('No such group.'), 404);
101             return false;
102         }
103
104         $cur = common_current_user();
105
106         if (!$cur->isAdmin($this->group)) {
107             $this->clientError(_('You must be an admin to edit the group.'), 403);
108             return false;
109         }
110
111         $this->submitaction = common_local_url('groupdesignsettings',
112             array('nickname' => $this->group->nickname));
113
114         return true;
115     }
116
117     /**
118      * A design for this action
119      *
120      * if the group attribute has been set, returns that group's
121      * design.
122      *
123      * @return Design a design object to use
124      */
125
126     function getDesign()
127     {
128
129         if (empty($this->group)) {
130             return null;
131         }
132
133         return $this->group->getDesign();
134     }
135
136     /**
137      * Title of the page
138      *
139      * @return string Title of the page
140      */
141
142     function title()
143     {
144         return _('Group design');
145     }
146
147     /**
148      * Instructions for use
149      *
150      * @return instructions for use
151      */
152
153     function getInstructions()
154     {
155         return _('Customize the way your group looks ' .
156         'with a background image and a colour palette of your choice.');
157     }
158
159     /**
160      * Override to show group nav stuff
161      *
162      * @return nothing
163      */
164
165     function showLocalNav()
166     {
167         $nav = new GroupNav($this, $this->group);
168         $nav->show();
169     }
170
171     /**
172      * Get the design we want to edit
173      *
174      * @return Design
175      */
176
177     function getWorkingDesign()
178     {
179         $design = null;
180
181         if (isset($this->group)) {
182             $design = $this->group->getDesign();
183         }
184
185         return $design;
186     }
187
188     /**
189      * Content area of the page
190      *
191      * Shows a form for changing the design
192      *
193      * @return void
194      */
195
196     function showContent()
197     {
198         $design = $this->getWorkingDesign();
199
200         if (empty($design)) {
201             $design = Design::siteDesign();
202         }
203
204         $this->showDesignForm($design);
205     }
206
207     /**
208      * Save or update the group's design settings
209      *
210      * @return void
211      */
212
213     function saveDesign()
214     {
215         try {
216
217             $bgcolor = new WebColor($this->trimmed('design_background'));
218             $ccolor  = new WebColor($this->trimmed('design_content'));
219             $sbcolor = new WebColor($this->trimmed('design_sidebar'));
220             $tcolor  = new WebColor($this->trimmed('design_text'));
221             $lcolor  = new WebColor($this->trimmed('design_links'));
222
223         } catch (WebColorException $e) {
224             $this->showForm($e->getMessage());
225             return;
226         }
227
228         $onoff = $this->arg('design_background-image_onoff');
229
230         $on   = false;
231         $off  = false;
232         $tile = false;
233
234         if ($onoff == 'on') {
235             $on = true;
236         } else {
237             $off = true;
238         }
239
240         $repeat = $this->boolean('design_background-image_repeat');
241
242         if ($repeat) {
243             $tile = true;
244         }
245
246         $design = $this->group->getDesign();
247
248         if (!empty($design)) {
249
250             // update design
251
252             $original = clone($design);
253
254             $design->backgroundcolor = $bgcolor->intValue();
255             $design->contentcolor    = $ccolor->intValue();
256             $design->sidebarcolor    = $sbcolor->intValue();
257             $design->textcolor       = $tcolor->intValue();
258             $design->linkcolor       = $lcolor->intValue();
259
260             $design->setDisposition($on, $off, $tile);
261
262             $result = $design->update($original);
263
264             if ($result === false) {
265                 common_log_db_error($design, 'UPDATE', __FILE__);
266                 $this->showForm(_('Could not update your design.'));
267                 return;
268             }
269
270         } else {
271
272             $this->group->query('BEGIN');
273
274             // save new design
275
276             $design = new Design();
277
278             $design->backgroundcolor = $bgcolor->intValue();
279             $design->contentcolor    = $ccolor->intValue();
280             $design->sidebarcolor    = $sbcolor->intValue();
281             $design->textcolor       = $tcolor->intValue();
282             $design->linkcolor       = $lcolor->intValue();
283
284             $design->setDisposition($on, $off, $tile);
285
286             $id = $design->insert();
287
288             if (empty($id)) {
289                 common_log_db_error($id, 'INSERT', __FILE__);
290                 $this->showForm(_('Unable to save your design settings.'));
291                 return;
292             }
293
294             $original               = clone($this->group);
295             $this->group->design_id = $id;
296             $result                 = $this->group->update($original);
297
298             if (empty($result)) {
299                 common_log_db_error($original, 'UPDATE', __FILE__);
300                 $this->showForm(_('Unable to save your design settings.'));
301                 $this->group->query('ROLLBACK');
302                 return;
303             }
304
305             $this->group->query('COMMIT');
306
307         }
308
309         $this->saveBackgroundImage($design);
310
311         $this->showForm(_('Design preferences saved.'), true);
312     }
313
314 }