GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-debug-bar.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Show debugging information in concert with the excellent {@link http://wordpress.org/plugins/debug-bar/ Debug Bar plugin}
5  *
6  * @file /includes/class.debug-bar.php
7  * @since 2.2.4
8  */
9 class GravityView_Debug_Bar extends Debug_Bar_Panel {
10 
11  var $warnings = NULL;
12 
13  var $notices = NULL;
14 
15  var $_visible = true;
16 
17  /**
18  * Only show if WP_DEBUG is running. Set the title of the panel.
19  * @return void
20  */
21  function init() {
22 
23  $icon = is_admin() ? '<i class="icon gv-icon-astronaut-head"></i>&nbsp;' : NULL;
24  $this->title( $icon . __('GravityView', 'gravityview') );
25  }
26 
27  function get_warnings() {
28 
29  if( is_null( $this->warnings ) ) {
30  $this->warnings = GravityView_Logging::get_errors();
31  }
32 
33  return $this->warnings;
34  }
35 
36  function get_notices() {
37 
38  if( is_null( $this->notices ) ) {
39  $this->notices = GravityView_Logging::get_notices();
40  }
41 
42  return $this->notices;
43  }
44 
45  function prerender() {
46  $this->set_visible();
47  }
48 
49  /**
50  * Should the panel be shown? If there are notices or warnings, yes.
51  * @param boolean $visible {@internal Leave here for compatibility with the Debug_Bar_Panel parent class}
52  * @return void
53  */
54  function set_visible( $visible = false ) {
55  $this->_visible = ( count( $this->get_notices() ) || count( $this->get_warnings() ) );
56  }
57 
58  /**
59  * Render the panel HTML
60  * @return string Panel output
61  */
62  function render() {
63 
64  $output = "
65  <style type='text/css'>
66  #debug-bar-gravityview { padding:10px 2%; width: 96%; }
67  #debug-bar-gravityview * { clear: none; }
68  #debug-bar-gravityview h3,
69  #debug-bar-gravityview .gravityview-debug-bar-title { font-weight: bold; font-size: 14px; line-height: 1.4; margin: 5px 0; }
70  #debug-bar-gravityview .alignright { float: right!important; margin-left: 10px!important; }
71  #debug-bar-gravityview .ul-square, #debug-bar-gravityview .ul-square li { list-style: square; }
72  #querylist #debug-bar-gravityview ol { font-family: \"Helvetica Neue\",sans-serif!important; }
73  #debug-bar-gravityview hr { border:none;border-top:1px solid #ccc; margin-top:20px; }
74  #debug-bar-gravityview h3 { margin-top:20px; }
75  #debug-bar-gravityview pre {
76  width:98%;
77  background:#f0f0f0;
78  border: 1px solid #ccc;
79  overflow:auto;
80  max-height:300px;
81  margin-bottom: 10px;
82  font: 12px Monaco,\"Courier New\",Courier,Fixed!important;
83  }
84  </style>
85  <div id='debug-bar-gravityview'>";
86 
87  $output .= '<img src="'.plugins_url('assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ).'" class="alignright" alt="" width="100" height="132" />';
88 
89 
90  $warnings = $this->get_warnings();
91  $notices = $this->get_notices();
92 
93  if(count($warnings)) {
94  $output .= '<h3><span>'.__('Warnings', 'gravityview').'</span></h3>';
95  $output .= '<ol>';
96  foreach ( $warnings as $key => $notice) {
97  if(empty($notice['message'])) { continue; }
98  $output .= '<li><a href="#'.sanitize_html_class( 'gv-warning-' . $key ).'">'.strip_tags($notice['message']).'</a></li>';
99  }
100  $output .= '</ol><hr />';
101  }
102  if(count($notices)) {
103  $output .= '<h3><span>'.__('Logs', 'gravityview').'</span></h3>';
104  $output .= '<ol>';
105  foreach ( $notices as $key => $notice) {
106  if(empty($notice['message'])) { continue; }
107  $output .= '<li><a href="#'.sanitize_html_class( 'gv-notice-' . $key ).'">'.strip_tags($notice['message']).'</a></li>';
108  }
109  $output .= '</ol><hr />';
110  }
111 
112  if ( count( $warnings ) ) {
113  $output .= '<h3>Warnings</h3>';
114  $output .= '<ol class="debug-bar-php-list">';
115  foreach ( $warnings as $key => $notice) { $output .= $this->render_item( $notice, 'gv-warning-' . $key ); }
116  $output .= '</ol>';
117  }
118 
119  if ( count( $notices ) ) {
120  $output .= '<h3>Notices</h3>';
121  $output .= '<ol class="debug-bar-php-list">';
122  foreach ( $notices as $key => $notice) { $output .= $this->render_item( $notice, 'gv-notice-' . $key ); }
123  $output .= '</ol>';
124  }
125 
126  $output .= "</div>";
127 
128  echo $output;
129  }
130 
131  /**
132  * Apply esc_html() to an array
133  * @param string|array $item Unescaped
134  * @return string Escaped HTML
135  */
136  function esc_html_recursive($item) {
137  if(is_object($item)) {
138  foreach($item as $key => $value) {
139  $item->{$key} = $this->esc_html_recursive($value);
140  }
141  } else if(is_array($item)) {
142  foreach($item as $key => $value) {
143  $item[$key] = $this->esc_html_recursive($value);
144  }
145  } else {
146  $item = esc_html($item);
147  }
148  return $item;
149  }
150 
151 
152  /**
153  * Render each log item
154  * @param array $notice `message`, `description`, `content`
155  * @param string $anchor The anchor ID for the item
156  * @return string HTML output
157  */
158  function render_item( $notice, $anchor = '' ) {
159 
160  $output = '';
161 
162  if(!empty($notice['message'])) {
163  $output .= '<a id="'.sanitize_html_class( $anchor ).'"></a>';
164  $output .= "<li class='debug-bar-php-notice'>";
165  }
166 
167  $output .= '<div class="clear"></div>';
168 
169  // Title
170  $output .= '<div class="gravityview-debug-bar-title">'.esc_attr( $notice['message'] ).'</div>';
171 
172  // Debugging Output
173  if( empty( $notice['data'] ) ) {
174  if( !is_null( $notice['data'] ) ) {
175  $output .= '<em>'._x('Empty', 'Debugging output data is empty.', 'gravityview' ).'</em>';
176  }
177  } else {
178  $output .= sprintf( '<pre>%s</pre>', print_r($this->esc_html_recursive( $notice['data'] ), true) );
179  }
180 
181  if(!empty($notice['message'])) {
182  $output .= '</li>';
183  }
184 
185  return $output;
186  }
187 }
render()
Render the panel HTML.
esc_html_recursive($item)
Apply esc_html() to an array.
init()
Only show if WP_DEBUG is running.
const GRAVITYVIEW_FILE(!defined( 'ABSPATH'))
Plugin Name: GravityView Plugin URI: https://gravityview.co Description: The best, easiest way to display Gravity Forms entries on your website.
Definition: gravityview.php:26
set_visible($visible=false)
Should the panel be shown? If there are notices or warnings, yes.
$anchor
render_item($notice, $anchor= '')
Render each log item.