【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“Flickr.php”一文,供大家参考学习
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE, and
* is available through the world-wide-web at the following URL:
* http://www.zend.com/license/framework/1_0.txt. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-
web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @package Zend_Service
* @subpackage Flickr
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
/**
* Zend_Service_Rest
*/
require_once 'Zend/Service/Rest.php';
/**
* Zend_Service_Exception
*/
require_once 'Zend/Service/Exception.php';
/**
* Zend_Service_Flickr_ResultSet
*/
require_once 'Zend/Service/Flickr/ResultSet.php';
/**
* Zend_Service_Flickr_Result
*/
require_once 'Zend/Service/Flickr/Result.php';
/**
* Zend_Service_Flickr_Image
*/
require_once 'Zend/Service/Flickr/Image.php';
/**
* Zend_Filter
*/
require_once 'Zend/Filter.php';
/**
* @package Zend_Service
* @subpackage Flickr
* @copyright Copyright (c) 2005-2006 Zend Technologies Inc. (http://www.zend.com)
* @license Zend Framework License version 1.0
*/
class Zend_Service_Flickr
{
/**
* Your Flickr API key
*
* @var string
*/
public $apiKey;
/**
* Zend_Service_Rest Object
*
* @var Zend_Service_Rest
*/
protected $_rest;
/**
* Zend_Service_Flickr Constructor, setup character encoding
*
* @param string $apiKey Your Flickr API key
*/
public function __construct($apiKey)
{
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
$this->apiKey = $apiKey;
$this->_rest = new Zend_Service_Rest();
$this->_rest->setUri('http://www.flickr.com');
$this->_array = array();
}
/**
* Find Flickr photos by tag.
*
* Additional query options include:
* # per_page: how many results to return per query
* # page: the starting page offset. first result will be (page -1)*per_page + 1
* # tag_mode: whether to 'any' or 'and' tags. Default is 'any'.
* # min_upload_date: Minimum upload date to search on. Date should be a unix timestamp.
* # max_upload_date: Maximum upload date to search on. Date should be a unix timestamp.
* # min_taken_date: Minimum upload date to search on. Date should be a MySQL datetime.
* # max_taken_date: Maximum upload date to search on. Date should be a MySQL datetime.
*
* @param mixed $query A single tag or an array of tags.
* @param array $options Additional parameters to refine your query.
* @return Zend_Service_Flickr_ResultSet
*/
public function tagSearch($query, $options = null)
{
static $method = 'flickr.photos.search';
static $defaultOptions = array('per_page' => 10,
'page' => 1,
'tag_mode' => 'or',
'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
// can't access by username, must get ID first
$options['tags'] = is_array($query) ? implode(',', $query) : $query;
$options = $this->_prepareOptions($method, $options, $defaultOptions);
$this->_validateTagSearch($options);
// now search for photos
$response = $this->_rest->restGet('/services/rest/', $options);
if ($response->isError()) {
throw new Zend_Service_Exception('An error occurered sending request. Status code: '
. $response->getStatus());
}
$dom = new DOMDocument();
$dom->loadXML($response->getBody());
self::_checkErrors($dom);
return new Zend_Service_Flickr_ResultSet($dom, $this);
}
/**
* Find Flickr photos by a user's username or email.
*
* Additional query options include:
* # per_page: how many results to return per query
* # page: the starting page offset. first result will be (page - 1) * per_page + 1
* # min_upload_date: Minimum upload date to search on. Date should be a unix timestamp.
* # max_upload_date: Maximum upload date to search on. Date should be a unix timestamp.
* # min_taken_date: Minimum upload date to search on. Date should be a MySQL datetime.
* # max_taken_date: Maximum upload date to search on. Date should be a MySQL datetime.
*
* @param string $query username
* @param array $options Additional parameters to refine your query.
* @return Zend_Service_Flickr_ResultSet|boolean
*/
public function userSearch($query, $options = null)
{
st