From aa754fe3d46c6f51e06c60085d918dbd96da6992 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 14 Jul 2008 05:31:01 +0000 Subject: [PATCH] MDL-15350, search files in box.net repository. --- repository/ajax.php | 9 +- repository/boxnet/boxlibphp5.php | 392 ++--- repository/boxnet/repository.class.php | 26 +- repository/curl.class.php | 34 +- repository/flickr/phpFlickr.php | 2128 ++++++++++++------------ repository/lib.php | 18 +- 6 files changed, 1313 insertions(+), 1294 deletions(-) diff --git a/repository/ajax.php b/repository/ajax.php index 9c15086b06..8b26ac7cea 100644 --- a/repository/ajax.php +++ b/repository/ajax.php @@ -91,6 +91,7 @@ function openpicker(){ // 10px top/bottom padding applied to Panel body element. The top/bottom border width is 0 var panel = new YAHOO.widget.Panel('file-picker', { draggable: true, + close: false, underlay: 'none', width: '510px', xy: [100, 100] @@ -190,8 +191,12 @@ function openpicker(){ }) var search = new YAHOO.util.Element('search'); search.on('click', function(e){ + if(repositoryid==0){ + alert('Select a repository first.'); + return; + } var data=window.prompt("What are you searching for?"); - if(data != null || data != '') { + if(data != null && data != '') { dosearch(data); } }) @@ -285,7 +290,7 @@ success: function(o) { try { var ret = YAHOO.lang.JSON.parse(o.responseText); } catch(e) { - alert(e); + alert('Invalid JSON String\n'+o.responseText); } datasource = ret; if(datasource.l){ diff --git a/repository/boxnet/boxlibphp5.php b/repository/boxnet/boxlibphp5.php index 0aa753505d..8fcc51f9da 100755 --- a/repository/boxnet/boxlibphp5.php +++ b/repository/boxnet/boxlibphp5.php @@ -1,13 +1,13 @@ * @link http://enabled.box.net * @access public * @version 1.0 - * copyright Box.net 2007 + * copyright Box.net 2007 * Available for use and distribution under GPL-license * Go to http://www.gnu.org/licenses/gpl-3.0.txt for full text */ @@ -32,7 +32,7 @@ class boxclient { $this->auth_token = $str; } - + public function __construct($api_key, $auth_token) { $this->api_key = $api_key; $this->auth_token = $auth_token; @@ -48,8 +48,8 @@ class boxclient { $query_str = implode('/', $args); } $request = $this->_box_api_upload_url .'/'. $query_str; - if ($this->_debug){ - echo "Upload Request: ".$request; + if ($this->_debug){ + echo "Upload Request: ".$request; } }else{ $args = array(); @@ -91,20 +91,20 @@ class boxclient { $xml .= fgets($fp, 1024); } fclose($fp); - - + + $xml_start = strpos($xml, '_debug) { echo '

XML Response

'; echo '
';
             echo htmlspecialchars($xml);
             echo '
'; } - + $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $xml, $data); xml_parser_free($xml_parser); @@ -131,7 +131,7 @@ class boxclient { echo '

Ticket Return

'; $this->_a($ret_array); var_dump ($a); - } + } return $ret_array; } // Get Auth Token @@ -144,17 +144,17 @@ class boxclient { return false; } foreach ($data as $a) { - switch ($a['tag']) + switch ($a['tag']) { - case 'STATUS': + case 'STATUS': $ret_array['status'] = $a['value']; - break; + break; case 'AUTH_TOKEN': $ret_array['auth_token'] = $a['value']; - break; + break; } } - + if ($ret_array['status'] == 'get_auth_token_ok'){ $this->auth_token = $ret_array['auth_token']; $auth_token = $ret_array['auth_token']; @@ -162,10 +162,10 @@ class boxclient { }else{ echo 'Login'; return false; - //header ('location: http://www.box.net/api/1.0/auth/'.$ticket) ; - } + //header ('location: http://www.box.net/api/1.0/auth/'.$ticket) ; + } } - + // Retrieve Account Tree (http://enabled.box.net/docs/rest#get_account_tree) function getAccountTree($params = array()) { $params['api_key'] = $this->api_key; @@ -183,7 +183,7 @@ class boxclient { $entry_count = 0; for ($i=0, $tree_count=count($data); $i<$tree_count; $i++) { $a = $data[$i]; - switch ($a['tag']) + switch ($a['tag']) { case 'FOLDER': if (@is_array($a['attributes'])) { @@ -192,7 +192,7 @@ class boxclient { $ret_array['shared'][$i] = $a['attributes']['SHARED']; } break; - + case 'FILE': if (@is_array($a['attributes'])) { $ret_array['file_id'][$i] = $a['attributes']['ID']; @@ -210,139 +210,139 @@ class boxclient { } return $ret_array; } - // Create New Folder - function CreateFolder($new_folder_name, $params = array()) { - $params['api_key'] = $this->api_key; - $params['auth_token'] = $this->auth_token; - $params['parent_id'] = 0; //Set to '0' by default. Change to create within sub-folder. - $params['name'] = $new_folder_name; - $params['share'] = 1; //Set to '1' by default. Set to '0' to make folder private. - - $ret_array = array(); - $data = $this->makeRequest('action=create_folder', $params); - - - if ($this->_checkForError($data)) { - return false; - } - foreach ($data as $a) { - switch ($a['tag']) { + // Create New Folder + function CreateFolder($new_folder_name, $params = array()) { + $params['api_key'] = $this->api_key; + $params['auth_token'] = $this->auth_token; + $params['parent_id'] = 0; //Set to '0' by default. Change to create within sub-folder. + $params['name'] = $new_folder_name; + $params['share'] = 1; //Set to '1' by default. Set to '0' to make folder private. + + $ret_array = array(); + $data = $this->makeRequest('action=create_folder', $params); + + + if ($this->_checkForError($data)) { + return false; + } + foreach ($data as $a) { + switch ($a['tag']) { case 'FOLDER_ID': - $ret_array['folder_id'] = $a['value']; - break; - + $ret_array['folder_id'] = $a['value']; + break; + case 'FOLDER_NAME': - $ret_array['folder_type'] = $a['value']; - break; - + $ret_array['folder_type'] = $a['value']; + break; + case 'SHARED': - $ret_array['shared'] = $a['value']; - break; + $ret_array['shared'] = $a['value']; + break; case 'PASSWORD': - $ret_array['password'] = $a['value']; + $ret_array['password'] = $a['value']; break; } - } + } if ($this->_debug) { - echo '

Account Tree Return

'; - $this->_a($ret_array); - var_dump ($a); - } - return $ret_array; - } - // Upload File - function UploadFile ($params = array()) { - $params['auth_token'] = $this->auth_token; - $params['new_file1'] = $_FILES['new_file1']; - $params['folder id'] = 0; //Set to '0' by default. Change to create within sub-folder. - $params['share'] = 1; //Set to '1' by default. Set to '0' to make folder private. - $ret_array = array(); - $data = $this->makeUploadRequst($params); - if ($this->_checkForError($data)) { - return false; - } - for ($i=0, $tree_count=count($data); $i<$tree_count; $i++) { - $a = $data[$i]; - switch ($a['tag']) { + echo '

Account Tree Return

'; + $this->_a($ret_array); + var_dump ($a); + } + return $ret_array; + } + // Upload File + function UploadFile ($params = array()) { + $params['auth_token'] = $this->auth_token; + $params['new_file1'] = $_FILES['new_file1']; + $params['folder id'] = 0; //Set to '0' by default. Change to create within sub-folder. + $params['share'] = 1; //Set to '1' by default. Set to '0' to make folder private. + $ret_array = array(); + $data = $this->makeUploadRequst($params); + if ($this->_checkForError($data)) { + return false; + } + for ($i=0, $tree_count=count($data); $i<$tree_count; $i++) { + $a = $data[$i]; + switch ($a['tag']) { case 'STATUS': $ret_array['status'] = $a['value']; - + break; - + case 'FILE': - if (is_array($a['attributes'])) { - $ret_array['file_name'][$i] = $a['attributes']['FILE_NAME']; - $ret_array['id'][$i] = $a['attributes']['ID']; - $ret_array['folder_name'][$i] = $a['attributes']['FOLDER_NAME']; + if (is_array($a['attributes'])) { + $ret_array['file_name'][$i] = $a['attributes']['FILE_NAME']; + $ret_array['id'][$i] = $a['attributes']['ID']; + $ret_array['folder_name'][$i] = $a['attributes']['FOLDER_NAME']; $ret_array['error'][$i] = $a['attributes']['ERROR']; $ret_array['public_name'][$i] = $a['attributes']['PUBLIC_NAME']; - $entry_count++; - } - break; + $entry_count++; + } + break; } } - + if ($this->_debug) { - echo '

Account Tree Return

'; - $this->_a($ret_array); - var_dump ($a); - } - return $ret_array; - } - - - // Set Description of File or Folder - - - - - // Register New User - - function RegisterUser($params = array()) { - - $params['api_key'] = $this->api_key; - $params['login'] = $_REQUEST['login']; - $params['password'] = $_REQUEST['password']; - $ret_array = array(); - $data = $this->makeRequest('action=register_new_user', $params); - if ($this->_checkForError($data)) { - return false; - } - foreach ($data as $a) { - switch ($a['tag']) { + echo '

Account Tree Return

'; + $this->_a($ret_array); + var_dump ($a); + } + return $ret_array; + } + + + // Set Description of File or Folder + + + + + // Register New User + + function RegisterUser($params = array()) { + + $params['api_key'] = $this->api_key; + $params['login'] = $_REQUEST['login']; + $params['password'] = $_REQUEST['password']; + $ret_array = array(); + $data = $this->makeRequest('action=register_new_user', $params); + if ($this->_checkForError($data)) { + return false; + } + foreach ($data as $a) { + switch ($a['tag']) { case 'STATUS': $ret_array['status'] = $a['value']; break; - + case 'AUTH_TOKEN': $ret_array['auth_token'] = $a['value']; - break; - + break; + case 'LOGIN': $ret_array['login'] = $a['value']; - break; + break; case 'SPACE_AMOUNT': $ret_array['space_amount'] = $a['value']; - break; - case 'SPACE_USED': + break; + case 'SPACE_USED': $ret_array['space_used'] = $a['value']; - break; + break; } } - - if ($this->_debug) { - echo '

Registration Return

'; - $this->_a($ret_array); - var_dump ($a); - } - - return $ret_array; - } - - // Add Tags (http://enabled.box.net/docs/rest#add_to_tag) - + + if ($this->_debug) { + echo '

Registration Return

'; + $this->_a($ret_array); + var_dump ($a); + } + + return $ret_array; + } + + // Add Tags (http://enabled.box.net/docs/rest#add_to_tag) + function AddTag($tag, $id, $target_type, $params = array()) { - + $params['api_key'] = $this->api_key; $params['auth_token'] = $this->auth_token; $params['target'] = $target_type; // File or folder @@ -357,24 +357,24 @@ class boxclient { switch ($a['tag']) { case 'STATUS': $ret_array['status'] = $a['value']; - + break; } } - + if ($this->_debug) { echo '

Tag Return

'; $this->_a($ret_array); var_dump ($a); - } - + } + return $ret_array; - - + + } - + // Public Share (http://enabled.box.net/docs/rest#public_share) - + function PublicShare($message, $emails, $id, $target_type, $password, $params = array()) { $params['api_key'] = $this->api_key; $params['auth_token'] = $this->auth_token; @@ -398,20 +398,20 @@ class boxclient { break; } } - + if ($this->_debug) { echo '

Public Share Return

'; $this->_a($ret_array); var_dump ($a); - } + } return $ret_array; } - - + + // Get Friends (http://enabled.box.net/docs/rest#get_friends) - + function GetFriends ($params = array()) { - + $params['api_key'] = $this->api_key; $params['auth_token'] = $this->auth_token; $params['params[]'] = 'nozip'; @@ -449,75 +449,75 @@ class boxclient { echo '

Get Friend Return

'; $this->_a($ret_array); var_dump ($a); - } + } return $ret_array; } - - + + // Logout User - - function Logout($params = array()) { - - $params['api_key'] = $this->api_key; - $params['auth_token'] = $this->auth_token; - $ret_array = array(); - $data = $this->makeRequest('action=logout', $params); - if ($this->_checkForError($data)) { - return false; - } - foreach ($data as $a) { - switch ($a['tag']) { + + function Logout($params = array()) { + + $params['api_key'] = $this->api_key; + $params['auth_token'] = $this->auth_token; + $ret_array = array(); + $data = $this->makeRequest('action=logout', $params); + if ($this->_checkForError($data)) { + return false; + } + foreach ($data as $a) { + switch ($a['tag']) { case 'ACTION': $ret_array['logout'] = $a['value']; - + break; - } + } if ($this->_debug) { echo '

Logout Return

'; $this->_a($ret_array); var_dump ($a); - } + } return $ret_array; } } - function _checkForError($data) { - if (@$data[0]['attributes']['STAT'] == 'fail') { - $this->_error_code = $data[1]['attributes']['CODE']; - $this->_error_msg = $data[1]['attributes']['MSG']; - return true; - } - return false; - } - - - public function isError() { - if ($this->_error_msg != '') { - return true; - } - return false; - } - - - function getErrorMsg() { - return '

Error: (' . $this->_error_code . ') ' . $this->_error_msg . '

'; - } - - function getErrorCode() { - return $this->_error_code; - } - - - function _clearErrors() { - $this->_error_code = ''; - $this->_error_msg = ''; - } - - public function setDebug($debug) { - $this->_debug = $debug; - } - - private function _a($array) { - var_dump($array); - } + function _checkForError($data) { + if (@$data[0]['attributes']['STAT'] == 'fail') { + $this->_error_code = $data[1]['attributes']['CODE']; + $this->_error_msg = $data[1]['attributes']['MSG']; + return true; + } + return false; + } + + + public function isError() { + if ($this->_error_msg != '') { + return true; + } + return false; + } + + + function getErrorMsg() { + return '

Error: (' . $this->_error_code . ') ' . $this->_error_msg . '

'; + } + + function getErrorCode() { + return $this->_error_code; + } + + + function _clearErrors() { + $this->_error_code = ''; + $this->_error_msg = ''; + } + + public function setDebug($debug) { + $this->_debug = $debug; + } + + private function _a($array) { + var_dump($array); + } } ?> diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 681bba13e9..9ff4f6a211 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -27,10 +27,10 @@ class repository_boxnet extends repository{ if(!empty($reset)) { unset($SESSION->box_token); } - // do login + // do login if(!empty($options['username']) - && !empty($options['password']) - && !empty($options['ticket']) ) + && !empty($options['password']) + && !empty($options['ticket']) ) { $c = new curl; $str = ''; @@ -71,9 +71,23 @@ class repository_boxnet extends repository{ $filenames = $tree['file_name']; $fileids = $tree['file_id']; foreach ($filenames as $n=>$v){ - $list[] = array('title'=>$v, 'size'=>0, 'date'=>'', - 'source'=>'http://box.net/api/1.0/download/'.$this->options['auth_token'].'/'.$fileids[$n], - 'thumbnail'=>$CFG->pixpath.'/i/files.gif'); + if(!empty($search)) { + if(strstr($v, $search) !== false) { + $list[] = array('title'=>$v, + 'size'=>0, + 'date'=>'', + 'source'=>'http://box.net/api/1.0/download/' + .$this->options['auth_token'].'/'.$fileids[$n], + 'thumbnail'=>$CFG->pixpath.'/f/text.gif'); + } + } else { + $list[] = array('title'=>$v, + 'size'=>0, + 'date'=>'', + 'source'=>'http://box.net/api/1.0/download/' + .$this->options['auth_token'].'/'.$fileids[$n], + 'thumbnail'=>$CFG->pixpath.'/f/text.gif'); + } } $this->listing = $list; $ret['list'] = $list; diff --git a/repository/curl.class.php b/repository/curl.class.php index 6c02ae3605..1214b51891 100644 --- a/repository/curl.class.php +++ b/repository/curl.class.php @@ -51,19 +51,19 @@ class curl { public function resetopt(){ $this->options = array(); $this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0'; - // True to include the header in the output + // True to include the header in the output $this->options['CURLOPT_HEADER'] = 0; - // True to Exclude the body from the output + // True to Exclude the body from the output $this->options['CURLOPT_NOBODY'] = 0; - // TRUE to follow any "Location: " header that the server - // sends as part of the HTTP header (note this is recursive, - // PHP will follow as many "Location: " headers that it is sent, - // unless CURLOPT_MAXREDIRS is set). + // TRUE to follow any "Location: " header that the server + // sends as part of the HTTP header (note this is recursive, + // PHP will follow as many "Location: " headers that it is sent, + // unless CURLOPT_MAXREDIRS is set). $this->options['CURLOPT_FOLLOWLOCATION'] = 1; $this->options['CURLOPT_MAXREDIRS'] = 10; $this->options['CURLOPT_ENCODING'] = ''; - // TRUE to return the transfer as a string of the return - // value of curl_exec() instead of outputting it out directly. + // TRUE to return the transfer as a string of the return + // value of curl_exec() instead of outputting it out directly. $this->options['CURLOPT_RETURNTRANSFER'] = 1; $this->options['CURLOPT_BINARYTRANSFER'] = 0; $this->options['CURLOPT_SSL_VERIFYPEER'] = 0; @@ -73,7 +73,7 @@ class curl { /** * Reset Cookie - * + * * @param array $options If array is null, this function will * reset the options to default value. * @@ -92,7 +92,7 @@ class curl { /** * Set curl options - * + * * @param array $options If array is null, this function will * reset the options to default value. * @@ -104,7 +104,7 @@ class curl { $name = strtoupper('CURLOPT_'.$name); } $this->options[$name] = $val; - } + } } } /** @@ -123,8 +123,8 @@ class curl { /** * Set HTTP Request Header - * - * @param array $headers + * + * @param array $headers * */ public function setHeader($header) { @@ -138,7 +138,7 @@ class curl { } /** * Set HTTP Response Header - * + * */ public function getResponse(){ return $this->response; @@ -146,9 +146,9 @@ class curl { /** * private callback function * Formatting HTTP Response Header - * + * */ - private function formatHeader($ch, $header) + private function formatHeader($ch, $header) { $this->count++; if (strlen($header) > 2) { @@ -173,7 +173,7 @@ class curl { /** * Formatting HTTP Response Header - * + * */ protected function request($url, $options = array()){ // Clean up diff --git a/repository/flickr/phpFlickr.php b/repository/flickr/phpFlickr.php index e2464e464a..dcbe1b89d1 100755 --- a/repository/flickr/phpFlickr.php +++ b/repository/flickr/phpFlickr.php @@ -6,12 +6,12 @@ * For more information about the class and upcoming tools and toys using it, * visit http://www.phpflickr.com/ or http://phpflickr.sourceforge.net * - * For installation instructions, open the README.txt file packaged with this - * class. If you don't have a copy, you can see it at: - * http://www.phpflickr.com/README.txt + * For installation instructions, open the README.txt file packaged with this + * class. If you don't have a copy, you can see it at: + * http://www.phpflickr.com/README.txt * - * Please submit all problems or questions to the Help Forum on my project page: - * http://sourceforge.net/forum/forum.php?forum_id=469652 + * Please submit all problems or questions to the Help Forum on my project page: + * http://sourceforge.net/forum/forum.php?forum_id=469652 * */ /** @@ -27,57 +27,57 @@ require_once('../config.php'); class phpFlickr { - var $api_key; - var $secret; - var $REST = 'http://api.flickr.com/services/rest/'; - var $Upload = 'http://api.flickr.com/services/upload/'; - var $Replace = 'http://api.flickr.com/services/replace/'; - var $req; - var $response; - var $parsed_response; - var $cache = false; - var $cache_db = null; - var $cache_table = null; - var $cache_dir = null; - var $cache_expire = null; - var $die_on_error; - var $error_code; - Var $error_msg; - var $token; - var $php_version; - - /* - * When your database cache table hits this many rows, a cleanup - * will occur to get rid of all of the old rows and cleanup the - * garbage in the table. For most personal apps, 1000 rows should - * be more than enough. If your site gets hit by a lot of traffic - * or you have a lot of disk space to spare, bump this number up. - * You should try to set it high enough that the cleanup only - * happens every once in a while, so this will depend on the growth - * of your table. - */ - var $max_cache_rows = 1000; - - function __construct ($api_key, $secret = NULL, $die_on_error = false) - { + var $api_key; + var $secret; + var $REST = 'http://api.flickr.com/services/rest/'; + var $Upload = 'http://api.flickr.com/services/upload/'; + var $Replace = 'http://api.flickr.com/services/replace/'; + var $req; + var $response; + var $parsed_response; + var $cache = false; + var $cache_db = null; + var $cache_table = null; + var $cache_dir = null; + var $cache_expire = null; + var $die_on_error; + var $error_code; + Var $error_msg; + var $token; + var $php_version; + + /* + * When your database cache table hits this many rows, a cleanup + * will occur to get rid of all of the old rows and cleanup the + * garbage in the table. For most personal apps, 1000 rows should + * be more than enough. If your site gets hit by a lot of traffic + * or you have a lot of disk space to spare, bump this number up. + * You should try to set it high enough that the cleanup only + * happens every once in a while, so this will depend on the growth + * of your table. + */ + var $max_cache_rows = 1000; + + function __construct ($api_key, $secret = NULL, $die_on_error = false) + { global $CFG; - //The API Key must be set before any calls can be made. You can - //get your own at http://www.flickr.com/services/api/misc.api_keys.html - $this->api_key = $api_key; - $this->secret = $secret; - $this->die_on_error = $die_on_error; - $this->service = "flickr"; + //The API Key must be set before any calls can be made. You can + //get your own at http://www.flickr.com/services/api/misc.api_keys.html + $this->api_key = $api_key; + $this->secret = $secret; + $this->die_on_error = $die_on_error; + $this->service = "flickr"; - //Find the PHP version and store it for future reference - $this->php_version = explode("-", phpversion()); - $this->php_version = explode(".", $this->php_version[0]); + //Find the PHP version and store it for future reference + $this->php_version = explode("-", phpversion()); + $this->php_version = explode(".", $this->php_version[0]); require_once($CFG->dirroot.'/repository/curl.class.php'); $this->curl = new curl(array('cache'=>true)); - } + } - function enableCache($type, $connection, $cache_expire = 600, $table = 'flickr_cache') - { + function enableCache($type, $connection, $cache_expire = 600, $table = 'flickr_cache') + { $this->cache = 'fs'; $connection = realpath($connection); $this->cache_dir = $connection; @@ -88,15 +88,15 @@ class phpFlickr { } } } - $this->cache_expire = $cache_expire; - } - - function getCached ($request) - { - //Checks the database or filesystem for a cached result to the request. - //If there is no cache result, it returns a value of false. If it finds one, - //it returns the unparsed XML. - $reqhash = md5(serialize($request)); + $this->cache_expire = $cache_expire; + } + + function getCached ($request) + { + //Checks the database or filesystem for a cached result to the request. + //If there is no cache result, it returns a value of false. If it finds one, + //it returns the unparsed XML. + $reqhash = md5(serialize($request)); $file = $this->cache_dir . '/' . $reqhash . '.cache'; if (file_exists($file)) { if ($this->php_version[0] > 4 || ($this->php_version[0] == 4 && $this->php_version[1] >= 3)) { @@ -105,1023 +105,1023 @@ class phpFlickr { return implode('', file($file)); } } - return false; - } + return false; + } - function cache ($request, $response) - { - //Caches the unparsed XML of a request. - $reqhash = md5(serialize($request)); + function cache ($request, $response) + { + //Caches the unparsed XML of a request. + $reqhash = md5(serialize($request)); $file = $this->cache_dir . "/" . $reqhash . ".cache"; $fstream = fopen($file, "w"); $result = fwrite($fstream,$response); fclose($fstream); return $result; - } + } - function request ($command, $args = array(), $nocache = false) - { + function request ($command, $args = array(), $nocache = false) + { global $SESSION; - //Sends a request to Flickr's REST endpoint via POST. - if (substr($command,0,7) != "flickr.") { - $command = "flickr." . $command; - } - - //Process arguments, including method and login data. - $args = array_merge(array("method" => $command, "format" => "php_serial", "api_key" => $this->api_key), $args); - if (!empty($this->token)) { - $args = array_merge($args, array("auth_token" => $this->token)); - } elseif (!empty($SESSION->phpFlickr_auth_token)) { - $args = array_merge($args, array("auth_token" => $SESSION->phpFlickr_auth_token)); - } - ksort($args); - $auth_sig = ""; - if (!($this->response = $this->getCached($args)) || $nocache) { - foreach ($args as $key => $data) { - $auth_sig .= $key . $data; - //$this->req->addPostData($key, $data); - } - if (!empty($this->secret)) { - $api_sig = md5($this->secret . $auth_sig); - //$this->req->addPostData("api_sig", $api_sig); - } - - //$this->req->addHeader("Connection", "Keep-Alive"); + //Sends a request to Flickr's REST endpoint via POST. + if (substr($command,0,7) != "flickr.") { + $command = "flickr." . $command; + } + + //Process arguments, including method and login data. + $args = array_merge(array("method" => $command, "format" => "php_serial", "api_key" => $this->api_key), $args); + if (!empty($this->token)) { + $args = array_merge($args, array("auth_token" => $this->token)); + } elseif (!empty($SESSION->phpFlickr_auth_token)) { + $args = array_merge($args, array("auth_token" => $SESSION->phpFlickr_auth_token)); + } + ksort($args); + $auth_sig = ""; + if (!($this->response = $this->getCached($args)) || $nocache) { + foreach ($args as $key => $data) { + $auth_sig .= $key . $data; + //$this->req->addPostData($key, $data); + } + if (!empty($this->secret)) { + $api_sig = md5($this->secret . $auth_sig); + //$this->req->addPostData("api_sig", $api_sig); + } + + //$this->req->addHeader("Connection", "Keep-Alive"); $ret = $this->curl->post($this->REST, $args); - } - /* - * Uncomment this line (and comment out the next one) if you're doing large queries - * and you're concerned about time. This will, however, change the structure of - * the result, so be sure that you look at the results. - */ - //$this->parsed_response = unserialize($this->response); - $this->parsed_response = $this->clean_text_nodes(unserialize($ret)); - if ($this->parsed_response['stat'] == 'fail') { - if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); - else { - $this->error_code = $this->parsed_response['code']; - $this->error_msg = $this->parsed_response['message']; - $this->parsed_response = false; - } - } else { - $this->error_code = false; - $this->error_msg = false; - } - return $this->response; - } - - function clean_text_nodes($arr) { - if (!is_array($arr)) { - return $arr; - } elseif (count($arr) == 0) { - return $arr; - } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) { - return $arr['_content']; - } else { - foreach ($arr as $key => $element) { - $arr[$key] = $this->clean_text_nodes($element); - } - return($arr); - } - } - - function setToken($token) - { - // Sets an authentication token to use instead of the session variable - $this->token = $token; - } - - function setProxy($server, $port) - { - // Sets the proxy for all phpFlickr calls. - //$this->req->setProxy($server, $port); - } - - function getErrorCode() - { - // Returns the error code of the last call. If the last call did not - // return an error. This will return a false boolean. - return $this->error_code; - } - - function getErrorMsg() - { - // Returns the error message of the last call. If the last call did not - // return an error. This will return a false boolean. - return $this->error_msg; - } - - /* These functions are front ends for the flickr calls */ - - function buildPhotoURL ($photo, $size = "Medium") - { - //receives an array (can use the individual photo data returned - //from an API call) and returns a URL (doesn't mean that the - //file size exists) - $sizes = array( - "square" => "_s", - "thumbnail" => "_t", - "small" => "_m", - "medium" => "", - "large" => "_b", - "original" => "_o" - ); - - $size = strtolower($size); - if (!array_key_exists($size, $sizes)) { - $size = "medium"; - } - - if ($size == "original") { - $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat']; - } else { - $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg"; - } - return $url; - } - - function getFriendlyGeodata($lat, $lon) { - /* I've added this method to get the friendly geodata (i.e. 'in New York, NY') that the - * website provides, but isn't available in the API. I'm providing this service as long - * as it doesn't flood my server with requests and crash it all the time. - */ - return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon)); - } - - function auth ($perms = "read", $remember_uri = true) - { + } + /* + * Uncomment this line (and comment out the next one) if you're doing large queries + * and you're concerned about time. This will, however, change the structure of + * the result, so be sure that you look at the results. + */ + //$this->parsed_response = unserialize($this->response); + $this->parsed_response = $this->clean_text_nodes(unserialize($ret)); + if ($this->parsed_response['stat'] == 'fail') { + if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); + else { + $this->error_code = $this->parsed_response['code']; + $this->error_msg = $this->parsed_response['message']; + $this->parsed_response = false; + } + } else { + $this->error_code = false; + $this->error_msg = false; + } + return $this->response; + } + + function clean_text_nodes($arr) { + if (!is_array($arr)) { + return $arr; + } elseif (count($arr) == 0) { + return $arr; + } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) { + return $arr['_content']; + } else { + foreach ($arr as $key => $element) { + $arr[$key] = $this->clean_text_nodes($element); + } + return($arr); + } + } + + function setToken($token) + { + // Sets an authentication token to use instead of the session variable + $this->token = $token; + } + + function setProxy($server, $port) + { + // Sets the proxy for all phpFlickr calls. + //$this->req->setProxy($server, $port); + } + + function getErrorCode() + { + // Returns the error code of the last call. If the last call did not + // return an error. This will return a false boolean. + return $this->error_code; + } + + function getErrorMsg() + { + // Returns the error message of the last call. If the last call did not + // return an error. This will return a false boolean. + return $this->error_msg; + } + + /* These functions are front ends for the flickr calls */ + + function buildPhotoURL ($photo, $size = "Medium") + { + //receives an array (can use the individual photo data returned + //from an API call) and returns a URL (doesn't mean that the + //file size exists) + $sizes = array( + "square" => "_s", + "thumbnail" => "_t", + "small" => "_m", + "medium" => "", + "large" => "_b", + "original" => "_o" + ); + + $size = strtolower($size); + if (!array_key_exists($size, $sizes)) { + $size = "medium"; + } + + if ($size == "original") { + $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat']; + } else { + $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg"; + } + return $url; + } + + function getFriendlyGeodata($lat, $lon) { + /* I've added this method to get the friendly geodata (i.e. 'in New York, NY') that the + * website provides, but isn't available in the API. I'm providing this service as long + * as it doesn't flood my server with requests and crash it all the time. + */ + return unserialize(file_get_contents('http://phpflickr.com/geodata/?format=php&lat=' . $lat . '&lon=' . $lon)); + } + + function auth ($perms = "read", $remember_uri = true) + { global $SESSION; - // Redirects to Flickr's authentication piece if there is no valid token. - // If remember_uri is set to false, the callback script (included) will - // redirect to its default page. - - if (empty($SESSION->phpFlickr_auth_token) && empty($this->token)) { - if ($remember_uri) { - $redirect = $_SERVER['REQUEST_URI']; - } - //$api_sig = md5($this->secret . "api_key" . $this->api_key . "extra" . $redirect . "perms" . $perms); + // Redirects to Flickr's authentication piece if there is no valid token. + // If remember_uri is set to false, the callback script (included) will + // redirect to its default page. + + if (empty($SESSION->phpFlickr_auth_token) && empty($this->token)) { + if ($remember_uri) { + $redirect = $_SERVER['REQUEST_URI']; + } + //$api_sig = md5($this->secret . "api_key" . $this->api_key . "extra" . $redirect . "perms" . $perms); echo $this->secret . "api_key" . $this->api_key . "perms" . $perms; - $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms); - if ($this->service == "23") { - header("Location: http://www.23hq.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig); - } else { - //header("Location: http://www.flickr.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig); - echo 'Login'; - } - //exit; - } else { - $tmp = $this->die_on_error; - $this->die_on_error = false; - $rsp = $this->auth_checkToken(); - if ($this->error_code !== false) { - unset($SESSION->phpFlickr_auth_token); - $this->auth($perms, $remember_uri); - } - $this->die_on_error = $tmp; - return $rsp['perms']; - } - } - - /******************************* - - To use the phpFlickr::call method, pass a string containing the API method you want - to use and an associative array of arguments. For example: - $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612')); - This method will allow you to make calls to arbitrary methods that haven't been - implemented in phpFlickr yet. - - *******************************/ - - function call($method, $arguments) - { - $this->request($method, $arguments); - return $this->parsed_response ? $this->parsed_response : false; - } - - /* - These functions are the direct implementations of flickr calls. - For method documentation, including arguments, visit the address - included in a comment in the function. - */ - - /* Activity methods */ - function activity_userComments ($per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.activity.userComments.html */ - $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page)); - return $this->parsed_response ? $this->parsed_response['items']['item'] : false; - } - - function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.activity.userPhotos.html */ - $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page)); - return $this->parsed_response ? $this->parsed_response['items']['item'] : false; - } - - /* Authentication methods */ - function auth_checkToken () - { - /* http://www.flickr.com/services/api/flickr.auth.checkToken.html */ - $this->request('flickr.auth.checkToken'); - return $this->parsed_response ? $this->parsed_response['auth'] : false; - } - - function auth_getFrob () - { - /* http://www.flickr.com/services/api/flickr.auth.getFrob.html */ - $this->request('flickr.auth.getFrob'); - return $this->parsed_response ? $this->parsed_response['frob'] : false; - } - - function auth_getFullToken ($mini_token) - { - /* http://www.flickr.com/services/api/flickr.auth.getFullToken.html */ - $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token)); - return $this->parsed_response ? $this->parsed_response['auth'] : false; - } - - function auth_getToken ($frob) - { + $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms); + if ($this->service == "23") { + header("Location: http://www.23hq.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig); + } else { + //header("Location: http://www.flickr.com/services/auth/?api_key=" . $this->api_key . "&extra=" . $redirect . "&perms=" . $perms . "&api_sig=". $api_sig); + echo 'Login'; + } + //exit; + } else { + $tmp = $this->die_on_error; + $this->die_on_error = false; + $rsp = $this->auth_checkToken(); + if ($this->error_code !== false) { + unset($SESSION->phpFlickr_auth_token); + $this->auth($perms, $remember_uri); + } + $this->die_on_error = $tmp; + return $rsp['perms']; + } + } + + /******************************* + + To use the phpFlickr::call method, pass a string containing the API method you want + to use and an associative array of arguments. For example: + $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612')); + This method will allow you to make calls to arbitrary methods that haven't been + implemented in phpFlickr yet. + + *******************************/ + + function call($method, $arguments) + { + $this->request($method, $arguments); + return $this->parsed_response ? $this->parsed_response : false; + } + + /* + These functions are the direct implementations of flickr calls. + For method documentation, including arguments, visit the address + included in a comment in the function. + */ + + /* Activity methods */ + function activity_userComments ($per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.activity.userComments.html */ + $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page)); + return $this->parsed_response ? $this->parsed_response['items']['item'] : false; + } + + function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.activity.userPhotos.html */ + $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page)); + return $this->parsed_response ? $this->parsed_response['items']['item'] : false; + } + + /* Authentication methods */ + function auth_checkToken () + { + /* http://www.flickr.com/services/api/flickr.auth.checkToken.html */ + $this->request('flickr.auth.checkToken'); + return $this->parsed_response ? $this->parsed_response['auth'] : false; + } + + function auth_getFrob () + { + /* http://www.flickr.com/services/api/flickr.auth.getFrob.html */ + $this->request('flickr.auth.getFrob'); + return $this->parsed_response ? $this->parsed_response['frob'] : false; + } + + function auth_getFullToken ($mini_token) + { + /* http://www.flickr.com/services/api/flickr.auth.getFullToken.html */ + $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token)); + return $this->parsed_response ? $this->parsed_response['auth'] : false; + } + + function auth_getToken ($frob) + { global $SESSION; - /* http://www.flickr.com/services/api/flickr.auth.getToken.html */ - $this->request('flickr.auth.getToken', array('frob'=>$frob)); - $SESSION->phpFlickr_auth_token = $this->parsed_response['auth']['token']; - return $this->parsed_response ? $this->parsed_response['auth'] : false; - } - - /* Blogs methods */ - function blogs_getList () - { - /* http://www.flickr.com/services/api/flickr.blogs.getList.html */ - $this->request('flickr.blogs.getList'); - return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false; - } - - function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL) - { - /* http://www.flickr.com/services/api/flickr.blogs.postPhoto.html */ - $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE); - return $this->parsed_response ? true : false; - } - - /* Contacts Methods */ - function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL) - { - /* http://www.flickr.com/services/api/flickr.contacts.getList.html */ - $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page)); - return $this->parsed_response ? $this->parsed_response['contacts'] : false; - } - - function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL) - { - /* http://www.flickr.com/services/api/flickr.contacts.getPublicList.html */ - $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page)); - return $this->parsed_response ? $this->parsed_response['contacts'] : false; - } - - /* Favorites Methods */ - function favorites_add ($photo_id) - { - /* http://www.flickr.com/services/api/flickr.favorites.add.html */ - $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.favorites.getList.html */ - if (is_array($extras)) { $extras = implode(",", $extras); } - $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function favorites_remove($photo_id) - { - /* http://www.flickr.com/services/api/flickr.favorites.remove.html */ - $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - /* Groups Methods */ - function groups_browse ($cat_id = NULL) - { - /* http://www.flickr.com/services/api/flickr.groups.browse.html */ - $this->request("flickr.groups.browse", array("cat_id"=>$cat_id)); - return $this->parsed_response ? $this->parsed_response['category'] : false; - } - - function groups_getInfo ($group_id) - { - /* http://www.flickr.com/services/api/flickr.groups.getInfo.html */ - $this->request("flickr.groups.getInfo", array("group_id"=>$group_id)); - return $this->parsed_response ? $this->parsed_response['group'] : false; - } - - function groups_search ($text, $per_page=NULL, $page=NULL) - { - /* http://www.flickr.com/services/api/flickr.groups.search.html */ - $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page)); - return $this->parsed_response ? $this->parsed_response['groups'] : false; - } - - /* Groups Pools Methods */ - function groups_pools_add ($photo_id, $group_id) - { - /* http://www.flickr.com/services/api/flickr.groups.pools.add.html */ - $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); - return $this->parsed_response ? true : false; - } - - function groups_pools_getContext ($photo_id, $group_id) - { - /* http://www.flickr.com/services/api/flickr.groups.pools.getContext.html */ - $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id)); - return $this->parsed_response ? $this->parsed_response : false; - } - - function groups_pools_getGroups ($page = NULL, $per_page = NULL) - { - /* http://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */ - $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page)); - return $this->parsed_response ? $this->parsed_response['groups'] : false; - } - - function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $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)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function groups_pools_remove ($photo_id, $group_id) - { - /* http://www.flickr.com/services/api/flickr.groups.pools.remove.html */ - $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); - return $this->parsed_response ? true : false; - } - - /* Interestingness methods */ - function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.interestingness.getList.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - - $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - /* People methods */ - function people_findByEmail ($find_email) - { - /* http://www.flickr.com/services/api/flickr.people.findByEmail.html */ - $this->request("flickr.people.findByEmail", array("find_email"=>$find_email)); - return $this->parsed_response ? $this->parsed_response['user'] : false; - } - - function people_findByUsername ($username) - { - /* http://www.flickr.com/services/api/flickr.people.findByUsername.html */ - $this->request("flickr.people.findByUsername", array("username"=>$username)); - return $this->parsed_response ? $this->parsed_response['user'] : false; - } - - function people_getInfo($user_id) - { - /* http://www.flickr.com/services/api/flickr.people.getInfo.html */ - $this->request("flickr.people.getInfo", array("user_id"=>$user_id)); - return $this->parsed_response ? $this->parsed_response['person'] : false; - } - - function people_getPublicGroups($user_id) - { - /* http://www.flickr.com/services/api/flickr.people.getPublicGroups.html */ - $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id)); - return $this->parsed_response ? $this->parsed_response['groups']['group'] : false; - } - - function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) { - /* http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - - $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function people_getUploadStatus() - { - /* http://www.flickr.com/services/api/flickr.people.getUploadStatus.html */ - /* Requires Authentication */ - $this->request("flickr.people.getUploadStatus"); - return $this->parsed_response ? $this->parsed_response['user'] : false; - } - - - /* Photos Methods */ - function photos_addTags ($photo_id, $tags) - { - /* http://www.flickr.com/services/api/flickr.photos.addTags.html */ - $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_delete($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.delete.html */ - $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_getAllContexts ($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.getAllContexts.html */ - $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response : false; - } - - function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */ - $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras)); - return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; - } - - function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */ - $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)); - return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; - } - - function photos_getContext ($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.getContext.html */ - $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response : false; - } - - function photos_getCounts ($dates = NULL, $taken_dates = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getCounts.html */ - $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates)); - return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false; - } - - function photos_getExif ($photo_id, $secret = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getExif.html */ - $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret)); - return $this->parsed_response ? $this->parsed_response['photo'] : false; - } - - function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getFavorites.html */ - $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page)); - return $this->parsed_response ? $this->parsed_response['photo'] : false; - } - - function photos_getInfo($photo_id, $secret = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getInfo.html */ - $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret)); - return $this->parsed_response ? $this->parsed_response['photo'] : false; - } - - 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) - { - /* http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $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)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_getPerms($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.getPerms.html */ - $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response['perms'] : false; - } - - function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getRecent.html */ - - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_getSizes($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.getSizes.html */ - $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false; - } - - 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) - { - /* http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $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)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_getWithGeoData($args = NULL) { - /* See the documentation included with the photos_search() function. - * I'm using the same style of arguments for this function. The only - * difference here is that this doesn't require any arguments. The - * flickr.photos.search method requires at least one search parameter. - */ - /* http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */ - if (is_null($args)) { - $args = array(); - } - $this->request("flickr.photos.getWithGeoData", $args); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_getWithoutGeoData($args = NULL) { - /* See the documentation included with the photos_search() function. - * I'm using the same style of arguments for this function. The only - * difference here is that this doesn't require any arguments. The - * flickr.photos.search method requires at least one search parameter. - */ - /* http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */ - if (is_null($args)) { - $args = array(); - } - $this->request("flickr.photos.getWithoutGeoData", $args); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ - if (is_array($extras)) { - $extras = implode(",", $extras); - } - $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_removeTag($tag_id) - { - /* http://www.flickr.com/services/api/flickr.photos.removeTag.html */ - $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_search($args) - { - /* This function strays from the method of arguments that I've - * used in the other functions for the fact that there are just - * so many arguments to this API method. What you'll need to do - * is pass an associative array to the function containing the - * arguments you want to pass to the API. For example: - * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any")); - * This will return photos tagged with either "brown" or "cow" - * or both. See the API documentation (link below) for a full - * list of arguments. - */ - - /* http://www.flickr.com/services/api/flickr.photos.search.html */ - $this->request("flickr.photos.search", $args); - return $this->parsed_response ? $this->parsed_response['photos'] : false; - } - - function photos_setContentType ($photo_id, $content_type) { - /* http://www.flickr.com/services/api/flickr.photos.setContentType.html */ - return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type)); - } - - function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.setDates.html */ - $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); - return $this->parsed_response ? true : false; - } - - function photos_setMeta($photo_id, $title, $description) - { - /* http://www.flickr.com/services/api/flickr.photos.setMeta.html */ - $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta) - { - /* http://www.flickr.com/services/api/flickr.photos.setPerms.html */ - $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); - return $this->parsed_response ? true : false; - } - - function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) { - /* http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */ - return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden)); - } - - - function photos_setTags($photo_id, $tags) - { - /* http://www.flickr.com/services/api/flickr.photos.setTags.html */ - $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); - return $this->parsed_response ? true : false; - } - - /* Photos - Comments Methods */ - function photos_comments_addComment($photo_id, $comment_text) { - /* http://www.flickr.com/services/api/flickr.photos.comments.addComment.html */ - $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE); - return $this->parsed_response ? $this->parsed_response['comment'] : false; - } - - function photos_comments_deleteComment($comment_id) { - /* http://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */ - $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_comments_editComment($comment_id, $comment_text) { - /* http://www.flickr.com/services/api/flickr.photos.comments.editComment.html */ - $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_comments_getList($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.comments.getList.html */ - $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response['comments'] : false; - } - - /* Photos - Geo Methods */ - function photos_geo_getLocation($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */ - $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response['photo'] : false; - } - - function photos_geo_getPerms($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */ - $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id)); - return $this->parsed_response ? $this->parsed_response['perms'] : false; - } - - function photos_geo_removeLocation($photo_id) - { - /* http://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */ - $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL) - { - /* http://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */ - $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family) - { - /* http://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */ - $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); - return $this->parsed_response ? true : false; - } - - /* Photos - Licenses Methods */ - function photos_licenses_getInfo() - { - /* http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */ - $this->request("flickr.photos.licenses.getInfo"); - return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false; - } - - function photos_licenses_setLicense($photo_id, $license_id) - { - /* http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */ - /* Requires Authentication */ - $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE); - return $this->parsed_response ? true : false; - } - - /* Photos - Notes Methods */ - function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text) - { - /* http://www.flickr.com/services/api/flickr.photos.notes.add.html */ - $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); - return $this->parsed_response ? $this->parsed_response['note'] : false; - } - - function photos_notes_delete($note_id) - { - /* http://www.flickr.com/services/api/flickr.photos.notes.delete.html */ - $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text) - { - /* http://www.flickr.com/services/api/flickr.photos.notes.edit.html */ - $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); - return $this->parsed_response ? true : false; - } - - /* Photos - Transform Methods */ - function photos_transform_rotate($photo_id, $degrees) - { - /* http://www.flickr.com/services/api/flickr.photos.transform.rotate.html */ - $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE); - return $this->parsed_response ? true : false; - } - - /* Photos - Upload Methods */ - function photos_upload_checkTickets($tickets) - { - /* http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */ - if (is_array($tickets)) { - $tickets = implode(",", $tickets); - } - $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE); - return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false; - } - - /* Photosets Methods */ - function photosets_addPhoto($photoset_id, $photo_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.addPhoto.html */ - $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_create($title, $description, $primary_photo_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.create.html */ - $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE); - return $this->parsed_response ? $this->parsed_response['photoset'] : false; - } - - function photosets_delete($photoset_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.delete.html */ - $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_editMeta($photoset_id, $title, $description = NULL) - { - /* http://www.flickr.com/services/api/flickr.photosets.editMeta.html */ - $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids) - { - /* http://www.flickr.com/services/api/flickr.photosets.editPhotos.html */ - $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_getContext($photo_id, $photoset_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.getContext.html */ - $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id)); - return $this->parsed_response ? $this->parsed_response : false; - } - - function photosets_getInfo($photoset_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.getInfo.html */ - $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id)); - return $this->parsed_response ? $this->parsed_response['photoset'] : false; - } - - function photosets_getList($user_id = NULL) - { - /* http://www.flickr.com/services/api/flickr.photosets.getList.html */ - $this->request("flickr.photosets.getList", array("user_id" => $user_id)); - return $this->parsed_response ? $this->parsed_response['photosets'] : false; - } - - function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL) - { - /* http://www.flickr.com/services/api/flickr.photosets.getPhotos.html */ - $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page)); - return $this->parsed_response ? $this->parsed_response['photoset'] : false; - } - - function photosets_orderSets($photoset_ids) - { - /* http://www.flickr.com/services/api/flickr.photosets.orderSets.html */ - if (is_array($photoset_ids)) { - $photoset_ids = implode(",", $photoset_ids); - } - $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_removePhoto($photoset_id, $photo_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.removePhoto.html */ - $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); - return $this->parsed_response ? true : false; - } - - /* Photosets Comments Methods */ - function photosets_comments_addComment($photoset_id, $comment_text) { - /* http://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */ - $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE); - return $this->parsed_response ? $this->parsed_response['comment'] : false; - } - - function photosets_comments_deleteComment($comment_id) { - /* http://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */ - $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_comments_editComment($comment_id, $comment_text) { - /* http://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */ - $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); - return $this->parsed_response ? true : false; - } - - function photosets_comments_getList($photoset_id) - { - /* http://www.flickr.com/services/api/flickr.photosets.comments.getList.html */ - $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id)); - return $this->parsed_response ? $this->parsed_response['comments'] : false; - } - - /* Places Methods */ - function places_resolvePlaceId ($place_id) { - /* http://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */ - $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id)); - return $rsp ? $rsp['location'] : $rsp; - } - - function places_resolvePlaceURL ($url) { - /* http://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */ - $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url)); - return $rsp ? $rsp['location'] : $rsp; - } - - /* Prefs Methods */ - function prefs_getContentType () { - /* http://www.flickr.com/services/api/flickr.prefs.getContentType.html */ - $rsp = $this->call('flickr.prefs.getContentType', array()); - return $rsp ? $rsp['person'] : $rsp; - } - - function prefs_getHidden () { - /* http://www.flickr.com/services/api/flickr.prefs.getHidden.html */ - $rsp = $this->call('flickr.prefs.getHidden', array()); - return $rsp ? $rsp['person'] : $rsp; - } - - function prefs_getPrivacy () { - /* http://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */ - $rsp = $this->call('flickr.prefs.getPrivacy', array()); - return $rsp ? $rsp['person'] : $rsp; - } - - function prefs_getSafetyLevel () { - /* http://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */ - $rsp = $this->call('flickr.prefs.getSafetyLevel', array()); - return $rsp ? $rsp['person'] : $rsp; - } - - /* Reflection Methods */ - function reflection_getMethodInfo($method_name) - { - /* http://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */ - $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name)); - return $this->parsed_response ? $this->parsed_response : false; - } - - function reflection_getMethods() - { - /* http://www.flickr.com/services/api/flickr.reflection.getMethods.html */ - $this->request("flickr.reflection.getMethods"); - return $this->parsed_response ? $this->parsed_response['methods']['method'] : false; - } - - /* Tags Methods */ - function tags_getHotList($period = NULL, $count = NULL) - { - /* http://www.flickr.com/services/api/flickr.tags.getHotList.html */ - $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count)); - return $this->parsed_response ? $this->parsed_response['hottags'] : false; - } - - function tags_getListPhoto($photo_id) - { - /* http://www.flickr.com/services/api/flickr.tags.getListPhoto.html */ - $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id)); - return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false; - } - - function tags_getListUser($user_id = NULL) - { - /* http://www.flickr.com/services/api/flickr.tags.getListUser.html */ - $this->request("flickr.tags.getListUser", array("user_id" => $user_id)); - return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; - } - - function tags_getListUserPopular($user_id = NULL, $count = NULL) - { - /* http://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */ - $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count)); - return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; - } - - function tags_getListUserRaw($tag) - { - /* http://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */ - $this->request("flickr.tags.getListUserRaw", array("tag" => $tag)); - return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false; - } - - function tags_getRelated($tag) - { - /* http://www.flickr.com/services/api/flickr.tags.getRelated.html */ - $this->request("flickr.tags.getRelated", array("tag" => $tag)); - return $this->parsed_response ? $this->parsed_response['tags'] : false; - } - - function test_echo($args = array()) - { - /* http://www.flickr.com/services/api/flickr.test.echo.html */ - $this->request("flickr.test.echo", $args); - return $this->parsed_response ? $this->parsed_response : false; - } - - function test_login() - { - /* http://www.flickr.com/services/api/flickr.test.login.html */ - $this->request("flickr.test.login"); - return $this->parsed_response ? $this->parsed_response['user'] : false; - } - - function urls_getGroup($group_id) - { - /* http://www.flickr.com/services/api/flickr.urls.getGroup.html */ - $this->request("flickr.urls.getGroup", array("group_id"=>$group_id)); - return $this->parsed_response ? $this->parsed_response['group']['url'] : false; - } - - function urls_getUserPhotos($user_id = NULL) - { - /* http://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */ - $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id)); - return $this->parsed_response ? $this->parsed_response['user']['url'] : false; - } - - function urls_getUserProfile($user_id = NULL) - { - /* http://www.flickr.com/services/api/flickr.urls.getUserProfile.html */ - $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id)); - return $this->parsed_response ? $this->parsed_response['user']['url'] : false; - } - - function urls_lookupGroup($url) - { - /* http://www.flickr.com/services/api/flickr.urls.lookupGroup.html */ - $this->request("flickr.urls.lookupGroup", array("url"=>$url)); - return $this->parsed_response ? $this->parsed_response['group'] : false; - } - - function urls_lookupUser($url) - { - /* http://www.flickr.com/services/api/flickr.photos.notes.edit.html */ - $this->request("flickr.urls.lookupUser", array("url"=>$url)); - return $this->parsed_response ? $this->parsed_response['user'] : false; - } + /* http://www.flickr.com/services/api/flickr.auth.getToken.html */ + $this->request('flickr.auth.getToken', array('frob'=>$frob)); + $SESSION->phpFlickr_auth_token = $this->parsed_response['auth']['token']; + return $this->parsed_response ? $this->parsed_response['auth'] : false; + } + + /* Blogs methods */ + function blogs_getList () + { + /* http://www.flickr.com/services/api/flickr.blogs.getList.html */ + $this->request('flickr.blogs.getList'); + return $this->parsed_response ? $this->parsed_response['blogs']['blog'] : false; + } + + function blogs_postPhoto($blog_id, $photo_id, $title, $description, $blog_password = NULL) + { + /* http://www.flickr.com/services/api/flickr.blogs.postPhoto.html */ + $this->request('flickr.blogs.postPhoto', array('blog_id'=>$blog_id, 'photo_id'=>$photo_id, 'title'=>$title, 'description'=>$description, 'blog_password'=>$blog_password), TRUE); + return $this->parsed_response ? true : false; + } + + /* Contacts Methods */ + function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL) + { + /* http://www.flickr.com/services/api/flickr.contacts.getList.html */ + $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page)); + return $this->parsed_response ? $this->parsed_response['contacts'] : false; + } + + function contacts_getPublicList($user_id, $page = NULL, $per_page = NULL) + { + /* http://www.flickr.com/services/api/flickr.contacts.getPublicList.html */ + $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page)); + return $this->parsed_response ? $this->parsed_response['contacts'] : false; + } + + /* Favorites Methods */ + function favorites_add ($photo_id) + { + /* http://www.flickr.com/services/api/flickr.favorites.add.html */ + $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + function favorites_getList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.favorites.getList.html */ + if (is_array($extras)) { $extras = implode(",", $extras); } + $this->request("flickr.favorites.getList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function favorites_getPublicList($user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.favorites.getPublicList.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $this->request("flickr.favorites.getPublicList", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function favorites_remove($photo_id) + { + /* http://www.flickr.com/services/api/flickr.favorites.remove.html */ + $this->request("flickr.favorites.remove", array("photo_id"=>$photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + /* Groups Methods */ + function groups_browse ($cat_id = NULL) + { + /* http://www.flickr.com/services/api/flickr.groups.browse.html */ + $this->request("flickr.groups.browse", array("cat_id"=>$cat_id)); + return $this->parsed_response ? $this->parsed_response['category'] : false; + } + + function groups_getInfo ($group_id) + { + /* http://www.flickr.com/services/api/flickr.groups.getInfo.html */ + $this->request("flickr.groups.getInfo", array("group_id"=>$group_id)); + return $this->parsed_response ? $this->parsed_response['group'] : false; + } + + function groups_search ($text, $per_page=NULL, $page=NULL) + { + /* http://www.flickr.com/services/api/flickr.groups.search.html */ + $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page)); + return $this->parsed_response ? $this->parsed_response['groups'] : false; + } + + /* Groups Pools Methods */ + function groups_pools_add ($photo_id, $group_id) + { + /* http://www.flickr.com/services/api/flickr.groups.pools.add.html */ + $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); + return $this->parsed_response ? true : false; + } + + function groups_pools_getContext ($photo_id, $group_id) + { + /* http://www.flickr.com/services/api/flickr.groups.pools.getContext.html */ + $this->request("flickr.groups.pools.getContext", array("photo_id"=>$photo_id, "group_id"=>$group_id)); + return $this->parsed_response ? $this->parsed_response : false; + } + + function groups_pools_getGroups ($page = NULL, $per_page = NULL) + { + /* http://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */ + $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page)); + return $this->parsed_response ? $this->parsed_response['groups'] : false; + } + + function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $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)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function groups_pools_remove ($photo_id, $group_id) + { + /* http://www.flickr.com/services/api/flickr.groups.pools.remove.html */ + $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); + return $this->parsed_response ? true : false; + } + + /* Interestingness methods */ + function interestingness_getList($date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.interestingness.getList.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + + $this->request("flickr.interestingness.getList", array("date"=>$date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + /* People methods */ + function people_findByEmail ($find_email) + { + /* http://www.flickr.com/services/api/flickr.people.findByEmail.html */ + $this->request("flickr.people.findByEmail", array("find_email"=>$find_email)); + return $this->parsed_response ? $this->parsed_response['user'] : false; + } + + function people_findByUsername ($username) + { + /* http://www.flickr.com/services/api/flickr.people.findByUsername.html */ + $this->request("flickr.people.findByUsername", array("username"=>$username)); + return $this->parsed_response ? $this->parsed_response['user'] : false; + } + + function people_getInfo($user_id) + { + /* http://www.flickr.com/services/api/flickr.people.getInfo.html */ + $this->request("flickr.people.getInfo", array("user_id"=>$user_id)); + return $this->parsed_response ? $this->parsed_response['person'] : false; + } + + function people_getPublicGroups($user_id) + { + /* http://www.flickr.com/services/api/flickr.people.getPublicGroups.html */ + $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id)); + return $this->parsed_response ? $this->parsed_response['groups']['group'] : false; + } + + function people_getPublicPhotos($user_id, $extras = NULL, $per_page = NULL, $page = NULL) { + /* http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + + $this->request("flickr.people.getPublicPhotos", array("user_id"=>$user_id, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function people_getUploadStatus() + { + /* http://www.flickr.com/services/api/flickr.people.getUploadStatus.html */ + /* Requires Authentication */ + $this->request("flickr.people.getUploadStatus"); + return $this->parsed_response ? $this->parsed_response['user'] : false; + } + + + /* Photos Methods */ + function photos_addTags ($photo_id, $tags) + { + /* http://www.flickr.com/services/api/flickr.photos.addTags.html */ + $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_delete($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.delete.html */ + $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_getAllContexts ($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.getAllContexts.html */ + $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response : false; + } + + function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */ + $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras)); + return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; + } + + function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */ + $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)); + return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; + } + + function photos_getContext ($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.getContext.html */ + $this->request("flickr.photos.getContext", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response : false; + } + + function photos_getCounts ($dates = NULL, $taken_dates = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getCounts.html */ + $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates)); + return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false; + } + + function photos_getExif ($photo_id, $secret = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getExif.html */ + $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret)); + return $this->parsed_response ? $this->parsed_response['photo'] : false; + } + + function photos_getFavorites($photo_id, $page = NULL, $per_page = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getFavorites.html */ + $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page)); + return $this->parsed_response ? $this->parsed_response['photo'] : false; + } + + function photos_getInfo($photo_id, $secret = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getInfo.html */ + $this->request("flickr.photos.getInfo", array("photo_id"=>$photo_id, "secret"=>$secret)); + return $this->parsed_response ? $this->parsed_response['photo'] : false; + } + + 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) + { + /* http://www.flickr.com/services/api/flickr.photos.getNotInSet.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $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)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_getPerms($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.getPerms.html */ + $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response['perms'] : false; + } + + function photos_getRecent($extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getRecent.html */ + + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $this->request("flickr.photos.getRecent", array("extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_getSizes($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.getSizes.html */ + $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false; + } + + 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) + { + /* http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $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)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_getWithGeoData($args = NULL) { + /* See the documentation included with the photos_search() function. + * I'm using the same style of arguments for this function. The only + * difference here is that this doesn't require any arguments. The + * flickr.photos.search method requires at least one search parameter. + */ + /* http://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */ + if (is_null($args)) { + $args = array(); + } + $this->request("flickr.photos.getWithGeoData", $args); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_getWithoutGeoData($args = NULL) { + /* See the documentation included with the photos_search() function. + * I'm using the same style of arguments for this function. The only + * difference here is that this doesn't require any arguments. The + * flickr.photos.search method requires at least one search parameter. + */ + /* http://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */ + if (is_null($args)) { + $args = array(); + } + $this->request("flickr.photos.getWithoutGeoData", $args); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_recentlyUpdated($min_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.getUntagged.html */ + if (is_array($extras)) { + $extras = implode(",", $extras); + } + $this->request("flickr.photos.recentlyUpdated", array("min_date"=>$min_date, "extras"=>$extras, "per_page"=>$per_page, "page"=>$page)); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_removeTag($tag_id) + { + /* http://www.flickr.com/services/api/flickr.photos.removeTag.html */ + $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_search($args) + { + /* This function strays from the method of arguments that I've + * used in the other functions for the fact that there are just + * so many arguments to this API method. What you'll need to do + * is pass an associative array to the function containing the + * arguments you want to pass to the API. For example: + * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any")); + * This will return photos tagged with either "brown" or "cow" + * or both. See the API documentation (link below) for a full + * list of arguments. + */ + + /* http://www.flickr.com/services/api/flickr.photos.search.html */ + $this->request("flickr.photos.search", $args); + return $this->parsed_response ? $this->parsed_response['photos'] : false; + } + + function photos_setContentType ($photo_id, $content_type) { + /* http://www.flickr.com/services/api/flickr.photos.setContentType.html */ + return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type)); + } + + function photos_setDates($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.setDates.html */ + $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); + return $this->parsed_response ? true : false; + } + + function photos_setMeta($photo_id, $title, $description) + { + /* http://www.flickr.com/services/api/flickr.photos.setMeta.html */ + $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_setPerms($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta) + { + /* http://www.flickr.com/services/api/flickr.photos.setPerms.html */ + $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); + return $this->parsed_response ? true : false; + } + + function photos_setSafetyLevel ($photo_id, $safety_level, $hidden = null) { + /* http://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */ + return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden)); + } + + + function photos_setTags($photo_id, $tags) + { + /* http://www.flickr.com/services/api/flickr.photos.setTags.html */ + $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); + return $this->parsed_response ? true : false; + } + + /* Photos - Comments Methods */ + function photos_comments_addComment($photo_id, $comment_text) { + /* http://www.flickr.com/services/api/flickr.photos.comments.addComment.html */ + $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE); + return $this->parsed_response ? $this->parsed_response['comment'] : false; + } + + function photos_comments_deleteComment($comment_id) { + /* http://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */ + $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_comments_editComment($comment_id, $comment_text) { + /* http://www.flickr.com/services/api/flickr.photos.comments.editComment.html */ + $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_comments_getList($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.comments.getList.html */ + $this->request("flickr.photos.comments.getList", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response['comments'] : false; + } + + /* Photos - Geo Methods */ + function photos_geo_getLocation($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */ + $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response['photo'] : false; + } + + function photos_geo_getPerms($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */ + $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id)); + return $this->parsed_response ? $this->parsed_response['perms'] : false; + } + + function photos_geo_removeLocation($photo_id) + { + /* http://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */ + $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_geo_setLocation($photo_id, $lat, $lon, $accuracy = NULL) + { + /* http://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */ + $this->request("flickr.photos.geo.setLocation", array("photo_id"=>$photo_id, "lat"=>$lat, "lon"=>$lon, "accuracy"=>$accuracy), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_geo_setPerms($photo_id, $is_public, $is_contact, $is_friend, $is_family) + { + /* http://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */ + $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); + return $this->parsed_response ? true : false; + } + + /* Photos - Licenses Methods */ + function photos_licenses_getInfo() + { + /* http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */ + $this->request("flickr.photos.licenses.getInfo"); + return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false; + } + + function photos_licenses_setLicense($photo_id, $license_id) + { + /* http://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */ + /* Requires Authentication */ + $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE); + return $this->parsed_response ? true : false; + } + + /* Photos - Notes Methods */ + function photos_notes_add($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text) + { + /* http://www.flickr.com/services/api/flickr.photos.notes.add.html */ + $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); + return $this->parsed_response ? $this->parsed_response['note'] : false; + } + + function photos_notes_delete($note_id) + { + /* http://www.flickr.com/services/api/flickr.photos.notes.delete.html */ + $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photos_notes_edit($note_id, $note_x, $note_y, $note_w, $note_h, $note_text) + { + /* http://www.flickr.com/services/api/flickr.photos.notes.edit.html */ + $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); + return $this->parsed_response ? true : false; + } + + /* Photos - Transform Methods */ + function photos_transform_rotate($photo_id, $degrees) + { + /* http://www.flickr.com/services/api/flickr.photos.transform.rotate.html */ + $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE); + return $this->parsed_response ? true : false; + } + + /* Photos - Upload Methods */ + function photos_upload_checkTickets($tickets) + { + /* http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */ + if (is_array($tickets)) { + $tickets = implode(",", $tickets); + } + $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE); + return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false; + } + + /* Photosets Methods */ + function photosets_addPhoto($photoset_id, $photo_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.addPhoto.html */ + $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_create($title, $description, $primary_photo_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.create.html */ + $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE); + return $this->parsed_response ? $this->parsed_response['photoset'] : false; + } + + function photosets_delete($photoset_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.delete.html */ + $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_editMeta($photoset_id, $title, $description = NULL) + { + /* http://www.flickr.com/services/api/flickr.photosets.editMeta.html */ + $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_editPhotos($photoset_id, $primary_photo_id, $photo_ids) + { + /* http://www.flickr.com/services/api/flickr.photosets.editPhotos.html */ + $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_getContext($photo_id, $photoset_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.getContext.html */ + $this->request("flickr.photosets.getContext", array("photo_id" => $photo_id, "photoset_id" => $photoset_id)); + return $this->parsed_response ? $this->parsed_response : false; + } + + function photosets_getInfo($photoset_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.getInfo.html */ + $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id)); + return $this->parsed_response ? $this->parsed_response['photoset'] : false; + } + + function photosets_getList($user_id = NULL) + { + /* http://www.flickr.com/services/api/flickr.photosets.getList.html */ + $this->request("flickr.photosets.getList", array("user_id" => $user_id)); + return $this->parsed_response ? $this->parsed_response['photosets'] : false; + } + + function photosets_getPhotos($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL) + { + /* http://www.flickr.com/services/api/flickr.photosets.getPhotos.html */ + $this->request("flickr.photosets.getPhotos", array("photoset_id" => $photoset_id, "extras" => $extras, "privacy_filter" => $privacy_filter, "per_page" => $per_page, "page" => $page)); + return $this->parsed_response ? $this->parsed_response['photoset'] : false; + } + + function photosets_orderSets($photoset_ids) + { + /* http://www.flickr.com/services/api/flickr.photosets.orderSets.html */ + if (is_array($photoset_ids)) { + $photoset_ids = implode(",", $photoset_ids); + } + $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_removePhoto($photoset_id, $photo_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.removePhoto.html */ + $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); + return $this->parsed_response ? true : false; + } + + /* Photosets Comments Methods */ + function photosets_comments_addComment($photoset_id, $comment_text) { + /* http://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */ + $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE); + return $this->parsed_response ? $this->parsed_response['comment'] : false; + } + + function photosets_comments_deleteComment($comment_id) { + /* http://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */ + $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_comments_editComment($comment_id, $comment_text) { + /* http://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */ + $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); + return $this->parsed_response ? true : false; + } + + function photosets_comments_getList($photoset_id) + { + /* http://www.flickr.com/services/api/flickr.photosets.comments.getList.html */ + $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id)); + return $this->parsed_response ? $this->parsed_response['comments'] : false; + } + + /* Places Methods */ + function places_resolvePlaceId ($place_id) { + /* http://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */ + $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id)); + return $rsp ? $rsp['location'] : $rsp; + } + + function places_resolvePlaceURL ($url) { + /* http://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */ + $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url)); + return $rsp ? $rsp['location'] : $rsp; + } + + /* Prefs Methods */ + function prefs_getContentType () { + /* http://www.flickr.com/services/api/flickr.prefs.getContentType.html */ + $rsp = $this->call('flickr.prefs.getContentType', array()); + return $rsp ? $rsp['person'] : $rsp; + } + + function prefs_getHidden () { + /* http://www.flickr.com/services/api/flickr.prefs.getHidden.html */ + $rsp = $this->call('flickr.prefs.getHidden', array()); + return $rsp ? $rsp['person'] : $rsp; + } + + function prefs_getPrivacy () { + /* http://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */ + $rsp = $this->call('flickr.prefs.getPrivacy', array()); + return $rsp ? $rsp['person'] : $rsp; + } + + function prefs_getSafetyLevel () { + /* http://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */ + $rsp = $this->call('flickr.prefs.getSafetyLevel', array()); + return $rsp ? $rsp['person'] : $rsp; + } + + /* Reflection Methods */ + function reflection_getMethodInfo($method_name) + { + /* http://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */ + $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name)); + return $this->parsed_response ? $this->parsed_response : false; + } + + function reflection_getMethods() + { + /* http://www.flickr.com/services/api/flickr.reflection.getMethods.html */ + $this->request("flickr.reflection.getMethods"); + return $this->parsed_response ? $this->parsed_response['methods']['method'] : false; + } + + /* Tags Methods */ + function tags_getHotList($period = NULL, $count = NULL) + { + /* http://www.flickr.com/services/api/flickr.tags.getHotList.html */ + $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count)); + return $this->parsed_response ? $this->parsed_response['hottags'] : false; + } + + function tags_getListPhoto($photo_id) + { + /* http://www.flickr.com/services/api/flickr.tags.getListPhoto.html */ + $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id)); + return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false; + } + + function tags_getListUser($user_id = NULL) + { + /* http://www.flickr.com/services/api/flickr.tags.getListUser.html */ + $this->request("flickr.tags.getListUser", array("user_id" => $user_id)); + return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; + } + + function tags_getListUserPopular($user_id = NULL, $count = NULL) + { + /* http://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */ + $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count)); + return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; + } + + function tags_getListUserRaw($tag) + { + /* http://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */ + $this->request("flickr.tags.getListUserRaw", array("tag" => $tag)); + return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'][0]['raw'] : false; + } + + function tags_getRelated($tag) + { + /* http://www.flickr.com/services/api/flickr.tags.getRelated.html */ + $this->request("flickr.tags.getRelated", array("tag" => $tag)); + return $this->parsed_response ? $this->parsed_response['tags'] : false; + } + + function test_echo($args = array()) + { + /* http://www.flickr.com/services/api/flickr.test.echo.html */ + $this->request("flickr.test.echo", $args); + return $this->parsed_response ? $this->parsed_response : false; + } + + function test_login() + { + /* http://www.flickr.com/services/api/flickr.test.login.html */ + $this->request("flickr.test.login"); + return $this->parsed_response ? $this->parsed_response['user'] : false; + } + + function urls_getGroup($group_id) + { + /* http://www.flickr.com/services/api/flickr.urls.getGroup.html */ + $this->request("flickr.urls.getGroup", array("group_id"=>$group_id)); + return $this->parsed_response ? $this->parsed_response['group']['url'] : false; + } + + function urls_getUserPhotos($user_id = NULL) + { + /* http://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */ + $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id)); + return $this->parsed_response ? $this->parsed_response['user']['url'] : false; + } + + function urls_getUserProfile($user_id = NULL) + { + /* http://www.flickr.com/services/api/flickr.urls.getUserProfile.html */ + $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id)); + return $this->parsed_response ? $this->parsed_response['user']['url'] : false; + } + + function urls_lookupGroup($url) + { + /* http://www.flickr.com/services/api/flickr.urls.lookupGroup.html */ + $this->request("flickr.urls.lookupGroup", array("url"=>$url)); + return $this->parsed_response ? $this->parsed_response['group'] : false; + } + + function urls_lookupUser($url) + { + /* http://www.flickr.com/services/api/flickr.photos.notes.edit.html */ + $this->request("flickr.urls.lookupUser", array("url"=>$url)); + return $this->parsed_response ? $this->parsed_response['user'] : false; + } } diff --git a/repository/lib.php b/repository/lib.php index d304995005..8a04352e7b 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -26,7 +26,7 @@ /** * This is the base class of the repository class * - * To use repository plugin, you need to create a new folder under repository/, named as the remote + * To use repository plugin, you need to create a new folder under repository/, named as the remote * repository, the subclass must be defined in the name * @@ -35,8 +35,8 @@ * See an example of use of this library in repository/box/repository.class.php * * A few notes : - * // options are stored as serialized format in database - * $options = array('api_key'=>'dmls97d8j3i9tn7av8y71m9eb55vrtj4', + * // options are stored as serialized format in database + * $options = array('api_key'=>'dmls97d8j3i9tn7av8y71m9eb55vrtj4', * 'auth_token'=>'', 'path_root'=>'/'); * $repo = new repository_xxx($options); * // print login page or a link to redirect to another page @@ -154,7 +154,7 @@ abstract class repository { return $str; } } - + /** * Show the login screen, if required * This is an abstract function, it must be overriden. @@ -166,7 +166,7 @@ abstract class repository { * 3. Redirect to authentication page, in this case, the repository * will callback moodle with following common parameters: * (1) boolean callback To tell moodle this is a callback - * (2) int id Specify repository ID + * (2) int id Specify repository ID * The callback page need to use these parameters to init * the repository plug-ins correctly. Also, auth_token or ticket may * attach in the callback url, these must be taken into account too. @@ -309,13 +309,13 @@ function repository_get_plugins(){ $ret = array(); if($dir = opendir($repo)){ while (false !== ($file = readdir($dir))) { - if(is_dir($file) && $file != '.' && $file != '..' + if(is_dir($file) && $file != '.' && $file != '..' && file_exists($repo.$file.'/repository.class.php')){ require_once($repo.$file.'/version.php'); - $ret[] = array('name'=>$plugin->name, - 'version'=>$plugin->version, + $ret[] = array('name'=>$plugin->name, + 'version'=>$plugin->version, 'path'=>$repo.$file, - 'settings'=>file_exists($repo.$file.'/settings.php')); + 'settings'=>file_exists($repo.$file.'/settings.php')); } } } -- 2.39.5