]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
d87f256fac06810835597c0a000033871066499d
[quix0rs-gnu-social.git] / actions / othersettings.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class OthersettingsAction extends SettingsAction {
25
26         function get_instructions() {
27                 return _('Manage various other options.');
28         }
29
30         function show_form($msg=NULL, $success=false) {
31                 $user = common_current_user();
32                 
33                 $this->form_header(_('Other Settings'), $msg, $success);
34                 
35                 common_element_start('form', array('method' => 'post',
36                                                                                    'id' => 'othersettings',
37                                                                                    'action' =>
38                                                                                    common_local_url('othersettings')));
39                 common_hidden('token', common_session_token());
40
41                 common_element('h2', NULL, _('URL Auto-shortening'));
42                 
43                 $services = array(
44                         '' => 'None',
45                         'tinyurl.com' => 'tinyurl.com',
46                         'is.gd' => 'is.gd',
47                         'snipr.com' => 'snipr.com',
48                         'metamark.net' => 'metamark.net'
49                 );
50                 
51                 common_dropdown('urlshorteningservice', _('Service'), $services, _('Shortening service to use when notices exceed the 140 character limit.'), FALSE, $user->urlshorteningservice);
52                 
53                 common_submit('save', _('Save'));
54                 
55                 common_element_end('form');
56                 common_show_footer();
57         }
58
59         function handle_post() {
60
61                 # CSRF protection
62                 $token = $this->trimmed('token');
63                 if (!$token || $token != common_session_token()) {
64                         $this->show_form(_('There was a problem with your session token. Try again, please.'));
65                         return;
66                 }
67
68                 if ($this->arg('save')) {
69                         $this->save_preferences();
70                 }else {
71                         $this->show_form(_('Unexpected form submission.'));
72                 }
73         }
74
75         function save_preferences() {
76
77                 $urlshorteningservice = $this->trimmed('urlshorteningservice');
78                 
79                 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
80                         $this->show_form(_('URL shortening service is too long (max 50 chars).'));
81                         return;
82                 }
83                 
84                 $user = common_current_user();
85
86                 assert(!is_null($user)); # should already be checked
87
88                 $user->query('BEGIN');
89
90                 $original = clone($user);
91
92                 $user->urlshorteningservice = $urlshorteningservice;
93
94                 $result = $user->update($original);
95
96                 if ($result === FALSE) {
97                         common_log_db_error($user, 'UPDATE', __FILE__);
98                         common_server_error(_('Couldn\'t update user.'));
99                         return;
100                 }
101
102                 $user->query('COMMIT');
103
104                 $this->show_form(_('Preferences saved.'), true);
105         }
106 }