/** * Get data from remote service * Method : pull(String $action [, Array $parameters]) * Return : a JSON object, same structure as returned by Web Service **/ public function get($action, $parameters = false) { $url = $this->baseURL . '/' . (!!$this->version ? $this->version . '/' : '') . $action . '?'; $url = $this->attach($url, $parameters); $response = Remote::pull($url); if (!!$response) { $ob = json_decode($response); if (!!$ob && is_object($ob)) { if (!isset($ob->error) || !$ob->error) { return $ob; } } } return false; }
private static function remoteToLocalImage($url, $path, $lim = false, $saveas = '', $quality = 75) { $im = @getimagesize($url); if (!!$im) { require_once 'Master/base/libraries/Images/SimpleImage.php'; $type = $im['mime']; $width = $im[0]; $height = $im[1]; $minWidth = static::MIN_WIDTH; $minHeight = static::MIN_HEIGHT; $maxWidth = static::MAX_WIDTH; $maxHeight = static::MAX_HEIGHT; if (!!$lim) { $lim = (object) $lim; if (isset($lim->minWidth)) { $minWidth = $lim->minWidth; } if (isset($lim->minHeight)) { $minHeight = $lim->minHeight; } if (isset($lim->maxWidth)) { $maxWidth = $lim->maxWidth; } if (isset($lim->maxHeight)) { $maxHeight = $lim->maxHeight; } } if ($width > $minWidth && $height > $minHeight && strpos($type, 'image') === 0) { $ext = static::getExt($type); if (!!$ext) { $content = Remote::pull($url); if (!!$content) { $name = !!$saveas ? $saveas : Bella::createId(32); $name .= $ext; $file = $path . $name; $save = @file_put_contents($file, $content); if (!!$save) { if ($width > $maxWidth || $height > $maxHeight) { $sm = new SimpleImage(); $sm->load($file); $sm->fillTo($maxWidth, $maxHeight); $sm->save($file, false, $quality); } return $name; } } } } } return false; }