⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flickr.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category   Zend * @package    Zend_Service * @subpackage Flickr * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License * @version    $Id: Flickr.php 8064 2008-02-16 10:58:39Z thomas $ *//** * @category   Zend * @package    Zend_Service * @subpackage Flickr * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */class Zend_Service_Flickr{    /**     * Base URI for the REST client     */    const URI_BASE = 'http://www.flickr.com';    /**     * Your Flickr API key     *     * @var string     */    public $apiKey;    /**     * Reference to REST client object     *     * @var Zend_Rest_Client     */    protected $_restClient = null;    /**     * Performs object initializations     *     *  # Sets up character encoding     *  # Saves the API key     *     * @param  string $apiKey Your Flickr API key     * @return void     */    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 = (string) $apiKey;    }    /**     * Find Flickr photos by tag.     *     * 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:        Either 'any' for an OR combination of tags,     *                     or 'all' for an AND combination. 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  string|array $query   A single tag or an array of tags.     * @param  array        $options Additional parameters to refine your query.     * @return Zend_Service_Flickr_ResultSet     * @throws Zend_Service_Exception     */    public function tagSearch($query, array $options = array())    {        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');        $options['tags'] = is_array($query) ? implode(',', $query) : $query;        $options = $this->_prepareOptions($method, $options, $defaultOptions);        $this->_validateTagSearch($options);        // now search for photos        $restClient = $this->getRestClient();        $restClient->getHttpClient()->resetParameters();        $response = $restClient->restGet('/services/rest/', $options);        if ($response->isError()) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('An error occurred sending request. Status code: '                                           . $response->getStatus());        }        $dom = new DOMDocument();        $dom->loadXML($response->getBody());        self::_checkErrors($dom);        /**         * @see Zend_Service_Flickr_ResultSet         */        require_once 'Zend/Service/Flickr/ResultSet.php';        return new Zend_Service_Flickr_ResultSet($dom, $this);    }    /**     * Finds 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 or email     * @param  array  $options Additional parameters to refine your query.     * @return Zend_Service_Flickr_ResultSet     * @throws Zend_Service_Exception     */    public function userSearch($query, array $options = null)    {        static $method = 'flickr.people.getPublicPhotos';        static $defaultOptions = array('per_page' => 10,                                       'page'     => 1,                                       'extras'   => 'license, date_upload, date_taken, owner_name, icon_server');        // can't access by username, must get ID first        if (strchr($query, '@')) {            // optimistically hope this is an email            $options['user_id'] = $this->getIdByEmail($query);        } else {            // we can safely ignore this exception here            $options['user_id'] = $this->getIdByUsername($query);        }        $options = $this->_prepareOptions($method, $options, $defaultOptions);        $this->_validateUserSearch($options);        // now search for photos        $restClient = $this->getRestClient();        $restClient->getHttpClient()->resetParameters();        $response = $restClient->restGet('/services/rest/', $options);        if ($response->isError()) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('An error occurred sending request. Status code: '                                           . $response->getStatus());        }        $dom = new DOMDocument();        $dom->loadXML($response->getBody());        self::_checkErrors($dom);        /**         * @see Zend_Service_Flickr_ResultSet         */        require_once 'Zend/Service/Flickr/ResultSet.php';        return new Zend_Service_Flickr_ResultSet($dom, $this);    }    /**     * Utility function to find Flickr User IDs for usernames.     *     * (You can only find a user's photo with their NSID.)     *     * @param  string $username the username     * @return string the NSID (userid)     * @throws Zend_Service_Exception     */    public function getIdByUsername($username)    {        static $method = 'flickr.people.findByUsername';        $options = array('api_key' => $this->apiKey, 'method' => $method, 'username' => (string) $username);        if (empty($username)) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('You must supply a username');        }        $restClient = $this->getRestClient();        $restClient->getHttpClient()->resetParameters();        $response = $restClient->restGet('/services/rest/', $options);        if ($response->isError()) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('An error occurred sending request. Status code: '                                           . $response->getStatus());        }        $dom = new DOMDocument();        $dom->loadXML($response->getBody());        self::_checkErrors($dom);        $xpath = new DOMXPath($dom);        return (string) $xpath->query('//user')->item(0)->getAttribute('id');    }    /**     * Utility function to find Flickr User IDs for emails.     *     * (You can only find a user's photo with their NSID.)     *     * @param  string $email the email     * @return string the NSID (userid)     * @throws Zend_Service_Exception     */    public function getIdByEmail($email)    {        static $method = 'flickr.people.findByEmail';        if (empty($email)) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('You must supply an e-mail address');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -