layersmenu-process.inc.php 4.9 KB

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