]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendshipsshow.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / actions / apifriendshipsshow.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show information about the relationship between two users
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  API
23  * @package   StatusNet
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/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR . '/lib/apibareauth.php';
37
38 /**
39  * Outputs detailed information about the relationship between two users
40  *
41  * @category API
42  * @package  StatusNet
43  * @author   Dan Moore <dan@moore.cx>
44  * @author   Evan Prodromou <evan@status.net>
45  * @author   Zach Copley <zach@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  */
49
50 class ApiFriendshipsShowAction extends ApiBareAuthAction
51 {
52     var $source = null;
53     var $target = null;
54
55     /**
56      * Take arguments for running
57      *
58      * @param array $args $_REQUEST args
59      *
60      * @return boolean success flag
61      *
62      */
63
64     function prepare($args)
65     {
66         parent::prepare($args);
67
68         $source_id          = (int)$this->trimmed('source_id');
69         $source_screen_name = $this->trimmed('source_screen_name');
70         $target_id          = (int)$this->trimmed('target_id');
71         $target_screen_name = $this->trimmed('target_screen_name');
72
73         if (!empty($source_id)) {
74             $this->source = User::staticGet($source_id);
75         } elseif (!empty($source_screen_name)) {
76             $this->source = User::staticGet('nickname', $source_screen_name);
77         } else {
78             $this->source = $this->auth_user;
79         }
80
81         if (!empty($target_id)) {
82             $this->target = User::staticGet($target_id);
83         } elseif (!empty($target_screen_name)) {
84             $this->target = User::staticGet('nickname', $target_screen_name);
85         }
86
87         return true;
88     }
89
90     /**
91      * Determines whether this API resource requires auth.  Overloaded to look
92      * return true in case source_id and source_screen_name are both empty
93      *
94      * @return boolean true or false
95      */
96
97     function requiresAuth()
98     {
99         if (common_config('site', 'private')) {
100             return true;
101         }
102
103         $source_id          = $this->trimmed('source_id');
104         $source_screen_name = $this->trimmed('source_screen_name');
105
106         if (empty($source_id) && empty($source_screen_name)) {
107             return true;
108         }
109
110         return false;
111     }
112
113     /**
114      * Handle the request
115      *
116      * Check the format and show the user info
117      *
118      * @param array $args $_REQUEST data (unused)
119      *
120      * @return void
121      */
122
123     function handle($args)
124     {
125         parent::handle($args);
126
127         if (!in_array($this->format, array('xml', 'json'))) {
128             $this->clientError(_('API method not found.'), 404);
129             return;
130         }
131
132         if (empty($this->source)) {
133             $this->clientError(
134                 _('Could not determine source user.'),
135                 404
136              );
137             return;
138         }
139
140         if (empty($this->target)) {
141             $this->clientError(
142                 _('Could not find target user.'),
143                 404
144             );
145             return;
146         }
147
148         $result = $this->twitterRelationshipArray($this->source, $this->target);
149
150         switch ($this->format) {
151         case 'xml':
152             $this->initDocument('xml');
153             $this->showTwitterXmlRelationship($result[relationship]);
154             $this->endDocument('xml');
155             break;
156         case 'json':
157             $this->initDocument('json');
158             print json_encode($result);
159             $this->endDocument('json');
160             break;
161         default:
162             break;
163         }
164
165     }
166
167     /**
168      * Return true if read only.
169      *
170      * MAY override
171      *
172      * @param array $args other arguments
173      *
174      * @return boolean is read only action?
175      */
176
177     function isReadOnly($args)
178     {
179         return true;
180     }
181
182 }