<?
/*****
funlib.inc
Function library for Leafwa.
Created 16-Mar-2000.
Last altered 29-Oct-2000.
*****/
require "settings.inc";
require "csettings.inc";
/*------------------------------------------------------------------*/
/*
header to make page automatically refresh whenever it is loaded,
disabling browser caching for the page. Note that all headers must be
sent before starting to write the page.
*/
function forceReload(){
// Date in the past:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified:
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// for HTTP/1.1:
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
}
/* split up, so you can put scripts in the middle */
function outHeadS1($title){
echo "<html>\n<head>\n";
echo "<title>$title</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/leafwamain.css\">\n";
echo "<link rel=\"shortcut icon\" href=\"images/leafwa.ico\" type=\"image/x-icon\">\n";
echo "<link rel=\"icon\" href=\"images/leafwa.ico\" type=\"image/x-icon\">\n";
}
function outHeadS2(){
echo "</head>\n\n<body color=\"#000000\" bgcolor=\"#f8f8ee\">\n\n";
}
/* output the HTML header for a page */
function outHead($title){
outHeadS1($title);
outHeadS2();
}
/* output text to go at the top of a screen */
function outTop($title, $slogan){
echo "<!-- basically forced to use FONT here in case the browser does not use/want the stylesheet... -->\n";
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000000\" width=\"100%\">\n";
echo "<tr>\n";
echo "<td width=\"0\" align=\"left\" valign=\"center\">\n";
echo "<img src=\"images/logo6b.png\" border=\"0\" alt=\"Leafwa logo\">\n";
echo "</td>\n";
echo "<td width=\"100%\" align=\"center\">\n";
echo "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" bgcolor=\"#004422\" width=\"100%\">\n";
echo "<tr><td align=\"center\">\n";
echo "<font color=\"#FFFFFF\" size=\"5\"><strong>$title</strong></font>\n";
echo "</td></tr>\n";
echo "</table>\n";
echo "<font color=\"#22FF22\"><strong><em>$slogan</em></strong></font>\n";
echo "</td>\n";
echo "<td width=\"0\" align=\"right\" valign=\"center\">\n";
echo "<img src=\"images/logo6brev.png\" border=\"0\" alt=\"Leafwa logo\">\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
}
/*------------------------------------------------------------------*/
/* output http headers (if necessary), http head, title and slogan */
function outHeadTop($title, $slogan, $force){
if ($force) forceReload();
outHead($title);
outTop($title, $slogan);
}
/*------------------------------------------------------------------*/
/* output lines of text for debugging purposes */
/* pass in the string to be displayed */
function debugOutput($output) {
if ($output == "") {
break;
} else {
echo "<span class=\"plainred\">debug!</span> ".$output."<br>\n";
}
}
/*------------------------------------------------------------------*/
/* break out of current page immediately */
/* add closing page tags prematurely */
function exitPageNow() {
echo "\n<hr noshade>\n";
echo "</body>\n";
echo "</html>\n";
exit();
}
/*------------------------------------------------------------------*/
/* output a Usenet message as HTML */
/* pass in the message id to be displayed */
function outMessage($msgId) {
global $outgoingDir, $monospaced, $defaultMono;
$mess = htmlspecialchars(readFileToString($outgoingDir . $msgId));
$useMono = $monospaced;
if ($monospaced == "") $useMono = $defaultMono;
if ($useMono) {
#***** view in monospaced font *****
echo "<pre class=\"msg\">\n$mess\n</pre>\n";
} else {
#***** view in variable-spaced font *****
$mess = nl2br($mess);
echo "<div class=\"plainmsg\">\n$mess\n</div>\n";
}
}
/*------------------------------------------------------------------*/
/* return information about the environment */
/* return the user that the PHP process is running as */
function getUser(){
$result = exec("whoami", $d1, $d2);
if ($result=="") $result = $d1[0];
return $result;
}
/* return a string containing the name of the operating system that
PHP is running on */
function getOperatingSystem(){
$os = exec("uname -s -r", $d1, $d2);
if ($os=="") $os = $d1[0];
return $os;
}
/* return a string containing the Leafnode version */
function getLeafnodeVersion(){
global $lnPrefix;
$ver = exec($lnPrefix."/bin/newsq -V", $d1, $d2);
if ($ver=="") $ver = $d1[0];
if (substr($ver,0,5) == "newsq"){
$ver = trim(substr($ver, 6));
} else {
$ver = "(before 2.0)";
}
return $ver;
}
function getLeafnodeVersion2() {
// global $leafnode;
// $ver = exec("sudo -u news echo QUIT | sudo -u news ".$leafnode, $d1, $d2);
global $lnPrefix;
$ver = exec($lnPrefix."/bin/leafnode-version", $d1, $d2);
if ($ver=="") $ver = $d1[0];
// $ver = trim(substr($d1[0], 34, 6));
$ver = trim(substr($d1[0], 18));
return $ver;
}
function getNewsqDepthVal() {
global $lnPrefix;
exec($lnPrefix."/bin/newsq", $arr, $retVal);
$arrSiz = sizeof($arr);
if ($arrSiz == 2) {
$newsQSiz = 0;
} else {
$newsQSiz = (($arrSiz - 1) / 5);
}
return $newsQSiz;
}
function getNewsqDepthStr() {
$newsQSiz = getNewsqDepthVal();
if ($newsQSiz == 1){
$s = "";
} else {
$s = "s";
}
$newsqDepth = "$newsQSiz message$s";
return $newsqDepth;
}
/*------------------------------------------------------------------*/
/* returns the string containing a file */
function readFileToString($fn){
$farr = file($fn);
return implode($farr, "");
}
/* save a string into a file */
function writeFileFromString($fn, $str){
$fp = fopen($fn, "w");
fwrite($fp, $str);
fclose($fp);
}
/*------------------------------------------------------------------*/
/* functions for viewsettings.php and viewcsettings.php */
function outValue2($n, $v, $helpTag){
echo "<tr><td align=\"left\" valign=\"top\" bgcolor=\"#ffffff\"><b>$n</b> </td>\n";
echo "<td align=\"left\" bgcolor=\"#ccddff\">$v</td>\n";
echo "<td> <a href=\"h_viewset.html#".$helpTag."\" target=\"leafwahelp\">?</a></td>";
echo "</tr>\n";
}
function outValue($n, $v1, $v2){
echo "<tr><td align=\"left\" valign=\"top\" bgcolor=\"#ffffff\"><b>$n</b> </td>\n";
echo "<td align=\"left\" bgcolor=\"#ddffcc\">$". $v1 ."</td>\n";
echo "<td align=\"left\" bgcolor=\"#ccddff\">". $v2 ."</td>\n";
echo "<td> <a href=\"h_viewset.html#".$v1."\" target=\"leafwahelp\">?</a></td>";
echo "</tr>\n";
}
function outValueBinary($n, $v1, $v2){
outValue($n, $v1,
$v2 . " <i>(means " . ($v2?"yes":"no") . ")</i>");
}
function outValueV($n, $vname){
global $$vname;
$v = $$vname;
outValue($n, $vname, $v);
}
function outSpacer($colspan){
echo "<tr><td colspan=\"$colspan\">\n"
. " <hr>\n</td></tr>\n";
}
function outValueNoHelp($n, $v1, $v2){
echo "<tr><td align=\"left\" valign=\"top\" bgcolor=\"#ffffff\"><b>$n</b> </td>\n";
echo "<td align=\"left\" bgcolor=\"#ddffcc\">$". $v1 ."</td>\n";
echo "<td align=\"left\" bgcolor=\"#ccddff\">". $v2 ."</td>\n";
echo "</tr>\n";
}
/* output a value from csettings.inc */
function outValueC($n, $vname){
global $$vname;
$v = $$vname;
outValueNoHelp($n, $vname, $v);
}
/*------------------------------------------------------------------*/
/*end*/
?>