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.");
121 // $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
123 // 'version' => 'RSS 1.0',
124 // 'item' => 'notices'),
125 // 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
127 // 'version' => 'FOAF',
128 // 'item' => 'foaf')));
130 // common_submit('deleteaccount', _('Delete my account'));
131 // common_element_end('form');
134 function handle_post() {
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.'));
143 if ($this->arg('save')) {
144 $this->save_preferences();
146 $this->show_form(_('Unexpected form submission.'));
150 function save_preferences() {
152 $urlshorteningservice = $this->trimmed('urlshorteningservice');
154 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
155 $this->show_form(_('URL shortening service is too long (max 50 chars).'));
159 $user = common_current_user();
161 assert(!is_null($user)); # should already be checked
163 $user->query('BEGIN');
165 $original = clone($user);
167 $user->urlshorteningservice = $urlshorteningservice;
169 $result = $user->update($original);
171 if ($result === FALSE) {
172 common_log_db_error($user, 'UPDATE', __FILE__);
173 common_server_error(_('Couldn\'t update user.'));
177 $user->query('COMMIT');
179 $this->show_form(_('Preferences saved.'), true);