My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/* phpYahoo Class 1.0.0
* Written by Jay (jay@gotfoo.org)
* Project Page: http://labs.gotfoo.org/phpyahoo.php
* Released under GNU Lesser General Public License (http://www.gnu.org/copyleft/lgpl.html)
* For more information about the class and upcoming tools and toys using it,
* visit http://labs.gotfoo.org/phpyahoo.php
*
*
*
*/
class phpYahoo {

var $appid = 'YAHOODEVELOPERID'; //----get one here http://api.search.yahoo.com/webservices/register_application
var $base_url = 'http://search.yahooapis.com/';
var $command_web_search = 'WebSearchService/V1/webSearch';
var $command_video_search = 'VideoSearchService/V1/videoSearch';
var $command_related_search = 'WebSearchService/V1/relatedSuggestion';
var $command_image_search = 'ImageSearchService/V1/imageSearch';


function request($command,$params)
{
$url = $this->base_url.$command.'?'.$params.'&appid='.$this->appid;
//echo $url;
$c = curl_init($url);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($c);
curl_close($c);

$xml = simplexml_load_string($response);

//print_r($response);
return $xml;
}

function request_web_search ($params) {
$xml = $this->request($this->command_web_search,$params);

$results = array();
$i = 0;
foreach($xml->Result as $result){
$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"displayUrl"=>$result->DisplayUrl,"modificationDate"=>$result->ModificationDate,"mimeType"=>$result->MimeType);
$i++;
}

return $results;
}

function request_related_search ($params) {
$xml = $this->request($this->command_related_search,$params);
$results = array();
$i = 0;
foreach($xml as $result){
$results[$i] = array("result"=>$result->Result);
$i++;
}
return $results;
}

function request_video_search ($params) {
$xml = $this->request($this->command_video_search,$params);
$results = array();
$i = 0;
foreach($xml->Result as $result){
$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"refererUrl"=>$result->RefererUrl,"fileSize"=>$result->FileSize,"fileFormat"=>$result->FileFormat,"weight"=>$result->Height,"width"=>$result->Width,"duration"=>$result->Duration,"streaming"=>$result->Streaming,"thumbnail"=>$result->Thumbnail->Url,"theight"=>$result->Thumbnail->Height,"twidth"=>$result->Thumbnail->Width);
$i++;
}

return $results;
}

function request_image_search ($params) {
$xml = $this->request($this->command_image_search,$params);
$results = array();
$i = 0;
foreach($xml->Result as $result){
$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"refererUrl"=>$result->RefererUrl,"fileSize"=>$result->FileSize,"fileFormat"=>$result->FileFormat,"weight"=>$result->Height,"width"=>$result->Width,"thumbnail"=>$result->Thumbnail->Url,"theight"=>$result->Thumbnail->Height,"twidth"=>$result->Thumbnail->Width);
$i++;
}

return $results;
}



function createQueryString($query,$results=null){
if (is_array($terms)) {
$extras = implode(" OR ", $query);
$extras = urlencode($extras);
$queryString = "query=$extras";
}else{
$query = urlencode($query);
$queryString = "query=$query";
}
$queryString .= "&results=$results";
return $queryString;
}

function searchWeb($query,$results=null){
//http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2

$response = $this->request_web_search($this->createQueryString($query,$results));
return $response;
}

function searchRelated($query,$results=null){
//http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2
$response = $this->request_related_search($this->createQueryString($query,$results));
return $response;
}



function searchVideos($query){
//http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=madonna&results=2

$response = $this->request_video_search($this->createQueryString($query,$results));
return $response;
}

function searchImages($query){
//http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=madonna&results=2

$response = $this->request_image_search($this->createQueryString($query,$results));
return $response;
}
}

?>
Show details Hide details

Change log

r7 by gotfoo on Jan 27, 2007   Diff
Moved remotely
Go to: 
Project members, sign in to write a code review

Older revisions

r5 by gotfoo on Jan 27, 2007   Diff
Added a file remotely
All revisions of this file

File info

Size: 5594 bytes, 130 lines
Hosted by Google Code