<?php
ini_set
('include_path','/usr/share/pear:/usr/share/phpinclude');
require_once(
'xml_doctype.inc');
require_once(
'dom_functions.inc');

$dom = new DOMDocument('1.0','UTF-8');
$dom->preserveWhiteSpace false;
$dom->formatOutput true;
$myPage = new docType($dom);
$xmlHtml $myPage->document();
$navMenu = new navMenu($dom,'pageNav');
$navMenu->navPrefix 'tnav_';
$navMenu->addNavItem('','home','/','Home',false);

$xmlBody $dom->createElement('body');
$contentDiv $dom->createElement('div');
$contentDiv->setAttribute('id','contentOne');
$contentDiv->setAttribute('class','content');
$navMenu->addMenu($contentDiv);

$navMenu->addNavItem($contentDiv,'intro','intro','Introduction');
$xmlHeader $dom->createElement('h1','Introduction');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','The file on this page is basically just a library of functions that I use to manipulated DOMDocument objects intended as web content. Reduces the typing. I also include one class with this file. Usually I like to keep classes separate but this is a small class that I use quite a bit, so it makes sense to keep it here.');
$contentDiv->appendChild($xmlPar);

$xmlPar $dom->createElement('p','This file compliments my ');
addLink($dom,$xmlPar,'/docType/','docType Class');
addText($dom,$xmlPar,'.');
$contentDiv->appendChild($xmlPar);

$xmlPar $dom->createElement('p','I will probably update this file with some frequency, check back often.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'source','source','Source');
$xmlHeader $dom->createElement('h2','Source');
$contentDiv->appendChild($xmlHeader);
$xmlBody->appendChild($contentDiv);

$codeDiv $dom->createElement('div');
$xmlBody->appendChild($codeDiv);
embedPHP($dom,$codeDiv,'dom_functions.phps','cls_source','phps_object','content');

$contentDiv $dom->createElement('div');
$contentDiv->setAttribute('id','contentTwo');
$contentDiv->setAttribute('class','content');

$navMenu->addNavItem($contentDiv,'func','func','Functions');
$xmlHeader $dom->createElement('h2','Functions');
$contentDiv->appendChild($xmlHeader);


$xmlPar $dom->createElement('p','I am not going to describe each function, read the file to see what is there. There are two basic forms that the functions take: ');
addSpan($dom,$xmlPar,'mkSomething()','mono');
addText($dom,$xmlPar,' and ');
addSpan($dom,$xmlPar,'addSomething()','mono');
addText($dom,$xmlPar,'.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'func','mk','mkSomething');
$xmlHeader $dom->createElement('h3','mkSomething()');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','Functions that start with ');
addSpan($dom,$xmlPar,'mk','mono');
addText($dom,$xmlPar,' return an object. Use them when you need to have a handle to reference the object for further manipulation. For example:');
$contentDiv->appendChild($xmlPar);

$phpCode = Array('<?php');
$phpCode[] = '$xmlLink = mkLink($dom,\'/path/to/something/\',\'\',\'[Bigger Version]\');';
$phpCode[] = '$xmlLink->appendChild($someOtherObject);';
$phpCode[] = '?>';
codeBlock($dom,$contentDiv,$phpCode,'php');

$xmlPar $dom->createElement('p','The arguments should be fairly self explanatory.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'func','add','addSomething');
$xmlHeader $dom->createElement('h3','addSomething()');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','Functions that start with ');
addSpan($dom,$xmlPar,'add','mono');
addText($dom,$xmlPar,' do not return an object, but they do create one. The second argument to these functions is always a parent object you want the created object attached to once it is created. For example:');
$contentDiv->appendChild($xmlPar);

$phpCode = Array('<?php');
$phpCode[] = 'addLink($dom,$xmlPar,\'/path/to/something/\',\'this string will be a link\');';
$phpCode[] = '?>';
codeBlock($dom,$contentDiv,$phpCode,'php');

$xmlPar $dom->createElement('p','The link would be created and then immediately appended as a child to the ');
addSpan($dom,$xmlPar,'$xmlPar','mono');
$contentDiv->appendChild($xmlPar);
addText($dom,$xmlPar,' object.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'func','notes','Function Notes');
$xmlHeader $dom->createElement('h3','Notes');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','In most cases, there are both ');
addSpan($dom,$xmlPar,'mk','mono');
addText($dom,$xmlPar,' and ');
addSpan($dom,$xmlPar,'mk','mono');
addText($dom,$xmlPar,' versions of a function. In a few cases, where I did not see the point of one of the two forms, there is only one version of the function.');
$contentDiv->appendChild($xmlPar);

$xmlPar $dom->createElement('p','In a couple cases, the ');
addSpan($dom,$xmlPar,'mk','mono');
addText($dom,$xmlPar,' and ');
addSpan($dom,$xmlPar,'mk','mono');
addText($dom,$xmlPar,' convention is not used:');
$contentDiv->appendChild($xmlPar);

$defList $dom->createElement('dl');
addDefinition($dom,$defList,'pageTitle($dom,$head,$title)','Adds a title object to the document head object (specified by second argument.)');
addDefinition($dom,$defList,'codeBlock($dom,$parent,$myArray,$lang=\'TXT\')','Creates a pre element node, takes an array of strings and adds them as children of the pre element node with a br node between each string, and then adds the pre node as a child of the node specified by $parent. Optional fourth argument specifies the code language so that syntax highlighting may be available if you have the pear Text_Highlighter package installed.');
addDefinition($dom,$defList,'embedPHP($dom,$parent,$source,$id,$objClass=\'\',$divClass=\'\')','Takes a php source file (usually with extension phps) specified by $source and embeds it in a web page as an object node. The $id argument is for the id attribute of the object node. You need to specify one, some browsers do not like object nodes that do not have an id defined. The option $objClass argument can be used to specify a CSS class to use with the object node. The optional $divClass argument can be used to specify a CSS class to use with fallback div node that is a child of the object node.');
$contentDiv->appendChild($defList);

$navMenu->addNavItem($contentDiv,'func','css','CSS notes');
$xmlHeader $dom->createElement('h3','CSS notes');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','In most cases you can define the CSS class to use. A couple classes are hard coded:');
$contentDiv->appendChild($xmlPar);

$cssCode = Array('div.cleardiv {');
$cssCode[] = '   clear: both;';
$cssCode[] = '   }';
$cssCode[] = '';
$cssCode[] = 'pre.mono {';
$cssCode[] = '   font-family: Monaco, "Lucida Mono", "Lucida Mono EFOP", "Lucida Mono EF", Courier, monospace;';
$cssCode[] = '   color: blue;';
$cssCode[] = '   }';
codeBlock($dom,$contentDiv,$cssCode,'css');

$xmlPar $dom->createElement('p','Of course, you are free to define them however you want.');
$contentDiv->appendChild($xmlPar);

$xmlPar $dom->createElement('p','If you are using the optional pear package ');
addSpan($dom,$xmlPar,'Text_Highlighter','mono');
addText($dom,$xmlPar,' you will need CSS definitions for the classes it uses. The CSS I am using for output generated by that class can be viewed here: ');
addLink($dom,$xmlPar,'/highlight.css','highlight.css');
addText($dom,$xmlPar,'.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'nmenu','nmenu','navMenu');
$xmlHeader $dom->createElement('h2','navMenu Class');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','This class is used to generate a navigation menu using (X)HTML unordered lists, such as the navigation menu at the top of this page. Once initialized, you can append the menu as a child to any node you want whether or not the menu has finished being generated, and you can add menu items to the menu at any point. When the navigation item is intended to link to an anchor within the current document, it will also create the anchor and append it to the parent node where you want it.');
$contentDiv->appendChild($xmlPar);

$navMenu->addNavItem($contentDiv,'nmenu','usage','Class Usage');
$xmlHeader $dom->createElement('h3','Class Usage');
$contentDiv->appendChild($xmlHeader);

$phpCode = Array('<?php');
$phpCode[] = '   // initiate navigation menu';
$phpCode[] = '$navMenu = new navMenu($dom,\'pageNav\');';
$phpCode[] = '$navMenu->navPrefix = \'tnav_\';';
$phpCode[] = '   // add navigation menu as a child to some parent node';
$phpCode[] = '$navMenu->addMenu($parent);';
$phpCode[] = '   // add a navigation menu item that links external page';
$phpCode[] = '$navMenu->addNavItem($parent,\'home\',\'/home.php\',\'Home\',false);';
$phpCode[] = '   // create an anchor with specified ID and add menu item';
$phpCode[] = '   //   that points to it';
$phpCode[] = '$navMenu->addNavItem($parent,\'foo\',\'foo\',\'Foo\');';
$phpCode[] = '   // add a second menu item to the same categery as foo';
$phpCode[] = '$navMenu->addNavItem($parent,\'foo\',\'bar\',\'Bar\');';
$phpCode[] = '?>';
codeBlock($dom,$contentDiv,$phpCode,'php');

$navMenu->addNavItem($contentDiv,'nmenu','pubvar','Public Variables');
$xmlHeader $dom->createElement('h3','Public Variables');
$contentDiv->appendChild($xmlHeader);

$defList $dom->createElement('dl');
addDefinition($dom,$defList,'public $navPrefix','String. The class adds an id attribute for each category of menu items. This variable defines a prefix to use for that id attribute to help insure that you do not end up with multiple elements that have the same id in your document. Defaults to empty, but I highly suggest you set it to something.');
$contentDiv->appendChild($defList);

$navMenu->addNavItem($contentDiv,'nmenu','pubfunc','Public Functions');
$xmlHeader $dom->createElement('h3','Public Functions');
$contentDiv->appendChild($xmlHeader);

$defList $dom->createElement('dl');
addDefinition($dom,$defList,'constructor function navMenu($dom,$id,$html5nav=false)','Called when you initialize the class. The first argument is the handle for your main DOM object. The second argument is the id attribute you want for the div or nav element object that will contain the navigation list. This is the id that you would reference in your CSS style sheet to style the navigation menu. The third argument is whether you are using the new (X)HTML 5 nav element as the parent element to your navigation menu. Defaults to false (in which case a div element node is used.)');
addDefinition($dom,$defList,'public function addNavItem($parent,$catid,$anchorid,$item,$makeanchor=true)','Add a navigation link to the menu. Arguments described in next section.');
addDefinition($dom,$defList,'public function returnMenuNode()','If you want to manipulate the menu object in a manner the class does not do, you can use this function to set a handle for the object. You probably will rarely ever need to use it.');
addDefinition($dom,$defList,'public function addMenu($parent)','Add the navigation menu to the document as a child of the node given in the argument. Note that you can call this function at any point, whether or not you have finished adding items to the menu. I usually call it before any items have been added.');
$contentDiv->appendChild($defList);

$navMenu->addNavItem($contentDiv,'nmenu','addnavitem','addNavItem');
$xmlHeader $dom->createElement('h3','addNavItem() Arguments');
$contentDiv->appendChild($xmlHeader);

$defList $dom->createElement('dl');
addDefinition($dom,$defList,'$parent','First Argument. When this function creates an anchor for navigation within the page, that is the element node the that the anchor will be appended as a child element of. Needs to exist before the function is called. If you are linking to an external page, you can set this argument to the string \'\'');
addDefinition($dom,$defList,'$catid','Second Argument. Can not be empty. This is used to create an id attribute for a category of similar navigation items. The value of the navPrefix public variable will automatically be prepended to this argument when the id attribute is made.');
addDefinition($dom,$defList,'$anchorid','Third Argument. When the navigation menu points to an external resource, this argument needs to be the URL to that resource. When the navigation menu points to an internal resource, this argument needs to be the id of that resource. You can set it to the same value as the $catid argument but only if you have set the navPrefix public variable, otherwise you will have two elements with same id in your document, and that is bad. You can also set this to the string \'\' and it will create a menu item that is not a link.');
addDefinition($dom,$defList,'$item','Fourth Argument. The string to use for the link in the navigation menu.');
addDefinition($dom,$defList,'$makeanchor','Optional Fifth Argument. Boolean. Set to false if you do not want the class to create an anchor element. For example, when the menu item points to an external resource, you would set this to false.');
$contentDiv->appendChild($defList);

$contentDiv->appendChild($defList);

$navMenu->addNavItem($contentDiv,'example','example','Example');
$xmlHeader $dom->createElement('h2','Example');
$contentDiv->appendChild($xmlHeader);

$xmlPar $dom->createElement('p','To see the functions and navMenu class in action:');
$contentDiv->appendChild($xmlPar);

$xmlBody->appendChild($contentDiv);

$codeDiv $dom->createElement('div');
$xmlBody->appendChild($codeDiv);
embedPHP($dom,$codeDiv,'README.phps','this_ource','phps_object','content');

$contentDiv $dom->createElement('div');
$contentDiv->setAttribute('id','contentThree');
$contentDiv->setAttribute('class','content');

$xmlPar $dom->createElement('p','To view the generated output of that code, use your web browsers page source functionality on this page.');
$contentDiv->appendChild($xmlPar);

// validator
if ($myPage->usexml == 1) {
   
$w3img='http://www.w3.org/Icons/valid-xhtml11-blue';
   } else {
   
$w3img='http://www.w3.org/Icons/valid-html401-blue';
   }
$w3cLink mkLink($dom,'http://validator.w3.org/check?uri=referer');
$ValidImage mkImage($dom,'',$w3img,'88','31','[W3C Valid]','','border: 0;');
$w3cLink->appendChild($ValidImage);
$xmlDiv $dom->createElement('div');
$xmlDiv->setAttribute('style','float: right; padding: 1em;');
$xmlDiv->appendChild($w3cLink);
$contentDiv->appendChild($xmlDiv);

$xmlBody->appendChild($contentDiv);
// make head section
$xmlHead $dom->createElement('head');
addCss($dom,$xmlHead,'/style.css');
addCss($dom,$xmlHead,'/highlight.css');
pageTitle($dom,$xmlHead,'DOM Functions');

// append head and body
$xmlHtml->appendChild($xmlHead);
$xmlHtml->appendChild($xmlBody);
// now serve it
$myPage->sendpage();
?>