Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Commit 7a90ac3

Browse files
committed
First version of Tracy WP implementation
Custom panels + autoload
1 parent 72ccec7 commit 7a90ac3

12 files changed

+360
-7
lines changed

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
composer.phar
1+
nbproject/
22
vendor/
3-
4-
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
3+
composer.phar
4+
composer.lock

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
# WP-Tracy
2-
WordPress implementation of debugger bar (Nette) Tracy.
1+
# WP Tracy
2+
3+
[Tracy](https://github.com/nette/tracy) is an excellent PHP debugger bar from [Nette](https://nette.org) PHP framework.
4+
WP Tracy is port to [WordPress](https://wordpress.org) for test environment.
5+
When it's activated, it automatically shows Tracy bar and displays within global WP constants and their values.
6+
7+
## Installation
8+
9+
1. Use command on your path: composer require ktstudio/wp-tracy
10+
3. Profit!
11+
4. You can optionally define PHP boolean constant WP_TRACY_CHECK_USER_LOGGED_IN...
12+
13+
![Tracy bar auto-display after plugin activation](/assests/screenshot-1.png?raw=true)
14+
15+
---
16+
17+
Copyright © KTStudio.cz 2015

assets/screenshot-1.png

15.8 KB
Loading

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "ktstudio/wp-tracy",
3+
"description": "(Nette) Tracy connector for WordPress",
4+
"keywords": ["tracy", "debugger", "wordpress"],
5+
"homepage": "https://github.com/ktstudio/wp-tracy",
6+
"license": "BSD-3-Clause",
7+
"authors": [
8+
{
9+
"name": "Martin Hlaváč",
10+
"email": "[email protected]",
11+
"homepage": "http://www.ktstudio.cz/",
12+
"role": "Developer"
13+
}
14+
],
15+
"require": {
16+
"php": ">=5.4.0",
17+
"tracy/tracy": "~2.3"
18+
},
19+
"autoload": {
20+
"classmap": ["src/panels"],
21+
"files": ["src/index.php"]
22+
},
23+
"minimum-stability": "dev"
24+
}

src/index.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
if (defined("WP_TRACY_CHECK_USER_LOGGED_IN") && WP_TRACY_CHECK_USER_LOGGED_IN && is_user_logged_in()) {
4+
return; // cancel for anonymous users
5+
}
6+
7+
Tracy\Debugger::enable(); // hooray, enabling debugging using Tracy
8+
9+
// panels in the correct order
10+
$panels = array(
11+
"WpTracy\\WpPanel",
12+
"WpTracy\\WpUserPanel",
13+
"WpTracy\\WpPostPanel",
14+
"WpTracy\\WpQueryPanel",
15+
"WpTracy\\WpDbPanel",
16+
"WpTracy\\WpRewritePanel",
17+
);
18+
19+
// panels registration
20+
foreach ($panels as $className) {
21+
Tracy\Debugger::getBar()->addPanel(new $className);
22+
}

src/panels/wpdbpanel.class.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace WpTracy;
4+
5+
/**
6+
* Custom panel based on global $wpdb variable
7+
*
8+
* @author Martin Hlaváč
9+
* @link http://www.ktstudio.cz/
10+
*/
11+
class WpDbPanel extends WpPanelBase {
12+
13+
public function getTab() {
14+
return parent::getSimpleTab(__("DB"));
15+
}
16+
17+
public function getPanel() {
18+
/* @var $wpdb \WPDB */
19+
global $wpdb;
20+
$output = parent::getTablePanel(array(
21+
"Last Query" => $wpdb->last_query,
22+
"Func Call" => $wpdb->func_call,
23+
));
24+
$output .= parent::getObjectPanel($wpdb);
25+
return $output;
26+
}
27+
28+
}

src/panels/wppanel.class.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace WpTracy;
4+
5+
use Tracy\Debugger;
6+
7+
/**
8+
* Custom panel based on global $wp variable + other global (versions) variables
9+
*
10+
* @author Martin Hlaváč
11+
* @link http://www.ktstudio.cz/
12+
*/
13+
class WpPanel extends WpPanelBase {
14+
15+
public function getTab() {
16+
return parent::getSimpleTab(__("WP"), null, "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABtUlEQVR42nXTXyjdYRzH8XN0TqZ2oUV2pDXadKwVyR3TtHGlhBuJ3BjGKIq4UBZtDZ3ajb8XUv7kjuGKFEVpKf9KmlxQRgm1FJua97c+v/pp89Src3p+3+f7PL/v8/15Pf+OVKTjj9jwwY/vWHUHe13/H6AaO4hDHhL17AemsY9k9ODSncAWN2IZg0jw/H8coAyvELIkToJ6rOMbHnruHxMoRjg+oMsSvEQsDhGDfAW1Ygt/8RYf0aZfj+Z+WYIa7GIBYfiJKFwjgHOsqbhHCNpClCDSElTiDQYwrxqUa5cq9KMZnzXXgCGMYcoSVOA9NlUgO9qcgi1htoq6p6KPYAbt+OIkqNSVPcaVXiMaX9GBU/VAGrrxHEnodF7hNYpQqh36NF+HRypck+2IQh3fTjnrVfNcYFSTOarJMMZ1K88Qr1O0qF7vEOFVVYM6qv0+wbECrZhP1dorqEWuElofnDiNZEfdwCQ+WYMgE4t63q8bCajVC5Bi3egk8OuqlnQjRSpgnZ6faXEWfiNDm1y5Pya/Fh+opUPqeYuxj6lRlX+BXt3Wna/RGUEV8UZt7MT59Erb7uBbAThl6Btg2vYAAAAASUVORK5CYII=");
17+
}
18+
19+
public function getPanel() {
20+
/* @var $wpdb \WP */
21+
global $wp;
22+
global $wp_version;
23+
global $wp_db_version;
24+
global $tinymce_version;
25+
global $required_php_version;
26+
global $required_mysql_version;
27+
global $pagenow;
28+
$output = parent::getTablePanel(array(
29+
__("WP Version") => $wp_version,
30+
__("WP DB Version ") => $wp_db_version,
31+
__("TinyMCE Version ") => $tinymce_version,
32+
__("Required PHP Version") => $required_php_version,
33+
__("Required MySQL Version") => $required_mysql_version,
34+
__("Page Now") => $pagenow,
35+
__("WP") => Debugger::dump($wp, true),
36+
));
37+
return $output;
38+
}
39+
40+
}

src/panels/wppanelbase.class.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace WpTracy;
4+
5+
use Tracy,
6+
Tracy\IBarPanel,
7+
Tracy\Dumper;
8+
9+
/**
10+
* Common basic model for other WP panels
11+
*
12+
* @author Martin Hlaváč
13+
* @link http://www.ktstudio.cz/
14+
*/
15+
abstract class WpPanelBase implements IBarPanel {
16+
17+
/**
18+
* (HTML) content of tab for panel
19+
*
20+
* @author Martin Hlaváč
21+
* @link http://www.ktstudio.cz/
22+
*
23+
* @param string $title
24+
* @param string $description
25+
* @param string $imageBase64
26+
* @return string
27+
*/
28+
public function getSimpleTab($title = null, $description = null, $imageBase64 = null) {
29+
$output = "<span" . (self::issetAndNotEmpty($description) ? " title=\"$description\"" : "") . ">";
30+
if (self::issetAndNotEmpty($imageBase64)) {
31+
$output .= "<img src=\"data:image/png;base64,$imageBase64\" /> ";
32+
}
33+
if (self::issetAndNotEmpty($title)) {
34+
$output .= $title;
35+
}
36+
$output .= "</span>";
37+
return $output;
38+
}
39+
40+
/**
41+
* (HTML) table content of panel based on parameters array
42+
*
43+
* @author Martin Hlaváč
44+
* @link http://www.ktstudio.cz/
45+
*
46+
* @param array $params
47+
* @param string $title
48+
* @return string
49+
*/
50+
public function getTablePanel(array $params, $title = null) {
51+
$output = null;
52+
if (self::issetAndNotEmpty($title)) {
53+
$output .= "<h1>$title</h1>";
54+
}
55+
$output .= "<div class=\"nette-inner\">";
56+
$output .= "<table>";
57+
$output .= "<thead>";
58+
$output .= "<tr>";
59+
$output .= "<th>" . __("Parameter") . "</th>";
60+
$output .= "<th>" . __("Value") . "</th>";
61+
$output .= "</tr>";
62+
$output .= "</thead>";
63+
foreach ($params as $key => $value) {
64+
$output .= "<tr>";
65+
$output .= "<td>$key:</td>";
66+
$output .= "<td>$value</td>";
67+
$output .= "</tr>";
68+
}
69+
$output .= "</table>";
70+
$output .= "</div>";
71+
return $output;
72+
}
73+
74+
/**
75+
* (HTML) content of panel based on object
76+
*
77+
* @author Martin Hlaváč
78+
* @link http://www.ktstudio.cz/
79+
*
80+
* @param mixed $object
81+
* @param string $title
82+
* @return string
83+
*/
84+
public function getObjectPanel($object, $title = null) {
85+
$output = null;
86+
if (self::issetAndNotEmpty($title)) {
87+
$output .= "<h1>$title</h1>";
88+
}
89+
$output .= "<div class=\"nette-inner\">";
90+
$output .= Dumper::toHtml($object, array(Dumper::COLLAPSE => false));
91+
$output .= "</div>";
92+
return $output;
93+
}
94+
95+
/**
96+
* Check if the value is assigned and if it's not empty
97+
*
98+
* @author Martin Hlaváč
99+
* @link http://www.ktstudio.cz/
100+
*
101+
* @param mixed $value
102+
* @return boolean
103+
*/
104+
public static function issetAndNotEmpty($value) {
105+
return isset($value) && !empty($value);
106+
}
107+
108+
}

src/panels/wppostpanel.class.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace WpTracy;
4+
5+
/**
6+
* Custom panel based on global (WP) $post variable
7+
*
8+
* @author Martin Hlaváč
9+
* @link http://www.ktstudio.cz/
10+
*/
11+
class WpPostPanel extends WpPanelBase {
12+
13+
public function getTab() {
14+
global $post;
15+
if (self::issetAndNotEmpty($post)) {
16+
return parent::getSimpleTab(__("Post"));
17+
}
18+
return null;
19+
}
20+
21+
public function getPanel() {
22+
/* @var $wpdb \WP_Post */
23+
global $post;
24+
$output = parent::getObjectPanel($post);
25+
return $output;
26+
}
27+
28+
}

src/panels/wpquerypanel.class.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace WpTracy;
4+
5+
/**
6+
* Custom panel based on global $wp_query variable
7+
*
8+
* @author Martin Hlaváč
9+
* @link http://www.ktstudio.cz/
10+
*/
11+
class WpQueryPanel extends WpPanelBase {
12+
13+
public function getTab() {
14+
return parent::getSimpleTab(__("Query"));
15+
}
16+
17+
public function getPanel() {
18+
/* @var $wpdb \WP_Query */
19+
global $wp_query;
20+
$output = parent::getTablePanel(array("Request" => $wp_query->request));
21+
$output .= parent::getObjectPanel($wp_query);
22+
return $output;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)