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

📄 yahoo.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        }        if (isset($options['zip']) && !preg_match('/(^\d{5}$)|(^\d{5}-\d{4}$)/', $options['zip'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'zip': {$options['zip']}");        }        $hasLocation = false;        $locationFields = array('street', 'city', 'state', 'zip', 'location');        foreach ($locationFields as $field) {            if (isset($options[$field]) && $options[$field] != '') {                $hasLocation = true;                break;            }        }        if (!$hasLocation && (!isset($options['latitude']) || !isset($options['longitude']))) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception('Location data are required but missing');        }        if (!in_array($options['sort'], array('relevance', 'title', 'distance', 'rating'))) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'sort': {$options['sort']}");        }    }    /**     * Validate News Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validateNewsSearch(array $options)    {        $validOptions = array('appid', 'query', 'results', 'start', 'sort', 'language', 'type', 'site');        $this->_compareOptions($options, $validOptions);        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 50, true);        if (isset($options['results']) && !$between->setMin(1)->setMax(50)->isValid($options['results'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'results': {$options['results']}");        }        if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'start': {$options['start']}");        }        if (isset($options['language'])) {            $this->_validateLanguage($options['language']);        }        $this->_validateInArray('sort', $options['sort'], array('rank', 'date'));        $this->_validateInArray('type', $options['type'], array('all', 'any', 'phrase'));    }    /**     * Validate Page Data Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validatePageDataSearch(array $options)    {        $validOptions = array('appid', 'query', 'results', 'start', 'domain_only');        $this->_compareOptions($options, $validOptions);        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 100, true);        if (isset($options['results']) && !$between->setMin(1)->setMax(100)->isValid($options['results'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'results': {$options['results']}");        }        if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'start': {$options['start']}");        }    }    /**     * Validate Video Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validateVideoSearch(array $options)    {        $validOptions = array('appid', 'query', 'type', 'results', 'start', 'format', 'adult_ok');        $this->_compareOptions($options, $validOptions);        if (isset($options['type'])) {            $this->_validateInArray('type', $options['type'], array('all', 'any', 'phrase'));        }        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 50, true);        if (isset($options['results']) && !$between->setMin(1)->setMax(50)->isValid($options['results'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'results': {$options['results']}");        }        if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'start': {$options['start']}");        }        if (isset($options['format'])) {            $this->_validateInArray('format', $options['format'], array('any', 'avi', 'flash', 'mpeg', 'msmedia', 'quicktime', 'realmedia'));        }    }    /**     * Validate Web Search Options     *     * @param  array $options     * @return void     * @throws Zend_Service_Exception     */    protected function _validateWebSearch(array $options)    {        $validOptions = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok',                              'similar_ok', 'country', 'site', 'subscription', 'license');        $this->_compareOptions($options, $validOptions);        /**         * @see Zend_Validate_Between         */        require_once 'Zend/Validate/Between.php';        $between = new Zend_Validate_Between(1, 100, true);        if (isset($options['results']) && !$between->setMin(1)->setMax(100)->isValid($options['results'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'results': {$options['results']}");        }        if (isset($options['start']) && !$between->setMin(1)->setMax(1000)->isValid($options['start'])) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option 'start': {$options['start']}");        }        if (isset($options['language'])) {            $this->_validateLanguage($options['language']);        }        $this->_validateInArray('type', $options['type'], array('all', 'any', 'phrase'));        $this->_validateInArray('format', $options['format'], array('any', 'html', 'msword', 'pdf', 'ppt', 'rss',                                                                    'txt', 'xls'));        $this->_validateInArray('license', $options['license'], array('any', 'cc_any', 'cc_commercial',                                                                      'cc_modifiable'));    }    /**     * Prepare options for sending to Yahoo!     *     * @param  string $query          Search Query     * @param  array  $options        User specified options     * @param  array  $defaultOptions Required/Default options     * @return array     */    protected function _prepareOptions($query, array $options, array $defaultOptions = array())    {        $options['appid'] = $this->appId;        $options['query'] = (string) $query;        return array_merge($defaultOptions, $options);    }    /**     * Throws an exception if the chosen language is not supported     *     * @param  string $lang Language code     * @return void     * @throws Zend_Service_Exception     */    protected function _validateLanguage($lang)    {        $languages = array('ar', 'bg', 'ca', 'szh', 'tzh', 'hr', 'cs', 'da', 'nl', 'en', 'et', 'fi', 'fr', 'de', 'el',            'he', 'hu', 'is', 'id', 'it', 'ja', 'ko', 'lv', 'lt', 'no', 'fa', 'pl', 'pt', 'ro', 'ru', 'sk', 'sr', 'sl',            'es', 'sv', 'th', 'tr'            );        if (!in_array($lang, $languages)) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("The selected language '$lang' is not supported");        }    }    /**     * Utility function to check for a difference between two arrays.     *     * @param  array $options      User specified options     * @param  array $validOptions Valid options     * @return void     * @throws Zend_Service_Exception if difference is found (e.g., unsupported query option)     */    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: ' . join(', ', $difference));        }    }    /**     * Check that a named value is in the given array     *     * @param  string $name  Name associated with the value     * @param  mixed  $value Value     * @param  array  $array Array in which to check for the value     * @return void     * @throws Zend_Service_Exception     */    protected function _validateInArray($name, $value, array $array)    {        if (!in_array($value, $array)) {            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception("Invalid value for option '$name': $value");        }    }    /**     * Check if response is an error     *     * @param  DOMDocument $dom DOM Object representing the result XML     * @return void     * @throws Zend_Service_Exception Thrown when the result from Yahoo! is an error     */    protected static function _checkErrors(DOMDocument $dom)    {        $xpath = new DOMXPath($dom);        $xpath->registerNamespace('yapi', 'urn:yahoo:api');        if ($xpath->query('//yapi:Error')->length >= 1) {            $message = $xpath->query('//yapi:Error/yapi:Message/text()')->item(0)->data;            /**             * @see Zend_Service_Exception             */            require_once 'Zend/Service/Exception.php';            throw new Zend_Service_Exception($message);        }    }}

⌨️ 快捷键说明

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