3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 class OthersettingsAction extends SettingsAction {
26 function get_instructions() {
27 return _('Manage various other options.');
30 function show_form($msg=NULL, $success=false) {
31 $user = common_current_user();
33 $this->form_header(_('Other Settings'), $msg, $success);
35 common_element('h2', NULL, _('URL Auto-shortening'));
36 common_element_start('form', array('method' => 'post',
37 'id' => 'othersettings',
39 common_local_url('othersettings')));
40 common_hidden('token', common_session_token());
44 'ur1.ca' => 'ur1.ca (free service)',
45 '2tu.us' => '2tu.us (free service)',
46 'ptiturl.com' => 'ptiturl.com',
48 'tinyurl.com' => 'tinyurl.com',
50 'snipr.com' => 'snipr.com',
51 'metamark.net' => 'metamark.net'
54 common_dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice);
56 common_submit('save', _('Save'));
58 common_element_end('form');
60 common_element('h2', NULL, _('Delete my account'));
61 $this->show_delete_form();
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'));
71 foreach ($feeds as $key => $value) {
72 $this->common_feed_item($feeds[$key]);
74 common_element_end('ul');
75 common_element_end('div');
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;
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";
92 $feed_classname = "foaf";
93 $feed_mimetype = "application/".$feed['type']."+xml";
94 $feed_title = "$nickname's FOAF file";
95 $feed['textContent'] = "FOAF";
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');
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();
113 common_element_start('form', array('method' => 'POST',
116 common_local_url('deleteprofile')));
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.");
122 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
124 'version' => 'RSS 1.0',
125 'item' => 'notices'),
126 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
131 common_submit('deleteaccount', _('Delete my account'));
132 common_element_end('form');
136 function handle_post() {
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.'));
145 if ($this->arg('save')) {
146 $this->save_preferences();
148 $this->show_form(_('Unexpected form submission.'));
152 function save_preferences() {
154 $urlshorteningservice = $this->trimmed('urlshorteningservice');
156 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
157 $this->show_form(_('URL shortening service is too long (max 50 chars).'));
161 $user = common_current_user();
163 assert(!is_null($user)); # should already be checked
165 $user->query('BEGIN');
167 $original = clone($user);
169 $user->urlshorteningservice = $urlshorteningservice;
171 $result = $user->update($original);
173 if ($result === FALSE) {
174 common_log_db_error($user, 'UPDATE', __FILE__);
175 common_server_error(_('Couldn\'t update user.'));
179 $user->query('COMMIT');
181 $this->show_form(_('Preferences saved.'), true);