-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
225 lines (211 loc) · 12.8 KB
/
index.php
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
session_start();
if (!isset($_SESSION['ttl'])) {
$_SESSION['ttl'] = microtime(true);
}
require_once 'Yandex.php';
// get "query" and "page" from request
$query = isset($_REQUEST['query'])?$_REQUEST['query']:'';
$page = isset($_REQUEST['page']) ?$_REQUEST['page']:0;
$host = isset($_REQUEST['host']) ?$_REQUEST['host']:null;
$geo = isset($_REQUEST['geo']) ?$_REQUEST['geo']:null;
$cat = isset($_REQUEST['cat']) ?$_REQUEST['cat']:null;
$theme = isset($_REQUEST['theme']) ?$_REQUEST['theme']:null;
// small protection for example script
// only 2 seconds
if ($query && (microtime(true) - $_SESSION['ttl']) > 2) {
// Your data http://xmlsearch.yandex.ru/xmlsearch?user=AntonShevchuk&key=03.28303679:b340c90e875df328e6e120986c837284
$user = 'AntonShevchuk';
$key = '03.28303679:b340c90e875df328e6e120986c837284';
// Create new instance of Yandex class
$Yandex = new Yandex($user, $key);
// Set Query
$Yandex -> query($query)
-> host($host) // set one host or multihost
//-> host(array('anton.shevchuk.name','cotoha.info'))
//-> site(array('anton.shevchuk.name','cotoha.info'))
//-> domain(array('ru','org'))
-> page($page) // set current page
-> limit(10) // set page limit
-> geo($geo) // set geo region - http://search.yaca.yandex.ru/geo.c2n
-> cat($cat) // set category - http://search.yaca.yandex.ru/cat.c2n
-> theme($theme) // set theme - http://help.yandex.ru/site/?id=1111797
-> sortby(Yandex::SORT_RLV)
-> groupby(Yandex::GROUP_DEFAULT)
-> set('max-title-length', 160) // set some options
-> set('max-passage-length', 200)
-> request() // send request
;
// Debug request
$request = $Yandex -> getRequest()->asXml();
}
// current URL
$server = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$server = substr($server, 0, strpos($server, '?'));
$url = $server .'?query='.urlencode($query)
.'&host='.urlencode($host)
.'&geo='.urlencode($geo)
.'&cat='.urlencode($cat)
.'&theme='.urlencode($theme)
;
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yandex XML Search</title>
<meta name="keywords" content="Yandex XML, PHP, PHP5" />
<meta name="description" content="Yandex XML Search for PHP" />
<link rel="profile" href="http://gmpg.org/xfn/11"/>
<link rel="stylesheet" href="styles.css" type="text/css" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7269638-9']);
_gaq.push(['_setDomainName', '.hohli.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="body">
<div class="form">
<form>
<fieldset class="box">
<a href="http://www.yandex.ru/" title="Яндекс"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAsCAMAAACkN+1nAAABqlBMVEUAAAADAwMGBgYJCQkMDAwPDw8SEhIVFRUYGBgbGxseH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O0gMDYnUY+psQ+c60a490wnwdqRgwJNoqMGsjSxA8L1oRmGhG5LcrjUhg0ipQ/3oEluvIOSAj2howZSN9MCJWi8BCC6S6S366veUidg5SBtbryHvAoSPuFywkBdGS2AtFoRXypWleeiS32iIrEJE6MouTiwQgVBSrDLDWAvlTB/lFFGl3uWagx0VyQG/qeLxavoakO+BtsRppjexeM83Lj73urlEYcpFpYE6c7DXph+C6jbS6XHpy84Z4IQnIucg8kG9ECgYMOpfrdBPyRO+tj594IZUQRtFF3gfeaUSsDzvO1/ZwJpuQn3WQX8ULWYRecZFNA5JNyIoB/faukmxEHl4yzStPPZEBmK4jWheENhoReR2MVR07CKFSA/KNDnJTvJByhM7KXiQDpBoQd4STwOB+5N5F3R//80TGISs2EhdtPQj0VxoQ6QPjrMgZtLHKXuQLHeSOeCClbj28GrcKo6+sm/cUWiSZ6nkltgdZAl6zRyH2Zqormq4h1nN4ddcLWWN/aXsmu4KLyAlgSaTcjZ2SGtf1L+t3qbWjz6RokxAVqzBMtkYkHQRrLuvkpQ6YEW0pDAlRZagDzeg/V0PkwCxEnAYcRErTmczcqrSpmEuPL26IPD/yzL1gyIUAR8VpBCPvA9LcS+Ql8gIh/wO4jFzH/PtOVAAAAABJRU5ErkJggg=="alt="Яндекс" width="100" border="0" height="44"></a>, <input type="text" name="query" class="txt" value="<?php echo $query;?>"/>,
<input type="submit" class="smb" name="search" value="Ищи!"/><br /><br />
<span>Регион</span>: <select name="geo">
<option value="">Все</option>
<optgroup label="Город">
<option value="213" <?php if ($geo == 213) echo 'selected="selected"'?>>Москва</option>
<option value="2" <?php if ($geo == 2) echo 'selected="selected"'?>>Санкт-Петербург</option>
<option value="143" <?php if ($geo == 143) echo 'selected="selected"'?>>Киев</option>
<option value="157" <?php if ($geo == 157) echo 'selected="selected"'?>>Минск</option>
</optgroup>
<optgroup label="Страна">
<option value="225" <?php if ($geo == 225) echo 'selected="selected"'?>>Россия</option>
<option value="187" <?php if ($geo == 187) echo 'selected="selected"'?>>Украина</option>
<option value="149" <?php if ($geo == 149) echo 'selected="selected"'?>>Беларусь</option>
</optgroup>
</select><br />
<span>Категория</span>: <select name="cat">
<option value="">Все</option>
<option value="5" <?php if ($cat == 5) echo 'selected="selected"'?>>Интернет</option>
<option value="3795" <?php if ($cat == 3795) echo 'selected="selected"'?>>Кино</option>
<option value="3796" <?php if ($cat == 3796) echo 'selected="selected"'?>>Музыка</option>
<option value="3797" <?php if ($cat == 3797) echo 'selected="selected"'?>>Литература</option>
<option value="3798" <?php if ($cat == 3798) echo 'selected="selected"'?>>Фото</option>
</select><br/>
</fieldset>
<input type="hidden" name="host" value="<?php echo $host ?>"/>
<input type="hidden" name="theme" value="<?php echo $theme ?>"/>
</form>
</div>
<div class="data">
<?php
// if $Yandex exists and don't have errors in response
if (isset($Yandex) && empty($Yandex->error)) :
?>
<div class="result box">
<p><?php echo $Yandex->totalHuman() ?></p>
</div>
<ol start="<?php echo $Yandex->getLimit()*$Yandex->getPage() + 1;?>">
<?php foreach ($Yandex->results() as $result) :?>
<?php
/*
$result is Object with next properties:
->url
->domain
->title
->headline
->passages // array
->sitelinks // array
*/
?>
<li class="box"><a href="<?php echo $result->url; ?>" title="<?php echo $result->url; ?>" class="title"><?php Yandex::highlight($result->title); ?></a>
<?php if ($result->headline) : ?>
<div class="headline">
<?php echo $result->headline; ?>
</div>
<?php endif; ?>
<?php if ($result->passages) : ?>
<ul class="passages">
<?php foreach ($result->passages as $passage) :?>
<li><?php Yandex::highlight($passage);?></li>
<?php endforeach;?>
</ul>
<?php endif; ?>
<a href="<?php echo $result->url; ?>" class="host" title="<?php echo $result->url; ?>"><?php echo $result->domain; ?></a>
<a href="<?php echo $server .'?query='.urlencode($query).'&host='. urlencode($result->domain)?>" class="host" title="Поиск на сайте <?php echo $result->domain; ?>">ещё</a>
</li>
<?php endforeach;?>
</ol>
<div class="pagebar box">
<p>
<?php foreach ($Yandex->pageBar() as $page => $value) : ;?>
<?php // switch statement for $value['type']
switch ($value['type']) {
case 'link':
echo '<a href="'. $url .'&page='. $page .'" title="Page '. ($page+1) .'">'. sprintf($value['text'], $page+1) .'</a> | ';
break;
case 'current':
echo sprintf($value['text'], $page+1) .' | ';
break;
case 'text':
echo $value['text'] .' | ';
break;
default:
break;
}
?>
<?php endforeach;?>
<?php /*if ($Yandex->pages() > 1 && $Yandex->getPage() != $Yandex->pages()-1) : ?>
<?php if ($Yandex->getPage() == $Yandex->pages() - 2):?>
<a href="<?php echo $url;?>&page=<?php echo $Yandex->getPage()+1;?>" title="Next Page"><?php echo $Yandex->getPage()+2;?></a>
<?php elseif ($Yandex->getPage() < $Yandex->pages()):?> .. |
<a href="<?php echo $url;?>&page=<?php echo $Yandex->getPage()+1;?>" title="Next Page">»</a>
<?php endif; ?>
<?php endif;*/ ?>
</p>
</div>
<?php
// Error in response
elseif(isset($Yandex) && isset($Yandex->error)):
?>
<div class="error"><?php echo $Yandex->error; ?></div>
<?php endif; ?>
</div>
<div class="download">
<p>
Демонстрация работы PHP скрипта с поисковым сервисом Яндекс.XML.<br/>
Последняя версия всегда доступна на страницах Code Google:<br/>
<code>
<a href="http://code.google.com/p/yandex/downloads/list">http://code.google.com/p/yandex/downloads/list</a>
</code>
Доступ к SVN репозиторию проекта:<br/>
<code>
svn checkout http://yandex.googlecode.com/svn/trunk/ yandex-read-only
</code>
Для организации поиска по регионам или категориям смотрите коды на следующих страницах:
</p>
<ul>
<li><a href="http://search.yaca.yandex.ru/geo.c2n">Коды регионов</a></li>
<li><a href="http://search.yaca.yandex.ru/cat.c2n">Коды рубрик</a></li>
</ul>
</div>
<!--div class="request">
<pre>
<?php //echo htmlentities($request, ENT_QUOTES, "UTF-8") ?>
</pre>
</div>-->
<div class="copyright">
© 2008-<?php echo date('Y') ?> <a href="http://anton.shevchuk.name" title="Anton Shevchuk">Anton Shevchuk</a><br/>
Поиск реализован на основе <a href="http://xml.yandex.ru/" title="Яндекс.XML">Яндекс.XML</a>
</div>
</div>
</body>
</html>