PageRenderTime 75ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/search/inc/core.inc.php

https://bitbucket.org/molusc/sma-website
PHP | 297 lines | 226 code | 48 blank | 23 comment | 30 complexity | 3e1d3e82796d018082b235cebc96127d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /******************************************************************************
  3. * iSearch2 - website search engine *
  4. * *
  5. * Visit the iSearch homepage at http://www.iSearchTheNet.com/isearch *
  6. * *
  7. * Copyright (C) 2002-2007 Z-Host. All rights reserved. *
  8. * *
  9. ******************************************************************************/
  10. if ( !defined('IN_ISEARCH') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. /* Disable notice/warning errors */
  15. error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  16. /* Include configuration options */
  17. require_once "$isearch_path/inc/config.inc.php";
  18. /* Import the list of supported languages */
  19. require_once "$isearch_path/lang/config.inc.php";
  20. $isearch_version = '2.18';
  21. /* Die function - called on a fatal error */
  22. function isearch_die( $error = 'unknown' )
  23. {
  24. echo "<h1>iSearch Error: $error.</h1>";
  25. exit;
  26. }
  27. /* Open the iSearch component */
  28. function isearch_open($readOnly = False)
  29. {
  30. global $isearch_path;
  31. global $isearch_sql_server, $isearch_sql_username, $isearch_sql_password, $isearch_sql_database;
  32. global $isearch_sql_ro_username, $isearch_sql_ro_password;
  33. global $isearch_db, $isearch_ro_db;
  34. global $isearch_table_info, $isearch_table_urls;
  35. global $isearch_config;
  36. /* From language include file */
  37. global $isearch_lang;
  38. global $isearch_languageCode;
  39. global $isearch_lang_config;
  40. if ($readOnly)
  41. {
  42. if ($isearch_sql_ro_username == '')
  43. {
  44. $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_username, $isearch_sql_password);
  45. $isearch_db = $isearch_ro_db;
  46. }
  47. else
  48. {
  49. $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_ro_username, $isearch_sql_ro_password);
  50. }
  51. }
  52. else
  53. {
  54. $isearch_db = mysql_connect($isearch_sql_server, $isearch_sql_username, $isearch_sql_password);
  55. if ($isearch_sql_ro_username == '')
  56. {
  57. $isearch_ro_db = $isearch_db;
  58. }
  59. else
  60. {
  61. $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_ro_username, $isearch_sql_ro_password);
  62. }
  63. if (!$isearch_db)
  64. {
  65. isearch_die('Unable to connect to MySQL. Please check your iSearch MySQL server, username and password configuration options in <i>isearch2/inc/config.inc.php</i>.');
  66. }
  67. mysql_select_db($isearch_sql_database, $isearch_db) or isearch_die('Unable to select the database. Please check your iSearch MySQL database configuration option in <i>isearch2/inc/config.inc.php</i>.');
  68. }
  69. if (!$isearch_ro_db)
  70. {
  71. isearch_die('Unable to connect to MySQL (readonly). Please check your iSearch MySQL server, username and password configuration options in <i>isearch2/inc/config.inc.php</i>.');
  72. }
  73. mysql_select_db($isearch_sql_database, $isearch_ro_db) or isearch_die('Unable to select the database (readonly). Please check your iSearch MySQL database configuration option in <i>isearch2/inc/config.inc.php</i>.');
  74. $resultInfo = mysql_query("SELECT * FROM $isearch_table_info", $isearch_ro_db);
  75. if (($resultInfo) && ($isearch_config = mysql_fetch_array($resultInfo, MYSQL_ASSOC)))
  76. {
  77. $explodeVars = array(
  78. 'allowed_ext',
  79. 'allowed_urls',
  80. 'allowed_urls_beginning',
  81. 'exclude_urls',
  82. 'exclude_urls_beginning',
  83. 'groups',
  84. 'remove_get_vars',
  85. 'start_urls',
  86. 'stop_words',
  87. 'strip_defaults',
  88. 'robots_domains',
  89. 'robots_excludes',
  90. );
  91. foreach ($explodeVars as $varname)
  92. {
  93. if ($isearch_config[$varname] == '')
  94. {
  95. $isearch_config[$varname] = array();
  96. }
  97. else
  98. {
  99. $isearch_config[$varname] = explode(' ', $isearch_config[$varname]);
  100. }
  101. }
  102. /* Check that language is valid */
  103. if (!in_array($isearch_config['lang_name'], $isearch_lang_config))
  104. {
  105. $isearch_config['lang_name'] = 'english';
  106. }
  107. include $isearch_path . '/lang/' . $isearch_config['lang_name'] . '.inc.php';
  108. /* Set maximum execution time */
  109. @ini_set('max_execution_time', $isearch_config['max_execution_time']);
  110. switch ($isearch_config['error_reporting'])
  111. {
  112. case 2:
  113. // Disable notices and warnings
  114. error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  115. break;
  116. case 3:
  117. // Show all errors
  118. error_reporting(E_ALL);
  119. break;
  120. case 4:
  121. // Turn off all error reporting
  122. error_reporting(0);
  123. break;
  124. default:
  125. // Disable notices
  126. error_reporting(E_ALL ^ (E_NOTICE));
  127. break;
  128. }
  129. if ((time() - $isearch_config['update_last_checked']) > (7 * 86400))
  130. {
  131. isearch_check_for_update();
  132. }
  133. return True;
  134. }
  135. return False;
  136. }
  137. /* Close the iSearch component */
  138. function isearch_close()
  139. {
  140. global $isearch_db, $isearch_ro_db;
  141. mysql_close($isearch_ro_db);
  142. if (isset($isearch_db))
  143. {
  144. mysql_close($isearch_db);
  145. }
  146. }
  147. function isearch_getPostVar($var, $default='')
  148. {
  149. if (isset($_REQUEST[$var]))
  150. {
  151. return $_REQUEST[$var];
  152. }
  153. return $default;
  154. }
  155. /* Check for an updated version of iSearch */
  156. function isearch_check_for_update()
  157. {
  158. global $isearch_table_info;
  159. global $isearch_db;
  160. global $isearch_config;
  161. global $isearch_version;
  162. if (isset($isearch_db))
  163. {
  164. $host='www.iSearchTheNet.com';
  165. $port=80;
  166. $path='/isearch/version.txt';
  167. $version = '';
  168. $msg = array();
  169. $sock = @fsockopen($host, $port, $errno, $errstr, 1.0);
  170. if ($sock)
  171. {
  172. $request = "GET http://$host$path HTTP/1.0\r\n";
  173. $request .= "User-Agent: iSearchPro/$isearch_version\r\n";
  174. $request .= "Host: $host\r\n";
  175. $request .= "Referer: http://".$_SERVER['HTTP_HOST'].$isearch_config['base_url']."/\r\n";
  176. $request .= "Connection: Close\r\n";
  177. $request .= "\r\n";
  178. fputs($sock, $request);
  179. /* Read status line */
  180. $status = fgets($sock, 1024);
  181. while (!feof($sock))
  182. {
  183. $line = fgets($sock, 1024);
  184. if ($line == '\r\n')
  185. {
  186. $version = fgets($sock, 1024);
  187. $mailSubject = fgets($sock, 1024);
  188. while (!feof($sock))
  189. {
  190. $msg[] = fgets($sock, 1024);
  191. }
  192. break;
  193. }
  194. }
  195. fclose($sock);
  196. }
  197. if ($version != '')
  198. {
  199. if ($version != $isearch_version)
  200. {
  201. $mailTo = $isearch_config['admin_email'];
  202. $mailHeaders = "From: " . $isearch_config['admin_email'] . "\n";
  203. $mailBody = explode("\n", $msg);
  204. $mailBody .= "\n";
  205. $mailBody .= "This email is automatically generated by iSearch. To prevent checking\n";
  206. $mailBody .= "for future updates, please untick the Update Notification setting in\n";
  207. $mailBody .= "your iSearch admin control panel.\n";
  208. $mailBody .= "\n";
  209. $mailBody .= "Visit the iSearch home page at http://www.iSearchTheNet.com/isearch\n";
  210. if (@mail($mailTo, $mailSubject, $mailBody, $mailHeaders))
  211. {
  212. mysql_query("UPDATE $isearch_table_info SET search_log_last_emailed='$now'", $isearch_db);
  213. $isearch_config['search_log_last_emailed'] = $now;
  214. isearch_clearSearchLog();
  215. }
  216. }
  217. }
  218. mysql_query("UPDATE $isearch_table_info SET update_last_checked='" . time() . "' WHERE id='1'", $isearch_db);
  219. }
  220. }
  221. if (function_exists('mysql_real_escape_string'))
  222. {
  223. function isearch_escape_string($str)
  224. {
  225. return mysql_real_escape_string($str);
  226. }
  227. }
  228. else
  229. {
  230. function isearch_escape_string($str)
  231. {
  232. return mysql_escape_string($str);
  233. }
  234. }
  235. if (get_magic_quotes_gpc())
  236. {
  237. function isearch_stripslashes($str)
  238. {
  239. return stripslashes($str);
  240. }
  241. }
  242. else
  243. {
  244. function isearch_stripslashes($str)
  245. {
  246. return $str;
  247. }
  248. }
  249. ?>