Merge branch 'wip-mdl-50675-m28' of https://github.com/rajeshtaneja/moodle into MOODL...
[moodle.git] / lib / flickrlib.php
blob997cdd0656d73bad8291ac1dd0cd9ca05e3df429
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
29 * @package moodlecore
30 * @subpackage 3rd-party
33 /**
34 * Flickr Class
35 * @package moodlecore
36 * @subpackage 3rd-party
38 class phpFlickr {
39 var $api_key;
40 var $secret;
41 var $REST = 'https://api.flickr.com/services/rest/';
42 var $Upload = 'https://api.flickr.com/services/upload/';
43 var $Replace = 'https://api.flickr.com/services/replace/';
44 var $req;
45 var $response;
46 var $parsed_response;
47 var $die_on_error;
48 var $error_code;
49 var $error_msg;
50 var $token;
51 var $php_version;
53 /**
54 * When your database cache table hits this many rows, a cleanup
55 * will occur to get rid of all of the old rows and cleanup the
56 * garbage in the table. For most personal apps, 1000 rows should
57 * be more than enough. If your site gets hit by a lot of traffic
58 * or you have a lot of disk space to spare, bump this number up.
59 * You should try to set it high enough that the cleanup only
60 * happens every once in a while, so this will depend on the growth
61 * of your table.
63 * @global object
66 function __construct ($api_key, $secret = NULL, $token = '')
68 global $CFG;
69 //The API Key must be set before any calls can be made. You can
70 //get your own at http://www.flickr.com/services/api/misc.api_keys.html
71 $this->api_key = $api_key;
72 $this->secret = $secret;
73 $this->die_on_error = false;
74 $this->service = "flickr";
75 $this->token = $token;
76 //Find the PHP version and store it for future reference
77 $this->php_version = explode("-", phpversion());
78 $this->php_version = explode(".", $this->php_version[0]);
79 $this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
82 function request ($command, $args = array())
84 //Sends a request to Flickr's REST endpoint via POST.
85 if (substr($command,0,7) != "flickr.") {
86 $command = "flickr." . $command;
89 //Process arguments, including method and login data.
90 if ($command == 'flickr.upload') {
91 $photo = $args['photo'];
92 if (empty($args['is_public'])) {
93 $args['is_public'] = 0;
95 if (empty($args['is_friend'])) {
96 $args['is_friend'] = 0;
98 if (empty($args['is_family'])) {
99 $args['is_family'] = 0;
101 if (empty($args['hidden'])) {
102 $args['hidden'] = 1;
104 $args = array("api_key" => $this->api_key,
105 "title" => $args['title'],
106 "description" => $args['description'],
107 "tags" => $args['tags'],
108 "is_public" => $args['is_public'],
109 "is_friend" => $args['is_friend'],
110 "is_family" => $args['is_family'],
111 "safety_level" => $args['safety_level'],
112 "content_type" => $args['content_type'],
113 "hidden" => $args['hidden']);
114 } else {
115 $args = array_merge(array("method" => $command, "format" => "php_serial", "api_key" => $this->api_key), $args);
118 if (!empty($this->token)) {
119 $args = array_merge($args, array("auth_token" => $this->token));
122 ksort($args);
123 $auth_sig = "";
124 foreach ($args as $key => $data) {
125 $auth_sig .= $key . $data;
128 if (!empty($this->secret)) {
129 $api_sig = md5($this->secret . $auth_sig);
130 $args['api_sig'] = $api_sig;
133 //$this->req->addHeader("Connection", "Keep-Alive");
134 if ($command != 'flickr.upload') {
135 $ret = $this->curl->post($this->REST, $args);
136 $this->parsed_response = $this->clean_text_nodes(unserialize($ret));
137 } else {
138 $args['photo'] = $photo;
139 $xml = simplexml_load_string($this->curl->post($this->Upload, $args));
141 if ($xml['stat'] == 'fail') {
142 $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'], 'message' => (string) $xml->err['msg']);
143 } elseif ($xml['stat'] == 'ok') {
144 $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid);
145 $this->response = true;
149 if ($this->parsed_response['stat'] == 'fail') {
150 if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
151 else {
152 $this->error_code = $this->parsed_response['code'];
153 $this->error_msg = $this->parsed_response['message'];
154 $this->parsed_response = false;
156 } else {
157 $this->error_code = false;
158 $this->error_msg = false;
160 return $this->response;
163 function clean_text_nodes($arr) {
164 if (!is_array($arr)) {
165 return $arr;
166 } elseif (count($arr) == 0) {
167 return $arr;
168 } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) {
169 return $arr['_content'];
170 } else {
171 foreach ($arr as $key => $element) {
172 $arr[$key] = $this->clean_text_nodes($element);
174 return($arr);
178 function setToken($token)
180 // Sets an authentication token to use instead of the session variable
181 $this->token = $token;
184 function setProxy($server, $port)
186 // Sets the proxy for all phpFlickr calls.
187 //$this->req->setProxy($server, $port);
190 function getErrorCode()
192 // Returns the error code of the last call. If the last call did not
193 // return an error. This will return a false boolean.
194 return $this->error_code;
197 function getErrorMsg()
199 // Returns the error message of the last call. If the last call did not
200 // return an error. This will return a false boolean.
201 return $this->error_msg;
204 /** These functions are front ends for the flickr calls */
206 function buildPhotoURL ($photo, $size = "Medium")
208 //receives an array (can use the individual photo data returned
209 //from an API call) and returns a URL (doesn't mean that the
210 //file size exists)
211 $sizes = array(
212 "square" => "_s",
213 "thumbnail" => "_t",
214 "small" => "_m",
215 "medium" => "",
216 "large" => "_b",
217 "original" => "_o"
220 $size = strtolower($size);
221 if (!array_key_exists($size, $sizes)) {
222 $size = "medium";
225 if ($size == "original") {
226 $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat'];
227 } else {
228 $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg";
230 return $url;
233 function getFriendlyGeodata($lat, $lon) {
234 /** I've added this method to get the friendly geodata (i.e. 'in New York, NY') that the
235 * website provides, but isn't available in the API. I'm providing this service as long
236 * as it doesn't flood my server with requests and crash it all the time.
238 return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon));
241 function auth ($perms = "write", $remember_uri = true)
243 // Redirects to Flickr's authentication piece if there is no valid token.
244 // If remember_uri is set to false, the callback script (included) will
245 // redirect to its default page.
246 if ($remember_uri) {
247 $redirect = qualified_me(); // TODO: this is not used, why?
249 $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms);
250 $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" . $perms . '&api_sig='. $api_sig;
251 return $url;
255 * To use the phpFlickr::call method, pass a string containing the API method you want
256 * to use and an associative array of arguments. For example:
257 * $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612'));
258 * This method will allow you to make calls to arbitrary methods that haven't been
259 * implemented in phpFlickr yet.
262 function call($method, $arguments)
264 $this->request($method, $arguments);
265 return $this->parsed_response ? $this->parsed_response : false;
269 * These functions are the direct implementations of flickr calls.
270 * For method documentation, including arguments, visit the address
271 * included in a comment in the function.
274 /** Activity methods */
275 function activity_userComments ($per_page = NULL, $page = NULL)
277 /** http://www.flickr.com/services/api/flickr.activity.userComments.html */
278 $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page));
279 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
282 function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL)
284 /** http://www.flickr.com/services/api/flickr.activity.userPhotos.html */
285 $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page));
286 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
289 /** Authentication methods */
290 function auth_checkToken ()
292 /** http://www.flickr.com/services/api/flickr.auth.checkToken.html */
293 $this->request('flickr.auth.checkToken');
294 return $this->parsed_response ? $this->parsed_response['auth'] : false;
297 function auth_getFrob ()
299 /** http://www.flickr.com/services/api/flickr.auth.getFrob.html */
300 $this->request('flickr.auth.getFrob');
301 return $this->parsed_response ? $this->parsed_response['frob'] : false;
304 function auth_getFullToken ($mini_token)
306 /** http://www.flickr.com/services/api/flickr.auth.getFullToken.html */
307 $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token));
308 return $this->parsed_response ? $this->parsed_response['auth'] : false;
311 function auth_getToken ($frob)
313 /** http://www.flickr.com/services/api/flickr.auth.getToken.html */
314 $this->request('flickr.auth.getToken', array('frob'=>$frob));
315 $this->token = $this->parsed_response['auth']['token'];
316 return $this->parsed_response ? $this->parsed_response['auth'] : false;
319 /** Blogs methods */
320 function blogs_getList ()
322 /** http://www.flickr.com/services/api/flickr.blogs.getList.html */
323 $this->request('flickr.blogs.getList');
324 return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false;
327 function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL)
329 /** http://www.flickr.com/services/api/flickr.blogs.postPhoto.html */
330 $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE);
331 return $this->parsed_response ? true : false;
334 /** Contacts Methods */
335 function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL)
337 /** http://www.flickr.com/services/api/flickr.contacts.getList.html */
338 $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page));
339 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
342 function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL)
344 /** http://www.flickr.com/services/api/flickr.contacts.getPublicList.html */
345 $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page));
346 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
349 /** Favorites Methods */
350 function favorites_add ($photo_id)
352 /** http://www.flickr.com/services/api/flickr.favorites.add.html */
353 $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE);
354 return $this->parsed_response ? true : false;
357 function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
359 /** http://www.flickr.com/services/api/flickr.favorites.getList.html */
360 if (is_array($extras)) { $extras = implode(",", $extras); }
361 $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
362 return $this->parsed_response ? $this->parsed_response['photos'] : false;
365 function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
367 /** http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */
368 if (is_array($extras)) {
369 $extras = implode(",", $extras);
371 $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
372 return $this->parsed_response ? $this->parsed_response['photos'] : false;
375 function favorites_remove($photo_id)
377 /** http://www.flickr.com/services/api/flickr.favorites.remove.html */
378 $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE);
379 return $this->parsed_response ? true : false;
382 /** Groups Methods */
383 function groups_browse ($cat_id = NULL)
385 /** http://www.flickr.com/services/api/flickr.groups.browse.html */
386 $this->request("flickr.groups.browse", array("cat_id"=>$cat_id));
387 return $this->parsed_response ? $this->parsed_response['category'] : false;
390 function groups_getInfo ($group_id)
392 /** http://www.flickr.com/services/api/flickr.groups.getInfo.html */
393 $this->request("flickr.groups.getInfo", array("group_id"=>$group_id));
394 return $this->parsed_response ? $this->parsed_response['group'] : false;
397 function groups_search ($text, $per_page=NULL, $page=NULL)
399 /** http://www.flickr.com/services/api/flickr.groups.search.html */
400 $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page));
401 return $this->parsed_response ? $this->parsed_response['groups'] : false;
404 /** Groups Pools Methods */
405 function groups_pools_add ($photo_id, $group_id)
407 /** http://www.flickr.com/services/api/flickr.groups.pools.add.html */
408 $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
409 return $this->parsed_response ? true : false;
412 function groups_pools_getContext ($photo_id, $group_id)
414 /** http://www.flickr.com/services/api/flickr.groups.pools.getContext.html */
415 $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id));
416 return $this->parsed_response ? $this->parsed_response : false;
419 function groups_pools_getGroups ($page = NULL, $per_page = NULL)
421 /** http://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */
422 $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page));
423 return $this->parsed_response ? $this->parsed_response['groups'] : false;
426 function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
428 /** http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */
429 if (is_array($extras)) {
430 $extras = implode(",", $extras);
432 $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));
433 return $this->parsed_response ? $this->parsed_response['photos'] : false;
436 function groups_pools_remove ($photo_id, $group_id)
438 /** http://www.flickr.com/services/api/flickr.groups.pools.remove.html */
439 $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
440 return $this->parsed_response ? true : false;
443 /** Interestingness methods */
444 function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
446 /** http://www.flickr.com/services/api/flickr.interestingness.getList.html */
447 if (is_array($extras)) {
448 $extras = implode(",", $extras);
451 $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
452 return $this->parsed_response ? $this->parsed_response['photos'] : false;
455 /** People methods */
456 function people_findByEmail ($find_email)
458 /** http://www.flickr.com/services/api/flickr.people.findByEmail.html */
459 $this->request("flickr.people.findByEmail", array("find_email"=>$find_email));
460 return $this->parsed_response ? $this->parsed_response['user'] : false;
463 function people_findByUsername ($username)
465 /** http://www.flickr.com/services/api/flickr.people.findByUsername.html */
466 $this->request("flickr.people.findByUsername", array("username"=>$username));
467 return $this->parsed_response ? $this->parsed_response['user'] : false;
470 function people_getInfo($user_id)
472 /** http://www.flickr.com/services/api/flickr.people.getInfo.html */
473 $this->request("flickr.people.getInfo", array("user_id"=>$user_id));
474 return $this->parsed_response ? $this->parsed_response['person'] : false;
477 function people_getPublicGroups($user_id)
479 /** http://www.flickr.com/services/api/flickr.people.getPublicGroups.html */
480 $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id));
481 return $this->parsed_response ? $this->parsed_response['groups']['group'] : false;
484 function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) {
485 /** http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */
486 if (is_array($extras)) {
487 $extras = implode(",", $extras);
490 $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
491 return $this->parsed_response ? $this->parsed_response['photos'] : false;
494 function people_getUploadStatus()
496 /** http://www.flickr.com/services/api/flickr.people.getUploadStatus.html */
497 /** Requires Authentication */
498 $this->request("flickr.people.getUploadStatus");
499 return $this->parsed_response ? $this->parsed_response['user'] : false;
503 /** Photos Methods */
504 function photos_addTags ($photo_id, $tags)
506 /** http://www.flickr.com/services/api/flickr.photos.addTags.html */
507 $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
508 return $this->parsed_response ? true : false;
511 function photos_delete($photo_id)
513 /** http://www.flickr.com/services/api/flickr.photos.delete.html */
514 $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE);
515 return $this->parsed_response ? true : false;
518 function photos_getAllContexts ($photo_id)
520 /** http://www.flickr.com/services/api/flickr.photos.getAllContexts.html */
521 $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id));
522 return $this->parsed_response ? $this->parsed_response : false;
525 function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
527 /** http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */
528 $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
529 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
532 function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
534 /** http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */
535 $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));
536 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
539 function photos_getContext ($photo_id)
541 /** http://www.flickr.com/services/api/flickr.photos.getContext.html */
542 $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id));
543 return $this->parsed_response ? $this->parsed_response : false;
546 function photos_getCounts ($dates = NULL, $taken_dates = NULL)
548 /** http://www.flickr.com/services/api/flickr.photos.getCounts.html */
549 $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates));
550 return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false;
553 function photos_getExif ($photo_id, $secret = NULL)
555 /** http://www.flickr.com/services/api/flickr.photos.getExif.html */
556 $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret));
557 return $this->parsed_response ? $this->parsed_response['photo'] : false;
560 function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL)
562 /** http://www.flickr.com/services/api/flickr.photos.getFavorites.html */
563 $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page));
564 return $this->parsed_response ? $this->parsed_response['photo'] : false;
567 function photos_getInfo($photo_id, $secret = NULL)
569 /** http://www.flickr.com/services/api/flickr.photos.getInfo.html */
570 $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret));
571 return $this->parsed_response ? $this->parsed_response['photo'] : false;
574 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)
576 /** http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */
577 if (is_array($extras)) {
578 $extras = implode(",", $extras);
580 $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));
581 return $this->parsed_response ? $this->parsed_response['photos'] : false;
584 function photos_getPerms($photo_id)
586 /** http://www.flickr.com/services/api/flickr.photos.getPerms.html */
587 $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id));
588 return $this->parsed_response ? $this->parsed_response['perms'] : false;
591 function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL)
593 /** http://www.flickr.com/services/api/flickr.photos.getRecent.html */
595 if (is_array($extras)) {
596 $extras = implode(",", $extras);
598 $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
599 return $this->parsed_response ? $this->parsed_response['photos'] : false;
602 function photos_getSizes($photo_id)
604 /** http://www.flickr.com/services/api/flickr.photos.getSizes.html */
605 $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id));
606 return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false;
609 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)
611 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
612 if (is_array($extras)) {
613 $extras = implode(",", $extras);
615 $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));
616 return $this->parsed_response ? $this->parsed_response['photos'] : false;
619 function photos_getWithGeoData($args = NULL) {
620 /** See the documentation included with the photos_search() function.
621 * I'm using the same style of arguments for this function. The only
622 * difference here is that this doesn't require any arguments. The
623 * flickr.photos.search method requires at least one search parameter.
625 /** http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */
626 if (is_null($args)) {
627 $args = array();
629 $this->request("flickr.photos.getWithGeoData", $args);
630 return $this->parsed_response ? $this->parsed_response['photos'] : false;
633 function photos_getWithoutGeoData($args = NULL) {
634 /** See the documentation included with the photos_search() function.
635 * I'm using the same style of arguments for this function. The only
636 * difference here is that this doesn't require any arguments. The
637 * flickr.photos.search method requires at least one search parameter.
639 /** http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */
640 if (is_null($args)) {
641 $args = array();
643 $this->request("flickr.photos.getWithoutGeoData", $args);
644 return $this->parsed_response ? $this->parsed_response['photos'] : false;
647 function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
649 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
650 if (is_array($extras)) {
651 $extras = implode(",", $extras);
653 $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
654 return $this->parsed_response ? $this->parsed_response['photos'] : false;
657 function photos_removeTag($tag_id)
659 /** http://www.flickr.com/services/api/flickr.photos.removeTag.html */
660 $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE);
661 return $this->parsed_response ? true : false;
664 function photos_search($args)
666 /** This function strays from the method of arguments that I've
667 * used in the other functions for the fact that there are just
668 * so many arguments to this API method. What you'll need to do
669 * is pass an associative array to the function containing the
670 * arguments you want to pass to the API. For example:
671 * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any"));
672 * This will return photos tagged with either "brown" or "cow"
673 * or both. See the API documentation (link below) for a full
674 * list of arguments.
677 /** http://www.flickr.com/services/api/flickr.photos.search.html */
678 $this->request("flickr.photos.search", $args);
679 return $this->parsed_response ? $this->parsed_response['photos'] : false;
682 function photos_setContentType ($photo_id, $content_type) {
683 /** http://www.flickr.com/services/api/flickr.photos.setContentType.html */
684 return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type));
687 function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL)
689 /** http://www.flickr.com/services/api/flickr.photos.setDates.html */
690 $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);
691 return $this->parsed_response ? true : false;
694 function photos_setMeta($photo_id, $title, $description)
696 /** http://www.flickr.com/services/api/flickr.photos.setMeta.html */
697 $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE);
698 return $this->parsed_response ? true : false;
701 function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta)
703 /** http://www.flickr.com/services/api/flickr.photos.setPerms.html */
704 $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);
705 return $this->parsed_response ? true : false;
708 function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) {
709 /** http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */
710 return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden));
714 function photos_setTags($photo_id, $tags)
716 /** http://www.flickr.com/services/api/flickr.photos.setTags.html */
717 $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
718 return $this->parsed_response ? true : false;
721 /** Photos - Comments Methods */
722 function photos_comments_addComment($photo_id, $comment_text) {
723 /** http://www.flickr.com/services/api/flickr.photos.comments.addComment.html */
724 $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE);
725 return $this->parsed_response ? $this->parsed_response['comment'] : false;
728 function photos_comments_deleteComment($comment_id) {
729 /** http://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */
730 $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
731 return $this->parsed_response ? true : false;
734 function photos_comments_editComment($comment_id, $comment_text) {
735 /** http://www.flickr.com/services/api/flickr.photos.comments.editComment.html */
736 $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
737 return $this->parsed_response ? true : false;
740 function photos_comments_getList($photo_id)
742 /** http://www.flickr.com/services/api/flickr.photos.comments.getList.html */
743 $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id));
744 return $this->parsed_response ? $this->parsed_response['comments'] : false;
747 /** Photos - Geo Methods */
748 function photos_geo_getLocation($photo_id)
750 /** http://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */
751 $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id));
752 return $this->parsed_response ? $this->parsed_response['photo'] : false;
755 function photos_geo_getPerms($photo_id)
757 /** http://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */
758 $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id));
759 return $this->parsed_response ? $this->parsed_response['perms'] : false;
762 function photos_geo_removeLocation($photo_id)
764 /** http://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */
765 $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE);
766 return $this->parsed_response ? true : false;
769 function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL)
771 /** http://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */
772 $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE);
773 return $this->parsed_response ? true : false;
776 function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family)
778 /** http://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */
779 $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);
780 return $this->parsed_response ? true : false;
783 /** Photos - Licenses Methods */
784 function photos_licenses_getInfo()
786 /** http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */
787 $this->request("flickr.photos.licenses.getInfo");
788 return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false;
791 function photos_licenses_setLicense($photo_id, $license_id)
793 /** http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */
794 /** Requires Authentication */
795 $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE);
796 return $this->parsed_response ? true : false;
799 /** Photos - Notes Methods */
800 function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text)
802 /** http://www.flickr.com/services/api/flickr.photos.notes.add.html */
803 $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);
804 return $this->parsed_response ? $this->parsed_response['note'] : false;
807 function photos_notes_delete($note_id)
809 /** http://www.flickr.com/services/api/flickr.photos.notes.delete.html */
810 $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE);
811 return $this->parsed_response ? true : false;
814 function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text)
816 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
817 $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);
818 return $this->parsed_response ? true : false;
821 /** Photos - Transform Methods */
822 function photos_transform_rotate($photo_id, $degrees)
824 /** http://www.flickr.com/services/api/flickr.photos.transform.rotate.html */
825 $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE);
826 return $this->parsed_response ? true : false;
829 /** Photos - Upload Methods */
830 function photos_upload_checkTickets($tickets)
832 /** http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */
833 if (is_array($tickets)) {
834 $tickets = implode(",", $tickets);
836 $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE);
837 return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false;
840 /** Photosets Methods */
841 function photosets_addPhoto($photoset_id, $photo_id)
843 /** http://www.flickr.com/services/api/flickr.photosets.addPhoto.html */
844 $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
845 return $this->parsed_response ? true : false;
848 function photosets_create($title, $description, $primary_photo_id)
850 /** http://www.flickr.com/services/api/flickr.photosets.create.html */
851 $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE);
852 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
855 function photosets_delete($photoset_id)
857 /** http://www.flickr.com/services/api/flickr.photosets.delete.html */
858 $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE);
859 return $this->parsed_response ? true : false;
862 function photosets_editMeta($photoset_id, $title, $description = NULL)
864 /** http://www.flickr.com/services/api/flickr.photosets.editMeta.html */
865 $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE);
866 return $this->parsed_response ? true : false;
869 function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids)
871 /** http://www.flickr.com/services/api/flickr.photosets.editPhotos.html */
872 $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE);
873 return $this->parsed_response ? true : false;
876 function photosets_getContext($photo_id, $photoset_id)
878 /** http://www.flickr.com/services/api/flickr.photosets.getContext.html */
879 $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id));
880 return $this->parsed_response ? $this->parsed_response : false;
883 function photosets_getInfo($photoset_id)
885 /** http://www.flickr.com/services/api/flickr.photosets.getInfo.html */
886 $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id));
887 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
890 function photosets_getList($user_id = NULL)
892 /** http://www.flickr.com/services/api/flickr.photosets.getList.html */
893 $this->request("flickr.photosets.getList", array("user_id" => $user_id));
894 return $this->parsed_response ? $this->parsed_response['photosets'] : false;
897 function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL)
899 /** http://www.flickr.com/services/api/flickr.photosets.getPhotos.html */
900 $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page));
901 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
904 function photosets_orderSets($photoset_ids)
906 /** http://www.flickr.com/services/api/flickr.photosets.orderSets.html */
907 if (is_array($photoset_ids)) {
908 $photoset_ids = implode(",", $photoset_ids);
910 $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE);
911 return $this->parsed_response ? true : false;
914 function photosets_removePhoto($photoset_id, $photo_id)
916 /** http://www.flickr.com/services/api/flickr.photosets.removePhoto.html */
917 $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
918 return $this->parsed_response ? true : false;
921 /** Photosets Comments Methods */
922 function photosets_comments_addComment($photoset_id, $comment_text) {
923 /** http://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */
924 $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE);
925 return $this->parsed_response ? $this->parsed_response['comment'] : false;
928 function photosets_comments_deleteComment($comment_id) {
929 /** http://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */
930 $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
931 return $this->parsed_response ? true : false;
934 function photosets_comments_editComment($comment_id, $comment_text) {
935 /** http://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */
936 $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
937 return $this->parsed_response ? true : false;
940 function photosets_comments_getList($photoset_id)
942 /** http://www.flickr.com/services/api/flickr.photosets.comments.getList.html */
943 $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id));
944 return $this->parsed_response ? $this->parsed_response['comments'] : false;
947 /** Places Methods */
948 function places_resolvePlaceId ($place_id) {
949 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */
950 $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id));
951 return $rsp ? $rsp['location'] : $rsp;
954 function places_resolvePlaceURL ($url) {
955 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */
956 $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url));
957 return $rsp ? $rsp['location'] : $rsp;
960 /** Prefs Methods */
961 function prefs_getContentType () {
962 /** http://www.flickr.com/services/api/flickr.prefs.getContentType.html */
963 $rsp = $this->call('flickr.prefs.getContentType', array());
964 return $rsp ? $rsp['person'] : $rsp;
967 function prefs_getHidden () {
968 /** http://www.flickr.com/services/api/flickr.prefs.getHidden.html */
969 $rsp = $this->call('flickr.prefs.getHidden', array());
970 return $rsp ? $rsp['person'] : $rsp;
973 function prefs_getPrivacy () {
974 /** http://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */
975 $rsp = $this->call('flickr.prefs.getPrivacy', array());
976 return $rsp ? $rsp['person'] : $rsp;
979 function prefs_getSafetyLevel () {
980 /** http://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */
981 $rsp = $this->call('flickr.prefs.getSafetyLevel', array());
982 return $rsp ? $rsp['person'] : $rsp;
985 /** Reflection Methods */
986 function reflection_getMethodInfo($method_name)
988 /** http://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */
989 $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name));
990 return $this->parsed_response ? $this->parsed_response : false;
993 function reflection_getMethods()
995 /** http://www.flickr.com/services/api/flickr.reflection.getMethods.html */
996 $this->request("flickr.reflection.getMethods");
997 return $this->parsed_response ? $this->parsed_response['methods']['method'] : false;
1000 /** Tags Methods */
1001 function tags_getHotList($period = NULL, $count = NULL)
1003 /** http://www.flickr.com/services/api/flickr.tags.getHotList.html */
1004 $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count));
1005 return $this->parsed_response ? $this->parsed_response['hottags'] : false;
1008 function tags_getListPhoto($photo_id)
1010 /** http://www.flickr.com/services/api/flickr.tags.getListPhoto.html */
1011 $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id));
1012 return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false;
1015 function tags_getListUser($user_id = NULL)
1017 /** http://www.flickr.com/services/api/flickr.tags.getListUser.html */
1018 $this->request("flickr.tags.getListUser", array("user_id" => $user_id));
1019 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1022 function tags_getListUserPopular($user_id = NULL, $count = NULL)
1024 /** http://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */
1025 $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count));
1026 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1029 function tags_getListUserRaw($tag)
1031 /** http://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */
1032 $this->request("flickr.tags.getListUserRaw", array("tag" => $tag));
1033 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false;
1036 function tags_getRelated($tag)
1038 /** http://www.flickr.com/services/api/flickr.tags.getRelated.html */
1039 $this->request("flickr.tags.getRelated", array("tag" => $tag));
1040 return $this->parsed_response ? $this->parsed_response['tags'] : false;
1043 function test_echo($args = array())
1045 /** http://www.flickr.com/services/api/flickr.test.echo.html */
1046 $this->request("flickr.test.echo", $args);
1047 return $this->parsed_response ? $this->parsed_response : false;
1050 function test_login()
1052 /** http://www.flickr.com/services/api/flickr.test.login.html */
1053 $this->request("flickr.test.login");
1054 return $this->parsed_response ? $this->parsed_response['user'] : false;
1057 function urls_getGroup($group_id)
1059 /** http://www.flickr.com/services/api/flickr.urls.getGroup.html */
1060 $this->request("flickr.urls.getGroup", array("group_id"=>$group_id));
1061 return $this->parsed_response ? $this->parsed_response['group']['url'] : false;
1064 function urls_getUserPhotos($user_id = NULL)
1066 /** http://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */
1067 $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id));
1068 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1071 function urls_getUserProfile($user_id = NULL)
1073 /** http://www.flickr.com/services/api/flickr.urls.getUserProfile.html */
1074 $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id));
1075 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1078 function urls_lookupGroup($url)
1080 /** http://www.flickr.com/services/api/flickr.urls.lookupGroup.html */
1081 $this->request("flickr.urls.lookupGroup", array("url"=>$url));
1082 return $this->parsed_response ? $this->parsed_response['group'] : false;
1085 function urls_lookupUser($url)
1087 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
1088 $this->request("flickr.urls.lookupUser", array("url"=>$url));
1089 return $this->parsed_response ? $this->parsed_response['user'] : false;
1093 * Upload a photo from Moodle file pool to Flickr
1095 * Optional meta information are title, description, tags, is_public, is_friend, is_family, safety_level,
1096 * content_type and hidden {@see http://www.flickr.com/services/api/upload.api.html}
1098 * @param stored_file $photo stored in Moodle file pool
1099 * @param array $meta optional meta information
1100 * @return boolean
1102 function upload(stored_file $photo, array $meta = array()) {
1104 $args = array();
1106 $args['title'] = isset($meta['title']) ? $meta['title'] : null;
1107 $args['description'] = isset($meta['description']) ? $meta['description'] : null;
1108 $args['tags'] = isset($meta['tags']) ? $meta['tags'] : null;
1109 $args['is_public'] = isset($meta['is_public']) ? $meta['is_public'] : 0;
1110 $args['is_friend'] = isset($meta['is_friend']) ? $meta['is_friend'] : 0;
1111 $args['is_family'] = isset($meta['is_family']) ? $meta['is_family'] : 0;
1112 $args['safety_level'] = isset($meta['safety_level']) ? $meta['safety_level'] : 1; // safe by default
1113 $args['content_type'] = isset($meta['content_type']) ? $meta['content_type'] : 1; // photo by default
1114 $args['hidden'] = isset($meta['hidden']) ? $meta['hidden'] : 2; // hide from public searches by default
1116 // Do not enable the asynchronous more because then the query does not return a photo ID,
1117 // and we need a photo ID to add the photo to a set later on.
1118 // $args['async'] = 1;
1119 $args['api_key'] = $this->api_key;
1121 if (!empty($this->email)) {
1122 $args['email'] = $this->email;
1124 if (!empty($this->password)) {
1125 $args['password'] = $this->password;
1127 if (!empty($this->token)) {
1128 $args['auth_token'] = $this->token;
1131 // sign the arguments using the shared secret
1132 ksort($args);
1133 $auth_sig = '';
1134 foreach ($args as $key => $data) {
1135 if (!is_null($data)) {
1136 $auth_sig .= $key . $data;
1137 } else {
1138 unset($args[$key]);
1141 if (!empty($this->secret)) {
1142 $api_sig = md5($this->secret . $auth_sig);
1143 $args['api_sig'] = $api_sig;
1146 $args['photo'] = $photo; // $this->curl will process it correctly
1148 if ($response = $this->curl->post($this->Upload, $args)) {
1149 $xml = simplexml_load_string($response);
1150 if ($xml['stat'] == 'fail') {
1151 $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'],
1152 'message' => (string) $xml->err['msg']);
1153 } elseif ($xml['stat'] == 'ok') {
1154 $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid);
1156 return true;
1157 } else {
1158 $this->parsed_response = array('stat' => 'fail', 'code' => $this->curl->get_errno(),
1159 'message' => $this->curl->error);
1160 return false;