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