3 * StatusNet, the distributed open-source microblogging tool
5 * Show information about the relationship between two users
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Dan Moore <dan@moore.cx>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Zach Copley <zach@status.net>
27 * @copyright 2009 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
37 * Outputs detailed information about the relationship between two users
41 * @author Dan Moore <dan@moore.cx>
42 * @author Evan Prodromou <evan@status.net>
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
47 class ApiFriendshipsShowAction extends ApiBareAuthAction
53 * Take arguments for running
55 * @param array $args $_REQUEST args
57 * @return boolean success flag
59 function prepare($args)
61 parent::prepare($args);
63 $source_id = (int)$this->trimmed('source_id');
64 $source_screen_name = $this->trimmed('source_screen_name');
65 $target_id = (int)$this->trimmed('target_id');
66 $target_screen_name = $this->trimmed('target_screen_name');
68 if (!empty($source_id)) {
69 $this->source = User::getKV($source_id);
70 } elseif (!empty($source_screen_name)) {
71 $this->source = User::getKV('nickname', $source_screen_name);
73 $this->source = $this->auth_user;
76 if (!empty($target_id)) {
77 $this->target = User::getKV($target_id);
78 } elseif (!empty($target_screen_name)) {
79 $this->target = User::getKV('nickname', $target_screen_name);
86 * Determines whether this API resource requires auth. Overloaded to look
87 * return true in case source_id and source_screen_name are both empty
89 * @return boolean true or false
91 function requiresAuth()
93 if (common_config('site', 'private')) {
97 $source_id = $this->trimmed('source_id');
98 $source_screen_name = $this->trimmed('source_screen_name');
100 if (empty($source_id) && empty($source_screen_name)) {
110 * Check the format and show the user info
112 * @param array $args $_REQUEST data (unused)
116 function handle($args)
118 parent::handle($args);
120 if (!in_array($this->format, array('xml', 'json'))) {
121 // TRANS: Client error displayed when coming across a non-supported API method.
122 $this->clientError(_('API method not found.'), 404);
125 if (empty($this->source)) {
127 // TRANS: Client error displayed when a source user could not be determined showing friendship.
128 _('Could not determine source user.'),
133 if (empty($this->target)) {
135 // TRANS: Client error displayed when a target user could not be determined showing friendship.
136 _('Could not find target user.'),
141 $result = $this->twitterRelationshipArray($this->source, $this->target);
143 switch ($this->format) {
145 $this->initDocument('xml');
146 $this->showTwitterXmlRelationship($result[relationship]);
147 $this->endDocument('xml');
150 $this->initDocument('json');
151 print json_encode($result);
152 $this->endDocument('json');
160 * Return true if read only.
164 * @param array $args other arguments
166 * @return boolean is read only action?
169 function isReadOnly($args)