Skip to content

Commit aa711cd

Browse files
committed
we want comments in code and better text
1 parent 0d553b5 commit aa711cd

File tree

7 files changed

+61
-33
lines changed

7 files changed

+61
-33
lines changed

README.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See a flowchart of the hooks of the page!
1313
== Description ==
1414

1515
All the hooks will showed in different flowchart in SVG format that you can download as PNG to study!
16-
In the settings page is possible set the parent hook to exclude.
16+
In the settings page is possible set the parent hooks to exclude.
1717

1818
The support for download as PNG not works on WebKit based browser.
1919

@@ -42,20 +42,11 @@ Check the screenshots!
4242
2. Extract the `hook-flowchart` directory to your computer
4343
3. Upload the `hook-flowchart` directory to the `/wp-content/plugins/` directory
4444
4. Activate the plugin in the Plugin dashboard
45-
== Frequently Asked Questions ==
46-
47-
= A question that someone might have =
48-
49-
An answer to that question.
50-
51-
= What about foo bar? =
52-
53-
Answer to foo bar dilemma.
5445

5546
== Screenshots ==
5647

5748
1. The window opened with all the flowcharts.
58-
2. The flowchart download for a specific parent hook
49+
2. The hook flowchart downloaded for a specific parent hook
5950

6051
== Changelog ==
6152

assets/screenshot-1.png

27.8 KB
Loading

assets/screenshot-2.png

52.2 KB
Loading

public/assets/css/mermaid.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ text.actor {
8181
.noteText {
8282
fill: black;
8383
stroke: none;
84-
font-family: 'trebuchet ms', verdana, arial;
85-
font-size: 14px;
84+
font-family: "Open Sans",sans-serif;
85+
font-size: 13px;
8686
}
8787
/** Section styling */
8888
.section {
@@ -251,7 +251,7 @@ text.actor {
251251
252252
*/
253253
text {
254-
font-family: 'trebuchet ms', verdana, arial;
255-
font-size: 14px;
254+
font-family: "Open Sans",sans-serif;
255+
font-size: 13px;
256256
}
257257

public/assets/js/mermaid.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/js/popupcode.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
document.addEventListener('DOMContentLoaded', function () {
22
var i = 0;
3+
//The download as png doesn't work on WebKit
34
var isWebkit = 'WebkitAppearance' in document.documentElement.style;
5+
//Prepare mermaid
46
mermaid.initialize({
57
flowchart: {
68
useMaxWidth: false
79
}});
10+
//Parse every hook
811
[].forEach.call(document.querySelectorAll('.mermaid-noise'), function (el) {
912
i++;
13+
//Get the markdown text
1014
var convert = el.innerHTML;
1115
convert = convert.replace(/\[n\]/g, "\n");
16+
//Get the hook name
1217
var hook = convert.slice(15).split(']');
1318
hook = hook[0];
19+
1420
document.querySelector('.body').innerHTML += "<h3 id='" + hook + "'>Hook " + hook + "</h3>";
1521
document.querySelector('.buttons').innerHTML += "<a href='#" + hook + "' class='button'>" + hook + "</a><input type='checkbox' data-hook='" + hook + "' data-id='" + i + "' alt='Hide' title='Hide' class='hide-hook' style='margin-top:3px'/>";
1622
if (!isWebkit) {
1723
document.querySelector('.body').innerHTML += "<button class='button button-primary mermaid-download' data-id='" + i + "'>Download</button>";
1824
}
1925
document.querySelector('.body').innerHTML += "<div class='mermaid-" + i + "'>" + convert + "</div><hr data-id='" + i + "'>";
26+
//Generate the flowchart
2027
mermaid.init(".mermaid-" + i);
2128
});
29+
//Go to top
2230
document.querySelector('button.gotop').addEventListener('click', function () {
2331
document.body.scrollTop = document.documentElement.scrollTop = 0;
2432
});
33+
//Hide system for hooks
2534
[].forEach.call(document.querySelectorAll('.hide-hook'), function (e) {
2635
e.addEventListener('click', function () {
2736
if (e.checked) {
@@ -36,6 +45,7 @@ document.addEventListener('DOMContentLoaded', function () {
3645
}
3746
});
3847
});
48+
//Download system
3949
if (!isWebkit) {
4050
[].forEach.call(document.querySelectorAll('button.mermaid-download'), function (e) {
4151
e.addEventListener('click', function () {
@@ -44,39 +54,48 @@ document.addEventListener('DOMContentLoaded', function () {
4454
});
4555

4656
function svgToPng(source) {
47-
var name = source.querySelector('#a div').innerHTML;
57+
//Prepare the canvas
4858
var canvas = document.createElement("canvas");
4959
canvas.setAttribute('width', source.getBBox().width);
5060
canvas.setAttribute('height', source.getBBox().height);
5161
var ctx = canvas.getContext("2d");
62+
//Prepare the image
5263
var img = new Image();
64+
//this doesn't work but maybe enalbe the support for webkit
5365
img.setAttribute('crossOrigin', 'anonymous');
5466
img.crossOrigin = "Anonymous";
67+
//Get the hook name
68+
var name = source.querySelector('#a div').innerHTML;
5569
var svgString = new XMLSerializer().serializeToString(source);
5670
//Hack for Mermaid to replace div to text object
5771
svgString = svgString.replace(/div/g, "text");
58-
//Hack for mermaid for text alignment
59-
svgString = svgString.replace(/translate\(0\,0\)/g, 'translate(-2,0)');
72+
//Convert the svg string in a blob
6073
var svg = new Blob([svgString], {
6174
type: "image/svg+xml;charset=utf-8"
6275
});
76+
//Convert as an URL
6377
var url = window.URL.createObjectURL(svg);
6478
img.onload = function () {
6579
ctx.drawImage(img, 0, 0);
6680
var png = canvas.toDataURL("image/png");
81+
//Generate a img tag
6782
var target = document.createElement('img');
6883
target.className = "on-the-fly";
84+
//We pass the empty canvas
6985
target.src = png;
7086
document.body.appendChild(target);
7187
window.URL.revokeObjectURL(png);
7288
};
89+
//Add the URL in the img
7390
img.src = url;
91+
//Little timeout to get the image
7492
var timeout = window.setTimeout(function () {
7593
var a = document.createElement('a');
7694
a.download = name + '.png';
7795
a.href = document.querySelector('.on-the-fly').src;
7896
document.body.appendChild(a);
79-
a.addEventListener("click", function (e) {
97+
a.addEventListener("click", function () {
98+
//Cleaning
8099
a.parentNode.removeChild(a);
81100
document.querySelector('.on-the-fly').parentNode.removeChild(document.querySelector('.on-the-fly'));
82101
});

public/class-hook-flowchart.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ class Hook_Flowchart {
6868
*/
6969
protected static $instance = null;
7070

71+
/**
72+
* Hooks
73+
*
74+
* @since 1.0.0
75+
*
76+
* @var array
77+
*/
78+
protected $hooks = null;
79+
7180
/**
7281
* Initialize the plugin by loading admin scripts & styles and adding a
7382
* settings page and menu.
@@ -211,33 +220,42 @@ private static function single_activate() {
211220
}
212221
}
213222

223+
/**
224+
* Fired for each hook
225+
*
226+
* @since 1.0.0
227+
*/
214228
function parent_hook() {
215-
global $wp_parent_hook, $wp_current_filter;
229+
global $wp_current_filter;
216230
foreach ( $wp_current_filter as $child => $hook_name ) {
217-
if ( $child === 0 && !isset( $wp_parent_hook[ $hook_name ] ) ) {
218-
$wp_parent_hook[ $hook_name ] = array();
219-
} elseif ( $child === 1 && !isset( $wp_parent_hook[ $wp_current_filter[ 0 ] ][ $hook_name ] ) ) {
220-
$wp_parent_hook[ $wp_current_filter[ 0 ] ][ $hook_name ] = array();
221-
} elseif ( $child === 2 && !isset( $wp_parent_hook[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $hook_name ] ) ) {
222-
$wp_parent_hook[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $hook_name ] = array();
231+
if ( $child === 0 && !isset( $this->hooks[ $hook_name ] ) ) {
232+
$this->hooks[ $hook_name ] = array();
233+
} elseif ( $child === 1 && !isset( $this->hooks[ $wp_current_filter[ 0 ] ][ $hook_name ] ) ) {
234+
$this->hooks[ $wp_current_filter[ 0 ] ][ $hook_name ] = array();
235+
} elseif ( $child === 2 && !isset( $this->hooks[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $hook_name ] ) ) {
236+
$this->hooks[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $hook_name ] = [ ];
223237
} elseif ( $child === 3 ) {
224-
$wp_parent_hook[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $wp_current_filter[ 2 ] ][ $hook_name ] = 1;
238+
$this->hooks[ $wp_current_filter[ 0 ] ][ $wp_current_filter[ 1 ] ][ $wp_current_filter[ 2 ] ][ $hook_name ] = 1;
225239
}
226240
}
227241
}
228242

243+
/**
244+
* Generate the window
245+
*
246+
* @since 1.0.0
247+
*/
229248
function print_hookr_flowchart() {
230-
global $wp_parent_hook;
231249
$html = '';
232-
ksort( $wp_parent_hook );
250+
ksort( $this->hooks );
233251
$exclude = get_option( $this->get_plugin_slug() );
234252
$exclude = explode( ',', $exclude[ 'excluded' ] );
235253
foreach ( $exclude as $key => $value ) {
236-
if ( isset( $wp_parent_hook[ $value ] ) ) {
237-
unset( $wp_parent_hook[ $value ] );
254+
if ( isset( $this->hooks[ $value ] ) ) {
255+
unset( $this->hooks[ $value ] );
238256
}
239257
}
240-
foreach ( $wp_parent_hook as $hook_father => $hook_son ) {
258+
foreach ( $this->hooks as $hook_father => $hook_son ) {
241259
if ( is_array( $hook_son ) && count( $hook_son ) > 1 ) {
242260
$html .= '<div class="mermaid-noise" style="display:none">';
243261
$html .= '[n]graph LR' . "[n]";

0 commit comments

Comments
 (0)