Esempio n. 1
0
                        $fullsize = CoreUtils::getFullsizeURL($StashItem['id'], 'sta.sh');
                        if (!is_string($fullsize)) {
                            if ($fullsize === 404) {
                                $Database->where('provider', 'sta.sh')->where('id', $StashItem['id'])->delete('deviation_cache');
                                $Database->where('preview', $StashItem['preview'])->orWhere('fullsize', $StashItem['fullsize'])->update('requests', array('fullsize' => null, 'preview' => null));
                                $Database->where('preview', $StashItem['preview'])->orWhere('fullsize', $StashItem['fullsize'])->update('reservations', array('fullsize' => null, 'preview' => null));
                                Response::fail('The original image has been deleted from Sta.sh', array('rmdirect' => true));
                            } else {
                                throw new Exception("Code {$fullsize}; Could not find the URL");
                            }
                        }
                    } catch (Exception $e) {
                        Response::fail('Error while finding URL: ' . $e->getMessage());
                    }
                    // Check image availability
                    if (!!DeviantArt::isImageAvailable($fullsize)) {
                        Response::fail("The specified image doesn't seem to exist. Please verify that you can reach the URL below and try again.<br><a href='{$fullsize}' target='_blank'>{$fullsize}</a>");
                    }
                    if (!$Database->where('id', $Post->id)->update("{$thing}s", array('fullsize' => $fullsize))) {
                        Response::dbError();
                    }
                    Response::done(array('fullsize' => $fullsize));
                }
            }
        }
    }
}
$type = (new Input('what', function ($value) {
    if (!in_array($value, Posts::$TYPES)) {
        return Input::ERROR_INVALID;
    }
Esempio n. 2
0
 private function _getDirectUrl($id)
 {
     switch ($this->provider) {
         case 'imgur':
             $this->fullsize = "https://i.imgur.com/{$id}.png";
             $this->preview = "https://i.imgur.com/{$id}m.png";
             self::_checkImageAllowed($this->fullsize);
             break;
         case 'derpibooru':
             $Data = @file_get_contents("http://derpibooru.org/{$id}.json");
             if (empty($Data)) {
                 throw new \Exception('The requested image could not be found on Derpibooru');
             }
             $Data = JSON::decode($Data);
             if (isset($Data['duplicate_of'])) {
                 return $this->_getDirectUrl($Data['duplicate_of']);
             }
             if (!isset($Data['is_rendered'])) {
                 error_log("Invalid Derpibooru response for ID {$id}\n" . var_export($Data, true));
                 throw new \Exception('Derpibooru returned an invalid API response. This issue has been logged, please <a class="send-feedback">remind us</a> to take a look.');
             }
             if (!$Data['is_rendered']) {
                 throw new \Exception('The image was found but it hasn\'t been rendered yet. Please wait for it to render and try again shortly.');
             }
             $this->fullsize = $Data['representations']['full'];
             $this->preview = $Data['representations']['small'];
             self::_checkImageAllowed($this->fullsize, $Data['mime_type']);
             break;
         case 'puush':
             $path = "http://puu.sh/{$id}";
             $image = @file_get_contents($path);
             if (empty($image) || $image === 'That puush could not be found.') {
                 throw new \Exception('The requested image could not be found on Puu.sh');
             }
             if ($image === 'You do not have access to view that puush.') {
                 throw new \Exception('The requested image is a private Puu.sh and the token is missing from the URL');
             }
             self::_checkImageAllowed($path);
             $this->fullsize = $this->preview = $path;
             break;
         case 'dA':
         case 'fav.me':
         case 'sta.sh':
             if ($this->provider === 'dA') {
                 $id = 'd' . base_convert($id, 10, 36);
                 $this->provider = 'fav.me';
             }
             try {
                 $CachedDeviation = DeviantArt::getCachedSubmission($id, $this->provider);
                 if (!DeviantArt::isImageAvailable($CachedDeviation['preview'])) {
                     $preview = CoreUtils::aposEncode($CachedDeviation['preview']);
                     throw new \Exception("The preview image appears to be unavailable. Please make sure <a href='{$preview}'>this link</a> works and try again, or re-submit the deviation if this persists.");
                 }
                 if (!DeviantArt::isImageAvailable($CachedDeviation['fullsize'])) {
                     $fullsize = CoreUtils::aposEncode($CachedDeviation['fullsize']);
                     throw new \Exception("The submission appears to be unavailable. Please make sure <a href='{$fullsize}'>this link</a> works and try again, or re-submit the deviation if this persists.");
                 }
             } catch (CURLRequestException $e) {
                 if ($e->getCode() === 404) {
                     throw new \Exception('The requested image could not be found');
                 }
                 throw new \Exception($e->getMessage());
             }
             if (empty($CachedDeviation)) {
                 throw new \Exception("{$this->provider} submission information could not be fetched for {$id}");
             }
             $this->preview = $CachedDeviation['preview'];
             $this->fullsize = $CachedDeviation['fullsize'];
             $this->title = $CachedDeviation['title'];
             $this->author = $CachedDeviation['author'];
             self::_checkImageAllowed($this->preview);
             self::_checkImageAllowed($this->fullsize);
             break;
         case 'lightshot':
             $page = @file_get_contents("http://prntscr.com/{$id}");
             if (empty($page)) {
                 throw new \Exception('The requested page could not be found');
             }
             if (!preg_match(new RegExp('<img\\s+class="image__pic[^"]*"\\s+src="http://i\\.imgur\\.com/([A-Za-z\\d]+)\\.'), $page, $_match)) {
                 throw new \Exception('The requested image could not be found');
             }
             $this->provider = 'imgur';
             $this->_getDirectUrl($_match[1]);
             break;
         default:
             throw new \Exception("The image could not be retrieved due to a missing handler for the provider \"{$this->provider}\"");
     }
     $this->preview = URL::makeHttps($this->preview);
     $this->fullsize = URL::makeHttps($this->fullsize);
     $this->id = $id;
 }