-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.php
254 lines (194 loc) · 7.11 KB
/
debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
namespace aw2\debug;
\aw2_library::add_service('debug','Debug Library',['namespace'=>__NAMESPACE__]);
\aw2_library::add_service('debug.ignore','Ignore what is inside',['namespace'=>__NAMESPACE__]);
function ignore($atts,$content=null,$shortcode){
return;
}
\aw2_library::add_service('debug.setup','Debug Setup',['namespace'=>__NAMESPACE__]);
function setup($atts,$content=null,$shortcode=null){
\aw2_library::set('debug_config.active','no');
if(!isset($_COOKIE['debug_output']) || $_COOKIE['debug_output']==='no' )return;
if(!current_user_can('develop_for_awesomeui')){
if(!isset($_COOKIE['debug_ticket']))return;
$t=\aw2\session_ticket\get(["main"=>$_COOKIE['debug_ticket']],null,null);
if(!$t || !$t['debug_ticket'])return;
}
\aw2_library::set('debug_config.active','yes');
\aw2_library::set('debug_config.starttime',microtime(true));
foreach($_COOKIE as $key=>$value){
if(\aw2_library::startsWith($key,'debug_')){
\aw2_library::set('debug_config.' . substr($key, 6),$value);
}
}
if(\aw2_library::get('debug_config.wp_queries')==='yes'){
define( 'SAVEQUERIES', true );
}
}
function diff_time($start=null){
if(!$start)$start=\aw2_library::get('debug_config.starttime');
// Get the difference between start and end in microseconds, as a float value
$diff = microtime(true) - $start;
// Break the difference into seconds and microseconds
$sec = intval($diff);
$micro = $diff - $sec;
// Format the result as you want it
// $final will contain something like "00:00:02.452"
$final = $sec . str_replace('0.', '.', sprintf('%.3f', $micro));
return $final;
}
\aw2_library::add_service('debug.z','Add z for app',['namespace'=>__NAMESPACE__]);
function z($atts,$content=null,$shortcode=null){
if(!\aw2_library::get('debug_config.z'))return;
$app=\aw2_library::get_array_ref('app');
if(!isset($app['collection']['modules']['post_type']))return;
$post_type=$app['collection']['modules']['post_type'];
//get service to call
$service=\aw2_library::get('debug_config.output');
if(isset($app['active']['module'])){
\aw2_library::get_post_from_slug($app['active']['module'],$post_type,$post);
if($post){
$str = '<a target=_blank href="' . SITE_URL . "/wp-admin/post.php?action=edit&post=" . $post->ID .'">Edit Current Module(' . $post->post_name .')</a><br>';
\aw2\service\run(['service'=>$service . '.html','channel'=>'z'],$str);
}
}
$str = '<a target=_blank href="' . SITE_URL . "/wp-admin/edit.php?post_type=" . $post_type .'">Posts Archive</a><br>';
\aw2\service\run(['service'=>$service . '.html','channel'=>'z'],$str);
$str = '<br><a target=_blank href="' . SITE_URL . "/wp-admin/post-new.php?post_type=" . $post_type .'">Add New</a><br>';
\aw2\service\run(['service'=>$service . '.html','channel'=>'z'],$str);
$args=array(
'post_type' => $post_type,
'post_status'=>'publish',
'posts_per_page'=>500,
'no_found_rows' => true, // counts posts, remove if pagination required
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...)
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required
'orderby'=>'title',
'order'=>'ASC'
);
$str='';
$results = new \WP_Query( $args );
$my_posts=$results->posts;
foreach ($my_posts as $obj){
$str .= '<a target=_blank href="' . SITE_URL . "wp-admin/post.php?post=" . $obj->ID . "&action=edit" .'">' . $obj->post_title . '(' . $obj->ID . ')</a>' . '<br>';
}
if(empty($service))return;
\aw2\service\run(['service'=>$service . '.html','channel'=>'z'],$str);
}
\aw2_library::add_service('debug.wp_queries','WP Queries',['namespace'=>__NAMESPACE__]);
function wp_queries($atts,$content=null,$shortcode=null){
if(!\aw2_library::get('debug_config.wp_queries'))return;
global $wpdb;
//get service to call
$service=\aw2_library::get('debug_config.output');
foreach($wpdb->queries as $query){
$html=\aw2_library::dump_debug(
[
[
'type'=>'html',
'value' =>$query[0]
]
]
,
"Query: " . $query[1]
);
\aw2\service\run(['service'=>$service . '.html','channel'=>'query'],$html);
}
}
\aw2_library::add_service('debug.query','Output one query',['namespace'=>__NAMESPACE__]);
function query($atts,$content=null,$shortcode=null){
extract(\aw2_library::shortcode_atts( array(
'main'=>'',
'start'=>''
), $atts, 'dump' ) );
//get service to call
$service=\aw2_library::get('debug_config.output');
$html=\aw2_library::dump_debug(
[
[
'type'=>'html',
'value' =>$main
]
]
,
"Query: Time Taken:" . diff_time($start)
);
\aw2\service\run(['service'=>$service . '.html','channel'=>'query'],$html);
}
\aw2_library::add_service('debug.flow','Flow',['namespace'=>__NAMESPACE__]);
function flow($atts,$content=null,$shortcode=null){
if(!\aw2_library::get('debug_config.flow'))return;
extract(\aw2_library::shortcode_atts( array(
'main'=>null,
), $atts, 'dump' ) );
//get service to call
$service=\aw2_library::get('debug_config.output');
$html=\aw2_library::dump_debug(
[]
,
$main . ': time:' . diff_time()
);
\aw2\service\run(['service'=>$service . '.html','channel'=>'flow'],$html);
}
\aw2_library::add_service('debug.module','Flow',['namespace'=>__NAMESPACE__]);
function module($atts,$content=null,$shortcode=null){
if(!\aw2_library::get('debug_config.module'))return;
extract(\aw2_library::shortcode_atts( array(
'template'=>'',
'start'=>''
), $atts, 'dump' ) );
//get service to call
$service=\aw2_library::get('debug_config.output');
$html=\aw2_library::dump_debug(
[
[
'type'=>'html',
'value' =>"Template:: $template"
],
[
'type'=>'html',
'value' =>"Module Array"
]
// ,
// [
// 'type'=>'arr',
// 'value' =>\aw2_library::get('module')
// ]
]
,
"Module: " . \aw2_library::$stack['module']['collection']['post_type'] . '::' . \aw2_library::$stack['module']['slug'] . ' Time Taken:' . diff_time($start)
);
\aw2\service\run(['service'=>$service . '.html','channel'=>'flow'],$html);
}
\aw2_library::add_service('debug.dump','Dump something to messages',['namespace'=>__NAMESPACE__]);
function dump($atts,$content=null,$shortcode=null)
{
if(\aw2_library::get('debug_config.active')!=='yes')return;
//get service to call
$service=\aw2_library::get('debug_config.output');
extract(\aw2_library::shortcode_atts( array(
'main'=>'',
'expandlevel'=>1,
'title'=>null
), $atts, 'dump' ) );
$arr[0]['type']='arr';
$arr[0]['value']=$main;
$html=\aw2_library::dump_debug($arr,$title);
\aw2\service\run(['service'=>$service . '.html','channel'=>'messages'],$html);
}
\aw2_library::add_service('debug.html','Dump something to messages',['namespace'=>__NAMESPACE__]);
function html($atts,$content=null,$shortcode=null)
{
if(\aw2_library::get('debug_config.active')!=='yes')return;
//get service to call
$service=\aw2_library::get('debug_config.output');
extract(\aw2_library::shortcode_atts( array(
'main'=>'',
'expandlevel'=>1,
'title'=>null
), $atts, 'dump' ) );
$arr[0]['type']='html';
$arr[0]['value']=$main;
$html=\aw2_library::dump_debug($arr,$title);
\aw2\service\run(['service'=>$service . '.html','channel'=>'messages'],$html);
}