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

📄 flickr.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
        }        $options = array('api_key' => $this->apiKey, 'method' => $method, 'find_email' => (string) $email);        $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');    }    /**     * Returns Flickr photo details by for the given photo ID     *     * @param  string $id the NSID     * @return array of Zend_Service_Flickr_Image, details for the specified image     * @throws Zend_Service_Exception     */    public function getImageDetails($id)    {        static $method = 'flickr.photos.getSizes';        if (empty($id)) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('You must supply a photo ID');        }        $options = array('api_key' => $this->apiKey, 'method' => $method, 'photo_id' => $id);        $restClient = $this->getRestClient();        $restClient->getHttpClient()->resetParameters();        $response = $restClient->restGet('/services/rest/', $options);        $dom = new DOMDocument();        $dom->loadXML($response->getBody());        $xpath = new DOMXPath($dom);        self::_checkErrors($dom);        $retval = array();        /**         * @see Zend_Service_Flickr_Image         */        require_once 'Zend/Service/Flickr/Image.php';        foreach ($xpath->query('//size') as $size) {            $label = (string) $size->getAttribute('label');            $retval[$label] = new Zend_Service_Flickr_Image($size);        }        return $retval;    }    /**     * Returns a reference to the REST client, instantiating it if necessary     *     * @return Zend_Rest_Client     */    public function getRestClient()    {        if (null === $this->_restClient) {            /**             * @see Zend_Rest_Client             */            require_once 'Zend/Rest/Client.php';            $this->_restClient = new Zend_Rest_Client(self::URI_BASE);        }        return $this->_restClient;    }    /**     * Validate User Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validateUserSearch(array $options)    {        $validOptions = array('api_key', 'method', 'user_id', 'per_page', 'page', 'extras', 'min_upload_date',                              'min_taken_date', 'max_upload_date', 'max_taken_date');        $this->_compareOptions($options, $validOptions);        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 500, true);        if (!$between->isValid($options['per_page'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');        }        /**         * @see Zend_Validate_Int         */        require_once 'Zend/Validate/Int.php';        $int = new Zend_Validate_Int();        if (!$int->isValid($options['page'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');        }        // validate extras, which are delivered in csv format        if ($options['extras']) {            $extras = explode(',', $options['extras']);            $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');            foreach($extras as $extra) {                /**                 * @todo The following does not do anything [yet], so it is commented out.                 */                //in_array(trim($extra), $validExtras);            }        }    }    /**     * Validate Tag Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validateTagSearch(array $options)    {        $validOptions = array('method', 'api_key', 'user_id', 'tags', 'tag_mode', 'text', 'min_upload_date',                              'max_upload_date', 'min_taken_date', 'max_taken_date', 'license', 'sort',                              'privacy_filter', 'bbox', 'accuracy', 'machine_tags', 'machine_tag_mode', 'group_id',                              'extras', 'per_page', 'page');        $this->_compareOptions($options, $validOptions);        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 500, true);        if (!$between->isValid($options['per_page'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option');        }        /**         * @see Zend_Validate_Int         */        require_once 'Zend/Validate/Int.php';        $int = new Zend_Validate_Int();        if (!$int->isValid($options['page'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option');        }        // validate extras, which are delivered in csv format        if ($options['extras']) {            $extras = explode(',', $options['extras']);            $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');            foreach($extras as $extra) {                /**                 * @todo The following does not do anything [yet], so it is commented out.                 */                //in_array(trim($extra), $validExtras);            }        }    }    /**     * Throws an exception if and only if the response status indicates a failure     *     * @param  DOMDocument $dom     * @return void     * @throws Zend_Service_Exception     */    protected static function _checkErrors(DOMDocument $dom)    {        if ($dom->documentElement->getAttribute('stat') === 'fail') {            $xpath = new DOMXPath($dom);            $err = $xpath->query('//err')->item(0);            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('Search failed due to error: ' . $err->getAttribute('msg')                                           . ' (error #' . $err->getAttribute('code') . ')');        }    }    /**     * Prepare options for the request     *     * @param  string $method         Flickr Method to call     * @param  array  $options        User Options     * @param  array  $defaultOptions Default Options     * @return array Merged array of user and default/required options     */    protected function _prepareOptions($method, array $options, array $defaultOptions)    {        $options['method']  = (string) $method;        $options['api_key'] = $this->apiKey;        return array_merge($defaultOptions, $options);    }    /**     * Throws an exception if and only if any user options are invalid     *     * @param  array $options      User options     * @param  array $validOptions Valid options     * @return void     * @throws Zend_Service_Exception     */    protected function _compareOptions(array $options, array $validOptions)    {        $difference = array_diff(array_keys($options), $validOptions);        if ($difference) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('The following parameters are invalid: ' . implode(',', $difference));        }    }}

⌨️ 快捷键说明

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