📄 yahoo.php
字号:
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_Yahoo_PageDataResultSet */ require_once 'Zend/Service/Yahoo/PageDataResultSet.php'; return new Zend_Service_Yahoo_PageDataResultSet($dom); } /** * Perform a search of videos. The most basic query consists simply * of a plain text search, but you can also specify the format of * video. * * The specific options are: * 'type' => (all|any|phrase) How to parse the query terms * 'results' => int How many results to return, max is 50 * 'start' => int The start offset for search results * 'format' => (any|avi|flash|mpeg|msmedia|quicktime|realmedia) The type of videos to search for * 'adult_ok' => bool Flag to allow 'adult' videos. * * @param string $query the query to be run * @param array $options an optional array of query options * @return Zend_Service_Yahoo_VideoResultSet the search results * @throws Zend_Service_Exception */ public function videoSearch($query, array $options = array()) { static $defaultOptions = array('type' => 'all', 'results' => 10, 'start' => 1, 'format' => 'any'); $options = $this->_prepareOptions($query, $options, $defaultOptions); $this->_validateVideoSearch($options); $this->_rest->getHttpClient()->resetParameters(); $this->_rest->setUri('http://search.yahooapis.com'); $response = $this->_rest->restGet('/VideoSearchService/V1/videoSearch', $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_YahooVideoResultSet */ require_once 'Zend/Service/Yahoo/VideoResultSet.php'; return new Zend_Service_Yahoo_VideoResultSet($dom); } /** * Perform a web content search on search.yahoo.com. A basic query * consists simply of a text query. Additional options that can be * specified consist of: * 'results' => int How many results to return, max is 50 * 'start' => int The start offset for search results * 'language' => lang The target document language to match * 'type' => (all|any|phrase) How the query should be parsed * 'site' => string A site to which your search should be restricted * 'format' => (any|html|msword|pdf|ppt|rss|txt|xls) * 'adult_ok' => bool permit 'adult' content in the search results * 'similar_ok' => bool permit similar results in the result set * 'country' => string The country code for the content searched * 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched * * @param string $query the query being run * @param array $options any optional parameters * @return Zend_Service_Yahoo_WebResultSet The return set * @throws Zend_Service_Exception */ public function webSearch($query, array $options = array()) { static $defaultOptions = array('type' => 'all', 'start' => 1, 'license' => 'any', 'results' => 10, 'format' => 'any'); $options = $this->_prepareOptions($query, $options, $defaultOptions); $this->_validateWebSearch($options); $this->_rest->getHttpClient()->resetParameters(); $this->_rest->setUri('http://search.yahooapis.com'); $response = $this->_rest->restGet('/WebSearchService/V1/webSearch', $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_Yahoo_WebResultSet */ require_once 'Zend/Service/Yahoo/WebResultSet.php'; return new Zend_Service_Yahoo_WebResultSet($dom); } /** * Returns a reference to the REST client * * @return Zend_Rest_Client */ public function getRestClient() { return $this->_rest; } /** * Validate Inlink Data Search Options * * @param array $options * @return void * @throws Zend_Service_Exception */ protected function _validateInlinkDataSearch(array $options) { $validOptions = array('appid', 'query', 'results', 'start', 'entire_site', 'omit_inlinks'); $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['omit_inlinks'])) { $this->_validateInArray('omit_inlinks', $options['omit_inlinks'], array('none', 'domain', 'subdomain')); } } /** * Validate Image Search Options * * @param array $options * @return void * @throws Zend_Service_Exception */ protected function _validateImageSearch(array $options) { $validOptions = array('appid', 'query', 'type', 'results', 'start', 'format', 'coloration', 'adult_ok'); $this->_compareOptions($options, $validOptions); if (isset($options['type'])) { switch($options['type']) { case 'all': case 'any': case 'phrase': break; default: /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception("Invalid value for option 'type': '{$options['type']}'"); } } /** * @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'])) { switch ($options['format']) { case 'any': case 'bmp': case 'gif': case 'jpeg': case 'png': break; default: /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception("Invalid value for option 'format': {$options['format']}"); } } if (isset($options['coloration'])) { switch ($options['coloration']) { case 'any': case 'color': case 'bw': break; default: /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception("Invalid value for option 'coloration': " . "{$options['coloration']}"); } } } /** * Validate Local Search Options * * @param array $options * @return void * @throws Zend_Service_Exception */ protected function _validateLocalSearch(array $options) { $validOptions = array('appid', 'query', 'results', 'start', 'sort', 'radius', 'street', 'city', 'state', 'zip', 'location', 'latitude', 'longitude'); $this->_compareOptions($options, $validOptions); /** * @see Zend_Validate_Between */ require_once 'Zend/Validate/Between.php'; $between = new Zend_Validate_Between(1, 20, true); if (isset($options['results']) && !$between->setMin(1)->setMax(20)->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['longitude']) && !$between->setMin(-90)->setMax(90)->isValid($options['longitude'])) { /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception("Invalid value for option 'longitude': {$options['longitude']}"); } if (isset($options['latitude']) && !$between->setMin(-180)->setMax(180)->isValid($options['latitude'])) { /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception("Invalid value for option 'latitude': {$options['latitude']}");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -