Source for file xmenu-defs.php

Documentation is available at xmenu-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: xmenu-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for a Javascript-based multi-level menu. */
  24. /* The system creates a semi-static config file in a */
  25. /* dynamic manner and the javascript content is generated */
  26. /* from that. The static file (XmenuConfig.js) is only */
  27. /* rebuilt when either the stylesheet or the menu data in */
  28. /* the database is changed. The stylesheet should contain */
  29. /* .menu and .submenu classes as per the default Axyl */
  30. /* installation. */
  31. /* */
  32. /* ******************************************************************** */
  33. /** @package menu */
  34. include_once("menu-defs.php");
  35.  
  36. // ----------------------------------------------------------------------
  37. /**
  38. * The HV Menu Javascript variables file. This file is
  39. * dynamically generated by this class.
  40. * @access private
  41. */
  42. define("MENU_VARS_FILE", "XmenuConfig.js");
  43. /**
  44. * XMenu class
  45. * A Generic Javascript Menu. This class provides a multi-level menu
  46. * implemented in cross-browser Javascript. It should be compatible with
  47. * Netscape 4, Netscape 6, and IE 4+.
  48. * @package menu
  49. */
  50. class Xmenu extends RenderableObject {
  51. // Public
  52. /** Menu name eg: 'main' */
  53.  
  54. var $menu_name = "";
  55. /** Menu language */
  56.  
  57. var $language = 0;
  58. /** Name of stylesheet file to get menu styles from */
  59.  
  60. var $stylesheet = "";
  61.  
  62. // Private
  63. /** The menu instance
  64. @access private */
  65. var $menu;
  66. /** Unique database menu ID
  67. @access private */
  68. var $menu_id = 0;
  69. /** Path to menu variables file - theme aware
  70. @access private */
  71. var $xmenu_configfile_path = "";
  72. /** Whether this menu exists in the database
  73. @access private */
  74. var $exists = false;
  75. /** Home dir for Xmenu scripts
  76. @access private */
  77. var $xmenu_js = "";
  78. /** Home dir for Xmenu images
  79. @access private */
  80. var $xmenu_img = "";
  81. /** WWW Xmenu config URL - theme aware
  82. @access private */
  83. var $xmenu_configfile_url = "";
  84. /** Menu type from stylesheet: vertical, horizontal
  85. or collapsing.
  86. @access private */
  87. var $menu_type = "vertical";
  88. /** Menu image object: vertical arrow
  89. @access private */
  90. var $img_vert_arrow;
  91. /** Menu image object: horizontal arrow
  92. @access private */
  93. var $img_horiz_arrow;
  94. /** Menu image object: spacer
  95. @access private */
  96. var $img_spacer;
  97. /** Whether to force rebuild or not
  98. @access private */
  99. var $force_rebuild = false;
  100. /** Whether menu structure was rebuilt or not
  101. @access private */
  102. var $menu_structure_changed = false;
  103. /** Whether images were changed or not
  104. @access private */
  105. var $imgs_changed = false;
  106. // ....................................................................
  107. /**
  108. * Constructor
  109. * Create the Xmenu object.
  110. * @param string $menu_name Menu name
  111. * @param object $webpage Webpage object that this menu is being created for
  112. * @param string $stylsheet Name of stylesheet file to reference for menu styles
  113. * @param integer $lang Optional language variant of this menu (zero = default)
  114. */
  115. function Xmenu($menu_name="main", $webpage=false, $stylesheet="", $lang=-1) {
  116. global $RESPONSE, $LIBDIR;
  117. // Set menu name..
  118. $this->menu_name = $menu_name;
  119. // Set the menu language..
  120. if ($lang != -1) {
  121. $this->language = $lang;
  122. }
  123. elseif ($webpage !== false && $webpage->multilang && isset($webpage->languages[0])) {
  124. $this->language = $webpage->languages[0];
  125. }
  126. elseif (isset($RESPONSE) && $RESPONSE->multilang && isset($RESPONSE->languages[0])) {
  127. $this->language = $RESPONSE->languages[0];
  128. }
  129. // Check if we can use a menu stored in the session..
  130. // Manage selected menuoption..
  131. if (is_object($webpage)) {
  132. $this->session_id = $webpage->session_id;
  133. if ($webpage->session_record["menu_status"] != "") {
  134. debugbr("unserializing menu..");
  135. $menu = unserialize($webpage->session_record["menu_status"]);
  136. if (is_object($menu) && $menu->valid
  137. && ($menu->menu_name == $this->menu_name && $menu->language == $this->language)) {
  138. debugbr("installing pre-existing menu..");
  139. $this->menu = $menu;
  140. if ($this->menu->get_if_modified()) {
  141. debugbr("rebuilt modified menu..");
  142. $this->menu_structure_changed = true;
  143. $this->save_to_session();
  144. }
  145. }
  146. }
  147. }
  148. // Create it if it doesn't exist, re-create if required..
  149. if (!isset($this->menu)
  150. || (isset($cachecontrol) && $cachecontrol == "refresh")) {
  151. $this->menu = new menu_instance($this->menu_name, $this->language);
  152. $this->save_to_session();
  153. debugbr("xmenu: new menu generated", DBG_DEBUG);
  154. }
  155. // If valid, continue processing..
  156. if ($this->menu->valid) {
  157. $this->menu_id = $this->menu->menu_id;
  158. $this->exists = true;
  159. }
  160.  
  161. if ($webpage) {
  162. $this->stylesheet = $webpage->site_docroot . $webpage->head->stylesheet;
  163. global $CMDIR;
  164. // Paths etc..
  165. $this->xmenu_configfile_path = $webpage->site_docroot . "$CMDIR/" . $webpage->theme . "_" . MENU_VARS_FILE;
  166. $this->xmenu_js = "$LIBDIR/js/xmenu/lib/js";
  167. $this->xmenu_img = "$LIBDIR/js/xmenu/img";
  168.  
  169. // Menu images..
  170. $this->img_horiz_arrow = new img("$this->xmenu_img/arrow_horiz.gif", "", "", 3, 5);
  171. $this->img_vert_arrow = new img("$this->xmenu_img/arrow_vert.gif", "", "", 5, 3);
  172. $this->img_spacer = new img("$this->xmenu_img/spacer.gif", "", "", 1, 1);
  173. // If images are set in session menu, use those..
  174. if (isset($this->menu->img_horiz_arrow)) {
  175. $this->img_horiz_arrow = $this->menu->img_horiz_arrow;
  176. }
  177. if (isset($this->menu->img_vert_arrow)) {
  178. $this->img_vert_arrow = $this->menu->img_vert_arrow;
  179. }
  180. if (isset($this->menu->img_spacer)) {
  181. $this->img_spacer = $this->menu->img_spacer;
  182. }
  183.  
  184. // Menu configuration file out on disk..
  185. $this->xmenu_configfile_url = "$CMDIR/" . $webpage->theme . "_" . MENU_VARS_FILE;
  186.  
  187. // Insert menu javascript calls into webpage..
  188. $this->display_in_webpage($webpage);
  189. }
  190. // Over-ridden stylesheet to use..
  191. if ($stylesheet != "") {
  192. $this->stylesheet = $webpage->site_docroot . "/" . $stylesheet;
  193. }
  194. } // Xmenu
  195. // ....................................................................
  196. /**
  197. * Over-rides the standard icon images used to indicate submenus and
  198. * spaces. The values passed should be image objects as instances
  199. * of the 'img' class (@see img()).
  200. * @param object $img_horiz_arrow New image for 'horizontal arrow' icon
  201. * @param object $img_vert_arrow New image for 'vertical arrow' icon
  202. * @param object $img_spacer New image for 'spacer' icon
  203. */
  204. function set_menu_images($img_horiz_arrow=false, $img_vert_arrow=false, $img_spacer=false) {
  205. $imgs_changed = false;
  206. if ($img_horiz_arrow !== false && $this->img_horiz_arrow->src != $img_horiz_arrow->src) {
  207. $this->img_horiz_arrow = $img_horiz_arrow;
  208. $imgs_changed = true;
  209. }
  210. if ($img_vert_arrow !== false && $this->img_vert_arrow->src != $img_vert_arrow->src) {
  211. $this->img_vert_arrow = $img_vert_arrow;
  212. $imgs_changed = true;
  213. }
  214. if ($img_spacer !== false && $this->img_spacer->src != $img_spacer->src) {
  215. $this->img_spacer = $img_spacer;
  216. $imgs_changed = true;
  217. }
  218. if ($imgs_changed) {
  219. $this->imgs_changed = true;
  220. }
  221. } // set_menu_images
  222. // ....................................................................
  223. /**
  224. * Set the standard images up. This method just re-asserts that the
  225. * Xmenu should use the standard Xmenu images for arrows, spacer etc.
  226. */
  227. function set_default_images() {
  228. $this->set_menu_images(
  229. new img("$this->xmenu_img/arrow_horiz.gif", "", "", 3, 5),
  230. new img("$this->xmenu_img/arrow_vert.gif", "", "", 5, 3),
  231. new img("$this->xmenu_img/spacer.gif", "", "", 1, 1)
  232. );
  233. } // set_default_images
  234. // ....................................................................
  235. /**
  236. * This method saves the menu_instance to the user session for next
  237. * time. This gives the menu persistence.
  238. * @access private
  239. */
  240. function save_to_session() {
  241. $this->menu->img_horiz_arrow = $this->img_horiz_arrow;
  242. $this->menu->img_vert_arrow = $this->img_vert_arrow;
  243. $this->menu->img_spacer = $this->img_spacer;
  244. $up = new dbupdate("ax_wwwsession");
  245. $up->set("menu_status", serialize($this->menu));
  246. $up->where("session_id='$this->session_id'");
  247. $up->execute();
  248. } // save_to_session
  249. // ....................................................................
  250. /**
  251. * Requires build
  252. * Check if the database records containing the menu
  253. * have been modified since the last modification time
  254. * of the menu vars file. Returns true if so.
  255. * @return bool True if menu requires build (config has been changed)
  256. * @access private
  257. */
  258. function requires_build() {
  259. // First check existence and file timestamp of the
  260. // menu setup file that is used by the system..
  261. if (!file_exists($this->xmenu_configfile_path)) {
  262. debugbr("xmenu rebuild: config file absent", DBG_DEBUG);
  263. return true;
  264. }
  265. elseif ($this->menu_structure_changed) {
  266. debugbr("xmenu rebuild: menu structure changed", DBG_DEBUG);
  267. return true;
  268. }
  269. elseif ($this->imgs_changed) {
  270. debugbr("xmenu rebuild: images changed", DBG_DEBUG);
  271. return true;
  272. }
  273. elseif ($this->force_rebuild) {
  274. debugbr("xmenu rebuild: forced rebuild", DBG_DEBUG);
  275. return true;
  276. }
  277. clearstatcache();
  278. $mvarmod_ts = filemtime($this->xmenu_configfile_path);
  279. $mvarmod_dt = timestamp_to_datetime($mvarmod_ts);
  280. // If stylesheet file is provided, then check against
  281. // that also, since this influences things like fonts
  282. // and colours etc..
  283. if ($this->stylesheet != "") {
  284. $stylemod_ts = filemtime($this->stylesheet);
  285. if ($stylemod_ts > $mvarmod_ts) {
  286. debugbr("xmenu rebuild: stylesheet changed", DBG_DEBUG);
  287. return true;
  288. }
  289. }
  290. // If we got here, no need to build..
  291. return false;
  292. } // requires build
  293. // ....................................................................
  294. /**
  295. * Build menu config
  296. * Build the static menu config file which is used to set menu
  297. * look and feel, driven by the given stylesheet. This is a physical
  298. * file which gets (re-)built and saved to disk.
  299. * @access private
  300. */
  301. function build() {
  302. global $RESPONSE;
  303. global $LIBDIR;
  304. // Get fonts and colours etc. If this stylesheet is undefined or
  305. // doesn't exist on disk, then we should still be able to generate
  306. // the vars below, but will get the defaults in each case..
  307. $ss = new stylesheet($this->stylesheet);
  308. // Read in all the style settings..
  309. $this->menu_type = defaulted($ss->style("menu", "menu-type"), "vertical");
  310. $FontLowColor = defaulted($ss->style("menu", "color"), "#efefef");
  311. $LowBgColor = defaulted($ss->style("menu", "background-color"), "black");
  312. $FontHighColor = defaulted($ss->style("menu_highlight", "color"), "white");
  313. $HighBgColor = defaulted($ss->style("menu_highlight", "background-color"), "grey");
  314. $BorderColor = defaulted($ss->style("menu", "border-color"), "black");
  315. $MenuTextAlign = defaulted($ss->style("menu", "text-align"), "left");
  316. $MenuCentered = defaulted($ss->style("menu", "menu-align"), "left");
  317. $MenuVerticalCentered = defaulted($ss->style("menu", "menu-vertical-align"), "top");
  318. $FontFamily = defaulted($ss->style("menu", "font-family"), "arial");
  319. $ClickedColor = defaulted($ss->style("menu", "clicked-color"), "black");
  320. $ClickedBgColor = defaulted($ss->style("menu", "clicked-background-color"), "white");
  321. $FontSubLowColor = defaulted($ss->style("submenu", "color"), "#efefef");
  322. $LowSubBgColor = defaulted($ss->style("submenu", "background-color"), "black");
  323. $FontSubHighColor = defaulted($ss->style("submenu_highlight", "color"), "white");
  324. $HighSubBgColor = defaulted($ss->style("submenu_highlight", "background-color"), "grey");
  325. $BorderSubColor = defaulted($ss->style("submenu", "border-color"), "black");
  326. $ItemTextAlign = defaulted($ss->style("submenu", "border-color"), "black");
  327. $SubFontFamily = defaulted($ss->style("submenu", "font-family"), "arial");
  328.  
  329. // Elements with superfluous bits to be removed..
  330. $val = defaulted($ss->style("menu", "margin-top"), "0");
  331. $StartTop = str_replace("px", "", $val);
  332. $val = defaulted($ss->style("menu", "margin-left"), "0");
  333. $StartLeft = str_replace("px", "", $val);
  334. $val = defaulted($ss->style("menu", "padding-left"), "0");
  335. $LeftPadding = str_replace("px", "", $val);
  336. $val = defaulted($ss->style("menu", "padding-top"), "0");
  337. $TopPadding = str_replace("px", "", $val);
  338. $val = defaulted($ss->style("menu", "padding-right"), "0");
  339. $RightPadding = str_replace("px", "", $val);
  340. $val = defaulted($ss->style("menu", "padding-bottom"), "0");
  341. $BotPadding = str_replace("px", "", $val);
  342. $val = defaulted($ss->style("menu", "font-size"), "8");
  343. $FontSize = str_replace("pt", "", $val);
  344. $val = defaulted($ss->style("menu", "menu-disappear-delay"), "1");
  345. $DisappearDelay = str_replace("ms", "", $val);
  346. // Sanity check for milliseconds mode..
  347. if ($DisappearDelay >= 100) {
  348. $DisappearDelay = ceil($DisappearDelay / 1000);
  349. }
  350. $val = defaulted($ss->style("menu", "border-width"), "1");
  351. $BorderWidth = str_replace("px", "", $val);
  352. $val = defaulted($ss->style("menu", "item-spacing"), "0");
  353. $BorderBtwnElmnts = str_replace("px", "", $val);
  354. $val = defaulted($ss->style("menu", "menu-x-offset"), "0");
  355. $MenuXOffset = str_replace("px", "", $val);
  356. $val = defaulted($ss->style("menu", "menu-y-offset"), "0");
  357. $MenuYOffset = str_replace("px", "", $val);
  358. $val = defaulted($ss->style("submenu", "parent-overlap"), "0");
  359. $ParentOverlap = str_replace("px", "", $val);
  360. $val = defaulted($ss->style("submenu", "parent-vertical-overlap"), "0");
  361. $ParentVertOverlap = str_replace("px", "", $val);
  362. $val = defaulted($ss->style("submenu", "padding-left"), "0");
  363. $SubLeftPadding = str_replace("px", "", $val);
  364. $val = defaulted($ss->style("submenu", "padding-top"), "0");
  365. $SubTopPadding = str_replace("px", "", $val);
  366. $val = defaulted($ss->style("submenu", "padding-right"), "0");
  367. $SubRightPadding = str_replace("px", "", $val);
  368. $val = defaulted($ss->style("submenu", "padding-bottom"), "0");
  369. $SubBotPadding = str_replace("px", "", $val);
  370. $val = defaulted($ss->style("submenu", "font-size"), "8");
  371. $SubFontSize = str_replace("pt", "", $val);
  372.  
  373. // Integers, Logicals, et al..
  374. $val = defaulted($ss->style("menu", "font-weight"), "normal");
  375. $FontBold = ($val == "bold") ? "true" : "false";
  376.  
  377. $val = defaulted($ss->style("submenu", "font-weight"), "normal");
  378. $SubFontBold = ($val == "bold") ? "true" : "false";
  379.  
  380. $val = defaulted($ss->style("menu", "menu-unfold-onclick"), "no");
  381. $UnfoldOnClick = ($val == "yes") ? "true" : "false";
  382.  
  383. $val = defaulted($ss->style("menu", "show-arrows"), "yes");
  384. $ShowArrows = ($val == "yes") ? true : false;
  385.  
  386. // This can take values: 'url' or 'description'. It determines
  387. // what is shown in the browser status bar..
  388. $StatusContent = defaulted($ss->style("menu", "status-content"), "url");
  389.  
  390. $val = defaulted($ss->style("menu", "clicked-node-highlighted"), "no");
  391. $ClickedNodeHighlighted = ($val == "yes") ? "true" : "false";
  392.  
  393. $val = defaulted($ss->style("menu", "relative-positioned"), "no");
  394. $this->relative_positioned = ($val == "yes");
  395.  
  396. $val = defaulted($ss->style("menu", "menu-sticky-state"), "no");
  397. $StickyState = ($val == "yes") ? "true" : "false";
  398.  
  399. $val = defaulted($ss->style("menu", "menu-below"), "yes");
  400. $MenuBelow = ($val == "yes") ? "true" : "false";
  401.  
  402. $val = defaulted($ss->style("menu", "child-left-align"), "no");
  403. $ChildLeftAlign = ($val == "yes") ? "true" : "false";
  404.  
  405. $val = defaulted($ss->style("menu", "menu-fade-effect"), "no");
  406. $FadeEffect = ($val == "yes");
  407. if ($FadeEffect) {
  408. $FadeStart = defaulted($ss->style("menu", "menu-fade-start"), "0");
  409. $FadeStop = defaulted($ss->style("menu", "menu-fade-stop"), "100");
  410. $FadeSteps = defaulted($ss->style("menu", "menu-fade-steps"), "10");
  411. $FadeDelay = defaulted($ss->style("menu", "menu-fade-delay"), "100");
  412. }
  413.  
  414. // Write the variables file out..
  415. // Complete example of a menu configuration for a
  416. /*
  417. var pastaVertical = [
  418. // globals -----------------
  419. [ Xmenu.prototype.VERTICAL,
  420. 1, // delay in sec. before closing menu
  421. false, // onclick / onmouseover
  422. true, // horizontal & vertical menu: menu appears below/right of the root-node
  423. false, // horizontal menu: each hierarchy starts on same X
  424. false, // keep expansion state
  425. true, // highlight clicked nodes
  426. [ 20, 1 ], // XlayerParent width, height
  427. "img/spacer.gif" // spacer url
  428. ],
  429. // Menu level style 0..
  430. [
  431. [ "#ff4400", "#ffaaaa" ], // onclick-menu: color of clicked node
  432. // xlayer style:
  433. [
  434. // xOffset, yOffset, width, height,
  435. 0, 0, 100, 35,
  436. // fading:
  437. // [start_val, stop_val, steps, delay(ms)],
  438. [0, 100, 10, 100], // or null,
  439. // onmouseout:
  440. [
  441. // bgcolor, fgcolor, align,
  442. "#ff5500", "white", "center",
  443. // topPad, rightPad, bottomPad, leftPad,
  444. 10, 15, 0, 0,
  445. // bold, fontFace, fontSize,
  446. true, "Arial, Helvetica, sans serif", 1,
  447. // always_show_img, img_src, img_width, img_height, img_padding,
  448. false, "img/arrow_horiz.gif", 3, 5, 10
  449. ],
  450. // onmouseover:
  451. [
  452. // bgcolor, fgcolor, align,
  453. "#ff7c00", "#ffbbaa", "center",
  454. // topPad, rightPad, bottomPad, leftPad,
  455. 0, 0, 0, 10,
  456. // bold, fontFace, fontSize,
  457. true, "Arial, Helvetica, sans serif", 1,
  458. // img_src, img_width, img_height, img_padding,
  459. "img/spacer.gif", 1, 1, 0
  460. ]
  461. ]
  462. ]
  463. // Menu level style 1..
  464. [ ] .. etc.
  465. ]
  466. */
  467.  
  468. $newMV = new outputfile($this->xmenu_configfile_path);
  469. if ($newMV->opened) {
  470. $newMV->writeln("var menu_$this->menu_id = [");
  471. $newMV->writeln("// globals");
  472. $newMV->writeln("[ Xmenu.prototype." . strtoupper($this->menu_type) . ", // menu type");
  473. $newMV->writeln(" $DisappearDelay, // disappear delay (S)");
  474. $newMV->writeln(" $UnfoldOnClick, // unfolds onclick");
  475. $newMV->writeln(" $MenuBelow, // menu appears below root-node if true, else to the right");
  476. $newMV->writeln(" $ChildLeftAlign, // horizontal menus: each child left aligned with parent");
  477. $newMV->writeln(" $StickyState, // keep expansion state");
  478. $newMV->writeln(" $ClickedNodeHighlighted, // onclick menu: highlight clicked nodes");
  479. $newMV->writeln(" [20,1], // XlayerParent width,height");
  480. $newMV->writeln(" \"" . $this->img_spacer->src . "\" // spacer image url");
  481. $newMV->writeln("],");
  482.  
  483. $styles = array();
  484.  
  485. $s = "\"$ClickedColor\",\"$ClickedBgColor\"";
  486. $styles[] = "[$s]";
  487.  
  488. // Start Level 0 styling..
  489. $s = "";
  490. $s .= "$MenuXOffset,$MenuYOffset,"
  491. . $this->menu->level_widths[0] . ","
  492. . $this->menu->level_heights[0] . ",";
  493. // Fade effect
  494. $s .= ($FadeEffect) ? "[$FadeStart,$FadeStop,$FadeSteps,$FadeDelay]," : "null,";
  495. // On-mouseout
  496. $s .= "[";
  497. $s .= "\"$LowBgColor\",\"$FontLowColor\",\"$MenuTextAlign\",";
  498. $s .= "$TopPadding,$RightPadding,$BotPadding,$LeftPadding,";
  499. $s .= "$FontBold,\"$FontFamily\",$FontSize,";
  500. $s .= "false,";
  501. if ($ShowArrows) {
  502. if ($this->menu_type == "horizontal") {
  503. $s .= "\"" . $this->img_vert_arrow->src . "\",";
  504. $s .= $this->img_vert_arrow->width . "," . $this->img_vert_arrow->height . ",";
  505. }
  506. else {
  507. $s .= "\"" . $this->img_horiz_arrow->src . "\",";
  508. $s .= $this->img_horiz_arrow->width . "," . $this->img_horiz_arrow->height . ",";
  509. }
  510. $s .= "10],";
  511. }
  512. else {
  513. $s .= "null,0,0,0],";
  514. }
  515. // On-mouseover
  516. $s .= "[";
  517. $s .= "\"$HighBgColor\",\"$FontHighColor\",\"$MenuTextAlign\",";
  518. $s .= "$TopPadding,$RightPadding,$BotPadding,$LeftPadding,";
  519. $s .= "$FontBold,\"$FontFamily\",$FontSize,";
  520. $s .= "\"" . $this->img_spacer->src . "\",";
  521. $s .= $this->img_spacer->width . "," . $this->img_spacer->height . ",";
  522. $s .= "0],";
  523. // End Level 0 styling..
  524. $styles[] = "// level 0\n[$s]";
  525.  
  526. // Level 1..N styling all the same, currently..
  527. for ($level = 1; $level <= $this->menu->level_depth; $level++) {
  528. // Start Level N styling..
  529. $s = "";
  530. $ParentOverlap = -($ParentOverlap);
  531. $ParentVertOverlap = -($ParentVertOverlap);
  532. $s .= "$ParentOverlap,$ParentVertOverlap,"
  533. . $this->menu->level_widths[$level] . ","
  534. . $this->menu->level_heights[$level] . ",";
  535. // Fade effect
  536. $s .= ($FadeEffect) ? "[$FadeStart,$FadeStop,$FadeSteps,$FadeDelay]," : "null,";
  537. // On-mouseout
  538. $s .= "[";
  539. $s .= "\"$LowSubBgColor\",\"$FontSubLowColor\",\"$ItemTextAlign\",";
  540. $s .= "$TopPadding,$RightPadding,$BotPadding,$LeftPadding,";
  541. $s .= "$FontBold,\"$FontFamily\",$FontSize,";
  542. $s .= "false,";
  543. if ($ShowArrows) {
  544. if ($this->menu_type == "horizontal") {
  545. $s .= "\"" . $this->img_vert_arrow->src . "\",";
  546. $s .= $this->img_vert_arrow->width . "," . $this->img_vert_arrow->height . ",";
  547. }
  548. else {
  549. $s .= "\"" . $this->img_horiz_arrow->src . "\",";
  550. $s .= $this->img_horiz_arrow->width . "," . $this->img_horiz_arrow->height . ",";
  551. }
  552. $s .= "10],";
  553. }
  554. else {
  555. $s .= "null,0,0,0],";
  556. }
  557. // On-mouseover
  558. $s .= "[";
  559. $s .= "\"$HighBgColor\",\"$FontHighColor\",\"$MenuTextAlign\",";
  560. $s .= "$SubTopPadding,$SubRightPadding,$SubBotPadding,$SubLeftPadding,";
  561. $s .= "$SubFontBold,\"$SubFontFamily\",$SubFontSize,";
  562. $s .= "\"" . $this->img_spacer->src . "\",";
  563. $s .= $this->img_spacer->width . "," . $this->img_spacer->height . ",";
  564. $s .= "0],";
  565. // End Level N styling..
  566. $styles[] = "// level $level\n[$s]";
  567. } // for
  568. // End styles
  569.  
  570. $newMV->writeln("// styles");
  571. $newMV->writeln("[" . implode(",\n", $styles) . "],");
  572.  
  573. // Menu structure
  574. $newMV->writeln("// content");
  575. $newMV->writeln($this->menu_structure());
  576.  
  577. $newMV->writeln("];");
  578.  
  579. // Finish up..
  580. $newMV->closefile();
  581. } // newMV file opened
  582. } // build
  583. // ....................................................................
  584. /**
  585. * Menu structure
  586. * This function returns a set of Javascript array definitions which
  587. * should be put into the page which will be hosting the menu. Note
  588. * that this will be built for each user, since each user has a
  589. * unique auth_code which might be a part of the menu..
  590. * @return string Javascript var definitions for menu structure
  591. * @access private
  592. */
  593. function menu_structure() {
  594. global $RESPONSE;
  595. // MENU ITEM DETAIL..
  596. if ($this->menu->menuop_count() > 0) {
  597. // Store each row..
  598. $menuopts = array();
  599. foreach ($this->menu->menu_top as $item_no => $mopid) {
  600. $prefix = "$item_no";
  601. $this->Xmenu_entry($menuopts, $prefix, $mopid);
  602. } // foreach
  603. }
  604. return "[" . implode(",\n", $menuopts) . "]";
  605. } // menu_structure
  606. // ....................................................................
  607. /**
  608. * Recursively produce menu definition entries. These array
  609. * definitions define the menu structure in terms of the actual
  610. * menus and their sub-menus. This routine produces a single
  611. * menu-option definition, but will recursively call all child
  612. * (sub-menu) definitions.
  613. @param reference $menuopts Reference to an array of menuoptions
  614. @param string $mopid Menu option ID
  615. @access private
  616. */
  617. function Xmenu_entry(&$menuopts, $prefix, $mopid) {
  618. // Store current menu option..
  619. $mop = $this->menu->menuop($mopid);
  620. if ($mop !== false) {
  621. $details = $mop->details();
  622. $menu_level = $mop->menu_level;
  623. $label = $mop->label;
  624. if ($label == MENU_ITEM_SPACER) {
  625. $label = "&nbsp;";
  626. }
  627. if ($label == MENU_ITEM_SEPARATOR) {
  628. switch ($this->menu_type) {
  629. case "vertical":
  630. case "collapsing":
  631. $label = "<hr width='" . $this->menu->level_widths[$menu_level] . "' noshade>";
  632. break;
  633. } // switch
  634. }
  635. $action = $mop->action;
  636. $expanded = $mop->expanded;
  637. $auth_code = $mop->auth_code;
  638. $heading = $mop->is_submenuheading(); // Whether it is a heading for sub-menu
  639. $pseudo = $mop->is_pseudo(); // Whether it is a pseudo menu-item
  640. $menuoption = !$heading;
  641.  
  642. // Current menu option..
  643. if ($action != "" && !$pseudo) {
  644. if ($authcode == "t") {
  645. $action = href_addparm($action, "auth_code", $RESPONSE->get_auth_code());
  646. }
  647. $action = "new WinTarget(\"$action\")";
  648. }
  649. else {
  650. $action = "null";
  651. }
  652. // Make menu entry..
  653. $menuopts[] = "[\"$label\",$action,$menu_level]";
  654.  
  655. // Process children..
  656. if (isset($mop->children) && $mop->children != "") {
  657. $childoptions = explode("|", $mop->children);
  658. $childcount = count($childoptions);
  659. $pfxcount = 1;
  660. foreach ($childoptions as $childmopid) {
  661. $childprefix = $prefix . "|" . $pfxcount;
  662. $this->Xmenu_entry($menuopts, $childprefix, $childmopid);
  663. $pfxcount += 1;
  664. }
  665. }
  666. }
  667. } // Xmenu_entry
  668. // ....................................................................
  669. /**
  670. * Display in webpage
  671. * Inserts the javascript necessary to embed the menu into a given webpage.
  672. * NB: Normally the webpage passed in here is $RESPONSE.
  673. * @param object $webpage Webpage object that this menu is being created for
  674. */
  675. function display_in_webpage($webpage) {
  676. global $LIBDIR;
  677. $webpage->head->add_scriptsrc("$this->xmenu_js/Browser.js");
  678. $webpage->head->add_scriptsrc("$this->xmenu_js/XlayerParent.js");
  679. $webpage->head->add_scriptsrc("$this->xmenu_js/Xlayer.js");
  680. $webpage->head->add_scriptsrc("$this->xmenu_js/Xmenu.js");
  681. $webpage->head->add_scriptsrc("$this->xmenu_js/Xmenus.js");
  682. $webpage->head->add_scriptsrc("$this->xmenu_js/XmenuConfig.js");
  683. $webpage->head->add_scriptsrc($this->xmenu_configfile_url);
  684. $webpage->head->add_scriptsrc("$this->xmenu_js/Debug.js");
  685. $webpage->head->add_script(
  686. "var menus=new Xmenus('','');\n"
  687. . "function initXmenu() {\n"
  688. . " menus.create();\n"
  689. . " debug.flushBuffer();\n"
  690. . "}\n"
  691. );
  692. $webpage->set_onload("initXmenu()");
  693. //$webpage->body->set_parms(" onResize=\"window.location.reload()\"");
  694. } // display_in_webpage
  695. // ....................................................................
  696. /**
  697. * This renders the field as HTML.
  698. * Inserts the HTML DIV tag which the HVmenu will use to position
  699. * itself to. The name of the DIV is taken from the unique menu ID,
  700. * and corresponds to the TargetLoc variable defined above..
  701. * @return string The menu anchor point (DIV) as HTML.
  702. */
  703. function html() {
  704. // Always build menu variables file if required..
  705. if ($this->requires_build()) {
  706. // Build static menu configuration file..
  707. $this->build();
  708. // Save menu object to session..
  709. $this->save_to_session();
  710. }
  711. $js = "<script language=\"javascript\">";
  712. $js .= "menus.add( menu_$this->menu_id );";
  713. $js .= "</script>";
  714. return $js;
  715. } // html
  716.  
  717. } // Xmenu class
  718. // ----------------------------------------------------------------------
  719.  
  720. ?>

Documentation generated by phpDocumentor 1.3.0RC3