Total Complexity | 124 |
Total Lines | 962 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Complex classes like Analyze often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Analyze, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Analyze extends PreRequirements |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var array $data |
||
17 | */ |
||
18 | private $data; |
||
19 | |||
20 | |||
21 | /** |
||
22 | * @var Helpers $helpers |
||
23 | */ |
||
24 | private $helpers; |
||
25 | |||
26 | /** |
||
27 | * @var DOMDocument $dom |
||
28 | */ |
||
29 | private $dom; |
||
30 | |||
31 | /** |
||
32 | * Initialize from URL via Guzzle |
||
33 | * |
||
34 | * @param string $url |
||
35 | * @return $this |
||
36 | */ |
||
37 | public function __construct($url) |
||
38 | { |
||
39 | $started_on = microtime(true); |
||
40 | $response = $this->Request($url); |
||
41 | |||
42 | $parsed_url = parse_url($url); |
||
43 | $dns_recods = (array) @dns_get_record($parsed_url['host']); |
||
44 | |||
45 | $this->data = [ |
||
46 | 'url' => $url, |
||
47 | 'parsed_url' => $parsed_url, |
||
48 | 'status' => $response->getStatusCode(), |
||
49 | 'headers' => $response->getHeaders(), |
||
50 | 'page_speed' => number_format(( microtime(true) - $started_on), 4), |
||
51 | 'dns_records' => $dns_recods, |
||
52 | 'content' => $response->getBody()->getContents() |
||
53 | ]; |
||
54 | |||
55 | $this->helpers = new Helpers($this->data); |
||
56 | |||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Initialize DOMDocument |
||
62 | * |
||
63 | * @return DOMDocument |
||
64 | */ |
||
65 | private function DOMDocument() |
||
66 | { |
||
67 | libxml_use_internal_errors(true); |
||
68 | |||
69 | $this->dom = new DOMDocument(); |
||
70 | |||
71 | return $this->dom; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Initialize DOMXPath |
||
76 | * |
||
77 | * @return DOMXPath |
||
78 | */ |
||
79 | private function DOMXPath() |
||
80 | { |
||
81 | return new DOMXPath($this->dom); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Standardizes output |
||
86 | * |
||
87 | * @param mixed $return |
||
88 | * @param string $service |
||
89 | * @return array |
||
90 | */ |
||
91 | private function Output($return, $service) |
||
92 | { |
||
93 | return [ |
||
94 | 'url' => $this->data['url'], |
||
95 | 'status' => $this->data['status'], |
||
96 | 'headers' => $this->data['headers'], |
||
97 | 'service' => preg_replace("([A-Z])", " $0", $service), |
||
98 | 'time' => time(), |
||
99 | 'data' => $return |
||
100 | ]; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Analyze Broken Links in a page |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | public function BrokenLinks() |
||
109 | { |
||
110 | $dom = $this->DOMDocument(); |
||
111 | $dom->loadHTML($this->data['content']); |
||
112 | |||
113 | $links = $this->helpers->Links($dom)->GetLinks(); |
||
114 | $scan = ['errors' => [], 'passed' => []]; |
||
115 | $i = 0; |
||
116 | |||
117 | foreach ($links as $key => $link) |
||
118 | { |
||
119 | $i++; |
||
120 | |||
121 | if($i >= 25) |
||
122 | break; |
||
123 | |||
124 | $status = $this->Request($link)->getStatusCode(); |
||
125 | |||
126 | if(substr($status,0,1) > 3 && $status != 999) |
||
127 | $scan['errors']["HTTP {$status}"][] = $link; |
||
128 | else |
||
129 | $scan['passed']["HTTP {$status}"][] = $link; |
||
130 | } |
||
131 | return $this->Output([ |
||
132 | 'links' => $links, |
||
133 | 'scanned' => $scan |
||
134 | ], __FUNCTION__); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Checks header parameters if there is something about cache |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | public function Cache() |
||
143 | { |
||
144 | $output = ['headers' => [], 'html' => []]; |
||
145 | |||
146 | foreach ($this->data['headers'] as $header) |
||
147 | { |
||
148 | foreach ($header as $item) |
||
149 | { |
||
150 | if(strpos(mb_strtolower($item),'cache') !== false) |
||
151 | { |
||
152 | $output['headers'][] = $item; |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | |||
157 | $dom = $this->DOMDocument(); |
||
158 | $dom->loadHTML($this->data['content']); |
||
159 | $xpath = $this->DOMXPath(); |
||
160 | |||
161 | foreach ($xpath->query('//comment()') as $comment) |
||
162 | { |
||
163 | if(strpos(mb_strtolower($comment->textContent),'cache') !== false) |
||
164 | { |
||
165 | $output['html'][] = '<!-- '.trim($comment->textContent).' //-->'; |
||
166 | } |
||
167 | } |
||
168 | return $this->Output($output, __FUNCTION__); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Checks canonical tag |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | public function CanonicalTag() |
||
177 | { |
||
178 | $dom = $this->DOMDocument(); |
||
179 | $dom->loadHTML($this->data['content']); |
||
180 | $output = array(); |
||
181 | $links = $this->helpers->GetAttributes($dom, 'link', 'rel'); |
||
182 | |||
183 | foreach($links as $item) |
||
184 | { |
||
185 | if($item == 'canonical') |
||
186 | { |
||
187 | $output[] = $item; |
||
188 | } |
||
189 | } |
||
190 | |||
191 | return $this->Output($output, __FUNCTION__); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Determines character set from headers |
||
196 | * |
||
197 | * @TODO: Use Regex instead of explode |
||
198 | * @return array |
||
199 | */ |
||
200 | public function CharacterSet() |
||
201 | { |
||
202 | $output = ''; |
||
203 | |||
204 | foreach ($this->data['headers'] as $key => $header) |
||
205 | { |
||
206 | if($key == 'Content-Type') |
||
207 | { |
||
208 | $output = explode('=', explode(';',$header[0])[1])[1]; |
||
209 | } |
||
210 | } |
||
211 | return $this->Output($output, __FUNCTION__); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Calculates code / content percentage |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function CodeContent() |
||
220 | { |
||
221 | $page_size = mb_strlen($this->data['content'], 'utf8'); |
||
222 | $dom = $this->DOMDocument(); |
||
223 | $dom->loadHTML($this->data['content']); |
||
224 | |||
225 | $script = $dom->getElementsByTagName('script'); |
||
226 | $remove = array(); |
||
227 | |||
228 | foreach ($script as $item) |
||
229 | { |
||
230 | $remove[] = $item; |
||
231 | } |
||
232 | |||
233 | foreach ($remove as $item) |
||
234 | { |
||
235 | $item->parentNode->removeChild($item); |
||
236 | } |
||
237 | |||
238 | $page = $dom->saveHTML(); |
||
239 | $content_size = mb_strlen(strip_tags($page), 'utf8'); |
||
240 | $rate = (round($content_size / $page_size * 100)); |
||
241 | $output = array( |
||
242 | 'page_size' => $page_size, |
||
243 | 'code_size' => ($page_size - $content_size), |
||
244 | 'content_size' => $content_size, |
||
245 | 'content' => $this->helpers->Whitespace(strip_tags($page)), |
||
246 | 'percentage' => "$rate%" |
||
247 | ); |
||
248 | |||
249 | return $this->Output($output, __FUNCTION__); |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * Checks deprecated HTML tag usage |
||
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | public function DeprecatedHTML() |
||
258 | { |
||
259 | $dom = $this->DOMDocument(); |
||
260 | $dom->loadHTML($this->data['content']); |
||
261 | |||
262 | $deprecated_tags = array( |
||
263 | 'acronym', |
||
264 | 'applet', |
||
265 | 'basefont', |
||
266 | 'big', |
||
267 | 'center', |
||
268 | 'dir', |
||
269 | 'font', |
||
270 | 'frame', |
||
271 | 'frameset', |
||
272 | 'isindex', |
||
273 | 'noframes', |
||
274 | 's', |
||
275 | 'strike', |
||
276 | 'tt', |
||
277 | 'u' |
||
278 | ); |
||
279 | |||
280 | $output = array(); |
||
281 | |||
282 | foreach ($deprecated_tags as $tag) |
||
283 | { |
||
284 | $tags = $dom->getElementsByTagName($tag); |
||
285 | |||
286 | if($tags->length > 0) |
||
287 | { |
||
288 | $output[$tag] = $tags->length; |
||
289 | } |
||
290 | } |
||
291 | |||
292 | return $this->Output($output, __FUNCTION__); |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * Determines length of the domain |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function DomainLength() |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * Looks for a favicon |
||
313 | * |
||
314 | * @return array |
||
315 | */ |
||
316 | public function Favicon() |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * Checks if there is a frame in the page |
||
361 | * |
||
362 | * @return array |
||
363 | */ |
||
364 | public function Frameset() |
||
365 | { |
||
366 | $dom = $this->DOMDocument(); |
||
367 | $dom->loadHTML($this->data['content']); |
||
368 | |||
369 | $tags = $dom->getElementsByTagName('frameset'); |
||
370 | $output = ['frameset' => [], 'frame' => []]; |
||
371 | foreach ($tags as $tag) |
||
372 | { |
||
373 | $output['frameset'][] = null; |
||
374 | } |
||
375 | |||
376 | $tags = $dom->getElementsByTagName('frame'); |
||
377 | foreach ($tags as $tag) |
||
378 | { |
||
379 | $output['frame'][] = null; |
||
380 | } |
||
381 | |||
382 | return $this->Output([ |
||
383 | 'frameset' => count($output['frameset']), |
||
384 | 'frame' => count($output['frame']) |
||
385 | ], __FUNCTION__); |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Finds Google Analytics code |
||
390 | * |
||
391 | * @return array |
||
392 | */ |
||
393 | public function GoogleAnalytics() |
||
394 | { |
||
395 | $dom = $this->DOMDocument(); |
||
396 | $dom->loadHTML($this->data['content']); |
||
397 | |||
398 | $script = ''; |
||
399 | |||
400 | $tags = $dom->getElementsByTagName('script'); |
||
401 | foreach ($tags as $tag) |
||
402 | { |
||
403 | if($tag->getAttribute('src')) |
||
404 | { |
||
405 | if (0 === strpos($tag->getAttribute('src'), '//')) |
||
406 | { |
||
407 | $href = $this->data['parsed_url']['scheme'] . ':'.$tag->getAttribute('src'); |
||
408 | } else if (0 !== strpos($tag->getAttribute('src'), 'http')) |
||
409 | { |
||
410 | $path = '/' . ltrim($tag->getAttribute('src'), '/'); |
||
411 | $href = $this->data['parsed_url']['scheme'] . '://'; |
||
412 | |||
413 | if (isset($this->data['parsed_url']['user']) && isset($this->data['parsed_url']['pass'])) |
||
414 | { |
||
415 | $href .= $this->data['parsed_url']['user'] . ':' . $this->data['parsed_url']['pass'] . '@'; |
||
416 | } |
||
417 | |||
418 | $href .= $this->data['parsed_url']['host']; |
||
419 | |||
420 | if (isset($this->data['parsed_url']['port'])) |
||
421 | { |
||
422 | $href .= ':' . $this->data['parsed_url']['port']; |
||
423 | } |
||
424 | $href .= $path; |
||
425 | } else { |
||
426 | $href = $tag->getAttribute('src'); |
||
427 | } |
||
428 | |||
429 | $script .= $this->Request($href)->getBody()->getContents(); |
||
430 | } else { |
||
431 | $script .= $tag->nodeValue; |
||
432 | } |
||
433 | } |
||
434 | |||
435 | $ua_regex = "/UA-[0-9]{5,}-[0-9]{1,}/"; |
||
436 | |||
437 | preg_match_all($ua_regex, $script, $ua_id); |
||
438 | |||
439 | return $this->Output($ua_id[0][0], __FUNCTION__); |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * Checks h1 HTML tag usage |
||
444 | * |
||
445 | * @return array |
||
446 | */ |
||
447 | public function Header1() |
||
448 | { |
||
449 | $dom = $this->DOMDocument(); |
||
450 | $dom->loadHTML($this->data['content']); |
||
451 | |||
452 | $tags = $dom->getElementsByTagName('h1'); |
||
453 | $output = array(); |
||
454 | foreach ($tags as $tag) |
||
455 | { |
||
456 | $output[] = $tag->nodeValue; |
||
457 | } |
||
458 | |||
459 | return $this->Output($output, __FUNCTION__); |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * Checks h2 HTML tag usage |
||
464 | * |
||
465 | * @return array |
||
466 | */ |
||
467 | public function Header2() |
||
468 | { |
||
469 | $dom = $this->DOMDocument(); |
||
470 | $dom->loadHTML($this->data['content']); |
||
471 | |||
472 | $tags = $dom->getElementsByTagName('h2'); |
||
473 | $output = array(); |
||
474 | foreach ($tags as $tag) |
||
475 | { |
||
476 | $output[] = $tag->nodeValue; |
||
477 | } |
||
478 | |||
479 | return $this->Output($output, __FUNCTION__); |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Checks HTTPS |
||
484 | * |
||
485 | * @return array |
||
486 | */ |
||
487 | public function Https() |
||
488 | { |
||
489 | $https = ($this->data['parsed_url']['scheme'] === 'https') ? true : false; |
||
490 | |||
491 | return $this->Output($https, __FUNCTION__); |
||
492 | } |
||
493 | |||
494 | /** |
||
495 | * Checks empty image alts |
||
496 | * |
||
497 | * @return array |
||
498 | */ |
||
499 | public function ImageAlt() |
||
500 | { |
||
501 | $dom = $this->DOMDocument(); |
||
502 | $dom->loadHTML($this->data['content']); |
||
503 | |||
504 | $tags = $dom->getElementsByTagName('img'); |
||
505 | $images = array(); |
||
506 | $errors = array(); |
||
507 | |||
508 | foreach($tags as $item) |
||
509 | { |
||
510 | $src = $item->getAttribute('src'); |
||
511 | $alt = $item->getAttribute('alt'); |
||
512 | |||
513 | $images[] = array( |
||
514 | 'src' => $src, |
||
515 | 'alt' => $alt |
||
516 | ); |
||
517 | |||
518 | if($alt == '') |
||
519 | { |
||
520 | $link = $src; |
||
521 | |||
522 | $errors[] = $link; |
||
523 | } |
||
524 | } |
||
525 | |||
526 | $output = array( |
||
527 | 'images' => $images, |
||
528 | 'without_alt' => $errors |
||
529 | ); |
||
530 | |||
531 | return $this->Output($output, __FUNCTION__); |
||
532 | } |
||
533 | |||
534 | /** |
||
535 | * Gets inbound links |
||
536 | * |
||
537 | * @return array |
||
538 | */ |
||
539 | public function InboundLinks() |
||
540 | { |
||
541 | $dom = $this->DOMDocument(); |
||
542 | $dom->loadHTML($this->data['content']); |
||
543 | |||
544 | $tags = $dom->getElementsByTagName('a'); |
||
545 | $output = array(); |
||
546 | |||
547 | foreach($tags as $item) |
||
548 | { |
||
549 | $link = $item->getAttribute('href'); |
||
550 | |||
551 | if($link != '' && strpos($link,'#') !== 0) |
||
552 | { |
||
553 | $link = parse_url($link); |
||
554 | |||
555 | if(!isset($link['scheme'])) |
||
556 | { |
||
557 | $link['scheme'] = $this->data['parsed_url']['scheme']; |
||
558 | } |
||
559 | |||
560 | if(!isset($link['host'])) |
||
561 | { |
||
562 | $link['host'] = $this->data['parsed_url']['host']; |
||
563 | } |
||
564 | |||
565 | if(!isset($link['path'])) |
||
566 | { |
||
567 | $link['path'] = ''; |
||
568 | } else { |
||
569 | if(strpos($link['path'],'/') === false) |
||
570 | { |
||
571 | $link['path'] = '/'.$link['path']; |
||
572 | } |
||
573 | } |
||
574 | |||
575 | if(!isset($link['query'])) |
||
576 | { |
||
577 | $link['query'] = ''; |
||
578 | } else { |
||
579 | $link['query'] = '?'.$link['query']; |
||
580 | } |
||
581 | |||
582 | $output[] = $link['scheme'].'://'.$link['host'].$link['path'].$link['query']; |
||
583 | } |
||
584 | } |
||
585 | |||
586 | foreach ($output as $key => $link) |
||
587 | { |
||
588 | if (parse_url($link)['host'] != $this->data['parsed_url']['host']) { |
||
589 | unset($output[$key]); |
||
590 | continue; |
||
591 | } |
||
592 | } |
||
593 | |||
594 | return $this->Output($output, __FUNCTION__); |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * Gets inbound links |
||
599 | * |
||
600 | * @return array |
||
601 | */ |
||
602 | public function InlineCss() |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Gets meta description |
||
620 | * |
||
621 | * @return array |
||
622 | */ |
||
623 | public function MetaDescription() |
||
624 | { |
||
625 | $dom = $this->DOMDocument(); |
||
626 | $dom->loadHTML($this->data['content']); |
||
627 | $tags = $dom->getElementsByTagName('meta'); |
||
628 | $output = ''; |
||
629 | foreach ($tags as $tag) |
||
630 | { |
||
631 | $content = $tag->getAttribute('content'); |
||
632 | if(strtolower($tag->getAttribute('name')) == 'description' && strlen($content) > 0) |
||
633 | { |
||
634 | $output = $content; |
||
635 | } |
||
636 | } |
||
637 | |||
638 | return $this->Output($output, __FUNCTION__); |
||
639 | } |
||
640 | |||
641 | /** |
||
642 | * Gets meta title |
||
643 | * |
||
644 | * @return array |
||
645 | */ |
||
646 | public function MetaTitle() |
||
663 | } |
||
664 | |||
665 | /** |
||
666 | * Gets no-follow tag |
||
667 | * |
||
668 | * @return array |
||
669 | */ |
||
670 | public function NofollowTag() |
||
671 | { |
||
672 | $dom = $this->DOMDocument(); |
||
673 | $dom->loadHTML($this->data['content']); |
||
674 | |||
675 | $tags = $dom->getElementsByTagName('meta'); |
||
676 | $output = array(); |
||
677 | foreach ($tags as $tag) |
||
678 | { |
||
679 | if($tag->getAttribute('name') == 'robots') |
||
680 | { |
||
681 | $output[] = $tag->getAttribute('content'); |
||
682 | } |
||
683 | } |
||
684 | |||
685 | return $this->Output(in_array('nofollow',$output), __FUNCTION__); |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * Gets no-index tag |
||
690 | * |
||
691 | * @return array |
||
692 | */ |
||
693 | public function NoindexTag() |
||
694 | { |
||
695 | $dom = $this->DOMDocument(); |
||
696 | $dom->loadHTML($this->data['content']); |
||
697 | |||
698 | $tags = $dom->getElementsByTagName('meta'); |
||
699 | $output = array(); |
||
700 | foreach ($tags as $tag) |
||
701 | { |
||
702 | if($tag->getAttribute('name') == 'robots') |
||
703 | { |
||
704 | $output[] = $tag->getAttribute('content'); |
||
705 | } |
||
706 | } |
||
707 | |||
708 | return $this->Output(in_array('noindex',$output), __FUNCTION__); |
||
709 | } |
||
710 | |||
711 | /** |
||
712 | * Counts objects in a page |
||
713 | * |
||
714 | * @return array |
||
715 | */ |
||
716 | public function ObjectCount() |
||
717 | { |
||
718 | $dom = $this->DOMDocument(); |
||
719 | $dom->loadHTML($this->data['content']); |
||
720 | |||
721 | $output = array( |
||
722 | 'css' => array(), |
||
723 | 'script' => array(), |
||
724 | 'img' => array() |
||
725 | ); |
||
726 | |||
727 | $tags = $dom->getElementsByTagName('link'); |
||
728 | foreach ($tags as $tag) |
||
729 | { |
||
730 | if($tag->getAttribute('type') == 'text/css' OR $tag->getAttribute('rel') == 'stylesheet') |
||
731 | { |
||
732 | $output['css'][] = $tag->getAttribute('href'); |
||
733 | } |
||
734 | } |
||
735 | $output['css'] = array_unique($output['css']); |
||
736 | |||
737 | $tags = $dom->getElementsByTagName('script'); |
||
738 | foreach ($tags as $tag) |
||
739 | { |
||
740 | if($tag->getAttribute('src') != '') |
||
741 | { |
||
742 | $output['script'][] = $tag->getAttribute('src'); |
||
743 | } |
||
744 | } |
||
745 | $output['script'] = array_unique($output['script']); |
||
746 | |||
747 | $tags = $dom->getElementsByTagName('img'); |
||
748 | foreach ($tags as $tag) |
||
749 | { |
||
750 | if($tag->getAttribute('src') != '') |
||
751 | { |
||
752 | $output['img'][] = $tag->getAttribute('src'); |
||
753 | } |
||
754 | } |
||
755 | $output['img'] = array_unique($output['img']); |
||
756 | |||
757 | return $this->Output($output, __FUNCTION__); |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * Calculates page speed |
||
762 | * |
||
763 | * @return array |
||
764 | */ |
||
765 | public function PageSpeed() |
||
766 | { |
||
767 | return $this->Output($this->data['page_speed'], __FUNCTION__); |
||
768 | } |
||
769 | |||
770 | /** |
||
771 | * Checks if there is some plaintext email |
||
772 | * |
||
773 | * @return array |
||
774 | */ |
||
775 | public function PlaintextEmail() |
||
776 | { |
||
777 | $dom = $this->DOMDocument(); |
||
778 | $dom->loadHTML($this->data['content']); |
||
779 | |||
780 | $script = $dom->getElementsByTagName('script'); |
||
781 | $remove = array(); |
||
782 | |||
783 | foreach($script as $item) |
||
784 | { |
||
785 | $remove[] = $item; |
||
786 | } |
||
787 | |||
788 | foreach ($remove as $item) |
||
789 | { |
||
790 | $item->parentNode->removeChild($item); |
||
791 | } |
||
792 | $style = $dom->getElementsByTagName('style'); |
||
793 | $remove = array(); |
||
794 | |||
795 | foreach($style as $item) |
||
796 | { |
||
797 | $remove[] = $item; |
||
798 | } |
||
799 | |||
800 | foreach ($remove as $item) |
||
801 | { |
||
802 | $item->parentNode->removeChild($item); |
||
803 | } |
||
804 | |||
805 | $page = $dom->saveHTML(); |
||
806 | $page = trim(preg_replace('/<[^>]*>/', ' ', $page)); |
||
807 | $page = preg_replace('/\s+/', ' ',$page); |
||
808 | $page = explode(' ',$page); |
||
809 | |||
810 | $output = array(); |
||
811 | foreach ($page as $item) |
||
812 | { |
||
813 | $item = trim($item); |
||
814 | |||
815 | if($item != '' && strpos($item,'@') !== false) |
||
816 | { |
||
817 | if (!filter_var($item, FILTER_VALIDATE_EMAIL) === false) { |
||
818 | $output[] = $item; |
||
819 | } |
||
820 | } |
||
821 | } |
||
822 | |||
823 | $output = array_unique($output); |
||
824 | |||
825 | return $this->Output($output, __FUNCTION__); |
||
826 | } |
||
827 | |||
828 | /** |
||
829 | * Checks HTML page compression |
||
830 | * |
||
831 | * @return array |
||
832 | */ |
||
833 | public function PageCompression() |
||
834 | { |
||
835 | $output = array(); |
||
836 | |||
837 | $output['actual'] = round(strlen($this->data['content']) / 1024,2); |
||
838 | $output['possible'] = gzcompress($this->data['content'], 9); |
||
839 | $output['possible'] = round(strlen($output['possible']) / 1024,2); |
||
840 | $output['percentage'] = round((($output['possible'] * 100) / $output['actual']),2); |
||
841 | $output['difference'] = round($output['actual'] - $output['possible'],2); |
||
842 | |||
843 | return $this->Output($output, __FUNCTION__); |
||
844 | } |
||
845 | |||
846 | /** |
||
847 | * Checks robots.txt |
||
848 | * |
||
849 | * @return array |
||
850 | */ |
||
851 | public function RobotsFile() |
||
852 | { |
||
853 | $output = $this->Request("{$this->data['parsed_url']['scheme']}://{$this->data['parsed_url']['host']}/robots.txt"); |
||
854 | |||
855 | if($output->getStatusCode() === 200) |
||
856 | { |
||
857 | $output = $output->getBody()->getContents(); |
||
858 | } else { |
||
859 | $output = false; |
||
860 | } |
||
861 | |||
862 | return $this->Output($output, __FUNCTION__); |
||
863 | } |
||
864 | |||
865 | /** |
||
866 | * Server signature |
||
867 | * |
||
868 | * @return array |
||
869 | */ |
||
870 | public function ServerSignature() |
||
890 | } |
||
891 | |||
892 | /** |
||
893 | * Social media accounts |
||
894 | * |
||
895 | * @return array |
||
896 | */ |
||
897 | public function SocialMedia() |
||
898 | { |
||
899 | $socials = array( |
||
900 | 'Facebook' => 'facebook.com', |
||
901 | 'Twitter' => 'twitter.com', |
||
902 | 'LinkedIn' => 'linkedin.com', |
||
903 | 'YouTube' => 'youtube.com', |
||
904 | 'GitHub' => 'github.com' |
||
905 | ); |
||
906 | |||
907 | $output = array(); |
||
908 | $dom = $this->DOMDocument(); |
||
909 | $dom->loadHTML($this->data['content']); |
||
910 | |||
925 | } |
||
926 | |||
927 | /** |
||
928 | * SPF record |
||
929 | * |
||
930 | * @return array |
||
931 | */ |
||
932 | public function SpfRecord() |
||
933 | { |
||
934 | $output = array(); |
||
935 | foreach ($this->data['dns_records'] as $record) |
||
936 | { |
||
937 | if (strtoupper($record['type']) == 'TXT' && strpos($record['txt'],'spf') !== false) |
||
938 | { |
||
939 | $output[] = $record['txt']; |
||
940 | } |
||
941 | |||
942 | } |
||
943 | |||
944 | return $this->Output($output, __FUNCTION__); |
||
945 | } |
||
946 | |||
947 | /** |
||
948 | * Underscored links |
||
949 | * |
||
950 | * @return array |
||
951 | */ |
||
952 | public function UnderscoredLinks() |
||
974 | } |
||
975 | } |