summaryrefslogtreecommitdiff
path: root/search.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--search.php124
1 files changed, 124 insertions, 0 deletions
diff --git a/search.php b/search.php
new file mode 100644
index 0000000..a66fc41
--- /dev/null
+++ b/search.php
@@ -0,0 +1,124 @@
+<?php
+ require 'common.php';
+?>
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+
+ <title>Manup &emsp; &emsp; &emsp; &emsp; &emsp; &emsp; &emsp; Lonely MAN near You</title>
+
+ <link rel="icon" type="image/png" sizes="128x128" href="imgs/logo-goog.png"/>
+ <link rel="icon" type="image/png" sizes="32x32" href="imgs/logo-goog32.png"/>
+ <link rel="icon" type="image/png" sizes="16x16" href="imgs/logo-goog16.png"/>
+ <!--<link rel="icon" type="image/x-icon" sizes="16x16" href="imgs/logo-goog16.ico"/>-->
+
+ <link rel="stylesheet" href="style/normalize.css"/>
+ <link rel="stylesheet" href="style/main.css"/>
+ <link rel="stylesheet" href="style/search.css"/>
+ <link rel="stylesheet" href="style/man.css"/>
+ </head>
+ <body>
+ <div id="main">
+ <header>
+ <a id="logo" href="/">
+ <h1>
+ <span id="logo-let">L</span>
+ <span id="logo-me">m</span>
+ <code id="logo-man">m</code>
+ <span id="logo-that">t</span>
+ <span id="logo-for">F</span>
+ <span id="logo-you">y</span>
+ </h1>
+ <div id="logo-ver_wrap">
+ <span id="logo-ver">BETA!</span>
+ </div>
+ </a>
+ <nav id="search_pane">
+ <form>
+ <div id="query_wrap">
+ <input id="query" type='searcg' value='<?=$query;?>' name='query' required/>
+ <button id="def" type='submit' value='man' name='action' class="btn-def" aria-hidden="true" tabindex="-1"></button>
+ <button id="mank" type='submit' value='apropos' name='action' title="apropos(1)">-k</button>
+ <button id="man" type='submit' value='man' name='action' title="Feeling lucky, punk?" class="btn-acc">
+ <div id="query_icon"></div>
+ </button>
+ </div>
+ </form>
+ </nav>
+ <nav id="topnav">
+ <a href="https://cabin.digital">Cabin</a>
+ <a href="#"><span id="topnav_icon"></span></a>
+ <button class="btn-acc">Man up</button>
+ </nav>
+ </header>
+ <section id="results">
+<?php
+ $found_man = false;
+ if($action === "man")
+ {
+ $arg_section = "";
+ if(!empty($section))
+ $arg_section = "-s ". escapeshellarg($section);
+
+ $res = exec("man -M $manpath -T html -O fragment $arg_section "
+ . escapeshellarg($query), $lines, $ret);
+ if($ret === 0)
+ {
+ $url = "$root/?query=". urlencode($query) ."&ampsection=1&action=lmmtfy";
+
+ echo "<nav id='lmmtfy'><div><div>";
+ echo " <label for='lmmtfy_url'>LmmtFy URL</label></div>";
+ echo " <textarea id='lmmtfy_url' wrap='off' rows='1' readonly>".$url."</textarea>";
+ echo " <button id='lmmtfy_copy' class='jsonly'>Copy</button></div><nav>";
+ echo "<article class='manpage'>". implode(PHP_EOL, $lines) ."</article>";
+ echo "<script src='/js/copy.js'></script>";
+
+ $found_man = true;
+ }
+ }
+
+ if(($action === "apropos") || !$found_man)
+ {
+ $res = exec("man -M $manpath -k " . escapeshellarg($query), $lines, $ret);
+ if($ret === 0)
+ {
+ $n = count($lines);
+ $s = $n > 1 ? "s" : "";
+ echo "<p class='hint'> Found $n result$s</p>";
+
+ foreach($lines as $line)
+ {
+ $split = explode(") - ", $line);
+ $full = $split[0];
+ $desc = $split[1];
+
+ $split = explode("(", $full);
+ $name = explode(",", $split[0])[0];
+ $sect = strtolower(explode(",", $split[1])[0]);
+
+ $url = "$root/search.php?query=". urlencode($name) ."&section=". urlencode($sect)
+ ."&action=man";
+
+ echo '<dl>';
+ echo " <dt><a href='".$url."'>$full)</a></dt>";
+ echo " <dd>$desc</dd>";
+ echo '</dl>';
+ }
+ }
+ else echo "<p class='hint'> No results.</p>";
+ }
+?>
+ </section>
+ <footer>
+ <p class="center">
+ Copyleft <span class="copyleft">&copy;</span> 2024
+ <a href="mailto:manup@cabin.digital">dweller</a> from
+ <a href="https://cabin.digital">cabin.digital</a>.
+ All Wrongs Reserved.
+ </p>
+ </footer>
+ </div>
+ </body>
+</html>