]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/userdesignsettings.php
Merge branch 'groupdesign' into 0.8.x
[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         try {
110
111             $bgcolor = new WebColor($this->trimmed('design_background'));
112             $ccolor  = new WebColor($this->trimmed('design_content'));
113             $sbcolor = new WebColor($this->trimmed('design_sidebar'));
114             $tcolor  = new WebColor($this->trimmed('design_text'));
115             $lcolor  = new WebColor($this->trimmed('design_links'));
116
117         } catch (WebColorException $e) {
118             $this->showForm($e->getMessage());
119             return;
120         }
121
122         $onoff = $this->arg('design_background-image_onoff');
123
124         $on   = false;
125         $off  = false;
126         $tile = false;
127
128         if ($onoff == 'on') {
129             $on = true;
130         } else {
131             $off = true;
132         }
133
134         $repeat = $this->boolean('design_background-image_repeat');
135
136         if ($repeat) {
137             $tile = true;
138         }
139
140         $user = common_current_user();
141         $design = $user->getDesign();
142
143         if (!empty($design)) {
144
145             $original = clone($design);
146
147             $design->backgroundcolor = $bgcolor->intValue();
148             $design->contentcolor    = $ccolor->intValue();
149             $design->sidebarcolor    = $sbcolor->intValue();
150             $design->textcolor       = $tcolor->intValue();
151             $design->linkcolor       = $lcolor->intValue();
152             $design->backgroundimage = $filepath;
153
154             $design->setDisposition($on, $off, $tile);
155
156             $result = $design->update($original);
157
158             if ($result === false) {
159                 common_log_db_error($design, 'UPDATE', __FILE__);
160                 $this->showForm(_('Couldn\'t update your design.'));
161                 return;
162             }
163
164             // update design
165         } else {
166
167             $user->query('BEGIN');
168
169             // save new design
170             $design = new Design();
171
172             $design->backgroundcolor = $bgcolor->intValue();
173             $design->contentcolor    = $ccolor->intValue();
174             $design->sidebarcolor    = $sbcolor->intValue();
175             $design->textcolor       = $tcolor->intValue();
176             $design->linkcolor       = $lcolor->intValue();
177             $design->backgroundimage = $filepath;
178
179             $design->setDisposition($on, $off, $tile);
180
181             $id = $design->insert();
182
183             if (empty($id)) {
184                 common_log_db_error($id, 'INSERT', __FILE__);
185                 $this->showForm(_('Unable to save your design settings!'));
186                 return;
187             }
188
189             $original = clone($user);
190             $user->design_id = $id;
191             $result = $user->update($original);
192
193             if (empty($result)) {
194                 common_log_db_error($original, 'UPDATE', __FILE__);
195                 $this->showForm(_('Unable to save your design settings!'));
196                 $user->query('ROLLBACK');
197                 return;
198             }
199
200             $user->query('COMMIT');
201
202         }
203
204         $this->saveBackgroundImage($design);
205
206         $this->showForm(_('Design preferences saved.'), true);
207     }
208 }