index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. // INCLUDE
  3. include_once("crawl.php");
  4. include_once("config.php");
  5. // END
  6. ?>
  7. <!DOCTYPE html>
  8. <html lang="en-US">
  9. <head>
  10. <title>Seed</title>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  12. <meta name="viewport" content="width=device-width, initial-scale=1" />
  13. <meta name="description" content="Open Source Search Engine, foss database, popular sites, media, and more." />
  14. <style rel="stylesheet" type="text/css">
  15. @import url('https://fonts.googleapis.com/css?family=Ubuntu+Mono&display=swap');
  16. @import url('https://fonts.googleapis.com/css2?family=Monoton&display=swap');
  17. @media only screen and (min-width: 2001px) { body { max-width: 750px; } }
  18. @media only screen and (max-width: 2000px) { body { max-width: 750px; } }
  19. @media only screen and (max-width: 1400px) { body { max-width: 750px; } }
  20. @media only screen and (max-width: 1200px) { body { max-width: 700px; } }
  21. @media only screen and (max-width: 1000px) { body { max-width: 700px; } }
  22. @media only screen and (max-width: 800px) { body { max-width: 700px; } }
  23. /* @media only screen and (max-width: 700px) { body { max-width: 600px; } }
  24. @media only screen and (max-width: 600px) { body { max-width: 500px; } }
  25. @media only screen and (max-width: 500px) { body { max-width: 450px; } }
  26. @media only screen and (max-width: 400px) { body { max-width: 350px; } } */
  27. html {
  28. font-family: "Ubuntu Mono", sans-serif;
  29. background-color: #222222;
  30. color: #ddddff;
  31. padding: 4px;
  32. margin: 0 auto;
  33. font-size: 16px;
  34. min-width: 700px;
  35. }
  36. body { margin: 0 auto; }
  37. a { color: #9900ff; }
  38. a:hover { color: #dd00ff; text-decoration: none; }
  39. table { width: 100%; }
  40. p { padding: 5px; }
  41. .menu {
  42. font-size: 20px;
  43. background: #131313;
  44. padding: 3px 3px 3px 3px;
  45. border: solid 1px #444444;
  46. width: 95%;
  47. margin: auto;
  48. border-radius: 4px;
  49. box-shadow: 0px 0px 10px #000000;
  50. }
  51. .menu a {
  52. color: silver;
  53. text-decoration: none;
  54. padding: 3px 10px 3px 10px;
  55. /* some effects */
  56. transition: ease-in .4s color;
  57. -moz-transition: ease-in .4s color;
  58. -webkit-transition: ease-in .4s color;
  59. -o-transition: ease-in .4s color;
  60. }
  61. .menu a:hover {
  62. color: white;
  63. text-decoration: none;
  64. }
  65. .header {
  66. font-family: "Monoton", sans-serif;
  67. font-size: 28px;
  68. width: 40px;
  69. color: #aa00ff;
  70. }
  71. #quote {
  72. max-width: 90%;
  73. background-color: #000000;
  74. border: solid 1px #101010;
  75. radius: 4px;
  76. font-size: 16px;
  77. padding: 4px;
  78. margin: 0 auto;
  79. }
  80. #searchbar {
  81. font-size: 20px;
  82. background-color: #131313;
  83. border: solid 1px #434343;
  84. color: #ececec;
  85. padding: 4px;
  86. width: 540px;
  87. border-radius: 4px;
  88. }
  89. input, button {
  90. font-size: 20px;
  91. background-color: #131313;
  92. border: solid 1px #434343;
  93. color: #ececec;
  94. padding: 4px;
  95. border-radius: 4px;
  96. }
  97. .container { padding: 12px; }
  98. .footer { font-size: 16px; color: #565656; text-align: center; }
  99. .footer a { text-decoration: none; }
  100. .note { color: red; font-weight: 500; padding: 7px; }
  101. .rfloat { float: right; position: inline-block; }
  102. </style>
  103. </head>
  104. <body>
  105. <table><tr><td>
  106. <div class="header">SEED</div>
  107. </td><td>
  108. <div class="menu"><!--
  109. --><a href="index.php">Search</a><!--
  110. --><a href="index.php?about">About</a><!--
  111. --><a href="index.php?submit">Submit</a><!--
  112. --></div>
  113. </td></tr></table>
  114. <div class="container">
  115. <p>
  116. <?php
  117. // Simple search engine paired with the crawler!
  118. // (C) Chris Dorman, 2021 CC-BY-SA 3.0
  119. $searchcount = "0";
  120. function filterSearchKeys($query){
  121. $query = trim(preg_replace("/(\s+)+/", " ", $query));
  122. $words = array();
  123. // expand this list with your words.
  124. $list = array("in","it","a","the","of","or","I","you","he","me","us","they","she","to","but","that","this","those","then");
  125. $c = 0;
  126. foreach(explode(" ", $query) as $key){
  127. if (in_array($key, $list)){
  128. continue;
  129. }
  130. $words[] = $key;
  131. // If over X words in queue for search, stop
  132. if ($c >= $GLOBALS['max_word_search_array']){
  133. break;
  134. }
  135. $c++;
  136. }
  137. return $words;
  138. }
  139. if(isset($_GET['search']) && $_GET['search']!="")
  140. {
  141. $searchquery = stripslashes(htmlentities($_GET['search']));
  142. $searchdb = file_get_contents($database);
  143. $searchbuffer = explode("URL: ", $searchdb);
  144. ?>
  145. <form action="index.php" method="get">
  146. <span style="font-size: 20px; padding-right: 8px; ">Search: </span><input type="text" name="search" id="searchbar"><input type="submit" value="Go">
  147. </form>
  148. <br /><br />
  149. <?php
  150. array_shift($searchbuffer);
  151. foreach($searchbuffer as $site) {
  152. if(stripos($site, $searchquery) !== false) {
  153. $url = explode("\n", $site); // $url[1]
  154. $pretitle = explode("Title: ", $site);
  155. $title = explode("Description: ", $pretitle[1]);
  156. $predesc = explode("Description: ", $site); // Used to calculate descriptions with line breaks
  157. $desc = explode("Keywords: ", $predesc[1]); // $desc[0]
  158. echo "<a href='" . $url[0] . "'>" . $title[0] . "</a><br />\n";
  159. echo "<p style='font-size: $descfontsize;'>"
  160. . "<span style='color:#00BB00;padding-bottom:4px;'>" . $url[0] . "</span><br />"
  161. . $desc[0] . "</p><br />\n";
  162. $searchcount++;
  163. }
  164. // IF there's too many finds, don't flood the page
  165. if($searchcount>$maxfinds) { break; }
  166. }
  167. // Didn't find any / lots of direct comparisons to the string
  168. // lets do a simple word by word search algorithm
  169. $searchedbuf = "";
  170. $finalbuf = "";
  171. if($searchcount < "25") {
  172. $searchkeys = filterSearchKeys($searchquery);
  173. $cnt = 1;
  174. foreach($searchkeys as $search) {
  175. if($cnt != count($searchkeys)) {
  176. foreach($searchbuffer as $site2) {
  177. if(stripos($site2, $search) !== false) {
  178. $searchedbuf .= "URL: " . $site2 . "\n";
  179. }
  180. }
  181. }
  182. if($cnt == count($searchkeys)) {
  183. foreach(explode("URL: ", $searchedbuf) as $sitebuf) {
  184. if(stripos($sitebuf, $search) !== false) {
  185. $finalbuf .= "URL: " . $sitebuf . "\n";
  186. }
  187. }
  188. }
  189. $cnt++;
  190. }
  191. $searchbuffer2 = explode("URL: ", $finalbuf);
  192. array_shift($searchbuffer2);
  193. foreach($searchbuffer2 as $searched) {
  194. $url = explode("\n", $searched); // $url[1]
  195. $pretitle = explode("Title: ", $searched);
  196. $title = explode("Description: ", $pretitle[1]);
  197. $predesc = explode("Description: ", $searched); // Used to calculate descriptions with line breaks
  198. $desc = explode("Keywords: ", $predesc[1]); // $desc[0]
  199. echo "<a href='" . $url[0] . "'>" . $title[0] . "</a><br />\n";
  200. echo "<p style='font-size: $descfontsize;'>"
  201. . "<span style='color:#00BB00;padding-bottom:4px;'>" . $url[0] . "</span><br />"
  202. . $desc[0] . "</p><br />\n";
  203. $searchcount++;
  204. }
  205. }
  206. echo "<p>Found $searchcount results</p>";
  207. echo "<br />\n";
  208. }
  209. else if(isset($_GET['crawl']) && $_GET['crawl']!="")
  210. {
  211. $crawlurl = htmlentities(stripslashes($_GET['crawl']));
  212. if(filter_var($crawlurl, FILTER_VALIDATE_URL)) {
  213. echo "Crawling $crawlurl, please wait this can take a few!<br />\n";
  214. $crawl = crawl_page($crawlurl, $crawl_depth, $database);
  215. if ($crawl == 3) {
  216. echo "";
  217. } else {
  218. echo "$crawlurl added to database!";
  219. }
  220. } else {
  221. echo "ERROR: Invalid URL format!";
  222. }
  223. }
  224. else if(isset($_GET['about']))
  225. {
  226. echo "<h3>About seed</h3>\n";
  227. echo "<p>Seed is the most simple yet most secure, non-tracking, open source search engine primarily around the free and open source community!"
  228. . " Building a search engine database requires resources, and lots of crawling! Help us out in providing us with some helpful links used to"
  229. . " add content to our database!</p>";
  230. }
  231. else if(isset($_GET['submit']))
  232. {
  233. echo "<h3>Submit a URL into the seed</h3>\n";
  234. echo "By submitting a URL into seed's web crawler prompt, you acknowledge that you're authorizing us to crawl the given link!<br />";
  235. echo "<form action='index.php' method='get'>";
  236. echo "URL: <input type='text' name='crawl'><input type='submit' value='Crawl'>";
  237. echo "</form>";
  238. }
  239. else
  240. {
  241. ?>
  242. <form action="index.php" method="get">
  243. <span style="font-size: 20px; padding-right: 8px; ">Search: </span><input type="text" name="search" id="searchbar"><input type="submit" value="Go">
  244. </form>
  245. <?php
  246. }
  247. ?>
  248. <br />
  249. <br />
  250. <div id="quote">
  251. <?php
  252. $quote = file_get_contents("quotes/" . rand(1,80) . ".txt");
  253. echo nl2br(stripslashes(htmlentities($quote)));
  254. ?>
  255. </div>
  256. </p>
  257. </div>
  258. <div class="footer">
  259. &copy; Seed, 2021
  260. </div>
  261. </body>
  262. </html>