search.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. $string = "";
  3. if (isset($_POST["s"])) {
  4. $string = htmlspecialchars($_POST["s"]);
  5. }
  6. ?>
  7. <!doctype html>
  8. <html>
  9. <head>
  10. <meta charset="utf-8" />
  11. <meta name="viewport" content="width=device-width, initial-scale=1" />
  12. <link rel="stylesheet" href="/style.css" />
  13. <title>Bloggings</title>
  14. </head>
  15. <body>
  16. <header>
  17. <h1>Bloggings</h1>
  18. <p>
  19. <a href="index.html">Home</a> | <a href="https://searx.wittamore.com" target="_blank">SearxNG</a>
  20. </p>
  21. <hr />
  22. </header>
  23. <h2>Search</h2>
  24. <form action="search.php" method="post">
  25. <input name="s" type="text">
  26. <input type="submit">
  27. </form>
  28. <!-- list start -->
  29. <?php if (!empty($string)) {
  30. echo "<h2>Results</h2>";
  31. echo 'Search terms: <b>"' . $string . '"</b>';
  32. echo "<h3>Static Pages</h3>";
  33. $dir = new RecursiveDirectoryIterator("./static");
  34. echo "<ul>";
  35. $i=0;
  36. foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
  37. if ($file != "." && $file != "..") {
  38. if (!is_dir($file)) {
  39. $content = file_get_contents($file->getPathname());
  40. if (strpos($content, $string) !== false) {
  41. $i++;
  42. preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre);
  43. $title = "?";
  44. if (isset($titre[1])) {
  45. $title = $titre[1];
  46. }
  47. echo '<li><a href="' . $file . '">' . $title . "</a></li>";
  48. }
  49. }
  50. }
  51. }
  52. if ($i == 0) echo "<i>No match</i>";
  53. echo "</ul>";
  54. echo "<h3>Articles</h3>";
  55. $dir = new RecursiveDirectoryIterator("./articles");
  56. echo "<ul>";
  57. $i=0;
  58. foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
  59. if ($file != "." && $file != "..") {
  60. if (!is_dir($file)) {
  61. $content = file_get_contents($file->getPathname());
  62. if (strpos($content, $string) !== false) {
  63. $i++;
  64. preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre);
  65. $title = "?";
  66. if (isset($titre[1])) {
  67. $title = $titre[1];
  68. }
  69. echo '<li><a href="' . $file . '">' . $title . "</a></li>";
  70. }
  71. }
  72. }
  73. }
  74. if ($i == 0) echo "<i>No match</i>";
  75. echo "</ul>";
  76. } ?>
  77. <!-- list end -->
  78. <p>&nbsp;</p>
  79. <hr />
  80. <center>
  81. <h5>A minimalist blog by <a href="mailto:%70%68%69%6C%69%70%40%77%69%74%74%61%6D%6F%72%65%2E%63%6F%6D">Philip Wittamore</a></h5>
  82. </center>
  83. </body>
  84. </html>