1
|
|
|
<?php |
2
|
|
|
namespace NirjharLo\Cgss\Lib\Analysis; |
3
|
|
|
|
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
5
|
|
|
|
6
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Tags; |
|
|
|
|
7
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Text; |
|
|
|
|
8
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Keywords; |
|
|
|
|
9
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Social; |
|
|
|
|
10
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Server; |
|
|
|
|
11
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Design; |
|
|
|
|
12
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Lib\Score; |
|
|
|
|
13
|
|
|
|
14
|
|
|
use \DOMDocument; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Crawls an URL |
18
|
|
|
*/ |
19
|
|
|
final class Crawl { |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
public $url; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
// Execute the crawl |
26
|
|
|
public function execute() { |
27
|
|
|
|
28
|
|
|
$tic = microtime(true); |
29
|
|
|
|
30
|
|
|
$this->header = $this->header_check(); |
|
|
|
|
31
|
|
|
$ok = $this->header['ok']; |
32
|
|
|
if (!$ok) { |
33
|
|
|
|
34
|
|
|
$this->no_header_scan(); |
35
|
|
|
|
36
|
|
|
} else { |
37
|
|
|
|
38
|
|
|
$this->parsed_url = $this->parse_url(); |
|
|
|
|
39
|
|
|
$this->body = $this->get_body(); |
|
|
|
|
40
|
|
|
$ok = $this->body['ok']; |
41
|
|
|
if (!$ok) { |
42
|
|
|
|
43
|
|
|
$this->no_body_scan(); |
44
|
|
|
|
45
|
|
|
} else { |
46
|
|
|
|
47
|
|
|
// Prepare the DOM |
48
|
|
|
$this->dom = new DOMDocument; |
|
|
|
|
49
|
|
|
libxml_use_internal_errors( true ); |
50
|
|
|
$this->dom->loadHTML( $this->body['body'] ); |
51
|
|
|
|
52
|
|
|
// Parse the DOM |
53
|
|
|
$this->title = $this->get_title(); |
|
|
|
|
54
|
|
|
$this->desc = $this->get_desc(); |
|
|
|
|
55
|
|
|
$this->robot = $this->get_robot(); |
|
|
|
|
56
|
|
|
$this->canonical = $this->get_canonical(); |
|
|
|
|
57
|
|
|
$this->viewport = $this->get_viewport(); |
|
|
|
|
58
|
|
|
$this->social_tags = $this->get_social_tags(); |
|
|
|
|
59
|
|
|
$this->links = $this->get_links(); |
|
|
|
|
60
|
|
|
$this->images = $this->get_images(); |
|
|
|
|
61
|
|
|
$this->iframe = $this->get_iframes(); |
|
|
|
|
62
|
|
|
$this->tag_css = $this->get_tag_css(); |
|
|
|
|
63
|
|
|
$this->headings = $this->get_headings(); |
|
|
|
|
64
|
|
|
$this->table = $this->get_nested_table(); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->text = $this->get_text_vars(); |
|
|
|
|
67
|
|
|
$this->keywords = $this->get_keywords(); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this->social_data = $this->get_social_data(); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->server = $this->get_server(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->css = $this->get_style(); |
|
|
|
|
74
|
|
|
$this->js = $this->get_javascript(); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$this->score = $this->get_score(); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$toc = microtime(true); |
81
|
|
|
|
82
|
|
|
$this->time = round( ( $toc - $tic ), 3 ); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
// Return snippet data |
87
|
|
|
public function return_snippet() { |
88
|
|
|
|
89
|
|
|
return array( |
90
|
|
|
'title' => $this->title, |
91
|
|
|
'url' => $this->parsed_url['val'], |
92
|
|
|
'desc' => $this->desc |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
// Return text data |
98
|
|
|
public function return_text() { |
99
|
|
|
|
100
|
|
|
return array( |
101
|
|
|
'count' => $this->text['count'], |
102
|
|
|
'size' => $this->text['size'], |
103
|
|
|
'ratio' => $this->text['ratio'], |
104
|
|
|
'keys' => $this->keywords['value'], |
105
|
|
|
'top_key' => $this->keywords['top'], |
106
|
|
|
'links' => $this->links, |
107
|
|
|
'htags' => $this->headings |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
//Return design data |
113
|
|
|
public function return_design() { |
114
|
|
|
|
115
|
|
|
return array( |
116
|
|
|
'iframe' => $this->iframe, |
117
|
|
|
'image' => $this->images, |
118
|
|
|
'nested_table' => $this->table, |
119
|
|
|
'tag_style' => $this->tag_css, |
120
|
|
|
'vport' => $this->viewport, |
121
|
|
|
'media' => $this->css['media'] |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
//Return crawl data |
127
|
|
|
public function return_crawl() { |
128
|
|
|
|
129
|
|
|
return array( |
130
|
|
|
'val' => $this->parsed_url['val'], |
131
|
|
|
'ssl' => $this->parsed_url['ssl'], |
132
|
|
|
'dynamic' => $this->parsed_url['dynamic'], |
133
|
|
|
'underscore' => $this->parsed_url['underscore'], |
134
|
|
|
'ip' => $this->server['ip'], |
135
|
|
|
'cano' => $this->canonical['ok'], |
136
|
|
|
'if_mod' => $this->server['if_mod'], |
137
|
|
|
'alive' => $this->server['alive'], |
138
|
|
|
'meta_robot' => $this->robot |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
//Return speed data |
144
|
|
|
public function return_speed() { |
145
|
|
|
|
146
|
|
|
return array( |
147
|
|
|
'res_time' => $this->header['time'], |
148
|
|
|
'down_time' => $this->body['time'], |
149
|
|
|
'gzip' => $this->server['gzip'], |
150
|
|
|
'cache' => $this->server['cache'], |
151
|
|
|
'css' => $this->css, |
152
|
|
|
'js' => $this->js |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
// Output the result |
158
|
|
|
public function result() { |
159
|
|
|
|
160
|
|
|
$result = array(); |
161
|
|
|
|
162
|
|
|
$result['score'] = $this->get_score(); |
163
|
|
|
$result['domain'] = $this->parsed_url['domain']; |
164
|
|
|
$result['time'] = $this->time; |
165
|
|
|
$result['snip'] = $this->return_snippet(); |
166
|
|
|
$result['social'] = $this->social_data; |
167
|
|
|
$result['text'] = $this->return_text(); |
168
|
|
|
$result['design'] = $this->return_design(); |
169
|
|
|
$result['crawl'] = $this->return_crawl(); |
170
|
|
|
$result['speed'] = $this->return_speed(); |
171
|
|
|
$result['social_tags'] = $this->social_tags; |
172
|
|
|
|
173
|
|
|
return $result; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
//Calculate score |
178
|
|
|
public function get_score() { |
179
|
|
|
|
180
|
|
|
$score = new Score(); |
181
|
|
|
$score->snippet = $this->return_snippet(); |
182
|
|
|
$score->text = $this->return_text(); |
183
|
|
|
$score->design = $this->return_design(); |
184
|
|
|
$score->crawl = $this->return_crawl(); |
185
|
|
|
$score->speed = $this->return_speed(); |
186
|
|
|
|
187
|
|
|
$score_obtained = $score->calculate(); |
188
|
|
|
return $score_obtained; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
// Analyze the JS |
193
|
|
|
public function get_javascript() { |
194
|
|
|
|
195
|
|
|
$js = new Tags(); |
196
|
|
|
$js->dom = $this->dom; |
197
|
|
|
$js->tag = 'script'; |
198
|
|
|
$js->atts = array( 'src' ); |
199
|
|
|
|
200
|
|
|
$js_list = $js->tag(); |
201
|
|
|
|
202
|
|
|
$js_data = new Design(); |
203
|
|
|
$js_data->js_url = $js_list; |
204
|
|
|
$js_details = $js_data->analyze_js(); |
205
|
|
|
|
206
|
|
|
return $js_details; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
|
211
|
|
|
//Get the Stylesheets |
212
|
|
|
public function get_style() { |
213
|
|
|
|
214
|
|
|
$css = new Tags(); |
215
|
|
|
$css->dom = $this->dom; |
216
|
|
|
$css->tag = 'link'; |
217
|
|
|
$css->specify = array( 'att' => 'rel', 'val' => 'stylesheet', 'get_att' => 'href' ); |
218
|
|
|
|
219
|
|
|
$css_list = $css->tag(); |
220
|
|
|
|
221
|
|
|
$css_data = new Design(); |
222
|
|
|
$css_data->css_url = $css_list; |
223
|
|
|
$css_details = $css_data->analyze_css(); |
224
|
|
|
|
225
|
|
|
return $css_details; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
//Get server data |
230
|
|
|
public function get_server() { |
231
|
|
|
|
232
|
|
|
$server = new Server(); |
233
|
|
|
$server->header = $this->header; |
234
|
|
|
$server->domain = $this->parsed_url['domain']; |
235
|
|
|
|
236
|
|
|
$server_data = array(); |
237
|
|
|
$server_data['gzip'] = $server->gzip(); |
238
|
|
|
$server_data['cache'] = $server->cache(); |
239
|
|
|
$server_data['if_mod'] = $server->if_mod(); |
240
|
|
|
$server_data['alive'] = $server->if_mod(); |
241
|
|
|
$server_data['ip'] = $server->IP(); |
242
|
|
|
|
243
|
|
|
return $server_data; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
|
247
|
|
|
//Get social data from 3rd party API |
248
|
|
|
public function get_social_data() { |
249
|
|
|
|
250
|
|
|
$social = new Social(); |
251
|
|
|
$social->url = $this->url; |
252
|
|
|
|
253
|
|
|
$facebook = $social->fb(); |
254
|
|
|
$social_data['fb_share'] = $facebook['share']; |
|
|
|
|
255
|
|
|
$social_data['fb_like'] = $facebook['like']; |
256
|
|
|
|
257
|
|
|
return $social_data; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
// Get keywords data from text |
262
|
|
|
public function get_keywords() { |
263
|
|
|
|
264
|
|
|
$keys = new Keywords(); |
265
|
|
|
$keys->words = $this->text['words']; |
266
|
|
|
$keys->text = $this->text['text']; |
267
|
|
|
|
268
|
|
|
$keys_data = array(); |
269
|
|
|
$keys_data['value'] = $keys->output(); |
270
|
|
|
$keywords = array_keys($keys_data['value']); |
271
|
|
|
$keys_data['top'] = $keywords[0]; |
272
|
|
|
|
273
|
|
|
return $keys_data; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
//Get text from dom |
278
|
|
|
public function get_text_vars() { |
279
|
|
|
|
280
|
|
|
$text = new Text(); |
281
|
|
|
$text->dom = $this->dom; |
282
|
|
|
$text->body_size = $this->body['size']; |
283
|
|
|
$text->execute(); |
284
|
|
|
$text_string = $text->text(); |
285
|
|
|
$words = $text->words(); |
|
|
|
|
286
|
|
|
|
287
|
|
|
$text_data = array(); |
288
|
|
|
|
289
|
|
|
$words = $text->words(); |
290
|
|
|
$text_data['words'] = $words; |
291
|
|
|
$text_data['text'] = $text_string; |
292
|
|
|
$text_data['count'] = count( $words ); |
293
|
|
|
$size = $text->size(); |
294
|
|
|
$text_data['size'] = round( ( $size / 1024 ), 1 ); |
295
|
|
|
$text_data['ratio'] = $text->ratio(); |
296
|
|
|
|
297
|
|
|
return $text_data; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
//Get nested table |
302
|
|
|
public function get_nested_table() { |
303
|
|
|
|
304
|
|
|
$table = $this->dom->getElementsByTagName( 'table' ); |
305
|
|
|
|
306
|
|
|
$nested_table_count = 0; |
307
|
|
|
if ( $table ) { |
308
|
|
|
foreach ( $table as $obj ) { |
309
|
|
|
$nested_table = $obj->getElementsByTagName( 'table' ); |
|
|
|
|
310
|
|
|
$nested_table_count = ( $nest_table ? $nested_table_count + 1 : $nested_table_count ); |
|
|
|
|
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
return $nested_table_count; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
//Get heading tags |
319
|
|
|
public function get_headings() { |
320
|
|
|
|
321
|
|
|
$all_headings = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ); |
322
|
|
|
|
323
|
|
|
$headings = array(); |
324
|
|
|
foreach ( $all_headings as $value ) { |
325
|
|
|
|
326
|
|
|
$head = new Tags(); |
327
|
|
|
$head->dom = $this->dom; |
328
|
|
|
$head->tag = $value; |
329
|
|
|
$head_tag = $head->tag(); |
330
|
|
|
|
331
|
|
|
$headings[$value] = $head_tag; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
$headings_filtered = array_filter( $headings ); |
335
|
|
|
|
336
|
|
|
$heading = array(); |
337
|
|
|
$heading['names'] = array_keys( $headings_filtered ); |
338
|
|
|
$heading['content'] = $headings_filtered; |
339
|
|
|
|
340
|
|
|
return $heading; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
|
344
|
|
|
//Get style attribute in tags |
345
|
|
|
public function get_tag_css() { |
346
|
|
|
|
347
|
|
|
$tags = array( |
348
|
|
|
'a', 'abbr', 'acronym', 'address', 'applet', 'area', |
349
|
|
|
'b', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blockquote', 'blink', 'body', 'br', 'button', |
350
|
|
|
'caption', 'center', 'cite', 'code', 'col', 'colgroup', |
351
|
|
|
'dd', 'dfn', 'del', 'dir', 'dl', 'div', 'dt', |
352
|
|
|
'embed', 'em', |
353
|
|
|
'fieldset', 'font', 'from', 'frame', 'frameset', |
354
|
|
|
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', |
355
|
|
|
'iframe', 'img', 'input', 'ins', 'isindex', 'i', |
356
|
|
|
'kbd', |
357
|
|
|
'label', 'legend', 'li', 'link', |
358
|
|
|
'marquee', 'menu', 'meta', |
359
|
|
|
'noframe', 'noscript', |
360
|
|
|
'optgroup', 'option', 'ol', |
361
|
|
|
'p', 'pre', |
362
|
|
|
'q', |
363
|
|
|
's', 'samp', 'script', 'select', 'small', 'span', 'strike', 'strong', 'style', 'sub', 'sup', |
364
|
|
|
'table', 'td', 'th', 'tr', 'tbody', 'textarea', 'tfoot', 'thead', 'title', 'tt', |
365
|
|
|
'u', 'ul', |
366
|
|
|
'var' |
367
|
|
|
); |
368
|
|
|
|
369
|
|
|
$tag_style_value = array(); |
370
|
|
|
foreach( $tags as $value ) { |
371
|
|
|
|
372
|
|
|
$tag = new Tags(); |
373
|
|
|
$tag->dom = $this->dom; |
374
|
|
|
$tag->tag = $value; |
375
|
|
|
$tag->specify = array( 'att' => null, 'val' => null, 'get_att' => 'style', ); |
376
|
|
|
|
377
|
|
|
$tag_style = $tag->tag(); |
378
|
|
|
$tag_style_value[] = ( $tag_style ? $value : false ); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$tag_style_filtered = array_filter($tag_style_value); |
382
|
|
|
|
383
|
|
|
$tag_css['count'] = count($tag_style_filtered); |
|
|
|
|
384
|
|
|
$tag_css['tags'] = $tag_style_filtered; |
385
|
|
|
|
386
|
|
|
return $tag_css; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
|
390
|
|
|
//Get the iframes |
391
|
|
|
public function get_iframes() { |
392
|
|
|
|
393
|
|
|
$iframes = new Tags(); |
394
|
|
|
$iframes->dom = $this->dom; |
395
|
|
|
$iframes->tag = 'iframe'; |
396
|
|
|
$iframes->specify = array( 'att' => null, 'val' => null, 'get_att' => 'src' ); |
397
|
|
|
|
398
|
|
|
$get_iframe = $iframes->tag(); |
399
|
|
|
|
400
|
|
|
return $get_iframe; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
//Get the images |
405
|
|
|
public function get_images() { |
406
|
|
|
|
407
|
|
|
$images = new Tags(); |
408
|
|
|
$images->dom = $this->dom; |
409
|
|
|
$images->tag = 'img'; |
410
|
|
|
$images->atts = array( 'src', 'alt' ); |
411
|
|
|
|
412
|
|
|
$attributes = $images->atts(); |
413
|
|
|
|
414
|
|
|
$alts = $attributes['alt']; |
415
|
|
|
$srcs = $attributes['src']; |
416
|
|
|
$pure_alt = array_filter($alts); |
417
|
|
|
|
418
|
|
|
$image_data = array(); |
419
|
|
|
$image_data['count'] = count($srcs); |
420
|
|
|
$image_data['alt_value'] = $pure_alt; |
421
|
|
|
$image_data['no_alt_count'] = count($srcs) - count($pure_alt); |
422
|
|
|
|
423
|
|
|
return $image_data; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
|
427
|
|
|
// Get the links |
428
|
|
|
public function get_links() { |
429
|
|
|
|
430
|
|
|
$links = new Tags(); |
431
|
|
|
$links->dom = $this->dom; |
432
|
|
|
$links->tag = 'a'; |
433
|
|
|
$links->atts = array( 'rel', 'href' ); |
434
|
|
|
|
435
|
|
|
$attributes = $links->atts(); |
436
|
|
|
$anchors = $links->tag(); |
437
|
|
|
|
438
|
|
|
$rels = $attributes['rel']; |
439
|
|
|
$hrefs = $attributes['href']; |
440
|
|
|
|
441
|
|
|
$domain = $this->parsed_url['domain']; |
442
|
|
|
|
443
|
|
|
$link_num = 0; |
444
|
|
|
$ext_link_num = 0; |
445
|
|
|
foreach ($hrefs as $value) { |
446
|
|
|
if (filter_var($value, FILTER_VALIDATE_URL)) { |
447
|
|
|
$link_num = $link_num + 1; |
448
|
|
|
|
449
|
|
|
if( parse_url($value, PHP_URL_HOST) == $domain ) { |
450
|
|
|
$ext_link_num = $ext_link_num + 1; |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$nofollow_link_num = 0; |
456
|
|
|
foreach ($rels as $value) { |
457
|
|
|
if( strpos($value, 'nofollow') !== false ) { |
458
|
|
|
$nofollow_link_num = $nofollow_link_num +1; |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
$no_txt_link_num = count($anchors) - count(array_filter($anchors)); |
463
|
|
|
$anchor_text = implode(' ', $anchors); |
464
|
|
|
|
465
|
|
|
$link_data = array(); |
466
|
|
|
$link_data['count'] = $link_num; |
467
|
|
|
$link_data['nofollow'] = $nofollow_link_num; |
468
|
|
|
$link_data['external'] = $link_num - $ext_link_num; |
469
|
|
|
$link_data['no_text'] = $no_txt_link_num; |
470
|
|
|
$link_data['anchors'] = $anchor_text; |
471
|
|
|
|
472
|
|
|
return $link_data; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
|
476
|
|
|
|
477
|
|
|
// Get the OGP and Twitter card tags |
478
|
|
|
public function get_social_tags() { |
479
|
|
|
|
480
|
|
|
$tags = array('title', 'description', 'url', 'image'); |
481
|
|
|
$social_tag_val = array(); |
482
|
|
|
foreach( $tags as $value ) { |
483
|
|
|
|
484
|
|
|
$social_tag = new Tags(); |
485
|
|
|
$social_tag->dom = $this->dom; |
486
|
|
|
$social_tag->tag = 'meta'; |
487
|
|
|
$social_tag->specify = array('att' => 'property', 'val' => 'og:'.$value, 'get_att' => 'content'); |
488
|
|
|
$social_tag_fetch = $social_tag->tag(); |
489
|
|
|
|
490
|
|
|
$social_tag_val[$value] = ( $social_tag_fetch ? array_pop($social_tag_fetch) : false ); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
return $social_tag_val; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
|
497
|
|
|
// Get viewport tag |
498
|
|
|
public function get_viewport() { |
499
|
|
|
|
500
|
|
|
$viewport = new Tags(); |
501
|
|
|
$viewport->dom = $this->dom; |
502
|
|
|
$viewport->tag = 'meta'; |
503
|
|
|
$viewport->specify = array( 'att' => 'name', 'val' => 'viewport', 'get_att' => 'content' ); |
504
|
|
|
$viewport_tag = $viewport->tag(); |
505
|
|
|
|
506
|
|
|
$meta_viewport_val = ( $viewport_tag ? array_pop($viewport_tag) : false ); |
507
|
|
|
$meta_viewport = ( $meta_viewport_val && $meta_viewport_val != '' ) ? 1 : 0; |
508
|
|
|
|
509
|
|
|
return $meta_viewport; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
|
513
|
|
|
|
514
|
|
|
// Get meta canonical |
515
|
|
|
public function get_canonical() { |
516
|
|
|
|
517
|
|
|
$meta_canonical = array(); |
518
|
|
|
|
519
|
|
|
$canonical = new Tags(); |
520
|
|
|
$canonical->dom = $this->dom; |
521
|
|
|
$canonical->tag = 'meta'; |
522
|
|
|
$canonical->specify = array( 'att' => 'rel', 'val' => 'canonical', 'get_att' => 'href' ); |
523
|
|
|
$canonical_tag = $canonical->tag(); |
524
|
|
|
|
525
|
|
|
$meta_canonical['val'] = ( $canonical_tag ? esc_url_raw(array_pop($canonical_tag)) : false ); |
|
|
|
|
526
|
|
|
$meta_canonical['ok'] = ( $meta_canonical['val'] && $meta_canonical['val'] != '' ) ? 1 : 0; |
527
|
|
|
|
528
|
|
|
return $meta_canonical; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
|
532
|
|
|
|
533
|
|
|
// Get meta robots |
534
|
|
|
public function get_robot() { |
535
|
|
|
|
536
|
|
|
$meta_robot = array(); |
537
|
|
|
|
538
|
|
|
$robot = new Tags(); |
539
|
|
|
$robot->dom = $this->dom; |
540
|
|
|
$robot->tag = 'meta'; |
541
|
|
|
$robot->specify = array( 'att' => 'name', 'val' => 'robots', 'get_att' => 'content' ); |
542
|
|
|
$robot_tag = $robot->tag(); |
543
|
|
|
|
544
|
|
|
$meta_robot['val'] = ( $robot_tag ? array_pop($robot_tag) : false ); |
545
|
|
|
$meta_robot['ok'] = $meta_robot['val'] && strpos($meta_robot['val'], 'index') !== false && strpos($meta_robot['val'], 'follow') !== false ? 1 : 0; |
546
|
|
|
|
547
|
|
|
return $meta_robot; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
|
551
|
|
|
|
552
|
|
|
// Get page description |
553
|
|
|
public function get_desc() { |
554
|
|
|
|
555
|
|
|
$description = new Tags(); |
556
|
|
|
$description->dom = $this->dom; |
557
|
|
|
$description->tag = 'meta'; |
558
|
|
|
$description->specify = array( 'att' => 'name', 'val' => 'description', 'get_att' => 'content' ); |
559
|
|
|
$desc = $description->tag(); |
560
|
|
|
|
561
|
|
|
return ( $desc ? array_pop($desc) : false ); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
|
565
|
|
|
|
566
|
|
|
// Get the page title |
567
|
|
|
public function get_title() { |
568
|
|
|
|
569
|
|
|
$title_fetch = new Tags(); |
570
|
|
|
$title_fetch->dom = $this->dom; |
571
|
|
|
$title_fetch->tag = 'title'; |
572
|
|
|
$title = $title_fetch->tag(); |
573
|
|
|
|
574
|
|
|
return ( $title ? array_pop($title) : false ); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
|
578
|
|
|
// Get the body |
579
|
|
|
public function get_body() { |
580
|
|
|
|
581
|
|
|
$response = array(); |
582
|
|
|
|
583
|
|
|
$start = microtime(true); |
584
|
|
|
$body = @file_get_contents( $this->url, FILE_USE_INCLUDE_PATH ); |
|
|
|
|
585
|
|
|
$end = microtime(true); |
586
|
|
|
|
587
|
|
|
$response['ok'] = empty($body) ? false : true; |
588
|
|
|
$response['time'] = round( ( $end - $start ), 3 ); |
589
|
|
|
$response['body'] = $body; |
590
|
|
|
$response['size'] = mb_strlen( $body, '8bit' ); |
|
|
|
|
591
|
|
|
|
592
|
|
|
return $response; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
|
596
|
|
|
|
597
|
|
|
// Check the header |
598
|
|
|
public function header_check() { |
599
|
|
|
|
600
|
|
|
$response = array(); |
601
|
|
|
|
602
|
|
|
$start = microtime(true); |
603
|
|
|
$header = get_headers( $this->url, 1 ); |
604
|
|
|
$end = microtime(true); |
605
|
|
|
|
606
|
|
|
$response['time'] = round( ( $end - $start ), 3 ); |
607
|
|
|
$response['response'] = $header[0]; |
608
|
|
|
$response['ok'] = (strchr($header[0], '200') != false) ? true : false; |
|
|
|
|
609
|
|
|
|
610
|
|
|
return $response; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
|
614
|
|
|
|
615
|
|
|
// Parse the URL |
616
|
|
|
public function parse_url() { |
617
|
|
|
|
618
|
|
|
$parse = array(); |
619
|
|
|
$parsed_url = parse_url($this->url); |
620
|
|
|
|
621
|
|
|
$parse['val'] = $this->url; |
622
|
|
|
$parse['domain'] = $parsed_url['host']; |
623
|
|
|
$parse['ssl'] = $parsed_url['scheme'] == 'http' ? false : true; |
624
|
|
|
$parse['dynamic'] = array_key_exists('query', $parsed_url) ? true : false; |
625
|
|
|
$parse['underscore'] = ( strpos($this->url, '_') !== false ) ? true : false; |
626
|
|
|
|
627
|
|
|
return $parse; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
|
631
|
|
|
// No scan possible notice |
632
|
|
|
public function no_body_scan() { ?> |
633
|
|
|
|
634
|
|
|
<div class="notice notice-error"> |
635
|
|
|
<p><?php _e( 'The page could not be downloaded. Try again', 'cgss' ); ?></p> |
|
|
|
|
636
|
|
|
</div> |
637
|
|
|
<?PHP |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
|
641
|
|
|
// No scan possible notice |
642
|
|
|
public function no_header_scan() { ?> |
643
|
|
|
|
644
|
|
|
<div class="notice notice-error"> |
645
|
|
|
<p><?php _e( 'The header returned is not Ok. Try again', 'cgss' ); ?></p> |
|
|
|
|
646
|
|
|
</div> |
647
|
|
|
<?PHP |
648
|
|
|
} |
649
|
|
|
} ?> |
650
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths