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()
28 return _('Manage various other options.');
31 function show_form($msg=null, $success=false)
33 $user = common_current_user();
35 $this->form_header(_('Other Settings'), $msg, $success);
37 common_element('h2', null, _('URL Auto-shortening'));
38 common_element_start('form', array('method' => 'post',
39 'id' => 'othersettings',
41 common_local_url('othersettings')));
42 common_hidden('token', common_session_token());
46 'ur1.ca' => 'ur1.ca (free service)',
47 '2tu.us' => '2tu.us (free service)',
48 'ptiturl.com' => 'ptiturl.com',
50 'tinyurl.com' => 'tinyurl.com',
52 'snipr.com' => 'snipr.com',
53 'metamark.net' => 'metamark.net'
56 common_dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice);
58 common_submit('save', _('Save'));
60 common_element_end('form');
62 // common_element('h2', null, _('Delete my account'));
63 // $this->show_delete_form();
68 function show_feeds_list($feeds)
70 common_element_start('div', array('class' => 'feedsdel'));
71 common_element('p', null, 'Feeds:');
72 common_element_start('ul', array('class' => 'xoxo'));
74 foreach ($feeds as $key => $value) {
75 $this->common_feed_item($feeds[$key]);
77 common_element_end('ul');
78 common_element_end('div');
81 //TODO move to common.php (and retrace its origin)
82 function common_feed_item($feed)
84 $user = common_current_user();
85 $nickname = $user->nickname;
87 switch($feed['item']) {
88 case 'notices': default:
89 $feed_classname = $feed['type'];
90 $feed_mimetype = "application/".$feed['type']."+xml";
91 $feed_title = "$nickname's ".$feed['version']." notice feed";
92 $feed['textContent'] = "RSS";
96 $feed_classname = "foaf";
97 $feed_mimetype = "application/".$feed['type']."+xml";
98 $feed_title = "$nickname's FOAF file";
99 $feed['textContent'] = "FOAF";
102 common_element_start('li');
103 common_element('a', array('href' => $feed['href'],
104 'class' => $feed_classname,
105 'type' => $feed_mimetype,
106 'title' => $feed_title),
107 $feed['textContent']);
108 common_element_end('li');
111 // function show_delete_form() {
112 // $user = common_current_user();
113 // $notices = DB_DataObject::factory('notice');
114 // $notices->profile_id = $user->id;
115 // $notice_count = (int) $notices->count();
117 // common_element_start('form', array('method' => 'POST',
120 // common_local_url('deleteprofile')));
122 // common_hidden('token', common_session_token());
123 // 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.");
125 // $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
127 // 'version' => 'RSS 1.0',
128 // 'item' => 'notices'),
129 // 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
131 // 'version' => 'FOAF',
132 // 'item' => 'foaf')));
134 // common_submit('deleteaccount', _('Delete my account'));
135 // common_element_end('form');
138 function handle_post()
142 $token = $this->trimmed('token');
143 if (!$token || $token != common_session_token()) {
144 $this->show_form(_('There was a problem with your session token. Try again, please.'));
148 if ($this->arg('save')) {
149 $this->save_preferences();
151 $this->show_form(_('Unexpected form submission.'));
155 function save_preferences()
158 $urlshorteningservice = $this->trimmed('urlshorteningservice');
160 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
161 $this->show_form(_('URL shortening service is too long (max 50 chars).'));
165 $user = common_current_user();
167 assert(!is_null($user)); # should already be checked
169 $user->query('BEGIN');
171 $original = clone($user);
173 $user->urlshorteningservice = $urlshorteningservice;
175 $result = $user->update($original);
177 if ($result === FALSE) {
178 common_log_db_error($user, 'UPDATE', __FILE__);
179 common_server_error(_('Couldn\'t update user.'));
183 $user->query('COMMIT');
185 $this->show_form(_('Preferences saved.'), true);