|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NirjharLo\Cgss\Lib\Action; |
|
4
|
|
|
|
|
5
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
|
6
|
|
|
|
|
7
|
|
|
use \NirjharLo\Cgss\Lib\Analysis\Crawl; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Perform scan action |
|
11
|
|
|
*/ |
|
12
|
|
|
final class Scan { |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public function __construct() { |
|
16
|
|
|
|
|
17
|
|
|
$post_id = intval($_GET['scan']); |
|
18
|
|
|
$url = get_permalink( $post_id ); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
$crawl = new Crawl(); |
|
21
|
|
|
$crawl->url = esc_url_raw($url); |
|
|
|
|
|
|
22
|
|
|
$crawl->execute(); |
|
23
|
|
|
$this->result = $crawl->result(); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
update_post_meta( $post_id, 'cgss_scan_result', $this->result ); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$this->render(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
//Display the score |
|
32
|
|
|
public function score_html() { |
|
33
|
|
|
|
|
34
|
|
|
$score = $this->result['score']; |
|
35
|
|
|
$social = $this->result['social']; |
|
36
|
|
|
$fb_share = $social['fb_share']; |
|
37
|
|
|
$fb_like = $social['fb_like']; |
|
38
|
|
|
|
|
39
|
|
|
$score_html = |
|
40
|
|
|
'<span>'.sprintf(__('Overall SEO score %d out of 10. Facebook shares: %d and likes: %d', 'cgss' ), $score, $fb_share, $fb_like ).'</span>'; |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
return $score_html; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
// Display the snippets |
|
47
|
|
|
public function snippet_display() { |
|
48
|
|
|
|
|
49
|
|
|
$snippet = $this->result['snip']; |
|
50
|
|
|
$title = $snippet['title']; |
|
51
|
|
|
$desc = $snippet['desc']; |
|
52
|
|
|
|
|
53
|
|
|
$social_snippet = $this->result['social_tags']; |
|
54
|
|
|
$social_title = $social_snippet['title']; |
|
55
|
|
|
$social_desc = $social_snippet['description']; |
|
56
|
|
|
$social_image = $social_snippet['image']; |
|
57
|
|
|
|
|
58
|
|
|
$not_found = __('NOT_FOUND', 'cgss'); |
|
|
|
|
|
|
59
|
|
|
$snippet_html = |
|
60
|
|
|
'<ul> |
|
61
|
|
|
<li><strong>'.__('Search snippet', 'cgss').':</strong> |
|
62
|
|
|
<ul> |
|
63
|
|
|
<li>'.sprintf(__('Title: %s', 'cgss'),($title ? $title : $not_found)).'</li> |
|
64
|
|
|
<li>'.sprintf(__('Description: %s', 'cgss'),($desc ? $desc : $not_found)).'</li> |
|
65
|
|
|
</ul> |
|
66
|
|
|
</li> |
|
67
|
|
|
<li><strong>'.__('Social snippet(OGP)', 'cgss').':</strong> |
|
68
|
|
|
<ul> |
|
69
|
|
|
<li>'.sprintf(__('Title: %s', 'cgss'),($social_title ? $social_title : $not_found)).'</li> |
|
70
|
|
|
<li>'.sprintf(__('Description: %s', 'cgss'),( $social_desc ? $social_desc : $not_found)).'</li> |
|
71
|
|
|
<li>'.sprintf(__('Image: %s', 'cgss'),( $social_image ? $social_image : $not_found)).'</li> |
|
72
|
|
|
</ul></li> |
|
73
|
|
|
</ul>'; |
|
74
|
|
|
|
|
75
|
|
|
return $snippet_html; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
// Display text and link data |
|
80
|
|
|
public function text_display() { |
|
81
|
|
|
|
|
82
|
|
|
$text = $this->result['text']; |
|
83
|
|
|
$keys = implode(', ', array_keys($text['keys'])); |
|
84
|
|
|
$count = $text['count']; |
|
85
|
|
|
$ratio = $text['ratio']; |
|
86
|
|
|
|
|
87
|
|
|
$htags = $text['htags']; |
|
88
|
|
|
$headings = implode( ', ', $htags['names'] ); |
|
89
|
|
|
|
|
90
|
|
|
$links = $text['links']; |
|
91
|
|
|
$link_count = $links['count']; |
|
92
|
|
|
$link_nofollow = $links['nofollow']; |
|
93
|
|
|
$link_external = $links['external']; |
|
94
|
|
|
|
|
95
|
|
|
$text_html = |
|
96
|
|
|
'<ul> |
|
97
|
|
|
<li>'.sprintf(__('Keywords: %s','cgss'), $keys).'</li> |
|
|
|
|
|
|
98
|
|
|
<li>'.sprintf(__('Number of words: %s','cgss'), $count).'</li> |
|
99
|
|
|
<li>'.sprintf(__('Text to html ratio: %s percent','cgss'), $ratio).'</li> |
|
100
|
|
|
<li>'.sprintf(__('Heading tags in text hierarchy: %s','cgss'), $headings).'</li> |
|
101
|
|
|
<li>'.sprintf(__('Total Links: %d, Nofollow Links %d, External Links: %d','cgss'), $link_count, $link_nofollow, $link_external).'</li> |
|
102
|
|
|
</ul>'; |
|
103
|
|
|
|
|
104
|
|
|
return $text_html; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
// Display design data |
|
109
|
|
|
public function design_display() { |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
$design = $this->result['design']; |
|
113
|
|
|
|
|
114
|
|
|
$iframe = $design['iframe']; |
|
115
|
|
|
|
|
116
|
|
|
$tag_style = $design['tag_style']; |
|
117
|
|
|
$tag_style_count = $tag_style['count']; |
|
118
|
|
|
$tag_style_attributes = implode( ', ', $tag_style['tags'] ); |
|
119
|
|
|
|
|
120
|
|
|
$nested_table = $design['nested_table']; |
|
121
|
|
|
$vport = $design['vport']; |
|
122
|
|
|
$media = $design['media']; |
|
123
|
|
|
$image = $design['image']; |
|
124
|
|
|
$image_count = $image['count']; |
|
125
|
|
|
$image_no_alt_count = $image['no_alt_count']; |
|
126
|
|
|
|
|
127
|
|
|
$design_html = |
|
128
|
|
|
'<ul> |
|
129
|
|
|
<li>'.sprintf(__('Total images: %d and images without alt tags: %d','cgss'), $image_count, $image_no_alt_count).'</li> |
|
|
|
|
|
|
130
|
|
|
<li>'.sprintf(__('iframe: %d','cgss'), $iframe).'</li> |
|
131
|
|
|
<li>'.sprintf(__('Nested Tables: %d','cgss'), $nested_table).'</li> |
|
132
|
|
|
<li>'.sprintf(__('Tags with style attribute: %s(%s)','cgss'), $tag_style_count, $tag_style_attributes).'</li> |
|
133
|
|
|
<li>'.sprintf(__('Mobile optimization: Viewport Tag: %d, @media Queries: %d','cgss'), $vport, $media).'</li> |
|
134
|
|
|
</ul>'; |
|
135
|
|
|
|
|
136
|
|
|
return $design_html; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
// Display crawl data |
|
141
|
|
|
public function crawl_display() { |
|
142
|
|
|
|
|
143
|
|
|
$crawl = $this->result['crawl']; |
|
144
|
|
|
|
|
145
|
|
|
$ssl = $crawl['ssl']; |
|
146
|
|
|
$dynamic = $crawl['dynamic']; |
|
147
|
|
|
$underscore = $crawl['underscore']; |
|
148
|
|
|
|
|
149
|
|
|
$ip = $crawl['ip']; |
|
150
|
|
|
$cano = $crawl['cano']; |
|
151
|
|
|
$if_mod = $crawl['if_mod']; |
|
152
|
|
|
$alive = $crawl['alive']; |
|
153
|
|
|
$robot = $crawl['meta_robot']; |
|
154
|
|
|
|
|
155
|
|
|
$on = __( 'on', 'cgss' ); |
|
|
|
|
|
|
156
|
|
|
$off = __( 'off', 'cgss' ); |
|
157
|
|
|
|
|
158
|
|
|
$crawl_html = |
|
159
|
|
|
'<ul> |
|
160
|
|
|
<li>'.sprintf(__('Your URL parameters: SSL security: %s, Static url: %s, underscores in Url: %s','cgss'), (!$ssl ? $off : $on ), (!$dynamic ? $off : $on ), (!$underscore ? $off : $on )).'</li> |
|
161
|
|
|
<li>'.sprintf(__('If modified since header: %s','cgss'), ($if_mod == 0 ? $off : $on )).'</li> |
|
162
|
|
|
<li>'.sprintf(__('Canonical Url: %s','cgss'), ($cano == 0 ? $off : $on )).'</li> |
|
163
|
|
|
<li>'.sprintf(__('Meta Robot: %s','cgss'), (!$robot['ok'] ? $off : $on )).'</li> |
|
164
|
|
|
<li>'.sprintf(__('IP Forward: %s','cgss'), ($ip ? $ip : $off )).'</li> |
|
165
|
|
|
<li>'.sprintf(__('Keep alive connection: %s','cgss'), ($alive == 0 ? $off : $on )).'</li> |
|
166
|
|
|
</ul>'; |
|
167
|
|
|
|
|
168
|
|
|
return $crawl_html; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
// Display speed data |
|
173
|
|
|
public function speed_display() { |
|
174
|
|
|
|
|
175
|
|
|
$speed = $this->result['speed']; |
|
176
|
|
|
|
|
177
|
|
|
$res_time = $speed['res_time']; |
|
178
|
|
|
$down_time = $speed['down_time']; |
|
179
|
|
|
$gzip = $speed['gzip']; |
|
180
|
|
|
$cache = $speed['cache']; |
|
181
|
|
|
$css = $speed['css']; |
|
182
|
|
|
$js = $speed['js']; |
|
183
|
|
|
|
|
184
|
|
|
$on = __( 'on', 'cgss' ); |
|
|
|
|
|
|
185
|
|
|
$off = __( 'off', 'cgss' ); |
|
186
|
|
|
|
|
187
|
|
|
$speed_html = |
|
188
|
|
|
'<ul> |
|
189
|
|
|
<li>'. sprintf( __( 'Header response time %s s and page downloading time %s s', 'cgss' ), $res_time, $down_time ). '</li> |
|
190
|
|
|
<li>'.sprintf(__('gZip compression: %s','cgss'), ($gzip ? $off : $on )).'</li> |
|
191
|
|
|
<li>'.sprintf(__('Browser caching: %s','cgss'), ($cache ? $off : $on )).'</li> |
|
192
|
|
|
<li>'.sprintf(__('Requests made by CSS is %s and by JS is %s','cgss'), $css['count'], $js['count']).'</li> |
|
193
|
|
|
<li>'.sprintf(__('Resources can be compressed by %s kb for CSS and %s kb for JS','cgss'), $css['compress_num'], $js['compress_num']).'</li> |
|
194
|
|
|
</ul>'; |
|
195
|
|
|
|
|
196
|
|
|
return $speed_html; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
// Render the HTML |
|
201
|
|
|
public function render() { |
|
202
|
|
|
|
|
203
|
|
|
$this->score_html = $this->score_html(); |
|
|
|
|
|
|
204
|
|
|
$this->snippets_html = $this->snippet_display(); |
|
|
|
|
|
|
205
|
|
|
$this->text_html = $this->text_display(); |
|
|
|
|
|
|
206
|
|
|
$this->design_html = $this->design_display(); |
|
|
|
|
|
|
207
|
|
|
$this->crawl_html = $this->crawl_display(); |
|
|
|
|
|
|
208
|
|
|
$this->speed_html = $this->speed_display(); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
$this->box( null, null, $this->score_html ); |
|
211
|
|
|
$this->box( __( 'Snippets', 'cgss' ), $this->dashicon('align-none'), $this->snippets_html ); |
|
|
|
|
|
|
212
|
|
|
$this->box( __( 'Text & Links', 'cgss' ), $this->dashicon('text'), $this->text_html ); |
|
213
|
|
|
$this->box( __( 'Design', 'cgss' ), $this->dashicon('smartphone'), $this->design_html ); |
|
214
|
|
|
$this->box( __( 'Crawl', 'cgss' ), $this->dashicon('randomize'), $this->crawl_html ); |
|
215
|
|
|
$this->box( __( 'Speed', 'cgss' ), $this->dashicon('clock'), $this->speed_html ); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
public function box($title, $icon, $desc) { |
|
220
|
|
|
|
|
221
|
|
|
echo |
|
222
|
|
|
'<div class="postbox"> |
|
223
|
|
|
<div class="inside"> |
|
224
|
|
|
<div class="main">' . |
|
225
|
|
|
'<h4>' . $icon . ' ' . $title . '</h4>' . |
|
226
|
|
|
$desc . |
|
227
|
|
|
'</div> |
|
228
|
|
|
</div> |
|
229
|
|
|
</div>'; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
public function dashicon($icon) { |
|
234
|
|
|
|
|
235
|
|
|
return '<span class="dashicons dashicons-'.$icon.'"></span>'; |
|
236
|
|
|
} |
|
237
|
|
|
} ?> |
|
|
|
|
|
|
238
|
|
|
|