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('GNUSOCIAL')) { exit(1); }
35 * Outputs detailed information about the relationship between two users
39 * @author Dan Moore <dan@moore.cx>
40 * @author Evan Prodromou <evan@status.net>
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
45 class ApiFriendshipsShowAction extends ApiBareAuthAction
51 * Take arguments for running
53 * @param array $args $_REQUEST args
55 * @return boolean success flag
57 protected function prepare(array $args=array())
59 parent::prepare($args);
61 $source_id = (int)$this->trimmed('source_id');
62 $source_screen_name = $this->trimmed('source_screen_name');
63 $target_id = (int)$this->trimmed('target_id');
64 $target_screen_name = $this->trimmed('target_screen_name');
66 if (!empty($source_id)) {
67 $this->source = User::getKV($source_id);
68 } elseif (!empty($source_screen_name)) {
69 $this->source = User::getKV('nickname', $source_screen_name);
71 $this->source = $this->auth_user;
74 if (!empty($target_id)) {
75 $this->target = User::getKV($target_id);
76 } elseif (!empty($target_screen_name)) {
77 $this->target = User::getKV('nickname', $target_screen_name);
84 * Determines whether this API resource requires auth. Overloaded to look
85 * return true in case source_id and source_screen_name are both empty
87 * @return boolean true or false
89 function requiresAuth()
91 if (common_config('site', 'private')) {
95 $source_id = $this->trimmed('source_id');
96 $source_screen_name = $this->trimmed('source_screen_name');
98 if (empty($source_id) && empty($source_screen_name)) {
108 * Check the format and show the user info
112 protected function handle()
116 if (!in_array($this->format, array('xml', 'json'))) {
117 // TRANS: Client error displayed when coming across a non-supported API method.
118 $this->clientError(_('API method not found.'), 404);
121 if (empty($this->source)) {
123 // TRANS: Client error displayed when a source user could not be determined showing friendship.
124 _('Could not determine source user.'),
129 if (empty($this->target)) {
131 // TRANS: Client error displayed when a target user could not be determined showing friendship.
132 _('Could not find target user.'),
137 $result = $this->twitterRelationshipArray($this->source, $this->target);
139 switch ($this->format) {
141 $this->initDocument('xml');
142 $this->showTwitterXmlRelationship($result[relationship]);
143 $this->endDocument('xml');
146 $this->initDocument('json');
147 print json_encode($result);
148 $this->endDocument('json');
156 * Return true if read only.
160 * @param array $args other arguments
162 * @return boolean is read only action?
165 function isReadOnly($args)