3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008-2011, StatusNet, Inc.
6 * Search subscription action.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Brion Vibber <brion@status.net>
26 * @author Evan Prodromou <evan@status.net>
27 * @copyright 2008-2010 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
37 * Search subscription action
41 * - token: session token to prevent CSRF attacks
42 * - ajax: boolean; whether to return Ajax or full-browser results
44 * Only works if the current user is logged in.
48 * @author Evan Prodromou <evan@status.net>
49 * @author Brion Vibber <brion@status.net>
50 * @copyright 2008-2011 StatusNet, Inc.
51 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
52 * @link http://status.net/
54 class SearchsubAction extends Action
60 * Check pre-requisites and instantiate attributes
62 * @param Array $args array of arguments (URL, GET, POST)
64 * @return boolean success flag
66 function prepare($args)
68 parent::prepare($args);
69 if ($this->boolean('ajax')) {
70 StatusNet::setApi(true);
73 // Only allow POST requests
75 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
76 // TRANS: Client error displayed trying to perform any request method other than POST.
77 // TRANS: Do not translate POST.
78 $this->clientError(_m('This action only accepts POST requests.'));
83 $token = $this->trimmed('token');
85 if (!$token || $token != common_session_token()) {
86 // TRANS: Client error displayed when the session token is not okay.
87 $this->clientError(_m('There was a problem with your session token.'.
88 ' Try again, please.'));
91 // Only for logged-in users
93 $this->user = common_current_user();
95 if (empty($this->user)) {
96 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
97 $this->clientError(_m('Not logged in.'));
100 // Profile to subscribe to
102 $this->search = $this->arg('search');
104 if (empty($this->search)) {
105 // TRANS: Client error displayed trying to subscribe to a non-existing profile.
106 $this->clientError(_m('No such profile.'));
115 * Does the subscription and returns results.
117 * @param Array $args unused.
121 function handle($args)
123 // Throws exception on error
125 SearchSub::start($this->user->getProfile(),
128 if ($this->boolean('ajax')) {
129 $this->startHTML('text/xml;charset=utf-8');
130 $this->elementStart('head');
131 // TRANS: Page title when search subscription succeeded.
132 $this->element('title', null, _m('Subscribed'));
133 $this->elementEnd('head');
134 $this->elementStart('body');
135 $unsubscribe = new SearchUnsubForm($this, $this->search);
136 $unsubscribe->show();
137 $this->elementEnd('body');
140 $url = common_local_url('search',
141 array('search' => $this->search));
142 common_redirect($url, 303);