diff options
| author | Philip Wittamore <philip@wittamore.com> | 2026-07-12 11:08:50 +0200 |
|---|---|---|
| committer | Philip Wittamore <philip@wittamore.com> | 2026-07-12 11:08:50 +0200 |
| commit | 420ceb49b53a8fa9d8ba8443e42e50cd7bd7cea9 (patch) | |
| tree | 3009f0564d75e3f7d1ca38507e7ebb92deaded07 /search.php | |
update
Diffstat (limited to 'search.php')
| -rwxr-xr-x | search.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/search.php b/search.php new file mode 100755 index 0000000..095d8c1 --- /dev/null +++ b/search.php @@ -0,0 +1,104 @@ +<?php +$string = ""; +if (isset($_POST["s"])) { + $string = htmlspecialchars($_POST["s"]); +} +?> +<!doctype html> +<html lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" > + <meta name="viewport" content="width=device-width, initial-scale=1.0" > + <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> + <nav> + <p><a href="index.php">Blog</a> | <a + href="/static/index.php">Static</a> | <b>Search</b> | <a + href="https://git.wittamore.fr" target="_blank" title="Git">Git</a> | <a + href="https://social.wittamore.fr/philip" target="_blank" title="Fediverse">Fedi</a> | <a + href="/feeds/index.php" target="_blank" title="Feeds">Feeds</a> | <a + href="rss.xml">RSS</a></p> + </nav> + <div class="banner"> + <img src="/images/me.jpg" alt="logo"> + <p>Comments: <a href="https://social.wittamore.fr/philip">@philip</a><br> + Contact: <a href="/images/deltachatqr.jpg">Deltachat</a> + </p> + </div> + </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("./static"); + 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> </p> + <hr /> + <p>ยง</p> + </body> +</html> + + + + |
