]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendshipsshow.php
Email notify-on-fave moved to Profile_prefs (run upgrade.php)
[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 /**
37  * Outputs detailed information about the relationship between two users
38  *
39  * @category API
40  * @package  StatusNet
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/
46  */
47 class ApiFriendshipsShowAction extends ApiBareAuthAction
48 {
49     var $source = null;
50     var $target = null;
51
52     /**
53      * Take arguments for running
54      *
55      * @param array $args $_REQUEST args
56      *
57      * @return boolean success flag
58      */
59     function prepare($args)
60     {
61         parent::prepare($args);
62
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');
67
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);
72         } else {
73             $this->source = $this->auth_user;
74         }
75
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);
80         }
81
82         return true;
83     }
84
85     /**
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
88      *
89      * @return boolean true or false
90      */
91     function requiresAuth()
92     {
93         if (common_config('site', 'private')) {
94             return true;
95         }
96
97         $source_id          = $this->trimmed('source_id');
98         $source_screen_name = $this->trimmed('source_screen_name');
99
100         if (empty($source_id) && empty($source_screen_name)) {
101             return true;
102         }
103
104         return false;
105     }
106
107     /**
108      * Handle the request
109      *
110      * Check the format and show the user info
111      *
112      * @param array $args $_REQUEST data (unused)
113      *
114      * @return void
115      */
116     function handle($args)
117     {
118         parent::handle($args);
119
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);
123         }
124
125         if (empty($this->source)) {
126             $this->clientError(
127                 // TRANS: Client error displayed when a source user could not be determined showing friendship.
128                 _('Could not determine source user.'),
129                 404
130              );
131         }
132
133         if (empty($this->target)) {
134             $this->clientError(
135                 // TRANS: Client error displayed when a target user could not be determined showing friendship.
136                 _('Could not find target user.'),
137                 404
138             );
139         }
140
141         $result = $this->twitterRelationshipArray($this->source, $this->target);
142
143         switch ($this->format) {
144         case 'xml':
145             $this->initDocument('xml');
146             $this->showTwitterXmlRelationship($result[relationship]);
147             $this->endDocument('xml');
148             break;
149         case 'json':
150             $this->initDocument('json');
151             print json_encode($result);
152             $this->endDocument('json');
153             break;
154         default:
155             break;
156         }
157     }
158
159     /**
160      * Return true if read only.
161      *
162      * MAY override
163      *
164      * @param array $args other arguments
165      *
166      * @return boolean is read only action?
167      */
168
169     function isReadOnly($args)
170     {
171         return true;
172     }
173 }