PHP Classes
Icontem

File: class/xmlmenuhasdom.cls.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  >  class/xmlmenuhasdom.cls.php  
File: class/xmlmenuhasdom.cls.php
Role: Class source
Content type: text/plain
Description: xml menu class when only DOMDocument is enabled
Class: XML to HTML menu
Generate menus in XML and HTML
 

Contents

Class file image Download
<?php
/**
* class xmlmenuhasdom
* DOMDocument is enabled, XSLTProcessor is not
*
* @author: johan <barbier_johan@hotmail.com>
*/
class xmlmenuhasdom extends abstractxmlmenu {

    
/**
    * public function __construct
    * constructor
    * @Param (string) sVersion : xml version
    * @Param (string) sEncoding : xml encoding
    */

    
public function __construct ($sVersion null$sEncodingnull) {
        
$this -> doc = new DOMDocument ($sVersion$sEncoding);
        
$root $this -> doc -> createElement ('menu');
        
$this -> root $this -> doc -> appendChild ($root);
        
parent::__construct ($sVersion$sEncoding);
    }

    
/**
    * public function htmlToFile
    * method to save the html to a file.
    * cannot be done if XSLTProcessor is not enabled (see comments in the xmlmenu::toHTML () method to learn how to save the HTML file)
    * @Param (string) sFileName :filename
    */
    
public function htmlToFile ($sFileName) {
        return 
false;
    }

    
/**
    * public function toHTML
    * method to transform the xml to html
    * @Param (string) sType : XSL file to be used
    * @Return (string) sHtml : transformed HTML string
    */
    
public function toHTML ($sType) {
        if (
false === ( $type array_search($sType$this -> aTypes))) {
            return 
false;
        }
        
/**
        * Difficult bit here that needs a bit of explanation
        * We do not have XSLTProcessor availaible.
        * So, we cannot use it to apply the stylesheet.
        * What we do is :
        * we take the generated xml.
        * We add a stylesheet import by parsing the text.
        * we save it to a temporary folder
        * we return only a link to the newly created file.
        * now, to have the html version of the xml , user will need to save it via his web browser...
        */
        
$sXsl '<?xml-stylesheet type="text/xsl" href="../xsl/'.$type.'"?>';
        
$this -> sHtml $this -> doc ->  saveXML ();
        
$iPos strpos ($this -> sHtml'?>');
        
$this -> sHtml substr_replace ($this -> sHtml$sXsl$iPos 20);
        
$iCpt count (scandir ('tmp_xml'));
        
$fp fopen ('tmp_xml/tmp_xmllfile_'.$iCpt.'.xml''w+');
        
fwrite ($fp$this -> sHtml);
        
fclose ($fp);
        
$this -> sHtml '<a href="tmp_xml/tmp_xmllfile_'.$iCpt.'.xml" title="Cliquer pour voir le html généré" target="_blank">Cliquer pour voir le html généré</a>';

        return 
$this -> sHtml;
    }
}
?>

 
  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