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