]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
497500509fc50fb4a1d856d96c3d8f33c89358e3
[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                 $services = array(
43                         '' => 'None',
44             'ur1.ca' => 'ur1.ca (free service)',
45             '2tu.us' => '2tu.us (free service)',
46             'ptiturl.com' => 'ptiturl.com',
47             'bit.ly' => 'bit.ly',
48                         'tinyurl.com' => 'tinyurl.com',
49                         'is.gd' => 'is.gd',
50                         'snipr.com' => 'snipr.com',
51                         'metamark.net' => 'metamark.net'
52                 );
53                 
54                 common_dropdown('urlshorteningservice', _('Service'), $services, _('Shortening service to use when notices exceed the 140 character limit. Precede a URL with a * to prevent shortening of that URL.'), FALSE, $user->urlshorteningservice);
55                 
56                 common_submit('save', _('Save'));
57                 
58                 common_element_end('form');
59                 common_show_footer();
60         }
61
62         function handle_post() {
63
64                 # CSRF protection
65                 $token = $this->trimmed('token');
66                 if (!$token || $token != common_session_token()) {
67                         $this->show_form(_('There was a problem with your session token. Try again, please.'));
68                         return;
69                 }
70
71                 if ($this->arg('save')) {
72                         $this->save_preferences();
73                 }else {
74                         $this->show_form(_('Unexpected form submission.'));
75                 }
76         }
77
78         function save_preferences() {
79
80                 $urlshorteningservice = $this->trimmed('urlshorteningservice');
81                 
82                 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
83                         $this->show_form(_('URL shortening service is too long (max 50 chars).'));
84                         return;
85                 }
86                 
87                 $user = common_current_user();
88
89                 assert(!is_null($user)); # should already be checked
90
91                 $user->query('BEGIN');
92
93                 $original = clone($user);
94
95                 $user->urlshorteningservice = $urlshorteningservice;
96
97                 $result = $user->update($original);
98
99                 if ($result === FALSE) {
100                         common_log_db_error($user, 'UPDATE', __FILE__);
101                         common_server_error(_('Couldn\'t update user.'));
102                         return;
103                 }
104
105                 $user->query('COMMIT');
106
107                 $this->show_form(_('Preferences saved.'), true);
108         }
109 }