]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
f35630f360df4aae598019820f63d46605fe0368
[quix0rs-gnu-social.git] / actions / othersettings.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Robin Millette <millette@controlyourself.ca>
25  * @author    Evan Prodromou <evan@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/accountsettingsaction.php';
36
37 /**
38  * Miscellaneous settings actions
39  *
40  * Currently this just manages URL shortening.
41  *
42  * @category Settings
43  * @package  Laconica
44  * @author   Robin Millette <millette@controlyourself.ca>
45  * @author   Zach Copley <zach@controlyourself.ca>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://laconi.ca/
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     /**
75      * Content area of the page
76      *
77      * Shows a form for uploading an avatar.
78      *
79      * @return void
80      */
81
82     function showContent()
83     {
84         $user = common_current_user();
85
86         $this->element('h2', null, _('URL Auto-shortening'));
87         $this->elementStart('form', array('method' => 'post',
88                                           'id' => 'othersettings',
89                                           'action' =>
90                                           common_local_url('othersettings')));
91         $this->hidden('token', common_session_token());
92
93         // I18N
94
95         $services = array(
96                           '' => 'None',
97                           'ur1.ca' => 'ur1.ca (free service)',
98                           '2tu.us' => '2tu.us (free service)',
99                           'ptiturl.com' => 'ptiturl.com',
100                           'bit.ly' => 'bit.ly',
101                           'tinyurl.com' => 'tinyurl.com',
102                           'is.gd' => 'is.gd',
103                           'snipr.com' => 'snipr.com',
104                           'metamark.net' => 'metamark.net'
105                           );
106
107         $this->dropdown('urlshorteningservice', _('Service'),
108                         $services, _('Automatic shortening service to use.'),
109                         false, $user->urlshorteningservice);
110
111         $this->submit('save', _('Save'));
112
113         $this->elementEnd('form');
114     }
115
116     /**
117      * Handle a post
118      *
119      * Saves the changes to url-shortening prefs and shows a success or failure
120      * message.
121      *
122      * @return void
123      */
124
125     function handlePost()
126     {
127         // CSRF protection
128         $token = $this->trimmed('token');
129         if (!$token || $token != common_session_token()) {
130             $this->showForm(_('There was a problem with your session token. '.
131                               'Try again, please.'));
132             return;
133         }
134
135         $urlshorteningservice = $this->trimmed('urlshorteningservice');
136
137         if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
138             $this->showForm(_('URL shortening service is too long (max 50 chars).'));
139             return;
140         }
141
142         $user = common_current_user();
143
144         assert(!is_null($user)); // should already be checked
145
146         $user->query('BEGIN');
147
148         $original = clone($user);
149
150         $user->urlshorteningservice = $urlshorteningservice;
151
152         $result = $user->update($original);
153
154         if ($result === false) {
155             common_log_db_error($user, 'UPDATE', __FILE__);
156             $this->serverError(_('Couldn\'t update user.'));
157             return;
158         }
159
160         $user->query('COMMIT');
161
162         $this->showForm(_('Preferences saved.'), true);
163     }
164 }