FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
core-debug-menus.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2013 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 ***********************************************************/
18 
19 define("TITLE_core_debug_menus", _("Debug Menus"));
20 
26 {
27  function __construct()
28  {
29  $this->Name = "debug-menus";
30  $this->Title = TITLE_core_debug_menus;
31  $this->MenuList = "Help::Debug::Debug Menus";
32  $this->DBaccess = PLUGIN_DB_ADMIN;
33  parent::__construct();
34  }
35 
42  function PostInitialize()
43  {
44  if ($this->State != PLUGIN_STATE_VALID) {
45  return(0);
46  }
47  // Make sure dependencies are met
48  foreach($this->Dependency as $key => $val)
49  {
50  $id = plugin_find_id($val);
51  if ($id < 0) {
52  $this->Destroy(); return(0);
53  }
54  }
55 
56  $FullMenuDebug = GetParm("fullmenu",PARM_INTEGER);
57  if ($FullMenuDebug == 2)
58  {
59  $_SESSION['fullmenudebug'] = 1;
60  }
61  if ($FullMenuDebug == 1)
62  {
63  $_SESSION['fullmenudebug'] = 0;
64  }
65 
66  // It worked, so mark this plugin as ready.
67  $this->State = PLUGIN_STATE_READY;
68  // Add this plugin to the menu
69  if ($this->MenuList !== "")
70  {
71  menu_insert("Main::" . $this->MenuList,$this->MenuOrder,$this->Name,$this->MenuTarget);
72  }
73  return(1);
74  } // PostInitialize()
75 
82  function Menu2HTML(&$Menu)
83  {
84  $V = "<ol>\n";
85  foreach($Menu as $M)
86  {
87  $V .= "<li>" . htmlentities($M->Name);
88  $V .= " (" . htmlentities($M->Order);
89  $V .= " -- " . htmlentities($M->URI);
90  $V .= " @ " . htmlentities($M->Target);
91  $V .= ")\n";
92  if (!empty($M->SubMenu)) {
93  $this->Menu2HTML($M->SubMenu);
94  }
95  }
96  $V .= "</ol>\n";
97  return $V;
98  }
99 
104  function Output()
105  {
106  if ($this->State != PLUGIN_STATE_READY)
107  {
108  return 0;
109  }
110  if ($this->OutputToStdout && $this->OutputType=="Text") {
111  global $MenuList;
112  print_r($MenuList);
113  }
114  $output = "";
115  if ($this->OutputType=='HTML')
116  {
117  $output = $this->htmlContent();
118  }
119  if (!$this->OutputToStdout)
120  {
121  $this->vars['content'] = $output;
122  return; // $output;
123  }
124  print $output;
125  }
126 
131  protected function htmlContent()
132  {
133  $V = '';
134  global $MenuList;
135 
136  $FullMenuDebug = GetParm("fullmenu",PARM_INTEGER);
137  if ($FullMenuDebug == 2)
138  {
139  $text = _("Full debug ENABLED!");
140  $text1 = _("Now view any page.");
141  $V .= "<b>$text</b> $text1<P>\n";
142  }
143  if ($FullMenuDebug == 1)
144  {
145  $text = _("Full debug disabled!");
146  $text1 = _("Now view any page.");
147  $V .= "<b>$text</b> $text1<P>\n";
148  }
149  $text = _("This developer tool lists all items in the menu structure.");
150  $V .= "$text\n";
151  $text = _("Since some menu inserts are conditional, not everything may appear here (the conditions may not lead to the insertion).");
152  $V .= "$text\n";
153  $text = _("Fully-debugged menus show the full menu path and order number");
154  $text1 = _("in the menu");
155  $V .= "$text <i>$text1</i>.\n";
156  $V .= "<ul>\n";
157  $text = _("The full debugging is restricted to");
158  $text1 = _("your");
159  $text2 = _(" login session. (Nobody else will see it.)\n");
160  $V .= "<li>$text <b>$text1</b>$text2";
161  $text = _("Full debugging shows the full menu path for each menu\n");
162  $V .= "<li>$text";
163  $text = _("and the order is included in parenthesis.");
164  $V .= "$text\n";
165  $text = _("However, menus that use HTML instead of text will");
166  $text1 = _("not");
167  $text2 = _("show the full path.\n");
168  $V .= "$text <i>$text1</i>$text2";
169  $text = _("To disable full debugging, return here and unselect the option.\n");
170  $V .= "<li>$text";
171  $V .= "</ul>\n";
172  $V .= "<br>\n";
173  $V .= "<form method='post'>\n";
174  if (@$_SESSION['fullmenudebug'] == 1)
175  {
176  $V .= "<input type='hidden' name='fullmenu' value='1'>";
177  $text = _("Disable Full Debug");
178  $V .= "<input type='submit' value='$text!'>";
179  }
180  else
181  {
182  $V .= "<input type='hidden' name='fullmenu' value='2'>";
183  $text = _("Enable Full Debug");
184  $V .= "<input type='submit' value='$text!'>";
185  }
186  $V .= "</form>\n";
187  $V .= "<hr>";
188  $this->Menu2HTML($MenuList);
189  $V .= "<hr>\n";
190  $V .= "<pre>";
191  $V .= htmlentities(print_r($MenuList,1));
192  $V .= "</pre>";
193 
194  return $V;
195  }
196 
197 }
198 $NewPlugin = new core_debug_menus;
199 $NewPlugin->Initialize();
htmlContent()
Get the output as HTML.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:51
PostInitialize()
This is where we check for changes to the full-debug setting.
Plugin to debug menus.
Definition: state.hpp:26
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_INTEGER
Definition: common-parm.php:25
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
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...
Destroy()
This is a destructor called after the plugin is no longer needed. It should assume that PostInitializ...
Definition: FO_Plugin.php:296
Output()
This function is called when user output is requested. This function is responsible for content...