PHP Classes
Icontem

File: index.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Johan Barbier  >  XML to HTML menu  >  index.php  
File: index.php
Role: Example script
Content type: text/plain
Description: index pâge
Class: XML to HTML menu
Generate menus in XML and HTML
 

Contents

Class file image Download
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
    <link rel="stylesheet" type="text/css" href="css/maindoc.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
<?php
require_once 'class/xmlmenu.cls.php';
require_once 
'class/abstractxmlmenu.cls.php';
/**
* instanciations and initializations
*/
$menu xmlmenu::getInstance ('1.0''iso-8859-1'); // the objet
$aIndex = array (); // array of indexes
$aAttr = array ( // array of styles
    
'style' => 'color:#ff0000;'
    
);

$project xmlmenu::getInstance ('1.0''iso-8859-1');
$aIndexProject = array ();
$iInd=$project->defineNode('project 1',$aAttr);
$aIndexProject[$iInd] = $iInd;

$iInd $project -> defineNode ('Task 1',$aAttr ,$aIndexProject[$iInd]);
$aIndexProject[$iInd] = $iInd;
$iInd $project -> defineNode ('Task 2',$aAttr ,$aIndexProject[$iInd]);
$aIndexProject[$iInd] = $iInd;

$iInd $project->defineNode('project 2',$aAttr);
$aIndexProject[$iInd] = $iInd;

$iInd $project -> defineNode ('Task 1',$aAttr ,$aIndexProject[$iInd]);
$aIndexProject[$iInd] = $iInd;


$iInd $project -> defineNode ('Task 2',$aAttr ,$aIndexProject[$iInd]);
$aIndexProject[$iInd] = $iInd;

echo 
$project -> toHTML ('LISTE');

$iInd $menu -> defineNode ('menu 1'$aAttr); // let's define a node
$aIndex[$iInd] = $iInd// we store the created node's id
$menu -> defineLink ('#'$aIndex[1]); // let's define a link for the new node
$iInd $menu -> defineNode ('menu 2'$aAttr); // let's define another node
$aIndex[$iInd] = $iInd;
$iInd $menu -> defineNode ('menu 1_1', array ('style' => 'color:#000000;'), $aIndex[1]); // let's define a child node for node 1, with some other attributes.
$aIndex[$iInd] = $iInd;
$menu -> defineAttributes (array ('attrNameTest' => 'attrValueTest'),2); // here, we test the public method xmlmenu::defineAttributes
echo $menu// let's see the generated xml

echo '<br /><br />';

echo 
$menu -> toHTML ('LISTE'); // let's transform it to an HTML list
$menu -> xmlToFile ('menu1'); // let's save the xml menu
$menu -> htmlToFile ('menu1'); // let's save the html menu

/**
* same player shoot again...but using another XSL transformation  type.
*/

$menu xmlmenu::getInstance ('1.0''iso-8859-1');

$aIndex = array ();
$aAttr = array (
    
'style' => 'background-color: #ffcc33; border: 1px solid #000000;'
    
);
$iInd $menu -> defineNode ('menu 1'$aAttr);
$aIndex[$iInd] = $iInd;
$iInd $menu -> defineNode ('menu 2'$aAttr);
$aIndex[$iInd] = $iInd;
$menu -> defineLink ('#'$aIndex[2]);
$iInd $menu -> defineNode ('menu 1_1', array ('style' => 'background-color:#ff00cc;border: 1px solid #000000;'), $aIndex[1]);
$aIndex[$iInd] = $iInd;
$iInd $menu -> defineNode ('menu 1_2', array ('style' => 'background-color:#ff00cc;border: 1px solid #000000;'), $aIndex[1]);
$aIndex[$iInd] = $iInd;
echo 
$menu;

echo 
'<br /><br />';
echo 
$menu -> toHTML ('TABLE'); // here we are : an html table
$menu -> xmlToFile ('menu2');
$menu -> htmlToFile ('menu2');

/**
* last example, simulating a DB extraction...
*/
$aMenu = array (
    
'menu 1' => array (
        
'ATTR' => array (
            
'link' => '#',
            
'style' => 'background-color: #ffcc33; width: 80px;'
            
),
        
'CHILDREN' => array (
            
'menu 1_1' =>     array (
                
'ATTR' => array (
                    
'link' => '#',
                    
'style' => 'background-color: #ccff33;width: 80px;'
                    
)
                ),
            
'menu 1_2' =>     array (
                
'ATTR' => array (
                    
'link' => '#',
                    
'style' => 'background-color: #00ffcc;width: 80px;'
                    
)
                )
            )
        ),
    
'menu 2' => array (
        
'ATTR' => array (
            
'link' => '#',
            
'style' => 'background-color: #ff33cc;width: 80px;'
            
),
        
'CHILREN' => array (
            )
        )
    );
$menu xmlmenu::getInstance ('1.0''iso-8859-1');

foreach (
$aMenu as $parentName => $parent) {
    
$iInd $menu -> defineNode ($parentName$parent['ATTR']);
    
$aIndex[$iInd] = $iInd;
    if (!empty (
$parent['CHILDREN'])) {
        foreach (
$parent['CHILDREN'] as $childName => $child) {
            
$iNewInd $menu -> defineNode ($childName$child['ATTR'], $aIndex[$iInd]);
            
$aIndex[$iNewInd] = $iNewInd;
        }
    }
}

echo 
$menu// let's see the generated xml

echo '<br /><br />';

echo 
$menu -> toHTML ('LISTE'); // let's transform it to an HTML list
$menu -> xmlToFile ('menu3'); // let's save the xml menu
$menu -> htmlToFile ('menu3'); // let's save the html menu
?>
    </body>
</html>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products