]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendshipsshow.php
* i18n/L10n fixes.
[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 class ApiFriendshipsShowAction extends ApiBareAuthAction
50 {
51     var $source = null;
52     var $target = null;
53
54     /**
55      * Take arguments for running
56      *
57      * @param array $args $_REQUEST args
58      *
59      * @return boolean success flag
60      */
61     function prepare($args)
62     {
63         parent::prepare($args);
64
65         $source_id          = (int)$this->trimmed('source_id');
66         $source_screen_name = $this->trimmed('source_screen_name');
67         $target_id          = (int)$this->trimmed('target_id');
68         $target_screen_name = $this->trimmed('target_screen_name');
69
70         if (!empty($source_id)) {
71             $this->source = User::staticGet($source_id);
72         } elseif (!empty($source_screen_name)) {
73             $this->source = User::staticGet('nickname', $source_screen_name);
74         } else {
75             $this->source = $this->auth_user;
76         }
77
78         if (!empty($target_id)) {
79             $this->target = User::staticGet($target_id);
80         } elseif (!empty($target_screen_name)) {
81             $this->target = User::staticGet('nickname', $target_screen_name);
82         }
83
84         return true;
85     }
86
87     /**
88      * Determines whether this API resource requires auth.  Overloaded to look
89      * return true in case source_id and source_screen_name are both empty
90      *
91      * @return boolean true or false
92      */
93     function requiresAuth()
94     {
95         if (common_config('site', 'private')) {
96             return true;
97         }
98
99         $source_id          = $this->trimmed('source_id');
100         $source_screen_name = $this->trimmed('source_screen_name');
101
102         if (empty($source_id) && empty($source_screen_name)) {
103             return true;
104         }
105
106         return false;
107     }
108
109     /**
110      * Handle the request
111      *
112      * Check the format and show the user info
113      *
114      * @param array $args $_REQUEST data (unused)
115      *
116      * @return void
117      */
118     function handle($args)
119     {
120         parent::handle($args);
121
122         if (!in_array($this->format, array('xml', 'json'))) {
123             // TRANS: Client error displayed trying to execute an unknown API method showing friendship.
124             $this->clientError(_('API method not found.'), 404);
125             return;
126         }
127
128         if (empty($this->source)) {
129             $this->clientError(
130                 // TRANS: Client error displayed when a source user could not be determined showing friendship.
131                 _('Could not determine source user.'),
132                 404
133              );
134             return;
135         }
136
137         if (empty($this->target)) {
138             $this->clientError(
139                 // TRANS: Client error displayed when a target user could not be determined showing friendship.
140                 _('Could not find target user.'),
141                 404
142             );
143             return;
144         }
145
146         $result = $this->twitterRelationshipArray($this->source, $this->target);
147
148         switch ($this->format) {
149         case 'xml':
150             $this->initDocument('xml');
151             $this->showTwitterXmlRelationship($result[relationship]);
152             $this->endDocument('xml');
153             break;
154         case 'json':
155             $this->initDocument('json');
156             print json_encode($result);
157             $this->endDocument('json');
158             break;
159         default:
160             break;
161         }
162     }
163
164     /**
165      * Return true if read only.
166      *
167      * MAY override
168      *
169      * @param array $args other arguments
170      *
171      * @return boolean is read only action?
172      */
173
174     function isReadOnly($args)
175     {
176         return true;
177     }
178 }