/** * Loads an image from a file path * * @param string $filename Full path to the file which will be manipulated * @return ImageGD */ public function load($filename) { if (function_exists("finfo_open")) { // not supported everywhere https://github.com/openphoto/frontend/issues/368 $finfo = finfo_open(FILEINFO_MIME_TYPE); $this->type = finfo_file($finfo, $filename); } else { if (function_exists("mime_content_type")) { $this->type = mime_content_type($filename); } else { if (function_exists('exec')) { $this->type = exec('/usr/bin/file --mime-type -b ' . escapeshellarg($filename)); if (!empty($this->type)) { $this->type = ""; } } } } if (preg_match('/png$/', $this->type)) { $this->image = imagecreatefrompng($filename); } elseif (preg_match('/gif$/', $this->type)) { $this->image = @imagecreatefromgif($filename); } else { $this->image = @imagecreatefromjpeg($filename); } if (!$this->image) { OPException::raise(new OPInvalidImageException('Could not create image with GD library')); } $this->width = imagesx($this->image); $this->height = imagesy($this->image); return $this; }
/** * Loads an image from a file path * * @param string $filename Full path to the file which will be manipulated * @return ImageGraphicsMagick */ public function load($filename) { try { $this->image = new Gmagick($filename); return $this; } catch (GmagickException $e) { OPException::raise(new OPInvalidImageException('Could not create jpeg with GraphicsMagick library')); } }
/** * Loads an image from a file path * * @param string $filename Full path to the file which will be manipulated * @return ImageImageMagick */ public function load($filename) { try { $this->image = new Imagick($filename); return $this; } catch (ImagickException $e) { OPException::raise(new OPInvalidImageException('Could not create jpeg with ImageMagick library')); } //$this->image->setImageCompression(imagick::COMPRESSION_NO); //$this->image->setImageCompressionQuality(20); }
/** * Check that the crumb is valid * * @param $crumb the crumb posted to validate */ public function requireCrumb($crumb = null) { if ($this->credential->isOAuthRequest()) { return; } elseif ($crumb === null && isset($_REQUEST['crumb'])) { $crumb = $_REQUEST['crumb']; } if ($this->session->get('crumb') != $crumb) { OPException::raise(new OPAuthorizationException('Crumb does not match')); } }
/** * Loads an image from a file path * * @param string $filename Full path to the file which will be manipulated * @return ImageGD */ public function load($filename) { if ($this->image) { imagedestroy($this->image); $this->image = null; } $this->type = get_mime_type($filename); if (preg_match('/png$/', $this->type)) { $this->image = imagecreatefrompng($filename); } elseif (preg_match('/gif$/', $this->type)) { $this->image = @imagecreatefromgif($filename); } else { $this->image = @imagecreatefromjpeg($filename); } if (!$this->image) { OPException::raise(new OPInvalidImageException('Could not create image with GD library')); } $this->filename = $filename; $this->width = imagesx($this->image); $this->height = imagesy($this->image); return $this; }
public function flow() { if (isset($_GET['oauth_token'])) { $consumerKey = $_GET['oauth_consumer_key']; $consumerSecret = $_GET['oauth_consumer_secret']; $token = $_GET['oauth_token']; $tokenSecret = $_GET['oauth_token_secret']; $verifier = $_GET['oauth_verifier']; try { $consumer = getDb()->getCredential($token); $oauth = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION); $oauth->setVersion('1.0a'); $oauth->setToken($token, $tokenSecret); $accessToken = $oauth->getAccessToken(sprintf('%s://%s/v1/oauth/token/access', $this->utility->getProtocol(false), $_SERVER['HTTP_HOST']), null, $verifier); $accessToken['oauth_consumer_key'] = $consumerKey; $accessToken['oauth_consumer_secret'] = $consumerSecret; setcookie('oauth', http_build_query($accessToken)); if (!isset($accessToken['oauth_token']) || !isset($accessToken['oauth_token_secret'])) { echo sprintf('Invalid response when getting an access token: %s', http_build_query($accessToken)); } else { echo sprintf('You exchanged a request token for an access token<br><a href="?reloaded=1">Reload to make an OAuth request</a>', $accessToken['oauth_token'], $accessToken['oauth_token_secret']); } } catch (OAuthException $e) { $message = OAuthProvider::reportProblem($e); getLogger()->info($message); OPException::raise(new OPAuthorizationOAuthException($message)); } } else { if (!isset($_GET['reloaded'])) { $callback = sprintf('%s://%s/v1/oauth/flow', $this->utility->getProtocol(false), $_SERVER['HTTP_HOST']); $name = isset($_GET['name']) ? $_GET['name'] : 'OAuth Test Flow'; echo sprintf('<a href="%s://%s/v1/oauth/authorize?oauth_callback=%s&name=%s">Create a new client id</a>', $this->utility->getProtocol(false), $_SERVER['HTTP_HOST'], urlencode($callback), urlencode($name)); } else { try { parse_str($_COOKIE['oauth']); $consumer = getDb()->getCredential($oauth_token); $oauth = new OAuth($oauth_consumer_key, $oauth_consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION); $oauth->setToken($oauth_token, $oauth_token_secret); $oauth->fetch(sprintf('http://%s/v1/oauth/test?oauth_consumer_key=%s', $_SERVER['HTTP_HOST'], $oauth_consumer_key)); $response_info = $oauth->getLastResponseInfo(); header("Content-Type: {$response_info["content_type"]}"); echo $oauth->getLastResponse(); } catch (OAuthException $e) { $message = OAuthProvider::reportProblem($e); getLogger()->info($message); OPException::raise(new OPAuthorizationOAuthException($message)); } } } }