summaryrefslogtreecommitdiff
path: root/search.php
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2024-02-27 20:48:15 +0200
committerdweller <dweller@cabin.digital>2024-02-27 20:48:15 +0200
commit2a66021e508fe2ff6912e6e6578eaf035e1ffdd8 (patch)
tree6a2066ac5a617ef3b02798e1e27d89d5368889fb /search.php
parentcd0894ddefbc9c0be2d59b9160fc911e16b67bd2 (diff)
add section and arch dropdowns, wow that was a pain
Diffstat (limited to '')
-rw-r--r--search.php64
1 files changed, 50 insertions, 14 deletions
diff --git a/search.php b/search.php
index 5e3c5f4..4d3129b 100644
--- a/search.php
+++ b/search.php
@@ -25,6 +25,9 @@
<link rel="stylesheet" href="style/main.css"/>
<link rel="stylesheet" href="style/search.css"/>
<link rel="stylesheet" href="style/man.css"/>
+ <noscript>
+ <style>.jsonly{ display: none; }</style>
+ </noscript>
</head>
<body>
<div id="main">
@@ -45,10 +48,36 @@
<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">
+ <input id="query" type='searcg' value='<?=$query;?>' name='query' required/>
+ <span class="query_opt" title="section">-s</span>
+ <select id="sect" name='section' title="section" autocomplete="off">
+ <option value=""></option>
+ <?php
+ for($i = 1; $i <= 9; $i++)
+ {
+ $sel = "";
+ if((strlen($section) > 0) && ($section[0] == $i))
+ $sel = 'selected="selected"';
+ echo "<option value='$i' $sel>$i</option>";
+ }
+ ?>
+ </select>
+ <span class="query_opt" title="architecture">-S</span>
+ <select id="arch" name='arch' title="architecture" autocomplete="off">
+ <option value=""></option>
+ <?php
+ foreach($archs as $a)
+ {
+ $sel = "";
+ if((strlen($arch) > 0) && ($arch == $a))
+ $sel = 'selected="selected"';
+ echo "<option value='$a' $sel>$a</option>";
+ }
+ ?>
+ </select>
+ <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>
@@ -62,13 +91,15 @@
</header>
<section id="results">
<?php
+ $arg_section = "";
+ if(!empty($section))
+ $arg_section .= " -s ". escapeshellarg($section);
+ if(!empty($arch))
+ $arg_section .= " -S ". escapeshellarg($arch);
+
$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,toc $arg_section "
. escapeshellarg($query), $lines, $ret);
if($ret === 0)
@@ -78,7 +109,7 @@
preg_match('/\<td.*\>.+\((.+)\)\<\/td>/iu', $lines[4], $sect);
$url = "$root/?query=". urlencode($query) ."&ampsection=". urlencode($sect[1])
- ."&action=lmmtfy";
+ ."&arch=". urlencode($arch) ."&action=lmmtfy";
/* HACK: fucking mandoc just generates tons of useless <br>s that make <code> stuff
* look horrible. So I just remove it here.
@@ -105,7 +136,7 @@
if(($action === "apropos") || !$found_man)
{
- $res = exec("man -M $manpath -k " . escapeshellarg($query), $lines, $ret);
+ $res = exec("man -M $manpath $arg_section -k " . escapeshellarg($query), $lines, $ret);
if($ret === 0)
{
$n = count($lines);
@@ -114,19 +145,22 @@
foreach($lines as $line)
{
- preg_match('/^((.+)(?:,.+)*)\(((.+)(?:,.+)*)\)\s?-\s?(.*)$/Uu', $line, $matches);
+ preg_match('/^((.+)(?:,.+)*)\((.+)\)\s?-\s?(.*)$/Uu', $line, $matches);
$fname = $matches[1];
$name = $matches[2];
$fsect = $matches[3];
- $sect = $matches[4];
- $desc = $matches[5];
+ $desc = $matches[4];
+ $sect = explode(',', $fsect);
+ $arch = explode('/', end($sect));
+ $sect = trim($arch[0]);
+ $arch = trim(end($arch));
$descl = strlen($desc);
if($descl > 320) $desc = substr($desc, 0, 320) . "...";
elseif($descl === 0) $desc = "No synopsis.";
$url = "$root/search.php?query=". urlencode($name) ."&section=". urlencode($sect)
- ."&action=man";
+ ."&arch=". urlencode($arch) ."&action=man";
echo '<dl>';
echo " <dt><a href='".$url."'>$fname($fsect)</a></dt>";
@@ -147,5 +181,7 @@
</p>
</footer>
</div>
+ <div id="js_tmp"></div>
</body>
+ <script src="js/query_opts.js"></script>
</html>