andy's php projects
Script and site usage:
All of the scripts on this site are provided free for non-commercial, personal or non-profit use. If you wish to use any of these in a commercial system, please refer to the payment plan.

Support:
Support for each of the scripts is given, free of charge, on the message board. Each script has its own message board which can be accessed by clicking on the 'project forum' link (beneath the description of each project).


Proudly hosted with Dreamhost

Save $20 when signing up for Dreamhost by using the promo code amnuts20


If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh to encourage me to continue? Every little helps!

Zend Certified Engineer logo


Amnuts Talker Helpfile Viewer

Allows to you list and display all the helpfiles associated with an Amnuts talker, or that use the same format as the Amnuts talker helpfiles do.

class.helpfiles.php

<?php

//
// class.helpfiles.php
// 1.0.0
//
// This class is used to parse and render helpfiles used in the Amnuts
// talker distribution (http://amnuts.talker.com/).  It allows for full
// or partial matching of the helpfile names.
// 
// Andrew Collington, 2002
// php@amnuts.com, http://php.amnuts.com/
//
// Example of use:
//
//    require_once("class.helpfiles.php");
//    $help = new HelpFiles("./helpfiles");
//    if ($keyword) $help->ViewHelp($keyword);
//    else $help->ViewAll();
//    $help->Version();
//

class HelpFiles
{
    
// variables
    
var $help;        // list of all helpfiles
    
var $vars;        // query string or form vars
    
var $cols;        // list how many wide
    
var $helpfile;    // the name of the helpfile
    
var $location;    // where the helpfiles are located

    // constructor
    
function HelpFiles($location="")
    {
        
// error checking
        
if ($location == "")
        {
            
$this->Error("You must supply the helpfile location.");
            return;
        }

        
// setting stuff
        
$this->location $location;
        if (
get_magic_quotes_gpc()==1$this->gpcSlashes 1;
        else 
$this->gpcSlashes 0;
        if (
$HTTP_GET_VARS$this->vars $HTTP_GET_VARS;
        else 
$this->vars $HTTP_POST_VARS;

        
// other variables
        
$this->cols 5;
        
$this->help = array();
    }
    
    function 
ViewAll()
    {
        
$this->GetFileList();
        if (!
count($this->help))
        {
            echo 
"<p class=\"error\">No helpfiles could be found.  Are you sure you put in the correct directory in the setup?</p>\n";    
            return;
        }
        
$this->ListFound();
    }

    function 
ViewHelp($keyword)
    {
        global 
$PHP_SELF;

        
$trans = array("~RS"=>"","~OL"=>"","~UL"=>"","~LI"=>"","~RV"=>"","~FK"=>"","~FR"=>"","~FG"=>"",
                
"~FY"=>"","~FB"=>"","~FM"=>"","~FT"=>"","~FW"=>"","~BK"=>"","~BR"=>"","~BG"=>"",
                
"~BY"=>"","~BB"=>"","~BM"=>"","~BT"=>"","~BW"=>"");

        
// make the word safe
        
if ($this->gpcSlashes$keyword stripslashes($keyword);
        
$this->helpfile eregi_replace("[\\./<>;]","",$keyword);
        
$this->helpfile trim($this->helpfile);

        
// load up the file
        
$fcontents = @file("$this->location/$this->helpfile");
        if (!
$fcontents[0])
        {
            echo 
"<p class=\"error\">There is no helpfile called <b>$this->helpfile</b>.</p>\n";
            
$this->GetStartsWithFileList();
            if (
count($this->help))
            {
                echo 
"<p>Helpfiles that start with <b>$this->helpfile</b></p>\n";
                
$this->ListFound();
            }
            
$this->GetPartialFileList();
            if (
count($this->help))
            {
                echo 
"<p>Helpfiles that contain <b>$this->helpfile</b> in them</p>\n";
                
$this->ListFound();
            }
            echo 
"<br><p class=\"content\"><a href=\"$PHP_SELF?type=helpfile\">&lt;&lt; full list</a></p>\n";        
            return;
        }
    
        
$command_str = array();
        
$usage_str = array();
        
$alias_str = array();
        
$content_str "";
        
$last_type "";
        
// remove all colour codes & \n
        
for ($i=0$i<count($fcontents); $i++)
        {
            
$fcontents[$i] = strtr($fcontents[$i],$trans);
            
$fcontents[$i] = ereg_replace("\n"," ",$fcontents[$i]);
            if (
eregi("^command",$fcontents[$i]))
            {
                
$arr split(":",$fcontents[$i],2);
                
$command_str[] = trim($arr[1]);
                
$last_type "command";
            }
            elseif (
eregi("^usage",$fcontents[$i]))
            {
                
$arr split(":",$fcontents[$i],2);
                
$usage_str[] = trim($arr[1]);
                
$last_type "usage";
            }
            elseif (
eregi("^aliases",$fcontents[$i]))
            {
                
$arr split(":",$fcontents[$i],2);
                
$alias_str[] = trim($arr[1]);
                
$last_type "alias";
            }
            elseif (
eregi("^[[:space:]]{8}: ",$fcontents[$i]))
            {
                
$arr split(":",$fcontents[$i],2);
                switch(
$last_type)
                {
                    case 
"command":
                        
$command_str[] = trim($arr[1]);
                        break;
                    case 
"usage":
                        
$usage_str[] = trim($arr[1]);
                        break;
                    case 
"alias":
                        
$alias_str[] = trim($arr[1]);
                        break;
                }
            }
            else
            {
                
$content_str .= $fcontents[$i];
            }
        }

        
// display it
        
echo "<p class=\"title\">Helpfile for the <b>$this->helpfile</b> command</p>\n";
        echo 
"<table border=\"0\" cellpadding=\"3\">\n";
        
$printed 0;
        for (
$i=0$i<count($command_str); $i++)
        {
            echo 
"<tr><td class=\"commandtitle\" align=\"right\">" . ((++$printed==1)?"Command":"&nbsp;") . "</td><td class=\"command\">" htmlspecialchars(trim($command_str[$i])) . "</td></tr>\n";
        }
        
$printed 0;
        for (
$i=0$i<count($usage_str); $i++)
        {
            echo 
"<tr><td class=\"usagetitle\" align=\"right\">" . ((++$printed==1)?"Usage":"&nbsp;") . "</td><td class=\"usage\">" htmlspecialchars(trim($usage_str[$i])) . "</td>\n";
        }
        
$printed 0;
        for (
$i=0$i<count($alias_str); $i++)
        {
            echo 
"<tr><td class=\"aliastitle\" align=\"right\">" . ((++$printed==1)?"Aliases":"&nbsp;") . "</td><td class=\"alias\">" htmlspecialchars(trim($alias_str[$i])) . "</td>\n";
        }
        echo 
"</table>\n";
        echo 
"<br><p class=\"content\">" nl2br(htmlspecialchars(trim($content_str))) . "</p>\n";
        echo 
"<br><p class=\"content\"><a href=\"$PHP_SELF?type=helpfile\">&lt;&lt; full list</a></p>\n";
    }

    function 
SearchForm()
    {
        global 
$PHP_SELF;
        
        echo 
"<form action=\"$PHP_SELF\" method=\"POST\">\n";
        echo 
"<p><input type=\"text\" name=\"search\" size=\"20\"> <input type=\"submit\" value=\"search\"></p>\n";
        echo 
"</form>\n";
    }

    function 
Error($err)
    {
        echo 
"\n\n<p><b><font colour=\"red\">$err</font></b></p>\n\n";
    }

    function 
GetFileList()
    {
        
$this->help = array();
        
$handle = @opendir($this->location);
        while (
$f = @readdir($handle))
        {
            if (!
is_dir($f)) $this->help[] = $f;
        }
        @
closedir($handle);
    }

    function 
GetPartialFileList()
    {
        
$i 0;
        
$this->help = array();
        
$handle = @opendir($this->location);
        while (
$f = @readdir($handle))
        {
            if (!
is_dir($f) && strstr($f,$this->helpfile)) $this->help[] = $f;
        }
        @
closedir($handle);    
    }
    
    function 
GetStartsWithFileList()
    {
        
$this->help = array();
        
$handle = @opendir($this->location);
        while (
$f = @readdir($handle))
        {
            if (!
is_dir($f) && eregi("^$this->helpfile",$f)) $this->help[] = $f;
        }
        @
closedir($handle);    
    }

    function 
ListFound()
    {
        global 
$PHP_SELF;

        
sort($this->help);
        echo 
"<table border=\"0\" width=\"100%\" cellpadding=\"5\">\n";
        
$trs 0;
        for (
$i=0$i<count($this->help); $i++)
        {
            if (!
$trs++) echo "<tr>\n";
            echo 
"<td class=\"list\"><a href=\"$PHP_SELF?type=helpfile&keyword={$this->help[$i]}\">{$this->help[$i]}</a></td>\n";
            if (
$trs==$this->cols)
            {
                
$trs=0;
                echo 
"</tr>\n";
            }
        }
        if (
$trs) echo "</tr>\n";
        echo 
"</table>\n";
        echo 
"<p class=\"count\">" count($this->help) . " helpfile" . ((count($this->help)==1)?"":"s") . " found.</p>\n";
    }


    function 
Version($full=0)
    {
        echo 
"\n\n<hr noshade size=\"1\" color=\"#000000\">\n";
        echo 
"<p class=\"small\">Created with the Amnuts helpfile class by Andrew Collington, <a href=\"mailto:php@amnuts.com\">php@amnuts.com</a>";
        if (
$full)
        {
            echo 
"\n<br>To be used with the helpfiles found in the Amnuts talker code<br>\n";
            echo 
"<a href=\"http://amnuts.talker.com/\">http://amnuts.talker.com/</a>\n";
        }
        echo 
"</p>\n";
    }

}

?>
6.79kb in size
last modified May 6, 2006 at 9:54pm
5462 views, 4894 downloads
list all projects :: this project's forum :: script in action
added Sep 19, 2002 at 2:50pm :: updated Sep 19, 2002 at 2:50pm :: 1 file :: 18445 views

© Andrew Collington, 2002-2007.