]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/othersettings.php
removed Profile_block::get, changed to use pkeyGet
[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
122                 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)), 
123                                                                                           'type' => 'rss',
124                                                                                           'version' => 'RSS 1.0',
125                                                                                           'item' => 'notices'),
126                                                                          1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
127                                                                                           'type' => 'rdf',
128                                                                                           'version' => 'FOAF',
129                                                                                           'item' => 'foaf')));
130
131                 common_submit('deleteaccount', _('Delete my account'));
132                 common_element_end('form');
133         }
134
135
136         function handle_post() {
137
138                 # CSRF protection
139                 $token = $this->trimmed('token');
140                 if (!$token || $token != common_session_token()) {
141                         $this->show_form(_('There was a problem with your session token. Try again, please.'));
142                         return;
143                 }
144
145                 if ($this->arg('save')) {
146                         $this->save_preferences();
147                 }else {
148                         $this->show_form(_('Unexpected form submission.'));
149                 }
150         }
151
152         function save_preferences() {
153
154                 $urlshorteningservice = $this->trimmed('urlshorteningservice');
155                 
156                 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
157                         $this->show_form(_('URL shortening service is too long (max 50 chars).'));
158                         return;
159                 }
160                 
161                 $user = common_current_user();
162
163                 assert(!is_null($user)); # should already be checked
164
165                 $user->query('BEGIN');
166
167                 $original = clone($user);
168
169                 $user->urlshorteningservice = $urlshorteningservice;
170
171                 $result = $user->update($original);
172
173                 if ($result === FALSE) {
174                         common_log_db_error($user, 'UPDATE', __FILE__);
175                         common_server_error(_('Couldn\'t update user.'));
176                         return;
177                 }
178
179                 $user->query('COMMIT');
180
181                 $this->show_form(_('Preferences saved.'), true);
182         }
183 }