aboutsummaryrefslogtreecommitdiff
path: root/search.php
blob: 095d8c1f0a9b2507c2086af87560365d618da44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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>