Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/flickrlib.php
Go to the documentation of this file.
00001 <?php
00038 class phpFlickr {
00039     var $api_key;
00040     var $secret;
00041     var $REST = 'http://api.flickr.com/services/rest/';
00042     var $Upload = 'http://api.flickr.com/services/upload/';
00043     var $Replace = 'http://api.flickr.com/services/replace/';
00044     var $req;
00045     var $response;
00046     var $parsed_response;
00047     var $die_on_error;
00048     var $error_code;
00049     var $error_msg;
00050     var $token;
00051     var $php_version;
00052 
00066     function __construct ($api_key, $secret = NULL, $token = '')
00067     {
00068         global $CFG;
00069         //The API Key must be set before any calls can be made.  You can
00070         //get your own at http://www.flickr.com/services/api/misc.api_keys.html
00071         $this->api_key = $api_key;
00072         $this->secret = $secret;
00073         $this->die_on_error = false;
00074         $this->service = "flickr";
00075         $this->token = $token;
00076         //Find the PHP version and store it for future reference
00077         $this->php_version = explode("-", phpversion());
00078         $this->php_version = explode(".", $this->php_version[0]);
00079         $this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
00080     }
00081 
00082     function request ($command, $args = array())
00083     {
00084         //Sends a request to Flickr's REST endpoint via POST.
00085         if (substr($command,0,7) != "flickr.") {
00086             $command = "flickr." . $command;
00087         }
00088 
00089         //Process arguments, including method and login data.
00090         if ($command == 'flickr.upload') {
00091             $photo = $args['photo'];
00092             if (empty($args['is_public'])) {
00093                 $args['is_public'] = 0;
00094             }
00095             if (empty($args['is_friend'])) {
00096                 $args['is_friend'] = 0;
00097             }
00098             if (empty($args['is_family'])) {
00099                 $args['is_family'] = 0;
00100             }
00101             if (empty($args['hidden'])) {
00102                 $args['hidden'] = 1;
00103             }
00104             $args = array("api_key" => $this->api_key,
00105                           "title" => $args['title'],
00106                           "description" => $args['description'],
00107                           "tags" => $args['tags'],
00108                           "is_public" => $args['is_public'],
00109                           "is_friend" => $args['is_friend'],
00110                           "is_family" => $args['is_family'],
00111                           "safety_level" => $args['safety_level'],
00112                           "content_type" => $args['content_type'],
00113                           "hidden" => $args['hidden']);
00114         } else {
00115             $args = array_merge(array("method" => $command, "format" => "php_serial", "api_key" => $this->api_key), $args);
00116         }
00117 
00118         if (!empty($this->token)) {
00119             $args = array_merge($args, array("auth_token" => $this->token));
00120         }
00121 
00122         ksort($args);
00123         $auth_sig = "";
00124         foreach ($args as $key => $data) {
00125             $auth_sig .= $key . $data;
00126         }
00127 
00128         if (!empty($this->secret)) {
00129             $api_sig = md5($this->secret . $auth_sig);
00130             $args['api_sig'] = $api_sig;
00131         }
00132 
00133         //$this->req->addHeader("Connection", "Keep-Alive");
00134         if ($command != 'flickr.upload') {
00135             $ret = $this->curl->post($this->REST, $args);
00136             $this->parsed_response = $this->clean_text_nodes(unserialize($ret));
00137         } else {
00138             $args['photo'] = $photo;
00139             $xml = simplexml_load_string($this->curl->post($this->Upload, $args));
00140 
00141             if ($xml['stat'] == 'fail') {
00142                 $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'], 'message' => (string) $xml->err['msg']);
00143             } elseif ($xml['stat'] == 'ok') {
00144                 $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid);
00145                 $this->response = true;
00146             }
00147         }
00148 
00149         if ($this->parsed_response['stat'] == 'fail') {
00150             if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
00151             else {
00152                 $this->error_code = $this->parsed_response['code'];
00153                 $this->error_msg = $this->parsed_response['message'];
00154                 $this->parsed_response = false;
00155             }
00156         } else {
00157             $this->error_code = false;
00158             $this->error_msg = false;
00159         }
00160         return $this->response;
00161     }
00162 
00163     function clean_text_nodes($arr) {
00164         if (!is_array($arr)) {
00165             return $arr;
00166         } elseif (count($arr) == 0) {
00167             return $arr;
00168         } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) {
00169             return $arr['_content'];
00170         } else {
00171             foreach ($arr as $key => $element) {
00172                 $arr[$key] = $this->clean_text_nodes($element);
00173             }
00174             return($arr);
00175         }
00176     }
00177 
00178     function setToken($token)
00179     {
00180         // Sets an authentication token to use instead of the session variable
00181         $this->token = $token;
00182     }
00183 
00184     function setProxy($server, $port)
00185     {
00186         // Sets the proxy for all phpFlickr calls.
00187         //$this->req->setProxy($server, $port);
00188     }
00189 
00190     function getErrorCode()
00191     {
00192         // Returns the error code of the last call.  If the last call did not
00193         // return an error. This will return a false boolean.
00194         return $this->error_code;
00195     }
00196 
00197     function getErrorMsg()
00198     {
00199         // Returns the error message of the last call.  If the last call did not
00200         // return an error. This will return a false boolean.
00201         return $this->error_msg;
00202     }
00203 
00206     function buildPhotoURL ($photo, $size = "Medium")
00207     {
00208         //receives an array (can use the individual photo data returned
00209         //from an API call) and returns a URL (doesn't mean that the
00210         //file size exists)
00211         $sizes = array(
00212                 "square" => "_s",
00213                 "thumbnail" => "_t",
00214                 "small" => "_m",
00215                 "medium" => "",
00216                 "large" => "_b",
00217                 "original" => "_o"
00218                 );
00219 
00220         $size = strtolower($size);
00221         if (!array_key_exists($size, $sizes)) {
00222             $size = "medium";
00223         }
00224 
00225         if ($size == "original") {
00226             $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat'];
00227         } else {
00228             $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg";
00229         }
00230         return $url;
00231     }
00232 
00233     function getFriendlyGeodata($lat, $lon) {
00238         return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon));
00239     }
00240 
00241     function auth ($perms = "write", $remember_uri = true)
00242     {
00243         global $FULLME;
00244         // Redirects to Flickr's authentication piece if there is no valid token.
00245         // If remember_uri is set to false, the callback script (included) will
00246         // redirect to its default page.
00247         if ($remember_uri) {
00248             $redirect = $FULLME;
00249         }
00250         $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms);
00251         $url = 'http://www.flickr.com/services/auth/?api_key=' . $this->api_key . "&perms=" .  $perms . '&api_sig='. $api_sig;
00252         return $url;
00253     }
00254 
00263     function call($method, $arguments)
00264     {
00265         $this->request($method, $arguments);
00266         return $this->parsed_response ? $this->parsed_response : false;
00267     }
00268 
00276     function activity_userComments ($per_page = NULL, $page = NULL)
00277     {
00279         $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page));
00280         return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
00281     }
00282 
00283     function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL)
00284     {
00286         $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page));
00287         return $this->parsed_response ? $this->parsed_response['items']['item'] : false;
00288     }
00289 
00291     function auth_checkToken ()
00292     {
00294         $this->request('flickr.auth.checkToken');
00295         return $this->parsed_response ? $this->parsed_response['auth'] : false;
00296     }
00297 
00298     function auth_getFrob ()
00299     {
00301         $this->request('flickr.auth.getFrob');
00302         return $this->parsed_response ? $this->parsed_response['frob'] : false;
00303     }
00304 
00305     function auth_getFullToken ($mini_token)
00306     {
00308         $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token));
00309         return $this->parsed_response ? $this->parsed_response['auth'] : false;
00310     }
00311 
00312     function auth_getToken ($frob)
00313     {
00315         $this->request('flickr.auth.getToken', array('frob'=>$frob));
00316         $this->token = $this->parsed_response['auth']['token'];
00317         return $this->parsed_response ? $this->parsed_response['auth'] : false;
00318     }
00319 
00321     function blogs_getList ()
00322     {
00324         $this->request('flickr.blogs.getList');
00325         return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false;
00326     }
00327 
00328     function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL)
00329     {
00331         $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE);
00332         return $this->parsed_response ? true : false;
00333     }
00334 
00336     function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL)
00337     {
00339         $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page));
00340         return $this->parsed_response ? $this->parsed_response['contacts'] : false;
00341     }
00342 
00343     function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL)
00344     {
00346         $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page));
00347         return $this->parsed_response ? $this->parsed_response['contacts'] : false;
00348     }
00349 
00351     function favorites_add ($photo_id)
00352     {
00354         $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE);
00355         return $this->parsed_response ? true : false;
00356     }
00357 
00358     function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
00359     {
00361         if (is_array($extras)) { $extras = implode(",", $extras); }
00362         $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00363         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00364     }
00365 
00366     function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
00367     {
00369         if (is_array($extras)) {
00370             $extras = implode(",", $extras);
00371         }
00372         $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00373         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00374     }
00375 
00376     function favorites_remove($photo_id)
00377     {
00379         $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE);
00380         return $this->parsed_response ? true : false;
00381     }
00382 
00384     function groups_browse ($cat_id = NULL)
00385     {
00387         $this->request("flickr.groups.browse", array("cat_id"=>$cat_id));
00388         return $this->parsed_response ? $this->parsed_response['category'] : false;
00389     }
00390 
00391     function groups_getInfo ($group_id)
00392     {
00394         $this->request("flickr.groups.getInfo", array("group_id"=>$group_id));
00395         return $this->parsed_response ? $this->parsed_response['group'] : false;
00396     }
00397 
00398     function groups_search ($text, $per_page=NULL, $page=NULL)
00399     {
00401         $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page));
00402         return $this->parsed_response ? $this->parsed_response['groups'] : false;
00403     }
00404 
00406     function groups_pools_add ($photo_id, $group_id)
00407     {
00409         $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
00410         return $this->parsed_response ? true : false;
00411     }
00412 
00413     function groups_pools_getContext ($photo_id, $group_id)
00414     {
00416         $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id));
00417         return $this->parsed_response ? $this->parsed_response : false;
00418     }
00419 
00420     function groups_pools_getGroups ($page = NULL, $per_page = NULL)
00421     {
00423         $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page));
00424         return $this->parsed_response ? $this->parsed_response['groups'] : false;
00425     }
00426 
00427     function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
00428     {
00430         if (is_array($extras)) {
00431             $extras = implode(",", $extras);
00432         }
00433         $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));
00434         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00435     }
00436 
00437     function groups_pools_remove ($photo_id, $group_id)
00438     {
00440         $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE);
00441         return $this->parsed_response ? true : false;
00442     }
00443 
00445     function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
00446     {
00448         if (is_array($extras)) {
00449             $extras = implode(",", $extras);
00450         }
00451 
00452         $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00453         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00454     }
00455 
00457     function people_findByEmail ($find_email)
00458     {
00460         $this->request("flickr.people.findByEmail", array("find_email"=>$find_email));
00461         return $this->parsed_response ? $this->parsed_response['user'] : false;
00462     }
00463 
00464     function people_findByUsername ($username)
00465     {
00467         $this->request("flickr.people.findByUsername", array("username"=>$username));
00468         return $this->parsed_response ? $this->parsed_response['user'] : false;
00469     }
00470 
00471     function people_getInfo($user_id)
00472     {
00474         $this->request("flickr.people.getInfo", array("user_id"=>$user_id));
00475         return $this->parsed_response ? $this->parsed_response['person'] : false;
00476     }
00477 
00478     function people_getPublicGroups($user_id)
00479     {
00481         $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id));
00482         return $this->parsed_response ? $this->parsed_response['groups']['group'] : false;
00483     }
00484 
00485     function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) {
00487         if (is_array($extras)) {
00488             $extras = implode(",", $extras);
00489         }
00490 
00491         $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00492         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00493     }
00494 
00495     function people_getUploadStatus()
00496     {
00499         $this->request("flickr.people.getUploadStatus");
00500         return $this->parsed_response ? $this->parsed_response['user'] : false;
00501     }
00502 
00503 
00505     function photos_addTags ($photo_id, $tags)
00506     {
00508         $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
00509         return $this->parsed_response ? true : false;
00510     }
00511 
00512     function photos_delete($photo_id)
00513     {
00515         $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE);
00516         return $this->parsed_response ? true : false;
00517     }
00518 
00519     function photos_getAllContexts ($photo_id)
00520     {
00522         $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id));
00523         return $this->parsed_response ? $this->parsed_response : false;
00524     }
00525 
00526     function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
00527     {
00529         $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
00530         return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
00531     }
00532 
00533     function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL)
00534     {
00536         $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));
00537         return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
00538     }
00539 
00540     function photos_getContext ($photo_id)
00541     {
00543         $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id));
00544         return $this->parsed_response ? $this->parsed_response : false;
00545     }
00546 
00547     function photos_getCounts ($dates = NULL, $taken_dates = NULL)
00548     {
00550         $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates));
00551         return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false;
00552     }
00553 
00554     function photos_getExif ($photo_id, $secret = NULL)
00555     {
00557         $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret));
00558         return $this->parsed_response ? $this->parsed_response['photo'] : false;
00559     }
00560 
00561     function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL)
00562     {
00564         $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page));
00565         return $this->parsed_response ? $this->parsed_response['photo'] : false;
00566     }
00567 
00568     function photos_getInfo($photo_id, $secret = NULL)
00569     {
00571         $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret));
00572         return $this->parsed_response ? $this->parsed_response['photo'] : false;
00573     }
00574 
00575     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)
00576     {
00578         if (is_array($extras)) {
00579             $extras = implode(",", $extras);
00580         }
00581         $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));
00582         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00583     }
00584 
00585     function photos_getPerms($photo_id)
00586     {
00588         $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id));
00589         return $this->parsed_response ? $this->parsed_response['perms'] : false;
00590     }
00591 
00592     function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL)
00593     {
00596         if (is_array($extras)) {
00597             $extras = implode(",", $extras);
00598         }
00599         $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00600         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00601     }
00602 
00603     function photos_getSizes($photo_id)
00604     {
00606         $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id));
00607         return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false;
00608     }
00609 
00610     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)
00611     {
00613         if (is_array($extras)) {
00614             $extras = implode(",", $extras);
00615         }
00616         $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));
00617         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00618     }
00619 
00620     function photos_getWithGeoData($args = NULL) {
00627         if (is_null($args)) {
00628             $args = array();
00629         }
00630         $this->request("flickr.photos.getWithGeoData", $args);
00631         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00632     }
00633 
00634     function photos_getWithoutGeoData($args = NULL) {
00641         if (is_null($args)) {
00642             $args = array();
00643         }
00644         $this->request("flickr.photos.getWithoutGeoData", $args);
00645         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00646     }
00647 
00648     function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
00649     {
00651         if (is_array($extras)) {
00652             $extras = implode(",", $extras);
00653         }
00654         $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page));
00655         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00656     }
00657 
00658     function photos_removeTag($tag_id)
00659     {
00661         $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE);
00662         return $this->parsed_response ? true : false;
00663     }
00664 
00665     function photos_search($args)
00666     {
00679         $this->request("flickr.photos.search", $args);
00680         return $this->parsed_response ? $this->parsed_response['photos'] : false;
00681     }
00682 
00683     function photos_setContentType ($photo_id, $content_type) {
00685         return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type));
00686     }
00687 
00688     function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL)
00689     {
00691         $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);
00692         return $this->parsed_response ? true : false;
00693     }
00694 
00695     function photos_setMeta($photo_id, $title, $description)
00696     {
00698         $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE);
00699         return $this->parsed_response ? true : false;
00700     }
00701 
00702     function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta)
00703     {
00705         $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);
00706         return $this->parsed_response ? true : false;
00707     }
00708 
00709     function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) {
00711         return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden));
00712     }
00713 
00714 
00715     function photos_setTags($photo_id, $tags)
00716     {
00718         $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE);
00719         return $this->parsed_response ? true : false;
00720     }
00721 
00723     function photos_comments_addComment($photo_id, $comment_text) {
00725         $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE);
00726         return $this->parsed_response ? $this->parsed_response['comment'] : false;
00727     }
00728 
00729     function photos_comments_deleteComment($comment_id) {
00731         $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
00732         return $this->parsed_response ? true : false;
00733     }
00734 
00735     function photos_comments_editComment($comment_id, $comment_text) {
00737         $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
00738         return $this->parsed_response ? true : false;
00739     }
00740 
00741     function photos_comments_getList($photo_id)
00742     {
00744         $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id));
00745         return $this->parsed_response ? $this->parsed_response['comments'] : false;
00746     }
00747 
00749     function photos_geo_getLocation($photo_id)
00750     {
00752         $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id));
00753         return $this->parsed_response ? $this->parsed_response['photo'] : false;
00754     }
00755 
00756     function photos_geo_getPerms($photo_id)
00757     {
00759         $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id));
00760         return $this->parsed_response ? $this->parsed_response['perms'] : false;
00761     }
00762 
00763     function photos_geo_removeLocation($photo_id)
00764     {
00766         $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE);
00767         return $this->parsed_response ? true : false;
00768     }
00769 
00770     function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL)
00771     {
00773         $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE);
00774         return $this->parsed_response ? true : false;
00775     }
00776 
00777     function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family)
00778     {
00780         $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);
00781         return $this->parsed_response ? true : false;
00782     }
00783 
00785     function photos_licenses_getInfo()
00786     {
00788         $this->request("flickr.photos.licenses.getInfo");
00789         return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false;
00790     }
00791 
00792     function photos_licenses_setLicense($photo_id, $license_id)
00793     {
00796         $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE);
00797         return $this->parsed_response ? true : false;
00798     }
00799 
00801     function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text)
00802     {
00804         $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);
00805         return $this->parsed_response ? $this->parsed_response['note'] : false;
00806     }
00807 
00808     function photos_notes_delete($note_id)
00809     {
00811         $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE);
00812         return $this->parsed_response ? true : false;
00813     }
00814 
00815     function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text)
00816     {
00818         $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);
00819         return $this->parsed_response ? true : false;
00820     }
00821 
00823     function photos_transform_rotate($photo_id, $degrees)
00824     {
00826         $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE);
00827         return $this->parsed_response ? true : false;
00828     }
00829 
00831     function photos_upload_checkTickets($tickets)
00832     {
00834         if (is_array($tickets)) {
00835             $tickets = implode(",", $tickets);
00836         }
00837         $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE);
00838         return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false;
00839     }
00840 
00842     function photosets_addPhoto($photoset_id, $photo_id)
00843     {
00845         $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
00846         return $this->parsed_response ? true : false;
00847     }
00848 
00849     function photosets_create($title, $description, $primary_photo_id)
00850     {
00852         $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE);
00853         return $this->parsed_response ? $this->parsed_response['photoset'] : false;
00854     }
00855 
00856     function photosets_delete($photoset_id)
00857     {
00859         $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE);
00860         return $this->parsed_response ? true : false;
00861     }
00862 
00863     function photosets_editMeta($photoset_id, $title, $description = NULL)
00864     {
00866         $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE);
00867         return $this->parsed_response ? true : false;
00868     }
00869 
00870     function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids)
00871     {
00873         $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE);
00874         return $this->parsed_response ? true : false;
00875     }
00876 
00877     function photosets_getContext($photo_id, $photoset_id)
00878     {
00880         $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id));
00881         return $this->parsed_response ? $this->parsed_response : false;
00882     }
00883 
00884     function photosets_getInfo($photoset_id)
00885     {
00887         $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id));
00888         return $this->parsed_response ? $this->parsed_response['photoset'] : false;
00889     }
00890 
00891     function photosets_getList($user_id = NULL)
00892     {
00894         $this->request("flickr.photosets.getList", array("user_id" => $user_id));
00895         return $this->parsed_response ? $this->parsed_response['photosets'] : false;
00896     }
00897 
00898     function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL)
00899     {
00901         $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page));
00902         return $this->parsed_response ? $this->parsed_response['photoset'] : false;
00903     }
00904 
00905     function photosets_orderSets($photoset_ids)
00906     {
00908         if (is_array($photoset_ids)) {
00909             $photoset_ids = implode(",", $photoset_ids);
00910         }
00911         $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE);
00912         return $this->parsed_response ? true : false;
00913     }
00914 
00915     function photosets_removePhoto($photoset_id, $photo_id)
00916     {
00918         $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE);
00919         return $this->parsed_response ? true : false;
00920     }
00921 
00923     function photosets_comments_addComment($photoset_id, $comment_text) {
00925         $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE);
00926         return $this->parsed_response ? $this->parsed_response['comment'] : false;
00927     }
00928 
00929     function photosets_comments_deleteComment($comment_id) {
00931         $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE);
00932         return $this->parsed_response ? true : false;
00933     }
00934 
00935     function photosets_comments_editComment($comment_id, $comment_text) {
00937         $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE);
00938         return $this->parsed_response ? true : false;
00939     }
00940 
00941     function photosets_comments_getList($photoset_id)
00942     {
00944         $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id));
00945         return $this->parsed_response ? $this->parsed_response['comments'] : false;
00946     }
00947 
00949     function places_resolvePlaceId ($place_id) {
00951         $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id));
00952         return $rsp ? $rsp['location'] : $rsp;
00953     }
00954 
00955     function places_resolvePlaceURL ($url) {
00957         $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url));
00958         return $rsp ? $rsp['location'] : $rsp;
00959     }
00960 
00962     function prefs_getContentType () {
00964         $rsp = $this->call('flickr.prefs.getContentType', array());
00965         return $rsp ? $rsp['person'] : $rsp;
00966     }
00967 
00968     function prefs_getHidden () {
00970         $rsp = $this->call('flickr.prefs.getHidden', array());
00971         return $rsp ? $rsp['person'] : $rsp;
00972     }
00973 
00974     function prefs_getPrivacy () {
00976         $rsp = $this->call('flickr.prefs.getPrivacy', array());
00977         return $rsp ? $rsp['person'] : $rsp;
00978     }
00979 
00980     function prefs_getSafetyLevel () {
00982         $rsp = $this->call('flickr.prefs.getSafetyLevel', array());
00983         return $rsp ? $rsp['person'] : $rsp;
00984     }
00985 
00987     function reflection_getMethodInfo($method_name)
00988     {
00990         $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name));
00991         return $this->parsed_response ? $this->parsed_response : false;
00992     }
00993 
00994     function reflection_getMethods()
00995     {
00997         $this->request("flickr.reflection.getMethods");
00998         return $this->parsed_response ? $this->parsed_response['methods']['method'] : false;
00999     }
01000 
01002     function tags_getHotList($period = NULL, $count = NULL)
01003     {
01005         $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count));
01006         return $this->parsed_response ? $this->parsed_response['hottags'] : false;
01007     }
01008 
01009     function tags_getListPhoto($photo_id)
01010     {
01012         $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id));
01013         return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false;
01014     }
01015 
01016     function tags_getListUser($user_id = NULL)
01017     {
01019         $this->request("flickr.tags.getListUser", array("user_id" => $user_id));
01020         return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
01021     }
01022 
01023     function tags_getListUserPopular($user_id = NULL, $count = NULL)
01024     {
01026         $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count));
01027         return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false;
01028     }
01029 
01030     function tags_getListUserRaw($tag)
01031     {
01033         $this->request("flickr.tags.getListUserRaw", array("tag" => $tag));
01034         return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false;
01035     }
01036 
01037     function tags_getRelated($tag)
01038     {
01040         $this->request("flickr.tags.getRelated", array("tag" => $tag));
01041         return $this->parsed_response ? $this->parsed_response['tags'] : false;
01042     }
01043 
01044     function test_echo($args = array())
01045     {
01047         $this->request("flickr.test.echo", $args);
01048         return $this->parsed_response ? $this->parsed_response : false;
01049     }
01050 
01051     function test_login()
01052     {
01054         $this->request("flickr.test.login");
01055         return $this->parsed_response ? $this->parsed_response['user'] : false;
01056     }
01057 
01058     function urls_getGroup($group_id)
01059     {
01061         $this->request("flickr.urls.getGroup", array("group_id"=>$group_id));
01062         return $this->parsed_response ? $this->parsed_response['group']['url'] : false;
01063     }
01064 
01065     function urls_getUserPhotos($user_id = NULL)
01066     {
01068         $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id));
01069         return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
01070     }
01071 
01072     function urls_getUserProfile($user_id = NULL)
01073     {
01075         $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id));
01076         return $this->parsed_response ? $this->parsed_response['user']['url'] : false;
01077     }
01078 
01079     function urls_lookupGroup($url)
01080     {
01082         $this->request("flickr.urls.lookupGroup", array("url"=>$url));
01083         return $this->parsed_response ? $this->parsed_response['group'] : false;
01084     }
01085 
01086     function urls_lookupUser($url)
01087     {
01089         $this->request("flickr.urls.lookupUser", array("url"=>$url));
01090         return $this->parsed_response ? $this->parsed_response['user'] : false;
01091     }
01092 
01103     function upload(stored_file $photo, array $meta = array()) {
01104 
01105         $args = array();
01106 
01107         $args['title']          = isset($meta['title']) ? $meta['title'] : null;
01108         $args['description']    = isset($meta['description']) ? $meta['description'] : null;
01109         $args['tags']           = isset($meta['tags']) ? $meta['tags'] : null;
01110         $args['is_public']      = isset($meta['is_public']) ? $meta['is_public'] : 0;
01111         $args['is_friend']      = isset($meta['is_friend']) ? $meta['is_friend'] : 0;
01112         $args['is_family']      = isset($meta['is_family']) ? $meta['is_family'] : 0;
01113         $args['safety_level']   = isset($meta['safety_level']) ? $meta['safety_level'] : 1; // safe by default
01114         $args['content_type']   = isset($meta['content_type']) ? $meta['content_type'] : 1; // photo by default
01115         $args['hidden']         = isset($meta['hidden']) ? $meta['hidden'] : 2;             // hide from public searches by default
01116 
01117         $args['async'] = 1;
01118         $args['api_key'] = $this->api_key;
01119 
01120         if (!empty($this->email)) {
01121             $args['email'] = $this->email;
01122         }
01123         if (!empty($this->password)) {
01124             $args['password'] = $this->password;
01125         }
01126         if (!empty($this->token)) {
01127             $args['auth_token'] = $this->token;
01128         }
01129 
01130         // sign the arguments using the shared secret
01131         ksort($args);
01132         $auth_sig = '';
01133         foreach ($args as $key => $data) {
01134             if (!is_null($data)) {
01135                 $auth_sig .= $key . $data;
01136             } else {
01137                 unset($args[$key]);
01138             }
01139         }
01140         if (!empty($this->secret)) {
01141             $api_sig = md5($this->secret . $auth_sig);
01142             $args['api_sig'] = $api_sig;
01143         }
01144 
01145         $args['photo'] = $photo; // $this->curl will process it correctly
01146 
01147         if ($response = $this->curl->post($this->Upload, $args)) {
01148             return true;
01149         } else {
01150             return false;
01151         }
01152     }
01153 }
 All Data Structures Namespaces Files Functions Variables Enumerations