Meus documentos/programas/Zend/projetos/lab/yahooSeach/class.yahooSeach.inc

00001 <?PHP
00002    
00003    require_once 'class.yahooWebSearch.inc';
00004    require_once 'class.yahooImageSearch.inc';
00005 
00006    class yahooSearch {
00007         
00008         private $_resource;
00009         private $_appid;
00010         private $_query;
00011         private $_type;
00012         
00020         public function __construct($appid, $query, $type = 'web') {
00021 
00022                 $this->_type = $type;
00023                 
00024                 if ($type == 'web') {
00025                  $this->_resource = file_get_contents('http://api.search.yahoo.com/WebSearchService/V1/webSearch?query=' . $query . '&appid=' . $appid);
00026                 } else if ($type == 'image') {
00027                  $this->_resource = file_get_contents('http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?query=' . $query . '&appid=' . $appid);
00028                 }          
00029                 
00030                 $this->_appid = $appid;
00031                 $this->_query = $query;
00032         
00033         }
00034         
00040         private function _getParam($param) {
00041                 
00042          preg_match_all("|$param=\"(.*)\"|U", $this->_resource, 
00043                              $out, PREG_PATTERN_ORDER); 
00044      return $out[1][0];                 
00045      
00046         }
00047         
00052         public function getTotalResultsAvailable() {
00053                        
00054                 return $this->_getParam('totalResultsAvailable');
00055                              
00056         }
00057         
00062         public function getTotalResultsReturned() {
00063                 
00064             return $this->_getParam('totalResultsReturned');    
00065         
00066         }
00067         
00072         public function getResource() {
00073           
00074                 return $this->_resource;
00075                         
00076         }
00077         
00083         public function query($query) {
00084 
00085           if ($this->_type == 'web') {  
00086            $this->_resource = file_get_contents('http://api.search.yahoo.com/WebSearchService/V1/webSearch?query=' . $query . '&appid=' . $this->_appid);               
00087           } else if ($this->_type == 'image') {
00088            $this->_resource = file_get_contents('http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?query=' . $query . '&appid=' . $this->_appid);                   
00089           }
00090                         
00091      $this->_query = $query;
00092          
00093         }
00094         
00099         public function search() {
00100           
00101           if ($this->_type == 'web') {  
00102                 return new yahooWebSearch($this);
00103           } else if ($this->_type == 'image') {
00104             return new yahooImageSearch($this);
00105           }
00106           
00107         }
00108         
00109    }
00110 
00111 ?>    

Generated on Tue Jan 23 16:06:41 2007 for Yahoo! Search for PHP by  doxygen 1.5.1-p1
Hosted by www.Geocities.ws

1