Automatically generated installer lang files
[moodle.git] / lib / flickrlib.php
blob7d54e28573c6e6f299cf829aa1db5f4f722cf185
1 <?php
2 /**
3 * phpFlickr Class 2.2.0
4 * Written by Dan Coulter (dan@dancoulter.com)
5 * Sourceforge Project Page: {@link http://www.sourceforge.net/projects/phpflickr/}
6 * Released under GNU Lesser General Public License ({@link http://www.gnu.org/copyleft/lgpl.html})
7 * For more information about the class and upcoming tools and toys using it,
8 * visit {@link http://www.phpflickr.com/} or {@link http://phpflickr.sourceforge.net}
10 * For installation instructions, open the README.txt file packaged with this
11 * class. If you don't have a copy, you can see it at:
12 * {@link http://www.phpflickr.com/README.txt}
14 * Please submit all problems or questions to the Help Forum on my project page:
15 * {@link http://sourceforge.net/forum/forum.php?forum_id=469652}
17 * Modified by Dongsheng Cai <dongsheng@moodle.com>
18 * ChangeLog:
19 * 1. Remove PEAR HTTP LIB, use curl.class.php (created by myself)
20 * 2. Remove PEAR DB LIB
21 * 3. Remove all cache code, it will implement in curl class.
22 * 4. Clean up session code
24 * Modified by David Mudrak <david@moodle.com>
25 * ChangeLog:
26 * 1. upload() method uses Moodle stored_file
27 * 2. upload() method supports all params provided by http://www.flickr.com/services/api/upload.api.html
28 * 3. auth() method shows debugging warning as this library cannot be used any
29 * more for calling Flickr API that requires authentication.
31 * @package moodlecore
32 * @subpackage 3rd-party
35 defined('MOODLE_INTERNAL') || die();
37 global $CFG;
38 require_once("{$CFG->libdir}/flickrclient.php");
40 /**
41 * Flickr Class
42 * @package moodlecore
43 * @subpackage 3rd-party
45 class phpFlickr {
46 var $api_key;
47 var $secret;
48 var $REST = 'https://api.flickr.com/services/rest/';
49 var $Upload = 'https://api.flickr.com/services/upload/';
50 var $Replace = 'https://api.flickr.com/services/replace/';
51 var $req;
52 var $response;
53 var $parsed_response;
54 var $die_on_error;
55 var $error_code;
56 var $error_msg;
57 var $token;
58 var $php_version;
60 /**
61 * When your database cache table hits this many rows, a cleanup
62 * will occur to get rid of all of the old rows and cleanup the
63 * garbage in the table. For most personal apps, 1000 rows should
64 * be more than enough. If your site gets hit by a lot of traffic
65 * or you have a lot of disk space to spare, bump this number up.
66 * You should try to set it high enough that the cleanup only
67 * happens every once in a while, so this will depend on the growth
68 * of your table.
70 * @global object
73 function __construct ($api_key, $secret = NULL, $token = '')
75 global $CFG;
76 //The API Key must be set before any calls can be made. You can
77 //get your own at http://www.flickr.com/services/api/misc.api_keys.html
78 $this->api_key = $api_key;
79 $this->secret = $secret;
80 $this->die_on_error = false;
81 $this->service = "flickr";
82 $this->token = $token;
83 //Find the PHP version and store it for future reference
84 $this->php_version = explode("-", phpversion());
85 $this->php_version = explode(".", $this->php_version[0]);
87 // Initialize curl helper, set custom user agent as Flickr blocks our "MoodleBot" agent string.
88 $this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
89 $this->curl->setopt([
90 'CURLOPT_USERAGENT' => flickr_client::user_agent(),
91 ]);
94 function request ($command, $args = array())
96 //Sends a request to Flickr's REST endpoint via POST.
97 if (substr($command,0,7) != "flickr.") {
98 $command = "flickr." . $command;
101 //Process arguments, including method and login data.
102 if ($command == 'flickr.upload') {
103 $photo = $args['photo'];
104 if (empty($args['is_public'])) {
105 $args['is_public'] = 0;
107 if (empty($args['is_friend'])) {
108 $args['is_friend'] = 0;
110 if (empty($args['is_family'])) {
111 $args['is_family'] = 0;
113 if (empty($args['hidden'])) {
114 $args['hidden'] = 1;
116 $args = array("api_key" => $this->api_key,
117 "title" => $args['title'],
118 "description" => $args['description'],
119 "tags" => $args['tags'],
120 "is_public" => $args['is_public'],
121 "is_friend" => $args['is_friend'],
122 "is_family" => $args['is_family'],
123 "safety_level" => $args['safety_level'],
124 "content_type" => $args['content_type'],
125 "hidden" => $args['hidden']);
126 } else {
127 $args = array_merge(array("method" => $command, "format" => "php_serial", "api_key" => $this->api_key), $args);
130 if (!empty($this->token)) {
131 $args = array_merge($args, array("auth_token" => $this->token));
134 ksort($args);
135 $auth_sig = "";
136 foreach ($args as $key => $data) {
137 $auth_sig .= $key . $data;
140 if (!empty($this->secret)) {
141 $api_sig = md5($this->secret . $auth_sig);
142 $args['api_sig'] = $api_sig;
145 //$this->req->addHeader("Connection", "Keep-Alive");
146 if ($command != 'flickr.upload') {
147 $ret = $this->curl->post($this->REST, $args);
148 $this->parsed_response = $this->clean_text_nodes(unserialize($ret));
149 } else {
150 $args['photo'] = $photo;
151 $xml = simplexml_load_string($this->curl->post($this->Upload, $args));
153 if ($xml['stat'] == 'fail') {
154 $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'], 'message' => (string) $xml->err['msg']);
155 } elseif ($xml['stat'] == 'ok') {
156 $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid);
157 $this->response = true;
161 if ($this->parsed_response['stat'] == 'fail') {
162 if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
163 else {
164 $this->error_code = $this->parsed_response['code'];
165 $this->error_msg = $this->parsed_response['message'];
166 $this->parsed_response = false;
168 } else {
169 $this->error_code = false;
170 $this->error_msg = false;
172 return $this->response;
175 function clean_text_nodes($arr) {
176 if (!is_array($arr)) {
177 return $arr;
178 } elseif (count($arr) == 0) {
179 return $arr;
180 } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) {
181 return $arr['_content'];
182 } else {
183 foreach ($arr as $key => $element) {
184 $arr[$key] = $this->clean_text_nodes($element);
186 return($arr);
190 function setToken($token)
192 // Sets an authentication token to use instead of the session variable
193 $this->token = $token;
196 function setProxy($server, $port)
198 // Sets the proxy for all phpFlickr calls.
199 //$this->req->setProxy($server, $port);
202 function getErrorCode()
204 // Returns the error code of the last call. If the last call did not
205 // return an error. This will return a false boolean.
206 return $this->error_code;
209 function getErrorMsg()
211 // Returns the error message of the last call. If the last call did not
212 // return an error. This will return a false boolean.
213 return $this->error_msg;
216 /** These functions are front ends for the flickr calls */
218 function buildPhotoURL ($photo, $size = "Medium")
220 //receives an array (can use the individual photo data returned
221 //from an API call) and returns a URL (doesn't mean that the
222 //file size exists)
223 $sizes = array(
224 "square" => "_s",
225 "thumbnail" => "_t",
226 "small" => "_m",
227 "medium" => "",
228 "large" => "_b",
229 "original" => "_o"
232 $size = strtolower($size);
233 if (!array_key_exists($size, $sizes)) {
234 $size = "medium";
237 if ($size == "original") {
238 $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat'];
239 } else {
240 $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg";
242 return $url;
245 function getFriendlyGeodata($lat, $lon) {
246 /** I've added this method to get the friendly geodata (i.e. 'in New York, NY') that the
247 * website provides, but isn't available in the API. I'm providing this service as long
248 * as it doesn't flood my server with requests and crash it all the time.
250 return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon));
253 function auth ($perms = "write", $remember_uri = true)
256 debugging('The flickrlib.php cannot be used for authenticated Flickr API calls.
257 Flickr does not support their legacy auth API any more. Use the new flickrclient.php instead.');
259 // Redirects to Flickr's authentication piece if there is no valid token.
260 // If remember_uri is set to false, the callback script (included) will
261 // redirect to its default page.
262 if ($remember_uri) {
263 $redirect = qualified_me(); // TODO: this is not used, why?
265 $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms);
266 $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" . $perms . '&api_sig='. $api_sig;
267 return $url;
271 * To use the phpFlickr::call method, pass a string containing the API method you want
272 * to use and an associative array of arguments. For example:
273 * $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612'));
274 * This method will allow you to make calls to arbitrary methods that haven't been
275 * implemented in phpFlickr yet.
278 function call($method, $arguments)
280 $this->request($method, $arguments);
281 return $this->parsed_response ? $this->parsed_response : false;
285 * These functions are the direct implementations of flickr calls.
286 * For method documentation, including arguments, visit the address
287 * included in a comment in the function.
290 /** Activity methods */
291 function activity_userComments ($per_page = NULL, $page = NULL)
293 /** http://www.flickr.com/services/api/flickr.activity.userComments.html */
294 $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page));
295 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
298 function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL)
300 /** http://www.flickr.com/services/api/flickr.activity.userPhotos.html */
301 $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page));
302 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
305 /** Authentication methods */
306 function auth_checkToken ()
308 /** http://www.flickr.com/services/api/flickr.auth.checkToken.html */
309 $this->request('flickr.auth.checkToken');
310 return $this->parsed_response ? $this->parsed_response['auth'] : false;
313 function auth_getFrob ()
315 /** http://www.flickr.com/services/api/flickr.auth.getFrob.html */
316 $this->request('flickr.auth.getFrob');
317 return $this->parsed_response ? $this->parsed_response['frob'] : false;
320 function auth_getFullToken ($mini_token)
322 /** http://www.flickr.com/services/api/flickr.auth.getFullToken.html */
323 $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token));
324 return $this->parsed_response ? $this->parsed_response['auth'] : false;
327 function auth_getToken ($frob)
329 /** http://www.flickr.com/services/api/flickr.auth.getToken.html */
330 $this->request('flickr.auth.getToken', array('frob'=>$frob));
331 $this->token = $this->parsed_response['auth']['token'];
332 return $this->parsed_response ? $this->parsed_response['auth'] : false;
335 /** Blogs methods */
336 function blogs_getList ()
338 /** http://www.flickr.com/services/api/flickr.blogs.getList.html */
339 $this->request('flickr.blogs.getList');
340 return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false;
343 function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL)
345 /** http://www.flickr.com/services/api/flickr.blogs.postPhoto.html */
346 $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE);
347 return $this->parsed_response ? true : false;
350 /** Contacts Methods */
351 function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL)
353 /** http://www.flickr.com/services/api/flickr.contacts.getList.html */
354 $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page));
355 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
358 function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL)
360 /** http://www.flickr.com/services/api/flickr.contacts.getPublicList.html */
361 $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page));
362 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
365 /** Favorites Methods */
366 function favorites_add ($photo_id)
368 /** http://www.flickr.com/services/api/flickr.favorites.add.html */
369 $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE);
370 return $this->parsed_response ? true : false;
373 function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
375 /** http://www.flickr.com/services/api/flickr.favorites.getList.html */
376 if (is_array($extras)) { $extras = implode(",", $extras); }
377 $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
378 return $this->parsed_response ? $this->parsed_response['photos'] : false;
381 function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
383 /** http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */
384 if (is_array($extras)) {
385 $extras = implode(",", $extras);
387 $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
388 return $this->parsed_response ? $this->parsed_response['photos'] : false;
391 function favorites_remove($photo_id)
393 /** http://www.flickr.com/services/api/flickr.favorites.remove.html */
394 $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE);
395 return $this->parsed_response ? true : false;
398 /** Groups Methods */
399 function groups_browse ($cat_id = NULL)
401 /** http://www.flickr.com/services/api/flickr.groups.browse.html */
402 $this->request("flickr.groups.browse", array("cat_id"=>$cat_id));
403 return $this->parsed_response ? $this->parsed_response['category'] : false;
406 function groups_getInfo ($group_id)
408 /** http://www.flickr.com/services/api/flickr.groups.getInfo.html */
409 $this->request("flickr.groups.getInfo", array("group_id"=>$group_id));
410 return $this->parsed_response ? $this->parsed_response['group'] : false;
413 function groups_search ($text, $per_page=NULL, $page=NULL)
415 /** http://www.flickr.com/services/api/flickr.groups.search.html */
416 $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page));
417 return $this->parsed_response ? $this->parsed_response['groups'] : false;
420 /** Groups Pools Methods */
421 function groups_pools_add ($photo_id, $group_id)
423 /** http://www.flickr.com/services/api/flickr.groups.pools.add.html */
424 $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
425 return $this->parsed_response ? true : false;
428 function groups_pools_getContext ($photo_id, $group_id)
430 /** http://www.flickr.com/services/api/flickr.groups.pools.getContext.html */
431 $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id));
432 return $this->parsed_response ? $this->parsed_response : false;
435 function groups_pools_getGroups ($page = NULL, $per_page = NULL)
437 /** http://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */
438 $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page));
439 return $this->parsed_response ? $this->parsed_response['groups'] : false;
442 function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
444 /** http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */
445 if (is_array($extras)) {
446 $extras = implode(",", $extras);
448 $this->request("flickr.groups.pools.getPhotos", array("group_id"=>$group_id, "tags"=>$tags, "user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
449 return $this->parsed_response ? $this->parsed_response['photos'] : false;
452 function groups_pools_remove ($photo_id, $group_id)
454 /** http://www.flickr.com/services/api/flickr.groups.pools.remove.html */
455 $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
456 return $this->parsed_response ? true : false;
459 /** Interestingness methods */
460 function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
462 /** http://www.flickr.com/services/api/flickr.interestingness.getList.html */
463 if (is_array($extras)) {
464 $extras = implode(",", $extras);
467 $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
468 return $this->parsed_response ? $this->parsed_response['photos'] : false;
471 /** People methods */
472 function people_findByEmail ($find_email)
474 /** http://www.flickr.com/services/api/flickr.people.findByEmail.html */
475 $this->request("flickr.people.findByEmail", array("find_email"=>$find_email));
476 return $this->parsed_response ? $this->parsed_response['user'] : false;
479 function people_findByUsername ($username)
481 /** http://www.flickr.com/services/api/flickr.people.findByUsername.html */
482 $this->request("flickr.people.findByUsername", array("username"=>$username));
483 return $this->parsed_response ? $this->parsed_response['user'] : false;
486 function people_getInfo($user_id)
488 /** http://www.flickr.com/services/api/flickr.people.getInfo.html */
489 $this->request("flickr.people.getInfo", array("user_id"=>$user_id));
490 return $this->parsed_response ? $this->parsed_response['person'] : false;
493 function people_getPublicGroups($user_id)
495 /** http://www.flickr.com/services/api/flickr.people.getPublicGroups.html */
496 $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id));
497 return $this->parsed_response ? $this->parsed_response['groups']['group'] : false;
500 function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) {
501 /** http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */
502 if (is_array($extras)) {
503 $extras = implode(",", $extras);
506 $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
507 return $this->parsed_response ? $this->parsed_response['photos'] : false;
510 function people_getUploadStatus()
512 /** http://www.flickr.com/services/api/flickr.people.getUploadStatus.html */
513 /** Requires Authentication */
514 $this->request("flickr.people.getUploadStatus");
515 return $this->parsed_response ? $this->parsed_response['user'] : false;
519 /** Photos Methods */
520 function photos_addTags ($photo_id, $tags)
522 /** http://www.flickr.com/services/api/flickr.photos.addTags.html */
523 $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
524 return $this->parsed_response ? true : false;
527 function photos_delete($photo_id)
529 /** http://www.flickr.com/services/api/flickr.photos.delete.html */
530 $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE);
531 return $this->parsed_response ? true : false;
534 function photos_getAllContexts ($photo_id)
536 /** http://www.flickr.com/services/api/flickr.photos.getAllContexts.html */
537 $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id));
538 return $this->parsed_response ? $this->parsed_response : false;
541 function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
543 /** http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */
544 $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
545 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
548 function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
550 /** http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */
551 $this->request("flickr.photos.getContactsPublicPhotos", array("user_id"=>$user_id, "count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
552 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
555 function photos_getContext ($photo_id)
557 /** http://www.flickr.com/services/api/flickr.photos.getContext.html */
558 $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id));
559 return $this->parsed_response ? $this->parsed_response : false;
562 function photos_getCounts ($dates = NULL, $taken_dates = NULL)
564 /** http://www.flickr.com/services/api/flickr.photos.getCounts.html */
565 $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates));
566 return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false;
569 function photos_getExif ($photo_id, $secret = NULL)
571 /** http://www.flickr.com/services/api/flickr.photos.getExif.html */
572 $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret));
573 return $this->parsed_response ? $this->parsed_response['photo'] : false;
576 function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL)
578 /** http://www.flickr.com/services/api/flickr.photos.getFavorites.html */
579 $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page));
580 return $this->parsed_response ? $this->parsed_response['photo'] : false;
583 function photos_getInfo($photo_id, $secret = NULL)
585 /** http://www.flickr.com/services/api/flickr.photos.getInfo.html */
586 $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret));
587 return $this->parsed_response ? $this->parsed_response['photo'] : false;
590 function photos_getNotInSet($min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL, $privacy_filter = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
592 /** http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */
593 if (is_array($extras)) {
594 $extras = implode(",", $extras);
596 $this->request("flickr.photos.getNotInSet", array("min_upload_date"=>$min_upload_date, "max_upload_date"=>$max_upload_date, "min_taken_date"=>$min_taken_date, "max_taken_date"=>$max_taken_date, "privacy_filter"=>$privacy_filter, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
597 return $this->parsed_response ? $this->parsed_response['photos'] : false;
600 function photos_getPerms($photo_id)
602 /** http://www.flickr.com/services/api/flickr.photos.getPerms.html */
603 $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id));
604 return $this->parsed_response ? $this->parsed_response['perms'] : false;
607 function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL)
609 /** http://www.flickr.com/services/api/flickr.photos.getRecent.html */
611 if (is_array($extras)) {
612 $extras = implode(",", $extras);
614 $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
615 return $this->parsed_response ? $this->parsed_response['photos'] : false;
618 function photos_getSizes($photo_id)
620 /** http://www.flickr.com/services/api/flickr.photos.getSizes.html */
621 $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id));
622 return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false;
625 function photos_getUntagged($min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL, $privacy_filter = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
627 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
628 if (is_array($extras)) {
629 $extras = implode(",", $extras);
631 $this->request("flickr.photos.getUntagged", array("min_upload_date"=>$min_upload_date, "max_upload_date"=>$max_upload_date, "min_taken_date"=>$min_taken_date, "max_taken_date"=>$max_taken_date, "privacy_filter"=>$privacy_filter, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
632 return $this->parsed_response ? $this->parsed_response['photos'] : false;
635 function photos_getWithGeoData($args = NULL) {
636 /** See the documentation included with the photos_search() function.
637 * I'm using the same style of arguments for this function. The only
638 * difference here is that this doesn't require any arguments. The
639 * flickr.photos.search method requires at least one search parameter.
641 /** http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */
642 if (is_null($args)) {
643 $args = array();
645 $this->request("flickr.photos.getWithGeoData", $args);
646 return $this->parsed_response ? $this->parsed_response['photos'] : false;
649 function photos_getWithoutGeoData($args = NULL) {
650 /** See the documentation included with the photos_search() function.
651 * I'm using the same style of arguments for this function. The only
652 * difference here is that this doesn't require any arguments. The
653 * flickr.photos.search method requires at least one search parameter.
655 /** http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */
656 if (is_null($args)) {
657 $args = array();
659 $this->request("flickr.photos.getWithoutGeoData", $args);
660 return $this->parsed_response ? $this->parsed_response['photos'] : false;
663 function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
665 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
666 if (is_array($extras)) {
667 $extras = implode(",", $extras);
669 $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
670 return $this->parsed_response ? $this->parsed_response['photos'] : false;
673 function photos_removeTag($tag_id)
675 /** http://www.flickr.com/services/api/flickr.photos.removeTag.html */
676 $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE);
677 return $this->parsed_response ? true : false;
680 function photos_search($args)
682 /** This function strays from the method of arguments that I've
683 * used in the other functions for the fact that there are just
684 * so many arguments to this API method. What you'll need to do
685 * is pass an associative array to the function containing the
686 * arguments you want to pass to the API. For example:
687 * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any"));
688 * This will return photos tagged with either "brown" or "cow"
689 * or both. See the API documentation (link below) for a full
690 * list of arguments.
693 /** http://www.flickr.com/services/api/flickr.photos.search.html */
694 $this->request("flickr.photos.search", $args);
695 return $this->parsed_response ? $this->parsed_response['photos'] : false;
698 function photos_setContentType ($photo_id, $content_type) {
699 /** http://www.flickr.com/services/api/flickr.photos.setContentType.html */
700 return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type));
703 function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL)
705 /** http://www.flickr.com/services/api/flickr.photos.setDates.html */
706 $this->request("flickr.photos.setDates", array("photo_id"=>$photo_id, "date_posted"=>$date_posted, "date_taken"=>$date_taken, "date_taken_granularity"=>$date_taken_granularity), TRUE);
707 return $this->parsed_response ? true : false;
710 function photos_setMeta($photo_id, $title, $description)
712 /** http://www.flickr.com/services/api/flickr.photos.setMeta.html */
713 $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE);
714 return $this->parsed_response ? true : false;
717 function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta)
719 /** http://www.flickr.com/services/api/flickr.photos.setPerms.html */
720 $this->request("flickr.photos.setPerms", array("photo_id"=>$photo_id, "is_public"=>$is_public, "is_friend"=>$is_friend, "is_family"=>$is_family, "perm_comment"=>$perm_comment, "perm_addmeta"=>$perm_addmeta), TRUE);
721 return $this->parsed_response ? true : false;
724 function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) {
725 /** http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */
726 return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden));
730 function photos_setTags($photo_id, $tags)
732 /** http://www.flickr.com/services/api/flickr.photos.setTags.html */
733 $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
734 return $this->parsed_response ? true : false;
737 /** Photos - Comments Methods */
738 function photos_comments_addComment($photo_id, $comment_text) {
739 /** http://www.flickr.com/services/api/flickr.photos.comments.addComment.html */
740 $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE);
741 return $this->parsed_response ? $this->parsed_response['comment'] : false;
744 function photos_comments_deleteComment($comment_id) {
745 /** http://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */
746 $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
747 return $this->parsed_response ? true : false;
750 function photos_comments_editComment($comment_id, $comment_text) {
751 /** http://www.flickr.com/services/api/flickr.photos.comments.editComment.html */
752 $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
753 return $this->parsed_response ? true : false;
756 function photos_comments_getList($photo_id)
758 /** http://www.flickr.com/services/api/flickr.photos.comments.getList.html */
759 $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id));
760 return $this->parsed_response ? $this->parsed_response['comments'] : false;
763 /** Photos - Geo Methods */
764 function photos_geo_getLocation($photo_id)
766 /** http://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */
767 $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id));
768 return $this->parsed_response ? $this->parsed_response['photo'] : false;
771 function photos_geo_getPerms($photo_id)
773 /** http://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */
774 $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id));
775 return $this->parsed_response ? $this->parsed_response['perms'] : false;
778 function photos_geo_removeLocation($photo_id)
780 /** http://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */
781 $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE);
782 return $this->parsed_response ? true : false;
785 function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL)
787 /** http://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */
788 $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE);
789 return $this->parsed_response ? true : false;
792 function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family)
794 /** http://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */
795 $this->request("flickr.photos.geo.setPerms", array("photo_id"=>$photo_id, "is_public"=>$is_public, "is_contact"=>$is_contact, "is_friend"=>$is_friend, "is_family"=>$is_family), TRUE);
796 return $this->parsed_response ? true : false;
799 /** Photos - Licenses Methods */
800 function photos_licenses_getInfo()
802 /** http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */
803 $this->request("flickr.photos.licenses.getInfo");
804 return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false;
807 function photos_licenses_setLicense($photo_id, $license_id)
809 /** http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */
810 /** Requires Authentication */
811 $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE);
812 return $this->parsed_response ? true : false;
815 /** Photos - Notes Methods */
816 function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text)
818 /** http://www.flickr.com/services/api/flickr.photos.notes.add.html */
819 $this->request("flickr.photos.notes.add", array("photo_id" => $photo_id, "note_x" => $note_x, "note_y" => $note_y, "note_w" => $note_w, "note_h" => $note_h, "note_text" => $note_text), TRUE);
820 return $this->parsed_response ? $this->parsed_response['note'] : false;
823 function photos_notes_delete($note_id)
825 /** http://www.flickr.com/services/api/flickr.photos.notes.delete.html */
826 $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE);
827 return $this->parsed_response ? true : false;
830 function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text)
832 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
833 $this->request("flickr.photos.notes.edit", array("note_id" => $note_id, "note_x" => $note_x, "note_y" => $note_y, "note_w" => $note_w, "note_h" => $note_h, "note_text" => $note_text), TRUE);
834 return $this->parsed_response ? true : false;
837 /** Photos - Transform Methods */
838 function photos_transform_rotate($photo_id, $degrees)
840 /** http://www.flickr.com/services/api/flickr.photos.transform.rotate.html */
841 $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE);
842 return $this->parsed_response ? true : false;
845 /** Photos - Upload Methods */
846 function photos_upload_checkTickets($tickets)
848 /** http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */
849 if (is_array($tickets)) {
850 $tickets = implode(",", $tickets);
852 $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE);
853 return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false;
856 /** Photosets Methods */
857 function photosets_addPhoto($photoset_id, $photo_id)
859 /** http://www.flickr.com/services/api/flickr.photosets.addPhoto.html */
860 $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
861 return $this->parsed_response ? true : false;
864 function photosets_create($title, $description, $primary_photo_id)
866 /** http://www.flickr.com/services/api/flickr.photosets.create.html */
867 $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE);
868 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
871 function photosets_delete($photoset_id)
873 /** http://www.flickr.com/services/api/flickr.photosets.delete.html */
874 $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE);
875 return $this->parsed_response ? true : false;
878 function photosets_editMeta($photoset_id, $title, $description = NULL)
880 /** http://www.flickr.com/services/api/flickr.photosets.editMeta.html */
881 $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE);
882 return $this->parsed_response ? true : false;
885 function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids)
887 /** http://www.flickr.com/services/api/flickr.photosets.editPhotos.html */
888 $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE);
889 return $this->parsed_response ? true : false;
892 function photosets_getContext($photo_id, $photoset_id)
894 /** http://www.flickr.com/services/api/flickr.photosets.getContext.html */
895 $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id));
896 return $this->parsed_response ? $this->parsed_response : false;
899 function photosets_getInfo($photoset_id)
901 /** http://www.flickr.com/services/api/flickr.photosets.getInfo.html */
902 $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id));
903 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
906 function photosets_getList($user_id = NULL)
908 /** http://www.flickr.com/services/api/flickr.photosets.getList.html */
909 $this->request("flickr.photosets.getList", array("user_id" => $user_id));
910 return $this->parsed_response ? $this->parsed_response['photosets'] : false;
913 function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL)
915 /** http://www.flickr.com/services/api/flickr.photosets.getPhotos.html */
916 $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page));
917 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
920 function photosets_orderSets($photoset_ids)
922 /** http://www.flickr.com/services/api/flickr.photosets.orderSets.html */
923 if (is_array($photoset_ids)) {
924 $photoset_ids = implode(",", $photoset_ids);
926 $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE);
927 return $this->parsed_response ? true : false;
930 function photosets_removePhoto($photoset_id, $photo_id)
932 /** http://www.flickr.com/services/api/flickr.photosets.removePhoto.html */
933 $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
934 return $this->parsed_response ? true : false;
937 /** Photosets Comments Methods */
938 function photosets_comments_addComment($photoset_id, $comment_text) {
939 /** http://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */
940 $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE);
941 return $this->parsed_response ? $this->parsed_response['comment'] : false;
944 function photosets_comments_deleteComment($comment_id) {
945 /** http://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */
946 $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
947 return $this->parsed_response ? true : false;
950 function photosets_comments_editComment($comment_id, $comment_text) {
951 /** http://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */
952 $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
953 return $this->parsed_response ? true : false;
956 function photosets_comments_getList($photoset_id)
958 /** http://www.flickr.com/services/api/flickr.photosets.comments.getList.html */
959 $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id));
960 return $this->parsed_response ? $this->parsed_response['comments'] : false;
963 /** Places Methods */
964 function places_resolvePlaceId ($place_id) {
965 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */
966 $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id));
967 return $rsp ? $rsp['location'] : $rsp;
970 function places_resolvePlaceURL ($url) {
971 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */
972 $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url));
973 return $rsp ? $rsp['location'] : $rsp;
976 /** Prefs Methods */
977 function prefs_getContentType () {
978 /** http://www.flickr.com/services/api/flickr.prefs.getContentType.html */
979 $rsp = $this->call('flickr.prefs.getContentType', array());
980 return $rsp ? $rsp['person'] : $rsp;
983 function prefs_getHidden () {
984 /** http://www.flickr.com/services/api/flickr.prefs.getHidden.html */
985 $rsp = $this->call('flickr.prefs.getHidden', array());
986 return $rsp ? $rsp['person'] : $rsp;
989 function prefs_getPrivacy () {
990 /** http://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */
991 $rsp = $this->call('flickr.prefs.getPrivacy', array());
992 return $rsp ? $rsp['person'] : $rsp;
995 function prefs_getSafetyLevel () {
996 /** http://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */
997 $rsp = $this->call('flickr.prefs.getSafetyLevel', array());
998 return $rsp ? $rsp['person'] : $rsp;
1001 /** Reflection Methods */
1002 function reflection_getMethodInfo($method_name)
1004 /** http://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */
1005 $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name));
1006 return $this->parsed_response ? $this->parsed_response : false;
1009 function reflection_getMethods()
1011 /** http://www.flickr.com/services/api/flickr.reflection.getMethods.html */
1012 $this->request("flickr.reflection.getMethods");
1013 return $this->parsed_response ? $this->parsed_response['methods']['method'] : false;
1016 /** Tags Methods */
1017 function tags_getHotList($period = NULL, $count = NULL)
1019 /** http://www.flickr.com/services/api/flickr.tags.getHotList.html */
1020 $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count));
1021 return $this->parsed_response ? $this->parsed_response['hottags'] : false;
1024 function tags_getListPhoto($photo_id)
1026 /** http://www.flickr.com/services/api/flickr.tags.getListPhoto.html */
1027 $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id));
1028 return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false;
1031 function tags_getListUser($user_id = NULL)
1033 /** http://www.flickr.com/services/api/flickr.tags.getListUser.html */
1034 $this->request("flickr.tags.getListUser", array("user_id" => $user_id));
1035 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1038 function tags_getListUserPopular($user_id = NULL, $count = NULL)
1040 /** http://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */
1041 $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count));
1042 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1045 function tags_getListUserRaw($tag)
1047 /** http://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */
1048 $this->request("flickr.tags.getListUserRaw", array("tag" => $tag));
1049 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false;
1052 function tags_getRelated($tag)
1054 /** http://www.flickr.com/services/api/flickr.tags.getRelated.html */
1055 $this->request("flickr.tags.getRelated", array("tag" => $tag));
1056 return $this->parsed_response ? $this->parsed_response['tags'] : false;
1059 function test_echo($args = array())
1061 /** http://www.flickr.com/services/api/flickr.test.echo.html */
1062 $this->request("flickr.test.echo", $args);
1063 return $this->parsed_response ? $this->parsed_response : false;
1066 function test_login()
1068 /** http://www.flickr.com/services/api/flickr.test.login.html */
1069 $this->request("flickr.test.login");
1070 return $this->parsed_response ? $this->parsed_response['user'] : false;
1073 function urls_getGroup($group_id)
1075 /** http://www.flickr.com/services/api/flickr.urls.getGroup.html */
1076 $this->request("flickr.urls.getGroup", array("group_id"=>$group_id));
1077 return $this->parsed_response ? $this->parsed_response['group']['url'] : false;
1080 function urls_getUserPhotos($user_id = NULL)
1082 /** http://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */
1083 $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id));
1084 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1087 function urls_getUserProfile($user_id = NULL)
1089 /** http://www.flickr.com/services/api/flickr.urls.getUserProfile.html */
1090 $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id));
1091 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1094 function urls_lookupGroup($url)
1096 /** http://www.flickr.com/services/api/flickr.urls.lookupGroup.html */
1097 $this->request("flickr.urls.lookupGroup", array("url"=>$url));
1098 return $this->parsed_response ? $this->parsed_response['group'] : false;
1101 function urls_lookupUser($url)
1103 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
1104 $this->request("flickr.urls.lookupUser", array("url"=>$url));
1105 return $this->parsed_response ? $this->parsed_response['user'] : false;
1109 * Upload a photo from Moodle file pool to Flickr
1111 * Optional meta information are title, description, tags, is_public, is_friend, is_family, safety_level,
1112 * content_type and hidden {@see http://www.flickr.com/services/api/upload.api.html}
1114 * @param stored_file $photo stored in Moodle file pool
1115 * @param array $meta optional meta information
1116 * @return boolean
1118 function upload(stored_file $photo, array $meta = array()) {
1120 $args = array();
1122 $args['title'] = isset($meta['title']) ? $meta['title'] : null;
1123 $args['description'] = isset($meta['description']) ? $meta['description'] : null;
1124 $args['tags'] = isset($meta['tags']) ? $meta['tags'] : null;
1125 $args['is_public'] = isset($meta['is_public']) ? $meta['is_public'] : 0;
1126 $args['is_friend'] = isset($meta['is_friend']) ? $meta['is_friend'] : 0;
1127 $args['is_family'] = isset($meta['is_family']) ? $meta['is_family'] : 0;
1128 $args['safety_level'] = isset($meta['safety_level']) ? $meta['safety_level'] : 1; // safe by default
1129 $args['content_type'] = isset($meta['content_type']) ? $meta['content_type'] : 1; // photo by default
1130 $args['hidden'] = isset($meta['hidden']) ? $meta['hidden'] : 2; // hide from public searches by default
1132 // Do not enable the asynchronous more because then the query does not return a photo ID,
1133 // and we need a photo ID to add the photo to a set later on.
1134 // $args['async'] = 1;
1135 $args['api_key'] = $this->api_key;
1137 if (!empty($this->email)) {
1138 $args['email'] = $this->email;
1140 if (!empty($this->password)) {
1141 $args['password'] = $this->password;
1143 if (!empty($this->token)) {
1144 $args['auth_token'] = $this->token;
1147 // sign the arguments using the shared secret
1148 ksort($args);
1149 $auth_sig = '';
1150 foreach ($args as $key => $data) {
1151 if (!is_null($data)) {
1152 $auth_sig .= $key . $data;
1153 } else {
1154 unset($args[$key]);
1157 if (!empty($this->secret)) {
1158 $api_sig = md5($this->secret . $auth_sig);
1159 $args['api_sig'] = $api_sig;
1162 $args['photo'] = $photo; // $this->curl will process it correctly
1164 if ($response = $this->curl->post($this->Upload, $args)) {
1165 $xml = simplexml_load_string($response);
1166 if ($xml['stat'] == 'fail') {
1167 $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'],
1168 'message' => (string) $xml->err['msg']);
1169 } elseif ($xml['stat'] == 'ok') {
1170 $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid);
1172 return true;
1173 } else {
1174 $this->parsed_response = array('stat' => 'fail', 'code' => $this->curl->get_errno(),
1175 'message' => $this->curl->error);
1176 return false;