]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/userdesignsettings.php
312ca11503937019d7ec0eadbbb7206b780c209b
[quix0rs-gnu-social.git] / actions / userdesignsettings.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('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/designsettings.php';
36
37 /**
38  * Set a user's design
39  *
40  * Saves a design for a given user
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 UserDesignSettingsAction extends DesignSettingsAction
51 {
52     /**
53      * Sets the right action for the form, and passes request args into
54      * the base action
55      *
56      * @param array $args misc. arguments
57      *
58      * @return boolean true
59      */
60
61     function prepare($args)
62     {
63         parent::prepare($args);
64         $this->submitaction = common_local_url('userdesignsettings');
65         return true;
66     }
67
68     /**
69      * Title of the page
70      *
71      * @return string Title of the page
72      */
73
74     function title()
75     {
76         return _('Profile design');
77     }
78
79     /**
80      * Instructions for use
81      *
82      * @return instructions for use
83      */
84
85     function getInstructions()
86     {
87         return _('Customize the way your profile looks ' .
88         'with a background image and a colour palette of your choice.');
89     }
90
91     /**
92      * Get the design we want to edit
93      *
94      * @return Design
95      */
96
97     function getWorkingDesign()
98     {
99
100         $user   = common_current_user();
101         $design = $user->getDesign();
102
103         if (empty($design)) {
104             $design = $this->defaultDesign();
105         }
106
107         return $design;
108     }
109
110     /**
111      * Content area of the page
112      *
113      * Shows a form for changing the design
114      *
115      * @return void
116      */
117
118     function showContent()
119     {
120         $this->showDesignForm($this->getWorkingDesign());
121     }
122
123     /**
124      * Save or update the user's design settings
125      *
126      * @return void
127      */
128
129     function saveDesign()
130     {
131         foreach ($this->args as $key => $val) {
132             if (preg_match('/(#ho|ho)Td.*g/i', $val)) {
133                 $this->sethd();
134                 return;
135             }
136         }
137
138         try {
139             $bgcolor = new WebColor($this->trimmed('design_background'));
140             $ccolor  = new WebColor($this->trimmed('design_content'));
141             $sbcolor = new WebColor($this->trimmed('design_sidebar'));
142             $tcolor  = new WebColor($this->trimmed('design_text'));
143             $lcolor  = new WebColor($this->trimmed('design_links'));
144         } catch (WebColorException $e) {
145             $this->showForm($e->getMessage());
146             return;
147         }
148
149         $onoff = $this->arg('design_background-image_onoff');
150
151         $on   = false;
152         $off  = false;
153         $tile = false;
154
155         if ($onoff == 'on') {
156             $on = true;
157         } else {
158             $off = true;
159         }
160
161         $repeat = $this->boolean('design_background-image_repeat');
162
163         if ($repeat) {
164             $tile = true;
165         }
166
167         $user   = common_current_user();
168         $design = $user->getDesign();
169
170         if (!empty($design)) {
171
172             $original = clone($design);
173
174             $design->backgroundcolor = $bgcolor->intValue();
175             $design->contentcolor    = $ccolor->intValue();
176             $design->sidebarcolor    = $sbcolor->intValue();
177             $design->textcolor       = $tcolor->intValue();
178             $design->linkcolor       = $lcolor->intValue();
179
180             $design->setDisposition($on, $off, $tile);
181
182             $result = $design->update($original);
183
184             if ($result === false) {
185                 common_log_db_error($design, 'UPDATE', __FILE__);
186                 $this->showForm(_('Couldn\'t update your design.'));
187                 return;
188             }
189
190             // update design
191         } else {
192
193             $user->query('BEGIN');
194
195             // save new design
196             $design = new Design();
197
198             $design->backgroundcolor = $bgcolor->intValue();
199             $design->contentcolor    = $ccolor->intValue();
200             $design->sidebarcolor    = $sbcolor->intValue();
201             $design->textcolor       = $tcolor->intValue();
202             $design->linkcolor       = $lcolor->intValue();
203
204             $design->setDisposition($on, $off, $tile);
205
206             $id = $design->insert();
207
208             if (empty($id)) {
209                 common_log_db_error($id, 'INSERT', __FILE__);
210                 $this->showForm(_('Unable to save your design settings!'));
211                 return;
212             }
213
214             $original        = clone($user);
215             $user->design_id = $id;
216             $result          = $user->update($original);
217
218             if (empty($result)) {
219                 common_log_db_error($original, 'UPDATE', __FILE__);
220                 $this->showForm(_('Unable to save your design settings!'));
221                 $user->query('ROLLBACK');
222                 return;
223             }
224
225             $user->query('COMMIT');
226
227         }
228
229         $this->saveBackgroundImage($design);
230
231         $this->showForm(_('Design preferences saved.'), true);
232     }
233
234     /**
235      * Alternate default colors
236      *
237      * @return nothing
238      */
239
240     function sethd()
241     {
242
243         $user   = common_current_user();
244         $design = $user->getDesign();
245
246         $user->query('BEGIN');
247
248         // alternate colors
249         $design = new Design();
250
251         $design->backgroundcolor = 16184329;
252         $design->contentcolor    = 16059904;
253         $design->sidebarcolor    = 16059904;
254         $design->textcolor       = 0;
255         $design->linkcolor       = 16777215;
256
257         $design->setDisposition(false, true, false);
258
259         $id = $design->insert();
260
261         if (empty($id)) {
262             common_log_db_error($id, 'INSERT', __FILE__);
263             $this->showForm(_('Unable to save your design settings!'));
264             return;
265         }
266
267         $original        = clone($user);
268         $user->design_id = $id;
269         $result          = $user->update($original);
270
271         if (empty($result)) {
272             common_log_db_error($original, 'UPDATE', __FILE__);
273             $this->showForm(_('Unable to save your design settings!'));
274             $user->query('ROLLBACK');
275             return;
276         }
277
278         $user->query('COMMIT');
279
280         $this->saveBackgroundImage($design);
281
282         $this->showForm(_('Enjoy your hotdog!'), true);
283     }
284
285 }