Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Anthony Rogers  >  XMLnav  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Documentation & example
Class: XMLnav
Creates a menu bar from a definition in XML
Author: By
Last change: Changes to version numbering
Date: 6 years ago
Size: 10,439 bytes
 

Contents

Class file image Download
<?php
require("xmlmenu_class.php");

/*--------------------------------------------------------------------------------------*\
 * Copyright (C) 2004-2005 Anthony K Rogers roggyadres@hotmail.com			* 
 *											* 
 * This file is part of XMLmenu. It gives a quick example of how it is implemented	* 
 *											* 
 * version 1.0										* 
 * copyright 2004									* 
\*--------------------------------------------------------------------------------------*/

?>
<html>
<head>
<title><?php
if( isset($_GET["menuname"]) ) $menuname = $_GET["menuname"];
if( isset($_GET["item"]) ) $item = $_GET["item"];

if(! isset($menuname) ) $loc = "Home";
if( isset($menuname) ){
 if( isset($_GET[$menuname]) ) $menuitem = $_GET[$menuname];

 switch($menuname){
  case "home": $loc = "Home"; break;
  case "about": $loc = "About"; break;
  case "how": $loc = "How to Use"; break;
  case "future": $loc = "Future Developments"; break;
 }

 if( isset($menuitem) ){
  if( $menuname == "how" ){
   switch($menuitem){
    case "1": $loc .= " > Step 1"; break;
    case "2": $loc .= " > Step 2"; break;
    case "3": $loc .= " > Step 3"; break;
    case "4": $loc .= " > Step 4"; break;
   }
  }
 }
}

print $loc;
?></title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th colspan="2"><h1>XMLmenu</h1></th>
</tr><tr><td colspan="2" height="5"><hr width="85%" /></td></tr><tr>
<td width="180" valign="top"><?php
//Generate the menu...
$QueryVars = $_GET;
$XMLmenu = new XMLmenu("test.xml", $QueryVars);
$XMLmenu->Generate();
?></td>
<td valign="top"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th><h2><?php print $loc; ?></h2></th>
</tr><tr><td height="5"><hr width="70%" /></td></tr><tr>
<td valign="top"><?php

if(! isset($menuname) || $menuname == "home" ){
 print "<b>Welcome</b> This is my first PHP class, and I am proud of it!";
 print "\n<p><b>XMLmenu</b> uses an xml page to build a navigation bar.\n<br />The menu items grow and shrink according to the page you are viewing.";
 print "\n</p>On the left of this page shows what XMLmenu can do.\n<br />Try it out!\n<p><br /><b>Roganty</b></p>\n";
}else
if( isset($menuname) && $menuname == "about" ){

  print "<b>I</b> am 20 years old, living in Bristol (UK)\n";
  print "<br />I started learning PHP November 2003 and this is my first try at builing a PHP Class\n";
  print "<p>Read through the <a href=\"develop.php?menuname=develop\">Development</a> section on the developmental stages.\n";
  print "</td>\n</tr><tr><td height=\"5\"><hr width=\"75%\" /></td></tr><tr>\n<td valign=\"top\">";
  print "\n<br /><b>Copyright: </b> Copyright (C) 2004-2005 Anthony Rogers";
  print "\n<br /><b>Author: </b> Roganty <a href=\"mailto:" .urlencode('roggyadres@hotmail.com'). "\">roggyadres@hotmail.com</a>";
  print "\n<br /><b>Website: </b><a href=\"http://www.roganty.co.uk/\" target=\"_blank\">http://www.roganty.co.uk/</a></p>";
  print "\n<p>XMLmenu uses the same functions to read the xml file as TreeMenu";
  print "\n<br /><b>Author: </b>Carlos Falo Hervás <a href=\"mailto:" .urlencode('carles@bisinteractive.net'). "\">carles@bisinteractive.net</a>";
  print "\n<br /><b>Website: </b><a href=\"http://www.bisinteractive.net\" target=\"_blank\">http://www.bisinteractive.net</a></p>\n";

}else
if( isset($menuname) && $menuname == "how" ){
 echo('<center><table border="0" width="90%">
<tr><th colspan="8">Development Stages</th></tr><tr>
<td width="20"><img src="images/burst.gif" width="20" height="20" /></td><td><a href="index.php?menuname=how&how=1">Step 1</a></td>
<td width="20"><img src="images/burst.gif" width="20" height="20" /></td><td><a href="index.php?menuname=how&how=2">Step 2</a></td>
<td width="20"><img src="images/burst.gif" width="20" height="20" /></td><td><a href="index.php?menuname=how&how=3">Step 3</a></td>
<td width="20"><img src="images/burst.gif" width="20" height="20" /></td><td><a href="index.php?menuname=how&how=4">Step 4</a></td>
</tr></table></center></td></tr><tr><td><hr width="70%" /></td></tr><tr>
<td valign="top">');
 if( isset($menuitem) ){
  switch($menuitem){
   case "1": print "<b><u>Create Your Own XML File</u></b><ol>";
    print "\n<li>Don't forget to include the line: <tt>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?> on the very first line</tt></li>";
    print "\n<li>Don't forget to include the <tt>&lt;menuBar></tt> tag as the root element.<ul type=\"square\">";
     print "\n<li>You must include the <tt>baseUrl</tt> attribute</li>";
     print "\n<li>You must also include the attributes that point to the nav.xsd file within the <tt>&lt;menubar></tt> tag.\n<br /><tt>xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"nav.xsd\"</tt></li></ul></li>";
    print "\n<li>Don't forget to include the <tt>name</tt> and <tt>level</tt> attributes in <i>all</i> the tags, except the <tt>&lt;menuBar></tt> tag</li>";
    print "\n<li>Make sure that the value for the <tt>level</tt> attribute is either 1, 2 or 3, depending on which menu it is in. if it is not correct the item, or menu, will not be displayed properly</li>";
    print "\n<li>You can only have a <tt>&lt;menu></tt> tag at either level 1 or 2.</li>";
    print "\n<li>You can have an <tt>&lt;item></tt>, <tt>&lt;link></tt> or <tt>&lt;email></tt> tag at any level.</li>";
    print "\n<li>Don't forget to include the <tt>menuname</tt> attribute in all level 1 <tt>&lt;menu></tt> tags. The value can be any word, don't include spaces, and it must be unique</li>";
    print "\n<li>Don't forget to include the <tt>item</tt> attribute in all level 2 <tt>&lt;menu></tt> tags. The value can be any word, don't include spaces, and it must be unique</li>";
    print "\n<li>Don't forget to include the <tt>menuname</tt> attribute in all level 2 <tt>&lt;item></tt> tags. The value can be any word, don't include spaces, and it must be unique</li>";
    print "\n<li>Don't forget to include the <tt>item</tt> attribute in all level 3 <tt>&lt;item></tt> tags. The value can be any word, don't include spaces, and it must be unique</li>";
    print "\n<li>If a level 1 <tt>&lt;item></tt> tag dosen't include the <tt>url</tt> attribute, add the <tt>menuname</tt> attribute instead</li>";
    print "\n<li>The <tt>url</tt> attribute dosen't need to be included if the <tt>&lt;menuBar></tt> tag includes the <tt>basePage</tt> attribute</li>";
    print "\n<li>An item within a menu dosen't need to have the <tt>url</tt> attribute included if the <tt>&lt;menu></tt> tag includes a <tt>url</tt> attribute</li>";
    print "\n<li>Use the included xml file <a href=\"test.xml\" target=\"_blank\">(test.xml)</a> as a template to work from</li>";
    print "\n</ol>"; break;
   case "2": print "<b><u>Add The Code To Your Page</u></b><ol>";
    print "\n<li>Add the line: <tt>&lt;?php require(\"xmlmenu_class.php\"); ?></tt> to the top of all the pages you want XMLmenu to appear</li>";
    print "\n<li>Add the lines:<pre>&lt;?php
//Generate the menu...
\$QueryVars = \$_GET;
\$XMLmenu = new XMLmenu(\"<i>name_of_your_xml_file</i>\", \$QueryVars);
//This is where the custom images would be defined
\$XMLmenu->Generate();
?></pre>\nto where you want the menu to appear</li>";
    print "\n<li>If you want to change the images for the menu include these lines:<pre>\$XMLmenu->menuIMG(21, 21); //the image dimensions
\$XMLmenu->fileIMG(\"images/item.gif\"); //a file image
\$XMLmenu->folderIMG(\"images/menu.gif\", \"images/menu_open.gif\"); //closed and open folder image
\$XMLmenu->linkIMG(\"images/extern.gif\"); //external link image
\$XMLmenu->emailIMG(\"images/eMail.gif\"); //email link image</pre>\nOn the line where it says <tt>This is where the custom images would be defined</tt></li>";
    print "\n<li>Test that everything works</li>";
    print "\n</ol>"; break;
   case "3": print "<b><u>Upload Files</u></b><ol>";
    print "\n<li>Up load the following files to the root folder on your server<ul type=\"square\">";
     print "\n<li>All of the files that are going to include XMLmenu</li>";
     print "\n<li>Your xml file</li>";
     print "\n<li>nav.xsd</li>";
     print "\n<li>xmlmenu_class.xsd</li></ul></li>";
    print "\n<li>Up load the following files to the images folder on your server<ul type=\"square\">";
     print "\n<li>email.gif <i>or</i> the image your are going to use instead</li>";
     print "\n<li>file.gif <i>or</i> the image your are going to use instead</li>";
     print "\n<li>folder.gif <i>or</i> the image your are going to use instead</li>";
     print "\n<li>folder.open.gif <i>or</i> the image your are going to use instead</li>";
     print "\n<li>link.gif <i>or</i> the image your are going to use instead</li></ul></li>";
    print "\n</ol>"; break;
   case "4": print "<b><u>Thats It!</u></b><ol>";
    print "\n<li>Contact Me If:<ul type=\"square\">";
     print "\n<li>You are using XMLmenu</li>";
     print "\n<li>You like it</li>";
     print "\n<li>You find any bugs</li>";
     print "\n<li>You have improved it</li>";
     print "\n<li>You think that something else should be added</li>";
     print "\n<li>You have any comments</li></ul></li>";
    print "\n<li>To contact me use the link in the menu or <a href=\"mailto:" .urlencode('roggyadres@hotmail.com'). "\">Click Here</a></li>";
    print "\n<li>If you do use XMLmenu, please provide a link to my homepage at <a href=\"http://www.roganty.co.uk\" target=\"_blank\">http://www.roganty.co.uk</a></li>";
    print "\n</ol>"; break;
  }
 }else
 if(! isset($menuitem) ){
  print "<b>In</b> this section you can find the steps on how to implement XMLmenu on to your website";
 }
}else
if( isset($menuname) && $menuname == "future" ){
 print "Here is a list of possible furure developments I am think of adding:<ol>";
 print "\n<li>Bookmark able items within menus, or sub-menus could link to a book mark on the same page.</li>";
 print "\n<li>Instead of printing each row to the page as the tag is read, store the details into an array, and after the xml document has been read, then print out the menu.";
 print "\n<br />This would stop half of a menu being printed if an error occurs, instead no menu would be printed.</li>";
 print "\n</ol>";
}


?></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>