Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions phpFlickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ function phpFlickr ($api_key, $secret = NULL, $die_on_error = false) {
$this->php_version = explode(".", $this->php_version[0]);
}

/*
* Generic API call with cURL
* @require http://curl.haxx.se/ca/cacert.pem
*/
private function callApi($endpoint, $data) {
$error = array();
$curl = curl_init($endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
$response = curl_exec($curl);
$error['number'] = curl_errno($curl);
$error['message'] = curl_error($curl);
$error['curl_getinfo'] = curl_getinfo($curl);
curl_close($curl);
if ($error['number'] > 0 && $this->die_on_error) {
die("cURL returned the following error: #{$error['number']} - {$error['message']}");
}
return $response;
}

function enableCache ($type, $connection, $cache_expire = 600, $table = 'flickr_cache') {
// Turns on caching. $type must be either "db" (for database caching) or "fs" (for filesystem).
// When using db, $connection must be a PEAR::DB connection string. Example:
Expand Down Expand Up @@ -221,12 +245,7 @@ function post ($data, $type = null) {

if ( function_exists('curl_init') ) {
// Has curl. Use it!
$curl = curl_init($this->rest_endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
$response = $this->callApi($this->rest_endpoint, $data);
} else {
// Use sockets.
foreach ( $data as $key => $value ) {
Expand Down Expand Up @@ -429,15 +448,8 @@ function sync_upload ($photo, $title = null, $description = null, $tags = null,
$photo = realpath($photo);
$args['photo'] = '@' . $photo;


$curl = curl_init($this->upload_endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$this->response = $response;
curl_close($curl);

$response = $this->callApi($this->upload_endpoint, $args);

$rsp = explode("\n", $response);
foreach ($rsp as $line) {
if (preg_match('|<err code="([0-9]+)" msg="(.*)"|', $line, $match)) {
Expand Down Expand Up @@ -491,15 +503,8 @@ function async_upload ($photo, $title = null, $description = null, $tags = null,
$photo = realpath($photo);
$args['photo'] = '@' . $photo;


$curl = curl_init($this->upload_endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$this->response = $response;
curl_close($curl);

$response = $this->callApi($this->upload_endpoint, $args);

$rsp = explode("\n", $response);
foreach ($rsp as $line) {
if (preg_match('/<err code="([0-9]+)" msg="(.*)"/', $line, $match)) {
Expand Down Expand Up @@ -553,13 +558,7 @@ function replace ($photo, $photo_id, $async = null) {
$args['photo'] = '@' . $photo;


$curl = curl_init($this->replace_endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$this->response = $response;
curl_close($curl);
$this->response = $this->callApi($this->replace_endpoint, $args);

if ($async == 1)
$find = 'ticketid';
Expand Down Expand Up @@ -1819,4 +1818,3 @@ function next() {
}
}

?>