]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendshipsshow.php
Took out some unnecessary intializations
[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    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/apibareauth.php';
35
36 /**
37  * Outputs detailed information about the relationship between two users
38  *
39  * @category API
40  * @package  StatusNet
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/
44  */
45
46 class ApiFriendshipsShowAction extends ApiBareAuthAction
47 {
48     var $source = null;
49     var $target = null;
50
51     /**
52      * Take arguments for running
53      *
54      * @param array $args $_REQUEST args
55      *
56      * @return boolean success flag
57      *
58      */
59
60     function prepare($args)
61     {
62         parent::prepare($args);
63
64         $source_id          = (int)$this->trimmed('source_id');
65         $source_screen_name = $this->trimmed('source_screen_name');
66         $target_id          = (int)$this->trimmed('target_id');
67         $target_screen_name = $this->trimmed('target_screen_name');
68     
69         if (!empty($source_id)) {
70             $this->source = User::staticGet($source_id);
71         } elseif (!empty($source_screen_name)) {
72             $this->source = User::staticGet('nickname', $source_screen_name);
73         } else {
74             $this->source = $this->auth_user;
75         }
76
77         if (!empty($target_id)) {
78             $this->target = User::staticGet($target_id);
79         } elseif (!empty($target_screen_name)) {
80             $this->target = User::staticGet('nickname', $target_screen_name);
81         }
82
83         return true;
84     }
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        
94     function requiresAuth()
95     {
96         if (common_config('site', 'private')) {
97             return true;
98         }
99
100         $source_id          = $this->trimmed('source_id');
101         $source_screen_name = $this->trimmed('source_screen_name');
102
103         if (empty($source_id) && empty($source_screen_name)) {
104             return true;
105         }
106
107         return false;
108     }
109
110     /**
111      * Handle the request
112      *
113      * Check the format and show the user info
114      *
115      * @param array $args $_REQUEST data (unused)
116      *
117      * @return void
118      */
119
120     function handle($args)
121     {
122         parent::handle($args);
123
124         if (!in_array($this->format, array('xml', 'json'))) {
125             $this->clientError(_('API method not found!'), 404);
126             return;
127         }
128         
129         if (empty($this->source)) {
130             $this->clientError(
131                 _('Could not determine source user.'),
132                 404
133              );
134             return;
135         }
136               
137         if (empty($this->target)) {
138             $this->clientError(
139                 _('Could not find target user.'),
140                 404
141             );
142             return;
143         }
144         
145         $result = $this->twitterRelationshipArray($this->source, $this->target);
146
147         switch ($this->format) {
148         case 'xml':
149             $this->initDocument('xml');
150             $this->showTwitterXmlRelationship($result[relationship]);
151             $this->endDocument('xml');
152             break;
153         case 'json':
154             $this->initDocument('json');
155             print json_encode($result);
156             $this->endDocument('json');
157             break;
158         default:
159             break;
160         }
161         
162     }
163
164 }