]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendshipsexists.php
Merge branch '0.9.x' into refactor-api
[quix0rs-gnu-social.git] / actions / apifriendshipsexists.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show whether there is a friendship 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    Zach Copley <zach@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/twitterapi.php';
35
36 /**
37  * Tests for the existence of friendship between two users. Will return true if 
38  * user_a follows user_b, otherwise will return false.
39  *
40  * @category API
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46
47 class ApiFriendshipsExistsAction extends TwitterApiAction
48 {
49
50     var $format = null;
51     var $user_a = null;
52     var $user_b = null;
53
54     /**
55      * Take arguments for running
56      *
57      * @param array $args $_REQUEST args
58      *
59      * @return boolean success flag
60      *
61      */
62
63     function prepare($args)
64     {
65         parent::prepare($args);
66
67         $this->format = $this->arg('format');
68
69         $user_a_id = $this->trimmed('user_a');
70         $user_b_id = $this->trimmed('user_b');
71
72         common_debug("user_a = " . $user_a_id);
73         common_debug("user_b = " . $user_b_id);
74
75
76         $this->user_a = $this->getTargetUser($user_a_id);
77
78         if (empty($this->user_a)) {
79             common_debug('gargargra');
80         }
81
82         $this->user_b = $this->getTargetUser($user_b_id);
83
84         return true;
85     }
86
87     /**
88      * Handle the request
89      *
90      * Check the format and show the user info
91      *
92      * @param array $args $_REQUEST data (unused)
93      *
94      * @return void
95      */
96
97     function handle($args)
98     {
99         parent::handle($args);
100
101         if (empty($this->user_a) || empty($this->user_b)) {
102             $this->clientError(
103                 _('Two user ids or screen_names must be supplied.'),
104                 400,
105                 $this->format
106             );
107             return;
108         }
109
110         $result = $this->user_a->isSubscribed($this->user_b);
111
112         switch ($this->format) {
113         case 'xml':
114             $this->init_document('xml');
115             $this->element('friends', null, $result);
116             $this->end_document('xml');
117             break;
118         case 'json':
119             $this->init_document('json');
120             print json_encode($result);
121             $this->end_document('json');
122             break;
123         default:
124             break;
125         }
126     }
127
128 }