WP Meta SEO - Version 2.0.0

Version Description

  • Add: 404 and redirect manager
  • Add: Options to redirect all 404 to home page
  • Add: Setup 404 page as: WP Meta SEO page, custom page, defulat page
Download this release

Release Info

Developer JoomUnited
Plugin Icon 128x128 WP Meta SEO
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.7.3 to 2.0.0

css/googlefonticon.css ADDED
@@ -0,0 +1,22 @@
1
+ @font-face {
2
+ font-family: 'Material Icons';
3
+ font-style: normal;
4
+ font-weight: 400;
5
+ src: local('Material Icons'), local('MaterialIcons-Regular'), url(https://fonts.gstatic.com/s/materialicons/v12/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2) format('woff2');
6
+ }
7
+
8
+ .material-icons {
9
+ font-family: 'Material Icons';
10
+ font-weight: normal;
11
+ font-style: normal;
12
+ font-size: 24px;
13
+ line-height: 1;
14
+ letter-spacing: normal;
15
+ text-transform: none;
16
+ display: inline-block;
17
+ white-space: nowrap;
18
+ word-wrap: normal;
19
+ direction: ltr;
20
+ -webkit-font-feature-settings: 'liga';
21
+ -webkit-font-smoothing: antialiased;
22
+ }
css/metabox-tabs.css CHANGED
@@ -325,9 +325,9 @@ table.wpmseoanalysis td.score {
325
font-weight: 600;
326
}
327
328
- img.metaseo_help {
329
cursor: pointer;
330
- width: 20px;
331
}
332
333
.metaseo-qtip {
@@ -363,29 +363,7 @@ div.wpmseo-tab-content {
363
364
.metaseo-dashicons{
365
float: left;
366
- width: 30px;
367
- }
368
-
369
- .metaseo-dashicons:before{
370
- width: 30px;
371
- }
372
-
373
- .metaseo-dashicons.dashicons-yes {
374
- color: #1d9757;
375
-
376
- }
377
-
378
- .metaseo-dashicons.dashicons-yes:before{
379
- font-size: 25px;
380
- }
381
-
382
- .metaseo-dashicons.icons-mwarning {
383
- /* color: #f00;*/
384
- width: 20px;
385
- height: 20px;
386
- margin: 0px 5px;
387
- background-image: url(../img/warnig-red.png);
388
- background-size: 100% 100%;
389
}
390
391
.metaseo_analysis{
325
font-weight: 600;
326
}
327
328
+ i.metaseo_help {
329
cursor: pointer;
330
+ font-size: 20px;
331
}
332
333
.metaseo-qtip {
363
364
.metaseo-dashicons{
365
float: left;
366
+ line-height:18px !important;
367
}
368
369
.metaseo_analysis{
css/metaseo_admin.css CHANGED
@@ -386,4 +386,186 @@ strong {
386
display:none;
387
line-height:28px;
388
color: #F00;
389
}
386
display:none;
387
line-height:28px;
388
color: #F00;
389
+ }
390
+
391
+ .wpms-inline-editor-content{
392
+ display: none;
393
+ float: left;
394
+ }
395
+
396
+ #col_link_url{
397
+ width:30%;
398
+ }
399
+ .wpms-inline-editor-content span.title {
400
+ display: block;
401
+ float: left;
402
+ width: 5em;
403
+ }
404
+
405
+ .wpms-inline-editor-buttons{
406
+ padding: 0 !important;
407
+ }
408
+
409
+ .wpms-input-text-wrap .title{
410
+ line-height: 26px;
411
+ }
412
+
413
+ .wpms-link-url-field,.wpms-link-text-field,.wpms-link-redirect-field{
414
+ width:85%;
415
+ float: right;
416
+ }
417
+
418
+ .wpms-cancel-button{
419
+ float: left;
420
+ margin-top: 10px !important;
421
+ }
422
+
423
+ .wpms-update-link-button{
424
+ float: right;
425
+ margin-top: 10px !important;
426
+ }
427
+
428
+ #wp-seo-meta-form .bulkactions select,#wp-seo-meta-form .bulkactions #broken-submit{
429
+ float: left;
430
+ }
431
+
432
+ .wpms_scan_link{
433
+ float: left;
434
+ }
435
+
436
+ .wpms_scan_link.scanding{
437
+ background-image: url('../img/loading1.gif') !important;
438
+ background-size: 100% 100% !important;
439
+ }
440
+
441
+ .wpms_action_link{
442
+ cursor: pointer;
443
+ }
444
+ .column-col_hit{
445
+ text-align: center !important;
446
+ }
447
+ .broken_link_table th#col_hit{width:10%;}
448
+ .broken_link_table th#cb{width:3%}
449
+ .broken_link_table th#col_source{width:20%}
450
+ .broken_link_table th#col_link_url{width:40%}
451
+ .broken_link_table th#col_status{width:10%}
452
+
453
+ .tab-header{
454
+ width: 99%;
455
+ float: left;
456
+ }
457
+
458
+ .wpms-tabs{
459
+ float: left;
460
+ }
461
+
462
+ .wpms-tab-header{
463
+ float: left;
464
+ -webkit-box-sizing: content-box;
465
+ -moz-box-sizing: content-box;
466
+ box-sizing: content-box;
467
+ position: relative;
468
+ top: 1px;
469
+ background: #ebebeb;
470
+ color: #777;
471
+ cursor: pointer;
472
+ font: 13px/19px "Open Sans", sans-serif;
473
+ height: 20px;
474
+ margin: 5px 0 0 5px;
475
+ padding: 3px 8px 4px;
476
+ border: 1px solid #e5e5e5;
477
+ }
478
+
479
+ .wpms-tab-header:first-child{
480
+ margin: 5px 0 0 0px;
481
+ }
482
+
483
+ .wpms-tab-header.active{
484
+ background: #f5f5f5;
485
+ color: #555;
486
+ border-bottom-color: #f5f5f5;
487
+ }
488
+
489
+ .wpms-global{
490
+ display: block;
491
+ }
492
+
493
+ .content-box{
494
+ padding: 10px;
495
+ }
496
+
497
+ .content-wpms-redirection{
498
+ display: none;
499
+ }
500
+
501
+ .wpms_content_settings{
502
+ background: #fff;
503
+ }
504
+
505
+ .metaseo-dashicons{
506
+ float: left;
507
+ width: 30px;
508
+ }
509
+
510
+ .metaseo-dashicons:before{
511
+ width: 30px;
512
+ }
513
+
514
+ .metaseo-dashicons.icons-mwarning {
515
+ width: 20px;
516
+ height: 20px;
517
+ margin: 0px 5px;
518
+ background-image: url(../img/warnig-red.png);
519
+ background-size: 100% 100%;
520
+ }
521
+
522
+ .message_saved{
523
+ line-height: 28px;
524
+ color: #0073aa;
525
+ display: none;
526
+ }
527
+
528
+ .wpms_warning{
529
+ color: #FFB900;
530
+ }
531
+
532
+ .wpms_ok{
533
+ color: #4caf50;
534
+ }
535
+
536
+ .wpmf_process{
537
+ background:#81b5ee;
538
+ height: 2px;
539
+ width:0%;
540
+ display: none;
541
+ }
542
+
543
+ .wp-meta-seo_page_metaseo_broken_link .metaseo-qtip {
544
+ font-size: 12px !important;
545
+ line-height: 18px !important;
546
+ }
547
+
548
+ .link_html{
549
+ float: none;
550
+ }
551
+ .row-actions > span{
552
+ float: left;
553
+ }
554
+
555
+ .wpms_action_link{
556
+ color:#32373C !important;
557
+ }
558
+
559
+ .wpms_action_link i.material-icons{
560
+ font-size:20px !important;
561
+ }
562
+
563
+ .wpms_icon_action{
564
+ height: 20px;
565
+ float: left;
566
+ }
567
+
568
+ td.link_text i.material-icons{
569
+ font-size:20px;
570
+ color:#32373C
571
}
inc/class.metaseo-admin.php CHANGED
@@ -1,5 +1,4 @@
1
<?php
2
-
3
//Main plugin functions here
4
class MetaSeo_Admin {
5
@@ -40,13 +39,13 @@ class MetaSeo_Admin {
40
41
/** Load admin css * */
42
add_action('admin_init', array($this, 'addAdminStylesheets'));
43
-
44
$this->ajaxHandle();
45
46
//register ajax update meta handler...
47
add_action( 'wp_ajax_updateContentMeta', array($this, 'updateContentMeta_callback') );
48
add_action( 'admin_init', array($this, 'stop_heartbeat') , 1 );
49
add_action('admin_init', array($this,'metaseo_field_settings'));
50
add_action('init', array($this,'wpms_load_langguage'));
51
52
if(!get_option('wpms_set_ignore', false)){
@@ -58,6 +57,60 @@ class MetaSeo_Admin {
58
add_action( 'admin_notices', array( $this, 'wpms_public_warning' ) );
59
}
60
add_action( 'wp_enqueue_editor', array( $this,'wpms_link_title_field'), 20 );
61
}
62
63
function wpms_link_title_field() {
@@ -116,7 +169,7 @@ class MetaSeo_Admin {
116
}
117
118
function metaseo_create_field($data_title,$alt,$dashicon,$label,$value_hidden){
119
- $output = '<div class="metaseo_analysis metaseo_tool 123" data-title="'.$data_title.'" alt="'.$alt.'"><div class="metaseo-dashicons dashicons-before '.$dashicon.'"></div>'.$label.'</div>';
120
$output .= '<input type="hidden" class="wpms_analysis_hidden" name="wpms['.$data_title.']" value="'.$value_hidden.'">';
121
return $output;
122
}
@@ -158,14 +211,14 @@ class MetaSeo_Admin {
158
}
159
160
if($test){
161
- $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'dashicons-yes',__('Page title word in content heading','wp-meta-seo'),1);
162
$check ++;
163
}else{
164
- $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'icons-mwarning',__('Page title word in content heading','wp-meta-seo'),0);
165
}
166
167
}else{
168
- $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'dashicons-yes',__('Page title word in content heading','wp-meta-seo'),1);
169
$check ++;
170
}
171
@@ -186,41 +239,41 @@ class MetaSeo_Admin {
186
}
187
188
if($test1){
189
- $output .= $this->metaseo_create_field('content_title',$tooltip_page['title_in_content'],'dashicons-yes',__('Page title word in content','wp-meta-seo'),1);
190
$check ++;
191
}else{
192
- $output .= $this->metaseo_create_field('content_title',$tooltip_page['title_in_content'],'icons-mwarning',__('Page title word in content','wp-meta-seo'),0);
193
}
194
195
// page url matches page title
196
$mtitle = $_POST['datas']['title'];
197
if($_POST['datas']['mpageurl'] == sanitize_title($mtitle)){
198
- $output .= $this->metaseo_create_field('pageurl',$tooltip_page['page_url'],'dashicons-yes',__('Page url matches with page title','wp-meta-seo'),1);
199
$check ++;
200
}else{
201
- $output .= $this->metaseo_create_field('pageurl',$tooltip_page['page_url'],'icons-mwarning',__('Page url matches with page title','wp-meta-seo'),0);
202
}
203
204
// meta title filled
205
if(($_POST['datas']['meta_title'] != '' && strlen($_POST['datas']['meta_title']) <= self::$title_length)){
206
- $output .= $this->metaseo_create_field('metatitle',$tooltip_page['meta_title'],'dashicons-yes',__('Meta title filled','wp-meta-seo'),1);
207
$check++;
208
}else{
209
- $output .= $this->metaseo_create_field('metatitle',$tooltip_page['meta_title'],'icons-mwarning',__('Meta title filled','wp-meta-seo'),0);
210
}
211
212
// desc filled
213
if(($_POST['datas']['meta_desc'] != '' && strlen($_POST['datas']['meta_desc']) <= self::$desc_length)){
214
- $output .= $this->metaseo_create_field('metadesc',$tooltip_page['meta_desc'],'dashicons-yes',__('Meta description filled','wp-meta-seo'),1);
215
$check++;
216
}else{
217
- $output .= $this->metaseo_create_field('metadesc',$tooltip_page['meta_desc'],'icons-mwarning',__('Meta description filled','wp-meta-seo'),0);
218
}
219
220
// image resize
221
if($_POST['datas']['content'] == '') {
222
- $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'dashicons-yes',__('Wrong image resize','wp-meta-seo'),1);
223
- $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'dashicons-yes',__('Image have meta title or alt','wp-meta-seo'),1);
224
$check += 2;
225
}else{
226
$dom = new DOMDocument;
@@ -250,21 +303,21 @@ class MetaSeo_Admin {
250
}
251
252
if($img_wrong == false){
253
- $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'dashicons-yes',__('Wrong image resize','wp-meta-seo'),1);
254
$check++;
255
}else{
256
- $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'icons-mwarning',__('Wrong image resize','wp-meta-seo'),0);
257
}
258
259
if($img_wrong_alt == false){
260
- $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'dashicons-yes',__('Image have meta title or alt','wp-meta-seo'),1);
261
$check++;
262
}else{
263
- $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'icons-mwarning',__('Image have meta title or alt','wp-meta-seo'),0);
264
}
265
}else{
266
- $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'icons-mwarning',__('Wrong image resize','wp-meta-seo'),0);
267
- $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'icons-mwarning',__('Image have meta title or alt','wp-meta-seo'),0);
268
}
269
}
270
@@ -309,8 +362,15 @@ class MetaSeo_Admin {
309
}
310
}
311
wp_send_json(false);
312
- }
313
314
function metaseo_field_settings(){
315
register_setting('Wp Meta SEO','_metaseo_settings');
316
add_settings_section('metaseo_dashboard','',array( $this, 'showSettings' ),'metaseo_settings');
@@ -339,7 +399,7 @@ class MetaSeo_Admin {
339
public function showSettings(){
340
341
}
342
-
343
public function metaseo_title_home(){
344
$home_title = isset( $this->settings['metaseo_title_home'] ) ? $this->settings['metaseo_title_home'] : '';
345
echo '<input id="metaseo_title_home" name="_metaseo_settings[metaseo_title_home]" type="text" value="'.esc_attr( $home_title ).'" size="50"/>';
@@ -505,10 +565,13 @@ class MetaSeo_Admin {
505
wp_enqueue_script('metaseo-dashboard', plugins_url('js/dashboard.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
506
wp_enqueue_style('chart', plugins_url('/css/chart.css', dirname(__FILE__) ) );
507
wp_enqueue_style('metaseo-quirk', plugins_url('/css/metaseo-quirk.css', dirname(__FILE__) ) );
508
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', WPMSEO_FILE), array(), WPMSEO_VERSION);
509
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', WPMSEO_FILE), array('jquery'), '2.2.1', true);
510
}
511
512
if($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta'){
513
wp_enqueue_script('mautosize', plugins_url('js/autosize.js', dirname(__FILE__)), array('jquery'), '0.1', true);
514
}
@@ -528,7 +591,8 @@ class MetaSeo_Admin {
528
* of jquery-ui
529
*
530
*/
531
- function addAdminStylesheets() {
532
wp_enqueue_style('wpmetaseoAdmin', plugins_url('css/metaseo_admin.css', dirname(__FILE__)),array(), WPMSEO_VERSION);
533
wp_enqueue_style('tooltip-metaimage', plugins_url('/css/tooltip-metaimage.css',dirname(__FILE__)),array(), WPMSEO_VERSION);
534
wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__) ),array(), WPMSEO_VERSION);
@@ -576,6 +640,15 @@ class MetaSeo_Admin {
576
array($this, 'load_page'),
577
null,
578
),
579
array(
580
'metaseo_dashboard',
581
'',
@@ -620,6 +693,9 @@ class MetaSeo_Admin {
620
function load_page() {
621
if (isset($_GET['page'])) {
622
switch ($_GET['page']) {
623
case 'metaseo_settings':
624
require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php' );
625
break;
@@ -865,6 +941,12 @@ class MetaSeo_Admin {
865
add_action('wp_ajax_metaseo_reload_analysis',array($this,'metaseo_reload_analysis'));
866
add_action('wp_ajax_metaseo_validate_analysis',array($this,'metaseo_validate_analysis'));
867
add_action('wp_ajax_metaseo_update_link',array($this,'metaseo_update_link'));
868
}
869
870
}
1
<?php
2
//Main plugin functions here
3
class MetaSeo_Admin {
4
39
40
/** Load admin css * */
41
add_action('admin_init', array($this, 'addAdminStylesheets'));
42
$this->ajaxHandle();
43
44
//register ajax update meta handler...
45
add_action( 'wp_ajax_updateContentMeta', array($this, 'updateContentMeta_callback') );
46
add_action( 'admin_init', array($this, 'stop_heartbeat') , 1 );
47
add_action('admin_init', array($this,'metaseo_field_settings'));
48
+ add_action('admin_init', array($this,'metaseo_create_404page'));
49
add_action('init', array($this,'wpms_load_langguage'));
50
51
if(!get_option('wpms_set_ignore', false)){
57
add_action( 'admin_notices', array( $this, 'wpms_public_warning' ) );
58
}
59
add_action( 'wp_enqueue_editor', array( $this,'wpms_link_title_field'), 20 );
60
+ add_action( 'post_updated', array('MetaSeo_Broken_Link_Table','wpms_update_post'), 10, 3 );
61
+ add_action( 'delete_post', array('MetaSeo_Broken_Link_Table','wpms_delete_post' ));
62
+ add_action( 'edit_comment', array('MetaSeo_Broken_Link_Table','wpms_update_comment') );
63
+ add_action( 'deleted_comment', array('MetaSeo_Broken_Link_Table','wpms_deleted_comment') );
64
+
65
+ }
66
+
67
+ function metaseo_create_404page(){
68
+ global $wpdb;
69
+ // create table wpms_links
70
+ $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wpms_links`(
71
+ `id` int(20) unsigned NOT NULL AUTO_INCREMENT,
72
+ `link_url` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
73
+ `link_final_url` text CHARACTER SET latin1 COLLATE latin1_general_cs,
74
+ `link_url_redirect` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
75
+ `link_text` text NOT NULL DEFAULT '',
76
+ `source_id` int(20) DEFAULT '0',
77
+ `type` varchar(100) DEFAULT '',
78
+ `status_code` varchar(100) DEFAULT '',
79
+ `status_text` varchar(250) DEFAULT '',
80
+ `hit` int(20) NOT NULL DEFAULT '1',
81
+ `redirect` tinyint(1) NOT NULL DEFAULT '0',
82
+ `broken_indexed` tinyint(1) unsigned NOT NULL DEFAULT '0',
83
+ `broken_internal` tinyint(1) unsigned NOT NULL DEFAULT '0',
84
+ `warning` tinyint(1) unsigned NOT NULL DEFAULT '0',
85
+ `dismissed` tinyint(1) NOT NULL DEFAULT '0',
86
+ PRIMARY KEY (id))";
87
+
88
+ require_once(ABSPATH.'wp-admin/includes/upgrade.php');
89
+ dbDelta($sql);
90
+
91
+ // create page 404
92
+ $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "posts WHERE post_title = %s" , array("WP Meta SEO 404 Page"));
93
+ $post_if = $wpdb->get_var($sql);
94
+ if($post_if < 1){
95
+ $content = '<div class="wall" style="background-color: #F2F3F7; border: 30px solid #fff; width: 90%; height: 90%; margin: 0 auto;">
96
+
97
+ <h1 style="text-align: center; font-family:\'open-sans\', arial; color: #444; font-size: 60px; padding: 50px;">ERROR 404 <br />-<br />NOT FOUND</h1>
98
+ <p style="text-align: center; font-family:\'open-sans\', arial; color: #444; font-size: 40px; padding: 20px; line-height: 55px;">
99
+ // You may have mis-typed the URL,<br />
100
+ // Or the page has been removed,<br />
101
+ // Actually, there is nothing to see here...</p>
102
+ <p style="text-align: center;"><a style=" font-family:\'open-sans\', arial; color: #444; font-size: 20px; padding: 20px; line-height: 30px; text-decoration: none;" href="'. get_home_url().'"><< Go back to home page >></a></p>
103
+ </div>';
104
+ $_page404 = array(
105
+ 'post_title' => 'WP Meta SEO 404 Page',
106
+ 'post_content' => $content,
107
+ 'post_status' => 'publish',
108
+ 'post_excerpt' => 'metaseo_404_page',
109
+ 'post_type' => 'page',
110
+ );
111
+ wp_insert_post( $_page404 );
112
+ }
113
+
114
}
115
116
function wpms_link_title_field() {
169
}
170
171
function metaseo_create_field($data_title,$alt,$dashicon,$label,$value_hidden){
172
+ $output = '<div class="metaseo_analysis metaseo_tool" data-title="'.$data_title.'" alt="'.$alt.'"><i class="metaseo-dashicons material-icons dashicons-before" style="'.($dashicon == 'done'?'color:#46B450':'color:#FFB900').'">'.$dashicon.'</i>'.$label.'</div>';
173
$output .= '<input type="hidden" class="wpms_analysis_hidden" name="wpms['.$data_title.']" value="'.$value_hidden.'">';
174
return $output;
175
}
211
}
212
213
if($test){
214
+ $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'done',__('Page title word in content heading','wp-meta-seo'),1);
215
$check ++;
216
}else{
217
+ $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'warning',__('Page title word in content heading','wp-meta-seo'),0);
218
}
219
220
}else{
221
+ $output .= $this->metaseo_create_field('heading_title',$tooltip_page['title_in_heading'],'done',__('Page title word in content heading','wp-meta-seo'),1);
222
$check ++;
223
}
224
239
}
240
241
if($test1){
242
+ $output .= $this->metaseo_create_field('content_title',$tooltip_page['title_in_content'],'done',__('Page title word in content','wp-meta-seo'),1);
243
$check ++;
244
}else{
245
+ $output .= $this->metaseo_create_field('content_title',$tooltip_page['title_in_content'],'warning',__('Page title word in content','wp-meta-seo'),0);
246
}
247
248
// page url matches page title
249
$mtitle = $_POST['datas']['title'];
250
if($_POST['datas']['mpageurl'] == sanitize_title($mtitle)){
251
+ $output .= $this->metaseo_create_field('pageurl',$tooltip_page['page_url'],'done',__('Page url matches with page title','wp-meta-seo'),1);
252
$check ++;
253
}else{
254
+ $output .= $this->metaseo_create_field('pageurl',$tooltip_page['page_url'],'warning',__('Page url matches with page title','wp-meta-seo'),0);
255
}
256
257
// meta title filled
258
if(($_POST['datas']['meta_title'] != '' && strlen($_POST['datas']['meta_title']) <= self::$title_length)){
259
+ $output .= $this->metaseo_create_field('metatitle',$tooltip_page['meta_title'],'done',__('Meta title filled','wp-meta-seo'),1);
260
$check++;
261
}else{
262
+ $output .= $this->metaseo_create_field('metatitle',$tooltip_page['meta_title'],'warning',__('Meta title filled','wp-meta-seo'),0);
263
}
264
265
// desc filled
266
if(($_POST['datas']['meta_desc'] != '' && strlen($_POST['datas']['meta_desc']) <= self::$desc_length)){
267
+ $output .= $this->metaseo_create_field('metadesc',$tooltip_page['meta_desc'],'done',__('Meta description filled','wp-meta-seo'),1);
268
$check++;
269
}else{
270
+ $output .= $this->metaseo_create_field('metadesc',$tooltip_page['meta_desc'],'warning',__('Meta description filled','wp-meta-seo'),0);
271
}
272
273
// image resize
274
if($_POST['datas']['content'] == '') {
275
+ $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'done',__('Wrong image resize','wp-meta-seo'),1);
276
+ $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'done',__('Image have meta title or alt','wp-meta-seo'),1);
277
$check += 2;
278
}else{
279
$dom = new DOMDocument;
303
}
304
305
if($img_wrong == false){
306
+ $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'done',__('Wrong image resize','wp-meta-seo'),1);
307
$check++;
308
}else{
309
+ $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'warning',__('Wrong image resize','wp-meta-seo'),0);
310
}
311
312
if($img_wrong_alt == false){
313
+ $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'done',__('Image have meta title or alt','wp-meta-seo'),1);
314
$check++;
315
}else{
316
+ $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'warning',__('Image have meta title or alt','wp-meta-seo'),0);
317
}
318
}else{
319
+ $output .= $this->metaseo_create_field('imgresize',$tooltip_page['image_resize'],'warning',__('Wrong image resize','wp-meta-seo'),0);
320
+ $output .= $this->metaseo_create_field('imgalt',$tooltip_page['image_alt'],'warning',__('Image have meta title or alt','wp-meta-seo'),0);
321
}
322
}
323
362
}
363
}
364
wp_send_json(false);
365
+ }
366
367
+ function wpms_save_settings404(){
368
+ if(isset($_POST['wpms_redirect'])){
369
+ update_option('wpms_settings_404', $_POST['wpms_redirect']);
370
+ wp_send_json(true);
371
+ }
372
+ }
373
+
374
function metaseo_field_settings(){
375
register_setting('Wp Meta SEO','_metaseo_settings');
376
add_settings_section('metaseo_dashboard','',array( $this, 'showSettings' ),'metaseo_settings');
399
public function showSettings(){
400
401
}
402
+
403
public function metaseo_title_home(){
404
$home_title = isset( $this->settings['metaseo_title_home'] ) ? $this->settings['metaseo_title_home'] : '';
405
echo '<input id="metaseo_title_home" name="_metaseo_settings[metaseo_title_home]" type="text" value="'.esc_attr( $home_title ).'" size="50"/>';
565
wp_enqueue_script('metaseo-dashboard', plugins_url('js/dashboard.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
566
wp_enqueue_style('chart', plugins_url('/css/chart.css', dirname(__FILE__) ) );
567
wp_enqueue_style('metaseo-quirk', plugins_url('/css/metaseo-quirk.css', dirname(__FILE__) ) );
568
+ wp_enqueue_style('metaseo-quirk', plugins_url('/css/metaseo-quirk.css', dirname(__FILE__) ) );
569
}
570
571
+ wp_register_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
572
+ wp_register_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
573
+
574
+ wp_register_style('metaseo-google-icon', plugins_url('/css/googlefonticon.css', dirname(__FILE__) ) , array(), WPMSEO_VERSION );
575
if($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta'){
576
wp_enqueue_script('mautosize', plugins_url('js/autosize.js', dirname(__FILE__)), array('jquery'), '0.1', true);
577
}
591
* of jquery-ui
592
*
593
*/
594
+
595
+ function addAdminStylesheets() {
596
wp_enqueue_style('wpmetaseoAdmin', plugins_url('css/metaseo_admin.css', dirname(__FILE__)),array(), WPMSEO_VERSION);
597
wp_enqueue_style('tooltip-metaimage', plugins_url('/css/tooltip-metaimage.css',dirname(__FILE__)),array(), WPMSEO_VERSION);
598
wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__) ),array(), WPMSEO_VERSION);
640
array($this, 'load_page'),
641
null,
642
),
643
+ array(
644
+ 'metaseo_dashboard',
645
+ '',
646
+ __('404 & Redirects', 'wp-meta-seo'),
647
+ $manage_options_cap,
648
+ 'metaseo_broken_link',
649
+ array($this, 'load_page'),
650
+ null,
651
+ ),
652
array(
653
'metaseo_dashboard',
654
'',
693
function load_page() {
694
if (isset($_GET['page'])) {
695
switch ($_GET['page']) {
696
+ case 'metaseo_broken_link':
697
+ require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php' );
698
+ break;
699
case 'metaseo_settings':
700
require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php' );
701
break;
941
add_action('wp_ajax_metaseo_reload_analysis',array($this,'metaseo_reload_analysis'));
942
add_action('wp_ajax_metaseo_validate_analysis',array($this,'metaseo_validate_analysis'));
943
add_action('wp_ajax_metaseo_update_link',array($this,'metaseo_update_link'));
944
+ add_action('wp_ajax_wpms_save_settings404',array($this,'wpms_save_settings404'));
945
+ add_action('wp_ajax_wpms_update_link',array('MetaSeo_Broken_Link_Table','wpms_update_link'));
946
+ add_action('wp_ajax_wpms_unlink',array('MetaSeo_Broken_Link_Table','wpms_unlink'));
947
+ add_action('wp_ajax_wpms_recheck_link',array('MetaSeo_Broken_Link_Table','wpms_recheck_link'));
948
+ add_action('wp_ajax_wpms_scan_link',array('MetaSeo_Broken_Link_Table','wpms_scan_link'));
949
+ add_action('wp_ajax_wpms_flush_link',array('MetaSeo_Broken_Link_Table','wpms_flush_link'));
950
}
951
952
}
inc/class.metaseo-broken-link-table.php ADDED
@@ -0,0 +1,1554 @@
1
+ <?php
2
+ /*
3
+ * Comments to come later
4
+ *
5
+ *
6
+ */
7
+
8
+ if (!class_exists('WP_List_Table')) {
9
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
10
+ }
11
+
12
+ class MetaSeo_Broken_Link_Table extends WP_List_Table {
13
+
14
+ public $link_view = array();
15
+ public static $img_pattern = '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i';
16
+ public static $old_url = '';
17
+ public static $new_url = '';
18
+
19
+ function __construct() {
20
+ parent::__construct(array(
21
+ 'singular' => 'metaseo_image',
22
+ 'plural' => 'metaseo_images',
23
+ 'ajax' => true
24
+ ));
25
+ }
26
+
27
+ function display_tablenav($which) {
28
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
29
+ if (!empty($post_types['attachment']))
30
+ unset($post_types['attachment']);
31
+ $p_type = "('" . implode("','", $post_types) . "')";
32
+ ?>
33
+ <div class="tablenav <?php echo esc_attr($which); ?>">
34
+
35
+ <?php if ($which == 'top'): ?>
36
+ <input type="hidden" name="page" value="metaseo_image_meta" />
37
+
38
+ <div class="alignleft actions bulkactions">
39
+ <?php $this->broken_fillter('sl_broken'); ?>
40
+ <?php $this->redirect_fillter('sl_redirect'); ?>
41
+ <?php $this->type_fillter('sltype'); ?>
42
+ <?php $this->flush_fillter('sl_flush'); ?>
43
+ </div>
44
+ <?php elseif ($which == 'bottom'): ?>
45
+ <input type="hidden" name="page" value="metaseo_image_meta" />
46
+ <div class="alignleft actions bulkactions">
47
+ <?php $this->broken_fillter('sl_broken1'); ?>
48
+ <?php $this->redirect_fillter('sl_redirect1'); ?>
49
+ <?php $this->type_fillter('sltype1'); ?>
50
+ </div>
51
+ <?php endif ?>
52
+
53
+ <input type="hidden" name="page" value="metaseo_image_meta" />
54
+ <?php if (!empty($_REQUEST['post_status'])): ?>
55
+ <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>" />
56
+ <?php endif ?>
57
+
58
+ <?php //$this->extra_tablenav($which); ?>
59
+
60
+ <div style="float:right;margin-left:8px;">
61
+ <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>" maxlength="3" name="metaseo_broken_link_per_page" class="metaseo_imgs_per_page screen-per-page" max="999" min="1" step="1">
62
+ <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply" >
63
+ </div>
64
+
65
+ <?php $this->pagination($which); ?>
66
+ <br class="clear" />
67
+ </div>
68
+
69
+ <?php
70
+ }
71
+
72
+ function extra_tablenav($which) {
73
+
74
+ #if ('top' == $which) {
75
+ echo '<div class="alignleft actions">';
76
+ global $wpdb;
77
+
78
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
79
+ $post_types = "'" . implode("', '", $post_types) . "'";
80
+
81
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
82
+ $states['trash'] = 'trash';
83
+ $all_states = "'" . implode("', '", $states) . "'";
84
+
85
+ $query = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
86
+ $post_types = $wpdb->get_results($query);
87
+
88
+ $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
89
+
90
+ $options = '<option value="-1">Show All Post Types</option>';
91
+
92
+ foreach ($post_types as $post_type) {
93
+ $obj = get_post_type_object($post_type->post_type);
94
+ $options .= sprintf('<option value="%2$s" %3$s>%1$s</option>', $obj->labels->name, $post_type->post_type, selected($selected, $post_type->post_type, false));
95
+ }
96
+
97
+ echo "</div>";
98
+ #echo "</form>";
99
+ #}
100
+ }
101
+
102
+ function get_columns() {
103
+ return $columns = array(
104
+ 'col_link_url' => __('URL', 'wp-meta-seo'),
105
+ 'col_hit' => __('Hits number', 'wp-meta-seo'),
106
+ 'col_status' => __('Status', 'wp-meta-seo'),
107
+ 'col_link_text' => __('Type or Link text', 'wp-meta-seo'),
108
+ 'col_source' => __('Source', 'wp-meta-seo'),
109
+ );
110
+ }
111
+
112
+ function get_sortable_columns() {
113
+ return $sortable = array(
114
+ 'col_status' => array('status_text', true),
115
+ 'col_link_url' => array('link_url', true)
116
+ );
117
+ }
118
+
119
+ /**
120
+ * Print column headers, accounting for hidden and sortable columns.
121
+ *
122
+ * @since 3.1.0
123
+ * @access public
124
+ *
125
+ * @param bool $with_id Whether to set the id attribute or not
126
+ */
127
+ public function print_column_headers($with_id = true) {
128
+ list( $columns, $hidden, $sortable ) = $this->get_column_info();
129
+
130
+ $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
131
+ $current_url = remove_query_arg('paged', $current_url);
132
+
133
+ if (isset($_GET['orderby']))
134
+ $current_orderby = $_GET['orderby'];
135
+ else
136
+ $current_orderby = '';
137
+
138
+ if (isset($_GET['order']) && 'desc' == $_GET['order'])
139
+ $current_order = 'desc';
140
+ else
141
+ $current_order = 'asc';
142
+
143
+ if (!empty($columns['cb'])) {
144
+ static $cb_counter = 1;
145
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
146
+ . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
147
+ $cb_counter++;
148
+ }
149
+
150
+ foreach ($columns as $column_key => $column_display_name) {
151
+ $class = array('manage-column', "column-$column_key");
152
+
153
+ $style = '';
154
+ if (in_array($column_key, $hidden))
155
+ $style = 'display:none;';
156
+
157
+ $style = ' style="' . $style . '"';
158
+
159
+ if ('cb' == $column_key)
160
+ $class[] = 'check-column';
161
+ elseif (in_array($column_key, array('posts', 'comments', 'links')))
162
+ $class[] = 'num';
163
+
164
+ if (isset($sortable[$column_key])) {
165
+ list( $orderby, $desc_first ) = $sortable[$column_key];
166
+
167
+ if ($current_orderby == $orderby) {
168
+ $order = 'asc' == $current_order ? 'desc' : 'asc';
169
+ $class[] = 'sorted';
170
+ $class[] = $current_order;
171
+ } else {
172
+ $order = $desc_first ? 'desc' : 'asc';
173
+ $class[] = 'sortable';
174
+ $class[] = $desc_first ? 'asc' : 'desc';
175
+ }
176
+
177
+ $column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
178
+ }
179
+
180
+ $id = $with_id ? "id='$column_key'" : '';
181
+
182
+ if (!empty($class))
183
+ $class = "class='" . join(' ', $class) . "'";
184
+
185
+ if ($column_key === 'cb') {
186
+ echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
187
+ } else {
188
+ echo "<th scope='col' $id $class $style colspan=\"3\">$column_display_name</th>";
189
+ }
190
+ }
191
+ }
192
+
193
+ function prepare_items() {
194
+ global $wpdb, $_wp_column_headers;
195
+ $where = array('1=1');
196
+ if (!empty($_REQUEST['sltype']) && $_REQUEST['sltype'] != 'all') {
197
+ if ($_REQUEST['sltype'] != 'other') {
198
+ $where[] = "type = '" . $_REQUEST['sltype'] . "'";
199
+ } else {
200
+ $where[] = "type IN ('comment','404_automaticaly')";
201
+ }
202
+ }
203
+
204
+ if (!empty($_REQUEST['sl_broken']) && $_REQUEST['sl_broken'] != 'all') {
205
+ if ($_REQUEST['sl_broken'] == 'valid_links') {
206
+ $where[] = "broken_internal = 0 AND broken_indexed = 0";
207
+ }elseif ($_REQUEST['sl_broken'] == 'internal_broken_links') {
208
+ $where[] = "broken_internal = 1";
209
+ } else {
210
+ $where[] = "broken_indexed = 1";
211
+ }
212
+ }
213
+
214
+ if (!empty($_REQUEST['sl_redirect']) && $_REQUEST['sl_redirect'] != 'all') {
215
+ if ($_REQUEST['sl_redirect'] == 'already_redirect') {
216
+ $where[] = "(broken_internal = 1 OR broken_indexed = 1)";
217
+ $where[] = "link_url_redirect !='' ";
218
+ } else {
219
+ $where[] = "(broken_internal = 1 OR broken_indexed = 1)";
220
+ $where[] = "link_url_redirect ='' ";
221
+ }
222
+ }
223
+
224
+ $keyword = !empty($_GET["txtkeyword"]) ? $_GET["txtkeyword"] : '';
225
+ if (isset($keyword) && $keyword != '') {
226
+ $where[] .= '(link_text LIKE "%' . $keyword . '%" OR link_url LIKE "%' . $keyword . '%")';
227
+ }
228
+
229
+ $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
230
+ $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
231
+ $sortable = $this->get_sortable_columns();
232
+ if (in_array($orderby, $sortable)) {
233
+ $orderStr = $orderby;
234
+ } else {
235
+ $orderStr = 'id';
236
+ }
237
+
238
+ if ($order == "asc") {
239
+ $orderStr .= " ASC";
240
+ } else {
241
+ $orderStr .= " DESC";
242
+ }
243
+
244
+ if (!empty($orderby) & !empty($order)) {
245
+ $orderStr = ' ORDER BY ' . $orderStr;
246
+ }
247
+
248
+ $query = "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
249
+ $columns = $this->get_columns();
250
+ $hidden = array();
251
+ $sortable = $this->get_sortable_columns();
252
+ $this->_column_headers = array($columns, $hidden, $sortable);
253
+ $total_items = $wpdb->query($query);
254
+ if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
255
+ $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
256
+ } else {
257
+ $_per_page = 0;
258
+ }
259
+
260
+ $per_page = get_user_option('metaseo_broken_link_per_page');
261
+ if ($per_page !== false) {
262
+ if ($_per_page && $_per_page !== $per_page) {
263
+ $per_page = $_per_page;
264
+ update_user_option(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
265
+ }
266
+ } else {
267
+ if ($_per_page > 0) {
268
+ $per_page = $_per_page;
269
+ } else {
270
+ $per_page = 10;
271
+ }
272
+ add_user_meta(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
273
+ }
274
+
275
+ $paged = !empty($_GET["paged"]) ? $_GET["paged"] : '';
276
+ if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
277
+ $paged = 1;
278
+ }
279
+
280
+ $total_pages = ceil($total_items / $per_page);
281
+
282
+ if (!empty($paged) && !empty($per_page)) {
283
+ $offset = ($paged - 1) * $per_page;
284
+ $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
285
+ }
286
+
287
+ $this->set_pagination_args(array(
288
+ 'total_items' => $total_items,
289
+ 'total_pages' => $total_pages,
290
+ 'per_page' => $per_page
291
+ ));
292
+
293
+
294
+ $this->items = $wpdb->get_results($query);
295
+ }
296
+
297
+ function search_box1() {
298
+ if (empty($_REQUEST['txtkeyword']) && !$this->has_items())
299
+ return;
300
+ $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
301
+ if (!empty($_REQUEST['orderby']))
302
+ echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
303
+ if (!empty($_REQUEST['order']))
304
+ echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
305
+ if (!empty($_REQUEST['post_mime_type']))
306
+ echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
307
+ if (!empty($_REQUEST['detached']))
308
+ echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
309
+ ?>
310
+ <p class="search-box">
311
+
312
+ <input type="search" id="image-search-input" name="txtkeyword" value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>" />
313
+ <?php submit_button('Search URL', 'button', 'search', false, array('id' => 'search-submit')); ?>
314
+ </p>
315
+ <?php
316
+ }
317
+
318
+ function redirect_fillter($name) {
319
+ $redirects = array('not_yet_redirect' => __('Not yet redirected', 'wp-meta-seo'), 'already_redirect' => __('Already redirected', 'wp-meta-seo'));
320
+ $curent_redirect = isset($_REQUEST['sl_redirect']) ? $_REQUEST['sl_redirect'] : 'all';
321
+ ?>
322
+ <label for="filter-by-redirect" class="screen-reader-text"><?php _e('Filter by redirect', 'wp-meta-seo'); ?></label>
323
+ <select name="<?php echo $name ?>" id="filter-by-redirect" class="redirect_fillter">
324
+ <option<?php selected($curent_redirect, 'all'); ?> value="all"><?php _e('Status', 'wp-meta-seo'); ?></option>
325
+ <?php
326
+ foreach ($redirects as $k => $redirect) {
327
+ if ($curent_redirect == $k) {
328
+ echo '<option selected value="' . $k . '">' . $redirect . '</option>';
329
+ } else {
330
+ echo '<option value="' . $k . '">' . $redirect . '</option>';
331
+ }
332
+ }
333
+ ?>
334
+ </select>
335
+
336
+ <?php
337
+ }
338
+
339
+ function broken_fillter($name) {
340
+ $brokens = array('valid_links' => __('Valid links', 'wp-meta-seo') ,'automaticaly_indexed' => __('404 automaticaly indexed', 'wp-meta-seo'), 'internal_broken_links' => __('Internal broken links', 'wp-meta-seo'));
341
+ $curent_broken = isset($_REQUEST['sl_broken']) ? $_REQUEST['sl_broken'] : 'all';
342
+ ?>
343
+ <label for="filter-by-broken" class="screen-reader-text"><?php _e('Filter by broken', 'wp-meta-seo'); ?></label>
344
+ <select name="<?php echo $name ?>" id="filter-by-broken" class="broken_fillter">
345
+ <option<?php selected($curent_broken, 'all'); ?> value="all"><?php _e('All', 'wp-meta-seo'); ?></option>
346
+ <?php
347
+ foreach ($brokens as $k => $broken) {
348
+ if ($curent_broken == $k) {
349
+ echo '<option selected value="' . $k . '">' . $broken . '</option>';
350
+ } else {
351
+ echo '<option value="' . $k . '">' . $broken . '</option>';
352
+ }
353
+ }
354
+ ?>
355
+ </select>
356
+
357
+ <?php
358
+ }
359
+
360
+ function type_fillter($name) {
361
+ $types = array('url' => 'URL', 'image' => 'Image', 'other' => 'Other');
362
+ $curent_type = isset($_REQUEST['sltype']) ? $_REQUEST['sltype'] : 'all';
363
+ ?>
364
+ <label for="filter-by-type" class="screen-reader-text"><?php _e('Filter by type', 'wp-meta-seo'); ?></label>
365
+ <select name="<?php echo $name ?>" id="filter-by-type" class="metaseo-filter">
366
+ <option<?php selected($curent_type, 'all'); ?> value="all"><?php _e('Type', 'wp-meta-seo'); ?></option>
367
+ <?php
368
+ foreach ($types as $k => $type) {
369
+ if ($curent_type == $k) {
370
+ echo '<option selected value="' . $k . '">' . $type . '</option>';
371
+ } else {
372
+ echo '<option value="' . $k . '">' . $type . '</option>';
373
+ }
374
+ }
375
+ ?>
376
+ </select>
377
+
378
+ <?php
379
+ submit_button(__('Filter'), 'button', 'filter_type_action', false, array('id' => 'broken-submit'));
380
+ echo '<div style="float:left;padding-left: 5px;"><div class="wpmf_process" data-w="0"></div>';
381
+ echo '<div data-paged="1" class="button wpms_scan_link">' . __('Index internal broken links', 'wp-meta-seo') . '</div></div>';
382
+ echo '<span class="spinner"></span>';
383
+
384
+ }
385
+
386
+ function flush_fillter($name) {
387
+ $flushs = array('automaticaly_indexed' => __('Automatic indexed 404', 'wp-meta-seo'), 'internal_broken_links' => __('Internal broken links', 'wp-meta-seo') , 'all' => __('Flush all 404', 'wp-meta-seo'));
388
+ ?>
389
+ <label for="filter-by-flush" class="screen-reader-text"><?php _e('Filter by flush', 'wp-meta-seo'); ?></label>
390
+ <select name="<?php echo $name ?>" id="filter-by-flush">
391
+ <option value="none"><?php _e('Select', 'wp-meta-seo'); ?></option>
392
+ <?php
393
+ foreach ($flushs as $k => $flush) {
394
+ echo '<option value="' . $k . '">' . $flush . '</option>';
395
+ }
396
+ ?>
397
+ </select>
398
+
399
+ <?php
400
+ echo '<div class="button wpms_flush_link">' . __('Flush', 'wp-meta-seo') . '</div>';
401
+
402
+ }
403
+
404
+ function display_rows() {
405
+ $url = URL;
406
+ $url = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', $url);
407
+ $records = $this->items;
408
+ $i = 0;
409
+ $alternate = "";
410
+ list( $columns, $hidden ) = $this->get_column_info();
411
+ if (!empty($records)) {
412
+ foreach ($records as $rec) {
413
+ $i++;
414
+ echo '<tr id="record_' . $i . '" data-link="' . $i . '" data-post_id="' . $rec->source_id . '">';
415
+ foreach ($columns as $column_name => $column_display_name) {
416
+
417
+ $class = sprintf('class="%1$s column-%1$s"', $column_name);
418
+ $style = "";
419
+
420
+ if (in_array($column_name, $hidden)) {
421
+ $style = ' style="display:none;"';
422
+ }
423
+
424
+ $attributes = $class . $style;
425
+
426
+ switch ($column_name) {
427
+ case 'col_link_url':
428
+ if($rec->type == 'url'){
429
+ $value_url = $rec->link_final_url;
430
+ }else{
431
+ $value_url = $rec->link_url;
432
+ }
433
+ echo '<td class="wpms_link_html" colspan="3">';
434
+ echo '<input type="hidden" class="wpms_link_text" value="' . esc_attr($rec->link_text) . '">';
435
+ echo '<a class="link_html" target="_blank" href="' . esc_url($value_url) . '">' . $value_url . '</a>';
436
+ $row_action = array(
437
+ 'edit' => '<a class="wpms_action_link wpms-edit-button" title="Edit this link"><div class="wpms_icon_action"><i class="material-icons">mode_edit</i></div><span>' . __('Redirect', 'wp-meta-seo') . '</span></a>',
438
+ 'delete' => '<a class="wpms_action_link submitdelete wpms-unlink-button" data-link_id="' . $rec->id . '" data-type="' . $rec->type . '" data-source_id="' . $rec->source_id . '" title="' . __('Remove this link from all posts', 'wp-meta-seo') . '"><div class="wpms_icon_action"><i class="material-icons">delete_forever</i></div><span>' . __('Remove link', 'wp-meta-seo') . '</span></a>',
439
+ 'recheck' => '<a class="wpms_action_link wpms-recheck-button" data-link_id="' . $rec->id . '" data-type="' . $rec->type . '" data-source_id="' . $rec->source_id . '" title="' . __('Recheck this link', 'wp-meta-seo') . '"><div class="wpms_icon_action"><i class="material-icons">loop</i></div><span>' . __('Recheck', 'wp-meta-seo') . '</span></a>'
440
+ );
441
+ echo $this->row_actions($row_action, false);
442
+ if(!empty($rec->source_id) && $rec->type == 'url'){
443
+ $iii = 0;
444
+ $pos = get_post($rec->source_id);
445
+ if(!empty($pos)){
446
+ preg_match_all("#<a[^>]*>.*?</a>#si", $pos->post_content, $matches, PREG_PATTERN_ORDER);
447
+ foreach ($matches[0] as $i => $content) {
448
+ preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
449
+ $href = $matches[1];
450
+ if($href == $rec->link_url){
451
+ $iii++;
452
+ }
453
+
454
+ }
455
+ }
456
+ }
457
+ ?>
458
+ <div class="wpms-inline-editor-content">
459
+ <h4><?php echo _x('Edit Link', 'inline editor title', 'wp-meta-seo'); ?></h4>
460
+ <?php
461
+ if($rec->type == 'url'){
462
+ if($iii>1){
463
+ echo '<span class="wpms-input-text-wrap"><span class="title">'.__('Text', 'wp-meta-seo').'</span><input type="text" name="link_text" class="wpms-link-text-field" placeholder="'.__('Multiple link', 'wp-meta-seo').'" data-type="multi" /></span>';
464
+ }else{
465
+ echo '<span class="wpms-input-text-wrap"><span class="title">'.__('Text', 'wp-meta-seo').'</span><input type="text" name="link_text" class="wpms-link-text-field" value="'.esc_attr($rec->link_text).'" data-type="only" /></span>';
466
+ }
467
+ }else{
468
+ echo '<span class="wpms-input-text-wrap"><span class="title">'.__('Text', 'wp-meta-seo').'</span><input readonly type="text" name="link_text" class="wpms-link-text-field" value="(None)" data-type="only" /></span>';
469
+ }
470
+ ?>
471
+
472
+ <span class="wpms-input-text-wrap"><span class="title"><?php _e('URL', 'wp-meta-seo'); ?></span><input <?php echo ($rec->type == '404_automaticaly') ? 'readonly' : '' ?> type="text" name="link_url" class="wpms-link-url-field" value="<?php echo esc_attr($value_url); ?>" /></span>
473
+ <span class="wpms-input-text-wrap"><span class="title"><?php _e('Redirect', 'wp-meta-seo'); ?></span><input type="text" name="link_url_redirect" class="wpms-link-redirect-field" value="<?php echo esc_attr($rec->link_url_redirect); ?>" /></span>
474
+ </label>
475
+
476
+ <div class="submit wpms-inline-editor-buttons">
477
+ <input type="button" class="button-secondary cancel alignleft wpms-cancel-button" value="<?php echo esc_attr(__('Cancel', 'wp-meta-seo')); ?>" />
478
+ <input type="button" data-type="<?php echo $rec->type ?>" data-link_id="<?php echo $rec->id ?>" data-source_id="<?php echo $rec->source_id ?>" class="button-primary save alignright wpms-update-link-button" value="<?php echo esc_attr(__('Update', 'wp-meta-seo')); ?>" />
479
+ </div>
480
+ </div>
481
+ <?php
482
+ echo '</td>';
483
+ break;
484
+
485
+ case 'col_hit':
486
+ echo '<td colspan="3" style="text-align:center;">';
487
+ echo $rec->hit;
488
+ echo '</td>';
489
+ break;
490
+ case 'col_status':
491
+ echo '<td colspan="3" class="col_status">';
492
+
493
+ if(strpos($rec->status_text, '200') !== false){
494
+ echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Link is OK">done</i>';
495
+ }elseif(strpos($rec->status_text, '301') !== false){
496
+ echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Permanent redirect">done</i>';
497
+ }elseif(strpos($rec->status_text, '302') !== false){
498
+ echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Moved temporarily">done</i>';
499
+ }elseif(strpos($rec->status_text, '404') !== false || $rec->status_text == 'Server Not Found'){
500
+ $wpms_settings_404 = get_option('wpms_settings_404');
501
+ if((isset($wpms_settings_404['wpms_redirect_homepage']) && $wpms_settings_404['wpms_redirect_homepage'] == 1) || $rec->link_url_redirect != ''){
502
+ echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Permanent redirect">done</i>';
503
+ }else{
504
+ echo '<i class="material-icons wpms_warning metaseo_help_status" alt="404 error, not found">warning</i>';
505
+ }
506
+ }else{
507
+ echo $rec->status_text;
508
+ }
509
+
510
+ echo '</td>';
511
+ break;
512
+
513
+ case 'col_link_text':
514
+ if ($rec->type == 'image') {
515
+ echo '<td colspan="3" class="link_text"><span style="float: left;margin-right: 5px;"><i class="material-icons">photo</i></span><span> ' . __('Image', 'wp-meta-seo') . '</span></td>';
516
+ } elseif ($rec->type == 'comment') {
517
+ echo '<td colspan="3" class="link_text"><span style="float: left;margin-right: 5px;"><i class="material-icons">chat_bubble</i></span><span> ' . $rec->link_text . '</span></td>';
518
+ } else {
519
+ if (strip_tags($rec->link_text) != '') {
520
+ echo '<td colspan="3" class="link_text">' . strip_tags($rec->link_text) . '</td>';
521
+ } else {
522
+ echo '<td colspan="3" class="link_text"><i>(None)</i></td>';
523
+ }
524
+ }
525
+
526
+ break;
527
+
528
+ case 'col_source':
529
+ if ($rec->type == '404_automaticaly') {
530
+ echo '<td colspan="3">' . __('404 automaticaly indexed', 'wp-meta-seo') . '</td>';
531
+ } else {
532
+ if ($rec->type == 'comment') {
533
+ $source = get_comment($rec->source_id);
534
+ if(!empty($source)){
535
+ $row_action = array(
536
+ 'edit' => '<a target="_blank" href="' . get_edit_comment_link($rec->source_id) . '" title="Edit this item">Edit</a>',
537
+ 'view' => '<a target="_blank" href="' . get_comment_link($rec->source_id) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
538
+ );
539
+ $source_inner = '<a target="_blank" href="' . get_edit_comment_link($rec->source_id) . '">' . $source->comment_author . '</a>';
540
+ }
541
+ } else {
542
+ $source = get_post($rec->source_id);
543
+ if(!empty($source)){
544
+ $row_action = array(
545
+ 'edit' => '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '" title="Edit this item">Edit</a>',
546
+ 'view' => '<a target="_blank" href="' . get_post_permalink($rec->source_id) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
547
+ );
548
+
549
+ $source_inner = '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '">' . $source->post_title . '</a>';
550
+ }
551
+ }
552
+
553
+ echo '<td colspan="3">';
554
+ if(!empty($source)){
555
+ echo $source_inner;
556
+ echo $this->row_actions($row_action, false);
557
+ }else{
558
+ echo '<a>'.__('Source Not Found','wp-meta-seo').'</a>';
559
+ }
560
+ echo '</td>';
561
+ break;
562
+ }
563
+ }
564
+ }
565
+
566
+ echo '</tr>';
567
+ }
568
+ }
569
+ }
570
+
571
+ public function process_action() {
572
+ global $wpdb;
573
+ $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
574
+ $redirect = false;
575
+
576
+ if (isset($_POST['search'])) {
577
+ $current_url = add_query_arg(array("search" => "Search", "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))), $current_url);
578
+ $redirect = true;
579
+ }
580
+
581
+ if (isset($_POST['filter_type_action']) and $_POST['filter_type_action'] === 'Filter') {
582
+ $current_url = add_query_arg(array("sltype" => $_POST["sltype"], 'sl_redirect' => $_POST["sl_redirect"], 'sl_broken' => $_POST["sl_broken"]), $current_url);
583
+ $redirect = true;
584
+ }
585
+
586
+ if (!empty($_POST['paged'])) {
587
+ $current_url = add_query_arg(array("paged" => intval($_POST['paged'])), $current_url);
588
+ $redirect = true;
589
+ }
590
+
591
+ if (!empty($_POST['metaseo_broken_link_per_page'])) {
592
+ $current_url = add_query_arg(array("metaseo_broken_link_per_page" => intval($_POST['metaseo_broken_link_per_page'])), $current_url);
593
+ $redirect = true;
594
+ }
595
+
596
+ if ($redirect === true) {
597
+ wp_redirect($current_url);
598
+ ob_end_flush();
599
+ exit();
600
+ }
601
+ }
602
+
603
+ public static function wpms_get_links() {
604
+ global $wpdb, $_wp_column_headers;
605
+
606
+ $where = array();
607
+ $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
608
+ if ($post_type == "-1") {
609
+ $post_type = "";
610
+ }
611
+
612
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
613
+ unset($post_types['attachment']);
614
+ if (!empty($post_type) && !in_array($post_type, $post_types))
615
+ $post_type = '\'post\'';
616
+ else if (empty($post_type)) {
617
+ $post_type = "'" . implode("', '", $post_types) . "'";
618
+ } else {
619
+ $post_type = "'" . $post_type . "'";
620
+ }
621
+
622
+ $where[] = "post_type IN ($post_type)";
623
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
624
+ $states['trash'] = 'trash';
625
+ $all_states = "'" . implode("', '", $states) . "'";
626
+
627
+ if (empty($_REQUEST['post_status'])) {
628
+ $where[] = "post_status IN ($all_states)";
629
+ } else {
630
+ $requested_state = $_REQUEST['post_status'];
631
+ if (in_array($requested_state, $states)) {
632
+ $where[] = "post_status IN ('$requested_state')";
633
+ } else {
634
+ $where[] = "post_status IN ($all_states)";
635
+ }
636
+ }
637
+
638
+ $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
639
+ . " FROM $wpdb->posts "
640
+ . " WHERE " . implode(' AND ', $where);
641
+
642
+ $results = $wpdb->get_results($query);
643
+ $list_link = array();
644
+
645
+ $comments = get_comments();
646
+ foreach ($comments as $comment) {
647
+ if (!empty($comment->comment_author_url)) {
648
+
649
+ $row_action = array(
650
+ 'edit' => '<a href="' . get_edit_comment_link($comment->comment_ID) . '" title="Edit this item">Edit</a>',
651
+ 'view' => '<a href="' . get_comment_link($comment->comment_ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
652
+ );
653
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
654
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($comment->comment_author_url);
655
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
656
+ $list_link[$comment->comment_author_url . $comment->comment_ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $comment->comment_ID, $comment->comment_author_url, $comment->comment_author, 'comment', $status, $status_type);
657
+ }
658
+ }
659
+
660
+ foreach ($results as $post) {
661
+ if($post->post_excerpt != 'metaseo_404_page'){
662
+ $dom = new DOMDocument;
663
+ libxml_use_internal_errors(true);
664
+ if (isset($post->post_content) && $post->post_content != '') {
665
+ preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
666
+ foreach (array_unique($matches[0]) as $i => $content) {
667
+ preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
668
+ $href = $matches[1];
669
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
670
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
671
+ $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
672
+ $row_action = array(
673
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
674
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
675
+ );
676
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
677
+ $list_link[$href.'url'.$post->ID.$link_text] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $href, $link_text, 'url', $status, $status_type);
678
+ }
679
+ preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
680
+ foreach (array_unique($matches[0]) as $content) {
681
+
682
+ $row_action = array(
683
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
684
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
685
+ );
686
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
687
+ preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
688
+ $src = $matches[1];
689
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
690
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
691
+ $link_text = '';
692
+ $list_link[$src.'img'.$post->ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $src, $link_text, 'image', $status, $status_type);
693
+ }
694
+ }
695
+ }
696
+ }
697
+
698
+ return $list_link;
699
+ }
700
+
701
+ public static function get_result_link( $source_link, $row_action, $source_id, $url, $link_text, $type, $status, $status_type) {
702
+ $res = array(
703
+ 'source_link' => $source_link,
704
+ 'row_action' => $row_action,
705
+ 'source_id' => (int) $source_id,
706
+ 'link_url' => $url,
707
+ 'link_text' => $link_text,
708
+ 'type' => $type,
709
+ 'status' => $status,
710
+ 'status_type' => $status_type);
711
+
712
+ if($type == 'url'){
713
+ if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
714
+ $perlink = get_option('permalink_structure');
715
+ if(empty($perlink)){
716
+ $res['link_final_url'] = get_site_url().'/'.$url;
717
+ }else{
718
+ $res['link_final_url'] = $perlink.'/'.$url;
719
+ }
720
+ }else{
721
+ $res['link_final_url'] = $url;
722
+ }
723
+ }else{
724
+ $res['link_final_url'] = $url;
725
+ }
726
+ return $res;
727
+ }
728
+
729
+ public static function get_urlstatus($url) {
730
+ $status = @get_headers($url, 0);
731
+ if (isset($status[0])) {
732
+ return $status[0];
733
+ } else {
734
+ return 'Server Not Found';
735
+ }
736
+ }
737
+
738
+ public static function get_urlstatus_type($status) {
739
+ if (isset($status) && $status != 'Server Not Found') {
740
+ if (((int) substr($status, 9, 3) >= 200 && (int) substr($status, 9, 3) <= 204) || (int) substr($status, 9, 3) == 401) {
741
+ $type = 'ok';
742
+ } elseif (((int) substr($status, 9, 3) >= 400 && (int) substr($status, 9, 3) <= 503 && (int) substr($status, 9, 3) != 401)) {
743
+ if (in_array((int) substr($status, 9, 3), array(404, 410))) {
744
+ $type = 'broken_internal';
745
+ } else {
746
+ $type = 'warning';
747
+ }
748
+ } elseif (((int) substr($status, 9, 3) >= 301 && (int) substr($status, 9, 3) <= 304)) {
749
+ $type = 'ok';
750
+ } else {
751
+ $type = 'dismissed';
752
+ }
753
+ } else {
754
+ $type = 'broken_internal';
755
+ }
756
+ return $type;
757
+ }
758
+
759
+ public static function wpms_deleted_comment($comment_ID) {
760
+
761
+ global $wpdb;
762
+ $wpdb->query(
763
+ $wpdb->prepare(
764
+ "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
765
+ AND type = %s
766
+ ", $comment_ID, 'comment'
767
+ )
768
+ );
769
+ }
770
+
771
+ public static function wpms_delete_post($post_id) {
772
+ global $wpdb;
773
+ $wpdb->query(
774
+ $wpdb->prepare(
775
+ "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
776
+ AND type != %s
777
+ ", $post_id, 'comment'
778
+ )
779
+ );
780
+ }
781
+
782
+ public static function wpms_update_comment($comment_ID) {
783
+ $comment = get_comment($comment_ID);
784
+ if (!empty($comment->comment_author_url)) {
785
+ global $wpdb;
786
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus(($comment->comment_author_url));
787
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
788
+ $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type=%s ", array($comment_ID, 'comment'));
789
+ $check = $wpdb->get_var($sql);
790
+ if ($check == 0) {
791
+ $value = array(
792
+ 'link_url' => $comment->comment_author_url,
793
+ 'link_text' => $comment->comment_author,
794
+ 'source_id' => $comment_ID,
795
+ 'type' => 'comment',
796
+ 'status_code' => $status,
797
+ 'status_text' => ($status != 'Server Not Found') ? substr($status, 9) : 'Server Not Found',
798
+ 'broken_indexed' => 0,
799
+ 'broken_internal' => 0,
800
+ 'warning' => 0,
801
+ 'dismissed' => 0,
802
+ );
803
+ if (isset($status_type) && $status_type != 'ok') {
804
+ $value[$status_type] = 1;
805
+ }
806
+ $wpdb->insert(
807
+ $wpdb->prefix . 'wpms_links', $value
808
+ );
809
+ } else {
810
+ $value = array('link_url' => $comment->comment_author_url,
811
+ 'status_code' => $status,
812
+ 'status_text' => ($status != 'Server Not Found') ? substr($status, 9) : 'Server Not Found',
813
+ 'broken_indexed' => 0,
814
+ 'broken_internal' => 0,
815
+ 'warning' => 0,
816
+ 'dismissed' => 0,
817
+ );
818
+
819
+ if (isset($_POST['link_redirect']))
820
+ $value['link_url_redirect'] = ($_POST['link_redirect']);
821
+
822
+ if (isset($status_type) && $status_type != 'ok') {
823
+ $value[$status_type] = 1;
824
+ }
825
+ $wpdb->update(
826
+ $wpdb->prefix . 'wpms_links', $value, array('source_id' => $comment_ID, 'type' => 'comment'), array('%s', '%s', '%s', '%d', '%d', '%d', '%d'), array('%d', '%s')
827
+ );
828
+ }
829
+ }
830
+ }
831
+
832
+ public static function wpms_update_post($post_ID, $post_after, $post_before) {
833
+ $post = $post_after;
834
+ $dom = new DOMDocument;
835
+ libxml_use_internal_errors(true);
836
+ $links_in_content = array();
837
+
838
+ if($post->post_excerpt != 'metaseo_404_page'){
839
+ if (isset($post->post_content) && $post->post_content != '') {
840
+ preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
841
+ foreach (array_unique($matches[0]) as $i => $content) {
842
+ preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
843
+ $href = $matches[1];
844
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
845
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
846
+ $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
847
+ $row_action = array(
848
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
849
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
850
+ );
851
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
852
+ $links_in_content[$href.'url'.$post->ID.$link_text] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $href, $link_text, 'url', $status, $status_type);
853
+ }
854
+ preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
855
+ foreach (array_unique($matches[0]) as $content) {
856
+
857
+ $row_action = array(
858
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
859
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
860
+ );
861
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
862
+ preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
863
+ $src = $matches[1];
864
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
865
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
866
+ $link_text = '';
867
+ $links_in_content[$src.'img'.$post->ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $src, $link_text, 'image', $status, $status_type);
868
+ }
869
+ }
870
+
871
+ global $wpdb;
872
+ $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type != %s", array($post->ID, "comment"));
873
+ $links = $wpdb->get_results($sql);
874
+ foreach ($links as $link) {
875
+ if (empty($links_in_content[$link->link_url.$link->type])) {
876
+ $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
877
+ } else {
878
+ unset($links_in_content[$link->link_url.$link->type.$link->link_text]);
879
+ }
880
+ }
881
+
882
+ if (!empty($links_in_content)) {
883
+ foreach ($links_in_content as $link){
884
+ MetaSeo_Broken_Link_Table::wpms_insert_link($link, $wpdb);
885
+ }
886
+ }
887
+ }
888
+ }
889
+
890
+ public static function wpms_scan_link() {
891
+
892
+ global $wpdb, $_wp_column_headers;
893
+ $limit_comment = 10;
894
+ $limit_post = 1;
895
+
896
+ $where = array();
897
+ $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
898
+ if ($post_type == "-1") {
899
+ $post_type = "";
900
+ }
901
+
902
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
903
+ unset($post_types['attachment']);
904
+ if (!empty($post_type) && !in_array($post_type, $post_types))
905
+ $post_type = '\'post\'';
906
+ else if (empty($post_type)) {
907
+ $post_type = "'" . implode("', '", $post_types) . "'";
908
+ } else {
909
+ $post_type = "'" . $post_type . "'";
910
+ }
911
+
912
+ $where[] = "post_type IN ($post_type)";
913
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
914
+ $states['trash'] = 'trash';
915
+ $all_states = "'" . implode("', '", $states) . "'";
916
+
917
+ if (empty($_REQUEST['post_status'])) {
918
+ $where[] = "post_status IN ($all_states)";
919
+ } else {
920
+ $requested_state = $_REQUEST['post_status'];
921
+ if (in_array($requested_state, $states)) {
922
+ $where[] = "post_status IN ('$requested_state')";
923
+ } else {
924
+ $where[] = "post_status IN ($all_states)";
925
+ }
926
+ }
927
+
928
+ $total_comments = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "comments");
929
+ $total_posts = $wpdb->get_var("SELECT COUNT(*)"
930
+ . " FROM $wpdb->posts "
931
+ . " WHERE " . implode(' AND ', $where));
932
+
933
+ $total_link = (int)$total_comments + (int) $total_posts;
934
+ $percent_comment = 50;
935
+ $percent_post = 50;
936
+ if(!empty($total_comments)) $percent_comment = 50/$total_comments;
937
+ if($total_comments < $limit_comment) $percent_comment = 50;
938
+ if(!empty($total_posts)) $percent_post = 50/$total_posts;
939
+ if($total_posts < $limit_post) $percent_post = 50;
940
+
941
+ // scan link in comment
942
+ $comments = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "comments WHERE comment_author_url != '' AND comment_author_url NOT IN (SELECT link_url FROM " . $wpdb->prefix . "wpms_links WHERE type='comment') LIMIT $limit_comment");
943
+ $i = 0;
944
+ if (!empty($comments)) {
945
+ foreach ($comments as $comment) {
946
+ if (!empty($comment->comment_author_url)) {
947
+
948
+ $row_action = array(
949
+ 'edit' => '<a href="' . get_edit_comment_link($comment->comment_ID) . '" title="Edit this item">Edit</a>',
950
+ 'view' => '<a href="' . get_comment_link($comment->comment_ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
951
+ );
952
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
953
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($comment->comment_author_url);
954
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
955
+ $coms = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $comment->comment_ID, $comment->comment_author_url, $comment->comment_author, 'comment', $status, $status_type);
956
+ MetaSeo_Broken_Link_Table::wpms_insert_link($coms, $wpdb);
957
+ $i++;
958
+ }
959
+ }
960
+ wp_send_json(array('status' => false, 'type' => 'limit' , 'percent' => $percent_comment));
961
+ }
962
+
963
+ // scan link in post
964
+ $j = 0;
965
+ $off_set = ($_POST['paged'] - 1) * $limit_post;
966
+ $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
967
+ . " FROM $wpdb->posts "
968
+ . " WHERE " . implode(' AND ', $where) . "LIMIT $limit_post OFFSET $off_set";
969
+
970
+ $results = $wpdb->get_results($query);
971
+ if (empty($results))
972
+ wp_send_json(array('status' => true));
973
+
974
+ foreach ($results as $post) {
975
+ if ($post->post_excerpt != 'metaseo_404_page') {
976
+ $dom = new DOMDocument;
977
+ libxml_use_internal_errors(true);
978
+ if (isset($post->post_content) && $post->post_content != '') {
979
+ preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
980
+ foreach (array_unique($matches[0]) as $i => $content) {
981
+ preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
982
+ $href = $matches[1];
983
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
984
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
985
+ $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
986
+ $row_action = array(
987
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
988
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
989
+ );
990
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
991
+ $link_a = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $href, $link_text, 'url', $status, $status_type);
992
+ MetaSeo_Broken_Link_Table::wpms_insert_link($link_a, $wpdb);
993
+ }
994
+ preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
995
+ foreach (array_unique($matches[0]) as $content) {
996
+
997
+ $row_action = array(
998
+ 'edit' => '<a href="' . get_edit_post_link($post->ID) . '" title="Edit this item">Edit</a>',
999
+ 'view' => '<a href="' . get_post_permalink($post->ID) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
1000
+ );
1001
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
1002
+ preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1003
+ $src = $matches[1];
1004
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
1005
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1006
+ $link_text = '';
1007
+ $link_sou = MetaSeo_Broken_Link_Table::get_result_link($source_link, $row_action, $post->ID, $src, $link_text, 'image', $status, $status_type);
1008
+ MetaSeo_Broken_Link_Table::wpms_insert_link($link_sou, $wpdb);
1009
+ }
1010
+ }
1011
+ }
1012
+ $j++;
1013
+ if ($j >= $limit_post) {
1014
+ wp_send_json(array('status' => false, 'type' => 'limit_post', 'paged' => $_POST['paged'] ,'percent' => $percent_post*count($results)));
1015
+ }
1016
+ }
1017
+ wp_send_json(array('status' => true));
1018
+ }
1019
+
1020
+ public static function wpms_insert_link($link, $wpdb) {
1021
+ $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE link_url=%s AND type=%s AND source_id=%d ", array($link['link_url'], $link['type'], $link['source_id']));
1022
+ $check = $wpdb->get_var($sql);
1023
+ if ($check == 0) {
1024
+ $columns = array(
1025
+ 'link_url' => $link['link_url'],
1026
+ 'link_final_url' => $link['link_final_url'],
1027
+ 'link_text' => $link['link_text'],
1028
+ 'source_id' => $link['source_id'],
1029
+ 'type' => $link['type'],
1030
+ 'status_code' => $link['status'],
1031
+ 'status_text' => ($link['status'] != 'Server Not Found') ? substr($link['status'], 9) : 'Server Not Found',
1032
+ 'broken_indexed' => 0,
1033
+ 'broken_internal' => 0,
1034
+ 'warning' => 0,
1035
+ 'dismissed' => 0,
1036
+ );
1037
+ if (isset($link['status_type']) && $link['status_type'] != 'ok') {
1038
+ $columns[$link['status_type']] = 1;
1039
+ }
1040
+
1041
+ $wpdb->insert(
1042
+ $wpdb->prefix . 'wpms_links', $columns
1043
+ );
1044
+ }
1045
+ }
1046
+
1047
+ public static function wpms_flush_link() {
1048
+ global $wpdb;
1049
+ if(isset($_POST['type']) && $_POST['type'] != 'none'){
1050
+ switch ($_POST['type']){
1051
+ case 'automaticaly_indexed':
1052
+ $wpdb->query(
1053
+ $wpdb->prepare(
1054
+ "
1055
+ DELETE FROM ".$wpdb->prefix . "wpms_links
1056
+ WHERE broken_indexed = %d AND link_url_redirect = %s
1057
+ " , array(1,'')
1058
+ )
1059
+ );
1060
+ break;
1061
+ case 'internal_broken_links':
1062
+ $wpdb->query(
1063
+ $wpdb->prepare(
1064
+ "
1065
+ DELETE FROM ".$wpdb->prefix . "wpms_links
1066
+ WHERE broken_internal = %d AND link_url_redirect = %s
1067
+ " , array(1,'')
1068
+ )
1069
+ );
1070
+ break;
1071
+ case 'all':
1072
+ $wpdb->query(
1073
+ $wpdb->prepare(
1074
+ "
1075
+ DELETE FROM ".$wpdb->prefix . "wpms_links
1076
+ WHERE (broken_internal = %d
1077
+ OR broken_indexed = %d) AND link_url_redirect = %s
1078
+ " , array(1,1,'')
1079
+ )
1080
+ );
1081
+
1082
+ break;
1083
+ }
1084
+ wp_send_json(true);
1085
+
1086
+ }
1087
+ wp_send_json(false);
1088
+ }
1089
+
1090
+ public static function wpms_update_link() {
1091
+
1092
+ if (isset($_POST['link_id'])) {
1093
+ global $wpdb;
1094
+ $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($_POST['link_id']));
1095
+ $link_detail = $wpdb->get_row($sql);
1096
+ if (empty($link_detail))
1097
+ wp_send_json(false);
1098
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus(($_POST['new_link']));
1099
+ if ($status == 'Server Not Found') {
1100
+ $status_text = 'Server Not Found';
1101
+ } else {
1102
+ $status_text = substr($status, 9);
1103
+ }
1104
+
1105
+ $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1106
+
1107
+ if ($link_detail->type != '404_automaticaly') {
1108
+ $value = array('link_url' => ($_POST['new_link']),
1109
+ 'link_final_url' => '',
1110
+ 'link_url_redirect' => '',
1111
+ 'link_text' => stripcslashes($_POST['new_text']),
1112
+ 'status_code' => $status,
1113
+ 'status_text' => $status_text,
1114
+ 'broken_indexed' => 0,
1115
+ 'broken_internal' => 0,
1116
+ 'warning' => 0,
1117
+ 'dismissed' => 0,
1118
+ );
1119
+
1120
+ if (!preg_match("~^(?:f|ht)tps?://~i", $_POST['new_link'])) {
1121
+ $perlink = get_option('permalink_structure');
1122
+ if(empty($perlink)){
1123
+ $value['link_final_url'] = get_site_url().'/'.$_POST['new_link'];
1124
+ }else{
1125
+ $value['link_final_url'] = $perlink.'/'.$_POST['new_link'];
1126
+ }
1127
+ }else{
1128
+ $value['link_final_url'] = $_POST['new_link'];
1129
+ }
1130
+
1131
+ if (!empty($_POST['link_redirect']))
1132
+ $value['link_url_redirect'] = ($_POST['link_redirect']);
1133
+ if (isset($status_type) && $status_type != 'ok') {
1134
+ $value[$status_type] = 1;
1135
+ }
1136
+ } else {
1137
+ $status = MetaSeo_Broken_Link_Table::get_urlstatus(($_POST['link_redirect']));
1138
+ if ($status == 'Server Not Found') {
1139
+ $status_text = 'Server Not Found';
1140
+ } else {
1141
+ $status_text = substr($status, 9);
1142
+ }
1143
+
1144
+ $value = array(
1145
+ 'link_url_redirect' => ($_POST['link_redirect']),
1146
+ 'status_code' => $status,
1147
+ 'status_text' => $status_text,
1148
+ 'broken_indexed' => 1
1149
+ );
1150
+ }
1151
+
1152
+ $wpdb->update(
1153
+ $wpdb->prefix . 'wpms_links', $value, array('ID' => $_POST['link_id'])
1154
+ );
1155
+
1156
+ switch ($link_detail->type) {
1157
+ case '404_automaticaly':
1158
+ wp_send_json(array('status' => true, 'type' => '404_automaticaly', 'status_text' => $status_text, 'new_link' => esc_url($_POST['new_link'])));
1159
+ break;
1160
+ case 'image':
1161
+ $post = get_post($link_detail->source_id);
1162
+ if(!empty($post)){
1163
+ $old_value = $post->post_content;
1164
+ $edit_result = MetaSeo_Broken_Link_Table::edit_linkimg($old_value, $_POST['new_link'], $link_detail->link_url);
1165
+ $my_post = array(
1166
+ 'ID' => $link_detail->source_id,
1167
+ 'post_content' => $edit_result['content']
1168
+ );
1169
+ remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1170
+ wp_update_post($my_post);
1171
+ wp_send_json(array('status' => true, 'type' => 'image', 'status_text' => $status_text, 'new_link' => esc_url($edit_result['raw_url']) ));
1172
+ }
1173
+ break;
1174
+ case 'url':
1175
+ $post = get_post($link_detail->source_id);
1176
+ if(!empty($post)){
1177
+ $old_value = $post->post_content;
1178
+ if(isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $_POST['new_text'] == ''){
1179
+ $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $_POST['new_link'], $link_detail->link_url);
1180
+ $new_text = '';
1181
+ }else{
1182
+ $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $_POST['new_link'], $link_detail->link_url, $_POST['new_text']);
1183
+ $new_text = strip_tags($edit_result['link_text']);
1184
+ }
1185
+
1186
+ $my_post = array(
1187
+ 'ID' => $link_detail->source_id,
1188
+ 'post_content' => $edit_result['content']
1189
+ );
1190
+ remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1191
+ wp_update_post($my_post);
1192
+ wp_send_json(array('status' => true, 'type' => 'url', 'status_text' => $status_text, 'new_link' => $edit_result['raw_url'], 'new_text' => $new_text ));
1193
+ }
1194
+
1195
+ break;
1196
+ case 'comment':
1197
+ wp_update_comment(array('comment_ID' => $link_detail->source_id, 'comment_author_url' => $_POST['new_link']));
1198
+ wp_send_json(array('status' => true, 'type' => 'orther', 'status_text' => $status_text, 'new_link' => $_POST['new_link']));
1199
+ break;
1200
+ }
1201
+ }
1202
+ wp_send_json(false);
1203
+ }
1204
+
1205
+ public static function wpms_unlink() {
1206
+ if (isset($_POST['link_id'])) {
1207
+ global $wpdb;
1208
+ $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($_POST['link_id']));
1209
+ $link_detail = $wpdb->get_row($sql);
1210
+ if (empty($link_detail))
1211
+ wp_send_json(false);
1212
+ $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => $_POST['link_id']));
1213
+ switch ($link_detail->type) {
1214
+ case '404_automaticaly':
1215
+ wp_send_json(true);
1216
+ break;
1217
+ case 'image':
1218
+ $post = get_post($link_detail->source_id);
1219
+ if(!empty($post)){
1220
+ $old_value = $post->post_content;
1221
+ $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_img($old_value, $link_detail->link_url);
1222
+ remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1223
+ $my_post = array(
1224
+ 'ID' => $link_detail->source_id,
1225
+ 'post_content' => $new_content
1226
+ );
1227
+ wp_update_post($my_post);
1228
+ }
1229
+ wp_send_json(true);
1230
+ break;
1231
+ case 'url':
1232
+ $post = get_post($link_detail->source_id);
1233
+ if(!empty($post)){
1234
+ $old_value = $post->post_content;
1235
+ $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_html($old_value, $link_detail->link_url);
1236
+ remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1237
+ $my_post = array(
1238
+ 'ID' => $link_detail->source_id,
1239
+ 'post_content' => $new_content
1240
+ );
1241
+ wp_update_post($my_post);
1242
+ }
1243
+ wp_send_json(true);
1244
+ break;
1245
+ case 'comment':
1246
+ wp_update_comment(array('comment_ID' => $link_detail->source_id, 'comment_author_url' => ''));
1247
+ wp_send_json(true);
1248
+ break;
1249
+ }
1250
+ }
1251
+ wp_send_json(false);
1252
+ }
1253
+
1254
+ public static function edit_linkimg($content, $new_url, $old_url) {
1255
+ self::$old_url = $old_url;
1256
+ self::$new_url = htmlentities($new_url);
1257
+ $content = preg_replace_callback(self::$img_pattern, array('MetaSeo_Broken_Link_Table', 'editimg_callback'), $content);
1258
+
1259
+ return array(
1260
+ 'content' => $content,
1261
+ 'raw_url' => self::$new_url,
1262
+ );
1263
+ }
1264
+
1265
+ public static function editimg_callback($matches) {
1266
+ $url = $matches[3];
1267
+ if (($url) == self::$old_url) {
1268
+