Skip to content

Commit 10fda56

Browse files
committed
new version
1 parent 03da094 commit 10fda56

File tree

4 files changed

+125
-80
lines changed

4 files changed

+125
-80
lines changed

hook-flowchart.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
die;
2828
}
2929

30+
define( 'HF_VERSION', '2.0.0' );
31+
define( 'HF_TEXTDOMAIN', 'hook-flowchart' );
32+
define( 'HF_NAME', 'Hook Flowchart' );
33+
define( 'HF_PLUGIN_ROOT', plugin_dir_path( __FILE__ ) );
34+
define( 'HF_PLUGIN_ABSOLUTE', __FILE__ );
35+
3036
/*
3137
* ------------------------------------------------------------------------------
3238
* Public-Facing Functionality

public/assets/css/mermaid.css

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22
/* Sequence Diagram variables */
33
/* Gantt chart variables */
44
.mermaid .label {
5-
color: #333333;
5+
color: #333;
66
}
77
.node rect,
88
.node circle,
9+
.node ellipse,
910
.node polygon {
10-
fill: #ececff;
11-
stroke: #ccccff;
11+
fill: #ECECFF;
12+
stroke: #CCCCFF;
1213
stroke-width: 1px;
1314
}
1415
.edgePath .path {
15-
stroke: #333333 !important;
16+
stroke: #333333;
17+
}
18+
.edgeLabel {
19+
background-color: #e8e8e8;
1620
}
1721
.cluster rect {
18-
fill: #ffffde;
19-
rx: 40;
20-
stroke: #aaaa33;
21-
stroke-width: 1px;
22+
fill: #ffffde !important;
23+
rx: 4 !important;
24+
stroke: #aaaa33 !important;
25+
stroke-width: 1px !important;
2226
}
2327
.cluster text {
24-
fill: #333333;
28+
fill: #333;
2529
}
2630
.actor {
27-
stroke: #ccccff;
28-
fill: #ececff;
31+
stroke: #CCCCFF;
32+
fill: #ECECFF;
2933
}
3034
text.actor {
3135
fill: black;
@@ -38,27 +42,27 @@ text.actor {
3842
stroke-width: 1.5;
3943
stroke-dasharray: "2 2";
4044
marker-end: "url(#arrowhead)";
41-
stroke: #333333;
45+
stroke: #333;
4246
}
4347
.messageLine1 {
4448
stroke-width: 1.5;
4549
stroke-dasharray: "2 2";
46-
stroke: #333333;
50+
stroke: #333;
4751
}
4852
#arrowhead {
49-
fill: #333333;
53+
fill: #333;
5054
}
5155
#crosshead path {
52-
fill: #333333 !important;
53-
stroke: #333333 !important;
56+
fill: #333 !important;
57+
stroke: #333 !important;
5458
}
5559
.messageText {
56-
fill: #333333;
60+
fill: #333;
5761
stroke: none;
5862
}
5963
.labelBox {
60-
stroke: #ccccff;
61-
fill: #ececff;
64+
stroke: #CCCCFF;
65+
fill: #ECECFF;
6266
}
6367
.labelText {
6468
fill: black;
@@ -72,7 +76,7 @@ text.actor {
7276
stroke-width: 2;
7377
stroke-dasharray: "2 2";
7478
marker-end: "url(#arrowhead)";
75-
stroke: #ccccff;
79+
stroke: #CCCCFF;
7680
}
7781
.note {
7882
stroke: #aaaa33;
@@ -81,8 +85,8 @@ text.actor {
8185
.noteText {
8286
fill: black;
8387
stroke: none;
84-
font-family: "Open Sans",sans-serif;
85-
font-size: 13px;
88+
font-family: 'trebuchet ms', verdana, arial;
89+
font-size: 14px;
8690
}
8791
/** Section styling */
8892
.section {
@@ -101,16 +105,16 @@ text.actor {
101105
opacity: 0.2;
102106
}
103107
.sectionTitle0 {
104-
fill: #333333;
108+
fill: #333;
105109
}
106110
.sectionTitle1 {
107-
fill: #333333;
111+
fill: #333;
108112
}
109113
.sectionTitle2 {
110-
fill: #333333;
114+
fill: #333;
111115
}
112116
.sectionTitle3 {
113-
fill: #333333;
117+
fill: #333;
114118
}
115119
.sectionTitle {
116120
text-anchor: start;
@@ -250,8 +254,20 @@ text.actor {
250254
251255
252256
*/
253-
text {
254-
font-family: "Open Sans",sans-serif;
255-
font-size: 13px;
257+
.node text {
258+
font-family: 'trebuchet ms', verdana, arial;
259+
font-size: 14px;
260+
}
261+
div.mermaidTooltip {
262+
position: absolute;
263+
text-align: center;
264+
max-width: 200px;
265+
padding: 2px;
266+
font-family: 'trebuchet ms', verdana, arial;
267+
font-size: 12px;
268+
background: #ffffde;
269+
border: 1px solid #aaaa33;
270+
border-radius: 2px;
271+
pointer-events: none;
272+
z-index: 100;
256273
}
257-

public/assets/js/mermaid.js

Lines changed: 20 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/class-hook-flowchart.php

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ private function __construct() {
8787
add_action( 'admin_bar_menu', array( $this, 'register_menu' ), 99 );
8888
add_action( 'all', array( $this, 'parent_hook' ) );
8989
add_action( 'shutdown', array( $this, 'print_hookr_flowchart' ), 9999 );
90+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_stuff' ) );
91+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_stuff' ) );
92+
add_action( 'init', array( $this, 'show_flowchart' ), 9999 );
9093
}
9194

9295
/**
@@ -181,12 +184,9 @@ public static function activate( $network_wide ) {
181184

182185
restore_current_blog();
183186
}
184-
} else {
185-
self::single_activate();
186187
}
187-
} else {
188-
self::single_activate();
189188
}
189+
self::single_activate();
190190
}
191191

192192
/**
@@ -197,9 +197,9 @@ public static function activate( $network_wide ) {
197197
*/
198198
function register_menu( $wp_admin_bar ) {
199199
$wp_admin_bar->add_node( array(
200-
'id' => 'hook-flowchart',
201-
'title' => 'Hook FlowChart',
202-
'href' => '#'
200+
'id' => 'hook-flowchart',
201+
'title' => 'Hook FlowChart',
202+
'href' => '#'
203203
) );
204204
}
205205

@@ -225,7 +225,7 @@ private static function single_activate() {
225225
*
226226
* @since 1.0.0
227227
*/
228-
function parent_hook() {
228+
public function parent_hook() {
229229
global $wp_current_filter;
230230
foreach ( $wp_current_filter as $child => $hook_name ) {
231231
if ( $child === 0 && !isset( $this->hooks[ $hook_name ] ) ) {
@@ -240,22 +240,58 @@ function parent_hook() {
240240
}
241241
}
242242

243+
public function enqueue_stuff() {
244+
if ( is_user_logged_in() ) {
245+
wp_enqueue_style( HF_TEXTDOMAIN . '-plugin-styles', plugins_url( 'public/assets/css/mermaid.css', HF_PLUGIN_ABSOLUTE ), array(), HF_VERSION );
246+
wp_enqueue_script( HF_TEXTDOMAIN . '-mermaid', plugins_url( 'public/assets/js/mermaid.js', HF_PLUGIN_ABSOLUTE ), array( 'jquery' ), HF_VERSION );
247+
wp_enqueue_script( HF_TEXTDOMAIN . '-plugin-script', plugins_url( 'public/assets/js/popupcode.js', HF_PLUGIN_ABSOLUTE ), array( 'jquery' ), HF_VERSION );
248+
}
249+
}
250+
243251
/**
244252
* Generate the window
245253
*
246254
* @since 1.0.0
247255
*/
248256
function print_hookr_flowchart() {
249-
$html = '';
250-
ksort( $this->hooks );
251-
$exclude = get_option( $this->get_plugin_slug() );
252-
$exclude = explode( ',', $exclude[ 'excluded' ] );
253-
foreach ( $exclude as $key => $value ) {
254-
if ( isset( $this->hooks[ $value ] ) ) {
255-
unset( $this->hooks[ $value ] );
257+
if ( !isset( $_GET[ 'hookr-flowchart' ] ) ) {
258+
ksort( $this->hooks );
259+
$exclude = get_option( $this->get_plugin_slug() );
260+
$exclude = explode( ',', $exclude[ 'excluded' ] );
261+
foreach ( $exclude as $key => $value ) {
262+
if ( isset( $this->hooks[ $value ] ) ) {
263+
unset( $this->hooks[ $value ] );
264+
}
256265
}
266+
267+
echo '<div class="hookr-flowchart" style="display:none;z-index:9999;">'
268+
. '<div class="body" style="padding-left:20px"><h1>Hook Flowchart</h1><h3>' . "\n"
269+
. __( 'Use ctrl + f to use your browser search function or click on that buttons to jump to the parent hook, check the hook to hide', $this->get_plugin_slug() ) . '</h3><span class="buttons"></span>' . "\n"
270+
. $this->array_to_mermaid( $this->hooks ) . "\n"
271+
. '<button class="button button-primary gotop" style="float:right;position:fixed;bottom:10px;right:10px;">' . __( 'Go Top', $this->get_plugin_slug() ) . '</button></div>'
272+
. '</div><style>.hookr-flowchart {z-index: 9999;position: absolute;}.wp-admin .hookr-flowchart{margin-left: 160px;}</style><script>'
273+
. 'jQuery(document).ready(function() {'
274+
. 'jQuery( "#wp-admin-bar-hook-flowchart a" ).click(function() {
275+
jQuery(".hookr-flowchart").show();
276+
});'
277+
. '});'
278+
. '</script>';
257279
}
258-
foreach ( $this->hooks as $hook_father => $hook_son ) {
280+
}
281+
282+
public function show_flowchart() {
283+
if ( is_user_logged_in() ) {
284+
if ( isset( $_GET[ 'hookr-flowchart' ] ) ) {
285+
$hooks = str_replace( '\"', '"', $_GET[ 'hookr-flowchart' ] );
286+
;
287+
die();
288+
}
289+
}
290+
}
291+
292+
public function array_to_mermaid( $hooks ) {
293+
$html = '';
294+
foreach ( $hooks as $hook_father => $hook_son ) {
259295
if ( is_array( $hook_son ) && count( $hook_son ) > 1 ) {
260296
$html .= '<div class="mermaid-noise" style="display:none">';
261297
$html .= '[n]graph LR' . "[n]";
@@ -284,22 +320,7 @@ function print_hookr_flowchart() {
284320
$html .= '</div>';
285321
}
286322
}
287-
$html = '<html><head><title>Hook Flowchart - ' . $_SERVER[ 'REQUEST_URI' ] . '</title>'
288-
. '<link rel="stylesheet" type="text/css" href="' . get_site_url() . '/wp-admin/load-styles.php?c=1&dir=ltr&load=wp-admin,buttons" />'
289-
. '<link rel="stylesheet" type="text/css" href="' . plugins_url( 'assets/css/mermaid.css', __FILE__ ) . '" />'
290-
. '<script type="text/javascript" src="' . plugins_url( 'assets/js/mermaid.js', __FILE__ ) . '"></script>'
291-
. '<script type="text/javascript" src="' . plugins_url( 'assets/js/popupcode.js', __FILE__ ) . '"></script>'
292-
. '</head><body class="wp-core-ui"><div class="body" style="padding-left:20px"><h1>Hook Flowchart - ' . get_site_url() . $_SERVER[ 'REQUEST_URI' ] . '</h1><h3>' . __( 'Use ctrl + f to use your browser search function or click on that buttons to jump to the parent hook, check the hook to hide', $this->get_plugin_slug() ) . '</h3><span class="buttons"></span>' . $html . '<button class="button button-primary gotop" style="float:right;position:fixed;bottom:10px;right:10px;">' . __( 'Go Top', $this->get_plugin_slug() ) . '</button></div></body></html>';
293-
echo '<script>'
294-
. 'jQuery(document).ready(function() {'
295-
. 'jQuery( "#wp-admin-bar-hook-flowchart a" ).click(function() {
296-
html = jQuery("<div/>").html("' . htmlentities( $html ) . '").text();
297-
url = \'data:text/html,\' + html;
298-
var win = window.open(url, "_blank");
299-
win.focus();
300-
});'
301-
. '});'
302-
. '</script>';
323+
return $html;
303324
}
304325

305326
}

0 commit comments

Comments
 (0)