]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apicheckhub.php
Calling parent::handle in ApiCheckHubAction
[quix0rs-gnu-social.git] / actions / apicheckhub.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a notice's attachment
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   GNUSocial
24  * @author    Hannes Mannerheim <h@nnesmannerhe.im>
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://www.gnu.org/software/social/
27  */
28
29 if (!defined('GNUSOCIAL')) { exit(1); }
30
31 /**
32  * Check if a url have a push-hub, i.e. if it is possible to subscribe
33  *
34  */
35 class ApiCheckHubAction extends ApiAuthAction
36 {
37     /**
38      * Take arguments for running
39      *
40      * @param array $args $_REQUEST args
41      *
42      * @return boolean success flag
43      */
44     protected function prepare($args)
45     {
46         parent::prepare($args);
47
48         $this->url = urldecode($args['url']);
49         
50         if (empty($this->url)) {
51             $this->clientError(_('No URL.'), 403, 'json');
52             return;            
53         }
54
55         if (!common_valid_http_url($this->url)) {
56             $this->clientError(_('Invalid URL.'), 403, 'json');
57             return;
58         }
59         
60         return true;
61     }
62
63     /**
64      * Handle the request
65      *
66      * @param array $args $_REQUEST data (unused)
67      *
68      * @return void
69      */
70     protected function handle()
71     {
72         parent::handle();
73
74         $discover = new FeedDiscovery();
75
76         try {
77             $feeduri = $discover->discoverFromURL($this->url);
78             if($feeduri) {
79                 $huburi = $discover->getHubLink();                
80             }
81         } catch (FeedSubNoFeedException $e) {
82             $this->clientError(_('No feed found'), 403, 'json');
83             return;
84         } catch (FeedSubBadResponseException $e) {
85             $this->clientError(_('No hub found'), 403, 'json');
86             return;
87         }
88                 
89                 $hub_status = array();
90                 if ($huburi) {
91                         $hub_status = array('huburi' => $huburi);
92                 }
93                         
94                 $this->initDocument('json');
95                 $this->showJsonObjects($hub_status);
96                 $this->endDocument('json');
97     }
98
99     /**
100      * Return true if read only.
101      *
102      * MAY override
103      *
104      * @param array $args other arguments
105      *
106      * @return boolean is read only action?
107      */
108
109     function isReadOnly($args)
110     {
111         return true;
112     }
113 }