├── LICENSE ├── README.md ├── auth.php ├── example.php ├── getToken.php └── phpFlickr.php /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notice 2 | 3 | This library was originally written for PHP 4 back in 2005. In the 4 | intervening years, I have stopped using PHP and stopped using Flickr. 5 | This package has gone unmaintained for much of that time. 6 | 7 | If someone has a burning desire to develop and maintain a replacement 8 | using a modern version of PHP and set it up for Composer, feel free to 9 | reach out to me on [Twitter](http://twitter.com/danco). 10 | 11 | [phpFlickr](https://github.com/dan-coulter/phpflickr) 12 | ===================================================== 13 | by [Dan Coulter](http://twitter.com/danco) 14 | 15 | A PHP wrapper for the Flickr API. 16 | 17 | Installation 18 | ============ 19 | 20 | 1. Copy the files from the installation package into a folder on your 21 | server. They need to be readable by your web server. You can put 22 | them into an include folder defined in your php.ini file, if you 23 | like, though it's not required. 24 | 25 | 2. All you have to do now is include the file in your PHP scripts and 26 | create an instance. For example: 27 | $f = new phpFlickr(); 28 | 29 | The constructor has three arguments: 30 | 1. $api_key - This is the API key given to you by flickr.com. This 31 | argument is required and you can get an API Key at: 32 | https://www.flickr.com/services/api/keys/ 33 | 34 | 2. $secret - The "secret" is optional because is not required to 35 | make unauthenticated calls, but is absolutely required for the 36 | new authentication API (see Authentication section below). You 37 | will get one assigned alongside your api key. 38 | 39 | 3. $die_on_error - This takes a boolean value and determines 40 | whether the class will die (aka cease operation) if the API 41 | returns an error statement. It defaults to false. Every method 42 | will return false if the API returns an error. You can access 43 | error messages using the getErrorCode() and getErrorMsg() 44 | methods. 45 | 46 | 3. All of the API methods have been implemented in my class. You can 47 | see a full list and documentation here: 48 | http://www.flickr.com/services/api/ 49 | To call a method, remove the "flickr." part of the name and replace 50 | any periods with underscores. For example, instead of 51 | flickr.photos.search, you would call $f->photos_search() or instead 52 | of flickr.photos.licenses.getInfo, you would call 53 | $f->photos_licenses_getInfo() (yes, it is case sensitive). 54 | 55 | All functions have their arguments implemented in the list order on 56 | their documentation page (a link to which is included with each 57 | method in the phpFlickr clasS). The only exceptions to this are 58 | photos_search(), photos_getWithoutGeodata() and 59 | photos_getWithoutGeodata() which have so many optional arguments 60 | that it's easier for everyone if you just have to pass an 61 | associative array of arguments. See the comment in the 62 | photos_search() definition in phpFlickr.php for more information. 63 | 64 | 65 | Authentication 66 | ============== 67 | As of this release of the phpFlickr class there is only one authentication method 68 | available to the API. This method is somewhat complex, but is far more secure and 69 | allows your users to feel a little safer authenticating to your application. You'll 70 | no longer have to ask for their username and password. 71 | 72 | [Flickr Authentication API](http://www.flickr.com/services/api/auth.spec.html) 73 | 74 | I know how complicated this API looks at first glance, so I've tried to 75 | make this as transparent to the coding process. I'll go through the steps 76 | you'll need to use this. Both the auth.php and getToken.php file will 77 | need your API Key and Secret entered before you can use them. 78 | 79 | To have end users authenticate their accounts: 80 | 1. setup a callback script. I've included a callback script that 81 | is pretty flexible. You'll find it in the package entitled "auth.php". 82 | 83 | You'll need to go to flickr and point your api key to this file as the 84 | callback script. Once you've done this, on any page that you want to 85 | require the end user end user to authenticate their flickr account to 86 | your app, just call the phpFlickr::auth() function with whatever 87 | permission you need to use. 88 | 89 | For example: 90 | $f->auth("write"); 91 | 92 | The three permissions are "read", "write" and "delete". The function 93 | defaults to "read", if you leave it blank. 94 | 95 | Calling this function will send the user's browser to Flickr's page to 96 | authenticate to your app. Once they have logged in, it will bounce 97 | them back to your callback script which will redirect back to the 98 | original page that you called the auth() function from after setting 99 | a session variable to save their authentication token. If that session 100 | variable exists, calling the auth() function will return the permissions 101 | that the user granted your app on the Flickr page instead of redirecting 102 | to an external page. 103 | 104 | 2. To authenticate the app to your account to show your private pictures (for example) 105 | 106 | This method will allow you to have the app authenticate to one specific 107 | account, no matter who views your website. This is useful to display 108 | private photos or photosets (among other things). 109 | 110 | *Note*: The method below is a little hard to understand, so I've setup a tool 111 | to help you through this: http://www.phpflickr.com/tools/auth/. 112 | 113 | First, you'll have to setup a callback script with Flickr. Once you've 114 | done that, edit line 12 of the included getToken.php file to reflect 115 | which permissions you'll need for the app. Then browse to the page. 116 | Once you've authorized the app with Flickr, it'll send you back to that 117 | page which will give you a token which will look something like this: 118 | 1234-567890abcdef1234 119 | Go to the file where you are creating an instance of phpFlickr (I suggest 120 | an include file) and after you've created it set the token to use: 121 | $f->setToken(""); 122 | This token never expires, so you don't have to worry about having to 123 | login periodically. 124 | 125 | 126 | Caching 127 | ======= 128 | 129 | Caching can be very important to a project. Just a few calls to the Flickr API 130 | can take long enough to bore your average web user (depending on the calls you 131 | are making). I've built in caching that will access either a database or files 132 | in your filesystem. To enable caching, use the phpFlickr::enableCache() function. 133 | This function requires at least two arguments. The first will be the type of 134 | cache you're using (either "db" or "fs") 135 | 136 | 1. If you're using database caching, you'll need to supply a PEAR::DB style connection 137 | string. For example: 138 | 139 | $flickr->enableCache("db", "mysql://user:password@server/database"); 140 | 141 | The third (optional) argument is expiration of the cache in seconds (defaults 142 | to 600). The fourth (optional) argument is the table where you want to store 143 | the cache. This defaults to flickr_cache and will attempt to create the table 144 | if it does not already exist. 145 | 146 | 2. If you're using filesystem caching, you'll need to supply a folder where the 147 | web server has write access. For example: 148 | 149 | $flickr->enableCache("fs", "/var/www/phpFlickrCache"); 150 | 151 | The third (optional) argument is, the same as in the Database caching, an 152 | expiration in seconds for the cache. 153 | 154 | Note: filesystem caching will probably be slower than database caching. I 155 | haven't done any tests of this, but if you get large amounts of calls, the 156 | process of cleaning out old calls may get hard on your server. 157 | 158 | You may not want to allow the world to view the files that are created during 159 | caching. If you want to hide this information, either make sure that your 160 | permissions are set correctly, or disable the webserver from displaying 161 | *.cache files. In Apache, you can specify this in the configuration files 162 | or in a .htaccess file with the following directives: 163 | 164 | 165 | Deny from all 166 | 167 | 168 | Alternatively, you can specify a directory that is outside of the web server's 169 | document root. 170 | 171 | Uploading 172 | ========= 173 | 174 | Uploading is pretty simple. Aside from being authenticated (see Authentication 175 | section) the very minimum that you'll have to pass is a path to an image file on 176 | your php server. You can do either synchronous or asynchronous uploading as follows: 177 | 178 | synchronous: sync_upload("photo.jpg"); 179 | asynchronous: async_upload("photo.jpg"); 180 | 181 | The basic difference is that synchronous uploading waits around until Flickr 182 | processes the photo and returns a PhotoID. Asynchronous just uploads the 183 | picture and gets a "ticketid" that you can use to check on the status of your 184 | upload. Asynchronous is much faster, though the photoid won't be instantly 185 | available for you. You can read more about asynchronous uploading here: 186 | 187 | http://www.flickr.com/services/api/upload.async.html 188 | 189 | Both of the functions take the same arguments which are: 190 | 191 | > Photo: The path of the file to upload. 192 | > Title: The title of the photo. 193 | > Description: A description of the photo. May contain some limited HTML. 194 | > Tags: A space-separated list of tags to apply to the photo. 195 | > is_public: Set to 0 for no, 1 for yes. 196 | > is_friend: Set to 0 for no, 1 for yes. 197 | > is_family: Set to 0 for no, 1 for yes. 198 | 199 | Replacing Photos 200 | ================ 201 | 202 | Flickr has released API support for uploading a replacement photo. To use this 203 | new method, just use the "replace" function in phpFlickr. You'll be required 204 | to pass the file name and Flickr's photo ID. You need to authenticate your script 205 | with "write" permissions before you can replace a photo. The arguments are: 206 | 207 | > Photo: The path of the file to upload. 208 | > Photo ID: The numeric Flickr ID of the photo you want to replace. 209 | > Async (optional): Set to 0 for a synchronous call, 1 for asynchronous. 210 | 211 | If you use the asynchronous call, it will return a ticketid instead 212 | of photoid. 213 | 214 | Other Notes: 215 | 1. Many of the methods have optional arguments. For these, I have implemented 216 | them in the same order that the Flickr API documentation lists them. PHP 217 | allows for optional arguments in function calls, but if you want to use the 218 | third optional argument, you have to fill in the others to the left first. 219 | You can use the "NULL" value (without quotes) in the place of an actual 220 | argument. For example: 221 | 222 | $f->groups_pools_getPhotos($group_id, NULL, NULL, 10); 223 | 224 | This will get the first ten photos from a specific group's pool. If you look 225 | at the documentation, you will see that there is another argument, "page". I've 226 | left it off because it appears after "per_page". 227 | 228 | 2. Some people will need to ues phpFlickr from behind a proxy server. I've 229 | implemented a method that will allow you to use an HTTP proxy for all of your 230 | traffic. Let's say that you have a proxy server on your local server running 231 | at port 8181. This is the code you would use: 232 | 233 | $f = new phpFlickr("[api key]"); 234 | $f->setProxy("localhost", "8181"); 235 | 236 | After that, all of your calls will be automatically made through your proxy server. 237 | 238 | -------------------------------------------------------------------------------- /auth.php: -------------------------------------------------------------------------------- 1 | auth($permissions, false); 28 | } else { 29 | $f->auth_getToken($_GET['frob']); 30 | } 31 | 32 | if (empty($redirect)) { 33 | header("Location: " . $default_redirect); 34 | } else { 35 | header("Location: " . $redirect); 36 | } 37 | 38 | ?> -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | " with one provided 13 | * by Flickr: http://www.flickr.com/services/api/key.gne 14 | */ 15 | 16 | require_once("phpFlickr.php"); 17 | $f = new phpFlickr(""); 18 | 19 | $recent = $f->photos_getRecent(); 20 | 21 | foreach ($recent['photo'] as $photo) { 22 | $owner = $f->people_getInfo($photo['owner']); 23 | echo ""; 24 | echo $photo['title']; 25 | echo " Owner: "; 26 | echo ""; 27 | echo $owner['username']; 28 | echo "
"; 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /getToken.php: -------------------------------------------------------------------------------- 1 | ", ""); 13 | 14 | //change this to the permissions you will need 15 | $f->auth("read"); 16 | 17 | echo "Copy this token into your code: " . $_SESSION['phpFlickr_auth_token']; 18 | 19 | ?> -------------------------------------------------------------------------------- /phpFlickr.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | if ( !class_exists('phpFlickr') ) { 21 | if (session_id() == "") { 22 | @session_start(); 23 | } 24 | 25 | class phpFlickr { 26 | var $api_key; 27 | var $secret; 28 | 29 | var $rest_endpoint = 'https://api.flickr.com/services/rest/'; 30 | var $upload_endpoint = 'https://up.flickr.com/services/upload/'; 31 | var $replace_endpoint = 'https://up.flickr.com/services/replace/'; 32 | var $req; 33 | var $response; 34 | var $parsed_response; 35 | var $cache = false; 36 | var $cache_db = null; 37 | var $cache_table = null; 38 | var $cache_dir = null; 39 | var $cache_expire = null; 40 | var $cache_key = null; 41 | var $last_request = null; 42 | var $die_on_error; 43 | var $error_code; 44 | Var $error_msg; 45 | var $token; 46 | var $php_version; 47 | var $custom_post = null, $custom_cache_get = null, $custom_cache_set = null; 48 | 49 | /* 50 | * When your database cache table hits this many rows, a cleanup 51 | * will occur to get rid of all of the old rows and cleanup the 52 | * garbage in the table. For most personal apps, 1000 rows should 53 | * be more than enough. If your site gets hit by a lot of traffic 54 | * or you have a lot of disk space to spare, bump this number up. 55 | * You should try to set it high enough that the cleanup only 56 | * happens every once in a while, so this will depend on the growth 57 | * of your table. 58 | */ 59 | var $max_cache_rows = 1000; 60 | 61 | function phpFlickr ($api_key, $secret = NULL, $die_on_error = false) { 62 | //The API Key must be set before any calls can be made. You can 63 | //get your own at https://www.flickr.com/services/api/misc.api_keys.html 64 | $this->api_key = $api_key; 65 | $this->secret = $secret; 66 | $this->die_on_error = $die_on_error; 67 | $this->service = "flickr"; 68 | 69 | //Find the PHP version and store it for future reference 70 | $this->php_version = explode("-", phpversion()); 71 | $this->php_version = explode(".", $this->php_version[0]); 72 | } 73 | 74 | function enableCache ($type, $connection, $cache_expire = 600, $table = 'flickr_cache') { 75 | // Turns on caching. $type must be either "db" (for database caching) or "fs" (for filesystem). 76 | // When using db, $connection must be a PEAR::DB connection string. Example: 77 | // "mysql://user:password@server/database" 78 | // If the $table, doesn't exist, it will attempt to create it. 79 | // When using file system, caching, the $connection is the folder that the web server has write 80 | // access to. Use absolute paths for best results. Relative paths may have unexpected behavior 81 | // when you include this. They'll usually work, you'll just want to test them. 82 | if ($type == 'db') { 83 | if ( preg_match('|mysql://([^:]*):([^@]*)@([^/]*)/(.*)|', $connection, $matches) ) { 84 | //Array ( [0] => mysql://user:password@server/database [1] => user [2] => password [3] => server [4] => database ) 85 | $db = mysqli_connect($matches[3], $matches[1], $matches[2]); 86 | mysqli_query($db, "USE $matches[4]"); 87 | 88 | /* 89 | * If high performance is crucial, you can easily comment 90 | * out this query once you've created your database table. 91 | */ 92 | mysqli_query($db, " 93 | CREATE TABLE IF NOT EXISTS `$table` ( 94 | `request` varchar(128) NOT NULL, 95 | `response` mediumtext NOT NULL, 96 | `expiration` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 97 | UNIQUE KEY `request` (`request`) 98 | ) 99 | "); 100 | 101 | $result = mysqli_query($db, "SELECT COUNT(*) 'count' FROM $table"); 102 | if( $result ) { 103 | $result = mysqli_fetch_assoc($result); 104 | } 105 | 106 | if ( $result && $result['count'] > $this->max_cache_rows ) { 107 | mysqli_query($db, "DELETE FROM $table WHERE CURRENT_TIMESTAMP > expiration"); 108 | mysqli_query($db, 'OPTIMIZE TABLE ' . $this->cache_table); 109 | } 110 | $this->cache = 'db'; 111 | $this->cache_db = $db; 112 | $this->cache_table = $table; 113 | } 114 | } elseif ($type == 'fs') { 115 | $this->cache = 'fs'; 116 | $connection = realpath($connection); 117 | $this->cache_dir = $connection; 118 | if ($dir = opendir($this->cache_dir)) { 119 | while ($file = readdir($dir)) { 120 | if (substr($file, -6) == '.cache' && ((filemtime($this->cache_dir . '/' . $file) + $cache_expire) < time()) ) { 121 | unlink($this->cache_dir . '/' . $file); 122 | } 123 | } 124 | } 125 | } elseif ( $type == 'custom' ) { 126 | $this->cache = "custom"; 127 | $this->custom_cache_get = $connection[0]; 128 | $this->custom_cache_set = $connection[1]; 129 | } 130 | $this->cache_expire = $cache_expire; 131 | } 132 | 133 | function getCached ($request) 134 | { 135 | //Checks the database or filesystem for a cached result to the request. 136 | //If there is no cache result, it returns a value of false. If it finds one, 137 | //it returns the unparsed XML. 138 | unset($request['api_sig']); 139 | foreach ( $request as $key => $value ) { 140 | if ( empty($value) ) unset($request[$key]); 141 | else $request[$key] = (string) $request[$key]; 142 | } 143 | //if ( is_user_logged_in() ) print_r($request); 144 | $reqhash = md5(serialize($request)); 145 | $this->cache_key = $reqhash; 146 | $this->cache_request = $request; 147 | if ($this->cache == 'db') { 148 | $result = mysqli_query($this->cache_db, "SELECT response FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "' AND CURRENT_TIMESTAMP < expiration"); 149 | if ( $result && mysqli_num_rows($result) ) { 150 | $result = mysqli_fetch_assoc($result); 151 | return urldecode($result['response']); 152 | } else { 153 | return false; 154 | } 155 | } elseif ($this->cache == 'fs') { 156 | $file = $this->cache_dir . '/' . $reqhash . '.cache'; 157 | if (file_exists($file)) { 158 | if ($this->php_version[0] > 4 || ($this->php_version[0] == 4 && $this->php_version[1] >= 3)) { 159 | return file_get_contents($file); 160 | } else { 161 | return implode('', file($file)); 162 | } 163 | } 164 | } elseif ( $this->cache == 'custom' ) { 165 | return call_user_func_array($this->custom_cache_get, array($reqhash)); 166 | } 167 | return false; 168 | } 169 | 170 | function cache ($request, $response) 171 | { 172 | //Caches the unparsed response of a request. 173 | unset($request['api_sig']); 174 | foreach ( $request as $key => $value ) { 175 | if ( empty($value) ) unset($request[$key]); 176 | else $request[$key] = (string) $request[$key]; 177 | } 178 | $reqhash = md5(serialize($request)); 179 | if ($this->cache == 'db') { 180 | //$this->cache_db->query("DELETE FROM $this->cache_table WHERE request = '$reqhash'"); 181 | $response = urlencode($response); 182 | $sql = 'INSERT INTO '.$this->cache_table.' (request, response, expiration) 183 | VALUES (\''.$reqhash.'\', \''.$response.'\', TIMESTAMPADD(SECOND,'.$this->cache_expire.',CURRENT_TIMESTAMP)) 184 | ON DUPLICATE KEY UPDATE response=\''.$response.'\', 185 | expiration=TIMESTAMPADD(SECOND,'.$this->cache_expire.',CURRENT_TIMESTAMP) '; 186 | 187 | $result = mysqli_query($this->cache_db, $sql); 188 | if(!$result) { 189 | echo mysqli_error($this->cache_db); 190 | } 191 | 192 | return $result; 193 | } elseif ($this->cache == "fs") { 194 | $file = $this->cache_dir . "/" . $reqhash . ".cache"; 195 | $fstream = fopen($file, "w"); 196 | $result = fwrite($fstream,$response); 197 | fclose($fstream); 198 | return $result; 199 | } elseif ( $this->cache == "custom" ) { 200 | return call_user_func_array($this->custom_cache_set, array($reqhash, $response, $this->cache_expire)); 201 | } 202 | return false; 203 | } 204 | 205 | function setCustomPost ( $function ) { 206 | $this->custom_post = $function; 207 | } 208 | 209 | function post ($data, $type = null) { 210 | if ( is_null($type) ) { 211 | $url = $this->rest_endpoint; 212 | } 213 | 214 | if ( !is_null($this->custom_post) ) { 215 | return call_user_func($this->custom_post, $url, $data); 216 | } 217 | 218 | if ( !preg_match("|https://(.*?)(/.*)|", $url, $matches) ) { 219 | die('There was some problem figuring out your endpoint'); 220 | } 221 | 222 | if ( function_exists('curl_init') ) { 223 | // Has curl. Use it! 224 | $curl = curl_init($this->rest_endpoint); 225 | curl_setopt($curl, CURLOPT_POST, true); 226 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 227 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 228 | $response = curl_exec($curl); 229 | curl_close($curl); 230 | } else { 231 | // Use sockets. 232 | foreach ( $data as $key => $value ) { 233 | $data[$key] = $key . '=' . urlencode($value); 234 | } 235 | $data = implode('&', $data); 236 | 237 | $fp = @pfsockopen('ssl://'.$matches[1], 443); 238 | if (!$fp) { 239 | die('Could not connect to the web service'); 240 | } 241 | fputs ($fp,'POST ' . $matches[2] . " HTTP/1.1\n"); 242 | fputs ($fp,'Host: ' . $matches[1] . "\n"); 243 | fputs ($fp,"Content-type: application/x-www-form-urlencoded\n"); 244 | fputs ($fp,"Content-length: ".strlen($data)."\n"); 245 | fputs ($fp,"Connection: close\r\n\r\n"); 246 | fputs ($fp,$data . "\n\n"); 247 | $response = ""; 248 | while(!feof($fp)) { 249 | $response .= fgets($fp, 1024); 250 | } 251 | fclose ($fp); 252 | $chunked = false; 253 | $http_status = trim(substr($response, 0, strpos($response, "\n"))); 254 | if ( $http_status != 'HTTP/1.1 200 OK' ) { 255 | die('The web service endpoint returned a "' . $http_status . '" response'); 256 | } 257 | if ( strpos($response, 'Transfer-Encoding: chunked') !== false ) { 258 | $temp = trim(strstr($response, "\r\n\r\n")); 259 | $response = ''; 260 | $length = trim(substr($temp, 0, strpos($temp, "\r"))); 261 | while ( trim($temp) != "0" && ($length = trim(substr($temp, 0, strpos($temp, "\r")))) != "0" ) { 262 | $response .= trim(substr($temp, strlen($length)+2, hexdec($length))); 263 | $temp = trim(substr($temp, strlen($length) + 2 + hexdec($length))); 264 | } 265 | } elseif ( strpos($response, 'HTTP/1.1 200 OK') !== false ) { 266 | $response = trim(strstr($response, "\r\n\r\n")); 267 | } 268 | } 269 | return $response; 270 | } 271 | 272 | function request ($command, $args = array(), $nocache = false) 273 | { 274 | //Sends a request to Flickr's REST endpoint via POST. 275 | if (substr($command,0,7) != "flickr.") { 276 | $command = "flickr." . $command; 277 | } 278 | 279 | //Process arguments, including method and login data. 280 | $args = array_merge(array("method" => $command, "format" => "json", "nojsoncallback" => "1", "api_key" => $this->api_key), $args); 281 | if (!empty($this->token)) { 282 | $args = array_merge($args, array("auth_token" => $this->token)); 283 | } elseif (!empty($_SESSION['phpFlickr_auth_token'])) { 284 | $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token'])); 285 | } 286 | ksort($args); 287 | $auth_sig = ""; 288 | $this->last_request = $args; 289 | $this->response = $this->getCached($args); 290 | if (!($this->response) || $nocache) { 291 | foreach ($args as $key => $data) { 292 | if ( is_null($data) ) { 293 | unset($args[$key]); 294 | continue; 295 | } 296 | $auth_sig .= $key . $data; 297 | } 298 | if (!empty($this->secret)) { 299 | $api_sig = md5($this->secret . $auth_sig); 300 | $args['api_sig'] = $api_sig; 301 | } 302 | $this->response = $this->post($args); 303 | $this->cache($args, $this->response); 304 | } 305 | 306 | 307 | /* 308 | * Uncomment this line (and comment out the next one) if you're doing large queries 309 | * and you're concerned about time. This will, however, change the structure of 310 | * the result, so be sure that you look at the results. 311 | */ 312 | $this->parsed_response = json_decode($this->response, TRUE); 313 | /* $this->parsed_response = $this->clean_text_nodes(json_decode($this->response, TRUE)); */ 314 | if ($this->parsed_response['stat'] == 'fail') { 315 | if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); 316 | else { 317 | $this->error_code = $this->parsed_response['code']; 318 | $this->error_msg = $this->parsed_response['message']; 319 | $this->parsed_response = false; 320 | } 321 | } else { 322 | $this->error_code = false; 323 | $this->error_msg = false; 324 | } 325 | return $this->response; 326 | } 327 | 328 | function clean_text_nodes ($arr) { 329 | if (!is_array($arr)) { 330 | return $arr; 331 | } elseif (count($arr) == 0) { 332 | return $arr; 333 | } elseif (count($arr) == 1 && array_key_exists('_content', $arr)) { 334 | return $arr['_content']; 335 | } else { 336 | foreach ($arr as $key => $element) { 337 | $arr[$key] = $this->clean_text_nodes($element); 338 | } 339 | return($arr); 340 | } 341 | } 342 | 343 | function setToken ($token) { 344 | // Sets an authentication token to use instead of the session variable 345 | $this->token = $token; 346 | } 347 | 348 | function setProxy ($server, $port) { 349 | // Sets the proxy for all phpFlickr calls. 350 | $this->req->setProxy($server, $port); 351 | } 352 | 353 | function getErrorCode () { 354 | // Returns the error code of the last call. If the last call did not 355 | // return an error. This will return a false boolean. 356 | return $this->error_code; 357 | } 358 | 359 | function getErrorMsg () { 360 | // Returns the error message of the last call. If the last call did not 361 | // return an error. This will return a false boolean. 362 | return $this->error_msg; 363 | } 364 | 365 | /* These functions are front ends for the flickr calls */ 366 | 367 | function buildPhotoURL ($photo, $size = "Medium") { 368 | //receives an array (can use the individual photo data returned 369 | //from an API call) and returns a URL (doesn't mean that the 370 | //file size exists) 371 | $sizes = array( 372 | "square" => "_s", 373 | "square_75" => "_s", 374 | "square_150" => "_q", 375 | "thumbnail" => "_t", 376 | "small" => "_m", 377 | "small_240" => "_m", 378 | "small_320" => "_n", 379 | "medium" => "", 380 | "medium_500" => "", 381 | "medium_640" => "_z", 382 | "medium_800" => "_c", 383 | "large" => "_b", 384 | "large_1024" => "_b", 385 | "large_1600" => "_h", 386 | "large_2048" => "_k", 387 | "original" => "_o", 388 | ); 389 | 390 | $size = strtolower($size); 391 | if (!array_key_exists($size, $sizes)) { 392 | $size = "medium"; 393 | } 394 | 395 | if ($size == "original") { 396 | $url = "https://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat']; 397 | } else { 398 | $url = "https://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg"; 399 | } 400 | return $url; 401 | } 402 | 403 | function sync_upload ($photo, $title = null, $description = null, $tags = null, $is_public = null, $is_friend = null, $is_family = null) { 404 | if ( function_exists('curl_init') ) { 405 | // Has curl. Use it! 406 | 407 | //Process arguments, including method and login data. 408 | $args = array("api_key" => $this->api_key, "title" => $title, "description" => $description, "tags" => $tags, "is_public" => $is_public, "is_friend" => $is_friend, "is_family" => $is_family); 409 | if (!empty($this->token)) { 410 | $args = array_merge($args, array("auth_token" => $this->token)); 411 | } elseif (!empty($_SESSION['phpFlickr_auth_token'])) { 412 | $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token'])); 413 | } 414 | 415 | ksort($args); 416 | $auth_sig = ""; 417 | foreach ($args as $key => $data) { 418 | if ( is_null($data) ) { 419 | unset($args[$key]); 420 | } else { 421 | $auth_sig .= $key . $data; 422 | } 423 | } 424 | if (!empty($this->secret)) { 425 | $api_sig = md5($this->secret . $auth_sig); 426 | $args["api_sig"] = $api_sig; 427 | } 428 | 429 | $photo = realpath($photo); 430 | $args['photo'] = '@' . $photo; 431 | 432 | 433 | $curl = curl_init($this->upload_endpoint); 434 | curl_setopt($curl, CURLOPT_POST, true); 435 | curl_setopt($curl, CURLOPT_POSTFIELDS, $args); 436 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 437 | $response = curl_exec($curl); 438 | $this->response = $response; 439 | curl_close($curl); 440 | 441 | $rsp = explode("\n", $response); 442 | foreach ($rsp as $line) { 443 | if (preg_match('|die_on_error) 445 | die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); 446 | else { 447 | $this->error_code = $match[1]; 448 | $this->error_msg = $match[2]; 449 | $this->parsed_response = false; 450 | return false; 451 | } 452 | } elseif (preg_match("|(.*)|", $line, $match)) { 453 | $this->error_code = false; 454 | $this->error_msg = false; 455 | return $match[1]; 456 | } 457 | } 458 | 459 | } else { 460 | die("Sorry, your server must support CURL in order to upload files"); 461 | } 462 | 463 | } 464 | 465 | function async_upload ($photo, $title = null, $description = null, $tags = null, $is_public = null, $is_friend = null, $is_family = null) { 466 | if ( function_exists('curl_init') ) { 467 | // Has curl. Use it! 468 | 469 | //Process arguments, including method and login data. 470 | $args = array("async" => 1, "api_key" => $this->api_key, "title" => $title, "description" => $description, "tags" => $tags, "is_public" => $is_public, "is_friend" => $is_friend, "is_family" => $is_family); 471 | if (!empty($this->token)) { 472 | $args = array_merge($args, array("auth_token" => $this->token)); 473 | } elseif (!empty($_SESSION['phpFlickr_auth_token'])) { 474 | $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token'])); 475 | } 476 | 477 | ksort($args); 478 | $auth_sig = ""; 479 | foreach ($args as $key => $data) { 480 | if ( is_null($data) ) { 481 | unset($args[$key]); 482 | } else { 483 | $auth_sig .= $key . $data; 484 | } 485 | } 486 | if (!empty($this->secret)) { 487 | $api_sig = md5($this->secret . $auth_sig); 488 | $args["api_sig"] = $api_sig; 489 | } 490 | 491 | $photo = realpath($photo); 492 | $args['photo'] = '@' . $photo; 493 | 494 | 495 | $curl = curl_init($this->upload_endpoint); 496 | curl_setopt($curl, CURLOPT_POST, true); 497 | curl_setopt($curl, CURLOPT_POSTFIELDS, $args); 498 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 499 | $response = curl_exec($curl); 500 | $this->response = $response; 501 | curl_close($curl); 502 | 503 | $rsp = explode("\n", $response); 504 | foreach ($rsp as $line) { 505 | if (preg_match('/die_on_error) 507 | die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); 508 | else { 509 | $this->error_code = $match[1]; 510 | $this->error_msg = $match[2]; 511 | $this->parsed_response = false; 512 | return false; 513 | } 514 | } elseif (preg_match("/(.*)error_code = false; 516 | $this->error_msg = false; 517 | return $match[1]; 518 | } 519 | } 520 | } else { 521 | die("Sorry, your server must support CURL in order to upload files"); 522 | } 523 | } 524 | 525 | // Interface for new replace API method. 526 | function replace ($photo, $photo_id, $async = null) { 527 | if ( function_exists('curl_init') ) { 528 | // Has curl. Use it! 529 | 530 | //Process arguments, including method and login data. 531 | $args = array("api_key" => $this->api_key, "photo_id" => $photo_id, "async" => $async); 532 | if (!empty($this->token)) { 533 | $args = array_merge($args, array("auth_token" => $this->token)); 534 | } elseif (!empty($_SESSION['phpFlickr_auth_token'])) { 535 | $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token'])); 536 | } 537 | 538 | ksort($args); 539 | $auth_sig = ""; 540 | foreach ($args as $key => $data) { 541 | if ( is_null($data) ) { 542 | unset($args[$key]); 543 | } else { 544 | $auth_sig .= $key . $data; 545 | } 546 | } 547 | if (!empty($this->secret)) { 548 | $api_sig = md5($this->secret . $auth_sig); 549 | $args["api_sig"] = $api_sig; 550 | } 551 | 552 | $photo = realpath($photo); 553 | $args['photo'] = '@' . $photo; 554 | 555 | 556 | $curl = curl_init($this->replace_endpoint); 557 | curl_setopt($curl, CURLOPT_POST, true); 558 | curl_setopt($curl, CURLOPT_POSTFIELDS, $args); 559 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 560 | $response = curl_exec($curl); 561 | $this->response = $response; 562 | curl_close($curl); 563 | 564 | if ($async == 1) 565 | $find = 'ticketid'; 566 | else 567 | $find = 'photoid'; 568 | 569 | $rsp = explode("\n", $response); 570 | foreach ($rsp as $line) { 571 | if (preg_match('|die_on_error) 573 | die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); 574 | else { 575 | $this->error_code = $match[1]; 576 | $this->error_msg = $match[2]; 577 | $this->parsed_response = false; 578 | return false; 579 | } 580 | } elseif (preg_match("|<" . $find . ">(.*)error_code = false; 582 | $this->error_msg = false; 583 | return $match[1]; 584 | } 585 | } 586 | } else { 587 | die("Sorry, your server must support CURL in order to upload files"); 588 | } 589 | } 590 | 591 | function auth ($perms = "read", $remember_uri = true) { 592 | // Redirects to Flickr's authentication piece if there is no valid token. 593 | // If remember_uri is set to false, the callback script (included) will 594 | // redirect to its default page. 595 | 596 | if (empty($_SESSION['phpFlickr_auth_token']) && empty($this->token)) { 597 | if ( $remember_uri === true ) { 598 | $_SESSION['phpFlickr_auth_redirect'] = $_SERVER['REQUEST_URI']; 599 | } elseif ( $remember_uri !== false ) { 600 | $_SESSION['phpFlickr_auth_redirect'] = $remember_uri; 601 | } 602 | $api_sig = md5($this->secret . "api_key" . $this->api_key . "perms" . $perms); 603 | 604 | if ($this->service == "23") { 605 | header("Location: http://www.23hq.com/services/auth/?api_key=" . $this->api_key . "&perms=" . $perms . "&api_sig=". $api_sig); 606 | } else { 607 | header("Location: https://www.flickr.com/services/auth/?api_key=" . $this->api_key . "&perms=" . $perms . "&api_sig=". $api_sig); 608 | } 609 | exit; 610 | } else { 611 | $tmp = $this->die_on_error; 612 | $this->die_on_error = false; 613 | $rsp = $this->auth_checkToken(); 614 | if ($this->error_code !== false) { 615 | unset($_SESSION['phpFlickr_auth_token']); 616 | $this->auth($perms, $remember_uri); 617 | } 618 | $this->die_on_error = $tmp; 619 | return $rsp['perms']; 620 | } 621 | } 622 | 623 | function auth_url($frob, $perms = 'read') { 624 | $sig = md5(sprintf('%sapi_key%sfrob%sperms%s', $this->secret, $this->api_key, $frob, $perms)); 625 | return sprintf('https://flickr.com/services/auth/?api_key=%s&perms=%s&frob=%s&api_sig=%s', $this->api_key, $perms, $frob, $sig); 626 | } 627 | 628 | /******************************* 629 | 630 | To use the phpFlickr::call method, pass a string containing the API method you want 631 | to use and an associative array of arguments. For example: 632 | $result = $f->call("flickr.photos.comments.getList", array("photo_id"=>'34952612')); 633 | This method will allow you to make calls to arbitrary methods that haven't been 634 | implemented in phpFlickr yet. 635 | 636 | *******************************/ 637 | 638 | function call ($method, $arguments) { 639 | foreach ( $arguments as $key => $value ) { 640 | if ( is_null($value) ) unset($arguments[$key]); 641 | } 642 | $this->request($method, $arguments); 643 | return $this->parsed_response ? $this->parsed_response : false; 644 | } 645 | 646 | /* 647 | These functions are the direct implementations of flickr calls. 648 | For method documentation, including arguments, visit the address 649 | included in a comment in the function. 650 | */ 651 | 652 | /* Activity methods */ 653 | function activity_userComments ($per_page = NULL, $page = NULL) { 654 | /* https://www.flickr.com/services/api/flickr.activity.userComments.html */ 655 | $this->request('flickr.activity.userComments', array("per_page" => $per_page, "page" => $page)); 656 | return $this->parsed_response ? $this->parsed_response['items']['item'] : false; 657 | } 658 | 659 | function activity_userPhotos ($timeframe = NULL, $per_page = NULL, $page = NULL) { 660 | /* https://www.flickr.com/services/api/flickr.activity.userPhotos.html */ 661 | $this->request('flickr.activity.userPhotos', array("timeframe" => $timeframe, "per_page" => $per_page, "page" => $page)); 662 | return $this->parsed_response ? $this->parsed_response['items']['item'] : false; 663 | } 664 | 665 | /* Authentication methods */ 666 | function auth_checkToken () { 667 | /* https://www.flickr.com/services/api/flickr.auth.checkToken.html */ 668 | $this->request('flickr.auth.checkToken'); 669 | return $this->parsed_response ? $this->parsed_response['auth'] : false; 670 | } 671 | 672 | function auth_getFrob () { 673 | /* https://www.flickr.com/services/api/flickr.auth.getFrob.html */ 674 | $this->request('flickr.auth.getFrob'); 675 | return $this->parsed_response ? $this->parsed_response['frob'] : false; 676 | } 677 | 678 | function auth_getFullToken ($mini_token) { 679 | /* https://www.flickr.com/services/api/flickr.auth.getFullToken.html */ 680 | $this->request('flickr.auth.getFullToken', array('mini_token'=>$mini_token)); 681 | return $this->parsed_response ? $this->parsed_response['auth'] : false; 682 | } 683 | 684 | function auth_getToken ($frob) { 685 | /* https://www.flickr.com/services/api/flickr.auth.getToken.html */ 686 | $this->request('flickr.auth.getToken', array('frob'=>$frob)); 687 | $_SESSION['phpFlickr_auth_token'] = $this->parsed_response['auth']['token']; 688 | return $this->parsed_response ? $this->parsed_response['auth'] : false; 689 | } 690 | 691 | /* Blogs methods */ 692 | function blogs_getList ($service = NULL) { 693 | /* https://www.flickr.com/services/api/flickr.blogs.getList.html */ 694 | $rsp = $this->call('flickr.blogs.getList', array('service' => $service)); 695 | return $rsp['blogs']['blog']; 696 | } 697 | 698 | function blogs_getServices () { 699 | /* https://www.flickr.com/services/api/flickr.blogs.getServices.html */ 700 | return $this->call('flickr.blogs.getServices', array()); 701 | } 702 | 703 | function blogs_postPhoto ($blog_id = NULL, $photo_id, $title, $description, $blog_password = NULL, $service = NULL) { 704 | /* https://www.flickr.com/services/api/flickr.blogs.postPhoto.html */ 705 | return $this->call('flickr.blogs.postPhoto', array('blog_id' => $blog_id, 'photo_id' => $photo_id, 'title' => $title, 'description' => $description, 'blog_password' => $blog_password, 'service' => $service)); 706 | } 707 | 708 | /* Collections Methods */ 709 | function collections_getInfo ($collection_id) { 710 | /* https://www.flickr.com/services/api/flickr.collections.getInfo.html */ 711 | return $this->call('flickr.collections.getInfo', array('collection_id' => $collection_id)); 712 | } 713 | 714 | function collections_getTree ($collection_id = NULL, $user_id = NULL) { 715 | /* https://www.flickr.com/services/api/flickr.collections.getTree.html */ 716 | return $this->call('flickr.collections.getTree', array('collection_id' => $collection_id, 'user_id' => $user_id)); 717 | } 718 | 719 | /* Commons Methods */ 720 | function commons_getInstitutions () { 721 | /* https://www.flickr.com/services/api/flickr.commons.getInstitutions.html */ 722 | return $this->call('flickr.commons.getInstitutions', array()); 723 | } 724 | 725 | /* Contacts Methods */ 726 | function contacts_getList ($filter = NULL, $page = NULL, $per_page = NULL) { 727 | /* https://www.flickr.com/services/api/flickr.contacts.getList.html */ 728 | $this->request('flickr.contacts.getList', array('filter'=>$filter, 'page'=>$page, 'per_page'=>$per_page)); 729 | return $this->parsed_response ? $this->parsed_response['contacts'] : false; 730 | } 731 | 732 | function contacts_getPublicList ($user_id, $page = NULL, $per_page = NULL) { 733 | /* https://www.flickr.com/services/api/flickr.contacts.getPublicList.html */ 734 | $this->request('flickr.contacts.getPublicList', array('user_id'=>$user_id, 'page'=>$page, 'per_page'=>$per_page)); 735 | return $this->parsed_response ? $this->parsed_response['contacts'] : false; 736 | } 737 | 738 | function contacts_getListRecentlyUploaded ($date_lastupload = NULL, $filter = NULL) { 739 | /* https://www.flickr.com/services/api/flickr.contacts.getListRecentlyUploaded.html */ 740 | return $this->call('flickr.contacts.getListRecentlyUploaded', array('date_lastupload' => $date_lastupload, 'filter' => $filter)); 741 | } 742 | 743 | /* Favorites Methods */ 744 | function favorites_add ($photo_id) { 745 | /* https://www.flickr.com/services/api/flickr.favorites.add.html */ 746 | $this->request('flickr.favorites.add', array('photo_id'=>$photo_id), TRUE); 747 | return $this->parsed_response ? true : false; 748 | } 749 | 750 | function favorites_getList ($user_id = NULL, $jump_to = NULL, $min_fave_date = NULL, $max_fave_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 751 | /* https://www.flickr.com/services/api/flickr.favorites.getList.html */ 752 | return $this->call('flickr.favorites.getList', array('user_id' => $user_id, 'jump_to' => $jump_to, 'min_fave_date' => $min_fave_date, 'max_fave_date' => $max_fave_date, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 753 | } 754 | 755 | function favorites_getPublicList ($user_id, $jump_to = NULL, $min_fave_date = NULL, $max_fave_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 756 | /* https://www.flickr.com/services/api/flickr.favorites.getPublicList.html */ 757 | return $this->call('flickr.favorites.getPublicList', array('user_id' => $user_id, 'jump_to' => $jump_to, 'min_fave_date' => $min_fave_date, 'max_fave_date' => $max_fave_date, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 758 | } 759 | 760 | function favorites_remove ($photo_id, $user_id = NULL) { 761 | /* https://www.flickr.com/services/api/flickr.favorites.remove.html */ 762 | $this->request("flickr.favorites.remove", array('photo_id' => $photo_id, 'user_id' => $user_id), TRUE); 763 | return $this->parsed_response ? true : false; 764 | } 765 | 766 | /* Galleries Methods */ 767 | function galleries_addPhoto ($gallery_id, $photo_id, $comment = NULL) { 768 | /* https://www.flickr.com/services/api/flickr.galleries.addPhoto.html */ 769 | return $this->call('flickr.galleries.addPhoto', array('gallery_id' => $gallery_id, 'photo_id' => $photo_id, 'comment' => $comment)); 770 | } 771 | 772 | function galleries_create ($title, $description, $primary_photo_id = NULL) { 773 | /* https://www.flickr.com/services/api/flickr.galleries.create.html */ 774 | return $this->call('flickr.galleries.create', array('title' => $title, 'description' => $description, 'primary_photo_id' => $primary_photo_id)); 775 | } 776 | 777 | function galleries_editMeta ($gallery_id, $title, $description = NULL) { 778 | /* https://www.flickr.com/services/api/flickr.galleries.editMeta.html */ 779 | return $this->call('flickr.galleries.editMeta', array('gallery_id' => $gallery_id, 'title' => $title, 'description' => $description)); 780 | } 781 | 782 | function galleries_editPhoto ($gallery_id, $photo_id, $comment) { 783 | /* https://www.flickr.com/services/api/flickr.galleries.editPhoto.html */ 784 | return $this->call('flickr.galleries.editPhoto', array('gallery_id' => $gallery_id, 'photo_id' => $photo_id, 'comment' => $comment)); 785 | } 786 | 787 | function galleries_editPhotos ($gallery_id, $primary_photo_id, $photo_ids) { 788 | /* https://www.flickr.com/services/api/flickr.galleries.editPhotos.html */ 789 | return $this->call('flickr.galleries.editPhotos', array('gallery_id' => $gallery_id, 'primary_photo_id' => $primary_photo_id, 'photo_ids' => $photo_ids)); 790 | } 791 | 792 | function galleries_getInfo ($gallery_id) { 793 | /* https://www.flickr.com/services/api/flickr.galleries.getInfo.html */ 794 | return $this->call('flickr.galleries.getInfo', array('gallery_id' => $gallery_id)); 795 | } 796 | 797 | function galleries_getList ($user_id, $per_page = NULL, $page = NULL) { 798 | /* https://www.flickr.com/services/api/flickr.galleries.getList.html */ 799 | return $this->call('flickr.galleries.getList', array('user_id' => $user_id, 'per_page' => $per_page, 'page' => $page)); 800 | } 801 | 802 | function galleries_getListForPhoto ($photo_id, $per_page = NULL, $page = NULL) { 803 | /* https://www.flickr.com/services/api/flickr.galleries.getListForPhoto.html */ 804 | return $this->call('flickr.galleries.getListForPhoto', array('photo_id' => $photo_id, 'per_page' => $per_page, 'page' => $page)); 805 | } 806 | 807 | function galleries_getPhotos ($gallery_id, $extras = NULL, $per_page = NULL, $page = NULL) { 808 | /* https://www.flickr.com/services/api/flickr.galleries.getPhotos.html */ 809 | return $this->call('flickr.galleries.getPhotos', array('gallery_id' => $gallery_id, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 810 | } 811 | 812 | /* Groups Methods */ 813 | function groups_browse ($cat_id = NULL) { 814 | /* https://www.flickr.com/services/api/flickr.groups.browse.html */ 815 | $this->request("flickr.groups.browse", array("cat_id"=>$cat_id)); 816 | return $this->parsed_response ? $this->parsed_response['category'] : false; 817 | } 818 | 819 | function groups_getInfo ($group_id, $lang = NULL) { 820 | /* https://www.flickr.com/services/api/flickr.groups.getInfo.html */ 821 | return $this->call('flickr.groups.getInfo', array('group_id' => $group_id, 'lang' => $lang)); 822 | } 823 | 824 | function groups_search ($text, $per_page = NULL, $page = NULL) { 825 | /* https://www.flickr.com/services/api/flickr.groups.search.html */ 826 | $this->request("flickr.groups.search", array("text"=>$text,"per_page"=>$per_page,"page"=>$page)); 827 | return $this->parsed_response ? $this->parsed_response['groups'] : false; 828 | } 829 | 830 | /* Groups Members Methods */ 831 | function groups_members_getList ($group_id, $membertypes = NULL, $per_page = NULL, $page = NULL) { 832 | /* https://www.flickr.com/services/api/flickr.groups.members.getList.html */ 833 | return $this->call('flickr.groups.members.getList', array('group_id' => $group_id, 'membertypes' => $membertypes, 'per_page' => $per_page, 'page' => $page)); 834 | } 835 | 836 | /* Groups Pools Methods */ 837 | function groups_pools_add ($photo_id, $group_id) { 838 | /* https://www.flickr.com/services/api/flickr.groups.pools.add.html */ 839 | $this->request("flickr.groups.pools.add", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); 840 | return $this->parsed_response ? true : false; 841 | } 842 | 843 | function groups_pools_getContext ($photo_id, $group_id, $num_prev = NULL, $num_next = NULL) { 844 | /* https://www.flickr.com/services/api/flickr.groups.pools.getContext.html */ 845 | return $this->call('flickr.groups.pools.getContext', array('photo_id' => $photo_id, 'group_id' => $group_id, 'num_prev' => $num_prev, 'num_next' => $num_next)); 846 | } 847 | 848 | function groups_pools_getGroups ($page = NULL, $per_page = NULL) { 849 | /* https://www.flickr.com/services/api/flickr.groups.pools.getGroups.html */ 850 | $this->request("flickr.groups.pools.getGroups", array('page'=>$page, 'per_page'=>$per_page)); 851 | return $this->parsed_response ? $this->parsed_response['groups'] : false; 852 | } 853 | 854 | function groups_pools_getPhotos ($group_id, $tags = NULL, $user_id = NULL, $jump_to = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 855 | /* https://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html */ 856 | if (is_array($extras)) { 857 | $extras = implode(",", $extras); 858 | } 859 | return $this->call('flickr.groups.pools.getPhotos', array('group_id' => $group_id, 'tags' => $tags, 'user_id' => $user_id, 'jump_to' => $jump_to, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 860 | } 861 | 862 | function groups_pools_remove ($photo_id, $group_id) { 863 | /* https://www.flickr.com/services/api/flickr.groups.pools.remove.html */ 864 | $this->request("flickr.groups.pools.remove", array("photo_id"=>$photo_id, "group_id"=>$group_id), TRUE); 865 | return $this->parsed_response ? true : false; 866 | } 867 | 868 | /* Interestingness methods */ 869 | function interestingness_getList ($date = NULL, $use_panda = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 870 | /* https://www.flickr.com/services/api/flickr.interestingness.getList.html */ 871 | if (is_array($extras)) { 872 | $extras = implode(",", $extras); 873 | } 874 | 875 | return $this->call('flickr.interestingness.getList', array('date' => $date, 'use_panda' => $use_panda, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 876 | } 877 | 878 | /* Machine Tag methods */ 879 | function machinetags_getNamespaces ($predicate = NULL, $per_page = NULL, $page = NULL) { 880 | /* https://www.flickr.com/services/api/flickr.machinetags.getNamespaces.html */ 881 | return $this->call('flickr.machinetags.getNamespaces', array('predicate' => $predicate, 'per_page' => $per_page, 'page' => $page)); 882 | } 883 | 884 | function machinetags_getPairs ($namespace = NULL, $predicate = NULL, $per_page = NULL, $page = NULL) { 885 | /* https://www.flickr.com/services/api/flickr.machinetags.getPairs.html */ 886 | return $this->call('flickr.machinetags.getPairs', array('namespace' => $namespace, 'predicate' => $predicate, 'per_page' => $per_page, 'page' => $page)); 887 | } 888 | 889 | function machinetags_getPredicates ($namespace = NULL, $per_page = NULL, $page = NULL) { 890 | /* https://www.flickr.com/services/api/flickr.machinetags.getPredicates.html */ 891 | return $this->call('flickr.machinetags.getPredicates', array('namespace' => $namespace, 'per_page' => $per_page, 'page' => $page)); 892 | } 893 | 894 | function machinetags_getRecentValues ($namespace = NULL, $predicate = NULL, $added_since = NULL) { 895 | /* https://www.flickr.com/services/api/flickr.machinetags.getRecentValues.html */ 896 | return $this->call('flickr.machinetags.getRecentValues', array('namespace' => $namespace, 'predicate' => $predicate, 'added_since' => $added_since)); 897 | } 898 | 899 | function machinetags_getValues ($namespace, $predicate, $per_page = NULL, $page = NULL, $usage = NULL) { 900 | /* https://www.flickr.com/services/api/flickr.machinetags.getValues.html */ 901 | return $this->call('flickr.machinetags.getValues', array('namespace' => $namespace, 'predicate' => $predicate, 'per_page' => $per_page, 'page' => $page, 'usage' => $usage)); 902 | } 903 | 904 | /* Panda methods */ 905 | function panda_getList () { 906 | /* https://www.flickr.com/services/api/flickr.panda.getList.html */ 907 | return $this->call('flickr.panda.getList', array()); 908 | } 909 | 910 | function panda_getPhotos ($panda_name, $extras = NULL, $per_page = NULL, $page = NULL) { 911 | /* https://www.flickr.com/services/api/flickr.panda.getPhotos.html */ 912 | return $this->call('flickr.panda.getPhotos', array('panda_name' => $panda_name, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 913 | } 914 | 915 | /* People methods */ 916 | function people_findByEmail ($find_email) { 917 | /* https://www.flickr.com/services/api/flickr.people.findByEmail.html */ 918 | $this->request("flickr.people.findByEmail", array("find_email"=>$find_email)); 919 | return $this->parsed_response ? $this->parsed_response['user'] : false; 920 | } 921 | 922 | function people_findByUsername ($username) { 923 | /* https://www.flickr.com/services/api/flickr.people.findByUsername.html */ 924 | $this->request("flickr.people.findByUsername", array("username"=>$username)); 925 | return $this->parsed_response ? $this->parsed_response['user'] : false; 926 | } 927 | 928 | function people_getInfo ($user_id) { 929 | /* https://www.flickr.com/services/api/flickr.people.getInfo.html */ 930 | $this->request("flickr.people.getInfo", array("user_id"=>$user_id)); 931 | return $this->parsed_response ? $this->parsed_response['person'] : false; 932 | } 933 | 934 | function people_getPhotos ($user_id, $args = array()) { 935 | /* This function strays from the method of arguments that I've 936 | * used in the other functions for the fact that there are just 937 | * so many arguments to this API method. What you'll need to do 938 | * is pass an associative array to the function containing the 939 | * arguments you want to pass to the API. For example: 940 | * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any")); 941 | * This will return photos tagged with either "brown" or "cow" 942 | * or both. See the API documentation (link below) for a full 943 | * list of arguments. 944 | */ 945 | 946 | /* https://www.flickr.com/services/api/flickr.people.getPhotos.html */ 947 | return $this->call('flickr.people.getPhotos', array_merge(array('user_id' => $user_id), $args)); 948 | } 949 | 950 | function people_getPhotosOf ($user_id, $extras = NULL, $per_page = NULL, $page = NULL) { 951 | /* https://www.flickr.com/services/api/flickr.people.getPhotosOf.html */ 952 | return $this->call('flickr.people.getPhotosOf', array('user_id' => $user_id, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 953 | } 954 | 955 | function people_getPublicGroups ($user_id) { 956 | /* https://www.flickr.com/services/api/flickr.people.getPublicGroups.html */ 957 | $this->request("flickr.people.getPublicGroups", array("user_id"=>$user_id)); 958 | return $this->parsed_response ? $this->parsed_response['groups']['group'] : false; 959 | } 960 | 961 | function people_getPublicPhotos ($user_id, $safe_search = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 962 | /* https://www.flickr.com/services/api/flickr.people.getPublicPhotos.html */ 963 | return $this->call('flickr.people.getPublicPhotos', array('user_id' => $user_id, 'safe_search' => $safe_search, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 964 | } 965 | 966 | function people_getUploadStatus () { 967 | /* https://www.flickr.com/services/api/flickr.people.getUploadStatus.html */ 968 | /* Requires Authentication */ 969 | $this->request("flickr.people.getUploadStatus"); 970 | return $this->parsed_response ? $this->parsed_response['user'] : false; 971 | } 972 | 973 | 974 | /* Photos Methods */ 975 | function photos_addTags ($photo_id, $tags) { 976 | /* https://www.flickr.com/services/api/flickr.photos.addTags.html */ 977 | $this->request("flickr.photos.addTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); 978 | return $this->parsed_response ? true : false; 979 | } 980 | 981 | function photos_delete ($photo_id) { 982 | /* https://www.flickr.com/services/api/flickr.photos.delete.html */ 983 | $this->request("flickr.photos.delete", array("photo_id"=>$photo_id), TRUE); 984 | return $this->parsed_response ? true : false; 985 | } 986 | 987 | function photos_getAllContexts ($photo_id) { 988 | /* https://www.flickr.com/services/api/flickr.photos.getAllContexts.html */ 989 | $this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id)); 990 | return $this->parsed_response ? $this->parsed_response : false; 991 | } 992 | 993 | function photos_getContactsPhotos ($count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) { 994 | /* https://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */ 995 | $this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras)); 996 | return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; 997 | } 998 | 999 | function photos_getContactsPublicPhotos ($user_id, $count = NULL, $just_friends = NULL, $single_photo = NULL, $include_self = NULL, $extras = NULL) { 1000 | /* https://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */ 1001 | $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)); 1002 | return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false; 1003 | } 1004 | 1005 | function photos_getContext ($photo_id, $num_prev = NULL, $num_next = NULL, $extras = NULL, $order_by = NULL) { 1006 | /* https://www.flickr.com/services/api/flickr.photos.getContext.html */ 1007 | return $this->call('flickr.photos.getContext', array('photo_id' => $photo_id, 'num_prev' => $num_prev, 'num_next' => $num_next, 'extras' => $extras, 'order_by' => $order_by)); 1008 | } 1009 | 1010 | function photos_getCounts ($dates = NULL, $taken_dates = NULL) { 1011 | /* https://www.flickr.com/services/api/flickr.photos.getCounts.html */ 1012 | $this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates)); 1013 | return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false; 1014 | } 1015 | 1016 | function photos_getExif ($photo_id, $secret = NULL) { 1017 | /* https://www.flickr.com/services/api/flickr.photos.getExif.html */ 1018 | $this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret)); 1019 | return $this->parsed_response ? $this->parsed_response['photo'] : false; 1020 | } 1021 | 1022 | function photos_getFavorites ($photo_id, $page = NULL, $per_page = NULL) { 1023 | /* https://www.flickr.com/services/api/flickr.photos.getFavorites.html */ 1024 | $this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page)); 1025 | return $this->parsed_response ? $this->parsed_response['photo'] : false; 1026 | } 1027 | 1028 | function photos_getInfo ($photo_id, $secret = NULL, $humandates = NULL, $privacy_filter = NULL, $get_contexts = NULL) { 1029 | /* https://www.flickr.com/services/api/flickr.photos.getInfo.html */ 1030 | return $this->call('flickr.photos.getInfo', array('photo_id' => $photo_id, 'secret' => $secret, 'humandates' => $humandates, 'privacy_filter' => $privacy_filter, 'get_contexts' => $get_contexts)); 1031 | } 1032 | 1033 | function photos_getNotInSet ($max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL, $privacy_filter = NULL, $media = NULL, $min_upload_date = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 1034 | /* https://www.flickr.com/services/api/flickr.photos.getNotInSet.html */ 1035 | return $this->call('flickr.photos.getNotInSet', array('max_upload_date' => $max_upload_date, 'min_taken_date' => $min_taken_date, 'max_taken_date' => $max_taken_date, 'privacy_filter' => $privacy_filter, 'media' => $media, 'min_upload_date' => $min_upload_date, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1036 | } 1037 | 1038 | function photos_getPerms ($photo_id) { 1039 | /* https://www.flickr.com/services/api/flickr.photos.getPerms.html */ 1040 | $this->request("flickr.photos.getPerms", array("photo_id"=>$photo_id)); 1041 | return $this->parsed_response ? $this->parsed_response['perms'] : false; 1042 | } 1043 | 1044 | function photos_getRecent ($jump_to = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 1045 | /* https://www.flickr.com/services/api/flickr.photos.getRecent.html */ 1046 | if (is_array($extras)) { 1047 | $extras = implode(",", $extras); 1048 | } 1049 | return $this->call('flickr.photos.getRecent', array('jump_to' => $jump_to, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1050 | } 1051 | 1052 | function photos_getSizes ($photo_id) { 1053 | /* https://www.flickr.com/services/api/flickr.photos.getSizes.html */ 1054 | $this->request("flickr.photos.getSizes", array("photo_id"=>$photo_id)); 1055 | return $this->parsed_response ? $this->parsed_response['sizes']['size'] : false; 1056 | } 1057 | 1058 | function photos_getUntagged ($min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL, $privacy_filter = NULL, $media = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 1059 | /* https://www.flickr.com/services/api/flickr.photos.getUntagged.html */ 1060 | return $this->call('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, 'media' => $media, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1061 | } 1062 | 1063 | function photos_getWithGeoData ($args = array()) { 1064 | /* See the documentation included with the photos_search() function. 1065 | * I'm using the same style of arguments for this function. The only 1066 | * difference here is that this doesn't require any arguments. The 1067 | * flickr.photos.search method requires at least one search parameter. 1068 | */ 1069 | /* https://www.flickr.com/services/api/flickr.photos.getWithGeoData.html */ 1070 | $this->request("flickr.photos.getWithGeoData", $args); 1071 | return $this->parsed_response ? $this->parsed_response['photos'] : false; 1072 | } 1073 | 1074 | function photos_getWithoutGeoData ($args = array()) { 1075 | /* See the documentation included with the photos_search() function. 1076 | * I'm using the same style of arguments for this function. The only 1077 | * difference here is that this doesn't require any arguments. The 1078 | * flickr.photos.search method requires at least one search parameter. 1079 | */ 1080 | /* https://www.flickr.com/services/api/flickr.photos.getWithoutGeoData.html */ 1081 | $this->request("flickr.photos.getWithoutGeoData", $args); 1082 | return $this->parsed_response ? $this->parsed_response['photos'] : false; 1083 | } 1084 | 1085 | function photos_recentlyUpdated ($min_date, $extras = NULL, $per_page = NULL, $page = NULL) { 1086 | /* https://www.flickr.com/services/api/flickr.photos.recentlyUpdated.html */ 1087 | return $this->call('flickr.photos.recentlyUpdated', array('min_date' => $min_date, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1088 | } 1089 | 1090 | function photos_removeTag ($tag_id) { 1091 | /* https://www.flickr.com/services/api/flickr.photos.removeTag.html */ 1092 | $this->request("flickr.photos.removeTag", array("tag_id"=>$tag_id), TRUE); 1093 | return $this->parsed_response ? true : false; 1094 | } 1095 | 1096 | function photos_search ($args = array()) { 1097 | /* This function strays from the method of arguments that I've 1098 | * used in the other functions for the fact that there are just 1099 | * so many arguments to this API method. What you'll need to do 1100 | * is pass an associative array to the function containing the 1101 | * arguments you want to pass to the API. For example: 1102 | * $photos = $f->photos_search(array("tags"=>"brown,cow", "tag_mode"=>"any")); 1103 | * This will return photos tagged with either "brown" or "cow" 1104 | * or both. See the API documentation (link below) for a full 1105 | * list of arguments. 1106 | */ 1107 | 1108 | /* https://www.flickr.com/services/api/flickr.photos.search.html */ 1109 | $result = $this->request("flickr.photos.search", $args); 1110 | return ($this->parsed_response) ? $this->parsed_response['photos'] : false; 1111 | } 1112 | 1113 | function photos_setContentType ($photo_id, $content_type) { 1114 | /* https://www.flickr.com/services/api/flickr.photos.setContentType.html */ 1115 | return $this->call('flickr.photos.setContentType', array('photo_id' => $photo_id, 'content_type' => $content_type)); 1116 | } 1117 | 1118 | function photos_setDates ($photo_id, $date_posted = NULL, $date_taken = NULL, $date_taken_granularity = NULL) { 1119 | /* https://www.flickr.com/services/api/flickr.photos.setDates.html */ 1120 | $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); 1121 | return $this->parsed_response ? true : false; 1122 | } 1123 | 1124 | function photos_setMeta ($photo_id, $title, $description) { 1125 | /* https://www.flickr.com/services/api/flickr.photos.setMeta.html */ 1126 | $this->request("flickr.photos.setMeta", array("photo_id"=>$photo_id, "title"=>$title, "description"=>$description), TRUE); 1127 | return $this->parsed_response ? true : false; 1128 | } 1129 | 1130 | function photos_setPerms ($photo_id, $is_public, $is_friend, $is_family, $perm_comment, $perm_addmeta) { 1131 | /* https://www.flickr.com/services/api/flickr.photos.setPerms.html */ 1132 | $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); 1133 | return $this->parsed_response ? true : false; 1134 | } 1135 | 1136 | function photos_setSafetyLevel ($photo_id, $safety_level = NULL, $hidden = NULL) { 1137 | /* https://www.flickr.com/services/api/flickr.photos.setSafetyLevel.html */ 1138 | return $this->call('flickr.photos.setSafetyLevel', array('photo_id' => $photo_id, 'safety_level' => $safety_level, 'hidden' => $hidden)); 1139 | } 1140 | 1141 | function photos_setTags ($photo_id, $tags) { 1142 | /* https://www.flickr.com/services/api/flickr.photos.setTags.html */ 1143 | $this->request("flickr.photos.setTags", array("photo_id"=>$photo_id, "tags"=>$tags), TRUE); 1144 | return $this->parsed_response ? true : false; 1145 | } 1146 | 1147 | /* Photos - Comments Methods */ 1148 | function photos_comments_addComment ($photo_id, $comment_text) { 1149 | /* https://www.flickr.com/services/api/flickr.photos.comments.addComment.html */ 1150 | $this->request("flickr.photos.comments.addComment", array("photo_id" => $photo_id, "comment_text"=>$comment_text), TRUE); 1151 | return $this->parsed_response ? $this->parsed_response['comment'] : false; 1152 | } 1153 | 1154 | function photos_comments_deleteComment ($comment_id) { 1155 | /* https://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html */ 1156 | $this->request("flickr.photos.comments.deleteComment", array("comment_id" => $comment_id), TRUE); 1157 | return $this->parsed_response ? true : false; 1158 | } 1159 | 1160 | function photos_comments_editComment ($comment_id, $comment_text) { 1161 | /* https://www.flickr.com/services/api/flickr.photos.comments.editComment.html */ 1162 | $this->request("flickr.photos.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); 1163 | return $this->parsed_response ? true : false; 1164 | } 1165 | 1166 | function photos_comments_getList ($photo_id, $min_comment_date = NULL, $max_comment_date = NULL, $page = NULL, $per_page = NULL, $include_faves = NULL) { 1167 | /* https://www.flickr.com/services/api/flickr.photos.comments.getList.html */ 1168 | return $this->call('flickr.photos.comments.getList', array('photo_id' => $photo_id, 'min_comment_date' => $min_comment_date, 'max_comment_date' => $max_comment_date, 'page' => $page, 'per_page' => $per_page, 'include_faves' => $include_faves)); 1169 | } 1170 | 1171 | function photos_comments_getRecentForContacts ($date_lastcomment = NULL, $contacts_filter = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 1172 | /* https://www.flickr.com/services/api/flickr.photos.comments.getRecentForContacts.html */ 1173 | return $this->call('flickr.photos.comments.getRecentForContacts', array('date_lastcomment' => $date_lastcomment, 'contacts_filter' => $contacts_filter, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1174 | } 1175 | 1176 | /* Photos - Geo Methods */ 1177 | function photos_geo_batchCorrectLocation ($lat, $lon, $accuracy, $place_id = NULL, $woe_id = NULL) { 1178 | /* https://www.flickr.com/services/api/flickr.photos.geo.batchCorrectLocation.html */ 1179 | return $this->call('flickr.photos.geo.batchCorrectLocation', array('lat' => $lat, 'lon' => $lon, 'accuracy' => $accuracy, 'place_id' => $place_id, 'woe_id' => $woe_id)); 1180 | } 1181 | 1182 | function photos_geo_correctLocation ($photo_id, $place_id = NULL, $woe_id = NULL) { 1183 | /* https://www.flickr.com/services/api/flickr.photos.geo.correctLocation.html */ 1184 | return $this->call('flickr.photos.geo.correctLocation', array('photo_id' => $photo_id, 'place_id' => $place_id, 'woe_id' => $woe_id)); 1185 | } 1186 | 1187 | function photos_geo_getLocation ($photo_id) { 1188 | /* https://www.flickr.com/services/api/flickr.photos.geo.getLocation.html */ 1189 | $this->request("flickr.photos.geo.getLocation", array("photo_id"=>$photo_id)); 1190 | return $this->parsed_response ? $this->parsed_response['photo'] : false; 1191 | } 1192 | 1193 | function photos_geo_getPerms ($photo_id) { 1194 | /* https://www.flickr.com/services/api/flickr.photos.geo.getPerms.html */ 1195 | $this->request("flickr.photos.geo.getPerms", array("photo_id"=>$photo_id)); 1196 | return $this->parsed_response ? $this->parsed_response['perms'] : false; 1197 | } 1198 | 1199 | function photos_geo_photosForLocation ($lat, $lon, $accuracy = NULL, $extras = NULL, $per_page = NULL, $page = NULL) { 1200 | /* https://www.flickr.com/services/api/flickr.photos.geo.photosForLocation.html */ 1201 | return $this->call('flickr.photos.geo.photosForLocation', array('lat' => $lat, 'lon' => $lon, 'accuracy' => $accuracy, 'extras' => $extras, 'per_page' => $per_page, 'page' => $page)); 1202 | } 1203 | 1204 | function photos_geo_removeLocation ($photo_id) { 1205 | /* https://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html */ 1206 | $this->request("flickr.photos.geo.removeLocation", array("photo_id"=>$photo_id), TRUE); 1207 | return $this->parsed_response ? true : false; 1208 | } 1209 | 1210 | function photos_geo_setContext ($photo_id, $context) { 1211 | /* https://www.flickr.com/services/api/flickr.photos.geo.setContext.html */ 1212 | return $this->call('flickr.photos.geo.setContext', array('photo_id' => $photo_id, 'context' => $context)); 1213 | } 1214 | 1215 | function photos_geo_setLocation ($photo_id, $lat, $lon, $accuracy = NULL, $context = NULL, $bookmark_id = NULL) { 1216 | /* https://www.flickr.com/services/api/flickr.photos.geo.setLocation.html */ 1217 | return $this->call('flickr.photos.geo.setLocation', array('photo_id' => $photo_id, 'lat' => $lat, 'lon' => $lon, 'accuracy' => $accuracy, 'context' => $context, 'bookmark_id' => $bookmark_id)); 1218 | } 1219 | 1220 | function photos_geo_setPerms ($is_public, $is_contact, $is_friend, $is_family, $photo_id) { 1221 | /* https://www.flickr.com/services/api/flickr.photos.geo.setPerms.html */ 1222 | return $this->call('flickr.photos.geo.setPerms', array('is_public' => $is_public, 'is_contact' => $is_contact, 'is_friend' => $is_friend, 'is_family' => $is_family, 'photo_id' => $photo_id)); 1223 | } 1224 | 1225 | /* Photos - Licenses Methods */ 1226 | function photos_licenses_getInfo () { 1227 | /* https://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html */ 1228 | $this->request("flickr.photos.licenses.getInfo"); 1229 | return $this->parsed_response ? $this->parsed_response['licenses']['license'] : false; 1230 | } 1231 | 1232 | function photos_licenses_setLicense ($photo_id, $license_id) { 1233 | /* https://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html */ 1234 | /* Requires Authentication */ 1235 | $this->request("flickr.photos.licenses.setLicense", array("photo_id"=>$photo_id, "license_id"=>$license_id), TRUE); 1236 | return $this->parsed_response ? true : false; 1237 | } 1238 | 1239 | /* Photos - Notes Methods */ 1240 | function photos_notes_add ($photo_id, $note_x, $note_y, $note_w, $note_h, $note_text) { 1241 | /* https://www.flickr.com/services/api/flickr.photos.notes.add.html */ 1242 | $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); 1243 | return $this->parsed_response ? $this->parsed_response['note'] : false; 1244 | } 1245 | 1246 | function photos_notes_delete ($note_id) { 1247 | /* https://www.flickr.com/services/api/flickr.photos.notes.delete.html */ 1248 | $this->request("flickr.photos.notes.delete", array("note_id" => $note_id), TRUE); 1249 | return $this->parsed_response ? true : false; 1250 | } 1251 | 1252 | function photos_notes_edit ($note_id, $note_x, $note_y, $note_w, $note_h, $note_text) { 1253 | /* https://www.flickr.com/services/api/flickr.photos.notes.edit.html */ 1254 | $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); 1255 | return $this->parsed_response ? true : false; 1256 | } 1257 | 1258 | /* Photos - Transform Methods */ 1259 | function photos_transform_rotate ($photo_id, $degrees) { 1260 | /* https://www.flickr.com/services/api/flickr.photos.transform.rotate.html */ 1261 | $this->request("flickr.photos.transform.rotate", array("photo_id" => $photo_id, "degrees" => $degrees), TRUE); 1262 | return $this->parsed_response ? true : false; 1263 | } 1264 | 1265 | /* Photos - People Methods */ 1266 | function photos_people_add ($photo_id, $user_id, $person_x = NULL, $person_y = NULL, $person_w = NULL, $person_h = NULL) { 1267 | /* https://www.flickr.com/services/api/flickr.photos.people.add.html */ 1268 | return $this->call('flickr.photos.people.add', array('photo_id' => $photo_id, 'user_id' => $user_id, 'person_x' => $person_x, 'person_y' => $person_y, 'person_w' => $person_w, 'person_h' => $person_h)); 1269 | } 1270 | 1271 | function photos_people_delete ($photo_id, $user_id, $email = NULL) { 1272 | /* https://www.flickr.com/services/api/flickr.photos.people.delete.html */ 1273 | return $this->call('flickr.photos.people.delete', array('photo_id' => $photo_id, 'user_id' => $user_id, 'email' => $email)); 1274 | } 1275 | 1276 | function photos_people_deleteCoords ($photo_id, $user_id) { 1277 | /* https://www.flickr.com/services/api/flickr.photos.people.deleteCoords.html */ 1278 | return $this->call('flickr.photos.people.deleteCoords', array('photo_id' => $photo_id, 'user_id' => $user_id)); 1279 | } 1280 | 1281 | function photos_people_editCoords ($photo_id, $user_id, $person_x, $person_y, $person_w, $person_h, $email = NULL) { 1282 | /* https://www.flickr.com/services/api/flickr.photos.people.editCoords.html */ 1283 | return $this->call('flickr.photos.people.editCoords', array('photo_id' => $photo_id, 'user_id' => $user_id, 'person_x' => $person_x, 'person_y' => $person_y, 'person_w' => $person_w, 'person_h' => $person_h, 'email' => $email)); 1284 | } 1285 | 1286 | function photos_people_getList ($photo_id) { 1287 | /* https://www.flickr.com/services/api/flickr.photos.people.getList.html */ 1288 | return $this->call('flickr.photos.people.getList', array('photo_id' => $photo_id)); 1289 | } 1290 | 1291 | /* Photos - Upload Methods */ 1292 | function photos_upload_checkTickets ($tickets) { 1293 | /* https://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html */ 1294 | if (is_array($tickets)) { 1295 | $tickets = implode(",", $tickets); 1296 | } 1297 | $this->request("flickr.photos.upload.checkTickets", array("tickets" => $tickets), TRUE); 1298 | return $this->parsed_response ? $this->parsed_response['uploader']['ticket'] : false; 1299 | } 1300 | 1301 | /* Photosets Methods */ 1302 | function photosets_addPhoto ($photoset_id, $photo_id) { 1303 | /* https://www.flickr.com/services/api/flickr.photosets.addPhoto.html */ 1304 | $this->request("flickr.photosets.addPhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); 1305 | return $this->parsed_response ? true : false; 1306 | } 1307 | 1308 | function photosets_create ($title, $description, $primary_photo_id) { 1309 | /* https://www.flickr.com/services/api/flickr.photosets.create.html */ 1310 | $this->request("flickr.photosets.create", array("title" => $title, "primary_photo_id" => $primary_photo_id, "description" => $description), TRUE); 1311 | return $this->parsed_response ? $this->parsed_response['photoset'] : false; 1312 | } 1313 | 1314 | function photosets_delete ($photoset_id) { 1315 | /* https://www.flickr.com/services/api/flickr.photosets.delete.html */ 1316 | $this->request("flickr.photosets.delete", array("photoset_id" => $photoset_id), TRUE); 1317 | return $this->parsed_response ? true : false; 1318 | } 1319 | 1320 | function photosets_editMeta ($photoset_id, $title, $description = NULL) { 1321 | /* https://www.flickr.com/services/api/flickr.photosets.editMeta.html */ 1322 | $this->request("flickr.photosets.editMeta", array("photoset_id" => $photoset_id, "title" => $title, "description" => $description), TRUE); 1323 | return $this->parsed_response ? true : false; 1324 | } 1325 | 1326 | function photosets_editPhotos ($photoset_id, $primary_photo_id, $photo_ids) { 1327 | /* https://www.flickr.com/services/api/flickr.photosets.editPhotos.html */ 1328 | $this->request("flickr.photosets.editPhotos", array("photoset_id" => $photoset_id, "primary_photo_id" => $primary_photo_id, "photo_ids" => $photo_ids), TRUE); 1329 | return $this->parsed_response ? true : false; 1330 | } 1331 | 1332 | function photosets_getContext ($photo_id, $photoset_id, $num_prev = NULL, $num_next = NULL) { 1333 | /* https://www.flickr.com/services/api/flickr.photosets.getContext.html */ 1334 | return $this->call('flickr.photosets.getContext', array('photo_id' => $photo_id, 'photoset_id' => $photoset_id, 'num_prev' => $num_prev, 'num_next' => $num_next)); 1335 | } 1336 | 1337 | function photosets_getInfo ($photoset_id) { 1338 | /* https://www.flickr.com/services/api/flickr.photosets.getInfo.html */ 1339 | $this->request("flickr.photosets.getInfo", array("photoset_id" => $photoset_id)); 1340 | return $this->parsed_response ? $this->parsed_response['photoset'] : false; 1341 | } 1342 | 1343 | function photosets_getList ($user_id = NULL, $page = NULL, $per_page = NULL, $primary_photo_extras = NULL) { 1344 | /* https://www.flickr.com/services/api/flickr.photosets.getList.html */ 1345 | $this->request("flickr.photosets.getList", array("user_id" => $user_id, 'page' => $page, 'per_page' => $per_page, 'primary_photo_extras' => $primary_photo_extras)); 1346 | return $this->parsed_response ? $this->parsed_response['photosets'] : false; 1347 | } 1348 | 1349 | function photosets_getPhotos ($photoset_id, $extras = NULL, $privacy_filter = NULL, $per_page = NULL, $page = NULL, $media = NULL) { 1350 | /* https://www.flickr.com/services/api/flickr.photosets.getPhotos.html */ 1351 | return $this->call('flickr.photosets.getPhotos', array('photoset_id' => $photoset_id, 'extras' => $extras, 'privacy_filter' => $privacy_filter, 'per_page' => $per_page, 'page' => $page, 'media' => $media)); 1352 | } 1353 | 1354 | function photosets_orderSets ($photoset_ids) { 1355 | /* https://www.flickr.com/services/api/flickr.photosets.orderSets.html */ 1356 | if (is_array($photoset_ids)) { 1357 | $photoset_ids = implode(",", $photoset_ids); 1358 | } 1359 | $this->request("flickr.photosets.orderSets", array("photoset_ids" => $photoset_ids), TRUE); 1360 | return $this->parsed_response ? true : false; 1361 | } 1362 | 1363 | function photosets_removePhoto ($photoset_id, $photo_id) { 1364 | /* https://www.flickr.com/services/api/flickr.photosets.removePhoto.html */ 1365 | $this->request("flickr.photosets.removePhoto", array("photoset_id" => $photoset_id, "photo_id" => $photo_id), TRUE); 1366 | return $this->parsed_response ? true : false; 1367 | } 1368 | 1369 | function photosets_removePhotos ($photoset_id, $photo_ids) { 1370 | /* https://www.flickr.com/services/api/flickr.photosets.removePhotos.html */ 1371 | return $this->call('flickr.photosets.removePhotos', array('photoset_id' => $photoset_id, 'photo_ids' => $photo_ids)); 1372 | } 1373 | 1374 | function photosets_reorderPhotos ($photoset_id, $photo_ids) { 1375 | /* https://www.flickr.com/services/api/flickr.photosets.reorderPhotos.html */ 1376 | return $this->call('flickr.photosets.reorderPhotos', array('photoset_id' => $photoset_id, 'photo_ids' => $photo_ids)); 1377 | } 1378 | 1379 | function photosets_setPrimaryPhoto ($photoset_id, $photo_id) { 1380 | /* https://www.flickr.com/services/api/flickr.photosets.setPrimaryPhoto.html */ 1381 | return $this->call('flickr.photosets.setPrimaryPhoto', array('photoset_id' => $photoset_id, 'photo_id' => $photo_id)); 1382 | } 1383 | 1384 | /* Photosets Comments Methods */ 1385 | function photosets_comments_addComment ($photoset_id, $comment_text) { 1386 | /* https://www.flickr.com/services/api/flickr.photosets.comments.addComment.html */ 1387 | $this->request("flickr.photosets.comments.addComment", array("photoset_id" => $photoset_id, "comment_text"=>$comment_text), TRUE); 1388 | return $this->parsed_response ? $this->parsed_response['comment'] : false; 1389 | } 1390 | 1391 | function photosets_comments_deleteComment ($comment_id) { 1392 | /* https://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html */ 1393 | $this->request("flickr.photosets.comments.deleteComment", array("comment_id" => $comment_id), TRUE); 1394 | return $this->parsed_response ? true : false; 1395 | } 1396 | 1397 | function photosets_comments_editComment ($comment_id, $comment_text) { 1398 | /* https://www.flickr.com/services/api/flickr.photosets.comments.editComment.html */ 1399 | $this->request("flickr.photosets.comments.editComment", array("comment_id" => $comment_id, "comment_text"=>$comment_text), TRUE); 1400 | return $this->parsed_response ? true : false; 1401 | } 1402 | 1403 | function photosets_comments_getList ($photoset_id) { 1404 | /* https://www.flickr.com/services/api/flickr.photosets.comments.getList.html */ 1405 | $this->request("flickr.photosets.comments.getList", array("photoset_id"=>$photoset_id)); 1406 | return $this->parsed_response ? $this->parsed_response['comments'] : false; 1407 | } 1408 | 1409 | /* Places Methods */ 1410 | function places_find ($query) { 1411 | /* https://www.flickr.com/services/api/flickr.places.find.html */ 1412 | return $this->call('flickr.places.find', array('query' => $query)); 1413 | } 1414 | 1415 | function places_findByLatLon ($lat, $lon, $accuracy = NULL) { 1416 | /* https://www.flickr.com/services/api/flickr.places.findByLatLon.html */ 1417 | return $this->call('flickr.places.findByLatLon', array('lat' => $lat, 'lon' => $lon, 'accuracy' => $accuracy)); 1418 | } 1419 | 1420 | function places_getChildrenWithPhotosPublic ($place_id = NULL, $woe_id = NULL) { 1421 | /* https://www.flickr.com/services/api/flickr.places.getChildrenWithPhotosPublic.html */ 1422 | return $this->call('flickr.places.getChildrenWithPhotosPublic', array('place_id' => $place_id, 'woe_id' => $woe_id)); 1423 | } 1424 | 1425 | function places_getInfo ($place_id = NULL, $woe_id = NULL) { 1426 | /* https://www.flickr.com/services/api/flickr.places.getInfo.html */ 1427 | return $this->call('flickr.places.getInfo', array('place_id' => $place_id, 'woe_id' => $woe_id)); 1428 | } 1429 | 1430 | function places_getInfoByUrl ($url) { 1431 | /* https://www.flickr.com/services/api/flickr.places.getInfoByUrl.html */ 1432 | return $this->call('flickr.places.getInfoByUrl', array('url' => $url)); 1433 | } 1434 | 1435 | function places_getPlaceTypes () { 1436 | /* https://www.flickr.com/services/api/flickr.places.getPlaceTypes.html */ 1437 | return $this->call('flickr.places.getPlaceTypes', array()); 1438 | } 1439 | 1440 | function places_getShapeHistory ($place_id = NULL, $woe_id = NULL) { 1441 | /* https://www.flickr.com/services/api/flickr.places.getShapeHistory.html */ 1442 | return $this->call('flickr.places.getShapeHistory', array('place_id' => $place_id, 'woe_id' => $woe_id)); 1443 | } 1444 | 1445 | function places_getTopPlacesList ($place_type_id, $date = NULL, $woe_id = NULL, $place_id = NULL) { 1446 | /* https://www.flickr.com/services/api/flickr.places.getTopPlacesList.html */ 1447 | return $this->call('flickr.places.getTopPlacesList', array('place_type_id' => $place_type_id, 'date' => $date, 'woe_id' => $woe_id, 'place_id' => $place_id)); 1448 | } 1449 | 1450 | function places_placesForBoundingBox ($bbox, $place_type = NULL, $place_type_id = NULL, $recursive = NULL) { 1451 | /* https://www.flickr.com/services/api/flickr.places.placesForBoundingBox.html */ 1452 | return $this->call('flickr.places.placesForBoundingBox', array('bbox' => $bbox, 'place_type' => $place_type, 'place_type_id' => $place_type_id, 'recursive' => $recursive)); 1453 | } 1454 | 1455 | function places_placesForContacts ($place_type = NULL, $place_type_id = NULL, $woe_id = NULL, $place_id = NULL, $threshold = NULL, $contacts = NULL, $min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL) { 1456 | /* https://www.flickr.com/services/api/flickr.places.placesForContacts.html */ 1457 | return $this->call('flickr.places.placesForContacts', array('place_type' => $place_type, 'place_type_id' => $place_type_id, 'woe_id' => $woe_id, 'place_id' => $place_id, 'threshold' => $threshold, 'contacts' => $contacts, 'min_upload_date' => $min_upload_date, 'max_upload_date' => $max_upload_date, 'min_taken_date' => $min_taken_date, 'max_taken_date' => $max_taken_date)); 1458 | } 1459 | 1460 | function places_placesForTags ($place_type_id, $woe_id = NULL, $place_id = NULL, $threshold = NULL, $tags = NULL, $tag_mode = NULL, $machine_tags = NULL, $machine_tag_mode = NULL, $min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL) { 1461 | /* https://www.flickr.com/services/api/flickr.places.placesForTags.html */ 1462 | return $this->call('flickr.places.placesForTags', array('place_type_id' => $place_type_id, 'woe_id' => $woe_id, 'place_id' => $place_id, 'threshold' => $threshold, 'tags' => $tags, 'tag_mode' => $tag_mode, 'machine_tags' => $machine_tags, 'machine_tag_mode' => $machine_tag_mode, 'min_upload_date' => $min_upload_date, 'max_upload_date' => $max_upload_date, 'min_taken_date' => $min_taken_date, 'max_taken_date' => $max_taken_date)); 1463 | } 1464 | 1465 | function places_placesForUser ($place_type_id = NULL, $place_type = NULL, $woe_id = NULL, $place_id = NULL, $threshold = NULL, $min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL) { 1466 | /* https://www.flickr.com/services/api/flickr.places.placesForUser.html */ 1467 | return $this->call('flickr.places.placesForUser', array('place_type_id' => $place_type_id, 'place_type' => $place_type, 'woe_id' => $woe_id, 'place_id' => $place_id, 'threshold' => $threshold, 'min_upload_date' => $min_upload_date, 'max_upload_date' => $max_upload_date, 'min_taken_date' => $min_taken_date, 'max_taken_date' => $max_taken_date)); 1468 | } 1469 | 1470 | function places_resolvePlaceId ($place_id) { 1471 | /* https://www.flickr.com/services/api/flickr.places.resolvePlaceId.html */ 1472 | $rsp = $this->call('flickr.places.resolvePlaceId', array('place_id' => $place_id)); 1473 | return $rsp ? $rsp['location'] : $rsp; 1474 | } 1475 | 1476 | function places_resolvePlaceURL ($url) { 1477 | /* https://www.flickr.com/services/api/flickr.places.resolvePlaceURL.html */ 1478 | $rsp = $this->call('flickr.places.resolvePlaceURL', array('url' => $url)); 1479 | return $rsp ? $rsp['location'] : $rsp; 1480 | } 1481 | 1482 | function places_tagsForPlace ($woe_id = NULL, $place_id = NULL, $min_upload_date = NULL, $max_upload_date = NULL, $min_taken_date = NULL, $max_taken_date = NULL) { 1483 | /* https://www.flickr.com/services/api/flickr.places.tagsForPlace.html */ 1484 | return $this->call('flickr.places.tagsForPlace', array('woe_id' => $woe_id, 'place_id' => $place_id, 'min_upload_date' => $min_upload_date, 'max_upload_date' => $max_upload_date, 'min_taken_date' => $min_taken_date, 'max_taken_date' => $max_taken_date)); 1485 | } 1486 | 1487 | /* Prefs Methods */ 1488 | function prefs_getContentType () { 1489 | /* https://www.flickr.com/services/api/flickr.prefs.getContentType.html */ 1490 | $rsp = $this->call('flickr.prefs.getContentType', array()); 1491 | return $rsp ? $rsp['person'] : $rsp; 1492 | } 1493 | 1494 | function prefs_getGeoPerms () { 1495 | /* https://www.flickr.com/services/api/flickr.prefs.getGeoPerms.html */ 1496 | return $this->call('flickr.prefs.getGeoPerms', array()); 1497 | } 1498 | 1499 | function prefs_getHidden () { 1500 | /* https://www.flickr.com/services/api/flickr.prefs.getHidden.html */ 1501 | $rsp = $this->call('flickr.prefs.getHidden', array()); 1502 | return $rsp ? $rsp['person'] : $rsp; 1503 | } 1504 | 1505 | function prefs_getPrivacy () { 1506 | /* https://www.flickr.com/services/api/flickr.prefs.getPrivacy.html */ 1507 | $rsp = $this->call('flickr.prefs.getPrivacy', array()); 1508 | return $rsp ? $rsp['person'] : $rsp; 1509 | } 1510 | 1511 | function prefs_getSafetyLevel () { 1512 | /* https://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html */ 1513 | $rsp = $this->call('flickr.prefs.getSafetyLevel', array()); 1514 | return $rsp ? $rsp['person'] : $rsp; 1515 | } 1516 | 1517 | /* Reflection Methods */ 1518 | function reflection_getMethodInfo ($method_name) { 1519 | /* https://www.flickr.com/services/api/flickr.reflection.getMethodInfo.html */ 1520 | $this->request("flickr.reflection.getMethodInfo", array("method_name" => $method_name)); 1521 | return $this->parsed_response ? $this->parsed_response : false; 1522 | } 1523 | 1524 | function reflection_getMethods () { 1525 | /* https://www.flickr.com/services/api/flickr.reflection.getMethods.html */ 1526 | $this->request("flickr.reflection.getMethods"); 1527 | return $this->parsed_response ? $this->parsed_response['methods']['method'] : false; 1528 | } 1529 | 1530 | /* Stats Methods */ 1531 | function stats_getCollectionDomains ($date, $collection_id = NULL, $per_page = NULL, $page = NULL) { 1532 | /* https://www.flickr.com/services/api/flickr.stats.getCollectionDomains.html */ 1533 | return $this->call('flickr.stats.getCollectionDomains', array('date' => $date, 'collection_id' => $collection_id, 'per_page' => $per_page, 'page' => $page)); 1534 | } 1535 | 1536 | function stats_getCollectionReferrers ($date, $domain, $collection_id = NULL, $per_page = NULL, $page = NULL) { 1537 | /* https://www.flickr.com/services/api/flickr.stats.getCollectionReferrers.html */ 1538 | return $this->call('flickr.stats.getCollectionReferrers', array('date' => $date, 'domain' => $domain, 'collection_id' => $collection_id, 'per_page' => $per_page, 'page' => $page)); 1539 | } 1540 | 1541 | function stats_getCollectionStats ($date, $collection_id) { 1542 | /* https://www.flickr.com/services/api/flickr.stats.getCollectionStats.html */ 1543 | return $this->call('flickr.stats.getCollectionStats', array('date' => $date, 'collection_id' => $collection_id)); 1544 | } 1545 | 1546 | function stats_getCSVFiles () { 1547 | /* https://www.flickr.com/services/api/flickr.stats.getCSVFiles.html */ 1548 | return $this->call('flickr.stats.getCSVFiles', array()); 1549 | } 1550 | 1551 | function stats_getPhotoDomains ($date, $photo_id = NULL, $per_page = NULL, $page = NULL) { 1552 | /* https://www.flickr.com/services/api/flickr.stats.getPhotoDomains.html */ 1553 | return $this->call('flickr.stats.getPhotoDomains', array('date' => $date, 'photo_id' => $photo_id, 'per_page' => $per_page, 'page' => $page)); 1554 | } 1555 | 1556 | function stats_getPhotoReferrers ($date, $domain, $photo_id = NULL, $per_page = NULL, $page = NULL) { 1557 | /* https://www.flickr.com/services/api/flickr.stats.getPhotoReferrers.html */ 1558 | return $this->call('flickr.stats.getPhotoReferrers', array('date' => $date, 'domain' => $domain, 'photo_id' => $photo_id, 'per_page' => $per_page, 'page' => $page)); 1559 | } 1560 | 1561 | function stats_getPhotosetDomains ($date, $photoset_id = NULL, $per_page = NULL, $page = NULL) { 1562 | /* https://www.flickr.com/services/api/flickr.stats.getPhotosetDomains.html */ 1563 | return $this->call('flickr.stats.getPhotosetDomains', array('date' => $date, 'photoset_id' => $photoset_id, 'per_page' => $per_page, 'page' => $page)); 1564 | } 1565 | 1566 | function stats_getPhotosetReferrers ($date, $domain, $photoset_id = NULL, $per_page = NULL, $page = NULL) { 1567 | /* https://www.flickr.com/services/api/flickr.stats.getPhotosetReferrers.html */ 1568 | return $this->call('flickr.stats.getPhotosetReferrers', array('date' => $date, 'domain' => $domain, 'photoset_id' => $photoset_id, 'per_page' => $per_page, 'page' => $page)); 1569 | } 1570 | 1571 | function stats_getPhotosetStats ($date, $photoset_id) { 1572 | /* https://www.flickr.com/services/api/flickr.stats.getPhotosetStats.html */ 1573 | return $this->call('flickr.stats.getPhotosetStats', array('date' => $date, 'photoset_id' => $photoset_id)); 1574 | } 1575 | 1576 | function stats_getPhotoStats ($date, $photo_id) { 1577 | /* https://www.flickr.com/services/api/flickr.stats.getPhotoStats.html */ 1578 | return $this->call('flickr.stats.getPhotoStats', array('date' => $date, 'photo_id' => $photo_id)); 1579 | } 1580 | 1581 | function stats_getPhotostreamDomains ($date, $per_page = NULL, $page = NULL) { 1582 | /* https://www.flickr.com/services/api/flickr.stats.getPhotostreamDomains.html */ 1583 | return $this->call('flickr.stats.getPhotostreamDomains', array('date' => $date, 'per_page' => $per_page, 'page' => $page)); 1584 | } 1585 | 1586 | function stats_getPhotostreamReferrers ($date, $domain, $per_page = NULL, $page = NULL) { 1587 | /* https://www.flickr.com/services/api/flickr.stats.getPhotostreamReferrers.html */ 1588 | return $this->call('flickr.stats.getPhotostreamReferrers', array('date' => $date, 'domain' => $domain, 'per_page' => $per_page, 'page' => $page)); 1589 | } 1590 | 1591 | function stats_getPhotostreamStats ($date) { 1592 | /* https://www.flickr.com/services/api/flickr.stats.getPhotostreamStats.html */ 1593 | return $this->call('flickr.stats.getPhotostreamStats', array('date' => $date)); 1594 | } 1595 | 1596 | function stats_getPopularPhotos ($date = NULL, $sort = NULL, $per_page = NULL, $page = NULL) { 1597 | /* https://www.flickr.com/services/api/flickr.stats.getPopularPhotos.html */ 1598 | return $this->call('flickr.stats.getPopularPhotos', array('date' => $date, 'sort' => $sort, 'per_page' => $per_page, 'page' => $page)); 1599 | } 1600 | 1601 | function stats_getTotalViews ($date = NULL) { 1602 | /* https://www.flickr.com/services/api/flickr.stats.getTotalViews.html */ 1603 | return $this->call('flickr.stats.getTotalViews', array('date' => $date)); 1604 | } 1605 | 1606 | /* Tags Methods */ 1607 | function tags_getClusterPhotos ($tag, $cluster_id) { 1608 | /* https://www.flickr.com/services/api/flickr.tags.getClusterPhotos.html */ 1609 | return $this->call('flickr.tags.getClusterPhotos', array('tag' => $tag, 'cluster_id' => $cluster_id)); 1610 | } 1611 | 1612 | function tags_getClusters ($tag) { 1613 | /* https://www.flickr.com/services/api/flickr.tags.getClusters.html */ 1614 | return $this->call('flickr.tags.getClusters', array('tag' => $tag)); 1615 | } 1616 | 1617 | function tags_getHotList ($period = NULL, $count = NULL) { 1618 | /* https://www.flickr.com/services/api/flickr.tags.getHotList.html */ 1619 | $this->request("flickr.tags.getHotList", array("period" => $period, "count" => $count)); 1620 | return $this->parsed_response ? $this->parsed_response['hottags'] : false; 1621 | } 1622 | 1623 | function tags_getListPhoto ($photo_id) { 1624 | /* https://www.flickr.com/services/api/flickr.tags.getListPhoto.html */ 1625 | $this->request("flickr.tags.getListPhoto", array("photo_id" => $photo_id)); 1626 | return $this->parsed_response ? $this->parsed_response['photo']['tags']['tag'] : false; 1627 | } 1628 | 1629 | function tags_getListUser ($user_id = NULL) { 1630 | /* https://www.flickr.com/services/api/flickr.tags.getListUser.html */ 1631 | $this->request("flickr.tags.getListUser", array("user_id" => $user_id)); 1632 | return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; 1633 | } 1634 | 1635 | function tags_getListUserPopular ($user_id = NULL, $count = NULL) { 1636 | /* https://www.flickr.com/services/api/flickr.tags.getListUserPopular.html */ 1637 | $this->request("flickr.tags.getListUserPopular", array("user_id" => $user_id, "count" => $count)); 1638 | return $this->parsed_response ? $this->parsed_response['who']['tags']['tag'] : false; 1639 | } 1640 | 1641 | function tags_getListUserRaw ($tag = NULL) { 1642 | /* https://www.flickr.com/services/api/flickr.tags.getListUserRaw.html */ 1643 | return $this->call('flickr.tags.getListUserRaw', array('tag' => $tag)); 1644 | } 1645 | 1646 | function tags_getRelated ($tag) { 1647 | /* https://www.flickr.com/services/api/flickr.tags.getRelated.html */ 1648 | $this->request("flickr.tags.getRelated", array("tag" => $tag)); 1649 | return $this->parsed_response ? $this->parsed_response['tags'] : false; 1650 | } 1651 | 1652 | function test_echo ($args = array()) { 1653 | /* https://www.flickr.com/services/api/flickr.test.echo.html */ 1654 | $this->request("flickr.test.echo", $args); 1655 | return $this->parsed_response ? $this->parsed_response : false; 1656 | } 1657 | 1658 | function test_login () { 1659 | /* https://www.flickr.com/services/api/flickr.test.login.html */ 1660 | $this->request("flickr.test.login"); 1661 | return $this->parsed_response ? $this->parsed_response['user'] : false; 1662 | } 1663 | 1664 | function urls_getGroup ($group_id) { 1665 | /* https://www.flickr.com/services/api/flickr.urls.getGroup.html */ 1666 | $this->request("flickr.urls.getGroup", array("group_id"=>$group_id)); 1667 | return $this->parsed_response ? $this->parsed_response['group']['url'] : false; 1668 | } 1669 | 1670 | function urls_getUserPhotos ($user_id = NULL) { 1671 | /* https://www.flickr.com/services/api/flickr.urls.getUserPhotos.html */ 1672 | $this->request("flickr.urls.getUserPhotos", array("user_id"=>$user_id)); 1673 | return $this->parsed_response ? $this->parsed_response['user']['url'] : false; 1674 | } 1675 | 1676 | function urls_getUserProfile ($user_id = NULL) { 1677 | /* https://www.flickr.com/services/api/flickr.urls.getUserProfile.html */ 1678 | $this->request("flickr.urls.getUserProfile", array("user_id"=>$user_id)); 1679 | return $this->parsed_response ? $this->parsed_response['user']['url'] : false; 1680 | } 1681 | 1682 | function urls_lookupGallery ($url) { 1683 | /* https://www.flickr.com/services/api/flickr.urls.lookupGallery.html */ 1684 | return $this->call('flickr.urls.lookupGallery', array('url' => $url)); 1685 | } 1686 | 1687 | function urls_lookupGroup ($url) { 1688 | /* https://www.flickr.com/services/api/flickr.urls.lookupGroup.html */ 1689 | $this->request("flickr.urls.lookupGroup", array("url"=>$url)); 1690 | return $this->parsed_response ? $this->parsed_response['group'] : false; 1691 | } 1692 | 1693 | function urls_lookupUser ($url) { 1694 | /* https://www.flickr.com/services/api/flickr.photos.notes.edit.html */ 1695 | $this->request("flickr.urls.lookupUser", array("url"=>$url)); 1696 | return $this->parsed_response ? $this->parsed_response['user'] : false; 1697 | } 1698 | } 1699 | } 1700 | 1701 | if ( !class_exists('phpFlickr_pager') ) { 1702 | class phpFlickr_pager { 1703 | var $phpFlickr, $per_page, $method, $args, $results, $global_phpFlickr; 1704 | var $total = null, $page = 0, $pages = null, $photos, $_extra = null; 1705 | 1706 | 1707 | function phpFlickr_pager($phpFlickr, $method = null, $args = null, $per_page = 30) { 1708 | $this->per_page = $per_page; 1709 | $this->method = $method; 1710 | $this->args = $args; 1711 | $this->set_phpFlickr($phpFlickr); 1712 | } 1713 | 1714 | function set_phpFlickr($phpFlickr) { 1715 | if ( is_a($phpFlickr, 'phpFlickr') ) { 1716 | $this->phpFlickr = $phpFlickr; 1717 | if ( $this->phpFlickr->cache ) { 1718 | $this->args['per_page'] = 500; 1719 | } else { 1720 | $this->args['per_page'] = (int) $this->per_page; 1721 | } 1722 | } 1723 | } 1724 | 1725 | function __sleep() { 1726 | return array( 1727 | 'method', 1728 | 'args', 1729 | 'per_page', 1730 | 'page', 1731 | '_extra', 1732 | ); 1733 | } 1734 | 1735 | function load($page) { 1736 | $allowed_methods = array( 1737 | 'flickr.photos.search' => 'photos', 1738 | 'flickr.photosets.getPhotos' => 'photoset', 1739 | ); 1740 | if ( !in_array($this->method, array_keys($allowed_methods)) ) return false; 1741 | 1742 | if ( $this->phpFlickr->cache ) { 1743 | $min = ($page - 1) * $this->per_page; 1744 | $max = $page * $this->per_page - 1; 1745 | if ( floor($min/500) == floor($max/500) ) { 1746 | $this->args['page'] = floor($min/500) + 1; 1747 | $this->results = $this->phpFlickr->call($this->method, $this->args); 1748 | if ( $this->results ) { 1749 | $this->results = $this->results[$allowed_methods[$this->method]]; 1750 | $this->photos = array_slice($this->results['photo'], $min % 500, $this->per_page); 1751 | $this->total = $this->results['total']; 1752 | $this->pages = ceil($this->results['total'] / $this->per_page); 1753 | return true; 1754 | } else { 1755 | return false; 1756 | } 1757 | } else { 1758 | $this->args['page'] = floor($min/500) + 1; 1759 | $this->results = $this->phpFlickr->call($this->method, $this->args); 1760 | if ( $this->results ) { 1761 | $this->results = $this->results[$allowed_methods[$this->method]]; 1762 | 1763 | $this->photos = array_slice($this->results['photo'], $min % 500); 1764 | $this->total = $this->results['total']; 1765 | $this->pages = ceil($this->results['total'] / $this->per_page); 1766 | 1767 | $this->args['page'] = floor($min/500) + 2; 1768 | $this->results = $this->phpFlickr->call($this->method, $this->args); 1769 | if ( $this->results ) { 1770 | $this->results = $this->results[$allowed_methods[$this->method]]; 1771 | $this->photos = array_merge($this->photos, array_slice($this->results['photo'], 0, $max % 500 + 1)); 1772 | } 1773 | return true; 1774 | } else { 1775 | return false; 1776 | } 1777 | 1778 | } 1779 | } else { 1780 | $this->args['page'] = $page; 1781 | $this->results = $this->phpFlickr->call($this->method, $this->args); 1782 | if ( $this->results ) { 1783 | $this->results = $this->results[$allowed_methods[$this->method]]; 1784 | 1785 | $this->photos = $this->results['photo']; 1786 | $this->total = $this->results['total']; 1787 | $this->pages = $this->results['pages']; 1788 | return true; 1789 | } else { 1790 | return false; 1791 | } 1792 | } 1793 | } 1794 | 1795 | function get($page = null) { 1796 | if ( is_null($page) ) { 1797 | $page = $this->page; 1798 | } else { 1799 | $this->page = $page; 1800 | } 1801 | if ( $this->load($page) ) { 1802 | return $this->photos; 1803 | } 1804 | $this->total = 0; 1805 | $this->pages = 0; 1806 | return array(); 1807 | } 1808 | 1809 | function next() { 1810 | $this->page++; 1811 | if ( $this->load($this->page) ) { 1812 | return $this->photos; 1813 | } 1814 | $this->total = 0; 1815 | $this->pages = 0; 1816 | return array(); 1817 | } 1818 | 1819 | } 1820 | } 1821 | 1822 | ?> 1823 | --------------------------------------------------------------------------------