]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistmember.php
Removing unnecessary require_once lines (autoload!)
[quix0rs-gnu-social.git] / actions / apilistmember.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * API method to check if a user belongs to a list.
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    Shashi Gowda <connect2shashi@gmail.com>
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 /**
34  * Action handler for Twitter list_memeber methods
35  *
36  * @category API
37  * @package  StatusNet
38  * @author   Shashi Gowda <connect2shashi@gmail.com>
39  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40  * @link     http://status.net/
41  * @see      ApiBareAuthAction
42  */
43 class ApiListMemberAction extends ApiBareAuthAction
44 {
45     /**
46      * Set the flags for handling the request. Show the profile if this
47      * is a GET request AND the profile is a member of the list, add a member
48      * if it is a POST, remove the profile from the list if method is DELETE
49      * or if method is POST and an argument _method is set to DELETE. Act
50      * like we don't know if the current user has no access to the list.
51      *
52      * Takes parameters:
53      *     - user: the user id or nickname
54      *     - list_id: the id of the tag or the tag itself
55      *     - id: the id of the member being looked for/added/removed
56      *
57      * @return boolean success flag
58      */
59     function prepare($args)
60     {
61         parent::prepare($args);
62
63         $this->user = $this->getTargetUser($this->arg('id'));
64         $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
65
66         if (empty($this->list)) {
67             // TRANS: Client error displayed when referring to a non-existing list.
68             $this->clientError(_('List not found.'), 404, $this->format);
69             return false;
70         }
71
72         if (empty($this->user)) {
73             // TRANS: Client error displayed when referring to a non-existing user.
74             $this->clientError(_('No such user.'), 404, $this->format);
75             return false;
76         }
77         return true;
78     }
79
80     /**
81      * Handle the request
82      *
83      * @return boolean success flag
84      */
85     function handle($args)
86     {
87         parent::handle($args);
88
89         $arr = array('tagger' => $this->list->tagger,
90                       'tag' => $this->list->tag,
91                       'tagged' => $this->user->id);
92         $ptag = Profile_tag::pkeyGet($arr);
93
94         if(empty($ptag)) {
95             $this->clientError(
96                 // TRANS: Client error displayed when referring to a non-list member.
97                 _('The specified user is not a member of this list.'),
98                 400,
99                 $this->format
100             );
101         }
102
103         $user = $this->twitterUserArray($this->user->getProfile(), true);
104
105         switch($this->format) {
106         case 'xml':
107             $this->showTwitterXmlUser($user, 'user', true);
108             break;
109         case 'json':
110             $this->showSingleJsonUser($user);
111             break;
112         default:
113             $this->clientError(
114                 // TRANS: Client error displayed when coming across a non-supported API method.
115                 _('API method not found.'),
116                 404,
117                 $this->format
118             );
119             break;
120         }
121         return true;
122     }
123 }