PHPLayersMenu
[ class tree: PHPLayersMenu ] [ index: PHPLayersMenu ] [ all elements ]

Source for file layersmenu-process.inc.php

Documentation is available at layersmenu-process.inc.php

  1. <?php
  2. // PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/
  3.  
  4. /**
  5. * This file contains the code of the ProcessLayersMenu class.
  6. @package PHPLayersMenu
  7. */
  8.  
  9. /**
  10. * This is an extension of the "common" class of the PHP Layers Menu library.
  11. *
  12. * It provides methods useful to process/convert menus data, e.g. to output a menu structure and a DB SQL dump corresponding to already parsed data and hence also to convert a menu structure file to a DB SQL dump and viceversa
  13. *
  14. @version 3.2.0-rc
  15. @package PHPLayersMenu
  16. */
  17. {
  18.  
  19. /**
  20. * The constructor method
  21. @return void 
  22. */
  23. function ProcessLayersMenu()
  24. {
  25.     $this->LayersMenuCommon();
  26. }
  27.  
  28. /**
  29. * The method to set the dirroot directory
  30. @access public
  31. @return boolean 
  32. */
  33. function setDirroot($dirroot)
  34. {
  35.     return $this->setDirrootCommon($dirroot);
  36. }
  37.  
  38. /**
  39. * Method to output a menu structure corresponding to items of a menu
  40. @access public
  41. @param string $menu_name the name of the menu for which a menu structure
  42. *    has to be returned
  43. @param string $separator the character used in the menu structure format
  44. *    to separate fields of each item
  45. @return string 
  46. */
  47. function getMenuStructure(
  48.     $menu_name '',    // non consistent default...
  49.     $separator '|'
  50.     )
  51. {
  52.     $menuStructure '';
  53.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the menu
  54.         $menuStructure .= str_repeat('.'$this->tree[$cnt]['level']);
  55.         $menuStructure .= $separator;
  56.         $menuStructure .= $this->tree[$cnt]['text'];
  57.         $menuStructure .= $separator;
  58.         $menuStructure .= $this->tree[$cnt]['href'];
  59.         $menuStructure .= $separator;
  60.         $menuStructure .= $this->tree[$cnt]['title'];
  61.         $menuStructure .= $separator;
  62.         $menuStructure .= $this->tree[$cnt]['icon'];
  63.         $menuStructure .= $separator;
  64.         $menuStructure .= $this->tree[$cnt]['target'];
  65.         $menuStructure .= $separator;
  66.         $menuStructure .= $this->tree[$cnt]['expanded'];
  67.         $menuStructure .= "\n";
  68.     }
  69.     return $menuStructure;
  70. }
  71.  
  72. /**
  73. * Method to output a DB SQL dump corresponding to items of a menu
  74. @access public
  75. @param string $menu_name the name of the menu for which a DB SQL dump
  76. *    has to be returned
  77. @param string $db_type the type of DB to dump for;
  78. *    leave it either empty or not specified if you are using PHP < 5,
  79. *    as sqlite_escape_string() has been added in PHP 5;
  80. *    it has to be specified and set to 'sqlite' only if the dump
  81. *    has to be prepared for SQLite; it is not significant if != 'sqlite'
  82. @return string 
  83. */
  84. function getSQLDump(
  85.     $menu_name '',    // non consistent default...
  86.     $db_type ''
  87.     )
  88. {
  89.     $SQLDump '';
  90.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the menu
  91.         $current_node[$this->tree[$cnt]['level']] $cnt;
  92.         if (!$this->tree[$cnt]['child_of_root_node']{
  93.             $this->tree[$cnt]['father_node'$current_node[$this->tree[$cnt]['level']-1];
  94.         }
  95.         $VALUES '';
  96.         $SQLDump .= 'INSERT INTO ';
  97.         $SQLDump .= $this->tableName;
  98.         $SQLDump .= ' (';
  99.         $SQLDump .= $this->tableFields['id'', ';
  100.         $VALUES .= "'" 10*$cnt "', ";
  101.         $SQLDump .= $this->tableFields['parent_id'', ';
  102.         if (isset($this->tree[$cnt]['father_node']&& $this->tree[$cnt]['father_node'!= 0{
  103.             $VALUES .= "'" 10*$this->tree[$cnt]['father_node'"', ";
  104.         else {
  105.             $VALUES .= "'1', ";
  106.         }
  107.         $SQLDump .= $this->tableFields['text'', ';
  108.         $foobar $this->tree[$cnt]['text'];
  109.         if ($foobar != ''{
  110.             if ($db_type != 'sqlite'{
  111.                 $foobar addslashes($foobar);
  112.             else {
  113.                 $foobar sqlite_escape_string($foobar);
  114.             }
  115.         }
  116.         $VALUES .= "'$foobar', ";
  117.         $SQLDump .= $this->tableFields['href'', ';
  118.         $VALUES .= "'" $this->tree[$cnt]['href'"', ";
  119.         if ($this->tableFields['title'!= "''"{
  120.             $SQLDump .= $this->tableFields['title'', ';
  121.             $foobar $this->tree[$cnt]['title'];
  122.             if ($foobar != ''{
  123.                 if ($db_type != 'sqlite'{
  124.                     $foobar addslashes($foobar);
  125.                 else {
  126.                     $foobar sqlite_escape_string($foobar);
  127.                 }
  128.             }
  129.             $VALUES .= "'$foobar', ";
  130.         }
  131.         if ($this->tableFields['icon'!= "''"{
  132.             $SQLDump .= $this->tableFields['icon'', ';
  133.             $VALUES .= "'" $this->tree[$cnt]['icon'"', ";
  134.         }
  135.         if ($this->tableFields['target'!= "''"{
  136.             $SQLDump .= $this->tableFields['target'', ';
  137.             $VALUES .= "'" $this->tree[$cnt]['target'"', ";
  138.         }
  139.         if ($this->tableFields['orderfield'!= "''"{
  140.             $SQLDump .= $this->tableFields['orderfield'', ';
  141.             $VALUES .= "'" 10*$cnt "', ";
  142.         }
  143.         if ($this->tableFields['expanded'!= "''"{
  144.             $SQLDump .= $this->tableFields['expanded'', ';
  145.             $this->tree[$cnt]['expanded'= (int) $this->tree[$cnt]['expanded'];
  146.             $VALUES .= "'" $this->tree[$cnt]['expanded'"', ";
  147.         }
  148.         $SQLDump substr($SQLDump0-2);
  149.         $VALUES substr($VALUES0-2);
  150.         $SQLDump .= ") VALUES ($VALUES);\n";
  151.     }
  152.     return $SQLDump;
  153. }
  154.  
  155. /* END OF CLASS */
  156.  
  157. ?>

Documentation generated on Fri, 18 Jul 2008 21:47:22 +0200 by phpDocumentor 1.4.1