123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiAttachmentAction extends ApiAuthAction
- {
- const MAXCOUNT = 100;
- var $original = null;
- var $cnt = self::MAXCOUNT;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- if ($this->format !== 'json') {
- $this->clientError('This method currently only serves JSON.', 415);
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
-
- $file = new File();
- $file->selectAdd();
- $file->selectAdd('url');
- $file->id = $this->trimmed('id');
- $url = $file->fetchAll('url');
-
- $file_txt = '';
- if(strstr($url[0],'.html')) {
- $file_txt['txt'] = file_get_contents($url[0]);
- $file_txt['body_start'] = strpos($file_txt['txt'],'<body>')+6;
- $file_txt['body_end'] = strpos($file_txt['txt'],'</body>');
- $file_txt = substr($file_txt['txt'],$file_txt['body_start'],$file_txt['body_end']-$file_txt['body_start']);
- }
- $this->initDocument('json');
- $this->showJsonObjects($file_txt);
- $this->endDocument('json');
- }
-
- function isReadOnly($args)
- {
- return true;
- }
- }
|