corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
<?php /* --- ۞---> text { encoding:utf-8;bom:no;linebreaks:unix;tabs:4sp; } */
// for my colors and stuff..
require_once $_SERVER['DOCUMENT_ROOT'].'/inc/init.php';
$version = '0.6';
$topic = '';
$section = '';
$k = '';
$use_man2html = false;
$format = false;
$keepformat = false;
if (isset($_GET['format'])) { $format = true; }
if (isset($_GET['keepformat'])) {
if ($_GET['keepformat'] = 'on' ) $keepformat = true;
$format = true;
}
if (isset($_GET['topic'])) {
$topic = $_GET['topic'];
if (isset($_GET['section'])) {
$section = $_GET['section'];
if ($section == 'keyword') {
$k = '-k';
}
}
}
/*
Quick'n'Dirty PHP Man Page Viewer
Not a replacement for man2html by any means, but a handy "bare" viewer.
If you don't have perl cgi enabled, or just prefer php over perl
regardless, this might be useful to you. it's very compact, at any rate.
I came across "col" *almost by accident* when I was trying to diagnose
why my man2html had stopped working one day. It was, wait for it..
a permission problem! *sigh*, and once I fixed that, they both worked! heh.
this technique is suggested in the tips for the "man" man page. the
real work is done by the operating system, we're just pushing the buttons.
If you have man2html installed, this works in tandem with it, offering
"formatted" versions, also works for keyword searches. You can also disable
that on servers where Man2HTML is not available (most web servers)
Recently I tarted it up a bit for the molasses, and here it is..
;o)
note: searching for "keywords" can be amazing (Mac OS X/bsd) or useless (most
*nix I've tried) I'd be interested to hear how well it works on different
platforms. of course, none of this works on Windoze. period.
(c) 2004->tomorrow! ~ cor + corz.org ;o)
Please view the license for this free software, here:
https://corz.org/free-scripts-licence.nfo
*/
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<title>quick\'n\'dirty php man page viewer v',$version,'</title>
<link rel="stylesheet" href="/inc/css/machine.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/inc/css/bfix.css" type="text/css" media="screen" />';
include $site_config['metadata'];
echo '
<style type="text/css" media="screen">
.mantop, .manpage {
padding: 1rem;
background: ',$site_scheme['promo_background'],';
width: 100%;
max-width: 800px;
color: ',$site_scheme['pre_color'],';
}
.mantop {
margin-top: 7rem;
}
.manpage {
font-size: 90%;
}
.man-title {
font-size: 150%;
font-weight: bold;
float: left;
}
.format {
margin-top: .2rem;
font-size: 90%;
}
.toplinks {
position: fixed;
}
select {
width: 17rem;
height: 3.2rem;
}
@media screen and (max-width: 1024px) {
.manpage {
font-size: 80%;
}
}
@media screen and (max-width: 920px) {
.manpage {
font-size: 70%;
}
.toplinks {
position: relative;
}
}
@media screen and (max-width: 800px) {
.mantop {
margin-top: 8rem;
}
select {
width: 100%;
height: 300%;
}
}
</style>
</head>
<body>';
@include $_SERVER['DOCUMENT_ROOT'].'/inc/header.php';
// $_SERVER['SCRIPT_NAME'] is usual, but I like my cute short links to stay short!
echo '
<div id="tool" class="content super-wide">
<form name="manform" method="get" action="',$_SERVER['REQUEST_URI'],'">
<div class="mantop">
<div class="man-title">
search..
</div>
<div class="right" title="search..">
<select name="section" id="chooser">
<option value="all"';
if ($section == 'all') echo ' selected';
echo '>for manpage</option>
<option value="keyword"';
if ($section == 'keyword') echo ' selected';
echo '>for keyword</option>
</select>
<input name="topic" type="text" value="'.$topic.'" size="21" title="enter the name of the manpage you wish to view" />
<input type="submit" value="get my man!" />
</div>
<div class="clear-small"></div>';
if ($topic != '') {
if ($use_man2html) {
echo '
<div class="left format">
<a href="/cgi-bin/man.cgi?',$_SERVER['QUERY_STRING'],'" title="you need man2html installed for this
['.$site_config['url'].'/public/mac/]">
get a plain HTML formatted version <small>(more reliable)</small></a>
</div>
<div class="right format">
<a href="',$_SERVER['REQUEST_URI'],'?section=',$section,'&topic=',$topic,'&format=true"
title="you need man2html installed for this
['.$site_config['url'].'/public/mac/man/]">format this version</a><br />
<input type="checkbox" name="keepformat"';
if ($keepformat == true) {
echo ' checked';
}
echo '> always
</div>
</div>
<div class="clear"></div>';
}
if ($use_man2html and $format == true) {
system('man '.$k.' '.$topic.' | man2html -cgiurl '.$_SERVER['REQUEST_URI'].'?section=${section}${subsection}&topic=${title} 2>&1');
} else {
echo '<pre class="manpage">';
system("man $k $topic | col -bf 2>&1");
echo '</pre>';
}
echo '
</div>';
}
echo '
</form>
</div>
<div class="clear-quarter"></div>
<div class="toplinks"><a href="https://corz.org/engine?section=php/corz%20function%20library" title="download the source in a zip">download source</a></div>
</div>
<div class="clear-small"></div>';
include $site_config['footer'];
echo '
</body>
</html>';