]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
replace all tabs with four spaces
[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('h2', NULL, _('URL Auto-shortening'));
36         common_element_start('form', array('method' => 'post',
37                                            'id' => 'othersettings',
38                                            'action' =>
39                                            common_local_url('othersettings')));
40         common_hidden('token', common_session_token());
41
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, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice);
55
56         common_submit('save', _('Save'));
57
58         common_element_end('form');
59
60 //        common_element('h2', NULL, _('Delete my account'));
61 //        $this->show_delete_form();
62
63         common_show_footer();
64     }
65
66     function show_feeds_list($feeds) {
67         common_element_start('div', array('class' => 'feedsdel'));
68         common_element('p', null, 'Feeds:');
69         common_element_start('ul', array('class' => 'xoxo'));
70
71         foreach ($feeds as $key => $value) {
72             $this->common_feed_item($feeds[$key]);
73         }
74         common_element_end('ul');
75         common_element_end('div');
76     }
77
78     //TODO move to common.php (and retrace its origin)
79     function common_feed_item($feed) {
80         $user = common_current_user();
81         $nickname = $user->nickname;
82
83         switch($feed['item']) {
84             case 'notices': default:
85                 $feed_classname = $feed['type'];
86                 $feed_mimetype = "application/".$feed['type']."+xml";
87                 $feed_title = "$nickname's ".$feed['version']." notice feed";
88                 $feed['textContent'] = "RSS";
89                 break;
90
91             case 'foaf':
92                 $feed_classname = "foaf";
93                 $feed_mimetype = "application/".$feed['type']."+xml";
94                 $feed_title = "$nickname's FOAF file";
95                 $feed['textContent'] = "FOAF";
96                 break;
97         }
98         common_element_start('li');
99         common_element('a', array('href' => $feed['href'],
100                                   'class' => $feed_classname,
101                                   'type' => $feed_mimetype,
102                                   'title' => $feed_title),
103                             $feed['textContent']);
104         common_element_end('li');
105     }
106
107 //    function show_delete_form() {
108 //        $user = common_current_user();
109 //      $notices = DB_DataObject::factory('notice');
110 //      $notices->profile_id = $user->id;
111 //      $notice_count = (int) $notices->count();
112 //
113 //        common_element_start('form', array('method' => 'POST',
114 //                                           'id' => 'delete',
115 //                                           'action' =>
116 //                                           common_local_url('deleteprofile')));
117 //
118 //        common_hidden('token', common_session_token());
119 //      common_element('p', null, "You can copy your notices and contacts by saving the two links below before deleting your account. Be careful, this operation cannot be undone.");
120 //
121 //        $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
122 //                                              'type' => 'rss',
123 //                                              'version' => 'RSS 1.0',
124 //                                              'item' => 'notices'),
125 //                                     1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
126 //                                              'type' => 'rdf',
127 //                                              'version' => 'FOAF',
128 //                                              'item' => 'foaf')));
129 //
130 //        common_submit('deleteaccount', _('Delete my account'));
131 //        common_element_end('form');
132 //    }
133
134     function handle_post() {
135
136         # CSRF protection
137         $token = $this->trimmed('token');
138         if (!$token || $token != common_session_token()) {
139             $this->show_form(_('There was a problem with your session token. Try again, please.'));
140             return;
141         }
142
143         if ($this->arg('save')) {
144             $this->save_preferences();
145         }else {
146             $this->show_form(_('Unexpected form submission.'));
147         }
148     }
149
150     function save_preferences() {
151
152         $urlshorteningservice = $this->trimmed('urlshorteningservice');
153
154         if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
155             $this->show_form(_('URL shortening service is too long (max 50 chars).'));
156             return;
157         }
158
159         $user = common_current_user();
160
161         assert(!is_null($user)); # should already be checked
162
163         $user->query('BEGIN');
164
165         $original = clone($user);
166
167         $user->urlshorteningservice = $urlshorteningservice;
168
169         $result = $user->update($original);
170
171         if ($result === FALSE) {
172             common_log_db_error($user, 'UPDATE', __FILE__);
173             common_server_error(_('Couldn\'t update user.'));
174             return;
175         }
176
177         $user->query('COMMIT');
178
179         $this->show_form(_('Preferences saved.'), true);
180     }
181 }