aboutsummaryrefslogtreecommitdiff
path: root/search.php
diff options
context:
space:
mode:
Diffstat (limited to 'search.php')
-rwxr-xr-xsearch.php104
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>&nbsp;|&nbsp;<a
+ href="/static/index.php">Static</a>&nbsp;|&nbsp;<b>Search</b>&nbsp;|&nbsp;<a
+ href="https://git.wittamore.fr" target="_blank" title="Git">Git</a>&nbsp;|&nbsp;<a
+ href="https://social.wittamore.fr/philip" target="_blank" title="Fediverse">Fedi</a>&nbsp;|&nbsp;<a
+ href="/feeds/index.php" target="_blank" title="Feeds">Feeds</a>&nbsp;|&nbsp;<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>&nbsp;</p>
+ <hr />
+ <p>ยง</p>
+ </body>
+</html>
+
+
+
+