PHP Classes

File: helpdocs.php

Recommend this page to a friend!
  Classes of Mark Cole   PHP Online Help System   helpdocs.php   Download  
File: helpdocs.php
Role: Example script
Content type: text/plain
Description: Example code displays PHPHelp Documentation
Class: PHP Online Help System
Get site help topics from file defined with macros
Author: By
Last change:
Date: 10 years ago
Size: 5,305 bytes
 

Contents

Class file image Download
<?php

/*********************************************************************************************

    This script serves both as an example of the use of PHPHelp and also to display the
    PHPHelp class documentation by actually using PHPHelp.
   
    The same documentation (although without live examples) is available as plain text
    in helpdocs.txt
   
    Put this script (helpdocs.php), phphelp.class.php, helpdocs.hxt and snippets.txt in an executable
    directory on your server. If need be change the "require_once" and or the "$helpfile=" settings
    at lines 38 and 84 and then browse to helpdocs.php
   
    If topic links don't work properly you may need to adjust phphelp->linkURI for your server.
    See linkURI in phphelp.txt

    The complete distribution package for PHPHelp consists of the following files.

    phphelp.class.php ... The PHPHelp class itself.
    helpdocs.php ........ Example script that displays the documentation.
    phphelp.hxt ......... PHPHelp documentation in PHPHelp file form to be viewed using helpdocs.php
    snippets.txt ........ Example "snippets" file also used by helpdocs.php
   
    All of the above are Copyright Mark Cole, 2014 and are released under the same GNU licence as
    phphelp.class.php and should be included in any modified package that you distribute.

    Also in the complete package is LICENCE.TXT, the GNU General Public Licence and this too must be
    included in any modified distribution.
   
    Note: PHPHelp and its examples and documentation were written on a Windows XP box (developed with
    php 5.4.15/Apache 2.4.4) I apologise for any file encoding problems that may occur for users of other
    OS's. PHPHelp has been tested with linux (PHP 5.3.28/Apache 2.2.24).

**********************************************************************************************/


require_once('phphelp.class.php');

echo
'<!DOCTYPE HTML><html><head><style>
h1 { text-align:center} h2 { text-align: center;}
html {height: 100%; overflow:hidden; }
body {position:relative; width:100%; height:97%;background: lightgray;}
div.code { position: relative; width: 90%; margin: auto; padding: 1em;background: white;font: 10pt Monospace;text-align:left;}
div.codei { position: relative; width: 70%; margin: auto; padding: 1em;background: white;font: 10pt Monospace;text-align:left;}
div.help { position: relative; height: 75%; overflow: auto; width: 90%;margin:auto; ;padding: 1em;background: beige; font: 10pt Verdana,Arial,Helvetica; text-align: justify;}
p.cent { position: relative; text-align: center;}
p.indent { position: relative; margin-left:5%; margin-right:5%;}
ul { width: 20%; margin: auto; list-style:none; line-height: 2em;}
b { font-style: italic; font-weight: bold;}
</style></head><body>
'
;

// This is an example of a callback macro - it is used by the phphelp.hxt file
// to show next topic and index links on each page.
function indexlink($s)
{
    if (
$s) return '<hr><div style="float:right">@{phphelp:Back to Index}</div><div>Next Topic: '.$s.'</div>';
    else return
'<p style="text-align: right;">@{phphelp:Back to Index}</p><hr>';
}


// Example to show the use of the phphelp->topics() method
function allTopics()
{
    global
$help;
   
$topics=$help->topics();
    echo
"<h1>PHPHelp Documentation</h1>";
    echo
"<div class=\"help\"><p style=\"text-align: center\"><h2>Available Topics</h2></p>";
    echo
'<p class="cent">(an example of the phphelp->topics() method)</p>';
    echo
"<div style=\"position: relative; width:30%;margin: auto; padding: 16px; border: 2px solid; text-align: left;\">";
    foreach (
$topics as $topic)
    {
        echo
$topic['link']."<br>";
    }
    echo
"</div></div>";
}

   
// Main code. Display help topics from the phphelp.hxt file
    //=========================================================
   
    // Path to help files. Change if need be.
$helpfile="phphelp.hxt";

   
// Instantiate a new phphelp object
$help=new phphelp($helpfile);

   
// Register the indexlink callback macro which is used in the PHPHelp help file (phphelp.hxt).
$help->registerCallbackMacro('indexlink');

   
// Example (used in the help file) of registering a PHP function as a callback macro
$help->registerCallbackMacro('substr');

   
// Variable Substitution example (used in the help file).
$example = "This is an example variable substitution.";
$help->registerVar('example',$example);

   
// Set ignoreErrors TRUE for production sites, false while debugging a
    // help file. Default is FALSE
//$help->ignoreErrors=true;


    // Expect a topic in the query string. If not go to the introduction page.
if (isset($_GET['topic'])) $topic=$_GET['topic']; else $topic="phphelp";

   
// If the topic is "topiclist" call allTopics to display a topic list.
if ($topic == "topiclist")
   
allTopics();
else
{
    if (
$topic=$help->help($topic))
    {
        echo
"<h1>PHPHelp Documentation</h1><p class=\"cent\"><a href=\"".(isset($_SERVER['SCRIPT_URL']) ? $_SERVER['SCRIPT_URL'] : parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH))."?topic=topiclist\">List all Topics</a></p>";
        echo
"<div class=\"help\"><p class=\"cent\"><h2>$topic[0]</h2></p>";
        echo
"$topic[1]</div>";
    }
    else
    {
        echo
"Help topic not found<br>";
        if (
$help->error) echo "Error=".$help->errorInfo;
    }
}

echo
'</body></html>';

?>