<?php
/**********************************************************************
* @author: AliReza Ghafouri aka F0ruD (hide@address.com)
* @web...: http://cyberrabbits.net
* @name..: OpenSearch result for PHP (Just an example to use with XHTML)
* @description : A simple classes to add open search to your web application
* base on http://www.opensearch.org/Home.
*
*/
//This is far from complete.
class OSResponse {
var $_os_description=NULL;
var $_title;
var $_search_term;
var $_total_results;
var $_start_index;
var $_items_per_page;
var $_lang='en';
var $_os_title=NULL;
var $_results=array();
function OSResponse($search_term,$total=0,$start=0,$per_pages=0,$os_title='',$os_desc=''){
$this->_title=$search_term;
$this->_search_term=$search_term;
$this->_total_results=intval($total);
$this->_start_index=intval($start);
$this->_items_per_page=intval($per_pages);
$this->_os_description=$os_desc;
$this->_os_title=$os_title;
}
function get_title(){
return $this->_title;
}
function set_title($title){
$this->_title=$title;
}
function set_lang($lang){
$this->_lang=$lang;
}
function get_lang(){
return $this->_lang;
}
function add_result($item_title,$item_link,$item_desc){
$this->_results[]=array($item_title,$item_link,$item_desc);
}
function serve_xhtml(){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"".$this->_lang."\">\n";
echo "\t<head profile=\"http://a9.com/-/spec/opensearch/1.1/\" >\n";
echo "\t\t<title>".$this->_title."</title>\n";
if (!empty($this->_os_description))
echo "\t\t<link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"".$this->_os_description."\" title=\"".$this->_os_title."\"/>\n";
if ($this->_total_results>0)
echo "\t\t<meta name=\"totalResults\" content=\"".$this->_total_results."\"/>\n";
if ($this->_start_index>0)
echo "\t\t<meta name=\"startIndex\" content=\"".$this->_start_index."\"/>\n";
if ($this->_items_per_page>0)
echo "\t\t<meta name=\"itemsPerPage\" content=\"".$this->_items_per_page."\"/>\n";
echo "\t</head>\n";
echo "\t<body>\n";
echo "\t\t<ul id=\"result_list\">\n";
$i=0;
foreach($this->_results as $res){
$i++;
echo "\t\t\t<li id=\"list_$i\" class=\"search list\">\n";
echo "\t\t\t\t<a id=\"link_$i\" class=\"search link\" href=\"".$res[1]."\" title=\"".$res[0]."\">".$res[0]."</a>\n";
echo "\t\t\t\t<div id=\"desc_$i\" class=\"search description\">".$res[2]."</div>\n";
echo "\t\t\t</li>\n";
}
echo "\t\t</ul>\n";
echo "\t</body>\n</html>";
}
}
?>