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
27 function get_instructions()
29 return _('Manage various other options.');
32 function show_form($msg=null, $success=false)
34 $user = common_current_user();
36 $this->form_header(_('Other Settings'), $msg, $success);
38 $this->element('h2', null, _('URL Auto-shortening'));
39 $this->elementStart('form', array('method' => 'post',
40 'id' => 'othersettings',
42 common_local_url('othersettings')));
43 $this->hidden('token', common_session_token());
47 'ur1.ca' => 'ur1.ca (free service)',
48 '2tu.us' => '2tu.us (free service)',
49 'ptiturl.com' => 'ptiturl.com',
51 'tinyurl.com' => 'tinyurl.com',
53 'snipr.com' => 'snipr.com',
54 'metamark.net' => 'metamark.net'
57 $this->dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), false, $user->urlshorteningservice);
59 $this->submit('save', _('Save'));
61 $this->elementEnd('form');
63 // $this->element('h2', null, _('Delete my account'));
64 // $this->show_delete_form();
69 function show_feeds_list($feeds)
71 $this->elementStart('div', array('class' => 'feedsdel'));
72 $this->element('p', null, 'Feeds:');
73 $this->elementStart('ul', array('class' => 'xoxo'));
75 foreach ($feeds as $key => $value) {
76 $this->common_feed_item($feeds[$key]);
78 $this->elementEnd('ul');
79 $this->elementEnd('div');
82 //TODO move to common.php (and retrace its origin)
83 function common_feed_item($feed)
85 $user = common_current_user();
86 $nickname = $user->nickname;
88 switch($feed['item']) {
89 case 'notices': default:
90 $feed_classname = $feed['type'];
91 $feed_mimetype = "application/".$feed['type']."+xml";
92 $feed_title = "$nickname's ".$feed['version']." notice feed";
93 $feed['textContent'] = "RSS";
97 $feed_classname = "foaf";
98 $feed_mimetype = "application/".$feed['type']."+xml";
99 $feed_title = "$nickname's FOAF file";
100 $feed['textContent'] = "FOAF";
103 $this->elementStart('li');
104 $this->element('a', array('href' => $feed['href'],
105 'class' => $feed_classname,
106 'type' => $feed_mimetype,
107 'title' => $feed_title),
108 $feed['textContent']);
109 $this->elementEnd('li');
112 // function show_delete_form() {
113 // $user = common_current_user();
114 // $notices = DB_DataObject::factory('notice');
115 // $notices->profile_id = $user->id;
116 // $notice_count = (int) $notices->count();
118 // $this->elementStart('form', array('method' => 'POST',
121 // common_local_url('deleteprofile')));
123 // $this->hidden('token', common_session_token());
124 // $this->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.");
126 // $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
128 // 'version' => 'RSS 1.0',
129 // 'item' => 'notices'),
130 // 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
132 // 'version' => 'FOAF',
133 // 'item' => 'foaf')));
135 // $this->submit('deleteaccount', _('Delete my account'));
136 // $this->elementEnd('form');
139 function handle_post()
143 $token = $this->trimmed('token');
144 if (!$token || $token != common_session_token()) {
145 $this->show_form(_('There was a problem with your session token. Try again, please.'));
149 if ($this->arg('save')) {
150 $this->save_preferences();
152 $this->show_form(_('Unexpected form submission.'));
156 function save_preferences()
159 $urlshorteningservice = $this->trimmed('urlshorteningservice');
161 if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
162 $this->show_form(_('URL shortening service is too long (max 50 chars).'));
166 $user = common_current_user();
168 assert(!is_null($user)); # should already be checked
170 $user->query('BEGIN');
172 $original = clone($user);
174 $user->urlshorteningservice = $urlshorteningservice;
176 $result = $user->update($original);
178 if ($result === false) {
179 common_log_db_error($user, 'UPDATE', __FILE__);
180 $this->serverError(_('Couldn\'t update user.'));
184 $user->query('COMMIT');
186 $this->show_form(_('Preferences saved.'), true);