• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/search.lib.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00017 global $cmsFolder,$sourceFolder;
00018 require_once("$sourceFolder/modules/search/settings/conf.php");
00019 require_once("$sourceFolder/modules/search/include/commonfuncs.php");
00020 require_once("$sourceFolder/modules/search/include/categoryfuncs.php");
00021 require_once("$sourceFolder/modules/search/include/searchfuncs.php");
00022 
00023 function saveToLog ($query, $elapsed, $results) {
00024         global $sph_mysql_table_prefix;
00025         if ($results == '')
00026                 $results = 0;
00027         $query = "insert into ".$sph_mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')";
00028         if(!mysql_query($query))
00029                 displayerror(mysql_error());
00030 }
00031 
00032 function getmicrotime(){
00033         list($usec, $sec) = explode(" ",microtime());
00034         return ((float)$usec + (float)$sec);
00035 }
00036 
00037 function getSearchBox(){
00038         $CMS_TITLE = CMS_TITLE;
00039         $lastquery="";
00040         if($_GET['query']!="") $lastquery=safe_html($_GET['query']);
00041         if($_POST['query']!="") $lastquery=safe_html($_POST['query']);
00042 
00043         global $cmsFolder,$urlRequestRoot,$ICONS;
00044         $searchbox=<<<SEARCH
00045         <style type="text/css">
00046                 table.searchBox{border:1px solid #113377}
00047                 #result_report {
00048                         text-align:center ;
00049                         padding:3px;
00050                         background-color:#e5ecf9; 
00051                         font-weight: bold;
00052                         margin-bottom:14px;
00053                         margin-right: 10px;
00054                 }
00055         </style>
00056 
00057         <fieldset>
00058         <legend>{$ICONS['Search']['small']}$CMS_TITLE Search</legend>
00059         
00060         <center>
00061         <form action="./+search" method="POST">
00062         <table cellspacing="1" cellpadding="5" class="searchBox">
00063                 <tr>
00064                         <td align="center">
00065                                 <table>
00066                                         <tr>
00067                                                 <td><div align="left"><input type="text" size="40" id="query" name="query" value="$lastquery" /></td>
00068                                                 <td><input type="submit" value="Search"/></td>
00069                                         </tr>
00070                                 </table>
00071                                 
00072                         </td>
00073                 </tr>
00074         </table>
00075         Powered by <a href="http://www.sphider.eu/" target="_blank"><img src="$urlRequestRoot/$cmsFolder/templates/common/images/sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a><br/><br/>
00076         </form>
00077         </center>
00078 SEARCH;
00079         return $searchbox;
00080                         
00081 }
00082 function getSearchResultString($query) {
00083         $search_results = get_search_results("$query","","","and","","");
00084 
00085         extract($search_results);
00086         global $urlRequestRoot,$cmsFolder;
00087         $resultHTML = "<link rel='stylesheet' media='print' type='text/css' href=\"$urlRequestRoot/$cmsFolder/templates/common/search.css\" />";
00088         if ($search_results['did_you_mean']){
00089                 $dym = quote_replace(addmarks($search_results['did_you_mean']));
00090                 $resultHTML .= <<<DIDYOUMEAN
00091                         <div id="did_you_mean">
00092                                 Did You Mean: <a href="./+search&query=$dym&search=1">{$search_results['did_you_mean_b']}</a>
00093                         </div>
00094 DIDYOUMEAN;
00095         }
00096 
00097         if ($search_results['ignore_words']) {
00098                 $resultHTML .= '<div id="common_report">';
00099                 $ignored = '';
00100                 while ($thisword=each($ignore_words)) {
00101                         $ignored .= " ".$thisword[1];
00102                 }
00103                 $resultHTML .= '</div>';
00104         }
00105 
00106         if ($search_results['total_results']==0) {
00107                 $resultHTML .= '<div id ="result_report">';
00108                 $resultHTML .= str_replace ('%query', $ent_query, "Sorry! No matches found.");
00109                 $resultHTML .= '</div>';
00110         }
00111 
00112         if ($total_results != 0 && $from <= $to) {
00113                 $resultHTML .= '<div id ="result_report">';
00114                 $res = 'Results';
00115                 $res = str_replace ('%from', $from, $res);
00116                 $res = str_replace ('%to', $to, $res);
00117                 $res = str_replace ('%all', $total_results, $res);
00118                 $matchword = "matches";
00119                 if ($total_results== 1)
00120                         $matchword= "match";
00121                 else
00122                         $matchword= "matches";
00123 
00124                 $res = str_replace ('%matchword', $matchword, $res);
00125                 $res = str_replace ('%secs', $time, $res);
00126                 $resultHTML .= $res;
00127                 $resultHTML .= '</div>';
00128         }
00129 
00130         if (isset($qry_results)) {
00131                 $resultHTML .= '<div id="results">';
00132 
00133                 foreach ($qry_results as $_key => $_row){
00134                         $last_domain = $domain_name;
00135                         extract($_row);
00136                         if ($sph_show_query_scores == 0)
00137                                 $weight = '';
00138                         else
00139                                 $weight = "[$weight%]"; 
00140                         if ($domain_name == $last_domain && $sph_merge_site_results == 1 && $domain == "") {
00141                                 $resultHTML .= '<div class="idented">';
00142                         }
00143 
00144                         $resultHTML .= "<b>$num.</b> $weight \n";
00145                         $resultHTML .= "<a href=\"$url\" class=\"sph_title\">" . ($title?$title:'Untitled') . "</a><br/>\n";
00146                         $resultHTML .= "<div class=\"description\">$fulltxt</div>\n";
00147                         $resultHTML .= "<div class=\"url\">$url2 - $page_size</div>\n";
00148 
00149                         if ($domain_name == $last_domain && $sph_merge_site_results == 1 && $domain == "") {
00150                                 $q = quote_replace(addmarks($query));
00151                                 $resultHTML .= "[ <a href=\"./+search&query=$q&search=1&results=$results_per_page&domain=$domain_name\">More results from $domain_name</a> ]";
00152                                 $resultHTML .= "</div class=\"idented\">\n";
00153                         }
00154                         $resultHTML .= "<br />\n";
00155                 }
00156                 $resultHTML .= '</div>';
00157         }
00158 
00159         if (isset($other_pages)) {
00160                 if ($adv==1) {
00161                         $adv_qry = "&adv=1";
00162                 }
00163                 if ($type != "") {
00164                         $type_qry = "&type=$type";
00165                 }
00166 
00167                 $resultHTML .= "<div id=\"other_pages\">\nResult page: ";
00168                 if ($start >1) {
00169                         $q = quote_replace(addmarks($query));
00170                         $resultHTML .= "<a href=\"./+search&query=$q&start=$prev&search=1&results={$results_per_page}{$type_qry}{$adv_qry}&domain=$domain\">Previous</a>";
00171                 }
00172 
00173                 foreach ($other_pages as $page_num) {
00174                         if ($page_num !=$start) {
00175                                 $q = quote_replace(addmarks($query));
00176                                 $resultHTML .= "<a href=\"./+search&query=$q&start=$page_num&search=1&results={$results_per_page}{$type_qry}{$adv_qry}&domain=$domain\">$page_num</a>";
00177                         }
00178                         else {
00179                                 $resultHTML .= "<b>$page_num</b>";
00180                         }
00181                 }
00182 
00183                 if ($next <= $pages) {
00184                         $q = quote_replace(addmarks($query));
00185                         $resultHTML .= "<a href=\"./+search&query=$q&start=$next&search=1&results={$results_per_page}{$type_qry}{$adv_qry}&domain=$domain\">Next</a>";
00186                 }
00187 
00188                 $resultHTML .= '</div>';
00189         }
00190         return $resultHTML;
00191 }

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1