[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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} 9 * 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} 13 * 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} 16 * 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 23 * 24 * Modified by David Mudrak <david@moodle.com> 25 * ChangeLog: 26 * 1. upload() method uses Moodle stored_file 27 * 2. upload() method supports all params provided by http://www.flickr.com/services/api/upload.api.html 28 * 29 * @package moodlecore 30 * @subpackage 3rd-party 31 */ 32 33 /** 34 * Flickr Class 35 * @package moodlecore 36 * @subpackage 3rd-party 37 */ 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; 52 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. 62 * 63 * @global object 64 */ 65 66 function __construct ($api_key, $secret = NULL, $token = '') 67 { 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')); 80 } 81 82 function request ($command, $args = array()) 83 { 84 //Sends a request to Flickr's REST endpoint via POST. 85 if (substr($command,0,7) != "flickr.") { 86 $command = "flickr." . $command; 87 } 88 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; 94 } 95 if (empty($args['is_friend'])) { 96 $args['is_friend'] = 0; 97 } 98 if (empty($args['is_family'])) { 99 $args['is_family'] = 0; 100 } 101 if (empty($args['hidden'])) { 102 $args['hidden'] = 1; 103 } 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); 116 } 117 118 if (!empty($this->token)) { 119 $args = array_merge($args, array("auth_token" => $this->token)); 120 } 121 122 ksort($args); 123 $auth_sig = ""; 124 foreach ($args as $key => $data) { 125 $auth_sig .= $key . $data; 126 } 127 128 if (!empty($this->secret)) { 129 $api_sig = md5($this->secret . $auth_sig); 130 $args['api_sig'] = $api_sig; 131 } 132 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)); 140 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; 146 } 147 } 148 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; 155 } 156 } else { 157 $this->error_code = false; 158 $this->error_msg = false; 159 } 160 return $this->response; 161 } 162 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); 173 } 174 return($arr); 175 } 176 } 177 178 function setToken($token) 179 { 180 // Sets an authentication token to use instead of the session variable 181 $this->token = $token; 182 } 183 184 function setProxy($server, $port) 185 { 186 // Sets the proxy for all phpFlickr calls. 187 //$this->req->setProxy($server, $port); 188 } 189 190 function getErrorCode() 191 { 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; 195 } 196 197 function getErrorMsg() 198 { 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; 202 } 203 204 /** These functions are front ends for the flickr calls */ 205 206 function buildPhotoURL ($photo, $size = "Medium") 207 { 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" 218 ); 219 220 $size = strtolower($size); 221 if (!array_key_exists($size, $sizes)) { 222 $size = "medium"; 223 } 224 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"; 229 } 230 return $url; 231 } 232 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. 237 */ 238 return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon)); 239 } 240 241 function auth ($perms = "write", $remember_uri = true) 242 { 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? 248 } 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; 252 } 253 254 /** 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. 260 */ 261 262 function call($method, $arguments) 263 { 264 $this->request($method, $arguments); 265 return $this->parsed_response ? $this->parsed_response : false; 266 } 267 268 /** 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. 272 */ 273 274 /** Activity methods */ 275 function activity_userComments ($per_page = NULL, $page = NULL) 276 { 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; 280 } 281 282 function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL) 283 { 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; 287 } 288 289 /** Authentication methods */ 290 function auth_checkToken () 291 { 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; 295 } 296 297 function auth_getFrob () 298 { 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; 302 } 303 304 function auth_getFullToken ($mini_token) 305 { 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; 309 } 310 311 function auth_getToken ($frob) 312 { 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; 317 } 318 319 /** Blogs methods */ 320 function blogs_getList () 321 { 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; 325 } 326 327 function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL) 328 { 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; 332 } 333 334 /** Contacts Methods */ 335 function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL) 336 { 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; 340 } 341 342 function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL) 343 { 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; 347 } 348 349 /** Favorites Methods */ 350 function favorites_add ($photo_id) 351 { 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; 355 } 356 357 function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) 358 { 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; 363 } 364 365 function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) 366 { 367 /** http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */ 368 if (is_array($extras)) { 369 $extras = implode(",", $extras); 370 } 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; 373 } 374 375 function favorites_remove($photo_id) 376 { 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; 380 } 381 382 /** Groups Methods */ 383 function groups_browse ($cat_id = NULL) 384 { 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; 388 } 389 390 function groups_getInfo ($group_id) 391 { 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; 395 } 396 397 function groups_search ($text, $per_page=NULL, $page=NULL) 398 { 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; 402 } 403 404 /** Groups Pools Methods */ 405 function groups_pools_add ($photo_id, $group_id) 406 { 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; 410 } 411 412 function groups_pools_getContext ($photo_id, $group_id) 413 { 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; 417 } 418 419 function groups_pools_getGroups ($page = NULL, $per_page = NULL) 420 { 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; 424 } 425 426 function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) 427 { 428 /** http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */ 429 if (is_array($extras)) { 430 $extras = implode(",", $extras); 431 } 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; 434 } 435 436 function groups_pools_remove ($photo_id, $group_id) 437 { 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; 441 } 442 443 /** Interestingness methods */ 444 function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) 445 { 446 /** http://www.flickr.com/services/api/flickr.interestingness.getList.html */ 447 if (is_array($extras)) { 448 $extras = implode(",", $extras); 449 } 450 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; 453 } 454 455 /** People methods */ 456 function people_findByEmail ($find_email) 457 { 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; 461 } 462 463 function people_findByUsername ($username) 464 { 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; 468 } 469 470 function people_getInfo($user_id) 471 { 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; 475 } 476 477 function people_getPublicGroups($user_id) 478 { 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; 482 } 483 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); 488 } 489 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; 492 } 493 494 function people_getUploadStatus() 495 { 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; 500 } 501 502 503 /** Photos Methods */ 504 function photos_addTags ($photo_id, $tags) 505 { 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; 509 } 510 511 function photos_delete($photo_id) 512 { 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; 516 } 517 518 function photos_getAllContexts ($photo_id) 519 { 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; 523 } 524 525 function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) 526 { 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; 530 } 531 532 function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) 533 { 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; 537 } 538 539 function photos_getContext ($photo_id) 540 { 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; 544 } 545 546 function photos_getCounts ($dates = NULL, $taken_dates = NULL) 547 { 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; 551 } 552 553 function photos_getExif ($photo_id, $secret = NULL) 554 { 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; 558 } 559 560 function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL) 561 { 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; 565 } 566 567 function photos_getInfo($photo_id, $secret = NULL) 568 { 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; 572 } 573 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) 575 { 576 /** http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */ 577 if (is_array($extras)) { 578 $extras = implode(",", $extras); 579 } 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; 582 } 583 584 function photos_getPerms($photo_id) 585 { 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; 589 } 590 591 function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL) 592 { 593 /** http://www.flickr.com/services/api/flickr.photos.getRecent.html */ 594 595 if (is_array($extras)) { 596 $extras = implode(",", $extras); 597 } 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; 600 } 601 602 function photos_getSizes($photo_id) 603 { 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; 607 } 608 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) 610 { 611 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ 612 if (is_array($extras)) { 613 $extras = implode(",", $extras); 614 } 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; 617 } 618 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. 624 */ 625 /** http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */ 626 if (is_null($args)) { 627 $args = array(); 628 } 629 $this->request("flickr.photos.getWithGeoData", $args); 630 return $this->parsed_response ? $this->parsed_response['photos'] : false; 631 } 632 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. 638 */ 639 /** http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */ 640 if (is_null($args)) { 641 $args = array(); 642 } 643 $this->request("flickr.photos.getWithoutGeoData", $args); 644 return $this->parsed_response ? $this->parsed_response['photos'] : false; 645 } 646 647 function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) 648 { 649 /** http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ 650 if (is_array($extras)) { 651 $extras = implode(",", $extras); 652 } 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; 655 } 656 657 function photos_removeTag($tag_id) 658 { 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; 662 } 663 664 function photos_search($args) 665 { 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. 675 */ 676 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; 680 } 681 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)); 685 } 686 687 function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL) 688 { 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; 692 } 693 694 function photos_setMeta($photo_id, $title, $description) 695 { 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; 699 } 700 701 function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta) 702 { 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; 706 } 707 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)); 711 } 712 713 714 function photos_setTags($photo_id, $tags) 715 { 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; 719 } 720 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; 726 } 727 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; 732 } 733 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; 738 } 739 740 function photos_comments_getList($photo_id) 741 { 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; 745 } 746 747 /** Photos - Geo Methods */ 748 function photos_geo_getLocation($photo_id) 749 { 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; 753 } 754 755 function photos_geo_getPerms($photo_id) 756 { 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; 760 } 761 762 function photos_geo_removeLocation($photo_id) 763 { 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; 767 } 768 769 function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL) 770 { 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; 774 } 775 776 function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family) 777 { 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; 781 } 782 783 /** Photos - Licenses Methods */ 784 function photos_licenses_getInfo() 785 { 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; 789 } 790 791 function photos_licenses_setLicense($photo_id, $license_id) 792 { 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; 797 } 798 799 /** Photos - Notes Methods */ 800 function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text) 801 { 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; 805 } 806 807 function photos_notes_delete($note_id) 808 { 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; 812 } 813 814 function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text) 815 { 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; 819 } 820 821 /** Photos - Transform Methods */ 822 function photos_transform_rotate($photo_id, $degrees) 823 { 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; 827 } 828 829 /** Photos - Upload Methods */ 830 function photos_upload_checkTickets($tickets) 831 { 832 /** http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */ 833 if (is_array($tickets)) { 834 $tickets = implode(",", $tickets); 835 } 836 $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE); 837 return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false; 838 } 839 840 /** Photosets Methods */ 841 function photosets_addPhoto($photoset_id, $photo_id) 842 { 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; 846 } 847 848 function photosets_create($title, $description, $primary_photo_id) 849 { 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; 853 } 854 855 function photosets_delete($photoset_id) 856 { 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; 860 } 861 862 function photosets_editMeta($photoset_id, $title, $description = NULL) 863 { 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; 867 } 868 869 function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids) 870 { 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; 874 } 875 876 function photosets_getContext($photo_id, $photoset_id) 877 { 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; 881 } 882 883 function photosets_getInfo($photoset_id) 884 { 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; 888 } 889 890 function photosets_getList($user_id = NULL) 891 { 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; 895 } 896 897 function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL) 898 { 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; 902 } 903 904 function photosets_orderSets($photoset_ids) 905 { 906 /** http://www.flickr.com/services/api/flickr.photosets.orderSets.html */ 907 if (is_array($photoset_ids)) { 908 $photoset_ids = implode(",", $photoset_ids); 909 } 910 $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE); 911 return $this->parsed_response ? true : false; 912 } 913 914 function photosets_removePhoto($photoset_id, $photo_id) 915 { 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; 919 } 920 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; 926 } 927 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; 932 } 933 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; 938 } 939 940 function photosets_comments_getList($photoset_id) 941 { 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; 945 } 946 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; 952 } 953 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; 958 } 959 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; 965 } 966 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; 971 } 972 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; 977 } 978 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; 983 } 984 985 /** Reflection Methods */ 986 function reflection_getMethodInfo($method_name) 987 { 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; 991 } 992 993 function reflection_getMethods() 994 { 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; 998 } 999 1000 /** Tags Methods */ 1001 function tags_getHotList($period = NULL, $count = NULL) 1002 { 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; 1006 } 1007 1008 function tags_getListPhoto($photo_id) 1009 { 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; 1013 } 1014 1015 function tags_getListUser($user_id = NULL) 1016 { 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; 1020 } 1021 1022 function tags_getListUserPopular($user_id = NULL, $count = NULL) 1023 { 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; 1027 } 1028 1029 function tags_getListUserRaw($tag) 1030 { 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; 1034 } 1035 1036 function tags_getRelated($tag) 1037 { 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; 1041 } 1042 1043 function test_echo($args = array()) 1044 { 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; 1048 } 1049 1050 function test_login() 1051 { 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; 1055 } 1056 1057 function urls_getGroup($group_id) 1058 { 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; 1062 } 1063 1064 function urls_getUserPhotos($user_id = NULL) 1065 { 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; 1069 } 1070 1071 function urls_getUserProfile($user_id = NULL) 1072 { 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; 1076 } 1077 1078 function urls_lookupGroup($url) 1079 { 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; 1083 } 1084 1085 function urls_lookupUser($url) 1086 { 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; 1090 } 1091 1092 /** 1093 * Upload a photo from Moodle file pool to Flickr 1094 * 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} 1097 * 1098 * @param stored_file $photo stored in Moodle file pool 1099 * @param array $meta optional meta information 1100 * @return boolean 1101 */ 1102 function upload(stored_file $photo, array $meta = array()) { 1103 1104 $args = array(); 1105 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 1115 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; 1120 1121 if (!empty($this->email)) { 1122 $args['email'] = $this->email; 1123 } 1124 if (!empty($this->password)) { 1125 $args['password'] = $this->password; 1126 } 1127 if (!empty($this->token)) { 1128 $args['auth_token'] = $this->token; 1129 } 1130 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]); 1139 } 1140 } 1141 if (!empty($this->secret)) { 1142 $api_sig = md5($this->secret . $auth_sig); 1143 $args['api_sig'] = $api_sig; 1144 } 1145 1146 $args['photo'] = $photo; // $this->curl will process it correctly 1147 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); 1155 } 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; 1161 } 1162 } 1163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |