MDL-31627: Arialist theme do not resize content when there are no blocks
[moodle.git] / lib / flickrlib.php
blob534cf35dadcafce1d25c937f5f2503cbf22ff359
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 = 'http://api.flickr.com/services/rest/';
42 var $Upload = 'http://api.flickr.com/services/upload/';
43 var $Replace = 'http://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 global $FULLME;
244 // Redirects to Flickr's authentication piece if there is no valid token.
245 // If remember_uri is set to false, the callback script (included) will
246 // redirect to its default page.
247 if ($remember_uri) {
248 $redirect = $FULLME;
250 $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms);
251 $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" . $perms . '&api_sig='. $api_sig;
252 return $url;
256 * To use the phpFlickr::call method, pass a string containing the API method you want
257 * to use and an associative array of arguments. For example:
258 * $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612'));
259 * This method will allow you to make calls to arbitrary methods that haven't been
260 * implemented in phpFlickr yet.
263 function call($method, $arguments)
265 $this->request($method, $arguments);
266 return $this->parsed_response ? $this->parsed_response : false;
270 * These functions are the direct implementations of flickr calls.
271 * For method documentation, including arguments, visit the address
272 * included in a comment in the function.
275 /** Activity methods */
276 function activity_userComments ($per_page = NULL, $page = NULL)
278 /** http://www.flickr.com/services/api/flickr.activity.userComments.html */
279 $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page));
280 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
283 function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL)
285 /** http://www.flickr.com/services/api/flickr.activity.userPhotos.html */
286 $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page));
287 return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
290 /** Authentication methods */
291 function auth_checkToken ()
293 /** http://www.flickr.com/services/api/flickr.auth.checkToken.html */
294 $this->request('flickr.auth.checkToken');
295 return $this->parsed_response ? $this->parsed_response['auth'] : false;
298 function auth_getFrob ()
300 /** http://www.flickr.com/services/api/flickr.auth.getFrob.html */
301 $this->request('flickr.auth.getFrob');
302 return $this->parsed_response ? $this->parsed_response['frob'] : false;
305 function auth_getFullToken ($mini_token)
307 /** http://www.flickr.com/services/api/flickr.auth.getFullToken.html */
308 $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token));
309 return $this->parsed_response ? $this->parsed_response['auth'] : false;
312 function auth_getToken ($frob)
314 /** http://www.flickr.com/services/api/flickr.auth.getToken.html */
315 $this->request('flickr.auth.getToken', array('frob'=>$frob));
316 $this->token = $this->parsed_response['auth']['token'];
317 return $this->parsed_response ? $this->parsed_response['auth'] : false;
320 /** Blogs methods */
321 function blogs_getList ()
323 /** http://www.flickr.com/services/api/flickr.blogs.getList.html */
324 $this->request('flickr.blogs.getList');
325 return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false;
328 function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL)
330 /** http://www.flickr.com/services/api/flickr.blogs.postPhoto.html */
331 $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE);
332 return $this->parsed_response ? true : false;
335 /** Contacts Methods */
336 function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL)
338 /** http://www.flickr.com/services/api/flickr.contacts.getList.html */
339 $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page));
340 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
343 function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL)
345 /** http://www.flickr.com/services/api/flickr.contacts.getPublicList.html */
346 $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page));
347 return $this->parsed_response ? $this->parsed_response['contacts'] : false;
350 /** Favorites Methods */
351 function favorites_add ($photo_id)
353 /** http://www.flickr.com/services/api/flickr.favorites.add.html */
354 $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE);
355 return $this->parsed_response ? true : false;
358 function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
360 /** http://www.flickr.com/services/api/flickr.favorites.getList.html */
361 if (is_array($extras)) { $extras = implode(",", $extras); }
362 $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
363 return $this->parsed_response ? $this->parsed_response['photos'] : false;
366 function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
368 /** http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */
369 if (is_array($extras)) {
370 $extras = implode(",", $extras);
372 $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
373 return $this->parsed_response ? $this->parsed_response['photos'] : false;
376 function favorites_remove($photo_id)
378 /** http://www.flickr.com/services/api/flickr.favorites.remove.html */
379 $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE);
380 return $this->parsed_response ? true : false;
383 /** Groups Methods */
384 function groups_browse ($cat_id = NULL)
386 /** http://www.flickr.com/services/api/flickr.groups.browse.html */
387 $this->request("flickr.groups.browse", array("cat_id"=>$cat_id));
388 return $this->parsed_response ? $this->parsed_response['category'] : false;
391 function groups_getInfo ($group_id)
393 /** http://www.flickr.com/services/api/flickr.groups.getInfo.html */
394 $this->request("flickr.groups.getInfo", array("group_id"=>$group_id));
395 return $this->parsed_response ? $this->parsed_response['group'] : false;
398 function groups_search ($text, $per_page=NULL, $page=NULL)
400 /** http://www.flickr.com/services/api/flickr.groups.search.html */
401 $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page));
402 return $this->parsed_response ? $this->parsed_response['groups'] : false;
405 /** Groups Pools Methods */
406 function groups_pools_add ($photo_id, $group_id)
408 /** http://www.flickr.com/services/api/flickr.groups.pools.add.html */
409 $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
410 return $this->parsed_response ? true : false;
413 function groups_pools_getContext ($photo_id, $group_id)
415 /** http://www.flickr.com/services/api/flickr.groups.pools.getContext.html */
416 $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id));
417 return $this->parsed_response ? $this->parsed_response : false;
420 function groups_pools_getGroups ($page = NULL, $per_page = NULL)
422 /** http://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */
423 $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page));
424 return $this->parsed_response ? $this->parsed_response['groups'] : false;
427 function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
429 /** http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */
430 if (is_array($extras)) {
431 $extras = implode(",", $extras);
433 $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));
434 return $this->parsed_response ? $this->parsed_response['photos'] : false;
437 function groups_pools_remove ($photo_id, $group_id)
439 /** http://www.flickr.com/services/api/flickr.groups.pools.remove.html */
440 $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
441 return $this->parsed_response ? true : false;
444 /** Interestingness methods */
445 function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
447 /** http://www.flickr.com/services/api/flickr.interestingness.getList.html */
448 if (is_array($extras)) {
449 $extras = implode(",", $extras);
452 $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
453 return $this->parsed_response ? $this->parsed_response['photos'] : false;
456 /** People methods */
457 function people_findByEmail ($find_email)
459 /** http://www.flickr.com/services/api/flickr.people.findByEmail.html */
460 $this->request("flickr.people.findByEmail", array("find_email"=>$find_email));
461 return $this->parsed_response ? $this->parsed_response['user'] : false;
464 function people_findByUsername ($username)
466 /** http://www.flickr.com/services/api/flickr.people.findByUsername.html */
467 $this->request("flickr.people.findByUsername", array("username"=>$username));
468 return $this->parsed_response ? $this->parsed_response['user'] : false;
471 function people_getInfo($user_id)
473 /** http://www.flickr.com/services/api/flickr.people.getInfo.html */
474 $this->request("flickr.people.getInfo", array("user_id"=>$user_id));
475 return $this->parsed_response ? $this->parsed_response['person'] : false;
478 function people_getPublicGroups($user_id)
480 /** http://www.flickr.com/services/api/flickr.people.getPublicGroups.html */
481 $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id));
482 return $this->parsed_response ? $this->parsed_response['groups']['group'] : false;
485 function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) {
486 /** http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */
487 if (is_array($extras)) {
488 $extras = implode(",", $extras);
491 $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
492 return $this->parsed_response ? $this->parsed_response['photos'] : false;
495 function people_getUploadStatus()
497 /** http://www.flickr.com/services/api/flickr.people.getUploadStatus.html */
498 /** Requires Authentication */
499 $this->request("flickr.people.getUploadStatus");
500 return $this->parsed_response ? $this->parsed_response['user'] : false;
504 /** Photos Methods */
505 function photos_addTags ($photo_id, $tags)
507 /** http://www.flickr.com/services/api/flickr.photos.addTags.html */
508 $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
509 return $this->parsed_response ? true : false;
512 function photos_delete($photo_id)
514 /** http://www.flickr.com/services/api/flickr.photos.delete.html */
515 $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE);
516 return $this->parsed_response ? true : false;
519 function photos_getAllContexts ($photo_id)
521 /** http://www.flickr.com/services/api/flickr.photos.getAllContexts.html */
522 $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id));
523 return $this->parsed_response ? $this->parsed_response : false;
526 function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
528 /** http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */
529 $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
530 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
533 function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
535 /** http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */
536 $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));
537 return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
540 function photos_getContext ($photo_id)
542 /** http://www.flickr.com/services/api/flickr.photos.getContext.html */
543 $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id));
544 return $this->parsed_response ? $this->parsed_response : false;
547 function photos_getCounts ($dates = NULL, $taken_dates = NULL)
549 /** http://www.flickr.com/services/api/flickr.photos.getCounts.html */
550 $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates));
551 return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false;
554 function photos_getExif ($photo_id, $secret = NULL)
556 /** http://www.flickr.com/services/api/flickr.photos.getExif.html */
557 $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret));
558 return $this->parsed_response ? $this->parsed_response['photo'] : false;
561 function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL)
563 /** http://www.flickr.com/services/api/flickr.photos.getFavorites.html */
564 $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page));
565 return $this->parsed_response ? $this->parsed_response['photo'] : false;
568 function photos_getInfo($photo_id, $secret = NULL)
570 /** http://www.flickr.com/services/api/flickr.photos.getInfo.html */
571 $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret));
572 return $this->parsed_response ? $this->parsed_response['photo'] : false;
575 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)
577 /** http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */
578 if (is_array($extras)) {
579 $extras = implode(",", $extras);
581 $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));
582 return $this->parsed_response ? $this->parsed_response['photos'] : false;
585 function photos_getPerms($photo_id)
587 /** http://www.flickr.com/services/api/flickr.photos.getPerms.html */
588 $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id));
589 return $this->parsed_response ? $this->parsed_response['perms'] : false;
592 function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL)
594 /** http://www.flickr.com/services/api/flickr.photos.getRecent.html */
596 if (is_array($extras)) {
597 $extras = implode(",", $extras);
599 $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
600 return $this->parsed_response ? $this->parsed_response['photos'] : false;
603 function photos_getSizes($photo_id)
605 /** http://www.flickr.com/services/api/flickr.photos.getSizes.html */
606 $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id));
607 return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false;
610 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)
612 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
613 if (is_array($extras)) {
614 $extras = implode(",", $extras);
616 $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));
617 return $this->parsed_response ? $this->parsed_response['photos'] : false;
620 function photos_getWithGeoData($args = NULL) {
621 /** See the documentation included with the photos_search() function.
622 * I'm using the same style of arguments for this function. The only
623 * difference here is that this doesn't require any arguments. The
624 * flickr.photos.search method requires at least one search parameter.
626 /** http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */
627 if (is_null($args)) {
628 $args = array();
630 $this->request("flickr.photos.getWithGeoData", $args);
631 return $this->parsed_response ? $this->parsed_response['photos'] : false;
634 function photos_getWithoutGeoData($args = NULL) {
635 /** See the documentation included with the photos_search() function.
636 * I'm using the same style of arguments for this function. The only
637 * difference here is that this doesn't require any arguments. The
638 * flickr.photos.search method requires at least one search parameter.
640 /** http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */
641 if (is_null($args)) {
642 $args = array();
644 $this->request("flickr.photos.getWithoutGeoData", $args);
645 return $this->parsed_response ? $this->parsed_response['photos'] : false;
648 function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
650 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */
651 if (is_array($extras)) {
652 $extras = implode(",", $extras);
654 $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
655 return $this->parsed_response ? $this->parsed_response['photos'] : false;
658 function photos_removeTag($tag_id)
660 /** http://www.flickr.com/services/api/flickr.photos.removeTag.html */
661 $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE);
662 return $this->parsed_response ? true : false;
665 function photos_search($args)
667 /** This function strays from the method of arguments that I've
668 * used in the other functions for the fact that there are just
669 * so many arguments to this API method. What you'll need to do
670 * is pass an associative array to the function containing the
671 * arguments you want to pass to the API. For example:
672 * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any"));
673 * This will return photos tagged with either "brown" or "cow"
674 * or both. See the API documentation (link below) for a full
675 * list of arguments.
678 /** http://www.flickr.com/services/api/flickr.photos.search.html */
679 $this->request("flickr.photos.search", $args);
680 return $this->parsed_response ? $this->parsed_response['photos'] : false;
683 function photos_setContentType ($photo_id, $content_type) {
684 /** http://www.flickr.com/services/api/flickr.photos.setContentType.html */
685 return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type));
688 function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL)
690 /** http://www.flickr.com/services/api/flickr.photos.setDates.html */
691 $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);
692 return $this->parsed_response ? true : false;
695 function photos_setMeta($photo_id, $title, $description)
697 /** http://www.flickr.com/services/api/flickr.photos.setMeta.html */
698 $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE);
699 return $this->parsed_response ? true : false;
702 function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta)
704 /** http://www.flickr.com/services/api/flickr.photos.setPerms.html */
705 $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);
706 return $this->parsed_response ? true : false;
709 function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) {
710 /** http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */
711 return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden));
715 function photos_setTags($photo_id, $tags)
717 /** http://www.flickr.com/services/api/flickr.photos.setTags.html */
718 $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
719 return $this->parsed_response ? true : false;
722 /** Photos - Comments Methods */
723 function photos_comments_addComment($photo_id, $comment_text) {
724 /** http://www.flickr.com/services/api/flickr.photos.comments.addComment.html */
725 $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE);
726 return $this->parsed_response ? $this->parsed_response['comment'] : false;
729 function photos_comments_deleteComment($comment_id) {
730 /** http://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */
731 $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
732 return $this->parsed_response ? true : false;
735 function photos_comments_editComment($comment_id, $comment_text) {
736 /** http://www.flickr.com/services/api/flickr.photos.comments.editComment.html */
737 $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
738 return $this->parsed_response ? true : false;
741 function photos_comments_getList($photo_id)
743 /** http://www.flickr.com/services/api/flickr.photos.comments.getList.html */
744 $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id));
745 return $this->parsed_response ? $this->parsed_response['comments'] : false;
748 /** Photos - Geo Methods */
749 function photos_geo_getLocation($photo_id)
751 /** http://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */
752 $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id));
753 return $this->parsed_response ? $this->parsed_response['photo'] : false;
756 function photos_geo_getPerms($photo_id)
758 /** http://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */
759 $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id));
760 return $this->parsed_response ? $this->parsed_response['perms'] : false;
763 function photos_geo_removeLocation($photo_id)
765 /** http://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */
766 $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE);
767 return $this->parsed_response ? true : false;
770 function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL)
772 /** http://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */
773 $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE);
774 return $this->parsed_response ? true : false;
777 function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family)
779 /** http://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */
780 $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);
781 return $this->parsed_response ? true : false;
784 /** Photos - Licenses Methods */
785 function photos_licenses_getInfo()
787 /** http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */
788 $this->request("flickr.photos.licenses.getInfo");
789 return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false;
792 function photos_licenses_setLicense($photo_id, $license_id)
794 /** http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */
795 /** Requires Authentication */
796 $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE);
797 return $this->parsed_response ? true : false;
800 /** Photos - Notes Methods */
801 function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text)
803 /** http://www.flickr.com/services/api/flickr.photos.notes.add.html */
804 $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);
805 return $this->parsed_response ? $this->parsed_response['note'] : false;
808 function photos_notes_delete($note_id)
810 /** http://www.flickr.com/services/api/flickr.photos.notes.delete.html */
811 $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE);
812 return $this->parsed_response ? true : false;
815 function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text)
817 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
818 $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);
819 return $this->parsed_response ? true : false;
822 /** Photos - Transform Methods */
823 function photos_transform_rotate($photo_id, $degrees)
825 /** http://www.flickr.com/services/api/flickr.photos.transform.rotate.html */
826 $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE);
827 return $this->parsed_response ? true : false;
830 /** Photos - Upload Methods */
831 function photos_upload_checkTickets($tickets)
833 /** http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */
834 if (is_array($tickets)) {
835 $tickets = implode(",", $tickets);
837 $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE);
838 return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false;
841 /** Photosets Methods */
842 function photosets_addPhoto($photoset_id, $photo_id)
844 /** http://www.flickr.com/services/api/flickr.photosets.addPhoto.html */
845 $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
846 return $this->parsed_response ? true : false;
849 function photosets_create($title, $description, $primary_photo_id)
851 /** http://www.flickr.com/services/api/flickr.photosets.create.html */
852 $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE);
853 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
856 function photosets_delete($photoset_id)
858 /** http://www.flickr.com/services/api/flickr.photosets.delete.html */
859 $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE);
860 return $this->parsed_response ? true : false;
863 function photosets_editMeta($photoset_id, $title, $description = NULL)
865 /** http://www.flickr.com/services/api/flickr.photosets.editMeta.html */
866 $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE);
867 return $this->parsed_response ? true : false;
870 function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids)
872 /** http://www.flickr.com/services/api/flickr.photosets.editPhotos.html */
873 $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE);
874 return $this->parsed_response ? true : false;
877 function photosets_getContext($photo_id, $photoset_id)
879 /** http://www.flickr.com/services/api/flickr.photosets.getContext.html */
880 $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id));
881 return $this->parsed_response ? $this->parsed_response : false;
884 function photosets_getInfo($photoset_id)
886 /** http://www.flickr.com/services/api/flickr.photosets.getInfo.html */
887 $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id));
888 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
891 function photosets_getList($user_id = NULL)
893 /** http://www.flickr.com/services/api/flickr.photosets.getList.html */
894 $this->request("flickr.photosets.getList", array("user_id" => $user_id));
895 return $this->parsed_response ? $this->parsed_response['photosets'] : false;
898 function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL)
900 /** http://www.flickr.com/services/api/flickr.photosets.getPhotos.html */
901 $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page));
902 return $this->parsed_response ? $this->parsed_response['photoset'] : false;
905 function photosets_orderSets($photoset_ids)
907 /** http://www.flickr.com/services/api/flickr.photosets.orderSets.html */
908 if (is_array($photoset_ids)) {
909 $photoset_ids = implode(",", $photoset_ids);
911 $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE);
912 return $this->parsed_response ? true : false;
915 function photosets_removePhoto($photoset_id, $photo_id)
917 /** http://www.flickr.com/services/api/flickr.photosets.removePhoto.html */
918 $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
919 return $this->parsed_response ? true : false;
922 /** Photosets Comments Methods */
923 function photosets_comments_addComment($photoset_id, $comment_text) {
924 /** http://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */
925 $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE);
926 return $this->parsed_response ? $this->parsed_response['comment'] : false;
929 function photosets_comments_deleteComment($comment_id) {
930 /** http://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */
931 $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
932 return $this->parsed_response ? true : false;
935 function photosets_comments_editComment($comment_id, $comment_text) {
936 /** http://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */
937 $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
938 return $this->parsed_response ? true : false;
941 function photosets_comments_getList($photoset_id)
943 /** http://www.flickr.com/services/api/flickr.photosets.comments.getList.html */
944 $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id));
945 return $this->parsed_response ? $this->parsed_response['comments'] : false;
948 /** Places Methods */
949 function places_resolvePlaceId ($place_id) {
950 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */
951 $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id));
952 return $rsp ? $rsp['location'] : $rsp;
955 function places_resolvePlaceURL ($url) {
956 /** http://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */
957 $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url));
958 return $rsp ? $rsp['location'] : $rsp;
961 /** Prefs Methods */
962 function prefs_getContentType () {
963 /** http://www.flickr.com/services/api/flickr.prefs.getContentType.html */
964 $rsp = $this->call('flickr.prefs.getContentType', array());
965 return $rsp ? $rsp['person'] : $rsp;
968 function prefs_getHidden () {
969 /** http://www.flickr.com/services/api/flickr.prefs.getHidden.html */
970 $rsp = $this->call('flickr.prefs.getHidden', array());
971 return $rsp ? $rsp['person'] : $rsp;
974 function prefs_getPrivacy () {
975 /** http://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */
976 $rsp = $this->call('flickr.prefs.getPrivacy', array());
977 return $rsp ? $rsp['person'] : $rsp;
980 function prefs_getSafetyLevel () {
981 /** http://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */
982 $rsp = $this->call('flickr.prefs.getSafetyLevel', array());
983 return $rsp ? $rsp['person'] : $rsp;
986 /** Reflection Methods */
987 function reflection_getMethodInfo($method_name)
989 /** http://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */
990 $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name));
991 return $this->parsed_response ? $this->parsed_response : false;
994 function reflection_getMethods()
996 /** http://www.flickr.com/services/api/flickr.reflection.getMethods.html */
997 $this->request("flickr.reflection.getMethods");
998 return $this->parsed_response ? $this->parsed_response['methods']['method'] : false;
1001 /** Tags Methods */
1002 function tags_getHotList($period = NULL, $count = NULL)
1004 /** http://www.flickr.com/services/api/flickr.tags.getHotList.html */
1005 $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count));
1006 return $this->parsed_response ? $this->parsed_response['hottags'] : false;
1009 function tags_getListPhoto($photo_id)
1011 /** http://www.flickr.com/services/api/flickr.tags.getListPhoto.html */
1012 $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id));
1013 return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false;
1016 function tags_getListUser($user_id = NULL)
1018 /** http://www.flickr.com/services/api/flickr.tags.getListUser.html */
1019 $this->request("flickr.tags.getListUser", array("user_id" => $user_id));
1020 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1023 function tags_getListUserPopular($user_id = NULL, $count = NULL)
1025 /** http://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */
1026 $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count));
1027 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
1030 function tags_getListUserRaw($tag)
1032 /** http://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */
1033 $this->request("flickr.tags.getListUserRaw", array("tag" => $tag));
1034 return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false;
1037 function tags_getRelated($tag)
1039 /** http://www.flickr.com/services/api/flickr.tags.getRelated.html */
1040 $this->request("flickr.tags.getRelated", array("tag" => $tag));
1041 return $this->parsed_response ? $this->parsed_response['tags'] : false;
1044 function test_echo($args = array())
1046 /** http://www.flickr.com/services/api/flickr.test.echo.html */
1047 $this->request("flickr.test.echo", $args);
1048 return $this->parsed_response ? $this->parsed_response : false;
1051 function test_login()
1053 /** http://www.flickr.com/services/api/flickr.test.login.html */
1054 $this->request("flickr.test.login");
1055 return $this->parsed_response ? $this->parsed_response['user'] : false;
1058 function urls_getGroup($group_id)
1060 /** http://www.flickr.com/services/api/flickr.urls.getGroup.html */
1061 $this->request("flickr.urls.getGroup", array("group_id"=>$group_id));
1062 return $this->parsed_response ? $this->parsed_response['group']['url'] : false;
1065 function urls_getUserPhotos($user_id = NULL)
1067 /** http://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */
1068 $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id));
1069 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1072 function urls_getUserProfile($user_id = NULL)
1074 /** http://www.flickr.com/services/api/flickr.urls.getUserProfile.html */
1075 $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id));
1076 return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
1079 function urls_lookupGroup($url)
1081 /** http://www.flickr.com/services/api/flickr.urls.lookupGroup.html */
1082 $this->request("flickr.urls.lookupGroup", array("url"=>$url));
1083 return $this->parsed_response ? $this->parsed_response['group'] : false;
1086 function urls_lookupUser($url)
1088 /** http://www.flickr.com/services/api/flickr.photos.notes.edit.html */
1089 $this->request("flickr.urls.lookupUser", array("url"=>$url));
1090 return $this->parsed_response ? $this->parsed_response['user'] : false;
1094 * Upload a photo from Moodle file pool to Flickr
1096 * Optional meta information are title, description, tags, is_public, is_friend, is_family, safety_level,
1097 * content_type and hidden {@see http://www.flickr.com/services/api/upload.api.html}
1099 * @param stored_file $photo stored in Moodle file pool
1100 * @param array $meta optional meta information
1101 * @return boolean
1103 function upload(stored_file $photo, array $meta = array()) {
1105 $args = array();
1107 $args['title'] = isset($meta['title']) ? $meta['title'] : null;
1108 $args['description'] = isset($meta['description']) ? $meta['description'] : null;
1109 $args['tags'] = isset($meta['tags']) ? $meta['tags'] : null;
1110 $args['is_public'] = isset($meta['is_public']) ? $meta['is_public'] : 0;
1111 $args['is_friend'] = isset($meta['is_friend']) ? $meta['is_friend'] : 0;
1112 $args['is_family'] = isset($meta['is_family']) ? $meta['is_family'] : 0;
1113 $args['safety_level'] = isset($meta['safety_level']) ? $meta['safety_level'] : 1; // safe by default
1114 $args['content_type'] = isset($meta['content_type']) ? $meta['content_type'] : 1; // photo by default
1115 $args['hidden'] = isset($meta['hidden']) ? $meta['hidden'] : 2; // hide from public searches by default
1117 $args['async'] = 1;
1118 $args['api_key'] = $this->api_key;
1120 if (!empty($this->email)) {
1121 $args['email'] = $this->email;
1123 if (!empty($this->password)) {
1124 $args['password'] = $this->password;
1126 if (!empty($this->token)) {
1127 $args['auth_token'] = $this->token;
1130 // sign the arguments using the shared secret
1131 ksort($args);
1132 $auth_sig = '';
1133 foreach ($args as $key => $data) {
1134 if (!is_null($data)) {
1135 $auth_sig .= $key . $data;
1136 } else {
1137 unset($args[$key]);
1140 if (!empty($this->secret)) {
1141 $api_sig = md5($this->secret . $auth_sig);
1142 $args['api_sig'] = $api_sig;
1145 $args['photo'] = $photo; // $this->curl will process it correctly
1147 if ($response = $this->curl->post($this->Upload, $args)) {
1148 return true;
1149 } else {
1150 return false;