123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiCheckHubAction extends ApiAuthAction
- {
- protected $url = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- if ($this->format !== 'json') {
- $this->clientError('This method currently only serves JSON.', 415);
- }
- $this->url = urldecode($args['url']);
-
- if (empty($this->url)) {
- $this->clientError(_('No URL.'), 403);
- }
- if (!common_valid_http_url($this->url)) {
- $this->clientError(_('Invalid URL.'), 403);
- }
-
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $discover = new FeedDiscovery();
- try {
- $feeduri = $discover->discoverFromURL($this->url);
- if($feeduri) {
- $huburi = $discover->getHubLink();
- }
- } catch (FeedSubNoFeedException $e) {
- $this->clientError(_('No feed found'), 403);
- } catch (FeedSubBadResponseException $e) {
- $this->clientError(_('No hub found'), 403);
- }
-
- $hub_status = array();
- if ($huburi) {
- $hub_status = array('huburi' => $huburi);
- }
-
- $this->initDocument('json');
- $this->showJsonObjects($hub_status);
- $this->endDocument('json');
- }
-
- function isReadOnly($args)
- {
- return true;
- }
- }
|