FOSSology  4.4.0
Open Source License Compliance by Open Source Software
core-debug-menus.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 define("TITLE_core_debug_menus", _("Debug Menus"));
9 
15 {
16  function __construct()
17  {
18  $this->Name = "debug-menus";
19  $this->Title = TITLE_core_debug_menus;
20  $this->MenuList = "Help::Debug::Debug Menus";
21  $this->DBaccess = PLUGIN_DB_ADMIN;
22  parent::__construct();
23  }
24 
31  function PostInitialize()
32  {
33  if ($this->State != PLUGIN_STATE_VALID) {
34  return(0);
35  }
36  // Make sure dependencies are met
37  foreach($this->Dependency as $key => $val)
38  {
39  $id = plugin_find_id($val);
40  if ($id < 0) {
41  $this->Destroy(); return(0);
42  }
43  }
44 
45  $FullMenuDebug = GetParm("fullmenu",PARM_INTEGER);
46  if ($FullMenuDebug == 2)
47  {
48  $_SESSION['fullmenudebug'] = 1;
49  }
50  if ($FullMenuDebug == 1)
51  {
52  $_SESSION['fullmenudebug'] = 0;
53  }
54 
55  // It worked, so mark this plugin as ready.
56  $this->State = PLUGIN_STATE_READY;
57  // Add this plugin to the menu
58  if ($this->MenuList !== "")
59  {
60  menu_insert("Main::" . $this->MenuList,$this->MenuOrder,$this->Name,$this->MenuTarget);
61  }
62  return(1);
63  } // PostInitialize()
64 
71  function Menu2HTML(&$Menu)
72  {
73  $V = "<ol>\n";
74  foreach($Menu as $M)
75  {
76  $V .= "<li>" . htmlentities($M->Name);
77  $V .= " (" . htmlentities($M->Order);
78  $V .= " -- " . htmlentities($M->URI);
79  $V .= " @ " . htmlentities($M->Target);
80  $V .= ")\n";
81  if (!empty($M->SubMenu)) {
82  $this->Menu2HTML($M->SubMenu);
83  }
84  }
85  $V .= "</ol>\n";
86  return $V;
87  }
88 
93  function Output()
94  {
95  if ($this->State != PLUGIN_STATE_READY)
96  {
97  return 0;
98  }
99  if ($this->OutputToStdout && $this->OutputType=="Text") {
100  global $MenuList;
101  print_r($MenuList);
102  }
103  $output = "";
104  if ($this->OutputType=='HTML')
105  {
106  $output = $this->htmlContent();
107  }
108  if (!$this->OutputToStdout)
109  {
110  $this->vars['content'] = $output;
111  return; // $output;
112  }
113  print $output;
114  }
115 
120  protected function htmlContent()
121  {
122  $V = '';
123  global $MenuList;
124 
125  $FullMenuDebug = GetParm("fullmenu",PARM_INTEGER);
126  if ($FullMenuDebug == 2)
127  {
128  $text = _("Full debug ENABLED!");
129  $text1 = _("Now view any page.");
130  $V .= "<b>$text</b> $text1<P>\n";
131  }
132  if ($FullMenuDebug == 1)
133  {
134  $text = _("Full debug disabled!");
135  $text1 = _("Now view any page.");
136  $V .= "<b>$text</b> $text1<P>\n";
137  }
138  $text = _("This developer tool lists all items in the menu structure.");
139  $V .= "$text\n";
140  $text = _("Since some menu inserts are conditional, not everything may appear here (the conditions may not lead to the insertion).");
141  $V .= "$text\n";
142  $text = _("Fully-debugged menus show the full menu path and order number");
143  $text1 = _("in the menu");
144  $V .= "$text <i>$text1</i>.\n";
145  $V .= "<ul>\n";
146  $text = _("The full debugging is restricted to");
147  $text1 = _("your");
148  $text2 = _(" login session. (Nobody else will see it.)\n");
149  $V .= "<li>$text <b>$text1</b>$text2";
150  $text = _("Full debugging shows the full menu path for each menu\n");
151  $V .= "<li>$text";
152  $text = _("and the order is included in parenthesis.");
153  $V .= "$text\n";
154  $text = _("However, menus that use HTML instead of text will");
155  $text1 = _("not");
156  $text2 = _("show the full path.\n");
157  $V .= "$text <i>$text1</i>$text2";
158  $text = _("To disable full debugging, return here and unselect the option.\n");
159  $V .= "<li>$text";
160  $V .= "</ul>\n";
161  $V .= "<br>\n";
162  $V .= "<form method='post'>\n";
163  if (@$_SESSION['fullmenudebug'] == 1)
164  {
165  $V .= "<input type='hidden' name='fullmenu' value='1'>";
166  $text = _("Disable Full Debug");
167  }
168  else
169  {
170  $V .= "<input type='hidden' name='fullmenu' value='2'>";
171  $text = _("Enable Full Debug");
172  }
173  $V .= "<input type='submit' value='$text!'>";
174  $V .= "</form>\n";
175  $V .= "<hr>";
176  $this->Menu2HTML($MenuList);
177  $V .= "<hr>\n";
178  $V .= "<pre>";
179  $V .= htmlentities(print_r($MenuList,1));
180  $V .= "</pre>";
181 
182  return $V;
183  }
184 
185 }
186 $NewPlugin = new core_debug_menus;
187 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Destroy()
This is a destructor called after the plugin is no longer needed. It should assume that PostInitializ...
Definition: FO_Plugin.php:285
Definition: state.hpp:16
Plugin to debug menus.
Output()
This function is called when user output is requested. This function is responsible for content....
htmlContent()
Get the output as HTML.
__construct()
base constructor. Most plugins will just use this
PostInitialize()
This is where we check for changes to the full-debug setting.
Menu2HTML(&$Menu)
Display the full menu as an ordered list. This is recursive.
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item.
const PARM_INTEGER
Definition: common-parm.php:14
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:39