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