function startElement($parser, $name, $attrs)
{
global $path, $depth, $info, $snippet;
$depth++;
switch($name)
{
case "FOUND": $path[$depth]=$name."_".$attrs['PRIORITY']."_".$depth; break;
default: $path[$depth]=$name; break;
}
// echo implode("/",$path)." open<br>\n";
}
function endElement($parser, $name)
{
global $path, $depth, $info, $snippet, $i;
// echo implode("/",$path)." close<br>\n";
if($path[$depth]=='PASSAGE') { $snippet[$path[$depth]].="... "; }
unset($path[$depth]);
$depth--;
if($name=='PAGE'&&$depth==4) echo "<link rel=\"Stylesheet\" href=\"/xml.css\" />\n<div class=\"refblock\">Результат поиска: страниц — <b>".$info['FOUND_all_3']."</b><!--, сайтов — не менее <b>".$info['FOUND_all_5']."</b>--></div>\n\n<ol class=\"results\">";
if($name=='GROUP')
{
$i++;
echo "<li value=$i>\n<div class=\"title\"><a href=".$snippet['URL'].">".($snippet['TITLE']?$snippet['TITLE']:$snippet['URL'])."</a></div>\n";
echo "<div class=\"text\">".($snippet['_PASSAGESTYPE']?"<span style=\"color:#777; font-weight:bold;\">текст ссылок: </span>":"")."".($snippet['PASSAGE']?$snippet['PASSAGE']:$snippet['HEADLINE'])."</span>\n";
echo "<div class=\"info\"><span style=\"color:#060;\">".$snippet['URL']." · ".sprintf("%d Кб",$snippet['SIZE']/1024)." · ".($snippet['MODTIME']?sprintf("%02d.%02d.%d",substr($snippet['MODTIME'],6,2),substr($snippet['MODTIME'],4,2),substr($snippet['MODTIME'],0,4)):"")."</span>".($snippet['_PASSAGESTYPE']?" — найден по ссылке":"")."</div>\n";
echo "<div class=\"info\">".($snippet['DOCCOUNT']>1?"<a href=\"/yandsearch?text=yandex&pag=u&surl=".$snippet['DOMAIN']."&\">Еще с сайта</a> <span class=\"count\">".$snippet['DOCCOUNT']."":"")."</span></div></li>\n\n";
//<!--<a href=\"http://hghltd.yandex.com/yandbtm?url=".urlencode($snippet['URL'])."&text=$qs&reqtext=yandex%3A%3A18030&dsn=".$snippet['HIGHLIGHT-COOKIE']."&isu=1\" target=\"_blank\">Сохраненная копия</a>-->
$snippet="";
}
}
function dataElement($parser, $data)
{
if(!trim($data)) return;
global $path, $depth, $info, $snippet;
$info_elem=array("REQID","WORDSTAT","FOUND_all_3","FOUND_all_5","ERROR");
$snippet_elem=array("DOCCOUNT","URL","DOMAIN","TITLE","MODTIME","SIZE","CHARSET","PASSAGE","_PASSAGESTYPE","HIGHLIGHT-COOKIE","MIME-TYPE","HEADLINE");
if(in_array($path[$depth],$info_elem)) { if(trim($data)) $info[$path[$depth]].=$data; }
if(in_array($path[$depth],$snippet_elem)) { if(trim($data)) $snippet[$path[$depth]].=$data; }
if($path[$depth]=='HLWORD') { if(trim($data)) $snippet[$path[$depth-1]].="<b>".$data."</b> "; }
// if($path[$depth]=='_PASSAGESTYPE') { if($data==1) $snippet['PASSAGE']="<span style=\"color:#777; font-weight:bold;\">текст ссылок: </span>".$snippet['PASSAGE']; }
}
if ($qs)
{
echo "<script language=\"JavaScript\">yandex_premium_print();</script><table><tr><td valign=top>\n";
$fp = @fsockopen ("xmlsearch.yandex.ru", 80, $errno, $errstr, 10);
if (!$fp)
{
echo "<h1>Сервис временно недоступен</h1><error $errstr ($errno)><br>\n";
}
else
{
$XML_Tree=array();
$XML_Data='';
$i=$_GET['curPos']+0;
$numdoc=10;
$page=$_GET['curPos']/$numdoc;
$data="<"."?xml version='1.0' encoding='koi8-r'?".">\n".
"<request>\n".
"<query>$qs << url=\"www.millionmenu.ru*\"</query>\n".
"<maxpassages>3</maxpassages>\n".
"<max-title-length>100</max-title-length>\n".
"<max-headline-length>150</max-headline-length>\n".
"<max-passage-length>100</max-passage-length>\n".
"".($page?"<page>$page</page>\n":"")."".
// "".($q?"<reqid>$q</reqid>\n":"")."".
"<groupings>\n".
"<groupby attr='d' mode='flat' groups-on-page='10' docs-in-group='1' curcateg='-1'/>\n".
"</groupings>\n".
"</request>";
$request="POST /xmlsearch/ HTTP/1.0\r\nAccept: */"."*\r\nAccept-Language: ru\r\nHost: xmlsearch.yandex.ru\r\nConnection: Close\r\n";
$request.="Content-Length: ".strlen($data)."\r\n";
$request.="User-Agent: UnKnown\r\n\r\n$data";
fputs ($fp, $request);
while (!feof($fp))
{
$line=fgets($fp,4096);
if (!trim($line)) break;
}
while (!feof($fp))
{
$XML_Data.=fgets($fp,4096);
}
$XML_Data=preg_replace("/*/"," ",$XML_Data);
$XML_Data=iconv("UTF-8","KOI8-U",$XML_Data);
$XML=xml_parser_create();
xml_set_element_handler($XML, "startElement", "endElement");
xml_set_character_data_handler($XML,"dataElement");
xml_parse($XML, $XML_Data);
$options['curPos']=$_GET['curPos']+0;
$options['maxRows']=$numdoc;
$options['totRows']=$info['FOUND_all_3'];
$options['prefix']="<br>\nСтраницы: <a href='\$queryStr&curPos=0' class=pgs1 onMouseOver=\\\"this.className='pgs0'\\\" onMouseOut=\\\"this.className='pgs1'\\\">первая</a>\n";
$options['active']="<span class=pgs0>%PAGE</span>\n";
$options['unactive']="<a href='%URL' class=pgs1 onMouseOver=\\\"this.className='pgs0'\\\" onMouseOut=\\\"this.className='pgs1'\\\">%PAGE</a>\n";
$options['suffix']="<a href='\$queryStr&curPos=\".((\$page_count-1)*\$maxRows).\"' class=pgs1 onMouseOver=\\\"this.className='pgs0'\\\" onMouseOut=\\\"this.className='pgs1'\\\">последняя</a>\n";
$options['divider']=" ";
$options['LocalQuery']=substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],'?'))."?qs=".$qs."";
if(!$options['LocalQuery']) $options['LocalQuery']=$_SERVER['REQUEST_URI'];
//echo "<!-- ".print_r($options)."-->";
echo browse_messages($options, 10);
}
echo "</ol>\n";
echo "</td></tr></table>";
}