search.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /* mnoGoSearch-php v.3.2.10
  3. * for mnoGoSearch ( formely known as UdmSearch ) free web search engine
  4. * (C) 2001 by Sergey Kartashoff <gluke@mail.ru>,
  5. * mnoGoSearch Developers Team <devel@mnogosearch.org>
  6. */
  7. if (!extension_loaded('mnogosearch')) {
  8. print "<b>This script requires PHP4.3.0+ with mnoGoSearch extension</b>";
  9. exit;
  10. }
  11. define("UDM_ENABLED", 1);
  12. define("UDM_DISABLED", 0);
  13. require ('./config.inc');
  14. require ('./common.inc');
  15. require ('./template.inc');
  16. require ('./init.inc');
  17. //api_block_anonymous_users();
  18. //require ('filter_user.functions.php');
  19. if ($lang_content_negotiation == 'yes') {
  20. // path to template file ($lang_content_negotiation = 'yes')
  21. // please refer to docs on this feature before using it.
  22. $template_file = preg_replace("/\.php\.*/", ".xml.php", basename($SCRIPT_FILENAME));
  23. $template_file = "./".$template_file;
  24. } else {
  25. // path to template file ($lang_content_negotiation = 'no')
  26. $template_file = './search.xml.php';
  27. }
  28. // -----------------------------------------------
  29. // M A I N
  30. // -----------------------------------------------
  31. if (!$cc) {
  32. $XMLOutput = 1;
  33. init();
  34. if (!$have_query_flag) {
  35. print_template('bottom');
  36. return;
  37. }
  38. elseif ($have_query_flag && ($q == '')) {
  39. print_template('noquery');
  40. print_template('bottom');
  41. return;
  42. }
  43. $res = udm_find($udm_agent, $q);
  44. if (!$res) {
  45. print_error_local(udm_error($udm_agent));
  46. } else {
  47. $found = udm_get_res_param($res, UDM_PARAM_FOUND);
  48. $rows = udm_get_res_param($res, UDM_PARAM_NUM_ROWS);
  49. //YW commented out because broke everything
  50. //if (udm_api_version() >= 30231) {
  51. // $wordinfo=Udm_Get_Agent_Param_Ex($udm_agent,'W');
  52. //} else {
  53. $wordinfo = udm_get_res_param($res, UDM_PARAM_WORDINFO_ALL);
  54. //}
  55. $searchtime = udm_get_res_param($res, UDM_PARAM_SEARCHTIME);
  56. $first_doc = udm_get_res_param($res, UDM_PARAM_FIRST_DOC);
  57. $last_doc = udm_get_res_param($res, UDM_PARAM_LAST_DOC);
  58. if (!$found) {
  59. $ws = '';
  60. if ((udm_api_version() >= 30233) && ($suggest == 'yes')) {
  61. $ws = udm_get_agent_param_ex($udm_agent, 'WS');
  62. }
  63. print_template('notfound');
  64. print_template('bottom');
  65. return;
  66. }
  67. $from = IntVal($np) * IntVal($ps);
  68. $to = IntVal($np +1) * IntVal($ps);
  69. if ($to > $found)
  70. $to = $found;
  71. if (($from + $ps) < $found)
  72. $isnext = 1;
  73. $nav = make_nav($query_orig);
  74. print_template('restop');
  75. $global_doc_res = $res;
  76. $my_skip = 0;
  77. for ($i = 0; $i < $rows; $i += 1) {
  78. $excerpt_flag = 0;
  79. $clonestr = '';
  80. $rec_id = udm_get_res_field($res, $i, UDM_FIELD_URLID);
  81. $global_res_position = $i;
  82. if (udm_api_version() >= 30207) {
  83. $origin_id = udm_get_res_field($res, $i, UDM_FIELD_ORIGINID);
  84. if ($origin_id)
  85. continue;
  86. else {
  87. for ($j = 0; $j < $rows; $j += 1) {
  88. $cl_origin_id = udm_get_res_field($res, $j, UDM_FIELD_ORIGINID);
  89. if (($cl_origin_id) && ($cl_origin_id == $rec_id)) {
  90. $url = udm_get_res_field($res, $j, UDM_FIELD_URL);
  91. //YW
  92. /*if (!access_check($url)) {
  93. $my_skip ++;
  94. continue;
  95. }*/
  96. //YW
  97. $contype = udm_get_res_field($res, $j, UDM_FIELD_CONTENT);
  98. $docsize = udm_get_res_field($res, $j, UDM_FIELD_SIZE);
  99. $lastmod = format_lastmod(udm_get_res_field($res, $j, UDM_FIELD_MODIFIED));
  100. if (udm_api_version() >= 30207) {
  101. $pop_rank = udm_get_res_field($res, $i, UDM_FIELD_POP_RANK);
  102. } else
  103. $pop_rank = '';
  104. $clonestr .= print_template('clone', 0)."\n";
  105. }
  106. }
  107. }
  108. }
  109. if (udm_api_version() >= 30204) {
  110. $excerpt_flag = udm_make_excerpt($udm_agent, $res, $i);
  111. }
  112. //YW
  113. /*
  114. $ndoc = udm_get_res_field($res, $i, UDM_FIELD_ORDER) - $my_skip;
  115. */
  116. //YW
  117. $rating = udm_get_res_field($res, $i, UDM_FIELD_RATING);
  118. $url = udm_get_res_field($res, $i, UDM_FIELD_URL);
  119. //YW
  120. /*
  121. if (!access_check($url)) {
  122. $my_skip ++;
  123. continue;
  124. }*/
  125. //YW
  126. $contype = udm_get_res_field($res, $i, UDM_FIELD_CONTENT);
  127. $docsize = udm_get_res_field($res, $i, UDM_FIELD_SIZE);
  128. $lastmod = format_lastmod(udm_get_res_field($res, $i, UDM_FIELD_MODIFIED));
  129. $title = udm_get_res_field($res, $i, UDM_FIELD_TITLE);
  130. $title = ($title) ? htmlspecialchars($title) : basename($url);
  131. $title = ParseDocText($title);
  132. $text = ParseDocText(htmlspecialchars(udm_get_res_field($res, $i, UDM_FIELD_TEXT)));
  133. //$text=ParseDocText(htmlspecialchars(udm_get_res_field_ex($res,$i,"Body")));
  134. $keyw = ParseDocText(htmlspecialchars(udm_get_res_field($res, $i, UDM_FIELD_KEYWORDS)));
  135. $desc = ParseDocText(htmlspecialchars(udm_get_res_field($res, $i, UDM_FIELD_DESC)));
  136. $crc = udm_get_res_field($res, $i, UDM_FIELD_CRC);
  137. if (udm_api_version() >= 30203) {
  138. $doclang = udm_get_res_field($res, $i, UDM_FIELD_LANG);
  139. $doccharset = udm_get_res_field($res, $i, UDM_FIELD_CHARSET);
  140. }
  141. if ($phpver >= 40006) {
  142. $category = udm_get_res_field($res, $i, UDM_FIELD_CATEGORY);
  143. } else {
  144. $category = '';
  145. }
  146. reset($alias_arr);
  147. $save_url = $url;
  148. while (list ($t_alias, $t_url) = each($alias_arr)) {
  149. $url = str_replace($t_alias, $t_url, $url);
  150. }
  151. if (udm_api_version() <= 30223) {
  152. if (udm_api_version() >= 30204) {
  153. if ($excerpt_flag) {
  154. if (udm_api_version() >= 30216) {
  155. if (udm_get_res_field_ex($res, $i, "CachedCopy") != '') {
  156. $stored_href = "$self?cc=1"."&url=".urlencode($save_url)."&q=".urlencode($query_orig);
  157. }
  158. }
  159. elseif (udm_api_version() >= 30211) {
  160. $stored_href = "$storedocurl?rec_id=".udm_hash32($udm_agent, $save_url)."&DM=".urlencode($lastmod)."&DS=$docsize"."&L=$doclang"."&CS=$doccharset"."&DU=".urlencode($save_url)."&CT=".urlencode($contype)."&q=".urlencode($query_orig);
  161. } else {
  162. $stored_href = "$storedocurl?rec_id=".udm_CRC32($udm_agent, $save_url)."&DM=".urlencode($lastmod)."&DS=$docsize"."&L=$doclang"."&CS=$doccharset"."&DU=".urlencode($save_url)."&CT=".urlencode($contype)."&q=".urlencode($query_orig);
  163. }
  164. if ($stored_href != '')
  165. $storedstr = print_template('stored', 0);
  166. } else
  167. $storedstr = '';
  168. } else
  169. $storedstr = '';
  170. } else {
  171. if (udm_get_res_field_ex($res, $i, "CachedCopy") != '') {
  172. if (udm_get_res_field_ex($res, $i, "dbnum") == '') {
  173. $stored_href = "$self?cc=1"."&url=".urlencode($save_url)."&q=".urlencode($query_orig);
  174. } else {
  175. $stored_href = "$self?cc=1"."&dbnum=".udm_get_res_field_ex($res, $i, "dbnum")."&url=".urlencode($save_url)."&q=".urlencode($query_orig);
  176. }
  177. $storedstr = print_template('stored', 0);
  178. }
  179. }
  180. $sitelimitstr = $persite = '';
  181. if ((udm_api_version() >= 30207) && ($groupbysite == 'yes')) {
  182. if (!$site) {
  183. $sitelimit_href = "$PHP_SELF?$QUERY_STRING";
  184. $sitelimit_href = preg_replace("/\&np=\d*/", '', $sitelimit_href);
  185. $sitelimit_href .= "&np=0&site=".udm_get_res_field($res, $i, UDM_FIELD_SITEID);
  186. $persite = udm_get_res_field_ex($res, $i, "PerSite");
  187. $sitelimitstr = print_template('site_limit', 0);
  188. }
  189. }
  190. if (udm_api_version() >= 30207) {
  191. $pop_rank = udm_get_res_field($res, $i, UDM_FIELD_POP_RANK);
  192. } else
  193. $pop_rank = '';
  194. if ((substr($url, 0, 6) == "ftp://") && ($templates['ftpres'][0] != '')) {
  195. print_template('ftpres');
  196. }
  197. elseif (((substr($url, 0, 7) == "http://") || (substr($url, 0, 8) == "https://")) && ($templates['httpres'][0] != '')) {
  198. print_template('httpres');
  199. } else {
  200. print_template('res');
  201. }
  202. }
  203. $global_doc_res = '';
  204. print_template('resbot');
  205. print_template('bottom');
  206. // Free result
  207. udm_free_res($res);
  208. }
  209. } else {
  210. /* show cached copy */
  211. init_cc();
  212. $res = udm_store_doc_cgi($udm_agent);
  213. $id = udm_get_agent_param_ex($udm_agent, 'ID');
  214. $last_modified = udm_get_agent_param_ex($udm_agent, 'Last-Modified');
  215. $content = udm_get_agent_param_ex($udm_agent, 'Content-Type');
  216. $length = udm_get_agent_param_ex($udm_agent, 'Content-Length');
  217. $charset = udm_get_agent_param_ex($udm_agent, 'Charset');
  218. Header("Content-Type: text/html; charset=$charset");
  219. print_template('storedoc_top');
  220. if ($res) {
  221. $document = ParseDocText(udm_get_agent_param_ex($udm_agent, 'document'));
  222. print_template('storedoc');
  223. }
  224. print_template('storedoc_bottom');
  225. }
  226. udm_free_agent($udm_agent);
  227. ?>