aboutsummaryrefslogtreecommitdiff
path: root/search.php
diff options
context:
space:
mode:
Diffstat (limited to 'search.php')
-rw-r--r--search.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/search.php b/search.php
new file mode 100644
index 0000000..72d65c4
--- /dev/null
+++ b/search.php
@@ -0,0 +1,93 @@
+<?php
+$string = "";
+if (isset($_POST["s"])) {
+ $string = htmlspecialchars($_POST["s"]);
+}
+?>
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <link rel="stylesheet" href="/style.css" />
+ <link rel="icon" type="image/x-icon" href="/favicon.ico">
+ <title>Bloggings</title>
+ </head>
+ <body>
+ <header>
+ <h1>Bloggings</h1>
+ <p><a href="index.php">Blog</a>&nbsp;|&nbsp;<a
+ href="sticky.php">Sticky</a>&nbsp;|&nbsp;<b>Search</b>&nbsp;|&nbsp;<a
+ href="https://wittamore-com.translate.goog/?_x_tr_sl=auto&_x_tr_tl=fr&_x_tr_hl=en-GB&_x_tr_pto=wapp">Français</a>&nbsp;|&nbsp;<a
+ href="https://git.wittamore.com" target="_blank" title="Git">Git</a>&nbsp;|&nbsp;<a
+ href="rss.xml">RSS</a>&nbsp;|&nbsp;<a
+ href="https://bsky.app/profile/wittamore.com" target="_blank">Bluesky</a></p>
+ <hr />
+ </header>
+ <h2>Search this blog</h2>
+ <form action="search.php" method="post">
+ <input name="s" type="text" autofocus>
+ <input type="submit">
+ </form>
+ <!-- list start -->
+
+<?php if (!empty($string)) {
+ $string = strtolower($string);
+ echo "<h2>Results</h2>";
+ echo 'Search terms: <b>"' . $string . '"</b>';
+ echo "<h3>Static Pages</h3>";
+ $dir = new RecursiveDirectoryIterator("./sticky");
+ echo "<ul>";
+ $i=0;
+ foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
+ if ($file != "." && $file != "..") {
+ if (!is_dir($file)) {
+ $content = strtolower(file_get_contents($file->getPathname()));
+ if (strpos($content, $string) !== false) {
+ $i++;
+ preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre);
+ $title = "?";
+ if (isset($titre[1])) {
+ $title = ucfirst($titre[1]);
+ }
+ echo '<li><a href="' . $file . '">' . $title . "</a></li>";
+ }
+ }
+ }
+ }
+ if ($i == 0) echo "<i>No match</i>";
+ echo "</ul>";
+ echo "<h3>Articles</h3>";
+ $dir = new RecursiveDirectoryIterator("./articles");
+ echo "<ul>";
+ $i=0;
+ foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
+ if ($file != "." && $file != "..") {
+ if (!is_dir($file)) {
+ $content = strtolower(file_get_contents($file->getPathname()));
+ if (strpos($content, $string) !== false) {
+ $i++;
+ preg_match("/<h2>(.*?)<\/h2>/s", $content, $titre);
+ $title = "?";
+ if (isset($titre[1])) {
+ $title = ucfirst($titre[1]);
+ }
+ echo '<li><a href="' . $file . '">' . $title . "</a></li>";
+ }
+ }
+ }
+ }
+ if ($i == 0) echo "<i>No match</i>";
+ echo "</ul>";
+} ?>
+
+ <!-- list end -->
+ <p>&nbsp;</p>
+ <hr />
+ <p>§</p>
+ </body>
+</html>
+
+
+
+