]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
Merge branch '0.8.x' of git://gitorious.org/~brion/statusnet/brion-fixes into 0.8.x
[quix0rs-gnu-social.git] / actions / othersettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Miscellaneous settings
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    Robin Millette <millette@status.net>
25  * @author    Evan Prodromou <evan@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/accountsettingsaction.php';
36
37 /**
38  * Miscellaneous settings actions
39  *
40  * Currently this just manages URL shortening.
41  *
42  * @category Settings
43  * @package  StatusNet
44  * @author   Robin Millette <millette@status.net>
45  * @author   Zach Copley <zach@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 OthersettingsAction extends AccountSettingsAction
51 {
52     /**
53      * Title of the page
54      *
55      * @return string Title of the page
56      */
57
58     function title()
59     {
60         return _('Other Settings');
61     }
62
63     /**
64      * Instructions for use
65      *
66      * @return instructions for use
67      */
68
69     function getInstructions()
70     {
71         return _('Manage various other options.');
72     }
73
74     function showScripts()
75     {
76         parent::showScripts();
77         $this->autofocus('urlshorteningservice');
78     }
79
80     /**
81      * Content area of the page
82      *
83      * Shows a form for uploading an avatar.
84      *
85      * @return void
86      */
87
88     function showContent()
89     {
90         $user = common_current_user();
91
92         $this->elementStart('form', array('method' => 'post',
93                                           'id' => 'form_settings_other',
94                                           'class' => 'form_settings',
95                                           'action' =>
96                                           common_local_url('othersettings')));
97         $this->elementStart('fieldset');
98         $this->hidden('token', common_session_token());
99
100         // I18N
101
102         $services = array(
103                           '' => 'None',
104                           'ur1.ca' => 'ur1.ca (free service)',
105                           '2tu.us' => '2tu.us (free service)',
106                           'ptiturl.com' => 'ptiturl.com',
107                           'bit.ly' => 'bit.ly',
108                           'tinyurl.com' => 'tinyurl.com',
109                           'is.gd' => 'is.gd',
110                           'snipr.com' => 'snipr.com',
111                           'metamark.net' => 'metamark.net'
112                           );
113
114         $this->elementStart('ul', 'form_data');
115         $this->elementStart('li');
116         $this->dropdown('urlshorteningservice', _('Shorten URLs with'),
117                         $services, _('Automatic shortening service to use.'),
118                         false, $user->urlshorteningservice);
119         $this->elementEnd('li');
120         $this->elementStart('li');
121         $this->checkbox('viewdesigns', _('View profile designs'),
122                         $user->viewdesigns, _('Show or hide profile designs.'));
123         $this->elementEnd('li');
124         $this->elementEnd('ul');
125         $this->submit('save', _('Save'));
126         $this->elementEnd('fieldset');
127         $this->elementEnd('form');
128     }
129
130     /**
131      * Handle a post
132      *
133      * Saves the changes to url-shortening prefs and shows a success or failure
134      * message.
135      *
136      * @return void
137      */
138
139     function handlePost()
140     {
141         // CSRF protection
142         $token = $this->trimmed('token');
143         if (!$token || $token != common_session_token()) {
144             $this->showForm(_('There was a problem with your session token. '.
145                               'Try again, please.'));
146             return;
147         }
148
149         $urlshorteningservice = $this->trimmed('urlshorteningservice');
150
151         if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
152             $this->showForm(_('URL shortening service is too long (max 50 chars).'));
153             return;
154         }
155
156         $viewdesigns = $this->boolean('viewdesigns');
157
158         $user = common_current_user();
159
160         assert(!is_null($user)); // should already be checked
161
162         $user->query('BEGIN');
163
164         $original = clone($user);
165
166         $user->urlshorteningservice = $urlshorteningservice;
167         $user->viewdesigns          = $viewdesigns;
168
169         $result = $user->update($original);
170
171         if ($result === false) {
172             common_log_db_error($user, 'UPDATE', __FILE__);
173             $this->serverError(_('Couldn\'t update user.'));
174             return;
175         }
176
177         $user->query('COMMIT');
178
179         $this->showForm(_('Preferences saved.'), true);
180     }
181 }