WP Meta SEO - Version 3.7.3

Version Description

  • Fix : Enhance code readability and performance
Download this release

Release Info

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

Code changes from version 3.7.2 to 3.7.3

Files changed (43) hide show
  1. css/html_sitemap.css +1 -1
  2. css/materialize/materialize_frontend_accordions_theme.css +4 -2
  3. css/metabox-tabs.css +5 -0
  4. inc/autoload.php +5 -2
  5. inc/breadcrumb/class.metaseo-breadcrumb.php +162 -121
  6. inc/class.image-helper.php +194 -164
  7. inc/class.metaseo-admin.php +954 -652
  8. inc/class.metaseo-broken-link-table.php +837 -737
  9. inc/class.metaseo-content-list-table.php +319 -364
  10. inc/class.metaseo-dashboard.php +269 -202
  11. inc/class.metaseo-front_end.php +38 -37
  12. inc/class.metaseo-google-analytics.php +28 -14
  13. inc/class.metaseo-image-list-table.php +648 -651
  14. inc/class.metaseo-link-list-table.php +208 -295
  15. inc/class.metaseo-meta.php +97 -91
  16. inc/class.metaseo-metabox.php +243 -409
  17. inc/class.metaseo-opengraph.php +250 -196
  18. inc/class.metaseo-sitemap.php +756 -601
  19. inc/class.metaseo-snippet-preview.php +54 -28
  20. inc/class.wp-metaseo.php +23 -10
  21. inc/google_analytics/tracking/code-classic.php +10 -5
  22. inc/google_analytics/tracking/code-universal.php +17 -14
  23. inc/google_analytics/tracking/custom.php +0 -12
  24. inc/google_analytics/tracking/events-universal.php +4 -3
  25. inc/google_analytics/wpmsga.php +17 -1
  26. inc/google_analytics/wpmsgapi.php +224 -191
  27. inc/google_analytics/wpmstools.php +76 -49
  28. inc/pages/content-meta.php +3 -2
  29. inc/pages/dashboard.php +55 -56
  30. inc/pages/dashboard_widgets.php +29 -29
  31. inc/pages/google-analytics/form-connect.php +20 -16
  32. inc/pages/google-analytics/ga-trackcode.php +46 -45
  33. inc/pages/google-analytics/google-analytics.php +29 -25
  34. inc/pages/google-analytics/menu.php +10 -6
  35. inc/pages/image-meta.php +2 -1
  36. inc/pages/link-meta.php +4 -3
  37. inc/pages/metaseo-broken-link.php +6 -3
  38. inc/pages/metaseo-image-compression.php +70 -54
  39. inc/pages/notification.php +8 -8
  40. inc/pages/settings.php +54 -43
  41. inc/pages/sitemaps/metaseo-google-sitemap.php +10 -8
  42. inc/pages/sitemaps/metaseo-source_menu.php +8 -6
  43. inc/pages/sitemaps/metaseo-source_pages.php +18 -18
css/html_sitemap.css CHANGED
@@ -33,7 +33,7 @@
33
  background: none;
34
  }
35
 
36
- #wpms_sitemap ul ul, #sitemap_pages ul {
37
  margin-bottom: 0;
38
  list-style-type: circle;
39
  }
33
  background: none;
34
  }
35
 
36
+ #wpms_sitemap ul {
37
  margin-bottom: 0;
38
  list-style-type: circle;
39
  }
css/materialize/materialize_frontend_accordions_theme.css CHANGED
@@ -22,9 +22,11 @@
22
  display: block;
23
  cursor: pointer;
24
  min-height: 3rem;
25
- line-height: 3rem;
26
  padding: 0 1rem;
27
- border-bottom: 1px solid #ddd
 
 
 
28
  }
29
 
30
  .wpms_collapsible .collapsible-header i {
22
  display: block;
23
  cursor: pointer;
24
  min-height: 3rem;
 
25
  padding: 0 1rem;
26
+ border-bottom: 1px solid #ddd;
27
+ font-size: 16px;
28
+ font-weight: 400;
29
+ line-height: 48px;
30
  }
31
 
32
  .wpms_collapsible .collapsible-header i {
css/metabox-tabs.css CHANGED
@@ -475,4 +475,9 @@ div.wpmseo-tab-content {
475
 
476
  .icons-mboxwarning {
477
  color:#FFB900
 
 
 
 
 
478
  }
475
 
476
  .icons-mboxwarning {
477
  color:#FFB900
478
+ }
479
+
480
+ .p_index_folder {
481
+ float: left;
482
+ width: 100%;
483
  }
inc/autoload.php CHANGED
@@ -21,12 +21,15 @@ if (!function_exists('google_api_php_client_autoload')) {
21
 
22
  /**
23
  * Auto include class
24
- * @param $className
 
 
 
25
  */
26
  function google_api_php_client_autoload($className)
27
  {
28
  $classPath = explode('_', $className);
29
- if ($classPath[0] != 'Google') {
30
  return;
31
  }
32
  if (count($classPath) > 3) {
21
 
22
  /**
23
  * Auto include class
24
+ *
25
+ * @param string $className Class name
26
+ *
27
+ * @return void
28
  */
29
  function google_api_php_client_autoload($className)
30
  {
31
  $classPath = explode('_', $className);
32
+ if ($classPath[0] !== 'Google') {
33
  return;
34
  }
35
  if (count($classPath) > 3) {
inc/breadcrumb/class.metaseo-breadcrumb.php CHANGED
@@ -8,15 +8,21 @@ defined('ABSPATH') || die('No direct script access allowed!');
8
  class MetaSeoBreadcrumb
9
  {
10
  /**
 
 
11
  * @var array
12
  */
13
  public $breadcrumbs = array();
14
  /**
 
 
15
  * @var array
16
  */
17
  public $breadcrumb_settings = array();
18
  /**
19
- * @var
 
 
20
  */
21
  public $template_no_anchor;
22
 
@@ -30,15 +36,15 @@ class MetaSeoBreadcrumb
30
  $home_title = get_bloginfo('title');
31
  }
32
  $this->breadcrumb_settings = array(
33
- 'separator' => ' > ',
34
- 'include_home' => 1,
35
  'home_text_default' => 0,
36
- 'home_text' => $home_title,
37
- 'clickable' => 1,
38
- 'apost_post_root' => get_option('page_for_posts'),
39
- 'apost_page_root' => get_option('page_on_front')
40
  );
41
- $breadcrumb_settings = get_option('_metaseo_breadcrumbs');
42
  if (is_array($breadcrumb_settings)) {
43
  $this->breadcrumb_settings = array_merge($this->breadcrumb_settings, $breadcrumb_settings);
44
  }
@@ -48,6 +54,8 @@ class MetaSeoBreadcrumb
48
  * Breadcrumb Trail Filling Function
49
  *
50
  * This functions fills the breadcrumb trail.
 
 
51
  */
52
  public function checkPosts()
53
  {
@@ -59,9 +67,9 @@ class MetaSeoBreadcrumb
59
  $this->addBreadcrumb($site_name, WPMSEO_TEMPLATE_BREADCRUMB, array('home', 'current-item'));
60
  if (!is_main_site()) {
61
  $site_name = get_site_option('site_name');
62
- $template = __('<span property="itemListElement" typeof="ListItem">
63
- <a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%">
64
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
65
  $this->addBreadcrumb(
66
  $site_name,
67
  $template,
@@ -84,7 +92,7 @@ class MetaSeoBreadcrumb
84
  } elseif (is_author()) {
85
  $this->author();
86
  } elseif (is_archive()) {
87
- $type = $wp_query->get_queried_object();
88
  $type_str = get_query_var('post_type');
89
  if (is_array($type_str)) {
90
  $type_str = reset($type_str);
@@ -93,7 +101,7 @@ class MetaSeoBreadcrumb
93
  if (is_date()) {
94
  $this->archiveByDate($this->getType());
95
  } elseif (is_post_type_archive() && !isset($type->taxonomy)
96
- && (!is_numeric($this->breadcrumb_settings['apost_' . $type_str . '_root']))) {
97
  $this->archiveByPosttype();
98
  } elseif (is_category() || is_tag() || is_tax()) {
99
  $this->archiveByTerm();
@@ -115,8 +123,11 @@ class MetaSeoBreadcrumb
115
  }
116
 
117
  /**
118
- * @param bool $return Whether to return or echo the trail. (optional)
119
- * @param bool $reverse Whether to reverse the output or not. (optional)
 
 
 
120
  * @return string
121
  */
122
  public function breadcrumbDisplay($return = false, $reverse = false)
@@ -128,7 +139,7 @@ class MetaSeoBreadcrumb
128
  krsort($this->breadcrumbs);
129
  }
130
 
131
- $html = '';
132
  $position = 1;
133
  //The main compiling loop
134
  foreach ($this->breadcrumbs as $key => $breadcrumb) {
@@ -144,32 +155,35 @@ class MetaSeoBreadcrumb
144
  }
145
 
146
  $html .= $this->generateBreadcrumb($breadcrumb, $position);
147
- $position++;
148
  }
149
 
150
  if ($return) {
151
  return $html; // for return has true
152
  } else {
 
153
  echo $html; // for return has false
154
  }
155
  }
156
 
157
  /**
158
  * Generate breadcrumb
159
- * @param array $breadcrumb breadcrumb info
160
- * @param int $position position of breadcrumb element
 
 
161
  * @return mixed
162
  */
163
  public function generateBreadcrumb($breadcrumb, $position)
164
  {
165
  $params = array(
166
- '%title%' => esc_attr(strip_tags($breadcrumb['name'])),
167
- '%link%' => esc_url($breadcrumb['url']),
168
- '%htitle%' => $breadcrumb['name'],
169
- '%type%' => $breadcrumb['type'],
170
- '%ftitle%' => esc_attr(strip_tags($breadcrumb['name'])),
171
- '%fhtitle%' => $breadcrumb['name'],
172
- '%position%' => $position
173
  );
174
  //The type may be an array, implode it if that is the case
175
  if (is_array($params['%type%'])) {
@@ -194,7 +208,9 @@ class MetaSeoBreadcrumb
194
  *
195
  * This functions fills a breadcrumb for posts
196
  *
197
- * @param $post WP_Post Instance of WP_Post object to create a breadcrumb for
 
 
198
  */
199
  public function post($post)
200
  {
@@ -203,26 +219,26 @@ class MetaSeoBreadcrumb
203
  }
204
 
205
  $arrays = array(
206
- 'name' => get_the_title($post),
207
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
208
- 'type' => array('post', 'post-' . $post->post_type, 'current-item'),
209
- 'url' => null,
210
- 'id' => $post->ID,
211
- 'click' => false
212
  );
213
 
214
  if (is_attachment()) {
215
- $template = __('<span property="itemListElement" typeof="ListItem">
216
- <a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%">
217
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
218
  $arrays['template'] = $template;
219
- $arrays['url'] = get_permalink($post);
220
- $arrays['click'] = true;
221
  }
222
  $this->breadcrumbs[] = $arrays;
223
  if ($post->post_type === 'page') {
224
  $frontpage = get_option('page_on_front');
225
- if ($post->post_parent && $post->ID != $post->post_parent && $frontpage != $post->post_parent) {
226
  $this->postParents($post->post_parent, $frontpage);
227
  }
228
  } else {
@@ -234,17 +250,19 @@ class MetaSeoBreadcrumb
234
  * A Breadcrumb Trail Filling Function
235
  *
236
  * This recursive functions fills the trail with breadcrumbs for parent posts/pages.
237
- * @param int $id The id of the parent page.
238
- * @param int $frontpage The id of the front page.
 
 
239
  * @return WP_Post The parent we stopped at
240
  */
241
  public function postParents($id, $frontpage)
242
  {
243
  $parent = get_post($id);
244
  // Add to breadcrumbs list
245
- $template = __('<span property="itemListElement" typeof="ListItem">
246
- <a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%">
247
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
248
  $this->addBreadcrumb(
249
  get_the_title($id),
250
  $template,
@@ -252,8 +270,7 @@ class MetaSeoBreadcrumb
252
  get_permalink($id),
253
  $id
254
  );
255
- if ($parent->post_parent >= 0 && $parent->post_parent != false
256
- && $id != $parent->post_parent && $frontpage != $parent->post_parent) {
257
  //If valid call this function
258
  $parent = $this->postParents($parent->post_parent, $frontpage);
259
  }
@@ -264,6 +281,8 @@ class MetaSeoBreadcrumb
264
  * A Breadcrumb Trail Filling Function
265
  *
266
  * This functions fills a breadcrumb for an attachment page.
 
 
267
  */
268
  public function attachment()
269
  {
@@ -278,8 +297,8 @@ class MetaSeoBreadcrumb
278
  );
279
  //Done with the current item, now on to the parents
280
  $frontpage = get_option('page_on_front');
281
- if ($post->post_parent >= 0 && $post->post_parent != false && $post->ID != $post->post_parent
282
- && $frontpage != $post->post_parent) {
283
  $parent = get_post($post->post_parent);
284
  //set the parent's breadcrumb
285
  $this->post($parent);
@@ -290,12 +309,14 @@ class MetaSeoBreadcrumb
290
  * A Breadcrumb Trail Filling Function
291
  *
292
  * This functions fills a breadcrumb for a search page.
 
 
293
  */
294
  public function search()
295
  {
296
- $template = __('<span property="itemListElement" typeof="ListItem">
297
- <span property="name">Search results for &#39;%htitle%&#39;</span>
298
- <meta property="position" content="%position%"></span>', 'wp-meta-seo');
299
  $this->addBreadcrumb(get_search_query(), $template, array('search', 'current-item'));
300
  }
301
 
@@ -303,6 +324,8 @@ class MetaSeoBreadcrumb
303
  * A Breadcrumb Trail Filling Function
304
  *
305
  * This functions fills a breadcrumb for an author page.
 
 
306
  */
307
  public function author()
308
  {
@@ -315,9 +338,9 @@ class MetaSeoBreadcrumb
315
  $author_name = array('display_name', 'nickname', 'first_name', 'last_name');
316
  if (in_array('display_name', $author_name)) {
317
  // Add to breadcrumbs list
318
- $template = __('<span property="itemListElement" typeof="ListItem">
319
- <span property="name">Articles by: %htitle%</span>
320
- <meta property="position" content="%position%"></span>', 'wp-meta-seo');
321
  $this->addBreadcrumb(
322
  get_the_author_meta(
323
  'display_name',
@@ -338,6 +361,8 @@ class MetaSeoBreadcrumb
338
  * A Breadcrumb Trail Filling Function
339
  *
340
  * This functions fills a breadcrumb for a post type archive (WP 3.1 feature)
 
 
341
  */
342
  public function archiveByPosttype()
343
  {
@@ -360,31 +385,33 @@ class MetaSeoBreadcrumb
360
  * This functions fills a breadcrumb for a date archive.
361
  *
362
  * @param string $type The type to restrict the date archives to
 
 
363
  */
364
  public function archiveByDate($type)
365
  {
366
- $date_template = __('<span property="itemListElement" typeof="ListItem">
367
- <a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%">
368
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
369
  if (is_day() || is_single()) {
370
  $arrays = array(
371
- 'name' => get_the_time(_x('d', 'day archive breadcrumb date format', 'wp-meta-seo')),
372
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
373
- 'type' => array('archive', 'date-day'),
374
  );
375
 
376
  if (is_day()) {
377
- $arrays['type'] = 'current-item';
378
- $arrays['url'] = null;
379
  $arrays['click'] = false;
380
  }
381
  // if is single
382
  if (is_single()) {
383
  $arrays['template'] = $date_template;
384
- $url = get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
385
- $url = $this->addPosttypeArg($url, $type);
386
- $arrays['url'] = $url;
387
- $arrays['click'] = true;
388
  }
389
 
390
  $this->breadcrumbs[] = $arrays;
@@ -393,23 +420,23 @@ class MetaSeoBreadcrumb
393
  //Now deal with the month breadcrumb
394
  if (is_month() || is_day() || is_single()) {
395
  $arrays = array(
396
- 'name' => get_the_time(_x('F', 'month archive breadcrumb date format', 'wp-meta-seo')),
397
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
398
- 'type' => array('archive', 'date-month'),
399
  );
400
 
401
  if (is_month()) {
402
- $arrays['type'] = 'current-item';
403
- $arrays['url'] = null;
404
  $arrays['click'] = false;
405
  }
406
 
407
  if (is_day() || is_single()) {
408
  $arrays['template'] = $date_template;
409
- $url = get_month_link(get_the_time('Y'), get_the_time('m'));
410
- $url = $this->addPosttypeArg($url, $type);
411
- $arrays['url'] = $url;
412
- $arrays['click'] = true;
413
  }
414
 
415
  $this->breadcrumbs[] = $arrays;
@@ -417,25 +444,25 @@ class MetaSeoBreadcrumb
417
 
418
 
419
  $arrays = array(
420
- 'name' => get_the_time(_x('Y', 'year archive breadcrumb date format', 'wp-meta-seo')),
421
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
422
- 'type' => array('archive', 'date-year'),
423
  );
424
 
425
  //If this is a year archive, add current-item type
426
  if (is_year()) {
427
- $arrays['type'] = 'current-item';
428
- $arrays['url'] = null;
429
  $arrays['click'] = false;
430
  }
431
  // day or month or single
432
  if (is_day() || is_month() || is_single()) {
433
  //We're linking, so set the linked template
434
  $arrays['template'] = $date_template;
435
- $url = get_year_link(get_the_time('Y'));
436
- $url = $this->addPosttypeArg($url, $type);
437
- $arrays['url'] = $url;
438
- $arrays['click'] = true;
439
  }
440
 
441
  $this->breadcrumbs[] = $arrays;
@@ -445,15 +472,17 @@ class MetaSeoBreadcrumb
445
  * A Breadcrumb Trail Filling Function
446
  *
447
  * This function fills a breadcrumb for any taxonomy archive, was previously two separate functions
 
 
448
  */
449
  public function archiveByTerm()
450
  {
451
  global $wp_query;
452
  $term = $wp_query->get_queried_object();
453
  // Add to breadcrumbs list
454
- $template = __('<span property="itemListElement" typeof="ListItem">
455
- <a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%">
456
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
457
  $this->addBreadcrumb(
458
  $term->name,
459
  $template,
@@ -476,8 +505,10 @@ class MetaSeoBreadcrumb
476
  * A Breadcrumb Trail Filling Function
477
  *
478
  * This recursive functions fills the trail with breadcrumbs for parent terms.
479
- * @param int $id The id of the term.
480
- * @param string $taxonomy The name of the taxonomy that the term belongs to
 
 
481
  * @return WP_Term The term we stopped at
482
  */
483
  public function termParents($id, $taxonomy)
@@ -485,9 +516,9 @@ class MetaSeoBreadcrumb
485
  //Get the current category
486
  $term = get_term($id, $taxonomy);
487
  // Add to breadcrumbs list
488
- $template = __('<span property="itemListElement" typeof="ListItem">
489
- <a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%">
490
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
491
  $this->addBreadcrumb(
492
  $term->name,
493
  $template,
@@ -502,19 +533,22 @@ class MetaSeoBreadcrumb
502
  ),
503
  $id
504
  );
505
- if ($term->parent && $term->parent != $id) {
506
  $term = $this->termParents($term->parent, $taxonomy);
507
  }
508
  return $term;
509
  }
510
 
511
  /**
512
- * add a enlement to lists
513
- * @param string $name
514
- * @param string $template
515
- * @param array $type
516
- * @param string $url
517
- * @param null $id
 
 
 
518
  */
519
  public function addBreadcrumb(
520
  $name = '',
@@ -523,18 +557,18 @@ class MetaSeoBreadcrumb
523
  $url = '',
524
  $id = null
525
  ) {
526
- $allowed_html = wp_kses_allowed_html('post');
527
- $tmp = __('<span property="itemListElement" typeof="ListItem">
528
- <a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%">
529
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
530
  $this->template_no_anchor = WPMSEO_TEMPLATE_BREADCRUMB;
531
- if ($template == null) {
532
  $template = wp_kses($tmp, $allowed_html);
533
  } else {
534
  //Loose comparison, evaluates to true if URL is '' or null
535
- if ($url == null) {
536
  $this->template_no_anchor = wp_kses($template, $allowed_html);
537
- $template = wp_kses($tmp, $allowed_html);
538
  } else {
539
  $template = wp_kses($template, $allowed_html);
540
  }
@@ -544,7 +578,7 @@ class MetaSeoBreadcrumb
544
  if (empty($this->breadcrumb_settings['clickable'])) {
545
  $click = false;
546
  } else {
547
- if ($url == null) {
548
  $click = false;
549
  } else {
550
  $click = true;
@@ -553,12 +587,12 @@ class MetaSeoBreadcrumb
553
 
554
  // add to array
555
  $this->breadcrumbs[] = array(
556
- 'name' => $name,
557
  'template' => $template,
558
- 'type' => $type,
559
- 'url' => $url,
560
- 'id' => $id,
561
- 'click' => $click
562
  );
563
  }
564
 
@@ -566,22 +600,25 @@ class MetaSeoBreadcrumb
566
  * A Breadcrumb Trail Filling Function
567
  *
568
  * This function fills breadcrumbs for any post taxonomy
569
- * @param int $id The id of the post to figure out the taxonomy for
 
 
 
570
  */
571
  public function postHierarchy($id)
572
  {
573
  $taxonomy = 'category';
574
  if (is_taxonomy_hierarchical($taxonomy)) {
575
  // Get all term of object
576
- $wpms_object = get_the_terms($id, $taxonomy);
577
  $potential_parent = 0;
578
- $term = false;
579
  // check array
580
  if (is_array($wpms_object)) {
581
  $wpms_use_term = key($wpms_object);
582
  foreach ($wpms_object as $key => $object) {
583
  if ($object->parent > 0 && ($potential_parent === 0 || $object->parent === $potential_parent)) {
584
- $wpms_use_term = $key;
585
  $potential_parent = $object->term_id;
586
  }
587
  }
@@ -600,16 +637,16 @@ class MetaSeoBreadcrumb
600
  /**
601
  * Adds the post type argument to the URL iff the passed in type is not post
602
  *
603
- * @param string $url The URL to possibly add the post_type argument to
604
- * @param string $type [optional] The type to possibly add to the URL
605
- * @param string $taxonomy [optional] If we're dealing with a taxonomy term, the taxonomy of that term
606
  *
607
  * @return string The possibly modified URL
608
  */
609
  public function addPosttypeArg($url, $type = null, $taxonomy = null)
610
  {
611
  global $wp_taxonomies;
612
- if ($type == null) {
613
  $type = $this->getType();
614
  }
615
 
@@ -622,8 +659,10 @@ class MetaSeoBreadcrumb
622
  }
623
 
624
  /**
625
- * get post type
626
- * @param string $default
 
 
627
  * @return string
628
  */
629
  public function getType($default = 'post')
@@ -644,15 +683,17 @@ class MetaSeoBreadcrumb
644
  * A Breadcrumb Trail Filling Function
645
  *
646
  * This functions fills a breadcrumb for the home page.
 
 
647
  */
648
  public function home()
649
  {
650
  global $current_site;
651
  //Get the site name
652
  $site_name = get_option('blogname');
653
- $template = __('<span property="itemListElement" typeof="ListItem">
654
- <a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%">
655
- <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
656
 
657
  if (!empty($this->breadcrumb_settings['home_text_default'])) {
658
  $title = $this->breadcrumb_settings['home_text'];
8
  class MetaSeoBreadcrumb
9
  {
10
  /**
11
+ * Breadcrumbs array
12
+ *
13
  * @var array
14
  */
15
  public $breadcrumbs = array();
16
  /**
17
+ * Breadcrumb settings
18
+ *
19
  * @var array
20
  */
21
  public $breadcrumb_settings = array();
22
  /**
23
+ * Template no anchor
24
+ *
25
+ * @var string
26
  */
27
  public $template_no_anchor;
28
 
36
  $home_title = get_bloginfo('title');
37
  }
38
  $this->breadcrumb_settings = array(
39
+ 'separator' => ' &gt; ',
40
+ 'include_home' => 1,
41
  'home_text_default' => 0,
42
+ 'home_text' => $home_title,
43
+ 'clickable' => 1,
44
+ 'apost_post_root' => get_option('page_for_posts'),
45
+ 'apost_page_root' => get_option('page_on_front')
46
  );
47
+ $breadcrumb_settings = get_option('_metaseo_breadcrumbs');
48
  if (is_array($breadcrumb_settings)) {
49
  $this->breadcrumb_settings = array_merge($this->breadcrumb_settings, $breadcrumb_settings);
50
  }
54
  * Breadcrumb Trail Filling Function
55
  *
56
  * This functions fills the breadcrumb trail.
57
+ *
58
+ * @return void
59
  */
60
  public function checkPosts()
61
  {
67
  $this->addBreadcrumb($site_name, WPMSEO_TEMPLATE_BREADCRUMB, array('home', 'current-item'));
68
  if (!is_main_site()) {
69
  $site_name = get_site_option('site_name');
70
+ $template = '<span property="itemListElement" typeof="ListItem">
71
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to %title%.', 'wp-meta-seo') . '" href="%link%" class="%type%">
72
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
73
  $this->addBreadcrumb(
74
  $site_name,
75
  $template,
92
  } elseif (is_author()) {
93
  $this->author();
94
  } elseif (is_archive()) {
95
+ $type = $wp_query->get_queried_object();
96
  $type_str = get_query_var('post_type');
97
  if (is_array($type_str)) {
98
  $type_str = reset($type_str);
101
  if (is_date()) {
102
  $this->archiveByDate($this->getType());
103
  } elseif (is_post_type_archive() && !isset($type->taxonomy)
104
+ && (!is_numeric($this->breadcrumb_settings['apost_' . $type_str . '_root']))) {
105
  $this->archiveByPosttype();
106
  } elseif (is_category() || is_tag() || is_tax()) {
107
  $this->archiveByTerm();
123
  }
124
 
125
  /**
126
+ * Render breadcrumb
127
+ *
128
+ * @param boolean $return Whether to return or echo the trail. (optional)
129
+ * @param boolean $reverse Whether to reverse the output or not. (optional)
130
+ *
131
  * @return string
132
  */
133
  public function breadcrumbDisplay($return = false, $reverse = false)
139
  krsort($this->breadcrumbs);
140
  }
141
 
142
+ $html = '';
143
  $position = 1;
144
  //The main compiling loop
145
  foreach ($this->breadcrumbs as $key => $breadcrumb) {
155
  }
156
 
157
  $html .= $this->generateBreadcrumb($breadcrumb, $position);
158
+ $position ++;
159
  }
160
 
161
  if ($return) {
162
  return $html; // for return has true
163
  } else {
164
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method generateBreadcrumb
165
  echo $html; // for return has false
166
  }
167
  }
168
 
169
  /**
170
  * Generate breadcrumb
171
+ *
172
+ * @param array $breadcrumb Breadcrumb info
173
+ * @param integer $position Position of breadcrumb element
174
+ *
175
  * @return mixed
176
  */
177
  public function generateBreadcrumb($breadcrumb, $position)
178
  {
179
  $params = array(
180
+ '%title%' => esc_attr(strip_tags($breadcrumb['name'])),
181
+ '%link%' => esc_url($breadcrumb['url']),
182
+ '%htitle%' => esc_html($breadcrumb['name']),
183
+ '%type%' => esc_attr($breadcrumb['type']),
184
+ '%ftitle%' => esc_attr(strip_tags($breadcrumb['name'])),
185
+ '%fhtitle%' => esc_html($breadcrumb['name']),
186
+ '%position%' => esc_attr($position)
187
  );
188
  //The type may be an array, implode it if that is the case
189
  if (is_array($params['%type%'])) {
208
  *
209
  * This functions fills a breadcrumb for posts
210
  *
211
+ * @param object $post WP_Post Instance of WP_Post object to create a breadcrumb for
212
+ *
213
+ * @return void
214
  */
215
  public function post($post)
216
  {
219
  }
220
 
221
  $arrays = array(
222
+ 'name' => get_the_title($post),
223
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
224
+ 'type' => array('post', 'post-' . $post->post_type, 'current-item'),
225
+ 'url' => null,
226
+ 'id' => $post->ID,
227
+ 'click' => false
228
  );
229
 
230
  if (is_attachment()) {
231
+ $template = '<span property="itemListElement" typeof="ListItem">
232
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to %title%.', 'wp-meta-seo') . '" href="%link%" class="%type%">
233
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
234
  $arrays['template'] = $template;
235
+ $arrays['url'] = get_permalink($post);
236
+ $arrays['click'] = true;
237
  }
238
  $this->breadcrumbs[] = $arrays;
239
  if ($post->post_type === 'page') {
240
  $frontpage = get_option('page_on_front');
241
+ if ($post->post_parent && (int) $post->ID !== (int) $post->post_parent && (int) $frontpage !== (int) $post->post_parent) {
242
  $this->postParents($post->post_parent, $frontpage);
243
  }
244
  } else {
250
  * A Breadcrumb Trail Filling Function
251
  *
252
  * This recursive functions fills the trail with breadcrumbs for parent posts/pages.
253
+ *
254
+ * @param integer $id The id of the parent page.
255
+ * @param integer $frontpage The id of the front page.
256
+ *
257
  * @return WP_Post The parent we stopped at
258
  */
259
  public function postParents($id, $frontpage)
260
  {
261
  $parent = get_post($id);
262
  // Add to breadcrumbs list
263
+ $template = '<span property="itemListElement" typeof="ListItem">
264
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to %title%.', 'wp-meta-seo') . '" href="%link%" class="%type%">
265
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
266
  $this->addBreadcrumb(
267
  get_the_title($id),
268
  $template,
270
  get_permalink($id),
271
  $id
272
  );
273
+ if ($parent->post_parent >= 0 && $parent->post_parent && (int) $id !== (int) $parent->post_parent && (int) $frontpage !== (int) $parent->post_parent) {
 
274
  //If valid call this function
275
  $parent = $this->postParents($parent->post_parent, $frontpage);
276
  }
281
  * A Breadcrumb Trail Filling Function
282
  *
283
  * This functions fills a breadcrumb for an attachment page.
284
+ *
285
+ * @return void
286
  */
287
  public function attachment()
288
  {
297
  );
298
  //Done with the current item, now on to the parents
299
  $frontpage = get_option('page_on_front');
300
+ if ($post->post_parent >= 0 && $post->post_parent && (int) $post->ID !== (int) $post->post_parent
301
+ && (int) $frontpage !== (int) $post->post_parent) {
302
  $parent = get_post($post->post_parent);
303
  //set the parent's breadcrumb
304
  $this->post($parent);
309
  * A Breadcrumb Trail Filling Function
310
  *
311
  * This functions fills a breadcrumb for a search page.
312
+ *
313
+ * @return void
314
  */
315
  public function search()
316
  {
317
+ $template = '<span property="itemListElement" typeof="ListItem">
318
+ <span property="name">' . esc_html__('Search results for "%htitle%"', 'wp-meta-seo') . '</span>
319
+ <meta property="position" content="%position%"></span>';
320
  $this->addBreadcrumb(get_search_query(), $template, array('search', 'current-item'));
321
  }
322
 
324
  * A Breadcrumb Trail Filling Function
325
  *
326
  * This functions fills a breadcrumb for an author page.
327
+ *
328
+ * @return void
329
  */
330
  public function author()
331
  {
338
  $author_name = array('display_name', 'nickname', 'first_name', 'last_name');
339
  if (in_array('display_name', $author_name)) {
340
  // Add to breadcrumbs list
341
+ $template = '<span property="itemListElement" typeof="ListItem">
342
+ <span property="name">' . esc_html__('Articles by: %htitle%', 'wp-meta-seo') . '</span>
343
+ <meta property="position" content="%position%"></span>';
344
  $this->addBreadcrumb(
345
  get_the_author_meta(
346
  'display_name',
361
  * A Breadcrumb Trail Filling Function
362
  *
363
  * This functions fills a breadcrumb for a post type archive (WP 3.1 feature)
364
+ *
365
+ * @return void
366
  */
367
  public function archiveByPosttype()
368
  {
385
  * This functions fills a breadcrumb for a date archive.
386
  *
387
  * @param string $type The type to restrict the date archives to
388
+ *
389
+ * @return void
390
  */
391
  public function archiveByDate($type)
392
  {
393
+ $date_template = '<span property="itemListElement" typeof="ListItem">
394
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to the %title% archives.', 'wp-meta-seo') . '" href="%link%" class="%type%">
395
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
396
  if (is_day() || is_single()) {
397
  $arrays = array(
398
+ 'name' => get_the_time(_x('d', 'day archive breadcrumb date format', 'wp-meta-seo')),
399
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
400
+ 'type' => array('archive', 'date-day'),
401
  );
402
 
403
  if (is_day()) {
404
+ $arrays['type'] = 'current-item';
405
+ $arrays['url'] = null;
406
  $arrays['click'] = false;
407
  }
408
  // if is single
409
  if (is_single()) {
410
  $arrays['template'] = $date_template;
411
+ $url = get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
412
+ $url = $this->addPosttypeArg($url, $type);
413
+ $arrays['url'] = $url;
414
+ $arrays['click'] = true;
415
  }
416
 
417
  $this->breadcrumbs[] = $arrays;
420
  //Now deal with the month breadcrumb
421
  if (is_month() || is_day() || is_single()) {
422
  $arrays = array(
423
+ 'name' => get_the_time(_x('F', 'month archive breadcrumb date format', 'wp-meta-seo')),
424
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
425
+ 'type' => array('archive', 'date-month'),
426
  );
427
 
428
  if (is_month()) {
429
+ $arrays['type'] = 'current-item';
430
+ $arrays['url'] = null;
431
  $arrays['click'] = false;
432
  }
433
 
434
  if (is_day() || is_single()) {
435
  $arrays['template'] = $date_template;
436
+ $url = get_month_link(get_the_time('Y'), get_the_time('m'));
437
+ $url = $this->addPosttypeArg($url, $type);
438
+ $arrays['url'] = $url;
439
+ $arrays['click'] = true;
440
  }
441
 
442
  $this->breadcrumbs[] = $arrays;
444
 
445
 
446
  $arrays = array(
447
+ 'name' => get_the_time(_x('Y', 'year archive breadcrumb date format', 'wp-meta-seo')),
448
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
449
+ 'type' => array('archive', 'date-year'),
450
  );
451
 
452
  //If this is a year archive, add current-item type
453
  if (is_year()) {
454
+ $arrays['type'] = 'current-item';
455
+ $arrays['url'] = null;
456
  $arrays['click'] = false;
457
  }
458
  // day or month or single
459
  if (is_day() || is_month() || is_single()) {
460
  //We're linking, so set the linked template
461
  $arrays['template'] = $date_template;
462
+ $url = get_year_link(get_the_time('Y'));
463
+ $url = $this->addPosttypeArg($url, $type);
464
+ $arrays['url'] = $url;
465
+ $arrays['click'] = true;
466
  }
467
 
468
  $this->breadcrumbs[] = $arrays;
472
  * A Breadcrumb Trail Filling Function
473
  *
474
  * This function fills a breadcrumb for any taxonomy archive, was previously two separate functions
475
+ *
476
+ * @return void
477
  */
478
  public function archiveByTerm()
479
  {
480
  global $wp_query;
481
  $term = $wp_query->get_queried_object();
482
  // Add to breadcrumbs list
483
+ $template = '<span property="itemListElement" typeof="ListItem">
484
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to the %title% category archives.', 'wp-meta-seo') . '" href="%link%" class="%type%">
485
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
486
  $this->addBreadcrumb(
487
  $term->name,
488
  $template,
505
  * A Breadcrumb Trail Filling Function
506
  *
507
  * This recursive functions fills the trail with breadcrumbs for parent terms.
508
+ *
509
+ * @param integer $id The id of the term.
510
+ * @param string $taxonomy The name of the taxonomy that the term belongs to
511
+ *
512
  * @return WP_Term The term we stopped at
513
  */
514
  public function termParents($id, $taxonomy)
516
  //Get the current category
517
  $term = get_term($id, $taxonomy);
518
  // Add to breadcrumbs list
519
+ $template = '<span property="itemListElement" typeof="ListItem">
520
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to the %title% category archives.', 'wp-meta-seo') . '" href="%link%" class="%type%">
521
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
522
  $this->addBreadcrumb(
523
  $term->name,
524
  $template,
533
  ),
534
  $id
535
  );
536
+ if ($term->parent && (int) $term->parent !== (int) $id) {
537
  $term = $this->termParents($term->parent, $taxonomy);
538
  }
539
  return $term;
540
  }
541
 
542
  /**
543
+ * Add a enlement to lists
544
+ *
545
+ * @param string $name Breadcrumb name
546
+ * @param string $template Breadcrumb template
547
+ * @param array $type Breadcrumb type
548
+ * @param string $url Breadcrumb URL
549
+ * @param null $id Breadcrumb id
550
+ *
551
+ * @return void
552
  */
553
  public function addBreadcrumb(
554
  $name = '',
557
  $url = '',
558
  $id = null
559
  ) {
560
+ $allowed_html = wp_kses_allowed_html('post');
561
+ $tmp = '<span property="itemListElement" typeof="ListItem">
562
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to %title%.', 'wp-meta-seo') . '" href="%link%" class="%type%">
563
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
564
  $this->template_no_anchor = WPMSEO_TEMPLATE_BREADCRUMB;
565
+ if (is_null($template)) {
566
  $template = wp_kses($tmp, $allowed_html);
567
  } else {
568
  //Loose comparison, evaluates to true if URL is '' or null
569
+ if (is_null($url)) {
570
  $this->template_no_anchor = wp_kses($template, $allowed_html);
571
+ $template = wp_kses($tmp, $allowed_html);
572
  } else {
573
  $template = wp_kses($template, $allowed_html);
574
  }
578
  if (empty($this->breadcrumb_settings['clickable'])) {
579
  $click = false;
580
  } else {
581
+ if (is_null($url)) {
582
  $click = false;
583
  } else {
584
  $click = true;
587
 
588
  // add to array
589
  $this->breadcrumbs[] = array(
590
+ 'name' => $name,
591
  'template' => $template,
592
+ 'type' => $type,
593
+ 'url' => $url,
594
+ 'id' => $id,
595
+ 'click' => $click
596
  );
597
  }
598
 
600
  * A Breadcrumb Trail Filling Function
601
  *
602
  * This function fills breadcrumbs for any post taxonomy
603
+ *
604
+ * @param integer $id The id of the post to figure out the taxonomy for
605
+ *
606
+ * @return void
607
  */
608
  public function postHierarchy($id)
609
  {
610
  $taxonomy = 'category';
611
  if (is_taxonomy_hierarchical($taxonomy)) {
612
  // Get all term of object
613
+ $wpms_object = get_the_terms($id, $taxonomy);
614
  $potential_parent = 0;
615
+ $term = false;
616
  // check array
617
  if (is_array($wpms_object)) {
618
  $wpms_use_term = key($wpms_object);
619
  foreach ($wpms_object as $key => $object) {
620
  if ($object->parent > 0 && ($potential_parent === 0 || $object->parent === $potential_parent)) {
621
+ $wpms_use_term = $key;
622
  $potential_parent = $object->term_id;
623
  }
624
  }
637
  /**
638
  * Adds the post type argument to the URL iff the passed in type is not post
639
  *
640
+ * @param string $url The URL to possibly add the post_type argument to
641
+ * @param string $type The type to possibly add to the URL
642
+ * @param string $taxonomy If we're dealing with a taxonomy term, the taxonomy of that term
643
  *
644
  * @return string The possibly modified URL
645
  */
646
  public function addPosttypeArg($url, $type = null, $taxonomy = null)
647
  {
648
  global $wp_taxonomies;
649
+ if (is_null($type)) {
650
  $type = $this->getType();
651
  }
652
 
659
  }
660
 
661
  /**
662
+ * Get post type
663
+ *
664
+ * @param string $default Post type
665
+ *
666
  * @return string
667
  */
668
  public function getType($default = 'post')
683
  * A Breadcrumb Trail Filling Function
684
  *
685
  * This functions fills a breadcrumb for the home page.
686
+ *
687
+ * @return void
688
  */
689
  public function home()
690
  {
691
  global $current_site;
692
  //Get the site name
693
  $site_name = get_option('blogname');
694
+ $template = '<span property="itemListElement" typeof="ListItem">
695
+ <a property="item" typeof="WebPage" title="' . esc_attr__('Go to %title%.', 'wp-meta-seo') . '" href="%link%" class="%type%">
696
+ <span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
697
 
698
  if (!empty($this->breadcrumb_settings['home_text_default'])) {
699
  $title = $this->breadcrumb_settings['home_text'];
inc/class.image-helper.php CHANGED
@@ -11,75 +11,84 @@ class ImageHelper
11
 
12
  /**
13
  * Source url of image
 
14
  * @var string
15
  */
16
  public static $src = '';
17
 
18
  /**
19
  * ImageHelper constructor.
20
- * @param array $params
 
21
  */
22
  public function __construct(array $params = array())
23
  {
24
- $c = new ReflectionClass(__CLASS__);
25
  $statics = $c->getStaticProperties();
26
-
27
  foreach ($params as $key => $value) {
28
  if (!in_array($key, array_keys($statics))) {
29
  $this->{$key} = $value;
30
  } else {
31
- self::$$key = $value;
32
  }
33
  }
34
  }
35
 
36
  /**
37
- * get image info
38
- * @param string $src source url of image
 
 
39
  * @return ImageHelper
40
  */
41
  public static function IGetPart($src = '')
42
  {
43
- if ($src == '') {
44
  $src = self::$src;
45
  }
46
  $ipart = new ImageHelper(array(
47
- 'src' => $src,
48
- 'base_path' => '',
49
- 'name' => '',
50
- 'ext' => '',
51
- 'dimension' => '',
52
  'name_prefix' => '',
53
- 'name_suffix' => ''));
 
54
 
55
- if (($dot = strrpos($src, '.')) === false) {
 
56
  return $ipart;
57
  }
58
 
59
- if (($bslash = strrpos($src, '/')) === false) {
 
60
  $bslash = 0;
61
  } else {
62
- $bslash++;
63
  }
64
 
65
- $ipart->_src = $src;
66
  $ipart->base_path = substr($src, 0, $bslash);
67
- $ipart->name = substr($src, $bslash, $dot - $bslash);
68
- $ipart->ext = substr($src, $dot);
69
  $ipart->dimension = self::IGetDimension($ipart->name);
70
  if (!empty($ipart->dimension)) {
71
  $ipart->name_prefix = substr($ipart->name, 0, strpos($ipart->name, $ipart->dimension) - 1);
72
  $ipart->name_suffix = str_replace($ipart->name_prefix . '-' . $ipart->dimension, '', $ipart->name);
73
  } else {
74
- $ipart->name_prefix = $ipart->name_suffix = '';
 
75
  }
76
 
77
  return $ipart;
78
  }
79
 
80
  /**
81
- * get Image width and height
82
- * @param string $src source url of image
 
 
83
  * @return mixed|string
84
  */
85
  public static function IGetDimension($src)
@@ -93,13 +102,15 @@ class ImageHelper
93
 
94
  /**
95
  * Replace image src
96
- * @param string $newName new name of image
97
- * @param string $src source url of image
 
 
98
  * @return string
99
  */
100
  public static function IReplace($newName, $src = '')
101
  {
102
- if ($src == '') {
103
  $src = self::$src;
104
  }
105
  if ($newName === '') {
@@ -107,14 +118,17 @@ class ImageHelper
107
  }
108
 
109
  $ipart = self::IgetPart($src);
110
- $src = $ipart->base_path . $newName . '-' . $ipart->dimension . $ipart->name_suffix . $ipart->ext;
111
  return $src;
112
  }
113
 
114
  /**
115
- * @param $img
116
- * @param $obj
117
- * @return bool|mixed
 
 
 
118
  */
119
  public static function IHasClone($img, $obj)
120
  {
@@ -144,38 +158,42 @@ class ImageHelper
144
  }
145
 
146
  /**
147
- * get image info when scan post
148
- * @param array $imgs list img in content
149
- * @param string $content post content
 
 
150
  * @return array
151
  */
152
  public static function IScan($content, $imgs = array())
153
  {
154
  $ifound = array();
155
- $doc = new DOMDocument();
156
  libxml_use_internal_errors(true);
157
- @$doc->loadHtml($content);
158
  $tags = $doc->getElementsByTagName('img');
159
 
160
  //For standard images names, convert spaces to -
161
  $_imgs = array();
162
  foreach ($imgs as $iname => $iid) {
163
- $iname = preg_replace('/(\s{1,})/', '-', $iname);
164
  $_imgs[$iname] = $iid;
165
  }
166
  if ($tags->length > 0) {
167
  foreach ($tags as $order => $tag) {
168
  // only find img tag have source
169
- if (($obj = $tag->getAttribute('src')) == '') {
 
170
  continue;
171
  }
172
- if ($img_name = self::IHasClone(array_keys($_imgs), $obj)) {
 
173
  if (!empty($_imgs[$img_name])) {
174
- $ifound[$order]['id'] = $_imgs[$img_name];
175
- $ifound[$order]['src'] = $obj;
176
- $ifound[$order]['width'] = $tag->getAttribute('width');
177
  $ifound[$order]['height'] = $tag->getAttribute('height');
178
- $ifound[$order]['alt'] = trim($tag->getAttribute('alt'));
179
  } else {
180
  continue;
181
  }
@@ -187,16 +205,18 @@ class ImageHelper
187
  }
188
 
189
  /**
190
- * get posts list
191
- * @param int $iID ID of post
192
- * @param string $opt_type meta type
 
 
193
  * @return array|mixed
194
  */
195
  public static function getPostList($iID, $opt_type)
196
  {
197
  //Get image info from wp_postmeta with key equals to _metaseo_img_meta_not_good
198
  $meta_key = '_metaseo_' . strtolower(trim($opt_type));
199
- $posts = get_post_meta($iID, $meta_key, true);
200
 
201
  if (is_array($posts) && !empty($posts)) {
202
  return $posts;
@@ -206,19 +226,20 @@ class ImageHelper
206
  }
207
 
208
  /**
209
- * get image not good
210
- * @param $imgs
211
- * @param $posts
212
- * @param array $meta_checkout
 
213
  * @return array
214
  */
215
  public static function IPrepare($imgs, $posts)
216
  {
217
- $iNotGood = array();
218
- $iNotGoodTotal = array();
219
  $imNotGoodTotal = array();
220
- $imNotGood = array();
221
- $upload_dir = wp_upload_dir();
222
 
223
  // scan img tag for each post content
224
  foreach ($posts as $post) {
@@ -234,15 +255,15 @@ class ImageHelper
234
  $iID = $img['id'];
235
  //Get image that its size is not good
236
  $imgpath = str_replace(site_url(), ABSPATH, $img['src']);
237
- if (!list($width_origin, $height_origin) = @getimagesize($imgpath)) {
238
  continue;
239
  }
240
  $ratio_origin = $width_origin / $height_origin;
241
- $width = $img['width'];
242
- $height = $img['height'];
243
  //Check if img tag is missing with/height attribute value or not
244
  if (!$width && !$height) {
245
- $width = $width_origin;
246
  $height = $height_origin;
247
  } elseif ($width && !$height) {
248
  $height = $width * (1 / $ratio_origin);
@@ -250,61 +271,61 @@ class ImageHelper
250
  $width = $height * ($ratio_origin);
251
  }
252
 
253
- if ((int)$width_origin > (int)$width || (int)$height_origin > (int)$height) {
254
  $img_before = str_replace(array($upload_dir['baseurl']), '', $img['src']);
255
- $ibpart = ImageHelper::IGetPart($img_before);
256
 
257
  $img_after = $ibpart->base_path
258
- . (!empty($ibpart->name_prefix) ? $ibpart->name_prefix : $ibpart->name)
259
- . '-' . $width . 'x' . $height
260
- . $ibpart->name_suffix
261
- . $ibpart->ext;
262
 
263
  // create new image url and dir
264
  $srcs = array(
265
  'img_before_dir' => $upload_dir['basedir'] . $img_before,
266
  'img_before_url' => $upload_dir['baseurl'] . $img_before,
267
- 'img_after_dir' => $upload_dir['basedir'] . $img_after,
268
- 'img_after_url' => $upload_dir['baseurl'] . $img_after
269
  );
270
 
271
  // get size img
272
  $size = (filesize($srcs['img_before_dir']) / 1024);
273
  if ($size > 1024) {
274
- $size = $size / 1024;
275
  $sizes = 'MB';
276
  } else {
277
  $sizes = 'KB';
278
  }
279
- $size = @round($size, 1);
280
 
281
- $iNotGood[$iID][$post->ID]['ID'] = $post->ID;
282
- $iNotGood[$iID][$post->ID]['title'] = $post->post_title;
283
- $iNotGood[$iID][$post->ID]['post_type'] = $post->post_type;
284
  $iNotGood[$iID][$post->ID]['img_before_optm'][$order] = array(
285
- 'size' => $size,
286
- 'sizes' => $sizes,
287
- 'src' => $srcs['img_before_url'],
288
- 'width' => $width,
289
- 'height' => $height,
290
- 'dimension' => ImageHelper::IGetDimension($img_before)
291
  );
292
 
293
  $iNotGood[$iID][$post->ID]['img_after_optm'][$order] = array(
294
- 'size' => 0,
295
- 'path' => $img_after,
296
- 'src' => $srcs['img_after_url'],
297
  'src_origin' => $srcs['img_before_url'],
298
- 'width' => $width,
299
- 'height' => $height,
300
- 'dimension' => ImageHelper::IGetDimension($img_after)
301
  );
302
 
303
  //Get the number of images which their size are not good
304
  if (!isset($iNotGoodTotal[$iID])) {
305
  $iNotGoodTotal[$iID] = 0;
306
  }
307
- $iNotGoodTotal[$iID]++;
308
  } else {
309
  if (!isset($iNotGood[$iID])) {
310
  $iNotGood[$iID] = array();
@@ -315,24 +336,24 @@ class ImageHelper
315
  }
316
 
317
  //Get image that its meta/metas is/are not good
318
- $meta_value = $img['alt'];
319
- $imNotGood[$iID][$post->ID]['ID'] = $post->ID;
320
- $imNotGood[$iID][$post->ID]['title'] = $post->post_title;
321
- $imNotGood[$iID][$post->ID]['post_type'] = $post->post_type;
322
- $imNotGood[$iID][$post->ID]['meta'][$order]['img_src'] = $img['src'];
323
  $imNotGood[$iID][$post->ID]['meta'][$order]['type']['alt'] = $meta_value;
324
- if ($meta_value == '') {
325
  if (!isset($imNotGoodTotal[$iID]['alt'])) {
326
  $imNotGoodTotal[$iID]['alt'] = 0;
327
  }
328
- $imNotGoodTotal[$iID]['alt']++;
329
  }
330
  }
331
  }
332
 
333
  foreach ($imgs as $name => $iID) {
334
  if (!isset($iNotGoodTotal[$iID])) {
335
- $iNotGoodTotal[$iID] = -1;
336
  }
337
  if (!isset($iNotGood[$iID])) {
338
  $iNotGood[$iID] = array();
@@ -354,9 +375,9 @@ class ImageHelper
354
  unset($posts, $imgs);
355
 
356
  $ret = array(
357
- 'iNotGood' => $iNotGood,
358
- 'iNotGoodTotal' => $iNotGoodTotal,
359
- 'imNotGood' => $imNotGood,
360
  'imNotGoodTotal' => $imNotGoodTotal
361
  );
362
 
@@ -365,9 +386,11 @@ class ImageHelper
365
 
366
  /**
367
  * Scan image that has not good size or not good meta(s), then update info to postmeta table
368
- * @param $imgs
369
- * @param bool $delete
370
- * @param int $postID ID of post
 
 
371
  * @return array
372
  */
373
  public static function IScanPosts($imgs, $delete = false, $postID = 0)
@@ -378,50 +401,55 @@ class ImageHelper
378
 
379
  // get list sizes image
380
  $metadats = get_post_meta($idPost, '_wp_attachment_metadata', true);
381
- $sizes = $metadats['sizes'];
382
 
383
  // get list url image and image thumbnail
384
- $list_thum_url = array();
385
- $imageUrl = wp_get_attachment_url($idPost);
386
  $list_thum_url[] = $imageUrl;
387
  if (!empty($sizes)) {
388
  foreach ($sizes as $key => $size) {
389
- $thum_url = wp_get_attachment_image_src($idPost, $key);
390
  $list_thum_url[] = $thum_url[0];
391
  }
392
  }
393
 
394
- $msg = array();
395
  $_imgs = array_flip($imgs);
396
- $post_types = MetaSeoContentListTable::getPostTypes();
397
-
398
  // sql where
399
  $w = '';
400
  $w .= '(';
401
  $i = 0;
402
  foreach ($list_thum_url as $url) {
403
  $url = str_replace(array('https', 'http'), array('', ''), $url);
404
- $i++;
405
- if ($i == count($list_thum_url)) {
406
- $w .= ' post_content LIKE "%' . $url . '%"';
407
  } else {
408
- $w .= ' post_content LIKE "%' . $url . '%" OR';
409
  }
410
  }
411
 
412
- $w .= ')';
413
  $where = array();
414
  if ($delete) {
415
- $where[] = "ID != $postID";
 
 
 
 
 
416
  }
417
- $where[] = "post_type IN ($post_types)";
418
- $where[] = "post_content LIKE '%<img%'";
419
- $where[] = $w;
420
- $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
421
- FROM $wpdb->posts
422
- WHERE " . implode(' AND ', $where) . " ORDER BY ID";
423
  // query post
424
- $posts = $wpdb->get_results($query);
 
 
 
425
  $results = self::IPrepare($imgs, $posts);
426
  //Update some value into fields in wp_postmeta
427
  if (count($results['iNotGood']) > 0) {
@@ -435,19 +463,19 @@ class ImageHelper
435
  }
436
 
437
  $msg[$iID]['iNotGood']['msg']
438
- = __($results['iNotGoodTotal'][$iID] . $im . 'with wrong size', 'wp-meta-seo');
439
  $msg[$iID]['iNotGood']['warning'] = true;
440
 
441
  $msg[$iID]['iNotGood']['button'] = '<a href="javascript:void(0);"
442
- class=" img-resize wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '"
443
- data-post-id="' . $iID . '" data-opt-key="resize_image"
444
  onclick="showPostsList(this)">
445
- ' . __('Resize image', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
446
 
447
  update_post_meta($iID, '_metaseo_resize_image_counter', $results['iNotGoodTotal'][$iID]);
448
  update_post_meta($iID, '_metaseo_resize_image', $post_group);
449
  } else {
450
- $msg[$iID]['iNotGood']['msg'] = __('Image sizes are good!', 'wp-meta-seo');
451
  $msg[$iID]['iNotGood']['warning'] = false;
452
 
453
  delete_post_meta($iID, '_metaseo_resize_image_counter');
@@ -461,39 +489,39 @@ class ImageHelper
461
  foreach ($results['imNotGood'] as $iID => $post_group) {
462
  //This has a litle bit value
463
  if ($results['imNotGoodTotal'][$iID]['alt'] > 1) {
464
- $i = $results['imNotGoodTotal'][$iID]['alt'] . ' ' . 'alt text';
465
- $msg[$iID]['imNotGood']['msg']['alt'] = $i . __('s are missing', 'wp-meta-seo');
466
- } elseif ($results['imNotGoodTotal'][$iID]['alt'] == 1) {
467
- $i = $results['imNotGoodTotal'][$iID]['alt'] . ' ' . 'alt text';
468
- $msg[$iID]['imNotGood']['msg']['alt'] = $i . __(' is missing', 'wp-meta-seo');
469
  }
470
 
471
  $msg[$iID]['imNotGood']['warning'] = true;
472
- $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
473
- class=" fix-metas wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '"
474
- data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
475
- alt="' . __('This image has been detected
476
  in your content, edit information here…', 'wp-meta-seo') . '">
477
- ' . __('Edit meta in content', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
478
 
479
 
480
  update_post_meta($iID, '_metaseo_fix_metas_counter', count($post_group));
481
  update_post_meta($iID, '_metaseo_fix_metas', $post_group);
482
 
483
 
484
- if ($results['imNotGoodTotal'][$iID]['alt'] == 0) {
485
- if ($results['iNotGoodTotal'][$iID] != -1) {
486
  $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
487
- class=" fix-metas wpmsbtn wpmsbtn_small wpmsbtn_secondary" data-img-name="' . $_imgs[$iID] . '"
488
- data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
489
- alt="' . __('This image has been detected in your content,
490
  edit information here…', 'wp-meta-seo') . '">
491
- ' . __('Edit meta', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
492
  } else {
493
  $msg[$iID]['imNotGood']['button'] = '';
494
  }
495
  $msg[$iID]['imNotGood']['warning'] = false;
496
- $msg[$iID]['imNotGood']['msg'] = '';
497
  }
498
  }
499
  }
@@ -505,25 +533,24 @@ class ImageHelper
505
 
506
  /**
507
  * Ajax optimize image and update content
508
- * @param $post_id
509
- * @param $img_post_id
510
- * @param $img_exclude
 
 
511
  * @return array
512
  */
513
  public static function optimizeImages($post_id, $img_post_id, $img_exclude)
514
  {
515
  global $wpdb;
516
  $ret = array('success' => false, 'msg' => '');
517
- $query = "SELECT `post_content` FROM $wpdb->posts WHERE `ID`=" . $post_id;
518
-
519
- if (!($post_content = @$wpdb->get_row($query)->post_content)) {
520
- $ret['msg'] = __('This post is not existed or deleted, please choose one another!', 'wp-meta-seo');
521
-
522
  return $ret;
523
  }
524
-
525
  $imgs_to_resize = get_post_meta($img_post_id, '_metaseo_resize_image', true);
526
-
527
  if (preg_match_all('/<img [^<>]+ \/>/i', $post_content, $matches)) {
528
  $replacement = array();
529
  foreach ($matches[0] as $order => $tag) {
@@ -533,11 +560,12 @@ class ImageHelper
533
  if (!isset($imgs_to_resize[$post_id])) {
534
  continue;
535
  }
 
536
  foreach ($imgs_to_resize[$post_id]['img_after_optm'] as $key => $img) {
537
  if (!in_array($order, $img_exclude)) {
538
  if (stripos($tag, $img['src_origin']) !== false &&
539
- (('width' == $dimension[1] && $dimension[2] == $img['width'])
540
- || ('height' == $dimension[1] && $dimension[2] == $img['height']))
541
  ) {
542
  $replacement[$order] = str_replace($img['src_origin'], $img['src'], $tag);
543
  }
@@ -553,40 +581,42 @@ class ImageHelper
553
 
554
  //Update post content with all imgs has been just optimized
555
  $id = wp_update_post(array(
556
- 'ID' => $post_id,
557
  'post_content' => $post_content
558
  ));
559
 
560
  if ($id) {
561
  $ret['success'] = true;
562
- $ret['msg'] = __('Well! This image is so good now.', 'wp-meta-seo');
563
  } else {
564
- $ret['msg'] = __('Opps! An error occured when updating the post, please try again', 'wp-meta-seo');
565
  }
566
 
567
  return $ret;
568
  }
569
 
570
  /**
571
- * create new size for image
572
- * @param string $src source url of image
573
- * @param float $width width of image
574
- * @param float $height height of image
575
- * @param $destination
576
- * @return bool|string
 
 
577
  */
578
  public static function IResize($src, $width, $height, $destination)
579
  {
580
  $imgpath = str_replace(site_url(), ABSPATH, $src);
581
  if (!list($w_origin, $h_origin) = getimagesize($imgpath)) {
582
- return "Unsupported picture type!";
583
  }
584
 
585
  if (is_readable($destination)) {
586
  return true;
587
  }
588
 
589
- $type = strtolower(substr(strrchr($imgpath, "."), 1));
590
  if ($type === 'jpeg') {
591
  $type = 'jpg';
592
  }
@@ -605,13 +635,13 @@ class ImageHelper
605
  $img = imagecreatefrompng($imgpath);
606
  break;
607
  default:
608
- return "Unsupported picture type!";
609
  }
610
 
611
  $new = imagecreatetruecolor($width, $height);
612
 
613
  // preserve transparency
614
- if ($type === "gif" or $type === "png") {
615
  imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
616
  imagealphablending($new, false);
617
  imagesavealpha($new, true);
11
 
12
  /**
13
  * Source url of image
14
+ *
15
  * @var string
16
  */
17
  public static $src = '';
18
 
19
  /**
20
  * ImageHelper constructor.
21
+ *
22
+ * @param array $params Params
23
  */
24
  public function __construct(array $params = array())
25
  {
26
+ $c = new ReflectionClass(__CLASS__);
27
  $statics = $c->getStaticProperties();
 
28
  foreach ($params as $key => $value) {
29
  if (!in_array($key, array_keys($statics))) {
30
  $this->{$key} = $value;
31
  } else {
32
+ self::${$key} = $value;
33
  }
34
  }
35
  }
36
 
37
  /**
38
+ * Get image info
39
+ *
40
+ * @param string $src Source url of image
41
+ *
42
  * @return ImageHelper
43
  */
44
  public static function IGetPart($src = '')
45
  {
46
+ if ($src === '') {
47
  $src = self::$src;
48
  }
49
  $ipart = new ImageHelper(array(
50
+ 'src' => $src,
51
+ 'base_path' => '',
52
+ 'name' => '',
53
+ 'ext' => '',
54
+ 'dimension' => '',
55
  'name_prefix' => '',
56
+ 'name_suffix' => ''
57
+ ));
58
 
59
+ $dot = strrpos($src, '.');
60
+ if ($dot === false) {
61
  return $ipart;
62
  }
63
 
64
+ $bslash = strrpos($src, '/');
65
+ if ($bslash === false) {
66
  $bslash = 0;
67
  } else {
68
+ $bslash ++;
69
  }
70
 
71
+ $ipart->_src = $src;
72
  $ipart->base_path = substr($src, 0, $bslash);
73
+ $ipart->name = substr($src, $bslash, $dot - $bslash);
74
+ $ipart->ext = substr($src, $dot);
75
  $ipart->dimension = self::IGetDimension($ipart->name);
76
  if (!empty($ipart->dimension)) {
77
  $ipart->name_prefix = substr($ipart->name, 0, strpos($ipart->name, $ipart->dimension) - 1);
78
  $ipart->name_suffix = str_replace($ipart->name_prefix . '-' . $ipart->dimension, '', $ipart->name);
79
  } else {
80
+ $ipart->name_prefix = '';
81
+ $ipart->name_suffix = '';
82
  }
83
 
84
  return $ipart;
85
  }
86
 
87
  /**
88
+ * Get Image width and height
89
+ *
90
+ * @param string $src Source url of image
91
+ *
92
  * @return mixed|string
93
  */
94
  public static function IGetDimension($src)
102
 
103
  /**
104
  * Replace image src
105
+ *
106
+ * @param string $newName New name of image
107
+ * @param string $src Source url of image
108
+ *
109
  * @return string
110
  */
111
  public static function IReplace($newName, $src = '')
112
  {
113
+ if ($src === '') {
114
  $src = self::$src;
115
  }
116
  if ($newName === '') {
118
  }
119
 
120
  $ipart = self::IgetPart($src);
121
+ $src = $ipart->base_path . $newName . '-' . $ipart->dimension . $ipart->name_suffix . $ipart->ext;
122
  return $src;
123
  }
124
 
125
  /**
126
+ * Get image name when scan post
127
+ *
128
+ * @param array $img List image name
129
+ * @param object $obj URL of image inserted in post content
130
+ *
131
+ * @return boolean|mixed
132
  */
133
  public static function IHasClone($img, $obj)
134
  {
158
  }
159
 
160
  /**
161
+ * Get image info when scan post
162
+ *
163
+ * @param string $content Post content
164
+ * @param array $imgs List img in content
165
+ *
166
  * @return array
167
  */
168
  public static function IScan($content, $imgs = array())
169
  {
170
  $ifound = array();
171
+ $doc = new DOMDocument();
172
  libxml_use_internal_errors(true);
173
+ $doc->loadHtml($content);
174
  $tags = $doc->getElementsByTagName('img');
175
 
176
  //For standard images names, convert spaces to -
177
  $_imgs = array();
178
  foreach ($imgs as $iname => $iid) {
179
+ $iname = preg_replace('/(\s{1,})/', '-', $iname);
180
  $_imgs[$iname] = $iid;
181
  }
182
  if ($tags->length > 0) {
183
  foreach ($tags as $order => $tag) {
184
  // only find img tag have source
185
+ $obj = $tag->getAttribute('src');
186
+ if ($obj === '') {
187
  continue;
188
  }
189
+ $img_name = self::IHasClone(array_keys($_imgs), $obj);
190
+ if ($img_name) {
191
  if (!empty($_imgs[$img_name])) {
192
+ $ifound[$order]['id'] = $_imgs[$img_name];
193
+ $ifound[$order]['src'] = $obj;
194
+ $ifound[$order]['width'] = $tag->getAttribute('width');
195
  $ifound[$order]['height'] = $tag->getAttribute('height');
196
+ $ifound[$order]['alt'] = trim($tag->getAttribute('alt'));
197
  } else {
198
  continue;
199
  }
205
  }
206
 
207
  /**
208
+ * Get posts list
209
+ *
210
+ * @param integer $iID ID of post
211
+ * @param string $opt_type Meta type
212
+ *
213
  * @return array|mixed
214
  */
215
  public static function getPostList($iID, $opt_type)
216
  {
217
  //Get image info from wp_postmeta with key equals to _metaseo_img_meta_not_good
218
  $meta_key = '_metaseo_' . strtolower(trim($opt_type));
219
+ $posts = get_post_meta($iID, $meta_key, true);
220
 
221
  if (is_array($posts) && !empty($posts)) {
222
  return $posts;
226
  }
227
 
228
  /**
229
+ * Get image not good
230
+ *
231
+ * @param array $imgs List images
232
+ * @param array $posts List post container image
233
+ *
234
  * @return array
235
  */
236
  public static function IPrepare($imgs, $posts)
237
  {
238
+ $iNotGood = array();
239
+ $iNotGoodTotal = array();
240
  $imNotGoodTotal = array();
241
+ $imNotGood = array();
242
+ $upload_dir = wp_upload_dir();
243
 
244
  // scan img tag for each post content
245
  foreach ($posts as $post) {
255
  $iID = $img['id'];
256
  //Get image that its size is not good
257
  $imgpath = str_replace(site_url(), ABSPATH, $img['src']);
258
+ if (!list($width_origin, $height_origin) = getimagesize($imgpath)) {
259
  continue;
260
  }
261
  $ratio_origin = $width_origin / $height_origin;
262
+ $width = $img['width'];
263
+ $height = $img['height'];
264
  //Check if img tag is missing with/height attribute value or not
265
  if (!$width && !$height) {
266
+ $width = $width_origin;
267
  $height = $height_origin;
268
  } elseif ($width && !$height) {
269
  $height = $width * (1 / $ratio_origin);
271
  $width = $height * ($ratio_origin);
272
  }
273
 
274
+ if ((int) $width_origin > (int) $width || (int) $height_origin > (int) $height) {
275
  $img_before = str_replace(array($upload_dir['baseurl']), '', $img['src']);
276
+ $ibpart = self::IGetPart($img_before);
277
 
278
  $img_after = $ibpart->base_path
279
+ . (!empty($ibpart->name_prefix) ? $ibpart->name_prefix : $ibpart->name)
280
+ . '-' . $width . 'x' . $height
281
+ . $ibpart->name_suffix
282
+ . $ibpart->ext;
283
 
284
  // create new image url and dir
285
  $srcs = array(
286
  'img_before_dir' => $upload_dir['basedir'] . $img_before,
287
  'img_before_url' => $upload_dir['baseurl'] . $img_before,
288
+ 'img_after_dir' => $upload_dir['basedir'] . $img_after,
289
+ 'img_after_url' => $upload_dir['baseurl'] . $img_after
290
  );
291
 
292
  // get size img
293
  $size = (filesize($srcs['img_before_dir']) / 1024);
294
  if ($size > 1024) {
295
+ $size = $size / 1024;
296
  $sizes = 'MB';
297
  } else {
298
  $sizes = 'KB';
299
  }
300
+ $size = round($size, 1);
301
 
302
+ $iNotGood[$iID][$post->ID]['ID'] = $post->ID;
303
+ $iNotGood[$iID][$post->ID]['title'] = $post->post_title;
304
+ $iNotGood[$iID][$post->ID]['post_type'] = $post->post_type;
305
  $iNotGood[$iID][$post->ID]['img_before_optm'][$order] = array(
306
+ 'size' => $size,
307
+ 'sizes' => $sizes,
308
+ 'src' => $srcs['img_before_url'],
309
+ 'width' => $width,
310
+ 'height' => $height,
311
+ 'dimension' => self::IGetDimension($img_before)
312
  );
313
 
314
  $iNotGood[$iID][$post->ID]['img_after_optm'][$order] = array(
315
+ 'size' => 0,
316
+ 'path' => $img_after,
317
+ 'src' => $srcs['img_after_url'],
318
  'src_origin' => $srcs['img_before_url'],
319
+ 'width' => $width,
320
+ 'height' => $height,
321
+ 'dimension' => self::IGetDimension($img_after)
322
  );
323
 
324
  //Get the number of images which their size are not good
325
  if (!isset($iNotGoodTotal[$iID])) {
326
  $iNotGoodTotal[$iID] = 0;
327
  }
328
+ $iNotGoodTotal[$iID] ++;
329
  } else {
330
  if (!isset($iNotGood[$iID])) {
331
  $iNotGood[$iID] = array();
336
  }
337
 
338
  //Get image that its meta/metas is/are not good
339
+ $meta_value = $img['alt'];
340
+ $imNotGood[$iID][$post->ID]['ID'] = $post->ID;
341
+ $imNotGood[$iID][$post->ID]['title'] = $post->post_title;
342
+ $imNotGood[$iID][$post->ID]['post_type'] = $post->post_type;
343
+ $imNotGood[$iID][$post->ID]['meta'][$order]['img_src'] = $img['src'];
344
  $imNotGood[$iID][$post->ID]['meta'][$order]['type']['alt'] = $meta_value;
345
+ if ($meta_value === '') {
346
  if (!isset($imNotGoodTotal[$iID]['alt'])) {
347
  $imNotGoodTotal[$iID]['alt'] = 0;
348
  }
349
+ $imNotGoodTotal[$iID]['alt'] ++;
350
  }
351
  }
352
  }
353
 
354
  foreach ($imgs as $name => $iID) {
355
  if (!isset($iNotGoodTotal[$iID])) {
356
+ $iNotGoodTotal[$iID] = - 1;
357
  }
358
  if (!isset($iNotGood[$iID])) {
359
  $iNotGood[$iID] = array();
375
  unset($posts, $imgs);
376
 
377
  $ret = array(
378
+ 'iNotGood' => $iNotGood,
379
+ 'iNotGoodTotal' => $iNotGoodTotal,
380
+ 'imNotGood' => $imNotGood,
381
  'imNotGoodTotal' => $imNotGoodTotal
382
  );
383
 
386
 
387
  /**
388
  * Scan image that has not good size or not good meta(s), then update info to postmeta table
389
+ *
390
+ * @param array $imgs List images
391
+ * @param boolean $delete Is delete
392
+ * @param integer $postID ID of post
393
+ *
394
  * @return array
395
  */
396
  public static function IScanPosts($imgs, $delete = false, $postID = 0)
401
 
402
  // get list sizes image
403
  $metadats = get_post_meta($idPost, '_wp_attachment_metadata', true);
404
+ $sizes = $metadats['sizes'];
405
 
406
  // get list url image and image thumbnail
407
+ $list_thum_url = array();
408
+ $imageUrl = wp_get_attachment_url($idPost);
409
  $list_thum_url[] = $imageUrl;
410
  if (!empty($sizes)) {
411
  foreach ($sizes as $key => $size) {
412
+ $thum_url = wp_get_attachment_image_src($idPost, $key);
413
  $list_thum_url[] = $thum_url[0];
414
  }
415
  }
416
 
417
+ $msg = array();
418
  $_imgs = array_flip($imgs);
 
 
419
  // sql where
420
  $w = '';
421
  $w .= '(';
422
  $i = 0;
423
  foreach ($list_thum_url as $url) {
424
  $url = str_replace(array('https', 'http'), array('', ''), $url);
425
+ $i ++;
426
+ if ((int) $i === count($list_thum_url)) {
427
+ $w .= $wpdb->prepare(' post_content LIKE %s', array('%' . $url . '%'));
428
  } else {
429
+ $w .= $wpdb->prepare(' post_content LIKE %s OR', array('%' . $url . '%'));
430
  }
431
  }
432
 
433
+ $w .= ')';
434
  $where = array();
435
  if ($delete) {
436
+ $where[] = 'ID != ' . (int) $postID;
437
+ }
438
+
439
+ $post_types = MetaSeoContentListTable::getPostTypes();
440
+ foreach ($post_types as &$post_type) {
441
+ $post_type = esc_sql($post_type);
442
  }
443
+
444
+ $post_types = implode("', '", $post_types);
445
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
446
+ $where[] = "post_content LIKE '%<img%'";
447
+ $where[] = $w;
 
448
  // query post
449
+ $posts = $wpdb->get_results('SELECT ID, post_title, post_content, post_type, post_date
450
+ FROM ' . $wpdb->posts . '
451
+ WHERE ' . implode(' AND ', $where) . ' ORDER BY ID'); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
452
+
453
  $results = self::IPrepare($imgs, $posts);
454
  //Update some value into fields in wp_postmeta
455
  if (count($results['iNotGood']) > 0) {
463
  }
464
 
465
  $msg[$iID]['iNotGood']['msg']
466
+ = $results['iNotGoodTotal'][$iID] . $im . esc_html__('with wrong size', 'wp-meta-seo');
467
  $msg[$iID]['iNotGood']['warning'] = true;
468
 
469
  $msg[$iID]['iNotGood']['button'] = '<a href="javascript:void(0);"
470
+ class=" img-resize wpmsbtn wpmsbtn_small" data-img-name="' . esc_attr($_imgs[$iID]) . '"
471
+ data-post-id="' . esc_attr($iID) . '" data-opt-key="resize_image"
472
  onclick="showPostsList(this)">
473
+ ' . esc_html__('Resize image', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
474
 
475
  update_post_meta($iID, '_metaseo_resize_image_counter', $results['iNotGoodTotal'][$iID]);
476
  update_post_meta($iID, '_metaseo_resize_image', $post_group);
477
  } else {
478
+ $msg[$iID]['iNotGood']['msg'] = esc_html__('Image sizes are good!', 'wp-meta-seo');
479
  $msg[$iID]['iNotGood']['warning'] = false;
480
 
481
  delete_post_meta($iID, '_metaseo_resize_image_counter');
489
  foreach ($results['imNotGood'] as $iID => $post_group) {
490
  //This has a litle bit value
491
  if ($results['imNotGoodTotal'][$iID]['alt'] > 1) {
492
+ $i = $results['imNotGoodTotal'][$iID]['alt'] . ' alt text';
493
+ $msg[$iID]['imNotGood']['msg']['alt'] = $i . esc_html__('s are missing', 'wp-meta-seo');
494
+ } elseif ((int) $results['imNotGoodTotal'][$iID]['alt'] === 1) {
495
+ $i = $results['imNotGoodTotal'][$iID]['alt'] . ' alt text';
496
+ $msg[$iID]['imNotGood']['msg']['alt'] = $i . esc_html__(' is missing', 'wp-meta-seo');
497
  }
498
 
499
  $msg[$iID]['imNotGood']['warning'] = true;
500
+ $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
501
+ class=" fix-metas wpmsbtn wpmsbtn_small" data-img-name="' . esc_attr($_imgs[$iID]) . '"
502
+ data-post-id="' . esc_attr($iID) . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
503
+ alt="' . esc_attr__('This image has been detected
504
  in your content, edit information here…', 'wp-meta-seo') . '">
505
+ ' . esc_html__('Edit meta in content', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
506
 
507
 
508
  update_post_meta($iID, '_metaseo_fix_metas_counter', count($post_group));
509
  update_post_meta($iID, '_metaseo_fix_metas', $post_group);
510
 
511
 
512
+ if ((int) $results['imNotGoodTotal'][$iID]['alt'] === 0) {
513
+ if ((int) $results['iNotGoodTotal'][$iID] !== - 1) {
514
  $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
515
+ class=" fix-metas wpmsbtn wpmsbtn_small wpmsbtn_secondary" data-img-name="' . esc_attr($_imgs[$iID]) . '"
516
+ data-post-id="' . esc_attr($iID) . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
517
+ alt="' . esc_attr__('This image has been detected in your content,
518
  edit information here…', 'wp-meta-seo') . '">
519
+ ' . esc_html__('Edit meta', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
520
  } else {
521
  $msg[$iID]['imNotGood']['button'] = '';
522
  }
523
  $msg[$iID]['imNotGood']['warning'] = false;
524
+ $msg[$iID]['imNotGood']['msg'] = '';
525
  }
526
  }
527
  }
533
 
534
  /**
535
  * Ajax optimize image and update content
536
+ *
537
+ * @param integer $post_id Post id
538
+ * @param integer $img_post_id Image id
539
+ * @param array $img_exclude Image exclude
540
+ *
541
  * @return array
542
  */
543
  public static function optimizeImages($post_id, $img_post_id, $img_exclude)
544
  {
545
  global $wpdb;
546
  $ret = array('success' => false, 'msg' => '');
547
+ $res = $wpdb->get_row($wpdb->prepare('SELECT post_content FROM ' . $wpdb->posts . ' WHERE ID=%d', array($post_id)));
548
+ if (empty($res)) {
549
+ $ret['msg'] = esc_html__('This post is not existed or deleted, please choose one another!', 'wp-meta-seo');
 
 
550
  return $ret;
551
  }
552
+ $post_content = $res->post_content;
553
  $imgs_to_resize = get_post_meta($img_post_id, '_metaseo_resize_image', true);
 
554
  if (preg_match_all('/<img [^<>]+ \/>/i', $post_content, $matches)) {
555
  $replacement = array();
556
  foreach ($matches[0] as $order => $tag) {
560
  if (!isset($imgs_to_resize[$post_id])) {
561
  continue;
562
  }
563
+
564
  foreach ($imgs_to_resize[$post_id]['img_after_optm'] as $key => $img) {
565
  if (!in_array($order, $img_exclude)) {
566
  if (stripos($tag, $img['src_origin']) !== false &&
567
+ (('width' === $dimension[1] && (int) $dimension[2] === (int) $img['width'])
568
+ || ('height' === $dimension[1] && (int) $dimension[2] === (int) $img['height']))
569
  ) {
570
  $replacement[$order] = str_replace($img['src_origin'], $img['src'], $tag);
571
  }
581
 
582
  //Update post content with all imgs has been just optimized
583
  $id = wp_update_post(array(
584
+ 'ID' => $post_id,
585
  'post_content' => $post_content
586
  ));
587
 
588
  if ($id) {
589
  $ret['success'] = true;
590
+ $ret['msg'] = esc_html__('Well! This image is so good now.', 'wp-meta-seo');
591
  } else {
592
+ $ret['msg'] = esc_html__('Opps! An error occured when updating the post, please try again', 'wp-meta-seo');
593
  }
594
 
595
  return $ret;
596
  }
597
 
598
  /**
599
+ * Create new size for image
600
+ *
601
+ * @param string $src Source url of image
602
+ * @param float $width Width of image
603
+ * @param float $height Height of image
604
+ * @param string $destination Destination
605
+ *
606
+ * @return boolean|string
607
  */
608
  public static function IResize($src, $width, $height, $destination)
609
  {
610
  $imgpath = str_replace(site_url(), ABSPATH, $src);
611
  if (!list($w_origin, $h_origin) = getimagesize($imgpath)) {
612
+ return esc_html__('Unsupported picture type!', 'wp-meta-seo');
613
  }
614
 
615
  if (is_readable($destination)) {
616
  return true;
617
  }
618
 
619
+ $type = strtolower(substr(strrchr($imgpath, '.'), 1));
620
  if ($type === 'jpeg') {
621
  $type = 'jpg';
622
  }
635
  $img = imagecreatefrompng($imgpath);
636
  break;
637
  default:
638
+ return esc_html__('Unsupported picture type!', 'wp-meta-seo');
639
  }
640
 
641
  $new = imagecreatetruecolor($width, $height);
642
 
643
  // preserve transparency
644
+ if ($type === 'gif' || $type === 'png') {
645
  imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
646
  imagealphablending($new, false);
647
  imagesavealpha($new, true);
inc/class.metaseo-admin.php CHANGED
@@ -11,58 +11,70 @@ class MetaSeoAdmin
11
 
12
  /**
13
  * Current page
 
14
  * @var mixed
15
  */
16
  private $pagenow;
17
  /**
18
- * max length meta description
19
- * @var int
 
20
  */
21
  public static $desc_length = 320;
22
  /**
23
- * max length meta title
24
- * @var int
 
25
  */
26
  public static $title_length = 69;
27
  /**
28
  * Google client
29
- * @var
 
30
  */
31
  public $client;
32
  /**
33
  * Default access to connect to google
 
34
  * @var array
35
  */
36
  public $access = array(WPMS_CLIENTID, WPMS_CLIENTSECRET);
37
  /**
38
- * @var
 
 
39
  */
40
  public $error_timeout;
41
  /**
42
  * List google analytics options
 
43
  * @var array
44
  */
45
  public $ga_tracking;
46
  /**
47
- * option to check connect status
48
- * @var
 
49
  */
50
  public $gaDisconnect;
51
  /**
52
- * google alanytics options
53
- * @var
 
54
  */
55
  public $google_alanytics;
56
 
57
  /**
58
  * All settings for meta seo
 
59
  * @var array
60
  */
61
  public $settings;
62
 
63
  /**
64
  * Google service
65
- * @var
 
66
  */
67
  public $service;
68
 
@@ -83,7 +95,9 @@ class MetaSeoAdmin
83
  add_action('init', array($this, 'loadLangguage'));
84
  add_action('admin_menu', array($this, 'addMenuPage'));
85
 
86
- /** Load admin js * */
 
 
87
  add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts'));
88
  add_action('added_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4);
89
  add_action('updated_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4);
@@ -93,7 +107,7 @@ class MetaSeoAdmin
93
  }
94
 
95
  add_action('wp_ajax_wpms_set_ignore', array($this, 'setIgnore'));
96
- if ('0' == get_option('blog_public')) {
97
  add_action('admin_notices', array($this, 'publicWarning'));
98
  }
99
  add_action('wp_enqueue_editor', array($this, 'linkTitleField'), 20);
@@ -122,82 +136,91 @@ class MetaSeoAdmin
122
 
123
  /**
124
  * Init Meta seo settings
 
 
125
  */
126
  public function initSettings()
127
  {
128
  $this->settings = array(
129
- "metaseo_title_home" => "",
130
- "metaseo_desc_home" => "",
131
- "metaseo_showfacebook" => "",
132
- "metaseo_showfbappid" => "",
133
- "metaseo_showtwitter" => "",
134
- "metaseo_twitter_card" => "summary",
135
- "metaseo_showkeywords" => 0,
136
- "metaseo_showtmetablock" => 1,
137
- "metaseo_showsocial" => 1,
138
- "metaseo_seovalidate" => 0,
139
- "metaseo_linkfield" => 1,
140
- "metaseo_metatitle_tab" => 0,
141
- "metaseo_follow" => 0,
142
- "metaseo_index" => 0,
143
- "metaseo_overridemeta" => 1
144
  );
145
- $settings = get_option('_metaseo_settings');
146
 
147
  if (is_array($settings)) {
148
  $this->settings = array_merge($this->settings, $settings);
149
  }
150
 
151
- if ((isset($this->settings['metaseo_showtmetablock']) && $this->settings['metaseo_showtmetablock'] == 1)) {
152
  $this->loadMetaBoxes();
153
  }
154
  }
155
 
156
  /**
157
  * Init google analytics tracking options
 
 
158
  */
159
  public function initGaSettings()
160
  {
161
  $this->ga_tracking = array(
162
- 'wpmsga_dash_tracking' => 1,
163
- 'wpmsga_dash_tracking_type' => 'universal',
164
- 'wpmsga_dash_anonim' => 0,
165
- 'wpmsga_dash_remarketing' => 0,
166
- 'wpmsga_event_tracking' => 0,
167
- 'wpmsga_event_downloads' => 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*',
168
- 'wpmsga_aff_tracking' => 0,
169
- 'wpmsga_event_affiliates' => '/out/',
170
- 'wpmsga_hash_tracking' => 0,
171
- 'wpmsga_author_dimindex' => 0,
172
- 'wpmsga_pubyear_dimindex' => 0,
173
- 'wpmsga_category_dimindex' => 0,
174
- 'wpmsga_user_dimindex' => 0,
175
- 'wpmsga_tag_dimindex' => 0,
176
- 'wpmsga_speed_samplerate' => 1,
177
- 'wpmsga_event_bouncerate' => 0,
178
- 'wpmsga_enhanced_links' => 0,
179
- 'wpmsga_dash_adsense' => 0,
180
  'wpmsga_crossdomain_tracking' => 0,
181
- 'wpmsga_crossdomain_list' => '',
182
- 'wpmsga_cookiedomain' => '',
183
- 'wpmsga_cookiename' => '',
184
- 'wpmsga_cookieexpires' => '',
185
- 'wpmsga_track_exclude' => array(),
186
- 'wpmsga_code_tracking' => ''
187
  );
188
  }
189
 
190
  /**
191
  * Admin init
 
 
192
  */
193
  public function adminInit()
194
  {
195
  $this->fieldSettings();
196
  $this->createDatabase();
 
197
  }
198
 
199
  /**
200
- * add category meta field
 
 
201
  */
202
  public function categoryField()
203
  {
@@ -221,74 +244,90 @@ class MetaSeoAdmin
221
  ?>
222
  <div class="form-field">
223
  <label class="wpms_custom_cat_field"
224
- data-alt="<?php _e('This is the title of your content that may be displayed in search engine
225
  results (meta title). By default it’s the content title (page title, post title…).
226
  69 characters max allowed.', 'wp-meta-seo') ?>">
227
- <?php _e('Search engine title', 'wp-meta-seo'); ?>
228
  </label>
229
  <label>
230
  <textarea name="wpms_category_metatitle" class="wpms_category_metatitle"></textarea>
231
  <br/>
232
  </label>
233
- <div class="cat-title-len"><?php echo MPMSCAT_TITLE_LENGTH; ?></div>
234
  </div>
235
 
236
  <?php
237
  $settings = get_option('_metaseo_settings');
238
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) :
239
  ?>
240
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
241
  <label class="wpms_custom_cat_field"
242
- data-alt="<?php _e('This is the keywords of your content that may be
243
  displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>">
244
- <?php _e('Search engine keywords', 'wp-meta-seo'); ?>
245
  </label>
246
  <label>
247
  <textarea name="wpms_category_metakeywords" class="wpms_cat_keywords"></textarea><br/>
248
  </label>
249
- <div class="cat-keywords-len"><?php echo MPMSCAT_KEYWORDS_LENGTH; ?></div>
250
  </div>
251
  <?php endif; ?>
252
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
253
  <label for="extra1" class="wpms_custom_cat_field"
254
- data-alt="<?php _e('This is the title of your content that may be displayed in search
255
  engine results (meta title). By default it’s the content title (page title, post title…).
256
  69 characters max allowed.', 'wp-meta-seo') ?>">
257
- <?php _e('Search engine description', 'wp-meta-seo'); ?>
258
  </label>
259
  <label>
260
  <textarea name="wpms_category_metadesc" class="wpms_category_metadesc"></textarea><br/>
 
261
  </label>
262
- <div class="cat-desc-len"><?php echo MPMSCAT_DESC_LENGTH; ?></div>
263
  </div>
264
  <?php
265
  }
266
 
267
  /**
268
  * Save category meta
269
- * @param int $term_id current category id
 
 
 
270
  */
271
  public function saveCategoryMeta($term_id)
272
  {
273
- if (isset($_POST['wpms_category_metatitle'])) {
274
- update_term_meta($term_id, 'wpms_category_metatitle', $_POST['wpms_category_metatitle']);
275
- }
 
 
 
 
276
 
277
- if (isset($_POST['wpms_category_metadesc'])) {
278
- update_term_meta($term_id, 'wpms_category_metadesc', $_POST['wpms_category_metadesc']);
279
- }
280
 
281
- $settings = get_option('_metaseo_settings');
282
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
283
- if (isset($_POST['wpms_category_metakeywords'])) {
284
- update_term_meta($term_id, 'wpms_category_metakeywords', $_POST['wpms_category_metakeywords']);
 
 
 
 
 
285
  }
286
  }
287
  }
288
 
289
  /**
290
- * add extra fields to category edit form callback function
291
- * @param object $tag current category
 
 
 
292
  */
293
  public function editCategoryFields($tag)
294
  {
@@ -308,24 +347,24 @@ class MetaSeoAdmin
308
 
309
  wp_enqueue_style('wpms-category-field');
310
  wp_enqueue_script('wpms-category-field');
311
- $t_id = $tag->term_id;
312
- $metatitle = get_term_meta($t_id, 'wpms_category_metatitle', true);
313
- $metadesc = get_term_meta($t_id, 'wpms_category_metadesc', true);
314
  $metakeywords = get_term_meta($t_id, 'wpms_category_metakeywords', true);
315
  ?>
316
  <tr class="form-field">
317
  <th scope="row" valign="top">
318
- <label class="wpms_custom_cat_field" data-alt="<?php _e('This is the title of your content that may
319
  be displayed in search engine results (meta title). By default it’s the content title
320
  (page title, post title…).69 characters max allowed.', 'wp-meta-seo') ?>">
321
- <?php _e('Search engine title', 'wp-meta-seo'); ?>
322
  </label>
323
  </th>
324
  <td>
325
  <label>
326
  <?php if ((!empty($metatitle))) : ?>
327
  <textarea name="wpms_category_metatitle"
328
- class="wpms_category_metatitle"><?php echo $metatitle; ?></textarea>
329
  <?php else : ?>
330
  <textarea name="wpms_category_metatitle"
331
  class="wpms_category_metatitle"></textarea>
@@ -334,7 +373,7 @@ class MetaSeoAdmin
334
  </label>
335
  <div class="cat-title-len">
336
  <?php
337
- echo $metatitle ? MPMSCAT_TITLE_LENGTH - strlen($metatitle) : MPMSCAT_TITLE_LENGTH;
338
  ?>
339
  </div>
340
  </td>
@@ -342,21 +381,21 @@ class MetaSeoAdmin
342
 
343
  <?php
344
  $settings = get_option('_metaseo_settings');
345
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) :
346
  ?>
347
  <tr class="form-field">
348
  <th scope="row" valign="top">
349
  <label for="extra1" class="wpms_custom_cat_field"
350
- data-alt="<?php _e('This is the keywords of your content that may be
351
  displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>">
352
- <?php _e('Search engine keywords', 'wp-meta-seo'); ?>
353
  </label>
354
  </th>
355
  <td>
356
  <label>
357
  <?php if ((!empty($metakeywords))) : ?>
358
  <textarea name="wpms_category_metakeywords"
359
- class="wpms_cat_keywords"><?php echo $metakeywords; ?></textarea>
360
  <?php else : ?>
361
  <textarea name="wpms_category_metakeywords"
362
  class="wpms_cat_keywords"></textarea>
@@ -366,7 +405,7 @@ class MetaSeoAdmin
366
 
367
  <div class="cat-keywords-len">
368
  <?php
369
- echo $metakeywords ? MPMSCAT_KEYWORDS_LENGTH - strlen($metakeywords) : MPMSCAT_KEYWORDS_LENGTH;
370
  ?>
371
  </div>
372
  </td>
@@ -375,25 +414,26 @@ class MetaSeoAdmin
375
  <tr class="form-field">
376
  <th scope="row" valign="top">
377
  <label for="extra1" class="wpms_custom_cat_field"
378
- data-alt="<?php _e('This is the title of your content that may be displayed in
379
  search engine results (meta title). By default it’s the content title (page title, post title…).
380
  69 characters max allowed.', 'wp-meta-seo') ?>">
381
- <?php _e('Search engine description', 'wp-meta-seo'); ?>
382
  </label>
383
  </th>
384
  <td>
385
  <label>
386
  <?php if ((!empty($metadesc))) : ?>
387
  <textarea name="wpms_category_metadesc"
388
- class="wpms_category_metadesc"><?php echo $metadesc; ?></textarea>
389
  <?php else : ?>
390
  <textarea name="wpms_category_metadesc"
391
  class="wpms_category_metadesc"></textarea>
392
  <?php endif; ?>
393
  <br/>
394
  </label>
 
395
  <div class="cat-desc-len">
396
- <?php echo $metadesc ? MPMSCAT_DESC_LENGTH - strlen($metadesc) : MPMSCAT_DESC_LENGTH; ?>
397
  </div>
398
  </td>
399
  </tr>
@@ -402,6 +442,8 @@ class MetaSeoAdmin
402
 
403
  /**
404
  * Function that outputs the contents of the dashboard widget
 
 
405
  */
406
  public function dashboardWidget()
407
  {
@@ -432,13 +474,14 @@ class MetaSeoAdmin
432
 
433
  /**
434
  * Function used in the action hook
 
 
435
  */
436
  public function addDashboardWidgets()
437
  {
438
-
439
  wp_add_dashboard_widget(
440
  'wpms_dashboard_widget',
441
- __('WP Meta SEO: Quick SEO preview', 'wp-meta-seo'),
442
  array(
443
  $this,
444
  'dashboardWidget'
@@ -448,151 +491,190 @@ class MetaSeoAdmin
448
 
449
  /**
450
  * Create link dialog
 
 
451
  */
452
  public function editorFooter()
453
  {
454
  if (!class_exists('_WP_Editors', false)) {
455
- require_once ABSPATH . "wp-includes/class-wp-editor.php";
456
  _WP_Editors::wp_link_dialog();
457
  }
458
  }
459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  /**
461
  * Create wpms_links table
 
 
462
  */
463
  public function createDatabase()
464
  {
465
  global $wpdb;
466
- $option_v = 'metaseo_db_version3.3.0';
467
  $db_installed = get_option($option_v, false);
468
  if (!$db_installed) {
469
  // create table wpms_links
470
- $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wpms_links`(
471
  `id` int(20) unsigned NOT NULL AUTO_INCREMENT,
472
  `link_url` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
473
  `link_final_url` text CHARACTER SET latin1 COLLATE latin1_general_cs,
474
  `link_url_redirect` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
475
- `link_text` text NOT NULL DEFAULT '',
476
- `source_id` int(20) DEFAULT '0',
477
- `type` varchar(100) DEFAULT '',
478
- `status_code` varchar(100) DEFAULT '',
479
- `status_text` varchar(250) DEFAULT '',
480
- `hit` int(20) NOT NULL DEFAULT '1',
481
- `redirect` tinyint(1) NOT NULL DEFAULT '0',
482
- `broken_indexed` tinyint(1) unsigned NOT NULL DEFAULT '0',
483
- `broken_internal` tinyint(1) unsigned NOT NULL DEFAULT '0',
484
- `warning` tinyint(1) unsigned NOT NULL DEFAULT '0',
485
- `dismissed` tinyint(1) NOT NULL DEFAULT '0',
486
- PRIMARY KEY (id))";
487
 
488
 
489
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
490
  dbDelta($sql);
491
 
492
-
493
- $sql = $wpdb->prepare(
494
- "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
495
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",
496
  array($wpdb->prefix . 'wpms_links', 'follow', $wpdb->dbname)
497
- );
498
- $row = $wpdb->get_results($sql);
499
 
500
  if (empty($row)) {
501
- $wpdb->query("ALTER TABLE " . $wpdb->prefix . "wpms_links ADD follow tinyint(1) DEFAULT 1");
502
  }
503
 
504
- $sql = $wpdb->prepare(
505
- "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
506
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",
507
  array($wpdb->prefix . 'wpms_links', 'meta_title', $wpdb->dbname)
508
- );
509
- $row = $wpdb->get_results($sql);
510
 
511
  if (empty($row)) {
512
- $wpdb->query("ALTER TABLE " . $wpdb->prefix . "wpms_links ADD meta_title varchar(250) DEFAULT ''");
513
  }
514
 
515
- $sql = $wpdb->prepare(
516
- "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
517
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",
518
  array($wpdb->prefix . 'wpms_links', 'internal', $wpdb->dbname)
519
- );
520
- $row = $wpdb->get_results($sql);
521
 
522
  if (empty($row)) {
523
- $wpdb->query("ALTER TABLE " . $wpdb->prefix . "wpms_links ADD internal tinyint(1) DEFAULT 1");
524
  }
525
 
526
  // create page 404
527
- $sql = $wpdb->prepare(
528
- "SELECT * FROM " . $wpdb->prefix . "posts
529
- WHERE post_title = %s AND post_excerpt = %s AND post_type = %s",
530
- array("WP Meta SEO 404 Page", "metaseo_404_page", "page")
531
- );
532
- $post_if = $wpdb->get_results($sql);
533
- if (empty($post_if)) {
534
- $content = '<div class="wall"
535
- style="background-color: #F2F3F7; border: 30px solid #fff; width: 90%; height: 90%; margin: 0 auto;">
536
-
537
- <h1 style="text-align: center; font-family:\'open-sans\', arial;
538
- color: #444; font-size: 60px; padding: 50px;">ERROR 404 <br />-<br />NOT FOUND</h1>
539
- <p style="text-align: center; font-family:\'open-sans\', arial; color: #444;
540
- font-size: 40px; padding: 20px; line-height: 55px;">
541
- // You may have mis-typed the URL,<br />
542
- // Or the page has been removed,<br />
543
- // Actually, there is nothing to see here...</p>
544
- <p style="text-align: center;"><a style=" font-family:\'open-sans\', arial; color: #444;
545
- font-size: 20px; padding: 20px; line-height: 30px; text-decoration: none;"
546
- href="' . get_home_url() . '"><< Go back to home page >></a></p>
547
- </div>';
548
- $_page404 = array(
549
- 'post_title' => '404 error page',
550
- 'post_content' => $content,
551
- 'post_status' => 'publish',
552
- 'post_excerpt' => 'metaseo_404_page',
553
- 'post_type' => 'page',
554
- );
555
- wp_insert_post($_page404);
556
- } else {
557
- $my_post = array(
558
- 'ID' => $post_if[0]->ID,
559
- 'post_title' => '404 error page'
560
- );
561
-
562
- wp_update_post($my_post);
563
- }
564
-
565
- $sql = $wpdb->prepare(
566
- "SELECT COUNT(*) FROM " . $wpdb->prefix . "posts
567
- WHERE post_title = %s AND post_excerpt = %s AND post_type = %s",
568
- array(
569
- "WPMS HTML Sitemap",
570
- "metaseo_html_sitemap",
571
- "page"
572
- )
573
  );
574
- $post_if = $wpdb->get_var($sql);
575
  if ($post_if < 1) {
576
  $_sitemap_page = array(
577
- 'post_title' => 'WPMS HTML Sitemap',
578
  'post_content' => '',
579
- 'post_status' => 'publish',
580
  'post_excerpt' => 'metaseo_html_sitemap',
581
- 'post_type' => 'page',
582
  );
583
  wp_insert_post($_sitemap_page);
584
  }
585
 
586
  update_option($option_v, true);
587
  }
 
 
 
 
 
 
 
 
 
588
  }
589
 
590
  /**
591
  * Add field title in dialog link when edit a link
 
 
592
  */
593
  public function linkTitleField()
594
  {
595
- if (isset($this->settings['metaseo_linkfield']) && $this->settings['metaseo_linkfield'] == 1) {
596
  wp_enqueue_script(
597
  'wpmslinkTitle',
598
  plugins_url('js/wpms-link-title-field.js', dirname(__FILE__)),
@@ -601,13 +683,15 @@ class MetaSeoAdmin
601
  true
602
  );
603
  wp_localize_script('wpmslinkTitle', 'wpmsLinkTitleL10n', array(
604
- 'titleLabel' => __('Title', 'wp-meta-seo'),
605
  ));
606
  }
607
  }
608
 
609
  /**
610
  * Update option wpms_set_ignore
 
 
611
  */
612
  public function setIgnore()
613
  {
@@ -620,6 +704,8 @@ class MetaSeoAdmin
620
 
621
  /**
622
  * Render message error when disable search engines from indexing this site
 
 
623
  */
624
  public function publicWarning()
625
  {
@@ -627,7 +713,7 @@ class MetaSeoAdmin
627
  return;
628
  }
629
 
630
- if (get_option('wpms_set_ignore') == 0) {
631
  return;
632
  }
633
 
@@ -640,19 +726,21 @@ class MetaSeoAdmin
640
  class="button">%4$s</a>
641
  </p>
642
  </div>',
643
- __('Your website is not indexed by search engine because of your WordPress settings.', 'wp-meta-seo'),
644
  sprintf(
645
- __('%sFix it now%s', 'wp-meta-seo'),
646
  sprintf('<a href="%s">', esc_url(admin_url('options-reading.php'))),
647
  '</a>'
648
  ),
649
  esc_js(wp_create_nonce('wpseo-ignore')),
650
- __('OK I know that.', 'wp-meta-seo')
651
  );
652
  }
653
 
654
  /**
655
  * Loads translated strings.
 
 
656
  */
657
  public function loadLangguage()
658
  {
@@ -664,48 +752,58 @@ class MetaSeoAdmin
664
  }
665
 
666
  /**
667
- * @param $data_title
668
- * @param $alt
669
- * @param $dashicon
670
- * @param $label
671
- * @param $value_hidden
 
 
 
672
  * @return string
673
  */
674
  public function createFieldAnalysis($data_title, $alt, $dashicon, $label, $value_hidden)
675
  {
676
- $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . $data_title . '" data-alt="' . $alt . '">';
677
- if ($dashicon == 'done') {
678
  $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxdone">done</i>';
679
  } else {
680
  $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxwarning">warning</i>';
681
  }
682
 
683
- $output .= $label;
684
  $output .= '</div>';
685
  $output .= '<input type="hidden" class="wpms_analysis_hidden"
686
- name="wpms[' . $data_title . ']" value="' . $value_hidden . '">';
687
  return $output;
688
  }
689
 
690
  /**
691
  * Ajax load page analysis
 
 
692
  */
693
  public function reloadAnalysis()
694
  {
695
- if (!current_user_can('manage_options')) {
 
 
 
 
 
696
  wp_send_json(array('status' => false));
697
  }
698
- $tooltip_page = array();
699
- $tooltip_page['title_in_heading'] = __('Check if a word of this content title
700
  is also in a title heading (h1, h2...)', 'wp-meta-seo');
701
- $tooltip_page['title_in_content'] = __('Check if a word of this content
702
  title is also in the text', 'wp-meta-seo');
703
- $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
704
- $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
705
- $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
706
- $tooltip_page['image_resize'] = __('Check for image HTML resizing in content
707
  (usually image resized using handles)', 'wp-meta-seo');
708
- $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
709
  if (empty($_POST['datas'])) {
710
  wp_send_json(false);
711
  }
@@ -714,15 +812,15 @@ class MetaSeoAdmin
714
  update_post_meta($_POST['datas']['post_id'], 'wpms_validate_analysis', '');
715
  }
716
 
717
- $meta_analysis = get_post_meta((int)$_POST['datas']['post_id'], 'wpms_validate_analysis', true);
718
- $check = 0;
719
- $output = '';
720
 
721
  // title heading
722
  $words_post_title = preg_split(
723
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
724
  strtolower($_POST['datas']['title']),
725
- -1,
726
  PREG_SPLIT_NO_EMPTY
727
  );
728
 
@@ -741,17 +839,17 @@ class MetaSeoAdmin
741
  'heading_title',
742
  $tooltip_page['title_in_heading'],
743
  'done',
744
- __('Page title word in content heading', 'wp-meta-seo'),
745
  1
746
  );
747
- $check++;
748
  } else {
749
- if ($content == '') {
750
  $output .= $this->createFieldAnalysis(
751
  'heading_title',
752
  $tooltip_page['title_in_heading'],
753
  'warning',
754
- __('Page title word in content heading', 'wp-meta-seo'),
755
  0
756
  );
757
  } else {
@@ -777,12 +875,12 @@ class MetaSeoAdmin
777
  $words_tagh1 = preg_split(
778
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
779
  utf8_decode(strtolower($tagh1->nodeValue)),
780
- -1,
781
  PREG_SPLIT_NO_EMPTY
782
  );
783
  if (is_array($words_tagh1) && is_array($words_post_title)) {
784
  foreach ($words_tagh1 as $mh) {
785
- if (in_array($mh, $words_post_title) && $mh != '') {
786
  $test = true;
787
  }
788
  }
@@ -796,12 +894,12 @@ class MetaSeoAdmin
796
  $words_tagh2 = preg_split(
797
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
798
  utf8_decode(strtolower($tagh2->nodeValue)),
799
- -1,
800
  PREG_SPLIT_NO_EMPTY
801
  );
802
  if (is_array($words_tagh2) && is_array($words_post_title)) {
803
  foreach ($words_tagh2 as $mh) {
804
- if (in_array($mh, $words_post_title) && $mh != '') {
805
  $test = true;
806
  }
807
  }
@@ -815,12 +913,12 @@ class MetaSeoAdmin
815
  $words_tagh3 = preg_split(
816
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
817
  utf8_decode(strtolower($tagh3->nodeValue)),
818
- -1,
819
  PREG_SPLIT_NO_EMPTY
820
  );
821
  if (is_array($words_tagh3) && is_array($words_post_title)) {
822
  foreach ($words_tagh3 as $mh) {
823
- if (in_array($mh, $words_post_title) && $mh != '') {
824
  $test = true;
825
  }
826
  }
@@ -834,12 +932,12 @@ class MetaSeoAdmin
834
  $words_tagh4 = preg_split(
835
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
836
  utf8_decode(strtolower($tagh4->nodeValue)),
837
- -1,
838
  PREG_SPLIT_NO_EMPTY
839
  );
840
  if (is_array($words_tagh4) && is_array($words_post_title)) {
841
  foreach ($words_tagh4 as $mh) {
842
- if (in_array($mh, $words_post_title) && $mh != '') {
843
  $test = true;
844
  }
845
  }
@@ -853,12 +951,12 @@ class MetaSeoAdmin
853
  $words_tagh5 = preg_split(
854
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
855
  utf8_decode(strtolower($tagh5->nodeValue)),
856
- -1,
857
  PREG_SPLIT_NO_EMPTY
858
  );
859
  if (is_array($words_tagh5) && is_array($words_post_title)) {
860
  foreach ($words_tagh5 as $mh) {
861
- if (in_array($mh, $words_post_title) && $mh != '') {
862
  $test = true;
863
  }
864
  }
@@ -872,12 +970,12 @@ class MetaSeoAdmin
872
  $words_tagh6 = preg_split(
873
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
874
  utf8_decode(strtolower($tagh6->nodeValue)),
875
- -1,
876
  PREG_SPLIT_NO_EMPTY
877
  );
878
  if (is_array($words_tagh6) && is_array($words_post_title)) {
879
  foreach ($words_tagh6 as $mh) {
880
- if (in_array($mh, $words_post_title) && $mh != '') {
881
  $test = true;
882
  }
883
  }
@@ -891,16 +989,16 @@ class MetaSeoAdmin
891
  'heading_title',
892
  $tooltip_page['title_in_heading'],
893
  'done',
894
- __('Page title word in content heading', 'wp-meta-seo'),
895
  1
896
  );
897
- $check++;
898
  } else {
899
  $output .= $this->createFieldAnalysis(
900
  'heading_title',
901
  $tooltip_page['title_in_heading'],
902
  'warning',
903
- __('Page title word in content heading', 'wp-meta-seo'),
904
  0
905
  );
906
  }
@@ -909,7 +1007,7 @@ class MetaSeoAdmin
909
  'heading_title',
910
  $tooltip_page['title_in_heading'],
911
  'warning',
912
- __('Page title word in content heading', 'wp-meta-seo'),
913
  0
914
  );
915
  }
@@ -917,23 +1015,23 @@ class MetaSeoAdmin
917
  }
918
 
919
  // title content
920
- $words_title = preg_split(
921
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
922
  strtolower($_POST['datas']['title']),
923
- -1,
924
  PREG_SPLIT_NO_EMPTY
925
  );
926
  $words_post_content = preg_split(
927
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
928
  strtolower(strip_tags($content)),
929
- -1,
930
  PREG_SPLIT_NO_EMPTY
931
  );
932
 
933
  $test1 = false;
934
  if (is_array($words_title) && is_array($words_post_content)) {
935
  foreach ($words_title as $mtitle) {
936
- if (in_array($mtitle, $words_post_content) && $mtitle != '') {
937
  $test1 = true;
938
  break;
939
  }
@@ -947,26 +1045,26 @@ class MetaSeoAdmin
947
  'content_title',
948
  $tooltip_page['title_in_content'],
949
  'done',
950
- __('Page title word in content', 'wp-meta-seo'),
951
  1
952
  );
953
- $check++;
954
  } else {
955
  if ($test1) {
956
  $output .= $this->createFieldAnalysis(
957
  'content_title',
958
  $tooltip_page['title_in_content'],
959
  'done',
960
- __('Page title word in content', 'wp-meta-seo'),
961
  1
962
  );
963
- $check++;
964
  } else {
965
  $output .= $this->createFieldAnalysis(
966
  'content_title',
967
  $tooltip_page['title_in_content'],
968
  'warning',
969
- __('Page title word in content', 'wp-meta-seo'),
970
  0
971
  );
972
  }
@@ -979,33 +1077,33 @@ class MetaSeoAdmin
979
  'pageurl',
980
  $tooltip_page['page_url'],
981
  'done',
982
- __('Page url matches with page title', 'wp-meta-seo'),
983
  1
984
  );
985
- $check++;
986
  } else {
987
- if ($_POST['datas']['editor'] == 'gutenberg') {
988
- $infos = pathinfo($_POST['datas']['mpageurl']);
989
  $mpageurl = $infos['filename'];
990
  } else {
991
  $mpageurl = $_POST['datas']['mpageurl'];
992
  }
993
 
994
- if ($mpageurl == sanitize_title($mtitle)) {
995
  $output .= $this->createFieldAnalysis(
996
  'pageurl',
997
  $tooltip_page['page_url'],
998
  'done',
999
- __('Page url matches with page title', 'wp-meta-seo'),
1000
  1
1001
  );
1002
- $check++;
1003
  } else {
1004
  $output .= $this->createFieldAnalysis(
1005
  'pageurl',
1006
  $tooltip_page['page_url'],
1007
  'warning',
1008
- __('Page url matches with page title', 'wp-meta-seo'),
1009
  0
1010
  );
1011
  }
@@ -1017,27 +1115,27 @@ class MetaSeoAdmin
1017
  'metatitle',
1018
  $tooltip_page['meta_title'],
1019
  'done',
1020
- __('Meta title filled', 'wp-meta-seo'),
1021
  1
1022
  );
1023
- $check++;
1024
  } else {
1025
- if (($_POST['datas']['meta_title'] != ''
1026
- && mb_strlen($_POST['datas']['meta_title'], 'UTF-8') <= self::$title_length)) {
1027
  $output .= $this->createFieldAnalysis(
1028
  'metatitle',
1029
  $tooltip_page['meta_title'],
1030
  'done',
1031
- __('Meta title filled', 'wp-meta-seo'),
1032
  1
1033
  );
1034
- $check++;
1035
  } else {
1036
  $output .= $this->createFieldAnalysis(
1037
  'metatitle',
1038
  $tooltip_page['meta_title'],
1039
  'warning',
1040
- __('Meta title filled', 'wp-meta-seo'),
1041
  0
1042
  );
1043
  }
@@ -1049,59 +1147,59 @@ class MetaSeoAdmin
1049
  'metadesc',
1050
  $tooltip_page['meta_desc'],
1051
  'done',
1052
- __('Meta description filled', 'wp-meta-seo'),
1053
  1
1054
  );
1055
- $check++;
1056
  } else {
1057
- if ($_POST['datas']['meta_desc'] != ''
1058
  && mb_strlen($_POST['datas']['meta_desc'], 'UTF-8') <= self::$desc_length) {
1059
  $output .= $this->createFieldAnalysis(
1060
  'metadesc',
1061
  $tooltip_page['meta_desc'],
1062
  'done',
1063
- __('Meta description filled', 'wp-meta-seo'),
1064
  1
1065
  );
1066
- $check++;
1067
  } else {
1068
  $output .= $this->createFieldAnalysis(
1069
  'metadesc',
1070
  $tooltip_page['meta_desc'],
1071
  'warning',
1072
- __('Meta description filled', 'wp-meta-seo'),
1073
  0
1074
  );
1075
  }
1076
  }
1077
 
1078
  // image resize
1079
- if ($content == '') {
1080
  $output .= $this->createFieldAnalysis(
1081
  'imgresize',
1082
  $tooltip_page['image_resize'],
1083
  'done',
1084
- __('Wrong image resize', 'wp-meta-seo'),
1085
  1
1086
  );
1087
  $output .= $this->createFieldAnalysis(
1088
  'imgalt',
1089
  $tooltip_page['image_alt'],
1090
  'done',
1091
- __('Image have meta alt', 'wp-meta-seo'),
1092
  1
1093
  );
1094
- $check += 2;
1095
  } else {
1096
  $dom = new DOMDocument;
1097
  libxml_use_internal_errors(true);
1098
  if ($dom->loadHTML($content)) {
1099
  // Extracting the specified elements from the web page
1100
- $tags = $dom->getElementsByTagName('img');
1101
- $img_wrong = false;
1102
  $img_wrong_alt = false;
1103
  foreach ($tags as $order => $tag) {
1104
- $src = $tag->getAttribute('src');
1105
  $imgpath = str_replace(site_url(), ABSPATH, $src);
1106
  if (!file_exists($imgpath)) {
1107
  continue;
@@ -1110,19 +1208,19 @@ class MetaSeoAdmin
1110
  continue;
1111
  }
1112
 
1113
- if ((int)$tag->getAttribute('width') == 0 && (int)$tag->getAttribute('height') == 0) {
1114
  $img_wrong = false;
1115
  } else {
1116
  if (!empty($width_origin) && !empty($height_origin)) {
1117
- if (((int)$width_origin != (int)$tag->getAttribute('width'))
1118
- || ((int)$height_origin != (int)$tag->getAttribute('height'))) {
1119
  $img_wrong = true;
1120
  }
1121
  }
1122
  }
1123
 
1124
  $image_alt = $tag->getAttribute('alt');
1125
- if ($image_alt == '') {
1126
  $img_wrong_alt = true;
1127
  }
1128
  }
@@ -1132,26 +1230,26 @@ class MetaSeoAdmin
1132
  'imgresize',
1133
  $tooltip_page['image_resize'],
1134
  'done',
1135
- __('Wrong image resize', 'wp-meta-seo'),
1136
  1
1137
  );
1138
- $check++;
1139
  } else {
1140
- if ($img_wrong == false) {
1141
  $output .= $this->createFieldAnalysis(
1142
  'imgresize',
1143
  $tooltip_page['image_resize'],
1144
  'done',
1145
- __('Wrong image resize', 'wp-meta-seo'),
1146
  1
1147
  );
1148
- $check++;
1149
  } else {
1150
  $output .= $this->createFieldAnalysis(
1151
  'imgresize',
1152
  $tooltip_page['image_resize'],
1153
  'warning',
1154
- __('Wrong image resize', 'wp-meta-seo'),
1155
  0
1156
  );
1157
  }
@@ -1162,44 +1260,43 @@ class MetaSeoAdmin
1162
  'imgalt',
1163
  $tooltip_page['image_alt'],
1164
  'done',
1165
- __('Image have meta alt', 'wp-meta-seo'),
1166
  1
1167
  );
1168
- $check++;
1169
  } else {
1170
- if ($img_wrong_alt == false) {
1171
  $output .= $this->createFieldAnalysis(
1172
  'imgalt',
1173
  $tooltip_page['image_alt'],
1174
  'done',
1175
- __('Image have meta alt', 'wp-meta-seo'),
1176
  1
1177
  );
1178
- $check++;
1179
  } else {
1180
  $output .= $this->createFieldAnalysis(
1181
  'imgalt',
1182
  $tooltip_page['image_alt'],
1183
  'warning',
1184
- __('Image have meta alt', 'wp-meta-seo'),
1185
  0
1186
  );
1187
  }
1188
  }
1189
-
1190
  } else {
1191
  $output .= $this->createFieldAnalysis(
1192
  'imgresize',
1193
  $tooltip_page['image_resize'],
1194
  'warning',
1195
- __('Wrong image resize', 'wp-meta-seo'),
1196
  0
1197
  );
1198
  $output .= $this->createFieldAnalysis(
1199
  'imgalt',
1200
  $tooltip_page['image_alt'],
1201
  'warning',
1202
- __('Image have meta alt', 'wp-meta-seo'),
1203
  0
1204
  );
1205
  }
@@ -1210,15 +1307,22 @@ class MetaSeoAdmin
1210
  }
1211
 
1212
  /**
1213
- * validate propertyin page optimization
 
 
1214
  */
1215
  public function validateAnalysis()
1216
  {
 
 
 
 
 
1217
  if (!current_user_can('manage_options')) {
1218
  wp_send_json(false);
1219
  }
1220
- $post_id = $_POST['post_id'];
1221
- $key = 'wpms_validate_analysis';
1222
  $analysis = get_post_meta($post_id, $key, true);
1223
  if (empty($analysis)) {
1224
  $analysis = array();
@@ -1231,16 +1335,23 @@ class MetaSeoAdmin
1231
 
1232
  /**
1233
  * Remove link in source 404
 
 
1234
  */
1235
  public function removeLink()
1236
  {
 
 
 
 
 
1237
  if (!current_user_can('manage_options')) {
1238
  wp_send_json(array('status' => false));
1239
  }
1240
 
1241
  global $wpdb;
1242
  if (isset($_POST['link_id'])) {
1243
- $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => (int)$_POST['link_id']));
1244
  wp_send_json(array('status' => true));
1245
  }
1246
 
@@ -1249,21 +1360,27 @@ class MetaSeoAdmin
1249
 
1250
  /**
1251
  * Ajax update link meta title and content editor
 
 
1252
  */
1253
  public function updateLink()
1254
  {
 
 
 
 
 
1255
  if (!current_user_can('manage_options')) {
1256
  wp_send_json(false);
1257
  }
1258
  if (isset($_POST['link_id'])) {
1259
  global $wpdb;
1260
- $sql = $wpdb->prepare(
1261
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1262
  array(
1263
- (int)$_POST['link_id']
1264
  )
1265
- );
1266
- $link_detail = $wpdb->get_row($sql);
1267
  if (empty($link_detail)) {
1268
  wp_send_json(false);
1269
  }
@@ -1272,24 +1389,42 @@ class MetaSeoAdmin
1272
  $wpdb->update(
1273
  $wpdb->prefix . 'wpms_links',
1274
  $value,
1275
- array('id' => $_POST['link_id'])
1276
  );
1277
 
1278
 
1279
  $post = get_post($link_detail->source_id);
1280
  if (!empty($post)) {
1281
- $old_value = $post->post_content;
1282
- $edit_result = $this->editLinkHtml(
1283
- $old_value,
1284
- $link_detail->link_url,
1285
- $link_detail->link_url,
1286
- $_POST['meta_title'],
1287
- $link_detail->follow
1288
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1289
 
1290
  $my_post = array(
1291
- 'ID' => $link_detail->source_id,
1292
- 'post_content' => $edit_result['content']
1293
  );
1294
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1295
  wp_update_post($my_post);
@@ -1301,9 +1436,16 @@ class MetaSeoAdmin
1301
 
1302
  /**
1303
  * Ajax update meta index for page
 
 
1304
  */
1305
  public function updatePageIndex()
1306
  {
 
 
 
 
 
1307
  if (!current_user_can('manage_options')) {
1308
  wp_send_json(array('status' => false));
1309
  }
@@ -1316,14 +1458,21 @@ class MetaSeoAdmin
1316
 
1317
  /**
1318
  * Ajax update meta follow for page
 
 
1319
  */
1320
  public function updatePageFollow()
1321
  {
 
 
 
 
 
1322
  if (!current_user_can('manage_options')) {
1323
  wp_send_json(array('status' => false));
1324
  }
1325
  if (isset($_POST['page_id']) && isset($_POST['follow'])) {
1326
- update_post_meta($_POST['page_id'], '_metaseo_metafollow', $_POST['follow']);
1327
  wp_send_json(array('status' => true));
1328
  }
1329
  wp_send_json(array('status' => false));
@@ -1331,9 +1480,16 @@ class MetaSeoAdmin
1331
 
1332
  /**
1333
  * Ajax update meta follow for link
 
 
1334
  */
1335
  public function updateFollow()
1336
  {
 
 
 
 
 
1337
  if (!current_user_can('manage_options')) {
1338
  wp_send_json(array('status' => false));
1339
  }
@@ -1346,15 +1502,22 @@ class MetaSeoAdmin
1346
 
1347
  /**
1348
  * Ajax update multitle meta follow for link
 
 
1349
  */
1350
  public function updateMultipleFollow()
1351
  {
 
 
 
 
 
1352
  if (!current_user_can('manage_options')) {
1353
  wp_send_json(array('status' => false));
1354
  }
1355
  global $wpdb;
1356
  $follow_value = $_POST['follow_value'];
1357
- $limit = 20;
1358
 
1359
  switch ($follow_value) {
1360
  case 'follow_selected':
@@ -1370,16 +1533,16 @@ class MetaSeoAdmin
1370
 
1371
  case 'follow_all':
1372
  $follow = 1;
1373
- $i = 0;
1374
- $links = $wpdb->get_results(
1375
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=0 AND type='url'"
1376
  );
1377
  foreach ($links as $link) {
1378
  if ($i > $limit) {
1379
  wp_send_json(array('status' => false, 'message' => 'limit'));
1380
  } else {
1381
  $this->doUpdateFollow($link->id, $follow);
1382
- $i++;
1383
  }
1384
  }
1385
 
@@ -1398,16 +1561,16 @@ class MetaSeoAdmin
1398
 
1399
  case 'nofollow_all':
1400
  $follow = 0;
1401
- $i = 0;
1402
- $links = $wpdb->get_results(
1403
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=1 AND type='url'"
1404
  );
1405
  foreach ($links as $link) {
1406
  if ($i > $limit) {
1407
  wp_send_json(array('status' => false, 'message' => 'limit'));
1408
  } else {
1409
  $this->doUpdateFollow($link->id, $follow);
1410
- $i++;
1411
  }
1412
  }
1413
  break;
@@ -1417,34 +1580,33 @@ class MetaSeoAdmin
1417
 
1418
  /**
1419
  * Ajax update meta follow for link
1420
- * @param int $linkId link id
1421
- * @param int $follow follow value
 
 
 
1422
  */
1423
  public function doUpdateFollow($linkId, $follow)
1424
  {
1425
  global $wpdb;
1426
- $sql = $wpdb->prepare(
1427
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1428
- array(
1429
- $linkId
1430
- )
1431
- );
1432
- $link_detail = $wpdb->get_row($sql);
1433
  if (empty($link_detail)) {
1434
  wp_send_json(array('status' => false));
1435
  }
1436
 
1437
-
1438
  $value = array('follow' => $follow);
1439
  $wpdb->update(
1440
  $wpdb->prefix . 'wpms_links',
1441
  $value,
1442
- array('id' => $linkId)
1443
  );
1444
 
1445
  $post = get_post($link_detail->source_id);
1446
  if (!empty($post)) {
1447
- $old_value = $post->post_content;
1448
  $edit_result = $this->editLinkHtml(
1449
  $old_value,
1450
  $link_detail->link_url,
@@ -1452,8 +1614,8 @@ class MetaSeoAdmin
1452
  $link_detail->meta_title,
1453
  $follow
1454
  );
1455
- $my_post = array(
1456
- 'ID' => $link_detail->source_id,
1457
  'post_content' => $edit_result['content']
1458
  );
1459
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
@@ -1463,23 +1625,25 @@ class MetaSeoAdmin
1463
 
1464
  /**
1465
  * Render new content when edit a link
1466
- * @param string $content post content
1467
- * @param string $new_url new url
1468
- * @param string $old_url old url
1469
- * @param string $meta_title meta title
1470
- * @param int $follow follow value
1471
- * @param null $new_text new text of link
 
 
1472
  * @return array
1473
  */
1474
  public function editLinkHtml($content, $new_url, $old_url, $meta_title, $follow, $new_text = null)
1475
  {
1476
  //Save the old & new URLs for use in the edit callback.
1477
  $args = array(
1478
- 'old_url' => $old_url,
1479
- 'new_url' => $new_url,
1480
- 'new_text' => $new_text,
1481
  'meta_title' => $meta_title,
1482
- 'follow' => $follow
1483
  );
1484
 
1485
  //Find all links and replace those that match $old_url.
@@ -1504,9 +1668,16 @@ class MetaSeoAdmin
1504
 
1505
  /**
1506
  * Update option wpms_settings_404
 
 
1507
  */
1508
  public function save404Settings()
1509
  {
 
 
 
 
 
1510
  if (!current_user_can('manage_options')) {
1511
  wp_send_json(false);
1512
  }
@@ -1516,7 +1687,7 @@ class MetaSeoAdmin
1516
  }
1517
 
1518
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1519
- $params = array('enable', 'numberFrequency', 'showlinkFrequency');
1520
  $settinglink = array();
1521
  foreach ($params as $param) {
1522
  if (isset($_POST[$param])) {
@@ -1535,14 +1706,21 @@ class MetaSeoAdmin
1535
 
1536
  /**
1537
  * Update breadcrumb settings
 
 
1538
  */
1539
  public function saveBreadcrumbSettings()
1540
  {
 
 
 
 
 
1541
  if (!current_user_can('manage_options')) {
1542
  wp_send_json(false);
1543
  }
1544
 
1545
- $params = array('separator', 'include_home', 'home_text', 'clickable', 'home_text_default');
1546
  $settinglink = array();
1547
  foreach ($params as $param) {
1548
  if (isset($_POST[$param])) {
@@ -1556,6 +1734,8 @@ class MetaSeoAdmin
1556
 
1557
  /**
1558
  * Add a new field to a section of a settings page
 
 
1559
  */
1560
  public function fieldSettings()
1561
  {
@@ -1563,180 +1743,182 @@ class MetaSeoAdmin
1563
  add_settings_section('metaseo_dashboard', '', array($this, 'showSettings'), 'metaseo_settings');
1564
  add_settings_field(
1565
  'metaseo_title_home',
1566
- __('Homepage meta title', 'wp-meta-seo'),
1567
  array($this, 'titleHome'),
1568
  'metaseo_settings',
1569
  'metaseo_dashboard',
1570
  array(
1571
- 'label_for' => __('You can define your home page meta title in the content
1572
  itself (a page, a post category…),
1573
  if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1574
  )
1575
  );
1576
  add_settings_field(
1577
  'metaseo_desc_home',
1578
- __('Homepage meta description', 'wp-meta-seo'),
1579
  array($this, 'descHome'),
1580
  'metaseo_settings',
1581
  'metaseo_dashboard',
1582
  array(
1583
- 'label_for' => __('You can define your home page meta description in the content
1584
  itself (a page, a post category…),
1585
  if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1586
  )
1587
  );
1588
  add_settings_field(
1589
  'metaseo_showfacebook',
1590
- __('Facebook profile URL', 'wp-meta-seo'),
1591
  array($this, 'showfacebook'),
1592
  'metaseo_settings',
1593
  'metaseo_dashboard',
1594
  array(
1595
- 'label_for' => __('Used as profile in case of social sharing content on Facebook', 'wp-meta-seo')
1596
  )
1597
  );
1598
  add_settings_field(
1599
  'metaseo_showfbappid',
1600
- __('Facebook App ID', 'wp-meta-seo'),
1601
  array($this, 'showfbappid'),
1602
  'metaseo_settings',
1603
  'metaseo_dashboard',
1604
  array(
1605
- 'label_for' => __('Used as facebook app ID in case of
1606
  social sharing content on Facebook', 'wp-meta-seo')
1607
  )
1608
  );
1609
  add_settings_field(
1610
  'metaseo_showtwitter',
1611
- __('Twitter Username', 'wp-meta-seo'),
1612
  array($this, 'showtwitter'),
1613
  'metaseo_settings',
1614
  'metaseo_dashboard',
1615
  array(
1616
- 'label_for' => __('Used as profile in case of social sharing content on Twitter', 'wp-meta-seo')
1617
  )
1618
  );
1619
  add_settings_field(
1620
  'metaseo_twitter_card',
1621
- __('The default card type to use', 'wp-meta-seo'),
1622
  array($this, 'showtwittercard'),
1623
  'metaseo_settings',
1624
  'metaseo_dashboard',
1625
  array(
1626
- 'label_for' => __('Choose the Twitter card size generated when sharing a content', 'wp-meta-seo')
1627
  )
1628
  );
1629
  add_settings_field(
1630
  'metaseo_metatitle_tab',
1631
- __('Meta title as page title', 'wp-meta-seo'),
1632
  array($this, 'showmetatitletab'),
1633
  'metaseo_settings',
1634
  'metaseo_dashboard',
1635
  array(
1636
- 'label_for' => __('Usually not recommended as meta information is
1637
  for search engines and content title for readers, but in some case... :)', 'wp-meta-seo')
1638
  )
1639
  );
1640
  add_settings_field(
1641
  'metaseo_showkeywords',
1642
- __('Meta keywords', 'wp-meta-seo'),
1643
  array($this, 'showkeywords'),
1644
  'metaseo_settings',
1645
  'metaseo_dashboard',
1646
  array(
1647
- 'label_for' => __('Not used directly by search engine to index content,
1648
  but in some case it can be helpful (multilingual is an example)', 'wp-meta-seo')
1649
  )
1650
  );
1651
  add_settings_field(
1652
  'metaseo_showtmetablock',
1653
- __('Meta block edition', 'wp-meta-seo'),
1654
  array($this, 'showtmetablock'),
1655
  'metaseo_settings',
1656
  'metaseo_dashboard',
1657
  array(
1658
- 'label_for' => __('Load the onpage meta edition and analysis block', 'wp-meta-seo')
1659
  )
1660
  );
1661
  add_settings_field(
1662
  'metaseo_showsocial',
1663
- __('Social sharing block', 'wp-meta-seo'),
1664
  array($this, 'showsocial'),
1665
  'metaseo_settings',
1666
  'metaseo_dashboard',
1667
  array(
1668
- 'label_for' => __('Activate the custom social sharing tool, above the meta block', 'wp-meta-seo')
1669
  )
1670
  );
1671
  add_settings_field(
1672
  'metaseo_seovalidate',
1673
- __('Force SEO validation', 'wp-meta-seo'),
1674
  array($this, 'showseovalidate'),
1675
  'metaseo_settings',
1676
  'metaseo_dashboard',
1677
  array(
1678
- 'label_for' => __('Possibility to force a criteria validation
1679
  in the content analysis tool', 'wp-meta-seo')
1680
  )
1681
  );
1682
  add_settings_field(
1683
  'metaseo_linkfield',
1684
- __('Link text field', 'wp-meta-seo'),
1685
  array($this, 'showlinkfield'),
1686
  'metaseo_settings',
1687
  'metaseo_dashboard',
1688
  array(
1689
- 'label_for' => __('Add the link title field in the text editor and
1690
  in the bulk link edition view', 'wp-meta-seo')
1691
  )
1692
  );
1693
  add_settings_field(
1694
  'metaseo_follow',
1695
- __('Post/Page follow', 'wp-meta-seo'),
1696
  array($this, 'showfollow'),
1697
  'metaseo_settings',
1698
  'metaseo_dashboard',
1699
  array(
1700
- 'label_for' => __('Add an option to setup Follow/Nofollow instruction for each content', 'wp-meta-seo')
1701
  )
1702
  );
1703
  add_settings_field(
1704
  'metaseo_index',
1705
- __('Post/Page index', 'wp-meta-seo'),
1706
  array($this, 'showindex'),
1707
  'metaseo_settings',
1708
  'metaseo_dashboard',
1709
  array(
1710
- 'label_for' => __('Add an option to say to search engine: hey!
1711
  Do not index this content', 'wp-meta-seo')
1712
  )
1713
  );
1714
  add_settings_field(
1715
  'metaseo_overridemeta',
1716
- __('Auto override Meta', 'wp-meta-seo'),
1717
  array($this, 'showoverridemeta'),
1718
  'metaseo_settings',
1719
  'metaseo_dashboard',
1720
  array(
1721
- 'label_for' => __('Auto override image meta in post content when update meta', 'wp-meta-seo')
1722
  )
1723
  );
1724
  }
1725
 
1726
  /**
1727
  * Display metatitle_tab input
 
 
1728
  */
1729
  public function showmetatitletab()
1730
  {
1731
  echo '<input name="_metaseo_settings[metaseo_metatitle_tab]" type="hidden" value="0"/>';
1732
  ?>
1733
  <label>
1734
- <?php _e('When meta title is filled use it as page title instead of the content title', 'wp-meta-seo'); ?>
1735
  </label>
1736
  <div class="switch-optimization">
1737
  <label class="switch switch-optimization">
1738
  <?php
1739
- if (isset($this->settings['metaseo_metatitle_tab']) && $this->settings['metaseo_metatitle_tab'] == 1) :
1740
  ?>
1741
  <input type="checkbox" id="metaseo_metatitle_tab" name="_metaseo_settings[metaseo_metatitle_tab]"
1742
  value="1" checked>
@@ -1750,12 +1932,19 @@ class MetaSeoAdmin
1750
  <?php
1751
  }
1752
 
 
 
 
 
 
1753
  public function showSettings()
1754
  {
1755
  }
1756
 
1757
  /**
1758
  * Display title_home input
 
 
1759
  */
1760
  public function titleHome()
1761
  {
@@ -1766,6 +1955,8 @@ class MetaSeoAdmin
1766
 
1767
  /**
1768
  * Display desc_home input
 
 
1769
  */
1770
  public function descHome()
1771
  {
@@ -1776,16 +1967,18 @@ class MetaSeoAdmin
1776
 
1777
  /**
1778
  * Display showkeywords input
 
 
1779
  */
1780
  public function showkeywords()
1781
  {
1782
  echo '<input name="_metaseo_settings[metaseo_showkeywords]" type="hidden" value="0"/>';
1783
  ?>
1784
- <label><?php _e('Active meta keywords', 'wp-meta-seo'); ?></label>
1785
  <div class="switch-optimization">
1786
  <label class="switch switch-optimization">
1787
  <?php
1788
- if (isset($this->settings['metaseo_showkeywords']) && $this->settings['metaseo_showkeywords'] == 1) :
1789
  ?>
1790
  <input type="checkbox" id="metaseo_showkeywords" name="_metaseo_settings[metaseo_showkeywords]"
1791
  value="1" checked>
@@ -1801,17 +1994,19 @@ class MetaSeoAdmin
1801
 
1802
  /**
1803
  * Display showtmetablock input
 
 
1804
  */
1805
  public function showtmetablock()
1806
  {
1807
  echo '<input name="_metaseo_settings[metaseo_showtmetablock]" type="hidden" value="0"/>';
1808
  ?>
1809
- <label><?php _e('Activate meta block edition below content', 'wp-meta-seo'); ?></label>
1810
  <div class="switch-optimization">
1811
  <label class="switch switch-optimization">
1812
  <?php
1813
  if (isset($this->settings['metaseo_showtmetablock'])
1814
- && $this->settings['metaseo_showtmetablock'] == 1) :
1815
  ?>
1816
  <input type="checkbox" id="metaseo_showtmetablock" name="_metaseo_settings[metaseo_showtmetablock]"
1817
  value="1" checked>
@@ -1827,16 +2022,18 @@ class MetaSeoAdmin
1827
 
1828
  /**
1829
  * Display showsocial input
 
 
1830
  */
1831
  public function showsocial()
1832
  {
1833
  echo '<input name="_metaseo_settings[metaseo_showsocial]" type="hidden" value="0"/>';
1834
  ?>
1835
- <label><?php _e('Activate social edition', 'wp-meta-seo'); ?></label>
1836
  <div class="switch-optimization">
1837
  <label class="switch switch-optimization">
1838
  <?php
1839
- if (isset($this->settings['metaseo_showsocial']) && $this->settings['metaseo_showsocial'] == 1) :
1840
  ?>
1841
  <input type="checkbox" id="metaseo_showsocial" name="_metaseo_settings[metaseo_showsocial]"
1842
  value="1" checked>
@@ -1852,18 +2049,20 @@ class MetaSeoAdmin
1852
 
1853
  /**
1854
  * Display seovalidate input
 
 
1855
  */
1856
  public function showseovalidate()
1857
  {
1858
  echo '<input name="_metaseo_settings[metaseo_seovalidate]" type="hidden" value="0"/>';
1859
  ?>
1860
  <label>
1861
- <?php _e('Allow user to force on page SEO criteria validation by clicking on the icon', 'wp-meta-seo'); ?>
1862
  </label>
1863
  <div class="switch-optimization">
1864
  <label class="switch switch-optimization">
1865
  <?php
1866
- if (isset($this->settings['metaseo_seovalidate']) && $this->settings['metaseo_seovalidate'] == 1) :
1867
  ?>
1868
  <input type="checkbox" id="metaseo_seovalidate" name="_metaseo_settings[metaseo_seovalidate]"
1869
  value="1" checked>
@@ -1879,16 +2078,18 @@ class MetaSeoAdmin
1879
 
1880
  /**
1881
  * Display linkfield input
 
 
1882
  */
1883
  public function showlinkfield()
1884
  {
1885
  echo '<input name="_metaseo_settings[metaseo_linkfield]" type="hidden" value="0"/>';
1886
  ?>
1887
- <label><?php _e("Adds back the missing 'title' field in the Insert/Edit URL box", "wp-meta-seo"); ?></label>
1888
  <div class="switch-optimization">
1889
  <label class="switch switch-optimization">
1890
  <?php
1891
- if (isset($this->settings['metaseo_linkfield']) && $this->settings['metaseo_linkfield'] == 1) :
1892
  ?>
1893
  <input type="checkbox" id="metaseo_linkfield" name="_metaseo_settings[metaseo_linkfield]"
1894
  value="1" checked>
@@ -1904,19 +2105,21 @@ class MetaSeoAdmin
1904
 
1905
  /**
1906
  * Display follow input
 
 
1907
  */
1908
  public function showfollow()
1909
  {
1910
  echo '<input name="_metaseo_settings[metaseo_follow]" type="hidden" value="0"/>';
1911
  ?>
1912
  <label>
1913
- <?php _e("Provides a way for webmasters to tell
1914
- search engines don't follow links on the page.", "wp-meta-seo"); ?>
1915
  </label>
1916
  <div class="switch-optimization">
1917
  <label class="switch switch-optimization">
1918
  <?php
1919
- if (isset($this->settings['metaseo_follow']) && $this->settings['metaseo_follow'] == 1) :
1920
  ?>
1921
  <input type="checkbox" id="metaseo_follow" name="_metaseo_settings[metaseo_follow]"
1922
  value="1" checked>
@@ -1932,19 +2135,21 @@ class MetaSeoAdmin
1932
 
1933
  /**
1934
  * Display index input
 
 
1935
  */
1936
  public function showindex()
1937
  {
1938
  echo '<input name="_metaseo_settings[metaseo_index]" type="hidden" value="0"/>';
1939
  ?>
1940
  <label>
1941
- <?php _e("Provides show or do not show this page in search
1942
- results in search results.", "wp-meta-seo"); ?>
1943
  </label>
1944
  <div class="switch-optimization">
1945
  <label class="switch switch-optimization">
1946
  <?php
1947
- if (isset($this->settings['metaseo_index']) && $this->settings['metaseo_index'] == 1) :
1948
  ?>
1949
  <input type="checkbox" id="metaseo_index" name="_metaseo_settings[metaseo_index]"
1950
  value="1" checked>
@@ -1960,16 +2165,18 @@ class MetaSeoAdmin
1960
 
1961
  /**
1962
  * Display override meta
 
 
1963
  */
1964
  public function showoverridemeta()
1965
  {
1966
  echo '<input name="_metaseo_settings[metaseo_overridemeta]" type="hidden" value="0"/>';
1967
  ?>
1968
- <label><?php _e("Override meta image in post content when update meta", "wp-meta-seo"); ?></label>
1969
  <div class="switch-optimization">
1970
  <label class="switch switch-optimization">
1971
  <?php
1972
- if (isset($this->settings['metaseo_overridemeta']) && $this->settings['metaseo_overridemeta'] == 1) :
1973
  ?>
1974
  <input type="checkbox" id="metaseo_overridemeta" name="_metaseo_settings[metaseo_overridemeta]"
1975
  value="1" checked>
@@ -1985,6 +2192,8 @@ class MetaSeoAdmin
1985
 
1986
  /**
1987
  * Display showfacebook input
 
 
1988
  */
1989
  public function showfacebook()
1990
  {
@@ -1995,6 +2204,8 @@ class MetaSeoAdmin
1995
 
1996
  /**
1997
  * Display fb app id input
 
 
1998
  */
1999
  public function showfbappid()
2000
  {
@@ -2005,6 +2216,8 @@ class MetaSeoAdmin
2005
 
2006
  /**
2007
  * Display showtwitter input
 
 
2008
  */
2009
  public function showtwitter()
2010
  {
@@ -2015,6 +2228,8 @@ class MetaSeoAdmin
2015
 
2016
  /**
2017
  * Display twitter_card input
 
 
2018
  */
2019
  public function showtwittercard()
2020
  {
@@ -2027,9 +2242,9 @@ class MetaSeoAdmin
2027
  <label>
2028
  <select class="select" name="_metaseo_settings[metaseo_twitter_card]" id="metaseo_twitter_card">
2029
  <option <?php selected($twitter_card, 'summary') ?>
2030
- value="summary"><?php _e('Summary', 'wp-meta-seo'); ?></option>
2031
  <option <?php selected($twitter_card, 'summary_large_image') ?>
2032
- value="summary_large_image"><?php _e('Summary with large image', 'wp-meta-seo'); ?></option>
2033
  </select>
2034
  </label>
2035
  <?php
@@ -2037,6 +2252,8 @@ class MetaSeoAdmin
2037
 
2038
  /**
2039
  * Show meta box in single post
 
 
2040
  */
2041
  private function loadMetaBoxes()
2042
  {
@@ -2053,46 +2270,52 @@ class MetaSeoAdmin
2053
 
2054
  /**
2055
  * Update meta title , meta description , meta keyword for content
 
 
2056
  */
2057
  public function updateContentMetaCallback()
2058
  {
 
 
 
 
2059
 
2060
  if (!current_user_can('manage_options')) {
2061
  wp_send_json(array('status' => false));
2062
  }
2063
- $_POST = stripslashes_deep($_POST);
2064
- $response = new stdClass();
2065
- $metakey = strtolower(trim($_POST['metakey']));
2066
- $postID = intval($_POST['postid']);
2067
- $value = trim($_POST['value']);
2068
- $response->msg = __('Modification was saved', 'wp-meta-seo');
2069
- if ($metakey == 'metatitle') {
2070
  if (!update_post_meta($postID, '_metaseo_metatitle', $value)) {
2071
  $response->updated = false;
2072
- $response->msg = __('Meta title was not saved', 'wp-meta-seo');
2073
  } else {
2074
  $response->updated = true;
2075
- $response->msg = __('Meta title was saved', 'wp-meta-seo');
2076
  }
2077
  }
2078
 
2079
- if ($metakey == 'metadesc') {
2080
  if (!update_post_meta($postID, '_metaseo_metadesc', $value)) {
2081
  $response->updated = false;
2082
- $response->msg = __('Meta description was not saved', 'wp-meta-seo');
2083
  } else {
2084
  $response->updated = true;
2085
- $response->msg = __('Meta description was saved', 'wp-meta-seo');
2086
  }
2087
  }
2088
 
2089
- if ($metakey == 'metakeywords') {
2090
  if (!update_post_meta($postID, '_metaseo_metakeywords', $value)) {
2091
  $response->updated = false;
2092
- $response->msg = __('Meta keywords was not saved', 'wp-meta-seo');
2093
  } else {
2094
  $response->updated = true;
2095
- $response->msg = __('Meta keywords was saved', 'wp-meta-seo');
2096
  }
2097
  }
2098
  update_option('wpms_last_update_post', time());
@@ -2102,6 +2325,8 @@ class MetaSeoAdmin
2102
 
2103
  /**
2104
  * Loads js/ajax scripts
 
 
2105
  */
2106
  public function loadAdminScripts()
2107
  {
@@ -2159,7 +2384,7 @@ class MetaSeoAdmin
2159
  true
2160
  );
2161
 
2162
- if (in_array($current_screen->base, $array_menu) || $pagenow == 'post.php' || $pagenow == 'post-new.php') {
2163
  wp_enqueue_style(
2164
  'wpmetaseoAdmin',
2165
  plugins_url('css/metaseo_admin.css', dirname(__FILE__)),
@@ -2175,8 +2400,8 @@ class MetaSeoAdmin
2175
  wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
2176
  }
2177
 
2178
- if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta'
2179
- || $current_screen->base == 'wp-meta-seo_page_metaseo_content_meta') {
2180
  wp_enqueue_script(
2181
  'wpms-bulk',
2182
  plugins_url('js/wpms-bulk-action.js', dirname(__FILE__)),
@@ -2187,7 +2412,7 @@ class MetaSeoAdmin
2187
  wp_localize_script('wpms-bulk', 'wpmseobulkL10n', $this->localizeScript());
2188
  }
2189
 
2190
- if ($current_screen->base == 'wp-meta-seo_page_metaseo_broken_link') {
2191
  wp_enqueue_style(
2192
  'wpms_brokenlink_style',
2193
  plugins_url('css/broken_link.css', dirname(__FILE__)),
@@ -2196,7 +2421,7 @@ class MetaSeoAdmin
2196
  );
2197
  }
2198
 
2199
- if ($current_screen->base == 'toplevel_page_metaseo_dashboard') {
2200
  wp_enqueue_script(
2201
  'Chart',
2202
  plugins_url('js/Chart.js', dirname(__FILE__)),
@@ -2245,7 +2470,8 @@ class MetaSeoAdmin
2245
  'wp-meta-seo_page_metaseo_google_sitemap',
2246
  'wp-meta-seo_page_metaseo_link_meta',
2247
  'wp-meta-seo_page_metaseo_broken_link',
2248
- 'wp-meta-seo_page_metaseo_google_analytics');
 
2249
  if (in_array($current_screen->base, $lists_pages)) {
2250
  wp_enqueue_style(
2251
  'wpms_notification_style',
@@ -2308,7 +2534,7 @@ class MetaSeoAdmin
2308
  );
2309
 
2310
  wp_register_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons');
2311
- if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta') {
2312
  wp_enqueue_script(
2313
  'mautosize',
2314
  plugins_url('js/autosize.js', dirname(__FILE__)),
@@ -2318,7 +2544,7 @@ class MetaSeoAdmin
2318
  );
2319
  }
2320
 
2321
- if ($current_screen->base == 'wp-meta-seo_page_metaseo_google_analytics') {
2322
  $lang = get_bloginfo('language');
2323
  $lang = explode('-', $lang);
2324
  $lang = $lang[0];
@@ -2376,69 +2602,69 @@ class MetaSeoAdmin
2376
  'wpms-google-analytics',
2377
  'wpmsItemData',
2378
  array(
2379
- 'ajaxurl' => admin_url('admin-ajax.php'),
2380
- 'security' => wp_create_nonce('wpms_backend_item_reports'),
2381
- 'dateList' => array(
2382
- 'realtime' => __("Real-Time", 'wp-meta-seo'),
2383
- 'today' => __("Today", 'wp-meta-seo'),
2384
- 'yesterday' => __("Yesterday", 'wp-meta-seo'),
2385
- '7daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 7),
2386
- '14daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 14),
2387
- '30daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 30),
2388
- '90daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 90),
2389
- '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'wp-meta-seo'), __('One', 'wp-meta-seo')),
2390
  '1095daysAgo' => sprintf(
2391
- _n("%s Year", "%s Years", 3, 'wp-meta-seo'),
2392
- __('Three', 'wp-meta-seo')
2393
  ),
2394
  ),
2395
- 'reportList' => array(
2396
- 'sessions' => __("Sessions", 'wp-meta-seo'),
2397
- 'users' => __("Users", 'wp-meta-seo'),
2398
- 'organicSearches' => __("Organic", 'wp-meta-seo'),
2399
- 'pageviews' => __("Page Views", 'wp-meta-seo'),
2400
- 'visitBounceRate' => __("Bounce Rate", 'wp-meta-seo'),
2401
- 'locations' => __("Location", 'wp-meta-seo'),
2402
- 'contentpages' => __("Pages", 'wp-meta-seo'),
2403
- 'referrers' => __("Referrers", 'wp-meta-seo'),
2404
- 'searches' => __("Searches", 'wp-meta-seo'),
2405
- 'trafficdetails' => __("Traffic", 'wp-meta-seo'),
2406
- 'technologydetails' => __("Technology", 'wp-meta-seo'),
2407
  ),
2408
- 'i18n' => array(
2409
- __("A JavaScript Error is blocking plugin resources!", 'wp-meta-seo'), //0
2410
- __("Traffic Mediums", 'wp-meta-seo'),
2411
- __("Visitor Type", 'wp-meta-seo'),
2412
- __("Search Engines", 'wp-meta-seo'),
2413
- __("Social Networks", 'wp-meta-seo'),
2414
- __("Sessions", 'wp-meta-seo'),
2415
- __("Users", 'wp-meta-seo'),
2416
- __("Page Views", 'wp-meta-seo'),
2417
- __("Bounce Rate", 'wp-meta-seo'),
2418
- __("Organic Search", 'wp-meta-seo'),
2419
- __("Pages/Session", 'wp-meta-seo'),
2420
- __("Invalid response", 'wp-meta-seo'),
2421
- __("Not enough data collected", 'wp-meta-seo'),
2422
- __("This report is unavailable", 'wp-meta-seo'),
2423
- __("report generated by", 'wp-meta-seo'), //14
2424
- __("This plugin needs an authorization:", 'wp-meta-seo') . '
2425
- <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">
2426
- ' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
2427
- __("Browser", 'wp-meta-seo'), //16
2428
- __("Operating System", 'wp-meta-seo'),
2429
- __("Screen Resolution", 'wp-meta-seo'),
2430
- __("Mobile Brand", 'wp-meta-seo'),
2431
- __("REFERRALS", 'wp-meta-seo'), //20
2432
- __("KEYWORDS", 'wp-meta-seo'),
2433
- __("SOCIAL", 'wp-meta-seo'),
2434
- __("CAMPAIGN", 'wp-meta-seo'),
2435
- __("DIRECT", 'wp-meta-seo'),
2436
- __("NEW", 'wp-meta-seo'), //25
2437
- __("You need select a profile:", 'wp-meta-seo') . '
2438
- <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">
2439
- ' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
2440
  ),
2441
- 'rtLimitPages' => 10,
2442
  'colorVariations' => array(
2443
  '#1e73be',
2444
  '#0459a4',
@@ -2448,22 +2674,23 @@ class MetaSeoAdmin
2448
  '#6abfff',
2449
  '#002671'
2450
  ),
2451
- 'region' => false,
2452
- 'language' => get_bloginfo('language'),
2453
- 'viewList' => false,
2454
- 'scope' => 'admin-widgets',
2455
- 'admin_url' => admin_url()
2456
  )
2457
  );
2458
  }
2459
 
2460
  // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
2461
  wp_localize_script('wpmetaseoAdmin', 'wpms_localize', array(
2462
- 'ajax_url' => admin_url('admin-ajax.php'),
2463
- 'settings' => $this->settings,
2464
- 'wpms_cat_metatitle_length' => MPMSCAT_TITLE_LENGTH,
2465
- 'wpms_cat_metadesc_length' => MPMSCAT_DESC_LENGTH,
2466
- 'wpms_cat_metakeywords_length' => MPMSCAT_KEYWORDS_LENGTH
 
2467
  ));
2468
  }
2469
 
@@ -2471,11 +2698,13 @@ class MetaSeoAdmin
2471
  * Localize a script.
2472
  *
2473
  * Works only if the script has already been added.
 
 
2474
  */
2475
  public function localizeScript()
2476
  {
2477
  return array(
2478
- 'metaseo_message_false_copy' => __('Warning, you\'re about to replace existing image
2479
  alt or tile content, are you sire about that?', 'wp-meta-seo'),
2480
  );
2481
  }
@@ -2485,13 +2714,15 @@ class MetaSeoAdmin
2485
  *
2486
  * This function takes a capability which will be used to determine whether
2487
  * or not a page is included in the menu.
 
 
2488
  */
2489
  public function addMenuPage()
2490
  {
2491
  // Add main page
2492
  add_menu_page(
2493
- __('WP Meta SEO: Dashboard', 'wp-meta-seo'),
2494
- __('WP Meta SEO', 'wp-meta-seo'),
2495
  'manage_options',
2496
  'metaseo_dashboard',
2497
  array(
@@ -2514,16 +2745,25 @@ class MetaSeoAdmin
2514
  array(
2515
  'metaseo_dashboard',
2516
  '',
2517
- __('Content meta', 'wp-meta-seo'),
 
 
 
 
 
 
 
 
 
2518
  $manage_options_cap,
2519
  'metaseo_content_meta',
2520
  array($this, 'loadPage'),
2521
- null,
2522
  ),
2523
  array(
2524
  'metaseo_dashboard',
2525
  '',
2526
- __('Sitemap', 'wp-meta-seo'),
2527
  $manage_options_cap,
2528
  'metaseo_google_sitemap',
2529
  array($this, 'loadPage'),
@@ -2532,57 +2772,82 @@ class MetaSeoAdmin
2532
  array(
2533
  'metaseo_dashboard',
2534
  '',
2535
- __('Image information', 'wp-meta-seo'),
2536
  $manage_options_cap,
2537
  'metaseo_image_meta',
2538
  array($this, 'loadPage'),
2539
- null,
2540
  ),
2541
  array(
2542
  'metaseo_dashboard',
2543
  '',
2544
- __('Image compression', 'wp-meta-seo'),
2545
  $manage_options_cap,
2546
  'metaseo_image_compression',
2547
  array($this, 'loadPage'),
2548
- null,
2549
  ),
2550
  array(
2551
  'metaseo_dashboard',
2552
  '',
2553
- __('Link editor', 'wp-meta-seo'),
2554
  $manage_options_cap,
2555
  'metaseo_link_meta',
2556
  array($this, 'loadPage'),
2557
- null,
2558
  ),
2559
  array(
2560
  'metaseo_dashboard',
2561
  '',
2562
- __('404 & Redirects', 'wp-meta-seo'),
2563
  $manage_options_cap,
2564
  'metaseo_broken_link',
2565
  array($this, 'loadPage'),
2566
- null,
2567
  ),
2568
  array(
2569
  'metaseo_dashboard',
2570
  '',
2571
- __('Google Analytics', 'wp-meta-seo'),
2572
  $manage_options_cap,
2573
  'metaseo_google_analytics',
2574
  array($this, 'loadPage'),
2575
- null,
2576
- ),
2577
- array(
 
 
 
 
 
2578
  'metaseo_dashboard',
2579
- '',
2580
- __('Settings', 'wp-meta-seo'),
2581
  $manage_options_cap,
2582
- 'metaseo_settings',
2583
- array($this, 'loadPage'),
2584
- null,
2585
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2586
  );
2587
 
2588
  // Allow submenu pages manipulation
@@ -2594,7 +2859,7 @@ class MetaSeoAdmin
2594
  // Add submenu page
2595
  $admin_page = add_submenu_page(
2596
  $submenu_page[0],
2597
- $submenu_page[2] . ' - ' . __('WP Meta SEO:', 'wp-meta-seo'),
2598
  $submenu_page[2],
2599
  $submenu_page[3],
2600
  $submenu_page[4],
@@ -2602,7 +2867,7 @@ class MetaSeoAdmin
2602
  );
2603
 
2604
  // Check if we need to hook
2605
- if (isset($submenu_page[6]) && null != $submenu_page[6]
2606
  && is_array($submenu_page[6]) && count($submenu_page[6]) > 0) {
2607
  foreach ($submenu_page[6] as $submenu_page_action) {
2608
  add_action('load-' . $admin_page, $submenu_page_action);
@@ -2610,22 +2875,18 @@ class MetaSeoAdmin
2610
  }
2611
  }
2612
  }
2613
-
2614
- global $submenu;
2615
- if (isset($submenu['metaseo_dashboard']) && current_user_can($manage_options_cap)) {
2616
- $submenu['metaseo_dashboard'][0][0] = __('Dashboard', 'wp-meta-seo');
2617
- }
2618
  }
2619
 
2620
  /**
2621
  * Set error time out
 
 
2622
  */
2623
  public function setErrorTimeout()
2624
  {
2625
- $midnight = strtotime("tomorrow 00:00:00"); // UTC midnight
2626
- $midnight = $midnight + 8 * 3600; // UTC 8 AM
2627
  $this->error_timeout = $midnight - time();
2628
- return;
2629
  }
2630
 
2631
  /**
@@ -2637,8 +2898,8 @@ class MetaSeoAdmin
2637
  {
2638
  try {
2639
  $ga_dash_profile_list = array();
2640
- $startindex = 1;
2641
- $totalresults = 65535; // use something big
2642
  while ($startindex < $totalresults) {
2643
  $profiles = $this->service->management_profiles->listManagementProfiles(
2644
  '~all',
@@ -2647,15 +2908,15 @@ class MetaSeoAdmin
2647
  'start-index' => $startindex
2648
  )
2649
  );
2650
- $items = $profiles->getItems();
2651
 
2652
  $totalresults = $profiles->getTotalResults();
2653
 
2654
  if ($totalresults > 0) {
2655
  foreach ($items as $profile) {
2656
- $timetz = new DateTimeZone($profile->getTimezone());
2657
- $localtime = new DateTime('now', $timetz);
2658
- $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
2659
  $ga_dash_profile_list[] = array(
2660
  $profile->getName(),
2661
  $profile->getId(),
@@ -2665,7 +2926,7 @@ class MetaSeoAdmin
2665
  $profile->getTimezone(),
2666
  $profile->getDefaultPage()
2667
  );
2668
- $startindex++;
2669
  }
2670
  }
2671
  }
@@ -2690,7 +2951,7 @@ class MetaSeoAdmin
2690
  } catch (Google_Service_Exception $e) {
2691
  WpmsGaTools::setCache(
2692
  'last_error',
2693
- date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
2694
  $this->error_timeout
2695
  );
2696
  WpmsGaTools::setCache(
@@ -2711,27 +2972,37 @@ class MetaSeoAdmin
2711
 
2712
  /**
2713
  * Load the form for a WPSEO admin page
 
 
2714
  */
2715
  public function loadPage()
2716
  {
2717
  if (isset($_GET['page'])) {
 
2718
  switch ($_GET['page']) {
2719
  case 'metaseo_google_analytics':
2720
- $message_ublock = "<div class='error wpms_msg_ublock'><p>";
2721
- $message_ublock .= __('It seems that you use an adblocker, you need to
2722
  deactivate it for this page in order to load the Google Analytics scripts. ', 'wp-meta-seo');
2723
- $message_ublock .= "</p></div>";
2724
- echo $message_ublock;
2725
  $this->google_alanytics = get_option('wpms_google_alanytics');
2726
  if (isset($_POST['_metaseo_ggtracking_settings'])) {
 
 
 
 
2727
  update_option('_metaseo_ggtracking_settings', $_POST['_metaseo_ggtracking_settings']);
2728
  echo '<div id="setting-error-settings_updated"
2729
  class="updated settings-error notice is-dismissible">
2730
- <p><strong>' . __('Settings saved.', 'wp-meta-seo') . '</strong></p><button type="button" class="notice-dismiss">
2731
  <span class="screen-reader-text">Dismiss this notice.</span></button></div>';
2732
  }
2733
 
2734
  if (!empty($_POST['tableid_jail'])) {
 
 
 
 
2735
  $this->google_alanytics['tableid_jail'] = $_POST['tableid_jail'];
2736
  update_option('wpms_google_alanytics', $this->google_alanytics);
2737
  }
@@ -2744,15 +3015,17 @@ class MetaSeoAdmin
2744
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
2745
  wp_enqueue_style('m-style-qtip');
2746
  wp_enqueue_script('jquery-qtip');
2747
- if (isset($_GET['view']) && $_GET['view'] == 'wpmsga_trackcode') {
2748
  wp_enqueue_style('wpms-backend-tracking-code');
2749
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/ga-trackcode.php');
2750
  } else {
2751
  wp_enqueue_style('wpms-backend-item-reports');
2752
-
2753
-
2754
  if (isset($_POST['wpmsga_dash_clientid']) && isset($_POST['wpmsga_dash_clientsecret'])) {
2755
- $this->google_alanytics['wpmsga_dash_clientid'] = $_POST['wpmsga_dash_clientid'];
 
 
 
 
2756
  $this->google_alanytics['wpmsga_dash_clientsecret'] = $_POST['wpmsga_dash_clientsecret'];
2757
  update_option('wpms_google_alanytics', $this->google_alanytics);
2758
  }
@@ -2766,18 +3039,19 @@ class MetaSeoAdmin
2766
  $this->client->setApplicationName('WP Meta SEO');
2767
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
2768
  $this->setErrorTimeout();
2769
- $this->client = WpmsGaTools::setClient($this->client, $this->google_alanytics, $this->access);
2770
- $authUrl = $this->client->createAuthUrl();
2771
  $this->service = new Google_Service_Analytics($this->client);
2772
- $controller = new WpmsGapiController();
2773
 
2774
  if (!empty($_POST['wpms_ga_code'])) {
2775
- if (!stripos('x' . $_POST['wpms_ga_code'], 'UA-', 1) == 1) {
 
2776
  WpmsGaTools::deleteCache('gapi_errors');
2777
  WpmsGaTools::deleteCache('last_error');
2778
  WpmsGaTools::clearCache();
2779
  try {
2780
- $this->client->authenticate($_POST['wpms_ga_code']);
2781
  $getAccessToken = $this->client->getAccessToken();
2782
  if ($getAccessToken) {
2783
  try {
@@ -2793,7 +3067,7 @@ class MetaSeoAdmin
2793
  } catch (Google_Service_Exception $e) {
2794
  WpmsGaTools::setCache(
2795
  'wpmsga_dash_lasterror',
2796
- date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
2797
  $this->error_timeout
2798
  );
2799
  WpmsGaTools::setCache(
@@ -2816,18 +3090,21 @@ class MetaSeoAdmin
2816
  $profiles = $this->refreshProfiles();
2817
  }
2818
 
2819
- $this->google_alanytics['code'] = $_POST['wpms_ga_code'];
2820
  $this->google_alanytics['googleCredentials'] = $getAccessToken;
2821
- $this->google_alanytics['profile_list'] = $profiles;
2822
  update_option('wpms_google_alanytics', $this->google_alanytics);
2823
  } catch (Google_IO_Exception $e) {
 
2824
  } catch (Google_Service_Exception $e) {
 
2825
  } catch (Exception $e) {
 
2826
  }
2827
  } else {
2828
- echo "<div class='error'><p>" . __("The access code is
2829
  <strong>NOT</strong> your <strong>Tracking ID</strong>
2830
- (UA-XXXXX-X). Try again, and use the red link to get your access code", 'wp-meta-seo') . ".</p></div>";
2831
  }
2832
 
2833
  update_option('wpms_google_alanytics', $this->google_alanytics);
@@ -2835,19 +3112,20 @@ class MetaSeoAdmin
2835
  exit;
2836
  }
2837
  $this->gaDisconnect = array(
2838
- 'wpms_ga_uax_reference' => '',
2839
  'wpmsga_dash_tracking_type' => 'classic',
2840
- 'wpmsga_code_tracking' => ''
2841
  );
2842
- $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
2843
  if (is_array($gaDisconnect)) {
2844
  $this->gaDisconnect = array_merge(
2845
  $this->gaDisconnect,
2846
  $gaDisconnect
2847
  );
2848
  }
 
2849
  if (isset($_POST['_metaseo_ga_disconnect'])) {
2850
- $_metaseo_ga_disconnect = $_POST['_metaseo_ga_disconnect'];
2851
  $_metaseo_ga_disconnect['wpmsga_code_tracking'] = stripslashes($_metaseo_ga_disconnect['wpmsga_code_tracking']);
2852
  update_option(
2853
  '_metaseo_ggtracking_disconnect_settings',
@@ -2865,28 +3143,26 @@ class MetaSeoAdmin
2865
  $this->google_alanytics = get_option('wpms_google_alanytics');
2866
  if (!empty($this->google_alanytics['googleCredentials'])) {
2867
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
2868
- $message = "<div class='error'><p>" . __("The tracking component is
2869
  disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
2870
- ", 'wp-meta-seo') . ".</p></div>";
2871
- echo $message;
2872
  }
2873
  echo '<div class="wrap wpmsga_wrap">';
2874
  echo '<div>';
2875
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
2876
- echo '<h2>' . __("Google Analytics Settings", "wp-meta-seo") . '</h2>';
2877
  echo '<div id="wpms-window-1"></div>';
2878
  echo '</div>';
2879
  echo '</div>';
2880
  } else {
2881
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
2882
- $message = "<div class='error'><p>" . __("The tracking component is disabled.
2883
  You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
2884
- ", 'wp-meta-seo') . ".</p></div>";
2885
- echo $message;
2886
  }
2887
 
2888
  if (isset($this->google_alanytics['wpmsga_dash_userapi'])
2889
- && $this->google_alanytics['wpmsga_dash_userapi'] == 1) {
2890
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/form-connect.php');
2891
  } else {
2892
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/google-analytics.php');
@@ -2894,8 +3170,8 @@ class MetaSeoAdmin
2894
  }
2895
  }
2896
 
2897
- $w = '99%';
2898
- $text = __('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report,
2899
  Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo');
2900
  $class_btn_close = 'close_gga';
2901
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
@@ -2927,20 +3203,20 @@ class MetaSeoAdmin
2927
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php');
2928
  break;
2929
  case 'metaseo_settings':
2930
- $posts = get_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'numberposts' => -1));
2931
  $types_404 = array(
2932
- 'none' => 'None',
2933
- 'wp-meta-seo-page' => __('WP Meta SEO page', 'wp-meta-seo'),
2934
- 'custom_page' => __('Custom page', 'wp-meta-seo')
2935
  );
2936
 
2937
  // get settings 404
2938
  $defaul_settings_404 = array(
2939
  'wpms_redirect_homepage' => 0,
2940
- 'wpms_type_404' => 'none',
2941
- 'wpms_page_redirected' => 'none'
2942
  );
2943
- $wpms_settings_404 = get_option('wpms_settings_404');
2944
  if (is_array($wpms_settings_404)) {
2945
  $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404);
2946
  }
@@ -2950,12 +3226,12 @@ class MetaSeoAdmin
2950
  if (empty($home_title)) {
2951
  $home_title = get_bloginfo('title');
2952
  }
2953
- $breadcrumbs = array(
2954
- 'separator' => ' &gt; ',
2955
- 'include_home' => 1,
2956
- 'home_text' => $home_title,
2957
  'home_text_default' => 0,
2958
- 'clickable' => 1
2959
  );
2960
  $breadcrumb_settings = get_option('_metaseo_breadcrumbs');
2961
  if (is_array($breadcrumb_settings)) {
@@ -2964,13 +3240,13 @@ class MetaSeoAdmin
2964
 
2965
  // email settings
2966
  $email_settings = array(
2967
- "enable" => 0,
2968
- "host" => "smtp.gmail.com",
2969
- "type_encryption" => "ssl",
2970
- "port" => "465",
2971
- "autentication" => "yes",
2972
- "username" => "",
2973
- "password" => "",
2974
  );
2975
 
2976
  $mailsettings = get_option('wpms_email_settings');
@@ -2982,9 +3258,9 @@ class MetaSeoAdmin
2982
 
2983
  // link settings
2984
  $link_settings = array(
2985
- "enable" => 0,
2986
- "numberFrequency" => 1,
2987
- "showlinkFrequency" => "month"
2988
  );
2989
 
2990
  $linksettings = get_option('wpms_link_settings');
@@ -2996,22 +3272,22 @@ class MetaSeoAdmin
2996
 
2997
  // local business settings
2998
  $local_business = array(
2999
- "enable" => 0,
3000
- "logo" => "",
3001
- "type_name" => "",
3002
- "country" => "",
3003
- "address" => "",
3004
- "city" => "",
3005
- "state" => "",
3006
- "phone" => "",
3007
- "pricerange" => "$$"
3008
  );
3009
 
3010
  $business = get_option('wpms_local_business');
3011
  if (is_array($business)) {
3012
  $local_business = array_merge($local_business, $business);
3013
  }
3014
- $countrys = apply_filters('wpms_get_countryList', array());
3015
  $local_business_html = apply_filters('wpmsaddon_local_business', '', $local_business, $countrys);
3016
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php');
3017
  break;
@@ -3043,24 +3319,33 @@ class MetaSeoAdmin
3043
 
3044
  /**
3045
  * Ajax check attachment have alt empty
 
 
3046
  */
3047
  public function checkExist()
3048
  {
 
 
 
 
 
3049
  if (isset($_POST['type'])) {
3050
- if ($_POST['type'] == 'alt') {
3051
  $margs = array(
3052
- 'posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'any',
3053
- 'meta_query' => array(
 
 
3054
  'relation' => 'OR',
3055
  array(
3056
- 'key' => '_wp_attachment_image_alt',
3057
- 'value' => '',
3058
  'compare' => '!='
3059
- ),
3060
  )
3061
  );
3062
 
3063
- $m_newquery = new WP_Query($margs);
3064
  $mposts_empty_alt = $m_newquery->get_posts();
3065
  if (!empty($mposts_empty_alt)) {
3066
  wp_send_json(true);
@@ -3069,12 +3354,8 @@ class MetaSeoAdmin
3069
  }
3070
  } else {
3071
  global $wpdb;
3072
- $sql = $wpdb->prepare(
3073
- "SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts
3074
- WHERE posts.post_type = %s AND post_title != %s",
3075
- array('attachment', '')
3076
- );
3077
- $check_title = $wpdb->get_var($sql);
3078
  if ($check_title > 0) {
3079
  wp_send_json(true);
3080
  } else {
@@ -3086,31 +3367,33 @@ class MetaSeoAdmin
3086
 
3087
  /**
3088
  * Ajax update image alt and image title
 
 
3089
  */
3090
  public function bulkImageCopy()
3091
  {
 
 
 
 
 
3092
  global $wpdb;
3093
  if (empty($_POST['mtype'])) {
3094
  wp_send_json(false);
3095
  }
3096
 
3097
- if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') {
3098
  // select all
3099
  $limit = 500;
3100
  // query attachment and update meta
3101
- $sql = $wpdb->prepare(
3102
- "SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts
3103
- WHERE posts.post_type = %s",
3104
- array('attachment')
3105
- );
3106
- $total = $wpdb->get_var($sql);
3107
 
3108
- $j = ceil((int)$total / $limit);
3109
- for ($i = 0; $i <= $j; $i++) {
3110
- $ofset = $i * $limit;
3111
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts as posts
3112
- WHERE posts.post_type = %s LIMIT %d OFFSET %d", array('attachment', $limit, $ofset));
3113
- $attachments = $wpdb->get_results($sql);
3114
 
3115
  foreach ($attachments as $attachment) {
3116
  $i_info_url = pathinfo($attachment->guid);
@@ -3130,23 +3413,20 @@ class MetaSeoAdmin
3130
  } else {
3131
  // selected
3132
  if (isset($_POST['ids'])) {
3133
- $ids = $_POST['ids'];
3134
  $margs = array(
3135
- 'posts_per_page' => -1,
3136
- 'post_type' => 'attachment',
3137
- 'post_status' => 'any',
3138
- 'post__in' => $ids
3139
  );
3140
 
3141
- $query = "SELECT *
3142
- FROM $wpdb->posts
3143
- WHERE `post_type` = 'attachment'
3144
- AND `post_mime_type` LIKE '%image%' AND `ID` IN (" . implode(',', esc_sql($ids)) . ")
3145
- ";
3146
-
3147
- $m_newquery = new WP_Query($margs);
3148
- $mposts_empty_alt = $m_newquery->get_posts();
3149
- $mposts_empty_title = $wpdb->get_results($query);
3150
  switch ($_POST['mtype']) {
3151
  case 'image_alt':
3152
  if (!empty($mposts_empty_alt)) {
@@ -3179,17 +3459,24 @@ class MetaSeoAdmin
3179
 
3180
  /**
3181
  * Ajax bulk update meta title for a post/page
 
 
3182
  */
3183
  public function bulkPostCopyTitle()
3184
  {
 
 
 
 
 
3185
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
3186
  unset($post_types['attachment']);
3187
  $margs = array();
3188
- if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') { // for select a;;
3189
  $margs = array(
3190
- 'posts_per_page' => -1,
3191
- 'post_type' => $post_types,
3192
- 'post_status' => array(
3193
  'publish',
3194
  'pending',
3195
  'draft',
@@ -3199,25 +3486,26 @@ class MetaSeoAdmin
3199
  'inherit',
3200
  'trash'
3201
  ),
3202
- 'meta_query' => array(
3203
  'relation' => 'OR',
3204
  array(
3205
- 'key' => '_metaseo_metatitle',
3206
  'compare' => 'NOT EXISTS',
3207
  ),
3208
  array(
3209
- 'key' => '_metaseo_metatitle',
3210
  'value' => false,
3211
- 'type' => 'BOOLEAN'
3212
  ),
3213
- ));
 
3214
  } else { // for select some post
3215
  if (isset($_POST['ids'])) {
3216
- $ids = $_POST['ids'];
3217
  $margs = array(
3218
- 'posts_per_page' => -1,
3219
- 'post_type' => $post_types,
3220
- 'post_status' => array(
3221
  'publish',
3222
  'pending',
3223
  'draft',
@@ -3227,26 +3515,27 @@ class MetaSeoAdmin
3227
  'inherit',
3228
  'trash'
3229
  ),
3230
- 'post__in' => $ids,
3231
- 'meta_query' => array(
3232
  'relation' => 'OR',
3233
  array(
3234
- 'key' => '_metaseo_metatitle',
3235
  'compare' => 'NOT EXISTS',
3236
  ),
3237
  array(
3238
- 'key' => '_metaseo_metatitle',
3239
  'value' => false,
3240
- 'type' => 'BOOLEAN'
3241
  ),
3242
- ));
 
3243
  } else {
3244
  wp_send_json(false);
3245
  }
3246
  }
3247
 
3248
  $m_newquery = new WP_Query($margs);
3249
- $mposts = $m_newquery->get_posts();
3250
  if (!empty($mposts)) {
3251
  foreach ($mposts as $post) {
3252
  update_post_meta($post->ID, '_metaseo_metatitle', $post->post_title);
@@ -3258,12 +3547,19 @@ class MetaSeoAdmin
3258
  }
3259
 
3260
  /**
3261
- * set cookie notification
 
 
3262
  */
3263
  public function setcookieNotification()
3264
  {
 
 
 
 
 
3265
  if (isset($_POST['page'])) {
3266
- setcookie($_POST['page'], time(), time() + (86400 * 30), "/");
3267
  wp_send_json(true);
3268
  }
3269
  wp_send_json(false);
@@ -3271,9 +3567,15 @@ class MetaSeoAdmin
3271
 
3272
  /**
3273
  * Run ajax
 
 
3274
  */
3275
  public function startProcess()
3276
  {
 
 
 
 
3277
  if (isset($_REQUEST['task'])) {
3278
  switch ($_REQUEST['task']) {
3279
  case 'updateContentMeta':
11
 
12
  /**
13
  * Current page
14
+ *
15
  * @var mixed
16
  */
17
  private $pagenow;
18
  /**
19
+ * Max length meta description
20
+ *
21
+ * @var integer
22
  */
23
  public static $desc_length = 320;
24
  /**
25
+ * Max length meta title
26
+ *
27
+ * @var integer
28
  */
29
  public static $title_length = 69;
30
  /**
31
  * Google client
32
+ *
33
+ * @var object
34
  */
35
  public $client;
36
  /**
37
  * Default access to connect to google
38
+ *
39
  * @var array
40
  */
41
  public $access = array(WPMS_CLIENTID, WPMS_CLIENTSECRET);
42
  /**
43
+ * Error timeout
44
+ *
45
+ * @var integer
46
  */
47
  public $error_timeout;
48
  /**
49
  * List google analytics options
50
+ *
51
  * @var array
52
  */
53
  public $ga_tracking;
54
  /**
55
+ * Option to check connect status
56
+ *
57
+ * @var array
58
  */
59
  public $gaDisconnect;
60
  /**
61
+ * Google alanytics options
62
+ *
63
+ * @var array
64
  */
65
  public $google_alanytics;
66
 
67
  /**
68
  * All settings for meta seo
69
+ *
70
  * @var array
71
  */
72
  public $settings;
73
 
74
  /**
75
  * Google service
76
+ *
77
+ * @var object
78
  */
79
  public $service;
80
 
95
  add_action('init', array($this, 'loadLangguage'));
96
  add_action('admin_menu', array($this, 'addMenuPage'));
97
 
98
+ /**
99
+ * Load admin js
100
+ */
101
  add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts'));
102
  add_action('added_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4);
103
  add_action('updated_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4);
107
  }
108
 
109
  add_action('wp_ajax_wpms_set_ignore', array($this, 'setIgnore'));
110
+ if (0 === (int) get_option('blog_public')) {
111
  add_action('admin_notices', array($this, 'publicWarning'));
112
  }
113
  add_action('wp_enqueue_editor', array($this, 'linkTitleField'), 20);
136
 
137
  /**
138
  * Init Meta seo settings
139
+ *
140
+ * @return void
141
  */
142
  public function initSettings()
143
  {
144
  $this->settings = array(
145
+ 'metaseo_title_home' => '',
146
+ 'metaseo_desc_home' => '',
147
+ 'metaseo_showfacebook' => '',
148
+ 'metaseo_showfbappid' => '',
149
+ 'metaseo_showtwitter' => '',
150
+ 'metaseo_twitter_card' => 'summary',
151
+ 'metaseo_showkeywords' => 0,
152
+ 'metaseo_showtmetablock' => 1,
153
+ 'metaseo_showsocial' => 1,
154
+ 'metaseo_seovalidate' => 0,
155
+ 'metaseo_linkfield' => 1,
156
+ 'metaseo_metatitle_tab' => 0,
157
+ 'metaseo_follow' => 0,
158
+ 'metaseo_index' => 0,
159
+ 'metaseo_overridemeta' => 1
160
  );
161
+ $settings = get_option('_metaseo_settings');
162
 
163
  if (is_array($settings)) {
164
  $this->settings = array_merge($this->settings, $settings);
165
  }
166
 
167
+ if ((isset($this->settings['metaseo_showtmetablock']) && (int) $this->settings['metaseo_showtmetablock'] === 1)) {
168
  $this->loadMetaBoxes();
169
  }
170
  }
171
 
172
  /**
173
  * Init google analytics tracking options
174
+ *
175
+ * @return void
176
  */
177
  public function initGaSettings()
178
  {
179
  $this->ga_tracking = array(
180
+ 'wpmsga_dash_tracking' => 1,
181
+ 'wpmsga_dash_tracking_type' => 'universal',
182
+ 'wpmsga_dash_anonim' => 0,
183
+ 'wpmsga_dash_remarketing' => 0,
184
+ 'wpmsga_event_tracking' => 0,
185
+ 'wpmsga_event_downloads' => 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*',
186
+ 'wpmsga_aff_tracking' => 0,
187
+ 'wpmsga_event_affiliates' => '/out/',
188
+ 'wpmsga_hash_tracking' => 0,
189
+ 'wpmsga_author_dimindex' => 0,
190
+ 'wpmsga_pubyear_dimindex' => 0,
191
+ 'wpmsga_category_dimindex' => 0,
192
+ 'wpmsga_user_dimindex' => 0,
193
+ 'wpmsga_tag_dimindex' => 0,
194
+ 'wpmsga_speed_samplerate' => 1,
195
+ 'wpmsga_event_bouncerate' => 0,
196
+ 'wpmsga_enhanced_links' => 0,
197
+ 'wpmsga_dash_adsense' => 0,
198
  'wpmsga_crossdomain_tracking' => 0,
199
+ 'wpmsga_crossdomain_list' => '',
200
+ 'wpmsga_cookiedomain' => '',
201
+ 'wpmsga_cookiename' => '',
202
+ 'wpmsga_cookieexpires' => '',
203
+ 'wpmsga_track_exclude' => array(),
204
+ 'wpmsga_code_tracking' => ''
205
  );
206
  }
207
 
208
  /**
209
  * Admin init
210
+ *
211
+ * @return void
212
  */
213
  public function adminInit()
214
  {
215
  $this->fieldSettings();
216
  $this->createDatabase();
217
+ $this->updateLinksTable();
218
  }
219
 
220
  /**
221
+ * Add category meta field
222
+ *
223
+ * @return void
224
  */
225
  public function categoryField()
226
  {
244
  ?>
245
  <div class="form-field">
246
  <label class="wpms_custom_cat_field"
247
+ data-alt="<?php esc_attr_e('This is the title of your content that may be displayed in search engine
248
  results (meta title). By default it’s the content title (page title, post title…).
249
  69 characters max allowed.', 'wp-meta-seo') ?>">
250
+ <?php esc_html_e('Search engine title', 'wp-meta-seo'); ?>
251
  </label>
252
  <label>
253
  <textarea name="wpms_category_metatitle" class="wpms_category_metatitle"></textarea>
254
  <br/>
255
  </label>
256
+ <div class="cat-title-len"><?php echo esc_html(MPMSCAT_TITLE_LENGTH); ?></div>
257
  </div>
258
 
259
  <?php
260
  $settings = get_option('_metaseo_settings');
261
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) :
262
  ?>
263
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
264
  <label class="wpms_custom_cat_field"
265
+ data-alt="<?php esc_attr_e('This is the keywords of your content that may be
266
  displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>">
267
+ <?php esc_html_e('Search engine keywords', 'wp-meta-seo'); ?>
268
  </label>
269
  <label>
270
  <textarea name="wpms_category_metakeywords" class="wpms_cat_keywords"></textarea><br/>
271
  </label>
272
+ <div class="cat-keywords-len"><?php echo esc_html(MPMSCAT_KEYWORDS_LENGTH); ?></div>
273
  </div>
274
  <?php endif; ?>
275
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
276
  <label for="extra1" class="wpms_custom_cat_field"
277
+ data-alt="<?php esc_attr_e('This is the title of your content that may be displayed in search
278
  engine results (meta title). By default it’s the content title (page title, post title…).
279
  69 characters max allowed.', 'wp-meta-seo') ?>">
280
+ <?php esc_html_e('Search engine description', 'wp-meta-seo'); ?>
281
  </label>
282
  <label>
283
  <textarea name="wpms_category_metadesc" class="wpms_category_metadesc"></textarea><br/>
284
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
285
  </label>
286
+ <div class="cat-desc-len"><?php echo esc_html(MPMSCAT_DESC_LENGTH); ?></div>
287
  </div>
288
  <?php
289
  }
290
 
291
  /**
292
  * Save category meta
293
+ *
294
+ * @param integer $term_id Current category id
295
+ *
296
+ * @return void
297
  */
298
  public function saveCategoryMeta($term_id)
299
  {
300
+ global $pagenow;
301
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce used in next lines
302
+ if ($pagenow === 'edit-tags.php' || (isset($_POST['action'], $_POST['screen']) && $_POST['action'] === 'add-tag' && $_POST['screen'] === 'edit-category')) {
303
+ if (empty($_POST['wpms_nonce'])
304
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
305
+ die();
306
+ }
307
 
308
+ if (isset($_POST['wpms_category_metatitle'])) {
309
+ update_term_meta($term_id, 'wpms_category_metatitle', $_POST['wpms_category_metatitle']);
310
+ }
311
 
312
+ if (isset($_POST['wpms_category_metadesc'])) {
313
+ update_term_meta($term_id, 'wpms_category_metadesc', $_POST['wpms_category_metadesc']);
314
+ }
315
+
316
+ $settings = get_option('_metaseo_settings');
317
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
318
+ if (isset($_POST['wpms_category_metakeywords'])) {
319
+ update_term_meta($term_id, 'wpms_category_metakeywords', $_POST['wpms_category_metakeywords']);
320
+ }
321
  }
322
  }
323
  }
324
 
325
  /**
326
+ * Add extra fields to category edit form callback function
327
+ *
328
+ * @param object $tag Current category
329
+ *
330
+ * @return void
331
  */
332
  public function editCategoryFields($tag)
333
  {
347
 
348
  wp_enqueue_style('wpms-category-field');
349
  wp_enqueue_script('wpms-category-field');
350
+ $t_id = $tag->term_id;
351
+ $metatitle = get_term_meta($t_id, 'wpms_category_metatitle', true);
352
+ $metadesc = get_term_meta($t_id, 'wpms_category_metadesc', true);
353
  $metakeywords = get_term_meta($t_id, 'wpms_category_metakeywords', true);
354
  ?>
355
  <tr class="form-field">
356
  <th scope="row" valign="top">
357
+ <label class="wpms_custom_cat_field" data-alt="<?php esc_attr_e('This is the title of your content that may
358
  be displayed in search engine results (meta title). By default it’s the content title
359
  (page title, post title…).69 characters max allowed.', 'wp-meta-seo') ?>">
360
+ <?php esc_html_e('Search engine title', 'wp-meta-seo'); ?>
361
  </label>
362
  </th>
363
  <td>
364
  <label>
365
  <?php if ((!empty($metatitle))) : ?>
366
  <textarea name="wpms_category_metatitle"
367
+ class="wpms_category_metatitle"><?php echo esc_textarea($metatitle); ?></textarea>
368
  <?php else : ?>
369
  <textarea name="wpms_category_metatitle"
370
  class="wpms_category_metatitle"></textarea>
373
  </label>
374
  <div class="cat-title-len">
375
  <?php
376
+ echo esc_html($metatitle ? MPMSCAT_TITLE_LENGTH - strlen($metatitle) : MPMSCAT_TITLE_LENGTH);
377
  ?>
378
  </div>
379
  </td>
381
 
382
  <?php
383
  $settings = get_option('_metaseo_settings');
384
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) :
385
  ?>
386
  <tr class="form-field">
387
  <th scope="row" valign="top">
388
  <label for="extra1" class="wpms_custom_cat_field"
389
+ data-alt="<?php esc_attr_e('This is the keywords of your content that may be
390
  displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>">
391
+ <?php esc_html_e('Search engine keywords', 'wp-meta-seo'); ?>
392
  </label>
393
  </th>
394
  <td>
395
  <label>
396
  <?php if ((!empty($metakeywords))) : ?>
397
  <textarea name="wpms_category_metakeywords"
398
+ class="wpms_cat_keywords"><?php echo esc_textarea($metakeywords); ?></textarea>
399
  <?php else : ?>
400
  <textarea name="wpms_category_metakeywords"
401
  class="wpms_cat_keywords"></textarea>
405
 
406
  <div class="cat-keywords-len">
407
  <?php
408
+ echo esc_html($metakeywords ? MPMSCAT_KEYWORDS_LENGTH - strlen($metakeywords) : MPMSCAT_KEYWORDS_LENGTH);
409
  ?>
410
  </div>
411
  </td>
414
  <tr class="form-field">
415
  <th scope="row" valign="top">
416
  <label for="extra1" class="wpms_custom_cat_field"
417
+ data-alt="<?php esc_attr_e('This is the title of your content that may be displayed in
418
  search engine results (meta title). By default it’s the content title (page title, post title…).
419
  69 characters max allowed.', 'wp-meta-seo') ?>">
420
+ <?php esc_html_e('Search engine description', 'wp-meta-seo'); ?>
421
  </label>
422
  </th>
423
  <td>
424
  <label>
425
  <?php if ((!empty($metadesc))) : ?>
426
  <textarea name="wpms_category_metadesc"
427
+ class="wpms_category_metadesc"><?php echo esc_textarea($metadesc); ?></textarea>
428
  <?php else : ?>
429
  <textarea name="wpms_category_metadesc"
430
  class="wpms_category_metadesc"></textarea>
431
  <?php endif; ?>
432
  <br/>
433
  </label>
434
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
435
  <div class="cat-desc-len">
436
+ <?php echo esc_html($metadesc ? MPMSCAT_DESC_LENGTH - strlen($metadesc) : MPMSCAT_DESC_LENGTH); ?>
437
  </div>
438
  </td>
439
  </tr>
442
 
443
  /**
444
  * Function that outputs the contents of the dashboard widget
445
+ *
446
+ * @return void
447
  */
448
  public function dashboardWidget()
449
  {
474
 
475
  /**
476
  * Function used in the action hook
477
+ *
478
+ * @return void
479
  */
480
  public function addDashboardWidgets()
481
  {
 
482
  wp_add_dashboard_widget(
483
  'wpms_dashboard_widget',
484
+ esc_html__('WP Meta SEO: Quick SEO preview', 'wp-meta-seo'),
485
  array(
486
  $this,
487
  'dashboardWidget'
491
 
492
  /**
493
  * Create link dialog
494
+ *
495
+ * @return void
496
  */
497
  public function editorFooter()
498
  {
499
  if (!class_exists('_WP_Editors', false)) {
500
+ require_once ABSPATH . 'wp-includes/class-wp-editor.php';
501
  _WP_Editors::wp_link_dialog();
502
  }
503
  }
504
 
505
+ /**
506
+ * Create or update 404 page
507
+ *
508
+ * @param string $title Old page title
509
+ * @param string $newtitle New page title
510
+ *
511
+ * @return void
512
+ */
513
+ public function create404Page($title, $newtitle)
514
+ {
515
+ global $wpdb;
516
+ $post_if = $wpdb->get_results($wpdb->prepare(
517
+ 'SELECT * FROM ' . $wpdb->prefix . 'posts
518
+ WHERE post_title = %s AND post_excerpt = %s AND post_type = %s',
519
+ array($title, 'metaseo_404_page', 'page')
520
+ ));
521
+
522
+ if (empty($post_if)) {
523
+ $content = '<div class="wall"
524
+ style="background-color: #F2F3F7; border: 30px solid #fff; width: 90%; height: 90%; margin: 0 auto;">
525
+
526
+ <h1 style="text-align: center; font-family:\'open-sans\', arial;
527
+ color: #444; font-size: 60px; padding: 50px;">ERROR 404 <br />-<br />NOT FOUND</h1>
528
+ <p style="text-align: center; font-family:\'open-sans\', arial; color: #444;
529
+ font-size: 40px; padding: 20px; line-height: 55px;">
530
+ // You may have mis-typed the URL,<br />
531
+ // Or the page has been removed,<br />
532
+ // Actually, there is nothing to see here...</p>
533
+ <p style="text-align: center;"><a style=" font-family:\'open-sans\', arial; color: #444;
534
+ font-size: 20px; padding: 20px; line-height: 30px; text-decoration: none;"
535
+ href="' . get_home_url() . '"><< Go back to home page >></a></p>
536
+ </div>';
537
+ $_page404 = array(
538
+ 'post_title' => $newtitle,
539
+ 'post_content' => $content,
540
+ 'post_status' => 'publish',
541
+ 'post_excerpt' => 'metaseo_404_page',
542
+ 'post_type' => 'page'
543
+ );
544
+ wp_insert_post($_page404);
545
+ } else {
546
+ $my_post = array(
547
+ 'ID' => $post_if[0]->ID,
548
+ 'post_title' => $newtitle
549
+ );
550
+
551
+ wp_update_post($my_post);
552
+ }
553
+ }
554
+
555
+ /**
556
+ * Update links table
557
+ *
558
+ * @return void
559
+ */
560
+ public function updateLinksTable()
561
+ {
562
+ global $wpdb;
563
+ $option_v = 'metaseo_db_version3.7.2';
564
+ $db_installed = get_option($option_v, false);
565
+ if (!$db_installed) {
566
+ $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links MODIFY `link_url` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL');
567
+ update_option($option_v, true);
568
+ }
569
+ }
570
+
571
  /**
572
  * Create wpms_links table
573
+ *
574
+ * @return void
575
  */
576
  public function createDatabase()
577
  {
578
  global $wpdb;
579
+ $option_v = 'metaseo_db_version3.3.0';
580
  $db_installed = get_option($option_v, false);
581
  if (!$db_installed) {
582
  // create table wpms_links
583
+ $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'wpms_links(
584
  `id` int(20) unsigned NOT NULL AUTO_INCREMENT,
585
  `link_url` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
586
  `link_final_url` text CHARACTER SET latin1 COLLATE latin1_general_cs,
587
  `link_url_redirect` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,
588
+ `link_text` text NOT NULL DEFAULT "",
589
+ `source_id` int(20) DEFAULT "0",
590
+ `type` varchar(100) DEFAULT "",
591
+ `status_code` varchar(100) DEFAULT "",
592
+ `status_text` varchar(250) DEFAULT "",
593
+ `hit` int(20) NOT NULL DEFAULT "1",
594
+ `redirect` tinyint(1) NOT NULL DEFAULT "0",
595
+ `broken_indexed` tinyint(1) unsigned NOT NULL DEFAULT "0",
596
+ `broken_internal` tinyint(1) unsigned NOT NULL DEFAULT "0",
597
+ `warning` tinyint(1) unsigned NOT NULL DEFAULT "0",
598
+ `dismissed` tinyint(1) NOT NULL DEFAULT "0",
599
+ PRIMARY KEY (id))';
600
 
601
 
602
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
603
  dbDelta($sql);
604
 
605
+ $row = $wpdb->get_results($wpdb->prepare(
606
+ 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
607
+ WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s',
 
608
  array($wpdb->prefix . 'wpms_links', 'follow', $wpdb->dbname)
609
+ ));
 
610
 
611
  if (empty($row)) {
612
+ $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD follow tinyint(1) DEFAULT 1');
613
  }
614
 
615
+ $row = $wpdb->get_results($wpdb->prepare(
616
+ 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
617
+ WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s',
618
  array($wpdb->prefix . 'wpms_links', 'meta_title', $wpdb->dbname)
619
+ ));
 
620
 
621
  if (empty($row)) {
622
+ $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD meta_title varchar(250) DEFAULT ""');
623
  }
624
 
625
+ $row = $wpdb->get_results($wpdb->prepare(
626
+ 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
627
+ WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s',
628
  array($wpdb->prefix . 'wpms_links', 'internal', $wpdb->dbname)
629
+ ));
 
630
 
631
  if (empty($row)) {
632
+ $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD internal tinyint(1) DEFAULT 1');
633
  }
634
 
635
  // create page 404
636
+ $this->create404Page('WP Meta SEO 404 Page', '404 error page');
637
+ // create sitemap page
638
+ $post_if = $wpdb->get_var(
639
+ $wpdb->prepare('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts
640
+ WHERE post_title = %s AND post_excerpt = %s AND post_type = %s', array(
641
+ 'WPMS HTML Sitemap',
642
+ 'metaseo_html_sitemap',
643
+ 'page'
644
+ ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  );
 
646
  if ($post_if < 1) {
647
  $_sitemap_page = array(
648
+ 'post_title' => 'WPMS HTML Sitemap',
649
  'post_content' => '',
650
+ 'post_status' => 'publish',
651
  'post_excerpt' => 'metaseo_html_sitemap',
652
+ 'post_type' => 'page',
653
  );
654
  wp_insert_post($_sitemap_page);
655
  }
656
 
657
  update_option($option_v, true);
658
  }
659
+
660
+
661
+ $option_v = 'metaseo_db_version3.7.3';
662
+ $db_installed = get_option($option_v, false);
663
+ if (!$db_installed) {
664
+ // create page 404
665
+ $this->create404Page('404 error page', '404 Error, content does not exist anymore');
666
+ update_option($option_v, true);
667
+ }
668
  }
669
 
670
  /**
671
  * Add field title in dialog link when edit a link
672
+ *
673
+ * @return void
674
  */
675
  public function linkTitleField()
676
  {
677
+ if (isset($this->settings['metaseo_linkfield']) && (int) $this->settings['metaseo_linkfield'] === 1) {
678
  wp_enqueue_script(
679
  'wpmslinkTitle',
680
  plugins_url('js/wpms-link-title-field.js', dirname(__FILE__)),
683
  true
684
  );
685
  wp_localize_script('wpmslinkTitle', 'wpmsLinkTitleL10n', array(
686
+ 'titleLabel' => esc_html__('Title', 'wp-meta-seo'),
687
  ));
688
  }
689
  }
690
 
691
  /**
692
  * Update option wpms_set_ignore
693
+ *
694
+ * @return void
695
  */
696
  public function setIgnore()
697
  {
704
 
705
  /**
706
  * Render message error when disable search engines from indexing this site
707
+ *
708
+ * @return void
709
  */
710
  public function publicWarning()
711
  {
713
  return;
714
  }
715
 
716
+ if ((int) get_option('wpms_set_ignore') === 0) {
717
  return;
718
  }
719
 
726
  class="button">%4$s</a>
727
  </p>
728
  </div>',
729
+ esc_html__('Your website is not indexed by search engine because of your WordPress settings.', 'wp-meta-seo'),
730
  sprintf(
731
+ esc_html__('%1$sFix it now%2$s', 'wp-meta-seo'),
732
  sprintf('<a href="%s">', esc_url(admin_url('options-reading.php'))),
733
  '</a>'
734
  ),
735
  esc_js(wp_create_nonce('wpseo-ignore')),
736
+ esc_html__('OK I know that.', 'wp-meta-seo')
737
  );
738
  }
739
 
740
  /**
741
  * Loads translated strings.
742
+ *
743
+ * @return void
744
  */
745
  public function loadLangguage()
746
  {
752
  }
753
 
754
  /**
755
+ * Create field analysis
756
+ *
757
+ * @param string $data_title Title
758
+ * @param string $alt Alt text
759
+ * @param string $dashicon Type
760
+ * @param string $label Label
761
+ * @param string $value_hidden Value
762
+ *
763
  * @return string
764
  */
765
  public function createFieldAnalysis($data_title, $alt, $dashicon, $label, $value_hidden)
766
  {
767
+ $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . esc_attr($data_title) . '" data-alt="' . esc_attr($alt) . '">';
768
+ if ($dashicon === 'done') {
769
  $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxdone">done</i>';
770
  } else {
771
  $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxwarning">warning</i>';
772
  }
773
 
774
+ $output .= esc_html($label);
775
  $output .= '</div>';
776
  $output .= '<input type="hidden" class="wpms_analysis_hidden"
777
+ name="' . esc_attr('wpms[' . $data_title . ']') . '" value="' . esc_attr($value_hidden) . '">';
778
  return $output;
779
  }
780
 
781
  /**
782
  * Ajax load page analysis
783
+ *
784
+ * @return void
785
  */
786
  public function reloadAnalysis()
787
  {
788
+ if (empty($_POST['wpms_nonce'])
789
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
790
+ die();
791
+ }
792
+
793
+ if (!current_user_can('edit_posts')) {
794
  wp_send_json(array('status' => false));
795
  }
796
+ $tooltip_page = array();
797
+ $tooltip_page['title_in_heading'] = esc_attr__('Check if a word of this content title
798
  is also in a title heading (h1, h2...)', 'wp-meta-seo');
799
+ $tooltip_page['title_in_content'] = esc_attr__('Check if a word of this content
800
  title is also in the text', 'wp-meta-seo');
801
+ $tooltip_page['page_url'] = esc_attr__('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
802
+ $tooltip_page['meta_title'] = esc_attr__('Is the meta title of this page filled?', 'wp-meta-seo');
803
+ $tooltip_page['meta_desc'] = esc_attr__('Is the meta description of this page filled?', 'wp-meta-seo');
804
+ $tooltip_page['image_resize'] = esc_attr__('Check for image HTML resizing in content
805
  (usually image resized using handles)', 'wp-meta-seo');
806
+ $tooltip_page['image_alt'] = esc_attr__('Check for image Alt text and title', 'wp-meta-seo');
807
  if (empty($_POST['datas'])) {
808
  wp_send_json(false);
809
  }
812
  update_post_meta($_POST['datas']['post_id'], 'wpms_validate_analysis', '');
813
  }
814
 
815
+ $meta_analysis = get_post_meta((int) $_POST['datas']['post_id'], 'wpms_validate_analysis', true);
816
+ $check = 0;
817
+ $output = '';
818
 
819
  // title heading
820
  $words_post_title = preg_split(
821
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
822
  strtolower($_POST['datas']['title']),
823
+ - 1,
824
  PREG_SPLIT_NO_EMPTY
825
  );
826
 
839
  'heading_title',
840
  $tooltip_page['title_in_heading'],
841
  'done',
842
+ esc_html__('Page title word in content heading', 'wp-meta-seo'),
843
  1
844
  );
845
+ $check ++;
846
  } else {
847
+ if ($content === '') {
848
  $output .= $this->createFieldAnalysis(
849
  'heading_title',
850
  $tooltip_page['title_in_heading'],
851
  'warning',
852
+ esc_html__('Page title word in content heading', 'wp-meta-seo'),
853
  0
854
  );
855
  } else {
875
  $words_tagh1 = preg_split(
876
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
877
  utf8_decode(strtolower($tagh1->nodeValue)),
878
+ - 1,
879
  PREG_SPLIT_NO_EMPTY
880
  );
881
  if (is_array($words_tagh1) && is_array($words_post_title)) {
882
  foreach ($words_tagh1 as $mh) {
883
+ if (in_array($mh, $words_post_title) && $mh !== '') {
884
  $test = true;
885
  }
886
  }
894
  $words_tagh2 = preg_split(
895
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
896
  utf8_decode(strtolower($tagh2->nodeValue)),
897
+ - 1,
898
  PREG_SPLIT_NO_EMPTY
899
  );
900
  if (is_array($words_tagh2) && is_array($words_post_title)) {
901
  foreach ($words_tagh2 as $mh) {
902
+ if (in_array($mh, $words_post_title) && $mh !== '') {
903
  $test = true;
904
  }
905
  }
913
  $words_tagh3 = preg_split(
914
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
915
  utf8_decode(strtolower($tagh3->nodeValue)),
916
+ - 1,
917
  PREG_SPLIT_NO_EMPTY
918
  );
919
  if (is_array($words_tagh3) && is_array($words_post_title)) {
920
  foreach ($words_tagh3 as $mh) {
921
+ if (in_array($mh, $words_post_title) && $mh !== '') {
922
  $test = true;
923
  }
924
  }
932
  $words_tagh4 = preg_split(
933
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
934
  utf8_decode(strtolower($tagh4->nodeValue)),
935
+ - 1,
936
  PREG_SPLIT_NO_EMPTY
937
  );
938
  if (is_array($words_tagh4) && is_array($words_post_title)) {
939
  foreach ($words_tagh4 as $mh) {
940
+ if (in_array($mh, $words_post_title) && $mh !== '') {
941
  $test = true;
942
  }
943
  }
951
  $words_tagh5 = preg_split(
952
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
953
  utf8_decode(strtolower($tagh5->nodeValue)),
954
+ - 1,
955
  PREG_SPLIT_NO_EMPTY
956
  );
957
  if (is_array($words_tagh5) && is_array($words_post_title)) {
958
  foreach ($words_tagh5 as $mh) {
959
+ if (in_array($mh, $words_post_title) && $mh !== '') {
960
  $test = true;
961
  }
962
  }
970
  $words_tagh6 = preg_split(
971
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
972
  utf8_decode(strtolower($tagh6->nodeValue)),
973
+ - 1,
974
  PREG_SPLIT_NO_EMPTY
975
  );
976
  if (is_array($words_tagh6) && is_array($words_post_title)) {
977
  foreach ($words_tagh6 as $mh) {
978
+ if (in_array($mh, $words_post_title) && $mh !== '') {
979
  $test = true;
980
  }
981
  }
989
  'heading_title',
990
  $tooltip_page['title_in_heading'],
991
  'done',
992
+ esc_html__('Page title word in content heading', 'wp-meta-seo'),
993
  1
994
  );
995
+ $check ++;
996
  } else {
997
  $output .= $this->createFieldAnalysis(
998
  'heading_title',
999
  $tooltip_page['title_in_heading'],
1000
  'warning',
1001
+ esc_html__('Page title word in content heading', 'wp-meta-seo'),
1002
  0
1003
  );
1004
  }
1007
  'heading_title',
1008
  $tooltip_page['title_in_heading'],
1009
  'warning',
1010
+ esc_html__('Page title word in content heading', 'wp-meta-seo'),
1011
  0
1012
  );
1013
  }
1015
  }
1016
 
1017
  // title content
1018
+ $words_title = preg_split(
1019
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
1020
  strtolower($_POST['datas']['title']),
1021
+ - 1,
1022
  PREG_SPLIT_NO_EMPTY
1023
  );
1024
  $words_post_content = preg_split(
1025
  '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
1026
  strtolower(strip_tags($content)),
1027
+ - 1,
1028
  PREG_SPLIT_NO_EMPTY
1029
  );
1030
 
1031
  $test1 = false;
1032
  if (is_array($words_title) && is_array($words_post_content)) {
1033
  foreach ($words_title as $mtitle) {
1034
+ if (in_array($mtitle, $words_post_content) && $mtitle !== '') {
1035
  $test1 = true;
1036
  break;
1037
  }
1045
  'content_title',
1046
  $tooltip_page['title_in_content'],
1047
  'done',
1048
+ esc_html__('Page title word in content', 'wp-meta-seo'),
1049
  1
1050
  );
1051
+ $check ++;
1052
  } else {
1053
  if ($test1) {
1054
  $output .= $this->createFieldAnalysis(
1055
  'content_title',
1056
  $tooltip_page['title_in_content'],
1057
  'done',
1058
+ esc_html__('Page title word in content', 'wp-meta-seo'),
1059
  1
1060
  );
1061
+ $check ++;
1062
  } else {
1063
  $output .= $this->createFieldAnalysis(
1064
  'content_title',
1065
  $tooltip_page['title_in_content'],
1066
  'warning',
1067
+ esc_html__('Page title word in content', 'wp-meta-seo'),
1068
  0
1069
  );
1070
  }
1077
  'pageurl',
1078
  $tooltip_page['page_url'],
1079
  'done',
1080
+ esc_html__('Page url matches with page title', 'wp-meta-seo'),
1081
  1
1082
  );
1083
+ $check ++;
1084
  } else {
1085
+ if ($_POST['datas']['editor'] === 'gutenberg') {
1086
+ $infos = pathinfo($_POST['datas']['mpageurl']);
1087
  $mpageurl = $infos['filename'];
1088
  } else {
1089
  $mpageurl = $_POST['datas']['mpageurl'];
1090
  }
1091
 
1092
+ if ($mpageurl === sanitize_title($mtitle)) {
1093
  $output .= $this->createFieldAnalysis(
1094
  'pageurl',
1095
  $tooltip_page['page_url'],
1096
  'done',
1097
+ esc_html__('Page url matches with page title', 'wp-meta-seo'),
1098
  1
1099
  );
1100
+ $check ++;
1101
  } else {
1102
  $output .= $this->createFieldAnalysis(
1103
  'pageurl',
1104
  $tooltip_page['page_url'],
1105
  'warning',
1106
+ esc_html__('Page url matches with page title', 'wp-meta-seo'),
1107
  0
1108
  );
1109
  }
1115
  'metatitle',
1116
  $tooltip_page['meta_title'],
1117
  'done',
1118
+ esc_html__('Meta title filled', 'wp-meta-seo'),
1119
  1
1120
  );
1121
+ $check ++;
1122
  } else {
1123
+ if (($_POST['datas']['meta_title'] !== ''
1124
+ && mb_strlen($_POST['datas']['meta_title'], 'UTF-8') <= self::$title_length)) {
1125
  $output .= $this->createFieldAnalysis(
1126
  'metatitle',
1127
  $tooltip_page['meta_title'],
1128
  'done',
1129
+ esc_html__('Meta title filled', 'wp-meta-seo'),
1130
  1
1131
  );
1132
+ $check ++;
1133
  } else {
1134
  $output .= $this->createFieldAnalysis(
1135
  'metatitle',
1136
  $tooltip_page['meta_title'],
1137
  'warning',
1138
+ esc_html__('Meta title filled', 'wp-meta-seo'),
1139
  0
1140
  );
1141
  }
1147
  'metadesc',
1148
  $tooltip_page['meta_desc'],
1149
  'done',
1150
+ esc_html__('Meta description filled', 'wp-meta-seo'),
1151
  1
1152
  );
1153
+ $check ++;
1154
  } else {
1155
+ if ($_POST['datas']['meta_desc'] !== ''
1156
  && mb_strlen($_POST['datas']['meta_desc'], 'UTF-8') <= self::$desc_length) {
1157
  $output .= $this->createFieldAnalysis(
1158
  'metadesc',
1159
  $tooltip_page['meta_desc'],
1160
  'done',
1161
+ esc_html__('Meta description filled', 'wp-meta-seo'),
1162
  1
1163
  );
1164
+ $check ++;
1165
  } else {
1166
  $output .= $this->createFieldAnalysis(
1167
  'metadesc',
1168
  $tooltip_page['meta_desc'],
1169
  'warning',
1170
+ esc_html__('Meta description filled', 'wp-meta-seo'),
1171
  0
1172
  );
1173
  }
1174
  }
1175
 
1176
  // image resize
1177
+ if ($content === '') {
1178
  $output .= $this->createFieldAnalysis(
1179
  'imgresize',
1180
  $tooltip_page['image_resize'],
1181
  'done',
1182
+ esc_html__('Wrong image resize', 'wp-meta-seo'),
1183
  1
1184
  );
1185
  $output .= $this->createFieldAnalysis(
1186
  'imgalt',
1187
  $tooltip_page['image_alt'],
1188
  'done',
1189
+ esc_html__('Image have meta alt', 'wp-meta-seo'),
1190
  1
1191
  );
1192
+ $check += 2;
1193
  } else {
1194
  $dom = new DOMDocument;
1195
  libxml_use_internal_errors(true);
1196
  if ($dom->loadHTML($content)) {
1197
  // Extracting the specified elements from the web page
1198
+ $tags = $dom->getElementsByTagName('img');
1199
+ $img_wrong = false;
1200
  $img_wrong_alt = false;
1201
  foreach ($tags as $order => $tag) {
1202
+ $src = $tag->getAttribute('src');
1203
  $imgpath = str_replace(site_url(), ABSPATH, $src);
1204
  if (!file_exists($imgpath)) {
1205
  continue;
1208
  continue;
1209
  }
1210
 
1211
+ if ((int) $tag->getAttribute('width') === 0 && (int) $tag->getAttribute('height') === 0) {
1212
  $img_wrong = false;
1213
  } else {
1214
  if (!empty($width_origin) && !empty($height_origin)) {
1215
+ if (((int) $width_origin !== (int) $tag->getAttribute('width'))
1216
+ || ((int) $height_origin !== (int) $tag->getAttribute('height'))) {
1217
  $img_wrong = true;
1218
  }
1219
  }
1220
  }
1221
 
1222
  $image_alt = $tag->getAttribute('alt');
1223
+ if ($image_alt === '') {
1224
  $img_wrong_alt = true;
1225
  }
1226
  }
1230
  'imgresize',
1231
  $tooltip_page['image_resize'],
1232
  'done',
1233
+ esc_html__('Wrong image resize', 'wp-meta-seo'),
1234
  1
1235
  );
1236
+ $check ++;
1237
  } else {
1238
+ if (!$img_wrong) {
1239
  $output .= $this->createFieldAnalysis(
1240
  'imgresize',
1241
  $tooltip_page['image_resize'],
1242
  'done',
1243
+ esc_html__('Wrong image resize', 'wp-meta-seo'),
1244
  1
1245
  );
1246
+ $check ++;
1247
  } else {
1248
  $output .= $this->createFieldAnalysis(
1249
  'imgresize',
1250
  $tooltip_page['image_resize'],
1251
  'warning',
1252
+ esc_html__('Wrong image resize', 'wp-meta-seo'),
1253
  0
1254
  );
1255
  }
1260
  'imgalt',
1261
  $tooltip_page['image_alt'],
1262
  'done',
1263
+ esc_html__('Image have meta alt', 'wp-meta-seo'),
1264
  1
1265
  );
1266
+ $check ++;
1267
  } else {
1268
+ if (!$img_wrong_alt) {
1269
  $output .= $this->createFieldAnalysis(
1270
  'imgalt',
1271
  $tooltip_page['image_alt'],
1272
  'done',
1273
+ esc_html__('Image have meta alt', 'wp-meta-seo'),
1274
  1
1275
  );
1276
+ $check ++;
1277
  } else {
1278
  $output .= $this->createFieldAnalysis(
1279
  'imgalt',
1280
  $tooltip_page['image_alt'],
1281
  'warning',
1282
+ esc_html__('Image have meta alt', 'wp-meta-seo'),
1283
  0
1284
  );
1285
  }
1286
  }
 
1287
  } else {
1288
  $output .= $this->createFieldAnalysis(
1289
  'imgresize',
1290
  $tooltip_page['image_resize'],
1291
  'warning',
1292
+ esc_html__('Wrong image resize', 'wp-meta-seo'),
1293
  0
1294
  );
1295
  $output .= $this->createFieldAnalysis(
1296
  'imgalt',
1297
  $tooltip_page['image_alt'],
1298
  'warning',
1299
+ esc_html__('Image have meta alt', 'wp-meta-seo'),
1300
  0
1301
  );
1302
  }
1307
  }
1308
 
1309
  /**
1310
+ * Validate propertyin page optimization
1311
+ *
1312
+ * @return void
1313
  */
1314
  public function validateAnalysis()
1315
  {
1316
+ if (empty($_POST['wpms_nonce'])
1317
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1318
+ die();
1319
+ }
1320
+
1321
  if (!current_user_can('manage_options')) {
1322
  wp_send_json(false);
1323
  }
1324
+ $post_id = $_POST['post_id'];
1325
+ $key = 'wpms_validate_analysis';
1326
  $analysis = get_post_meta($post_id, $key, true);
1327
  if (empty($analysis)) {
1328
  $analysis = array();
1335
 
1336
  /**
1337
  * Remove link in source 404
1338
+ *
1339
+ * @return void
1340
  */
1341
  public function removeLink()
1342
  {
1343
+ if (empty($_POST['wpms_nonce'])
1344
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1345
+ die();
1346
+ }
1347
+
1348
  if (!current_user_can('manage_options')) {
1349
  wp_send_json(array('status' => false));
1350
  }
1351
 
1352
  global $wpdb;
1353
  if (isset($_POST['link_id'])) {
1354
+ $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => (int) $_POST['link_id']));
1355
  wp_send_json(array('status' => true));
1356
  }
1357
 
1360
 
1361
  /**
1362
  * Ajax update link meta title and content editor
1363
+ *
1364
+ * @return void
1365
  */
1366
  public function updateLink()
1367
  {
1368
+ if (empty($_POST['wpms_nonce'])
1369
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1370
+ die();
1371
+ }
1372
+
1373
  if (!current_user_can('manage_options')) {
1374
  wp_send_json(false);
1375
  }
1376
  if (isset($_POST['link_id'])) {
1377
  global $wpdb;
1378
+ $link_detail = $wpdb->get_row($wpdb->prepare(
1379
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d',
1380
  array(
1381
+ (int) $_POST['link_id']
1382
  )
1383
+ ));
 
1384
  if (empty($link_detail)) {
1385
  wp_send_json(false);
1386
  }
1389
  $wpdb->update(
1390
  $wpdb->prefix . 'wpms_links',
1391
  $value,
1392
+ array('id' => (int) $_POST['link_id'])
1393
  );
1394
 
1395
 
1396
  $post = get_post($link_detail->source_id);
1397
  if (!empty($post)) {
1398
+ $content = $post->post_content;
1399
+ $links = MetaSeoBrokenLinkTable::extractTags($post->post_content, 'a', false, true);
1400
+ foreach ($links as $link) {
1401
+ if ($link['contents'] === $link_detail->link_text) {
1402
+ $new_html = '<a';
1403
+
1404
+ foreach ($link['attributes'] as $name => $value) {
1405
+ //Skip special keys like '#raw' and '#offset'
1406
+ if (substr($name, 0, 1) === '#') {
1407
+ continue;
1408
+ }
1409
+
1410
+ if (!isset($link['attributes']['title'])) {
1411
+ $new_html .= sprintf(' %s="%s"', 'title', esc_attr($_POST['meta_title']));
1412
+ }
1413
+
1414
+ if ($name === 'title') {
1415
+ $new_html .= sprintf(' %s="%s"', $name, esc_attr($_POST['meta_title']));
1416
+ } else {
1417
+ $new_html .= sprintf(' %s="%s"', $name, esc_attr($value));
1418
+ }
1419
+ }
1420
+ $new_html .= '>' . $link_detail->link_text . '</a>';
1421
+ $content = str_replace($link['full_tag'], $new_html, $content);
1422
+ }
1423
+ }
1424
 
1425
  $my_post = array(
1426
+ 'ID' => (int) $link_detail->source_id,
1427
+ 'post_content' => $content
1428
  );
1429
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1430
  wp_update_post($my_post);
1436
 
1437
  /**
1438
  * Ajax update meta index for page
1439
+ *
1440
+ * @return void
1441
  */
1442
  public function updatePageIndex()
1443
  {
1444
+ if (empty($_POST['wpms_nonce'])
1445
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1446
+ die();
1447
+ }
1448
+
1449
  if (!current_user_can('manage_options')) {
1450
  wp_send_json(array('status' => false));
1451
  }
1458
 
1459
  /**
1460
  * Ajax update meta follow for page
1461
+ *
1462
+ * @return void
1463
  */
1464
  public function updatePageFollow()
1465
  {
1466
+ if (empty($_POST['wpms_nonce'])
1467
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1468
+ die();
1469
+ }
1470
+
1471
  if (!current_user_can('manage_options')) {
1472
  wp_send_json(array('status' => false));
1473
  }
1474
  if (isset($_POST['page_id']) && isset($_POST['follow'])) {
1475
+ update_post_meta((int) $_POST['page_id'], '_metaseo_metafollow', $_POST['follow']);
1476
  wp_send_json(array('status' => true));
1477
  }
1478
  wp_send_json(array('status' => false));
1480
 
1481
  /**
1482
  * Ajax update meta follow for link
1483
+ *
1484
+ * @return void
1485
  */
1486
  public function updateFollow()
1487
  {
1488
+ if (empty($_POST['wpms_nonce'])
1489
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1490
+ die();
1491
+ }
1492
+
1493
  if (!current_user_can('manage_options')) {
1494
  wp_send_json(array('status' => false));
1495
  }
1502
 
1503
  /**
1504
  * Ajax update multitle meta follow for link
1505
+ *
1506
+ * @return void
1507
  */
1508
  public function updateMultipleFollow()
1509
  {
1510
+ if (empty($_POST['wpms_nonce'])
1511
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1512
+ die();
1513
+ }
1514
+
1515
  if (!current_user_can('manage_options')) {
1516
  wp_send_json(array('status' => false));
1517
  }
1518
  global $wpdb;
1519
  $follow_value = $_POST['follow_value'];
1520
+ $limit = 20;
1521
 
1522
  switch ($follow_value) {
1523
  case 'follow_selected':
1533
 
1534
  case 'follow_all':
1535
  $follow = 1;
1536
+ $i = 0;
1537
+ $links = $wpdb->get_results(
1538
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE follow=0 AND type="url"'
1539
  );
1540
  foreach ($links as $link) {
1541
  if ($i > $limit) {
1542
  wp_send_json(array('status' => false, 'message' => 'limit'));
1543
  } else {
1544
  $this->doUpdateFollow($link->id, $follow);
1545
+ $i ++;
1546
  }
1547
  }
1548
 
1561
 
1562
  case 'nofollow_all':
1563
  $follow = 0;
1564
+ $i = 0;
1565
+ $links = $wpdb->get_results(
1566
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE follow=1 AND type="url"'
1567
  );
1568
  foreach ($links as $link) {
1569
  if ($i > $limit) {
1570
  wp_send_json(array('status' => false, 'message' => 'limit'));
1571
  } else {
1572
  $this->doUpdateFollow($link->id, $follow);
1573
+ $i ++;
1574
  }
1575
  }
1576
  break;
1580
 
1581
  /**
1582
  * Ajax update meta follow for link
1583
+ *
1584
+ * @param integer $linkId Link id
1585
+ * @param integer $follow Follow value
1586
+ *
1587
+ * @return void
1588
  */
1589
  public function doUpdateFollow($linkId, $follow)
1590
  {
1591
  global $wpdb;
1592
+ $link_detail = $wpdb->get_row($wpdb->prepare(
1593
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d',
1594
+ array((int) $linkId)
1595
+ ));
 
 
 
1596
  if (empty($link_detail)) {
1597
  wp_send_json(array('status' => false));
1598
  }
1599
 
 
1600
  $value = array('follow' => $follow);
1601
  $wpdb->update(
1602
  $wpdb->prefix . 'wpms_links',
1603
  $value,
1604
+ array('id' => (int) $linkId)
1605
  );
1606
 
1607
  $post = get_post($link_detail->source_id);
1608
  if (!empty($post)) {
1609
+ $old_value = $post->post_content;
1610
  $edit_result = $this->editLinkHtml(
1611
  $old_value,
1612
  $link_detail->link_url,
1614
  $link_detail->meta_title,
1615
  $follow
1616
  );
1617
+ $my_post = array(
1618
+ 'ID' => (int) $link_detail->source_id,
1619
  'post_content' => $edit_result['content']
1620
  );
1621
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1625
 
1626
  /**
1627
  * Render new content when edit a link
1628
+ *
1629
+ * @param string $content Post content
1630
+ * @param string $new_url New url
1631
+ * @param string $old_url Old url
1632
+ * @param string $meta_title Meta title
1633
+ * @param integer $follow Follow value
1634
+ * @param null $new_text New text of link
1635
+ *
1636
  * @return array
1637
  */
1638
  public function editLinkHtml($content, $new_url, $old_url, $meta_title, $follow, $new_text = null)
1639
  {
1640
  //Save the old & new URLs for use in the edit callback.
1641
  $args = array(
1642
+ 'old_url' => $old_url,
1643
+ 'new_url' => $new_url,
1644
+ 'new_text' => $new_text,
1645
  'meta_title' => $meta_title,
1646
+ 'follow' => $follow
1647
  );
1648
 
1649
  //Find all links and replace those that match $old_url.
1668
 
1669
  /**
1670
  * Update option wpms_settings_404
1671
+ *
1672
+ * @return void
1673
  */
1674
  public function save404Settings()
1675
  {
1676
+ if (empty($_POST['wpms_nonce'])
1677
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1678
+ die();
1679
+ }
1680
+
1681
  if (!current_user_can('manage_options')) {
1682
  wp_send_json(false);
1683
  }
1687
  }
1688
 
1689
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1690
+ $params = array('enable', 'numberFrequency', 'showlinkFrequency');
1691
  $settinglink = array();
1692
  foreach ($params as $param) {
1693
  if (isset($_POST[$param])) {
1706
 
1707
  /**
1708
  * Update breadcrumb settings
1709
+ *
1710
+ * @return void
1711
  */
1712
  public function saveBreadcrumbSettings()
1713
  {
1714
+ if (empty($_POST['wpms_nonce'])
1715
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1716
+ die();
1717
+ }
1718
+
1719
  if (!current_user_can('manage_options')) {
1720
  wp_send_json(false);
1721
  }
1722
 
1723
+ $params = array('separator', 'include_home', 'home_text', 'clickable', 'home_text_default');
1724
  $settinglink = array();
1725
  foreach ($params as $param) {
1726
  if (isset($_POST[$param])) {
1734
 
1735
  /**
1736
  * Add a new field to a section of a settings page
1737
+ *
1738
+ * @return void
1739
  */
1740
  public function fieldSettings()
1741
  {
1743
  add_settings_section('metaseo_dashboard', '', array($this, 'showSettings'), 'metaseo_settings');
1744
  add_settings_field(
1745
  'metaseo_title_home',
1746
+ esc_html__('Homepage meta title', 'wp-meta-seo'),
1747
  array($this, 'titleHome'),
1748
  'metaseo_settings',
1749
  'metaseo_dashboard',
1750
  array(
1751
+ 'label_for' => esc_html__('You can define your home page meta title in the content
1752
  itself (a page, a post category…),
1753
  if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1754
  )
1755
  );
1756
  add_settings_field(
1757
  'metaseo_desc_home',
1758
+ esc_html__('Homepage meta description', 'wp-meta-seo'),
1759
  array($this, 'descHome'),
1760
  'metaseo_settings',
1761
  'metaseo_dashboard',
1762
  array(
1763
+ 'label_for' => esc_html__('You can define your home page meta description in the content
1764
  itself (a page, a post category…),
1765
  if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1766
  )
1767
  );
1768
  add_settings_field(
1769
  'metaseo_showfacebook',
1770
+ esc_html__('Facebook profile URL', 'wp-meta-seo'),
1771
  array($this, 'showfacebook'),
1772
  'metaseo_settings',
1773
  'metaseo_dashboard',
1774
  array(
1775
+ 'label_for' => esc_html__('Used as profile in case of social sharing content on Facebook', 'wp-meta-seo')
1776
  )
1777
  );
1778
  add_settings_field(
1779
  'metaseo_showfbappid',
1780
+ esc_html__('Facebook App ID', 'wp-meta-seo'),
1781
  array($this, 'showfbappid'),
1782
  'metaseo_settings',
1783
  'metaseo_dashboard',
1784
  array(
1785
+ 'label_for' => esc_html__('Used as facebook app ID in case of
1786
  social sharing content on Facebook', 'wp-meta-seo')
1787
  )
1788
  );
1789
  add_settings_field(
1790
  'metaseo_showtwitter',
1791
+ esc_html__('Twitter Username', 'wp-meta-seo'),
1792
  array($this, 'showtwitter'),
1793
  'metaseo_settings',
1794
  'metaseo_dashboard',
1795
  array(
1796
+ 'label_for' => esc_html__('Used as profile in case of social sharing content on Twitter', 'wp-meta-seo')
1797
  )
1798
  );
1799
  add_settings_field(
1800
  'metaseo_twitter_card',
1801
+ esc_html__('The default card type to use', 'wp-meta-seo'),
1802
  array($this, 'showtwittercard'),
1803
  'metaseo_settings',
1804
  'metaseo_dashboard',
1805
  array(
1806
+ 'label_for' => esc_html__('Choose the Twitter card size generated when sharing a content', 'wp-meta-seo')
1807
  )
1808
  );
1809
  add_settings_field(
1810
  'metaseo_metatitle_tab',
1811
+ esc_html__('Meta title as page title', 'wp-meta-seo'),
1812
  array($this, 'showmetatitletab'),
1813
  'metaseo_settings',
1814
  'metaseo_dashboard',
1815
  array(
1816
+ 'label_for' => esc_html__('Usually not recommended as meta information is
1817
  for search engines and content title for readers, but in some case... :)', 'wp-meta-seo')
1818
  )
1819
  );
1820
  add_settings_field(
1821
  'metaseo_showkeywords',
1822
+ esc_html__('Meta keywords', 'wp-meta-seo'),
1823
  array($this, 'showkeywords'),
1824
  'metaseo_settings',
1825
  'metaseo_dashboard',
1826
  array(
1827
+ 'label_for' => esc_html__('Not used directly by search engine to index content,
1828
  but in some case it can be helpful (multilingual is an example)', 'wp-meta-seo')
1829
  )
1830
  );
1831
  add_settings_field(
1832
  'metaseo_showtmetablock',
1833
+ esc_html__('Meta block edition', 'wp-meta-seo'),
1834
  array($this, 'showtmetablock'),
1835
  'metaseo_settings',
1836
  'metaseo_dashboard',
1837
  array(
1838
+ 'label_for' => esc_html__('Load the onpage meta edition and analysis block', 'wp-meta-seo')
1839
  )
1840
  );
1841
  add_settings_field(
1842
  'metaseo_showsocial',
1843
+ esc_html__('Social sharing block', 'wp-meta-seo'),
1844
  array($this, 'showsocial'),
1845
  'metaseo_settings',
1846
  'metaseo_dashboard',
1847
  array(
1848
+ 'label_for' => esc_html__('Activate the custom social sharing tool, above the meta block', 'wp-meta-seo')
1849
  )
1850
  );
1851
  add_settings_field(
1852
  'metaseo_seovalidate',
1853
+ esc_html__('Force SEO validation', 'wp-meta-seo'),
1854
  array($this, 'showseovalidate'),
1855
  'metaseo_settings',
1856
  'metaseo_dashboard',
1857
  array(
1858
+ 'label_for' => esc_html__('Possibility to force a criteria validation
1859
  in the content analysis tool', 'wp-meta-seo')
1860
  )
1861
  );
1862
  add_settings_field(
1863
  'metaseo_linkfield',
1864
+ esc_html__('Link text field', 'wp-meta-seo'),
1865
  array($this, 'showlinkfield'),
1866
  'metaseo_settings',
1867
  'metaseo_dashboard',
1868
  array(
1869
+ 'label_for' => esc_html__('Add the link title field in the text editor and
1870
  in the bulk link edition view', 'wp-meta-seo')
1871
  )
1872
  );
1873
  add_settings_field(
1874
  'metaseo_follow',
1875
+ esc_html__('Post/Page follow', 'wp-meta-seo'),
1876
  array($this, 'showfollow'),
1877
  'metaseo_settings',
1878
  'metaseo_dashboard',
1879
  array(
1880
+ 'label_for' => esc_html__('Add an option to setup Follow/Nofollow instruction for each content', 'wp-meta-seo')
1881
  )
1882
  );
1883
  add_settings_field(
1884
  'metaseo_index',
1885
+ esc_html__('Post/Page index', 'wp-meta-seo'),
1886
  array($this, 'showindex'),
1887
  'metaseo_settings',
1888
  'metaseo_dashboard',
1889
  array(
1890
+ 'label_for' => esc_html__('Add an option to say to search engine: hey!
1891
  Do not index this content', 'wp-meta-seo')
1892
  )
1893
  );
1894
  add_settings_field(
1895
  'metaseo_overridemeta',
1896
+ esc_html__('Auto override Meta', 'wp-meta-seo'),
1897
  array($this, 'showoverridemeta'),
1898
  'metaseo_settings',
1899
  'metaseo_dashboard',
1900
  array(
1901
+ 'label_for' => esc_html__('Auto override image meta in post content when update meta', 'wp-meta-seo')
1902
  )
1903
  );
1904
  }
1905
 
1906
  /**
1907
  * Display metatitle_tab input
1908
+ *
1909
+ * @return void
1910
  */
1911
  public function showmetatitletab()
1912
  {
1913
  echo '<input name="_metaseo_settings[metaseo_metatitle_tab]" type="hidden" value="0"/>';
1914
  ?>
1915
  <label>
1916
+ <?php esc_html_e('When meta title is filled use it as page title instead of the content title', 'wp-meta-seo'); ?>
1917
  </label>
1918
  <div class="switch-optimization">
1919
  <label class="switch switch-optimization">
1920
  <?php
1921
+ if (isset($this->settings['metaseo_metatitle_tab']) && (int) $this->settings['metaseo_metatitle_tab'] === 1) :
1922
  ?>
1923
  <input type="checkbox" id="metaseo_metatitle_tab" name="_metaseo_settings[metaseo_metatitle_tab]"
1924
  value="1" checked>
1932
  <?php
1933
  }
1934
 
1935
+ /**
1936
+ * Show setting title
1937
+ *
1938
+ * @return void
1939
+ */
1940
  public function showSettings()
1941
  {
1942
  }
1943
 
1944
  /**
1945
  * Display title_home input
1946
+ *
1947
+ * @return void
1948
  */
1949
  public function titleHome()
1950
  {
1955
 
1956
  /**
1957
  * Display desc_home input
1958
+ *
1959
+ * @return void
1960
  */
1961
  public function descHome()
1962
  {
1967
 
1968
  /**
1969
  * Display showkeywords input
1970
+ *
1971
+ * @return void
1972
  */
1973
  public function showkeywords()
1974
  {
1975
  echo '<input name="_metaseo_settings[metaseo_showkeywords]" type="hidden" value="0"/>';
1976
  ?>
1977
+ <label><?php esc_html_e('Active meta keywords', 'wp-meta-seo'); ?></label>
1978
  <div class="switch-optimization">
1979
  <label class="switch switch-optimization">
1980
  <?php
1981
+ if (isset($this->settings['metaseo_showkeywords']) && (int) $this->settings['metaseo_showkeywords'] === 1) :
1982
  ?>
1983
  <input type="checkbox" id="metaseo_showkeywords" name="_metaseo_settings[metaseo_showkeywords]"
1984
  value="1" checked>
1994
 
1995
  /**
1996
  * Display showtmetablock input
1997
+ *
1998
+ * @return void
1999
  */
2000
  public function showtmetablock()
2001
  {
2002
  echo '<input name="_metaseo_settings[metaseo_showtmetablock]" type="hidden" value="0"/>';
2003
  ?>
2004
+ <label><?php esc_html_e('Activate meta block edition below content', 'wp-meta-seo'); ?></label>
2005
  <div class="switch-optimization">
2006
  <label class="switch switch-optimization">
2007
  <?php
2008
  if (isset($this->settings['metaseo_showtmetablock'])
2009
+ && (int) $this->settings['metaseo_showtmetablock'] === 1) :
2010
  ?>
2011
  <input type="checkbox" id="metaseo_showtmetablock" name="_metaseo_settings[metaseo_showtmetablock]"
2012
  value="1" checked>
2022
 
2023
  /**
2024
  * Display showsocial input
2025
+ *
2026
+ * @return void
2027
  */
2028
  public function showsocial()
2029
  {
2030
  echo '<input name="_metaseo_settings[metaseo_showsocial]" type="hidden" value="0"/>';
2031
  ?>
2032
+ <label><?php esc_html_e('Activate social edition', 'wp-meta-seo'); ?></label>
2033
  <div class="switch-optimization">
2034
  <label class="switch switch-optimization">
2035
  <?php
2036
+ if (isset($this->settings['metaseo_showsocial']) && (int) $this->settings['metaseo_showsocial'] === 1) :
2037
  ?>
2038
  <input type="checkbox" id="metaseo_showsocial" name="_metaseo_settings[metaseo_showsocial]"
2039
  value="1" checked>
2049
 
2050
  /**
2051
  * Display seovalidate input
2052
+ *
2053
+ * @return void
2054
  */
2055
  public function showseovalidate()
2056
  {
2057
  echo '<input name="_metaseo_settings[metaseo_seovalidate]" type="hidden" value="0"/>';
2058
  ?>
2059
  <label>
2060
+ <?php esc_html_e('Allow user to force on page SEO criteria validation by clicking on the icon', 'wp-meta-seo'); ?>
2061
  </label>
2062
  <div class="switch-optimization">
2063
  <label class="switch switch-optimization">
2064
  <?php
2065
+ if (isset($this->settings['metaseo_seovalidate']) && (int) $this->settings['metaseo_seovalidate'] === 1) :
2066
  ?>
2067
  <input type="checkbox" id="metaseo_seovalidate" name="_metaseo_settings[metaseo_seovalidate]"
2068
  value="1" checked>
2078
 
2079
  /**
2080
  * Display linkfield input
2081
+ *
2082
+ * @return void
2083
  */
2084
  public function showlinkfield()
2085
  {
2086
  echo '<input name="_metaseo_settings[metaseo_linkfield]" type="hidden" value="0"/>';
2087
  ?>
2088
+ <label><?php esc_html_e('Adds back the missing title field in the Insert/Edit URL box', 'wp-meta-seo'); ?></label>
2089
  <div class="switch-optimization">
2090
  <label class="switch switch-optimization">
2091
  <?php
2092
+ if (isset($this->settings['metaseo_linkfield']) && (int) $this->settings['metaseo_linkfield'] === 1) :
2093
  ?>
2094
  <input type="checkbox" id="metaseo_linkfield" name="_metaseo_settings[metaseo_linkfield]"
2095
  value="1" checked>
2105
 
2106
  /**
2107
  * Display follow input
2108
+ *
2109
+ * @return void
2110
  */
2111
  public function showfollow()
2112
  {
2113
  echo '<input name="_metaseo_settings[metaseo_follow]" type="hidden" value="0"/>';
2114
  ?>
2115
  <label>
2116
+ <?php esc_html_e('Provides a way for webmasters to tell
2117
+ search engines don\'t follow links on the page.', 'wp-meta-seo'); ?>
2118
  </label>
2119
  <div class="switch-optimization">
2120
  <label class="switch switch-optimization">
2121
  <?php
2122
+ if (isset($this->settings['metaseo_follow']) && (int) $this->settings['metaseo_follow'] === 1) :
2123
  ?>
2124
  <input type="checkbox" id="metaseo_follow" name="_metaseo_settings[metaseo_follow]"
2125
  value="1" checked>
2135
 
2136
  /**
2137
  * Display index input
2138
+ *
2139
+ * @return void
2140
  */
2141
  public function showindex()
2142
  {
2143
  echo '<input name="_metaseo_settings[metaseo_index]" type="hidden" value="0"/>';
2144
  ?>
2145
  <label>
2146
+ <?php esc_html_e('Provides show or do not show this page in search
2147
+ results in search results.', 'wp-meta-seo'); ?>
2148
  </label>
2149
  <div class="switch-optimization">
2150
  <label class="switch switch-optimization">
2151
  <?php
2152
+ if (isset($this->settings['metaseo_index']) && (int) $this->settings['metaseo_index'] === 1) :
2153
  ?>
2154
  <input type="checkbox" id="metaseo_index" name="_metaseo_settings[metaseo_index]"
2155
  value="1" checked>
2165
 
2166
  /**
2167
  * Display override meta
2168
+ *
2169
+ * @return void
2170
  */
2171
  public function showoverridemeta()
2172
  {
2173
  echo '<input name="_metaseo_settings[metaseo_overridemeta]" type="hidden" value="0"/>';
2174
  ?>
2175
+ <label><?php esc_html_e('Override meta image in post content when update meta', 'wp-meta-seo'); ?></label>
2176
  <div class="switch-optimization">
2177
  <label class="switch switch-optimization">
2178
  <?php
2179
+ if (isset($this->settings['metaseo_overridemeta']) && (int) $this->settings['metaseo_overridemeta'] === 1) :
2180
  ?>
2181
  <input type="checkbox" id="metaseo_overridemeta" name="_metaseo_settings[metaseo_overridemeta]"
2182
  value="1" checked>
2192
 
2193
  /**
2194
  * Display showfacebook input
2195
+ *
2196
+ * @return void
2197
  */
2198
  public function showfacebook()
2199
  {
2204
 
2205
  /**
2206
  * Display fb app id input
2207
+ *
2208
+ * @return void
2209
  */
2210
  public function showfbappid()
2211
  {
2216
 
2217
  /**
2218
  * Display showtwitter input
2219
+ *
2220
+ * @return void
2221
  */
2222
  public function showtwitter()
2223
  {
2228
 
2229
  /**
2230
  * Display twitter_card input
2231
+ *
2232
+ * @return void
2233
  */
2234
  public function showtwittercard()
2235
  {
2242
  <label>
2243
  <select class="select" name="_metaseo_settings[metaseo_twitter_card]" id="metaseo_twitter_card">
2244
  <option <?php selected($twitter_card, 'summary') ?>
2245
+ value="summary"><?php esc_html_e('Summary', 'wp-meta-seo'); ?></option>
2246
  <option <?php selected($twitter_card, 'summary_large_image') ?>
2247
+ value="summary_large_image"><?php esc_html_e('Summary with large image', 'wp-meta-seo'); ?></option>
2248
  </select>
2249
  </label>
2250
  <?php
2252
 
2253
  /**
2254
  * Show meta box in single post
2255
+ *
2256
+ * @return void
2257
  */
2258
  private function loadMetaBoxes()
2259
  {
2270
 
2271
  /**
2272
  * Update meta title , meta description , meta keyword for content
2273
+ *
2274
+ * @return void
2275
  */
2276
  public function updateContentMetaCallback()
2277
  {
2278
+ if (empty($_POST['wpms_nonce'])
2279
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
2280
+ die();
2281
+ }
2282
 
2283
  if (!current_user_can('manage_options')) {
2284
  wp_send_json(array('status' => false));
2285
  }
2286
+ $_POST = stripslashes_deep($_POST);
2287
+ $response = new stdClass();
2288
+ $metakey = strtolower(trim($_POST['metakey']));
2289
+ $postID = intval($_POST['postid']);
2290
+ $value = trim($_POST['value']);
2291
+ $response->msg = esc_html__('Modification was saved', 'wp-meta-seo');
2292
+ if ($metakey === 'metatitle') {
2293
  if (!update_post_meta($postID, '_metaseo_metatitle', $value)) {
2294
  $response->updated = false;
2295
+ $response->msg = esc_html__('Meta title was not saved', 'wp-meta-seo');
2296
  } else {
2297
  $response->updated = true;
2298
+ $response->msg = esc_html__('Meta title was saved', 'wp-meta-seo');
2299
  }
2300
  }
2301
 
2302
+ if ($metakey === 'metadesc') {
2303
  if (!update_post_meta($postID, '_metaseo_metadesc', $value)) {
2304
  $response->updated = false;
2305
+ $response->msg = esc_html__('Meta description was not saved', 'wp-meta-seo');
2306
  } else {
2307
  $response->updated = true;
2308
+ $response->msg = esc_html__('Meta description was saved', 'wp-meta-seo');
2309
  }
2310
  }
2311
 
2312
+ if ($metakey === 'metakeywords') {
2313
  if (!update_post_meta($postID, '_metaseo_metakeywords', $value)) {
2314
  $response->updated = false;
2315
+ $response->msg = esc_html__('Meta keywords was not saved', 'wp-meta-seo');
2316
  } else {
2317
  $response->updated = true;
2318
+ $response->msg = esc_html__('Meta keywords was saved', 'wp-meta-seo');
2319
  }
2320
  }
2321
  update_option('wpms_last_update_post', time());
2325
 
2326
  /**
2327
  * Loads js/ajax scripts
2328
+ *
2329
+ * @return void
2330
  */
2331
  public function loadAdminScripts()
2332
  {
2384
  true
2385
  );
2386
 
2387
+ if (in_array($current_screen->base, $array_menu) || $pagenow === 'post.php' || $pagenow === 'post-new.php') {
2388
  wp_enqueue_style(
2389
  'wpmetaseoAdmin',
2390
  plugins_url('css/metaseo_admin.css', dirname(__FILE__)),
2400
  wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
2401
  }
2402
 
2403
+ if ($current_screen->base === 'wp-meta-seo_page_metaseo_image_meta'
2404
+ || $current_screen->base === 'wp-meta-seo_page_metaseo_content_meta') {
2405
  wp_enqueue_script(
2406
  'wpms-bulk',
2407
  plugins_url('js/wpms-bulk-action.js', dirname(__FILE__)),
2412
  wp_localize_script('wpms-bulk', 'wpmseobulkL10n', $this->localizeScript());
2413
  }
2414
 
2415
+ if ($current_screen->base === 'wp-meta-seo_page_metaseo_broken_link') {
2416
  wp_enqueue_style(
2417
  'wpms_brokenlink_style',
2418
  plugins_url('css/broken_link.css', dirname(__FILE__)),
2421
  );
2422
  }
2423
 
2424
+ if ($current_screen->base === 'toplevel_page_metaseo_dashboard') {
2425
  wp_enqueue_script(
2426
  'Chart',
2427
  plugins_url('js/Chart.js', dirname(__FILE__)),
2470
  'wp-meta-seo_page_metaseo_google_sitemap',
2471
  'wp-meta-seo_page_metaseo_link_meta',
2472
  'wp-meta-seo_page_metaseo_broken_link',
2473
+ 'wp-meta-seo_page_metaseo_google_analytics'
2474
+ );
2475
  if (in_array($current_screen->base, $lists_pages)) {
2476
  wp_enqueue_style(
2477
  'wpms_notification_style',
2534
  );
2535
 
2536
  wp_register_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons');
2537
+ if ($current_screen->base === 'wp-meta-seo_page_metaseo_image_meta') {
2538
  wp_enqueue_script(
2539
  'mautosize',
2540
  plugins_url('js/autosize.js', dirname(__FILE__)),
2544
  );
2545
  }
2546
 
2547
+ if ($current_screen->base === 'wp-meta-seo_page_metaseo_google_analytics') {
2548
  $lang = get_bloginfo('language');
2549
  $lang = explode('-', $lang);
2550
  $lang = $lang[0];
2602
  'wpms-google-analytics',
2603
  'wpmsItemData',
2604
  array(
2605
+ 'ajaxurl' => admin_url('admin-ajax.php'),
2606
+ 'security' => wp_create_nonce('wpms_backend_item_reports'),
2607
+ 'dateList' => array(
2608
+ 'realtime' => esc_html__('Real-Time', 'wp-meta-seo'),
2609
+ 'today' => esc_html__('Today', 'wp-meta-seo'),
2610
+ 'yesterday' => esc_html__('Yesterday', 'wp-meta-seo'),
2611
+ '7daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 7),
2612
+ '14daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 14),
2613
+ '30daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 30),
2614
+ '90daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 90),
2615
+ '365daysAgo' => sprintf(_n('%s Year', '%s Years', 1, 'wp-meta-seo'), esc_html__('One', 'wp-meta-seo')),
2616
  '1095daysAgo' => sprintf(
2617
+ _n('%s Year', '%s Years', 3, 'wp-meta-seo'),
2618
+ esc_html__('Three', 'wp-meta-seo')
2619
  ),
2620
  ),
2621
+ 'reportList' => array(
2622
+ 'sessions' => esc_html__('Sessions', 'wp-meta-seo'),
2623
+ 'users' => esc_html__('Users', 'wp-meta-seo'),
2624
+ 'organicSearches' => esc_html__('Organic', 'wp-meta-seo'),
2625
+ 'pageviews' => esc_html__('Page Views', 'wp-meta-seo'),
2626
+ 'visitBounceRate' => esc_html__('Bounce Rate', 'wp-meta-seo'),
2627
+ 'locations' => esc_html__('Location', 'wp-meta-seo'),
2628
+ 'contentpages' => esc_html__('Pages', 'wp-meta-seo'),
2629
+ 'referrers' => esc_html__('Referrers', 'wp-meta-seo'),
2630
+ 'searches' => esc_html__('Searches', 'wp-meta-seo'),
2631
+ 'trafficdetails' => esc_html__('Traffic', 'wp-meta-seo'),
2632
+ 'technologydetails' => esc_html__('Technology', 'wp-meta-seo'),
2633
  ),
2634
+ 'i18n' => array(
2635
+ esc_html__('A JavaScript Error is blocking plugin resources!', 'wp-meta-seo'), //0
2636
+ esc_html__('Traffic Mediums', 'wp-meta-seo'),
2637
+ esc_html__('Visitor Type', 'wp-meta-seo'),
2638
+ esc_html__('Search Engines', 'wp-meta-seo'),
2639
+ esc_html__('Social Networks', 'wp-meta-seo'),
2640
+ esc_html__('Sessions', 'wp-meta-seo'),
2641
+ esc_html__('Users', 'wp-meta-seo'),
2642
+ esc_html__('Page Views', 'wp-meta-seo'),
2643
+ esc_html__('Bounce Rate', 'wp-meta-seo'),
2644
+ esc_html__('Organic Search', 'wp-meta-seo'),
2645
+ esc_html__('Pages/Session', 'wp-meta-seo'),
2646
+ esc_html__('Invalid response', 'wp-meta-seo'),
2647
+ esc_html__('Not enough data collected', 'wp-meta-seo'),
2648
+ esc_html__('This report is unavailable', 'wp-meta-seo'),
2649
+ esc_html__('report generated by', 'wp-meta-seo'), //14
2650
+ esc_html__('This plugin needs an authorization:', 'wp-meta-seo') . '
2651
+ <a href="' . esc_html(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) . '">
2652
+ ' . esc_html__('authorize the plugin', 'wp-meta-seo') . '</a>.',
2653
+ esc_html__('Browser', 'wp-meta-seo'), //16
2654
+ esc_html__('Operating System', 'wp-meta-seo'),
2655
+ esc_html__('Screen Resolution', 'wp-meta-seo'),
2656
+ esc_html__('Mobile Brand', 'wp-meta-seo'),
2657
+ esc_html__('REFERRALS', 'wp-meta-seo'), //20
2658
+ esc_html__('KEYWORDS', 'wp-meta-seo'),
2659
+ esc_html__('SOCIAL', 'wp-meta-seo'),
2660
+ esc_html__('CAMPAIGN', 'wp-meta-seo'),
2661
+ esc_html__('DIRECT', 'wp-meta-seo'),
2662
+ esc_html__('NEW', 'wp-meta-seo'), //25
2663
+ esc_html__('You need select a profile:', 'wp-meta-seo') . '
2664
+ <a href="' . esc_html(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) . '">
2665
+ ' . esc_html__('authorize the plugin', 'wp-meta-seo') . '</a>.',
2666
  ),
2667
+ 'rtLimitPages' => 10,
2668
  'colorVariations' => array(
2669
  '#1e73be',
2670
  '#0459a4',
2674
  '#6abfff',
2675
  '#002671'
2676
  ),
2677
+ 'region' => false,
2678
+ 'language' => get_bloginfo('language'),
2679
+ 'viewList' => false,
2680
+ 'scope' => 'admin-widgets',
2681
+ 'admin_url' => admin_url()
2682
  )
2683
  );
2684
  }
2685
 
2686
  // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
2687
  wp_localize_script('wpmetaseoAdmin', 'wpms_localize', array(
2688
+ 'ajax_url' => admin_url('admin-ajax.php'),
2689
+ 'settings' => $this->settings,
2690
+ 'wpms_cat_metatitle_length' => MPMSCAT_TITLE_LENGTH,
2691
+ 'wpms_cat_metadesc_length' => MPMSCAT_DESC_LENGTH,
2692
+ 'wpms_cat_metakeywords_length' => MPMSCAT_KEYWORDS_LENGTH,
2693
+ 'wpms_nonce' => wp_create_nonce('wpms_nonce')
2694
  ));
2695
  }
2696
 
2698
  * Localize a script.
2699
  *
2700
  * Works only if the script has already been added.
2701
+ *
2702
+ * @return array
2703
  */
2704
  public function localizeScript()
2705
  {
2706
  return array(
2707
+ 'metaseo_message_false_copy' => esc_html__('Warning, you\'re about to replace existing image
2708
  alt or tile content, are you sire about that?', 'wp-meta-seo'),
2709
  );
2710
  }
2714
  *
2715
  * This function takes a capability which will be used to determine whether
2716
  * or not a page is included in the menu.
2717
+ *
2718
+ * @return void
2719
  */
2720
  public function addMenuPage()
2721
  {
2722
  // Add main page
2723
  add_menu_page(
2724
+ esc_html__('WP Meta SEO: Dashboard', 'wp-meta-seo'),
2725
+ esc_html__('WP Meta SEO', 'wp-meta-seo'),
2726
  'manage_options',
2727
  'metaseo_dashboard',
2728
  array(
2745
  array(
2746
  'metaseo_dashboard',
2747
  '',
2748
+ esc_html__('Dashboard', 'wp-meta-seo'),
2749
+ $manage_options_cap,
2750
+ 'metaseo_dashboard',
2751
+ array($this, 'loadPage'),
2752
+ null
2753
+ ),
2754
+ array(
2755
+ 'metaseo_dashboard',
2756
+ '',
2757
+ esc_html__('Content meta', 'wp-meta-seo'),
2758
  $manage_options_cap,
2759
  'metaseo_content_meta',
2760
  array($this, 'loadPage'),
2761
+ null
2762
  ),
2763
  array(
2764
  'metaseo_dashboard',
2765
  '',
2766
+ esc_html__('Sitemap', 'wp-meta-seo'),
2767
  $manage_options_cap,
2768
  'metaseo_google_sitemap',
2769
  array($this, 'loadPage'),
2772
  array(
2773
  'metaseo_dashboard',
2774
  '',
2775
+ esc_html__('Image information', 'wp-meta-seo'),
2776
  $manage_options_cap,
2777
  'metaseo_image_meta',
2778
  array($this, 'loadPage'),
2779
+ null
2780
  ),
2781
  array(
2782
  'metaseo_dashboard',
2783
  '',
2784
+ esc_html__('Image compression', 'wp-meta-seo'),
2785
  $manage_options_cap,
2786
  'metaseo_image_compression',
2787
  array($this, 'loadPage'),
2788
+ null
2789
  ),
2790
  array(
2791
  'metaseo_dashboard',
2792
  '',
2793
+ esc_html__('Link editor', 'wp-meta-seo'),
2794
  $manage_options_cap,
2795
  'metaseo_link_meta',
2796
  array($this, 'loadPage'),
2797
+ null
2798
  ),
2799
  array(
2800
  'metaseo_dashboard',
2801
  '',
2802
+ esc_html__('404 & Redirects', 'wp-meta-seo'),
2803
  $manage_options_cap,
2804
  'metaseo_broken_link',
2805
  array($this, 'loadPage'),
2806
+ null
2807
  ),
2808
  array(
2809
  'metaseo_dashboard',
2810
  '',
2811
+ esc_html__('Google Analytics', 'wp-meta-seo'),
2812
  $manage_options_cap,
2813
  'metaseo_google_analytics',
2814
  array($this, 'loadPage'),
2815
+ null
2816
+ )
2817
+
2818
+ );
2819
+
2820
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2821
+ global $metaseo_addon;
2822
+ $submenu_pages[] = array(
2823
  'metaseo_dashboard',
2824
+ esc_html__('WP Meta SEO Send email', 'wp-meta-seo'),
2825
+ esc_html__('Email report', 'wp-meta-seo'),
2826
  $manage_options_cap,
2827
+ 'metaseo_sendemail',
2828
+ array($metaseo_addon, 'loadPageSendEmail'),
2829
+ null
2830
+ );
2831
+
2832
+ $submenu_pages[] = array(
2833
+ 'metaseo_dashboard',
2834
+ esc_html__('Search Console', 'wp-meta-seo'),
2835
+ esc_html__('Search Console', 'wp-meta-seo'),
2836
+ $manage_options_cap,
2837
+ 'metaseo_console',
2838
+ array($metaseo_addon->admin_features['metaseo_gsc'], 'display'),
2839
+ null
2840
+ );
2841
+ }
2842
+
2843
+ $submenu_pages[] = array(
2844
+ 'metaseo_dashboard',
2845
+ '',
2846
+ esc_html__('Settings', 'wp-meta-seo'),
2847
+ $manage_options_cap,
2848
+ 'metaseo_settings',
2849
+ array($this, 'loadPage'),
2850
+ null
2851
  );
2852
 
2853
  // Allow submenu pages manipulation
2859
  // Add submenu page
2860
  $admin_page = add_submenu_page(
2861
  $submenu_page[0],
2862
+ $submenu_page[2] . ' - ' . esc_html__('WP Meta SEO:', 'wp-meta-seo'),
2863
  $submenu_page[2],
2864
  $submenu_page[3],
2865
  $submenu_page[4],
2867
  );
2868
 
2869
  // Check if we need to hook
2870
+ if (isset($submenu_page[6]) && null !== $submenu_page[6]
2871
  && is_array($submenu_page[6]) && count($submenu_page[6]) > 0) {
2872
  foreach ($submenu_page[6] as $submenu_page_action) {
2873
  add_action('load-' . $admin_page, $submenu_page_action);
2875
  }
2876
  }
2877
  }
 
 
 
 
 
2878
  }
2879
 
2880
  /**
2881
  * Set error time out
2882
+ *
2883
+ * @return void
2884
  */
2885
  public function setErrorTimeout()
2886
  {
2887
+ $midnight = strtotime('tomorrow 00:00:00'); // UTC midnight
2888
+ $midnight = $midnight + 8 * 3600; // UTC 8 AM
2889
  $this->error_timeout = $midnight - time();
 
2890
  }
2891
 
2892
  /**
2898
  {
2899
  try {
2900
  $ga_dash_profile_list = array();
2901
+ $startindex = 1;
2902
+ $totalresults = 65535; // use something big
2903
  while ($startindex < $totalresults) {
2904
  $profiles = $this->service->management_profiles->listManagementProfiles(
2905
  '~all',
2908
  'start-index' => $startindex
2909
  )
2910
  );
2911
+ $items = $profiles->getItems();
2912
 
2913
  $totalresults = $profiles->getTotalResults();
2914
 
2915
  if ($totalresults > 0) {
2916
  foreach ($items as $profile) {
2917
+ $timetz = new DateTimeZone($profile->getTimezone());
2918
+ $localtime = new DateTime('now', $timetz);
2919
+ $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
2920
  $ga_dash_profile_list[] = array(
2921
  $profile->getName(),
2922
  $profile->getId(),
2926
  $profile->getTimezone(),
2927
  $profile->getDefaultPage()
2928
  );
2929
+ $startindex ++;
2930
  }
2931
  }
2932
  }
2951
  } catch (Google_Service_Exception $e) {
2952
  WpmsGaTools::setCache(
2953
  'last_error',
2954
+ date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
2955
  $this->error_timeout
2956
  );
2957
  WpmsGaTools::setCache(
2972
 
2973
  /**
2974
  * Load the form for a WPSEO admin page
2975
+ *
2976
+ * @return void
2977
  */
2978
  public function loadPage()
2979
  {
2980
  if (isset($_GET['page'])) {
2981
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
2982
  switch ($_GET['page']) {
2983
  case 'metaseo_google_analytics':
2984
+ echo "<div class='error wpms_msg_ublock'><p>";
2985
+ esc_html_e('It seems that you use an adblocker, you need to
2986
  deactivate it for this page in order to load the Google Analytics scripts. ', 'wp-meta-seo');
2987
+ echo '</p></div>';
 
2988
  $this->google_alanytics = get_option('wpms_google_alanytics');
2989
  if (isset($_POST['_metaseo_ggtracking_settings'])) {
2990
+ if (empty($_POST['gadash_security'])
2991
+ || !wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
2992
+ die();
2993
+ }
2994
  update_option('_metaseo_ggtracking_settings', $_POST['_metaseo_ggtracking_settings']);
2995
  echo '<div id="setting-error-settings_updated"
2996
  class="updated settings-error notice is-dismissible">
2997
+ <p><strong>' . esc_html__('Settings saved.', 'wp-meta-seo') . '</strong></p><button type="button" class="notice-dismiss">
2998
  <span class="screen-reader-text">Dismiss this notice.</span></button></div>';
2999
  }
3000
 
3001
  if (!empty($_POST['tableid_jail'])) {
3002
+ if (empty($_POST['wpms_nonce'])
3003
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3004
+ die();
3005
+ }
3006
  $this->google_alanytics['tableid_jail'] = $_POST['tableid_jail'];
3007
  update_option('wpms_google_alanytics', $this->google_alanytics);
3008
  }
3015
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
3016
  wp_enqueue_style('m-style-qtip');
3017
  wp_enqueue_script('jquery-qtip');
3018
+ if (isset($_GET['view']) && $_GET['view'] === 'wpmsga_trackcode') {
3019
  wp_enqueue_style('wpms-backend-tracking-code');
3020
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/ga-trackcode.php');
3021
  } else {
3022
  wp_enqueue_style('wpms-backend-item-reports');
 
 
3023
  if (isset($_POST['wpmsga_dash_clientid']) && isset($_POST['wpmsga_dash_clientsecret'])) {
3024
+ if (empty($_POST['wpms_nonce'])
3025
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3026
+ die();
3027
+ }
3028
+ $this->google_alanytics['wpmsga_dash_clientid'] = $_POST['wpmsga_dash_clientid'];
3029
  $this->google_alanytics['wpmsga_dash_clientsecret'] = $_POST['wpmsga_dash_clientsecret'];
3030
  update_option('wpms_google_alanytics', $this->google_alanytics);
3031
  }
3039
  $this->client->setApplicationName('WP Meta SEO');
3040
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
3041
  $this->setErrorTimeout();
3042
+ $this->client = WpmsGaTools::setClient($this->client, $this->google_alanytics, $this->access);
3043
+ $authUrl = $this->client->createAuthUrl();
3044
  $this->service = new Google_Service_Analytics($this->client);
3045
+ $controller = new WpmsGapiController();
3046
 
3047
  if (!empty($_POST['wpms_ga_code'])) {
3048
+ $wpms_ga_code = $_POST['wpms_ga_code'];
3049
+ if (!stripos('x' . $wpms_ga_code, 'UA-', 1)) {
3050
  WpmsGaTools::deleteCache('gapi_errors');
3051
  WpmsGaTools::deleteCache('last_error');
3052
  WpmsGaTools::clearCache();
3053
  try {
3054
+ $this->client->authenticate($wpms_ga_code);
3055
  $getAccessToken = $this->client->getAccessToken();
3056
  if ($getAccessToken) {
3057
  try {
3067
  } catch (Google_Service_Exception $e) {
3068
  WpmsGaTools::setCache(
3069
  'wpmsga_dash_lasterror',
3070
+ date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
3071
  $this->error_timeout
3072
  );
3073
  WpmsGaTools::setCache(
3090
  $profiles = $this->refreshProfiles();
3091
  }
3092
 
3093
+ $this->google_alanytics['code'] = $wpms_ga_code;
3094
  $this->google_alanytics['googleCredentials'] = $getAccessToken;
3095
+ $this->google_alanytics['profile_list'] = $profiles;
3096
  update_option('wpms_google_alanytics', $this->google_alanytics);
3097
  } catch (Google_IO_Exception $e) {
3098
+ echo '';
3099
  } catch (Google_Service_Exception $e) {
3100
+ echo '';
3101
  } catch (Exception $e) {
3102
+ echo '';
3103
  }
3104
  } else {
3105
+ echo '<div class="error"><p>' . esc_html__('The access code is
3106
  <strong>NOT</strong> your <strong>Tracking ID</strong>
3107
+ (UA-XXXXX-X). Try again, and use the red link to get your access code', 'wp-meta-seo') . '.</p></div>';
3108
  }
3109
 
3110
  update_option('wpms_google_alanytics', $this->google_alanytics);
3112
  exit;
3113
  }
3114
  $this->gaDisconnect = array(
3115
+ 'wpms_ga_uax_reference' => '',
3116
  'wpmsga_dash_tracking_type' => 'classic',
3117
+ 'wpmsga_code_tracking' => ''
3118
  );
3119
+ $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
3120
  if (is_array($gaDisconnect)) {
3121
  $this->gaDisconnect = array_merge(
3122
  $this->gaDisconnect,
3123
  $gaDisconnect
3124
  );
3125
  }
3126
+
3127
  if (isset($_POST['_metaseo_ga_disconnect'])) {
3128
+ $_metaseo_ga_disconnect = $_POST['_metaseo_ga_disconnect'];
3129
  $_metaseo_ga_disconnect['wpmsga_code_tracking'] = stripslashes($_metaseo_ga_disconnect['wpmsga_code_tracking']);
3130
  update_option(
3131
  '_metaseo_ggtracking_disconnect_settings',
3143
  $this->google_alanytics = get_option('wpms_google_alanytics');
3144
  if (!empty($this->google_alanytics['googleCredentials'])) {
3145
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
3146
+ echo '<div class="error"><p>' . esc_html__('The tracking component is
3147
  disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
3148
+ ', 'wp-meta-seo') . '.</p></div>';
 
3149
  }
3150
  echo '<div class="wrap wpmsga_wrap">';
3151
  echo '<div>';
3152
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
3153
+ echo '<h2>' . esc_html__('Google Analytics Settings', 'wp-meta-seo') . '</h2>';
3154
  echo '<div id="wpms-window-1"></div>';
3155
  echo '</div>';
3156
  echo '</div>';
3157
  } else {
3158
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
3159
+ echo '<div class="error"><p>' . esc_html__('The tracking component is disabled.
3160
  You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
3161
+ ', 'wp-meta-seo') . '.</p></div>';
 
3162
  }
3163
 
3164
  if (isset($this->google_alanytics['wpmsga_dash_userapi'])
3165
+ && (int) $this->google_alanytics['wpmsga_dash_userapi'] === 1) {
3166
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/form-connect.php');
3167
  } else {
3168
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/google-analytics.php');
3170
  }
3171
  }
3172
 
3173
+ $w = '99%';
3174
+ $text = esc_html__('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report,
3175
  Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo');
3176
  $class_btn_close = 'close_gga';
3177
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
3203
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php');
3204
  break;
3205
  case 'metaseo_settings':
3206
+ $posts = get_posts(array('post_type' => 'page', 'posts_per_page' => - 1, 'numberposts' => - 1));
3207
  $types_404 = array(
3208
+ 'none' => 'None',
3209
+ 'wp-meta-seo-page' => esc_html__('WP Meta SEO page', 'wp-meta-seo'),
3210
+ 'custom_page' => esc_html__('Custom page', 'wp-meta-seo')
3211
  );
3212
 
3213
  // get settings 404
3214
  $defaul_settings_404 = array(
3215
  'wpms_redirect_homepage' => 0,
3216
+ 'wpms_type_404' => 'none',
3217
+ 'wpms_page_redirected' => 'none'
3218
  );
3219
+ $wpms_settings_404 = get_option('wpms_settings_404');
3220
  if (is_array($wpms_settings_404)) {
3221
  $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404);
3222
  }
3226
  if (empty($home_title)) {
3227
  $home_title = get_bloginfo('title');
3228
  }
3229
+ $breadcrumbs = array(
3230
+ 'separator' => ' &gt; ',
3231
+ 'include_home' => 1,
3232
+ 'home_text' => $home_title,
3233
  'home_text_default' => 0,
3234
+ 'clickable' => 1
3235
  );
3236
  $breadcrumb_settings = get_option('_metaseo_breadcrumbs');
3237
  if (is_array($breadcrumb_settings)) {
3240
 
3241
  // email settings
3242
  $email_settings = array(
3243
+ 'enable' => 0,
3244
+ 'host' => 'smtp.gmail.com',
3245
+ 'type_encryption' => 'ssl',
3246
+ 'port' => '465',
3247
+ 'autentication' => 'yes',
3248
+ 'username' => '',
3249
+ 'password' => '',
3250
  );
3251
 
3252
  $mailsettings = get_option('wpms_email_settings');
3258
 
3259
  // link settings
3260
  $link_settings = array(
3261
+ 'enable' => 0,
3262
+ 'numberFrequency' => 1,
3263
+ 'showlinkFrequency' => 'month'
3264
  );
3265
 
3266
  $linksettings = get_option('wpms_link_settings');
3272
 
3273
  // local business settings
3274
  $local_business = array(
3275
+ 'enable' => 0,
3276
+ 'logo' => '',
3277
+ 'type_name' => '',
3278
+ 'country' => '',
3279
+ 'address' => '',
3280
+ 'city' => '',
3281
+ 'state' => '',
3282
+ 'phone' => '',
3283
+ 'pricerange' => '$$'
3284
  );
3285
 
3286
  $business = get_option('wpms_local_business');
3287
  if (is_array($business)) {
3288
  $local_business = array_merge($local_business, $business);
3289
  }
3290
+ $countrys = apply_filters('wpms_get_countryList', array());
3291
  $local_business_html = apply_filters('wpmsaddon_local_business', '', $local_business, $countrys);
3292
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php');
3293
  break;
3319
 
3320
  /**
3321
  * Ajax check attachment have alt empty
3322
+ *
3323
+ * @return void
3324
  */
3325
  public function checkExist()
3326
  {
3327
+ if (empty($_POST['wpms_nonce'])
3328
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3329
+ die();
3330
+ }
3331
+
3332
  if (isset($_POST['type'])) {
3333
+ if ($_POST['type'] === 'alt') {
3334
  $margs = array(
3335
+ 'posts_per_page' => - 1,
3336
+ 'post_type' => 'attachment',
3337
+ 'post_status' => 'any',
3338
+ 'meta_query' => array(
3339
  'relation' => 'OR',
3340
  array(
3341
+ 'key' => '_wp_attachment_image_alt',
3342
+ 'value' => '',
3343
  'compare' => '!='
3344
+ )
3345
  )
3346
  );
3347
 
3348
+ $m_newquery = new WP_Query($margs);
3349
  $mposts_empty_alt = $m_newquery->get_posts();
3350
  if (!empty($mposts_empty_alt)) {
3351
  wp_send_json(true);
3354
  }
3355
  } else {
3356
  global $wpdb;
3357
+ $check_title = $wpdb->get_var('SELECT COUNT(posts.ID) as total FROM ' . $wpdb->prefix . 'posts as posts
3358
+ WHERE posts.post_type = "attachment" AND post_title != ""');
 
 
 
 
3359
  if ($check_title > 0) {
3360
  wp_send_json(true);
3361
  } else {
3367
 
3368
  /**
3369
  * Ajax update image alt and image title
3370
+ *
3371
+ * @return void
3372
  */
3373
  public function bulkImageCopy()
3374
  {
3375
+ if (empty($_POST['wpms_nonce'])
3376
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3377
+ die();
3378
+ }
3379
+
3380
  global $wpdb;
3381
  if (empty($_POST['mtype'])) {
3382
  wp_send_json(false);
3383
  }
3384
 
3385
+ if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] === 'all') {
3386
  // select all
3387
  $limit = 500;
3388
  // query attachment and update meta
3389
+ $total = $wpdb->get_var('SELECT COUNT(posts.ID) as total FROM ' . $wpdb->prefix . 'posts as posts
3390
+ WHERE posts.post_type = "attachment"');
 
 
 
 
3391
 
3392
+ $j = ceil((int) $total / $limit);
3393
+ for ($i = 0; $i <= $j; $i ++) {
3394
+ $ofset = $i * $limit;
3395
+ $attachments = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'posts as posts
3396
+ WHERE posts.post_type = %s LIMIT %d OFFSET %d', array('attachment', $limit, $ofset)));
 
3397
 
3398
  foreach ($attachments as $attachment) {
3399
  $i_info_url = pathinfo($attachment->guid);
3413
  } else {
3414
  // selected
3415
  if (isset($_POST['ids'])) {
3416
+ $ids = $_POST['ids'];
3417
  $margs = array(
3418
+ 'posts_per_page' => - 1,
3419
+ 'post_type' => 'attachment',
3420
+ 'post_status' => 'any',
3421
+ 'post__in' => $ids
3422
  );
3423
 
3424
+ $m_newquery = new WP_Query($margs);
3425
+ $mposts_empty_alt = $m_newquery->get_posts();
3426
+ $mposts_empty_title = $wpdb->get_results($wpdb->prepare('SELECT *
3427
+ FROM ' . $wpdb->posts . ' WHERE post_type = %s
3428
+ AND post_mime_type LIKE %s AND ID IN (' . implode(',', esc_sql($ids)) . ')
3429
+ ', array('attachment', '%image%')));
 
 
 
3430
  switch ($_POST['mtype']) {
3431
  case 'image_alt':
3432
  if (!empty($mposts_empty_alt)) {
3459
 
3460
  /**
3461
  * Ajax bulk update meta title for a post/page
3462
+ *
3463
+ * @return void
3464
  */
3465
  public function bulkPostCopyTitle()
3466
  {
3467
+ if (empty($_POST['wpms_nonce'])
3468
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3469
+ die();
3470
+ }
3471
+
3472
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
3473
  unset($post_types['attachment']);
3474
  $margs = array();
3475
+ if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] === 'all') { // for select a;;
3476
  $margs = array(
3477
+ 'posts_per_page' => - 1,
3478
+ 'post_type' => $post_types,
3479
+ 'post_status' => array(
3480
  'publish',
3481
  'pending',
3482
  'draft',
3486
  'inherit',
3487
  'trash'
3488
  ),
3489
+ 'meta_query' => array(
3490
  'relation' => 'OR',
3491
  array(
3492
+ 'key' => '_metaseo_metatitle',
3493
  'compare' => 'NOT EXISTS',
3494
  ),
3495
  array(
3496
+ 'key' => '_metaseo_metatitle',
3497
  'value' => false,
3498
+ 'type' => 'BOOLEAN'
3499
  ),
3500
+ )
3501
+ );
3502
  } else { // for select some post
3503
  if (isset($_POST['ids'])) {
3504
+ $ids = $_POST['ids'];
3505
  $margs = array(
3506
+ 'posts_per_page' => - 1,
3507
+ 'post_type' => $post_types,
3508
+ 'post_status' => array(
3509
  'publish',
3510
  'pending',
3511
  'draft',
3515
  'inherit',
3516
  'trash'
3517
  ),
3518
+ 'post__in' => $ids,
3519
+ 'meta_query' => array(
3520
  'relation' => 'OR',
3521
  array(
3522
+ 'key' => '_metaseo_metatitle',
3523
  'compare' => 'NOT EXISTS',
3524
  ),
3525
  array(
3526
+ 'key' => '_metaseo_metatitle',
3527
  'value' => false,
3528
+ 'type' => 'BOOLEAN'
3529
  ),
3530
+ )
3531
+ );
3532
  } else {
3533
  wp_send_json(false);
3534
  }
3535
  }
3536
 
3537
  $m_newquery = new WP_Query($margs);
3538
+ $mposts = $m_newquery->get_posts();
3539
  if (!empty($mposts)) {
3540
  foreach ($mposts as $post) {
3541
  update_post_meta($post->ID, '_metaseo_metatitle', $post->post_title);
3547
  }
3548
 
3549
  /**
3550
+ * Set cookie notification
3551
+ *
3552
+ * @return void
3553
  */
3554
  public function setcookieNotification()
3555
  {
3556
+ if (empty($_POST['wpms_nonce'])
3557
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3558
+ die();
3559
+ }
3560
+
3561
  if (isset($_POST['page'])) {
3562
+ setcookie($_POST['page'], time(), time() + (86400 * 30), '/');
3563
  wp_send_json(true);
3564
  }
3565
  wp_send_json(false);
3567
 
3568
  /**
3569
  * Run ajax
3570
+ *
3571
+ * @return void
3572
  */
3573
  public function startProcess()
3574
  {
3575
+ if (empty($_POST['wpms_nonce']) || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
3576
+ die();
3577
+ }
3578
+
3579
  if (isset($_REQUEST['task'])) {
3580
  switch ($_REQUEST['task']) {
3581
  case 'updateContentMeta':
inc/class.metaseo-broken-link-table.php CHANGED
@@ -12,18 +12,20 @@ if (!class_exists('WP_List_Table')) {
12
  class MetaSeoBrokenLinkTable extends WP_List_Table
13
  {
14
  /**
15
- * @var array
16
- */
17
- public $link_view = array();
18
- /**
19
  * @var string
20
  */
21
  public static $img_pattern = '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i';
22
  /**
 
 
23
  * @var string
24
  */
25
  public static $old_url = '';
26
  /**
 
 
27
  * @var string
28
  */
29
  public static $new_url = '';
@@ -35,50 +37,50 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
35
  {
36
  parent::__construct(array(
37
  'singular' => 'metaseo_image',
38
- 'plural' => 'metaseo_images',
39
- 'ajax' => true
40
  ));
41
  }
42
 
43
  /**
44
  * Generate the table navigation above or below the table
45
- * @param string $which
 
 
 
46
  */
47
- protected function display_tablenav($which)
48
  {
49
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
50
  if (!empty($post_types['attachment'])) {
51
  unset($post_types['attachment']);
52
  }
53
  ?>
54
- <div class="tablenav <?php echo esc_attr($which); ?>">
55
 
56
- <?php if ($which == 'top') : ?>
57
  <input type="hidden" name="page" value="metaseo_image_meta"/>
58
 
59
  <div class="alignleft actions bulkactions">
60
- <?php $this->brokenFillter('sl_broken'); ?>
61
- <?php $this->redirectFillter('sl_redirect'); ?>
62
- <?php $this->typeFillter('sltype'); ?>
63
- <?php $this->flushFillter('sl_flush'); ?>
64
  </div>
65
- <?php elseif ($which == 'bottom') : ?>
66
  <input type="hidden" name="page" value="metaseo_image_meta"/>
67
  <div class="alignleft actions bulkactions">
68
- <?php $this->brokenFillter('sl_broken1'); ?>
69
- <?php $this->redirectFillter('sl_redirect1'); ?>
70
- <?php $this->flushFillter('sltype1'); ?>
71
  </div>
72
  <?php endif ?>
73
 
74
  <input type="hidden" name="page" value="metaseo_image_meta"/>
75
- <?php if (!empty($_REQUEST['post_status'])) : ?>
76
- <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
77
- <?php endif ?>
78
-
79
  <div style="float:right;margin-left:8px;">
80
  <label>
81
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>"
 
82
  maxlength="3" name="metaseo_broken_link_per_page"
83
  class="metaseo_imgs_per_page screen-per-page"
84
  max="999" min="1" step="1">
@@ -86,7 +88,6 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
86
 
87
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
88
  </div>
89
-
90
  <?php $this->pagination($which); ?>
91
  <br class="clear"/>
92
  </div>
@@ -97,17 +98,20 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
97
  /**
98
  * Get a list of columns. The format is:
99
  * 'internal-name' => 'Title'
 
100
  * @return array
101
  */
102
- public function get_columns()
103
  {
104
- return $columns = array(
105
- 'col_link_url' => __('URL', 'wp-meta-seo'),
106
- 'col_hit' => __('Hits number', 'wp-meta-seo'),
107
- 'col_status' => __('Status', 'wp-meta-seo'),
108
- 'col_link_text' => __('Type or Link text', 'wp-meta-seo'),
109
- 'col_source' => __('Source', 'wp-meta-seo')
110
  );
 
 
111
  }
112
 
113
  /**
@@ -117,61 +121,63 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
117
  * 'internal-name' => array( 'orderby', true )
118
  *
119
  * The second format will make the initial sorting order be descending
 
120
  * @return array
121
  */
122
- protected function get_sortable_columns()
123
  {
124
- return $sortable = array(
125
- 'col_status' => array('status_text', true),
126
  'col_link_url' => array('link_url', true)
127
  );
 
 
128
  }
129
 
130
  /**
131
  * Print column headers, accounting for hidden and sortable columns.
132
  *
133
- * @since 3.1.0
134
- * @access public
135
  *
136
- * @param bool $with_id Whether to set the id attribute or not
137
  */
138
- public function print_column_headers($with_id = true)
139
  {
140
  list($columns, $hidden, $sortable) = $this->get_column_info();
141
 
142
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
143
  $current_url = remove_query_arg('paged', $current_url);
144
 
 
145
  if (isset($_GET['orderby'])) {
146
  $current_orderby = $_GET['orderby'];
147
  } else {
148
  $current_orderby = '';
149
  }
150
 
151
- if (isset($_GET['order']) && 'desc' == $_GET['order']) {
152
  $current_order = 'desc';
153
  } else {
154
  $current_order = 'asc';
155
  }
156
-
157
  if (!empty($columns['cb'])) {
158
  static $cb_counter = 1;
159
  $columns['cb'] = '<label class="screen-reader-text"
160
- for="cb-select-all-' . $cb_counter . '">' . __('Select All', 'wp-meta-seo') . '</label>'
161
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
162
- $cb_counter++;
163
  }
164
 
165
  foreach ($columns as $column_key => $column_display_name) {
166
- $class = array('manage-column', "column-$column_key");
167
 
168
  $style = '';
169
  if (in_array($column_key, $hidden)) {
170
- $style = 'display:none;';
171
  }
172
- $style = ' style="' . $style . '"';
173
 
174
- if ('cb' == $column_key) {
175
  $class[] = 'check-column';
176
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
177
  $class[] = 'num';
@@ -180,114 +186,99 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
180
  if (isset($sortable[$column_key])) {
181
  list($orderby, $desc_first) = $sortable[$column_key];
182
 
183
- if ($current_orderby == $orderby) {
184
- $order = 'asc' == $current_order ? 'desc' : 'asc';
185
  $class[] = 'sorted';
186
  $class[] = $current_order;
187
  } else {
188
- $order = $desc_first ? 'desc' : 'asc';
189
  $class[] = 'sortable';
190
  $class[] = $desc_first ? 'asc' : 'desc';
191
  }
192
 
193
- $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
194
- $column_name = '<a href="' . $hr . '">';
195
- $column_name .= '<span>' . $column_display_name . '</span>';
196
- $column_name .= '<span class="sorting-indicator"></span>';
197
- $column_name .= '</a>';
198
  }
199
 
200
- $id = $with_id ? "id='$column_key'" : '';
201
 
202
  if (!empty($class)) {
203
- $class = "class='" . join(' ', $class) . "'";
204
  }
205
 
 
206
  if ($column_key === 'cb') {
207
- echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
208
  } else {
209
- echo "<th scope='col' $id $class $style colspan=\"3\">$column_display_name</th>";
210
  }
 
211
  }
212
  }
213
 
214
  /**
215
  * Prepares the list of items for displaying.
216
- * @uses WP_List_Table::set_pagination_args()
 
217
  */
218
- public function prepare_items()
219
  {
220
  global $wpdb;
221
  $where = array('1=1');
222
- if (!empty($_REQUEST['sltype']) && $_REQUEST['sltype'] != 'all') {
223
- if ($_REQUEST['sltype'] != 'other') {
224
- $where[] = "type = '" . $_REQUEST['sltype'] . "'";
 
225
  } else {
226
  $where[] = "type IN ('comment','404_automaticaly')";
227
  }
228
  }
229
 
230
- if (!empty($_REQUEST['sl_broken']) && $_REQUEST['sl_broken'] != 'all') {
231
- if ($_REQUEST['sl_broken'] == 'custom_redirect_url') {
232
  $where[] = "link_url_redirect !=''";
233
- } elseif ($_REQUEST['sl_broken'] == 'valid_links') {
234
- $where[] = "broken_internal = 0 AND broken_indexed = 0";
235
- } elseif ($_REQUEST['sl_broken'] == 'internal_broken_links') {
236
- $where[] = "broken_internal = 1";
237
  } else {
238
- $where[] = "broken_indexed = 1";
239
  }
240
  }
241
 
242
- if (!empty($_REQUEST['sl_redirect']) && $_REQUEST['sl_redirect'] != 'all') {
243
- if ($_REQUEST['sl_redirect'] == 'already_redirect') {
244
- $where[] = "(broken_internal = 1 OR broken_indexed = 1)";
245
- $where[] = "link_url_redirect !='' ";
246
  } else {
247
- $where[] = "(broken_internal = 1 OR broken_indexed = 1)";
248
- $where[] = "link_url_redirect ='' ";
249
  }
250
  }
251
 
252
- $keyword = !empty($_GET["txtkeyword"]) ? $_GET["txtkeyword"] : '';
253
- if (isset($keyword) && $keyword != '') {
254
- $where[] .= '(link_text LIKE "%' . $keyword . '%" OR link_url LIKE "%' . $keyword . '%")';
255
- }
256
-
257
- $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
258
- $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
259
- $sortable = $this->get_sortable_columns();
260
- $orderby_array = array($orderby, true);
261
- if (in_array($orderby_array, $sortable)) {
262
- $orderStr = $orderby;
263
- } else {
264
- $orderStr = 'id';
265
  }
266
 
267
- if ($order == "asc") {
268
- $orderStr .= " ASC";
269
- } else {
270
- $orderStr .= " DESC";
271
- }
272
-
273
- if (!empty($orderby) & !empty($order)) {
274
- $orderStr = $wpdb->prepare(' ORDER BY %s ', $orderStr);
275
- $orderStr = str_replace("'", "", $orderStr);
276
  }
277
 
278
- $query = "SELECT COUNT(id) FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
279
- $total_items = $wpdb->get_var($query);
280
- $columns = $this->get_columns();
281
- $hidden = array();
282
- $sortable = $this->get_sortable_columns();
283
- $this->_column_headers = array($columns, $hidden, $sortable);
284
- $query = "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
285
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
286
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
287
  } else {
288
  $_per_page = 0;
289
  }
290
-
291
  $per_page = get_user_option('metaseo_broken_link_per_page');
292
  if ($per_page !== false) {
293
  if ($_per_page && $_per_page !== $per_page) {
@@ -303,41 +294,65 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
303
  add_user_meta(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
304
  }
305
 
306
- $paged = !empty($_GET["paged"]) ? $_GET["paged"] : '';
307
- if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
308
- $paged = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  }
310
 
 
 
 
 
 
 
 
 
311
  $total_pages = ceil($total_items / $per_page);
312
 
313
  if (!empty($paged) && !empty($per_page)) {
314
  $offset = ($paged - 1) * $per_page;
315
- $query .= ' LIMIT ' . (int)$offset . ',' . (int)$per_page;
316
  }
317
 
318
  $this->set_pagination_args(array(
319
  'total_items' => $total_items,
320
  'total_pages' => $total_pages,
321
- 'per_page' => $per_page
322
  ));
323
 
324
-
325
  $this->items = $wpdb->get_results($query);
326
  }
327
 
328
  /**
329
  * Displays the search box.
 
 
330
  */
331
  public function searchBox1()
332
  {
333
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
334
  require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/custom_redirect_form.php');
335
  }
 
336
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
337
  return;
338
  }
339
 
340
- $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
341
  if (!empty($_REQUEST['orderby'])) {
342
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
343
  }
@@ -353,7 +368,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
353
  if (!empty($_REQUEST['detached'])) {
354
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
355
  }
356
-
357
  ?>
358
  <p class="search-box">
359
  <label>
@@ -367,29 +382,33 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
367
  }
368
 
369
  /**
370
- * Add fillter redirect
371
- * @param $name
 
 
 
372
  */
373
- public function redirectFillter($name)
374
  {
375
  $redirects = array(
376
- 'not_yet_redirect' => __('Not yet redirected', 'wp-meta-seo'),
377
- 'already_redirect' => __('Already redirected', 'wp-meta-seo')
378
  );
 
379
  $curent_redirect = isset($_REQUEST['sl_redirect']) ? $_REQUEST['sl_redirect'] : 'all';
380
  ?>
381
  <label for="filter-by-redirect"
382
- class="screen-reader-text"><?php _e('Filter by redirect', 'wp-meta-seo'); ?></label>
383
- <select name="<?php echo $name ?>" id="filter-by-redirect" class="redirect_fillter">
384
  <option<?php selected($curent_redirect, 'all'); ?> value="all">
385
- <?php _e('Status', 'wp-meta-seo'); ?>
386
  </option>
387
  <?php
388
  foreach ($redirects as $k => $redirect) {
389
- if ($curent_redirect == $k) {
390
- echo '<option selected value="' . $k . '">' . $redirect . '</option>';
391
  } else {
392
- echo '<option value="' . $k . '">' . $redirect . '</option>';
393
  }
394
  }
395
  ?>
@@ -399,30 +418,36 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
399
  }
400
 
401
  /**
402
- * Add fillter broken
403
- * @param string $name selectbox name
 
 
 
404
  */
405
- public function brokenFillter($name)
406
  {
407
  $brokens = array(
408
- 'valid_links' => __('Valid links', 'wp-meta-seo'),
409
- 'automaticaly_indexed' => __('404 automaticaly indexed', 'wp-meta-seo'),
410
- 'internal_broken_links' => __('Internal broken links', 'wp-meta-seo')
411
  );
412
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
413
- $brokens['custom_redirect_url'] = __('Custom redirect URL', 'wp-meta-seo');
414
  }
 
415
  $curent_broken = isset($_REQUEST['sl_broken']) ? $_REQUEST['sl_broken'] : 'all';
416
  ?>
417
- <label for="filter-by-broken" class="screen-reader-text"><?php _e('Filter by broken', 'wp-meta-seo'); ?></label>
418
- <select name="<?php echo $name ?>" id="filter-by-broken" class="broken_fillter">
419
- <option<?php selected($curent_broken, 'all'); ?> value="all"><?php _e('All', 'wp-meta-seo'); ?></option>
 
 
420
  <?php
421
  foreach ($brokens as $k => $broken) {
422
- if ($curent_broken == $k) {
423
- echo '<option selected value="' . $k . '">' . $broken . '</option>';
424
  } else {
425
- echo '<option value="' . $k . '">' . $broken . '</option>';
426
  }
427
  }
428
  ?>
@@ -432,86 +457,98 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
432
  }
433
 
434
  /**
435
- * Add fillter type
436
- * @param $name
 
 
 
437
  */
438
- public function typeFillter($name)
439
  {
440
  $types = array(
441
- 'url' => __('URL', 'wp-meta-seo'),
442
- 'image' => __('Image', 'wp-meta-seo'),
443
- 'other' => __('Other', 'wp-meta-seo')
444
  );
 
445
  $curent_type = isset($_REQUEST['sltype']) ? $_REQUEST['sltype'] : 'all';
446
  ?>
447
- <label for="filter-by-type" class="screen-reader-text"><?php _e('Filter by type', 'wp-meta-seo'); ?></label>
448
- <select name="<?php echo $name ?>" id="filter-by-type" class="metaseo-filter">
449
- <option<?php selected($curent_type, 'all'); ?> value="all"><?php _e('Type', 'wp-meta-seo'); ?></option>
 
 
450
  <?php
451
  foreach ($types as $k => $type) {
452
- if ($curent_type == $k) {
453
- echo '<option selected value="' . $k . '">' . $type . '</option>';
454
  } else {
455
- echo '<option value="' . $k . '">' . $type . '</option>';
456
  }
457
  }
458
  ?>
459
  </select>
460
  <input type="submit" name="filter_type_action" id="broken-submit"
461
- class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="<?php _e('Filter', 'wp-meta-seo') ?>">
462
  <?php
463
  echo '<div style="float:left;padding-left: 5px;"><div class="wpms_process" data-w="0"></div>';
464
  echo '<div data-comment_paged="1" data-paged="1" class="wpmsbtn wpmsbtn_small wpms_scan_link">';
465
- echo __('Index internal broken links', 'wp-meta-seo');
466
  echo '</div></div>';
467
  echo '<span class="spinner"></span>';
468
  }
469
 
470
  /**
471
- * Add fillter flush
472
- * @param $name
 
 
 
473
  */
474
- public function flushFillter($name)
475
  {
476
  $flushs = array(
477
- 'automaticaly_indexed' => __('Automatic indexed 404', 'wp-meta-seo'),
478
- 'internal_broken_links' => __('Internal broken links', 'wp-meta-seo'),
479
- 'all' => __('Flush all 404', 'wp-meta-seo')
480
  );
481
  ?>
482
- <label for="filter-by-flush" class="screen-reader-text"><?php _e('Filter by flush', 'wp-meta-seo'); ?></label>
483
- <select name="<?php echo $name ?>" id="filter-by-flush">
484
- <option value="none"><?php _e('Select', 'wp-meta-seo'); ?></option>
 
485
  <?php
486
  foreach ($flushs as $k => $flush) {
487
- echo '<option value="' . $k . '">' . $flush . '</option>';
488
  }
489
  ?>
490
  </select>
491
 
492
  <?php
493
  echo '<div class="wpmsbtn wpmsbtn_small wpmsbtn_secondary wpms_flush_link">';
494
- echo __('Flush', 'wp-meta-seo');
495
  echo '</div>';
496
  }
497
 
498
  /**
499
  * Generate the table rows
 
 
500
  */
501
- public function display_rows()
502
  {
503
  $records = $this->items;
504
- $i = 0;
505
  list($columns, $hidden) = $this->get_column_info();
506
  if (!empty($records)) {
507
  foreach ($records as $rec) {
508
- $i++;
509
- echo '<tr id="record_' . $i . '" data-linkid="' . $rec->id . '"
510
- data-link="' . $i . '" data-post_id="' . $rec->source_id . '">';
511
  foreach ($columns as $column_name => $column_display_name) {
512
  switch ($column_name) {
513
  case 'col_link_url':
514
- if ($rec->type == 'url') {
515
  $value_url = $rec->link_final_url;
516
  } else {
517
  $value_url = $rec->link_url;
@@ -519,47 +556,49 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
519
  echo '<td class="wpms_link_html" colspan="3">';
520
  echo '<input type="hidden" class="wpms_link_text"
521
  value="' . esc_attr($rec->link_text) . '">';
522
- if ($rec->type == 'add_custom') {
523
  echo '<a class="link_html" target="_blank"
524
- href="' . esc_url(site_url() . '/' . $rec->link_url) . '">' . $value_url . '</a>';
525
- if ($rec->link_url_redirect != '') {
526
  echo ' to ';
527
  echo '<a class="link_html" target="_blank"
528
  href="' . esc_url($rec->link_url_redirect) . '"
529
- >' . str_replace(site_url(), '', $rec->link_url_redirect) . '</a>';
530
  }
531
  } else {
532
  echo '<a class="link_html" target="_blank"
533
- href="' . esc_url($value_url) . '">' . $value_url . '</a>';
534
  }
535
 
536
  $row_action = array(
537
- 'edit' => '<a class="wpms_action_link wpms-edit-button"
538
- title="' . __('Edit redirect', 'wp-meta-seo') . '">
539
  <div class="wpms_icon_action"><i class="material-icons">mode_edit</i></div>
540
- <span>' . __('Edit', 'wp-meta-seo') . '</span></a>',
541
- 'delete' => '<a class="wpms_action_link submitdelete wpms-unlink-button"
542
- data-link_id="' . $rec->id . '" data-type="' . $rec->type . '"
543
- data-source_id="' . $rec->source_id . '"
544
- title="' . __('Remove redirect or link', 'wp-meta-seo') . '">
545
  <div class="wpms_icon_action"><i class="material-icons">delete_forever</i></div>
546
- <span>' . __('Remove redirect', 'wp-meta-seo') . '</span></a>',
547
  'recheck' => '<a class="wpms_action_link wpms-recheck-button"
548
- data-link_id="' . $rec->id . '" data-type="' . $rec->type . '"
549
- data-source_id="' . $rec->source_id . '"
550
- title="' . __('Check the link', 'wp-meta-seo') . '">
551
  <div class="wpms_icon_action"><i class="material-icons">loop</i></div>
552
- <span>' . __('Check', 'wp-meta-seo') . '</span></a>'
553
  );
 
 
554
  echo $this->row_actions($row_action, false);
555
  $iii = 0;
556
  $jjj = 0;
557
  if (!empty($rec->source_id)) {
558
- if ($rec->type == 'url') {
559
  $pos = get_post($rec->source_id);
560
  if (!empty($pos)) {
561
  preg_match_all(
562
- "#<a[^>]*>.*?</a>#si",
563
  $pos->post_content,
564
  $matches,
565
  PREG_PATTERN_ORDER
@@ -567,16 +606,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
567
  foreach ($matches[0] as $i => $content) {
568
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
569
  $href = $matches[1];
570
- if ($href == $rec->link_url) {
571
- $iii++;
572
  }
573
  }
574
  }
575
- } elseif ($rec->type == 'comment_content_url') {
576
  $com = get_comment($rec->source_id);
577
  if (!empty($pos)) {
578
  preg_match_all(
579
- "#<a[^>]*>.*?</a>#si",
580
  $com->comment_content,
581
  $matches,
582
  PREG_PATTERN_ORDER
@@ -584,8 +623,8 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
584
  foreach ($matches[0] as $i => $content) {
585
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
586
  $href = $matches[1];
587
- if ($href == $rec->link_url) {
588
- $jjj++;
589
  }
590
  }
591
  }
@@ -593,42 +632,42 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
593
  }
594
  ?>
595
  <div class="wpms-inline-editor-content">
596
- <h4><?php echo _x('Edit Link', 'inline editor title', 'wp-meta-seo'); ?></h4>
597
  <?php
598
- if ($rec->type == 'url') {
599
  if ($iii > 1) {
600
  echo '<span class="wpms-input-text-wrap">
601
- <span class="title">' . __('Text', 'wp-meta-seo') . '</span>
602
  <input type="text" name="link_text" class="wpms-link-text-field"
603
- placeholder="' . __('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
604
  } else {
605
  echo '<span class="wpms-input-text-wrap">
606
- <span class="title">' . __('Text', 'wp-meta-seo') . '</span>
607
  <input type="text" name="link_text" class="wpms-link-text-field"
608
  value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
609
  }
610
- } elseif ($rec->type == 'comment_content_url') {
611
  if ($jjj > 1) {
612
  echo '<span class="wpms-input-text-wrap">
613
- <span class="title">' . __('Text', 'wp-meta-seo') . '</span>
614
  <input type="text" name="link_text" class="wpms-link-text-field"
615
- placeholder="' . __('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
616
  } else {
617
  echo '<span class="wpms-input-text-wrap">
618
- <span class="title">' . __('Text', 'wp-meta-seo') . '</span>
619
  <input type="text" name="link_text" class="wpms-link-text-field"
620
  value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
621
  }
622
  } else {
623
- if ($rec->type != 'add_custom') {
624
  echo '<span class="wpms-input-text-wrap">
625
- <span class="title">' . __('Text', 'wp-meta-seo') . '</span>
626
  <input readonly type="text" name="link_text" class="wpms-link-text-field" value="(None)" data-type="only" /></span>';
627
  } else {
628
  ?>
629
  <p class="wpms-input-text-wrap">
630
  <span class="title">
631
- <?php _e('Status', 'wp-meta-seo') ?>
632
  </span>
633
  <label>
634
  <select name="custom_redirect_status" class="custom_redirect_status">
@@ -649,16 +688,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
649
  <p class="wpms-input-text-wrap">
650
  <span
651
  class="title">
652
- <?php _e('URL', 'wp-meta-seo'); ?>
653
  </span>
654
  <label>
655
- <input <?php echo ($rec->type == '404_automaticaly') ? 'readonly' : '' ?>
656
  type="text" name="link_url" class="wpms-link-url-field"
657
  value="<?php echo esc_attr($value_url); ?>"/>
658
  </label>
659
  </p>
660
  <p class="wpms-input-text-wrap">
661
- <span class="title"><?php _e('Redirect', 'wp-meta-seo'); ?></span>
662
  <label>
663
  <input type="text" name="link_url_redirect" class="wpms-link-redirect-field"
664
  value="<?php echo esc_attr($rec->link_url_redirect); ?>"/>
@@ -673,9 +712,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
673
  class="wpmsbtn wpmsbtn_small wpmsbtn_secondary
674
  cancel alignleft wpms-cancel-button"
675
  value="<?php echo esc_attr(__('Cancel', 'wp-meta-seo')); ?>"/>
676
- <input type="button" data-type="<?php echo $rec->type ?>"
677
- data-link_id="<?php echo $rec->id ?>"
678
- data-source_id="<?php echo $rec->source_id ?>"
679
  class="wpmsbtn wpmsbtn_small save alignright wpms-update-link-button"
680
  value="<?php echo esc_attr(__('Add custom redirect', 'wp-meta-seo')); ?>"/>
681
  </div>
@@ -686,51 +725,51 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
686
 
687
  case 'col_hit':
688
  echo '<td colspan="3" style="text-align:center;">';
689
- echo $rec->hit;
690
  echo '</td>';
691
  break;
692
  case 'col_status':
693
  echo '<td colspan="3" class="col_status">';
694
  if (strpos($rec->status_text, '200') !== false) {
695
- echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Link is OK">done</i>';
696
  } elseif (strpos($rec->status_text, '301') !== false) {
697
  echo '<i class="material-icons wpms_ok metaseo_help_status"
698
- alt="Permanent redirect">done</i>';
699
  } elseif (strpos($rec->status_text, '302') !== false) {
700
  echo '<i class="material-icons wpms_ok metaseo_help_status"
701
- alt="Moved temporarily">done</i>';
702
  } elseif (strpos($rec->status_text, '404') !== false
703
- || $rec->status_text == 'Server Not Found') {
704
  $wpms_settings_404 = get_option('wpms_settings_404');
705
  if ((isset($wpms_settings_404['wpms_redirect_homepage'])
706
- && $wpms_settings_404['wpms_redirect_homepage'] == 1)
707
- || $rec->link_url_redirect != '') {
708
  echo '<i class="material-icons wpms_ok metaseo_help_status"
709
- alt="Permanent redirect">done</i>';
710
  } else {
711
  echo '<i class="material-icons wpms_warning metaseo_help_status"
712
- alt="404 error, not found">warning</i>';
713
  }
714
  } else {
715
- echo $rec->status_text;
716
  }
717
 
718
  echo '</td>';
719
  break;
720
 
721
  case 'col_link_text':
722
- if ($rec->type == 'image' || $rec->type == 'comment_content_image') {
723
  echo '<td colspan="3" class="link_text">
724
- <span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="Images">photo</i></span>
725
- <span> ' . __('Image', 'wp-meta-seo') . '</span></td>';
726
- } elseif ($rec->type == 'comment') {
727
- echo '<td colspan="3" class="link_text"><span> ' . $rec->link_text . '</span></td>';
728
  } else {
729
- if (strip_tags($rec->link_text) != '') {
730
- echo '<td colspan="3" class="link_text">' . strip_tags($rec->link_text) . '</td>';
731
  } else {
732
  echo '<td colspan="3" class="link_text">
733
- <i>' . __('No text on this link', 'wp-meta-seo') . '</i></td>';
734
  }
735
  }
736
 
@@ -738,71 +777,74 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
738
 
739
  case 'col_source':
740
  $source_inner = '';
741
- $row_action = array();
742
- if ($rec->type == '404_automaticaly') {
743
  $source_inner = '<span style="float: left;margin-right: 5px;">
744
- <i class="material-icons metaseo_help_status" alt="External URL indexed">link</i></span>';
745
- $source_inner .= __('404 automaticaly indexed', 'wp-meta-seo');
 
746
  echo '<td colspan="3">' . $source_inner . '</td>';
747
  } else {
748
- if ($rec->type == 'comment' || $rec->type == 'comment_content_url'
749
- || $rec->type == 'comment_content_image') {
750
  $source = get_comment($rec->source_id);
751
  if (!empty($source)) {
752
  $row_action = array(
753
  'edit' => '<a target="_blank"
754
- href="' . get_edit_comment_link($rec->source_id) . '"
755
- title="' . __('Edit this item', 'wp-meta-seo') . '">
756
- ' . __('Edit', 'wp-meta-seo', 'wp-meta-seo') . '</a>',
757
  'view' => '<a target="_blank"
758
- href="' . get_comment_link($rec->source_id) . '"
759
- title="View &#8220;' . $source->comment_author . '&#8221;" rel="permalink">
760
- ' . __('View', 'wp-meta-seo') . '</a>'
761
  );
762
 
763
- if ($rec->type == 'comment') {
764
  $source_inner = '<span style="float: left;margin-right: 5px;">
765
- <i class="material-icons metaseo_help_status" alt="Comments">person_outline</i></span>';
766
  } else {
767
  $source_inner = '<span style="float: left;margin-right: 5px;">
768
- <i class="material-icons metaseo_help_status" alt="Comments content">chat_bubble</i></span>';
769
  }
770
  $source_inner .= '<a target="_blank"
771
  href="' . get_edit_comment_link($rec->source_id) . '">
772
- ' . $source->comment_author . '</a>';
773
  }
774
  } else {
775
  $source = get_post($rec->source_id);
776
  if (!empty($source)) {
777
  $row_action = array(
778
  'edit' => '<a target="_blank"
779
- href="' . get_edit_post_link($rec->source_id) . '"
780
- title="' . __('Edit this item', 'wp-meta-seo') . '">
781
- ' . __('Edit', 'wp-meta-seo') . '</a>',
782
  'view' => '<a target="_blank"
783
- href="' . get_post_permalink($rec->source_id) . '"
784
- title="View &#8220;' . $source->post_title . '&#8221;"
785
  rel="permalink">View</a>'
786
  );
787
 
788
  $source_inner = '<span style="float: left;margin-right: 5px;">
789
- <i class="material-icons metaseo_help_status" alt="Post , Page , Custom post">layers</i></span>';
790
  $source_inner .= '<a target="_blank"
791
- href="' . get_edit_post_link($rec->source_id) . '">
792
- ' . $source->post_title . '</a>';
793
  }
794
  }
795
 
796
  echo '<td colspan="3">';
797
  if (!empty($source)) {
 
798
  echo $source_inner;
 
799
  echo $this->row_actions($row_action, false);
800
  } else {
801
- if ($rec->type == 'add_custom' || $rec->type == 'add_rule') {
802
- echo '<a><i title="' . __('Custom redirect', 'wp-meta-seo') . '"
803
  class="wpms_outgoing material-icons">call_missed_outgoing</i></a>';
804
  } else {
805
- echo '<a>' . __('Source Not Found', 'wp-meta-seo') . '</a>';
806
  }
807
  }
808
  echo '</td>';
@@ -816,52 +858,55 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
816
  }
817
  }
818
 
819
- /*
820
  * Retrieves a modified URL query string.
 
 
821
  */
822
  public function processAction()
823
  {
824
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
825
- $redirect = false;
826
-
827
  if (isset($_POST['search'])) {
828
  $current_url = add_query_arg(
829
  array(
830
- "search" => "Search",
831
- "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))),
 
832
  $current_url
833
  );
834
- $redirect = true;
835
  }
836
 
837
  if (isset($_POST['filter_type_action'])) {
838
  $current_url = add_query_arg(
839
  array(
840
- "sltype" => $_POST["sltype"],
841
- 'sl_redirect' => $_POST["sl_redirect"],
842
- 'sl_broken' => $_POST["sl_broken"]
843
  ),
844
  $current_url
845
  );
846
- $redirect = true;
847
  }
848
 
849
  if (!empty($_POST['paged'])) {
850
- $current_url = add_query_arg(array("paged" => intval($_POST['paged'])), $current_url);
851
- $redirect = true;
852
  }
853
 
854
  if (!empty($_POST['metaseo_broken_link_per_page'])) {
855
  $current_url = add_query_arg(
856
  array(
857
- "metaseo_broken_link_per_page" => intval($_POST['metaseo_broken_link_per_page'])
858
  ),
859
  $current_url
860
  );
861
- $redirect = true;
862
  }
863
-
864
- if ($redirect === true) {
865
  wp_redirect($current_url);
866
  ob_end_flush();
867
  exit();
@@ -870,16 +915,18 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
870
 
871
  /**
872
  * Get link details
873
- * @param string $source_link link source container current link
874
- * @param int $source_id id source container current link
875
- * @param string $url link url
876
- * @param string $link_text link text
877
- * @param string $type link type
878
- * @param string $status link status
879
- * @param string $status_type link status type
880
- * @param string $meta_title title of link
881
- * @param string $rel link rel
882
- * @param int $postID post id
 
 
883
  * @return array
884
  */
885
  public static function getResultLink(
@@ -896,12 +943,13 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
896
  ) {
897
  $res = array(
898
  'source_link' => $source_link,
899
- 'source_id' => (int)$source_id,
900
- 'link_url' => $url,
901
- 'link_text' => $link_text,
902
- 'type' => $type,
903
- 'status' => $status,
904
- 'status_type' => $status_type);
 
905
 
906
  if (isset($meta_title)) {
907
  $res['meta_title'] = $meta_title;
@@ -909,7 +957,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
909
  $res['meta_title'] = '';
910
  }
911
 
912
- if (isset($rel) && $rel == 'nofollow') {
913
  $res['follow'] = 0;
914
  } else {
915
  $res['follow'] = 1;
@@ -918,8 +966,8 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
918
  if (strpos($url, 'mailto:') !== false) {
919
  $res['link_final_url'] = $url;
920
  } else {
921
- if ($type == 'url') {
922
- if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
923
  $perlink = get_option('permalink_structure');
924
  if (empty($perlink)) {
925
  $res['link_final_url'] = get_site_url() . '/' . $url;
@@ -943,10 +991,13 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
943
 
944
  /**
945
  * Get link status
946
- * @param string $url url to get status
 
 
 
947
  * @return string
948
  */
949
- public static function getUrlStatus($url, $type='')
950
  {
951
  if (strpos($url, 'mailto:') !== false) {
952
  return 'Not checked';
@@ -956,10 +1007,10 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
956
  return 'HTTP/1.1 200 OK';
957
  }
958
 
959
- if ($type == 'update_post') {
960
  return 'HTTP/1.1 200 OK';
961
  }
962
- $status = @get_headers($url, 0);
963
  if (isset($status[0])) {
964
  return $status[0];
965
  } else {
@@ -969,27 +1020,29 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
969
 
970
  /**
971
  * Get link status type
972
- * @param string $status status label
 
 
973
  * @return string
974
  */
975
  public static function getUrlStatusType($status)
976
  {
977
- if (isset($status) && $status == 'Not checked') {
978
  return 'ok';
979
  }
980
 
981
- if (isset($status) && $status != 'Server Not Found') {
982
- if (((int)substr($status, 9, 3) >= 200
983
- && (int)substr($status, 9, 3) <= 204) || (int)substr($status, 9, 3) == 401) {
984
  $type = 'ok';
985
- } elseif (((int)substr($status, 9, 3) >= 400
986
- && (int)substr($status, 9, 3) <= 503 && (int)substr($status, 9, 3) != 401)) {
987
- if (in_array((int)substr($status, 9, 3), array(404, 410))) {
988
  $type = 'broken_internal';
989
  } else {
990
  $type = 'warning';
991
  }
992
- } elseif (((int)substr($status, 9, 3) >= 301 && (int)substr($status, 9, 3) <= 304)) {
993
  $type = 'ok';
994
  } else {
995
  $type = 'dismissed';
@@ -1002,78 +1055,92 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1002
 
1003
  /**
1004
  * Delete link comment in wpms_links table when delete comment
1005
- * @param int $comment_ID comment id
 
 
 
1006
  */
1007
  public static function deletedComment($comment_ID)
1008
  {
1009
  global $wpdb;
1010
  $wpdb->query(
1011
  $wpdb->prepare(
1012
- "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
1013
- AND (type = %s || type = %s || type = %s)
1014
- ",
1015
- $comment_ID,
1016
- 'comment',
1017
- 'comment_content_url',
1018
- 'comment_content_image'
1019
  )
1020
  );
1021
  }
1022
 
1023
  /**
1024
  * Delete link post in wpms_links table when delete post
1025
- * @param $post_id
 
 
 
1026
  */
1027
  public static function deletePost($post_id)
1028
  {
1029
  global $wpdb;
1030
  $wpdb->query(
1031
  $wpdb->prepare(
1032
- "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
1033
- AND type != %s
1034
- ",
1035
- $post_id,
1036
- 'comment'
 
1037
  )
1038
  );
1039
  }
1040
 
1041
  /**
1042
  * Update wpms_links table when update comment
1043
- * @param int $comment_ID Id of current comment
 
 
 
1044
  */
1045
  public static function updateComment($comment_ID)
1046
  {
 
 
 
 
 
1047
  global $wpdb;
1048
  $comment = get_comment($comment_ID);
1049
- $status = wp_get_comment_status($comment_ID);
1050
- if ($status == 'approved') {
1051
  if (!empty($comment->comment_author_url)) {
1052
- $status = MetaSeoBrokenLinkTable::getUrlStatus(($comment->comment_author_url));
1053
- $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1054
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1055
- $sql = $wpdb->prepare(
1056
- "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type=%s ",
1057
  array(
1058
  $comment_ID,
1059
  'comment'
1060
  )
1061
- );
1062
- $check = $wpdb->get_var($sql);
1063
- if ($check == 0) {
1064
  $value = array(
1065
- 'link_url' => $comment->comment_author_url,
1066
- 'link_text' => $comment->comment_author,
1067
- 'source_id' => $comment_ID,
1068
- 'type' => 'comment',
1069
- 'status_code' => $status,
1070
- 'status_text' => $status_text,
1071
- 'broken_indexed' => 0,
1072
  'broken_internal' => 0,
1073
- 'warning' => 0,
1074
- 'dismissed' => 0,
1075
  );
1076
- if (isset($status_type) && $status_type != 'ok') {
1077
  $value[$status_type] = 1;
1078
  }
1079
  $wpdb->insert(
@@ -1081,20 +1148,21 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1081
  $value
1082
  );
1083
  } else {
1084
- $value = array('link_url' => $comment->comment_author_url,
1085
- 'status_code' => $status,
1086
- 'status_text' => $status_text,
1087
- 'broken_indexed' => 0,
 
1088
  'broken_internal' => 0,
1089
- 'warning' => 0,
1090
- 'dismissed' => 0,
1091
  );
1092
 
1093
  if (isset($_POST['link_redirect'])) {
1094
  $value['link_url_redirect'] = ($_POST['link_redirect']);
1095
  }
1096
 
1097
- if (isset($status_type) && $status_type != 'ok') {
1098
  $value[$status_type] = 1;
1099
  }
1100
  $wpdb->update(
@@ -1102,7 +1170,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1102
  $value,
1103
  array(
1104
  'source_id' => $comment_ID,
1105
- 'type' => 'comment'
1106
  ),
1107
  array('%s', '%s', '%s', '%d', '%d', '%d', '%d'),
1108
  array('%d', '%s')
@@ -1111,9 +1179,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1111
  } else {
1112
  $wpdb->query(
1113
  $wpdb->prepare(
1114
- "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d AND (type = %s)",
1115
  array(
1116
- $comment_ID,
1117
  'comment'
1118
  )
1119
  )
@@ -1121,19 +1189,19 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1121
  }
1122
 
1123
  $linkscontent = array();
1124
- if (isset($comment->comment_content) && $comment->comment_content != '') {
1125
- preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1126
  foreach (array_unique($matches[0]) as $i => $content) {
1127
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1128
- $href = $matches[1];
1129
- $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1130
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1131
- $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1132
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1133
- $source_link .= '<b>' . $comment->comment_author . '</b>';
1134
- $source_link .= '</a>';
1135
- $key = $href . 'comment_content_url' . $comment->comment_ID . $link_text;
1136
- $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1137
  $source_link,
1138
  $comment->comment_ID,
1139
  $href,
@@ -1151,15 +1219,15 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1151
  );
1152
  foreach (array_unique($matches[0]) as $content) {
1153
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1154
- $src = $matches[1];
1155
- $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1156
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1157
- $link_text = '';
1158
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1159
- $source_link .= '<b>' . $comment->comment_author . '</b>';
1160
- $source_link .= '</a>';
1161
- $key = $src . 'comment_content_image' . $comment->comment_ID;
1162
- $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1163
  $source_link,
1164
  $comment->comment_ID,
1165
  $src,
@@ -1171,18 +1239,17 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1171
  }
1172
  }
1173
 
1174
- $sql = $wpdb->prepare(
1175
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND (type = %s || type = %s)",
1176
  array(
1177
- $comment->comment_ID,
1178
- "comment_content_url",
1179
- "comment_content_image"
1180
  )
1181
- );
1182
- $links = $wpdb->get_results($sql);
1183
  foreach ($links as $link) {
1184
  if (empty($linkscontent[$link->link_url . $link->type])) {
1185
- $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
1186
  } else {
1187
  unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1188
  }
@@ -1190,16 +1257,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1190
 
1191
  if (!empty($linkscontent)) {
1192
  foreach ($linkscontent as $link) {
1193
- MetaSeoBrokenLinkTable::insertLink($link, $wpdb);
1194
  }
1195
  }
1196
  } else {
1197
  $wpdb->query(
1198
  $wpdb->prepare(
1199
- "DELETE FROM " . $wpdb->prefix . "wpms_links
1200
- WHERE source_id = %d AND (type = %s || type = %s || type = %s)",
1201
  array(
1202
- $comment_ID,
1203
  'comment',
1204
  'comment_content_url',
1205
  'comment_content_image'
@@ -1213,39 +1280,48 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1213
 
1214
  /**
1215
  * Update wpms_links table when update post
1216
- * @param int $post_ID Id of current post
1217
- * @param $post_after
1218
- * @param $post_before
 
 
 
1219
  */
1220
  public static function updatePost($post_ID, $post_after, $post_before)
1221
  {
 
 
 
 
 
 
1222
  global $wpdb;
1223
  $post = $post_after;
1224
- $dom = new DOMDocument;
1225
  libxml_use_internal_errors(true);
1226
  $linkscontent = array();
1227
 
1228
- if ($post->post_excerpt != 'metaseo_404_page') {
1229
- if ($post->post_status == 'publish') {
1230
- if (isset($post->post_content) && $post->post_content != '') {
1231
  // find <a> tag in current post content
1232
- preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
1233
  foreach (array_unique($matches[0]) as $i => $content) {
1234
  $dom->loadHTML($content);
1235
- $tags = $dom->getElementsByTagName('a');
1236
  $meta_title = $tags->item(0)->getAttribute('title');
1237
- $rel = $tags->item(0)->getAttribute('rel');
1238
 
1239
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1240
- $href = $matches[1];
1241
- $status = MetaSeoBrokenLinkTable::getUrlStatus($href, 'update_post');
1242
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1243
- $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1244
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1245
- $source_link .= '<b>' . $post->post_title . '</b>';
1246
- $source_link .= '</a>';
1247
- $key = $href . 'url' . $post->ID . $link_text;
1248
- $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1249
  $source_link,
1250
  $post->ID,
1251
  $href,
@@ -1270,11 +1346,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1270
  $source_link .= '<b>' . $post->post_title . '</b>';
1271
  $source_link .= '</a>';
1272
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1273
- $src = $matches[1];
1274
- $status = MetaSeoBrokenLinkTable::getUrlStatus($src, 'update_post');
1275
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1276
- $link_text = '';
1277
- $linkscontent[$src . 'img' . $post->ID] = MetaSeoBrokenLinkTable::getResultLink(
1278
  $source_link,
1279
  $post->ID,
1280
  $src,
@@ -1286,17 +1362,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1286
  }
1287
  }
1288
 
1289
- $sql = $wpdb->prepare(
1290
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type != %s",
1291
  array(
1292
  $post->ID,
1293
- "comment"
1294
  )
1295
- );
1296
- $links = $wpdb->get_results($sql);
1297
  foreach ($links as $link) {
1298
  if (empty($linkscontent[$link->link_url . $link->type])) {
1299
- $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
1300
  } else {
1301
  unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1302
  }
@@ -1304,14 +1379,14 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1304
 
1305
  if (!empty($linkscontent)) {
1306
  foreach ($linkscontent as $link) {
1307
- MetaSeoBrokenLinkTable::insertLink($link, $wpdb);
1308
  }
1309
  }
1310
  } else {
1311
  $wpdb->query(
1312
  $wpdb->prepare(
1313
- "DELETE FROM " . $wpdb->prefix . "wpms_links
1314
- WHERE source_id = %d AND (type = %s || type = %s)",
1315
  array(
1316
  $post->ID,
1317
  'image',
@@ -1327,42 +1402,23 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1327
 
1328
  /**
1329
  * Scan link in comment , post
 
 
1330
  */
1331
  public static function scanLink()
1332
  {
1333
- global $wpdb;
1334
- $limit_comment_content = 1;
1335
- $limit_comment = 10;
1336
- $limit_post = 1;
1337
-
1338
- $where = array();
1339
- $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
1340
- if ($post_type == "-1") {
1341
- $post_type = "";
1342
  }
1343
 
1344
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1345
- unset($post_types['attachment']);
1346
- if (!empty($post_type) && !in_array($post_type, $post_types)) {
1347
- $post_type = '\'post\'';
1348
- } elseif (empty($post_type)) {
1349
- $post_type = "'" . implode("', '", $post_types) . "'";
1350
- } else {
1351
- $post_type = "'" . $post_type . "'";
1352
- }
1353
-
1354
- $where[] = "post_type IN ($post_type)";
1355
- $states = 'publish';
1356
- $where[] = "post_status = '$states'";
1357
- $total_comments = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "comments");
1358
- $total_posts = $wpdb->get_var("SELECT COUNT(*)"
1359
- . " FROM $wpdb->posts "
1360
- . " WHERE " . implode(' AND ', $where));
1361
-
1362
  $percent_comment_content = 33.33;
1363
- $percent_comment = 33.33;
1364
- $percent_post = 33.33;
1365
-
1366
  if (!empty($total_comments)) {
1367
  $percent_comment_content = 33.33 / $total_comments;
1368
  }
@@ -1379,18 +1435,10 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1379
  $percent_comment = 33.33;
1380
  }
1381
 
1382
- if (!empty($total_posts)) {
1383
- $percent_post = 33.33 / $total_posts;
1384
- }
1385
-
1386
- if ($total_posts < $limit_post) {
1387
- $percent_post = 33.33;
1388
- }
1389
-
1390
  // scan link in comment url
1391
- $comments = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "comments
1392
- WHERE comment_approved = 1 AND comment_author_url != '' AND comment_author_url NOT IN (SELECT link_url
1393
- FROM " . $wpdb->prefix . "wpms_links WHERE type='comment') LIMIT $limit_comment");
1394
 
1395
  if (!empty($comments)) {
1396
  foreach ($comments as $comment) {
@@ -1398,9 +1446,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1398
  $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1399
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1400
  $source_link .= '</a>';
1401
- $status = MetaSeoBrokenLinkTable::getUrlStatus($comment->comment_author_url);
1402
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1403
- $coms = MetaSeoBrokenLinkTable::getResultLink(
1404
  $source_link,
1405
  $comment->comment_ID,
1406
  $comment->comment_author_url,
@@ -1409,7 +1457,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1409
  $status,
1410
  $status_type
1411
  );
1412
- MetaSeoBrokenLinkTable::insertLink($coms, $wpdb);
1413
  }
1414
  }
1415
  wp_send_json(array('status' => false, 'type' => 'limit', 'percent' => $percent_comment));
@@ -1423,23 +1471,25 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1423
  $off_set = 0;
1424
  }
1425
 
1426
- $query = "SELECT * FROM " . $wpdb->prefix . "comments
1427
- WHERE comment_approved = 1 AND comment_content != '' LIMIT $limit_comment_content OFFSET $off_set";
1428
- $comments_content = $wpdb->get_results($query);
 
 
1429
  if (!empty($comments_content)) {
1430
  foreach ($comments_content as $comment) {
1431
- if (isset($comment->comment_content) && $comment->comment_content != '') {
1432
- preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1433
  foreach (array_unique($matches[0]) as $i => $content) {
1434
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1435
- $href = $matches[1];
1436
- $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1437
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1438
- $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1439
  $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1440
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1441
  $source_link .= '</a>';
1442
- $link_a = MetaSeoBrokenLinkTable::getResultLink(
1443
  $source_link,
1444
  $comment->comment_ID,
1445
  $href,
@@ -1448,7 +1498,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1448
  $status,
1449
  $status_type
1450
  );
1451
- MetaSeoBrokenLinkTable::insertLink($link_a, $wpdb);
1452
  }
1453
  preg_match_all(
1454
  '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
@@ -1461,11 +1511,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1461
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1462
  $source_link .= '</a>';
1463
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1464
- $src = $matches[1];
1465
- $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1466
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1467
- $link_text = '';
1468
- $link_sou = MetaSeoBrokenLinkTable::getResultLink(
1469
  $source_link,
1470
  $comment->comment_ID,
1471
  $src,
@@ -1474,18 +1524,18 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1474
  $status,
1475
  $status_type
1476
  );
1477
- MetaSeoBrokenLinkTable::insertLink($link_sou, $wpdb);
1478
  }
1479
  }
1480
  }
1481
 
1482
- $k++;
1483
  if ($k >= $limit_comment_content) {
1484
  wp_send_json(
1485
  array(
1486
- 'status' => false,
1487
- 'type' => 'limit_comment_content',
1488
- 'paged' => $_POST['comment_paged'],
1489
  'percent' => $percent_comment_content * count($comments_content)
1490
  )
1491
  );
@@ -1493,37 +1543,57 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1493
  }
1494
 
1495
  // scan link in post
1496
- $j = 0;
1497
- $off_set = ($_POST['paged'] - 1) * $limit_post;
1498
- $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
1499
- . " FROM $wpdb->posts "
1500
- . " WHERE " . implode(' AND ', $where) . "LIMIT $limit_post OFFSET $off_set";
 
 
 
 
 
 
 
 
 
 
 
 
1501
 
1502
- $results = $wpdb->get_results($query);
 
 
 
 
 
 
 
 
1503
  if (empty($results)) {
1504
  wp_send_json(array('status' => true));
1505
  }
1506
 
1507
  foreach ($results as $post) {
1508
- if ($post->post_excerpt != 'metaseo_404_page') {
1509
  $dom = new DOMDocument;
1510
  libxml_use_internal_errors(true);
1511
- if (isset($post->post_content) && $post->post_content != '') {
1512
- preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
1513
  foreach (array_unique($matches[0]) as $i => $content) {
1514
  $dom->loadHTML($content);
1515
- $tags = $dom->getElementsByTagName('a');
1516
  $meta_title = $tags->item(0)->getAttribute('title');
1517
- $rel = $tags->item(0)->getAttribute('rel');
1518
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1519
- $href = $matches[1];
1520
- $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1521
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1522
- $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1523
  $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1524
  $source_link .= '<b>' . $post->post_title . '</b>';
1525
  $source_link .= '</a>';
1526
- $link_a = MetaSeoBrokenLinkTable::getResultLink(
1527
  $source_link,
1528
  $post->ID,
1529
  $href,
@@ -1535,7 +1605,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1535
  $rel,
1536
  $post->ID
1537
  );
1538
- MetaSeoBrokenLinkTable::insertLink($link_a, $wpdb);
1539
  }
1540
  preg_match_all(
1541
  '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
@@ -1548,11 +1618,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1548
  $source_link .= '<b>' . $post->post_title . '</b>';
1549
  $source_link .= '</a>';
1550
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1551
- $src = $matches[1];
1552
- $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1553
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1554
- $link_text = '';
1555
- $link_src = MetaSeoBrokenLinkTable::getResultLink(
1556
  $source_link,
1557
  $post->ID,
1558
  $src,
@@ -1561,17 +1631,17 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1561
  $status,
1562
  $status_type
1563
  );
1564
- MetaSeoBrokenLinkTable::insertLink($link_src, $wpdb);
1565
  }
1566
  }
1567
  }
1568
- $j++;
1569
  if ($j >= $limit_post) {
1570
  wp_send_json(
1571
  array(
1572
- 'status' => false,
1573
- 'type' => 'limit_post',
1574
- 'paged' => $_POST['paged'],
1575
  'percent' => $percent_post * count($results)
1576
  )
1577
  );
@@ -1579,9 +1649,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1579
  }
1580
 
1581
  $link_settings = array(
1582
- "enable" => 0,
1583
- "numberFrequency" => 1,
1584
- "showlinkFrequency" => "month"
1585
  );
1586
 
1587
  $linksettings = get_option('wpms_link_settings');
@@ -1596,61 +1666,64 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1596
 
1597
  /**
1598
  * Insert link to wpms_link table
1599
- * @param array $link link details to insert
1600
- * @param object $wpdb global wordpress database
 
 
 
1601
  */
1602
  public static function insertLink($link, $wpdb)
1603
  {
1604
- $sql = $wpdb->prepare(
1605
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE link_url=%s AND type=%s AND source_id=%d ",
1606
  array(
1607
  $link['link_url'],
 
1608
  $link['type'],
1609
  $link['source_id']
1610
  )
1611
- );
1612
- $links = $wpdb->get_results($sql);
1613
- if (count($links) == 0) {
1614
- $status_text = MetaSeoBrokenLinkTable::getStatusText($link['status']);
1615
- $value = array(
1616
- 'link_url' => $link['link_url'],
1617
- 'link_final_url' => $link['link_final_url'],
1618
- 'link_text' => $link['link_text'],
1619
- 'source_id' => $link['source_id'],
1620
- 'type' => $link['type'],
1621
- 'status_code' => $link['status'],
1622
- 'status_text' => $status_text,
1623
- 'broken_indexed' => 0,
1624
  'broken_internal' => 0,
1625
- 'warning' => 0,
1626
- 'dismissed' => 0,
1627
- 'meta_title' => $link['meta_title'],
1628
- 'follow' => $link['follow']
1629
  );
1630
- if (isset($link['status_type']) && $link['status_type'] != 'ok') {
1631
  $value[$link['status_type']] = 1;
1632
  }
1633
 
1634
  $site_url = get_site_url();
1635
- $value = MetaSeoBrokenLinkTable::checkInternalLink($link['link_url'], $site_url, $value);
1636
 
1637
  $wpdb->insert(
1638
  $wpdb->prefix . 'wpms_links',
1639
  $value
1640
  );
1641
  } else {
1642
- $value = array(
1643
  'meta_title' => $link['meta_title'],
1644
- 'follow' => $link['follow']
1645
  );
1646
  $site_url = get_site_url();
1647
  // get status
1648
- $status_text = MetaSeoBrokenLinkTable::getStatusText($link['status']);
1649
- $value = MetaSeoBrokenLinkTable::checkInternalLink($links[0]->link_url, $site_url, $value);
1650
  $value['status_code'] = $link['status'];
1651
  $value['status_text'] = $status_text;
1652
- if ($links[0]->follow != $link['follow'] || $links[0]->meta_title != $link['meta_title']
1653
- || $links[0]->internal != $value['internal'] || $links[0]->status_code != $value['status_code']) {
1654
  // update link status
1655
  $wpdb->update(
1656
  $wpdb->prefix . 'wpms_links',
@@ -1665,9 +1738,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1665
 
1666
  /**
1667
  * Check internal link
1668
- * @param string $link current link url
1669
- * @param string $siteUrl site url
1670
- * @param $value
 
 
1671
  * @return mixed
1672
  */
1673
  public static function checkInternalLink($link, $siteUrl, $value)
@@ -1684,8 +1759,8 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1684
  }
1685
 
1686
  $info_site_url = parse_url($siteUrl);
1687
- $domain_link = $info_link['host'] . $info_link['path'] . '/';
1688
- $domain_site = $info_site_url['host'] . $info_site_url['path'] . '/';
1689
  if (strpos($domain_link, $domain_site) !== false) {
1690
  $value['internal'] = 1;
1691
  } else {
@@ -1697,45 +1772,27 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1697
 
1698
  /**
1699
  * Flush link
 
 
1700
  */
1701
  public static function flushLink()
1702
  {
 
 
 
 
 
1703
  global $wpdb;
1704
- if (isset($_POST['type']) && $_POST['type'] != 'none') {
1705
  switch ($_POST['type']) {
1706
  case 'automaticaly_indexed':
1707
- $wpdb->query(
1708
- $wpdb->prepare(
1709
- "
1710
- DELETE FROM " . $wpdb->prefix . "wpms_links
1711
- WHERE broken_indexed = %d AND link_url_redirect = %s
1712
- ",
1713
- array(1, '')
1714
- )
1715
- );
1716
  break;
1717
  case 'internal_broken_links':
1718
- $wpdb->query(
1719
- $wpdb->prepare(
1720
- "
1721
- DELETE FROM " . $wpdb->prefix . "wpms_links
1722
- WHERE broken_internal = %d AND link_url_redirect = %s
1723
- ",
1724
- array(1, '')
1725
- )
1726
- );
1727
  break;
1728
  case 'all':
1729
- $wpdb->query(
1730
- $wpdb->prepare(
1731
- "
1732
- DELETE FROM " . $wpdb->prefix . "wpms_links
1733
- WHERE (broken_internal = %d
1734
- OR broken_indexed = %d) AND link_url_redirect = %s
1735
- ",
1736
- array(1, 1, '')
1737
- )
1738
- );
1739
 
1740
  break;
1741
  }
@@ -1746,15 +1803,17 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1746
 
1747
  /**
1748
  * Get status text
1749
- * @param string $status statue of link
1750
- * @return bool|string
 
 
1751
  */
1752
  public static function getStatusText($status)
1753
  {
1754
- if ($status == 'Not checked') {
1755
  return 'Not checked';
1756
  }
1757
- if ($status == 'Server Not Found') {
1758
  $status_text = 'Server Not Found';
1759
  } else {
1760
  $status_text = substr($status, 9);
@@ -1764,31 +1823,45 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1764
 
1765
  /**
1766
  * Add custom redirect
 
 
1767
  */
1768
  public static function addCustomRedirect()
1769
  {
1770
- do_action('wpms_add_custom_redirect');
1771
- wp_send_json(array('status' => true, 'message' => __('Done!', 'wp-meta-seo')));
 
 
 
 
 
 
 
1772
  }
1773
 
1774
  /**
1775
  * Update link
 
 
1776
  */
1777
  public static function updateLinkRedirect()
1778
  {
 
 
 
 
1779
 
1780
  if (isset($_POST['link_id'])) {
1781
  global $wpdb;
1782
- $sql = $wpdb->prepare(
1783
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1784
  array($_POST['link_id'])
1785
- );
1786
- $link_detail = $wpdb->get_row($sql);
1787
  if (empty($link_detail)) {
1788
  wp_send_json(false);
1789
  }
1790
 
1791
- $new_link = stripslashes($_POST['new_link']);
1792
  $link_redirect = stripslashes($_POST['link_redirect']);
1793
  if (isset($_POST['new_text'])) {
1794
  $new_text = stripcslashes($_POST['new_text']);
@@ -1796,30 +1869,31 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1796
  $new_text = '';
1797
  }
1798
 
1799
- if ($link_redirect != '') {
1800
  $status = 'HTTP/1.1 200 OK';
1801
  } else {
1802
- $status = MetaSeoBrokenLinkTable::getUrlStatus($new_link);
1803
  }
1804
 
1805
- $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1806
- $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1807
- if ($link_detail->type != '404_automaticaly') {
1808
- $value = array('link_url' => $new_link,
1809
- 'link_final_url' => '',
 
1810
  'link_url_redirect' => '',
1811
- 'link_text' => stripcslashes($new_text),
1812
- 'status_code' => $status,
1813
- 'status_text' => $status_text,
1814
- 'broken_indexed' => 0,
1815
- 'broken_internal' => 0,
1816
- 'warning' => 0,
1817
- 'dismissed' => 0,
1818
  );
1819
  if (strpos($new_link, 'mailto:') !== false) {
1820
  $value['link_final_url'] = $new_link;
1821
  } else {
1822
- if (!preg_match("~^(?:f|ht)tps?://~i", $new_link)) {
1823
  $perlink = get_option('permalink_structure');
1824
  if (empty($perlink)) {
1825
  $value['link_final_url'] = get_site_url() . '/' . $new_link;
@@ -1839,27 +1913,27 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1839
  $value['link_url_redirect'] = $link_redirect;
1840
  }
1841
 
1842
- if (isset($status_type) && $status_type != 'ok') {
1843
  $value[$status_type] = 1;
1844
  }
1845
  } else {
1846
- $status = MetaSeoBrokenLinkTable::getUrlStatus($link_redirect);
1847
- $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1848
 
1849
  $value = array(
1850
  'link_url_redirect' => stripslashes($link_redirect),
1851
- 'status_code' => $status,
1852
- 'status_text' => $status_text,
1853
- 'broken_indexed' => 1
1854
  );
1855
  }
1856
 
1857
- if ($link_detail->type == 'add_custom') {
1858
  $value['meta_title'] = $_POST['status_redirect'];
1859
  }
1860
 
1861
  $site_url = get_site_url();
1862
- $value = MetaSeoBrokenLinkTable::checkInternalLink($new_link, $site_url, $value);
1863
 
1864
  $wpdb->update(
1865
  $wpdb->prefix . 'wpms_links',
@@ -1873,34 +1947,34 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1873
  case '404_automaticaly':
1874
  wp_send_json(
1875
  array(
1876
- 'status' => true,
1877
- 'type' => '404_automaticaly',
1878
  'status_text' => $status_text,
1879
- 'new_link' => esc_url($new_link)
1880
  )
1881
  );
1882
  break;
1883
  case 'comment_content_image':
1884
  $comment = get_comment($link_detail->source_id);
1885
  if (!empty($comment)) {
1886
- $old_value = $comment->comment_content;
1887
- $edit_result = MetaSeoBrokenLinkTable::editLinkImg(
1888
  $old_value,
1889
  $new_link,
1890
  $link_detail->link_url
1891
  );
1892
- $my_comment = array(
1893
- 'comment_ID' => $link_detail->source_id,
1894
  'comment_content' => $edit_result['content']
1895
  );
1896
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
1897
  wp_update_comment($my_comment);
1898
  wp_send_json(
1899
  array(
1900
- 'status' => true,
1901
- 'type' => 'image',
1902
  'status_text' => $status_text,
1903
- 'new_link' => esc_url($edit_result['raw_url'])
1904
  )
1905
  );
1906
  }
@@ -1908,24 +1982,24 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1908
  case 'image':
1909
  $post = get_post($link_detail->source_id);
1910
  if (!empty($post)) {
1911
- $old_value = $post->post_content;
1912
- $edit_result = MetaSeoBrokenLinkTable::editLinkImg(
1913
  $old_value,
1914
  $new_link,
1915
  $link_detail->link_url
1916
  );
1917
- $my_post = array(
1918
- 'ID' => $link_detail->source_id,
1919
  'post_content' => $edit_result['content']
1920
  );
1921
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1922
  wp_update_post($my_post);
1923
  wp_send_json(
1924
  array(
1925
- 'status' => true,
1926
- 'type' => 'image',
1927
  'status_text' => $status_text,
1928
- 'new_link' => esc_url($edit_result['raw_url'])
1929
  )
1930
  );
1931
  }
@@ -1935,36 +2009,36 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1935
  $comment = get_comment($link_detail->source_id);
1936
  if (!empty($comment)) {
1937
  $old_value = $comment->comment_content;
1938
- if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1939
- $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1940
  $old_value,
1941
  $new_link,
1942
  $link_detail->link_url
1943
  );
1944
- $new_text = '';
1945
  } else {
1946
- $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1947
  $old_value,
1948
  $new_link,
1949
  $link_detail->link_url,
1950
  $new_text
1951
  );
1952
- $new_text = strip_tags($edit_result['link_text']);
1953
  }
1954
 
1955
  $my_comment = array(
1956
- 'comment_ID' => $link_detail->source_id,
1957
  'comment_content' => $edit_result['content']
1958
  );
1959
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
1960
  wp_update_comment($my_comment);
1961
  wp_send_json(
1962
  array(
1963
- 'status' => true,
1964
- 'type' => 'url',
1965
  'status_text' => $status_text,
1966
- 'new_link' => $edit_result['raw_url'],
1967
- 'new_text' => $new_text
1968
  )
1969
  );
1970
  }
@@ -1975,36 +2049,36 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
1975
  $post = get_post($link_detail->source_id);
1976
  if (!empty($post)) {
1977
  $old_value = $post->post_content;
1978
- if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1979
- $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1980
  $old_value,
1981
  $new_link,
1982
  $link_detail->link_url
1983
  );
1984
- $new_text = '';
1985
  } else {
1986
- $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1987
  $old_value,
1988
  $new_link,
1989
  $link_detail->link_url,
1990
  $new_text
1991
  );
1992
- $new_text = strip_tags($edit_result['link_text']);
1993
  }
1994
 
1995
  $my_post = array(
1996
- 'ID' => $link_detail->source_id,
1997
  'post_content' => $edit_result['content']
1998
  );
1999
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2000
  wp_update_post($my_post);
2001
  wp_send_json(
2002
  array(
2003
- 'status' => true,
2004
- 'type' => 'url',
2005
  'status_text' => $status_text,
2006
- 'new_link' => $edit_result['raw_url'],
2007
- 'new_text' => $new_text
2008
  )
2009
  );
2010
  }
@@ -2013,16 +2087,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2013
  case 'comment':
2014
  wp_update_comment(
2015
  array(
2016
- 'comment_ID' => $link_detail->source_id,
2017
  'comment_author_url' => $new_link
2018
  )
2019
  );
2020
  wp_send_json(
2021
  array(
2022
- 'status' => true,
2023
- 'type' => 'orther',
2024
  'status_text' => $status_text,
2025
- 'new_link' => $new_link
2026
  )
2027
  );
2028
  break;
@@ -2030,10 +2104,10 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2030
  case 'add_custom':
2031
  wp_send_json(
2032
  array(
2033
- 'status' => true,
2034
- 'type' => 'orther',
2035
  'status_text' => $status_text,
2036
- 'new_link' => $new_link
2037
  )
2038
  );
2039
  break;
@@ -2044,16 +2118,22 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2044
 
2045
  /**
2046
  * Remove link
 
 
2047
  */
2048
  public static function unlink()
2049
  {
 
 
 
 
 
2050
  if (isset($_POST['link_id'])) {
2051
  global $wpdb;
2052
- $sql = $wpdb->prepare(
2053
- "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
2054
  array($_POST['link_id'])
2055
- );
2056
- $link_detail = $wpdb->get_row($sql);
2057
  if (empty($link_detail)) {
2058
  wp_send_json(false);
2059
  }
@@ -2068,11 +2148,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2068
  case 'comment_content_image':
2069
  $comment = get_comment($link_detail->source_id);
2070
  if (!empty($comment)) {
2071
- $old_value = $comment->comment_content;
2072
- $new_content = MetaSeoBrokenLinkTable::unlinkImg($old_value, $link_detail->link_url);
2073
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2074
  $my_comment = array(
2075
- 'comment_ID' => $link_detail->source_id,
2076
  'comment_content' => $new_content
2077
  );
2078
  wp_update_comment($my_comment);
@@ -2083,11 +2163,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2083
  case 'image':
2084
  $post = get_post($link_detail->source_id);
2085
  if (!empty($post)) {
2086
- $old_value = $post->post_content;
2087
- $new_content = MetaSeoBrokenLinkTable::unlinkImg($old_value, $link_detail->link_url);
2088
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2089
  $my_post = array(
2090
- 'ID' => $link_detail->source_id,
2091
  'post_content' => $new_content
2092
  );
2093
  wp_update_post($my_post);
@@ -2098,11 +2178,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2098
  case 'comment_content_url':
2099
  $comment = get_comment($link_detail->source_id);
2100
  if (!empty($comment)) {
2101
- $old_value = $comment->comment_content;
2102
- $new_content = MetaSeoBrokenLinkTable::unlinkHtml($old_value, $link_detail->link_url);
2103
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2104
  $my_comment = array(
2105
- 'comment_ID' => $link_detail->source_id,
2106
  'comment_content' => $new_content
2107
  );
2108
  wp_update_comment($my_comment);
@@ -2113,11 +2193,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2113
  case 'url':
2114
  $post = get_post($link_detail->source_id);
2115
  if (!empty($post)) {
2116
- $old_value = $post->post_content;
2117
- $new_content = MetaSeoBrokenLinkTable::unlinkHtml($old_value, $link_detail->link_url);
2118
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2119
  $my_post = array(
2120
- 'ID' => $link_detail->source_id,
2121
  'post_content' => $new_content
2122
  );
2123
  wp_update_post($my_post);
@@ -2151,7 +2231,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2151
  {
2152
  self::$old_url = $old_url;
2153
  self::$new_url = htmlentities($new_url);
2154
- $content = preg_replace_callback(
2155
  self::$img_pattern,
2156
  array(
2157
  'MetaSeoBrokenLinkTable',
@@ -2167,13 +2247,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2167
  }
2168
 
2169
  /**
2170
- * @param $matches
 
 
 
2171
  * @return string
2172
  */
2173
  public static function editImgCallback($matches)
2174
  {
2175
  $url = $matches[3];
2176
- if (($url) == self::$old_url) {
2177
  return $matches[1] . '"' . self::$new_url . '"' . $matches[4];
2178
  } else {
2179
  return $matches[0];
@@ -2184,13 +2267,14 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2184
  * Remove all occurrences of a specific plaintext URL.
2185
  *
2186
  * @param string $content Look for URLs in this string.
2187
- * @param string $url The URL to look for.
 
2188
  * @return string Input string with all matching plaintext URLs removed.
2189
  */
2190
  public static function unlinkImg($content, $url)
2191
  {
2192
  self::$old_url = $url; //used by the callback
2193
- $content = preg_replace_callback(
2194
  self::$img_pattern,
2195
  array(
2196
  'MetaSeoBrokenLinkTable',
@@ -2202,14 +2286,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2202
  }
2203
 
2204
  /**
2205
- * get image unchanged
2206
- * @param $matches
 
 
2207
  * @return string
2208
  */
2209
  public static function unlinkImgCallback($matches)
2210
  {
2211
  $url = $matches[3];
2212
- if (($url) == self::$old_url) {
2213
  return ''; //Completely remove the IMG tag
2214
  } else {
2215
  return $matches[0]; //return the image unchanged
@@ -2220,7 +2306,8 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2220
  * Remove all occurrences of a specific plaintext URL.
2221
  *
2222
  * @param string $content Look for URLs in this string.
2223
- * @param string $url The URL to look for.
 
2224
  * @return string Input string with all matching plaintext URLs removed.
2225
  */
2226
  public static function unlinkHtml($content, $url)
@@ -2229,7 +2316,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2229
  'old_url' => $url,
2230
  );
2231
 
2232
- $content = MetaSeoBrokenLinkTable::multiEdit(
2233
  $content,
2234
  array(
2235
  'MetaSeoBrokenLinkTable',
@@ -2243,13 +2330,15 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2243
 
2244
  /**
2245
  * Get link to remove
2246
- * @param $link
2247
- * @param $params
 
 
2248
  * @return mixed
2249
  */
2250
  public static function unlinkHtmlCallback($link, $params)
2251
  {
2252
- if ($link['href'] != $params['old_url']) {
2253
  return $link['#raw'];
2254
  }
2255
 
@@ -2259,10 +2348,11 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2259
  /**
2260
  * Change all occurrences of a given plaintext URLs to a new URL.
2261
  *
2262
- * @param string $content Look for URLs in this string.
2263
- * @param string $new_url Change them to this URL.
2264
- * @param string $old_url The URL to look for.
2265
- * @param string $new_text new text of this URL.
 
2266
  * @return array|WP_Error If successful, the return value will be an associative array with two
2267
  * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
2268
  * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
@@ -2271,13 +2361,13 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2271
  {
2272
  //Save the old & new URLs for use in the edit callback.
2273
  $args = array(
2274
- 'old_url' => $old_url,
2275
- 'new_url' => $new_url,
2276
  'new_text' => $new_text,
2277
  );
2278
 
2279
  //Find all links and replace those that match $old_url.
2280
- $content = MetaSeoBrokenLinkTable::multiEdit(
2281
  $content,
2282
  array(
2283
  'MetaSeoBrokenLinkTable',
@@ -2297,14 +2387,16 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2297
  }
2298
 
2299
  /**
2300
- * get url in content
2301
- * @param array $link link details
2302
- * @param array $params new params to edit
 
 
2303
  * @return array
2304
  */
2305
  public static function editHtmlCallback($link, $params)
2306
  {
2307
- if ($link['href'] == $params['old_url']) {
2308
  $modified = array(
2309
  'href' => $params['new_url'],
2310
  );
@@ -2316,7 +2408,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2316
  $modified['title'] = $params['meta_title'];
2317
  }
2318
 
2319
- if (isset($params['follow']) && $params['follow'] == 0) {
2320
  $modified['rel'] = 'nofollow';
2321
  } else {
2322
  $modified['rel'] = '';
@@ -2334,10 +2426,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2334
  * a replacement HTML tag instead, it will be stored in the '#new_raw'
2335
  * key of the return array.
2336
  *
2337
- * @access protected
2338
- *
2339
- * @param array $link
2340
  * @param array $info The callback function and the extra argument to pass to that function (if any).
 
2341
  * @return array
2342
  */
2343
  public static function editCallback($link, $info)
@@ -2368,15 +2459,17 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2368
  * of that string. If an array is returned, the current link will be modified/rebuilt
2369
  * by substituting the new values for the old ones.
2370
  * htmlentities() will be automatically applied to attribute values (but not to #link_text).
2371
- * @param string $content A text string containing the links to edit.
 
2372
  * @param callback $callback Callback function used to modify the links.
2373
- * @param mixed $extra If supplied, $extra will be passed as the second parameter to the function $callback.
 
2374
  * @return string The modified input string.
2375
  */
2376
  public static function multiEdit($content, $callback, $extra = null)
2377
  {
2378
  //Just reuse map() + a little helper func. to apply the callback to all links and get modified links
2379
- $modified_links = MetaSeoBrokenLinkTable::map(
2380
  $content,
2381
  array(
2382
  'MetaSeoBrokenLinkTable',
@@ -2397,7 +2490,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2397
  $new_html = '<a';
2398
  foreach ($link as $name => $value) {
2399
  //Skip special keys like '#raw' and '#offset'
2400
- if (substr($name, 0, 1) == '#') {
2401
  continue;
2402
  }
2403
 
@@ -2415,7 +2508,6 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2415
  }
2416
 
2417
  /**
2418
- * extractTags()
2419
  * Extract specific HTML tags and their attributes from a string.
2420
  *
2421
  * You can either specify one tag, an array of tag names, or a regular expression that matches the tag name(s).
@@ -2431,12 +2523,12 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2431
  * full_tag - the entire matched tag, e.g. '<a href="http://example.com">example.com</a>'. This key
2432
  * will only be present if you set $return_the_entire_tag to true.
2433
  *
2434
- * @param string $html The HTML code to search for tags.
2435
- * @param string|array $tag The tag(s) to extract.
2436
- * @param bool $selfclosing Whether the tag is self-closing or not.
2437
- * Setting it to null will force the script to try and make an educated guess.
2438
- * @param bool $return_the_entire_tag Return the entire matched tag in 'full_tag' key of the results array.
2439
- * @param string $charset The character set of the HTML code. Defaults to ISO-8859-1.
2440
  *
2441
  * @return array An array of extracted tags, or an empty array if no matching tags were found.
2442
  */
@@ -2526,9 +2618,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2526
  }
2527
 
2528
  $tag = array(
2529
- 'tag_name' => $match['tag'][0],
2530
- 'offset' => $match[0][1],
2531
- 'contents' => !empty($match['contents']) ? $match['contents'][0] : '', //empty for self-closing tags
2532
  'attributes' => $attributes,
2533
  );
2534
  if ($return_the_entire_tag) {
@@ -2552,10 +2644,12 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2552
  *
2553
  * Any attributes of the link tag will also be included in the returned array as attr_name => attr_value
2554
  * pairs. This function will also automatically decode any HTML entities found in attribute values.
2555
- * @param string $content A text string to parse for links.
 
2556
  * @param callback $callback Callback function to apply to all found links.
2557
- * @param mixed $extra If the optional $extra param. is supplied,
2558
- * it will be passed as the second parameter to the function $callback.
 
2559
  * @return array An array of all detected links after applying $callback to each of them.
2560
  */
2561
  public static function map($content, $callback, $extra = null)
@@ -2563,7 +2657,7 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2563
  $results = array();
2564
 
2565
  //Find all links
2566
- $links = MetaSeoBrokenLinkTable::extractTags($content, 'a', false, true);
2567
 
2568
  //Iterate over the links and apply $callback to each
2569
  foreach ($links as $link) {
@@ -2572,10 +2666,10 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2572
  $param = array_merge(
2573
  $param,
2574
  array(
2575
- '#raw' => $link['full_tag'],
2576
- '#offset' => $link['offset'],
2577
  '#link_text' => $link['contents'],
2578
- 'href' => isset($link['attributes']['href']) ? $link['attributes']['href'] : '',
2579
  )
2580
  );
2581
 
@@ -2592,40 +2686,46 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2592
  return $results;
2593
  }
2594
 
2595
- /*
2596
  * Ajax recheck link
 
 
2597
  */
2598
  public static function reCheckLink()
2599
  {
 
 
 
 
 
2600
  if (isset($_POST['link_id'])) {
2601
  global $wpdb;
2602
  $linkId = $_POST['link_id'];
2603
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($linkId));
2604
- $link = $wpdb->get_row($sql);
2605
  if (!empty($link)) {
2606
- if ($link->link_url_redirect != '') {
2607
  $status = 'HTTP/1.1 200 OK';
2608
  } else {
2609
- $status = MetaSeoBrokenLinkTable::getUrlStatus(($link->link_url));
2610
  }
2611
 
2612
- $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
2613
 
2614
- if ($link->type == '404_automaticaly') {
2615
- if (((int)substr($status, 9, 3) >= 301
2616
- && (int)substr($status, 9, 3) <= 304)
2617
- || ((int)substr($status, 9, 3) >= 400
2618
- && (int)substr($status, 9, 3) <= 503
2619
- && (int)substr($status, 9, 3) != 401) || $status == 'Server Not Found') {
2620
  $type = array('broken_indexed' => 1, 'broken_internal' => 0);
2621
  } else {
2622
  $type = array('broken_indexed' => 0, 'broken_internal' => 0);
2623
  }
2624
  } else {
2625
- if (((int)substr($status, 9, 3) >= 400
2626
- && (int)substr($status, 9, 3) <= 503
2627
- && (int)substr($status, 9, 3) != 401)
2628
- || $status == 'Server Not Found') {
2629
  $type = array('broken_internal' => 1, 'broken_indexed' => 0);
2630
  } else {
2631
  $type = array('broken_internal' => 0, 'broken_indexed' => 0);
@@ -2633,9 +2733,9 @@ class MetaSeoBrokenLinkTable extends WP_List_Table
2633
  }
2634
 
2635
  $value = array(
2636
- 'status_code' => $status,
2637
- 'status_text' => $status_text,
2638
- 'broken_indexed' => $type['broken_indexed'],
2639
  'broken_internal' => $type['broken_internal']
2640
  );
2641
 
12
  class MetaSeoBrokenLinkTable extends WP_List_Table
13
  {
14
  /**
15
+ * Img pattern
16
+ *
 
 
17
  * @var string
18
  */
19
  public static $img_pattern = '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i';
20
  /**
21
+ * Old URL
22
+ *
23
  * @var string
24
  */
25
  public static $old_url = '';
26
  /**
27
+ * New URL
28
+ *
29
  * @var string
30
  */
31
  public static $new_url = '';
37
  {
38
  parent::__construct(array(
39
  'singular' => 'metaseo_image',
40
+ 'plural' => 'metaseo_images',
41
+ 'ajax' => true
42
  ));
43
  }
44
 
45
  /**
46
  * Generate the table navigation above or below the table
47
+ *
48
+ * @param string $which Possition of table nav
49
+ *
50
+ * @return void
51
  */
52
+ protected function display_tablenav($which) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
53
  {
54
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
55
  if (!empty($post_types['attachment'])) {
56
  unset($post_types['attachment']);
57
  }
58
  ?>
59
+ <div class="<?php echo esc_attr('tablenav ' . $which); ?>">
60
 
61
+ <?php if ($which === 'top') : ?>
62
  <input type="hidden" name="page" value="metaseo_image_meta"/>
63
 
64
  <div class="alignleft actions bulkactions">
65
+ <?php $this->brokenFilter('sl_broken'); ?>
66
+ <?php $this->redirectFilter('sl_redirect'); ?>
67
+ <?php $this->typeFilter('sltype'); ?>
68
+ <?php $this->flushFilter('sl_flush'); ?>
69
  </div>
70
+ <?php elseif ($which === 'bottom') : ?>
71
  <input type="hidden" name="page" value="metaseo_image_meta"/>
72
  <div class="alignleft actions bulkactions">
73
+ <?php $this->brokenFilter('sl_broken1'); ?>
74
+ <?php $this->redirectFilter('sl_redirect1'); ?>
75
+ <?php $this->flushFilter('sltype1'); ?>
76
  </div>
77
  <?php endif ?>
78
 
79
  <input type="hidden" name="page" value="metaseo_image_meta"/>
 
 
 
 
80
  <div style="float:right;margin-left:8px;">
81
  <label>
82
+ <input type="number" required
83
+ value="<?php echo esc_attr($this->_pagination_args['per_page']) ?>"
84
  maxlength="3" name="metaseo_broken_link_per_page"
85
  class="metaseo_imgs_per_page screen-per-page"
86
  max="999" min="1" step="1">
88
 
89
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
90
  </div>
 
91
  <?php $this->pagination($which); ?>
92
  <br class="clear"/>
93
  </div>
98
  /**
99
  * Get a list of columns. The format is:
100
  * 'internal-name' => 'Title'
101
+ *
102
  * @return array
103
  */
104
+ public function get_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
105
  {
106
+ $columns = array(
107
+ 'col_link_url' => esc_html__('URL', 'wp-meta-seo'),
108
+ 'col_hit' => esc_html__('Hits number', 'wp-meta-seo'),
109
+ 'col_status' => esc_html__('Status', 'wp-meta-seo'),
110
+ 'col_link_text' => esc_html__('Type or Link text', 'wp-meta-seo'),
111
+ 'col_source' => esc_html__('Source', 'wp-meta-seo')
112
  );
113
+
114
+ return $columns;
115
  }
116
 
117
  /**
121
  * 'internal-name' => array( 'orderby', true )
122
  *
123
  * The second format will make the initial sorting order be descending
124
+ *
125
  * @return array
126
  */
127
+ protected function get_sortable_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
128
  {
129
+ $sortable = array(
130
+ 'col_status' => array('status_text', true),
131
  'col_link_url' => array('link_url', true)
132
  );
133
+
134
+ return $sortable;
135
  }
136
 
137
  /**
138
  * Print column headers, accounting for hidden and sortable columns.
139
  *
140
+ * @param boolean $with_id Whether to set the id attribute or not
 
141
  *
142
+ * @return void
143
  */
144
+ public function print_column_headers($with_id = true) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
145
  {
146
  list($columns, $hidden, $sortable) = $this->get_column_info();
147
 
148
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
149
  $current_url = remove_query_arg('paged', $current_url);
150
 
151
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
152
  if (isset($_GET['orderby'])) {
153
  $current_orderby = $_GET['orderby'];
154
  } else {
155
  $current_orderby = '';
156
  }
157
 
158
+ if (isset($_GET['order']) && 'desc' === $_GET['order']) {
159
  $current_order = 'desc';
160
  } else {
161
  $current_order = 'asc';
162
  }
163
+ // phpcs:enable
164
  if (!empty($columns['cb'])) {
165
  static $cb_counter = 1;
166
  $columns['cb'] = '<label class="screen-reader-text"
167
+ for="' . esc_attr('cb-select-all-' . $cb_counter) . '">' . esc_html__('Select All', 'wp-meta-seo') . '</label>'
168
+ . '<input id="' . esc_attr('cb-select-all-' . $cb_counter) . '" type="checkbox" style="margin:0;" />';
169
+ $cb_counter ++;
170
  }
171
 
172
  foreach ($columns as $column_key => $column_display_name) {
173
+ $class = array('manage-column', 'column-' . $column_key);
174
 
175
  $style = '';
176
  if (in_array($column_key, $hidden)) {
177
+ $style = 'style="display:none;"';
178
  }
 
179
 
180
+ if ('cb' === $column_key) {
181
  $class[] = 'check-column';
182
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
183
  $class[] = 'num';
186
  if (isset($sortable[$column_key])) {
187
  list($orderby, $desc_first) = $sortable[$column_key];
188
 
189
+ if ($current_orderby === $orderby) {
190
+ $order = 'asc' === $current_order ? 'desc' : 'asc';
191
  $class[] = 'sorted';
192
  $class[] = $current_order;
193
  } else {
194
+ $order = $desc_first ? 'desc' : 'asc';
195
  $class[] = 'sortable';
196
  $class[] = $desc_first ? 'asc' : 'desc';
197
  }
198
 
199
+ $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
200
+ $column_display_name = '<a href="' . esc_url($hr) . '">
201
+ <span>' . esc_html($column_display_name) . '</span>
202
+ <span class="sorting-indicator"></span></a>';
 
203
  }
204
 
205
+ $id = $with_id ? 'id="' . esc_attr($column_key) . '"' : '';
206
 
207
  if (!empty($class)) {
208
+ $class = "class='" . esc_attr(join(' ', $class)) . "'";
209
  }
210
 
211
+ // phpcs:disable WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
212
  if ($column_key === 'cb') {
213
+ echo '<th scope="col" ' . $id . ' ' . $class . ' style="padding:8px 10px;">' . $column_display_name . '</th>';
214
  } else {
215
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="3">' . $column_display_name . '</th>';
216
  }
217
+ // phpcs:enable
218
  }
219
  }
220
 
221
  /**
222
  * Prepares the list of items for displaying.
223
+ *
224
+ * @return void
225
  */
226
+ public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
227
  {
228
  global $wpdb;
229
  $where = array('1=1');
230
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
231
+ if (!empty($_REQUEST['sltype']) && $_REQUEST['sltype'] !== 'all') {
232
+ if ($_REQUEST['sltype'] !== 'other') {
233
+ $where[] = $wpdb->prepare('type = %s', array($_REQUEST['sltype']));
234
  } else {
235
  $where[] = "type IN ('comment','404_automaticaly')";
236
  }
237
  }
238
 
239
+ if (!empty($_REQUEST['sl_broken']) && $_REQUEST['sl_broken'] !== 'all') {
240
+ if ($_REQUEST['sl_broken'] === 'custom_redirect_url') {
241
  $where[] = "link_url_redirect !=''";
242
+ } elseif ($_REQUEST['sl_broken'] === 'valid_links') {
243
+ $where[] = 'broken_internal = 0 AND broken_indexed = 0';
244
+ } elseif ($_REQUEST['sl_broken'] === 'internal_broken_links') {
245
+ $where[] = 'broken_internal = 1';
246
  } else {
247
+ $where[] = 'broken_indexed = 1';
248
  }
249
  }
250
 
251
+ if (!empty($_REQUEST['sl_redirect']) && $_REQUEST['sl_redirect'] !== 'all') {
252
+ if ($_REQUEST['sl_redirect'] === 'already_redirect') {
253
+ $where[] = '(broken_internal = 1 OR broken_indexed = 1)';
254
+ $where[] = 'link_url_redirect !="" ';
255
  } else {
256
+ $where[] = '(broken_internal = 1 OR broken_indexed = 1)';
257
+ $where[] = 'link_url_redirect ="" ';
258
  }
259
  }
260
 
261
+ $keyword = !empty($_GET['txtkeyword']) ? $_GET['txtkeyword'] : '';
262
+ if (isset($keyword) && $keyword !== '') {
263
+ $where[] .= $wpdb->prepare('(link_text LIKE %s OR link_url LIKE %s)', array(
264
+ '%' . $keyword . '%',
265
+ '%' . $keyword . '%'
266
+ ));
 
 
 
 
 
 
 
267
  }
268
 
269
+ $orderby = !empty($_GET['orderby']) ? ($_GET['orderby']) : 'id';
270
+ $order = !empty($_GET['order']) ? ($_GET['order']) : 'asc';
271
+ $paged = !empty($_GET['paged']) ? $_GET['paged'] : '';
272
+ if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
273
+ $paged = 1;
 
 
 
 
274
  }
275
 
 
 
 
 
 
 
 
276
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
277
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
278
  } else {
279
  $_per_page = 0;
280
  }
281
+ // phpcs:enable
282
  $per_page = get_user_option('metaseo_broken_link_per_page');
283
  if ($per_page !== false) {
284
  if ($_per_page && $_per_page !== $per_page) {
294
  add_user_meta(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
295
  }
296
 
297
+ $sortable = $this->get_sortable_columns();
298
+ $orderby_array = array($orderby, true);
299
+ if (in_array($orderby_array, $sortable)) {
300
+ $orderStr = $orderby;
301
+ } else {
302
+ $orderStr = 'id';
303
+ }
304
+
305
+ if ($order === 'asc') {
306
+ $orderStr .= ' ASC';
307
+ } else {
308
+ $orderStr .= ' DESC';
309
+ }
310
+
311
+ if (!empty($orderby) & !empty($order)) {
312
+ $orderStr = ' ORDER BY ' . esc_sql($orderStr) . ' ';
313
  }
314
 
315
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
316
+ $total_items = $wpdb->get_var('SELECT COUNT(id) FROM ' . $wpdb->prefix . 'wpms_links WHERE ' . implode(' AND ', $where) . $orderStr);
317
+ $columns = $this->get_columns();
318
+ $hidden = array();
319
+ $sortable = $this->get_sortable_columns();
320
+ $this->_column_headers = array($columns, $hidden, $sortable);
321
+ $query = 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE ' . implode(' AND ', $where) . $orderStr;
322
+
323
  $total_pages = ceil($total_items / $per_page);
324
 
325
  if (!empty($paged) && !empty($per_page)) {
326
  $offset = ($paged - 1) * $per_page;
327
+ $query .= $wpdb->prepare(' LIMIT %d, %d', array($offset, $per_page));
328
  }
329
 
330
  $this->set_pagination_args(array(
331
  'total_items' => $total_items,
332
  'total_pages' => $total_pages,
333
+ 'per_page' => $per_page
334
  ));
335
 
336
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
337
  $this->items = $wpdb->get_results($query);
338
  }
339
 
340
  /**
341
  * Displays the search box.
342
+ *
343
+ * @return void
344
  */
345
  public function searchBox1()
346
  {
347
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
348
  require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/custom_redirect_form.php');
349
  }
350
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
351
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
352
  return;
353
  }
354
 
355
+ $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : '';
356
  if (!empty($_REQUEST['orderby'])) {
357
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
358
  }
368
  if (!empty($_REQUEST['detached'])) {
369
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
370
  }
371
+ // phpcs:enable
372
  ?>
373
  <p class="search-box">
374
  <label>
382
  }
383
 
384
  /**
385
+ * Add filter redirect
386
+ *
387
+ * @param string $name Filter name
388
+ *
389
+ * @return void
390
  */
391
+ public function redirectFilter($name)
392
  {
393
  $redirects = array(
394
+ 'not_yet_redirect' => esc_html__('Not yet redirected', 'wp-meta-seo'),
395
+ 'already_redirect' => esc_html__('Already redirected', 'wp-meta-seo')
396
  );
397
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
398
  $curent_redirect = isset($_REQUEST['sl_redirect']) ? $_REQUEST['sl_redirect'] : 'all';
399
  ?>
400
  <label for="filter-by-redirect"
401
+ class="screen-reader-text"><?php esc_html_e('Filter by redirect', 'wp-meta-seo'); ?></label>
402
+ <select name="<?php echo esc_html($name) ?>" id="filter-by-redirect" class="redirect_filter">
403
  <option<?php selected($curent_redirect, 'all'); ?> value="all">
404
+ <?php esc_html_e('Status', 'wp-meta-seo'); ?>
405
  </option>
406
  <?php
407
  foreach ($redirects as $k => $redirect) {
408
+ if ($curent_redirect === $k) {
409
+ echo '<option selected value="' . esc_attr($k) . '">' . esc_html($redirect) . '</option>';
410
  } else {
411
+ echo '<option value="' . esc_attr($k) . '">' . esc_html($redirect) . '</option>';
412
  }
413
  }
414
  ?>
418
  }
419
 
420
  /**
421
+ * Add filter broken
422
+ *
423
+ * @param string $name Selectbox name
424
+ *
425
+ * @return void
426
  */
427
+ public function brokenFilter($name)
428
  {
429
  $brokens = array(
430
+ 'valid_links' => esc_html__('Valid links', 'wp-meta-seo'),
431
+ 'automaticaly_indexed' => esc_html__('404 automaticaly indexed', 'wp-meta-seo'),
432
+ 'internal_broken_links' => esc_html__('Internal broken links', 'wp-meta-seo')
433
  );
434
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
435
+ $brokens['custom_redirect_url'] = esc_html__('Custom redirect URL', 'wp-meta-seo');
436
  }
437
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
438
  $curent_broken = isset($_REQUEST['sl_broken']) ? $_REQUEST['sl_broken'] : 'all';
439
  ?>
440
+ <label for="filter-by-broken"
441
+ class="screen-reader-text"><?php esc_html_e('Filter by broken', 'wp-meta-seo'); ?></label>
442
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-broken" class="broken_filter">
443
+ <option<?php selected($curent_broken, 'all'); ?>
444
+ value="all"><?php esc_html_e('All', 'wp-meta-seo'); ?></option>
445
  <?php
446
  foreach ($brokens as $k => $broken) {
447
+ if ($curent_broken === $k) {
448
+ echo '<option selected value="' . esc_attr($k) . '">' . esc_html($broken) . '</option>';
449
  } else {
450
+ echo '<option value="' . esc_attr($k) . '">' . esc_html($broken) . '</option>';
451
  }
452
  }
453
  ?>
457
  }
458
 
459
  /**
460
+ * Add filter type
461
+ *
462
+ * @param string $name Filter name
463
+ *
464
+ * @return void
465
  */
466
+ public function typeFilter($name)
467
  {
468
  $types = array(
469
+ 'url' => esc_html__('URL', 'wp-meta-seo'),
470
+ 'image' => esc_html__('Image', 'wp-meta-seo'),
471
+ 'other' => esc_html__('Other', 'wp-meta-seo')
472
  );
473
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
474
  $curent_type = isset($_REQUEST['sltype']) ? $_REQUEST['sltype'] : 'all';
475
  ?>
476
+ <label for="filter-by-type"
477
+ class="screen-reader-text"><?php esc_html_e('Filter by type', 'wp-meta-seo'); ?></label>
478
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-type" class="metaseo-filter">
479
+ <option<?php selected($curent_type, 'all'); ?>
480
+ value="all"><?php esc_html_e('Type', 'wp-meta-seo'); ?></option>
481
  <?php
482
  foreach ($types as $k => $type) {
483
+ if ($curent_type === $k) {
484
+ echo '<option selected value="' . esc_attr($k) . '">' . esc_html($type) . '</option>';
485
  } else {
486
+ echo '<option value="' . esc_attr($k) . '">' . esc_html($type) . '</option>';
487
  }
488
  }
489
  ?>
490
  </select>
491
  <input type="submit" name="filter_type_action" id="broken-submit"
492
+ class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="<?php esc_attr_e('Filter', 'wp-meta-seo') ?>">
493
  <?php
494
  echo '<div style="float:left;padding-left: 5px;"><div class="wpms_process" data-w="0"></div>';
495
  echo '<div data-comment_paged="1" data-paged="1" class="wpmsbtn wpmsbtn_small wpms_scan_link">';
496
+ esc_html_e('Index internal broken links', 'wp-meta-seo');
497
  echo '</div></div>';
498
  echo '<span class="spinner"></span>';
499
  }
500
 
501
  /**
502
+ * Add filter flush
503
+ *
504
+ * @param string $name Filter name
505
+ *
506
+ * @return void
507
  */
508
+ public function flushFilter($name)
509
  {
510
  $flushs = array(
511
+ 'automaticaly_indexed' => esc_html__('Automatic indexed 404', 'wp-meta-seo'),
512
+ 'internal_broken_links' => esc_html__('Internal broken links', 'wp-meta-seo'),
513
+ 'all' => esc_html__('Flush all 404', 'wp-meta-seo')
514
  );
515
  ?>
516
+ <label for="filter-by-flush"
517
+ class="screen-reader-text"><?php esc_html_e('Filter by flush', 'wp-meta-seo'); ?></label>
518
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-flush">
519
+ <option value="none"><?php esc_html_e('Select', 'wp-meta-seo'); ?></option>
520
  <?php
521
  foreach ($flushs as $k => $flush) {
522
+ echo '<option value="' . esc_attr($k) . '">' . esc_html($flush) . '</option>';
523
  }
524
  ?>
525
  </select>
526
 
527
  <?php
528
  echo '<div class="wpmsbtn wpmsbtn_small wpmsbtn_secondary wpms_flush_link">';
529
+ esc_html_e('Flush', 'wp-meta-seo');
530
  echo '</div>';
531
  }
532
 
533
  /**
534
  * Generate the table rows
535
+ *
536
+ * @return void
537
  */
538
+ public function display_rows() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
539
  {
540
  $records = $this->items;
541
+ $i = 0;
542
  list($columns, $hidden) = $this->get_column_info();
543
  if (!empty($records)) {
544
  foreach ($records as $rec) {
545
+ $i ++;
546
+ echo '<tr id="' . esc_attr('record_' . $i) . '" data-linkid="' . esc_attr($rec->id) . '"
547
+ data-link="' . esc_attr($i) . '" data-post_id="' . esc_attr($rec->source_id) . '">';
548
  foreach ($columns as $column_name => $column_display_name) {
549
  switch ($column_name) {
550
  case 'col_link_url':
551
+ if ($rec->type === 'url') {
552
  $value_url = $rec->link_final_url;
553
  } else {
554
  $value_url = $rec->link_url;
556
  echo '<td class="wpms_link_html" colspan="3">';
557
  echo '<input type="hidden" class="wpms_link_text"
558
  value="' . esc_attr($rec->link_text) . '">';
559
+ if ($rec->type === 'add_custom') {
560
  echo '<a class="link_html" target="_blank"
561
+ href="' . esc_url(site_url() . '/' . $rec->link_url) . '">' . esc_html($value_url) . '</a>';
562
+ if ($rec->link_url_redirect !== '') {
563
  echo ' to ';
564
  echo '<a class="link_html" target="_blank"
565
  href="' . esc_url($rec->link_url_redirect) . '"
566
+ >' . esc_html(str_replace(site_url(), '', $rec->link_url_redirect)) . '</a>';
567
  }
568
  } else {
569
  echo '<a class="link_html" target="_blank"
570
+ href="' . esc_url($value_url) . '">' . esc_html($value_url) . '</a>';
571
  }
572
 
573
  $row_action = array(
574
+ 'edit' => '<a class="wpms_action_link wpms-edit-button"
575
+ title="' . esc_attr__('Edit redirect', 'wp-meta-seo') . '">
576
  <div class="wpms_icon_action"><i class="material-icons">mode_edit</i></div>
577
+ <span>' . esc_html__('Edit', 'wp-meta-seo') . '</span></a>',
578
+ 'delete' => '<a class="wpms_action_link submitdelete wpms-unlink-button"
579
+ data-link_id="' . esc_attr($rec->id) . '" data-type="' . esc_attr($rec->type) . '"
580
+ data-source_id="' . esc_attr($rec->source_id) . '"
581
+ title="' . esc_attr__('Remove redirect or link', 'wp-meta-seo') . '">
582
  <div class="wpms_icon_action"><i class="material-icons">delete_forever</i></div>
583
+ <span>' . esc_html__('Remove redirect', 'wp-meta-seo') . '</span></a>',
584
  'recheck' => '<a class="wpms_action_link wpms-recheck-button"
585
+ data-link_id="' . esc_attr($rec->id) . '" data-type="' . esc_attr($rec->type) . '"
586
+ data-source_id="' . esc_attr($rec->source_id) . '"
587
+ title="' . esc_attr__('Check the link', 'wp-meta-seo') . '">
588
  <div class="wpms_icon_action"><i class="material-icons">loop</i></div>
589
+ <span>' . esc_html__('Check', 'wp-meta-seo') . '</span></a>'
590
  );
591
+
592
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
593
  echo $this->row_actions($row_action, false);
594
  $iii = 0;
595
  $jjj = 0;
596
  if (!empty($rec->source_id)) {
597
+ if ($rec->type === 'url') {
598
  $pos = get_post($rec->source_id);
599
  if (!empty($pos)) {
600
  preg_match_all(
601
+ '#<a[^>]*>.*?</a>#si',
602
  $pos->post_content,
603
  $matches,
604
  PREG_PATTERN_ORDER
606
  foreach ($matches[0] as $i => $content) {
607
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
608
  $href = $matches[1];
609
+ if ($href === $rec->link_url) {
610
+ $iii ++;
611
  }
612
  }
613
  }
614
+ } elseif ($rec->type === 'comment_content_url') {
615
  $com = get_comment($rec->source_id);
616
  if (!empty($pos)) {
617
  preg_match_all(
618
+ '#<a[^>]*>.*?</a>#si',
619
  $com->comment_content,
620
  $matches,
621
  PREG_PATTERN_ORDER
623
  foreach ($matches[0] as $i => $content) {
624
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
625
  $href = $matches[1];
626
+ if ($href === $rec->link_url) {
627
+ $jjj ++;
628
  }
629
  }
630
  }
632
  }
633
  ?>
634
  <div class="wpms-inline-editor-content">
635
+ <h4><?php esc_html_e('Edit Link', 'wp-meta-seo'); ?></h4>
636
  <?php
637
+ if ($rec->type === 'url') {
638
  if ($iii > 1) {
639
  echo '<span class="wpms-input-text-wrap">
640
+ <span class="title">' . esc_html__('Text', 'wp-meta-seo') . '</span>
641
  <input type="text" name="link_text" class="wpms-link-text-field"
642
+ placeholder="' . esc_attr__('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
643
  } else {
644
  echo '<span class="wpms-input-text-wrap">
645
+ <span class="title">' . esc_html__('Text', 'wp-meta-seo') . '</span>
646
  <input type="text" name="link_text" class="wpms-link-text-field"
647
  value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
648
  }
649
+ } elseif ($rec->type === 'comment_content_url') {
650
  if ($jjj > 1) {
651
  echo '<span class="wpms-input-text-wrap">
652
+ <span class="title">' . esc_html__('Text', 'wp-meta-seo') . '</span>
653
  <input type="text" name="link_text" class="wpms-link-text-field"
654
+ placeholder="' . esc_attr__('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
655
  } else {
656
  echo '<span class="wpms-input-text-wrap">
657
+ <span class="title">' . esc_html__('Text', 'wp-meta-seo') . '</span>
658
  <input type="text" name="link_text" class="wpms-link-text-field"
659
  value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
660
  }
661
  } else {
662
+ if ($rec->type !== 'add_custom') {
663
  echo '<span class="wpms-input-text-wrap">
664
+ <span class="title">' . esc_html__('Text', 'wp-meta-seo') . '</span>
665
  <input readonly type="text" name="link_text" class="wpms-link-text-field" value="(None)" data-type="only" /></span>';
666
  } else {
667
  ?>
668
  <p class="wpms-input-text-wrap">
669
  <span class="title">
670
+ <?php esc_html_e('Status', 'wp-meta-seo') ?>
671
  </span>
672
  <label>
673
  <select name="custom_redirect_status" class="custom_redirect_status">
688
  <p class="wpms-input-text-wrap">
689
  <span
690
  class="title">
691
+ <?php esc_html_e('URL', 'wp-meta-seo'); ?>
692
  </span>
693
  <label>
694
+ <input <?php echo ($rec->type === '404_automaticaly') ? 'readonly' : '' ?>
695
  type="text" name="link_url" class="wpms-link-url-field"
696
  value="<?php echo esc_attr($value_url); ?>"/>
697
  </label>
698
  </p>
699
  <p class="wpms-input-text-wrap">
700
+ <span class="title"><?php esc_html_e('Redirect', 'wp-meta-seo'); ?></span>
701
  <label>
702
  <input type="text" name="link_url_redirect" class="wpms-link-redirect-field"
703
  value="<?php echo esc_attr($rec->link_url_redirect); ?>"/>
712
  class="wpmsbtn wpmsbtn_small wpmsbtn_secondary
713
  cancel alignleft wpms-cancel-button"
714
  value="<?php echo esc_attr(__('Cancel', 'wp-meta-seo')); ?>"/>
715
+ <input type="button" data-type="<?php echo esc_html($rec->type) ?>"
716
+ data-link_id="<?php echo esc_attr($rec->id) ?>"
717
+ data-source_id="<?php echo esc_attr($rec->source_id) ?>"
718
  class="wpmsbtn wpmsbtn_small save alignright wpms-update-link-button"
719
  value="<?php echo esc_attr(__('Add custom redirect', 'wp-meta-seo')); ?>"/>
720
  </div>
725
 
726
  case 'col_hit':
727
  echo '<td colspan="3" style="text-align:center;">';
728
+ echo esc_html($rec->hit);
729
  echo '</td>';
730
  break;
731
  case 'col_status':
732
  echo '<td colspan="3" class="col_status">';
733
  if (strpos($rec->status_text, '200') !== false) {
734
+ echo '<i class="material-icons wpms_ok metaseo_help_status" data-alt="Link is OK">done</i>';
735
  } elseif (strpos($rec->status_text, '301') !== false) {
736
  echo '<i class="material-icons wpms_ok metaseo_help_status"
737
+ data-alt="Permanent redirect">done</i>';
738
  } elseif (strpos($rec->status_text, '302') !== false) {
739
  echo '<i class="material-icons wpms_ok metaseo_help_status"
740
+ data-alt="Moved temporarily">done</i>';
741
  } elseif (strpos($rec->status_text, '404') !== false
742
+ || $rec->status_text === 'Server Not Found') {
743
  $wpms_settings_404 = get_option('wpms_settings_404');
744
  if ((isset($wpms_settings_404['wpms_redirect_homepage'])
745
+ && (int) $wpms_settings_404['wpms_redirect_homepage'] === 1)
746
+ || $rec->link_url_redirect !== '') {
747
  echo '<i class="material-icons wpms_ok metaseo_help_status"
748
+ data-alt="Permanent redirect">done</i>';
749
  } else {
750
  echo '<i class="material-icons wpms_warning metaseo_help_status"
751
+ data-alt="404 error, not found">warning</i>';
752
  }
753
  } else {
754
+ echo esc_html($rec->status_text);
755
  }
756
 
757
  echo '</td>';
758
  break;
759
 
760
  case 'col_link_text':
761
+ if ($rec->type === 'image' || $rec->type === 'comment_content_image') {
762
  echo '<td colspan="3" class="link_text">
763
+ <span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" data-alt="Images">photo</i></span>
764
+ <span> ' . esc_html__('Image', 'wp-meta-seo') . '</span></td>';
765
+ } elseif ($rec->type === 'comment') {
766
+ echo '<td colspan="3" class="link_text"><span> ' . esc_html($rec->link_text) . '</span></td>';
767
  } else {
768
+ if (strip_tags($rec->link_text) !== '') {
769
+ echo '<td colspan="3" class="link_text">' . esc_html(strip_tags($rec->link_text)) . '</td>';
770
  } else {
771
  echo '<td colspan="3" class="link_text">
772
+ <i>' . esc_html__('No text on this link', 'wp-meta-seo') . '</i></td>';
773
  }
774
  }
775
 
777
 
778
  case 'col_source':
779
  $source_inner = '';
780
+ $row_action = array();
781
+ if ($rec->type === '404_automaticaly') {
782
  $source_inner = '<span style="float: left;margin-right: 5px;">
783
+ <i class="material-icons metaseo_help_status" data-alt="External URL indexed">link</i></span>';
784
+ $source_inner .= esc_html__('404 automaticaly indexed', 'wp-meta-seo');
785
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
786
  echo '<td colspan="3">' . $source_inner . '</td>';
787
  } else {
788
+ if ($rec->type === 'comment' || $rec->type === 'comment_content_url'
789
+ || $rec->type === 'comment_content_image') {
790
  $source = get_comment($rec->source_id);
791
  if (!empty($source)) {
792
  $row_action = array(
793
  'edit' => '<a target="_blank"
794
+ href="' . esc_url(get_edit_comment_link($rec->source_id)) . '"
795
+ title="' . esc_attr__('Edit this item', 'wp-meta-seo') . '">
796
+ ' . esc_html__('Edit', 'wp-meta-seo') . '</a>',
797
  'view' => '<a target="_blank"
798
+ href="' . esc_url(get_comment_link($rec->source_id)) . '"
799
+ title="' . esc_attr('View &#8220;' . $source->comment_author . '&#8221;') . '" rel="permalink">
800
+ ' . esc_html__('View', 'wp-meta-seo') . '</a>'
801
  );
802
 
803
+ if ($rec->type === 'comment') {
804
  $source_inner = '<span style="float: left;margin-right: 5px;">
805
+ <i class="material-icons metaseo_help_status" data-alt="Comments">person_outline</i></span>';
806
  } else {
807
  $source_inner = '<span style="float: left;margin-right: 5px;">
808
+ <i class="material-icons metaseo_help_status" data-alt="Comments content">chat_bubble</i></span>';
809
  }
810
  $source_inner .= '<a target="_blank"
811
  href="' . get_edit_comment_link($rec->source_id) . '">
812
+ ' . esc_html($source->comment_author) . '</a>';
813
  }
814
  } else {
815
  $source = get_post($rec->source_id);
816
  if (!empty($source)) {
817
  $row_action = array(
818
  'edit' => '<a target="_blank"
819
+ href="' . esc_url(get_edit_post_link($rec->source_id)) . '"
820
+ title="' . esc_attr__('Edit this item', 'wp-meta-seo') . '">
821
+ ' . esc_html__('Edit', 'wp-meta-seo') . '</a>',
822
  'view' => '<a target="_blank"
823
+ href="' . esc_url(get_post_permalink($rec->source_id)) . '"
824
+ title="' . esc_attr('View &#8220;' . $source->post_title . '&#8221;') . '"
825
  rel="permalink">View</a>'
826
  );
827
 
828
  $source_inner = '<span style="float: left;margin-right: 5px;">
829
+ <i class="material-icons metaseo_help_status" data-alt="Post , Page , Custom post">layers</i></span>';
830
  $source_inner .= '<a target="_blank"
831
+ href="' . esc_url(get_edit_post_link($rec->source_id)) . '">
832
+ ' . esc_html($source->post_title) . '</a>';
833
  }
834
  }
835
 
836
  echo '<td colspan="3">';
837
  if (!empty($source)) {
838
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
839
  echo $source_inner;
840
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
841
  echo $this->row_actions($row_action, false);
842
  } else {
843
+ if ($rec->type === 'add_custom' || $rec->type === 'add_rule') {
844
+ echo '<a><i title="' . esc_attr__('Custom redirect', 'wp-meta-seo') . '"
845
  class="wpms_outgoing material-icons">call_missed_outgoing</i></a>';
846
  } else {
847
+ echo '<a>' . esc_html__('Source Not Found', 'wp-meta-seo') . '</a>';
848
  }
849
  }
850
  echo '</td>';
858
  }
859
  }
860
 
861
+ /**
862
  * Retrieves a modified URL query string.
863
+ *
864
+ * @return void
865
  */
866
  public function processAction()
867
  {
868
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
869
+ $redirect = false;
870
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
871
  if (isset($_POST['search'])) {
872
  $current_url = add_query_arg(
873
  array(
874
+ 'search' => 'Search',
875
+ 'txtkeyword' => urlencode(stripslashes($_POST['txtkeyword']))
876
+ ),
877
  $current_url
878
  );
879
+ $redirect = true;
880
  }
881
 
882
  if (isset($_POST['filter_type_action'])) {
883
  $current_url = add_query_arg(
884
  array(
885
+ 'sltype' => $_POST['sltype'],
886
+ 'sl_redirect' => $_POST['sl_redirect'],
887
+ 'sl_broken' => $_POST['sl_broken']
888
  ),
889
  $current_url
890
  );
891
+ $redirect = true;
892
  }
893
 
894
  if (!empty($_POST['paged'])) {
895
+ $current_url = add_query_arg(array('paged' => intval($_POST['paged'])), $current_url);
896
+ $redirect = true;
897
  }
898
 
899
  if (!empty($_POST['metaseo_broken_link_per_page'])) {
900
  $current_url = add_query_arg(
901
  array(
902
+ 'metaseo_broken_link_per_page' => intval($_POST['metaseo_broken_link_per_page'])
903
  ),
904
  $current_url
905
  );
906
+ $redirect = true;
907
  }
908
+ // phpcs:enable
909
+ if ($redirect) {
910
  wp_redirect($current_url);
911
  ob_end_flush();
912
  exit();
915
 
916
  /**
917
  * Get link details
918
+ *
919
+ * @param string $source_link Link source container current link
920
+ * @param integer $source_id Id source container current link
921
+ * @param string $url Link url
922
+ * @param string $link_text Link text
923
+ * @param string $type Link type
924
+ * @param string $status Link status
925
+ * @param string $status_type Link status type
926
+ * @param string $meta_title Title of link
927
+ * @param string $rel Link rel
928
+ * @param integer $postID Post id
929
+ *
930
  * @return array
931
  */
932
  public static function getResultLink(
943
  ) {
944
  $res = array(
945
  'source_link' => $source_link,
946
+ 'source_id' => (int) $source_id,
947
+ 'link_url' => $url,
948
+ 'link_text' => $link_text,
949
+ 'type' => $type,
950
+ 'status' => $status,
951
+ 'status_type' => $status_type
952
+ );
953
 
954
  if (isset($meta_title)) {
955
  $res['meta_title'] = $meta_title;
957
  $res['meta_title'] = '';
958
  }
959
 
960
+ if (isset($rel) && $rel === 'nofollow') {
961
  $res['follow'] = 0;
962
  } else {
963
  $res['follow'] = 1;
966
  if (strpos($url, 'mailto:') !== false) {
967
  $res['link_final_url'] = $url;
968
  } else {
969
+ if ($type === 'url') {
970
+ if (!preg_match('~^(?:f|ht)tps?://~i', $url)) {
971
  $perlink = get_option('permalink_structure');
972
  if (empty($perlink)) {
973
  $res['link_final_url'] = get_site_url() . '/' . $url;
991
 
992
  /**
993
  * Get link status
994
+ *
995
+ * @param string $url Url to get status
996
+ * @param string $type Type
997
+ *
998
  * @return string
999
  */
1000
+ public static function getUrlStatus($url, $type = '')
1001
  {
1002
  if (strpos($url, 'mailto:') !== false) {
1003
  return 'Not checked';
1007
  return 'HTTP/1.1 200 OK';
1008
  }
1009
 
1010
+ if ($type === 'update_post') {
1011
  return 'HTTP/1.1 200 OK';
1012
  }
1013
+ $status = get_headers($url, 0);
1014
  if (isset($status[0])) {
1015
  return $status[0];
1016
  } else {
1020
 
1021
  /**
1022
  * Get link status type
1023
+ *
1024
+ * @param string $status Status label
1025
+ *
1026
  * @return string
1027
  */
1028
  public static function getUrlStatusType($status)
1029
  {
1030
+ if (isset($status) && $status === 'Not checked') {
1031
  return 'ok';
1032
  }
1033
 
1034
+ if (isset($status) && $status !== 'Server Not Found') {
1035
+ if (((int) substr($status, 9, 3) >= 200
1036
+ && (int) substr($status, 9, 3) <= 204) || (int) substr($status, 9, 3) === 401) {
1037
  $type = 'ok';
1038
+ } elseif (((int) substr($status, 9, 3) >= 400
1039
+ && (int) substr($status, 9, 3) <= 503 && (int) substr($status, 9, 3) !== 401)) {
1040
+ if (in_array((int) substr($status, 9, 3), array(404, 410))) {
1041
  $type = 'broken_internal';
1042
  } else {
1043
  $type = 'warning';
1044
  }
1045
+ } elseif (((int) substr($status, 9, 3) >= 301 && (int) substr($status, 9, 3) <= 304)) {
1046
  $type = 'ok';
1047
  } else {
1048
  $type = 'dismissed';
1055
 
1056
  /**
1057
  * Delete link comment in wpms_links table when delete comment
1058
+ *
1059
+ * @param integer $comment_ID Comment id
1060
+ *
1061
+ * @return void
1062
  */
1063
  public static function deletedComment($comment_ID)
1064
  {
1065
  global $wpdb;
1066
  $wpdb->query(
1067
  $wpdb->prepare(
1068
+ 'DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id = %d AND (type = %s || type = %s || type = %s)',
1069
+ array(
1070
+ $comment_ID,
1071
+ 'comment',
1072
+ 'comment_content_url',
1073
+ 'comment_content_image'
1074
+ )
1075
  )
1076
  );
1077
  }
1078
 
1079
  /**
1080
  * Delete link post in wpms_links table when delete post
1081
+ *
1082
+ * @param integer $post_id Post id
1083
+ *
1084
+ * @return void
1085
  */
1086
  public static function deletePost($post_id)
1087
  {
1088
  global $wpdb;
1089
  $wpdb->query(
1090
  $wpdb->prepare(
1091
+ 'DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id = %d
1092
+ AND type != %s',
1093
+ array(
1094
+ $post_id,
1095
+ 'comment'
1096
+ )
1097
  )
1098
  );
1099
  }
1100
 
1101
  /**
1102
  * Update wpms_links table when update comment
1103
+ *
1104
+ * @param integer $comment_ID Id of current comment
1105
+ *
1106
+ * @return void
1107
  */
1108
  public static function updateComment($comment_ID)
1109
  {
1110
+ if (empty($_POST['_wpnonce'])
1111
+ || !wp_verify_nonce($_POST['_wpnonce'], 'update-comment_' . $comment_ID)) {
1112
+ die();
1113
+ }
1114
+
1115
  global $wpdb;
1116
  $comment = get_comment($comment_ID);
1117
+ $status = wp_get_comment_status($comment_ID);
1118
+ if ($status === 'approved') {
1119
  if (!empty($comment->comment_author_url)) {
1120
+ $status = self::getUrlStatus(($comment->comment_author_url));
1121
+ $status_text = self::getStatusText($status);
1122
+ $status_type = self::getUrlStatusType($status);
1123
+ $check = $wpdb->get_var($wpdb->prepare(
1124
+ 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id=%d AND type=%s ',
1125
  array(
1126
  $comment_ID,
1127
  'comment'
1128
  )
1129
+ ));
1130
+ if ((int) $check === 0) {
 
1131
  $value = array(
1132
+ 'link_url' => $comment->comment_author_url,
1133
+ 'link_text' => $comment->comment_author,
1134
+ 'source_id' => $comment_ID,
1135
+ 'type' => 'comment',
1136
+ 'status_code' => $status,
1137
+ 'status_text' => $status_text,
1138
+ 'broken_indexed' => 0,
1139
  'broken_internal' => 0,
1140
+ 'warning' => 0,
1141
+ 'dismissed' => 0,
1142
  );
1143
+ if (isset($status_type) && $status_type !== 'ok') {
1144
  $value[$status_type] = 1;
1145
  }
1146
  $wpdb->insert(
1148
  $value
1149
  );
1150
  } else {
1151
+ $value = array(
1152
+ 'link_url' => $comment->comment_author_url,
1153
+ 'status_code' => $status,
1154
+ 'status_text' => $status_text,
1155
+ 'broken_indexed' => 0,
1156
  'broken_internal' => 0,
1157
+ 'warning' => 0,
1158
+ 'dismissed' => 0,
1159
  );
1160
 
1161
  if (isset($_POST['link_redirect'])) {
1162
  $value['link_url_redirect'] = ($_POST['link_redirect']);
1163
  }
1164
 
1165
+ if (isset($status_type) && $status_type !== 'ok') {
1166
  $value[$status_type] = 1;
1167
  }
1168
  $wpdb->update(
1170
  $value,
1171
  array(
1172
  'source_id' => $comment_ID,
1173
+ 'type' => 'comment'
1174
  ),
1175
  array('%s', '%s', '%s', '%d', '%d', '%d', '%d'),
1176
  array('%d', '%s')
1179
  } else {
1180
  $wpdb->query(
1181
  $wpdb->prepare(
1182
+ 'DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id = %d AND (type = %s)',
1183
  array(
1184
+ (int) $comment_ID,
1185
  'comment'
1186
  )
1187
  )
1189
  }
1190
 
1191
  $linkscontent = array();
1192
+ if (isset($comment->comment_content) && $comment->comment_content !== '') {
1193
+ preg_match_all('#<a[^>]*>.*?</a>#si', $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1194
  foreach (array_unique($matches[0]) as $i => $content) {
1195
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1196
+ $href = $matches[1];
1197
+ $status = self::getUrlStatus($href);
1198
+ $status_type = self::getUrlStatusType($status);
1199
+ $link_text = preg_replace('/<a\s(.+?)>(.+?)<\/a>/is', '$2', $content);
1200
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1201
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1202
+ $source_link .= '</a>';
1203
+ $key = $href . 'comment_content_url' . $comment->comment_ID . $link_text;
1204
+ $linkscontent[$key] = self::getResultLink(
1205
  $source_link,
1206
  $comment->comment_ID,
1207
  $href,
1219
  );
1220
  foreach (array_unique($matches[0]) as $content) {
1221
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1222
+ $src = $matches[1];
1223
+ $status = self::getUrlStatus($src);
1224
+ $status_type = self::getUrlStatusType($status);
1225
+ $link_text = '';
1226
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1227
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1228
+ $source_link .= '</a>';
1229
+ $key = $src . 'comment_content_image' . $comment->comment_ID;
1230
+ $linkscontent[$key] = self::getResultLink(
1231
  $source_link,
1232
  $comment->comment_ID,
1233
  $src,
1239
  }
1240
  }
1241
 
1242
+ $links = $wpdb->get_results($wpdb->prepare(
1243
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id=%d AND (type = %s || type = %s)',
1244
  array(
1245
+ (int) $comment->comment_ID,
1246
+ 'comment_content_url',
1247
+ 'comment_content_image'
1248
  )
1249
+ ));
 
1250
  foreach ($links as $link) {
1251
  if (empty($linkscontent[$link->link_url . $link->type])) {
1252
+ $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => $link->id), array('%d'));
1253
  } else {
1254
  unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1255
  }
1257
 
1258
  if (!empty($linkscontent)) {
1259
  foreach ($linkscontent as $link) {
1260
+ self::insertLink($link, $wpdb);
1261
  }
1262
  }
1263
  } else {
1264
  $wpdb->query(
1265
  $wpdb->prepare(
1266
+ 'DELETE FROM ' . $wpdb->prefix . 'wpms_links
1267
+ WHERE source_id = %d AND (type = %s || type = %s || type = %s)',
1268
  array(
1269
+ (int) $comment_ID,
1270
  'comment',
1271
  'comment_content_url',
1272
  'comment_content_image'
1280
 
1281
  /**
1282
  * Update wpms_links table when update post
1283
+ *
1284
+ * @param integer $post_ID Id of current post
1285
+ * @param string $post_after Post content after update
1286
+ * @param string $post_before Post content before update
1287
+ *
1288
+ * @return void
1289
  */
1290
  public static function updatePost($post_ID, $post_after, $post_before)
1291
  {
1292
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1293
+ unset($post_types['attachment']);
1294
+ if (!in_array($post_after->post_type, $post_types)) {
1295
+ return;
1296
+ }
1297
+
1298
  global $wpdb;
1299
  $post = $post_after;
1300
+ $dom = new DOMDocument;
1301
  libxml_use_internal_errors(true);
1302
  $linkscontent = array();
1303
 
1304
+ if ($post->post_excerpt !== 'metaseo_404_page') {
1305
+ if ($post->post_status === 'publish') {
1306
+ if (isset($post->post_content) && $post->post_content !== '') {
1307
  // find <a> tag in current post content
1308
+ preg_match_all('#<a[^>]*>.*?</a>#si', $post->post_content, $matches, PREG_PATTERN_ORDER);
1309
  foreach (array_unique($matches[0]) as $i => $content) {
1310
  $dom->loadHTML($content);
1311
+ $tags = $dom->getElementsByTagName('a');
1312
  $meta_title = $tags->item(0)->getAttribute('title');
1313
+ $rel = $tags->item(0)->getAttribute('rel');
1314
 
1315
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1316
+ $href = $matches[1];
1317
+ $status = self::getUrlStatus($href, 'update_post');
1318
+ $status_type = self::getUrlStatusType($status);
1319
+ $link_text = preg_replace('/<a\s(.+?)>(.+?)<\/a>/is', '$2', $content);
1320
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1321
+ $source_link .= '<b>' . $post->post_title . '</b>';
1322
+ $source_link .= '</a>';
1323
+ $key = $href . 'url' . $post->ID . $link_text;
1324
+ $linkscontent[$key] = self::getResultLink(
1325
  $source_link,
1326
  $post->ID,
1327
  $href,
1346
  $source_link .= '<b>' . $post->post_title . '</b>';
1347
  $source_link .= '</a>';
1348
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1349
+ $src = $matches[1];
1350
+ $status = self::getUrlStatus($src, 'update_post');
1351
+ $status_type = self::getUrlStatusType($status);
1352
+ $link_text = '';
1353
+ $linkscontent[$src . 'img' . $post->ID] = self::getResultLink(
1354
  $source_link,
1355
  $post->ID,
1356
  $src,
1362
  }
1363
  }
1364
 
1365
+ $links = $wpdb->get_results($wpdb->prepare(
1366
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE source_id=%d AND type != %s',
1367
  array(
1368
  $post->ID,
1369
+ 'comment'
1370
  )
1371
+ ));
 
1372
  foreach ($links as $link) {
1373
  if (empty($linkscontent[$link->link_url . $link->type])) {
1374
+ $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => $link->id), array('%d'));
1375
  } else {
1376
  unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1377
  }
1379
 
1380
  if (!empty($linkscontent)) {
1381
  foreach ($linkscontent as $link) {
1382
+ self::insertLink($link, $wpdb);
1383
  }
1384
  }
1385
  } else {
1386
  $wpdb->query(
1387
  $wpdb->prepare(
1388
+ 'DELETE FROM ' . $wpdb->prefix . 'wpms_links
1389
+ WHERE source_id = %d AND (type = %s || type = %s)',
1390
  array(
1391
  $post->ID,
1392
  'image',
1402
 
1403
  /**
1404
  * Scan link in comment , post
1405
+ *
1406
+ * @return void
1407
  */
1408
  public static function scanLink()
1409
  {
1410
+ if (empty($_POST['wpms_nonce'])
1411
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1412
+ die();
 
 
 
 
 
 
1413
  }
1414
 
1415
+ global $wpdb;
1416
+ $limit_comment_content = 1;
1417
+ $limit_comment = 10;
1418
+ $limit_post = 1;
1419
+ $total_comments = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'comments');
 
 
 
 
 
 
 
 
 
 
 
 
 
1420
  $percent_comment_content = 33.33;
1421
+ $percent_comment = 33.33;
 
 
1422
  if (!empty($total_comments)) {
1423
  $percent_comment_content = 33.33 / $total_comments;
1424
  }
1435
  $percent_comment = 33.33;
1436
  }
1437
 
 
 
 
 
 
 
 
 
1438
  // scan link in comment url
1439
+ $comments = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'comments
1440
+ WHERE comment_approved = 1 AND comment_author_url != "" AND comment_author_url NOT IN (SELECT link_url
1441
+ FROM ' . $wpdb->prefix . 'wpms_links WHERE type = %s) LIMIT %d', array('comment', $limit_comment)));
1442
 
1443
  if (!empty($comments)) {
1444
  foreach ($comments as $comment) {
1446
  $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1447
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1448
  $source_link .= '</a>';
1449
+ $status = self::getUrlStatus($comment->comment_author_url);
1450
+ $status_type = self::getUrlStatusType($status);
1451
+ $coms = self::getResultLink(
1452
  $source_link,
1453
  $comment->comment_ID,
1454
  $comment->comment_author_url,
1457
  $status,
1458
  $status_type
1459
  );
1460
+ self::insertLink($coms, $wpdb);
1461
  }
1462
  }
1463
  wp_send_json(array('status' => false, 'type' => 'limit', 'percent' => $percent_comment));
1471
  $off_set = 0;
1472
  }
1473
 
1474
+ $comments_content = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'comments
1475
+ WHERE comment_approved = 1 AND comment_content != "" LIMIT %d OFFSET %d', array(
1476
+ $limit_comment_content,
1477
+ $off_set
1478
+ )));
1479
  if (!empty($comments_content)) {
1480
  foreach ($comments_content as $comment) {
1481
+ if (isset($comment->comment_content) && $comment->comment_content !== '') {
1482
+ preg_match_all('#<a[^>]*>.*?</a>#si', $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1483
  foreach (array_unique($matches[0]) as $i => $content) {
1484
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1485
+ $href = $matches[1];
1486
+ $status = self::getUrlStatus($href);
1487
+ $status_type = self::getUrlStatusType($status);
1488
+ $link_text = preg_replace('/<a\s(.+?)>(.+?)<\/a>/is', '$2', $content);
1489
  $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1490
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1491
  $source_link .= '</a>';
1492
+ $link_a = self::getResultLink(
1493
  $source_link,
1494
  $comment->comment_ID,
1495
  $href,
1498
  $status,
1499
  $status_type
1500
  );
1501
+ self::insertLink($link_a, $wpdb);
1502
  }
1503
  preg_match_all(
1504
  '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1511
  $source_link .= '<b>' . $comment->comment_author . '</b>';
1512
  $source_link .= '</a>';
1513
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1514
+ $src = $matches[1];
1515
+ $status = self::getUrlStatus($src);
1516
+ $status_type = self::getUrlStatusType($status);
1517
+ $link_text = '';
1518
+ $link_sou = self::getResultLink(
1519
  $source_link,
1520
  $comment->comment_ID,
1521
  $src,
1524
  $status,
1525
  $status_type
1526
  );
1527
+ self::insertLink($link_sou, $wpdb);
1528
  }
1529
  }
1530
  }
1531
 
1532
+ $k ++;
1533
  if ($k >= $limit_comment_content) {
1534
  wp_send_json(
1535
  array(
1536
+ 'status' => false,
1537
+ 'type' => 'limit_comment_content',
1538
+ 'paged' => $_POST['comment_paged'],
1539
  'percent' => $percent_comment_content * count($comments_content)
1540
  )
1541
  );
1543
  }
1544
 
1545
  // scan link in post
1546
+ $j = 0;
1547
+ $off_set = ($_POST['paged'] - 1) * $limit_post;
1548
+ $post_types = MetaSeoContentListTable::getPostTypes('attachment');
1549
+ foreach ($post_types as &$post_type) {
1550
+ $post_type = esc_sql($post_type);
1551
+ }
1552
+ $post_types = implode("', '", $post_types);
1553
+
1554
+ $where = array();
1555
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
1556
+ $where[] = 'post_status = "publish"';
1557
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
1558
+ $total_posts = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where));
1559
+ $percent_post = 33.33;
1560
+ if (!empty($total_posts)) {
1561
+ $percent_post = 33.33 / $total_posts;
1562
+ }
1563
 
1564
+ if ($total_posts < $limit_post) {
1565
+ $percent_post = 33.33;
1566
+ }
1567
+
1568
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
1569
+ $results = $wpdb->get_results($wpdb->prepare('SELECT ID, post_title, post_excerpt, post_content, post_name, post_type, post_status FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where) . 'LIMIT %d OFFSET %d', array(
1570
+ $limit_post,
1571
+ $off_set
1572
+ )));
1573
  if (empty($results)) {
1574
  wp_send_json(array('status' => true));
1575
  }
1576
 
1577
  foreach ($results as $post) {
1578
+ if ($post->post_excerpt !== 'metaseo_404_page') {
1579
  $dom = new DOMDocument;
1580
  libxml_use_internal_errors(true);
1581
+ if (isset($post->post_content) && $post->post_content !== '') {
1582
+ preg_match_all('#<a[^>]*>.*?</a>#si', $post->post_content, $matches, PREG_PATTERN_ORDER);
1583
  foreach (array_unique($matches[0]) as $i => $content) {
1584
  $dom->loadHTML($content);
1585
+ $tags = $dom->getElementsByTagName('a');
1586
  $meta_title = $tags->item(0)->getAttribute('title');
1587
+ $rel = $tags->item(0)->getAttribute('rel');
1588
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1589
+ $href = $matches[1];
1590
+ $status = self::getUrlStatus($href);
1591
+ $status_type = self::getUrlStatusType($status);
1592
+ $link_text = preg_replace('/<a\s(.+?)>(.+?)<\/a>/is', '$2', $content);
1593
  $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1594
  $source_link .= '<b>' . $post->post_title . '</b>';
1595
  $source_link .= '</a>';
1596
+ $link_a = self::getResultLink(
1597
  $source_link,
1598
  $post->ID,
1599
  $href,
1605
  $rel,
1606
  $post->ID
1607
  );
1608
+ self::insertLink($link_a, $wpdb);
1609
  }
1610
  preg_match_all(
1611
  '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1618
  $source_link .= '<b>' . $post->post_title . '</b>';
1619
  $source_link .= '</a>';
1620
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1621
+ $src = $matches[1];
1622
+ $status = self::getUrlStatus($src);
1623
+ $status_type = self::getUrlStatusType($status);
1624
+ $link_text = '';
1625
+ $link_src = self::getResultLink(
1626
  $source_link,
1627
  $post->ID,
1628
  $src,
1631
  $status,
1632
  $status_type
1633
  );
1634
+ self::insertLink($link_src, $wpdb);
1635
  }
1636
  }
1637
  }
1638
+ $j ++;
1639
  if ($j >= $limit_post) {
1640
  wp_send_json(
1641
  array(
1642
+ 'status' => false,
1643
+ 'type' => 'limit_post',
1644
+ 'paged' => $_POST['paged'],
1645
  'percent' => $percent_post * count($results)
1646
  )
1647
  );
1649
  }
1650
 
1651
  $link_settings = array(
1652
+ 'enable' => 0,
1653
+ 'numberFrequency' => 1,
1654
+ 'showlinkFrequency' => 'month'
1655
  );
1656
 
1657
  $linksettings = get_option('wpms_link_settings');
1666
 
1667
  /**
1668
  * Insert link to wpms_link table
1669
+ *
1670
+ * @param array $link Link details to insert
1671
+ * @param object $wpdb Global wordpress database
1672
+ *
1673
+ * @return void
1674
  */
1675
  public static function insertLink($link, $wpdb)
1676
  {
1677
+ $links = $wpdb->get_results($wpdb->prepare(
1678
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE link_url=%s AND link_text=%s AND type=%s AND source_id=%d ',
1679
  array(
1680
  $link['link_url'],
1681
+ $link['link_text'],
1682
  $link['type'],
1683
  $link['source_id']
1684
  )
1685
+ ));
1686
+ if (count($links) === 0) {
1687
+ $status_text = self::getStatusText($link['status']);
1688
+ $value = array(
1689
+ 'link_url' => $link['link_url'],
1690
+ 'link_final_url' => $link['link_final_url'],
1691
+ 'link_text' => $link['link_text'],
1692
+ 'source_id' => $link['source_id'],
1693
+ 'type' => $link['type'],
1694
+ 'status_code' => $link['status'],
1695
+ 'status_text' => $status_text,
1696
+ 'broken_indexed' => 0,
 
1697
  'broken_internal' => 0,
1698
+ 'warning' => 0,
1699
+ 'dismissed' => 0,
1700
+ 'meta_title' => $link['meta_title'],
1701
+ 'follow' => $link['follow']
1702
  );
1703
+ if (isset($link['status_type']) && $link['status_type'] !== 'ok') {
1704
  $value[$link['status_type']] = 1;
1705
  }
1706
 
1707
  $site_url = get_site_url();
1708
+ $value = self::checkInternalLink($link['link_url'], $site_url, $value);
1709
 
1710
  $wpdb->insert(
1711
  $wpdb->prefix . 'wpms_links',
1712
  $value
1713
  );
1714
  } else {
1715
+ $value = array(
1716
  'meta_title' => $link['meta_title'],
1717
+ 'follow' => $link['follow']
1718
  );
1719
  $site_url = get_site_url();
1720
  // get status
1721
+ $status_text = self::getStatusText($link['status']);
1722
+ $value = self::checkInternalLink($links[0]->link_url, $site_url, $value);
1723
  $value['status_code'] = $link['status'];
1724
  $value['status_text'] = $status_text;
1725
+ if ((int) $links[0]->follow !== (int) $link['follow'] || $links[0]->meta_title !== $link['meta_title']
1726
+ || (int) $links[0]->internal !== (int) $value['internal'] || $links[0]->status_code !== $value['status_code']) {
1727
  // update link status
1728
  $wpdb->update(
1729
  $wpdb->prefix . 'wpms_links',
1738
 
1739
  /**
1740
  * Check internal link
1741
+ *
1742
+ * @param string $link Current link url
1743
+ * @param string $siteUrl Site url
1744
+ * @param array $value Value
1745
+ *
1746
  * @return mixed
1747
  */
1748
  public static function checkInternalLink($link, $siteUrl, $value)
1759
  }
1760
 
1761
  $info_site_url = parse_url($siteUrl);
1762
+ $domain_link = $info_link['host'] . $info_link['path'] . '/';
1763
+ $domain_site = $info_site_url['host'] . $info_site_url['path'] . '/';
1764
  if (strpos($domain_link, $domain_site) !== false) {
1765
  $value['internal'] = 1;
1766
  } else {
1772
 
1773
  /**
1774
  * Flush link
1775
+ *
1776
+ * @return void
1777
  */
1778
  public static function flushLink()
1779
  {
1780
+ if (empty($_POST['wpms_nonce'])
1781
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1782
+ die();
1783
+ }
1784
+
1785
  global $wpdb;
1786
+ if (isset($_POST['type']) && $_POST['type'] !== 'none') {
1787
  switch ($_POST['type']) {
1788
  case 'automaticaly_indexed':
1789
+ $wpdb->query('DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE broken_indexed = 1 AND link_url_redirect = ""');
 
 
 
 
 
 
 
 
1790
  break;
1791
  case 'internal_broken_links':
1792
+ $wpdb->query('DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE broken_internal = 1 AND link_url_redirect = ""');
 
 
 
 
 
 
 
 
1793
  break;
1794
  case 'all':
1795
+ $wpdb->query('DELETE FROM ' . $wpdb->prefix . 'wpms_links WHERE (broken_internal = 1 OR broken_indexed = 1) AND link_url_redirect = ""');
 
 
 
 
 
 
 
 
 
1796
 
1797
  break;
1798
  }
1803
 
1804
  /**
1805
  * Get status text
1806
+ *
1807
+ * @param string $status Statue of link
1808
+ *
1809
+ * @return boolean|string
1810
  */
1811
  public static function getStatusText($status)
1812
  {
1813
+ if ($status === 'Not checked') {
1814
  return 'Not checked';
1815
  }
1816
+ if ($status === 'Server Not Found') {
1817
  $status_text = 'Server Not Found';
1818
  } else {
1819
  $status_text = substr($status, 9);
1823
 
1824
  /**
1825
  * Add custom redirect
1826
+ *
1827
+ * @return void
1828
  */
1829
  public static function addCustomRedirect()
1830
  {
1831
+ if (empty($_POST['wpms_nonce'])
1832
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1833
+ $wpms_nonce = 0;
1834
+ } else {
1835
+ $wpms_nonce = $_POST['wpms_nonce'];
1836
+ }
1837
+
1838
+ do_action('wpms_add_custom_redirect', $wpms_nonce);
1839
+ wp_send_json(array('status' => true, 'message' => esc_html__('Done!', 'wp-meta-seo')));
1840
  }
1841
 
1842
  /**
1843
  * Update link
1844
+ *
1845
+ * @return void
1846
  */
1847
  public static function updateLinkRedirect()
1848
  {
1849
+ if (empty($_POST['wpms_nonce'])
1850
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1851
+ die();
1852
+ }
1853
 
1854
  if (isset($_POST['link_id'])) {
1855
  global $wpdb;
1856
+ $link_detail = $wpdb->get_row($wpdb->prepare(
1857
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d',
1858
  array($_POST['link_id'])
1859
+ ));
 
1860
  if (empty($link_detail)) {
1861
  wp_send_json(false);
1862
  }
1863
 
1864
+ $new_link = stripslashes($_POST['new_link']);
1865
  $link_redirect = stripslashes($_POST['link_redirect']);
1866
  if (isset($_POST['new_text'])) {
1867
  $new_text = stripcslashes($_POST['new_text']);
1869
  $new_text = '';
1870
  }
1871
 
1872
+ if ($link_redirect !== '') {
1873
  $status = 'HTTP/1.1 200 OK';
1874
  } else {
1875
+ $status = self::getUrlStatus($new_link);
1876
  }
1877
 
1878
+ $status_text = self::getStatusText($status);
1879
+ $status_type = self::getUrlStatusType($status);
1880
+ if ($link_detail->type !== '404_automaticaly') {
1881
+ $value = array(
1882
+ 'link_url' => $new_link,
1883
+ 'link_final_url' => '',
1884
  'link_url_redirect' => '',
1885
+ 'link_text' => stripcslashes($new_text),
1886
+ 'status_code' => $status,
1887
+ 'status_text' => $status_text,
1888
+ 'broken_indexed' => 0,
1889
+ 'broken_internal' => 0,
1890
+ 'warning' => 0,
1891
+ 'dismissed' => 0,
1892
  );
1893
  if (strpos($new_link, 'mailto:') !== false) {
1894
  $value['link_final_url'] = $new_link;
1895
  } else {
1896
+ if (!preg_match('~^(?:f|ht)tps?://~i', $new_link)) {
1897
  $perlink = get_option('permalink_structure');
1898
  if (empty($perlink)) {
1899
  $value['link_final_url'] = get_site_url() . '/' . $new_link;
1913
  $value['link_url_redirect'] = $link_redirect;
1914
  }
1915
 
1916
+ if (isset($status_type) && $status_type !== 'ok') {
1917
  $value[$status_type] = 1;
1918
  }
1919
  } else {
1920
+ $status = self::getUrlStatus($link_redirect);
1921
+ $status_text = self::getStatusText($status);
1922
 
1923
  $value = array(
1924
  'link_url_redirect' => stripslashes($link_redirect),
1925
+ 'status_code' => $status,
1926
+ 'status_text' => $status_text,
1927
+ 'broken_indexed' => 1
1928
  );
1929
  }
1930
 
1931
+ if ($link_detail->type === 'add_custom') {
1932
  $value['meta_title'] = $_POST['status_redirect'];
1933
  }
1934
 
1935
  $site_url = get_site_url();
1936
+ $value = self::checkInternalLink($new_link, $site_url, $value);
1937
 
1938
  $wpdb->update(
1939
  $wpdb->prefix . 'wpms_links',
1947
  case '404_automaticaly':
1948
  wp_send_json(
1949
  array(
1950
+ 'status' => true,
1951
+ 'type' => '404_automaticaly',
1952
  'status_text' => $status_text,
1953
+ 'new_link' => esc_url($new_link)
1954
  )
1955
  );
1956
  break;
1957
  case 'comment_content_image':
1958
  $comment = get_comment($link_detail->source_id);
1959
  if (!empty($comment)) {
1960
+ $old_value = $comment->comment_content;
1961
+ $edit_result = self::editLinkImg(
1962
  $old_value,
1963
  $new_link,
1964
  $link_detail->link_url
1965
  );
1966
+ $my_comment = array(
1967
+ 'comment_ID' => $link_detail->source_id,
1968
  'comment_content' => $edit_result['content']
1969
  );
1970
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
1971
  wp_update_comment($my_comment);
1972
  wp_send_json(
1973
  array(
1974
+ 'status' => true,
1975
+ 'type' => 'image',
1976
  'status_text' => $status_text,
1977
+ 'new_link' => esc_url($edit_result['raw_url'])
1978
  )
1979
  );
1980
  }
1982
  case 'image':
1983
  $post = get_post($link_detail->source_id);
1984
  if (!empty($post)) {
1985
+ $old_value = $post->post_content;
1986
+ $edit_result = self::editLinkImg(
1987
  $old_value,
1988
  $new_link,
1989
  $link_detail->link_url
1990
  );
1991
+ $my_post = array(
1992
+ 'ID' => $link_detail->source_id,
1993
  'post_content' => $edit_result['content']
1994
  );
1995
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1996
  wp_update_post($my_post);
1997
  wp_send_json(
1998
  array(
1999
+ 'status' => true,
2000
+ 'type' => 'image',
2001
  'status_text' => $status_text,
2002
+ 'new_link' => esc_url($edit_result['raw_url'])
2003
  )
2004
  );
2005
  }
2009
  $comment = get_comment($link_detail->source_id);
2010
  if (!empty($comment)) {
2011
  $old_value = $comment->comment_content;
2012
+ if (isset($_POST['data_type']) && $_POST['data_type'] === 'multi' && $new_text === '') {
2013
+ $edit_result = self::editLinkHtml(
2014
  $old_value,
2015
  $new_link,
2016
  $link_detail->link_url
2017
  );
2018
+ $new_text = '';
2019
  } else {
2020
+ $edit_result = self::editLinkHtml(
2021
  $old_value,
2022
  $new_link,
2023
  $link_detail->link_url,
2024
  $new_text
2025
  );
2026
+ $new_text = strip_tags($edit_result['link_text']);
2027
  }
2028
 
2029
  $my_comment = array(
2030
+ 'comment_ID' => $link_detail->source_id,
2031
  'comment_content' => $edit_result['content']
2032
  );
2033
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2034
  wp_update_comment($my_comment);
2035
  wp_send_json(
2036
  array(
2037
+ 'status' => true,
2038
+ 'type' => 'url',
2039
  'status_text' => $status_text,
2040
+ 'new_link' => $edit_result['raw_url'],
2041
+ 'new_text' => $new_text
2042
  )
2043
  );
2044
  }
2049
  $post = get_post($link_detail->source_id);
2050
  if (!empty($post)) {
2051
  $old_value = $post->post_content;
2052
+ if (isset($_POST['data_type']) && $_POST['data_type'] === 'multi' && $new_text === '') {
2053
+ $edit_result = self::editLinkHtml(
2054
  $old_value,
2055
  $new_link,
2056
  $link_detail->link_url
2057
  );
2058
+ $new_text = '';
2059
  } else {
2060
+ $edit_result = self::editLinkHtml(
2061
  $old_value,
2062
  $new_link,
2063
  $link_detail->link_url,
2064
  $new_text
2065
  );
2066
+ $new_text = strip_tags($edit_result['link_text']);
2067
  }
2068
 
2069
  $my_post = array(
2070
+ 'ID' => $link_detail->source_id,
2071
  'post_content' => $edit_result['content']
2072
  );
2073
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2074
  wp_update_post($my_post);
2075
  wp_send_json(
2076
  array(
2077
+ 'status' => true,
2078
+ 'type' => 'url',
2079
  'status_text' => $status_text,
2080
+ 'new_link' => $edit_result['raw_url'],
2081
+ 'new_text' => $new_text
2082
  )
2083
  );
2084
  }
2087
  case 'comment':
2088
  wp_update_comment(
2089
  array(
2090
+ 'comment_ID' => $link_detail->source_id,
2091
  'comment_author_url' => $new_link
2092
  )
2093
  );
2094
  wp_send_json(
2095
  array(
2096
+ 'status' => true,
2097
+ 'type' => 'orther',
2098
  'status_text' => $status_text,
2099
+ 'new_link' => $new_link
2100
  )
2101
  );
2102
  break;
2104
  case 'add_custom':
2105
  wp_send_json(
2106
  array(
2107
+ 'status' => true,
2108
+ 'type' => 'orther',
2109
  'status_text' => $status_text,
2110
+ 'new_link' => $new_link
2111
  )
2112
  );
2113
  break;
2118
 
2119
  /**
2120
  * Remove link
2121
+ *
2122
+ * @return void
2123
  */
2124
  public static function unlink()
2125
  {
2126
+ if (empty($_POST['wpms_nonce'])
2127
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
2128
+ die();
2129
+ }
2130
+
2131
  if (isset($_POST['link_id'])) {
2132
  global $wpdb;
2133
+ $link_detail = $wpdb->get_row($wpdb->prepare(
2134
+ 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d',
2135
  array($_POST['link_id'])
2136
+ ));
 
2137
  if (empty($link_detail)) {
2138
  wp_send_json(false);
2139
  }
2148
  case 'comment_content_image':
2149
  $comment = get_comment($link_detail->source_id);
2150
  if (!empty($comment)) {
2151
+ $old_value = $comment->comment_content;
2152
+ $new_content = self::unlinkImg($old_value, $link_detail->link_url);
2153
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2154
  $my_comment = array(
2155
+ 'comment_ID' => $link_detail->source_id,
2156
  'comment_content' => $new_content
2157
  );
2158
  wp_update_comment($my_comment);
2163
  case 'image':
2164
  $post = get_post($link_detail->source_id);
2165
  if (!empty($post)) {
2166
+ $old_value = $post->post_content;
2167
+ $new_content = self::unlinkImg($old_value, $link_detail->link_url);
2168
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2169
  $my_post = array(
2170
+ 'ID' => $link_detail->source_id,
2171
  'post_content' => $new_content
2172
  );
2173
  wp_update_post($my_post);
2178
  case 'comment_content_url':
2179
  $comment = get_comment($link_detail->source_id);
2180
  if (!empty($comment)) {
2181
+ $old_value = $comment->comment_content;
2182
+ $new_content = self::unlinkHtml($old_value, $link_detail->link_url);
2183
  remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2184
  $my_comment = array(
2185
+ 'comment_ID' => $link_detail->source_id,
2186
  'comment_content' => $new_content
2187
  );
2188
  wp_update_comment($my_comment);
2193
  case 'url':
2194
  $post = get_post($link_detail->source_id);
2195
  if (!empty($post)) {
2196
+ $old_value = $post->post_content;
2197
+ $new_content = self::unlinkHtml($old_value, $link_detail->link_url);
2198
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2199
  $my_post = array(
2200
+ 'ID' => $link_detail->source_id,
2201
  'post_content' => $new_content
2202
  );
2203
  wp_update_post($my_post);
2231
  {
2232
  self::$old_url = $old_url;
2233
  self::$new_url = htmlentities($new_url);
2234
+ $content = preg_replace_callback(
2235
  self::$img_pattern,
2236
  array(
2237
  'MetaSeoBrokenLinkTable',
2247
  }
2248
 
2249
  /**
2250
+ * Edit Image callback
2251
+ *
2252
+ * @param array $matches Matches
2253
+ *
2254
  * @return string
2255
  */
2256
  public static function editImgCallback($matches)
2257
  {
2258
  $url = $matches[3];
2259
+ if (($url) === self::$old_url) {
2260
  return $matches[1] . '"' . self::$new_url . '"' . $matches[4];
2261
  } else {
2262
  return $matches[0];
2267
  * Remove all occurrences of a specific plaintext URL.
2268
  *
2269
  * @param string $content Look for URLs in this string.
2270
+ * @param string $url The URL to look for.
2271
+ *
2272
  * @return string Input string with all matching plaintext URLs removed.
2273
  */
2274
  public static function unlinkImg($content, $url)
2275
  {
2276
  self::$old_url = $url; //used by the callback
2277
+ $content = preg_replace_callback(
2278
  self::$img_pattern,
2279
  array(
2280
  'MetaSeoBrokenLinkTable',
2286
  }
2287
 
2288
  /**
2289
+ * Get image unchanged
2290
+ *
2291
+ * @param array $matches Matches
2292
+ *
2293
  * @return string
2294
  */
2295
  public static function unlinkImgCallback($matches)
2296
  {
2297
  $url = $matches[3];
2298
+ if (($url) === self::$old_url) {
2299
  return ''; //Completely remove the IMG tag
2300
  } else {
2301
  return $matches[0]; //return the image unchanged
2306
  * Remove all occurrences of a specific plaintext URL.
2307
  *
2308
  * @param string $content Look for URLs in this string.
2309
+ * @param string $url The URL to look for.
2310
+ *
2311
  * @return string Input string with all matching plaintext URLs removed.
2312
  */
2313
  public static function unlinkHtml($content, $url)
2316
  'old_url' => $url,
2317
  );
2318
 
2319
+ $content = self::multiEdit(
2320
  $content,
2321
  array(
2322
  'MetaSeoBrokenLinkTable',
2330
 
2331
  /**
2332
  * Get link to remove
2333
+ *
2334
+ * @param array $link Link infos
2335
+ * @param array $params Params
2336
+ *
2337
  * @return mixed
2338
  */
2339
  public static function unlinkHtmlCallback($link, $params)
2340
  {
2341
+ if ($link['href'] !== $params['old_url']) {
2342
  return $link['#raw'];
2343
  }
2344
 
2348
  /**
2349
  * Change all occurrences of a given plaintext URLs to a new URL.
2350
  *
2351
+ * @param string $content Look for URLs in this string.
2352
+ * @param string $new_url Change them to this URL.
2353
+ * @param string $old_url The URL to look for.
2354
+ * @param string $new_text New text of this URL.
2355
+ *
2356
  * @return array|WP_Error If successful, the return value will be an associative array with two
2357
  * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
2358
  * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
2361
  {
2362
  //Save the old & new URLs for use in the edit callback.
2363
  $args = array(
2364
+ 'old_url' => $old_url,
2365
+ 'new_url' => $new_url,
2366
  'new_text' => $new_text,
2367
  );
2368
 
2369
  //Find all links and replace those that match $old_url.
2370
+ $content = self::multiEdit(
2371
  $content,
2372
  array(
2373
  'MetaSeoBrokenLinkTable',
2387
  }
2388
 
2389
  /**
2390
+ * Get url in content
2391
+ *
2392
+ * @param array $link Link details
2393
+ * @param array $params New params to edit
2394
+ *
2395
  * @return array
2396
  */
2397
  public static function editHtmlCallback($link, $params)
2398
  {
2399
+ if ($link['href'] === $params['old_url']) {
2400
  $modified = array(
2401
  'href' => $params['new_url'],
2402
  );
2408
  $modified['title'] = $params['meta_title'];
2409
  }
2410
 
2411
+ if (isset($params['follow']) && (int) $params['follow'] === 0) {
2412
  $modified['rel'] = 'nofollow';
2413
  } else {
2414
  $modified['rel'] = '';
2426
  * a replacement HTML tag instead, it will be stored in the '#new_raw'
2427
  * key of the return array.
2428
  *
2429
+ * @param array $link Link
 
 
2430
  * @param array $info The callback function and the extra argument to pass to that function (if any).
2431
+ *
2432
  * @return array
2433
  */
2434
  public static function editCallback($link, $info)
2459
  * of that string. If an array is returned, the current link will be modified/rebuilt
2460
  * by substituting the new values for the old ones.
2461
  * htmlentities() will be automatically applied to attribute values (but not to #link_text).
2462
+ *
2463
+ * @param string $content A text string containing the links to edit.
2464
  * @param callback $callback Callback function used to modify the links.
2465
+ * @param mixed $extra If supplied, $extra will be passed as the second parameter to the function $callback.
2466
+ *
2467
  * @return string The modified input string.
2468
  */
2469
  public static function multiEdit($content, $callback, $extra = null)
2470
  {
2471
  //Just reuse map() + a little helper func. to apply the callback to all links and get modified links
2472
+ $modified_links = self::map(
2473
  $content,
2474
  array(
2475
  'MetaSeoBrokenLinkTable',
2490
  $new_html = '<a';
2491
  foreach ($link as $name => $value) {
2492
  //Skip special keys like '#raw' and '#offset'
2493
+ if (substr($name, 0, 1) === '#') {
2494
  continue;
2495
  }
2496
 
2508
  }
2509
 
2510
  /**
 
2511
  * Extract specific HTML tags and their attributes from a string.
2512
  *
2513
  * You can either specify one tag, an array of tag names, or a regular expression that matches the tag name(s).
2523
  * full_tag - the entire matched tag, e.g. '<a href="http://example.com">example.com</a>'. This key
2524
  * will only be present if you set $return_the_entire_tag to true.
2525
  *
2526
+ * @param string $html The HTML code to search for tags.
2527
+ * @param string|array $tag The tag(s) to extract.
2528
+ * @param boolean $selfclosing Whether the tag is self-closing or not.
2529
+ * Setting it to null will force the script to try and make an educated guess.
2530
+ * @param boolean $return_the_entire_tag Return the entire matched tag in 'full_tag' key of the results array.
2531
+ * @param string $charset The character set of the HTML code. Defaults to ISO-8859-1.
2532
  *
2533
  * @return array An array of extracted tags, or an empty array if no matching tags were found.
2534
  */
2618
  }
2619
 
2620
  $tag = array(
2621
+ 'tag_name' => $match['tag'][0],
2622
+ 'offset' => $match[0][1],
2623
+ 'contents' => !empty($match['contents']) ? $match['contents'][0] : '', //empty for self-closing tags
2624
  'attributes' => $attributes,
2625
  );
2626
  if ($return_the_entire_tag) {
2644
  *
2645
  * Any attributes of the link tag will also be included in the returned array as attr_name => attr_value
2646
  * pairs. This function will also automatically decode any HTML entities found in attribute values.
2647
+ *
2648
+ * @param string $content A text string to parse for links.
2649
  * @param callback $callback Callback function to apply to all found links.
2650
+ * @param mixed $extra If the optional $extra param. is supplied,
2651
+ * it will be passed as the second parameter to the function $callback.
2652
+ *
2653
  * @return array An array of all detected links after applying $callback to each of them.
2654
  */
2655
  public static function map($content, $callback, $extra = null)
2657
  $results = array();
2658
 
2659
  //Find all links
2660
+ $links = self::extractTags($content, 'a', false, true);
2661
 
2662
  //Iterate over the links and apply $callback to each
2663
  foreach ($links as $link) {
2666
  $param = array_merge(
2667
  $param,
2668
  array(
2669
+ '#raw' => $link['full_tag'],
2670
+ '#offset' => $link['offset'],
2671
  '#link_text' => $link['contents'],
2672
+ 'href' => isset($link['attributes']['href']) ? $link['attributes']['href'] : '',
2673
  )
2674
  );
2675
 
2686
  return $results;
2687
  }
2688
 
2689
+ /**
2690
  * Ajax recheck link
2691
+ *
2692
+ * @return void
2693
  */
2694
  public static function reCheckLink()
2695
  {
2696
+ if (empty($_POST['wpms_nonce'])
2697
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
2698
+ die();
2699
+ }
2700
+
2701
  if (isset($_POST['link_id'])) {
2702
  global $wpdb;
2703
  $linkId = $_POST['link_id'];
2704
+ $link = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d', array($linkId)));
 
2705
  if (!empty($link)) {
2706
+ if ($link->link_url_redirect !== '') {
2707
  $status = 'HTTP/1.1 200 OK';
2708
  } else {
2709
+ $status = self::getUrlStatus(($link->link_url));
2710
  }
2711
 
2712
+ $status_text = self::getStatusText($status);
2713
 
2714
+ if ($link->type === '404_automaticaly') {
2715
+ if (((int) substr($status, 9, 3) >= 301
2716
+ && (int) substr($status, 9, 3) <= 304)
2717
+ || ((int) substr($status, 9, 3) >= 400
2718
+ && (int) substr($status, 9, 3) <= 503
2719
+ && (int) substr($status, 9, 3) !== 401) || $status === 'Server Not Found') {
2720
  $type = array('broken_indexed' => 1, 'broken_internal' => 0);
2721
  } else {
2722
  $type = array('broken_indexed' => 0, 'broken_internal' => 0);
2723
  }
2724
  } else {
2725
+ if (((int) substr($status, 9, 3) >= 400
2726
+ && (int) substr($status, 9, 3) <= 503
2727
+ && (int) substr($status, 9, 3) !== 401)
2728
+ || $status === 'Server Not Found') {
2729
  $type = array('broken_internal' => 1, 'broken_indexed' => 0);
2730
  } else {
2731
  $type = array('broken_internal' => 0, 'broken_indexed' => 0);
2733
  }
2734
 
2735
  $value = array(
2736
+ 'status_code' => $status,
2737
+ 'status_text' => $status_text,
2738
+ 'broken_indexed' => $type['broken_indexed'],
2739
  'broken_internal' => $type['broken_internal']
2740
  );
2741
 
inc/class.metaseo-content-list-table.php CHANGED
@@ -12,7 +12,9 @@ if (!class_exists('WP_List_Table')) {
12
  class MetaSeoContentListTable extends WP_List_Table
13
  {
14
  /**
15
- * @var
 
 
16
  */
17
  public $post_types;
18
 
@@ -23,37 +25,43 @@ class MetaSeoContentListTable extends WP_List_Table
23
  {
24
  parent::__construct(array(
25
  'singular' => 'metaseo_content',
26
- 'plural' => 'metaseo_contents',
27
- 'ajax' => true
28
  ));
29
  }
30
 
31
  /**
32
  * Generate the table navigation above or below the table
33
- * @param string $which
 
 
 
34
  */
35
- protected function display_tablenav($which)
36
  {
37
  ?>
38
- <div class="tablenav <?php echo esc_attr($which); ?>">
39
 
40
  <input type="hidden" name="page" value="metaseo_content_meta"/>
41
  <input type="hidden" name="page" value="metaseo_content_meta"/>
 
 
42
  <?php if (!empty($_REQUEST['post_status'])) : ?>
43
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
44
  <?php endif ?>
45
-
 
46
  <?php $this->extra_tablenav($which); ?>
47
 
48
  <div style="float:right;margin-left:8px;">
49
  <label>
50
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>"
 
51
  maxlength="3" name="metaseo_posts_per_page" class="metaseo_imgs_per_page screen-per-page"
52
  max="999" min="1" step="1">
53
  </label>
54
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
55
  </div>
56
-
57
  <?php $this->pagination($which); ?>
58
  <br class="clear"/>
59
  </div>
@@ -61,181 +69,112 @@ class MetaSeoContentListTable extends WP_List_Table
61
  <?php
62
  }
63
 
64
- /**
65
- * Get an associative array ( id => link ) with the list
66
- * of views available on this table.
67
- * @return array
68
- */
69
- protected function get_views()
70
- {
71
- global $wpdb;
72
- $status_links = array();
73
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
74
- $post_types = "'" . implode("', '", $post_types) . "'";
75
-
76
- $states = get_post_stati(array('show_in_admin_all_list' => true));
77
- $states['trash'] = 'trash';
78
- $all_states = "'" . implode("', '", $states) . "'";
79
-
80
- $total_posts = $wpdb->get_var(
81
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)"
82
- );
83
-
84
- $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
85
- $tag = "<a href='admin.php?page=metaseo_content_meta'$class>";
86
- $tag .= sprintf(
87
- _nx(
88
- 'All <span class="count">(%s)</span>',
89
- 'All <span class="count">(%s)</span>',
90
- $total_posts,
91
- 'posts'
92
- ),
93
- number_format_i18n($total_posts)
94
- );
95
- $tag .= "</a>";
96
- $status_links['all'] = $tag;
97
-
98
- foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
99
- $status_name = $status->name;
100
- $total = $wpdb->get_var(
101
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$status_name') AND post_type IN ($post_types)"
102
- );
103
-
104
- if ($total == 0) {
105
- continue;
106
- }
107
-
108
- if (isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status']) {
109
- $class = ' class="current"';
110
- } else {
111
- $class = '';
112
- }
113
-
114
- $status_links[$status_name]
115
- = "<a href='admin.php?page=metaseo_content_meta&amp;post_status=$status_name'$class>";
116
- $status_links[$status_name] .= sprintf(
117
- translate_nooped_plural(
118
- $status->label_count,
119
- $total
120
- ),
121
- number_format_i18n($total)
122
- );
123
- $status_links[$status_name] .= "</a>";
124
- }
125
- $trashed_posts = $wpdb->get_var(
126
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)"
127
- );
128
- $class = (isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status']) ? 'class="current"' : '';
129
- $status_links['trash'] = "<a href='admin.php?page=metaseo_content_meta&amp;post_status=trash'$class>";
130
- $status_links['trash'] .= sprintf(
131
- _nx(
132
- 'Trash <span class="count">(%s)</span>',
133
- 'Trash <span class="count">(%s)</span>',
134
- $trashed_posts,
135
- 'posts'
136
- ),
137
- number_format_i18n($trashed_posts)
138
- );
139
- $status_links['trash'] .= "</a>";
140
-
141
- return $status_links;
142
- }
143
-
144
  /**
145
  * Extra controls to be displayed between bulk actions and pagination
146
- * @param string $which
 
 
 
147
  */
148
- protected function extra_tablenav($which)
149
  {
150
  echo '<div class="alignleft actions">';
151
- $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
 
152
 
153
  $options = '<option value="-1">Show All Post Types</option>';
154
 
155
  foreach ($this->post_types as $post_type) {
156
- $obj = get_post_type_object($post_type->post_type);
157
  $options .= sprintf(
158
  '<option value="%2$s" %3$s>%1$s</option>',
159
- $obj->labels->name,
160
- $post_type->post_type,
161
- selected($selected, $post_type->post_type, false)
162
  );
163
  }
164
 
165
- $sl_bulk = '<select name="mbulk_copy" class="mbulk_copy">
166
- <option value="0">' . __('Bulk copy', 'wp-meta-seo') . '</option>
167
- <option value="all">' . __('All Posts', 'wp-meta-seo') . '</option>
168
- <option value="bulk-copy-metatitle">' . __('Selected posts', 'wp-meta-seo') . '</option>
169
  </select>';
170
  $btn_bulk = '<input type="button" name="do_copy" id="post_do_copy"
171
  class="wpmsbtn wpmsbtn_small btn_do_copy post_do_copy"
172
- value="' . __('Content title as meta title', 'wp-meta-seo') . '"><span class="spinner"></span>';
173
 
 
174
  $selected_duplicate = !empty($_REQUEST['wpms_duplicate_meta']) ? $_REQUEST['wpms_duplicate_meta'] : 'none';
175
- $options_dups = array(
176
- 'none' => __('All meta information', 'wp-meta-seo'),
177
- 'duplicate_title' => __('Duplicated meta titles', 'wp-meta-seo'),
178
- 'duplicate_desc' => __('Duplicated meta descriptions', 'wp-meta-seo')
179
  );
180
- $sl_duplicate = '<select name="wpms_duplicate_meta" class="wpms_duplicate_meta">';
181
  foreach ($options_dups as $key => $label) {
182
- if ($selected_duplicate == $key) {
183
- $sl_duplicate .= '<option selected value="' . $key . '">' . $label . '</option>';
184
  } else {
185
- $sl_duplicate .= '<option value="' . $key . '">' . $label . '</option>';
186
  }
187
  }
188
  $sl_duplicate .= '</select>';
189
-
190
  echo sprintf('<select name="post_type_filter" class="metaseo-filter">%1$s</select>', $options);
 
191
  echo $sl_duplicate;
192
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
193
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
194
  || is_plugin_active('polylang/polylang.php'))) {
195
- $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
 
196
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
 
197
  echo $sl_lang;
198
  }
 
199
  echo '<input type="submit" name="do_filter" id="post-query-submit"
200
- class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="' . __('Filter', 'wp-meta-seo') . '">';
 
201
  echo $sl_bulk . $btn_bulk;
202
- echo "</div>";
203
  }
204
 
205
  /**
206
  * Get a list of columns. The format is:
207
  * 'internal-name' => 'Title'
 
208
  * @return array
209
  */
210
- public function get_columns()
211
  {
212
- $preview = __(" This is a rendering of what this post might look
213
  like in Google's search results.", 'wp-meta-seo');
214
- $info = sprintf('<a class="info-content"><img src=' . WPMETASEO_PLUGIN_URL . 'img/info.png>'
215
- . '<p class="tooltip-metacontent">'
216
- . $preview
217
- . '</p></a>');
218
 
219
  $columns = array(
220
- 'cb' => '<input id="cb-select-all-1" type="checkbox" style="margin:0">',
221
- 'col_id' => __('', 'wp-meta-seo'),
222
- 'col_title' => __('Title', 'wp-meta-seo'),
223
- 'col_snippet' => sprintf(__('Snippet Preview %s', 'wp-meta-seo'), $info),
224
- 'col_meta_title' => __('Meta Title', 'wp-meta-seo'),
225
  );
226
 
227
  $settings = get_option('_metaseo_settings');
228
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
229
- $columns['col_meta_keywords'] = __('Meta Keywords', 'wp-meta-seo');
230
  }
231
- $columns['col_meta_desc'] = __('Meta Description', 'wp-meta-seo');
232
- $settings = get_option('_metaseo_settings');
233
  if (!empty($settings['metaseo_follow'])) {
234
- $columns['col_follow'] = __('Follow', 'wp-meta-seo');
235
  }
236
 
237
  if (!empty($settings['metaseo_index'])) {
238
- $columns['col_index'] = __('Index', 'wp-meta-seo');
239
  }
240
 
241
  return $columns;
@@ -248,86 +187,87 @@ class MetaSeoContentListTable extends WP_List_Table
248
  * 'internal-name' => array( 'orderby', true )
249
  *
250
  * The second format will make the initial sorting order be descending
 
251
  * @return array
252
  */
253
- protected function get_sortable_columns()
254
  {
255
- return $sortable = array(
256
- 'col_title' => array('post_title', true),
257
  'col_meta_title' => array('metatitle', true),
258
- 'col_meta_desc' => array('metadesc', true)
259
  );
 
 
260
  }
261
 
262
  /**
263
- * Get a list of all registered post type objects.
 
 
 
 
264
  */
265
- public function getPostType()
266
  {
267
- global $wpdb;
268
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
269
- $post_types = "'" . implode("', '", esc_sql($post_types)) . "'";
270
-
271
- $states = get_post_stati(array('show_in_admin_all_list' => true));
272
- $states['trash'] = 'trash';
273
- $all_states = "'" . implode("', '", esc_sql($states)) . "'";
274
-
275
- $query = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_status IN ($all_states)
276
- AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
277
- $post_types = $wpdb->get_results($query);
278
  return $post_types;
279
  }
280
 
281
  /**
282
  * Prepares the list of items for displaying.
283
- * @uses WP_List_Table::set_pagination_args()
 
284
  */
285
- public function prepare_items()
286
  {
287
  global $wpdb;
288
- $this->post_types = $this->getPostType();
289
- $where = array();
290
- $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
291
- if ($post_type == "-1") {
292
- $post_type = "";
293
  }
294
 
295
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
296
- if (!empty($post_type) && !in_array($post_type, $post_types)) {
297
- $post_type = '\'post\'';
298
  } elseif (empty($post_type)) {
299
- $post_type = "'" . implode("', '", esc_sql($post_types)) . "'";
300
- } else {
301
- $post_type = "'" . $post_type . "'";
 
 
302
  }
303
 
304
- $where[] = "post_type IN ($post_type)";
305
-
306
  $states = get_post_stati(array('show_in_admin_all_list' => true));
307
- $all_states = "'" . implode("', '", $states) . "'";
308
-
309
- if (empty($_REQUEST['post_status'])) {
310
- $where[] = "post_status IN ($all_states)";
311
- } else {
312
- $requested_state = $_REQUEST['post_status'];
313
- if (in_array($requested_state, $states)) {
314
- $where[] = "post_status IN ('$requested_state')";
315
- } else {
316
- $where[] = "post_status IN ($all_states)";
317
- }
318
  }
319
 
320
- $keyword = !empty($_GET["s"]) ? $_GET["s"] : '';
321
- if (isset($keyword) && $keyword != '') {
322
- $where[] = '(post_title LIKE "%' . $keyword . '%"
323
- OR mt.meta_value LIKE "%' . $keyword . '%" OR md.meta_value LIKE "%' . $keyword . '%")';
 
 
 
 
 
 
 
 
324
  }
325
 
326
  //Order By block
327
- $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'post_title';
328
- $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
 
 
329
 
330
- $sortable = $this->get_sortable_columns();
331
  $orderby_array = array($orderby, true);
332
  if (in_array($orderby_array, $sortable)) {
333
  $orderStr = $orderby;
@@ -335,69 +275,65 @@ class MetaSeoContentListTable extends WP_List_Table
335
  $orderStr = 'post_title';
336
  }
337
 
338
- if ($order == "asc") {
339
- $orderStr .= " ASC";
340
  } else {
341
- $orderStr .= " DESC";
342
  }
343
 
344
  if (!empty($orderby) & !empty($order)) {
345
- $orderStr = $wpdb->prepare(' ORDER BY %s ', $orderStr);
346
- $orderStr = str_replace("'", "", $orderStr);
347
  }
348
 
349
- if (isset($_GET['wpms_duplicate_meta']) && $_GET['wpms_duplicate_meta'] != 'none') {
350
- if ($_GET['wpms_duplicate_meta'] == 'duplicate_title') {
351
- $where[] = "mt.meta_key = '_metaseo_metatitle'";
352
- $where[] = "mt.meta_value IN (SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key='_metaseo_metatitle' AND meta_value != '' GROUP BY meta_value HAVING COUNT(*) >= 2)";
353
-
354
- } elseif ($_GET['wpms_duplicate_meta'] == 'duplicate_desc') {
355
- $where[] = "md.meta_key = '_metaseo_metadesc'";
356
- $where[] = "md.meta_value IN (SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key='_metaseo_metadesc' AND meta_value != '' GROUP BY meta_value HAVING COUNT(*) >= 2)";
357
  }
358
  }
 
 
 
 
 
 
 
359
 
360
- $query = "SELECT COUNT(ID) "
361
- . " FROM $wpdb->posts "
362
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
363
- WHERE meta_key = '_metaseo_metatitle') mt ON mt.post_id = $wpdb->posts.ID "
364
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
365
- WHERE meta_key = '_metaseo_metadesc') md ON md.post_id = $wpdb->posts.ID "
366
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
367
- WHERE meta_key = '_metaseo_metakeywords') mk ON mk.post_id = $wpdb->posts.ID "
368
- . " WHERE " . implode(' AND ', $where);
369
-
370
  $total_items = $wpdb->get_var($query);
371
- $query = "SELECT DISTINCT ID, post_title, post_name, post_type, post_status,
372
- mt.meta_value AS metatitle, md.meta_value AS metadesc ,mk.meta_value AS metakeywords "
373
- . " FROM $wpdb->posts"
374
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metatitle')
375
- mt ON mt.post_id = $wpdb->posts.ID "
376
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metadesc')
377
- md ON md.post_id = $wpdb->posts.ID "
378
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metakeywords')
379
- mk ON mk.post_id = $wpdb->posts.ID ";
380
 
 
 
 
 
 
381
  // query post by lang with polylang plugin
382
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
383
- if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
384
- $query .= " INNER JOIN (SELECT * FROM $wpdb->term_relationships as ml
385
- INNER JOIN (SELECT * FROM $wpdb->terms WHERE slug='" . $_GET['wpms_lang_list'] . "')
386
- mp ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = $wpdb->posts.ID ";
 
387
  }
 
388
  }
389
 
390
  // query post by lang with WPML plugin
391
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
392
- if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
393
- $query .= " INNER JOIN (SELECT * FROM " . $wpdb->prefix . "icl_translations
394
- WHERE element_type LIKE 'post_%' AND language_code='" . $_GET['wpms_lang_list'] . "') t
395
- ON t.element_id = $wpdb->posts.ID ";
 
396
  }
 
397
  }
398
 
399
- $query .= " WHERE " . implode(' AND ', $where) . $orderStr;
400
 
 
401
  if (!empty($_REQUEST['metaseo_posts_per_page'])) {
402
  $_per_page = intval($_REQUEST['metaseo_posts_per_page']);
403
  } else {
@@ -419,7 +355,8 @@ class MetaSeoContentListTable extends WP_List_Table
419
  add_user_meta(get_current_user_id(), 'metaseo_posts_per_page', $per_page);
420
  }
421
 
422
- $paged = !empty($_GET["paged"]) ? $_GET["paged"] : '';
 
423
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
424
  $paged = 1;
425
  }
@@ -428,47 +365,50 @@ class MetaSeoContentListTable extends WP_List_Table
428
 
429
  if (!empty($paged) && !empty($per_page)) {
430
  $offset = ($paged - 1) * $per_page;
431
- $query .= ' LIMIT ' . (int)$offset . ',' . (int)$per_page;
432
  }
433
 
434
  $this->set_pagination_args(array(
435
  'total_items' => $total_items,
436
  'total_pages' => $total_pages,
437
- 'per_page' => $per_page
438
  ));
439
 
440
- $columns = $this->get_columns();
441
- $hidden = array();
442
- $sortable = $this->get_sortable_columns();
443
  $this->_column_headers = array($columns, $hidden, $sortable);
444
 
 
445
  $this->items = $wpdb->get_results($query);
446
  }
447
 
448
  /**
449
  * Generate the table rows
 
 
450
  */
451
- public function display_rows()
452
  {
453
- $records = $this->items;
454
- $i = 0;
455
- $alternate = "";
456
- $url = preg_replace('/(http|https):\/\/[w]*[.]?/', '', network_site_url('/'));
457
 
458
  list($columns, $hidden) = $this->get_column_info();
459
 
460
  if (!empty($records)) {
461
  foreach ($records as $rec) {
462
- $alternate = 'alternate' == $alternate ? '' : 'alternate';
463
- $i++;
464
- $classes = $alternate;
465
  $rec->link = $url;
466
 
467
- echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
468
 
469
  foreach ($columns as $column_name => $column_display_name) {
470
- $class = sprintf('class="%1$s column-%1$s"', $column_name);
471
- $style = "";
472
 
473
  if (in_array($column_name, $hidden)) {
474
  $style = ' style="display:none;"';
@@ -479,68 +419,69 @@ class MetaSeoContentListTable extends WP_List_Table
479
  switch ($column_name) {
480
  case 'cb':
481
  echo '<th scope="row" class="check-column">';
482
- echo '<input id="cb-select-' . $rec->ID . '"
483
- class="metaseo_post" type="checkbox" name="post[]" value="' . $rec->ID . '">';
484
  echo '</th>';
485
 
486
  break;
487
 
488
  case 'col_id':
489
  echo '<td class="col_id" >';
490
- echo $i;
491
  echo '</td>';
492
 
493
  break;
494
 
495
  case 'col_title':
496
  $post_title = stripslashes($rec->post_title);
497
- if ($post_title == '') {
498
- $post_title = __('(no title)', 'wp-meta-seo');
499
  }
500
 
501
  echo sprintf(
502
  '<td %2$s><div class="action-wrapper">
503
- <strong id="post-title-' . $rec->ID . '">%1$s</strong>',
504
- $post_title,
505
- $attributes
506
  );
507
 
508
  $post_type_object = get_post_type_object($rec->post_type);
509
- $can_edit_post = current_user_can($post_type_object->cap->edit_post, $rec->ID);
510
 
511
  $actions = array();
512
 
513
- if ($can_edit_post && 'trash' != $rec->post_status) {
514
- $actions['edit'] = '<a href="' . get_edit_post_link($rec->ID, true) . '"
515
- title="' . esc_attr(__('Edit this item', 'wp-meta-seo')) . '"
516
- >' . __('Edit', 'wp-meta-seo') . '</a>';
517
  }
518
 
519
  if ($post_type_object->public) {
520
  if (in_array($rec->post_status, array('pending', 'draft', 'future'))) {
521
  if ($can_edit_post) {
522
- $hr = esc_url(add_query_arg('preview', 'true', get_permalink($rec->ID)));
523
- $t = esc_attr(
524
  sprintf(
525
- __('Preview &#8220;%s&#8221;', 'wp-meta-seo'),
526
  $rec->post_title
527
  )
528
  );
529
- $actions['view'] = '<a href="' . $hr . '" title="' . $t . '" rel="permalink"
530
- >' . __('Preview', 'wp-meta-seo') . '</a>';
531
  }
532
- } elseif ('trash' != $rec->post_status) {
533
- $t = esc_attr(
534
  sprintf(
535
- __('View &#8220;%s&#8221;', 'wp-meta-seo'),
536
  $rec->post_title
537
  )
538
  );
539
- $actions['view'] = '<a target="_blank" href="' . get_permalink($rec->ID) . '"
540
- title="' . $t . '" rel="permalink">' . __('View', 'wp-meta-seo') . '</a>';
541
  }
542
  }
543
 
 
544
  echo $this->row_actions($actions);
545
  echo '</div></td>';
546
 
@@ -549,44 +490,35 @@ class MetaSeoContentListTable extends WP_List_Table
549
  case 'col_snippet':
550
  echo '<td><div class="snippet-wrapper">';
551
  echo '<div class="snippet">
552
- <a id="snippet_title' . $rec->ID . '" class="snippet_metatitle">
553
- ' . (!empty($rec->metatitle) ? $rec->metatitle : $rec->post_title) . '</a>';
554
 
555
- echo '<span class="snippet_metalink" id="snippet_metalink_' . $rec->ID . '">
556
- ' . $rec->link . '</span>';
557
 
558
- echo '<p id="snippet_desc' . $rec->ID . '" class="snippet_metades">
559
- ' . $rec->metadesc . '</p></div>';
560
- echo '<img class="wpms_loader' . $rec->ID . ' wpms_content_loader"
561
- src=' . WPMETASEO_PLUGIN_URL . 'img/update_loading.gif>';
562
- echo '<span id="savedInfo' . $rec->ID . '"
563
  style="position: relative; display: block;float:right"
564
  class="saved-info metaseo-msg-success"><span style="position:absolute; float:right" class="spinner"></span></span>';
565
  echo '</div></td>';
566
  break;
567
- case 'col_page_slug':
568
- $permalink = get_permalink($rec->ID);
569
- $display_slug = str_replace(get_bloginfo('url'), '', $permalink);
570
- echo sprintf(
571
- '<td %2$s><a href="%3$s" target="_blank">%1$s</a></td>',
572
- stripslashes($display_slug),
573
- $attributes,
574
- $permalink
575
- );
576
- break;
577
 
578
  case 'col_meta_title':
579
  $input = sprintf(
580
  '</br><textarea class="large-text metaseo-metatitle"
581
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
582
- 'metaseo-metatitle-' . $rec->ID,
583
- 'metatitle[' . $rec->ID . ']',
584
- ($rec->metatitle) ? $rec->metatitle : ''
585
  );
586
  $input .= sprintf(
587
  '<div class="title-len" id="%1$s"></div>',
588
- 'metaseo-metatitle-len' . $rec->ID
589
  );
 
590
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
591
  break;
592
 
@@ -594,14 +526,15 @@ class MetaSeoContentListTable extends WP_List_Table
594
  $input = sprintf(
595
  '</br><textarea class="large-text metaseo-metakeywords"
596
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
597
- 'metaseo-metakeywords-' . $rec->ID,
598
- 'metakeywords[' . $rec->ID . ']',
599
- ($rec->metakeywords) ? $rec->metakeywords : ''
600
  );
601
  $input .= sprintf(
602
  '<div class="keywords-len" id="%1$s"></div>',
603
- 'metaseo-metakeywords-len' . $rec->ID
604
  );
 
605
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
606
  break;
607
 
@@ -609,38 +542,41 @@ class MetaSeoContentListTable extends WP_List_Table
609
  $input = sprintf(
610
  '</br><textarea class="large-text metaseo-metadesc"
611
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
612
- 'metaseo-metadesc-' . $rec->ID,
613
- ' metades[' . $rec->ID . ']',
614
- ($rec->metadesc) ? $rec->metadesc : ''
615
  );
616
  $input .= sprintf(
617
  '<div class="desc-len" id="%1$s"></div>',
618
- 'metaseo-metadesc-len' . $rec->ID
619
  );
 
620
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
621
  break;
622
 
623
  case 'col_index':
624
  $page_index = get_post_meta($rec->ID, '_metaseo_metaindex', true);
625
- if (isset($page_index) && $page_index == 'noindex') {
626
  $input = '<input class="metaseo_post_index"
627
- name="index[]" type="checkbox" value="' . $rec->ID . '">';
628
  } else {
629
  $input = '<input checked class="metaseo_post_index"
630
- name="index[]" type="checkbox" value="' . $rec->ID . '">';
631
  }
 
632
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
633
  break;
634
 
635
  case 'col_follow':
636
  $page_follow = get_post_meta($rec->ID, '_metaseo_metafollow', true);
637
- if (isset($page_follow) && $page_follow == 'nofollow') {
638
  $input = '<input class="metaseo_post_follow"
639
- name="follow[]" type="checkbox" value="' . $rec->ID . '">';
640
  } else {
641
  $input = '<input checked class="metaseo_post_follow"
642
- name="follow[]" type="checkbox" value="' . $rec->ID . '">';
643
  }
 
644
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
645
  break;
646
  }
@@ -653,38 +589,51 @@ class MetaSeoContentListTable extends WP_List_Table
653
 
654
  /**
655
  * Retrieves a modified URL query string.
 
 
656
  */
657
  public function processAction()
658
  {
659
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
660
- $redirect = false;
 
661
  if (isset($_POST['do_filter'])) {
662
- $current_url = add_query_arg(array("post_type_filter" => $_POST['post_type_filter']), $current_url);
663
- $current_url = add_query_arg(array("wpms_duplicate_meta" => $_POST['wpms_duplicate_meta']), $current_url);
664
- $current_url = add_query_arg(array("wpms_lang_list" => $_POST['wpms_lang_list']), $current_url);
 
 
 
 
 
 
 
 
 
665
  $redirect = true;
666
  }
667
 
668
  if (!empty($_POST['paged'])) {
669
- $current_url = add_query_arg(array("paged" => intval($_POST['paged'])), $current_url);
670
- $redirect = true;
671
  }
672
 
673
  if (!empty($_POST['metaseo_posts_per_page'])) {
674
  $current_url = add_query_arg(
675
  array(
676
- "metaseo_posts_per_page" => intval($_POST['metaseo_posts_per_page'])),
 
677
  $current_url
678
  );
679
- $redirect = true;
680
  }
681
 
682
  if (isset($_POST['s'])) {
683
- $current_url = add_query_arg(array("s" => urlencode($_POST['s'])), $current_url);
684
- $redirect = true;
685
  }
686
-
687
- if ($redirect === true) {
688
  wp_redirect($current_url);
689
  ob_end_flush();
690
  exit();
@@ -692,44 +641,34 @@ class MetaSeoContentListTable extends WP_List_Table
692
  }
693
 
694
  /**
695
- * Get all posts that is public and contain images with a string seperated by comma
696
- * @return array|string
 
697
  */
698
- public static function getPostTypes()
699
  {
700
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
701
- if (!empty($post_types)) {
702
- $post_types = "'" . implode("', '", $post_types) . "'";
703
  }
704
 
705
- return $post_types;
706
- }
707
-
708
- /**
709
- * import meta from other plugin
710
- */
711
- public static function importMetaData()
712
- {
713
  global $wpdb;
714
  $meta_metaseo_keys = array('_metaseo_metatitle', '_metaseo_metadesc');
715
- $key = array(
716
- '_aio_' => array('_aioseop_title', '_aioseop_description'),
717
  '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
718
  );
719
 
720
- if (!empty($_POST['plugin']) and in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
721
- $plugin = strtolower(trim($_POST['plugin']));
722
  $metakeys = '';
723
  foreach ($meta_metaseo_keys as $k => $mkey) {
724
- $metakeys .= ' OR `meta_key` = \'' . $mkey . '\' OR `meta_key` = \'' . $key[$plugin][$k] . '\'';
725
  }
726
 
727
  $metakeys = ltrim($metakeys, ' OR ');
728
- $query = "SELECT `post_id` as pID, `meta_key`, `meta_value`
729
- FROM $wpdb->postmeta
730
- WHERE $metakeys
731
- ORDER BY `meta_key`";
732
- $posts_metas = $wpdb->get_results($query);
733
 
734
  if (is_array($posts_metas) && count($posts_metas) > 0) {
735
  $_posts_metas = array();
@@ -739,15 +678,15 @@ class MetaSeoContentListTable extends WP_List_Table
739
  unset($posts_metas);
740
  foreach ($_posts_metas as $pID => $pmeta) {
741
  foreach ($meta_metaseo_keys as $k => $mkey) {
742
- $mvalue = $pmeta[$mkey];
743
- $msynckey = $key[$plugin][$k];
744
  $msyncvalue = $pmeta[$msynckey];
745
 
746
- if (is_null($mvalue) || ($mvalue == '' && $msynckey != '')) {
747
  update_post_meta($pID, $mkey, $msyncvalue);
748
- } elseif (is_null($msyncvalue) || ($msyncvalue == '' && $mvalue != '')) {
749
  update_post_meta($pID, $msynckey, $mvalue);
750
- } elseif ($mvalue != '' && $msyncvalue != '') {
751
  update_post_meta($pID, $mkey, $msyncvalue);
752
  }
753
  }
@@ -772,10 +711,17 @@ class MetaSeoContentListTable extends WP_List_Table
772
 
773
  /**
774
  * Dismiss import message
 
 
775
  */
776
  public static function dismissImport()
777
  {
778
- if (!empty($_POST['plugin']) and in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
 
 
 
 
 
779
  $plugin = strtolower(trim($_POST['plugin']));
780
 
781
  update_option($plugin . 'import_notice_flag', 1);
@@ -790,11 +736,13 @@ class MetaSeoContentListTable extends WP_List_Table
790
 
791
  /**
792
  * Update meta sync
793
- * @param int $meta_id meta id
794
- * @param int $object_id object id
795
- * @param string $meta_key meta key
796
- * @param string $meta_value meta value
797
- * @return bool|null
 
 
798
  */
799
  public static function updateMetaSync($meta_id, $object_id, $meta_key, $meta_value)
800
  {
@@ -810,12 +758,14 @@ class MetaSeoContentListTable extends WP_List_Table
810
  }
811
 
812
  /**
813
- * deletes all custom fields with the specified key
814
- * @param int $meta_ids meta id
815
- * @param int $object_id object id
816
- * @param string $meta_key meta key
817
- * @param string $meta_value meta value
818
- * @return bool|null
 
 
819
  */
820
  public static function deleteMetaSync($meta_ids, $object_id, $meta_key, $meta_value)
821
  {
@@ -832,27 +782,30 @@ class MetaSeoContentListTable extends WP_List_Table
832
 
833
  /**
834
  * Update meta sync
835
- * @param string $type
836
- * @param int $object_id object id
837
- * @param string $meta_key meta key
838
- * @param string $meta_value meta value
839
- * @return bool
 
 
840
  */
841
  private static function doUpdateMetaSync($object_id, $meta_key, $meta_value, $type = '')
842
  {
843
- if (!($sync = get_option('plugin_to_sync_with')) or !in_array($sync, array('_aio_', '_yoast_'))) {
 
844
  return false;
845
  }
846
 
847
  $metakeys = array(
848
  '_metaseo_' => array('_metaseo_metatitle', '_metaseo_metadesc'),
849
- '_aio_' => array('_aioseop_title', '_aioseop_description'),
850
- '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
851
  );
852
 
853
- $_metakeys = array();
854
  $_metakeys['_metaseo_'] = $metakeys['_metaseo_'];
855
- $_metakeys[$sync] = $metakeys[$sync];
856
  unset($metakeys);
857
 
858
  foreach ($_metakeys as $identify => $mkeys) {
@@ -864,12 +817,12 @@ class MetaSeoContentListTable extends WP_List_Table
864
  $mkeysync = $_metakeys['_metaseo_'][$k];
865
  }
866
 
867
- if ($type == 'update') {
868
  update_post_meta($object_id, $mkeysync, $meta_value);
869
  return true;
870
  }
871
 
872
- if ($type == 'delete') {
873
  delete_post_meta($object_id, $mkeysync);
874
  return true;
875
  }
@@ -882,8 +835,10 @@ class MetaSeoContentListTable extends WP_List_Table
882
 
883
  /**
884
  * Check is update sync
885
- * @param $meta_key
886
- * @return bool
 
 
887
  */
888
  public static function isUpdateSync($meta_key)
889
  {
12
  class MetaSeoContentListTable extends WP_List_Table
13
  {
14
  /**
15
+ * Post type
16
+ *
17
+ * @var array
18
  */
19
  public $post_types;
20
 
25
  {
26
  parent::__construct(array(
27
  'singular' => 'metaseo_content',
28
+ 'plural' => 'metaseo_contents',
29
+ 'ajax' => true
30
  ));
31
  }
32
 
33
  /**
34
  * Generate the table navigation above or below the table
35
+ *
36
+ * @param string $which Possition of table nav
37
+ *
38
+ * @return void
39
  */
40
+ protected function display_tablenav($which) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
41
  {
42
  ?>
43
+ <div class="<?php echo esc_attr('tablenav ' . $which); ?>">
44
 
45
  <input type="hidden" name="page" value="metaseo_content_meta"/>
46
  <input type="hidden" name="page" value="metaseo_content_meta"/>
47
+ <?php // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
48
+ ?>
49
  <?php if (!empty($_REQUEST['post_status'])) : ?>
50
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
51
  <?php endif ?>
52
+ <?php // phpcs:enable
53
+ ?>
54
  <?php $this->extra_tablenav($which); ?>
55
 
56
  <div style="float:right;margin-left:8px;">
57
  <label>
58
+ <input type="number" required
59
+ value="<?php echo esc_attr($this->_pagination_args['per_page']) ?>"
60
  maxlength="3" name="metaseo_posts_per_page" class="metaseo_imgs_per_page screen-per-page"
61
  max="999" min="1" step="1">
62
  </label>
63
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
64
  </div>
 
65
  <?php $this->pagination($which); ?>
66
  <br class="clear"/>
67
  </div>
69
  <?php
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Extra controls to be displayed between bulk actions and pagination
74
+ *
75
+ * @param string $which Possition of table nav
76
+ *
77
+ * @return void
78
  */
79
+ protected function extra_tablenav($which) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
80
  {
81
  echo '<div class="alignleft actions">';
82
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
83
+ $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : - 1;
84
 
85
  $options = '<option value="-1">Show All Post Types</option>';
86
 
87
  foreach ($this->post_types as $post_type) {
88
+ $obj = get_post_type_object($post_type);
89
  $options .= sprintf(
90
  '<option value="%2$s" %3$s>%1$s</option>',
91
+ esc_html($obj->labels->name),
92
+ esc_attr($post_type),
93
+ selected($selected, $post_type, false)
94
  );
95
  }
96
 
97
+ $sl_bulk = '<select name="mbulk_copy" class="mbulk_copy">
98
+ <option value="0">' . esc_html__('Bulk copy', 'wp-meta-seo') . '</option>
99
+ <option value="all">' . esc_html__('All Posts', 'wp-meta-seo') . '</option>
100
+ <option value="bulk-copy-metatitle">' . esc_html__('Selected posts', 'wp-meta-seo') . '</option>
101
  </select>';
102
  $btn_bulk = '<input type="button" name="do_copy" id="post_do_copy"
103
  class="wpmsbtn wpmsbtn_small btn_do_copy post_do_copy"
104
+ value="' . esc_attr__('Content title as meta title', 'wp-meta-seo') . '"><span class="spinner"></span>';
105
 
106
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
107
  $selected_duplicate = !empty($_REQUEST['wpms_duplicate_meta']) ? $_REQUEST['wpms_duplicate_meta'] : 'none';
108
+ $options_dups = array(
109
+ 'none' => esc_html__('All meta information', 'wp-meta-seo'),
110
+ 'duplicate_title' => esc_html__('Duplicated meta titles', 'wp-meta-seo'),
111
+ 'duplicate_desc' => esc_html__('Duplicated meta descriptions', 'wp-meta-seo')
112
  );
113
+ $sl_duplicate = '<select name="wpms_duplicate_meta" class="wpms_duplicate_meta">';
114
  foreach ($options_dups as $key => $label) {
115
+ if ($selected_duplicate === $key) {
116
+ $sl_duplicate .= '<option selected value="' . esc_attr($key) . '">' . esc_html($label) . '</option>';
117
  } else {
118
+ $sl_duplicate .= '<option value="' . esc_attr($key) . '">' . esc_html($label) . '</option>';
119
  }
120
  }
121
  $sl_duplicate .= '</select>';
122
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
123
  echo sprintf('<select name="post_type_filter" class="metaseo-filter">%1$s</select>', $options);
124
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
125
  echo $sl_duplicate;
126
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
127
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
128
  || is_plugin_active('polylang/polylang.php'))) {
129
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
130
+ $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
131
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
132
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::listLanguageSelect
133
  echo $sl_lang;
134
  }
135
+
136
  echo '<input type="submit" name="do_filter" id="post-query-submit"
137
+ class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="' . esc_html__('Filter', 'wp-meta-seo') . '">';
138
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
139
  echo $sl_bulk . $btn_bulk;
140
+ echo '</div>';
141
  }
142
 
143
  /**
144
  * Get a list of columns. The format is:
145
  * 'internal-name' => 'Title'
146
+ *
147
  * @return array
148
  */
149
+ public function get_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
150
  {
151
+ $preview = esc_html__(" This is a rendering of what this post might look
152
  like in Google's search results.", 'wp-meta-seo');
153
+ $info = sprintf('<a class="info-content"><img src=' . WPMETASEO_PLUGIN_URL . 'img/info.png>'
154
+ . '<p class="tooltip-metacontent">'
155
+ . $preview
156
+ . '</p></a>');
157
 
158
  $columns = array(
159
+ 'cb' => '<input id="cb-select-all-1" type="checkbox" style="margin:0">',
160
+ 'col_id' => '',
161
+ 'col_title' => esc_html__('Title', 'wp-meta-seo'),
162
+ 'col_snippet' => sprintf(esc_html__('Snippet Preview %s', 'wp-meta-seo'), $info),
163
+ 'col_meta_title' => esc_html__('Meta Title', 'wp-meta-seo'),
164
  );
165
 
166
  $settings = get_option('_metaseo_settings');
167
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
168
+ $columns['col_meta_keywords'] = esc_html__('Meta Keywords', 'wp-meta-seo');
169
  }
170
+ $columns['col_meta_desc'] = esc_html__('Meta Description', 'wp-meta-seo');
171
+ $settings = get_option('_metaseo_settings');
172
  if (!empty($settings['metaseo_follow'])) {
173
+ $columns['col_follow'] = esc_html__('Follow', 'wp-meta-seo');
174
  }
175
 
176
  if (!empty($settings['metaseo_index'])) {
177
+ $columns['col_index'] = esc_html__('Index', 'wp-meta-seo');
178
  }
179
 
180
  return $columns;
187
  * 'internal-name' => array( 'orderby', true )
188
  *
189
  * The second format will make the initial sorting order be descending
190
+ *
191
  * @return array
192
  */
193
+ protected function get_sortable_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
194
  {
195
+ $sortable = array(
196
+ 'col_title' => array('post_title', true),
197
  'col_meta_title' => array('metatitle', true),
198
+ 'col_meta_desc' => array('metadesc', true)
199
  );
200
+
201
+ return $sortable;
202
  }
203
 
204
  /**
205
+ * Get all posts that is public and contain images with a string seperated by comma
206
+ *
207
+ * @param string $unset Unset element
208
+ *
209
+ * @return array
210
  */
211
+ public static function getPostTypes($unset = '')
212
  {
 
213
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
214
+ if (!empty($unset)) {
215
+ unset($post_types[$unset]);
216
+ }
 
 
 
 
 
 
217
  return $post_types;
218
  }
219
 
220
  /**
221
  * Prepares the list of items for displaying.
222
+ *
223
+ * @return void
224
  */
225
+ public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
226
  {
227
  global $wpdb;
228
+ $this->post_types = $this->getPostTypes();
229
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
230
+ $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : '';
231
+ if ($post_type === '-1') {
232
+ $post_type = '';
233
  }
234
 
235
+ if (!empty($post_type) && !in_array($post_type, $this->post_types)) {
236
+ $post_type = 'post';
 
237
  } elseif (empty($post_type)) {
238
+ $post_type = $this->getPostTypes();
239
+ foreach ($post_type as &$pt) {
240
+ $pt = esc_sql($pt);
241
+ }
242
+ $post_type = implode("', '", $post_type);
243
  }
244
 
 
 
245
  $states = get_post_stati(array('show_in_admin_all_list' => true));
246
+ foreach ($states as &$state) {
247
+ $state = esc_sql($state);
 
 
 
 
 
 
 
 
 
248
  }
249
 
250
+ $all_states = implode("', '", $states);
251
+ $where = array();
252
+ $where[] = 'post_type IN (\'' . $post_type . '\')';
253
+ $where[] = 'post_status IN (\'' . $all_states . '\')';
254
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
255
+ $keyword = !empty($_GET['s']) ? $_GET['s'] : '';
256
+ if (isset($keyword) && $keyword !== '') {
257
+ $where[] = $wpdb->prepare('(post_title LIKE %s OR mt.meta_value LIKE %s OR md.meta_value LIKE %s)', array(
258
+ '%' . $keyword . '%',
259
+ '%' . $keyword . '%',
260
+ '%' . $keyword . '%'
261
+ ));
262
  }
263
 
264
  //Order By block
265
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
266
+ $orderby = !empty($_GET['orderby']) ? ($_GET['orderby']) : 'post_title';
267
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
268
+ $order = !empty($_GET['order']) ? ($_GET['order']) : 'asc';
269
 
270
+ $sortable = $this->get_sortable_columns();
271
  $orderby_array = array($orderby, true);
272
  if (in_array($orderby_array, $sortable)) {
273
  $orderStr = $orderby;
275
  $orderStr = 'post_title';
276
  }
277
 
278
+ if ($order === 'asc') {
279
+ $orderStr .= ' ASC';
280
  } else {
281
+ $orderStr .= ' DESC';
282
  }
283
 
284
  if (!empty($orderby) & !empty($order)) {
285
+ $orderStr = ' ORDER BY ' . esc_sql($orderStr) . ' ';
 
286
  }
287
 
288
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
289
+ if (isset($_GET['wpms_duplicate_meta']) && $_GET['wpms_duplicate_meta'] !== 'none') {
290
+ if ($_GET['wpms_duplicate_meta'] === 'duplicate_title') {
291
+ $where[] = 'mt.meta_key = "_metaseo_metatitle" AND mt.meta_value IN (SELECT DISTINCT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key="_metaseo_metatitle" AND meta_value != "" GROUP BY meta_value HAVING COUNT(*) >= 2)';
292
+ } elseif ($_GET['wpms_duplicate_meta'] === 'duplicate_desc') {
293
+ $where[] = 'md.meta_key = "_metaseo_metadesc" AND md.meta_value IN (SELECT DISTINCT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key="_metaseo_metadesc" AND meta_value != "" GROUP BY meta_value HAVING COUNT(*) >= 2)';
 
 
294
  }
295
  }
296
+ // phpcs:enable
297
+ $query = 'SELECT COUNT(ID) '
298
+ . ' FROM ' . $wpdb->posts . ' as p'
299
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metatitle") mt ON mt.post_id = p.ID '
300
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metadesc") md ON md.post_id = p.ID '
301
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metakeywords") mk ON mk.post_id = p.ID ';
302
+ $query .= ' WHERE ' . implode(' AND ', $where);
303
 
304
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
 
 
 
 
 
 
 
 
 
305
  $total_items = $wpdb->get_var($query);
 
 
 
 
 
 
 
 
 
306
 
307
+ $query = 'SELECT DISTINCT ID, post_title, post_name, post_type, post_status, mt.meta_value AS metatitle, md.meta_value AS metadesc ,mk.meta_value AS metakeywords '
308
+ . ' FROM ' . $wpdb->posts . ' as p'
309
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metatitle") mt ON mt.post_id = p.ID '
310
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metadesc") md ON md.post_id = p.ID '
311
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metakeywords") mk ON mk.post_id = p.ID';
312
  // query post by lang with polylang plugin
313
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
314
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
315
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] !== '0') {
316
+ $query .= $wpdb->prepare(' INNER JOIN (SELECT * FROM ' . $wpdb->term_relationships . ' as ml
317
+ INNER JOIN (SELECT * FROM ' . $wpdb->terms . ' WHERE slug = %s)
318
+ mp ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = p.ID ', array($_GET['wpms_lang_list']));
319
  }
320
+ // phpcs:enable
321
  }
322
 
323
  // query post by lang with WPML plugin
324
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
325
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
326
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] !== '0') {
327
+ $query .= $wpdb->prepare(' INNER JOIN (SELECT * FROM ' . $wpdb->prefix . 'icl_translations
328
+ WHERE element_type LIKE %s AND language_code = %s) t
329
+ ON t.element_id = p.ID ', array('post_%', $_GET['wpms_lang_list']));
330
  }
331
+ // phpcs:enable
332
  }
333
 
334
+ $query .= ' WHERE ' . implode(' AND ', $where) . $orderStr;
335
 
336
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
337
  if (!empty($_REQUEST['metaseo_posts_per_page'])) {
338
  $_per_page = intval($_REQUEST['metaseo_posts_per_page']);
339
  } else {
355
  add_user_meta(get_current_user_id(), 'metaseo_posts_per_page', $per_page);
356
  }
357
 
358
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
359
+ $paged = !empty($_GET['paged']) ? $_GET['paged'] : '';
360
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
361
  $paged = 1;
362
  }
365
 
366
  if (!empty($paged) && !empty($per_page)) {
367
  $offset = ($paged - 1) * $per_page;
368
+ $query .= $wpdb->prepare(' LIMIT %d, %d', array($offset, $per_page));
369
  }
370
 
371
  $this->set_pagination_args(array(
372
  'total_items' => $total_items,
373
  'total_pages' => $total_pages,
374
+ 'per_page' => $per_page
375
  ));
376
 
377
+ $columns = $this->get_columns();
378
+ $hidden = array();
379
+ $sortable = $this->get_sortable_columns();
380
  $this->_column_headers = array($columns, $hidden, $sortable);
381
 
382
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
383
  $this->items = $wpdb->get_results($query);
384
  }
385
 
386
  /**
387
  * Generate the table rows
388
+ *
389
+ * @return void
390
  */
391
+ public function display_rows() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
392
  {
393
+ $records = $this->items;
394
+ $i = 0;
395
+ $alternate = '';
396
+ $url = preg_replace('/(http|https):\/\/[w]*[.]?/', '', network_site_url('/'));
397
 
398
  list($columns, $hidden) = $this->get_column_info();
399
 
400
  if (!empty($records)) {
401
  foreach ($records as $rec) {
402
+ $alternate = 'alternate' === $alternate ? '' : 'alternate';
403
+ $i ++;
404
+ $classes = $alternate;
405
  $rec->link = $url;
406
 
407
+ echo '<tr id="' . esc_attr('record_' . $rec->ID) . '" class="' . esc_attr($classes) . '" >';
408
 
409
  foreach ($columns as $column_name => $column_display_name) {
410
+ $class = sprintf('class="%1$s column-%1$s"', esc_attr($column_name));
411
+ $style = '';
412
 
413
  if (in_array($column_name, $hidden)) {
414
  $style = ' style="display:none;"';
419
  switch ($column_name) {
420
  case 'cb':
421
  echo '<th scope="row" class="check-column">';
422
+ echo '<input id="' . esc_attr('cb-select-' . $rec->ID) . '"
423
+ class="metaseo_post" type="checkbox" name="post[]" value="' . esc_attr($rec->ID) . '">';
424
  echo '</th>';
425
 
426
  break;
427
 
428
  case 'col_id':
429
  echo '<td class="col_id" >';
430
+ echo esc_html($i);
431
  echo '</td>';
432
 
433
  break;
434
 
435
  case 'col_title':
436
  $post_title = stripslashes($rec->post_title);
437
+ if ($post_title === '') {
438
+ $post_title = esc_html__('(no title)', 'wp-meta-seo');
439
  }
440
 
441
  echo sprintf(
442
  '<td %2$s><div class="action-wrapper">
443
+ <strong id="' . esc_attr('post-title-' . $rec->ID) . '">%1$s</strong>',
444
+ esc_html($post_title),
445
+ $attributes // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
446
  );
447
 
448
  $post_type_object = get_post_type_object($rec->post_type);
449
+ $can_edit_post = current_user_can($post_type_object->cap->edit_post, $rec->ID);
450
 
451
  $actions = array();
452
 
453
+ if ($can_edit_post && 'trash' !== $rec->post_status) {
454
+ $actions['edit'] = '<a href="' . esc_url(get_edit_post_link($rec->ID, true)) . '"
455
+ title="' . esc_attr__('Edit this item', 'wp-meta-seo') . '"
456
+ >' . esc_html__('Edit', 'wp-meta-seo') . '</a>';
457
  }
458
 
459
  if ($post_type_object->public) {
460
  if (in_array($rec->post_status, array('pending', 'draft', 'future'))) {
461
  if ($can_edit_post) {
462
+ $hr = esc_url(add_query_arg('preview', 'true', get_permalink($rec->ID)));
463
+ $t = esc_attr(
464
  sprintf(
465
+ esc_html__('Preview &#8220;%s&#8221;', 'wp-meta-seo'),
466
  $rec->post_title
467
  )
468
  );
469
+ $actions['view'] = '<a href="' . esc_url($hr) . '" title="' . esc_html($t) . '" rel="permalink"
470
+ >' . esc_html__('Preview', 'wp-meta-seo') . '</a>';
471
  }
472
+ } elseif ('trash' !== $rec->post_status) {
473
+ $t = esc_attr(
474
  sprintf(
475
+ esc_html__('View &#8220;%s&#8221;', 'wp-meta-seo'),
476
  $rec->post_title
477
  )
478
  );
479
+ $actions['view'] = '<a target="_blank" href="' . esc_url(get_permalink($rec->ID)) . '"
480
+ title="' . esc_attr($t) . '" rel="permalink">' . esc_html__('View', 'wp-meta-seo') . '</a>';
481
  }
482
  }
483
 
484
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
485
  echo $this->row_actions($actions);
486
  echo '</div></td>';
487
 
490
  case 'col_snippet':
491
  echo '<td><div class="snippet-wrapper">';
492
  echo '<div class="snippet">
493
+ <a id="' . esc_attr('snippet_title' . $rec->ID) . '" class="snippet_metatitle">
494
+ ' . (!empty($rec->metatitle) ? esc_html($rec->metatitle) : esc_html($rec->post_title)) . '</a>';
495
 
496
+ echo '<span class="snippet_metalink" id="' . esc_attr('snippet_metalink_' . $rec->ID) . '">
497
+ ' . esc_html($rec->link) . '</span>';
498
 
499
+ echo '<p id="' . esc_attr('snippet_desc' . $rec->ID) . '" class="snippet_metades">
500
+ ' . esc_html($rec->metadesc) . '</p></div>';
501
+ echo '<img class="' . esc_attr('wpms_loader' . $rec->ID . ' wpms_content_loader') . '"
502
+ src=' . esc_url(WPMETASEO_PLUGIN_URL) . 'img/update_loading.gif>';
503
+ echo '<span id="' . esc_attr('savedInfo' . $rec->ID) . '"
504
  style="position: relative; display: block;float:right"
505
  class="saved-info metaseo-msg-success"><span style="position:absolute; float:right" class="spinner"></span></span>';
506
  echo '</div></td>';
507
  break;
 
 
 
 
 
 
 
 
 
 
508
 
509
  case 'col_meta_title':
510
  $input = sprintf(
511
  '</br><textarea class="large-text metaseo-metatitle"
512
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
513
+ esc_attr('metaseo-metatitle-' . $rec->ID),
514
+ esc_attr('metatitle[' . $rec->ID . ']'),
515
+ ($rec->metatitle) ? esc_textarea($rec->metatitle) : ''
516
  );
517
  $input .= sprintf(
518
  '<div class="title-len" id="%1$s"></div>',
519
+ esc_attr('metaseo-metatitle-len' . $rec->ID)
520
  );
521
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
522
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
523
  break;
524
 
526
  $input = sprintf(
527
  '</br><textarea class="large-text metaseo-metakeywords"
528
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
529
+ esc_attr('metaseo-metakeywords-' . $rec->ID),
530
+ esc_attr('metakeywords[' . $rec->ID . ']'),
531
+ ($rec->metakeywords) ? esc_textarea($rec->metakeywords) : ''
532
  );
533
  $input .= sprintf(
534
  '<div class="keywords-len" id="%1$s"></div>',
535
+ esc_attr('metaseo-metakeywords-len' . $rec->ID)
536
  );
537
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
538
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
539
  break;
540
 
542
  $input = sprintf(
543
  '</br><textarea class="large-text metaseo-metadesc"
544
  rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
545
+ esc_attr('metaseo-metadesc-' . $rec->ID),
546
+ esc_attr(' metades[' . $rec->ID . ']'),
547
+ ($rec->metadesc) ? esc_textarea($rec->metadesc) : ''
548
  );
549
  $input .= sprintf(
550
  '<div class="desc-len" id="%1$s"></div>',
551
+ esc_attr('metaseo-metadesc-len' . $rec->ID)
552
  );
553
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
554
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
555
  break;
556
 
557
  case 'col_index':
558
  $page_index = get_post_meta($rec->ID, '_metaseo_metaindex', true);
559
+ if (isset($page_index) && $page_index === 'noindex') {
560
  $input = '<input class="metaseo_post_index"
561
+ name="index[]" type="checkbox" value="' . esc_attr($rec->ID) . '">';
562
  } else {
563
  $input = '<input checked class="metaseo_post_index"
564
+ name="index[]" type="checkbox" value="' . esc_attr($rec->ID) . '">';
565
  }
566
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
567
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
568
  break;
569
 
570
  case 'col_follow':
571
  $page_follow = get_post_meta($rec->ID, '_metaseo_metafollow', true);
572
+ if (isset($page_follow) && $page_follow === 'nofollow') {
573
  $input = '<input class="metaseo_post_follow"
574
+ name="follow[]" type="checkbox" value="' . esc_attr($rec->ID) . '">';
575
  } else {
576
  $input = '<input checked class="metaseo_post_follow"
577
+ name="follow[]" type="checkbox" value="' . esc_attr($rec->ID) . '">';
578
  }
579
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
580
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
581
  break;
582
  }
589
 
590
  /**
591
  * Retrieves a modified URL query string.
592
+ *
593
+ * @return void
594
  */
595
  public function processAction()
596
  {
597
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
598
+ $redirect = false;
599
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
600
  if (isset($_POST['do_filter'])) {
601
+ if (isset($_POST['post_type_filter'])) {
602
+ $current_url = add_query_arg(array('post_type_filter' => $_POST['post_type_filter']), $current_url);
603
+ }
604
+
605
+ if (isset($_POST['wpms_duplicate_meta'])) {
606
+ $current_url = add_query_arg(array('wpms_duplicate_meta' => $_POST['wpms_duplicate_meta']), $current_url);
607
+ }
608
+
609
+ if (isset($_POST['wpms_lang_list'])) {
610
+ $current_url = add_query_arg(array('wpms_lang_list' => $_POST['wpms_lang_list']), $current_url);
611
+ }
612
+
613
  $redirect = true;
614
  }
615
 
616
  if (!empty($_POST['paged'])) {
617
+ $current_url = add_query_arg(array('paged' => intval($_POST['paged'])), $current_url);
618
+ $redirect = true;
619
  }
620
 
621
  if (!empty($_POST['metaseo_posts_per_page'])) {
622
  $current_url = add_query_arg(
623
  array(
624
+ 'metaseo_posts_per_page' => intval($_POST['metaseo_posts_per_page'])
625
+ ),
626
  $current_url
627
  );
628
+ $redirect = true;
629
  }
630
 
631
  if (isset($_POST['s'])) {
632
+ $current_url = add_query_arg(array('s' => urlencode($_POST['s'])), $current_url);
633
+ $redirect = true;
634
  }
635
+ // phpcs:enable
636
+ if ($redirect) {
637
  wp_redirect($current_url);
638
  ob_end_flush();
639
  exit();
641
  }
642
 
643
  /**
644
+ * Import meta from other plugin
645
+ *
646
+ * @return void
647
  */
648
+ public static function importMetaData()
649
  {
650
+ if (empty($_POST['wpms_nonce'])
651
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
652
+ die();
653
  }
654
 
 
 
 
 
 
 
 
 
655
  global $wpdb;
656
  $meta_metaseo_keys = array('_metaseo_metatitle', '_metaseo_metadesc');
657
+ $key = array(
658
+ '_aio_' => array('_aioseop_title', '_aioseop_description'),
659
  '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
660
  );
661
 
662
+ if (!empty($_POST['plugin']) && in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
663
+ $plugin = strtolower(trim($_POST['plugin']));
664
  $metakeys = '';
665
  foreach ($meta_metaseo_keys as $k => $mkey) {
666
+ $metakeys .= $wpdb->prepare(' OR meta_key = %s OR meta_key = %s', array($mkey, $key[$plugin][$k]));
667
  }
668
 
669
  $metakeys = ltrim($metakeys, ' OR ');
670
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
671
+ $posts_metas = $wpdb->get_results('SELECT post_id as pID, meta_key, meta_value FROM ' . $wpdb->postmeta . ' WHERE ' . $metakeys . ' ORDER BY meta_key');
 
 
 
672
 
673
  if (is_array($posts_metas) && count($posts_metas) > 0) {
674
  $_posts_metas = array();
678
  unset($posts_metas);
679
  foreach ($_posts_metas as $pID => $pmeta) {
680
  foreach ($meta_metaseo_keys as $k => $mkey) {
681
+ $mvalue = $pmeta[$mkey];
682
+ $msynckey = $key[$plugin][$k];
683
  $msyncvalue = $pmeta[$msynckey];
684
 
685
+ if (is_null($mvalue) || ($mvalue === '' && $msynckey !== '')) {
686
  update_post_meta($pID, $mkey, $msyncvalue);
687
+ } elseif (is_null($msyncvalue) || ($msyncvalue === '' && $mvalue !== '')) {
688
  update_post_meta($pID, $msynckey, $mvalue);
689
+ } elseif ($mvalue !== '' && $msyncvalue !== '') {
690
  update_post_meta($pID, $mkey, $msyncvalue);
691
  }
692
  }
711
 
712
  /**
713
  * Dismiss import message
714
+ *
715
+ * @return void
716
  */
717
  public static function dismissImport()
718
  {
719
+ if (empty($_POST['wpms_nonce'])
720
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
721
+ die();
722
+ }
723
+
724
+ if (!empty($_POST['plugin']) && in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
725
  $plugin = strtolower(trim($_POST['plugin']));
726
 
727
  update_option($plugin . 'import_notice_flag', 1);
736
 
737
  /**
738
  * Update meta sync
739
+ *
740
+ * @param integer $meta_id Meta id
741
+ * @param integer $object_id Object id
742
+ * @param string $meta_key Meta key
743
+ * @param string $meta_value Meta value
744
+ *
745
+ * @return boolean|null
746
  */
747
  public static function updateMetaSync($meta_id, $object_id, $meta_key, $meta_value)
748
  {
758
  }
759
 
760
  /**
761
+ * Deletes all custom fields with the specified key
762
+ *
763
+ * @param integer $meta_ids Meta id
764
+ * @param integer $object_id Object id
765
+ * @param string $meta_key Meta key
766
+ * @param string $meta_value Meta value
767
+ *
768
+ * @return boolean|null
769
  */
770
  public static function deleteMetaSync($meta_ids, $object_id, $meta_key, $meta_value)
771
  {
782
 
783
  /**
784
  * Update meta sync
785
+ *
786
+ * @param integer $object_id Object id
787
+ * @param string $meta_key Meta key
788
+ * @param string $meta_value Meta value
789
+ * @param string $type Type
790
+ *
791
+ * @return boolean
792
  */
793
  private static function doUpdateMetaSync($object_id, $meta_key, $meta_value, $type = '')
794
  {
795
+ $sync = get_option('plugin_to_sync_with');
796
+ if (!$sync || !in_array($sync, array('_aio_', '_yoast_'))) {
797
  return false;
798
  }
799
 
800
  $metakeys = array(
801
  '_metaseo_' => array('_metaseo_metatitle', '_metaseo_metadesc'),
802
+ '_aio_' => array('_aioseop_title', '_aioseop_description'),
803
+ '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
804
  );
805
 
806
+ $_metakeys = array();
807
  $_metakeys['_metaseo_'] = $metakeys['_metaseo_'];
808
+ $_metakeys[$sync] = $metakeys[$sync];
809
  unset($metakeys);
810
 
811
  foreach ($_metakeys as $identify => $mkeys) {
817
  $mkeysync = $_metakeys['_metaseo_'][$k];
818
  }
819
 
820
+ if ($type === 'update') {
821
  update_post_meta($object_id, $mkeysync, $meta_value);
822
  return true;
823
  }
824
 
825
+ if ($type === 'delete') {
826
  delete_post_meta($object_id, $mkeysync);
827
  return true;
828
  }
835
 
836
  /**
837
  * Check is update sync
838
+ *
839
+ * @param string $meta_key Meta key
840
+ *
841
+ * @return boolean
842
  */
843
  public static function isUpdateSync($meta_key)
844
  {
inc/class.metaseo-dashboard.php CHANGED
@@ -9,42 +9,48 @@ defined('ABSPATH') || die('No direct script access allowed!');
9
  class MetaSeoDashboard
10
  {
11
  /**
12
- * max length meta title
13
- * @var int
 
14
  */
15
  public static $meta_title_length = 69;
16
  /**
17
- * max length meta description
18
- * @var int
 
19
  */
20
  public static $meta_desc_length = 320;
 
21
  /**
22
  * Get image optimize
 
23
  * @return array
24
  */
25
  public static function moptimizationChecking()
26
  {
27
  global $wpdb;
28
- $imgs = 0;
29
- $imgs_are_good = 0;
30
  $imgs_metas_are_good = array();
31
- $response = array(
32
- 'imgs_statis' => array(0, 0, 100),
33
  'imgs_metas_statis' => array(0, 0, 100),
34
  );
35
 
36
- $imgs_metas_are_good['alt'] = 0;
37
  $imgs_metas_are_not_good['alt'] = 0;
38
 
39
  $post_types = MetaSeoContentListTable::getPostTypes();
40
- $query = "SELECT `ID`,`post_content`
41
- FROM $wpdb->posts
42
- WHERE `post_type` IN ($post_types)
43
- AND `post_content` <> ''
44
- AND `post_content` LIKE '%<img%>%'
45
- ORDER BY ID";
46
-
47
- $posts = $wpdb->get_results($query);
 
 
48
  if (count($posts) > 0) {
49
  $doc = new DOMDocument();
50
  libxml_use_internal_errors(true);
@@ -70,13 +76,13 @@ class MetaSeoDashboard
70
  continue;
71
  }
72
 
73
- $width = $tag->getAttribute('width');
74
  $height = $tag->getAttribute('height');
75
- if (list($real_width, $real_height) = @getimagesize($img_path)) {
76
  $ratio_origin = $real_width / $real_height;
77
  //Check if img tag is missing with/height attribute value or not
78
  if (!$width && !$height) {
79
- $width = $real_width;
80
  $height = $real_height;
81
  } elseif ($width && !$height) {
82
  $height = $width * (1 / $ratio_origin);
@@ -86,23 +92,23 @@ class MetaSeoDashboard
86
 
87
  if (($real_width <= $width && $real_height <= $height)
88
  || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
89
- $imgs_are_good++;
90
  }
91
 
92
  if (trim($tag->getAttribute('alt'))
93
  || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
94
- $imgs_metas_are_good['alt']++;
95
  }
96
  }
97
 
98
- $imgs++;
99
  }
100
  }
101
 
102
  //Report analytic of images optimization
103
- $imgs_metas = $imgs_metas_are_good['alt'];
104
- $response['imgs_statis'][0] = $imgs_are_good;
105
- $response['imgs_statis'][1] = $imgs;
106
  $response['imgs_metas_statis'][0] = $imgs_metas;
107
  $response['imgs_metas_statis'][1] = $imgs;
108
 
@@ -125,27 +131,34 @@ class MetaSeoDashboard
125
 
126
  /**
127
  * Display rank of site
128
- * @param $url
 
 
 
129
  */
130
  public function displayRank($url)
131
  {
132
  $rank = $this->getRank($url);
133
  if ($rank !== '') {
 
134
  echo $rank;
135
  } else {
136
- echo __('We can\'t get rank of this site from Alexa.com!', 'wp-meta-seo');
137
  }
138
  }
139
 
140
  /**
141
  * Get rank of site
142
- * @param $url
 
 
143
  * @return mixed|string
144
  */
145
  public function getRank($url)
146
  {
147
  if (!function_exists('curl_version')) {
148
- if (!$content = @file_get_contents($url)) {
 
149
  return '';
150
  }
151
  } else {
@@ -153,20 +166,24 @@ class MetaSeoDashboard
153
  $url = array($url);
154
  }
155
  $contents = $this->getContents($url);
156
- $content = $contents[0];
157
  }
158
 
159
  $doc = new DOMDocument();
160
  libxml_use_internal_errors(true);
161
- @$doc->loadHTML($content);
 
 
 
 
162
  $doc->preserveWhiteSpace = false;
163
 
164
- $finder = new DOMXPath($doc);
165
  $classname = 'note-no-data';
166
- $nodes = $finder->query("//section[contains(@class, '$classname')]");
167
  if ($nodes->length < 1) {
168
  $classname = 'rank-row';
169
- $nodes = $finder->query("//div[contains(@class, '$classname')]");
170
  }
171
 
172
  $tmp_dom = new DOMDocument();
@@ -175,7 +192,7 @@ class MetaSeoDashboard
175
  }
176
 
177
  $html = trim($tmp_dom->saveHTML());
178
- $html = str_replace('We don\'t have', __('Alexa doesn\'t have', 'wp-meta-seo'), $html);
179
  $html = str_replace('Get Certified', '', $html);
180
  $html = str_replace('"/topsites/countries', '"http://www.alexa.com/topsites/countries', $html);
181
  return $html;
@@ -183,21 +200,23 @@ class MetaSeoDashboard
183
 
184
  /**
185
  * Get content a file
186
- * @param $urls
 
 
187
  * @return array
188
  */
189
  public function getContents($urls)
190
  {
191
- $mh = curl_multi_init();
192
  $curl_array = array();
193
- $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36';
194
  foreach ($urls as $i => $url) {
195
  $curl_array[$i] = curl_init($url);
196
  curl_setopt($curl_array[$i], CURLOPT_URL, $url);
197
  curl_setopt($curl_array[$i], CURLOPT_USERAGENT, $useragent); // set user agent
198
  curl_setopt($curl_array[$i], CURLOPT_RETURNTRANSFER, true);
199
  curl_setopt($curl_array[$i], CURLOPT_CONNECTTIMEOUT, 5);
200
- curl_setopt($curl_array[$i], CURLOPT_ENCODING, "UTF-8");
201
  curl_multi_add_handle($mh, $curl_array[$i]);
202
  }
203
 
@@ -209,7 +228,7 @@ class MetaSeoDashboard
209
 
210
  $contents = array();
211
  foreach ($urls as $i => $url) {
212
- $content = curl_multi_getcontent($curl_array[$i]);
213
  $contents[$i] = $content;
214
  }
215
 
@@ -221,136 +240,160 @@ class MetaSeoDashboard
221
  }
222
 
223
  /**
224
- * update option dashboard
225
- * @param $name
 
 
226
  * @return mixed
227
  */
228
  public static function updateDashboard($name)
229
  {
230
  $options_dashboard = get_option('options_dashboard');
231
- MetaSeoDashboard::updateOptionDash($options_dashboard, $name);
232
  $options_dashboard = get_option('options_dashboard');
233
- $results = $options_dashboard[$name];
234
  return $results;
235
  }
236
 
237
  /**
238
- * get Count posts
 
 
239
  */
240
  public static function getCountPost()
241
  {
242
  global $wpdb;
243
- $where = array();
244
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
245
- $post_type = "'" . implode("', '", esc_sql($post_types)) . "'";
246
- $where[] = "post_type IN ($post_type)";
247
- $states = get_post_stati(array('show_in_admin_all_list' => true));
248
- $all_states = "'" . implode("', '", $states) . "'";
249
- $where[] = "post_status IN ($all_states)";
250
- $query = "SELECT COUNT(ID) "
251
- . " FROM $wpdb->posts "
252
- . " WHERE " . implode(' AND ', $where);
253
 
254
- $total_posts = $wpdb->get_var($query);
 
 
 
 
 
255
  return $total_posts;
256
  }
257
 
258
  /**
259
- * get params meta title filled for dashboard
 
260
  * @return array
261
  */
262
  public static function metaTitle()
263
  {
264
- $total_posts = MetaSeoDashboard::getCountPost();
265
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
266
- if (!empty($post_types['attachment'])) {
267
- unset($post_types['attachment']);
268
- }
269
-
270
- $results = array(0, array(0, (int)$total_posts));
271
- $args = array(
272
- 'posts_per_page' => -1,
273
- 'post_type' => $post_types,
274
- 'meta_key' => '_metaseo_metatitle',
275
- 'meta_query' => array(
276
- array(
277
- 'key' => '_metaseo_metatitle',
278
- 'value' => '',
279
- 'compare' => '!=',
280
- ),
281
- ),
282
- );
283
- $query = new WP_Query($args);
284
- $posts = $query->get_posts();
 
 
 
 
 
285
  $metatitle_filled = 0;
286
- if (!empty($posts)) {
287
- foreach ($posts as $post) {
288
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
289
  if (empty($meta_analysis)) {
290
  $meta_analysis = array();
291
  }
292
 
293
  $meta_title = get_post_meta($post->ID, '_metaseo_metatitle', true);
294
- if (($meta_title != '' && mb_strlen($meta_title, 'UTF-8') <= self::$meta_title_length)
295
  || (!empty($meta_analysis) && !empty($meta_analysis['metatitle']))) {
296
- $metatitle_filled++;
297
  }
298
  }
299
 
300
- $results = array(ceil($metatitle_filled / $total_posts * 100), array($metatitle_filled, (int)$total_posts));
 
 
 
301
  }
302
 
303
  return $results;
304
  }
305
 
306
  /**
307
- * get html meta title filled for dashboard
 
 
308
  */
309
  public static function dashboardMetaTitle()
310
  {
311
- $results = MetaSeoDashboard::updateDashboard('metatitle');
312
  wp_send_json($results);
313
  }
314
 
315
  /**
316
- * get params meta description filled for dashboard
 
317
  * @return array
318
  */
319
  public static function metaDesc()
320
  {
321
- $total_posts = MetaSeoDashboard::getCountPost();
322
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
323
- if (!empty($post_types['attachment'])) {
324
- unset($post_types['attachment']);
325
- }
326
-
327
- $results = array(0, array(0, $total_posts));
328
- $args = array(
329
- 'posts_per_page' => -1,
330
- 'post_type' => $post_types,
331
- 'meta_key' => '_metaseo_metadesc',
332
- 'meta_query' => array(
333
- array(
334
- 'key' => '_metaseo_metadesc',
335
- 'value' => '',
336
- 'compare' => '!=',
337
- ),
338
- ),
339
- );
340
- $query = new WP_Query($args);
341
- $posts = $query->get_posts();
 
 
 
 
342
  $metadesc_filled = 0;
343
- if (!empty($posts)) {
344
- foreach ($posts as $post) {
345
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
346
  if (empty($meta_analysis)) {
347
  $meta_analysis = array();
348
  }
349
 
350
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
351
- if (($meta_desc != '' && mb_strlen($meta_desc, 'UTF-8') <= self::$meta_desc_length)
352
  || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
353
- $metadesc_filled++;
354
  }
355
  }
356
 
@@ -362,26 +405,29 @@ class MetaSeoDashboard
362
 
363
  /**
364
  * Return html description filled for dashboard
 
 
365
  */
366
  public static function dashboardMetaDesc()
367
  {
368
- $results = MetaSeoDashboard::updateDashboard('metadesc');
369
  wp_send_json($results);
370
  }
371
 
372
  /**
373
  * Return link_meta for dashboard
 
374
  * @return array
375
  */
376
  public static function linkMeta()
377
  {
378
  global $wpdb;
379
- $mlink_complete = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE meta_title !='' AND type ='url'");
380
- $mcount_link = $wpdb->get_var(
381
- "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE type ='url'"
382
  );
383
 
384
- if ($mcount_link == 0) {
385
  $link_percent = 100;
386
  } else {
387
  $link_percent = ceil($mlink_complete / $mcount_link * 100);
@@ -393,28 +439,31 @@ class MetaSeoDashboard
393
 
394
  /**
395
  * Return html link_meta for dashboard
 
 
396
  */
397
  public static function dashboardLinkMeta()
398
  {
399
- $results = MetaSeoDashboard::linkMeta();
400
  wp_send_json($results);
401
  }
402
 
403
  /**
404
  * Return permalink for dashboard
405
- * @return int
 
406
  */
407
  public static function permalink()
408
  {
409
- $permalink = 50;
410
  $permalink_structure = get_option('permalink_structure');
411
- if (strpos($permalink_structure, 'postname') == false && strpos($permalink_structure, 'category') == false) {
412
  $permalink = 0;
413
- } elseif (strpos($permalink_structure, 'postname') == true
414
- && strpos($permalink_structure, 'category') == true) {
415
  $permalink = 100;
416
- } elseif (strpos($permalink_structure, 'postname') == true
417
- || strpos($permalink_structure, 'category') == true) {
418
  $permalink = 50;
419
  }
420
  return $permalink;
@@ -422,29 +471,32 @@ class MetaSeoDashboard
422
 
423
  /**
424
  * Return html permalink for dashboard
 
 
425
  */
426
  public static function dashboardPermalink()
427
  {
428
- $permalink = MetaSeoDashboard::permalink();
429
  wp_send_json($permalink);
430
  }
431
 
432
  /**
433
  * Return count new content updated for dashboard
 
434
  * @return array
435
  */
436
  public static function newContent()
437
  {
438
- $total_posts = MetaSeoDashboard::getCountPost();
439
  $newcontent_args = array(
440
- 'date_query' => array(
441
  array(
442
  'column' => 'post_modified_gmt',
443
- 'after' => '30 days ago'
444
  )
445
  ),
446
- 'posts_per_page' => -1,
447
- 'post_type' => array('post', 'page'),
448
  );
449
 
450
  $newcontent = new WP_Query($newcontent_args);
@@ -460,33 +512,28 @@ class MetaSeoDashboard
460
 
461
  /**
462
  * Return html new content updated for dashboard
 
 
463
  */
464
  public static function dashboardNewContent()
465
  {
466
- $results = MetaSeoDashboard::updateDashboard('newcontent');
467
  wp_send_json($results);
468
  }
469
 
470
  /**
471
  * Return count link 404 , count link 404 is redirected , percent
 
472
  * @return array
473
  */
474
  public static function get404Link()
475
  {
476
  global $wpdb;
477
- $sql = $wpdb->prepare(
478
- "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE (broken_internal=%d OR broken_indexed=%d) ",
479
- array(1, 1)
480
- );
481
- $count_404 = $wpdb->get_var($sql);
482
 
483
- $sql = $wpdb->prepare(
484
- "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links
485
- WHERE link_url_redirect != '' AND (broken_internal=%d OR broken_indexed=%d) ",
486
- array(1, 1)
487
- );
488
- $count_404_redirected = $wpdb->get_var($sql);
489
- if ($count_404 != 0) {
490
  $percent = ceil($count_404_redirected / $count_404 * 100);
491
  } else {
492
  $percent = 100;
@@ -496,21 +543,20 @@ class MetaSeoDashboard
496
 
497
  /**
498
  * Return count image is optimized
499
- * @return int
 
500
  */
501
  public function getImagesOptimizer()
502
  {
503
  global $wpdb;
504
- $sql = $wpdb->prepare("SELECT * FROM INFORMATION_SCHEMA.TABLES
505
- WHERE table_name = %s AND TABLE_SCHEMA = %s", array($wpdb->prefix . 'wpio_images', $wpdb->dbname));
506
- $row = $wpdb->get_results($sql);
507
  if (!empty($row)) {
508
- $query = 'SELECT distinct file FROM ' . $wpdb->prefix . 'wpio_images';
509
- $files = $wpdb->get_results($query);
510
  $image_optimize = 0;
511
  foreach ($files as $file) {
512
  if (file_exists(str_replace('/', DIRECTORY_SEPARATOR, ABSPATH . $file->file))) {
513
- $image_optimize++;
514
  }
515
  }
516
  return $image_optimize;
@@ -521,23 +567,24 @@ class MetaSeoDashboard
521
 
522
  /**
523
  * Get count image
 
524
  * @return array
525
  */
526
  public function getImagesCount()
527
  {
528
  $image_optimize = $this->getImagesOptimizer();
529
- $allowed_ext = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf');
530
- $count_image = 0;
531
- $scan_dir = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH);
532
  foreach (new RecursiveIteratorIterator(new IgnorantRecursiveDirectoryIterator($scan_dir)) as $filename) {
533
  if (!in_array(strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $allowed_ext)) {
534
  continue;
535
  }
536
 
537
- $count_image++;
538
  }
539
 
540
- if ($count_image == 0) {
541
  $precent = 0;
542
  } else {
543
  $precent = ceil($image_optimize / $count_image * 100);
@@ -546,20 +593,26 @@ class MetaSeoDashboard
546
  }
547
 
548
  /**
549
- * update time dashboard update
550
- * @param $name
 
 
 
551
  */
552
  public static function dashLastUpdate($name)
553
  {
554
- if ($name == 'metadesc') {
555
  update_option('_wpms_dash_last_update', time());
556
  }
557
  }
558
 
559
  /**
560
- * update option dashboard
561
- * @param array $options_dashboard all criteria in dashboard
562
- * @param string $name option name
 
 
 
563
  */
564
  public static function updateOptionDash($options_dashboard, $name)
565
  {
@@ -571,47 +624,54 @@ class MetaSeoDashboard
571
  $results = array();
572
  switch ($name) {
573
  case 'metatitle':
574
- $results = MetaSeoDashboard::metaTitle();
575
  break;
576
  case 'metadesc':
577
- $results = MetaSeoDashboard::metaDesc();
578
  break;
579
  case 'newcontent':
580
- $results = MetaSeoDashboard::newContent();
581
  break;
582
  case 'image_meta':
583
- $results = MetaSeoDashboard::moptimizationChecking();
584
  break;
585
  }
586
  $options_dashboard[$name] = $results;
587
  update_option('options_dashboard', $options_dashboard);
588
- MetaSeoDashboard::dashLastUpdate($name);
589
  }
590
  }
591
 
592
  /**
593
- * get image metas
 
 
594
  */
595
  public static function dashImgsMeta()
596
  {
 
 
 
 
 
597
  global $wpdb;
598
- $imgs = 0;
599
- $imgs_are_good = 0;
600
  $imgs_metas_are_good = array();
601
- $meta_keys = array('alt');
602
  // create default value
603
  $response = array(
604
- 'imgs_statis' => array(0, 0, 100),
605
  'imgs_metas_statis' => array(0, 0, 100),
606
  );
607
 
608
- $options_dashboard = get_option('options_dashboard');
609
  $option_last_update_post = get_option('wpms_last_update_post');
610
  $option_last_dash_update = get_option('_wpms_dash_last_update');
611
  // get response from options_dashboard option
612
  if (!empty($options_dashboard) && is_array($options_dashboard)
613
  && !empty($options_dashboard['image_meta']) && $option_last_update_post < $option_last_dash_update) {
614
- $results = $options_dashboard['image_meta'];
615
  $results['status'] = true;
616
  wp_send_json($results);
617
  }
@@ -621,17 +681,23 @@ class MetaSeoDashboard
621
  $imgs_metas_are_good[$meta_key] = 0;
622
  }
623
 
624
- $limit = 50;
625
- $offset = ($_POST['page'] - 1) * $limit;
626
  $post_types = MetaSeoContentListTable::getPostTypes();
627
- $query = "SELECT `ID`,`post_content`
628
- FROM $wpdb->posts
629
- WHERE `post_type` IN ($post_types)
630
- AND `post_content` <> ''
631
- AND `post_content` LIKE '%<img%>%'
632
- ORDER BY ID LIMIT $limit OFFSET $offset";
633
-
634
- $posts = $wpdb->get_results($query);
 
 
 
 
 
 
635
  if (count($posts) > 0) {
636
  $doc = new DOMDocument();
637
  libxml_use_internal_errors(true);
@@ -657,13 +723,13 @@ class MetaSeoDashboard
657
  continue;
658
  }
659
 
660
- $width = $tag->getAttribute('width');
661
  $height = $tag->getAttribute('height');
662
- if (list($real_width, $real_height) = @getimagesize($img_path)) {
663
  $ratio_origin = $real_width / $real_height;
664
  //Check if img tag is missing with/height attribute value or not
665
  if (!$width && !$height) {
666
- $width = $real_width;
667
  $height = $real_height;
668
  } elseif ($width && !$height) {
669
  $height = $width * (1 / $ratio_origin);
@@ -673,28 +739,30 @@ class MetaSeoDashboard
673
 
674
  if (($real_width <= $width && $real_height <= $height)
675
  || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
676
- $imgs_are_good++;
677
  }
678
  foreach ($meta_keys as $meta_key) {
679
  if (trim($tag->getAttribute($meta_key))
680
  || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
681
- $imgs_metas_are_good[$meta_key]++;
682
  }
683
  }
684
- $imgs++;
685
  }
686
  }
687
  }
688
 
689
- $countImg = $imgs + (int)$_POST['imgs_count'];
690
  //Report analytic of images optimization
691
  $c_imgs_metas = $imgs_metas_are_good['alt'];
692
  // get results for image resize
693
- $response['imgs_statis'][0] = $imgs_are_good + (int)$_POST['imgs_statis'];
694
  // get results for image meta
695
- $response['imgs_metas_statis'][0] = $c_imgs_metas + (int)$_POST['imgs_metas_statis'];
696
- $response['imgs_statis'][1] = $response['imgs_metas_statis'][1] = $response['imgs_count'] = $countImg;
697
- $response['page'] = (int)$_POST['page'];
 
 
698
  } else {
699
  if (!empty($_POST['imgs_count'])) {
700
  $percent_iresizing = ceil($_POST['imgs_statis'] / $_POST['imgs_count'] * 100);
@@ -709,8 +777,8 @@ class MetaSeoDashboard
709
  }
710
 
711
  $response['imgs_metas_statis'][2] = $percent_imeta;
712
- $options_dashboard['image_meta'] = array(
713
- 'imgs_statis' => array($_POST['imgs_statis'], $_POST['imgs_count'], $percent_iresizing),
714
  'imgs_metas_statis' => array($_POST['imgs_metas_statis'], $_POST['imgs_count'], $percent_imeta)
715
  );
716
 
@@ -718,27 +786,26 @@ class MetaSeoDashboard
718
  if (!empty($options_dashboard) && is_array($options_dashboard)) {
719
  if (empty($options_dashboard['image_meta'])) {
720
  update_option('options_dashboard', $options_dashboard);
721
- MetaSeoDashboard::dashLastUpdate('image_meta');
722
  } else {
723
  $option_last_update_post = get_option('wpms_last_update_post');
724
  $option_last_dash_update = get_option('_wpms_dash_last_update');
725
  if ((!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update)
726
  || empty($option_last_update_post)) {
727
  update_option('options_dashboard', $options_dashboard);
728
- MetaSeoDashboard::dashLastUpdate('image_meta');
729
  }
730
  }
731
  } else {
732
  update_option('options_dashboard', $options_dashboard);
733
- MetaSeoDashboard::dashLastUpdate('image_meta');
734
  }
735
 
736
  $options_dashboard = get_option('options_dashboard');
737
- $results = $options_dashboard['image_meta'];
738
 
739
  $results['status'] = true;
740
  wp_send_json($results);
741
-
742
  }
743
 
744
  wp_send_json($response);
9
  class MetaSeoDashboard
10
  {
11
  /**
12
+ * Max length meta title
13
+ *
14
+ * @var integer
15
  */
16
  public static $meta_title_length = 69;
17
  /**
18
+ * Max length meta description
19
+ *
20
+ * @var integer
21
  */
22
  public static $meta_desc_length = 320;
23
+
24
  /**
25
  * Get image optimize
26
+ *
27
  * @return array
28
  */
29
  public static function moptimizationChecking()
30
  {
31
  global $wpdb;
32
+ $imgs = 0;
33
+ $imgs_are_good = 0;
34
  $imgs_metas_are_good = array();
35
+ $response = array(
36
+ 'imgs_statis' => array(0, 0, 100),
37
  'imgs_metas_statis' => array(0, 0, 100),
38
  );
39
 
40
+ $imgs_metas_are_good['alt'] = 0;
41
  $imgs_metas_are_not_good['alt'] = 0;
42
 
43
  $post_types = MetaSeoContentListTable::getPostTypes();
44
+ foreach ($post_types as &$post_type) {
45
+ $post_type = esc_sql($post_type);
46
+ }
47
+ $post_types = implode("', '", $post_types);
48
+ $where = array();
49
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
50
+ $where[] = 'post_content <> ""';
51
+ $where[] = 'post_content LIKE "%<img%>%"';
52
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
53
+ $posts = $wpdb->get_results('SELECT ID,post_content FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where) . ' ORDER BY ID');
54
  if (count($posts) > 0) {
55
  $doc = new DOMDocument();
56
  libxml_use_internal_errors(true);
76
  continue;
77
  }
78
 
79
+ $width = $tag->getAttribute('width');
80
  $height = $tag->getAttribute('height');
81
+ if (list($real_width, $real_height) = getimagesize($img_path)) {
82
  $ratio_origin = $real_width / $real_height;
83
  //Check if img tag is missing with/height attribute value or not
84
  if (!$width && !$height) {
85
+ $width = $real_width;
86
  $height = $real_height;
87
  } elseif ($width && !$height) {
88
  $height = $width * (1 / $ratio_origin);
92
 
93
  if (($real_width <= $width && $real_height <= $height)
94
  || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
95
+ $imgs_are_good ++;
96
  }
97
 
98
  if (trim($tag->getAttribute('alt'))
99
  || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
100
+ $imgs_metas_are_good['alt'] ++;
101
  }
102
  }
103
 
104
+ $imgs ++;
105
  }
106
  }
107
 
108
  //Report analytic of images optimization
109
+ $imgs_metas = $imgs_metas_are_good['alt'];
110
+ $response['imgs_statis'][0] = $imgs_are_good;
111
+ $response['imgs_statis'][1] = $imgs;
112
  $response['imgs_metas_statis'][0] = $imgs_metas;
113
  $response['imgs_metas_statis'][1] = $imgs;
114
 
131
 
132
  /**
133
  * Display rank of site
134
+ *
135
+ * @param string $url URL
136
+ *
137
+ * @return void
138
  */
139
  public function displayRank($url)
140
  {
141
  $rank = $this->getRank($url);
142
  if ($rank !== '') {
143
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method getRank
144
  echo $rank;
145
  } else {
146
+ esc_html_e('We can\'t get rank of this site from Alexa.com!', 'wp-meta-seo');
147
  }
148
  }
149
 
150
  /**
151
  * Get rank of site
152
+ *
153
+ * @param string $url URL
154
+ *
155
  * @return mixed|string
156
  */
157
  public function getRank($url)
158
  {
159
  if (!function_exists('curl_version')) {
160
+ $content = file_get_contents($url);
161
+ if (!$content) {
162
  return '';
163
  }
164
  } else {
166
  $url = array($url);
167
  }
168
  $contents = $this->getContents($url);
169
+ $content = $contents[0];
170
  }
171
 
172
  $doc = new DOMDocument();
173
  libxml_use_internal_errors(true);
174
+ if (empty($content)) {
175
+ return '';
176
+ }
177
+
178
+ $doc->loadHTML($content);
179
  $doc->preserveWhiteSpace = false;
180
 
181
+ $finder = new DOMXPath($doc);
182
  $classname = 'note-no-data';
183
+ $nodes = $finder->query('//section[contains(@class, "' . $classname . '")]');
184
  if ($nodes->length < 1) {
185
  $classname = 'rank-row';
186
+ $nodes = $finder->query('//div[contains(@class, "' . $classname . '")]');
187
  }
188
 
189
  $tmp_dom = new DOMDocument();
192
  }
193
 
194
  $html = trim($tmp_dom->saveHTML());
195
+ $html = str_replace('We don\'t have', esc_html__('Alexa doesn\'t have', 'wp-meta-seo'), $html);
196
  $html = str_replace('Get Certified', '', $html);
197
  $html = str_replace('"/topsites/countries', '"http://www.alexa.com/topsites/countries', $html);
198
  return $html;
200
 
201
  /**
202
  * Get content a file
203
+ *
204
+ * @param array $urls URL infos
205
+ *
206
  * @return array
207
  */
208
  public function getContents($urls)
209
  {
210
+ $mh = curl_multi_init();
211
  $curl_array = array();
212
+ $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36';
213
  foreach ($urls as $i => $url) {
214
  $curl_array[$i] = curl_init($url);
215
  curl_setopt($curl_array[$i], CURLOPT_URL, $url);
216
  curl_setopt($curl_array[$i], CURLOPT_USERAGENT, $useragent); // set user agent
217
  curl_setopt($curl_array[$i], CURLOPT_RETURNTRANSFER, true);
218
  curl_setopt($curl_array[$i], CURLOPT_CONNECTTIMEOUT, 5);
219
+ curl_setopt($curl_array[$i], CURLOPT_ENCODING, 'UTF-8');
220
  curl_multi_add_handle($mh, $curl_array[$i]);
221
  }
222
 
228
 
229
  $contents = array();
230
  foreach ($urls as $i => $url) {
231
+ $content = curl_multi_getcontent($curl_array[$i]);
232
  $contents[$i] = $content;
233
  }
234
 
240
  }
241
 
242
  /**
243
+ * Update option dashboard
244
+ *
245
+ * @param string $name Option name
246
+ *
247
  * @return mixed
248
  */
249
  public static function updateDashboard($name)
250
  {
251
  $options_dashboard = get_option('options_dashboard');
252
+ self::updateOptionDash($options_dashboard, $name);
253
  $options_dashboard = get_option('options_dashboard');
254
+ $results = $options_dashboard[$name];
255
  return $results;
256
  }
257
 
258
  /**
259
+ * Get Count posts
260
+ *
261
+ * @return null|string
262
  */
263
  public static function getCountPost()
264
  {
265
  global $wpdb;
266
+ $post_types = MetaSeoContentListTable::getPostTypes();
267
+ foreach ($post_types as &$post_type) {
268
+ $post_type = esc_sql($post_type);
269
+ }
270
+ $post_types = implode("', '", $post_types);
271
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
272
+ foreach ($states as &$state) {
273
+ $state = esc_sql($state);
274
+ }
 
275
 
276
+ $all_states = implode("', '", $states);
277
+ $where = array();
278
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
279
+ $where[] = 'post_status IN (\'' . $all_states . '\')';
280
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
281
+ $total_posts = $wpdb->get_var('SELECT COUNT(ID) FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where));
282
  return $total_posts;
283
  }
284
 
285
  /**
286
+ * Get params meta title filled for dashboard
287
+ *
288
  * @return array
289
  */
290
  public static function metaTitle()
291
  {
292
+ global $wpdb;
293
+ $total_posts = self::getCountPost();
294
+ $results = array(0, array(0, (int) $total_posts));
295
+
296
+ $post_types = MetaSeoContentListTable::getPostTypes('attachment');
297
+ foreach ($post_types as &$post_type) {
298
+ $post_type = esc_sql($post_type);
299
+ }
300
+ $post_types = implode("', '", $post_types);
301
+
302
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
303
+ foreach ($states as &$state) {
304
+ $state = esc_sql($state);
305
+ }
306
+
307
+ $all_states = implode("', '", $states);
308
+ $where = array();
309
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
310
+ $where[] = 'post_status IN (\'' . $all_states . '\')';
311
+ $query = 'SELECT DISTINCT ID '
312
+ . ' FROM ' . $wpdb->posts . ' as p'
313
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metatitle" AND meta_value != "") mt ON mt.post_id = p.ID ';
314
+ $query .= ' WHERE ' . implode(' AND ', $where);
315
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
316
+ $ps = $wpdb->get_results($query);
317
+
318
  $metatitle_filled = 0;
319
+ if (!empty($ps)) {
320
+ foreach ($ps as $post) {
321
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
322
  if (empty($meta_analysis)) {
323
  $meta_analysis = array();
324
  }
325
 
326
  $meta_title = get_post_meta($post->ID, '_metaseo_metatitle', true);
327
+ if (($meta_title !== '')
328
  || (!empty($meta_analysis) && !empty($meta_analysis['metatitle']))) {
329
+ $metatitle_filled ++;
330
  }
331
  }
332
 
333
+ $results = array(
334
+ ceil($metatitle_filled / $total_posts * 100),
335
+ array($metatitle_filled, (int) $total_posts)
336
+ );
337
  }
338
 
339
  return $results;
340
  }
341
 
342
  /**
343
+ * Get html meta title filled for dashboard
344
+ *
345
+ * @return void
346
  */
347
  public static function dashboardMetaTitle()
348
  {
349
+ $results = self::updateDashboard('metatitle');
350
  wp_send_json($results);
351
  }
352
 
353
  /**
354
+ * Get params meta description filled for dashboard
355
+ *
356
  * @return array
357
  */
358
  public static function metaDesc()
359
  {
360
+ global $wpdb;
361
+ $total_posts = self::getCountPost();
362
+ $results = array(0, array(0, $total_posts));
363
+
364
+ $post_types = MetaSeoContentListTable::getPostTypes('attachment');
365
+ foreach ($post_types as &$post_type) {
366
+ $post_type = esc_sql($post_type);
367
+ }
368
+ $post_types = implode("', '", $post_types);
369
+
370
+ $states = get_post_stati(array('show_in_admin_all_list' => true));
371
+ foreach ($states as &$state) {
372
+ $state = esc_sql($state);
373
+ }
374
+ $all_states = implode("', '", $states);
375
+
376
+ $where = array();
377
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
378
+ $where[] = 'post_status IN (\'' . $all_states . '\')';
379
+ $query = 'SELECT DISTINCT ID '
380
+ . ' FROM ' . $wpdb->posts . ' as p'
381
+ . ' LEFT JOIN (SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_metaseo_metadesc" AND meta_value != "") mt ON mt.post_id = p.ID ';
382
+ $query .= ' WHERE ' . implode(' AND ', $where);
383
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
384
+ $wpms_posts = $wpdb->get_results($query);
385
  $metadesc_filled = 0;
386
+ if (!empty($wpms_posts)) {
387
+ foreach ($wpms_posts as $post) {
388
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
389
  if (empty($meta_analysis)) {
390
  $meta_analysis = array();
391
  }
392
 
393
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
394
+ if (($meta_desc !== '')
395
  || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
396
+ $metadesc_filled ++;
397
  }
398
  }
399
 
405
 
406
  /**
407
  * Return html description filled for dashboard
408
+ *
409
+ * @return void
410
  */
411
  public static function dashboardMetaDesc()
412
  {
413
+ $results = self::updateDashboard('metadesc');
414
  wp_send_json($results);
415
  }
416
 
417
  /**
418
  * Return link_meta for dashboard
419
+ *
420
  * @return array
421
  */
422
  public static function linkMeta()
423
  {
424
  global $wpdb;
425
+ $mlink_complete = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'wpms_links WHERE meta_title !="" AND type ="url"');
426
+ $mcount_link = $wpdb->get_var(
427
+ 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'wpms_links WHERE type ="url"'
428
  );
429
 
430
+ if ((int) $mcount_link === 0) {
431
  $link_percent = 100;
432
  } else {
433
  $link_percent = ceil($mlink_complete / $mcount_link * 100);
439
 
440
  /**
441
  * Return html link_meta for dashboard
442
+ *
443
+ * @return void
444
  */
445
  public static function dashboardLinkMeta()
446
  {
447
+ $results = self::linkMeta();
448
  wp_send_json($results);
449
  }
450
 
451
  /**
452
  * Return permalink for dashboard
453
+ *
454
+ * @return integer
455
  */
456
  public static function permalink()
457
  {
458
+ $permalink = 50;
459
  $permalink_structure = get_option('permalink_structure');
460
+ if (!strpos($permalink_structure, 'postname') && !strpos($permalink_structure, 'category')) {
461
  $permalink = 0;
462
+ } elseif (strpos($permalink_structure, 'postname')
463
+ && strpos($permalink_structure, 'category')) {
464
  $permalink = 100;
465
+ } elseif (strpos($permalink_structure, 'postname')
466
+ || strpos($permalink_structure, 'category')) {
467
  $permalink = 50;
468
  }
469
  return $permalink;
471
 
472
  /**
473
  * Return html permalink for dashboard
474
+ *
475
+ * @return void
476
  */
477
  public static function dashboardPermalink()
478
  {
479
+ $permalink = self::permalink();
480
  wp_send_json($permalink);
481
  }
482
 
483
  /**
484
  * Return count new content updated for dashboard
485
+ *
486
  * @return array
487
  */
488
  public static function newContent()
489
  {
490
+ $total_posts = self::getCountPost();
491
  $newcontent_args = array(
492
+ 'date_query' => array(
493
  array(
494
  'column' => 'post_modified_gmt',
495
+ 'after' => '30 days ago'
496
  )
497
  ),
498
+ 'posts_per_page' => - 1,
499
+ 'post_type' => array('post', 'page'),
500
  );
501
 
502
  $newcontent = new WP_Query($newcontent_args);
512
 
513
  /**
514
  * Return html new content updated for dashboard
515
+ *
516
+ * @return void
517
  */
518
  public static function dashboardNewContent()
519
  {
520
+ $results = self::updateDashboard('newcontent');
521
  wp_send_json($results);
522
  }
523
 
524
  /**
525
  * Return count link 404 , count link 404 is redirected , percent
526
+ *
527
  * @return array
528
  */
529
  public static function get404Link()
530
  {
531
  global $wpdb;
532
+ $count_404 = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'wpms_links WHERE (broken_internal = 1 OR broken_indexed = 1)');
 
 
 
 
533
 
534
+ $count_404_redirected = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'wpms_links
535
+ WHERE link_url_redirect != "" AND (broken_internal = 1 OR broken_indexed = 1)');
536
+ if ((int) $count_404 !== 0) {
 
 
 
 
537
  $percent = ceil($count_404_redirected / $count_404 * 100);
538
  } else {
539
  $percent = 100;
543
 
544
  /**
545
  * Return count image is optimized
546
+ *
547
+ * @return integer
548
  */
549
  public function getImagesOptimizer()
550
  {
551
  global $wpdb;
552
+ $row = $wpdb->get_results($wpdb->prepare('SELECT * FROM INFORMATION_SCHEMA.TABLES
553
+ WHERE table_name = %s AND TABLE_SCHEMA = %s', array($wpdb->prefix . 'wpio_images', $wpdb->dbname)));
 
554
  if (!empty($row)) {
555
+ $files = $wpdb->get_results('SELECT distinct file FROM ' . $wpdb->prefix . 'wpio_images');
 
556
  $image_optimize = 0;
557
  foreach ($files as $file) {
558
  if (file_exists(str_replace('/', DIRECTORY_SEPARATOR, ABSPATH . $file->file))) {
559
+ $image_optimize ++;
560
  }
561
  }
562
  return $image_optimize;
567
 
568
  /**
569
  * Get count image
570
+ *
571
  * @return array
572
  */
573
  public function getImagesCount()
574
  {
575
  $image_optimize = $this->getImagesOptimizer();
576
+ $allowed_ext = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf');
577
+ $count_image = 0;
578
+ $scan_dir = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH);
579
  foreach (new RecursiveIteratorIterator(new IgnorantRecursiveDirectoryIterator($scan_dir)) as $filename) {
580
  if (!in_array(strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $allowed_ext)) {
581
  continue;
582
  }
583
 
584
+ $count_image ++;
585
  }
586
 
587
+ if ((int) $count_image === 0) {
588
  $precent = 0;
589
  } else {
590
  $precent = ceil($image_optimize / $count_image * 100);
593
  }
594
 
595
  /**
596
+ * Update time dashboard update
597
+ *
598
+ * @param string $name Option name
599
+ *
600
+ * @return void
601
  */
602
  public static function dashLastUpdate($name)
603
  {
604
+ if ($name === 'metadesc') {
605
  update_option('_wpms_dash_last_update', time());
606
  }
607
  }
608
 
609
  /**
610
+ * Update option dashboard
611
+ *
612
+ * @param array $options_dashboard All criteria in dashboard
613
+ * @param string $name Option name
614
+ *
615
+ * @return void
616
  */
617
  public static function updateOptionDash($options_dashboard, $name)
618
  {
624
  $results = array();
625
  switch ($name) {
626
  case 'metatitle':
627
+ $results = self::metaTitle();
628
  break;
629
  case 'metadesc':
630
+ $results = self::metaDesc();
631
  break;
632
  case 'newcontent':
633
+ $results = self::newContent();
634
  break;
635
  case 'image_meta':
636
+ $results = self::moptimizationChecking();
637
  break;
638
  }
639
  $options_dashboard[$name] = $results;
640
  update_option('options_dashboard', $options_dashboard);
641
+ self::dashLastUpdate($name);
642
  }
643
  }
644
 
645
  /**
646
+ * Get image metas
647
+ *
648
+ * @return void
649
  */
650
  public static function dashImgsMeta()
651
  {
652
+ if (empty($_POST['wpms_nonce'])
653
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
654
+ die();
655
+ }
656
+
657
  global $wpdb;
658
+ $imgs = 0;
659
+ $imgs_are_good = 0;
660
  $imgs_metas_are_good = array();
661
+ $meta_keys = array('alt');
662
  // create default value
663
  $response = array(
664
+ 'imgs_statis' => array(0, 0, 100),
665
  'imgs_metas_statis' => array(0, 0, 100),
666
  );
667
 
668
+ $options_dashboard = get_option('options_dashboard');
669
  $option_last_update_post = get_option('wpms_last_update_post');
670
  $option_last_dash_update = get_option('_wpms_dash_last_update');
671
  // get response from options_dashboard option
672
  if (!empty($options_dashboard) && is_array($options_dashboard)
673
  && !empty($options_dashboard['image_meta']) && $option_last_update_post < $option_last_dash_update) {
674
+ $results = $options_dashboard['image_meta'];
675
  $results['status'] = true;
676
  wp_send_json($results);
677
  }
681
  $imgs_metas_are_good[$meta_key] = 0;
682
  }
683
 
684
+ $limit = 50;
685
+ $offset = ($_POST['page'] - 1) * $limit;
686
  $post_types = MetaSeoContentListTable::getPostTypes();
687
+ foreach ($post_types as &$post_type) {
688
+ $post_type = esc_sql($post_type);
689
+ }
690
+ $post_types = implode("', '", $post_types);
691
+ $where = array();
692
+ $where[] = 'post_type IN (\'' . $post_types . '\')';
693
+ $where[] = 'post_content <> "" AND post_content LIKE "%<img%>%"';
694
+
695
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
696
+ $posts = $wpdb->get_results($wpdb->prepare('SELECT ID,post_content FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where) . ' ORDER BY ID LIMIT %d OFFSET %d', array(
697
+ $limit,
698
+ $offset
699
+ )));
700
+
701
  if (count($posts) > 0) {
702
  $doc = new DOMDocument();
703
  libxml_use_internal_errors(true);
723
  continue;
724
  }
725
 
726
+ $width = $tag->getAttribute('width');
727
  $height = $tag->getAttribute('height');
728
+ if (list($real_width, $real_height) = getimagesize($img_path)) {
729
  $ratio_origin = $real_width / $real_height;
730
  //Check if img tag is missing with/height attribute value or not
731
  if (!$width && !$height) {
732
+ $width = $real_width;
733
  $height = $real_height;
734
  } elseif ($width && !$height) {
735
  $height = $width * (1 / $ratio_origin);
739
 
740
  if (($real_width <= $width && $real_height <= $height)
741
  || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
742
+ $imgs_are_good ++;
743
  }
744
  foreach ($meta_keys as $meta_key) {
745
  if (trim($tag->getAttribute($meta_key))
746
  || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
747
+ $imgs_metas_are_good[$meta_key] ++;
748
  }
749
  }
750
+ $imgs ++;
751
  }
752
  }
753
  }
754
 
755
+ $countImg = $imgs + (int) $_POST['imgs_count'];
756
  //Report analytic of images optimization
757
  $c_imgs_metas = $imgs_metas_are_good['alt'];
758
  // get results for image resize
759
+ $response['imgs_statis'][0] = $imgs_are_good + (int) $_POST['imgs_statis'];
760
  // get results for image meta
761
+ $response['imgs_metas_statis'][0] = $c_imgs_metas + (int) $_POST['imgs_metas_statis'];
762
+ $response['imgs_statis'][1] = $countImg;
763
+ $response['imgs_metas_statis'][1] = $countImg;
764
+ $response['imgs_count'] = $countImg;
765
+ $response['page'] = (int) $_POST['page'];
766
  } else {
767
  if (!empty($_POST['imgs_count'])) {
768
  $percent_iresizing = ceil($_POST['imgs_statis'] / $_POST['imgs_count'] * 100);
777
  }
778
 
779
  $response['imgs_metas_statis'][2] = $percent_imeta;
780
+ $options_dashboard['image_meta'] = array(
781
+ 'imgs_statis' => array($_POST['imgs_statis'], $_POST['imgs_count'], $percent_iresizing),
782
  'imgs_metas_statis' => array($_POST['imgs_metas_statis'], $_POST['imgs_count'], $percent_imeta)
783
  );
784
 
786
  if (!empty($options_dashboard) && is_array($options_dashboard)) {
787
  if (empty($options_dashboard['image_meta'])) {
788
  update_option('options_dashboard', $options_dashboard);
789
+ self::dashLastUpdate('image_meta');
790
  } else {
791
  $option_last_update_post = get_option('wpms_last_update_post');
792
  $option_last_dash_update = get_option('_wpms_dash_last_update');
793
  if ((!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update)
794
  || empty($option_last_update_post)) {
795
  update_option('options_dashboard', $options_dashboard);
796
+ self::dashLastUpdate('image_meta');
797
  }
798
  }
799
  } else {
800
  update_option('options_dashboard', $options_dashboard);
801
+ self::dashLastUpdate('image_meta');
802
  }
803
 
804
  $options_dashboard = get_option('options_dashboard');
805
+ $results = $options_dashboard['image_meta'];
806
 
807
  $results['status'] = true;
808
  wp_send_json($results);
 
809
  }
810
 
811
  wp_send_json($response);
inc/class.metaseo-front_end.php CHANGED
@@ -11,10 +11,14 @@ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
11
  class MetaSeoFront
12
  {
13
  /**
 
 
14
  * @var array
15
  */
16
  public $ga_tracking;
17
  /**
 
 
18
  * @var array
19
  */
20
  public $gaDisconnect;
@@ -25,30 +29,30 @@ class MetaSeoFront
25
  public function __construct()
26
  {
27
  $this->ga_tracking = array(
28
- 'wpmsga_dash_tracking' => 1,
29
- 'wpmsga_dash_tracking_type' => 'universal',
30
- 'wpmsga_dash_anonim' => 0,
31
- 'wpmsga_dash_remarketing' => 0,
32
- 'wpmsga_event_tracking' => 0,
33
- 'wpmsga_event_downloads' => 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*',
34
- 'wpmsga_aff_tracking' => 0,
35
- 'wpmsga_event_affiliates' => '/out/',
36
- 'wpmsga_hash_tracking' => 0,
37
- 'wpmsga_author_dimindex' => 0,
38
- 'wpmsga_pubyear_dimindex' => 0,
39
- 'wpmsga_category_dimindex' => 0,
40
- 'wpmsga_user_dimindex' => 0,
41
- 'wpmsga_tag_dimindex' => 0,
42
- 'wpmsga_speed_samplerate' => 1,
43
- 'wpmsga_event_bouncerate' => 0,
44
- 'wpmsga_enhanced_links' => 0,
45
- 'wpmsga_dash_adsense' => 0,
46
  'wpmsga_crossdomain_tracking' => 0,
47
- 'wpmsga_crossdomain_list' => '',
48
- 'wpmsga_cookiedomain' => '',
49
- 'wpmsga_cookiename' => '',
50
- 'wpmsga_cookieexpires' => '',
51
- 'wpmsga_track_exclude' => array(),
52
  );
53
 
54
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
@@ -57,11 +61,11 @@ class MetaSeoFront
57
  }
58
 
59
  $this->gaDisconnect = array(
60
- 'wpms_ga_uax_reference' => '',
61
  'wpmsga_dash_tracking_type' => 'universal',
62
- 'wpmsga_code_tracking' => ''
63
  );
64
- $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
65
  if (is_array($gaDisconnect)) {
66
  $this->gaDisconnect = array_merge($this->gaDisconnect, $gaDisconnect);
67
  }
@@ -71,35 +75,32 @@ class MetaSeoFront
71
 
72
  /**
73
  * Create tracking code on front-end
74
- * @return bool
 
75
  */
76
  public function trackingCode()
77
  {
78
- if (!empty($this->ga_tracking['wpmsga_code_tracking'])) {
79
- require_once 'google_analytics/tracking/custom.php';
80
- return false;
81
- }
82
-
83
  if (WpmsGaTools::checkRoles($this->ga_tracking['wpmsga_track_exclude'], true)) {
84
  return false;
85
  }
86
 
87
  $google_alanytics = get_option('wpms_google_alanytics');
88
- $traking_mode = $this->ga_tracking['wpmsga_dash_tracking'];
89
  if ($traking_mode > 0) {
90
  if (empty($google_alanytics['tableid_jail'])) {
91
  $tracking_code = trim($this->gaDisconnect['wpmsga_code_tracking']);
92
  if (!empty($tracking_code)) {
93
  echo '<script type="text/javascript">';
94
- echo strip_tags(stripslashes($this->gaDisconnect['wpmsga_code_tracking']), '</script>');
 
95
  echo '</script>';
96
  } else {
97
  if (empty($this->gaDisconnect['wpms_ga_uax_reference'])) {
98
  return false;
99
  }
100
  $traking_type = $this->gaDisconnect['wpmsga_dash_tracking_type'];
101
- if ($traking_type == "classic") {
102
- echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Classic Tracking
103
  - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
104
  require_once 'google_analytics/tracking/classic_disconnect.php';
105
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
@@ -111,7 +112,7 @@ class MetaSeoFront
111
  }
112
  } else {
113
  $traking_type = $this->ga_tracking['wpmsga_dash_tracking_type'];
114
- if ($traking_type == "classic") {
115
  echo "\n<!-- Classic Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
116
  if ($this->ga_tracking['wpmsga_event_tracking']) {
117
  require_once 'google_analytics/tracking/events-classic.php';
11
  class MetaSeoFront
12
  {
13
  /**
14
+ * Google analytics tracking params
15
+ *
16
  * @var array
17
  */
18
  public $ga_tracking;
19
  /**
20
+ * Google analytics disconnect
21
+ *
22
  * @var array
23
  */
24
  public $gaDisconnect;
29
  public function __construct()
30
  {
31
  $this->ga_tracking = array(
32
+ 'wpmsga_dash_tracking' => 1,
33
+ 'wpmsga_dash_tracking_type' => 'universal',
34
+ 'wpmsga_dash_anonim' => 0,
35
+ 'wpmsga_dash_remarketing' => 0,
36
+ 'wpmsga_event_tracking' => 0,
37
+ 'wpmsga_event_downloads' => 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*',
38
+ 'wpmsga_aff_tracking' => 0,
39
+ 'wpmsga_event_affiliates' => '/out/',
40
+ 'wpmsga_hash_tracking' => 0,
41
+ 'wpmsga_author_dimindex' => 0,
42
+ 'wpmsga_pubyear_dimindex' => 0,
43
+ 'wpmsga_category_dimindex' => 0,
44
+ 'wpmsga_user_dimindex' => 0,
45
+ 'wpmsga_tag_dimindex' => 0,
46
+ 'wpmsga_speed_samplerate' => 1,
47
+ 'wpmsga_event_bouncerate' => 0,
48
+ 'wpmsga_enhanced_links' => 0,
49
+ 'wpmsga_dash_adsense' => 0,
50
  'wpmsga_crossdomain_tracking' => 0,
51
+ 'wpmsga_crossdomain_list' => '',
52
+ 'wpmsga_cookiedomain' => '',
53
+ 'wpmsga_cookiename' => '',
54
+ 'wpmsga_cookieexpires' => '',
55
+ 'wpmsga_track_exclude' => array(),
56
  );
57
 
58
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
61
  }
62
 
63
  $this->gaDisconnect = array(
64
+ 'wpms_ga_uax_reference' => '',
65
  'wpmsga_dash_tracking_type' => 'universal',
66
+ 'wpmsga_code_tracking' => ''
67
  );
68
+ $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
69
  if (is_array($gaDisconnect)) {
70
  $this->gaDisconnect = array_merge($this->gaDisconnect, $gaDisconnect);
71
  }
75
 
76
  /**
77
  * Create tracking code on front-end
78
+ *
79
+ * @return boolean
80
  */
81
  public function trackingCode()
82
  {
 
 
 
 
 
83
  if (WpmsGaTools::checkRoles($this->ga_tracking['wpmsga_track_exclude'], true)) {
84
  return false;
85
  }
86
 
87
  $google_alanytics = get_option('wpms_google_alanytics');
88
+ $traking_mode = $this->ga_tracking['wpmsga_dash_tracking'];
89
  if ($traking_mode > 0) {
90
  if (empty($google_alanytics['tableid_jail'])) {
91
  $tracking_code = trim($this->gaDisconnect['wpmsga_code_tracking']);
92
  if (!empty($tracking_code)) {
93
  echo '<script type="text/javascript">';
94
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content has saved by user when save Analytics JS code
95
+ echo strip_tags(stripslashes($this->gaDisconnect['wpmsga_code_tracking']));
96
  echo '</script>';
97
  } else {
98
  if (empty($this->gaDisconnect['wpms_ga_uax_reference'])) {
99
  return false;
100
  }
101
  $traking_type = $this->gaDisconnect['wpmsga_dash_tracking_type'];
102
+ if ($traking_type === 'classic') {
103
+ echo "\n<!-- BEGIN WPMSGA v" . esc_html(WPMSEO_VERSION) . " Classic Tracking
104
  - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
105
  require_once 'google_analytics/tracking/classic_disconnect.php';
106
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
112
  }
113
  } else {
114
  $traking_type = $this->ga_tracking['wpmsga_dash_tracking_type'];
115
+ if ($traking_type === 'classic') {
116
  echo "\n<!-- Classic Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
117
  if ($this->ga_tracking['wpmsga_event_tracking']) {
118
  require_once 'google_analytics/tracking/events-classic.php';
inc/class.metaseo-google-analytics.php CHANGED
@@ -9,7 +9,9 @@ defined('ABSPATH') || die('No direct script access allowed!');
9
  class MetaSeoGoogleAnalytics
10
  {
11
  /**
12
- * ajax display google analytics
 
 
13
  */
14
  public static function itemsReport()
15
  {
@@ -19,7 +21,7 @@ class MetaSeoGoogleAnalytics
19
 
20
  if (!isset($_POST['wpms_security_backend_item_reports'])
21
  || !wp_verify_nonce($_POST['wpms_security_backend_item_reports'], 'wpms_backend_item_reports')) {
22
- wp_die(-30);
23
  }
24
 
25
  if (isset($_POST['projectId']) && $_POST['projectId'] !== 'false') {
@@ -27,8 +29,8 @@ class MetaSeoGoogleAnalytics
27
  } else {
28
  $projectId = false;
29
  }
30
- $from = $_POST['from'];
31
- $to = $_POST['to'];
32
  $query = $_POST['query'];
33
  if (isset($_POST['filter'])) {
34
  $filter_id = $_POST['filter'];
@@ -44,7 +46,7 @@ class MetaSeoGoogleAnalytics
44
  $controller = new WpmsGapiController();
45
  }
46
  } else {
47
- wp_die(-99);
48
  }
49
 
50
  if (!empty($google_alanytics['googleCredentials']) && !empty($google_alanytics['tableid_jail'])
@@ -53,17 +55,17 @@ class MetaSeoGoogleAnalytics
53
  $controller = new WpmsGapiController();
54
  }
55
  } else {
56
- wp_die(-24);
57
  }
58
 
59
- if ($projectId == false) {
60
  $projectId = $google_alanytics['tableid_jail'];
61
  }
62
  $profile_info = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $projectId);
63
  if (isset($profile_info[4])) {
64
  $controller->timeshift = $profile_info[4];
65
  } else {
66
- $controller->timeshift = (int)current_time('timestamp') - time();
67
  }
68
 
69
  $filter = false;
@@ -73,17 +75,17 @@ class MetaSeoGoogleAnalytics
73
  if (isset($uri_parts[3])) {
74
  $uri = '/' . $uri_parts[3];
75
  // allow URL correction before sending an API request
76
- $filter = apply_filters('wpmsga_backenditem_uri', $uri);
77
- $lastchar = substr($filter, -1);
78
 
79
- if (isset($profile_info[6]) && $profile_info[6] && $lastchar == '/') {
80
  $filter = $filter . $profile_info[6];
81
  }
82
 
83
  // Encode URL
84
  $filter = rawurlencode(rawurldecode($filter));
85
  } else {
86
- wp_die(-25);
87
  }
88
  }
89
 
@@ -98,9 +100,16 @@ class MetaSeoGoogleAnalytics
98
 
99
  /**
100
  * Update analytics option
 
 
101
  */
102
  public static function updateOption()
103
  {
 
 
 
 
 
104
  $options = get_option('wpms_google_alanytics');
105
  if (isset($_POST['userapi'])) {
106
  $options['wpmsga_dash_userapi'] = $_POST['userapi'];
@@ -110,7 +119,9 @@ class MetaSeoGoogleAnalytics
110
  }
111
 
112
  /**
113
- * ajax clear author
 
 
114
  */
115
  public static function clearAuthor()
116
  {
@@ -119,7 +130,10 @@ class MetaSeoGoogleAnalytics
119
  }
120
 
121
  /**
122
- * @param $map
 
 
 
123
  * @return mixed|string
124
  */
125
  public static function map($map)
9
  class MetaSeoGoogleAnalytics
10
  {
11
  /**
12
+ * Ajax display google analytics
13
+ *
14
+ * @return void
15
  */
16
  public static function itemsReport()
17
  {
21
 
22
  if (!isset($_POST['wpms_security_backend_item_reports'])
23
  || !wp_verify_nonce($_POST['wpms_security_backend_item_reports'], 'wpms_backend_item_reports')) {
24
+ wp_die(- 30);
25
  }
26
 
27
  if (isset($_POST['projectId']) && $_POST['projectId'] !== 'false') {
29
  } else {
30
  $projectId = false;
31
  }
32
+ $from = $_POST['from'];
33
+ $to = $_POST['to'];
34
  $query = $_POST['query'];
35
  if (isset($_POST['filter'])) {
36
  $filter_id = $_POST['filter'];
46
  $controller = new WpmsGapiController();
47
  }
48
  } else {
49
+ wp_die(- 99);
50
  }
51
 
52
  if (!empty($google_alanytics['googleCredentials']) && !empty($google_alanytics['tableid_jail'])
55
  $controller = new WpmsGapiController();
56
  }
57
  } else {
58
+ wp_die(- 24);
59
  }
60
 
61
+ if (!$projectId) {
62
  $projectId = $google_alanytics['tableid_jail'];
63
  }
64
  $profile_info = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $projectId);
65
  if (isset($profile_info[4])) {
66
  $controller->timeshift = $profile_info[4];
67
  } else {
68
+ $controller->timeshift = (int) current_time('timestamp') - time();
69
  }
70
 
71
  $filter = false;
75
  if (isset($uri_parts[3])) {
76
  $uri = '/' . $uri_parts[3];
77
  // allow URL correction before sending an API request
78
+ $filter = apply_filters('wpmsga_backenditem_uri', $uri);
79
+ $lastchar = substr($filter, - 1);
80
 
81
+ if (isset($profile_info[6]) && $profile_info[6] && $lastchar === '/') {
82
  $filter = $filter . $profile_info[6];
83
  }
84
 
85
  // Encode URL
86
  $filter = rawurlencode(rawurldecode($filter));
87
  } else {
88
+ wp_die(- 25);
89
  }
90
  }
91
 
100
 
101
  /**
102
  * Update analytics option
103
+ *
104
+ * @return void
105
  */
106
  public static function updateOption()
107
  {
108
+ if (empty($_POST['wpms_nonce'])
109
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
110
+ die();
111
+ }
112
+
113
  $options = get_option('wpms_google_alanytics');
114
  if (isset($_POST['userapi'])) {
115
  $options['wpmsga_dash_userapi'] = $_POST['userapi'];
119
  }
120
 
121
  /**
122
+ * Ajax clear author
123
+ *
124
+ * @return void
125
  */
126
  public static function clearAuthor()
127
  {
130
  }
131
 
132
  /**
133
+ * Get map
134
+ *
135
+ * @param string $map Map
136
+ *
137
  * @return mixed|string
138
  */
139
  public static function map($map)
inc/class.metaseo-image-list-table.php CHANGED
@@ -16,7 +16,9 @@ if (!class_exists('ImageHelper')) {
16
  class MetaSeoImageListTable extends WP_List_Table
17
  {
18
  /**
19
- * @var
 
 
20
  */
21
  public $months;
22
 
@@ -27,21 +29,24 @@ class MetaSeoImageListTable extends WP_List_Table
27
  {
28
  parent::__construct(array(
29
  'singular' => 'metaseo_image',
30
- 'plural' => 'metaseo_images',
31
- 'ajax' => true
32
  ));
33
  }
34
 
35
  /**
36
  * Generate the table navigation above or below the table
37
- * @param string $which
 
 
 
38
  */
39
- protected function display_tablenav($which)
40
  {
41
  ?>
42
- <div class="tablenav <?php echo esc_attr($which); ?>">
43
 
44
- <?php if ($which == 'top') : ?>
45
  <input type="hidden" name="page" value="metaseo_image_meta"/>
46
  <div class="alignleft actions bulkactions">
47
  <?php
@@ -50,13 +55,15 @@ class MetaSeoImageListTable extends WP_List_Table
50
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
51
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
52
  || is_plugin_active('polylang/polylang.php'))) {
53
- $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
 
54
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
 
55
  echo $sl_lang;
56
  }
57
  ?>
58
  </div>
59
- <?php elseif ($which == 'bottom') : ?>
60
  <input type="hidden" name="page" value="metaseo_image_meta"/>
61
  <div class="alignleft actions bulkactions">
62
  <?php
@@ -65,8 +72,10 @@ class MetaSeoImageListTable extends WP_List_Table
65
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
66
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
67
  || is_plugin_active('polylang/polylang.php'))) {
68
- $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
 
69
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
 
70
  echo $sl_lang;
71
  }
72
  ?>
@@ -78,44 +87,48 @@ class MetaSeoImageListTable extends WP_List_Table
78
  <div class="alignleft actions">
79
  <label>
80
  <select name="image_mbulk_copy" class="mbulk_copy">
81
- <option value="0"><?php _e('Bulk copy', 'wp-meta-seo') ?></option>
82
- <option value="all"><?php _e('All Images', 'wp-meta-seo') ?></option>
83
- <option value="bulk-copy-title-alt"><?php _e('Selected images', 'wp-meta-seo') ?></option>
84
  </select>
85
  </label>
86
  <input type="button" name="image_do_copy_alt"
87
  class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_alt"
88
- value="<?php _e('Image name as alt text', 'wp-meta-seo') ?>">
89
  <input type="button" name="image_do_copy_title"
90
  class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_title"
91
- value="<?php _e('Image name as image title', 'wp-meta-seo') ?>">
92
- <?php if ($which == 'top') : ?>
93
  <div style="float:left;position: relative;">
94
  <div class="wpms_process_meta" data-w="0" style="position: absolute;top: -2px;"></div>
95
- <input alt="<?php _e('Index images is required to use the Images filtering system above.
96
  Beware it may take a while depending of the quantity of images you got.
97
  Check the progress bar and be patient :)', 'wp-meta-seo') ?>"
98
  type="button" name="image_scan_meta" class="wpmsbtn wpmsbtn_small image_scan_meta"
99
- data-paged="1" value="<?php _e('Index images', 'wp-meta-seo') ?>">
100
  </div>
101
  <?php endif; ?>
102
  <span class="spinner"></span>
103
  </div>
104
 
105
  <input type="hidden" name="page" value="metaseo_image_meta"/>
 
 
106
  <?php if (!empty($_REQUEST['post_status'])) : ?>
107
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
108
  <?php endif ?>
 
 
109
 
110
  <div style="float:right;margin-left:8px;">
111
  <label>
112
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>"
 
113
  maxlength="3" name="metaseo_imgs_per_page" class="metaseo_imgs_per_page screen-per-page"
114
  max="999" min="1" step="1">
115
  </label>
116
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
117
  </div>
118
-
119
  <?php $this->pagination($which); ?>
120
  <br class="clear"/>
121
  </div>
@@ -123,140 +136,27 @@ class MetaSeoImageListTable extends WP_List_Table
123
  <?php
124
  }
125
 
126
- /**
127
- * Get an associative array ( id => link ) with the list
128
- * of views available on this table.
129
- * @return array
130
- */
131
- protected function get_views()
132
- {
133
- global $wpdb;
134
- $status_links = array();
135
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
136
- $post_types = "'" . implode("', '", $post_types) . "'";
137
-
138
- $states = get_post_stati(array('show_in_admin_all_list' => true));
139
- $states['trash'] = 'trash';
140
- $all_states = "'" . implode("', '", $states) . "'";
141
-
142
- $total_posts = $wpdb->get_var(
143
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)"
144
- );
145
-
146
- $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
147
- $status_links['all'] = "<a href='admin.php?page=metaseo_image_meta'$class>";
148
- $status_links['all'] .= sprintf(
149
- _nx(
150
- 'All <span class="count">(%s)</span>',
151
- 'All <span class="count">(%s)</span>',
152
- $total_posts,
153
- 'posts'
154
- ),
155
- number_format_i18n(
156
- $total_posts
157
- )
158
- );
159
- $status_links['all'] .= "</a>";
160
- foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
161
- $name = $status->name;
162
-
163
- $total = $wpdb->get_var(
164
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$name') AND post_type IN ($post_types)"
165
- );
166
-
167
- if ($total == 0) {
168
- continue;
169
- }
170
-
171
- if (isset($_REQUEST['post_status']) && $name == $_REQUEST['post_status']) {
172
- $class = ' class="current"';
173
- } else {
174
- $class = '';
175
- }
176
-
177
- $status_links[$name] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=$name'$class>";
178
- $status_links[$name] .= sprintf(
179
- translate_nooped_plural($status->label_count, $total),
180
- number_format_i18n($total)
181
- );
182
- $status_links[$name] .= "</a>";
183
- }
184
- $trashed_posts = $wpdb->get_var(
185
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)"
186
- );
187
- $class = (isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status']) ? 'class="current"' : '';
188
- $status_links['trash'] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=trash'$class>";
189
- $status_links['trash'] .= sprintf(
190
- _nx(
191
- 'Trash <span class="count">(%s)</span>',
192
- 'Trash <span class="count">(%s)</span>',
193
- $trashed_posts,
194
- 'posts'
195
- ),
196
- number_format_i18n(
197
- $trashed_posts
198
- )
199
- );
200
- $status_links['trash'] .= "</a>";
201
-
202
- return $status_links;
203
- }
204
-
205
- /**
206
- * Extra controls to be displayed between bulk actions and pagination
207
- * @param string $which
208
- */
209
- protected function extra_tablenav($which)
210
- {
211
- echo '<div class="alignleft actions">';
212
- global $wpdb;
213
-
214
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
215
- $post_types = "'" . implode("', '", esc_sql($post_types)) . "'";
216
-
217
- $states = get_post_stati(array('show_in_admin_all_list' => true));
218
- $states['trash'] = 'trash';
219
- $all_states = "'" . implode("', '", esc_sql($states)) . "'";
220
-
221
- $query = "SELECT DISTINCT post_type FROM
222
- $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
223
- $post_types = $wpdb->get_results($query);
224
-
225
- $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
226
-
227
- $options = '<option value="-1">Show All Post Types</option>';
228
-
229
- foreach ($post_types as $post_type) {
230
- $obj = get_post_type_object($post_type->post_type);
231
- $options .= sprintf(
232
- '<option value="%2$s" %3$s>%1$s</option>',
233
- $obj->labels->name,
234
- $post_type->post_type,
235
- selected($selected, $post_type->post_type, false)
236
- );
237
- }
238
-
239
- echo "</div>";
240
- }
241
-
242
  /**
243
  * Get a list of columns. The format is:
244
  * 'internal-name' => 'Title'
 
245
  * @return array
246
  */
247
- public function get_columns()
248
  {
249
- return $columns = array(
250
- 'cb' => '<input id="cb-select-all-1" type="checkbox">',
251
- 'col_id' => __('ID', 'wp-meta-seo'),
252
- 'col_image' => __('Image', 'wp-meta-seo'),
253
- 'col_image_name' => __('Name', 'wp-meta-seo'),
254
- 'col_image_info' => __('Optimization Info', 'wp-meta-seo'),
255
- 'col_image_alternative' => __('Alternative text', 'wp-meta-seo'),
256
- 'col_image_title' => __('Title', 'wp-meta-seo'),
257
- 'col_image_legend' => __('Caption', 'wp-meta-seo'),
258
- 'col_image_desc' => __('Description', 'wp-meta-seo'),
259
  );
 
 
260
  }
261
 
262
  /**
@@ -266,61 +166,61 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
266
  * 'internal-name' => array( 'orderby', true )
267
  *
268
  * The second format will make the initial sorting order be descending
 
269
  * @return array
270
  */
271
- protected function get_sortable_columns()
272
  {
273
- return $sortable = array(
274
- 'col_image_name' => array('post_name', true),
275
- 'col_image_title' => array('post_title', true),
276
  );
 
 
277
  }
278
 
279
  /**
280
  * Print column headers, accounting for hidden and sortable columns.
281
  *
282
- * @since 3.1.0
283
- * @access public
284
  *
285
- * @param bool $with_id Whether to set the id attribute or not
286
  */
287
- public function print_column_headers($with_id = true)
288
  {
289
  list($columns, $hidden, $sortable) = $this->get_column_info();
290
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
291
  $current_url = remove_query_arg('paged', $current_url);
292
-
293
  if (isset($_GET['orderby'])) {
294
  $current_orderby = $_GET['orderby'];
295
  } else {
296
  $current_orderby = '';
297
  }
298
 
299
- if (isset($_GET['order']) && 'desc' == $_GET['order']) {
300
  $current_order = 'desc';
301
  } else {
302
  $current_order = 'asc';
303
  }
304
-
305
  if (!empty($columns['cb'])) {
306
  static $cb_counter = 1;
307
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">
308
- ' . __('Select All', 'wp-meta-seo') . '</label>'
309
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
310
- $cb_counter++;
311
  }
312
 
313
  foreach ($columns as $column_key => $column_display_name) {
314
- $class = array('manage-column', "column-$column_key");
315
 
316
  $style = '';
317
  if (in_array($column_key, $hidden)) {
318
- $style = 'display:none;';
319
  }
320
 
321
- $style = ' style="' . $style . '"';
322
-
323
- if ('cb' == $column_key) {
324
  $class[] = 'check-column';
325
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
326
  $class[] = 'num';
@@ -329,57 +229,58 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
329
  if (isset($sortable[$column_key])) {
330
  list($orderby, $desc_first) = $sortable[$column_key];
331
 
332
- if ($current_orderby == $orderby) {
333
- $order = 'asc' == $current_order ? 'desc' : 'asc';
334
  $class[] = 'sorted';
335
  $class[] = $current_order;
336
  } else {
337
- $order = $desc_first ? 'desc' : 'asc';
338
  $class[] = 'sortable';
339
  $class[] = $desc_first ? 'asc' : 'desc';
340
  }
341
 
342
- $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
343
- $column_display_name = '<a href="' . $hr . '">
344
- <span>' . $column_display_name . '</span>
345
  <span class="sorting-indicator"></span></a>';
346
  }
347
 
348
- $id = $with_id ? "id='$column_key'" : '';
349
 
350
  if (!empty($class)) {
351
- $class = "class='" . join(' ', $class) . "'";
352
  }
353
 
 
354
  if ($column_key === 'col_id') {
355
- echo "<th scope='col' $id $class $style colspan=\"1\">$column_display_name</th>";
356
  } elseif ($column_key === 'col_image_name') {
357
- echo "<th scope='col' $id $class $style colspan=\"4\">$column_display_name</th>";
358
  } elseif ($column_key === 'col_image_info') {
359
- echo "<th scope='col' $id $class $style colspan=\"5\">$column_display_name</th>";
360
  } elseif ($column_key === 'cb') {
361
- echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
362
  } else {
363
- echo "<th scope='col' $id $class $style colspan=\"3\">$column_display_name</th>";
364
  }
 
365
  }
366
  }
367
 
368
  /**
369
  * Get months
 
 
370
  */
371
  public function getMonths()
372
  {
373
  global $wpdb;
374
- $where = " AND ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg')";
375
- $where .= " OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
376
  $months = $wpdb->get_results(
377
- $wpdb->prepare("
378
  SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
379
- FROM $wpdb->posts
380
- WHERE post_type = %s" . $where . "
381
- ORDER BY post_date DESC
382
- ", 'attachment')
383
  );
384
 
385
  $months = apply_filters('months_dropdown_results', $months, 'attachment');
@@ -388,96 +289,90 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
388
 
389
  /**
390
  * Prepares the list of items for displaying.
391
- * @uses WP_List_Table::set_pagination_args()
 
392
  */
393
- public function prepare_items()
394
  {
395
  global $wpdb;
396
  $this->months = $this->getMonths();
397
- $where = array();
398
- $post_type = 'attachment';
399
- $where[] = " post_type='$post_type' ";
400
- $where[] = " ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg')
401
- OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
402
-
403
- if (!empty($_REQUEST["search"])) {
404
- if (!empty($_REQUEST["txtkeyword"])) {
405
- $_REQUEST["txtkeyword"] = stripslashes($_REQUEST["txtkeyword"]);
406
- $_REQUEST["txtkeyword"] = $wpdb->esc_like($_REQUEST["txtkeyword"]);
407
- $where[] = $wpdb->prepare(
408
- " (post_title Like %s or post_name Like %s)",
409
- "%" . $_REQUEST["txtkeyword"] . "%",
410
- "%" . $_REQUEST["txtkeyword"] . "%"
411
  );
412
  }
413
  }
414
 
415
  if (!empty($_REQUEST['sldate'])) {
416
- $where[] = $wpdb->prepare(" post_date Like %s", "%" . $_REQUEST['sldate'] . "%");
417
  }
418
 
419
- $sortable = $this->get_sortable_columns();
420
  $order_array = array('ASC', 'asc', 'DESC', 'desc');
421
- if (isset($_GET["orderby"])) {
422
- $orderby_array = array($_GET["orderby"], true);
423
  } else {
424
  $orderby_array = array('post_name', true);
425
  }
426
- $orderby = (!empty($_GET["orderby"]) && in_array($orderby_array, $sortable)) ? ($_GET["orderby"]) : 'post_name';
427
- $order = (!empty($_GET["order"]) && in_array($_GET["order"], $order_array)) ? ($_GET["order"]) : 'ASC';
428
 
429
  $orderStr = '';
430
  if (!empty($orderby) & !empty($order)) {
431
- $orderStr = $wpdb->prepare(' ORDER BY %s %s', $orderby, $order);
432
- $orderStr = str_replace("'", "", $orderStr);
433
  }
434
 
435
- if (isset($_GET['slmeta']) && $_GET['slmeta'] == 'missing_information') {
436
- $join = "INNER JOIN (SELECT * FROM {$wpdb->prefix}postmeta
437
- WHERE meta_key = 'wpms_missing_information') mt ON mt.post_id = posts.ID ";
438
- } elseif (isset($_GET['slmeta']) && $_GET['slmeta'] == 'resizeimages') {
439
- $join = "INNER JOIN (SELECT * FROM {$wpdb->prefix}postmeta
440
- WHERE meta_key = 'wpms_resizeimages' AND meta_value = 1) mt ON mt.post_id = posts.ID ";
441
  } else {
442
- $join = "LEFT JOIN (SELECT * FROM {$wpdb->prefix}postmeta
443
- WHERE meta_key = '_wp_attachment_image_alt') mt ON mt.post_id = posts.ID ";
444
  }
445
 
446
  // query post by lang with polylang plugin
447
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
448
- if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
449
- $join .= " INNER JOIN (SELECT * FROM $wpdb->term_relationships as ml
450
- INNER JOIN (SELECT * FROM $wpdb->terms WHERE slug='" . $_GET['wpms_lang_list'] . "') mp
451
- ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = posts.ID ";
452
  }
453
  }
454
 
455
  // query post by lang with WPML plugin
456
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
457
- if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
458
- $join .= " INNER JOIN (SELECT * FROM " . $wpdb->prefix . "icl_translations
459
- WHERE element_type LIKE 'post_%' AND language_code='" . $_GET['wpms_lang_list'] . "') t
460
- ON t.element_id = $wpdb->posts.ID ";
461
  }
462
  }
463
-
464
- $query = "SELECT COUNT(ID)
465
- FROM $wpdb->posts as posts
466
- " . $join . "
467
- WHERE " . implode(" and ", $where) . $orderStr;
468
-
469
- $total_items = $wpdb->get_var($query);
470
- $query = "SELECT ID, post_title as title, post_name as name, post_content as des,
471
  post_excerpt as legend, guid, post_type , post_mime_type, post_status, mt.meta_value AS alt
472
- FROM $wpdb->posts as posts
473
- " . $join . "
474
- WHERE " . implode(" and ", $where) . $orderStr;
475
 
476
  if (!empty($_REQUEST['metaseo_imgs_per_page'])) {
477
  $_per_page = intval($_REQUEST['metaseo_imgs_per_page']);
478
  } else {
479
  $_per_page = 0;
480
  }
 
481
  $per_page = get_user_option('metaseo_imgs_per_page');
482
  if ($per_page !== false) {
483
  if ($_per_page && $_per_page !== $per_page) {
@@ -493,7 +388,8 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
493
  add_user_meta(get_current_user_id(), 'metaseo_imgs_per_page', $per_page);
494
  }
495
 
496
- $paged = !empty($_GET["paged"]) ? ($_GET["paged"]) : '';
 
497
 
498
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
499
  $paged = 1;
@@ -503,22 +399,23 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
503
 
504
  if (!empty($paged) && !empty($per_page)) {
505
  $offset = ($paged - 1) * $per_page;
506
- $query .= ' LIMIT ' . (int)$offset . ',' . (int)$per_page;
507
  }
508
 
509
  $this->set_pagination_args(array(
510
  'total_items' => $total_items,
511
  'total_pages' => $total_pages,
512
- 'per_page' => $per_page
513
  ));
514
 
515
- $columns = $this->get_columns();
516
- $hidden = array();
517
- $sortable = $this->get_sortable_columns();
518
  $this->_column_headers = array($columns, $hidden, $sortable);
519
-
520
  $this->items = $wpdb->get_results($query);
521
- if (isset($_GET['slmeta']) && ($_GET['slmeta'] == 'missing_information' || $_GET['slmeta'] == 'resizeimages')) {
 
522
  foreach ($this->items as $item) {
523
  $item->alt = get_post_meta($item->ID, '_wp_attachment_image_alt', true);
524
  }
@@ -527,14 +424,17 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
527
 
528
  /**
529
  * Displays the search box.
 
 
530
  */
531
  public function searchBox1()
532
  {
 
533
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
534
  return;
535
  }
536
 
537
- $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
538
  if (!empty($_REQUEST['orderby'])) {
539
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
540
  }
@@ -550,7 +450,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
550
  if (!empty($_REQUEST['detached'])) {
551
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
552
  }
553
-
554
  ?>
555
  <p class="search-box">
556
  <label>
@@ -563,38 +463,43 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
563
  }
564
 
565
  /**
566
- * Add fillter month
567
- * @param $name
 
 
 
568
  */
569
  public function monthsFilter($name)
570
  {
571
  global $wp_locale;
572
  $month_count = count($this->months);
573
- if (!$month_count || (1 == $month_count && 0 == $this->months[0]->month)) {
574
  return;
575
  }
576
 
 
577
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
578
  ?>
579
- <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'wp-meta-seo'); ?></label>
580
- <select name="<?php echo $name ?>" id="filter-by-date" class="metaseo-filter">
581
- <option<?php selected($m, 0); ?> value="0"><?php _e('All dates', 'wp-meta-seo'); ?></option>
 
582
  <?php
583
  foreach ($this->months as $arc_row) {
584
- if (0 == $arc_row->year) {
585
  continue;
586
  }
587
 
588
  $month = zeroise($arc_row->month, 2);
589
- $year = $arc_row->year;
590
  printf(
591
  "<option %s value='%s' >%s</option>\n",
592
- selected($m, "$year-$month", false),
593
- esc_attr("$arc_row->year-$month"),
594
  sprintf(
595
- __('%1$s %2$d', 'wp-meta-seo'),
596
- $wp_locale->get_month($month),
597
- $year
598
  )
599
  );
600
  }
@@ -605,45 +510,52 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
605
  }
606
 
607
  /**
608
- * @param $name
 
 
 
 
609
  */
610
  public function metaFilter($name)
611
  {
 
612
  $m = isset($_REQUEST['slmeta']) ? $_REQUEST['slmeta'] : 0;
613
  ?>
614
  <label>
615
- <select name="<?php echo $name ?>" id="filter-by-meta" class="meta_filter">
616
- <option <?php selected($m, 'all') ?> value="all"><?php _e('All images', 'wp-meta-seo') ?></option>
 
617
  <option <?php selected($m, 'missing_information') ?>
618
  value="missing_information">
619
- <?php _e('Image with missing information', 'wp-meta-seo') ?>
620
  </option>
621
  <option <?php selected($m, 'resizeimages') ?>
622
- value="resizeimages"><?php _e('HTML resized images', 'wp-meta-seo') ?></option>
623
  </select>
624
  </label>
625
  <input type="submit" name="filter_meta_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary"
626
- value="<?php _e('Filter', 'wp-meta-seo') ?>">
627
  <span class="spinner imgspinner"></span>
628
  <?php
629
  }
630
 
631
  /**
632
  * Generate the table rows
 
 
633
  */
634
- public function display_rows()
635
  {
636
- $records = $this->items;
637
- $i = 0;
638
- $alternate = "";
639
 
640
  list($columns, $hidden) = $this->get_column_info();
641
-
642
  if (!empty($records)) {
643
  foreach ($records as $rec) {
644
- $alternate = 'alternate' == $alternate ? '' : 'alternate';
645
- $i++;
646
- $classes = $alternate;
647
  $img_meta = get_post_meta($rec->ID, '_wp_attachment_metadata', true);
648
  if (empty($img_meta['file'])) {
649
  continue;
@@ -660,37 +572,38 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
660
  } else {
661
  $img_name = $img_meta['file'];
662
  }
663
- $type = substr($img_meta['file'], strrpos($img_meta['file'], '.'));
664
  $img_name = str_replace($type, '', $img_name);
665
 
666
  $upload_dir = wp_upload_dir();
667
- $img_path = $upload_dir['basedir'] . '/' . $img_meta['file'];
668
  //Get the date that image was uploaded
669
- $img_date = get_the_date("", $rec->ID);
670
  if (file_exists($img_path)) {
671
  if (is_readable($img_path)) {
672
  //Get image attributes including width and height
673
  list($img_width, $img_height, $img_type) = getimagesize($img_path);
674
  //Get image size
675
- if (($size = filesize($img_path) / 1024) > 1024) {
676
- $img_size = ($size / 1024);
 
677
  $img_sizes = ' MB';
678
  } else {
679
- $img_size = ($size);
680
  $img_sizes = ' KB';
681
  }
682
  $img_size = round($img_size, 1);
683
  } else {
684
- $img_size = 0;
685
- $img_sizes = ' MB';
686
- $img_width = 0;
687
  $img_height = 0;
688
  }
689
 
690
- echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
691
  foreach ($columns as $column_name => $column_display_name) {
692
- $class = sprintf('class="%1$s column-%1$s"', $column_name);
693
- $style = "";
694
 
695
  if (in_array($column_name, $hidden)) {
696
  $style = ' style="display:none;"';
@@ -702,44 +615,45 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
702
  case 'cb':
703
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
704
  echo '<input id="cb-select-1" class="metaseo_post" type="checkbox"
705
- name="post[]" value="' . $rec->ID . '">';
706
  echo '</td>';
707
  break;
708
 
709
  case 'col_id':
710
  echo '<td class="col_id" colspan="1">';
711
- echo $i;
712
  echo '</td>';
713
  break;
714
 
715
  case 'col_image':
716
  $img = sprintf(
717
- "<img src='$thumb_url' width='100px' height='100px' class='metaseo-image'
718
- data-name='$img_name$type' data-img-post-id='$rec->ID' />"
719
  );
720
-
721
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $img, $attributes);
722
  break;
723
 
724
  case 'col_image_name':
725
  $info = '<div class="img-name-wrapper">';
726
- $info .= '<textarea name="name_image[' . $rec->ID . ']"
727
  class="metaseo-img-meta metaseo-img-name" data-meta-type="change_image_name"
728
- id="img-name-' . $rec->ID . '" data-post-id="' . $rec->ID . '" rows="2"
729
- data-extension="' . $type . '">' . $img_name . '</textarea>
730
- <span class="img_type">' . $type . '</span>';
731
- $info .= '<p>size: ' . $img_size . $img_sizes . '</p>';
732
- $info .= '<p>' . $img_width . 'x' . $img_height . '</p>';
733
- $info .= '<p>' . $img_date . '</p>';
734
  $info .= '<span class="saved-info" style="position:relative">
735
  <span class="spinner"></span>
736
  </span>';
737
  $info .= '</div>';
 
738
  echo sprintf('<td %2$s colspan="4">%1$s</td>', $info, $attributes);
739
  break;
740
 
741
  case 'col_image_info':
742
- $info = "<div class=\"opt-info\" id=\"opt-info-$rec->ID\"></div>";
743
  $info .= '<span class="metaseo-loading"></span>';
744
  $info .= '
745
  <div class="popup-bg"></div>
@@ -747,51 +661,51 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
747
  <span class="popup-close" title="Close">x</span>
748
  <div class="popup-content"></div>
749
  </div>';
750
-
751
- echo sprintf(
752
- '<td %2$s colspan="5" style="position:relative">%1$s</td>',
753
- $info,
754
- $attributes
755
- );
756
  break;
757
 
758
  case 'col_image_alternative':
759
- $input = "<textarea name='img_alternative[$rec->ID]' class='metaseo-img-meta'
760
- data-meta-type='alt_text' id='img-alt-$rec->ID' data-post-id='$rec->ID'
761
- rows='2'>" . esc_attr($rec->alt) . "</textarea>";
762
  $input .= ('<span class="saved-info" style="position:relative">
763
  <span class="spinner"></span>
764
  </span>');
 
765
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
766
  break;
767
 
768
  case 'col_image_title':
769
- $input = "<textarea name='img_title[$rec->ID]' class='metaseo-img-meta'
770
- data-meta-type='image_title' id='img-title-$rec->ID' data-post-id='$rec->ID'
771
- rows='2'>" . esc_attr($rec->title) . "</textarea>";
772
  $input .= ('<span class="saved-info" style="position:relative">
773
  <span class="spinner"></span>
774
  </span>');
 
775
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
776
  break;
777
 
778
  case 'col_image_legend':
779
- $input = "<textarea name='img_legend[$rec->ID]' class='metaseo-img-meta'
780
- data-meta-type='image_caption' id='img-legend-$rec->ID' data-post-id='$rec->ID'
781
- rows='2'>" . esc_attr($rec->legend) . "</textarea>";
782
  $input .= '<span class="saved-info" style="position:relative">
783
  <span class="spinner"></span>
784
  </span>';
 
785
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
786
  break;
787
 
788
  case 'col_image_desc':
789
- $input = "<textarea name='img_desc[$rec->ID]' class='metaseo-img-meta'
790
- data-meta-type='image_description' id='img-desc-$rec->ID' data-post-id='$rec->ID'
791
- rows='2'>" . esc_attr($rec->des) . "</textarea>";
792
  $input .= ('<span class="saved-info" style="position:relative">
793
  <span class="spinner"></span>
794
  </span>');
 
795
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
796
  break;
797
  }
@@ -805,8 +719,10 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
805
 
806
  /**
807
  * Add a size for image
808
- * @param $response
809
- * @param $attachment
 
 
810
  * @return mixed
811
  */
812
  public static function addMoreAttachmentSizes($response, $attachment)
@@ -824,19 +740,18 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
824
 
825
  /**
826
  * Add to the list of image sizes that are available to administrators in the WordPress Media Library.
827
- * @param $sizes
 
 
828
  * @return array
829
  */
830
  public static function addMoreAttachmentSizesChoose($sizes)
831
  {
832
  global $wpdb;
833
- $query = "SELECT `meta_value` FROM $wpdb->postmeta WHERE
834
- `meta_key` = '_metaseo_sizes_optional' AND `meta_value` <> ''";
835
-
836
- $imgSizes = $wpdb->get_results($query);
837
  if (!empty($imgSizes)) {
838
  foreach ($imgSizes as $metaseo_img_sizes) {
839
- $metaseo_img_sizes = @unserialize($metaseo_img_sizes->meta_value);
840
  if (!empty($metaseo_img_sizes)) {
841
  foreach ($metaseo_img_sizes as $key => $size) {
842
  add_image_size($key, $size['width'], $size['height'], false);
@@ -868,29 +783,30 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
868
 
869
  /**
870
  * Display page fix meta list
871
- * @param $img_post_id
872
- * @param $posts
873
- * @param $meta_counter
874
- * @param $p
875
- * @param $im
 
 
 
876
  */
877
- private static function display_fix_metas_list($img_post_id, $posts, $meta_counter, $p, $im)
878
  {
879
  if ($meta_counter) {
880
  $header = sprintf(
881
- __('We found %s image with missing Title or Alt text', 'wp-meta-seo'),
882
- $meta_counter . $im . $p
883
  );
884
  } else {
885
- $header = __('We found 0 image with missing Title or Alt text', 'wp-meta-seo');
886
  }
887
 
888
  //Get default meta information of the image
889
  $img_post = get_post($img_post_id);
890
- $alt = get_post_meta($img_post_id, '_wp_attachment_image_alt', true);
891
- $title = $img_post->post_title;
892
  ?>
893
- <h3 class="content-header"><?php echo $header ?></h3>
894
  <div class="content-box">
895
  <table class="wp-list-table widefat fixed posts">
896
  <thead></thead>
@@ -899,30 +815,30 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
899
  <?php if (count($posts) < 1) : ?>
900
  <tr>
901
  <td colspan="10" style="height:95%">
902
- <?php echo __('This image has still not been inserted in any post!', 'wp-meta-seo') ?>
903
  </td>
904
  </tr>
905
  <?php else : ?>
906
  <tr class="metaseo-border-bottom">
907
- <td colspan="1"><?php _e('ID', 'wp-meta-seo') ?></td>
908
- <td colspan="2"><?php _e('Title', 'wp-meta-seo') ?></td>
909
- <td colspan="2"><?php _e('Image', 'wp-meta-seo') ?></td>
910
- <td colspan="5"><?php _e('Image information', 'wp-meta-seo') ?></td>
911
  </tr>
912
  <?php foreach ($posts as $post) : ?>
913
  <?php foreach (wpmsUtf8($post['meta'], 'decode') as $k => $meta) : ?>
914
  <?php
915
- $alternate = 'alternate' == $alternate ? '' : 'alternate';
916
  $file_name = substr($meta['img_src'], strrpos($meta['img_src'], '/') + 1);
917
  ?>
918
- <tr class="<?php echo $alternate ?>">
919
- <td colspan="1"><?php echo $post['ID'] ?></td>
920
  <td colspan="2">
921
- <p><?php echo $post['title'] ?></p>
922
  </td>
923
  <td colspan="2">
924
  <div class="metaseo-img-wrapper">
925
- <img src="<?php echo $meta['img_src'] ?>"/>
926
  </div>
927
  </td>
928
  <td colspan="5">
@@ -933,40 +849,40 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
933
  foreach ($specialChr as $chr) {
934
  $value = str_replace($chr, htmlentities2($chr), $value);
935
  }
936
- if ($type == 'alt') {
937
- $lb = __('Image Alt', 'wp-meta-seo');
938
  } else {
939
- $lb = __('Image Title', 'wp-meta-seo');
940
  }
941
- if ($value == '') {
942
- $placeholder = __(ucfirst($type) . ' is empty', 'wp-meta-seo');
943
  } else {
944
  $placeholder = '';
945
  }
946
  ?>
947
  <div>
948
- <label class="metaseo-img-lb"><?php echo $lb; ?></label>
949
  <input type="text" value="<?php echo esc_attr($value) ?>"
950
- id="metaseo-img-<?php echo $type . '-' . $post['ID'] ?>"
951
- class="metaseo-fix-meta metaseo-img-<?php echo $type ?>"
952
  data-meta-key="_metaseo_fix_metas"
953
- data-post-id="<?php echo $post['ID'] ?>"
954
- data-img-post-id="<?php echo $img_post_id ?>"
955
- data-meta-type="<?php echo $type ?>"
956
- data-meta-order="<?php echo $k ?>"
957
- data-file-name="<?php echo $file_name; ?>"
958
- placeholder="<?php echo $placeholder ?>"
959
  onfocus="metaseo_fix_meta(this);" onblur="updateInputBlur(this)"
960
  onkeydown="return checkeyCode(event)"/>
961
  </div>
962
 
963
- <?php if (trim($$type) != '' && trim($$type) != $value) : ?>
964
  <a class="meta-default wpmsbtn wpmsbtn_small" href="#"
965
  data-default-value="<?php echo esc_attr($$type) ?>"
966
  title="Add to input box"
967
- onclick="add_meta_default(this)"><?php _e('Copy ', 'wp-meta-seo');
968
- echo $lb ?></a>
969
- <span class="img_seo_type"><?php echo $$type; ?></span>
970
  <?php endif ?>
971
  <span class="spinner"></span>
972
  </div>
@@ -987,62 +903,64 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
987
 
988
  /**
989
  * Display page resize image list
990
- * @param $img_post_id
991
- * @param $posts
992
- * @param $img_counter
993
- * @param $p
994
- * @param $im
 
 
 
995
  */
996
- private static function display_resize_image_list($img_post_id, $posts, $img_counter, $p, $im)
997
  {
998
-
999
- $header = __('We found some images you can resize...', 'wp-meta-seo');
1000
  ?>
1001
- <h3 class="content-header"><?php echo $header ?></h3>
1002
  <div class="content-box">
1003
  <table class="wp-list-table widefat fixed posts">
1004
  <thead></thead>
1005
  <tbody>
1006
  <tr class="metaseo-border-bottom">
1007
- <td colspan="1">ID</td>
1008
- <td colspan="3">Title</td>
1009
- <td colspan="4">Current Images</td>
1010
- <td colspan="2" class="metaseo-action">Action</td>
1011
- <td colspan="4">After Replacing</td>
1012
  </tr>
1013
  <?php
1014
- $alternate = "";
1015
  foreach ($posts as $post) :
1016
  ?>
1017
- <?php $alternate = 'alternate' == $alternate ? '' : 'alternate'; ?>
1018
- <tr class="<?php echo $alternate ?>">
1019
- <td colspan="1"><?php echo $post['ID'] ?></td>
1020
  <td colspan="3">
1021
- <p><?php echo $post['title'] ?></p>
1022
  </td>
1023
  <td colspan="4" style="overflow: hidden;">
1024
  <?php foreach ($post['img_before_optm'] as $key => $src) : ?>
1025
  <div class="metaseo-img-wrapper">
1026
  <div class="metaseo-img">
1027
- <img width="<?php echo @$src['width']; ?>"
1028
- height="<?php #echo @$src['height'] ; ?>" src="<?php echo $src['src'] ?>"/>
1029
  <div class="img-choosen">
1030
 
1031
  <div class="pure-checkbox">
1032
- <input id="checkin-<?php echo $post['ID'] ?>" checked type="checkbox"
1033
- class="metaseo-checkin checkin-<?php echo $post['ID'] ?>"
1034
- value="<?php echo $key ?>"
1035
- id="checkin-<?php echo $post['ID'] . '-' . $key ?>"
1036
  onclick="uncheck(this)">
1037
- <label for="checkin-<?php echo $post['ID'] ?>"></label>
1038
  </div>
1039
  </div>
1040
  <p class="metaseo-msg"></p>
1041
  </div>
1042
  <div class="dimension">
1043
- Orig. <br>
1044
- <span>Dimensions</span>: <?php echo $src['dimension'] ?><br>
1045
- <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
 
1046
  </div>
1047
  </div>
1048
  <?php endforeach ?>
@@ -1050,20 +968,22 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1050
  <td colspan="2" class="metaseo-action">
1051
  <a href="javascript:void(0);"
1052
  class="metaseo-optimize wpmsbtn wpmsbtn_small wpmsbtn_secondary"
1053
- data-img-post-id="<?php echo $img_post_id ?>" data-post-id="<?php echo $post['ID'] ?>"
1054
- onclick="optimize_imgs(this)"><?php echo __('Replace?', 'wp-meta-seo') ?></a>
 
1055
  <span class="optimizing spinner"></span>
1056
  </td>
1057
  <td colspan="4">
1058
  <?php foreach ($post['img_after_optm'] as $src) : ?>
1059
  <div class="metaseo-img-wrapper">
1060
  <div class="metaseo-img">
1061
- <img src="<?php echo $src['src'] ?>"/>
1062
  </div>
1063
  <div class="dimension">
1064
- OPT <br>
1065
- <span>Dimensions</span>: <?php echo $src['dimension'] ?><br>
1066
- <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
 
1067
  </div>
1068
  </div>
1069
  <?php endforeach ?>
@@ -1076,7 +996,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1076
  <td colspan="2">
1077
  <a href="javascript:void(0);" id="metaseo-replace-all" class="wpmsbtn wpmsbtn_small"
1078
  onclick="optimize_imgs_group(this)">
1079
- <?php echo __('Replace All', 'wp-meta-seo') ?>
1080
  </a>
1081
  <span class="optimizing spinner"></span>
1082
  </td>
@@ -1090,13 +1010,20 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1090
  <?php
1091
  }
1092
 
1093
- /*
1094
  * Ajax optimize image and update content
 
 
1095
  */
1096
  public static function optimizeImages()
1097
  {
 
 
 
 
 
1098
  if (!empty($_POST['post_id']) && !empty($_POST['img_post_id'])) {
1099
- $post_id = intval($_POST['post_id']);
1100
  $img_post_id = intval($_POST['img_post_id']);
1101
  if (!empty($_POST['img_exclude'])) {
1102
  $img_exclude = $_POST['img_exclude'];
@@ -1108,7 +1035,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1108
  } else {
1109
  $ret = array(
1110
  'success' => false,
1111
- 'msg' => __('The post is not existed, please choose one another!', 'wp-meta-seo')
1112
  );
1113
  }
1114
 
@@ -1116,56 +1043,58 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1116
  wp_die();
1117
  }
1118
 
1119
- /*
1120
  * Retrieves a modified URL query string.
 
 
1121
  */
1122
  public function processAction()
1123
  {
1124
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
1125
- $redirect = false;
1126
-
1127
- if (isset($_POST['search']) and $_POST['search'] === 'Search') {
1128
  $current_url = add_query_arg(
1129
  array(
1130
- "search" => "Search",
1131
- "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))),
 
1132
  $current_url
1133
  );
1134
- $redirect = true;
1135
  }
1136
 
1137
  if (isset($_POST['sldate'])) {
1138
- $current_url = add_query_arg(array("sldate" => $_POST["sldate"]), $current_url);
1139
- $redirect = true;
1140
  }
1141
 
1142
  if (isset($_POST['slmeta'])) {
1143
- $current_url = add_query_arg(array("slmeta" => $_POST["slmeta"]), $current_url);
1144
- $redirect = true;
1145
  }
1146
 
1147
  if (!empty($_POST['paged'])) {
1148
- $current_url = add_query_arg(array("paged" => intval($_POST['paged'])), $current_url);
1149
- $redirect = true;
1150
  }
1151
 
1152
  if (!empty($_POST['metaseo_imgs_per_page'])) {
1153
  $current_url = add_query_arg(
1154
  array(
1155
- "metaseo_imgs_per_page" => intval($_POST['metaseo_imgs_per_page'])
1156
  ),
1157
  $current_url
1158
  );
1159
- $redirect = true;
1160
  }
1161
 
1162
  if (!empty($_POST['wpms_lang_list'])) {
1163
- $current_url = add_query_arg(array("wpms_lang_list" => $_POST['wpms_lang_list']), $current_url);
1164
- $redirect = true;
1165
  }
1166
-
1167
-
1168
- if ($redirect === true) {
1169
  wp_redirect($current_url);
1170
  ob_end_flush();
1171
  exit();
@@ -1174,15 +1103,22 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1174
 
1175
  /**
1176
  * Ajax get list of posts contain this image and its clones
 
 
1177
  */
1178
  public static function loadPostsCallback()
1179
  {
1180
- $_POST = stripslashes_deep($_POST);
 
 
 
 
 
1181
  $post_id = intval($_POST['post_id']);
1182
- $img = trim($_POST['img_name']);
1183
  $opt_key = strtolower(trim($_POST['opt_key']));
1184
  if ($post_id && !empty($img) && !empty($opt_key)) {
1185
- $fn = "display_{$opt_key}_list";
1186
  if (method_exists('MetaSeoImageListTable', $fn)) {
1187
  //Get list of posts contain this image and its clones
1188
  $posts = ImageHelper::getPostList($post_id, $opt_key);
@@ -1191,7 +1127,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1191
  $img_counter = 0;
1192
  //Now the time to resize the images
1193
  if ($opt_key === 'resize_image') {
1194
- $upload_dir = wp_upload_dir();
1195
  $metaseo_sizes_optional = get_post_meta(
1196
  $post_id,
1197
  '_metaseo_sizes_optional',
@@ -1204,9 +1140,9 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1204
 
1205
  foreach ($posts as &$post) {
1206
  foreach ($post['img_after_optm'] as &$img) {
1207
- $img_counter++;
1208
  $destination = $upload_dir['basedir'] . '/' . $img['path'];
1209
- $iresize = ImageHelper::IResize(
1210
  $img['src_origin'],
1211
  $img['width'],
1212
  $img['height'],
@@ -1216,34 +1152,34 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1216
  if ($iresize) {
1217
  $size = (filesize($destination) / 1024);
1218
  if ($size > 1024) {
1219
- $size = $size / 1024;
1220
  $sizes = 'MB';
1221
  } else {
1222
  $sizes = 'KB';
1223
  }
1224
- $size = @round($size, 1);
1225
- $img['size'] = $size;
1226
  $img['sizes'] = $sizes;
1227
  }
1228
 
1229
  $kpart = ImageHelper::IGetPart($img['path']);
1230
- $key = preg_replace('/\-(\d+)x(\d+)$/i', '-metaseo${1}${2}', $kpart->name);
1231
- $key = strtolower($key);
1232
- $file = substr($img['path'], strrpos($img['path'], '/') + 1);
1233
  if (!in_array($key, array_keys($metaseo_sizes_optional))) {
1234
  $metaseo_sizes_optional[$key] = array(
1235
- 'url' => $img['src'],
1236
- 'width' => $img['width'],
1237
- 'height' => $img['height'],
1238
  'orientation' => 'landscape',
1239
  );
1240
  }
1241
 
1242
  if (!isset($attachment_meta_data['sizes'][$key])) {
1243
  $attachment_meta_data['sizes'][$key] = array(
1244
- 'file' => $file,
1245
- 'width' => $img['width'],
1246
- 'height' => $img['height'],
1247
  'mime-type' => 'image/jpeg'
1248
  );
1249
  }
@@ -1254,15 +1190,15 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1254
  update_post_meta($post_id, '_metaseo_sizes_optional', $metaseo_sizes_optional);
1255
  } elseif ($opt_key === 'fix_metas') {
1256
  $toEdit = false;
1257
- $pIDs = array();
1258
  foreach ($posts as $ID => &$post) {
1259
  $img_counter += count($post['meta']);
1260
  foreach ($post['meta'] as $order => $meta) {
1261
- if ($meta['type']['alt'] == '' || $meta['type']['title'] == '') {
1262
  $toEdit = true;
1263
  }
1264
 
1265
- if ($meta['type']['alt'] != '' && $meta['type']['title'] != '') {
1266
  $pIDs[$ID][] = $order;
1267
  }
1268
  }
@@ -1273,7 +1209,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1273
  foreach ($orders as $order) {
1274
  unset($posts[$ID]['meta'][$order]);
1275
  if ($img_counter > 0) {
1276
- $img_counter--;
1277
  }
1278
  }
1279
 
@@ -1293,7 +1229,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1293
  $p = '';
1294
  }
1295
 
1296
- if (isset($img_counter) and $img_counter > 1) {
1297
  $im = ' images ';
1298
  } else {
1299
  if (!isset($img_counter)) {
@@ -1310,33 +1246,40 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1310
 
1311
  /**
1312
  * Scan post to find image good and not good
 
 
1313
  */
1314
  public static function scanPostsCallback()
1315
  {
 
 
 
 
 
1316
  $_POST = stripslashes_deep($_POST);
1317
- $imgs = $_POST['imgs'];
1318
  if (!empty($imgs)) {
1319
  if (!is_array($imgs)) {
1320
  $ret['success'] = false;
1321
- $ret['msg'] = 'No images are available, please check again!';
1322
  wp_send_json($ret);
1323
  }
1324
 
1325
- $_imgs = array();
1326
  $_imgs[trim($imgs['name'])] = $imgs['img_post_id'];
1327
  unset($imgs);
1328
 
1329
  if (!count($_imgs)) {
1330
  $ret['success'] = false;
1331
- $ret['msg'] = 'No images are available, please check again!';
1332
  wp_send_json($ret);
1333
  }
1334
 
1335
- $msg = ImageHelper::IScanPosts($_imgs, true);
1336
- $ret['msg'] = $msg;
1337
  $ret['success'] = true;
1338
 
1339
- if (isset($_POST['imgs']['type']) && $_POST['imgs']['type'] == 'update_meta') {
1340
  if ($ret['msg'][$_POST['imgs']['img_post_id']]['imNotGood']['warning']) {
1341
  update_post_meta($_POST['imgs']['img_post_id'], 'wpms_missing_information', 1);
1342
  } else {
@@ -1350,7 +1293,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1350
  }
1351
  } else {
1352
  $ret['success'] = false;
1353
- $ret['msg'] = 'No images are available, please check again!';
1354
  }
1355
 
1356
  wp_send_json($ret);
@@ -1358,22 +1301,29 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1358
 
1359
  /**
1360
  * Ajax update image meta
 
 
1361
  */
1362
  public static function updateMetaCallback()
1363
  {
1364
- $response = new stdClass();
 
 
 
 
 
1365
  $response->updated = false;
1366
  if (!empty($_POST['addition']['meta_key'])) {
1367
  self::updateImgMetaCallback($_POST['addition'], true);
1368
  }
1369
 
1370
- if (!empty($_POST['meta_type']) and $_POST['meta_type'] == 'change_image_name') {
1371
  self::updateImageNameCallback();
1372
  }
1373
 
1374
  if (!empty($_POST['meta_type']) && !empty($_POST['post_id'])) {
1375
  $meta_type = strtolower(trim($_POST['meta_type']));
1376
- $post_id = intval($_POST['post_id']);
1377
 
1378
  if (!isset($_POST['meta_value'])) {
1379
  $meta_value = '';
@@ -1392,38 +1342,38 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1392
  $label = ucfirst($label);
1393
 
1394
  $aliases = array(
1395
- 'image_title' => 'post_title',
1396
- 'image_caption' => 'post_excerpt',
1397
  'image_description' => 'post_content',
1398
- 'alt_text' => '_wp_attachment_image_alt'
1399
  );
1400
 
1401
- if ($meta_type != 'alt_text') {
1402
  $data = array('ID' => $post_id, $aliases[$meta_type] => $meta_value);
1403
  if (wp_update_post($data)) {
1404
  $response->updated = true;
1405
- $response->msg = __($label . ' was saved', 'wp-meta-seo');
1406
  }
1407
  } else {
1408
  update_post_meta($post_id, $aliases[$meta_type], $meta_value);
1409
  $response->updated = true;
1410
- $response->msg = __($label . ' was saved', 'wp-meta-seo');
1411
  }
1412
 
1413
- if ($meta_type == 'alt_text') {
1414
  $settings = get_option('_metaseo_settings');
1415
  if (!isset($settings['metaseo_overridemeta']) || (!empty($settings['metaseo_overridemeta'])
1416
- && $settings['metaseo_overridemeta'] == 1)) {
1417
  // call function auto override in content
1418
 
1419
  self::autoUpdatePostContent($post_id, $meta_type, $meta_value);
1420
- $response->type = 'auto_override';
1421
- $response->pid = $post_id;
1422
  $response->imgname = $_POST['img_name'];
1423
  }
1424
  }
1425
  } else {
1426
- $response->msg = __('There is a problem when update image meta!', 'wp-meta-seo');
1427
  }
1428
 
1429
  echo json_encode($response);
@@ -1431,17 +1381,25 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1431
  }
1432
 
1433
  /**
1434
- * function auto override in content
1435
- * @param $post_id
1436
- * @param $meta_type
1437
- * @param $meta_value
 
 
 
1438
  */
1439
  public static function autoUpdatePostContent($post_id, $meta_type, $meta_value)
1440
  {
 
 
 
 
 
1441
  $_POST = stripslashes_deep($_POST);
1442
- $img = trim($_POST['img_name']);
1443
  if ($post_id && !empty($img)) {
1444
- $fn = "display_fix_metas_list";
1445
  if (method_exists('MetaSeoImageListTable', $fn)) {
1446
  //Get list of posts contain this image and its clones
1447
  $posts = ImageHelper::getPostList($post_id, 'fix_metas');
@@ -1449,15 +1407,15 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1449
  $img_counter = 0;
1450
  //Now the time to resize the images
1451
  $toEdit = false;
1452
- $pIDs = array();
1453
  foreach ($posts as $ID => &$post) {
1454
  $img_counter += count($post['meta']);
1455
  foreach ($post['meta'] as $order => $meta) {
1456
- if ($meta['type']['alt'] == '' || $meta['type']['title'] == '') {
1457
  $toEdit = true;
1458
  }
1459
 
1460
- if ($meta['type']['alt'] != '' && $meta['type']['title'] != '') {
1461
  $pIDs[$ID][] = $order;
1462
  }
1463
  }
@@ -1468,7 +1426,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1468
  foreach ($orders as $order) {
1469
  unset($posts[$ID]['meta'][$order]);
1470
  if ($img_counter > 0) {
1471
- $img_counter--;
1472
  }
1473
  }
1474
 
@@ -1484,17 +1442,17 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1484
  if (!empty($posts)) {
1485
  foreach ($posts as $p) {
1486
  foreach ($p['meta'] as $k => $meta) {
1487
- $addition = array();
1488
  $addition['meta_key'] = '_metaseo_fix_metas';
1489
- if ($meta_type == 'image_title') {
1490
  $addition['meta_type'] = 'title';
1491
  } else {
1492
  $addition['meta_type'] = 'alt';
1493
  }
1494
 
1495
- $addition['meta_value'] = $meta_value;
1496
- $addition['post_id'] = $p['ID'];
1497
- $addition['meta_order'] = $k;
1498
  $addition['img_post_id'] = $post_id;
1499
  self::updateImgMetaCallback($addition, false);
1500
  }
@@ -1504,40 +1462,47 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1504
 
1505
  /**
1506
  * Update image name
 
 
1507
  */
1508
  public static function updateImageNameCallback()
1509
  {
 
 
 
 
 
1510
  global $wpdb;
1511
- $postID = (int)$_POST['post_id'];
1512
- $name = trim($_POST['meta_value']);
1513
- $iname = preg_replace('/(\s{1,})/', '-', $name);
1514
- $img_meta = get_post_meta($postID, '_wp_attachment_metadata', true);
1515
- $linkold = $img_meta['file'];
1516
- $response = new stdClass();
1517
  $response->updated = false;
1518
- $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
1519
 
1520
  $upload_dirs = wp_upload_dir();
1521
- $upload_dir = $upload_dirs['basedir'];
1522
- $oldpart = ImageHelper::IGetPart($linkold);
1523
- $old_name = $oldpart->name;
1524
 
1525
- if ($name !== "") {
1526
- if (file_exists($upload_dir . "/" . $linkold)) {
1527
  $newFileName = $oldpart->base_path . $iname . $oldpart->ext;
1528
  // check file not exist
1529
- if (!file_exists($upload_dir . "/" . $newFileName)) {
1530
- if (rename($upload_dir . "/" . $linkold, $upload_dir . "/" . $newFileName)) {
1531
  $post_title = get_the_title($postID);
1532
- $where = array('ID' => $postID);
1533
- $guid = $upload_dirs['baseurl'] . "/" . $newFileName;
1534
  if (!$post_title) {
1535
  $id = $wpdb->update(
1536
  $wpdb->posts,
1537
  array(
1538
- 'guid' => $guid,
1539
  'post_title' => $name,
1540
- 'post_name' => strtolower($iname)
1541
  ),
1542
  $where
1543
  );
@@ -1546,30 +1511,30 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1546
  }
1547
 
1548
  if ($id) {
1549
- $attached_metadata = get_post_meta($postID, "_wp_attachment_metadata", true);
1550
- $attached_metadata["file"] = $newFileName;
1551
 
1552
  $images_to_rename = array($oldpart->name . $oldpart->ext => $iname . $oldpart->ext);
1553
  foreach ($attached_metadata['sizes'] as &$clone) {
1554
  $clone_file_new = ImageHelper::IReplace($iname, $clone['file']);
1555
- $clone_path = $upload_dir . '/' . $oldpart->base_path . $clone['file'];
1556
  $clone_path_new = $upload_dir . '/' . $oldpart->base_path . $clone_file_new;
1557
 
1558
- if (@rename($clone_path, $clone_path_new)) {
1559
  $images_to_rename[$clone['file']] = $clone_file_new;
1560
- $clone['file'] = $clone_file_new;
1561
  }
1562
  }
1563
 
1564
  $metadats = get_post_meta($postID, '_wp_attachment_metadata', true);
1565
- $sizes = $metadats['sizes'];
1566
 
1567
  // get list image url and image thumbnail url
1568
- $list_thum_url = array();
1569
- $imageUrl = wp_get_attachment_url($postID);
1570
  $list_thum_url[] = $imageUrl;
1571
  foreach ($sizes as $key => $size) {
1572
- $thum_url = wp_get_attachment_image_src($postID, $key);
1573
  $list_thum_url[] = $thum_url[0];
1574
  }
1575
 
@@ -1578,25 +1543,23 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1578
 
1579
  $i = 0;
1580
  foreach ($list_thum_url as $url) {
1581
- $i++;
1582
- if ($i == count($list_thum_url)) {
1583
- $w .= ' post_content LIKE "%' . $url . '%"';
1584
  } else {
1585
- $w .= ' post_content LIKE "%' . $url . '%" OR';
1586
  }
1587
  }
1588
 
1589
- $w .= ')';
1590
- $where = array();
1591
  $where[] = "(`post_type` = 'post' or `post_type` = 'page')";
1592
  $where[] = "post_content LIKE '%<img%>%'";
1593
  $where[] = $w;
1594
- $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
1595
- FROM $wpdb->posts
1596
- WHERE " . implode(' AND ', $where) . " ORDER BY ID";
1597
  // query post
1598
- $posts = $wpdb->get_results($query);
1599
- $imgs = array($old_name . $oldpart->ext => $postID);
 
1600
  $posts_contain_img = array();
1601
  foreach ($posts as $post) {
1602
  $ifound = ImageHelper::IScan($post->post_content, $imgs);
@@ -1607,17 +1570,19 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1607
 
1608
  // update post
1609
  foreach ($posts_contain_img as $id) {
1610
- if ($post = get_post($id)) {
 
1611
  foreach ($images_to_rename as $src_before => $src_after) {
1612
- $src_before = '/' . $src_before;
1613
- $src_after = '/' . $src_after;
1614
  $post->post_content = str_replace($src_before, $src_after, $post->post_content);
1615
  }
1616
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1617
  wp_update_post(
1618
  array(
1619
- 'ID' => $post->ID,
1620
- 'post_content' => $post->post_content)
 
1621
  );
1622
 
1623
  unset($post, $posts_contain_img);
@@ -1625,14 +1590,14 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1625
  }
1626
  }
1627
 
1628
- /** Update Image registered to Attachment sizes on Add media page* */
1629
  $sizeOptional = get_post_meta($postID, '_metaseo_sizes_optional', true);
1630
- $newOptional = array();
1631
  if (!empty($sizeOptional) && is_array($sizeOptional)) {
1632
  foreach ($sizeOptional as $key => $detail) {
1633
- $pattern = '/^' . strtolower($old_name) . '(-metaseo\d+)$/';
1634
- $key = preg_replace($pattern, strtolower($iname) . '${1}', $key);
1635
- $detail['url'] = ImageHelper::IReplace($iname, $detail['url']);
1636
  $newOptional[$key] = $detail;
1637
  }
1638
 
@@ -1647,23 +1612,23 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1647
  update_post_meta($postID, '_wp_attachment_metadata', $attached_metadata);
1648
 
1649
  $response->updated = true;
1650
- $response->msg = __('Image name was changed', 'wp-meta-seo');
1651
  } else {
1652
  $response->iname = $old_name;
1653
- $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
1654
  }
1655
  }
1656
  } else {
1657
- $response->msg = __('File name already given!', 'wp-meta-seo');
1658
  $response->iname = $old_name;
1659
  }
1660
  } else {
1661
  $response->iname = $old_name;
1662
- $response->msg = __('File is not existed', 'wp-meta-seo');
1663
  }
1664
  } else {
1665
  $response->iname = $old_name;
1666
- $response->msg = __('Should not be empty', 'wp-meta-seo');
1667
  }
1668
  echo json_encode($response);
1669
  wp_die();
@@ -1671,37 +1636,41 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1671
 
1672
  /**
1673
  * Update image meta
1674
- * @param $wpmspost
1675
- * @param bool $return
 
 
 
1676
  */
1677
  public static function updateImgMetaCallback($wpmspost, $return = true)
1678
  {
1679
- $response = new stdClass();
1680
  $response->updated = false;
1681
 
1682
  foreach ($wpmspost as $k => $v) {
1683
  if (!$v && !in_array($k, array('meta_value', 'meta_order'))) {
1684
- $response->msg = __('There is a problem when update image meta!', 'wp-meta-seo');
1685
 
1686
  echo json_encode($response);
1687
  wp_die();
1688
  }
1689
  }
1690
 
1691
- $meta_key = strtolower(trim($wpmspost['meta_key']));
1692
- $meta_type = strtolower(trim($wpmspost['meta_type']));
1693
- $meta_value = htmlspecialchars(trim($wpmspost['meta_value']));
1694
- $meta_order = intval($wpmspost['meta_order']);
1695
  $img_post_id = intval($wpmspost['img_post_id']);
1696
- $post_id = intval($wpmspost['post_id']);
1697
- $meta = get_post_meta($img_post_id, $meta_key, true);
1698
  //Update new value for meta info of this image in wp_postmeta
1699
  $meta[$post_id]['meta'][$meta_order]['type'][$meta_type] = wpmsUtf8($meta_value);
1700
  update_post_meta($img_post_id, $meta_key, $meta);
1701
 
1702
  //Then we must update this meta info in the appropriate post content
1703
- if (!$post = get_post($post_id)) {
1704
- $response->msg = __('The post has been deleted before, please check again!', 'wp-meta-seo');
 
1705
  } else {
1706
  if ($post->post_content !== '') {
1707
  //Split content part that do not contain img tag
@@ -1746,22 +1715,22 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1746
 
1747
  //Update content of this post.
1748
  if (!wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content))) {
1749
- $response->msg = __('The post haven\'t been updated, please check again!', 'wp-meta-seo');
1750
  } else {
1751
  update_option('wpms_last_update_post', time());
1752
  $response->updated = true;
1753
- $response->msg = __(ucfirst($meta_type) . ' was saved', 'wp-meta-seo');
1754
  }
1755
  } else {
1756
- $response->msg = __('This image has been removed from
1757
  the post, please check again!', 'wp-meta-seo');
1758
  }
1759
  } else {
1760
- $response->msg = __('Content of the post is empty, please check again', 'wp-meta-seo');
1761
  }
1762
  }
1763
 
1764
- if ($return == true) {
1765
  echo json_encode($response);
1766
  wp_die();
1767
  }
@@ -1769,43 +1738,42 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1769
 
1770
  /**
1771
  * Scan image metas
 
 
1772
  */
1773
  public static function imageScanMeta()
1774
  {
 
 
 
 
 
1775
  if (!current_user_can('manage_options')) {
1776
  wp_send_json(false);
1777
  }
1778
  global $wpdb;
1779
- $limit = 1;
1780
- $ofset = ((int)$_POST['paged'] - 1) * $limit;
1781
-
1782
- $where = array();
1783
- $where[] = " post_type='attachment' ";
1784
- $where[] = " ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg')
1785
- OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
1786
- $query = "SELECT COUNT(ID) FROM $wpdb->posts as posts WHERE " . implode(" and ", $where);
1787
- $count_images = $wpdb->get_var($query);
1788
- $present = (100 / $count_images) * $limit;
1789
-
1790
- $k = 0;
1791
- $sql = $wpdb->prepare(
1792
- "SELECT ID FROM " . $wpdb->posts . " WHERE " . implode(" AND ", $where) . " LIMIT %d OFFSET %d",
1793
- array(
1794
- $limit,
1795
- $ofset
1796
- )
1797
- );
1798
- $attachments = $wpdb->get_results($sql);
1799
  if (empty($attachments)) {
1800
  wp_send_json(array('status' => 'ok'));
1801
  }
1802
 
1803
  foreach ($attachments as $image) {
1804
- $path = get_attached_file($image->ID);
1805
- $infos = pathinfo($path);
1806
  $img_name = $infos['basename'];
1807
- $imgs = array('name' => $img_name, 'img_post_id' => $image->ID);
1808
- $results = MetaSeoImageListTable::scanPostsMeta($imgs, false, 0);
1809
  if ($results['msg'][$image->ID]['imNotGood']['warning']) {
1810
  update_post_meta($image->ID, 'wpms_missing_information', 1);
1811
  } else {
@@ -1816,7 +1784,7 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1816
  } else {
1817
  delete_post_meta($image->ID, 'wpms_resizeimages');
1818
  }
1819
- $k++;
1820
  }
1821
 
1822
  if ($k >= $limit) {
@@ -1827,9 +1795,12 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1827
  }
1828
 
1829
  /**
1830
- * @param $imgs
1831
- * @param bool $delete
1832
- * @param int $pid
 
 
 
1833
  * @return mixed
1834
  */
1835
  public static function scanPostsMeta($imgs, $delete = false, $pid = 0)
@@ -1837,40 +1808,43 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1837
  if (!empty($imgs)) {
1838
  if (!is_array($imgs)) {
1839
  $ret['success'] = false;
1840
- $ret['msg'] = 'No images are available, please check again!';
1841
  return $ret;
1842
  }
1843
 
1844
- $_imgs = array();
1845
  $_imgs[trim($imgs['name'])] = $imgs['img_post_id'];
1846
  unset($imgs);
1847
 
1848
  if (!count($_imgs)) {
1849
  $ret['success'] = false;
1850
- $ret['msg'] = 'No images are available, please check again!';
1851
  return $ret;
1852
  }
1853
 
1854
- $msg = ImageHelper::IScanPosts($_imgs, $delete, $pid);
1855
- $ret['msg'] = $msg;
1856
  $ret['success'] = true;
1857
  } else {
1858
  $ret['success'] = false;
1859
- $ret['msg'] = 'No images are available, please check again!';
1860
  }
1861
 
1862
  return $ret;
1863
  }
1864
 
1865
  /**
1866
- * update meta missing info and meta resize after delete post
1867
- * @param $pid
 
 
 
1868
  */
1869
  public static function deleteAttachment($pid)
1870
  {
1871
  $post = get_post($pid);
1872
  if (!empty($post)) {
1873
- $post_type = get_post_type($pid);
1874
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1875
  if (isset($post_types['attachment'])) {
1876
  unset($post_types['attachment']);
@@ -1879,17 +1853,17 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1879
  if (in_array($post_type, $post_types)) {
1880
  $dom = new DOMDocument();
1881
  libxml_use_internal_errors(true);
1882
- @$dom->loadHtml($post->post_content);
1883
  $tags = $dom->getElementsByTagName('img');
1884
  if (!empty($tags)) {
1885
  foreach ($tags as $tag) {
1886
- $url = $tag->getAttribute('src');
1887
- $postid = MetaSeoImageListTable::getAttachmentId($url);
1888
- $path = get_attached_file($postid);
1889
- $infos = pathinfo($path);
1890
  $img_name = $infos['basename'];
1891
- $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1892
- $results = MetaSeoImageListTable::scanPostsMeta($imgs, true, $pid);
1893
 
1894
  // update or delete meta
1895
  if ($results['msg'][$postid]['imNotGood']['warning']) {
@@ -1909,42 +1883,58 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1909
  }
1910
 
1911
  /**
1912
- * update meta missing info and meta resize after update post
1913
- * @param $post_ID
1914
- * @param $post_after
1915
- * @param $post_before
 
 
 
1916
  */
1917
  public static function updatePost($post_ID, $post_after, $post_before)
1918
  {
1919
- $old_imgs = MetaSeoImageListTable::getImagesInContent($post_before); // return list img in post before
1920
- $dom = new DOMDocument();
1921
- libxml_use_internal_errors(true);
1922
- @$dom->loadHtml($post_after->post_content);
1923
- $tags = $dom->getElementsByTagName('img');
 
 
 
 
 
 
1924
  $new_imgs = array(); // return list img in post after
1925
- if (!empty($tags)) {
1926
- foreach ($tags as $tag) {
1927
- $url = $tag->getAttribute('src');
1928
- $postid = MetaSeoImageListTable::getAttachmentId($url);
1929
- $new_imgs[] = $postid;
1930
- $post = get_post($postid);
1931
- if (!empty($post)) {
1932
- $path = get_attached_file($postid);
1933
- $infos = pathinfo($path);
1934
- $img_name = $infos['basename'];
1935
- $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1936
- $results = MetaSeoImageListTable::scanPostsMeta($imgs, false, 0);
1937
-
1938
- // update or delete meta
1939
- if ($results['msg'][$postid]['imNotGood']['warning']) {
1940
- update_post_meta($postid, 'wpms_missing_information', 1);
1941
- } else {
1942
- delete_post_meta($postid, 'wpms_missing_information');
1943
- }
1944
- if ($results['msg'][$postid]['iNotGood']['warning']) {
1945
- update_post_meta($postid, 'wpms_resizeimages', 1);
1946
- } else {
1947
- delete_post_meta($postid, 'wpms_resizeimages');
 
 
 
 
 
 
 
1948
  }
1949
  }
1950
  }
@@ -1954,11 +1944,11 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1954
  $imgs_diff = array_diff($old_imgs, $new_imgs);
1955
  if (!empty($imgs_diff)) {
1956
  foreach ($imgs_diff as $id) {
1957
- $path = get_attached_file($id);
1958
- $infos = pathinfo($path);
1959
  $img_name = $infos['basename'];
1960
- $imgs = array('name' => $img_name, 'img_post_id' => $id);
1961
- $results = MetaSeoImageListTable::scanPostsMeta($imgs, true, $post_ID);
1962
 
1963
  // update or delete meta
1964
  if ($results['msg'][$id]['imNotGood']['warning']) {
@@ -1977,56 +1967,63 @@ $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) O
1977
 
1978
  /**
1979
  * Get all images id in post content
1980
- * @param $post_before
 
 
1981
  * @return array
1982
  */
1983
  public static function getImagesInContent($post_before)
1984
  {
1985
  $dom = new DOMDocument();
1986
  libxml_use_internal_errors(true);
1987
- @$dom->loadHtml($post_before->post_content);
 
 
 
1988
  $tags = $dom->getElementsByTagName('img');
1989
- $ids = array();
1990
  if (empty($tags)) {
1991
  return $ids;
1992
  }
1993
  foreach ($tags as $tag) {
1994
- $url = $tag->getAttribute('src');
1995
- $postid = MetaSeoImageListTable::getAttachmentId($url);
1996
- $ids[] = $postid;
1997
  }
1998
  return $ids;
1999
  }
2000
 
2001
  /**
2002
  * Get attachment ID from URL
 
2003
  * @param string $url URl of attachment
2004
- * @return int
 
2005
  */
2006
  public static function getAttachmentId($url)
2007
  {
2008
  $attachment_id = 0;
2009
- $dir = wp_upload_dir();
2010
  if (false !== strpos($url, $dir['baseurl'] . '/')) { // Is URL in uploads directory?
2011
- $file = basename($url);
2012
  $query_args = array(
2013
- 'post_type' => 'attachment',
2014
  'post_status' => 'inherit',
2015
- 'fields' => 'ids',
2016
- 'meta_query' => array(
2017
  array(
2018
- 'value' => $file,
2019
  'compare' => 'LIKE',
2020
- 'key' => '_wp_attachment_metadata',
2021
  ),
2022
  )
2023
  );
2024
- $query = new WP_Query($query_args);
2025
  if ($query->have_posts()) {
2026
  foreach ($query->posts as $post_id) {
2027
  $meta = wp_get_attachment_metadata($post_id);
2028
  if (!empty($meta['file']) && !empty($meta['sizes'])) {
2029
- $original_file = basename($meta['file']);
2030
  $cropped_image_files = wp_list_pluck($meta['sizes'], 'file');
2031
  if ($original_file === $file || in_array($file, $cropped_image_files)) {
2032
  $attachment_id = $post_id;
16
  class MetaSeoImageListTable extends WP_List_Table
17
  {
18
  /**
19
+ * Months
20
+ *
21
+ * @var string
22
  */
23
  public $months;
24
 
29
  {
30
  parent::__construct(array(
31
  'singular' => 'metaseo_image',
32
+ 'plural' => 'metaseo_images',
33
+ 'ajax' => true
34
  ));
35
  }
36
 
37
  /**
38
  * Generate the table navigation above or below the table
39
+ *
40
+ * @param string $which Possition of table nav
41
+ *
42
+ * @return void
43
  */
44
+ protected function display_tablenav($which) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
45
  {
46
  ?>
47
+ <div class="<?php echo esc_attr('tablenav ' . $which); ?>">
48
 
49
+ <?php if ($which === 'top') : ?>
50
  <input type="hidden" name="page" value="metaseo_image_meta"/>
51
  <div class="alignleft actions bulkactions">
52
  <?php
55
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
56
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
57
  || is_plugin_active('polylang/polylang.php'))) {
58
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
59
+ $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
60
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
61
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::listLanguageSelect
62
  echo $sl_lang;
63
  }
64
  ?>
65
  </div>
66
+ <?php elseif ($which === 'bottom') : ?>
67
  <input type="hidden" name="page" value="metaseo_image_meta"/>
68
  <div class="alignleft actions bulkactions">
69
  <?php
72
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)
73
  && (is_plugin_active('sitepress-multilingual-cms/sitepress.php')
74
  || is_plugin_active('polylang/polylang.php'))) {
75
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
76
+ $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
77
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang);
78
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::listLanguageSelect
79
  echo $sl_lang;
80
  }
81
  ?>
87
  <div class="alignleft actions">
88
  <label>
89
  <select name="image_mbulk_copy" class="mbulk_copy">
90
+ <option value="0"><?php esc_html_e('Bulk copy', 'wp-meta-seo') ?></option>
91
+ <option value="all"><?php esc_html_e('All Images', 'wp-meta-seo') ?></option>
92
+ <option value="bulk-copy-title-alt"><?php esc_html_e('Selected images', 'wp-meta-seo') ?></option>
93
  </select>
94
  </label>
95
  <input type="button" name="image_do_copy_alt"
96
  class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_alt"
97
+ value="<?php esc_html_e('Image name as alt text', 'wp-meta-seo') ?>">
98
  <input type="button" name="image_do_copy_title"
99
  class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_title"
100
+ value="<?php esc_html_e('Image name as image title', 'wp-meta-seo') ?>">
101
+ <?php if ($which === 'top') : ?>
102
  <div style="float:left;position: relative;">
103
  <div class="wpms_process_meta" data-w="0" style="position: absolute;top: -2px;"></div>
104
+ <input alt="<?php esc_html_e('Index images is required to use the Images filtering system above.
105
  Beware it may take a while depending of the quantity of images you got.
106
  Check the progress bar and be patient :)', 'wp-meta-seo') ?>"
107
  type="button" name="image_scan_meta" class="wpmsbtn wpmsbtn_small image_scan_meta"
108
+ data-paged="1" value="<?php esc_html_e('Index images', 'wp-meta-seo') ?>">
109
  </div>
110
  <?php endif; ?>
111
  <span class="spinner"></span>
112
  </div>
113
 
114
  <input type="hidden" name="page" value="metaseo_image_meta"/>
115
+ <?php // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
116
+ ?>
117
  <?php if (!empty($_REQUEST['post_status'])) : ?>
118
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
119
  <?php endif ?>
120
+ <?php // phpcs:enable
121
+ ?>
122
 
123
  <div style="float:right;margin-left:8px;">
124
  <label>
125
+ <input type="number" required
126
+ value="<?php echo esc_attr($this->_pagination_args['per_page']) ?>"
127
  maxlength="3" name="metaseo_imgs_per_page" class="metaseo_imgs_per_page screen-per-page"
128
  max="999" min="1" step="1">
129
  </label>
130
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
131
  </div>
 
132
  <?php $this->pagination($which); ?>
133
  <br class="clear"/>
134
  </div>
136
  <?php
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  /**
140
  * Get a list of columns. The format is:
141
  * 'internal-name' => 'Title'
142
+ *
143
  * @return array
144
  */
145
+ public function get_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
146
  {
147
+ $columns = array(
148
+ 'cb' => '<input id="cb-select-all-1" type="checkbox">',
149
+ 'col_id' => esc_html__('ID', 'wp-meta-seo'),
150
+ 'col_image' => esc_html__('Image', 'wp-meta-seo'),
151
+ 'col_image_name' => esc_html__('Name', 'wp-meta-seo'),
152
+ 'col_image_info' => esc_html__('Optimization Info', 'wp-meta-seo'),
153
+ 'col_image_alternative' => esc_html__('Alternative text', 'wp-meta-seo'),
154
+ 'col_image_title' => esc_html__('Title', 'wp-meta-seo'),
155
+ 'col_image_legend' => esc_html__('Caption', 'wp-meta-seo'),
156
+ 'col_image_desc' => esc_html__('Description', 'wp-meta-seo')
157
  );
158
+
159
+ return $columns;
160
  }
161
 
162
  /**
166
  * 'internal-name' => array( 'orderby', true )
167
  *
168
  * The second format will make the initial sorting order be descending
169
+ *
170
  * @return array
171
  */
172
+ protected function get_sortable_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
173
  {
174
+ $sortable = array(
175
+ 'col_image_name' => array('post_name', true),
176
+ 'col_image_title' => array('post_title', true)
177
  );
178
+
179
+ return $sortable;
180
  }
181
 
182
  /**
183
  * Print column headers, accounting for hidden and sortable columns.
184
  *
185
+ * @param boolean $with_id Whether to set the id attribute or not
 
186
  *
187
+ * @return void
188
  */
189
+ public function print_column_headers($with_id = true) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
190
  {
191
  list($columns, $hidden, $sortable) = $this->get_column_info();
192
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
193
  $current_url = remove_query_arg('paged', $current_url);
194
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
195
  if (isset($_GET['orderby'])) {
196
  $current_orderby = $_GET['orderby'];
197
  } else {
198
  $current_orderby = '';
199
  }
200
 
201
+ if (isset($_GET['order']) && 'desc' === $_GET['order']) {
202
  $current_order = 'desc';
203
  } else {
204
  $current_order = 'asc';
205
  }
206
+ // phpcs:enable
207
  if (!empty($columns['cb'])) {
208
  static $cb_counter = 1;
209
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . esc_html($cb_counter) . '">
210
+ ' . esc_html__('Select All', 'wp-meta-seo') . '</label>'
211
+ . '<input id="cb-select-all-' . esc_html($cb_counter) . '" type="checkbox" style="margin:0;" />';
212
+ $cb_counter ++;
213
  }
214
 
215
  foreach ($columns as $column_key => $column_display_name) {
216
+ $class = array('manage-column', 'column-' . $column_key);
217
 
218
  $style = '';
219
  if (in_array($column_key, $hidden)) {
220
+ $style = 'style="display:none;"';
221
  }
222
 
223
+ if ('cb' === $column_key) {
 
 
224
  $class[] = 'check-column';
225
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
226
  $class[] = 'num';
229
  if (isset($sortable[$column_key])) {
230
  list($orderby, $desc_first) = $sortable[$column_key];
231
 
232
+ if ($current_orderby === $orderby) {
233
+ $order = 'asc' === $current_order ? 'desc' : 'asc';
234
  $class[] = 'sorted';
235
  $class[] = $current_order;
236
  } else {
237
+ $order = $desc_first ? 'desc' : 'asc';
238
  $class[] = 'sortable';
239
  $class[] = $desc_first ? 'asc' : 'desc';
240
  }
241
 
242
+ $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
243
+ $column_display_name = '<a href="' . esc_url($hr) . '">
244
+ <span>' . esc_html($column_display_name) . '</span>
245
  <span class="sorting-indicator"></span></a>';
246
  }
247
 
248
+ $id = $with_id ? 'id="' . esc_attr($column_key) . '"' : '';
249
 
250
  if (!empty($class)) {
251
+ $class = "class='" . esc_attr(join(' ', $class)) . "'";
252
  }
253
 
254
+ // phpcs:disable WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
255
  if ($column_key === 'col_id') {
256
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="1">' . $column_display_name . '</th>';
257
  } elseif ($column_key === 'col_image_name') {
258
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="4">' . $column_display_name . '</th>';
259
  } elseif ($column_key === 'col_image_info') {
260
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="5">' . $column_display_name . '</th>';
261
  } elseif ($column_key === 'cb') {
262
+ echo '<th scope="col" ' . $id . ' ' . $class . ' colspan="1" style="padding:8px 10px;">' . $column_display_name . '</th>';
263
  } else {
264
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="3">' . $column_display_name . '</th>';
265
  }
266
+ // phpcs:enable
267
  }
268
  }
269
 
270
  /**
271
  * Get months
272
+ *
273
+ * @return array|mixed|null|object
274
  */
275
  public function getMonths()
276
  {
277
  global $wpdb;
 
 
278
  $months = $wpdb->get_results(
279
+ $wpdb->prepare('
280
  SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
281
+ FROM ' . $wpdb->posts . '
282
+ WHERE post_type = %s AND ((post_mime_type="image/jpeg") OR (post_mime_type="image/jpg") OR (post_mime_type="image/png") OR (post_mime_type="image/gif"))
283
+ ORDER BY post_date DESC ', 'attachment')
 
284
  );
285
 
286
  $months = apply_filters('months_dropdown_results', $months, 'attachment');
289
 
290
  /**
291
  * Prepares the list of items for displaying.
292
+ *
293
+ * @return void
294
  */
295
+ public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
296
  {
297
  global $wpdb;
298
  $this->months = $this->getMonths();
299
+ $where = array();
300
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
301
+ $where[] = ' post_type="attachment" AND ((post_mime_type="image/jpeg") OR (post_mime_type="image/jpg")
302
+ OR (post_mime_type="image/png") OR (post_mime_type="image/gif")) ';
303
+ if (!empty($_REQUEST['search'])) {
304
+ if (!empty($_REQUEST['txtkeyword'])) {
305
+ $txtkeyword = stripslashes($_REQUEST['txtkeyword']);
306
+ $txtkeyword = $wpdb->esc_like($txtkeyword);
307
+ $where[] = $wpdb->prepare(
308
+ ' (post_title Like %s or post_name Like %s)',
309
+ '%' . $txtkeyword . '%',
310
+ '%' . $txtkeyword . '%'
 
 
311
  );
312
  }
313
  }
314
 
315
  if (!empty($_REQUEST['sldate'])) {
316
+ $where[] = $wpdb->prepare(' post_date Like %s', '%' . $_REQUEST['sldate'] . '%');
317
  }
318
 
319
+ $sortable = $this->get_sortable_columns();
320
  $order_array = array('ASC', 'asc', 'DESC', 'desc');
321
+ if (isset($_GET['orderby'])) {
322
+ $orderby_array = array($_GET['orderby'], true);
323
  } else {
324
  $orderby_array = array('post_name', true);
325
  }
326
+ $orderby = (!empty($_GET['orderby']) && in_array($orderby_array, $sortable)) ? ($_GET['orderby']) : 'post_name';
327
+ $order = (!empty($_GET['order']) && in_array($_GET['order'], $order_array)) ? ($_GET['order']) : 'ASC';
328
 
329
  $orderStr = '';
330
  if (!empty($orderby) & !empty($order)) {
331
+ $orderStr = ' ORDER BY ' . esc_sql($orderby) . ' ' . esc_sql($order);
 
332
  }
333
 
334
+ if (isset($_GET['slmeta']) && $_GET['slmeta'] === 'missing_information') {
335
+ $join = 'INNER JOIN (SELECT * FROM ' . $wpdb->prefix . 'postmeta
336
+ WHERE meta_key = "wpms_missing_information") mt ON mt.post_id = posts.ID ';
337
+ } elseif (isset($_GET['slmeta']) && $_GET['slmeta'] === 'resizeimages') {
338
+ $join = 'INNER JOIN (SELECT * FROM ' . $wpdb->prefix . 'postmeta
339
+ WHERE meta_key = "wpms_resizeimages" AND meta_value = 1) mt ON mt.post_id = posts.ID ';
340
  } else {
341
+ $join = 'LEFT JOIN (SELECT * FROM ' . $wpdb->prefix . 'postmeta
342
+ WHERE meta_key = "_wp_attachment_image_alt") mt ON mt.post_id = posts.ID ';
343
  }
344
 
345
  // query post by lang with polylang plugin
346
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
347
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] !== '0') {
348
+ $join .= $wpdb->prepare(' INNER JOIN (SELECT * FROM ' . $wpdb->term_relationships . ' as ml
349
+ INNER JOIN (SELECT * FROM ' . $wpdb->terms . ' WHERE slug = %s) mp
350
+ ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = posts.ID ', array($_GET['wpms_lang_list']));
351
  }
352
  }
353
 
354
  // query post by lang with WPML plugin
355
  if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
356
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] !== '0') {
357
+ $join .= $wpdb->prepare(' INNER JOIN (SELECT * FROM ' . $wpdb->prefix . 'icl_translations
358
+ WHERE element_type LIKE %s AND language_code = %s) t
359
+ ON t.element_id = posts.ID ', array('post_%', $_GET['wpms_lang_list']));
360
  }
361
  }
362
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
363
+ $total_items = $wpdb->get_var('SELECT COUNT(ID) FROM ' . $wpdb->posts . ' as posts ' . $join . ' WHERE ' . implode(' AND ', $where) . $orderStr);
364
+ $query = 'SELECT DISTINCT ID, post_title as title, post_name as name, post_content as des,
 
 
 
 
 
365
  post_excerpt as legend, guid, post_type , post_mime_type, post_status, mt.meta_value AS alt
366
+ FROM ' . $wpdb->posts . ' as posts
367
+ ' . $join . '
368
+ WHERE ' . implode(' AND ', $where) . $orderStr;
369
 
370
  if (!empty($_REQUEST['metaseo_imgs_per_page'])) {
371
  $_per_page = intval($_REQUEST['metaseo_imgs_per_page']);
372
  } else {
373
  $_per_page = 0;
374
  }
375
+ // phpcs:enable
376
  $per_page = get_user_option('metaseo_imgs_per_page');
377
  if ($per_page !== false) {
378
  if ($_per_page && $_per_page !== $per_page) {
388
  add_user_meta(get_current_user_id(), 'metaseo_imgs_per_page', $per_page);
389
  }
390
 
391
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
392
+ $paged = !empty($_GET['paged']) ? ($_GET['paged']) : '';
393
 
394
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
395
  $paged = 1;
399
 
400
  if (!empty($paged) && !empty($per_page)) {
401
  $offset = ($paged - 1) * $per_page;
402
+ $query .= $wpdb->prepare(' LIMIT %d, %d', array($offset, $per_page));
403
  }
404
 
405
  $this->set_pagination_args(array(
406
  'total_items' => $total_items,
407
  'total_pages' => $total_pages,
408
+ 'per_page' => $per_page
409
  ));
410
 
411
+ $columns = $this->get_columns();
412
+ $hidden = array();
413
+ $sortable = $this->get_sortable_columns();
414
  $this->_column_headers = array($columns, $hidden, $sortable);
415
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
416
  $this->items = $wpdb->get_results($query);
417
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
418
+ if (isset($_GET['slmeta']) && ($_GET['slmeta'] === 'missing_information' || $_GET['slmeta'] === 'resizeimages')) {
419
  foreach ($this->items as $item) {
420
  $item->alt = get_post_meta($item->ID, '_wp_attachment_image_alt', true);
421
  }
424
 
425
  /**
426
  * Displays the search box.
427
+ *
428
+ * @return void
429
  */
430
  public function searchBox1()
431
  {
432
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
433
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
434
  return;
435
  }
436
 
437
+ $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : '';
438
  if (!empty($_REQUEST['orderby'])) {
439
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
440
  }
450
  if (!empty($_REQUEST['detached'])) {
451
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
452
  }
453
+ // phpcs:enable
454
  ?>
455
  <p class="search-box">
456
  <label>
463
  }
464
 
465
  /**
466
+ * Add filter month
467
+ *
468
+ * @param string $name Filter name
469
+ *
470
+ * @return void
471
  */
472
  public function monthsFilter($name)
473
  {
474
  global $wp_locale;
475
  $month_count = count($this->months);
476
+ if (!$month_count || (1 === (int) $month_count && 0 === (int) $this->months[0]->month)) {
477
  return;
478
  }
479
 
480
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
481
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
482
  ?>
483
+ <label for="filter-by-date"
484
+ class="screen-reader-text"><?php esc_html_e('Filter by date', 'wp-meta-seo'); ?></label>
485
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-date" class="metaseo-filter">
486
+ <option<?php selected($m, 0); ?> value="0"><?php esc_html_e('All dates', 'wp-meta-seo'); ?></option>
487
  <?php
488
  foreach ($this->months as $arc_row) {
489
+ if (0 === (int) $arc_row->year) {
490
  continue;
491
  }
492
 
493
  $month = zeroise($arc_row->month, 2);
494
+ $year = $arc_row->year;
495
  printf(
496
  "<option %s value='%s' >%s</option>\n",
497
+ selected($m, $year . '-' . $month, false),
498
+ esc_attr($arc_row->year . '-' . $month),
499
  sprintf(
500
+ esc_html__('%1$s %2$d', 'wp-meta-seo'),
501
+ esc_html($wp_locale->get_month($month)),
502
+ esc_html($year)
503
  )
504
  );
505
  }
510
  }
511
 
512
  /**
513
+ * Render meta Filter
514
+ *
515
+ * @param string $name Filter name
516
+ *
517
+ * @return void
518
  */
519
  public function metaFilter($name)
520
  {
521
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
522
  $m = isset($_REQUEST['slmeta']) ? $_REQUEST['slmeta'] : 0;
523
  ?>
524
  <label>
525
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-meta" class="meta_filter">
526
+ <option <?php selected($m, 'all') ?>
527
+ value="all"><?php esc_html_e('All images', 'wp-meta-seo') ?></option>
528
  <option <?php selected($m, 'missing_information') ?>
529
  value="missing_information">
530
+ <?php esc_html_e('Image with missing information', 'wp-meta-seo') ?>
531
  </option>
532
  <option <?php selected($m, 'resizeimages') ?>
533
+ value="resizeimages"><?php esc_html_e('HTML resized images', 'wp-meta-seo') ?></option>
534
  </select>
535
  </label>
536
  <input type="submit" name="filter_meta_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary"
537
+ value="<?php esc_attr_e('Filter', 'wp-meta-seo') ?>">
538
  <span class="spinner imgspinner"></span>
539
  <?php
540
  }
541
 
542
  /**
543
  * Generate the table rows
544
+ *
545
+ * @return void
546
  */
547
+ public function display_rows() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
548
  {
549
+ $records = $this->items;
550
+ $i = 0;
551
+ $alternate = '';
552
 
553
  list($columns, $hidden) = $this->get_column_info();
 
554
  if (!empty($records)) {
555
  foreach ($records as $rec) {
556
+ $alternate = 'alternate' === $alternate ? '' : 'alternate';
557
+ $i ++;
558
+ $classes = $alternate;
559
  $img_meta = get_post_meta($rec->ID, '_wp_attachment_metadata', true);
560
  if (empty($img_meta['file'])) {
561
  continue;
572
  } else {
573
  $img_name = $img_meta['file'];
574
  }
575
+ $type = substr($img_meta['file'], strrpos($img_meta['file'], '.'));
576
  $img_name = str_replace($type, '', $img_name);
577
 
578
  $upload_dir = wp_upload_dir();
579
+ $img_path = $upload_dir['basedir'] . '/' . $img_meta['file'];
580
  //Get the date that image was uploaded
581
+ $img_date = get_the_date('', $rec->ID);
582
  if (file_exists($img_path)) {
583
  if (is_readable($img_path)) {
584
  //Get image attributes including width and height
585
  list($img_width, $img_height, $img_type) = getimagesize($img_path);
586
  //Get image size
587
+ $size = filesize($img_path) / 1024;
588
+ if ($size > 1024) {
589
+ $img_size = ($size / 1024);
590
  $img_sizes = ' MB';
591
  } else {
592
+ $img_size = ($size);
593
  $img_sizes = ' KB';
594
  }
595
  $img_size = round($img_size, 1);
596
  } else {
597
+ $img_size = 0;
598
+ $img_sizes = ' MB';
599
+ $img_width = 0;
600
  $img_height = 0;
601
  }
602
 
603
+ echo '<tr id="' . esc_attr('record_' . $rec->ID) . '" class="' . esc_attr($classes) . '" >';
604
  foreach ($columns as $column_name => $column_display_name) {
605
+ $class = sprintf('class="%1$s column-%1$s"', esc_attr($column_name));
606
+ $style = '';
607
 
608
  if (in_array($column_name, $hidden)) {
609
  $style = ' style="display:none;"';
615
  case 'cb':
616
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
617
  echo '<input id="cb-select-1" class="metaseo_post" type="checkbox"
618
+ name="post[]" value="' . esc_attr($rec->ID) . '">';
619
  echo '</td>';
620
  break;
621
 
622
  case 'col_id':
623
  echo '<td class="col_id" colspan="1">';
624
+ echo esc_html($i);
625
  echo '</td>';
626
  break;
627
 
628
  case 'col_image':
629
  $img = sprintf(
630
+ '<img src="' . esc_url($thumb_url) . '" width="100px" height="100px" class="metaseo-image"
631
+ data-name="' . esc_attr($img_name . $type) . '" data-img-post-id="' . esc_attr($rec->ID) . '" />'
632
  );
633
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
634
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $img, $attributes);
635
  break;
636
 
637
  case 'col_image_name':
638
  $info = '<div class="img-name-wrapper">';
639
+ $info .= '<textarea name="' . esc_attr('name_image[' . $rec->ID . ']') . '"
640
  class="metaseo-img-meta metaseo-img-name" data-meta-type="change_image_name"
641
+ id="' . esc_attr('img-name-' . $rec->ID) . '" data-post-id="' . esc_attr($rec->ID) . '" rows="2"
642
+ data-extension="' . esc_attr($type) . '">' . esc_textarea($img_name) . '</textarea>
643
+ <span class="img_type">' . esc_html($type) . '</span>';
644
+ $info .= '<p>size: ' . esc_html($img_size . $img_sizes) . '</p>';
645
+ $info .= '<p>' . esc_html($img_width) . 'x' . esc_html($img_height) . '</p>';
646
+ $info .= '<p>' . esc_html($img_date) . '</p>';
647
  $info .= '<span class="saved-info" style="position:relative">
648
  <span class="spinner"></span>
649
  </span>';
650
  $info .= '</div>';
651
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
652
  echo sprintf('<td %2$s colspan="4">%1$s</td>', $info, $attributes);
653
  break;
654
 
655
  case 'col_image_info':
656
+ $info = '<div class="opt-info" id="' . esc_attr('opt-info-' . $rec->ID) . '"></div>';
657
  $info .= '<span class="metaseo-loading"></span>';
658
  $info .= '
659
  <div class="popup-bg"></div>
661
  <span class="popup-close" title="Close">x</span>
662
  <div class="popup-content"></div>
663
  </div>';
664
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
665
+ echo sprintf('<td %2$s colspan="5" style="position:relative">%1$s</td>', $info, $attributes);
 
 
 
 
666
  break;
667
 
668
  case 'col_image_alternative':
669
+ $input = '<textarea name="' . esc_attr('img_alternative[' . $rec->ID . ']') . '" class="metaseo-img-meta"
670
+ data-meta-type="alt_text" id="' . esc_attr('img-alt-' . $rec->ID) . '" data-post-id="' . esc_attr($rec->ID) . '"
671
+ rows="2">' . esc_textarea($rec->alt) . '</textarea>';
672
  $input .= ('<span class="saved-info" style="position:relative">
673
  <span class="spinner"></span>
674
  </span>');
675
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
676
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
677
  break;
678
 
679
  case 'col_image_title':
680
+ $input = '<textarea name="' . esc_attr('img_title[' . $rec->ID . ']') . '" class="metaseo-img-meta"
681
+ data-meta-type="image_title" id="' . esc_attr('img-title-' . $rec->ID) . '" data-post-id="' . esc_attr($rec->ID) . '"
682
+ rows="2">' . esc_textarea($rec->title) . '</textarea>';
683
  $input .= ('<span class="saved-info" style="position:relative">
684
  <span class="spinner"></span>
685
  </span>');
686
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
687
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
688
  break;
689
 
690
  case 'col_image_legend':
691
+ $input = '<textarea name="' . esc_attr('img_legend[' . $rec->ID . ']') . '" class="metaseo-img-meta"
692
+ data-meta-type="image_caption" id="' . esc_attr('img-legend-' . $rec->ID) . '" data-post-id="' . esc_attr($rec->ID) . '"
693
+ rows="2">' . esc_textarea($rec->legend) . '</textarea>';
694
  $input .= '<span class="saved-info" style="position:relative">
695
  <span class="spinner"></span>
696
  </span>';
697
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
698
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
699
  break;
700
 
701
  case 'col_image_desc':
702
+ $input = '<textarea name="' . esc_attr('img_desc[' . $rec->ID . ']') . '" class="metaseo-img-meta"
703
+ data-meta-type="image_description" id="' . esc_attr('img-desc-' . $rec->ID) . '" data-post-id="' . esc_attr($rec->ID) . '"
704
+ rows="2">' . esc_textarea($rec->des) . '</textarea>';
705
  $input .= ('<span class="saved-info" style="position:relative">
706
  <span class="spinner"></span>
707
  </span>');
708
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
709
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
710
  break;
711
  }
719
 
720
  /**
721
  * Add a size for image
722
+ *
723
+ * @param array $response Response
724
+ * @param object $attachment Current attachment
725
+ *
726
  * @return mixed
727
  */
728
  public static function addMoreAttachmentSizes($response, $attachment)
740
 
741
  /**
742
  * Add to the list of image sizes that are available to administrators in the WordPress Media Library.
743
+ *
744
+ * @param array $sizes List sizes
745
+ *
746
  * @return array
747
  */
748
  public static function addMoreAttachmentSizesChoose($sizes)
749
  {
750
  global $wpdb;
751
+ $imgSizes = $wpdb->get_results($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key = %s AND meta_value <> ""', array('_metaseo_sizes_optional')));
 
 
 
752
  if (!empty($imgSizes)) {
753
  foreach ($imgSizes as $metaseo_img_sizes) {
754
+ $metaseo_img_sizes = unserialize($metaseo_img_sizes->meta_value);
755
  if (!empty($metaseo_img_sizes)) {
756
  foreach ($metaseo_img_sizes as $key => $size) {
757
  add_image_size($key, $size['width'], $size['height'], false);
783
 
784
  /**
785
  * Display page fix meta list
786
+ *
787
+ * @param integer $img_post_id Image id
788
+ * @param array $posts List posts
789
+ * @param string $meta_counter Meta counter
790
+ * @param string $p String
791
+ * @param string $im String
792
+ *
793
+ * @return void
794
  */
795
+ private static function display_fix_metas_list($img_post_id, $posts, $meta_counter, $p, $im) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- Method name have relationship in database
796
  {
797
  if ($meta_counter) {
798
  $header = sprintf(
799
+ __('We found %s image with missing Title', 'wp-meta-seo'),
800
+ esc_html($meta_counter . $im . $p)
801
  );
802
  } else {
803
+ $header = __('We found 0 image with missing Title', 'wp-meta-seo');
804
  }
805
 
806
  //Get default meta information of the image
807
  $img_post = get_post($img_post_id);
 
 
808
  ?>
809
+ <h3 class="content-header"><?php echo esc_html($header) ?></h3>
810
  <div class="content-box">
811
  <table class="wp-list-table widefat fixed posts">
812
  <thead></thead>
815
  <?php if (count($posts) < 1) : ?>
816
  <tr>
817
  <td colspan="10" style="height:95%">
818
+ <?php esc_html_e('This image has still not been inserted in any post!', 'wp-meta-seo') ?>
819
  </td>
820
  </tr>
821
  <?php else : ?>
822
  <tr class="metaseo-border-bottom">
823
+ <td colspan="1"><?php esc_html_e('ID', 'wp-meta-seo') ?></td>
824
+ <td colspan="2"><?php esc_html_e('Post title', 'wp-meta-seo') ?></td>
825
+ <td colspan="2"><?php esc_html_e('Image', 'wp-meta-seo') ?></td>
826
+ <td colspan="5"><?php esc_html_e('Image information', 'wp-meta-seo') ?></td>
827
  </tr>
828
  <?php foreach ($posts as $post) : ?>
829
  <?php foreach (wpmsUtf8($post['meta'], 'decode') as $k => $meta) : ?>
830
  <?php
831
+ $alternate = 'alternate' === $alternate ? '' : 'alternate';
832
  $file_name = substr($meta['img_src'], strrpos($meta['img_src'], '/') + 1);
833
  ?>
834
+ <tr class="<?php echo esc_html($alternate) ?>">
835
+ <td colspan="1"><?php echo esc_html($post['ID']) ?></td>
836
  <td colspan="2">
837
+ <p><?php echo esc_html($post['title']) ?></p>
838
  </td>
839
  <td colspan="2">
840
  <div class="metaseo-img-wrapper">
841
+ <img src="<?php echo esc_html($meta['img_src']) ?>"/>
842
  </div>
843
  </td>
844
  <td colspan="5">
849
  foreach ($specialChr as $chr) {
850
  $value = str_replace($chr, htmlentities2($chr), $value);
851
  }
852
+ if ($type === 'alt') {
853
+ $lb = esc_html__('Image Alt', 'wp-meta-seo');
854
  } else {
855
+ $lb = esc_html__('Image Title', 'wp-meta-seo');
856
  }
857
+ if ($value === '') {
858
+ $placeholder = ucfirst($type) . esc_html__(' is empty', 'wp-meta-seo');
859
  } else {
860
  $placeholder = '';
861
  }
862
  ?>
863
  <div>
864
+ <label class="metaseo-img-lb"><?php echo esc_html($lb); ?></label>
865
  <input type="text" value="<?php echo esc_attr($value) ?>"
866
+ id="<?php echo esc_attr('metaseo-img-' . $type . '-' . $post['ID']) ?>"
867
+ class="<?php echo esc_attr('metaseo-fix-meta metaseo-img-' . $type) ?>"
868
  data-meta-key="_metaseo_fix_metas"
869
+ data-post-id="<?php echo esc_attr($post['ID']) ?>"
870
+ data-img-post-id="<?php echo esc_attr($img_post_id) ?>"
871
+ data-meta-type="<?php echo esc_attr($type) ?>"
872
+ data-meta-order="<?php echo esc_attr($k) ?>"
873
+ data-file-name="<?php echo esc_attr($file_name); ?>"
874
+ placeholder="<?php echo esc_attr($placeholder) ?>"
875
  onfocus="metaseo_fix_meta(this);" onblur="updateInputBlur(this)"
876
  onkeydown="return checkeyCode(event)"/>
877
  </div>
878
 
879
+ <?php if (trim($$type) !== '' && trim($$type) !== $value) : ?>
880
  <a class="meta-default wpmsbtn wpmsbtn_small" href="#"
881
  data-default-value="<?php echo esc_attr($$type) ?>"
882
  title="Add to input box"
883
+ onclick="add_meta_default(this)"><?php esc_html_e('Copy ', 'wp-meta-seo');
884
+ echo esc_html($lb) ?></a>
885
+ <span class="img_seo_type"><?php echo esc_html($$type); ?></span>
886
  <?php endif ?>
887
  <span class="spinner"></span>
888
  </div>
903
 
904
  /**
905
  * Display page resize image list
906
+ *
907
+ * @param integer $img_post_id Image id
908
+ * @param array $posts List posts
909
+ * @param string $img_counter Image counter
910
+ * @param string $p String
911
+ * @param string $im String
912
+ *
913
+ * @return void
914
  */
915
+ private static function display_resize_image_list($img_post_id, $posts, $img_counter, $p, $im) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- Method name have relationship in database
916
  {
 
 
917
  ?>
918
+ <h3 class="content-header"><?php esc_html_e('We found some images you can resize...', 'wp-meta-seo') ?></h3>
919
  <div class="content-box">
920
  <table class="wp-list-table widefat fixed posts">
921
  <thead></thead>
922
  <tbody>
923
  <tr class="metaseo-border-bottom">
924
+ <td colspan="1"><?php esc_html_e('ID', 'wp-meta-seo') ?></td>
925
+ <td colspan="3"><?php esc_html_e('Title', 'wp-meta-seo') ?></td>
926
+ <td colspan="4"><?php esc_html_e('Current Images', 'wp-meta-seo') ?></td>
927
+ <td colspan="2" class="metaseo-action"><?php esc_html_e('Action', 'wp-meta-seo') ?></td>
928
+ <td colspan="4"><?php esc_html_e('After Replacing', 'wp-meta-seo') ?></td>
929
  </tr>
930
  <?php
931
+ $alternate = '';
932
  foreach ($posts as $post) :
933
  ?>
934
+ <?php $alternate = 'alternate' === $alternate ? '' : 'alternate'; ?>
935
+ <tr class="<?php echo esc_attr($alternate) ?>">
936
+ <td colspan="1"><?php echo esc_html($post['ID']) ?></td>
937
  <td colspan="3">
938
+ <p><?php echo esc_html($post['title']) ?></p>
939
  </td>
940
  <td colspan="4" style="overflow: hidden;">
941
  <?php foreach ($post['img_before_optm'] as $key => $src) : ?>
942
  <div class="metaseo-img-wrapper">
943
  <div class="metaseo-img">
944
+ <img width="<?php echo esc_attr($src['width']); ?>"
945
+ src="<?php echo esc_url($src['src']) ?>"/>
946
  <div class="img-choosen">
947
 
948
  <div class="pure-checkbox">
949
+ <input id="<?php echo esc_attr('checkin-' . $post['ID']) ?>" checked
950
+ type="checkbox"
951
+ class="<?php echo esc_attr('metaseo-checkin checkin-' . $post['ID']) ?>"
952
+ value="<?php echo esc_attr($key) ?>"
953
  onclick="uncheck(this)">
954
+ <label for="<?php echo esc_attr('checkin-' . $post['ID']) ?>"></label>
955
  </div>
956
  </div>
957
  <p class="metaseo-msg"></p>
958
  </div>
959
  <div class="dimension">
960
+ <?php esc_html_e('Orig.', 'wp-meta-seo') ?> <br>
961
+ <span><?php esc_html_e('Dimensions', 'wp-meta-seo') ?></span>: <?php echo esc_html($src['dimension']) ?>
962
+ <br>
963
+ <span><?php esc_html_e('File size', 'wp-meta-seo') ?></span>: <?php echo esc_html($src['size']) . ' ' . esc_html($src['sizes']) ?>
964
  </div>
965
  </div>
966
  <?php endforeach ?>
968
  <td colspan="2" class="metaseo-action">
969
  <a href="javascript:void(0);"
970
  class="metaseo-optimize wpmsbtn wpmsbtn_small wpmsbtn_secondary"
971
+ data-img-post-id="<?php echo esc_attr($img_post_id) ?>"
972
+ data-post-id="<?php echo esc_attr($post['ID']) ?>"
973
+ onclick="optimize_imgs(this)"><?php esc_html_e('Replace?', 'wp-meta-seo') ?></a>
974
  <span class="optimizing spinner"></span>
975
  </td>
976
  <td colspan="4">
977
  <?php foreach ($post['img_after_optm'] as $src) : ?>
978
  <div class="metaseo-img-wrapper">
979
  <div class="metaseo-img">
980
+ <img src="<?php echo esc_url($src['src']) ?>"/>
981
  </div>
982
  <div class="dimension">
983
+ <?php esc_html_e('OPT', 'wp-meta-seo') ?> <br>
984
+ <span><?php esc_html_e('Dimensions', 'wp-meta-seo') ?></span>: <?php echo esc_html($src['dimension']) ?>
985
+ <br>
986
+ <span><?php esc_html_e('File size', 'wp-meta-seo') ?></span>: <?php echo esc_html($src['size']) . ' ' . esc_html($src['sizes']) ?>
987
  </div>
988
  </div>
989
  <?php endforeach ?>
996
  <td colspan="2">
997
  <a href="javascript:void(0);" id="metaseo-replace-all" class="wpmsbtn wpmsbtn_small"
998
  onclick="optimize_imgs_group(this)">
999
+ <?php esc_html_e('Replace All', 'wp-meta-seo') ?>
1000
  </a>
1001
  <span class="optimizing spinner"></span>
1002
  </td>
1010
  <?php
1011
  }
1012
 
1013
+ /**
1014
  * Ajax optimize image and update content
1015
+ *
1016
+ * @return void
1017
  */
1018
  public static function optimizeImages()
1019
  {
1020
+ if (empty($_POST['wpms_nonce'])
1021
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1022
+ die();
1023
+ }
1024
+
1025
  if (!empty($_POST['post_id']) && !empty($_POST['img_post_id'])) {
1026
+ $post_id = intval($_POST['post_id']);
1027
  $img_post_id = intval($_POST['img_post_id']);
1028
  if (!empty($_POST['img_exclude'])) {
1029
  $img_exclude = $_POST['img_exclude'];
1035
  } else {
1036
  $ret = array(
1037
  'success' => false,
1038
+ 'msg' => esc_html__('The post is not existed, please choose one another!', 'wp-meta-seo')
1039
  );
1040
  }
1041
 
1043
  wp_die();
1044
  }
1045
 
1046
+ /**
1047
  * Retrieves a modified URL query string.
1048
+ *
1049
+ * @return void
1050
  */
1051
  public function processAction()
1052
  {
1053
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
1054
+ $redirect = false;
1055
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
1056
+ if (isset($_POST['search']) && $_POST['search'] === 'Search') {
1057
  $current_url = add_query_arg(
1058
  array(
1059
+ 'search' => 'Search',
1060
+ 'txtkeyword' => urlencode(stripslashes($_POST['txtkeyword']))
1061
+ ),
1062
  $current_url
1063
  );
1064
+ $redirect = true;
1065
  }
1066
 
1067
  if (isset($_POST['sldate'])) {
1068
+ $current_url = add_query_arg(array('sldate' => $_POST['sldate']), $current_url);
1069
+ $redirect = true;
1070
  }
1071
 
1072
  if (isset($_POST['slmeta'])) {
1073
+ $current_url = add_query_arg(array('slmeta' => $_POST['slmeta']), $current_url);
1074
+ $redirect = true;
1075
  }
1076
 
1077
  if (!empty($_POST['paged'])) {
1078
+ $current_url = add_query_arg(array('paged' => intval($_POST['paged'])), $current_url);
1079
+ $redirect = true;
1080
  }
1081
 
1082
  if (!empty($_POST['metaseo_imgs_per_page'])) {
1083
  $current_url = add_query_arg(
1084
  array(
1085
+ 'metaseo_imgs_per_page' => intval($_POST['metaseo_imgs_per_page'])
1086
  ),
1087
  $current_url
1088
  );
1089
+ $redirect = true;
1090
  }
1091
 
1092
  if (!empty($_POST['wpms_lang_list'])) {
1093
+ $current_url = add_query_arg(array('wpms_lang_list' => $_POST['wpms_lang_list']), $current_url);
1094
+ $redirect = true;
1095
  }
1096
+ // phpcs:enable
1097
+ if ($redirect) {
 
1098
  wp_redirect($current_url);
1099
  ob_end_flush();
1100
  exit();
1103
 
1104
  /**
1105
  * Ajax get list of posts contain this image and its clones
1106
+ *
1107
+ * @return void
1108
  */
1109
  public static function loadPostsCallback()
1110
  {
1111
+ if (empty($_POST['wpms_nonce'])
1112
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1113
+ die();
1114
+ }
1115
+
1116
+ $_POST = stripslashes_deep($_POST);
1117
  $post_id = intval($_POST['post_id']);
1118
+ $img = trim($_POST['img_name']);
1119
  $opt_key = strtolower(trim($_POST['opt_key']));
1120
  if ($post_id && !empty($img) && !empty($opt_key)) {
1121
+ $fn = 'display_' . $opt_key . '_list';
1122
  if (method_exists('MetaSeoImageListTable', $fn)) {
1123
  //Get list of posts contain this image and its clones
1124
  $posts = ImageHelper::getPostList($post_id, $opt_key);
1127
  $img_counter = 0;
1128
  //Now the time to resize the images
1129
  if ($opt_key === 'resize_image') {
1130
+ $upload_dir = wp_upload_dir();
1131
  $metaseo_sizes_optional = get_post_meta(
1132
  $post_id,
1133
  '_metaseo_sizes_optional',
1140
 
1141
  foreach ($posts as &$post) {
1142
  foreach ($post['img_after_optm'] as &$img) {
1143
+ $img_counter ++;
1144
  $destination = $upload_dir['basedir'] . '/' . $img['path'];
1145
+ $iresize = ImageHelper::IResize(
1146
  $img['src_origin'],
1147
  $img['width'],
1148
  $img['height'],
1152
  if ($iresize) {
1153
  $size = (filesize($destination) / 1024);
1154
  if ($size > 1024) {
1155
+ $size = $size / 1024;
1156
  $sizes = 'MB';
1157
  } else {
1158
  $sizes = 'KB';
1159
  }
1160
+ $size = round($size, 1);
1161
+ $img['size'] = $size;
1162
  $img['sizes'] = $sizes;
1163
  }
1164
 
1165
  $kpart = ImageHelper::IGetPart($img['path']);
1166
+ $key = preg_replace('/\-(\d+)x(\d+)$/i', '-metaseo${1}${2}', $kpart->name);
1167
+ $key = strtolower($key);
1168
+ $file = substr($img['path'], strrpos($img['path'], '/') + 1);
1169
  if (!in_array($key, array_keys($metaseo_sizes_optional))) {
1170
  $metaseo_sizes_optional[$key] = array(
1171
+ 'url' => $img['src'],
1172
+ 'width' => $img['width'],
1173
+ 'height' => $img['height'],
1174
  'orientation' => 'landscape',
1175
  );
1176
  }
1177
 
1178
  if (!isset($attachment_meta_data['sizes'][$key])) {
1179
  $attachment_meta_data['sizes'][$key] = array(
1180
+ 'file' => $file,
1181
+ 'width' => $img['width'],
1182
+ 'height' => $img['height'],
1183
  'mime-type' => 'image/jpeg'
1184
  );
1185
  }
1190
  update_post_meta($post_id, '_metaseo_sizes_optional', $metaseo_sizes_optional);
1191
  } elseif ($opt_key === 'fix_metas') {
1192
  $toEdit = false;
1193
+ $pIDs = array();
1194
  foreach ($posts as $ID => &$post) {
1195
  $img_counter += count($post['meta']);
1196
  foreach ($post['meta'] as $order => $meta) {
1197
+ if ($meta['type']['alt'] === '') {
1198
  $toEdit = true;
1199
  }
1200
 
1201
+ if ($meta['type']['alt'] !== '') {
1202
  $pIDs[$ID][] = $order;
1203
  }
1204
  }
1209
  foreach ($orders as $order) {
1210
  unset($posts[$ID]['meta'][$order]);
1211
  if ($img_counter > 0) {
1212
+ $img_counter --;
1213
  }
1214
  }
1215
 
1229
  $p = '';
1230
  }
1231
 
1232
+ if (isset($img_counter) && $img_counter > 1) {
1233
  $im = ' images ';
1234
  } else {
1235
  if (!isset($img_counter)) {
1246
 
1247
  /**
1248
  * Scan post to find image good and not good
1249
+ *
1250
+ * @return void
1251
  */
1252
  public static function scanPostsCallback()
1253
  {
1254
+ if (empty($_POST['wpms_nonce'])
1255
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1256
+ die();
1257
+ }
1258
+
1259
  $_POST = stripslashes_deep($_POST);
1260
+ $imgs = $_POST['imgs'];
1261
  if (!empty($imgs)) {
1262
  if (!is_array($imgs)) {
1263
  $ret['success'] = false;
1264
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1265
  wp_send_json($ret);
1266
  }
1267
 
1268
+ $_imgs = array();
1269
  $_imgs[trim($imgs['name'])] = $imgs['img_post_id'];
1270
  unset($imgs);
1271
 
1272
  if (!count($_imgs)) {
1273
  $ret['success'] = false;
1274
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1275
  wp_send_json($ret);
1276
  }
1277
 
1278
+ $msg = ImageHelper::IScanPosts($_imgs, true);
1279
+ $ret['msg'] = $msg;
1280
  $ret['success'] = true;
1281
 
1282
+ if (isset($_POST['imgs']['type']) && $_POST['imgs']['type'] === 'update_meta') {
1283
  if ($ret['msg'][$_POST['imgs']['img_post_id']]['imNotGood']['warning']) {
1284
  update_post_meta($_POST['imgs']['img_post_id'], 'wpms_missing_information', 1);
1285
  } else {
1293
  }
1294
  } else {
1295
  $ret['success'] = false;
1296
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1297
  }
1298
 
1299
  wp_send_json($ret);
1301
 
1302
  /**
1303
  * Ajax update image meta
1304
+ *
1305
+ * @return void
1306
  */
1307
  public static function updateMetaCallback()
1308
  {
1309
+ if (empty($_POST['wpms_nonce'])
1310
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1311
+ die();
1312
+ }
1313
+
1314
+ $response = new stdClass();
1315
  $response->updated = false;
1316
  if (!empty($_POST['addition']['meta_key'])) {
1317
  self::updateImgMetaCallback($_POST['addition'], true);
1318
  }
1319
 
1320
+ if (!empty($_POST['meta_type']) && $_POST['meta_type'] === 'change_image_name') {
1321
  self::updateImageNameCallback();
1322
  }
1323
 
1324
  if (!empty($_POST['meta_type']) && !empty($_POST['post_id'])) {
1325
  $meta_type = strtolower(trim($_POST['meta_type']));
1326
+ $post_id = intval($_POST['post_id']);
1327
 
1328
  if (!isset($_POST['meta_value'])) {
1329
  $meta_value = '';
1342
  $label = ucfirst($label);
1343
 
1344
  $aliases = array(
1345
+ 'image_title' => 'post_title',
1346
+ 'image_caption' => 'post_excerpt',
1347
  'image_description' => 'post_content',
1348
+ 'alt_text' => '_wp_attachment_image_alt'
1349
  );
1350
 
1351
+ if ($meta_type !== 'alt_text') {
1352
  $data = array('ID' => $post_id, $aliases[$meta_type] => $meta_value);
1353
  if (wp_update_post($data)) {
1354
  $response->updated = true;
1355
+ $response->msg = $label . esc_html__(' was saved', 'wp-meta-seo');
1356
  }
1357
  } else {
1358
  update_post_meta($post_id, $aliases[$meta_type], $meta_value);
1359
  $response->updated = true;
1360
+ $response->msg = $label . esc_html__(' was saved', 'wp-meta-seo');
1361
  }
1362
 
1363
+ if ($meta_type === 'alt_text') {
1364
  $settings = get_option('_metaseo_settings');
1365
  if (!isset($settings['metaseo_overridemeta']) || (!empty($settings['metaseo_overridemeta'])
1366
+ && (int) $settings['metaseo_overridemeta'] === 1)) {
1367
  // call function auto override in content
1368
 
1369
  self::autoUpdatePostContent($post_id, $meta_type, $meta_value);
1370
+ $response->type = 'auto_override';
1371
+ $response->pid = $post_id;
1372
  $response->imgname = $_POST['img_name'];
1373
  }
1374
  }
1375
  } else {
1376
+ $response->msg = esc_html__('There is a problem when update image meta!', 'wp-meta-seo');
1377
  }
1378
 
1379
  echo json_encode($response);
1381
  }
1382
 
1383
  /**
1384
+ * Function auto override in content
1385
+ *
1386
+ * @param integer $post_id Post id
1387
+ * @param string $meta_type Meta key
1388
+ * @param string $meta_value Meta value
1389
+ *
1390
+ * @return void
1391
  */
1392
  public static function autoUpdatePostContent($post_id, $meta_type, $meta_value)
1393
  {
1394
+ if (empty($_POST['wpms_nonce'])
1395
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1396
+ die();
1397
+ }
1398
+
1399
  $_POST = stripslashes_deep($_POST);
1400
+ $img = trim($_POST['img_name']);
1401
  if ($post_id && !empty($img)) {
1402
+ $fn = 'display_fix_metas_list';
1403
  if (method_exists('MetaSeoImageListTable', $fn)) {
1404
  //Get list of posts contain this image and its clones
1405
  $posts = ImageHelper::getPostList($post_id, 'fix_metas');
1407
  $img_counter = 0;
1408
  //Now the time to resize the images
1409
  $toEdit = false;
1410
+ $pIDs = array();
1411
  foreach ($posts as $ID => &$post) {
1412
  $img_counter += count($post['meta']);
1413
  foreach ($post['meta'] as $order => $meta) {
1414
+ if ($meta['type']['alt'] === '' || $meta['type']['title'] === '') {
1415
  $toEdit = true;
1416
  }
1417
 
1418
+ if ($meta['type']['alt'] !== '' && $meta['type']['title'] !== '') {
1419
  $pIDs[$ID][] = $order;
1420
  }
1421
  }
1426
  foreach ($orders as $order) {
1427
  unset($posts[$ID]['meta'][$order]);
1428
  if ($img_counter > 0) {
1429
+ $img_counter --;
1430
  }
1431
  }
1432
 
1442
  if (!empty($posts)) {
1443
  foreach ($posts as $p) {
1444
  foreach ($p['meta'] as $k => $meta) {
1445
+ $addition = array();
1446
  $addition['meta_key'] = '_metaseo_fix_metas';
1447
+ if ($meta_type === 'image_title') {
1448
  $addition['meta_type'] = 'title';
1449
  } else {
1450
  $addition['meta_type'] = 'alt';
1451
  }
1452
 
1453
+ $addition['meta_value'] = $meta_value;
1454
+ $addition['post_id'] = $p['ID'];
1455
+ $addition['meta_order'] = $k;
1456
  $addition['img_post_id'] = $post_id;
1457
  self::updateImgMetaCallback($addition, false);
1458
  }
1462
 
1463
  /**
1464
  * Update image name
1465
+ *
1466
+ * @return void
1467
  */
1468
  public static function updateImageNameCallback()
1469
  {
1470
+ if (empty($_POST['wpms_nonce'])
1471
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1472
+ die();
1473
+ }
1474
+
1475
  global $wpdb;
1476
+ $postID = (int) $_POST['post_id'];
1477
+ $name = trim($_POST['meta_value']);
1478
+ $iname = preg_replace('/(\s{1,})/', '-', $name);
1479
+ $img_meta = get_post_meta($postID, '_wp_attachment_metadata', true);
1480
+ $linkold = $img_meta['file'];
1481
+ $response = new stdClass();
1482
  $response->updated = false;
1483
+ $response->msg = esc_html__('There is a problem when update image name', 'wp-meta-seo');
1484
 
1485
  $upload_dirs = wp_upload_dir();
1486
+ $upload_dir = $upload_dirs['basedir'];
1487
+ $oldpart = ImageHelper::IGetPart($linkold);
1488
+ $old_name = $oldpart->name;
1489
 
1490
+ if ($name !== '') {
1491
+ if (file_exists($upload_dir . '/' . $linkold)) {
1492
  $newFileName = $oldpart->base_path . $iname . $oldpart->ext;
1493
  // check file not exist
1494
+ if (!file_exists($upload_dir . '/' . $newFileName)) {
1495
+ if (rename($upload_dir . '/' . $linkold, $upload_dir . '/' . $newFileName)) {
1496
  $post_title = get_the_title($postID);
1497
+ $where = array('ID' => $postID);
1498
+ $guid = $upload_dirs['baseurl'] . '/' . $newFileName;
1499
  if (!$post_title) {
1500
  $id = $wpdb->update(
1501
  $wpdb->posts,
1502
  array(
1503
+ 'guid' => $guid,
1504
  'post_title' => $name,
1505
+ 'post_name' => strtolower($iname)
1506
  ),
1507
  $where
1508
  );
1511
  }
1512
 
1513
  if ($id) {
1514
+ $attached_metadata = get_post_meta($postID, '_wp_attachment_metadata', true);
1515
+ $attached_metadata['file'] = $newFileName;
1516
 
1517
  $images_to_rename = array($oldpart->name . $oldpart->ext => $iname . $oldpart->ext);
1518
  foreach ($attached_metadata['sizes'] as &$clone) {
1519
  $clone_file_new = ImageHelper::IReplace($iname, $clone['file']);
1520
+ $clone_path = $upload_dir . '/' . $oldpart->base_path . $clone['file'];
1521
  $clone_path_new = $upload_dir . '/' . $oldpart->base_path . $clone_file_new;
1522
 
1523
+ if (rename($clone_path, $clone_path_new)) {
1524
  $images_to_rename[$clone['file']] = $clone_file_new;
1525
+ $clone['file'] = $clone_file_new;
1526
  }
1527
  }
1528
 
1529
  $metadats = get_post_meta($postID, '_wp_attachment_metadata', true);
1530
+ $sizes = $metadats['sizes'];
1531
 
1532
  // get list image url and image thumbnail url
1533
+ $list_thum_url = array();
1534
+ $imageUrl = wp_get_attachment_url($postID);
1535
  $list_thum_url[] = $imageUrl;
1536
  foreach ($sizes as $key => $size) {
1537
+ $thum_url = wp_get_attachment_image_src($postID, $key);
1538
  $list_thum_url[] = $thum_url[0];
1539
  }
1540
 
1543
 
1544
  $i = 0;
1545
  foreach ($list_thum_url as $url) {
1546
+ $i ++;
1547
+ if ((int) $i === count($list_thum_url)) {
1548
+ $w .= $wpdb->prepare(' post_content LIKE %s', array('%' . $url . '%'));
1549
  } else {
1550
+ $w .= $wpdb->prepare(' post_content LIKE %s OR', array('%' . $url . '%'));
1551
  }
1552
  }
1553
 
1554
+ $w .= ')';
1555
+ $where = array();
1556
  $where[] = "(`post_type` = 'post' or `post_type` = 'page')";
1557
  $where[] = "post_content LIKE '%<img%>%'";
1558
  $where[] = $w;
 
 
 
1559
  // query post
1560
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
1561
+ $posts = $wpdb->get_results('SELECT ID, post_title, post_content, post_type, post_date FROM ' . $wpdb->posts . ' WHERE ' . implode(' AND ', $where) . ' ORDER BY ID');
1562
+ $imgs = array($old_name . $oldpart->ext => $postID);
1563
  $posts_contain_img = array();
1564
  foreach ($posts as $post) {
1565
  $ifound = ImageHelper::IScan($post->post_content, $imgs);
1570
 
1571
  // update post
1572
  foreach ($posts_contain_img as $id) {
1573
+ $post = get_post($id);
1574
+ if ($post) {
1575
  foreach ($images_to_rename as $src_before => $src_after) {
1576
+ $src_before = '/' . $src_before;
1577
+ $src_after = '/' . $src_after;
1578
  $post->post_content = str_replace($src_before, $src_after, $post->post_content);
1579
  }
1580
  remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1581
  wp_update_post(
1582
  array(
1583
+ 'ID' => $post->ID,
1584
+ 'post_content' => $post->post_content
1585
+ )
1586
  );
1587
 
1588
  unset($post, $posts_contain_img);
1590
  }
1591
  }
1592
 
1593
+ // Update Image registered to Attachment sizes on Add media page
1594
  $sizeOptional = get_post_meta($postID, '_metaseo_sizes_optional', true);
1595
+ $newOptional = array();
1596
  if (!empty($sizeOptional) && is_array($sizeOptional)) {
1597
  foreach ($sizeOptional as $key => $detail) {
1598
+ $pattern = '/^' . strtolower($old_name) . '(-metaseo\d+)$/';
1599
+ $key = preg_replace($pattern, strtolower($iname) . '${1}', $key);
1600
+ $detail['url'] = ImageHelper::IReplace($iname, $detail['url']);
1601
  $newOptional[$key] = $detail;
1602
  }
1603
 
1612
  update_post_meta($postID, '_wp_attachment_metadata', $attached_metadata);
1613
 
1614
  $response->updated = true;
1615
+ $response->msg = esc_html__('Image name was changed', 'wp-meta-seo');
1616
  } else {
1617
  $response->iname = $old_name;
1618
+ $response->msg = esc_html__('There is a problem when update image name', 'wp-meta-seo');
1619
  }
1620
  }
1621
  } else {
1622
+ $response->msg = esc_html__('File name already given!', 'wp-meta-seo');
1623
  $response->iname = $old_name;
1624
  }
1625
  } else {
1626
  $response->iname = $old_name;
1627
+ $response->msg = esc_html__('File is not existed', 'wp-meta-seo');
1628
  }
1629
  } else {
1630
  $response->iname = $old_name;
1631
+ $response->msg = esc_html__('Should not be empty', 'wp-meta-seo');
1632
  }
1633
  echo json_encode($response);
1634
  wp_die();
1636
 
1637
  /**
1638
  * Update image meta
1639
+ *
1640
+ * @param array $wpmspost Post infos
1641
+ * @param boolean $return Return
1642
+ *
1643
+ * @return void
1644
  */
1645
  public static function updateImgMetaCallback($wpmspost, $return = true)
1646
  {
1647
+ $response = new stdClass();
1648
  $response->updated = false;
1649
 
1650
  foreach ($wpmspost as $k => $v) {
1651
  if (!$v && !in_array($k, array('meta_value', 'meta_order'))) {
1652
+ $response->msg = esc_html__('There is a problem when update image meta!', 'wp-meta-seo');
1653
 
1654
  echo json_encode($response);
1655
  wp_die();
1656
  }
1657
  }
1658
 
1659
+ $meta_key = strtolower(trim($wpmspost['meta_key']));
1660
+ $meta_type = strtolower(trim($wpmspost['meta_type']));
1661
+ $meta_value = htmlspecialchars(trim($wpmspost['meta_value']));
1662
+ $meta_order = intval($wpmspost['meta_order']);
1663
  $img_post_id = intval($wpmspost['img_post_id']);
1664
+ $post_id = intval($wpmspost['post_id']);
1665
+ $meta = get_post_meta($img_post_id, $meta_key, true);
1666
  //Update new value for meta info of this image in wp_postmeta
1667
  $meta[$post_id]['meta'][$meta_order]['type'][$meta_type] = wpmsUtf8($meta_value);
1668
  update_post_meta($img_post_id, $meta_key, $meta);
1669
 
1670
  //Then we must update this meta info in the appropriate post content
1671
+ $post = get_post($post_id);
1672
+ if (!$post) {
1673
+ $response->msg = esc_html__('The post has been deleted before, please check again!', 'wp-meta-seo');
1674
  } else {
1675
  if ($post->post_content !== '') {
1676
  //Split content part that do not contain img tag
1715
 
1716
  //Update content of this post.
1717
  if (!wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content))) {
1718
+ $response->msg = esc_html__('The post haven\'t been updated, please check again!', 'wp-meta-seo');
1719
  } else {
1720
  update_option('wpms_last_update_post', time());
1721
  $response->updated = true;
1722
+ $response->msg = ucfirst($meta_type) . esc_html__(' was saved', 'wp-meta-seo');
1723
  }
1724
  } else {
1725
+ $response->msg = esc_html__('This image has been removed from
1726
  the post, please check again!', 'wp-meta-seo');
1727
  }
1728
  } else {
1729
+ $response->msg = esc_html__('Content of the post is empty, please check again', 'wp-meta-seo');
1730
  }
1731
  }
1732
 
1733
+ if ($return) {
1734
  echo json_encode($response);
1735
  wp_die();
1736
  }
1738
 
1739
  /**
1740
  * Scan image metas
1741
+ *
1742
+ * @return void
1743
  */
1744
  public static function imageScanMeta()
1745
  {
1746
+ if (empty($_POST['wpms_nonce'])
1747
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
1748
+ die();
1749
+ }
1750
+
1751
  if (!current_user_can('manage_options')) {
1752
  wp_send_json(false);
1753
  }
1754
  global $wpdb;
1755
+ $limit = 1;
1756
+ $ofset = ((int) $_POST['paged'] - 1) * $limit;
1757
+ $count_images = $wpdb->get_var('SELECT COUNT(ID) FROM ' . $wpdb->posts . ' as posts WHERE post_type="attachment" AND ((post_mime_type="image/jpeg") OR (post_mime_type="image/jpg")
1758
+ OR (post_mime_type="image/png") OR (post_mime_type="image/gif"))');
1759
+ $present = (100 / $count_images) * $limit;
1760
+
1761
+ $k = 0;
1762
+ $attachments = $wpdb->get_results($wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type="attachment" AND ((post_mime_type="image/jpeg") OR (post_mime_type="image/jpg")
1763
+ OR (post_mime_type="image/png") OR (post_mime_type="image/gif")) LIMIT %d OFFSET %d', array(
1764
+ $limit,
1765
+ $ofset
1766
+ )));
 
 
 
 
 
 
 
 
1767
  if (empty($attachments)) {
1768
  wp_send_json(array('status' => 'ok'));
1769
  }
1770
 
1771
  foreach ($attachments as $image) {
1772
+ $path = get_attached_file($image->ID);
1773
+ $infos = pathinfo($path);
1774
  $img_name = $infos['basename'];
1775
+ $imgs = array('name' => $img_name, 'img_post_id' => $image->ID);
1776
+ $results = self::scanPostsMeta($imgs, false, 0);
1777
  if ($results['msg'][$image->ID]['imNotGood']['warning']) {
1778
  update_post_meta($image->ID, 'wpms_missing_information', 1);
1779
  } else {
1784
  } else {
1785
  delete_post_meta($image->ID, 'wpms_resizeimages');
1786
  }
1787
+ $k ++;
1788
  }
1789
 
1790
  if ($k >= $limit) {
1795
  }
1796
 
1797
  /**
1798
+ * Scan posts meta
1799
+ *
1800
+ * @param array $imgs Image infos
1801
+ * @param boolean $delete Is delete
1802
+ * @param integer $pid Post id
1803
+ *
1804
  * @return mixed
1805
  */
1806
  public static function scanPostsMeta($imgs, $delete = false, $pid = 0)
1808
  if (!empty($imgs)) {
1809
  if (!is_array($imgs)) {
1810
  $ret['success'] = false;
1811
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1812
  return $ret;
1813
  }
1814
 
1815
+ $_imgs = array();
1816
  $_imgs[trim($imgs['name'])] = $imgs['img_post_id'];
1817
  unset($imgs);
1818
 
1819
  if (!count($_imgs)) {
1820
  $ret['success'] = false;
1821
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1822
  return $ret;
1823
  }
1824
 
1825
+ $msg = ImageHelper::IScanPosts($_imgs, $delete, $pid);
1826
+ $ret['msg'] = $msg;
1827
  $ret['success'] = true;
1828
  } else {
1829
  $ret['success'] = false;
1830
+ $ret['msg'] = esc_html__('No images are available, please check again!', 'wp-meta-seo');
1831
  }
1832
 
1833
  return $ret;
1834
  }
1835
 
1836
  /**
1837
+ * Update meta missing info and meta resize after delete post
1838
+ *
1839
+ * @param integer $pid Post id
1840
+ *
1841
+ * @return void
1842
  */
1843
  public static function deleteAttachment($pid)
1844
  {
1845
  $post = get_post($pid);
1846
  if (!empty($post)) {
1847
+ $post_type = get_post_type($pid);
1848
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1849
  if (isset($post_types['attachment'])) {
1850
  unset($post_types['attachment']);
1853
  if (in_array($post_type, $post_types)) {
1854
  $dom = new DOMDocument();
1855
  libxml_use_internal_errors(true);
1856
+ $dom->loadHtml($post->post_content);
1857
  $tags = $dom->getElementsByTagName('img');
1858
  if (!empty($tags)) {
1859
  foreach ($tags as $tag) {
1860
+ $url = $tag->getAttribute('src');
1861
+ $postid = self::getAttachmentId($url);
1862
+ $path = get_attached_file($postid);
1863
+ $infos = pathinfo($path);
1864
  $img_name = $infos['basename'];
1865
+ $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1866
+ $results = self::scanPostsMeta($imgs, true, $pid);
1867
 
1868
  // update or delete meta
1869
  if ($results['msg'][$postid]['imNotGood']['warning']) {
1883
  }
1884
 
1885
  /**
1886
+ * Update meta missing info and meta resize after update post
1887
+ *
1888
+ * @param integer $post_ID Id of current post
1889
+ * @param string $post_after Post content after update
1890
+ * @param string $post_before Post content before update
1891
+ *
1892
+ * @return void
1893
  */
1894
  public static function updatePost($post_ID, $post_after, $post_before)
1895
  {
1896
+ $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1897
+ unset($post_types['attachment']);
1898
+ if (!in_array($post_after->post_type, $post_types)) {
1899
+ return;
1900
+ }
1901
+
1902
+ if ($post_before->post_content === '' && $post_after->post_content === '') {
1903
+ return;
1904
+ }
1905
+
1906
+ $old_imgs = self::getImagesInContent($post_before); // return list img in post before
1907
  $new_imgs = array(); // return list img in post after
1908
+ $dom = new DOMDocument();
1909
+ libxml_use_internal_errors(true);
1910
+ if ($post_after->post_content !== '') {
1911
+ $dom->loadHtml($post_after->post_content);
1912
+ $tags = $dom->getElementsByTagName('img');
1913
+
1914
+ if (!empty($tags)) {
1915
+ foreach ($tags as $tag) {
1916
+ $url = $tag->getAttribute('src');
1917
+ $postid = self::getAttachmentId($url);
1918
+ $new_imgs[] = $postid;
1919
+ $post = get_post($postid);
1920
+ if (!empty($post)) {
1921
+ $path = get_attached_file($postid);
1922
+ $infos = pathinfo($path);
1923
+ $img_name = $infos['basename'];
1924
+ $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1925
+ $results = self::scanPostsMeta($imgs, false, 0);
1926
+
1927
+ // update or delete meta
1928
+ if ($results['msg'][$postid]['imNotGood']['warning']) {
1929
+ update_post_meta($postid, 'wpms_missing_information', 1);
1930
+ } else {
1931
+ delete_post_meta($postid, 'wpms_missing_information');
1932
+ }
1933
+ if ($results['msg'][$postid]['iNotGood']['warning']) {
1934
+ update_post_meta($postid, 'wpms_resizeimages', 1);
1935
+ } else {
1936
+ delete_post_meta($postid, 'wpms_resizeimages');
1937
+ }
1938
  }
1939
  }
1940
  }
1944
  $imgs_diff = array_diff($old_imgs, $new_imgs);
1945
  if (!empty($imgs_diff)) {
1946
  foreach ($imgs_diff as $id) {
1947
+ $path = get_attached_file($id);
1948
+ $infos = pathinfo($path);
1949
  $img_name = $infos['basename'];
1950
+ $imgs = array('name' => $img_name, 'img_post_id' => $id);
1951
+ $results = self::scanPostsMeta($imgs, true, $post_ID);
1952
 
1953
  // update or delete meta
1954
  if ($results['msg'][$id]['imNotGood']['warning']) {
1967
 
1968
  /**
1969
  * Get all images id in post content
1970
+ *
1971
+ * @param string $post_before Post content before update
1972
+ *
1973
  * @return array
1974
  */
1975
  public static function getImagesInContent($post_before)
1976
  {
1977
  $dom = new DOMDocument();
1978
  libxml_use_internal_errors(true);
1979
+ if ($post_before->post_content === '') {
1980
+ return array();
1981
+ }
1982
+ $dom->loadHtml($post_before->post_content);
1983
  $tags = $dom->getElementsByTagName('img');
1984
+ $ids = array();
1985
  if (empty($tags)) {
1986
  return $ids;
1987
  }
1988
  foreach ($tags as $tag) {
1989
+ $url = $tag->getAttribute('src');
1990
+ $postid = self::getAttachmentId($url);
1991
+ $ids[] = $postid;
1992
  }
1993
  return $ids;
1994
  }
1995
 
1996
  /**
1997
  * Get attachment ID from URL
1998
+ *
1999
  * @param string $url URl of attachment
2000
+ *
2001
+ * @return integer
2002
  */
2003
  public static function getAttachmentId($url)
2004
  {
2005
  $attachment_id = 0;
2006
+ $dir = wp_upload_dir();
2007
  if (false !== strpos($url, $dir['baseurl'] . '/')) { // Is URL in uploads directory?
2008
+ $file = basename($url);
2009
  $query_args = array(
2010
+ 'post_type' => 'attachment',
2011
  'post_status' => 'inherit',
2012
+ 'fields' => 'ids',
2013
+ 'meta_query' => array(
2014
  array(
2015
+ 'value' => $file,
2016
  'compare' => 'LIKE',
2017
+ 'key' => '_wp_attachment_metadata',
2018
  ),
2019
  )
2020
  );
2021
+ $query = new WP_Query($query_args);
2022
  if ($query->have_posts()) {
2023
  foreach ($query->posts as $post_id) {
2024
  $meta = wp_get_attachment_metadata($post_id);
2025
  if (!empty($meta['file']) && !empty($meta['sizes'])) {
2026
+ $original_file = basename($meta['file']);
2027
  $cropped_image_files = wp_list_pluck($meta['sizes'], 'file');
2028
  if ($original_file === $file || in_array($file, $cropped_image_files)) {
2029
  $attachment_id = $post_id;
inc/class.metaseo-link-list-table.php CHANGED
@@ -13,7 +13,9 @@ wp_enqueue_style('metaseo-google-icon');
13
  class MetaSeoLinkListTable extends WP_List_Table
14
  {
15
  /**
16
- * @var
 
 
17
  */
18
  public $months;
19
 
@@ -24,28 +26,31 @@ class MetaSeoLinkListTable extends WP_List_Table
24
  {
25
  parent::__construct(array(
26
  'singular' => 'metaseo_image',
27
- 'plural' => 'metaseo_images',
28
- 'ajax' => true
29
  ));
30
  }
31
 
32
  /**
33
  * Generate the table navigation above or below the table
34
- * @param string $which
 
 
 
35
  */
36
- protected function display_tablenav($which)
37
  {
38
  ?>
39
- <div class="tablenav <?php echo esc_attr($which); ?>">
40
 
41
- <?php if ($which == 'top') : ?>
42
  <input type="hidden" name="page" value="metaseo_image_meta"/>
43
  <div class="alignleft actions bulkactions">
44
  <?php $this->monthsFilter('sldate'); ?>
45
  <?php $this->sourceFilter(); ?>
46
  </div>
47
 
48
- <?php elseif ($which == 'bottom') : ?>
49
  <input type="hidden" name="page" value="metaseo_image_meta"/>
50
  <div class="alignleft actions bulkactions">
51
  <?php $this->monthsFilter('sldate1'); ?>
@@ -54,24 +59,27 @@ class MetaSeoLinkListTable extends WP_List_Table
54
  <?php endif ?>
55
 
56
  <input type="hidden" name="page" value="metaseo_image_meta"/>
 
 
57
  <?php if (!empty($_REQUEST['post_status'])) : ?>
58
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
59
  <?php endif ?>
60
-
 
61
  <div style="float:right;margin-left:8px;">
62
  <label>
63
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>"
 
64
  maxlength="3" name="metaseo_link_per_page" class="metaseo_imgs_per_page screen-per-page"
65
  max="999" min="1" step="1">
66
  </label>
67
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
68
  </div>
69
-
70
- <?php if ($which == 'top') : ?>
71
  <div class="alignleft actions bulkactions">
72
  <?php $this->generateFollowFilter(); ?>
73
  </div>
74
- <?php elseif ($which == 'bottom') : ?>
75
  <div class="alignleft actions bulkactions">
76
  <?php $this->generateFollowFilter(); ?>
77
  </div>
@@ -84,140 +92,24 @@ class MetaSeoLinkListTable extends WP_List_Table
84
  <?php
85
  }
86
 
87
- /**
88
- * Get an associative array ( id => link ) with the list
89
- * of views available on this table.
90
- * @return array
91
- */
92
- protected function get_views()
93
- {
94
- global $wpdb;
95
-
96
-
97
- $status_links = array();
98
-
99
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
100
- $post_types = "'" . implode("', '", esc_sql($post_types)) . "'";
101
-
102
- $states = get_post_stati(array('show_in_admin_all_list' => true));
103
- $states['trash'] = 'trash';
104
- $all_states = "'" . implode("', '", esc_sql($states)) . "'";
105
-
106
- $total_posts = $wpdb->get_var(
107
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)"
108
- );
109
-
110
- $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
111
- $status_links['all'] = "<a href='admin.php?page=metaseo_image_meta'$class>";
112
- $status_links['all'] .= sprintf(
113
- _nx(
114
- 'All <span class="count">(%s)</span>',
115
- 'All <span class="count">(%s)</span>',
116
- $total_posts,
117
- 'posts'
118
- ),
119
- number_format_i18n($total_posts)
120
- );
121
- $status_links['all'] .= "</a>";
122
- foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
123
- $status = $status->name;
124
- $total = $wpdb->get_var(
125
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$status') AND post_type IN ($post_types)"
126
- );
127
-
128
- if ($total == 0) {
129
- continue;
130
- }
131
-
132
- if (isset($_REQUEST['post_status']) && $status == $_REQUEST['post_status']) {
133
- $class = ' class="current"';
134
- } else {
135
- $class = '';
136
- }
137
-
138
- $status_links[$status] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=$status'$class>";
139
- $status_links[$status] .= sprintf(
140
- translate_nooped_plural(
141
- $status->label_count,
142
- $total
143
- ),
144
- number_format_i18n(
145
- $total
146
- )
147
- );
148
- $status_links[$status] .= "</a>";
149
- }
150
- $trashed_posts = $wpdb->get_var(
151
- "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)"
152
- );
153
- $class = (isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status']) ? 'class="current"' : '';
154
- $status_links['trash'] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=trash'$class>";
155
- $status_links['trash'] .= sprintf(
156
- _nx(
157
- 'Trash <span class="count">(%s)</span>',
158
- 'Trash <span class="count">(%s)</span>',
159
- $trashed_posts,
160
- 'posts'
161
- ),
162
- number_format_i18n($trashed_posts)
163
- );
164
- $status_links['trash'] .= "</a>";
165
-
166
- return $status_links;
167
- }
168
-
169
- /**
170
- * Extra controls to be displayed between bulk actions and pagination
171
- * @param string $which
172
- */
173
- protected function extra_tablenav($which)
174
- {
175
- echo '<div class="alignleft actions">';
176
- global $wpdb;
177
-
178
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
179
- $post_types = "'" . implode("', '", $post_types) . "'";
180
-
181
- $states = get_post_stati(array('show_in_admin_all_list' => true));
182
- $states['trash'] = 'trash';
183
- $all_states = "'" . implode("', '", $states) . "'";
184
-
185
- $query = "SELECT DISTINCT post_type FROM $wpdb->posts
186
- WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
187
- $post_types = $wpdb->get_results($query);
188
-
189
- $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
190
-
191
- $options = '<option value="-1">Show All Post Types</option>';
192
-
193
- foreach ($post_types as $post_type) {
194
- $obj = get_post_type_object($post_type->post_type);
195
- $options .= sprintf(
196
- '<option value="%2$s" %3$s>%1$s</option>',
197
- $obj->labels->name,
198
- $post_type->post_type,
199
- selected($selected, $post_type->post_type, false)
200
- );
201
- }
202
-
203
- echo "</div>";
204
- }
205
-
206
  /**
207
  * Get a list of columns. The format is:
208
  * 'internal-name' => 'Title'
 
209
  * @return array
210
  */
211
- public function get_columns()
212
  {
213
- return $columns = array(
214
- 'cb' => '<input id="cb-select-all-1" type="checkbox">',
215
- 'post_id' => __('Source', 'wp-meta-seo'),
216
- 'col_link_url' => __('URL', 'wp-meta-seo'),
217
- 'col_link_title' => __('Link title', 'wp-meta-seo'),
218
- 'col_link_label' => __('Link text', 'wp-meta-seo'),
219
- 'col_follow' => __('Follow', 'wp-meta-seo')
220
  );
 
 
221
  }
222
 
223
  /**
@@ -227,41 +119,45 @@ class MetaSeoLinkListTable extends WP_List_Table
227
  * 'internal-name' => array( 'orderby', true )
228
  *
229
  * The second format will make the initial sorting order be descending
 
230
  * @return array
231
  */
232
- protected function get_sortable_columns()
233
  {
234
- return $sortable = array(
235
- 'post_id' => array('post_title', true),
236
- 'col_link_url' => array('link_url', true),
237
  'col_link_title' => array('meta_title', true),
238
- 'col_follow' => array('follow', true),
239
  );
 
 
240
  }
241
 
242
  /**
243
  * Print column headers, accounting for hidden and sortable columns.
244
  *
245
- * @since 3.1.0
246
- * @access public
247
  *
248
- * @param bool $with_id Whether to set the id attribute or not
249
  */
250
- public function print_column_headers($with_id = true)
251
  {
252
  list($columns, $hidden, $sortable) = $this->get_column_info();
253
 
254
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
255
  $current_url = remove_query_arg('paged', $current_url);
256
 
 
257
  if (isset($_GET['orderby'])) {
 
258
  $current_orderby = $_GET['orderby'];
259
  } else {
260
  $current_orderby = '';
261
  }
262
 
263
-
264
- if (isset($_GET['order']) && 'desc' == $_GET['order']) {
265
  $current_order = 'desc';
266
  } else {
267
  $current_order = 'asc';
@@ -269,14 +165,14 @@ class MetaSeoLinkListTable extends WP_List_Table
269
 
270
  if (!empty($columns['cb'])) {
271
  static $cb_counter = 1;
272
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">
273
- ' . __('Select All', 'wp-meta-seo') . '</label>'
274
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
275
- $cb_counter++;
276
  }
277
 
278
  foreach ($columns as $column_key => $column_display_name) {
279
- $class = array('manage-column', "column-$column_key");
280
 
281
  $style = '';
282
  if (in_array($column_key, $hidden)) {
@@ -285,7 +181,7 @@ class MetaSeoLinkListTable extends WP_List_Table
285
 
286
  $style = ' style="' . $style . '"';
287
 
288
- if ('cb' == $column_key) {
289
  $class[] = 'check-column';
290
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
291
  $class[] = 'num';
@@ -294,125 +190,100 @@ class MetaSeoLinkListTable extends WP_List_Table
294
  if (isset($sortable[$column_key])) {
295
  list($orderby, $desc_first) = $sortable[$column_key];
296
 
297
- if ($current_orderby == $orderby) {
298
- $order = 'asc' == $current_order ? 'desc' : 'asc';
299
  $class[] = 'sorted';
300
  $class[] = $current_order;
301
  } else {
302
- $order = $desc_first ? 'desc' : 'asc';
303
  $class[] = 'sortable';
304
  $class[] = $desc_first ? 'asc' : 'desc';
305
  }
306
 
307
- $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
308
  $column_display_name = '<a href="' . $hr . '">
309
- <span>' . $column_display_name . '</span>
310
  <span class="sorting-indicator"></span></a>';
311
  }
312
 
313
- $id = $with_id ? "id='$column_key'" : '';
314
  if (!empty($class)) {
315
- $class = "class='" . join(' ', $class) . "'";
316
  }
317
 
 
318
  if ($column_key === 'col_id') {
319
- echo "<th scope='col' $id $class $style colspan=\"1\">$column_display_name</th>";
320
  } elseif ($column_key === 'col_image_name') {
321
- echo "<th scope='col' $id $class $style colspan=\"4\">$column_display_name</th>";
322
  } elseif ($column_key === 'col_image_info') {
323
- echo "<th scope='col' $id $class $style colspan=\"5\">$column_display_name</th>";
324
  } elseif ($column_key === 'cb') {
325
- echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
326
  } else {
327
- echo "<th scope='col' $id $class $style colspan=\"3\">$column_display_name</th>";
328
  }
 
329
  }
330
  }
331
 
332
  /**
333
  * Get months
 
 
334
  */
335
  public function getMonths()
336
  {
337
  global $wpdb;
338
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
339
- if (!empty($post_types['attachment'])) {
340
- unset($post_types['attachment']);
341
  }
342
-
343
- $p_type = "('" . implode("','", $post_types) . "')";
344
- $months = $wpdb->get_results("
345
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
346
- FROM $wpdb->posts
347
- WHERE post_type IN $p_type
348
- ORDER BY post_date DESC
349
- ");
350
-
351
- $months = apply_filters('months_dropdown_results', $months, $p_type);
352
  return $months;
353
  }
354
 
355
  /**
356
  * Prepares the list of items for displaying.
357
- * @uses WP_List_Table::set_pagination_args()
 
358
  */
359
- public function prepare_items()
360
  {
361
  global $wpdb;
362
  $this->months = $this->getMonths();
363
 
364
  $where = array('1=1');
365
-
366
- $keyword = !empty($_GET["txtkeyword"]) ? $_GET["txtkeyword"] : '';
367
- if (isset($keyword) && $keyword != '') {
368
- $where[] .= '(link_text LIKE "%' . $keyword . '%" OR link_url LIKE "%' . $keyword . '%")';
 
 
 
369
  }
370
 
371
- if (isset($_GET['metaseo_link_source']) && $_GET['metaseo_link_source'] == 'internal') {
372
  $where[] .= 'internal = 1';
373
  }
374
 
375
- if (isset($_GET['metaseo_link_source']) && $_GET['metaseo_link_source'] == 'external') {
376
  $where[] .= 'internal = 0';
377
  }
378
 
379
  $where[] .= 'type="url"';
380
 
381
- $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
382
- $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
383
- $sortable = $this->get_sortable_columns();
384
- $orderby_array = array($orderby, true);
385
- if (in_array($orderby_array, $sortable)) {
386
- $orderStr = $orderby;
387
- } else {
388
- $orderStr = 'id';
389
- }
390
-
391
- if ($order == "asc") {
392
- $orderStr .= " ASC";
393
- } else {
394
- $orderStr .= " DESC";
395
- }
396
-
397
- if (!empty($orderby) & !empty($order)) {
398
- $orderStr = $wpdb->prepare(' ORDER BY %s ', $orderStr);
399
- $orderStr = str_replace("'", "", $orderStr);
400
- }
401
 
402
- $query = "SELECT COUNT(id) FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
403
- $total_items = $wpdb->get_var($query);
404
- $columns = $this->get_columns();
405
- $hidden = array();
406
- $sortable = $this->get_sortable_columns();
407
- $this->_column_headers = array($columns, $hidden, $sortable);
408
-
409
- $query = "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
410
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
411
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
412
  } else {
413
  $_per_page = 0;
414
  }
415
-
416
  $per_page = get_user_option('metaseo_broken_link_per_page');
417
  if ($per_page !== false) {
418
  if ($_per_page && $_per_page !== $per_page) {
@@ -428,37 +299,68 @@ class MetaSeoLinkListTable extends WP_List_Table
428
  add_user_meta(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
429
  }
430
 
431
- $paged = !empty($_GET["paged"]) ? $_GET["paged"] : '';
 
432
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
433
  $paged = 1;
434
  }
435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  $total_pages = ceil($total_items / $per_page);
437
 
438
  if (!empty($paged) && !empty($per_page)) {
439
  $offset = ($paged - 1) * $per_page;
440
- $query .= ' LIMIT ' . (int)$offset . ',' . (int)$per_page;
441
  }
442
 
443
  $this->set_pagination_args(array(
444
  'total_items' => $total_items,
445
  'total_pages' => $total_pages,
446
- 'per_page' => $per_page
447
  ));
448
 
 
449
  $this->items = $wpdb->get_results($query);
450
  }
451
 
452
  /**
453
  * Displays the search box.
 
 
454
  */
455
  public function searchBox1()
456
  {
 
457
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
458
  return;
459
  }
460
 
461
- $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
462
  if (!empty($_REQUEST['orderby'])) {
463
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
464
  }
@@ -474,7 +376,7 @@ class MetaSeoLinkListTable extends WP_List_Table
474
  if (!empty($_REQUEST['detached'])) {
475
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
476
  }
477
-
478
  ?>
479
  <p class="search-box">
480
  <label>
@@ -488,50 +390,51 @@ class MetaSeoLinkListTable extends WP_List_Table
488
 
489
  /**
490
  * Add filter follow
 
 
491
  */
492
  public function generateFollowFilter()
493
  {
494
  ?>
495
  <label>
496
  <select name="metaseo_follow_action" class="metaseo_follow_action">
497
- <option value="0"><?php _e('-- Selection --', 'wp-meta-seo') ?></option>
498
- <option value="follow_selected"><?php _e('Follow selected', 'wp-meta-seo') ?></option>
499
- <option value="nofollow_selected"><?php _e('Nofollow selected', 'wp-meta-seo') ?></option>
500
- <option value="follow_all"><?php _e('Follow all', 'wp-meta-seo') ?></option>
501
- <option value="nofollow_all"><?php _e('Nofollow all', 'wp-meta-seo') ?></option>
502
  </select>
503
  </label>
504
 
505
  <input type="button" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary btn_apply_follow"
506
- value="<?php _e('Apply', 'wp-meta-seo') ?>">
507
  <div data-comment_paged="1" data-paged="1"
508
  class="wpmsbtn wpmsbtn_small wpms_scan_link page_link_meta">
509
- <?php _e('Re-index content links', 'wp-meta-seo') ?></div>
510
  <span class="spinner spinner_apply_follow"></span>
511
  <?php
512
  }
513
 
514
  /**
515
- * Add fillter link source
 
 
516
  */
517
  public function sourceFilter()
518
  {
519
- if (isset($_GET['metaseo_link_source'])) {
520
- $link_source = $_GET['metaseo_link_source'];
521
- } else {
522
- $link_source = 0;
523
- }
524
  ?>
525
  <label>
526
  <select name="metaseo_link_source" class="metaseo_link_source">
527
  <option value="0" <?php selected($link_source, 0) ?>>
528
- <?php _e('Link source', 'wp-meta-seo') ?>
529
  </option>
530
  <option value="internal" <?php selected($link_source, 'internal') ?>>
531
- <?php _e('Internal', 'wp-meta-seo') ?>
532
  </option>
533
  <option value="external" <?php selected($link_source, 'external') ?>>
534
- <?php _e('External', 'wp-meta-seo') ?>
535
  </option>
536
  </select>
537
  </label>
@@ -539,66 +442,72 @@ class MetaSeoLinkListTable extends WP_List_Table
539
  }
540
 
541
  /**
542
- * Add fillter months
543
- * @param $name
 
 
 
544
  */
545
  public function monthsFilter($name)
546
  {
547
  global $wp_locale;
548
  $month_count = count($this->months);
549
 
550
- if (!$month_count || (1 == $month_count && 0 == $this->months[0]->month)) {
551
  return;
552
  }
553
-
554
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
555
  ?>
556
- <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'wp-meta-seo'); ?></label>
557
- <select name="<?php echo $name ?>" id="filter-by-date" class="metaseo-filter">
558
- <option<?php selected($m, 0); ?> value="0"><?php _e('All dates', 'wp-meta-seo'); ?></option>
 
559
  <?php
560
  foreach ($this->months as $arc_row) {
561
- if (0 == $arc_row->year) {
562
  continue;
563
  }
564
 
565
  $month = zeroise($arc_row->month, 2);
566
- $year = $arc_row->year;
567
  printf(
568
  "<option %s value='%s' >%s</option>\n",
569
- selected($m, "$year-$month", false),
570
- esc_attr("$arc_row->year-$month"),
571
  sprintf(
572
- __('%1$s %2$d', 'wp-meta-seo'),
573
- $wp_locale->get_month($month),
574
- $year
575
  )
576
  );
577
  }
578
  ?>
579
  </select>
580
  <input type="submit" name="filter_date_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary"
581
- value="<?php _e('Filter', 'wp-meta-seo') ?>">
582
  <?php
583
  }
584
 
585
  /**
586
  * Generate the table rows
 
 
587
  */
588
- public function display_rows()
589
  {
590
  $records = $this->items;
591
  list($columns) = $this->get_column_info();
592
  if (!empty($records)) {
593
  foreach ($records as $rec) {
594
- echo '<tr id="record_' . $rec->id . '" data-link="' . $rec->id . '"
595
- data-post_id="' . $rec->source_id . '">';
596
  foreach ($columns as $column_name => $column_display_name) {
597
  switch ($column_name) {
598
  case 'cb':
599
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
600
- echo '<input id="cb-select-' . $rec->id . '" class="metaseo_link"
601
- type="checkbox" name="link[' . $rec->id . ']" value="' . $rec->id . '">';
602
  echo '</td>';
603
  break;
604
 
@@ -607,21 +516,22 @@ class MetaSeoLinkListTable extends WP_List_Table
607
  if (empty($post)) {
608
  echo '<td class="col_id" colspan="3">';
609
  echo '<a target="_blank"
610
- href="#">' . __('Not found', 'wp-meta-seo') . '</a>';
611
  echo '<p class="wpms_remove_link"
612
- data-link_id="' . $rec->id . '">
613
- <span>' . __('Remove link', 'wp-meta-seo') . '</span></p>';
614
  echo '</td>';
615
  } else {
616
  $row_action = array(
617
- 'edit' => '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '"
618
  title="Edit this item">Edit</a>',
619
- 'view' => '<a target="_blank" href="' . get_permalink($rec->source_id) . '"
620
  title="View &#8220;test&#8221;" rel="permalink">View</a>'
621
  );
622
  echo '<td class="col_id" colspan="3">';
623
  echo '<a target="_blank"
624
- href="' . get_edit_post_link($rec->source_id) . '">' . $post->post_title . '</a>';
 
625
  echo $this->row_actions($row_action, false);
626
  echo '</td>';
627
  }
@@ -630,34 +540,33 @@ class MetaSeoLinkListTable extends WP_List_Table
630
 
631
  case 'col_link_url':
632
  echo '<td class="wpms_link_html" colspan="3">';
633
- echo '<a target="_blank" href="' . $rec->link_url . '">' . $rec->link_url . '</a>';
634
  echo '</td>';
635
  break;
636
 
637
  case 'col_link_title':
638
  echo '<td colspan="3">';
639
- echo '<input type="text" data-post_id="' . $rec->source_id . '" name="metaseo_link_title"
640
- id="metaseo_link_title" class="metaseo_link_title" value="' . $rec->meta_title . '">';
641
- echo '<div data-post_id="' . $rec->source_id . '"
642
- class="wpms_update_link">' . __('Update', 'wp-meta-seo') . '</div>';
643
- echo '<strong class="wpms_mesage_link">' . __('Saved.', 'wp-meta-seo') . '</strong>';
644
- echo '<strong class="wpms_error_mesage_link">' . __('Error.', 'wp-meta-seo') . '</strong>';
645
  echo '</td>';
646
  break;
647
 
648
  case 'col_link_label':
649
- echo '<td colspan="3">' . strip_tags($rec->link_text) . '</td>';
650
  break;
651
 
652
  case 'col_follow':
653
- if ($rec->follow == 1) {
654
- $follow = '<i class="material-icons wpms_ok wpms_change_follow"
655
- data-type="done">done</i>';
656
  } else {
657
- $follow = '<i class="material-icons wpms_warning wpms_change_follow"
658
- data-type="warning">warning</i>';
659
  }
660
- echo '<td colspan="3">' . $follow . '</td>';
661
  break;
662
  }
663
  }
@@ -669,48 +578,52 @@ class MetaSeoLinkListTable extends WP_List_Table
669
 
670
  /**
671
  * Retrieves a modified URL query string.
 
 
672
  */
673
  public function processAction()
674
  {
675
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
676
- $redirect = false;
677
 
678
- if (isset($_POST['search']) and $_POST['search'] === 'Search') {
 
679
  $current_url = add_query_arg(
680
  array(
681
- "search" => "Search",
682
- "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))
683
  ),
684
  $current_url
685
  );
686
- $redirect = true;
687
  }
688
 
689
  if (isset($_POST['filter_date_action'])) {
690
- $current_url = add_query_arg(array("sldate" => $_POST["sldate"]), $current_url);
691
- $redirect = true;
692
  }
693
 
694
  if (!empty($_POST['paged'])) {
695
- $current_url = add_query_arg(array("paged" => intval($_POST['paged'])), $current_url);
696
- $redirect = true;
697
  }
698
 
699
  if (isset($_POST['metaseo_link_source'])) {
700
- $current_url = add_query_arg(array("metaseo_link_source" => $_POST['metaseo_link_source']), $current_url);
701
- $redirect = true;
702
  }
703
 
704
  if (!empty($_POST['metaseo_link_per_page'])) {
705
  $current_url = add_query_arg(
706
  array(
707
- "metaseo_link_per_page" => intval($_POST['metaseo_link_per_page'])),
 
708
  $current_url
709
  );
710
- $redirect = true;
711
  }
712
-
713
- if ($redirect === true) {
714
  wp_redirect($current_url);
715
  ob_end_flush();
716
  exit();
13
  class MetaSeoLinkListTable extends WP_List_Table
14
  {
15
  /**
16
+ * Months
17
+ *
18
+ * @var string
19
  */
20
  public $months;
21
 
26
  {
27
  parent::__construct(array(
28
  'singular' => 'metaseo_image',
29
+ 'plural' => 'metaseo_images',
30
+ 'ajax' => true
31
  ));
32
  }
33
 
34
  /**
35
  * Generate the table navigation above or below the table
36
+ *
37
+ * @param string $which Possition of table nav
38
+ *
39
+ * @return void
40
  */
41
+ protected function display_tablenav($which) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
42
  {
43
  ?>
44
+ <div class="<?php echo esc_attr('tablenav ' . $which); ?>">
45
 
46
+ <?php if ($which === 'top') : ?>
47
  <input type="hidden" name="page" value="metaseo_image_meta"/>
48
  <div class="alignleft actions bulkactions">
49
  <?php $this->monthsFilter('sldate'); ?>
50
  <?php $this->sourceFilter(); ?>
51
  </div>
52
 
53
+ <?php elseif ($which === 'bottom') : ?>
54
  <input type="hidden" name="page" value="metaseo_image_meta"/>
55
  <div class="alignleft actions bulkactions">
56
  <?php $this->monthsFilter('sldate1'); ?>
59
  <?php endif ?>
60
 
61
  <input type="hidden" name="page" value="metaseo_image_meta"/>
62
+ <?php // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
63
+ ?>
64
  <?php if (!empty($_REQUEST['post_status'])) : ?>
65
  <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>"/>
66
  <?php endif ?>
67
+ <?php // phpcs:enable
68
+ ?>
69
  <div style="float:right;margin-left:8px;">
70
  <label>
71
+ <input type="number" required
72
+ value="<?php echo esc_attr($this->_pagination_args['per_page']) ?>"
73
  maxlength="3" name="metaseo_link_per_page" class="metaseo_imgs_per_page screen-per-page"
74
  max="999" min="1" step="1">
75
  </label>
76
  <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply">
77
  </div>
78
+ <?php if ($which === 'top') : ?>
 
79
  <div class="alignleft actions bulkactions">
80
  <?php $this->generateFollowFilter(); ?>
81
  </div>
82
+ <?php elseif ($which === 'bottom') : ?>
83
  <div class="alignleft actions bulkactions">
84
  <?php $this->generateFollowFilter(); ?>
85
  </div>
92
  <?php
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  /**
96
  * Get a list of columns. The format is:
97
  * 'internal-name' => 'Title'
98
+ *
99
  * @return array
100
  */
101
+ public function get_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
102
  {
103
+ $columns = array(
104
+ 'cb' => '<input id="cb-select-all-1" type="checkbox">',
105
+ 'post_id' => esc_html__('Source', 'wp-meta-seo'),
106
+ 'col_link_url' => esc_html__('URL', 'wp-meta-seo'),
107
+ 'col_link_title' => esc_html__('Link title', 'wp-meta-seo'),
108
+ 'col_link_label' => esc_html__('Link text', 'wp-meta-seo'),
109
+ 'col_follow' => esc_html__('Follow', 'wp-meta-seo')
110
  );
111
+
112
+ return $columns;
113
  }
114
 
115
  /**
119
  * 'internal-name' => array( 'orderby', true )
120
  *
121
  * The second format will make the initial sorting order be descending
122
+ *
123
  * @return array
124
  */
125
+ protected function get_sortable_columns() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
126
  {
127
+ $sortable = array(
128
+ 'post_id' => array('post_title', true),
129
+ 'col_link_url' => array('link_url', true),
130
  'col_link_title' => array('meta_title', true),
131
+ 'col_follow' => array('follow', true),
132
  );
133
+
134
+ return $sortable;
135
  }
136
 
137
  /**
138
  * Print column headers, accounting for hidden and sortable columns.
139
  *
140
+ * @param boolean $with_id Whether to set the id attribute or not
 
141
  *
142
+ * @return void
143
  */
144
+ public function print_column_headers($with_id = true) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
145
  {
146
  list($columns, $hidden, $sortable) = $this->get_column_info();
147
 
148
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
149
  $current_url = remove_query_arg('paged', $current_url);
150
 
151
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
152
  if (isset($_GET['orderby'])) {
153
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
154
  $current_orderby = $_GET['orderby'];
155
  } else {
156
  $current_orderby = '';
157
  }
158
 
159
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
160
+ if (isset($_GET['order']) && 'desc' === $_GET['order']) {
161
  $current_order = 'desc';
162
  } else {
163
  $current_order = 'asc';
165
 
166
  if (!empty($columns['cb'])) {
167
  static $cb_counter = 1;
168
+ $columns['cb'] = '<label class="screen-reader-text" for="' . esc_attr('cb-select-all-' . $cb_counter) . '">
169
+ ' . esc_html__('Select All', 'wp-meta-seo') . '</label>'
170
+ . '<input id="' . esc_attr('cb-select-all-' . $cb_counter) . '" type="checkbox" style="margin:0;" />';
171
+ $cb_counter ++;
172
  }
173
 
174
  foreach ($columns as $column_key => $column_display_name) {
175
+ $class = array('manage-column', 'column-' . $column_key);
176
 
177
  $style = '';
178
  if (in_array($column_key, $hidden)) {
181
 
182
  $style = ' style="' . $style . '"';
183
 
184
+ if ('cb' === $column_key) {
185
  $class[] = 'check-column';
186
  } elseif (in_array($column_key, array('posts', 'comments', 'links'))) {
187
  $class[] = 'num';
190
  if (isset($sortable[$column_key])) {
191
  list($orderby, $desc_first) = $sortable[$column_key];
192
 
193
+ if ($current_orderby === $orderby) {
194
+ $order = 'asc' === $current_order ? 'desc' : 'asc';
195
  $class[] = 'sorted';
196
  $class[] = $current_order;
197
  } else {
198
+ $order = $desc_first ? 'desc' : 'asc';
199
  $class[] = 'sortable';
200
  $class[] = $desc_first ? 'asc' : 'desc';
201
  }
202
 
203
+ $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
204
  $column_display_name = '<a href="' . $hr . '">
205
+ <span>' . esc_html($column_display_name) . '</span>
206
  <span class="sorting-indicator"></span></a>';
207
  }
208
 
209
+ $id = $with_id ? 'id="' . esc_attr($column_key) . '"' : '';
210
  if (!empty($class)) {
211
+ $class = "class='" . esc_attr(join(' ', $class)) . "'";
212
  }
213
 
214
+ // phpcs:disable WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
215
  if ($column_key === 'col_id') {
216
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="1">' . $column_display_name . '</th>';
217
  } elseif ($column_key === 'col_image_name') {
218
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="4">' . $column_display_name . '</th>';
219
  } elseif ($column_key === 'col_image_info') {
220
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="5">' . $column_display_name . '</th>';
221
  } elseif ($column_key === 'cb') {
222
+ echo '<th scope="col" ' . $id . ' ' . $class . ' style="padding:8px 10px;">' . $column_display_name . '</th>';
223
  } else {
224
+ echo '<th scope="col" ' . $id . ' ' . $class . ' ' . $style . ' colspan="3">' . $column_display_name . '</th>';
225
  }
226
+ // phpcs:enable
227
  }
228
  }
229
 
230
  /**
231
  * Get months
232
+ *
233
+ * @return array|mixed|null|object
234
  */
235
  public function getMonths()
236
  {
237
  global $wpdb;
238
+ $post_types = MetaSeoContentListTable::getPostTypes('attachment');
239
+ foreach ($post_types as &$post_type) {
240
+ $post_type = esc_sql($post_type);
241
  }
242
+ $post_types = implode("', '", $post_types);
243
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
244
+ $months = $wpdb->get_results('SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM ' . $wpdb->posts . ' WHERE post_type IN (\'' . $post_types . '\') ORDER BY post_date DESC');
 
 
 
 
 
 
 
245
  return $months;
246
  }
247
 
248
  /**
249
  * Prepares the list of items for displaying.
250
+ *
251
+ * @return void
252
  */
253
+ public function prepare_items() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
254
  {
255
  global $wpdb;
256
  $this->months = $this->getMonths();
257
 
258
  $where = array('1=1');
259
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
260
+ $keyword = !empty($_GET['txtkeyword']) ? $_GET['txtkeyword'] : '';
261
+ if (isset($keyword) && $keyword !== '') {
262
+ $where[] .= $wpdb->prepare('(link_text LIKE %s OR link_url LIKE %s)', array(
263
+ '%' . $keyword . '%',
264
+ '%' . $keyword . '%'
265
+ ));
266
  }
267
 
268
+ if (isset($_GET['metaseo_link_source']) && $_GET['metaseo_link_source'] === 'internal') {
269
  $where[] .= 'internal = 1';
270
  }
271
 
272
+ if (isset($_GET['metaseo_link_source']) && $_GET['metaseo_link_source'] === 'external') {
273
  $where[] .= 'internal = 0';
274
  }
275
 
276
  $where[] .= 'type="url"';
277
 
278
+ $orderby = !empty($_GET['orderby']) ? ($_GET['orderby']) : 'id';
279
+ $order = !empty($_GET['order']) ? ($_GET['order']) : 'asc';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
 
 
 
 
 
 
 
 
281
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
282
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
283
  } else {
284
  $_per_page = 0;
285
  }
286
+ // phpcs:enable
287
  $per_page = get_user_option('metaseo_broken_link_per_page');
288
  if ($per_page !== false) {
289
  if ($_per_page && $_per_page !== $per_page) {
299
  add_user_meta(get_current_user_id(), 'metaseo_broken_link_per_page', $per_page);
300
  }
301
 
302
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
303
+ $paged = !empty($_GET['paged']) ? $_GET['paged'] : '';
304
  if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
305
  $paged = 1;
306
  }
307
 
308
+ $sortable = $this->get_sortable_columns();
309
+ $orderby_array = array($orderby, true);
310
+ if (in_array($orderby_array, $sortable)) {
311
+ $orderStr = $orderby;
312
+ } else {
313
+ $orderStr = 'id';
314
+ }
315
+
316
+ if ($order === 'asc') {
317
+ $orderStr .= ' ASC';
318
+ } else {
319
+ $orderStr .= ' DESC';
320
+ }
321
+
322
+ if (!empty($orderby) & !empty($order)) {
323
+ $orderStr = ' ORDER BY ' . esc_sql($orderStr) . ' ';
324
+ }
325
+
326
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
327
+ $total_items = $wpdb->get_var('SELECT COUNT(id) FROM ' . $wpdb->prefix . 'wpms_links WHERE ' . implode(' AND ', $where) . $orderStr);
328
+ $columns = $this->get_columns();
329
+ $hidden = array();
330
+ $sortable = $this->get_sortable_columns();
331
+ $this->_column_headers = array($columns, $hidden, $sortable);
332
+
333
+ $query = 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE ' . implode(' AND ', $where) . $orderStr;
334
  $total_pages = ceil($total_items / $per_page);
335
 
336
  if (!empty($paged) && !empty($per_page)) {
337
  $offset = ($paged - 1) * $per_page;
338
+ $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
339
  }
340
 
341
  $this->set_pagination_args(array(
342
  'total_items' => $total_items,
343
  'total_pages' => $total_pages,
344
+ 'per_page' => $per_page
345
  ));
346
 
347
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared -- Variable has been prepare
348
  $this->items = $wpdb->get_results($query);
349
  }
350
 
351
  /**
352
  * Displays the search box.
353
+ *
354
+ * @return void
355
  */
356
  public function searchBox1()
357
  {
358
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
359
  if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
360
  return;
361
  }
362
 
363
+ $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : '';
364
  if (!empty($_REQUEST['orderby'])) {
365
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
366
  }
376
  if (!empty($_REQUEST['detached'])) {
377
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
378
  }
379
+ // phpcs:enable
380
  ?>
381
  <p class="search-box">
382
  <label>
390
 
391
  /**
392
  * Add filter follow
393
+ *
394
+ * @return void
395
  */
396
  public function generateFollowFilter()
397
  {
398
  ?>
399
  <label>
400
  <select name="metaseo_follow_action" class="metaseo_follow_action">
401
+ <option value="0"><?php esc_html_e('-- Selection --', 'wp-meta-seo') ?></option>
402
+ <option value="follow_selected"><?php esc_html_e('Follow selected', 'wp-meta-seo') ?></option>
403
+ <option value="nofollow_selected"><?php esc_html_e('Nofollow selected', 'wp-meta-seo') ?></option>
404
+ <option value="follow_all"><?php esc_html_e('Follow all', 'wp-meta-seo') ?></option>
405
+ <option value="nofollow_all"><?php esc_html_e('Nofollow all', 'wp-meta-seo') ?></option>
406
  </select>
407
  </label>
408
 
409
  <input type="button" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary btn_apply_follow"
410
+ value="<?php esc_attr_e('Apply', 'wp-meta-seo') ?>">
411
  <div data-comment_paged="1" data-paged="1"
412
  class="wpmsbtn wpmsbtn_small wpms_scan_link page_link_meta">
413
+ <?php esc_html_e('Re-index content links', 'wp-meta-seo') ?></div>
414
  <span class="spinner spinner_apply_follow"></span>
415
  <?php
416
  }
417
 
418
  /**
419
+ * Add filter link source
420
+ *
421
+ * @return void
422
  */
423
  public function sourceFilter()
424
  {
425
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
426
+ $link_source = isset($_GET['metaseo_link_source']) ? $_GET['metaseo_link_source'] : 0;
 
 
 
427
  ?>
428
  <label>
429
  <select name="metaseo_link_source" class="metaseo_link_source">
430
  <option value="0" <?php selected($link_source, 0) ?>>
431
+ <?php esc_html_e('Link source', 'wp-meta-seo') ?>
432
  </option>
433
  <option value="internal" <?php selected($link_source, 'internal') ?>>
434
+ <?php esc_html_e('Internal', 'wp-meta-seo') ?>
435
  </option>
436
  <option value="external" <?php selected($link_source, 'external') ?>>
437
+ <?php esc_html_e('External', 'wp-meta-seo') ?>
438
  </option>
439
  </select>
440
  </label>
442
  }
443
 
444
  /**
445
+ * Add filter months
446
+ *
447
+ * @param string $name Filter name
448
+ *
449
+ * @return void
450
  */
451
  public function monthsFilter($name)
452
  {
453
  global $wp_locale;
454
  $month_count = count($this->months);
455
 
456
+ if (!$month_count || (1 === (int) $month_count && 0 === (int) $this->months[0]->month)) {
457
  return;
458
  }
459
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
460
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
461
  ?>
462
+ <label for="filter-by-date"
463
+ class="screen-reader-text"><?php esc_html_e('Filter by date', 'wp-meta-seo'); ?></label>
464
+ <select name="<?php echo esc_attr($name) ?>" id="filter-by-date" class="metaseo-filter">
465
+ <option<?php selected($m, 0); ?> value="0"><?php esc_html_e('All dates', 'wp-meta-seo'); ?></option>
466
  <?php
467
  foreach ($this->months as $arc_row) {
468
+ if (0 === (int) $arc_row->year) {
469
  continue;
470
  }
471
 
472
  $month = zeroise($arc_row->month, 2);
473
+ $year = $arc_row->year;
474
  printf(
475
  "<option %s value='%s' >%s</option>\n",
476
+ selected($m, $year . '-' . $month, false),
477
+ esc_attr($arc_row->year . '-' . $month),
478
  sprintf(
479
+ esc_html__('%1$s %2$d', 'wp-meta-seo'),
480
+ esc_html($wp_locale->get_month($month)),
481
+ esc_html($year)
482
  )
483
  );
484
  }
485
  ?>
486
  </select>
487
  <input type="submit" name="filter_date_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary"
488
+ value="<?php esc_attr_e('Filter', 'wp-meta-seo') ?>">
489
  <?php
490
  }
491
 
492
  /**
493
  * Generate the table rows
494
+ *
495
+ * @return void
496
  */
497
+ public function display_rows() // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- extends from WP_List_Table class
498
  {
499
  $records = $this->items;
500
  list($columns) = $this->get_column_info();
501
  if (!empty($records)) {
502
  foreach ($records as $rec) {
503
+ echo '<tr id="' . esc_attr('record_' . $rec->id) . '" data-link="' . esc_attr($rec->id) . '"
504
+ data-post_id="' . esc_attr($rec->source_id) . '">';
505
  foreach ($columns as $column_name => $column_display_name) {
506
  switch ($column_name) {
507
  case 'cb':
508
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
509
+ echo '<input id="' . esc_attr('cb-select-' . $rec->id) . '" class="metaseo_link"
510
+ type="checkbox" name="' . esc_attr('link[' . $rec->id . ']') . '" value="' . esc_attr($rec->id) . '">';
511
  echo '</td>';
512
  break;
513
 
516
  if (empty($post)) {
517
  echo '<td class="col_id" colspan="3">';
518
  echo '<a target="_blank"
519
+ href="#">' . esc_html__('Not found', 'wp-meta-seo') . '</a>';
520
  echo '<p class="wpms_remove_link"
521
+ data-link_id="' . esc_attr($rec->id) . '">
522
+ <span>' . esc_html__('Remove link', 'wp-meta-seo') . '</span></p>';
523
  echo '</td>';
524
  } else {
525
  $row_action = array(
526
+ 'edit' => '<a target="_blank" href="' . esc_url(get_edit_post_link($rec->source_id)) . '"
527
  title="Edit this item">Edit</a>',
528
+ 'view' => '<a target="_blank" href="' . esc_url(get_permalink($rec->source_id)) . '"
529
  title="View &#8220;test&#8221;" rel="permalink">View</a>'
530
  );
531
  echo '<td class="col_id" colspan="3">';
532
  echo '<a target="_blank"
533
+ href="' . esc_url(get_edit_post_link($rec->source_id)) . '">' . esc_html($post->post_title) . '</a>';
534
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
535
  echo $this->row_actions($row_action, false);
536
  echo '</td>';
537
  }
540
 
541
  case 'col_link_url':
542
  echo '<td class="wpms_link_html" colspan="3">';
543
+ echo '<a target="_blank" href="' . esc_url($rec->link_url) . '">' . esc_html($rec->link_url) . '</a>';
544
  echo '</td>';
545
  break;
546
 
547
  case 'col_link_title':
548
  echo '<td colspan="3">';
549
+ echo '<input type="text" data-post_id="' . esc_attr($rec->source_id) . '" name="metaseo_link_title"
550
+ id="metaseo_link_title" class="metaseo_link_title" value="' . esc_attr($rec->meta_title) . '">';
551
+ echo '<div data-post_id="' . esc_attr($rec->source_id) . '"
552
+ class="wpms_update_link">' . esc_html__('Update', 'wp-meta-seo') . '</div>';
553
+ echo '<strong class="wpms_mesage_link">' . esc_html__('Saved.', 'wp-meta-seo') . '</strong>';
554
+ echo '<strong class="wpms_error_mesage_link">' . esc_html__('Error.', 'wp-meta-seo') . '</strong>';
555
  echo '</td>';
556
  break;
557
 
558
  case 'col_link_label':
559
+ echo '<td colspan="3">' . esc_html(strip_tags($rec->link_text)) . '</td>';
560
  break;
561
 
562
  case 'col_follow':
563
+ if ((int) $rec->follow === 1) {
564
+ echo '<td colspan="3"><i class="material-icons wpms_ok wpms_change_follow"
565
+ data-type="done">done</i></td>';
566
  } else {
567
+ echo '<td colspan="3"><i class="material-icons wpms_warning wpms_change_follow"
568
+ data-type="warning">warning</i></td>';
569
  }
 
570
  break;
571
  }
572
  }
578
 
579
  /**
580
  * Retrieves a modified URL query string.
581
+ *
582
+ * @return void
583
  */
584
  public function processAction()
585
  {
586
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
587
+ $redirect = false;
588
 
589
+ // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
590
+ if (isset($_POST['search']) && $_POST['search'] === 'Search') {
591
  $current_url = add_query_arg(
592
  array(
593
+ 'search' => 'Search',
594
+ 'txtkeyword' => urlencode(stripslashes($_POST['txtkeyword']))
595
  ),
596
  $current_url
597
  );
598
+ $redirect = true;
599
  }
600
 
601
  if (isset($_POST['filter_date_action'])) {
602
+ $current_url = add_query_arg(array('sldate' => $_POST['sldate']), $current_url);
603
+ $redirect = true;
604
  }
605
 
606
  if (!empty($_POST['paged'])) {
607
+ $current_url = add_query_arg(array('paged' => intval($_POST['paged'])), $current_url);
608
+ $redirect = true;
609
  }
610
 
611
  if (isset($_POST['metaseo_link_source'])) {
612
+ $current_url = add_query_arg(array('metaseo_link_source' => $_POST['metaseo_link_source']), $current_url);
613
+ $redirect = true;
614
  }
615
 
616
  if (!empty($_POST['metaseo_link_per_page'])) {
617
  $current_url = add_query_arg(
618
  array(
619
+ 'metaseo_link_per_page' => intval($_POST['metaseo_link_per_page'])
620
+ ),
621
  $current_url
622
  );
623
+ $redirect = true;
624
  }
625
+ // phpcs:enable
626
+ if ($redirect) {
627
  wp_redirect($current_url);
628
  ob_end_flush();
629
  exit();
inc/class.metaseo-meta.php CHANGED
@@ -10,142 +10,157 @@ defined('ABSPATH') || die('No direct script access allowed!');
10
  class WPMSEOMeta
11
  {
12
  /**
 
 
13
  * @var string
14
  */
15
  public static $meta_prefix = '_metaseo_meta';
16
  /**
 
 
17
  * @var string
18
  */
19
  public static $form_prefix = 'metaseo_wpmseo_';
20
  /**
21
- * @var int
 
 
22
  */
23
  public static $meta_length = 320;
24
  /**
25
- * @var int
 
 
26
  */
27
  public static $meta_title_length = 69;
28
  /**
29
- * @var int
 
 
30
  */
31
  public static $meta_keywords_length = 256;
32
  /**
 
 
33
  * @var string
34
  */
35
  public static $meta_length_reason = '';
36
  /**
 
 
37
  * @var array
38
  */
39
  public static $meta_fields = array(
40
- 'general' => array(
41
  'snippetpreview' => array(
42
- 'type' => 'snippetpreview',
43
  'title' => '',
44
- 'help' => '',
45
  ),
46
- 'title' => array(
47
- 'type' => 'textarea',
48
- 'title' => '',
49
  'default_value' => '',
50
- 'description' => '',
51
- 'help' => '',
52
- 'rows' => 2
53
  ),
54
- 'desc' => array(
55
- 'type' => 'textarea',
56
- 'title' => '',
57
  'default_value' => '',
58
- 'class' => 'desc',
59
- 'rows' => 3,
60
- 'description' => '',
61
- 'help' => '',
62
  ),
63
- 'keywords' => array(
64
- 'type' => 'textarea',
65
- 'title' => '',
66
  'default_value' => '',
67
- 'description' => '',
68
- 'help' => '',
69
- 'rows' => 2
70
  ),
71
- 'metaseo_chart' => array(
72
- 'type' => 'metaseo_chart',
73
- 'title' => '',
74
  'default_value' => '',
75
- 'class' => 'metaseo_chart',
76
- 'rows' => 2,
77
- 'description' => '',
78
- 'help' => '',
79
  )
80
  ),
81
- 'social' => array(
82
  'opengraph-title' => array(
83
- 'type' => 'text',
84
- 'title' => '',
85
  'default_value' => '',
86
- 'description' => '',
87
- 'help' => '',
88
  ),
89
- 'opengraph-desc' => array(
90
- 'type' => 'textarea',
91
- 'title' => '',
92
  'default_value' => '',
93
- 'class' => 'desc',
94
- 'rows' => 3,
95
- 'description' => '',
96
- 'help' => '',
97
  ),
98
  'opengraph-image' => array(
99
- 'type' => 'upload',
100
- 'title' => '',
101
  'default_value' => '',
102
- 'class' => 'desc',
103
- 'description' => '',
104
- 'help' => '',
105
  ),
106
- 'twitter-title' => array(
107
- 'type' => 'text',
108
- 'title' => '',
109
  'default_value' => '',
110
- 'description' => '',
111
- 'help' => '',
112
  ),
113
- 'twitter-desc' => array(
114
- 'type' => 'textarea',
115
- 'title' => '',
116
  'default_value' => '',
117
- 'class' => 'desc',
118
- 'rows' => 3,
119
- 'description' => '',
120
- 'help' => '',
121
  ),
122
- 'twitter-image' => array(
123
- 'type' => 'upload',
124
- 'title' => '',
125
  'default_value' => '',
126
- 'class' => 'desc',
127
- 'description' => '',
128
- 'help' => '',
129
  ),
130
  ),
131
  'non_form' => array(
132
  'linkdex' => array(
133
- 'type' => null,
134
  'default_value' => '0',
135
  ),
136
  ),
137
  );
 
138
  /**
139
- * @var array
140
- */
141
- public static $fields_index = array();
142
- /**
143
  * @var array
144
  */
145
  public static $defaults = array();
146
 
147
  /**
148
  * Init
 
 
149
  */
150
  public static function init()
151
  {
@@ -156,10 +171,8 @@ class WPMSEOMeta
156
  /**
157
  * Retrieve the meta box form field definitions for the given tab and post type.
158
  *
159
- * @static
160
- *
161
- * @param string $tab Tab for which to retrieve the field definitions.
162
- * @param string $post_type Post type of the current post.
163
  *
164
  * @return array Array containing the meta box field definitions
165
  */
@@ -179,7 +192,7 @@ class WPMSEOMeta
179
  case 'general':
180
  $options = get_option('wpmseo_titles');
181
  if ($options['usemetakeywords'] === true) {
182
- $hr = esc_url(admin_url('admin.php?page=wpmseo_titles#top#post_types'));
183
  $field_defs['metakeywords']['description'] = sprintf(
184
  $field_defs['metakeywords']['description'],
185
  '<a target="_blank" href="' . $hr . '">',
@@ -204,13 +217,8 @@ class WPMSEOMeta
204
  * Get a custom post meta value
205
  * Returns the default value if the meta value has not been set
206
  *
207
- * @internal Unfortunately there isn't a filter available to hook into before returning the results
208
- * for get_post_meta(), get_post_custom() and the likes. That would have been the preferred solution.
209
- *
210
- * @static
211
- *
212
- * @param string $key Internal key of the value to get (without prefix).
213
- * @param int $postid Post ID of the post to get the value for.
214
  *
215
  * @return string All 'normal' values returned from get_post_meta() are strings.
216
  * Objects and arrays are possible, but not used by this plugin
@@ -227,7 +235,7 @@ class WPMSEOMeta
227
  $postid = absint($postid);
228
  if ($postid === 0) {
229
  if ((isset($post) && is_object($post)) && (isset($post->post_status)
230
- && $post->post_status !== 'auto-draft')) {
231
  $postid = $post->ID;
232
  } else {
233
  return '';
@@ -255,13 +263,11 @@ class WPMSEOMeta
255
  /**
256
  * Update a meta value for a post
257
  *
258
- * @static
259
- *
260
- * @param string $key The internal key of the meta value to change (without prefix).
261
- * @param mixed $meta_value The value to set the meta to.
262
- * @param int $post_id The ID of the post to change the meta for.
263
  *
264
- * @return bool whether the value was changed
265
  */
266
  public static function setValue($key, $meta_value, $post_id)
267
  {
10
  class WPMSEOMeta
11
  {
12
  /**
13
+ * WPMS meta prefix
14
+ *
15
  * @var string
16
  */
17
  public static $meta_prefix = '_metaseo_meta';
18
  /**
19
+ * WPMS form prefix
20
+ *
21
  * @var string
22
  */
23
  public static $form_prefix = 'metaseo_wpmseo_';
24
  /**
25
+ * Meta description max length
26
+ *
27
+ * @var integer
28
  */
29
  public static $meta_length = 320;
30
  /**
31
+ * Meta title max length
32
+ *
33
+ * @var integer
34
  */
35
  public static $meta_title_length = 69;
36
  /**
37
+ * Meta keywords max length
38
+ *
39
+ * @var integer
40
  */
41
  public static $meta_keywords_length = 256;
42
  /**
43
+ * Meta length reason
44
+ *
45
  * @var string
46
  */
47
  public static $meta_length_reason = '';
48
  /**
49
+ * Meta fields
50
+ *
51
  * @var array
52
  */
53
  public static $meta_fields = array(
54
+ 'general' => array(
55
  'snippetpreview' => array(
56
+ 'type' => 'snippetpreview',
57
  'title' => '',
58
+ 'help' => '',
59
  ),
60
+ 'title' => array(
61
+ 'type' => 'textarea',
62
+ 'title' => '',
63
  'default_value' => '',
64
+ 'description' => '',
65
+ 'help' => '',
66
+ 'rows' => 2
67
  ),
68
+ 'desc' => array(
69
+ 'type' => 'textarea',
70
+ 'title' => '',
71
  'default_value' => '',
72
+ 'class' => 'desc',
73
+ 'rows' => 3,
74
+ 'description' => '',
75
+ 'help' => '',
76
  ),
77
+ 'keywords' => array(
78
+ 'type' => 'textarea',
79
+ 'title' => '',
80
  'default_value' => '',
81
+ 'description' => '',
82
+ 'help' => '',
83
+ 'rows' => 2
84
  ),
85
+ 'metaseo_chart' => array(
86
+ 'type' => 'metaseo_chart',
87
+ 'title' => '',
88
  'default_value' => '',
89
+ 'class' => 'metaseo_chart',
90
+ 'rows' => 2,
91
+ 'description' => '',
92
+ 'help' => '',
93
  )
94
  ),
95
+ 'social' => array(
96
  'opengraph-title' => array(
97
+ 'type' => 'text',
98
+ 'title' => '',
99
  'default_value' => '',
100
+ 'description' => '',
101
+ 'help' => '',
102
  ),
103
+ 'opengraph-desc' => array(
104
+ 'type' => 'textarea',
105
+ 'title' => '',
106
  'default_value' => '',
107
+ 'class' => 'desc',
108
+ 'rows' => 3,
109
+ 'description' => '',
110
+ 'help' => '',
111
  ),
112
  'opengraph-image' => array(
113
+ 'type' => 'upload',
114
+ 'title' => '',
115
  'default_value' => '',
116
+ 'class' => 'desc',
117
+ 'description' => '',
118
+ 'help' => '',
119
  ),
120
+ 'twitter-title' => array(
121
+ 'type' => 'text',
122
+ 'title' => '',
123
  'default_value' => '',
124
+ 'description' => '',
125
+ 'help' => '',
126
  ),
127
+ 'twitter-desc' => array(
128
+ 'type' => 'textarea',
129
+ 'title' => '',
130
  'default_value' => '',
131
+ 'class' => 'desc',
132
+ 'rows' => 3,
133
+ 'description' => '',
134
+ 'help' => '',
135
  ),
136
+ 'twitter-image' => array(
137
+ 'type' => 'upload',
138
+ 'title' => '',
139
  'default_value' => '',
140
+ 'class' => 'desc',
141
+ 'description' => '',
142
+ 'help' => '',
143
  ),
144
  ),
145
  'non_form' => array(
146
  'linkdex' => array(
147
+ 'type' => null,
148
  'default_value' => '0',
149
  ),
150
  ),
151
  );
152
+
153
  /**
154
+ * Default
155
+ *
 
 
156
  * @var array
157
  */
158
  public static $defaults = array();
159
 
160
  /**
161
  * Init
162
+ *
163
+ * @return void
164
  */
165
  public static function init()
166
  {
171
  /**
172
  * Retrieve the meta box form field definitions for the given tab and post type.
173
  *
174
+ * @param string $tab Tab for which to retrieve the field definitions.
175
+ * @param string $post_type Post type of the current post.
 
 
176
  *
177
  * @return array Array containing the meta box field definitions
178
  */
192
  case 'general':
193
  $options = get_option('wpmseo_titles');
194
  if ($options['usemetakeywords'] === true) {
195
+ $hr = esc_url(admin_url('admin.php?page=wpmseo_titles#top#post_types'));
196
  $field_defs['metakeywords']['description'] = sprintf(
197
  $field_defs['metakeywords']['description'],
198
  '<a target="_blank" href="' . $hr . '">',
217
  * Get a custom post meta value
218
  * Returns the default value if the meta value has not been set
219
  *
220
+ * @param string $key Internal key of the value to get (without prefix).
221
+ * @param integer $postid Post ID of the post to get the value for.
 
 
 
 
 
222
  *
223
  * @return string All 'normal' values returned from get_post_meta() are strings.
224
  * Objects and arrays are possible, but not used by this plugin
235
  $postid = absint($postid);
236
  if ($postid === 0) {
237
  if ((isset($post) && is_object($post)) && (isset($post->post_status)
238
+ && $post->post_status !== 'auto-draft')) {
239
  $postid = $post->ID;
240
  } else {
241
  return '';
263
  /**
264
  * Update a meta value for a post
265
  *
266
+ * @param string $key The internal key of the meta value to change (without prefix).
267
+ * @param mixed $meta_value The value to set the meta to.
268
+ * @param integer $post_id The ID of the post to change the meta for.
 
 
269
  *
270
+ * @return boolean whether the value was changed
271
  */
272
  public static function setValue($key, $meta_value, $post_id)
273
  {
inc/class.metaseo-metabox.php CHANGED
@@ -11,16 +11,21 @@ require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-snippet-preview.php');
11
  class WPMSEOMetabox extends WPMSEOMeta
12
  {
13
  /**
14
- * @var int
 
 
15
  */
16
  public $perc_score = 0;
17
  /**
18
- * @var
 
 
19
  */
20
  public $settings;
21
  /**
22
  * Google client
23
- * @var
 
24
  */
25
  public $client;
26
 
@@ -37,11 +42,22 @@ class WPMSEOMetabox extends WPMSEOMeta
37
  }
38
 
39
  /**
40
- * @param $post_id
41
- * @return bool
 
 
 
42
  */
43
  public function savePostData($post_id)
44
  {
 
 
 
 
 
 
 
 
45
  if ($post_id === null) {
46
  return false;
47
  }
@@ -52,7 +68,6 @@ class WPMSEOMetabox extends WPMSEOMeta
52
 
53
  clean_post_cache($post_id);
54
  $post = get_post($post_id);
55
-
56
  if (!is_object($post)) {
57
  return false;
58
  }
@@ -69,6 +84,7 @@ class WPMSEOMetabox extends WPMSEOMeta
69
  $this->getMetaFieldDefs('advanced'),
70
  $this->getMetaFieldDefs('social')
71
  );
 
72
  foreach ($meta_boxes as $key => $meta_box) {
73
  $data = null;
74
  if ('checkbox' === $meta_box['type']) {
@@ -88,77 +104,81 @@ class WPMSEOMetabox extends WPMSEOMeta
88
 
89
  /**
90
  * Translate text strings for use in the meta box
 
 
91
  */
92
  public static function translateMetaBoxes()
93
  {
94
- self::$meta_fields['general']['snippetpreview']['title'] = __('Results preview', 'wp-meta-seo');
95
- self::$meta_fields['general']['snippetpreview']['help'] = sprintf(
96
- __('This is a preview of what your content will looks like
97
  in search engine results: title, description and URL', 'wp-meta-seo'),
98
  '<a target="_blank" href="https://www.joomunited.com/wordpress-products/wpms">',
99
  '</a>'
100
  );
101
 
102
- self::$meta_fields['general']['title']['title'] = __('Search engine title', 'wp-meta-seo');
103
  self::$meta_fields['general']['title']['description'] = sprintf(
104
  '<span id="metaseo_wpmseo_title-length">%s</span>',
105
  self::$meta_length_reason
106
  );
107
- self::$meta_fields['general']['title']['help'] = __('This is the title of your content that may be displayed
108
  in search engine results (meta title). By default it’s the content title (page title, post title…).
109
  69 characters max allowed.', 'wp-meta-seo');
110
 
111
  $settings = get_option('_metaseo_settings');
112
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
113
- self::$meta_fields['general']['keywords']['title'] = __('Search engine keywords', 'wp-meta-seo');
114
  self::$meta_fields['general']['keywords']['description']
115
- = '<span id="metaseo_wpmseo_keywords-length"></span>';
116
- self::$meta_fields['general']['keywords']['help'] = __('This is the keywords of your content that may be
117
  displayed in search engine results (meta keywords).', 'wp-meta-seo');
118
  } else {
119
  unset(self::$meta_fields['general']['keywords']);
120
  }
121
 
122
 
123
- self::$meta_fields['general']['desc']['title'] = __('Search engine description', 'wp-meta-seo');
124
  self::$meta_fields['general']['desc']['description'] = sprintf(
125
  '<span id="metaseo_wpmseo_desc-length">%s</span>',
126
  self::$meta_length_reason
127
  );
128
- self::$meta_fields['general']['desc']['help'] = __('The description of your content that may be displayed
129
  in search engine results aka meta description.
130
  By default search engine take an excerpt from your content (depending on the search query).
131
  320 characters max allowed.', 'wp-meta-seo');
132
 
133
- self::$meta_fields['social']['opengraph-title']['title'] = __('Facebook Title', 'wp-meta-seo');
134
- self::$meta_fields['social']['opengraph-title']['description'] = __('Custom title to display when
135
  sharing this content on facebook, content title override', 'wp-meta-seo');
136
 
137
- self::$meta_fields['social']['opengraph-desc']['title'] = __('Facebook Description', 'wp-meta-seo');
138
- self::$meta_fields['social']['opengraph-desc']['description'] = __('Custom description to display when sharing
139
  this content on facebook, content description override', 'wp-meta-seo');
140
 
141
- self::$meta_fields['social']['opengraph-image']['title'] = __('Facebook Image', 'wp-meta-seo');
142
- self::$meta_fields['social']['opengraph-image']['description'] = __('Custom image to display when sharing
143
  this content on facebook, content description override, recommended size is 1200px x 630px', 'wp-meta-seo');
144
 
145
- self::$meta_fields['social']['twitter-title']['title'] = __('Twitter Title', 'wp-meta-seo');
146
- self::$meta_fields['social']['twitter-title']['description'] = __('Custom title to display when sharing this
147
  content on twitter, content title override', 'wp-meta-seo');
148
 
149
- self::$meta_fields['social']['twitter-desc']['title'] = __('Twitter Description', 'wp-meta-seo');
150
- self::$meta_fields['social']['twitter-desc']['description'] = __('Custom description to display when sharing
151
  this content on twitter, content description override', 'wp-meta-seo');
152
 
153
- self::$meta_fields['social']['twitter-image']['title'] = __('Twitter Image', 'wp-meta-seo');
154
- self::$meta_fields['social']['twitter-image']['description'] = __('Custom image to display when sharing
155
  this content on facebook, content description override, recommended min size 440px X 220px', 'wp-meta-seo');
156
 
157
  do_action('wpmseo_tab_translate');
158
  }
159
 
160
  /**
161
- * load script and style
 
 
162
  */
163
  public function metaseoEnqueue()
164
  {
@@ -168,13 +188,13 @@ class WPMSEOMetabox extends WPMSEOMeta
168
  'post.php',
169
  'edit.php',
170
  ), true)
171
- && apply_filters('wpmseo_always_register_metaboxes_on_admin', false) === false)
172
  ) {
173
  return;
174
  }
175
 
176
- if ($pagenow != 'edit.php') {
177
- if (0 != get_queried_object_id()) {
178
  // Enqueue files needed for upload functionality.
179
  wp_enqueue_media(
180
  array(
@@ -231,35 +251,48 @@ class WPMSEOMetabox extends WPMSEOMeta
231
 
232
  /**
233
  * Localize a script
 
234
  * @return array
235
  */
236
  public function localizeSettingsScript()
237
  {
 
 
 
 
 
 
 
 
 
238
  $this->settings = array(
239
- "metaseo_title_home" => "",
240
- "metaseo_desc_home" => "",
241
- "metaseo_showfacebook" => "",
242
- "metaseo_showtwitter" => "",
243
- "metaseo_twitter_card" => "summary",
244
- "metaseo_showkeywords" => 0,
245
- "metaseo_showtmetablock" => 1,
246
- "metaseo_showsocial" => 1,
247
- "metaseo_seovalidate" => 0
248
  );
249
- $settings = get_option('_metaseo_settings');
250
 
251
  if (is_array($settings)) {
252
  $this->settings = array_merge($this->settings, $settings);
253
  }
254
 
255
  return array(
256
- 'choose_image' => __('Use Image', 'wp-meta-seo'),
257
- 'use_validate' => $this->settings['metaseo_seovalidate']
 
 
258
  );
259
  }
260
 
261
  /**
262
  * Localize a script
 
263
  * @return array
264
  */
265
  public function localizeScript()
@@ -271,10 +304,10 @@ class WPMSEOMetabox extends WPMSEOMeta
271
  }
272
 
273
  self::$meta_length_reason = apply_filters('wpmseo_desc_length_reason', self::$meta_length_reason, $post);
274
- self::$meta_length = apply_filters('wpmseo_desc_length', self::$meta_length, $post);
275
- $title_template = '%%title%% - %%sitename%%';
276
 
277
- $desc_template = '';
278
  $sample_permalink = get_sample_permalink($post->ID);
279
  $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
280
 
@@ -291,24 +324,24 @@ class WPMSEOMetabox extends WPMSEOMeta
291
  }
292
 
293
  $cached_replacement_vars['sitename'] = get_option('blogname');
294
- $plugin_active = json_encode(get_option('active_plugins'));
295
- $array_keyword = array(
296
- 'plugin_active' => $plugin_active,
297
- 'field_prefix' => self::$form_prefix,
298
- 'choose_image' => __('Use Image', 'wp-meta-seo'),
299
- 'wpmseo_meta_desc_length' => self::$meta_length,
300
- 'wpmseo_meta_title_length' => self::$meta_title_length,
301
- 'wpmseo_meta_keywords_length' => self::$meta_keywords_length,
302
- 'wpmseo_title_template' => $title_template,
303
- 'wpmseo_desc_template' => $desc_template,
304
- 'wpmseo_permalink_template' => $sample_permalink,
305
  'wpmseo_keyword_suggest_nonce' => wp_create_nonce('wpmseo-get-suggest'),
306
- 'wpmseo_replace_vars_nonce' => wp_create_nonce('wpmseo-replace-vars'),
307
- 'no_parent_text' => __('(no parent)', 'wp-meta-seo'),
308
- 'show_keywords' => 0
309
  );
310
- $settings = get_option('_metaseo_settings');
311
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
312
  $array_keyword['show_keywords'] = 1;
313
  }
314
 
@@ -317,13 +350,15 @@ class WPMSEOMetabox extends WPMSEOMeta
317
 
318
  /**
319
  * Adds the Meta SEO meta box to the edit boxes in the edit post / page / cpt pages.
 
 
320
  */
321
  public function addMetaBox()
322
  {
323
  $post_types = get_post_types(array('public' => true));
324
  if (is_array($post_types) && $post_types !== array()) {
325
  foreach ($post_types as $post_type) {
326
- add_meta_box('wpmseo_meta', __('WP Meta SEO - Page optimization', 'wp-meta-seo'), array(
327
  $this,
328
  'metaBox',
329
  ), $post_type, 'normal', apply_filters('wpmseo_metabox_prio', 'core'));
@@ -333,32 +368,34 @@ class WPMSEOMetabox extends WPMSEOMeta
333
 
334
  /**
335
  * Output the meta box
 
 
336
  */
337
  public function metaBox()
338
  {
339
  $this->metaseoEnqueue();
340
- $post = $this->getMetaboxPost();
341
  $default_settings = array(
342
- "metaseo_title_home" => "",
343
- "metaseo_desc_home" => "",
344
- "metaseo_showfacebook" => "",
345
- "metaseo_showtwitter" => "",
346
- "metaseo_twitter_card" => "summary",
347
- "metaseo_showtmetablock" => 1,
348
- "metaseo_showsocial" => 1
349
  );
350
- $settings = get_option('_metaseo_settings');
351
  if (is_array($settings)) {
352
  $default_settings = array_merge($default_settings, $settings);
353
  }
354
  $check_connected = false;
355
- $service = false;
356
  ?>
357
  <div class="wpmseo-metabox-tabs-div">
358
  <ul class="wpmseo-metabox-tabs" id="wpmseo-metabox-tabs">
359
  <li class="general">
360
  <a class="wpmseo_tablink"
361
- data-link="wpmseo_general"><?php _e('SEO Page optimization', 'wp-meta-seo'); ?></a>
362
  </li>
363
  <?php
364
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
@@ -373,7 +410,7 @@ class WPMSEOMetabox extends WPMSEOMeta
373
  if ($check_connected) {
374
  echo '<li class="gsckeywords">';
375
  echo '<a class="wpmseo_tablink" data-link="wpmseo_gsc_keywords">';
376
- echo __('Search console keywords', 'wp-meta-seo');
377
  echo '</a>';
378
  echo '</li>';
379
  }
@@ -381,10 +418,10 @@ class WPMSEOMetabox extends WPMSEOMeta
381
  ?>
382
 
383
  <?php if ((isset($default_settings['metaseo_showsocial'])
384
- && $default_settings['metaseo_showsocial'] == 1)) : ?>
385
  <li class="social">
386
  <a class="wpmseo_tablink"
387
- data-link="wpmseo_social"><?php _e('Social for search engine', 'wp-meta-seo') ?></a>
388
  </li>
389
  <?php endif; ?>
390
  <?php do_action('wpmseo_tab_header'); ?>
@@ -400,6 +437,7 @@ class WPMSEOMetabox extends WPMSEOMeta
400
  $this->doTab('general', $content);
401
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
402
  if ($check_connected) {
 
403
  echo apply_filters('wpmsaddon_google_search_keywords', '', $post->post_content, $service);
404
  }
405
  }
@@ -410,7 +448,7 @@ class WPMSEOMetabox extends WPMSEOMeta
410
  $content .= $this->doMetaBox($meta_field, $meta_key);
411
  }
412
 
413
- if ((isset($default_settings['metaseo_showsocial']) && $default_settings['metaseo_showsocial'] == 1)) {
414
  $this->doTab('social', $content);
415
  }
416
 
@@ -420,318 +458,89 @@ class WPMSEOMetabox extends WPMSEOMeta
420
  }
421
 
422
  /**
423
- * @return bool|Wpms_Google_Service_Webmasters
 
 
424
  */
425
  public function serverWebmaster()
426
  {
427
  try {
428
  if (!class_exists('Wpms_Api_Google', false)) {
429
- require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/google-api/' . 'class-api-google.php';
430
  new Wpms_Api_Google();
431
  }
432
  } catch (Exception $exception) {
 
433
  }
434
 
435
  $conn = get_option('wpms_gsc_connect');
436
  if (!empty($conn['googleClientId']) && !empty($conn['googleClientSecret'])) {
437
- $client_id = $conn['googleClientId'];
438
  $client_secret = $conn['googleClientSecret'];
439
  } else {
440
- $client_id = WPMSEO_ADDON_CLIENT_ID;
441
  $client_secret = WPMSEO_ADDON_CLIENT_SECRET;
442
  }
443
 
444
  $gsc = array(
445
  'application_name' => 'WP Meta SEO',
446
- 'client_id' => $client_id,
447
- 'client_secret' => $client_secret,
448
- 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
449
- 'scopes' => array('https://www.googleapis.com/auth/webmasters'),
450
  );
451
 
452
  $this->client = new Wpms_Api_Google_Client($gsc, 'wpms-gsc', 'https://www.googleapis.com/webmasters/v3/');
453
- if ($this->client->getAccessToken() != null) {
454
  $service = new Wpms_Google_Service_Webmasters($this->client);
455
  return $service;
456
  }
457
  return false;
458
  }
459
 
460
- /**
461
- * Generate html field settings
462
- * @param $data_title
463
- * @param $alt
464
- * @param $dashicon
465
- * @param $label
466
- * @param $value_hidden
467
- * @return string
468
- */
469
- public function createFieldAnalysis($data_title, $alt, $dashicon, $label, $value_hidden)
470
- {
471
- $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . $data_title . '" data-alt="' . $alt . '">';
472
- if ($dashicon == 'done') {
473
- $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxdone">done</i>' . $label . '</div>';
474
- } else {
475
- $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxwarning">warning</i>' . $label . '</div>';
476
- }
477
-
478
- $output .= '<input type="hidden" class="wpms_analysis_hidden" name="wpms[' . $data_title . ']"
479
- value="' . $value_hidden . '">';
480
- return $output;
481
- }
482
-
483
- /**
484
- * load heading title status in page optimize
485
- * @param $tooltip_page
486
- * @return string
487
- */
488
- public function headingTitle($tooltip_page)
489
- {
490
- $output = $this->createFieldAnalysis(
491
- 'heading_title',
492
- $tooltip_page['title_in_heading'],
493
- 'warning',
494
- __('Page title word in content heading', 'wp-meta-seo'),
495
- 0
496
- );
497
- return $output;
498
- }
499
-
500
- /**
501
- * load meta title in content status in page optimize
502
- * @param $tooltip_page
503
- * @return string
504
- */
505
- public function titleContent($tooltip_page)
506
- {
507
- $output = $this->createFieldAnalysis(
508
- 'content_title',
509
- $tooltip_page['title_in_content'],
510
- 'warning',
511
- __('Page title word in content', 'wp-meta-seo'),
512
- 0
513
- );
514
- return $output;
515
- }
516
-
517
- /**
518
- * load page url status in page optimize
519
- * @param $tooltip_page
520
- * @return string
521
- */
522
- public function pageUrl($tooltip_page)
523
- {
524
- $output = $this->createFieldAnalysis(
525
- 'pageurl',
526
- $tooltip_page['page_url'],
527
- 'warning',
528
- __('Page url matches with page title', 'wp-meta-seo'),
529
- 0
530
- );
531
-
532
- return $output;
533
- }
534
-
535
- /**
536
- * load meta title status in page optimize
537
- * @param $tooltip_page
538
- * @return string
539
- */
540
- public function metaTitle($tooltip_page)
541
- {
542
- $output = $this->createFieldAnalysis(
543
- 'metatitle',
544
- $tooltip_page['meta_title'],
545
- 'warning',
546
- __('Meta title filled', 'wp-meta-seo'),
547
- 0
548
- );
549
-
550
- return $output;
551
- }
552
-
553
- /**
554
- * load meta description status in page optimize
555
- * @param $tooltip_page
556
- * @return string
557
- */
558
- public function metaDesc($tooltip_page)
559
- {
560
- $output = $this->createFieldAnalysis(
561
- 'metadesc',
562
- $tooltip_page['meta_desc'],
563
- 'warning',
564
- __('Meta description filled', 'wp-meta-seo'),
565
- 0
566
- );
567
-
568
- return $output;
569
- }
570
-
571
- /**
572
- * load image resize status in page optimize
573
- * @param $tooltip_page
574
- * @return string
575
- */
576
- public function imageResize($tooltip_page)
577
- {
578
- $output = $this->createFieldAnalysis(
579
- 'imgresize',
580
- $tooltip_page['image_resize'],
581
- 'warning',
582
- __('Wrong image resize', 'wp-meta-seo'),
583
- 0
584
- );
585
-
586
- return $output;
587
- }
588
-
589
- /**
590
- * load image alt status in page optimize
591
- * @param $tooltip_page
592
- * @return string
593
- */
594
- public function imageAlt($tooltip_page)
595
- {
596
- $output = $this->createFieldAnalysis(
597
- 'imgalt',
598
- $tooltip_page['image_alt'],
599
- 'warning',
600
- __('Image have meta title or alt', 'wp-meta-seo'),
601
- 0
602
- );
603
-
604
- return $output;
605
- }
606
-
607
  /**
608
  * Load page analysis
609
- * @param $post
 
 
610
  * @return string
611
  */
612
  public function pageAnalysis($post)
613
  {
614
-
615
- $tooltip_page = array();
616
- $tooltip_page['title_in_heading'] = __('Check if a word of this
617
- content title is also in a title heading (h1, h2...)', 'wp-meta-seo');
618
- $tooltip_page['title_in_content'] = __('Check if a word of this content
619
- title is also in the text', 'wp-meta-seo');
620
- $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
621
- $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
622
- $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
623
- $tooltip_page['image_resize'] = __('Check for image HTML resizing
624
- in content (usually image resized using handles)', 'wp-meta-seo');
625
- $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
626
-
627
- $headingtitle = $this->headingTitle($tooltip_page);
628
- $contenttitle = $this->titleContent($tooltip_page);
629
- $pageurl = $this->pageUrl($tooltip_page);
630
- $metatitle = $this->metaTitle($tooltip_page);
631
- $metadesc = $this->metaDesc($tooltip_page);
632
- $imagewrong = $this->imageResize($tooltip_page);
633
- $imagealt = $this->imageAlt($tooltip_page);
634
-
635
  $output = '';
636
-
637
  $circliful = 0;
638
- $output .= '<div style="width:100%;float:left;">';
639
- $output .= '<div class="metaseo_left">
640
- <div class="metaseo-progress-bar" data-post_id="' . $post->ID . '">
641
  <canvas id="inactiveProgress" class="metaseo-progress-inactive" height="275px" width="275px"></canvas>
642
  <canvas id="activeProgress" class="metaseo-progress-active" height="275px" width="275px"></canvas>
643
  <p>0%</p>
644
  </div>
645
- <input type="hidden" id="progressController" value="' . $circliful . '" />
646
- <input type="hidden" id="metaseo_alanysis_ok" value="' . $this->perc_score . '" />
647
  </div>';
648
 
649
  $output .= '<div class="metaseo_right">';
650
- $output .= $headingtitle . $contenttitle . $pageurl . $metatitle . $metadesc . $imagewrong . $imagealt;
651
  $output .= '</div>';
652
  $output .= '</div>';
653
  return $output;
654
  }
655
 
656
- /**
657
- * Display html content for current tab
658
- * @param $id
659
- * @param $content
660
- */
661
- public function doTab($id, $content)
662
- {
663
- global $post;
664
- ?>
665
- <div class="wpmseotab <?php echo esc_attr($id) ?>">
666
- <?php if ($id == 'general') : ?>
667
- <p class="reload_analysis">
668
- <span class="spinner" style="float: left;"></span>
669
- <input type="button" name="reload_analysis" id="reload_analysis" class="button button-primary"
670
- value="<?php _e('Reload analysis', 'wp-meta-seo'); ?>">
671
- </p>
672
- <?php endif; ?>
673
- <table class="form-table">
674
- <?php echo $content; ?>
675
- </table>
676
- <?php
677
- if ($id == 'general') {
678
- echo $this->pageAnalysis($post);
679
- $settings = get_option('_metaseo_settings');
680
- if (!empty($settings['metaseo_follow'])) {
681
- $page_follow = get_post_meta($post->ID, '_metaseo_metafollow', true);
682
- $slf = '<select class="metaseo_metabox_follow" data-post_id="' . $post->ID . '">';
683
- if ($page_follow == 'nofollow') {
684
- $slf .= '<option value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
685
- $slf .= '<option selected value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
686
- } else {
687
- $slf .= '<option selected value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
688
- $slf .= '<option value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
689
- }
690
- $slf .= '</select>';
691
- echo '<p><span class="wpmslabel">' . __('Follow', 'wp-meta-seo') . '
692
- <i class="material-icons alignright metaseo_help" id="deschelp"
693
- alt="' . __('Nofollow provides a way for webmasters to tell search engines:
694
- don\'t follow this link. So it may influence the link target’s ranking', 'wp-meta-seo') . '"
695
- style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $slf . '</p>';
696
- }
697
-
698
- if (!empty($settings['metaseo_index'])) {
699
- $page_index = get_post_meta($post->ID, '_metaseo_metaindex', true);
700
- $sli = '<select class="metaseo_metabox_index" data-post_id="' . $post->ID . '">';
701
- if ($page_index == 'noindex') {
702
- $sli .= '<option value="index">' . __('Index', 'wp-meta-seo') . '</option>';
703
- $sli .= '<option selected value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
704
- } else {
705
- $sli .= '<option selected value="index">' . __('Index', 'wp-meta-seo') . '</option>';
706
- $sli .= '<option value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
707
- }
708
-
709
- $sli .= '</select>';
710
- echo '<p><span class="wpmslabel">' . __('Index', 'wp-meta-seo') . '
711
- <i class="material-icons alignright metaseo_help" id="deschelp"
712
- alt="' . __('Allow search engines robots to index this content,
713
- as default your content is indexed', 'wp-meta-seo') . '"
714
- style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $sli . '</p>';
715
- }
716
- }
717
- ?>
718
- </div>
719
- <?php
720
- }
721
-
722
  /**
723
  * Display html content for current tab
724
- * @param $meta_field_def
725
- * @param string $key
 
 
726
  * @return string
727
  */
728
  public function doMetaBox($meta_field_def, $key = '')
729
  {
730
  wp_enqueue_style('metaseo-google-icon');
731
- $content = '';
732
  $esc_form_key = esc_attr(self::$form_prefix . $key);
733
- $post = $this->getMetaboxPost();
734
- $meta_value = self::getValue($key, $post->ID);
735
 
736
  $class = '';
737
  if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
@@ -756,9 +565,9 @@ class WPMSEOMetabox extends WPMSEOMeta
756
  if ($placeholder !== '') {
757
  $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
758
  }
759
- $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . '
760
- name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '"
761
- class="large-text' . $class . '"/><br />';
762
  break;
763
 
764
  case 'textarea':
@@ -766,19 +575,19 @@ class WPMSEOMetabox extends WPMSEOMeta
766
  if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
767
  $rows = $meta_field_def['rows'];
768
  }
769
- $content .= '<textarea class="large-text' . $class . '"
770
- rows="' . esc_attr($rows) . '" id="' . $esc_form_key . '"
771
- name="' . $esc_form_key . '">' . esc_textarea($meta_value) . '</textarea>';
772
  break;
773
 
774
  case 'select':
775
  if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
776
- && $meta_field_def['options'] !== array()) {
777
- $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '"
778
- class="metaseo' . $class . '">';
779
  foreach ($meta_field_def['options'] as $val => $option) {
780
  $selected = selected($meta_value, $val, false);
781
- $content .= '<option ' . $selected . '
782
  value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
783
  }
784
  unset($val, $option, $selected);
@@ -786,64 +595,11 @@ class WPMSEOMetabox extends WPMSEOMeta
786
  }
787
  break;
788
 
789
- case 'multiselect':
790
- if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
791
- && $meta_field_def['options'] !== array()) {
792
- $selected_arr = $meta_value;
793
- if ('meta-robots-adv' == $key) {
794
- $selected_arr = explode(',', $meta_value);
795
- }
796
-
797
- if (!is_array($selected_arr)) {
798
- $selected_arr = (array)$selected_arr;
799
- }
800
-
801
- $options_count = count($meta_field_def['options']);
802
-
803
- $content .= '<select multiple="multiple" size="' . esc_attr($options_count) . '"
804
- style="height: ' . esc_attr(($options_count * 20) + 4) . 'px;"
805
- name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="metaseo' . $class . '">';
806
- foreach ($meta_field_def['options'] as $val => $option) {
807
- $selected = '';
808
- if (in_array($val, $selected_arr)) {
809
- $selected = ' selected="selected"';
810
- }
811
- $content .= '<option ' . $selected . '
812
- value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
813
- }
814
- $content .= '</select>';
815
- unset($val, $option, $selected, $selected_arr, $options_count);
816
- }
817
- break;
818
-
819
- case 'checkbox':
820
- $checked = checked($meta_value, 'on', false);
821
- $expl = (isset($meta_field_def['expl'])) ? esc_html($meta_field_def['expl']) : '';
822
- $content .= '<label for="' . $esc_form_key . '"><input type="checkbox"
823
- id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . '
824
- value="on" class="metaseo' . $class . '"/> ' . $expl . '</label><br />';
825
- unset($checked, $expl);
826
- break;
827
-
828
- case 'radio':
829
- if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
830
- && $meta_field_def['options'] !== array()) {
831
- foreach ($meta_field_def['options'] as $val => $option) {
832
- $checked = checked($meta_value, $val, false);
833
- $content .= '<input type="radio" ' . $checked . '
834
- id="' . $esc_form_key . '_' . esc_attr($val) . '" name="' . $esc_form_key . '"
835
- value="' . esc_attr($val) . '"/> <label for="' . $esc_form_key . '_' . esc_attr($val) . '">
836
- ' . esc_html($option) . '</label> ';
837
- }
838
- unset($val, $option, $checked);
839
- }
840
- break;
841
-
842
  case 'upload':
843
- $content .= '<input id="' . $esc_form_key . '" type="text" size="36" class="' . $class . '"
844
- name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" />';
845
- $content .= '<input id="' . $esc_form_key . '_button" class="wpmseo_image_upload_button button"
846
- type="button" value="' . __('Upload Image', 'wp-meta-seo') . '" />';
847
  break;
848
  }
849
 
@@ -868,13 +624,13 @@ class WPMSEOMetabox extends WPMSEOMeta
868
  'checkbox',
869
  ), true) === false
870
  ) {
871
- $label = '<label for="' . $esc_form_key . '">' . $label . ':</label>';
872
  }
873
 
874
  $help = '';
875
  if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
876
  $help = '<i class="material-icons alignright metaseo_help"
877
- id="' . esc_attr($key . 'help') . '" alt="' . esc_attr($meta_field_def['help']) . '"
878
  style="color:#32373C">chat_bubble</i>';
879
  }
880
 
@@ -897,13 +653,16 @@ class WPMSEOMetabox extends WPMSEOMeta
897
  }
898
 
899
  /**
 
 
900
  * @return array|mixed|null|WP_Post
901
  */
902
  private function getMetaboxPost()
903
  {
 
904
  if (isset($_GET['post'])) {
905
- $post_id = (int)$_GET['post'];
906
- $post = get_post($post_id);
907
  } else {
908
  $post = $GLOBALS['post'];
909
  }
@@ -912,16 +671,91 @@ class WPMSEOMetabox extends WPMSEOMeta
912
  }
913
 
914
  /**
 
 
915
  * @return string
916
  */
917
  public function snippet()
918
  {
919
- $post = $this->getMetaboxPost();
920
- $title = self::getValue('title', $post->ID);
921
  $description = self::getValue('desc', $post->ID);
922
 
923
  $snippet_preview = new WPMSEOSnippetPreview($post, $title, $description);
924
 
925
  return $snippet_preview->getContent();
926
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
927
  }
11
  class WPMSEOMetabox extends WPMSEOMeta
12
  {
13
  /**
14
+ * Percent score
15
+ *
16
+ * @var integer
17
  */
18
  public $perc_score = 0;
19
  /**
20
+ * WPMS settings
21
+ *
22
+ * @var array
23
  */
24
  public $settings;
25
  /**
26
  * Google client
27
+ *
28
+ * @var object
29
  */
30
  public $client;
31
 
42
  }
43
 
44
  /**
45
+ * Save post
46
+ *
47
+ * @param integer $post_id Post id
48
+ *
49
+ * @return boolean
50
  */
51
  public function savePostData($post_id)
52
  {
53
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce used in next lines
54
+ if (isset($_POST['metaseo_wpmseo_title'])) {
55
+ if (empty($_POST['_wpnonce'])
56
+ || !wp_verify_nonce($_POST['_wpnonce'], 'update-post_' . $post_id)) {
57
+ return false;
58
+ }
59
+ }
60
+
61
  if ($post_id === null) {
62
  return false;
63
  }
68
 
69
  clean_post_cache($post_id);
70
  $post = get_post($post_id);
 
71
  if (!is_object($post)) {
72
  return false;
73
  }
84
  $this->getMetaFieldDefs('advanced'),
85
  $this->getMetaFieldDefs('social')
86
  );
87
+
88
  foreach ($meta_boxes as $key => $meta_box) {
89
  $data = null;
90
  if ('checkbox' === $meta_box['type']) {
104
 
105
  /**
106
  * Translate text strings for use in the meta box
107
+ *
108
+ * @return void
109
  */
110
  public static function translateMetaBoxes()
111
  {
112
+ self::$meta_fields['general']['snippetpreview']['title'] = esc_html__('Results preview', 'wp-meta-seo');
113
+ self::$meta_fields['general']['snippetpreview']['help'] = sprintf(
114
+ esc_attr__('This is a preview of what your content will looks like
115
  in search engine results: title, description and URL', 'wp-meta-seo'),
116
  '<a target="_blank" href="https://www.joomunited.com/wordpress-products/wpms">',
117
  '</a>'
118
  );
119
 
120
+ self::$meta_fields['general']['title']['title'] = esc_html__('Search engine title', 'wp-meta-seo');
121
  self::$meta_fields['general']['title']['description'] = sprintf(
122
  '<span id="metaseo_wpmseo_title-length">%s</span>',
123
  self::$meta_length_reason
124
  );
125
+ self::$meta_fields['general']['title']['help'] = esc_attr__('This is the title of your content that may be displayed
126
  in search engine results (meta title). By default it’s the content title (page title, post title…).
127
  69 characters max allowed.', 'wp-meta-seo');
128
 
129
  $settings = get_option('_metaseo_settings');
130
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
131
+ self::$meta_fields['general']['keywords']['title'] = esc_html__('Search engine keywords', 'wp-meta-seo');
132
  self::$meta_fields['general']['keywords']['description']
133
+ = '<span id="metaseo_wpmseo_keywords-length"></span>';
134
+ self::$meta_fields['general']['keywords']['help'] = esc_attr__('This is the keywords of your content that may be
135
  displayed in search engine results (meta keywords).', 'wp-meta-seo');
136
  } else {
137
  unset(self::$meta_fields['general']['keywords']);
138
  }
139
 
140
 
141
+ self::$meta_fields['general']['desc']['title'] = esc_html__('Search engine description', 'wp-meta-seo');
142
  self::$meta_fields['general']['desc']['description'] = sprintf(
143
  '<span id="metaseo_wpmseo_desc-length">%s</span>',
144
  self::$meta_length_reason
145
  );
146
+ self::$meta_fields['general']['desc']['help'] = esc_attr__('The description of your content that may be displayed
147
  in search engine results aka meta description.
148
  By default search engine take an excerpt from your content (depending on the search query).
149
  320 characters max allowed.', 'wp-meta-seo');
150
 
151
+ self::$meta_fields['social']['opengraph-title']['title'] = esc_html__('Facebook Title', 'wp-meta-seo');
152
+ self::$meta_fields['social']['opengraph-title']['description'] = esc_html__('Custom title to display when
153
  sharing this content on facebook, content title override', 'wp-meta-seo');
154
 
155
+ self::$meta_fields['social']['opengraph-desc']['title'] = esc_html__('Facebook Description', 'wp-meta-seo');
156
+ self::$meta_fields['social']['opengraph-desc']['description'] = esc_html__('Custom description to display when sharing
157
  this content on facebook, content description override', 'wp-meta-seo');
158
 
159
+ self::$meta_fields['social']['opengraph-image']['title'] = esc_html__('Facebook Image', 'wp-meta-seo');
160
+ self::$meta_fields['social']['opengraph-image']['description'] = esc_html__('Custom image to display when sharing
161
  this content on facebook, content description override, recommended size is 1200px x 630px', 'wp-meta-seo');
162
 
163
+ self::$meta_fields['social']['twitter-title']['title'] = esc_html__('Twitter Title', 'wp-meta-seo');
164
+ self::$meta_fields['social']['twitter-title']['description'] = esc_html__('Custom title to display when sharing this
165
  content on twitter, content title override', 'wp-meta-seo');
166
 
167
+ self::$meta_fields['social']['twitter-desc']['title'] = esc_html__('Twitter Description', 'wp-meta-seo');
168
+ self::$meta_fields['social']['twitter-desc']['description'] = esc_html__('Custom description to display when sharing
169
  this content on twitter, content description override', 'wp-meta-seo');
170
 
171
+ self::$meta_fields['social']['twitter-image']['title'] = esc_html__('Twitter Image', 'wp-meta-seo');
172
+ self::$meta_fields['social']['twitter-image']['description'] = esc_html__('Custom image to display when sharing
173
  this content on facebook, content description override, recommended min size 440px X 220px', 'wp-meta-seo');
174
 
175
  do_action('wpmseo_tab_translate');
176
  }
177
 
178
  /**
179
+ * Load script and style
180
+ *
181
+ * @return void
182
  */
183
  public function metaseoEnqueue()
184
  {
188
  'post.php',
189
  'edit.php',
190
  ), true)
191
+ && apply_filters('wpmseo_always_register_metaboxes_on_admin', false) === false)
192
  ) {
193
  return;
194
  }
195
 
196
+ if ($pagenow !== 'edit.php') {
197
+ if (0 !== (int) get_queried_object_id()) {
198
  // Enqueue files needed for upload functionality.
199
  wp_enqueue_media(
200
  array(
251
 
252
  /**
253
  * Localize a script
254
+ *
255
  * @return array
256
  */
257
  public function localizeSettingsScript()
258
  {
259
+ global $post;
260
+ if (!empty($post)) {
261
+ $post_title = $post->post_title;
262
+ $post_content = $post->post_content;
263
+ } else {
264
+ $post_title = '';
265
+ $post_content = '';
266
+ }
267
+
268
  $this->settings = array(
269
+ 'metaseo_title_home' => '',
270
+ 'metaseo_desc_home' => '',
271
+ 'metaseo_showfacebook' => '',
272
+ 'metaseo_showtwitter' => '',
273
+ 'metaseo_twitter_card' => 'summary',
274
+ 'metaseo_showkeywords' => 0,
275
+ 'metaseo_showtmetablock' => 1,
276
+ 'metaseo_showsocial' => 1,
277
+ 'metaseo_seovalidate' => 0
278
  );
279
+ $settings = get_option('_metaseo_settings');
280
 
281
  if (is_array($settings)) {
282
  $this->settings = array_merge($this->settings, $settings);
283
  }
284
 
285
  return array(
286
+ 'choose_image' => esc_html__('Use Image', 'wp-meta-seo'),
287
+ 'use_validate' => $this->settings['metaseo_seovalidate'],
288
+ 'post_title' => $post_title,
289
+ 'post_content' => $post_content
290
  );
291
  }
292
 
293
  /**
294
  * Localize a script
295
+ *
296
  * @return array
297
  */
298
  public function localizeScript()
304
  }
305
 
306
  self::$meta_length_reason = apply_filters('wpmseo_desc_length_reason', self::$meta_length_reason, $post);
307
+ self::$meta_length = apply_filters('wpmseo_desc_length', self::$meta_length, $post);
308
+ $title_template = '%%title%% - %%sitename%%';
309
 
310
+ $desc_template = '';
311
  $sample_permalink = get_sample_permalink($post->ID);
312
  $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
313
 
324
  }
325
 
326
  $cached_replacement_vars['sitename'] = get_option('blogname');
327
+ $plugin_active = json_encode(get_option('active_plugins'));
328
+ $array_keyword = array(
329
+ 'plugin_active' => $plugin_active,
330
+ 'field_prefix' => self::$form_prefix,
331
+ 'choose_image' => esc_html__('Use Image', 'wp-meta-seo'),
332
+ 'wpmseo_meta_desc_length' => self::$meta_length,
333
+ 'wpmseo_meta_title_length' => self::$meta_title_length,
334
+ 'wpmseo_meta_keywords_length' => self::$meta_keywords_length,
335
+ 'wpmseo_title_template' => $title_template,
336
+ 'wpmseo_desc_template' => $desc_template,
337
+ 'wpmseo_permalink_template' => $sample_permalink,
338
  'wpmseo_keyword_suggest_nonce' => wp_create_nonce('wpmseo-get-suggest'),
339
+ 'wpmseo_replace_vars_nonce' => wp_create_nonce('wpmseo-replace-vars'),
340
+ 'no_parent_text' => esc_html__('(no parent)', 'wp-meta-seo'),
341
+ 'show_keywords' => 0
342
  );
343
+ $settings = get_option('_metaseo_settings');
344
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
345
  $array_keyword['show_keywords'] = 1;
346
  }
347
 
350
 
351
  /**
352
  * Adds the Meta SEO meta box to the edit boxes in the edit post / page / cpt pages.
353
+ *
354
+ * @return void
355
  */
356
  public function addMetaBox()
357
  {
358
  $post_types = get_post_types(array('public' => true));
359
  if (is_array($post_types) && $post_types !== array()) {
360
  foreach ($post_types as $post_type) {
361
+ add_meta_box('wpmseo_meta', esc_html__('WP Meta SEO - Page optimization', 'wp-meta-seo'), array(
362
  $this,
363
  'metaBox',
364
  ), $post_type, 'normal', apply_filters('wpmseo_metabox_prio', 'core'));
368
 
369
  /**
370
  * Output the meta box
371
+ *
372
+ * @return void
373
  */
374
  public function metaBox()
375
  {
376
  $this->metaseoEnqueue();
377
+ $post = $this->getMetaboxPost();
378
  $default_settings = array(
379
+ 'metaseo_title_home' => '',
380
+ 'metaseo_desc_home' => '',
381
+ 'metaseo_showfacebook' => '',
382
+ 'metaseo_showtwitter' => '',
383
+ 'metaseo_twitter_card' => 'summary',
384
+ 'metaseo_showtmetablock' => 1,
385
+ 'metaseo_showsocial' => 1
386
  );
387
+ $settings = get_option('_metaseo_settings');
388
  if (is_array($settings)) {
389
  $default_settings = array_merge($default_settings, $settings);
390
  }
391
  $check_connected = false;
392
+ $service = false;
393
  ?>
394
  <div class="wpmseo-metabox-tabs-div">
395
  <ul class="wpmseo-metabox-tabs" id="wpmseo-metabox-tabs">
396
  <li class="general">
397
  <a class="wpmseo_tablink"
398
+ data-link="wpmseo_general"><?php esc_html_e('SEO Page optimization', 'wp-meta-seo'); ?></a>
399
  </li>
400
  <?php
401
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
410
  if ($check_connected) {
411
  echo '<li class="gsckeywords">';
412
  echo '<a class="wpmseo_tablink" data-link="wpmseo_gsc_keywords">';
413
+ esc_html_e('Search console keywords', 'wp-meta-seo');
414
  echo '</a>';
415
  echo '</li>';
416
  }
418
  ?>
419
 
420
  <?php if ((isset($default_settings['metaseo_showsocial'])
421
+ && (int) $default_settings['metaseo_showsocial'] === 1)) : ?>
422
  <li class="social">
423
  <a class="wpmseo_tablink"
424
+ data-link="wpmseo_social"><?php esc_html_e('Social for search engine', 'wp-meta-seo') ?></a>
425
  </li>
426
  <?php endif; ?>
427
  <?php do_action('wpmseo_tab_header'); ?>
437
  $this->doTab('general', $content);
438
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
439
  if ($check_connected) {
440
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::gscKeywords
441
  echo apply_filters('wpmsaddon_google_search_keywords', '', $post->post_content, $service);
442
  }
443
  }
448
  $content .= $this->doMetaBox($meta_field, $meta_key);
449
  }
450
 
451
+ if ((isset($default_settings['metaseo_showsocial']) && (int) $default_settings['metaseo_showsocial'] === 1)) {
452
  $this->doTab('social', $content);
453
  }
454
 
458
  }
459
 
460
  /**
461
+ * Get server webmaster
462
+ *
463
+ * @return boolean|Wpms_Google_Service_Webmasters
464
  */
465
  public function serverWebmaster()
466
  {
467
  try {
468
  if (!class_exists('Wpms_Api_Google', false)) {
469
+ require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/google-api/class-api-google.php';
470
  new Wpms_Api_Google();
471
  }
472
  } catch (Exception $exception) {
473
+ echo '';
474
  }
475
 
476
  $conn = get_option('wpms_gsc_connect');
477
  if (!empty($conn['googleClientId']) && !empty($conn['googleClientSecret'])) {
478
+ $client_id = $conn['googleClientId'];
479
  $client_secret = $conn['googleClientSecret'];
480
  } else {
481
+ $client_id = WPMSEO_ADDON_CLIENT_ID;
482
  $client_secret = WPMSEO_ADDON_CLIENT_SECRET;
483
  }
484
 
485
  $gsc = array(
486
  'application_name' => 'WP Meta SEO',
487
+ 'client_id' => $client_id,
488
+ 'client_secret' => $client_secret,
489
+ 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
490
+ 'scopes' => array('https://www.googleapis.com/auth/webmasters'),
491
  );
492
 
493
  $this->client = new Wpms_Api_Google_Client($gsc, 'wpms-gsc', 'https://www.googleapis.com/webmasters/v3/');
494
+ if (!is_null($this->client->getAccessToken())) {
495
  $service = new Wpms_Google_Service_Webmasters($this->client);
496
  return $service;
497
  }
498
  return false;
499
  }
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  /**
502
  * Load page analysis
503
+ *
504
+ * @param object $post Current post
505
+ *
506
  * @return string
507
  */
508
  public function pageAnalysis($post)
509
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  $output = '';
 
511
  $circliful = 0;
512
+ $output .= '<div style="width:100%;float:left;">';
513
+ $output .= '<div class="metaseo_left">
514
+ <div class="metaseo-progress-bar" data-post_id="' . esc_attr($post->ID) . '">
515
  <canvas id="inactiveProgress" class="metaseo-progress-inactive" height="275px" width="275px"></canvas>
516
  <canvas id="activeProgress" class="metaseo-progress-active" height="275px" width="275px"></canvas>
517
  <p>0%</p>
518
  </div>
519
+ <input type="hidden" id="progressController" value="' . esc_attr($circliful) . '" />
520
+ <input type="hidden" id="metaseo_alanysis_ok" value="' . esc_attr($this->perc_score) . '" />
521
  </div>';
522
 
523
  $output .= '<div class="metaseo_right">';
 
524
  $output .= '</div>';
525
  $output .= '</div>';
526
  return $output;
527
  }
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  /**
530
  * Display html content for current tab
531
+ *
532
+ * @param array $meta_field_def Meta field
533
+ * @param string $key Meta key
534
+ *
535
  * @return string
536
  */
537
  public function doMetaBox($meta_field_def, $key = '')
538
  {
539
  wp_enqueue_style('metaseo-google-icon');
540
+ $content = '';
541
  $esc_form_key = esc_attr(self::$form_prefix . $key);
542
+ $post = $this->getMetaboxPost();
543
+ $meta_value = self::getValue($key, $post->ID);
544
 
545
  $class = '';
546
  if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
565
  if ($placeholder !== '') {
566
  $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
567
  }
568
+ $content .= '<input type="text"' . $placeholder . ' id="' . esc_attr($esc_form_key) . '" ' . $ac . '
569
+ name="' . esc_attr($esc_form_key) . '" value="' . esc_attr($meta_value) . '"
570
+ class="' . esc_attr('large-text' . $class) . '"/><br />';
571
  break;
572
 
573
  case 'textarea':
575
  if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
576
  $rows = $meta_field_def['rows'];
577
  }
578
+ $content .= '<textarea class="' . esc_attr('large-text' . $class) . '"
579
+ rows="' . esc_attr($rows) . '" id="' . esc_attr($esc_form_key) . '"
580
+ name="' . esc_attr($esc_form_key) . '">' . esc_textarea($meta_value) . '</textarea>';
581
  break;
582
 
583
  case 'select':
584
  if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
585
+ && $meta_field_def['options'] !== array()) {
586
+ $content .= '<select name="' . esc_attr($esc_form_key) . '" id="' . esc_attr($esc_form_key) . '"
587
+ class="' . esc_attr('metaseo' . $class) . '">';
588
  foreach ($meta_field_def['options'] as $val => $option) {
589
  $selected = selected($meta_value, $val, false);
590
+ $content .= '<option ' . $selected . '
591
  value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
592
  }
593
  unset($val, $option, $selected);
595
  }
596
  break;
597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  case 'upload':
599
+ $content .= '<input id="' . esc_attr($esc_form_key) . '" type="text" size="36" class="' . esc_attr($class) . '"
600
+ name="' . esc_attr($esc_form_key) . '" value="' . esc_attr($meta_value) . '" />';
601
+ $content .= '<input id="' . esc_attr($esc_form_key) . '_button" class="wpmseo_image_upload_button button"
602
+ type="button" value="' . esc_html__('Upload Image', 'wp-meta-seo') . '" />';
603
  break;
604
  }
605
 
624
  'checkbox',
625
  ), true) === false
626
  ) {
627
+ $label = '<label for="' . esc_attr($esc_form_key) . '">' . $label . ':</label>';
628
  }
629
 
630
  $help = '';
631
  if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
632
  $help = '<i class="material-icons alignright metaseo_help"
633
+ id="' . esc_attr($key . 'help') . '" data-alt="' . esc_attr($meta_field_def['help']) . '"
634
  style="color:#32373C">chat_bubble</i>';
635
  }
636
 
653
  }
654
 
655
  /**
656
+ * Get meta box post
657
+ *
658
  * @return array|mixed|null|WP_Post
659
  */
660
  private function getMetaboxPost()
661
  {
662
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
663
  if (isset($_GET['post'])) {
664
+ $post_id = (int) $_GET['post'];
665
+ $post = get_post($post_id);
666
  } else {
667
  $post = $GLOBALS['post'];
668
  }
671
  }
672
 
673
  /**
674
+ * Get snippet
675
+ *
676
  * @return string
677
  */
678
  public function snippet()
679
  {
680
+ $post = $this->getMetaboxPost();
681
+ $title = self::getValue('title', $post->ID);
682
  $description = self::getValue('desc', $post->ID);
683
 
684
  $snippet_preview = new WPMSEOSnippetPreview($post, $title, $description);
685
 
686
  return $snippet_preview->getContent();
687
  }
688
+
689
+ /**
690
+ * Display html content for current tab
691
+ *
692
+ * @param string $id Tab id
693
+ * @param string $content Tab content
694
+ *
695
+ * @return void
696
+ */
697
+ public function doTab($id, $content)
698
+ {
699
+ global $post;
700
+ ?>
701
+ <div class="<?php echo esc_attr('wpmseotab ' . $id) ?>">
702
+ <?php if ($id === 'general') : ?>
703
+ <p class="reload_analysis">
704
+ <span class="spinner" style="float: left;"></span>
705
+ <input type="button" name="reload_analysis" id="reload_analysis" class="button button-primary"
706
+ value="<?php esc_attr_e('Reload analysis', 'wp-meta-seo'); ?>">
707
+ </p>
708
+ <?php endif; ?>
709
+ <table class="form-table">
710
+ <?php
711
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method doMetaBox
712
+ echo $content;
713
+ ?>
714
+ </table>
715
+ <?php
716
+ if ($id === 'general') {
717
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method pageAnalysis
718
+ echo $this->pageAnalysis($post);
719
+ $settings = get_option('_metaseo_settings');
720
+ if (!empty($settings['metaseo_follow'])) {
721
+ $page_follow = get_post_meta($post->ID, '_metaseo_metafollow', true);
722
+ $slf = '<select class="metaseo_metabox_follow" data-post_id="' . esc_attr($post->ID) . '">';
723
+ if ($page_follow === 'nofollow') {
724
+ $slf .= '<option value="follow">' . esc_html__('Follow', 'wp-meta-seo') . '</option>';
725
+ $slf .= '<option selected value="nofollow">' . esc_html__('Nofollow', 'wp-meta-seo') . '</option>';
726
+ } else {
727
+ $slf .= '<option selected value="follow">' . esc_html__('Follow', 'wp-meta-seo') . '</option>';
728
+ $slf .= '<option value="nofollow">' . esc_html__('Nofollow', 'wp-meta-seo') . '</option>';
729
+ }
730
+ $slf .= '</select>';
731
+ echo '<p class="p_index_folder"><span class="wpmslabel">' . esc_html__('Follow', 'wp-meta-seo') . '
732
+ <i class="material-icons alignright metaseo_help" id="deschelp"
733
+ data-alt="' . esc_attr__('Nofollow provides a way for webmasters to tell search engines:
734
+ don\'t follow this link. So it may influence the link target’s ranking', 'wp-meta-seo') . '"
735
+ style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $slf . '</p>'; // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
736
+ }
737
+
738
+ if (!empty($settings['metaseo_index'])) {
739
+ $page_index = get_post_meta($post->ID, '_metaseo_metaindex', true);
740
+ $sli = '<select class="metaseo_metabox_index" data-post_id="' . esc_attr($post->ID) . '">';
741
+ if ($page_index === 'noindex') {
742
+ $sli .= '<option value="index">' . esc_html__('Index', 'wp-meta-seo') . '</option>';
743
+ $sli .= '<option selected value="noindex">' . esc_html__('Noindex', 'wp-meta-seo') . '</option>';
744
+ } else {
745
+ $sli .= '<option selected value="index">' . esc_html__('Index', 'wp-meta-seo') . '</option>';
746
+ $sli .= '<option value="noindex">' . esc_html__('Noindex', 'wp-meta-seo') . '</option>';
747
+ }
748
+
749
+ $sli .= '</select>';
750
+ echo '<p class="p_index_folder"><span class="wpmslabel">' . esc_html__('Index', 'wp-meta-seo') . '
751
+ <i class="material-icons alignright metaseo_help" id="deschelp"
752
+ data-alt="' . esc_attr__('Allow search engines robots to index this content,
753
+ as default your content is indexed', 'wp-meta-seo') . '"
754
+ style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $sli . '</p>'; // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same function)
755
+ }
756
+ }
757
+ ?>
758
+ </div>
759
+ <?php
760
+ }
761
  }
inc/class.metaseo-opengraph.php CHANGED
@@ -10,32 +10,34 @@ class MetaSeoOpenGraph
10
  {
11
  /**
12
  * Get meta title for title tag
13
- * @param boolean $is_shop check is shop
14
- * @param int $id id of post
 
 
15
  * @return mixed|string
16
  */
17
  public function getTitle($is_shop, $id)
18
  {
19
- if ( $is_shop ) {
20
- $shop = get_post($id);
21
  $meta_title = get_post_meta($id, '_metaseo_metatitle', true);
22
- if ($meta_title != maybe_unserialize($meta_title)) {
23
  $meta_title = '';
24
  }
25
 
26
- if ($meta_title == '') {
27
  $meta_title = $shop->post_title;
28
  }
29
 
30
- return $meta_title;
31
  }
32
 
33
  $meta_title = get_post_meta($id, '_metaseo_metatitle', true);
34
- if ($meta_title != maybe_unserialize($meta_title)) {
35
  $meta_title = '';
36
  }
37
 
38
- if ($meta_title == '') {
39
  $post = get_post($id);
40
  if (empty($post)) {
41
  return '';
@@ -48,55 +50,61 @@ class MetaSeoOpenGraph
48
 
49
  /**
50
  * Get meta title for meta tag
51
- * @param array $settings meta seo settings
52
- * @param string $meta_title meta title
 
 
53
  * @return string
54
  */
55
  public function getMetaTitle($settings, $meta_title)
56
  {
57
  $meta_title_esc = esc_attr($meta_title);
58
  // check homepage is a page
59
- if ($meta_title == '' && is_front_page()) {
60
  $meta_title_esc = esc_attr($settings['metaseo_title_home']);
61
- if ($meta_title_esc != maybe_unserialize($meta_title_esc)) {
62
  $meta_title_esc = '';
63
  }
64
  }
65
 
66
- return esc_html($meta_title_esc);
67
  }
68
 
69
  /**
70
  * Get meta keyword for meta tag
71
- * @param array $settings meta seo settings
72
- * @param int $id id of post
 
 
73
  * @return string
74
  */
75
  public function getKeyword($settings, $id)
76
  {
77
  $keywords = '';
78
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
79
  $meta_keywords = get_post_meta($id, '_metaseo_metakeywords', true);
80
- $keywords = esc_attr($meta_keywords);
81
  }
82
- return esc_html($keywords);
83
  }
84
 
85
  /**
86
  * Get meta description for meta tag
87
- * @param array $settings meta seo settings
88
- * @param int $id id of post
89
- * @param string $content content of post
 
 
90
  * @return string
91
  */
92
  public function getDesc($settings, $id, $content)
93
  {
94
  $meta_desc_esc = get_post_meta($id, '_metaseo_metadesc', true);
95
- if ($meta_desc_esc != maybe_unserialize($meta_desc_esc)) {
96
  $meta_desc_esc = '';
97
  }
98
 
99
- if ($meta_desc_esc == '') {
100
  $content = strip_shortcodes($content);
101
  $content = trim(strip_tags($content));
102
  if (strlen($content) > MPMSCAT_DESC_LENGTH) {
@@ -106,58 +114,64 @@ class MetaSeoOpenGraph
106
  }
107
  }
108
 
109
- if (get_post_meta($id, '_metaseo_metadesc', true) == '' && is_front_page()) {
110
  $meta_desc_esc = esc_attr($settings['metaseo_desc_home']);
111
- if ($meta_desc_esc != maybe_unserialize($meta_desc_esc)) {
112
  $meta_desc_esc = '';
113
  }
114
  }
115
- return esc_html($meta_desc_esc);
116
  }
117
 
118
  /**
119
  * Get meta facebook title
120
- * @param string $meta_title_esc meta title default
121
- * @param int $id id of post
 
 
122
  * @return mixed|string
123
  */
124
  public function getFbtitle($meta_title_esc, $id)
125
  {
126
  $meta_fbtitle = get_post_meta($id, '_metaseo_metaopengraph-title', true);
127
- if ($meta_fbtitle != maybe_unserialize($meta_fbtitle)) {
128
  $meta_fbtitle = '';
129
  }
130
 
131
- if ($meta_fbtitle == '') {
132
  $meta_fbtitle = $meta_title_esc;
133
  }
134
 
135
- return esc_html($meta_fbtitle);
136
  }
137
 
138
  /**
139
  * Get meta facebook description
140
- * @param string $meta_desc_esc meta description default
141
- * @param int $id id of post
 
 
142
  * @return mixed|string
143
  */
144
  public function getFbdesc($meta_desc_esc, $id)
145
  {
146
  $meta_fbdesc = get_post_meta($id, '_metaseo_metaopengraph-desc', true);
147
- if ($meta_fbdesc != maybe_unserialize($meta_fbdesc)) {
148
  $meta_fbdesc = '';
149
  }
150
 
151
- if ($meta_fbdesc == '') {
152
  $meta_fbdesc = $meta_desc_esc;
153
  }
154
 
155
- return esc_html($meta_fbdesc);
156
  }
157
 
158
  /**
159
  * Get meta facebook image and twiter image
160
- * @param int $id id of post
 
 
161
  * @return array
162
  */
163
  public function getImage($id)
@@ -174,54 +188,63 @@ class MetaSeoOpenGraph
174
  $meta_fbimage = $default_image[0];
175
  }
176
 
177
- return array($meta_fbimage, $meta_twimage);
 
 
 
178
  }
179
 
180
  /**
181
  * Get meta twiter title
182
- * @param string $meta_title_esc meta title default
183
- * @param int $id id of post
 
 
184
  * @return string
185
  */
186
  public function getTwtitle($meta_title_esc, $id)
187
  {
188
  $twitter_title = get_post_meta($id, '_metaseo_metatwitter-title', true);
189
- if ($twitter_title != maybe_unserialize($twitter_title)) {
190
  $twitter_title = '';
191
  }
192
 
193
  $meta_twtitle = esc_attr($twitter_title);
194
- if ($meta_twtitle == '') {
195
  $meta_twtitle = $meta_title_esc;
196
  }
197
 
198
- return esc_html($meta_twtitle);
199
  }
200
 
201
  /**
202
  * Get meta twiter description
203
- * @param string $meta_desc_esc meta description default
204
- * @param int $id id of post
 
 
205
  * @return string
206
  */
207
  public function getTwdesc($meta_desc_esc, $id)
208
  {
209
  $twitter_desc = get_post_meta($id, '_metaseo_metatwitter-desc', true);
210
- if ($twitter_desc != maybe_unserialize($twitter_desc)) {
211
  $twitter_desc = '';
212
  }
213
 
214
  $meta_twdesc = esc_attr($twitter_desc);
215
- if ($meta_twdesc == '') {
216
  $meta_twdesc = $meta_desc_esc;
217
  }
218
 
219
- return esc_html($meta_twdesc);
220
  }
221
 
222
  /**
223
  * Get meta twiter card
224
- * @param array $settings meta seo settings
 
 
225
  * @return string
226
  */
227
  public function getTwCard($settings)
@@ -232,141 +255,149 @@ class MetaSeoOpenGraph
232
  $meta_twcard = 'summary';
233
  }
234
 
235
- return $meta_twcard;
236
  }
237
 
238
  /**
239
  * Get meta for home page
240
- * @param array $settings meta seo settings
 
 
241
  * @return array
242
  */
243
  public function getHome($settings)
244
  {
245
  // get option reading
246
  $mpage_for_posts = get_option('page_for_posts');
247
- $mshow_on_front = get_option('show_on_front');
248
- $title = '';
249
- $desc = '';
250
- $page_follow = 'follow';
251
- $page_index = 'index';
252
- if ($mshow_on_front == 'posts') {
253
- $title = esc_attr($settings['metaseo_title_home']);
254
- $desc = esc_attr($settings['metaseo_desc_home']);
255
- if ($title != maybe_unserialize($title)) {
256
  $title = '';
257
  }
258
 
259
- if ($desc != maybe_unserialize($desc)) {
260
  $desc = '';
261
  }
262
 
263
  // set meta title when setting is empty
264
- if ($settings['metaseo_title_home'] == '') {
265
- $title = esc_attr(get_bloginfo('name') . ' - ' . get_bloginfo('description'));
266
  }
267
 
268
  // set meta description when setting is empty
269
- if ($settings['metaseo_desc_home'] == '') {
270
- $desc = esc_attr(get_bloginfo('description'));
271
  }
272
- } elseif ($mshow_on_front == 'page') { // is page posts
273
- $title = esc_attr(get_post_meta($mpage_for_posts, '_metaseo_metatitle', true));
 
274
  $page_follow = get_post_meta($mpage_for_posts, '_metaseo_metafollow', true);
275
- $page_index = get_post_meta($mpage_for_posts, '_metaseo_metaindex', true);
276
  }
277
 
278
  return array(
279
- 'title' => $title,
280
- 'desc' => $desc,
281
- 'page_follow' => $page_follow,
282
- 'page_index' => $page_index,
283
  );
284
  }
285
 
286
  /**
287
  * Get meta for front page
 
 
 
288
  * @return array
289
  */
290
  public function getFrontPageMeta($settings)
291
  {
292
  $mpage_on_front = get_option('page_on_front');
293
- $title = esc_attr(get_post_meta($mpage_on_front, '_metaseo_metatitle', true));
294
- $desc = esc_attr(get_post_meta($mpage_on_front, '_metaseo_metadesc', true));
295
 
296
- if ($title == '') {
297
- $title = esc_attr($settings['metaseo_title_home']);
298
  }
299
 
300
- if ($desc == '') {
301
- $desc = esc_attr($settings['metaseo_desc_home']);
302
  }
303
 
304
  $page_follow = get_post_meta($mpage_on_front, '_metaseo_metafollow', true);
305
- $page_index = get_post_meta($mpage_on_front, '_metaseo_metaindex', true);
306
  return array(
307
- 'title' => esc_html($title),
308
- 'desc' => esc_html($desc),
309
- 'page_follow' => $page_follow,
310
- 'page_index' => $page_index,
311
  );
312
  }
313
 
314
  /**
315
  * Get meta for tag , category
316
- * @param $wp_query
317
- * @param array $settings meta seo settings
 
 
318
  * @return array
319
  */
320
  public function getTagMeta($wp_query, $settings)
321
  {
322
- $term = $wp_query->get_queried_object();
323
  $meta_keywords_esc = '';
324
  if (is_object($term) && !empty($term)) {
325
  if (function_exists('get_term_meta')) {
326
  $cat_metatitle = get_term_meta($term->term_id, 'wpms_category_metatitle', true);
327
- $cat_metadesc = get_term_meta($term->term_id, 'wpms_category_metadesc', true);
328
  } else {
329
  $cat_metatitle = get_metadata('term', $term->term_id, 'wpms_category_metatitle', true);
330
- $cat_metadesc = get_metadata('term', $term->term_id, 'wpms_category_metadesc', true);
331
  }
332
 
333
- if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
334
  if (function_exists('get_term_meta')) {
335
- $meta_keywords = get_term_meta($term->term_id, 'wpms_category_metakeywords', true);
336
  } else {
337
- $meta_keywords = get_metadata('term', $term->term_id, 'wpms_category_metakeywords', true);
338
  }
339
-
340
- $meta_keywords_esc = esc_attr($meta_keywords);
341
  }
342
 
343
- if (isset($cat_metatitle) && $cat_metatitle != '') {
344
- $title = esc_attr($cat_metatitle);
345
  } else {
346
- $title = esc_attr($term->name);
347
  }
348
 
349
- if (isset($cat_metadesc) && $cat_metadesc != '') {
350
- $desc = esc_attr($cat_metadesc);
351
  } else {
352
- $desc = esc_attr($term->description);
353
  }
354
  } else {
355
  $title = '';
356
- $desc = '';
357
  }
358
 
359
  return array(
360
- 'title' => esc_html($title),
361
- 'desc' => esc_html($desc),
362
- 'keyword' => $meta_keywords_esc
363
  );
364
  }
365
 
366
  /**
367
  * Get meta facebook admin and twitter site
368
- * @param array $settings meta seo settings
369
- * @param int $id id of post
 
 
370
  * @return array
371
  */
372
  public function getUserMeta($settings, $id)
@@ -375,29 +406,30 @@ class MetaSeoOpenGraph
375
  if (empty($post)) {
376
  return array(
377
  'meta_twitter_site' => '',
378
- 'facebook_admin' => ''
379
  );
380
  }
381
  $meta_twitter_site = get_user_meta($post->post_author, 'mtwitter', true);
382
- $facebook_admin = get_user_meta($post->post_author, 'mfacebook', true);
383
 
384
  if ($settings) {
385
- if ($meta_twitter_site == '' && $settings['metaseo_showtwitter'] != '') {
386
  $meta_twitter_site = $settings['metaseo_showtwitter'];
387
  }
388
 
389
- if ($facebook_admin == '' && $settings['metaseo_showfacebook'] != '') {
390
  $facebook_admin = $settings['metaseo_showfacebook'];
391
  }
392
  }
393
  return array(
394
- 'meta_twitter_site' => $meta_twitter_site,
395
- 'facebook_admin' => $facebook_admin
396
  );
397
  }
398
 
399
  /**
400
  * Get current URL
 
401
  * @return mixed|string
402
  */
403
  public function getCurentUrl()
@@ -414,6 +446,7 @@ class MetaSeoOpenGraph
414
 
415
  /**
416
  * Get type
 
417
  * @return string
418
  */
419
  public function getType()
@@ -430,26 +463,29 @@ class MetaSeoOpenGraph
430
  }
431
 
432
  /**
433
- * @param int $id id of post
434
- * @param array $settings meta seo settings
435
- * @param string $meta_twimage meta twiter image
436
- * @param string $meta_twcard meta twiter card
437
- * @param string $meta_twitter_site meta twiter site
438
- * @param string $sitename site name
439
- * @param string $meta_twdesc meta twiter description
440
- * @param string $meta_twtitle meta twiter title
441
- * @param string $facebook_admin meta facebook admin
442
- * @param string $meta_fbimage meta facebook image
443
- * @param string $meta_fbdesc meta facebook description
444
- * @param string $current_url current url
445
- * @param string $type meta type
446
- * @param string $fbapp_id meta facebook app id
447
- * @param string $meta_fbtitle meta facebook title
448
- * @param string $meta_desc_esc meta description
449
- * @param string $meta_keywords_esc meta keywords
450
- * @param string $meta_title_esc meta title
451
- * @param string $page_index page index
452
- * @param string $page_follow page follow
 
 
 
453
  * @return array
454
  */
455
  public function getPatterns(
@@ -475,134 +511,152 @@ class MetaSeoOpenGraph
475
  $page_follow
476
  ) {
477
  $patterns = array(
478
- 'twitter_image' => array(
479
  '#<meta name="twitter:image" [^<>]+ ?>#i',
480
- '<meta name="twitter:image" content="' . $meta_twimage . '" />',
481
- ($meta_twimage != '' ? true : false)),
482
- 'twitter_card' => array(
 
483
  '#<meta name="twitter:card" [^<>]+ ?>#i',
484
- '<meta name="twitter:card" content="' . $meta_twcard . '" />',
485
- ($meta_twcard != '' ? true : false)),
486
- 'twitter_site' => array(
 
487
  '#<meta name="twitter:site" [^<>]+ ?>#i',
488
- '<meta name="twitter:site" content="@' . $meta_twitter_site . '" />',
489
- ($meta_twitter_site != '' ? true : false)),
 
490
  'twitter_domain' => array(
491
  '#<meta name="twitter:domain" [^<>]+ ?>#i',
492
- '<meta name="twitter:domain" content="' . $sitename . '" />',
493
- ($sitename != '' ? true : false)),
494
- 'twitter_desc' => array(
 
495
  '#<meta name="twitter:description" [^<>]+ ?>#i',
496
- '<meta name="twitter:description" content="' . $meta_twdesc . '" />',
497
- ($meta_twdesc != '' ? true : false)),
498
- 'twitter_title' => array(
 
499
  '#<meta name="twitter:title" [^<>]+ ?>#i',
500
- '<meta name="twitter:title" content="' . $meta_twtitle . '" />',
501
- ($meta_twtitle != '' ? true : false)),
 
502
  'facebook_admin' => array(
503
  '#<meta property="fb:admins" [^<>]+ ?>#i',
504
- '<meta property="fb:admins" content="' . $facebook_admin . '" />',
505
- ($facebook_admin != '' ? true : false)),
 
506
  'facebook_image' => array(
507
  '#<meta property="og:image" [^<>]+ ?>#i',
508
- '<meta property="og:image" content="' . $meta_fbimage . '" />',
509
- ($meta_fbimage != '' ? true : false)),
510
- 'site_name' => array(
 
511
  '#<meta property="og:site_name" [^<>]+ ?>#i',
512
- '<meta property="og:site_name" content="' . $sitename . '" />',
513
- ($sitename != '' ? true : false)),
 
514
  'og:description' => array(
515
  '#<meta property="og:description" [^<>]+ ?>#i',
516
- '<meta property="og:description" content="' . $meta_fbdesc . '" />',
517
- ($meta_fbdesc != '' ? true : false)),
518
- 'og:url' => array(
 
519
  '#<meta property="og:url" [^<>]+ ?>#i',
520
- '<meta property="og:url" content="' . $current_url . '" />',
521
- ($current_url != '' ? true : false)),
522
- 'og:type' => array(
 
523
  '#<meta property="og:type" [^<>]+ ?>#i',
524
- '<meta property="og:type" content="' . $type . '" />',
525
- ($type != '' ? true : false)),
526
- 'fb:app_id' => array(
 
527
  '#<meta property="fb:app_id" [^<>]+ ?>#i',
528
- '<meta property="fb:app_id" content="' . $fbapp_id . '" />',
529
- ($type != '' ? true : false)),
530
- 'og:title' => array(
 
531
  '#<meta property="og:title" [^<>]+ ?>#i',
532
- '<meta property="og:title" content="' . $meta_fbtitle . '" />',
533
- ($meta_fbtitle != '' ? true : false)),
534
- '_description' => array(
 
535
  '#<meta name="description" [^<>]+ ?>#i',
536
- '<meta name="description" content="' . $meta_desc_esc . '" />',
537
- ($meta_desc_esc != '' ? true : false)),
538
- 'keywords' => array(
 
539
  '#<meta name="keywords" [^<>]+ ?>#i',
540
- '<meta name="keywords" content="' . $meta_keywords_esc . '" />',
541
- ($meta_keywords_esc != '' ? true : false)),
542
- 'title' => array(
 
543
  '#<meta name="title" [^<>]+ ?>#i',
544
- '<meta name="title" content="' . $meta_title_esc . '" />',
545
- ($meta_title_esc != '' ? true : false))
 
546
  );
547
 
548
  if (!empty($settings['metaseo_follow']) || !empty($settings['metaseo_index'])) {
549
  $patterns['follow'] = array(
550
  '#<meta name="robots" [^<>]+ ?>#i',
551
- '<meta name="robots" content="' . $page_index . ',' . $page_follow . '" />'
552
  );
553
  }
554
 
555
- if (get_post_meta($id, '_metaseo_metatitle', true) != '') {
556
  $patterns['title'] = array(
557
  '#<meta name="title" [^<>]+ ?>#i',
558
- '<meta name="title" content="' . $meta_title_esc . '" />',
559
- ($meta_title_esc != '' ? true : false));
 
560
  }
561
 
562
  // unset meta tag if empty value
563
- if ($meta_keywords_esc == '') {
564
  unset($patterns['keywords']);
565
  }
566
 
567
- if (!isset($fbapp_id) || (isset($fbapp_id) && $fbapp_id == '')) {
568
  unset($patterns['fb:app_id']);
569
  }
570
 
571
- if ($meta_twitter_site == '') {
572
  unset($patterns['twitter_site']);
573
  }
574
 
575
- if ($meta_twimage == '') {
576
  unset($patterns['twitter_image']);
577
  }
578
 
579
- if ($meta_twtitle == '') {
580
  unset($patterns['twitter_title']);
581
  }
582
 
583
- if ($meta_twdesc == '') {
584
  unset($patterns['twitter_desc']);
585
  }
586
 
587
- if ($meta_fbdesc == '') {
588
  unset($patterns['og:description']);
589
  }
590
 
591
- if ($meta_desc_esc == '') {
592
  unset($patterns['_description']);
593
  }
594
 
595
- if ($facebook_admin == '') {
596
  unset($patterns['facebook_admin']);
597
  }
598
 
599
- if ($meta_fbimage == '') {
600
  unset($patterns['facebook_image']);
601
  }
602
 
603
  $default_settings = array(
604
- "metaseo_showsocial" => 1,
605
- "metaseo_metatitle_tab" => 0
606
  );
607
 
608
  if (is_array($settings)) {
@@ -614,7 +668,7 @@ class MetaSeoOpenGraph
614
  }
615
 
616
  // unset meta tag if empty value
617
- if ((isset($default_settings['metaseo_showsocial']) && $default_settings['metaseo_showsocial'] == 0)) {
618
  unset($patterns['twitter_image']);
619
  unset($patterns['twitter_card']);
620
  unset($patterns['twitter_site']);
10
  {
11
  /**
12
  * Get meta title for title tag
13
+ *
14
+ * @param boolean $is_shop Check is shop
15
+ * @param integer $id Id of post
16
+ *
17
  * @return mixed|string
18
  */
19
  public function getTitle($is_shop, $id)
20
  {
21
+ if ($is_shop) {
22
+ $shop = get_post($id);
23
  $meta_title = get_post_meta($id, '_metaseo_metatitle', true);
24
+ if ($meta_title !== maybe_unserialize($meta_title)) {
25
  $meta_title = '';
26
  }
27
 
28
+ if ($meta_title === '') {
29
  $meta_title = $shop->post_title;
30
  }
31
 
32
+ return esc_html($meta_title);
33
  }
34
 
35
  $meta_title = get_post_meta($id, '_metaseo_metatitle', true);
36
+ if ($meta_title !== maybe_unserialize($meta_title)) {
37
  $meta_title = '';
38
  }
39
 
40
+ if ($meta_title === '') {
41
  $post = get_post($id);
42
  if (empty($post)) {
43
  return '';
50
 
51
  /**
52
  * Get meta title for meta tag
53
+ *
54
+ * @param array $settings Meta seo settings
55
+ * @param string $meta_title Meta title
56
+ *
57
  * @return string
58
  */
59
  public function getMetaTitle($settings, $meta_title)
60
  {
61
  $meta_title_esc = esc_attr($meta_title);
62
  // check homepage is a page
63
+ if ($meta_title === '' && is_front_page()) {
64
  $meta_title_esc = esc_attr($settings['metaseo_title_home']);
65
+ if ($meta_title_esc !== maybe_unserialize($meta_title_esc)) {
66
  $meta_title_esc = '';
67
  }
68
  }
69
 
70
+ return esc_attr($meta_title_esc);
71
  }
72
 
73
  /**
74
  * Get meta keyword for meta tag
75
+ *
76
+ * @param array $settings Meta seo settings
77
+ * @param integer $id Id of post
78
+ *
79
  * @return string
80
  */
81
  public function getKeyword($settings, $id)
82
  {
83
  $keywords = '';
84
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
85
  $meta_keywords = get_post_meta($id, '_metaseo_metakeywords', true);
86
+ $keywords = esc_attr($meta_keywords);
87
  }
88
+ return esc_attr($keywords);
89
  }
90
 
91
  /**
92
  * Get meta description for meta tag
93
+ *
94
+ * @param array $settings Meta seo settings
95
+ * @param integer $id Id of post
96
+ * @param string $content Content of post
97
+ *
98
  * @return string
99
  */
100
  public function getDesc($settings, $id, $content)
101
  {
102
  $meta_desc_esc = get_post_meta($id, '_metaseo_metadesc', true);
103
+ if ($meta_desc_esc !== maybe_unserialize($meta_desc_esc)) {
104
  $meta_desc_esc = '';
105
  }
106
 
107
+ if ($meta_desc_esc === '') {
108
  $content = strip_shortcodes($content);
109
  $content = trim(strip_tags($content));
110
  if (strlen($content) > MPMSCAT_DESC_LENGTH) {
114
  }
115
  }
116
 
117
+ if (get_post_meta($id, '_metaseo_metadesc', true) === '' && is_front_page()) {
118
  $meta_desc_esc = esc_attr($settings['metaseo_desc_home']);
119
+ if ($meta_desc_esc !== maybe_unserialize($meta_desc_esc)) {
120
  $meta_desc_esc = '';
121
  }
122
  }
123
+ return esc_attr($meta_desc_esc);
124
  }
125
 
126
  /**
127
  * Get meta facebook title
128
+ *
129
+ * @param string $meta_title_esc Meta title default
130
+ * @param integer $id Id of post
131
+ *
132
  * @return mixed|string
133
  */
134
  public function getFbtitle($meta_title_esc, $id)
135
  {
136
  $meta_fbtitle = get_post_meta($id, '_metaseo_metaopengraph-title', true);
137
+ if ($meta_fbtitle !== maybe_unserialize($meta_fbtitle)) {
138
  $meta_fbtitle = '';
139
  }
140
 
141
+ if ($meta_fbtitle === '') {
142
  $meta_fbtitle = $meta_title_esc;
143
  }
144
 
145
+ return esc_attr($meta_fbtitle);
146
  }
147
 
148
  /**
149
  * Get meta facebook description
150
+ *
151
+ * @param string $meta_desc_esc Meta description default
152
+ * @param integer $id Id of post
153
+ *
154
  * @return mixed|string
155
  */
156
  public function getFbdesc($meta_desc_esc, $id)
157
  {
158
  $meta_fbdesc = get_post_meta($id, '_metaseo_metaopengraph-desc', true);
159
+ if ($meta_fbdesc !== maybe_unserialize($meta_fbdesc)) {
160
  $meta_fbdesc = '';
161
  }
162
 
163
+ if ($meta_fbdesc === '') {
164
  $meta_fbdesc = $meta_desc_esc;
165
  }
166
 
167
+ return esc_attr($meta_fbdesc);
168
  }
169
 
170
  /**
171
  * Get meta facebook image and twiter image
172
+ *
173
+ * @param integer $id Id of post
174
+ *
175
  * @return array
176
  */
177
  public function getImage($id)
188
  $meta_fbimage = $default_image[0];
189
  }
190
 
191
+ return array(
192
+ esc_url($meta_fbimage),
193
+ esc_url($meta_twimage)
194
+ );
195
  }
196
 
197
  /**
198
  * Get meta twiter title
199
+ *
200
+ * @param string $meta_title_esc Meta title default
201
+ * @param integer $id Id of post
202
+ *
203
  * @return string
204
  */
205
  public function getTwtitle($meta_title_esc, $id)
206
  {
207
  $twitter_title = get_post_meta($id, '_metaseo_metatwitter-title', true);
208
+ if ($twitter_title !== maybe_unserialize($twitter_title)) {
209
  $twitter_title = '';
210
  }
211
 
212
  $meta_twtitle = esc_attr($twitter_title);
213
+ if ($meta_twtitle === '') {
214
  $meta_twtitle = $meta_title_esc;
215
  }
216
 
217
+ return esc_attr($meta_twtitle);
218
  }
219
 
220
  /**
221
  * Get meta twiter description
222
+ *
223
+ * @param string $meta_desc_esc Meta description default
224
+ * @param integer $id Id of post
225
+ *
226
  * @return string
227
  */
228
  public function getTwdesc($meta_desc_esc, $id)
229
  {
230
  $twitter_desc = get_post_meta($id, '_metaseo_metatwitter-desc', true);
231
+ if ($twitter_desc !== maybe_unserialize($twitter_desc)) {
232
  $twitter_desc = '';
233
  }
234
 
235
  $meta_twdesc = esc_attr($twitter_desc);
236
+ if ($meta_twdesc === '') {
237
  $meta_twdesc = $meta_desc_esc;
238
  }
239
 
240
+ return esc_attr($meta_twdesc);
241
  }
242
 
243
  /**
244
  * Get meta twiter card
245
+ *
246
+ * @param array $settings Meta seo settings
247
+ *
248
  * @return string
249
  */
250
  public function getTwCard($settings)
255
  $meta_twcard = 'summary';
256
  }
257
 
258
+ return esc_attr($meta_twcard);
259
  }
260
 
261
  /**
262
  * Get meta for home page
263
+ *
264
+ * @param array $settings Meta seo settings
265
+ *
266
  * @return array
267
  */
268
  public function getHome($settings)
269
  {
270
  // get option reading
271
  $mpage_for_posts = get_option('page_for_posts');
272
+ $mshow_on_front = get_option('show_on_front');
273
+ $title = '';
274
+ $desc = '';
275
+ $page_follow = 'follow';
276
+ $page_index = 'index';
277
+ if ($mshow_on_front === 'posts') {
278
+ $title = $settings['metaseo_title_home'];
279
+ $desc = $settings['metaseo_desc_home'];
280
+ if ($title !== maybe_unserialize($title)) {
281
  $title = '';
282
  }
283
 
284
+ if ($desc !== maybe_unserialize($desc)) {
285
  $desc = '';
286
  }
287
 
288
  // set meta title when setting is empty
289
+ if ($settings['metaseo_title_home'] === '') {
290
+ $title = get_bloginfo('name') . ' - ' . get_bloginfo('description');
291
  }
292
 
293
  // set meta description when setting is empty
294
+ if ($settings['metaseo_desc_home'] === '') {
295
+ $desc = get_bloginfo('description');
296
  }
297
+ } elseif ($mshow_on_front === 'page') { // is page posts
298
+ $title = get_post_meta($mpage_for_posts, '_metaseo_metatitle', true);
299
+ $desc = get_post_meta($mpage_for_posts, '_metaseo_metadesc', true);
300
  $page_follow = get_post_meta($mpage_for_posts, '_metaseo_metafollow', true);
301
+ $page_index = get_post_meta($mpage_for_posts, '_metaseo_metaindex', true);
302
  }
303
 
304
  return array(
305
+ 'title' => esc_attr($title),
306
+ 'desc' => esc_attr($desc),
307
+ 'page_follow' => esc_attr($page_follow),
308
+ 'page_index' => esc_attr($page_index)
309
  );
310
  }
311
 
312
  /**
313
  * Get meta for front page
314
+ *
315
+ * @param array $settings Settings
316
+ *
317
  * @return array
318
  */
319
  public function getFrontPageMeta($settings)
320
  {
321
  $mpage_on_front = get_option('page_on_front');
322
+ $title = get_post_meta($mpage_on_front, '_metaseo_metatitle', true);
323
+ $desc = get_post_meta($mpage_on_front, '_metaseo_metadesc', true);
324
 
325
+ if ($title === '') {
326
+ $title = $settings['metaseo_title_home'];
327
  }
328
 
329
+ if ($desc === '') {
330
+ $desc = $settings['metaseo_desc_home'];
331
  }
332
 
333
  $page_follow = get_post_meta($mpage_on_front, '_metaseo_metafollow', true);
334
+ $page_index = get_post_meta($mpage_on_front, '_metaseo_metaindex', true);
335
  return array(
336
+ 'title' => esc_attr($title),
337
+ 'desc' => esc_attr($desc),
338
+ 'page_follow' => esc_attr($page_follow),
339
+ 'page_index' => esc_attr($page_index)
340
  );
341
  }
342
 
343
  /**
344
  * Get meta for tag , category
345
+ *
346
+ * @param object $wp_query Wordpress query
347
+ * @param array $settings Meta seo settings
348
+ *
349
  * @return array
350
  */
351
  public function getTagMeta($wp_query, $settings)
352
  {
353
+ $term = $wp_query->get_queried_object();
354
  $meta_keywords_esc = '';
355
  if (is_object($term) && !empty($term)) {
356
  if (function_exists('get_term_meta')) {
357
  $cat_metatitle = get_term_meta($term->term_id, 'wpms_category_metatitle', true);
358
+ $cat_metadesc = get_term_meta($term->term_id, 'wpms_category_metadesc', true);
359
  } else {
360
  $cat_metatitle = get_metadata('term', $term->term_id, 'wpms_category_metatitle', true);
361
+ $cat_metadesc = get_metadata('term', $term->term_id, 'wpms_category_metadesc', true);
362
  }
363
 
364
+ if (isset($settings['metaseo_showkeywords']) && (int) $settings['metaseo_showkeywords'] === 1) {
365
  if (function_exists('get_term_meta')) {
366
+ $meta_keywords_esc = get_term_meta($term->term_id, 'wpms_category_metakeywords', true);
367
  } else {
368
+ $meta_keywords_esc = get_metadata('term', $term->term_id, 'wpms_category_metakeywords', true);
369
  }
 
 
370
  }
371
 
372
+ if (isset($cat_metatitle) && $cat_metatitle !== '') {
373
+ $title = $cat_metatitle;
374
  } else {
375
+ $title = $term->name;
376
  }
377
 
378
+ if (isset($cat_metadesc) && $cat_metadesc !== '') {
379
+ $desc = $cat_metadesc;
380
  } else {
381
+ $desc = $term->description;
382
  }
383
  } else {
384
  $title = '';
385
+ $desc = '';
386
  }
387
 
388
  return array(
389
+ 'title' => esc_attr($title),
390
+ 'desc' => esc_attr($desc),
391
+ 'keyword' => esc_attr($meta_keywords_esc)
392
  );
393
  }
394
 
395
  /**
396
  * Get meta facebook admin and twitter site
397
+ *
398
+ * @param array $settings Meta seo settings
399
+ * @param integer $id Id of post
400
+ *
401
  * @return array
402
  */
403
  public function getUserMeta($settings, $id)
406
  if (empty($post)) {
407
  return array(
408
  'meta_twitter_site' => '',
409
+ 'facebook_admin' => ''
410
  );
411
  }
412
  $meta_twitter_site = get_user_meta($post->post_author, 'mtwitter', true);
413
+ $facebook_admin = get_user_meta($post->post_author, 'mfacebook', true);
414
 
415
  if ($settings) {
416
+ if ($meta_twitter_site === '' && $settings['metaseo_showtwitter'] !== '') {
417
  $meta_twitter_site = $settings['metaseo_showtwitter'];
418
  }
419
 
420
+ if ($facebook_admin === '' && $settings['metaseo_showfacebook'] !== '') {
421
  $facebook_admin = $settings['metaseo_showfacebook'];
422
  }
423
  }
424
  return array(
425
+ 'meta_twitter_site' => esc_attr($meta_twitter_site),
426
+ 'facebook_admin' => esc_attr($facebook_admin)
427
  );
428
  }
429
 
430
  /**
431
  * Get current URL
432
+ *
433
  * @return mixed|string
434
  */
435
  public function getCurentUrl()
446
 
447
  /**
448
  * Get type
449
+ *
450
  * @return string
451
  */
452
  public function getType()
463
  }
464
 
465
  /**
466
+ * Render meta tag
467
+ *
468
+ * @param integer $id Id of post
469
+ * @param array $settings Meta seo settings
470
+ * @param string $meta_twimage Meta twiter image
471
+ * @param string $meta_twcard Meta twiter card
472
+ * @param string $meta_twitter_site Meta twiter site
473
+ * @param string $sitename Site name
474
+ * @param string $meta_twdesc Meta twiter description
475
+ * @param string $meta_twtitle Meta twiter title
476
+ * @param string $facebook_admin Meta facebook admin
477
+ * @param string $meta_fbimage Meta facebook image
478
+ * @param string $meta_fbdesc Meta facebook description
479
+ * @param string $current_url Current url
480
+ * @param string $type Meta type
481
+ * @param string $fbapp_id Meta facebook app id
482
+ * @param string $meta_fbtitle Meta facebook title
483
+ * @param string $meta_desc_esc Meta description
484
+ * @param string $meta_keywords_esc Meta keywords
485
+ * @param string $meta_title_esc Meta title
486
+ * @param string $page_index Page index
487
+ * @param string $page_follow Page follow
488
+ *
489
  * @return array
490
  */
491
  public function getPatterns(
511
  $page_follow
512
  ) {
513
  $patterns = array(
514
+ 'twitter_image' => array(
515
  '#<meta name="twitter:image" [^<>]+ ?>#i',
516
+ '<meta name="twitter:image" content="' . esc_url($meta_twimage) . '" />',
517
+ ($meta_twimage !== '' ? true : false)
518
+ ),
519
+ 'twitter_card' => array(
520
  '#<meta name="twitter:card" [^<>]+ ?>#i',
521
+ '<meta name="twitter:card" content="' . esc_attr($meta_twcard) . '" />',
522
+ ($meta_twcard !== '' ? true : false)
523
+ ),
524
+ 'twitter_site' => array(
525
  '#<meta name="twitter:site" [^<>]+ ?>#i',
526
+ '<meta name="twitter:site" content="' . esc_attr('@' . $meta_twitter_site) . '" />',
527
+ ($meta_twitter_site !== '' ? true : false)
528
+ ),
529
  'twitter_domain' => array(
530
  '#<meta name="twitter:domain" [^<>]+ ?>#i',
531
+ '<meta name="twitter:domain" content="' . esc_attr($sitename) . '" />',
532
+ ($sitename !== '' ? true : false)
533
+ ),
534
+ 'twitter_desc' => array(
535
  '#<meta name="twitter:description" [^<>]+ ?>#i',
536
+ '<meta name="twitter:description" content="' . esc_attr($meta_twdesc) . '" />',
537
+ ($meta_twdesc !== '' ? true : false)
538
+ ),
539
+ 'twitter_title' => array(
540
  '#<meta name="twitter:title" [^<>]+ ?>#i',
541
+ '<meta name="twitter:title" content="' . esc_attr($meta_twtitle) . '" />',
542
+ ($meta_twtitle !== '' ? true : false)
543
+ ),
544
  'facebook_admin' => array(
545
  '#<meta property="fb:admins" [^<>]+ ?>#i',
546
+ '<meta property="fb:admins" content="' . esc_attr($facebook_admin) . '" />',
547
+ ($facebook_admin !== '' ? true : false)
548
+ ),
549
  'facebook_image' => array(
550
  '#<meta property="og:image" [^<>]+ ?>#i',
551
+ '<meta property="og:image" content="' . esc_url($meta_fbimage) . '" />',
552
+ ($meta_fbimage !== '' ? true : false)
553
+ ),
554
+ 'site_name' => array(
555
  '#<meta property="og:site_name" [^<>]+ ?>#i',
556
+ '<meta property="og:site_name" content="' . esc_attr($sitename) . '" />',
557
+ ($sitename !== '' ? true : false)
558
+ ),
559
  'og:description' => array(
560
  '#<meta property="og:description" [^<>]+ ?>#i',
561
+ '<meta property="og:description" content="' . esc_attr($meta_fbdesc) . '" />',
562
+ ($meta_fbdesc !== '' ? true : false)
563
+ ),
564
+ 'og:url' => array(
565
  '#<meta property="og:url" [^<>]+ ?>#i',
566
+ '<meta property="og:url" content="' . esc_url($current_url) . '" />',
567
+ ($current_url !== '' ? true : false)
568
+ ),
569
+ 'og:type' => array(
570
  '#<meta property="og:type" [^<>]+ ?>#i',
571
+ '<meta property="og:type" content="' . esc_attr($type) . '" />',
572
+ ($type !== '' ? true : false)
573
+ ),
574
+ 'fb:app_id' => array(
575
  '#<meta property="fb:app_id" [^<>]+ ?>#i',
576
+ '<meta property="fb:app_id" content="' . esc_attr($fbapp_id) . '" />',
577
+ ($type !== '' ? true : false)
578
+ ),
579
+ 'og:title' => array(
580
  '#<meta property="og:title" [^<>]+ ?>#i',
581
+ '<meta property="og:title" content="' . esc_attr($meta_fbtitle) . '" />',
582
+ ($meta_fbtitle !== '' ? true : false)
583
+ ),
584
+ '_description' => array(
585
  '#<meta name="description" [^<>]+ ?>#i',
586
+ '<meta name="description" content="' . esc_attr($meta_desc_esc) . '" />',
587
+ ($meta_desc_esc !== '' ? true : false)
588
+ ),
589
+ 'keywords' => array(
590
  '#<meta name="keywords" [^<>]+ ?>#i',
591
+ '<meta name="keywords" content="' . esc_attr($meta_keywords_esc) . '" />',
592
+ ($meta_keywords_esc !== '' ? true : false)
593
+ ),
594
+ 'title' => array(
595
  '#<meta name="title" [^<>]+ ?>#i',
596
+ '<meta name="title" content="' . esc_attr($meta_title_esc) . '" />',
597
+ ($meta_title_esc !== '' ? true : false)
598
+ )
599
  );
600
 
601
  if (!empty($settings['metaseo_follow']) || !empty($settings['metaseo_index'])) {
602
  $patterns['follow'] = array(
603
  '#<meta name="robots" [^<>]+ ?>#i',
604
+ '<meta name="robots" content="' . esc_attr($page_index . ',' . $page_follow) . '" />'
605
  );
606
  }
607
 
608
+ if (get_post_meta($id, '_metaseo_metatitle', true) !== '') {
609
  $patterns['title'] = array(
610
  '#<meta name="title" [^<>]+ ?>#i',
611
+ '<meta name="title" content="' . esc_attr($meta_title_esc) . '" />',
612
+ ($meta_title_esc !== '' ? true : false)
613
+ );
614
  }
615
 
616
  // unset meta tag if empty value
617
+ if ($meta_keywords_esc === '') {
618
  unset($patterns['keywords']);
619
  }
620
 
621
+ if (!isset($fbapp_id) || (isset($fbapp_id) && $fbapp_id === '')) {
622
  unset($patterns['fb:app_id']);
623
  }
624
 
625
+ if ($meta_twitter_site === '') {
626
  unset($patterns['twitter_site']);
627
  }
628
 
629
+ if ($meta_twimage === '') {
630
  unset($patterns['twitter_image']);
631
  }
632
 
633
+ if ($meta_twtitle === '') {
634
  unset($patterns['twitter_title']);
635
  }
636
 
637
+ if ($meta_twdesc === '') {
638
  unset($patterns['twitter_desc']);
639
  }
640
 
641
+ if ($meta_fbdesc === '') {
642
  unset($patterns['og:description']);
643
  }
644
 
645
+ if ($meta_desc_esc === '') {
646
  unset($patterns['_description']);
647
  }
648
 
649
+ if ($facebook_admin === '') {
650
  unset($patterns['facebook_admin']);
651
  }
652
 
653
+ if ($meta_fbimage === '') {
654
  unset($patterns['facebook_image']);
655
  }
656
 
657
  $default_settings = array(
658
+ 'metaseo_showsocial' => 1,
659
+ 'metaseo_metatitle_tab' => 0
660
  );
661
 
662
  if (is_array($settings)) {
668
  }
669
 
670
  // unset meta tag if empty value
671
+ if ((isset($default_settings['metaseo_showsocial']) && (int) $default_settings['metaseo_showsocial'] === 0)) {
672
  unset($patterns['twitter_image']);
673
  unset($patterns['twitter_card']);
674
  unset($patterns['twitter_site']);
inc/class.metaseo-sitemap.php CHANGED
@@ -10,26 +10,38 @@ class MetaSeoSitemap
10
  {
11
 
12
  /**
 
 
13
  * @var string
14
  */
15
  public $html = '';
16
  /**
 
 
17
  * @var string
18
  */
19
  public $wpms_sitemap_name = 'wpms-sitemap.xml';
20
  /**
 
 
21
  * @var string
22
  */
23
  public $wpms_sitemap_default_name = 'sitemap.xml';
24
  /**
 
 
25
  * @var array
26
  */
27
  public $columns = array('Zezo', 'One', 'Two', 'Three');
28
  /**
 
 
29
  * @var array
30
  */
31
  public $level = array();
32
  /**
 
 
33
  * @var array
34
  */
35
  public $settings_sitemap;
@@ -38,54 +50,71 @@ class MetaSeoSitemap
38
  * MetaSeoSitemap constructor.
39
  */
40
  public function __construct()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  {
42
  $this->settings_sitemap = array(
43
- "wpms_sitemap_add" => 0,
44
- "wpms_sitemap_root" => 0,
45
- "wpms_sitemap_author" => 0,
46
- "wpms_sitemap_taxonomies" => array(),
47
- "wpms_category_link" => array(),
48
- "wpms_html_sitemap_page" => 0,
49
- "wpms_html_sitemap_column" => 1,
50
- "wpms_html_sitemap_theme" => "default",
51
- "wpms_html_sitemap_position" => "after",
52
- "wpms_display_column_menus" => array(0),
53
- "wpms_display_column_posts" => 1,
54
- "wpms_display_column_pages" => 1,
55
- "wpms_display_order_menus" => 1,
56
- "wpms_display_order_posts" => 2,
57
- "wpms_display_order_pages" => 3,
58
- "wpms_display_order_urls" => 4,
59
- "wpms_public_name_pages" => "",
60
- "wpms_public_name_posts" => "",
61
- "wpms_sitemap_posts" => array(),
62
- "wpms_sitemap_pages" => array(),
63
- "wpms_sitemap_include_lang" => array()
64
  );
65
 
66
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
67
- $this->settings_sitemap['wpms_sitemap_customUrl'] = array();
68
  $this->settings_sitemap['wpms_display_column_customUrl'] = 1;
69
- $this->settings_sitemap['wpms_public_name_customUrl'] = "";
70
- $custom_post_types = get_post_types(
71
  array(
72
- 'public' => true,
73
  'exclude_from_search' => false,
74
- '_builtin' => false
75
  )
76
  );
77
  if (!empty($custom_post_types)) {
78
  foreach ($custom_post_types as $post_type => $label) {
79
  $this->settings_sitemap['wpms_display_column_' . $post_type] = 1;
80
- $this->settings_sitemap['wpms_public_name_' . $post_type] = "";
81
- $this->settings_sitemap['wpms_sitemap_' . $post_type] = array();
82
  }
83
  }
84
  }
85
 
86
  $settings = get_option('_metaseo_settings_sitemap');
87
- if (is_object($settings['wpms_sitemap_pages']) || is_object($settings['wpms_sitemap_posts'])
88
- || is_object($settings['wpms_sitemap_menus'])) {
89
  $settings_array = json_decode(json_encode($settings), true);
90
  update_option('_metaseo_settings_sitemap', $settings_array);
91
  }
@@ -94,18 +123,12 @@ class MetaSeoSitemap
94
  if (is_array($settings)) {
95
  $this->settings_sitemap = array_merge($this->settings_sitemap, $settings);
96
  }
97
-
98
- add_action('admin_init', array($this, 'settingsSitemap'));
99
- add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts'));
100
- add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'));
101
- add_filter('the_content', array($this, 'sitemapInContent'));
102
- add_shortcode('wpms_html_sitemap', array($this, 'sitemapShortcode'));
103
- add_action('wp_ajax_wpms_regenerate_sitemaps', array($this, 'regenerateSitemaps'));
104
- add_action('wp_ajax_wpms_save_sitemap_settings', array($this, 'saveSitemapSettings'));
105
  }
106
 
107
  /**
108
- * load metaseo script and style front-end
 
 
109
  */
110
  public function enqueueScripts()
111
  {
@@ -114,7 +137,7 @@ class MetaSeoSitemap
114
  return;
115
  }
116
 
117
- if (!empty($this->settings_sitemap) && $this->settings_sitemap['wpms_html_sitemap_page'] != $post->ID) {
118
  return;
119
  }
120
 
@@ -147,39 +170,42 @@ class MetaSeoSitemap
147
 
148
  /**
149
  * Localize a script
 
150
  * @return array
151
  */
152
  public function localizeScript()
153
  {
154
  $custom_post_types = get_post_types(
155
  array(
156
- 'public' => true,
157
  'exclude_from_search' => false,
158
- '_builtin' => false
159
  )
160
  );
161
- $arrays = array(
162
  'wpms_display_column_menus' => $this->settings_sitemap['wpms_display_column_menus'],
163
- 'post_type' => $custom_post_types
164
  );
165
  return $arrays;
166
  }
167
 
168
  /**
169
- * load metaseo script and style back-end
 
 
170
  */
171
  public function adminEnqueueScripts()
172
  {
173
  global $current_screen;
174
- if (!empty($current_screen) && $current_screen->base != 'wp-meta-seo_page_metaseo_google_sitemap') {
175
  return;
176
  }
177
 
178
  $custom_post_types = get_post_types(
179
  array(
180
- 'public' => true,
181
  'exclude_from_search' => false,
182
- '_builtin' => false
183
  )
184
  );
185
 
@@ -233,6 +259,8 @@ class MetaSeoSitemap
233
 
234
  /**
235
  * Add a new field to a section of a sitemap settings page
 
 
236
  */
237
  public function settingsSitemap()
238
  {
@@ -240,62 +268,62 @@ class MetaSeoSitemap
240
  add_settings_section('metaseo_sitemap', '', array($this, 'showSettingSitemap'), 'metaseo_settings_sitemap');
241
  add_settings_field(
242
  'wpms_sitemap_link',
243
- __('XML sitemap link', 'wp-meta-seo'),
244
  array($this, 'sitemapLink'),
245
  'metaseo_settings_sitemap',
246
  'metaseo_sitemap',
247
  array(
248
- 'label_for' => __('Link to the xml file generated. It’s highly recommended
249
  to add this sitemap link to your Google search console', 'wp-meta-seo')
250
  )
251
  );
252
  add_settings_field(
253
  'wpms_html_sitemap_page',
254
- __('HTML Sitemap page', 'wp-meta-seo'),
255
  array($this, 'sitemapPage'),
256
  'metaseo_settings_sitemap',
257
  'metaseo_sitemap',
258
  array(
259
- 'label_for' => __('A page is automatically generated to display your HTML sitemap.
260
  You can also use any of the existing pages', 'wp-meta-seo')
261
  )
262
  );
263
  add_settings_field(
264
  'wpms_sitemap_taxonomies',
265
- __('Additional content', 'wp-meta-seo'),
266
  array($this, 'sitemapTaxonomies'),
267
  'metaseo_settings_sitemap',
268
  'metaseo_sitemap',
269
  array(
270
- 'label_for' => __('The additional WordPress taxonomies that you want
271
  to load in your sitemaps', 'wp-meta-seo')
272
  )
273
  );
274
  add_settings_field(
275
  'wpms_sitemap_author',
276
- __('Display author posts', 'wp-meta-seo'),
277
  array($this, 'sitemapAuthor'),
278
  'metaseo_settings_sitemap',
279
  'metaseo_sitemap',
280
  array(
281
- 'label_for' => __('You can include a list of posts by author in your sitemaps', 'wp-meta-seo')
282
  )
283
  );
284
  add_settings_field(
285
  'wpms_html_sitemap_column',
286
- __('HTML Sitemap display', 'wp-meta-seo'),
287
  array($this, 'sitemapColumn'),
288
  'metaseo_settings_sitemap',
289
  'metaseo_sitemap',
290
  array(
291
- 'label_for' => __('Number of columns of the HTML sitemap.
292
  You can also setup where your content will be displayed using the tabs above', 'wp-meta-seo')
293
  )
294
  );
295
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
296
  add_settings_field(
297
  'wpms_html_sitemap_theme',
298
- __('HTML Sitemap theme', 'wp-meta-seo'),
299
  array($this, 'sitemapTheme'),
300
  'metaseo_settings_sitemap',
301
  'metaseo_sitemap'
@@ -303,30 +331,30 @@ class MetaSeoSitemap
303
  }
304
  add_settings_field(
305
  'wpms_html_sitemap_position',
306
- __('HTML Sitemap Position', 'wp-meta-seo'),
307
  array($this, 'sitemapPosition'),
308
  'metaseo_settings_sitemap',
309
  'metaseo_sitemap'
310
  );
311
  add_settings_field(
312
  'wpms_sitemap_add',
313
- __('Sitemap and robot.txt', 'wp-meta-seo'),
314
  array($this, 'settingRobotFile'),
315
  'metaseo_settings_sitemap',
316
  'metaseo_sitemap',
317
  array(
318
- 'label_for' => __('You can include a link to your xml sitemap in the robot.txt.
319
  It helps some search engines to find it', 'wp-meta-seo')
320
  )
321
  );
322
  add_settings_field(
323
  'wpms_sitemap_root',
324
- __('Sitemap root', 'wp-meta-seo'),
325
  array($this, 'sitemapRoot'),
326
  'metaseo_settings_sitemap',
327
  'metaseo_sitemap',
328
  array(
329
- 'label_for' => __('Add a copy of the lastest version of your .xml sitemap at the root
330
  of your WordPress install named sitemap.xml. Some SEO tools and search engines bots
331
  are searching for it.', 'wp-meta-seo')
332
  )
@@ -334,7 +362,7 @@ class MetaSeoSitemap
334
 
335
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
336
  if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
337
- $label = __('WPML language', 'wp-meta-seo');
338
  add_settings_field(
339
  'wpms_sitemap_include_lang',
340
  $label,
@@ -342,12 +370,12 @@ class MetaSeoSitemap
342
  'metaseo_settings_sitemap',
343
  'metaseo_sitemap',
344
  array(
345
- 'label_for' => __('Select a language to include in your sitemap,
346
  it will add the relative menu, post, page… content automatically', 'wp-meta-seo')
347
  )
348
  );
349
  } elseif (is_plugin_active('polylang/polylang.php')) {
350
- $label = __('Polylang language', 'wp-meta-seo');
351
  add_settings_field(
352
  'wpms_sitemap_include_lang',
353
  $label,
@@ -355,35 +383,41 @@ class MetaSeoSitemap
355
  'metaseo_settings_sitemap',
356
  'metaseo_sitemap',
357
  array(
358
- 'label_for' => __('Select a language to include in your sitemap,
359
  it will add the relative menu, post, page… content automatically', 'wp-meta-seo')
360
  )
361
  );
362
  }
363
  }
364
 
365
-
366
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
367
  add_settings_field(
368
  'wpms_sitemap_link_check',
369
- __('Sitemap link check', 'wp-meta-seo'),
370
  array($this, 'checkLink'),
371
  'metaseo_settings_sitemap',
372
  'metaseo_sitemap',
373
  array(
374
- 'label_for' => __('A page is automatically generated to display your
375
  HTML sitemap. You can also use any of the existing pages.', 'wp-meta-seo')
376
  )
377
  );
378
  }
379
  }
380
 
 
 
 
 
 
381
  public function showSettingSitemap()
382
  {
383
  }
384
 
385
  /**
386
  * Display field sitemap link
 
 
387
  */
388
  public function sitemapLink()
389
  {
@@ -391,61 +425,67 @@ class MetaSeoSitemap
391
  type="hidden" value="1">';
392
  if (is_multisite()) {
393
  $home_url = preg_replace(
394
- "/[^a-zA-ZА-Яа-я0-9\s]/",
395
- "_",
396
  str_replace('http://', '', str_replace('https://', '', ABSPATH))
397
  );
398
- $value = trim(ABSPATH, '/') . '/wpms-sitemap_' . $home_url . '.xml';
399
- $link = get_option('siteurl') . '/wpms-sitemap_' . $home_url . '.xml';
400
  } else {
401
  $value = trim(ABSPATH, '/') . '/' . $this->wpms_sitemap_name;
402
- $link = get_option('siteurl') . '/' . $this->wpms_sitemap_name;
403
  }
404
  echo '<input readonly id="wpms_sitemap_link" name="_metaseo_settings_sitemap[wpms_sitemap_link]"
405
  type="text" value="' . esc_attr($value) . '" size="50"/>';
406
- echo '<a class="button" href="' . $link . '" target="_blank">' . __('Open', 'wp-meta-seo') . '</a>';
407
  }
408
 
409
  /**
410
  * Display field add sitemap robots
 
 
411
  */
412
  public function settingRobotFile()
413
  {
414
- ?>
415
- <?php if (is_multisite()) { ?>
416
- <div class="pure-checkbox">
417
- <input id="wpms_sitemap_add" disabled="disabled" type="checkbox"
418
- name="_metaseo_settings_sitemap[wpms_sitemap_add]"
419
- value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
420
- <label for="wpms_sitemap_add"><?php _e("add sitemap file path in robots.txt", 'wp-meta-seo'); ?></label>
421
- </div>
422
- <p style="color:red">
423
- <?php _e("Since you are using multisite,
424
- the plugin does not allow to add a sitemap to robots.txt", 'wp-meta-seo'); ?>
425
- </p>
426
  <?php } else { ?>
427
- <!-- for robots.txt we need to use site_url instead home_url ! -->
428
- <div class="pure-checkbox">
429
- <input id="wpms_sitemap_add" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_add]"
430
- value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
431
- <label for="wpms_sitemap_add"><?php _e("add sitemap link in the", 'wp-meta-seo'); ?> <a
432
- href="<?php echo site_url('/'); ?>robots.txt" target="_new">robots.txt</a></label>
433
- </div>
434
  <?php }
435
  }
436
 
437
  /**
438
  * Display field sitemap lang
 
 
439
  */
440
  public function sitemapIncludeLanguages()
441
  {
442
- $lang = $this->settings_sitemap['wpms_sitemap_include_lang'];
443
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang, 'multiple');
 
444
  echo $sl_lang;
445
  }
446
 
447
  /**
448
  * Display field sitemap root
 
 
449
  */
450
  public function sitemapRoot()
451
  {
@@ -453,24 +493,29 @@ class MetaSeoSitemap
453
  <div class="pure-checkbox">
454
  <input id="wpms_sitemap_root" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_root]"
455
  value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_root']); ?>>
456
- <label for="wpms_sitemap_root"><?php _e("Add a sitemap.xml copy @ the site root", 'wp-meta-seo'); ?></label>
457
  </div>
458
  <?php
459
  }
460
 
461
  /**
462
  * Display field sitemap link check
 
 
463
  */
464
  public function checkLink()
465
  {
466
  ?>
467
- <input type="button" class="button wpms_run_linkcheck" value="<?php _e('Run a link check', 'wp-meta-seo') ?>">
 
468
  <span class="spinner spinner_run_linkchecker"></span>
469
  <?php
470
  }
471
 
472
  /**
473
  * Display field sitemap author
 
 
474
  */
475
  public function sitemapAuthor()
476
  {
@@ -478,13 +523,15 @@ class MetaSeoSitemap
478
  <div class="pure-checkbox">
479
  <input id="wpms_sitemap_author" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_author]"
480
  value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_author']); ?>>
481
- <label for="wpms_sitemap_author"><?php _e("Display author post archive", 'wp-meta-seo'); ?></label>
482
  </div>
483
  <?php
484
  }
485
 
486
  /**
487
  * Display field sitemap taxonomies
 
 
488
  */
489
  public function sitemapTaxonomies()
490
  {
@@ -496,17 +543,19 @@ class MetaSeoSitemap
496
  ?>
497
  <div class="pure-checkbox">
498
  <?php if (in_array($key, $this->settings_sitemap['wpms_sitemap_taxonomies'])) : ?>
499
- <input class="wpms_sitemap_taxonomies" id="wpms_sitemap_taxonomies_<?php echo $key; ?>"
 
500
  type="checkbox"
501
  name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]"
502
- value="<?php echo $key ?>" checked>
503
  <?php else : ?>
504
- <input class="wpms_sitemap_taxonomies" id="wpms_sitemap_taxonomies_<?php echo $key; ?>"
 
505
  type="checkbox"
506
  name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]"
507
- value="<?php echo $key ?>">
508
  <?php endif; ?>
509
- <label for="wpms_sitemap_taxonomies_<?php echo $key; ?>"><?php echo $value ?></label>
510
  </div>
511
  <?php
512
  }
@@ -514,20 +563,21 @@ class MetaSeoSitemap
514
 
515
  /**
516
  * Display field sitemap list page
 
 
517
  */
518
  public function sitemapPage()
519
  {
520
  global $wpdb;
521
- $pages = get_pages();
522
- $sql = $wpdb->prepare(
523
- "SELECT * FROM " . $wpdb->prefix . "posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s",
524
  array(
525
- "WPMS HTML Sitemap",
526
- "metaseo_html_sitemap",
527
- "page"
528
  )
529
- );
530
- $sitemap_page = $wpdb->get_row($sql);
531
 
532
  if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) {
533
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
@@ -535,13 +585,13 @@ class MetaSeoSitemap
535
  ?>
536
  <label>
537
  <select id="wpms_html_sitemap_page" name="_metaseo_settings_sitemap[wpms_html_sitemap_page]">
538
- <option value="0"><?php _e('- Choose Your Sitemap Page -', 'wp-meta-seo') ?></option>
539
  <?php
540
  foreach ($pages as $page) {
541
- if ($this->settings_sitemap['wpms_html_sitemap_page'] == $page->ID) {
542
- echo '<option selected value="' . $page->ID . '">' . $page->post_title . '</option>';
543
  } else {
544
- echo '<option value="' . $page->ID . '">' . $page->post_title . '</option>';
545
  }
546
  }
547
  ?>
@@ -549,13 +599,15 @@ class MetaSeoSitemap
549
  </label>
550
  <?php
551
  if (!empty($this->settings_sitemap['wpms_html_sitemap_page'])) {
552
- echo '<a class="button" href="' . get_post_permalink($this->settings_sitemap['wpms_html_sitemap_page']) . '"
553
- target="_blank">' . __('Open', 'wp-meta-seo') . '</a>';
554
  }
555
  }
556
 
557
  /**
558
  * Display field sitemap column
 
 
559
  */
560
  public function sitemapColumn()
561
  {
@@ -563,11 +615,11 @@ class MetaSeoSitemap
563
  <label>
564
  <select id="wpms_html_sitemap_column" name="_metaseo_settings_sitemap[wpms_html_sitemap_column]">
565
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 1) ?>
566
- value="1"><?php _e('1 column', 'wp-meta-seo') ?></option>
567
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 2) ?>
568
- value="2"><?php _e('2 column', 'wp-meta-seo') ?></option>
569
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 3) ?>
570
- value="3"><?php _e('3 column', 'wp-meta-seo') ?></option>
571
  </select>
572
  </label>
573
  <?php
@@ -575,6 +627,8 @@ class MetaSeoSitemap
575
 
576
  /**
577
  * Display field sitemap position
 
 
578
  */
579
  public function sitemapTheme()
580
  {
@@ -582,11 +636,11 @@ class MetaSeoSitemap
582
  <label>
583
  <select id="wpms_html_sitemap_theme" name="_metaseo_settings_sitemap[wpms_html_sitemap_theme]">
584
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'default') ?>
585
- value="default"><?php _e('Simple list', 'wp-meta-seo') ?></option>
586
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'accordions') ?>
587
- value="accordions"><?php _e('List with accordions', 'wp-meta-seo') ?></option>
588
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'tab') ?>
589
- value="tab"><?php _e('Tab layout', 'wp-meta-seo') ?></option>
590
  </select>
591
  </label>
592
  <?php
@@ -594,6 +648,8 @@ class MetaSeoSitemap
594
 
595
  /**
596
  * Display field sitemap position
 
 
597
  */
598
  public function sitemapPosition()
599
  {
@@ -601,11 +657,11 @@ class MetaSeoSitemap
601
  <label>
602
  <select id="wpms_html_sitemap_position" name="_metaseo_settings_sitemap[wpms_html_sitemap_position]">
603
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'replace') ?>
604
- value="replace"><?php _e('Replace the Page Content', 'wp-meta-seo') ?></option>
605
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'before') ?>
606
- value="before"><?php _e('Before Page Content', 'wp-meta-seo') ?></option>
607
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'after') ?>
608
- value="after"><?php _e('After Page Content', 'wp-meta-seo') ?></option>
609
  </select>
610
  </label>
611
  <?php
@@ -613,14 +669,15 @@ class MetaSeoSitemap
613
 
614
  /**
615
  * Get info of sitemap file xml
 
616
  * @return array
617
  */
618
  public function getPathSitemapFile()
619
  {
620
  if (is_multisite()) {
621
  $home_url = preg_replace(
622
- "/[^a-zA-ZА-Яа-я0-9\s]/",
623
- "_",
624
  str_replace('http://', '', str_replace('https://', '', site_url()))
625
  );
626
  $xml_file = 'wpms-sitemap_' . $home_url . '.xml';
@@ -632,8 +689,11 @@ class MetaSeoSitemap
632
  }
633
 
634
  /**
635
- * create sitemap
636
- * @param $sitemap_xml_name
 
 
 
637
  */
638
  public function createSitemap($sitemap_xml_name)
639
  {
@@ -644,7 +704,7 @@ class MetaSeoSitemap
644
  $taxonomies[] = $val;
645
  }
646
 
647
- $xml = new DomDocument('1.0', 'utf-8');
648
  $xml_stylesheet_path = content_url();
649
  if (defined('WP_PLUGIN_DIR')) {
650
  $xml_stylesheet_path .= '/' . basename(WP_PLUGIN_DIR) . '/wp-meta-seo/wpms-sitemap.xsl';
@@ -652,7 +712,7 @@ class MetaSeoSitemap
652
  $xml_stylesheet_path .= '/plugins/wp-meta-seo/sitemap.xsl';
653
  }
654
 
655
- $xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"$xml_stylesheet_path\"");
656
  $xml->appendChild($xslt);
657
  $gglstmp_urlset = $xml->appendChild(
658
  $xml->createElementNS(
@@ -663,8 +723,8 @@ class MetaSeoSitemap
663
 
664
  /* add home page */
665
  $list_links[] = home_url('/');
666
- $url = $gglstmp_urlset->appendChild($xml->createElement('url'));
667
- $loc = $url->appendChild($xml->createElement('loc'));
668
  $loc->appendChild($xml->createTextNode(home_url('/')));
669
  $lastmod = $url->appendChild($xml->createElement('lastmod'));
670
  $lastmod->appendChild($xml->createTextNode(date('Y-m-d\TH:i:sP', time())));
@@ -675,30 +735,29 @@ class MetaSeoSitemap
675
 
676
  // add menus post custom
677
  $menus = $this->getAllMenus();
678
- $res = $menus['posts_custom'];
679
  if (!empty($res)) {
680
  foreach ($res as $val) {
681
- $sql = $wpdb->prepare(
682
- "SELECT post_id FROM $wpdb->postmeta WHERE meta_key=%s AND meta_value=%d",
683
- array("_menu_item_object_id", $val->ID)
684
- );
685
- $menu_object = $wpdb->get_results($sql);
686
  if (!empty($menu_object)) {
687
  foreach ($menu_object as $menu) {
688
- $id = $menu->post_id;
689
- $type = get_post_meta($id, '_menu_item_type', true);
690
  $check_type = get_post_meta($id, '_menu_item_object', true);
691
- $permalink = $this->getPermalinkSitemap($check_type, $val->ID);
692
- if ($permalink != '#') {
693
  if (!in_array($permalink, $list_links)) {
694
  $list_links[] = $permalink;
695
- if ($type != 'taxonomy') {
696
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
697
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
698
  $loc->appendChild($xml->createTextNode($permalink));
699
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
700
- $now = $val->post_modified;
701
- $date = date('Y-m-d\TH:i:sP', strtotime($now));
702
  $lastmod->appendChild($xml->createTextNode($date));
703
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
704
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -746,35 +805,34 @@ class MetaSeoSitemap
746
  $res = $menus['categories'];
747
  if (!empty($res)) {
748
  foreach ($res as $k => $val) {
749
- $sql = $wpdb->prepare(
750
- "SELECT post_id FROM $wpdb->postmeta WHERE meta_key=%s AND meta_value=%d",
751
  array(
752
- "_menu_item_object_id",
753
  $val
754
  )
755
- );
756
- $menu_object = $wpdb->get_results($sql);
757
  if (!empty($menu_object)) {
758
  foreach ($menu_object as $menu) {
759
- $id = $menu->post_id;
760
- $type = get_post_meta($id, '_menu_item_type', true);
761
  $check_type = get_post_meta($id, '_menu_item_object', true);
762
- $permalink = get_term_link((int)$val, $check_type);
763
  if (empty($permalink)) {
764
  $permalink = get_permalink($id);
765
  }
766
 
767
  if (!in_array($permalink, $list_links)) {
768
  $list_links[] = $permalink;
769
- if ($type == 'taxonomy') {
770
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
771
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
772
  $loc->appendChild($xml->createTextNode($permalink));
773
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
774
- $ps = get_post($id);
775
 
776
  if (!empty($ps)) {
777
- $now = $ps->post_modified;
778
  $date = date('Y-m-d\TH:i:sP', strtotime($now));
779
  $lastmod->appendChild($xml->createTextNode($date));
780
  }
@@ -818,12 +876,12 @@ class MetaSeoSitemap
818
  $permalink = get_permalink($val->ID);
819
  if (!in_array($permalink, $list_links)) {
820
  $list_links[] = $permalink;
821
- $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
822
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
823
  $loc->appendChild($xml->createTextNode($permalink));
824
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
825
- $now = $val->post_modified;
826
- $date = date('Y-m-d\TH:i:sP', strtotime($now));
827
  $lastmod->appendChild($xml->createTextNode($date));
828
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
829
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -859,42 +917,38 @@ class MetaSeoSitemap
859
  // add custom post type
860
  $custom_post_types = get_post_types(
861
  array(
862
- 'public' => true,
863
  'exclude_from_search' => false,
864
- '_builtin' => false
865
  )
866
  );
867
  if (!empty($custom_post_types)) {
868
  foreach ($custom_post_types as $pt => $label) {
869
- $ids = array(0);
870
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
871
  if (!empty($settings_sitemap['wpms_sitemap_' . $pt])) {
872
- foreach ((array)$settings_sitemap['wpms_sitemap_' . $pt] as $k => $v) {
873
  if (!empty($v['post_id'])) {
874
- $ids[] = $v['post_id'];
875
  }
876
  }
877
  }
878
 
879
- $args = array(
880
- 'posts_per_page' => -1,
881
- 'post_type' => $pt,
882
- 'post__in' => $ids,
883
- 'post_status' => 'any'
884
- );
885
- $query = new WP_Query($args);
886
- $posts = $query->get_posts();
887
  if (!empty($posts)) {
888
  foreach ($posts as $val) {
889
  $permalink = get_permalink($val->ID);
890
  if (!in_array($permalink, $list_links)) {
891
  $list_links[] = $permalink;
892
- $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
893
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
894
  $loc->appendChild($xml->createTextNode($permalink));
895
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
896
- $now = $val->post_modified;
897
- $date = date('Y-m-d\TH:i:sP', strtotime($now));
898
  $lastmod->appendChild($xml->createTextNode($date));
899
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
900
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -935,17 +989,17 @@ class MetaSeoSitemap
935
  // add custom Url
936
  $listUrls = get_option('wpms_customUrls_list');
937
  $settings = get_option('_metaseo_settings_sitemap');
938
- if (!empty($settings['wpms_sitemap_customUrl'])) {
939
  foreach ($settings['wpms_sitemap_customUrl'] as $key => $customUrl) {
940
  if (!empty($listUrls[$key])) {
941
  if (!in_array($listUrls[$key]['link'], $list_links)) {
942
  $list_links[] = $listUrls[$key]['link'];
943
- $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
944
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
945
 
946
  $loc->appendChild($xml->createTextNode($listUrls[$key]['link']));
947
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
948
- $date = date('Y-m-d\TH:i:sP', $key);
949
  $lastmod->appendChild($xml->createTextNode($date));
950
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
951
 
@@ -978,13 +1032,13 @@ class MetaSeoSitemap
978
  $permalink = get_permalink($val->ID);
979
  if (!in_array($permalink, $list_links)) {
980
  $list_links[] = $permalink;
981
- $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
982
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
983
 
984
  $loc->appendChild($xml->createTextNode($permalink));
985
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
986
- $now = $val->post_modified;
987
- $date = date('Y-m-d\TH:i:sP', strtotime($now));
988
  $lastmod->appendChild($xml->createTextNode($date));
989
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
990
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -1020,19 +1074,22 @@ class MetaSeoSitemap
1020
  $terms = get_terms($value, 'hide_empty=1');
1021
  if (!empty($terms) && !is_wp_error($terms)) {
1022
  foreach ($terms as $term_value) {
1023
- $permalink = get_term_link((int)$term_value->term_id, $value);
1024
  if (!in_array($permalink, $list_links)) {
1025
  $list_links[] = $permalink;
1026
- $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
1027
- $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
1028
 
1029
  $loc->appendChild($xml->createTextNode($permalink));
1030
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
1031
 
1032
- $now = $wpdb->get_var(
1033
- "SELECT `post_modified` FROM $wpdb->posts, $wpdb->term_relationships
1034
- WHERE `post_status` = 'publish' AND `term_taxonomy_id` = " . $term_value->term_taxonomy_id . "
1035
- AND $wpdb->posts.ID= $wpdb->term_relationships.object_id ORDER BY `post_modified` DESC"
 
 
 
1036
  );
1037
  $date = date('Y-m-d\TH:i:sP', strtotime($now));
1038
  $lastmod->appendChild($xml->createTextNode($date));
@@ -1049,13 +1106,13 @@ class MetaSeoSitemap
1049
  $xml->formatOutput = true;
1050
 
1051
  if (!is_writable(ABSPATH)) {
1052
- @chmod(ABSPATH, 0755);
1053
  }
1054
 
1055
  if (is_multisite()) {
1056
  $home_url = preg_replace(
1057
- "/[^a-zA-ZА-Яа-я0-9\s]/",
1058
- "_",
1059
  str_replace('http://', '', str_replace('https://', '', site_url()))
1060
  );
1061
  $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
@@ -1066,11 +1123,14 @@ class MetaSeoSitemap
1066
  }
1067
 
1068
  /**
1069
- * create xml language
1070
- * @param $xml
1071
- * @param $id
1072
- * @param $el_type
1073
- * @param $loc
 
 
 
1074
  */
1075
  public function createXmlLang($xml, $id, $el_type, $loc)
1076
  {
@@ -1102,7 +1162,7 @@ class MetaSeoSitemap
1102
  } elseif (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
1103
  if (!empty($this->settings_sitemap['wpms_sitemap_include_lang'])) {
1104
  global $polylang;
1105
- $model = $polylang->filters->links_model->model;
1106
  $model_post = $polylang->filters->links_model->model->post;
1107
  foreach ($model->get_languages_list() as $language) {
1108
  $value = $model_post->get_translation($id, $language);
@@ -1110,7 +1170,7 @@ class MetaSeoSitemap
1110
  $lang = pll_get_post_language($value);
1111
  if (isset($lang) && in_array($lang, $this->settings_sitemap['wpms_sitemap_include_lang'])) {
1112
  $permalink = get_permalink($value);
1113
- $node = $xml->appendChild(
1114
  $xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link')
1115
  );
1116
  $node->setAttribute('rel', 'alternate');
@@ -1126,15 +1186,17 @@ class MetaSeoSitemap
1126
 
1127
  /**
1128
  * Retrieves the full permalink for the current post or post ID
1129
- * @param $type
1130
- * @param $id
 
 
1131
  * @return false|mixed|string
1132
  */
1133
  public function getPermalinkSitemap($type, $id)
1134
  {
1135
- if (isset($type) && $type == 'custom') {
1136
  $permalink = get_post_meta($id, '_menu_item_url', true);
1137
- } elseif ($type == 'taxonomy') {
1138
  $permalink = get_category_link($id);
1139
  } else {
1140
  $permalink = get_permalink($id);
@@ -1143,35 +1205,39 @@ class MetaSeoSitemap
1143
  }
1144
 
1145
  /**
1146
- * update sitemap setting
 
 
1147
  */
1148
  public function sitemapInfos()
1149
  {
 
1150
  $info_file = $this->getPathSitemapFile();
1151
- $xml_url = site_url('/') . $info_file['name'];
1152
  if (file_exists($info_file['path'])) {
1153
- $this->settings_sitemap['sitemap'] = array(
1154
- 'file' => $info_file['name'],
1155
- 'path' => $info_file['path'],
1156
- 'loc' => $xml_url,
1157
  'lastmod' => date('Y-m-d\TH:i:sP', filemtime($info_file['path']))
1158
  );
1159
- update_option('_metaseo_settings_sitemap', $this->settings_sitemap);
1160
  }
1161
  }
1162
 
1163
  /**
1164
- * display sitemap posts by column in front-end
 
1165
  * @return string
1166
  */
1167
  public function displayPosts()
1168
  {
1169
- $html = '';
1170
  $postTitle = get_post_type_object('post');
1171
  $postTitle = $postTitle->label;
1172
 
1173
- if (get_option('show_on_front') == 'page') {
1174
- $postsURL = get_permalink(get_option('page_for_posts'));
1175
  $postTitle = get_the_title(get_option('page_for_posts'));
1176
  } else {
1177
  $postsURL = get_bloginfo('url');
@@ -1191,7 +1257,7 @@ class MetaSeoSitemap
1191
  //Categories
1192
  $ids = array(0);
1193
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
1194
- foreach ((array)$this->settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
1195
  if (!empty($v['post_id'])) {
1196
  $ids[] = $k;
1197
  }
@@ -1201,19 +1267,19 @@ class MetaSeoSitemap
1201
  $cats = get_categories();
1202
  foreach ($cats as $cat) {
1203
  if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
1204
- $cat_link = "<a href='" . esc_url(get_term_link($cat)) . "'>" . $cat->cat_name . "</a>";
1205
  } else {
1206
  $cat_link = $cat->cat_name;
1207
  }
1208
 
1209
- $html .= "<li class='wpms_li_cate'><div class='cat_name'>$cat_link</div>";
1210
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
1211
- $html .= "<ul>";
1212
- query_posts(array('post__in' => $ids, 'posts_per_page' => -1, 'cat' => $cat->cat_ID));
1213
  while (have_posts()) {
1214
  the_post();
1215
  if ((get_post_meta(get_the_ID(), '_yoast_wpseo_meta-robots-noindex', true) === '1'
1216
- && get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) !== 'always')
1217
  || (get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) === 'never')
1218
  || (get_post_meta(get_the_ID(), '_yoast_wpms_redirect', true) !== '')) {
1219
  continue;
@@ -1221,14 +1287,14 @@ class MetaSeoSitemap
1221
 
1222
  $category = get_the_category();
1223
  // Only display a post link once, even if it's in multiple categories
1224
- if ($category[0]->cat_ID == $cat->cat_ID) {
1225
  $html .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
1226
  }
1227
  }
1228
  wp_reset_query();
1229
- $html .= "</ul>";
1230
  }
1231
- $html .= "</li>";
1232
  }
1233
  $html .= '</ul></div>';
1234
  $html .= '<div class="holder holder_sitemaps_posts"></div>';
@@ -1237,7 +1303,8 @@ class MetaSeoSitemap
1237
  }
1238
 
1239
  /**
1240
- * display sitemap pages by column in front-end
 
1241
  * @return string
1242
  */
1243
  public function displayPages()
@@ -1249,20 +1316,20 @@ class MetaSeoSitemap
1249
  if (!empty($this->settings_sitemap['wpms_public_name_pages'])) {
1250
  $pageTitle = $this->settings_sitemap['wpms_public_name_pages'];
1251
  }
1252
- $html .= '<div id="sitemap_pages" class="wpms_sitemap_pages"><h4>' . $pageTitle . '</h4>
1253
  <ul>';
1254
- $pageInc = '';
1255
  $getPages = $this->getPagesSitemap();
1256
  foreach ($getPages as $page) {
1257
  if (isset($this->settings_sitemap['wpms_html_sitemap_page'])
1258
- && $page->ID !== $this->settings_sitemap['wpms_html_sitemap_page']) {
1259
  if ((get_post_meta($page->ID, '_yoast_wpseo_meta-robots-noindex', true) === '1'
1260
- && get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) !== 'always')
1261
  || (get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) === 'never')
1262
  || (get_post_meta($page->ID, '_yoast_wpms_redirect', true) !== '')) {
1263
  continue;
1264
  }
1265
- if ($pageInc == '') {
1266
  $pageInc = $page->ID;
1267
  continue;
1268
  }
@@ -1270,14 +1337,14 @@ class MetaSeoSitemap
1270
  }
1271
  }
1272
 
1273
- if ($pageInc != '') {
1274
  $html .= wp_list_pages(
1275
  array(
1276
- 'include' => $pageInc,
1277
- 'title_li' => '',
1278
  'sort_column' => 'post_title',
1279
- 'sort_order' => 'ASC',
1280
- 'echo' => false
1281
  )
1282
  );
1283
  }
@@ -1289,12 +1356,13 @@ class MetaSeoSitemap
1289
  }
1290
 
1291
  /**
1292
- * display sitemap customUrl by column in front-end
 
1293
  * @return string
1294
  */
1295
  public function displayCustomUrl()
1296
  {
1297
- $html = '';
1298
  $lists = $this->settings_sitemap['wpms_sitemap_customUrl'];
1299
  $links = get_option('wpms_customUrls_list');
1300
  if (!empty($lists)) {
@@ -1302,18 +1370,24 @@ class MetaSeoSitemap
1302
  if (!empty($this->settings_sitemap['wpms_public_name_customUrl'])) {
1303
  $publictitle = $this->settings_sitemap['wpms_public_name_customUrl'];
1304
  } else {
1305
- $publictitle = __('Custom Url', 'wp-meta-seo');
1306
  }
1307
- $html .= '<h4>' . $publictitle . '</h4>';
1308
- $html .= '<ul>';
1309
- foreach ($lists as $key => $list) {
1310
- if (!empty($links[$key])) {
1311
- $html .= "<li>";
1312
- $html .= '<a href="' . $links[$key]['link'] . '">' . $links[$key]['title'] . '</a>';
1313
- $html .= "</li>";
 
 
 
1314
  }
 
 
1315
  }
1316
- $html .= '</ul></div>';
 
1317
  $html .= '<div class="holder holder_sitemaps_customUrl"></div>';
1318
  }
1319
 
@@ -1321,32 +1395,34 @@ class MetaSeoSitemap
1321
  }
1322
 
1323
  /**
 
 
1324
  * @return string
1325
  */
1326
  public function sitemapThemeDefault()
1327
  {
1328
  $html = '';
1329
  $html .= '<div id="wpms_sitemap"
1330
- class="theme_default columns_' . $this->settings_sitemap['wpms_html_sitemap_column'] . '">';
1331
- $arrs = array("displayPosts" => "wpms_display_column_posts", "displayPages" => "wpms_display_column_pages");
1332
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1333
- $arrs["displayCustomUrl"] = "wpms_display_column_customUrl";
1334
  }
1335
  $checkColumn = array();
1336
- for ($i = 1; $i <= (int)$this->settings_sitemap['wpms_html_sitemap_column']; $i++) {
1337
- $html .= '<div class="wpms_column wpms_column_' . $i . '" style="width:33%;float:left;">';
1338
- if ($i == 1) {
1339
  // Authors
1340
- if ($this->settings_sitemap['wpms_sitemap_author'] == 1) {
1341
- $html .= '<div id="sitemap_authors"><h3>' . __('Authors', 'wp-meta-seo') . '</h3>
1342
  <ul>';
1343
 
1344
  $authEx = implode(
1345
- ", ",
1346
  get_users('orderby=nicename&meta_key=wpms_excludeauthorsitemap&meta_value=on')
1347
  );
1348
- $html .= wp_list_authors(array('exclude_admin' => false, 'exclude' => $authEx, 'echo' => false));
1349
- $html .= '</ul></div>';
1350
  }
1351
  }
1352
 
@@ -1356,10 +1432,10 @@ class MetaSeoSitemap
1356
  }
1357
 
1358
  if (!in_array($ar, $checkColumn)) {
1359
- if ($i == (int)$this->settings_sitemap[$arr]) {
1360
  $checkColumn[] = $ar;
1361
- $output = $this->{$ar}();
1362
- $html .= $output;
1363
  }
1364
  }
1365
  }
@@ -1367,18 +1443,18 @@ class MetaSeoSitemap
1367
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1368
  $custom_post_types = get_post_types(
1369
  array(
1370
- 'public' => true,
1371
  'exclude_from_search' => false,
1372
- '_builtin' => false
1373
  )
1374
  );
1375
  if (!empty($custom_post_types)) {
1376
  foreach ($custom_post_types as $post_type => $label) {
1377
  if (!empty($this->settings_sitemap['wpms_display_column_' . $post_type])
1378
- && $i == (int)$this->settings_sitemap['wpms_display_column_' . $post_type]) {
1379
  //=====================================================================================
1380
  if (isset($this->settings_sitemap['wpms_public_name_' . $post_type])
1381
- && $this->settings_sitemap['wpms_public_name_' . $post_type] != '') {
1382
  $postTitle = $this->settings_sitemap['wpms_public_name_' . $post_type];
1383
  } else {
1384
  $postTitle = get_post_type_object($post_type);
@@ -1387,52 +1463,76 @@ class MetaSeoSitemap
1387
 
1388
  global $wpdb;
1389
  $taxonomy_objects = get_object_taxonomies($post_type, 'names');
1390
- $ids = array(0);
1391
  if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1392
  $html .= '<div id="sitemap_posts" class="wpms_sitemap_posts"><h4>';
1393
- $html .= $postTitle;
1394
  $html .= '</h4><ul>';
1395
- foreach ((array)$this->settings_sitemap['wpms_sitemap_' . $post_type] as $k => $v) {
1396
  if (!empty($v['post_id'])) {
1397
- $ids[] = $k;
1398
  }
1399
  }
1400
  }
1401
- foreach ($taxonomy_objects as $taxo) {
1402
- $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1403
- foreach ($categorys as $cat) {
1404
- $sql = "SELECT p.ID as ID,p.post_title as post_title
1405
- FROM $wpdb->posts AS p
1406
- INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id)
1407
- INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1408
- INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
1409
- WHERE p.post_status = 'publish'
1410
- AND p.post_type = '$post_type'
1411
- AND tt.taxonomy = '$taxo' AND t.slug='$cat->slug'
1412
- ORDER BY p.post_date DESC";
1413
- $results = $wpdb->get_results($sql);
1414
- if (!empty($results)) {
1415
- if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
1416
- $cat_link = "<a href='" . esc_url(get_term_link($cat)) . "'>
1417
- " . $cat->cat_name . "</a>";
1418
- } else {
1419
- $cat_link = $cat->cat_name;
1420
- }
1421
- $html .= "<li class='wpms_li_cate wpms_li_cate'>";
1422
- $html .= "<div class='cat_name'>$cat_link</div>";
1423
-
1424
- if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1425
- $html .= "<ul>";
1426
- foreach ($results as $p) {
1427
- $i = $cat->cat_ID . '-' . $p->ID;
1428
- if (isset($this->settings_sitemap['wpms_sitemap_' . $post_type][$i])) {
1429
- $html .= '<li><a href="' . get_permalink($p->ID) . '">
1430
- ' . $p->post_title . '</a></li>';
 
 
 
 
 
 
1431
  }
 
1432
  }
1433
- $html .= "</ul>";
1434
  }
1435
- $html .= "</li>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1436
  }
1437
  }
1438
  }
@@ -1448,12 +1548,12 @@ ORDER BY p.post_date DESC";
1448
  }
1449
  // ====================
1450
 
1451
- $ids_menu = array(0);
1452
  $check_menu = array();
1453
- $terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true));
1454
  foreach ($terms as $term) {
1455
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1456
- $ids_menu = array_merge($ids_menu, $list_submenu_id);
1457
  }
1458
 
1459
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -1468,14 +1568,14 @@ ORDER BY p.post_date DESC";
1468
  $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] = 1;
1469
  }
1470
 
1471
- if ($i == (int)$this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) {
1472
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1473
- $html .= '<div id="sitemap_menus_' . $term->term_id . '" class="wpms_sitemap_menus">';
1474
- $viewmenu = $this->viewMenusFrontend($term, $ids_menu);
1475
- $html .= $viewmenu;
1476
 
1477
  $html .= '</div>';
1478
- $html .= '<div class="holder holder_sitemaps_menus_' . $term->term_id . '"></div>';
1479
  }
1480
  }
1481
  }
@@ -1493,7 +1593,8 @@ ORDER BY p.post_date DESC";
1493
  }
1494
 
1495
  /**
1496
- * display html sitemap in front-end
 
1497
  * @return array|string
1498
  */
1499
  public function sitemapShortcode()
@@ -1508,18 +1609,22 @@ ORDER BY p.post_date DESC";
1508
 
1509
  $custom_post_types = get_post_types(
1510
  array(
1511
- 'public' => true,
1512
  'exclude_from_search' => false,
1513
- '_builtin' => false
1514
  )
1515
  );
1516
 
1517
- if ($theme == 'default') {
1518
- echo '<link rel="stylesheet" type="text/css"
1519
- href="' . plugin_dir_url(dirname(__FILE__)) . 'css/html_sitemap.css"
1520
- media="screen" />';
 
 
 
 
1521
  $html = $this->sitemapThemeDefault();
1522
- } elseif ($theme == 'tab') {
1523
  wp_enqueue_script(
1524
  'wpms_materialize_js',
1525
  plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)),
@@ -1540,12 +1645,12 @@ ORDER BY p.post_date DESC";
1540
  require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php');
1541
 
1542
  // source menu
1543
- $ids_menu = array(0);
1544
  $check_menu = array();
1545
- $terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true));
1546
  foreach ($terms as $term) {
1547
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1548
- $ids_menu = array_merge($ids_menu, $list_submenu_id);
1549
  }
1550
 
1551
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
@@ -1558,19 +1663,20 @@ ORDER BY p.post_date DESC";
1558
  foreach ($terms as $term) {
1559
  if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
1560
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1561
- echo '<div id="sitemap_menus_' . $term->term_id . '" class="wpms_sitemap_menus">';
1562
  $viewmenu = $this->viewMenusFrontend($term, $ids_menu);
 
1563
  echo $viewmenu;
1564
 
1565
  echo '</div>';
1566
- echo '<div class="holder holder_sitemaps_menus_' . $term->term_id . '"></div>';
1567
  }
1568
  }
1569
  echo '</div>';
1570
  }
1571
  }
1572
  echo '</div>';
1573
- } elseif ($theme == 'accordions') {
1574
  wp_enqueue_script(
1575
  'wpms_materialize_js',
1576
  plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)),
@@ -1604,9 +1710,9 @@ ORDER BY p.post_date DESC";
1604
  = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_urlcustom.php';
1605
  }
1606
 
1607
- for ($i = 1; $i <= 4; $i++) {
1608
  foreach ($arrays as $key => $item) {
1609
- if ($this->settings_sitemap[$key] == $i) {
1610
  require_once($item);
1611
  }
1612
  }
@@ -1620,23 +1726,24 @@ ORDER BY p.post_date DESC";
1620
  }
1621
 
1622
  /**
1623
- * add wpms_html_sitemap shortcode in content
1624
- * @param $content
 
 
1625
  * @return string
1626
  */
1627
  public function sitemapInContent($content)
1628
  {
1629
  global $wpdb;
1630
- $sql = $wpdb->prepare(
1631
- "SELECT * FROM " . $wpdb->prefix . "posts
1632
- WHERE post_title = %s AND post_excerpt = %s AND post_type = %s",
1633
  array(
1634
- "WPMS HTML Sitemap",
1635
- "metaseo_html_sitemap",
1636
- "page"
1637
  )
1638
- );
1639
- $sitemap_page = $wpdb->get_row($sql);
1640
 
1641
  if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) {
1642
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
@@ -1663,30 +1770,31 @@ ORDER BY p.post_date DESC";
1663
  }
1664
 
1665
  /**
1666
- * get all menu
 
1667
  * @return array
1668
  */
1669
  public function getAllMenus()
1670
  {
1671
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1672
- $post_types = get_post_types('', 'names');
1673
  unset($post_types['revision']);
1674
  unset($post_types['attachment']);
1675
  $ids_posts_custom = array(0);
1676
- $ids_categories = array();
1677
 
1678
  if (empty($settings_sitemap['wpms_check_firstsave'])) {
1679
- $args = array(
1680
- 'posts_per_page' => -1,
1681
- 'post_type' => 'nav_menu_item',
1682
- 'post_status' => 'publish'
1683
  );
1684
- $query = new WP_Query($args);
1685
  $posts_menu = $query->get_posts();
1686
  foreach ($posts_menu as $k => $v) {
1687
- $type = get_post_meta($v->ID, '_menu_item_type', true);
1688
  $post_meta_object_id = get_post_meta($v->ID, '_menu_item_object_id', true);
1689
- if ($type != 'taxonomy') {
1690
  $ids_posts_custom[] = $post_meta_object_id;
1691
  } else {
1692
  $ids_categories[] = $post_meta_object_id;
@@ -1696,9 +1804,9 @@ ORDER BY p.post_date DESC";
1696
  if (!empty($settings_sitemap['wpms_sitemap_menus'])) {
1697
  foreach ($settings_sitemap['wpms_sitemap_menus'] as $k => $v) {
1698
  if (!empty($v['menu_id'])) {
1699
- $type = get_post_meta($k, '_menu_item_type', true);
1700
  $post_meta_object_id = get_post_meta($k, '_menu_item_object_id', true);
1701
- if ($type != 'taxonomy') {
1702
  $ids_posts_custom[] = $post_meta_object_id;
1703
  } else {
1704
  $ids_categories[] = $post_meta_object_id;
@@ -1708,39 +1816,40 @@ ORDER BY p.post_date DESC";
1708
  }
1709
  }
1710
 
1711
- $args = array(
1712
- 'posts_per_page' => -1,
1713
- 'post_type' => $post_types,
1714
- 'post__in' => $ids_posts_custom,
1715
- 'post_status' => 'publish'
1716
  );
1717
- $query = new WP_Query($args);
1718
  $menus_post_custom = $query->get_posts();
1719
  return array('posts_custom' => $menus_post_custom, 'categories' => $ids_categories);
1720
  }
1721
 
1722
  /**
1723
- * get posts selected in sitemap setting
 
1724
  * @return array
1725
  */
1726
  public function getPostsSitemap()
1727
  {
1728
- $post_types = $this->getPostType();
1729
- $ids = array(0);
1730
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1731
  if (!empty($settings_sitemap['wpms_sitemap_posts'])) {
1732
- foreach ((array)$settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
1733
  if (!empty($v['post_id'])) {
1734
  $ids[] = $k;
1735
  }
1736
  }
1737
  }
1738
 
1739
- $args = array(
1740
- 'posts_per_page' => -1,
1741
- 'post_type' => $post_types,
1742
- 'post__in' => $ids,
1743
- 'post_status' => 'publish'
1744
  );
1745
  $query = new WP_Query($args);
1746
  $posts = $query->get_posts();
@@ -1749,9 +1858,10 @@ ORDER BY p.post_date DESC";
1749
 
1750
  /**
1751
  * Get a list of all registered post type objects.
 
1752
  * @return array
1753
  */
1754
- public function getPostType()
1755
  {
1756
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1757
  unset($post_types['attachment']);
@@ -1760,12 +1870,13 @@ ORDER BY p.post_date DESC";
1760
  }
1761
 
1762
  /**
1763
- * get pages selected in sitemap setting
 
1764
  * @return array
1765
  */
1766
  public function getPagesSitemap()
1767
  {
1768
- $ids = array(0);
1769
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1770
  if (!empty($settings_sitemap['wpms_sitemap_pages'])) {
1771
  foreach ($settings_sitemap['wpms_sitemap_pages'] as $k => $v) {
@@ -1775,11 +1886,11 @@ ORDER BY p.post_date DESC";
1775
  }
1776
  }
1777
 
1778
- $args = array(
1779
- 'posts_per_page' => -1,
1780
- 'post_type' => 'page',
1781
- 'post__in' => $ids,
1782
- 'post_status' => 'publish'
1783
  );
1784
  $query = new WP_Query($args);
1785
  $pages = $query->get_posts();
@@ -1787,47 +1898,47 @@ ORDER BY p.post_date DESC";
1787
  }
1788
 
1789
  /**
1790
- * get pages
 
1791
  * @return array|null|object
1792
  */
1793
  public function getPages()
1794
  {
1795
  global $wpdb;
1796
- $sql = "SELECT ID,post_title FROM $wpdb->posts WHERE
1797
- post_status = 'publish' AND post_type = 'page' ORDER BY post_date DESC";
1798
- $pages = $wpdb->get_results($sql);
1799
  return $pages;
1800
  }
1801
 
1802
  /**
1803
- * get posts by category
 
1804
  * @return array
1805
  */
1806
  public function getPosts()
1807
  {
1808
- $posts = array();
1809
- $taxo = 'category';
1810
  $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1811
  global $wpdb;
1812
  foreach ($categorys as $cat) {
1813
- $sql = $wpdb->prepare("SELECT p.ID as ID,p.post_title as post_title
1814
- FROM $wpdb->posts AS p
1815
- INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id)
1816
- INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1817
- INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
1818
- WHERE p.post_status = 'publish'
1819
- AND p.post_type = 'post'
1820
  AND tt.taxonomy = %s AND t.slug=%s
1821
- ORDER BY p.post_date DESC", array($taxo, $cat->slug));
1822
- $results = $wpdb->get_results($sql);
1823
  if (!empty($results)) {
1824
- $obj = new StdClass();
1825
  $obj->cat_name = $cat->cat_name;
1826
- $obj->cat_ID = $cat->cat_ID;
1827
- $obj->taxo = $taxo;
1828
- $obj->slug = $cat->slug;
1829
- $obj->results = $results;
1830
- $posts[] = $obj;
1831
  }
1832
  }
1833
 
@@ -1835,40 +1946,56 @@ ORDER BY p.post_date DESC", array($taxo, $cat->slug));
1835
  }
1836
 
1837
  /**
1838
- * get posts by category
1839
- * @param $post_type
 
 
1840
  * @return array
1841
  */
1842
  public function getPostsCustom($post_type)
1843
  {
1844
- $posts = array();
 
1845
  $taxonomy_objects = get_object_taxonomies($post_type, 'names');
1846
- foreach ($taxonomy_objects as $taxo) {
1847
- $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1848
- global $wpdb;
1849
-
1850
- foreach ($categorys as $cat) {
1851
- $sql = $wpdb->prepare("SELECT p.ID as ID,p.post_title as post_title
1852
- FROM $wpdb->posts AS p
1853
- INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id)
1854
- INNER JOIN $wpdb->term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1855
- INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
1856
- WHERE p.post_status = 'publish'
1857
  AND p.post_type = %s
1858
  AND tt.taxonomy = %s AND t.slug=%s
1859
- ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1860
- $results = $wpdb->get_results($sql);
1861
-
1862
- if (!empty($results)) {
1863
- $obj = new StdClass();
1864
- $obj->cat_name = $cat->cat_name;
1865
- $obj->cat_ID = $cat->cat_ID;
1866
- $obj->taxo = $taxo;
1867
- $obj->slug = $cat->slug;
1868
- $obj->results = $results;
1869
- $posts[] = $obj;
1870
  }
1871
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1872
  }
1873
 
1874
  return $posts;
@@ -1876,13 +2003,15 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1876
 
1877
  /**
1878
  * Display sitemap menu in front-end
1879
- * @param $term
1880
- * @param array $ids_menu list menu id
 
 
1881
  * @return string
1882
  */
1883
  public function viewMenusFrontend($term, $ids_menu)
1884
  {
1885
- $html = '';
1886
  $list_menus = array();
1887
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1888
  $list_menus = $ids_menu;
@@ -1895,56 +2024,56 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1895
  }
1896
 
1897
  $args = array(
1898
- 'orderby' => 'menu_order',
1899
- 'order' => 'ASC',
1900
- 'posts_per_page' => -1,
1901
- 'post_type' => 'nav_menu_item',
1902
- 'post_status' => 'any',
1903
- 'post__in' => $list_menus,
1904
- 'tax_query' => array(
1905
  array(
1906
  'taxonomy' => 'nav_menu',
1907
- 'field' => 'slug',
1908
- 'terms' => $term->slug,
1909
  ),
1910
  ),
1911
  );
1912
 
1913
- $query = new WP_Query($args);
1914
  $submenus = $query->get_posts();
1915
  if (!empty($submenus)) {
1916
- $html .= '<h4>' . $term->name . '</h4>';
1917
  $html .= '<ul class="wpms_frontend_menus_sitemap">';
1918
  foreach ($submenus as $menu) {
1919
- $type = get_post_meta($menu->ID, '_menu_item_type', true);
1920
- $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
1921
- $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true);
1922
  $this->level[$menu->ID] = 0;
1923
- $level = $this->countParent($menu->ID);
1924
- if ($type == 'taxonomy') {
1925
  $post_submenu = get_post($menu->ID);
1926
- $title = $post_submenu->post_title;
1927
  if (empty($title)) {
1928
- $term = get_term($id_menu, $type_menu);
1929
  $title = $term->name;
1930
  }
1931
  } else {
1932
- $post = get_post($menu->ID);
1933
  $title = $post->post_title;
1934
  if (empty($title)) {
1935
  $post_submenu = get_post($id_menu);
1936
- $title = $post_submenu->post_title;
1937
  }
1938
  }
1939
- $type = get_post_meta($menu->ID, '_menu_item_type', true);
1940
  $permalink = $this->getPermalinkSitemap($type, $id_menu);
1941
- $margin = $level * 10;
1942
- $style = '';
1943
- if ($level != 0) {
1944
- $style = 'style="margin-left:' . $margin . 'px"';
1945
  }
1946
- $html .= '<li class="wpms_menu_level_' . $level . '" ' . $style . '>';
1947
- $html .= '<a href="' . $permalink . '">' . $title . '</a>';
1948
  $html .= '</li>';
1949
  }
1950
 
@@ -1954,9 +2083,11 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1954
  }
1955
 
1956
  /**
1957
- * get count parent for a menu
1958
- * @param int $menuID ID of menu
1959
- * @return int
 
 
1960
  */
1961
  public function countParent($menuID)
1962
  {
@@ -1968,16 +2099,20 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1968
  $this->loopParent($parent, $menuID);
1969
  }
1970
 
1971
- return (int)$this->level[$menuID];
1972
  }
1973
 
1974
  /**
1975
- * @param $menuID
1976
- * @param $menuIDroot
 
 
 
 
1977
  */
1978
  public function loopParent($menuID, $menuIDroot)
1979
  {
1980
- $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true);
1981
  $parent_1 = get_post_meta($parent, '_menu_item_menu_item_parent', true);
1982
  if ((!empty($this->settings_sitemap['wpms_sitemap_menus'][$parent]) && !empty($parent))
1983
  || (!empty($parent_1) && !empty($parent))) {
@@ -1988,42 +2123,44 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
1988
 
1989
  /**
1990
  * Display list menu in sitemap settings
1991
- * @param $term
 
 
1992
  * @return string
1993
  */
1994
  public function viewMenus($term)
1995
  {
1996
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1997
- $args = array(
1998
- 'orderby' => 'menu_order',
1999
- 'order' => 'ASC',
2000
- 'posts_per_page' => -1,
2001
- 'post_type' => 'nav_menu_item',
2002
- 'post_status' => 'any',
2003
- 'post__in' => $list_submenu_id,
2004
- 'meta_key' => '_menu_item_menu_item_parent',
2005
- 'meta_value' => 0
2006
  );
2007
 
2008
- $query = new WP_Query($args);
2009
  $submenus = $query->get_posts();
2010
 
2011
  $this->html .= '<h3>';
2012
  $this->html .= '<div class="pure-checkbox">';
2013
- $this->html .= '<input class="xm_cb_all" id="xm_cb_all_' . $term->slug . '" type="checkbox">';
2014
- $this->html .= '<label for="xm_cb_all_' . $term->slug . '">' . $term->name . '</label>';
2015
  $this->html .= '</div>';
2016
  $this->html .= '</h3>';
2017
  $this->html .= '<div class="wpms_xmp_custom_column" style="font-weight: bold;">';
2018
- $this->html .= '<label>' . __('Display in column', 'wp-meta-seo') . '</label>';
2019
  $this->html .= '<select class="wpms_display_column wpms_display_column_menus"
2020
- data-menu_id="' . $term->term_id . '">';
2021
- for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i++) {
2022
  if (isset($this->settings_sitemap['wpms_display_column_menus'][$term->term_id])
2023
- && $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] == $i) {
2024
- $this->html .= '<option selected value="' . $i . '">' . $this->columns[$i] . '</option>';
2025
  } else {
2026
- $this->html .= '<option value="' . $i . '">' . $this->columns[$i] . '</option>';
2027
  }
2028
  }
2029
  $this->html .= '</select>';
@@ -2046,60 +2183,60 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2046
  $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency']
2047
  );
2048
 
2049
- $type = get_post_meta($menu->ID, '_menu_item_type', true);
2050
  $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
2051
- $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true);
2052
- if ($type == 'taxonomy') {
2053
  $post_submenu = get_post($menu->ID);
2054
- $title = $post_submenu->post_title;
2055
  if (empty($title)) {
2056
- $term = get_term($id_menu, $type_menu);
2057
  $title = $term->name;
2058
  }
2059
  } else {
2060
- $post = get_post($menu->ID);
2061
  $title = $post->post_title;
2062
  if (empty($title)) {
2063
  $post_submenu = get_post($id_menu);
2064
- $title = $post_submenu->post_title;
2065
  }
2066
  }
2067
- $level = 1;
2068
  $this->html .= '<div class="wpms_row wpms_row_record">';
2069
  $check_type = get_post_meta($menu->ID, '_menu_item_object', true);
2070
- $permalink = $this->getPermalinkSitemap($check_type, $id_menu);
2071
  $this->html .= '<div style="float:left;line-height:30px">';
2072
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
2073
  $this->html .= '<input class="wpms_sitemap_input_link checked"
2074
- type="hidden" data-type="menu" value="' . $permalink . '">';
2075
  $this->html .= '<div class="pure-checkbox">';
2076
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '"
2077
- id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox"
2078
- name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]"
2079
- value="' . $menu->ID . '" checked>';
2080
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">' . $title . '</label>';
2081
  $this->html .= '</div>';
2082
  } else {
2083
  if (isset($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'])
2084
- && $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'] == $menu->ID) {
2085
  $this->html .= '<input class="wpms_sitemap_input_link checked"
2086
- type="hidden" data-type="menu" value="' . $permalink . '">';
2087
  $this->html .= '<div class="pure-checkbox">';
2088
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '"
2089
- id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox"
2090
- name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]"
2091
- value="' . $menu->ID . '" checked>';
2092
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">' . $title . '</label>';
2093
  $this->html .= '</div>';
2094
  } else {
2095
  $this->html .= '<input class="wpms_sitemap_input_link" type="hidden" data-type="menu"
2096
- value="' . $permalink . '">';
2097
  $this->html .= '<div class="pure-checkbox">';
2098
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '"
2099
- id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox"
2100
- name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]"
2101
- value="' . $menu->ID . '">';
2102
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">' . $title . '</label>';
2103
  $this->html .= '</div>';
2104
  }
2105
  }
@@ -2115,27 +2252,30 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2115
 
2116
  /**
2117
  * Display list menu in sitemap settings
2118
- * @param int $menuID ID of menu
2119
- * @param int $level level of menu
2120
- * @param array $settings_sitemap all settings
2121
- * @param $term
 
 
 
2122
  */
2123
  public function loop($menuID, $level, $settings_sitemap, $term)
2124
  {
2125
- $args = array(
2126
- 'post_type' => 'nav_menu_item',
2127
- 'posts_per_page' => -1,
2128
- 'meta_key' => '_menu_item_menu_item_parent',
2129
- 'meta_value' => $menuID,
2130
- 'orderby' => 'menu_order',
2131
- 'order' => 'ASC'
2132
  );
2133
- $query = new WP_Query($args);
2134
  $submenus = $query->get_posts();
2135
  if (!empty($submenus)) {
2136
  foreach ($submenus as $submenu) {
2137
- $type = get_post_meta($submenu->ID, '_menu_item_type', true);
2138
- $type_menu = get_post_meta($submenu->ID, '_menu_item_object', true);
2139
  $post_subid = get_post_meta($submenu->ID, '_menu_item_object_id', true);
2140
  if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'])) {
2141
  $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'] = 'monthly';
@@ -2143,24 +2283,24 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2143
  if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'])) {
2144
  $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'] = '1.0';
2145
  }
2146
- if ($type == 'taxonomy') {
2147
  $post_submenu = get_post($submenu->ID);
2148
- $title = $post_submenu->post_title;
2149
  if (empty($title)) {
2150
- $term = get_term($post_subid, $type_menu);
2151
  $title = $term->name;
2152
  }
2153
  } else {
2154
  $post_submenu = get_post($submenu->ID);
2155
- $title = $post_submenu->post_title;
2156
  if (empty($title)) {
2157
  $post_submenu = get_post($post_subid);
2158
- $title = $post_submenu->post_title;
2159
  }
2160
  }
2161
 
2162
  $space = '';
2163
- for ($i = 1; $i <= $level * 3; $i++) {
2164
  $space .= '&nbsp;';
2165
  }
2166
  $slpr = $this->viewPriority(
@@ -2175,22 +2315,22 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2175
  );
2176
 
2177
  if (empty($settings_sitemap['wpms_check_firstsave'])) {
2178
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '"
2179
- class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '"
2180
- checked name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]"
2181
  type="checkbox" value="' . $submenu->ID . '">';
2182
  } else {
2183
  if (isset($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'])
2184
- && $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'] == $submenu->ID) {
2185
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '"
2186
- class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" checked
2187
- name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]"
2188
- type="checkbox" value="' . $submenu->ID . '">';
2189
  } else {
2190
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '"
2191
- class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '"
2192
- name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]"
2193
- type="checkbox" value="' . $submenu->ID . '">';
2194
  }
2195
  }
2196
 
@@ -2198,7 +2338,7 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2198
  $this->html .= '<div style="float:left;line-height:30px">';
2199
  $this->html .= '<div class="pure-checkbox">';
2200
  $this->html .= $checkbox;
2201
- $this->html .= '<label for="wpms_sitemap_menus_' . $submenu->ID . '">' . $title . '</label>';
2202
  $this->html .= '</div>';
2203
  $this->html .= '</div>';
2204
  $this->html .= '<div style="margin-left:200px">' . $slpr . $slfr . '</div>';
@@ -2210,19 +2350,23 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2210
 
2211
  /**
2212
  * Ajax generate sitemap to xml file
 
 
2213
  */
2214
  public function regenerateSitemaps()
2215
  {
2216
  $wpms_url_robot = get_home_path() . 'robots.txt';
2217
- $wpms_url_home = site_url('/');
 
2218
  $this->createSitemap($this->wpms_sitemap_name);
2219
- if ($this->settings_sitemap['wpms_sitemap_root'] == 1) {
2220
  $this->createSitemap($this->wpms_sitemap_default_name);
2221
  }
2222
 
2223
- if (isset($this->settings_sitemap['wpms_sitemap_add']) && $this->settings_sitemap['wpms_sitemap_add'] == 1) {
2224
  if (!file_exists($wpms_url_robot) && !is_multisite()) {
2225
  ob_start();
 
2226
  error_reporting(0);
2227
  do_robots();
2228
  $robots_content = ob_get_clean();
@@ -2234,13 +2378,13 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2234
 
2235
  if (file_exists($wpms_url_robot) && !is_multisite()) {
2236
  if (!is_writable($wpms_url_robot)) {
2237
- @chmod($wpms_url_robot, 0755);
2238
  }
2239
 
2240
  if (is_writable($wpms_url_robot)) {
2241
  $file_content = file_get_contents($wpms_url_robot);
2242
  if (isset($this->settings_sitemap['wpms_sitemap_add'])
2243
- && $this->settings_sitemap['wpms_sitemap_add'] == 1
2244
  && !preg_match('|Sitemap: ' . $wpms_url_home . $this->wpms_sitemap_name . '|', $file_content)) {
2245
  file_put_contents(
2246
  $wpms_url_robot,
@@ -2248,7 +2392,7 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2248
  );
2249
  }
2250
  } else {
2251
- $error = __('Cannot edit "robots.txt". Check your permissions', 'wp-meta-seo');
2252
  wp_send_json(array('status' => false, 'message' => $error));
2253
  }
2254
  }
@@ -2260,21 +2404,23 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2260
 
2261
  /**
2262
  * Display priority for each item
2263
- * @param string $id selectbox id
2264
- * @param string $name selectbox name
2265
- * @param string $selected selected value
 
 
2266
  * @return string
2267
  */
2268
  public function viewPriority($id, $name, $selected)
2269
  {
2270
  $values = array('1' => '100%', '0.9' => '90%', '0.8' => '80%', '0.7' => '70%', '0.6' => '60%', '0.5' => '50%');
2271
- $select = '<select id="' . $id . '" name="' . $name . '" class="wpmsleft">';
2272
- $select .= '<option value="1">' . __('Priority', 'wp-meta-seo') . '</option>';
2273
  foreach ($values as $k => $v) {
2274
- if ($k == $selected) {
2275
- $select .= '<option selected value="' . $k . '">' . $v . '</option>';
2276
  } else {
2277
- $select .= '<option value="' . $k . '">' . $v . '</option>';
2278
  }
2279
  }
2280
  $select .= '</select>';
@@ -2283,29 +2429,31 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2283
 
2284
  /**
2285
  * Display frequency for each item
2286
- * @param string $id selectbox id
2287
- * @param string $name selectbox name
2288
- * @param string $selected selected value
 
 
2289
  * @return string
2290
  */
2291
  public function viewFrequency($id, $name, $selected)
2292
  {
2293
  $values = array(
2294
- 'always' => 'Always',
2295
- 'hourly' => 'Hourly',
2296
- 'daily' => 'Daily',
2297
- 'weekly' => 'Weekly',
2298
  'monthly' => 'Monthly',
2299
- 'yearly' => 'Yearly',
2300
- 'never' => 'Never'
2301
  );
2302
- $select = '<select id="' . $id . '" name="' . $name . '" class="wpmsleft">';
2303
- $select .= '<option value="monthly">' . __('Frequency', 'wp-meta-seo') . '</option>';
2304
  foreach ($values as $k => $v) {
2305
- if ($k == $selected) {
2306
- $select .= '<option selected value="' . $k . '">' . $v . '</option>';
2307
  } else {
2308
- $select .= '<option value="' . $k . '">' . $v . '</option>';
2309
  }
2310
  }
2311
  $select .= '</select>';
@@ -2314,48 +2462,55 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2314
 
2315
  /**
2316
  * Ajax update sitemap settings
 
 
2317
  */
2318
  public function saveSitemapSettings()
2319
  {
 
 
 
 
 
2320
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
2321
- $lists = array(
2322
- "wpms_sitemap_add" => 0,
2323
- "wpms_sitemap_root" => 0,
2324
- "wpms_sitemap_author" => 0,
2325
- "wpms_html_sitemap_page" => 0,
2326
- "wpms_html_sitemap_column" => 1,
2327
- "wpms_html_sitemap_theme" => "default",
2328
- "wpms_html_sitemap_position" => "after",
2329
- "wpms_sitemap_taxonomies" => array(),
2330
- "wpms_check_firstsave" => 0,
2331
- "wpms_display_column_posts" => 1,
2332
- "wpms_display_column_pages" => 1,
2333
- "wpms_category_link" => array(),
2334
- "wpms_display_order_menus" => 1,
2335
- "wpms_display_order_posts" => 2,
2336
- "wpms_display_order_pages" => 3,
2337
- "wpms_display_order_urls" => 4
2338
  );
2339
 
2340
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2341
  $custom_post_types = get_post_types(
2342
  array(
2343
- 'public' => true,
2344
  'exclude_from_search' => false,
2345
- '_builtin' => false
2346
  )
2347
  );
2348
  if (!empty($custom_post_types)) {
2349
  foreach ($custom_post_types as $post_type => $label) {
2350
  $lists['wpms_display_column_' . $post_type] = 1;
2351
- $lists['wpms_public_name_' . $post_type] = "";
2352
- $lists['wpms_sitemap_' . $post_type] = array();
2353
  }
2354
  }
2355
 
2356
  $lists['wpms_display_column_customUrl'] = 1;
2357
- $lists['wpms_public_name_customUrl'] = "";
2358
- $lists['wpms_sitemap_customUrl'] = array();
2359
  }
2360
 
2361
  $wpms_display_column_menus = json_decode(stripslashes($_POST['wpms_display_column_menus']), true);
@@ -2372,26 +2527,26 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2372
  }
2373
 
2374
  $lists_selected = array(
2375
- "wpms_sitemap_posts" => array(),
2376
- "wpms_sitemap_pages" => array(),
2377
- "wpms_sitemap_menus" => array()
2378
  );
2379
 
2380
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2381
  $custom_post_types = get_post_types(
2382
  array(
2383
- 'public' => true,
2384
  'exclude_from_search' => false,
2385
- '_builtin' => false
2386
  )
2387
  );
2388
  if (!empty($custom_post_types)) {
2389
  foreach ($custom_post_types as $post_type => $label) {
2390
- $lists_selected["wpms_sitemap_" . $post_type] = array();
2391
  }
2392
  }
2393
 
2394
- $lists_selected["wpms_sitemap_customUrl"] = array();
2395
 
2396
  // save setting include lang
2397
  if (isset($_POST['wpms_lang_list']) && is_array($_POST['wpms_lang_list'])) {
@@ -2400,8 +2555,8 @@ ORDER BY p.post_date DESC", array($post_type, $taxo, $cat->slug));
2400
  }
2401
 
2402
  foreach ($lists_selected as $k => $v) {
2403
- if (isset($_POST[$k]) && $_POST[$k] != '{}') {
2404
- $values = json_decode(stripslashes($_POST[$k]), true);
2405
  $settings_sitemap[$k] = $values;
2406
  } else {
2407
  $settings_sitemap[$k] = array();
10
  {
11
 
12
  /**
13
+ * Sitemap html
14
+ *
15
  * @var string
16
  */
17
  public $html = '';
18
  /**
19
+ * WPMS Sitemap xml file
20
+ *
21
  * @var string
22
  */
23
  public $wpms_sitemap_name = 'wpms-sitemap.xml';
24
  /**
25
+ * Sitemap xml file
26
+ *
27
  * @var string
28
  */
29
  public $wpms_sitemap_default_name = 'sitemap.xml';
30
  /**
31
+ * List columns sitemap
32
+ *
33
  * @var array
34
  */
35
  public $columns = array('Zezo', 'One', 'Two', 'Three');
36
  /**
37
+ * Level menu
38
+ *
39
  * @var array
40
  */
41
  public $level = array();
42
  /**
43
+ * Sitemap settings
44
+ *
45
  * @var array
46
  */
47
  public $settings_sitemap;
50
  * MetaSeoSitemap constructor.
51
  */
52
  public function __construct()
53
+ {
54
+ $this->getSitemapSettings();
55
+ add_action('admin_init', array($this, 'settingsSitemap'));
56
+ add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts'));
57
+ add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'));
58
+ add_filter('the_content', array($this, 'sitemapInContent'));
59
+ add_shortcode('wpms_html_sitemap', array($this, 'sitemapShortcode'));
60
+ add_action('wp_ajax_wpms_regenerate_sitemaps', array($this, 'regenerateSitemaps'));
61
+ add_action('wp_ajax_wpms_save_sitemap_settings', array($this, 'saveSitemapSettings'));
62
+ }
63
+
64
+ /**
65
+ * Get sitemap settings
66
+ *
67
+ * @return void
68
+ */
69
+ public function getSitemapSettings()
70
  {
71
  $this->settings_sitemap = array(
72
+ 'wpms_sitemap_add' => 0,
73
+ 'wpms_sitemap_root' => 0,
74
+ 'wpms_sitemap_author' => 0,
75
+ 'wpms_sitemap_taxonomies' => array(),
76
+ 'wpms_category_link' => array(),
77
+ 'wpms_html_sitemap_page' => 0,
78
+ 'wpms_html_sitemap_column' => 1,
79
+ 'wpms_html_sitemap_theme' => 'default',
80
+ 'wpms_html_sitemap_position' => 'after',
81
+ 'wpms_display_column_menus' => array(0),
82
+ 'wpms_display_column_posts' => 1,
83
+ 'wpms_display_column_pages' => 1,
84
+ 'wpms_display_order_menus' => 1,
85
+ 'wpms_display_order_posts' => 2,
86
+ 'wpms_display_order_pages' => 3,
87
+ 'wpms_display_order_urls' => 4,
88
+ 'wpms_public_name_pages' => '',
89
+ 'wpms_public_name_posts' => '',
90
+ 'wpms_sitemap_posts' => array(),
91
+ 'wpms_sitemap_pages' => array(),
92
+ 'wpms_sitemap_include_lang' => array()
93
  );
94
 
95
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
96
+ $this->settings_sitemap['wpms_sitemap_customUrl'] = array();
97
  $this->settings_sitemap['wpms_display_column_customUrl'] = 1;
98
+ $this->settings_sitemap['wpms_public_name_customUrl'] = '';
99
+ $custom_post_types = get_post_types(
100
  array(
101
+ 'public' => true,
102
  'exclude_from_search' => false,
103
+ '_builtin' => false
104
  )
105
  );
106
  if (!empty($custom_post_types)) {
107
  foreach ($custom_post_types as $post_type => $label) {
108
  $this->settings_sitemap['wpms_display_column_' . $post_type] = 1;
109
+ $this->settings_sitemap['wpms_public_name_' . $post_type] = '';
110
+ $this->settings_sitemap['wpms_sitemap_' . $post_type] = array();
111
  }
112
  }
113
  }
114
 
115
  $settings = get_option('_metaseo_settings_sitemap');
116
+ if ((isset($settings['wpms_sitemap_pages']) && is_object($settings['wpms_sitemap_pages'])) || (isset($settings['wpms_sitemap_posts']) && is_object($settings['wpms_sitemap_posts']))
117
+ || (isset($settings['wpms_sitemap_menus']) && is_object($settings['wpms_sitemap_menus']))) {
118
  $settings_array = json_decode(json_encode($settings), true);
119
  update_option('_metaseo_settings_sitemap', $settings_array);
120
  }
123
  if (is_array($settings)) {
124
  $this->settings_sitemap = array_merge($this->settings_sitemap, $settings);
125
  }
 
 
 
 
 
 
 
 
126
  }
127
 
128
  /**
129
+ * Load metaseo script and style front-end
130
+ *
131
+ * @return void
132
  */
133
  public function enqueueScripts()
134
  {
137
  return;
138
  }
139
 
140
+ if (!empty($this->settings_sitemap) && (int) $this->settings_sitemap['wpms_html_sitemap_page'] !== (int) $post->ID) {
141
  return;
142
  }
143
 
170
 
171
  /**
172
  * Localize a script
173
+ *
174
  * @return array
175
  */
176
  public function localizeScript()
177
  {
178
  $custom_post_types = get_post_types(
179
  array(
180
+ 'public' => true,
181
  'exclude_from_search' => false,
182
+ '_builtin' => false
183
  )
184
  );
185
+ $arrays = array(
186
  'wpms_display_column_menus' => $this->settings_sitemap['wpms_display_column_menus'],
187
+ 'post_type' => $custom_post_types
188
  );
189
  return $arrays;
190
  }
191
 
192
  /**
193
+ * Load metaseo script and style back-end
194
+ *
195
+ * @return void
196
  */
197
  public function adminEnqueueScripts()
198
  {
199
  global $current_screen;
200
+ if (!empty($current_screen) && $current_screen->base !== 'wp-meta-seo_page_metaseo_google_sitemap') {
201
  return;
202
  }
203
 
204
  $custom_post_types = get_post_types(
205
  array(
206
+ 'public' => true,
207
  'exclude_from_search' => false,
208
+ '_builtin' => false
209
  )
210
  );
211
 
259
 
260
  /**
261
  * Add a new field to a section of a sitemap settings page
262
+ *
263
+ * @return void
264
  */
265
  public function settingsSitemap()
266
  {
268
  add_settings_section('metaseo_sitemap', '', array($this, 'showSettingSitemap'), 'metaseo_settings_sitemap');
269
  add_settings_field(
270
  'wpms_sitemap_link',
271
+ esc_html__('XML sitemap link', 'wp-meta-seo'),
272
  array($this, 'sitemapLink'),
273
  'metaseo_settings_sitemap',
274
  'metaseo_sitemap',
275
  array(
276
+ 'label_for' => esc_html__('Link to the xml file generated. It’s highly recommended
277
  to add this sitemap link to your Google search console', 'wp-meta-seo')
278
  )
279
  );
280
  add_settings_field(
281
  'wpms_html_sitemap_page',
282
+ esc_html__('HTML Sitemap page', 'wp-meta-seo'),
283
  array($this, 'sitemapPage'),
284
  'metaseo_settings_sitemap',
285
  'metaseo_sitemap',
286
  array(
287
+ 'label_for' => esc_html__('A page is automatically generated to display your HTML sitemap.
288
  You can also use any of the existing pages', 'wp-meta-seo')
289
  )
290
  );
291
  add_settings_field(
292
  'wpms_sitemap_taxonomies',
293
+ esc_html__('Additional content', 'wp-meta-seo'),
294
  array($this, 'sitemapTaxonomies'),
295
  'metaseo_settings_sitemap',
296
  'metaseo_sitemap',
297
  array(
298
+ 'label_for' => esc_html__('The additional WordPress taxonomies that you want
299
  to load in your sitemaps', 'wp-meta-seo')
300
  )
301
  );
302
  add_settings_field(
303
  'wpms_sitemap_author',
304
+ esc_html__('Display author posts', 'wp-meta-seo'),
305
  array($this, 'sitemapAuthor'),
306
  'metaseo_settings_sitemap',
307
  'metaseo_sitemap',
308
  array(
309
+ 'label_for' => esc_html__('You can include a list of posts by author in your sitemaps', 'wp-meta-seo')
310
  )
311
  );
312
  add_settings_field(
313
  'wpms_html_sitemap_column',
314
+ esc_html__('HTML Sitemap display', 'wp-meta-seo'),
315
  array($this, 'sitemapColumn'),
316
  'metaseo_settings_sitemap',
317
  'metaseo_sitemap',
318
  array(
319
+ 'label_for' => esc_html__('Number of columns of the HTML sitemap.
320
  You can also setup where your content will be displayed using the tabs above', 'wp-meta-seo')
321
  )
322
  );
323
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
324
  add_settings_field(
325
  'wpms_html_sitemap_theme',
326
+ esc_html__('HTML Sitemap theme', 'wp-meta-seo'),
327
  array($this, 'sitemapTheme'),
328
  'metaseo_settings_sitemap',
329
  'metaseo_sitemap'
331
  }
332
  add_settings_field(
333
  'wpms_html_sitemap_position',
334
+ esc_html__('HTML Sitemap Position', 'wp-meta-seo'),
335
  array($this, 'sitemapPosition'),
336
  'metaseo_settings_sitemap',
337
  'metaseo_sitemap'
338
  );
339
  add_settings_field(
340
  'wpms_sitemap_add',
341
+ esc_html__('Sitemap and robot.txt', 'wp-meta-seo'),
342
  array($this, 'settingRobotFile'),
343
  'metaseo_settings_sitemap',
344
  'metaseo_sitemap',
345
  array(
346
+ 'label_for' => esc_html__('You can include a link to your xml sitemap in the robot.txt.
347
  It helps some search engines to find it', 'wp-meta-seo')
348
  )
349
  );
350
  add_settings_field(
351
  'wpms_sitemap_root',
352
+ esc_html__('Sitemap root', 'wp-meta-seo'),
353
  array($this, 'sitemapRoot'),
354
  'metaseo_settings_sitemap',
355
  'metaseo_sitemap',
356
  array(
357
+ 'label_for' => esc_html__('Add a copy of the lastest version of your .xml sitemap at the root
358
  of your WordPress install named sitemap.xml. Some SEO tools and search engines bots
359
  are searching for it.', 'wp-meta-seo')
360
  )
362
 
363
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
364
  if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
365
+ $label = esc_html__('WPML language', 'wp-meta-seo');
366
  add_settings_field(
367
  'wpms_sitemap_include_lang',
368
  $label,
370
  'metaseo_settings_sitemap',
371
  'metaseo_sitemap',
372
  array(
373
+ 'label_for' => esc_html__('Select a language to include in your sitemap,
374
  it will add the relative menu, post, page… content automatically', 'wp-meta-seo')
375
  )
376
  );
377
  } elseif (is_plugin_active('polylang/polylang.php')) {
378
+ $label = esc_html__('Polylang language', 'wp-meta-seo');
379
  add_settings_field(
380
  'wpms_sitemap_include_lang',
381
  $label,
383
  'metaseo_settings_sitemap',
384
  'metaseo_sitemap',
385
  array(
386
+ 'label_for' => esc_html__('Select a language to include in your sitemap,
387
  it will add the relative menu, post, page… content automatically', 'wp-meta-seo')
388
  )
389
  );
390
  }
391
  }
392
 
 
393
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
394
  add_settings_field(
395
  'wpms_sitemap_link_check',
396
+ esc_html__('Sitemap link check', 'wp-meta-seo'),
397
  array($this, 'checkLink'),
398
  'metaseo_settings_sitemap',
399
  'metaseo_sitemap',
400
  array(
401
+ 'label_for' => esc_html__('A page is automatically generated to display your
402
  HTML sitemap. You can also use any of the existing pages.', 'wp-meta-seo')
403
  )
404
  );
405
  }
406
  }
407
 
408
+ /**
409
+ * Show sitemap setting header
410
+ *
411
+ * @return void
412
+ */
413
  public function showSettingSitemap()
414
  {
415
  }
416
 
417
  /**
418
  * Display field sitemap link
419
+ *
420
+ * @return void
421
  */
422
  public function sitemapLink()
423
  {
425
  type="hidden" value="1">';
426
  if (is_multisite()) {
427
  $home_url = preg_replace(
428
+ '/[^a-zA-ZА-Яа-я0-9\s]/',
429
+ '_',
430
  str_replace('http://', '', str_replace('https://', '', ABSPATH))
431
  );
432
+ $value = trim(ABSPATH, '/') . '/wpms-sitemap_' . $home_url . '.xml';
433
+ $link = get_option('siteurl') . '/wpms-sitemap_' . $home_url . '.xml';
434
  } else {
435
  $value = trim(ABSPATH, '/') . '/' . $this->wpms_sitemap_name;
436
+ $link = get_option('siteurl') . '/' . $this->wpms_sitemap_name;
437
  }
438
  echo '<input readonly id="wpms_sitemap_link" name="_metaseo_settings_sitemap[wpms_sitemap_link]"
439
  type="text" value="' . esc_attr($value) . '" size="50"/>';
440
+ echo '<a class="button" href="' . esc_url($link) . '" target="_blank">' . esc_html__('Open', 'wp-meta-seo') . '</a>';
441
  }
442
 
443
  /**
444
  * Display field add sitemap robots
445
+ *
446
+ * @return void
447
  */
448
  public function settingRobotFile()
449
  {
450
+ if (is_multisite()) { ?>
451
+ <div class="pure-checkbox">
452
+ <input id="wpms_sitemap_add" disabled="disabled" type="checkbox"
453
+ name="_metaseo_settings_sitemap[wpms_sitemap_add]"
454
+ value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
455
+ <label for="wpms_sitemap_add"><?php esc_html_e('add sitemap file path in robots.txt', 'wp-meta-seo'); ?></label>
456
+ </div>
457
+ <p style="color:red">
458
+ <?php esc_html_e('Since you are using multisite,
459
+ the plugin does not allow to add a sitemap to robots.txt', 'wp-meta-seo'); ?>
460
+ </p>
 
461
  <?php } else { ?>
462
+ <!-- for robots.txt we need to use site_url instead home_url ! -->
463
+ <div class="pure-checkbox">
464
+ <input id="wpms_sitemap_add" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_add]"
465
+ value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
466
+ <label for="wpms_sitemap_add"><?php esc_html_e('add sitemap link in the', 'wp-meta-seo'); ?> <a
467
+ href="<?php echo esc_url(site_url('/')); ?>robots.txt" target="_new">robots.txt</a></label>
468
+ </div>
469
  <?php }
470
  }
471
 
472
  /**
473
  * Display field sitemap lang
474
+ *
475
+ * @return void
476
  */
477
  public function sitemapIncludeLanguages()
478
  {
479
+ $lang = $this->settings_sitemap['wpms_sitemap_include_lang'];
480
  $sl_lang = apply_filters('wpms_get_languagesList', '', $lang, 'multiple');
481
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::listLanguageSelect
482
  echo $sl_lang;
483
  }
484
 
485
  /**
486
  * Display field sitemap root
487
+ *
488
+ * @return void
489
  */
490
  public function sitemapRoot()
491
  {
493
  <div class="pure-checkbox">
494
  <input id="wpms_sitemap_root" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_root]"
495
  value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_root']); ?>>
496
+ <label for="wpms_sitemap_root"><?php esc_html_e('Add a sitemap.xml copy @ the site root', 'wp-meta-seo'); ?></label>
497
  </div>
498
  <?php
499
  }
500
 
501
  /**
502
  * Display field sitemap link check
503
+ *
504
+ * @return void
505
  */
506
  public function checkLink()
507
  {
508
  ?>
509
+ <input type="button" class="button wpms_run_linkcheck"
510
+ value="<?php esc_attr_e('Run a link check', 'wp-meta-seo') ?>">
511
  <span class="spinner spinner_run_linkchecker"></span>
512
  <?php
513
  }
514
 
515
  /**
516
  * Display field sitemap author
517
+ *
518
+ * @return void
519
  */
520
  public function sitemapAuthor()
521
  {
523
  <div class="pure-checkbox">
524
  <input id="wpms_sitemap_author" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_author]"
525
  value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_author']); ?>>
526
+ <label for="wpms_sitemap_author"><?php esc_html_e('Display author post archive', 'wp-meta-seo'); ?></label>
527
  </div>
528
  <?php
529
  }
530
 
531
  /**
532
  * Display field sitemap taxonomies
533
+ *
534
+ * @return void
535
  */
536
  public function sitemapTaxonomies()
537
  {
543
  ?>
544
  <div class="pure-checkbox">
545
  <?php if (in_array($key, $this->settings_sitemap['wpms_sitemap_taxonomies'])) : ?>
546
+ <input title class="wpms_sitemap_taxonomies"
547
+ id="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>"
548
  type="checkbox"
549
  name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]"
550
+ value="<?php echo esc_attr($key) ?>" checked>
551
  <?php else : ?>
552
+ <input title class="wpms_sitemap_taxonomies"
553
+ id="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>"
554
  type="checkbox"
555
  name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]"
556
+ value="<?php echo esc_attr($key) ?>">
557
  <?php endif; ?>
558
+ <label for="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>"><?php echo esc_html($value) ?></label>
559
  </div>
560
  <?php
561
  }
563
 
564
  /**
565
  * Display field sitemap list page
566
+ *
567
+ * @return void
568
  */
569
  public function sitemapPage()
570
  {
571
  global $wpdb;
572
+ $pages = get_pages();
573
+ $sitemap_page = $wpdb->get_row($wpdb->prepare(
574
+ 'SELECT * FROM ' . $wpdb->prefix . 'posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s',
575
  array(
576
+ 'WPMS HTML Sitemap',
577
+ 'metaseo_html_sitemap',
578
+ 'page'
579
  )
580
+ ));
 
581
 
582
  if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) {
583
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
585
  ?>
586
  <label>
587
  <select id="wpms_html_sitemap_page" name="_metaseo_settings_sitemap[wpms_html_sitemap_page]">
588
+ <option value="0"><?php esc_html_e('- Choose Your Sitemap Page -', 'wp-meta-seo') ?></option>
589
  <?php
590
  foreach ($pages as $page) {
591
+ if ((int) $this->settings_sitemap['wpms_html_sitemap_page'] === (int) $page->ID) {
592
+ echo '<option selected value="' . esc_attr($page->ID) . '">' . esc_html($page->post_title) . '</option>';
593
  } else {
594
+ echo '<option value="' . esc_attr($page->ID) . '">' . esc_html($page->post_title) . '</option>';
595
  }
596
  }
597
  ?>
599
  </label>
600
  <?php
601
  if (!empty($this->settings_sitemap['wpms_html_sitemap_page'])) {
602
+ echo '<a class="button" href="' . esc_url(get_post_permalink($this->settings_sitemap['wpms_html_sitemap_page'])) . '"
603
+ target="_blank">' . esc_html__('Open', 'wp-meta-seo') . '</a>';
604
  }
605
  }
606
 
607
  /**
608
  * Display field sitemap column
609
+ *
610
+ * @return void
611
  */
612
  public function sitemapColumn()
613
  {
615
  <label>
616
  <select id="wpms_html_sitemap_column" name="_metaseo_settings_sitemap[wpms_html_sitemap_column]">
617
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 1) ?>
618
+ value="1"><?php esc_html_e('1 column', 'wp-meta-seo') ?></option>
619
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 2) ?>
620
+ value="2"><?php esc_html_e('2 column', 'wp-meta-seo') ?></option>
621
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 3) ?>
622
+ value="3"><?php esc_html_e('3 column', 'wp-meta-seo') ?></option>
623
  </select>
624
  </label>
625
  <?php
627
 
628
  /**
629
  * Display field sitemap position
630
+ *
631
+ * @return void
632
  */
633
  public function sitemapTheme()
634
  {
636
  <label>
637
  <select id="wpms_html_sitemap_theme" name="_metaseo_settings_sitemap[wpms_html_sitemap_theme]">
638
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'default') ?>
639
+ value="default"><?php esc_html_e('Simple list', 'wp-meta-seo') ?></option>
640
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'accordions') ?>
641
+ value="accordions"><?php esc_html_e('List with accordions', 'wp-meta-seo') ?></option>
642
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'tab') ?>
643
+ value="tab"><?php esc_html_e('Tab layout', 'wp-meta-seo') ?></option>
644
  </select>
645
  </label>
646
  <?php
648
 
649
  /**
650
  * Display field sitemap position
651
+ *
652
+ * @return void
653
  */
654
  public function sitemapPosition()
655
  {
657
  <label>
658
  <select id="wpms_html_sitemap_position" name="_metaseo_settings_sitemap[wpms_html_sitemap_position]">
659
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'replace') ?>
660
+ value="replace"><?php esc_html_e('Replace the Page Content', 'wp-meta-seo') ?></option>
661
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'before') ?>
662
+ value="before"><?php esc_html_e('Before Page Content', 'wp-meta-seo') ?></option>
663
  <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'after') ?>
664
+ value="after"><?php esc_html_e('After Page Content', 'wp-meta-seo') ?></option>
665
  </select>
666
  </label>
667
  <?php
669
 
670
  /**
671
  * Get info of sitemap file xml
672
+ *
673
  * @return array
674
  */
675
  public function getPathSitemapFile()
676
  {
677
  if (is_multisite()) {
678
  $home_url = preg_replace(
679
+ '/[^a-zA-ZА-Яа-я0-9\s]/',
680
+ '_',
681
  str_replace('http://', '', str_replace('https://', '', site_url()))
682
  );
683
  $xml_file = 'wpms-sitemap_' . $home_url . '.xml';
689
  }
690
 
691
  /**
692
+ * Create sitemap
693
+ *
694
+ * @param string $sitemap_xml_name Sitemap file name
695
+ *
696
+ * @return void
697
  */
698
  public function createSitemap($sitemap_xml_name)
699
  {
704
  $taxonomies[] = $val;
705
  }
706
 
707
+ $xml = new DomDocument('1.0', 'utf-8');
708
  $xml_stylesheet_path = content_url();
709
  if (defined('WP_PLUGIN_DIR')) {
710
  $xml_stylesheet_path .= '/' . basename(WP_PLUGIN_DIR) . '/wp-meta-seo/wpms-sitemap.xsl';
712
  $xml_stylesheet_path .= '/plugins/wp-meta-seo/sitemap.xsl';
713
  }
714
 
715
+ $xslt = $xml->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $xml_stylesheet_path . '"');
716
  $xml->appendChild($xslt);
717
  $gglstmp_urlset = $xml->appendChild(
718
  $xml->createElementNS(
723
 
724
  /* add home page */
725
  $list_links[] = home_url('/');
726
+ $url = $gglstmp_urlset->appendChild($xml->createElement('url'));
727
+ $loc = $url->appendChild($xml->createElement('loc'));
728
  $loc->appendChild($xml->createTextNode(home_url('/')));
729
  $lastmod = $url->appendChild($xml->createElement('lastmod'));
730
  $lastmod->appendChild($xml->createTextNode(date('Y-m-d\TH:i:sP', time())));
735
 
736
  // add menus post custom
737
  $menus = $this->getAllMenus();
738
+ $res = $menus['posts_custom'];
739
  if (!empty($res)) {
740
  foreach ($res as $val) {
741
+ $menu_object = $wpdb->get_results($wpdb->prepare(
742
+ 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s AND meta_value=%d',
743
+ array('_menu_item_object_id', $val->ID)
744
+ ));
 
745
  if (!empty($menu_object)) {
746
  foreach ($menu_object as $menu) {
747
+ $id = $menu->post_id;
748
+ $type = get_post_meta($id, '_menu_item_type', true);
749
  $check_type = get_post_meta($id, '_menu_item_object', true);
750
+ $permalink = $this->getPermalinkSitemap($check_type, $val->ID);
751
+ if ($permalink !== '#') {
752
  if (!in_array($permalink, $list_links)) {
753
  $list_links[] = $permalink;
754
+ if ($type !== 'taxonomy') {
755
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
756
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
757
  $loc->appendChild($xml->createTextNode($permalink));
758
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
759
+ $now = $val->post_modified;
760
+ $date = date('Y-m-d\TH:i:sP', strtotime($now));
761
  $lastmod->appendChild($xml->createTextNode($date));
762
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
763
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
805
  $res = $menus['categories'];
806
  if (!empty($res)) {
807
  foreach ($res as $k => $val) {
808
+ $menu_object = $wpdb->get_results($wpdb->prepare(
809
+ 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s AND meta_value=%d',
810
  array(
811
+ '_menu_item_object_id',
812
  $val
813
  )
814
+ ));
 
815
  if (!empty($menu_object)) {
816
  foreach ($menu_object as $menu) {
817
+ $id = $menu->post_id;
818
+ $type = get_post_meta($id, '_menu_item_type', true);
819
  $check_type = get_post_meta($id, '_menu_item_object', true);
820
+ $permalink = get_term_link((int) $val, $check_type);
821
  if (empty($permalink)) {
822
  $permalink = get_permalink($id);
823
  }
824
 
825
  if (!in_array($permalink, $list_links)) {
826
  $list_links[] = $permalink;
827
+ if ($type === 'taxonomy') {
828
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
829
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
830
  $loc->appendChild($xml->createTextNode($permalink));
831
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
832
+ $ps = get_post($id);
833
 
834
  if (!empty($ps)) {
835
+ $now = $ps->post_modified;
836
  $date = date('Y-m-d\TH:i:sP', strtotime($now));
837
  $lastmod->appendChild($xml->createTextNode($date));
838
  }
876
  $permalink = get_permalink($val->ID);
877
  if (!in_array($permalink, $list_links)) {
878
  $list_links[] = $permalink;
879
+ $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
880
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
881
  $loc->appendChild($xml->createTextNode($permalink));
882
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
883
+ $now = $val->post_modified;
884
+ $date = date('Y-m-d\TH:i:sP', strtotime($now));
885
  $lastmod->appendChild($xml->createTextNode($date));
886
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
887
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
917
  // add custom post type
918
  $custom_post_types = get_post_types(
919
  array(
920
+ 'public' => true,
921
  'exclude_from_search' => false,
922
+ '_builtin' => false
923
  )
924
  );
925
  if (!empty($custom_post_types)) {
926
  foreach ($custom_post_types as $pt => $label) {
927
+ $ids = array(0);
928
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
929
  if (!empty($settings_sitemap['wpms_sitemap_' . $pt])) {
930
+ foreach ((array) $settings_sitemap['wpms_sitemap_' . $pt] as $k => $v) {
931
  if (!empty($v['post_id'])) {
932
+ $ids[] = (int) $v['post_id'];
933
  }
934
  }
935
  }
936
 
937
+ $posts = $wpdb->get_results($wpdb->prepare('SELECT ID, post_modified FROM ' . $wpdb->posts . ' WHERE post_status = %s AND post_type = %s AND ID IN (' . implode(',', esc_sql($ids)) . ') ORDER BY post_date DESC', array(
938
+ 'publish',
939
+ $pt
940
+ )));
 
 
 
 
941
  if (!empty($posts)) {
942
  foreach ($posts as $val) {
943
  $permalink = get_permalink($val->ID);
944
  if (!in_array($permalink, $list_links)) {
945
  $list_links[] = $permalink;
946
+ $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
947
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
948
  $loc->appendChild($xml->createTextNode($permalink));
949
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
950
+ $now = $val->post_modified;
951
+ $date = date('Y-m-d\TH:i:sP', strtotime($now));
952
  $lastmod->appendChild($xml->createTextNode($date));
953
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
954
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
989
  // add custom Url
990
  $listUrls = get_option('wpms_customUrls_list');
991
  $settings = get_option('_metaseo_settings_sitemap');
992
+ if (!empty($settings['wpms_sitemap_customUrl']) && $settings['wpms_sitemap_customUrl'] !== '{}') {
993
  foreach ($settings['wpms_sitemap_customUrl'] as $key => $customUrl) {
994
  if (!empty($listUrls[$key])) {
995
  if (!in_array($listUrls[$key]['link'], $list_links)) {
996
  $list_links[] = $listUrls[$key]['link'];
997
+ $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
998
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
999
 
1000
  $loc->appendChild($xml->createTextNode($listUrls[$key]['link']));
1001
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
1002
+ $date = date('Y-m-d\TH:i:sP', $key);
1003
  $lastmod->appendChild($xml->createTextNode($date));
1004
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
1005
 
1032
  $permalink = get_permalink($val->ID);
1033
  if (!in_array($permalink, $list_links)) {
1034
  $list_links[] = $permalink;
1035
+ $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
1036
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
1037
 
1038
  $loc->appendChild($xml->createTextNode($permalink));
1039
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
1040
+ $now = $val->post_modified;
1041
+ $date = date('Y-m-d\TH:i:sP', strtotime($now));
1042
  $lastmod->appendChild($xml->createTextNode($date));
1043
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
1044
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1074
  $terms = get_terms($value, 'hide_empty=1');
1075
  if (!empty($terms) && !is_wp_error($terms)) {
1076
  foreach ($terms as $term_value) {
1077
+ $permalink = get_term_link((int) $term_value->term_id, $value);
1078
  if (!in_array($permalink, $list_links)) {
1079
  $list_links[] = $permalink;
1080
+ $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
1081
+ $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
1082
 
1083
  $loc->appendChild($xml->createTextNode($permalink));
1084
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
1085
 
1086
+ $now = $wpdb->get_var(
1087
+ $wpdb->prepare('SELECT post_modified FROM ' . $wpdb->posts . ', ' . $wpdb->term_relationships . '
1088
+ WHERE post_status = %s AND term_taxonomy_id = %d
1089
+ AND $wpdb->posts.ID = $wpdb->term_relationships.object_id ORDER BY post_modified DESC', array(
1090
+ 'publish',
1091
+ $term_value->term_taxonomy_id
1092
+ ))
1093
  );
1094
  $date = date('Y-m-d\TH:i:sP', strtotime($now));
1095
  $lastmod->appendChild($xml->createTextNode($date));
1106
  $xml->formatOutput = true;
1107
 
1108
  if (!is_writable(ABSPATH)) {
1109
+ chmod(ABSPATH, 0755);
1110
  }
1111
 
1112
  if (is_multisite()) {
1113
  $home_url = preg_replace(
1114
+ '/[^a-zA-ZА-Яа-я0-9\s]/',
1115
+ '_',
1116
  str_replace('http://', '', str_replace('https://', '', site_url()))
1117
  );
1118
  $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
1123
  }
1124
 
1125
  /**
1126
+ * Create xml language
1127
+ *
1128
+ * @param object $xml XML
1129
+ * @param integer $id Element Id
1130
+ * @param string $el_type Element type
1131
+ * @param object $loc Node Info
1132
+ *
1133
+ * @return void
1134
  */
1135
  public function createXmlLang($xml, $id, $el_type, $loc)
1136
  {
1162
  } elseif (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
1163
  if (!empty($this->settings_sitemap['wpms_sitemap_include_lang'])) {
1164
  global $polylang;
1165
+ $model = $polylang->filters->links_model->model;
1166
  $model_post = $polylang->filters->links_model->model->post;
1167
  foreach ($model->get_languages_list() as $language) {
1168
  $value = $model_post->get_translation($id, $language);
1170
  $lang = pll_get_post_language($value);
1171
  if (isset($lang) && in_array($lang, $this->settings_sitemap['wpms_sitemap_include_lang'])) {
1172
  $permalink = get_permalink($value);
1173
+ $node = $xml->appendChild(
1174
  $xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link')
1175
  );
1176
  $node->setAttribute('rel', 'alternate');
1186
 
1187
  /**
1188
  * Retrieves the full permalink for the current post or post ID
1189
+ *
1190
+ * @param string $type Element type
1191
+ * @param integer $id Element id
1192
+ *
1193
  * @return false|mixed|string
1194
  */
1195
  public function getPermalinkSitemap($type, $id)
1196
  {
1197
+ if (isset($type) && $type === 'custom') {
1198
  $permalink = get_post_meta($id, '_menu_item_url', true);
1199
+ } elseif ($type === 'taxonomy') {
1200
  $permalink = get_category_link($id);
1201
  } else {
1202
  $permalink = get_permalink($id);
1205
  }
1206
 
1207
  /**
1208
+ * Update sitemap setting
1209
+ *
1210
+ * @return void
1211
  */
1212
  public function sitemapInfos()
1213
  {
1214
+ $settings = get_option('_metaseo_settings_sitemap');
1215
  $info_file = $this->getPathSitemapFile();
1216
+ $xml_url = site_url('/') . $info_file['name'];
1217
  if (file_exists($info_file['path'])) {
1218
+ $settings['sitemap'] = array(
1219
+ 'file' => $info_file['name'],
1220
+ 'path' => $info_file['path'],
1221
+ 'loc' => $xml_url,
1222
  'lastmod' => date('Y-m-d\TH:i:sP', filemtime($info_file['path']))
1223
  );
1224
+ update_option('_metaseo_settings_sitemap', $settings);
1225
  }
1226
  }
1227
 
1228
  /**
1229
+ * Display sitemap posts by column in front-end
1230
+ *
1231
  * @return string
1232
  */
1233
  public function displayPosts()
1234
  {
1235
+ $html = '';
1236
  $postTitle = get_post_type_object('post');
1237
  $postTitle = $postTitle->label;
1238
 
1239
+ if (get_option('show_on_front') === 'page') {
1240
+ $postsURL = get_permalink(get_option('page_for_posts'));
1241
  $postTitle = get_the_title(get_option('page_for_posts'));
1242
  } else {
1243
  $postsURL = get_bloginfo('url');
1257
  //Categories
1258
  $ids = array(0);
1259
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
1260
+ foreach ((array) $this->settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
1261
  if (!empty($v['post_id'])) {
1262
  $ids[] = $k;
1263
  }
1267
  $cats = get_categories();
1268
  foreach ($cats as $cat) {
1269
  if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
1270
+ $cat_link = '<a href="' . esc_url(get_term_link($cat)) . '">' . esc_html($cat->cat_name) . '</a>';
1271
  } else {
1272
  $cat_link = $cat->cat_name;
1273
  }
1274
 
1275
+ $html .= '<li class="wpms_li_cate"><div class="cat_name">' . $cat_link . '</div>';
1276
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
1277
+ $html .= '<ul>';
1278
+ query_posts(array('post__in' => $ids, 'posts_per_page' => - 1, 'cat' => $cat->cat_ID));
1279
  while (have_posts()) {
1280
  the_post();
1281
  if ((get_post_meta(get_the_ID(), '_yoast_wpseo_meta-robots-noindex', true) === '1'
1282
+ && get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) !== 'always')
1283
  || (get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) === 'never')
1284
  || (get_post_meta(get_the_ID(), '_yoast_wpms_redirect', true) !== '')) {
1285
  continue;
1287
 
1288
  $category = get_the_category();
1289
  // Only display a post link once, even if it's in multiple categories
1290
+ if ((int) $category[0]->cat_ID === (int) $cat->cat_ID) {
1291
  $html .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
1292
  }
1293
  }
1294
  wp_reset_query();
1295
+ $html .= '</ul>';
1296
  }
1297
+ $html .= '</li>';
1298
  }
1299
  $html .= '</ul></div>';
1300
  $html .= '<div class="holder holder_sitemaps_posts"></div>';
1303
  }
1304
 
1305
  /**
1306
+ * Display sitemap pages by column in front-end
1307
+ *
1308
  * @return string
1309
  */
1310
  public function displayPages()
1316
  if (!empty($this->settings_sitemap['wpms_public_name_pages'])) {
1317
  $pageTitle = $this->settings_sitemap['wpms_public_name_pages'];
1318
  }
1319
+ $html .= '<div id="sitemap_pages" class="wpms_sitemap_pages"><h4>' . $pageTitle . '</h4>
1320
  <ul>';
1321
+ $pageInc = '';
1322
  $getPages = $this->getPagesSitemap();
1323
  foreach ($getPages as $page) {
1324
  if (isset($this->settings_sitemap['wpms_html_sitemap_page'])
1325
+ && (int) $page->ID !== (int) $this->settings_sitemap['wpms_html_sitemap_page']) {
1326
  if ((get_post_meta($page->ID, '_yoast_wpseo_meta-robots-noindex', true) === '1'
1327
+ && get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) !== 'always')
1328
  || (get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) === 'never')
1329
  || (get_post_meta($page->ID, '_yoast_wpms_redirect', true) !== '')) {
1330
  continue;
1331
  }
1332
+ if ($pageInc === '') {
1333
  $pageInc = $page->ID;
1334
  continue;
1335
  }
1337
  }
1338
  }
1339
 
1340
+ if ($pageInc !== '') {
1341
  $html .= wp_list_pages(
1342
  array(
1343
+ 'include' => $pageInc,
1344
+ 'title_li' => '',
1345
  'sort_column' => 'post_title',
1346
+ 'sort_order' => 'ASC',
1347
+ 'echo' => false
1348
  )
1349
  );
1350
  }
1356
  }
1357
 
1358
  /**
1359
+ * Display sitemap customUrl by column in front-end
1360
+ *
1361
  * @return string
1362
  */
1363
  public function displayCustomUrl()
1364
  {
1365
+ $html = '';
1366
  $lists = $this->settings_sitemap['wpms_sitemap_customUrl'];
1367
  $links = get_option('wpms_customUrls_list');
1368
  if (!empty($lists)) {
1370
  if (!empty($this->settings_sitemap['wpms_public_name_customUrl'])) {
1371
  $publictitle = $this->settings_sitemap['wpms_public_name_customUrl'];
1372
  } else {
1373
+ $publictitle = esc_html__('Custom Url', 'wp-meta-seo');
1374
  }
1375
+
1376
+ if (!empty($lists) && $lists !== '{}') {
1377
+ $html .= '<h4>' . $publictitle . '</h4>';
1378
+ $html .= '<ul>';
1379
+ foreach ($lists as $key => $list) {
1380
+ if (!empty($links[$key])) {
1381
+ $html .= '<li>';
1382
+ $html .= '<a href="' . esc_url($links[$key]['link']) . '">' . esc_html($links[$key]['title']) . '</a>';
1383
+ $html .= '</li>';
1384
+ }
1385
  }
1386
+
1387
+ $html .= '</ul>';
1388
  }
1389
+
1390
+ $html .= '</div>';
1391
  $html .= '<div class="holder holder_sitemaps_customUrl"></div>';
1392
  }
1393
 
1395
  }
1396
 
1397
  /**
1398
+ * Render sitemap theme default
1399
+ *
1400
  * @return string
1401
  */
1402
  public function sitemapThemeDefault()
1403
  {
1404
  $html = '';
1405
  $html .= '<div id="wpms_sitemap"
1406
+ class="' . esc_attr('theme_default columns_' . $this->settings_sitemap['wpms_html_sitemap_column']) . '">';
1407
+ $arrs = array('displayPosts' => 'wpms_display_column_posts', 'displayPages' => 'wpms_display_column_pages');
1408
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1409
+ $arrs['displayCustomUrl'] = 'wpms_display_column_customUrl';
1410
  }
1411
  $checkColumn = array();
1412
+ for ($i = 1; $i <= (int) $this->settings_sitemap['wpms_html_sitemap_column']; $i ++) {
1413
+ $html .= '<div class="' . esc_attr('wpms_column wpms_column_' . $i) . '" style="width:33%;float:left;">';
1414
+ if ((int) $i === 1) {
1415
  // Authors
1416
+ if ((int) $this->settings_sitemap['wpms_sitemap_author'] === 1) {
1417
+ $html .= '<div id="sitemap_authors"><h3>' . esc_html__('Authors', 'wp-meta-seo') . '</h3>
1418
  <ul>';
1419
 
1420
  $authEx = implode(
1421
+ ', ',
1422
  get_users('orderby=nicename&meta_key=wpms_excludeauthorsitemap&meta_value=on')
1423
  );
1424
+ $html .= wp_list_authors(array('exclude_admin' => false, 'exclude' => $authEx, 'echo' => false));
1425
+ $html .= '</ul></div>';
1426
  }
1427
  }
1428
 
1432
  }
1433
 
1434
  if (!in_array($ar, $checkColumn)) {
1435
+ if ((int) $i === (int) $this->settings_sitemap[$arr]) {
1436
  $checkColumn[] = $ar;
1437
+ $output = $this->{$ar}();
1438
+ $html .= $output;
1439
  }
1440
  }
1441
  }
1443
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1444
  $custom_post_types = get_post_types(
1445
  array(
1446
+ 'public' => true,
1447
  'exclude_from_search' => false,
1448
+ '_builtin' => false
1449
  )
1450
  );
1451
  if (!empty($custom_post_types)) {
1452
  foreach ($custom_post_types as $post_type => $label) {
1453
  if (!empty($this->settings_sitemap['wpms_display_column_' . $post_type])
1454
+ && (int) $i === (int) $this->settings_sitemap['wpms_display_column_' . $post_type]) {
1455
  //=====================================================================================
1456
  if (isset($this->settings_sitemap['wpms_public_name_' . $post_type])
1457
+ && $this->settings_sitemap['wpms_public_name_' . $post_type] !== '') {
1458
  $postTitle = $this->settings_sitemap['wpms_public_name_' . $post_type];
1459
  } else {
1460
  $postTitle = get_post_type_object($post_type);
1463
 
1464
  global $wpdb;
1465
  $taxonomy_objects = get_object_taxonomies($post_type, 'names');
1466
+ $ids = array(0);
1467
  if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1468
  $html .= '<div id="sitemap_posts" class="wpms_sitemap_posts"><h4>';
1469
+ $html .= esc_html($postTitle);
1470
  $html .= '</h4><ul>';
1471
+ foreach ((array) $this->settings_sitemap['wpms_sitemap_' . $post_type] as $k => $v) {
1472
  if (!empty($v['post_id'])) {
1473
+ $ids[] = (int) $v['post_id'];
1474
  }
1475
  }
1476
  }
1477
+
1478
+ $list_links = array();
1479
+ if (!empty($taxonomy_objects)) {
1480
+ foreach ($taxonomy_objects as $taxo) {
1481
+ $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1482
+ foreach ($categorys as $cat) {
1483
+ $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title
1484
+ FROM ' . $wpdb->posts . ' AS p
1485
+ INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id)
1486
+ INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1487
+ INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id)
1488
+ WHERE p.post_status = %s
1489
+ AND p.post_type = %s
1490
+ AND tt.taxonomy = %s AND t.slug = %s AND ID IN (' . implode(',', esc_sql($ids)) . ')
1491
+ ORDER BY p.post_date DESC', array('publish', $post_type, $taxo, $cat->slug)));
1492
+ if (!empty($results)) {
1493
+ if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
1494
+ $cat_link = '<a href="' . esc_url(get_term_link($cat)) . '">
1495
+ ' . esc_html($cat->cat_name) . '</a>';
1496
+ } else {
1497
+ $cat_link = esc_html($cat->cat_name);
1498
+ }
1499
+ $html .= '<li class="wpms_li_cate wpms_li_cate">';
1500
+ $html .= '<div class="cat_name">' . $cat_link . '</div>';
1501
+
1502
+ if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1503
+ $html .= '<ul>';
1504
+ foreach ($results as $p) {
1505
+ $i = $cat->cat_ID . '-' . $p->ID;
1506
+ if (isset($this->settings_sitemap['wpms_sitemap_' . $post_type][$i])) {
1507
+ $link = get_permalink($p->ID);
1508
+ if (!in_array($link, $list_links)) {
1509
+ $list_links[] = $link;
1510
+ $html .= '<li><a href="' . esc_url($link) . '">' . esc_html($p->post_title) . '</a></li>';
1511
+ }
1512
+ }
1513
  }
1514
+ $html .= '</ul>';
1515
  }
1516
+ $html .= '</li>';
1517
  }
1518
+ }
1519
+ }
1520
+ } else {
1521
+ $results = $wpdb->get_results($wpdb->prepare('SELECT ID, post_title FROM ' . $wpdb->posts . ' WHERE post_status = %s AND post_type = %s AND ID IN (' . implode(',', esc_sql($ids)) . ') ORDER BY post_date DESC', array(
1522
+ 'publish',
1523
+ $post_type
1524
+ )));
1525
+ if (!empty($results)) {
1526
+ if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1527
+ $html .= '<ul>';
1528
+ foreach ($results as $p) {
1529
+ $link = get_permalink($p->ID);
1530
+ if (!in_array($link, $list_links)) {
1531
+ $list_links[] = $link;
1532
+ $html .= '<li><a href="' . esc_url(get_permalink($p->ID)) . '">' . esc_html($p->post_title) . '</a></li>';
1533
+ }
1534
+ }
1535
+ $html .= '</ul>';
1536
  }
1537
  }
1538
  }
1548
  }
1549
  // ====================
1550
 
1551
+ $ids_menu = array(0);
1552
  $check_menu = array();
1553
+ $terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true));
1554
  foreach ($terms as $term) {
1555
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1556
+ $ids_menu = array_merge($ids_menu, $list_submenu_id);
1557
  }
1558
 
1559
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1568
  $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] = 1;
1569
  }
1570
 
1571
+ if ((int) $i === (int) $this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) {
1572
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1573
+ $html .= '<div id="' . esc_attr('sitemap_menus_' . $term->term_id) . '" class="wpms_sitemap_menus">';
1574
+ $viewmenu = $this->viewMenusFrontend($term, $ids_menu);
1575
+ $html .= $viewmenu;
1576
 
1577
  $html .= '</div>';
1578
+ $html .= '<div class="' . esc_attr('holder holder_sitemaps_menus_' . $term->term_id) . '"></div>';
1579
  }
1580
  }
1581
  }
1593
  }
1594
 
1595
  /**
1596
+ * Display html sitemap in front-end
1597
+ *
1598
  * @return array|string
1599
  */
1600
  public function sitemapShortcode()
1609
 
1610
  $custom_post_types = get_post_types(
1611
  array(
1612
+ 'public' => true,
1613
  'exclude_from_search' => false,
1614
+ '_builtin' => false
1615
  )
1616
  );
1617
 
1618
+ if ($theme === 'default') {
1619
+ wp_enqueue_style(
1620
+ 'html-sitemap',
1621
+ plugins_url('css/html_sitemap.css', dirname(__FILE__)),
1622
+ array(),
1623
+ WPMSEO_VERSION
1624
+ );
1625
+
1626
  $html = $this->sitemapThemeDefault();
1627
+ } elseif ($theme === 'tab') {
1628
  wp_enqueue_script(
1629
  'wpms_materialize_js',
1630
  plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)),
1645
  require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php');
1646
 
1647
  // source menu
1648
+ $ids_menu = array(0);
1649
  $check_menu = array();
1650
+ $terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true));
1651
  foreach ($terms as $term) {
1652
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1653
+ $ids_menu = array_merge($ids_menu, $list_submenu_id);
1654
  }
1655
 
1656
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1663
  foreach ($terms as $term) {
1664
  if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
1665
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1666
+ echo '<div id="' . esc_attr('sitemap_menus_' . $term->term_id) . '" class="wpms_sitemap_menus">';
1667
  $viewmenu = $this->viewMenusFrontend($term, $ids_menu);
1668
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method viewMenusFrontend
1669
  echo $viewmenu;
1670
 
1671
  echo '</div>';
1672
+ echo '<div class="' . esc_attr('holder holder_sitemaps_menus_' . $term->term_id) . '"></div>';
1673
  }
1674
  }
1675
  echo '</div>';
1676
  }
1677
  }
1678
  echo '</div>';
1679
+ } elseif ($theme === 'accordions') {
1680
  wp_enqueue_script(
1681
  'wpms_materialize_js',
1682
  plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)),
1710
  = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_urlcustom.php';
1711
  }
1712
 
1713
+ for ($i = 1; $i <= 4; $i ++) {
1714
  foreach ($arrays as $key => $item) {
1715
+ if ((int) $this->settings_sitemap[$key] === (int) $i) {
1716
  require_once($item);
1717
  }
1718
  }
1726
  }
1727
 
1728
  /**
1729
+ * Add wpms_html_sitemap shortcode in content
1730
+ *
1731
+ * @param string $content Sitemap content
1732
+ *
1733
  * @return string
1734
  */
1735
  public function sitemapInContent($content)
1736
  {
1737
  global $wpdb;
1738
+ $sitemap_page = $wpdb->get_row($wpdb->prepare(
1739
+ 'SELECT * FROM ' . $wpdb->prefix . 'posts
1740
+ WHERE post_title = %s AND post_excerpt = %s AND post_type = %s',
1741
  array(
1742
+ 'WPMS HTML Sitemap',
1743
+ 'metaseo_html_sitemap',
1744
+ 'page'
1745
  )
1746
+ ));
 
1747
 
1748
  if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) {
1749
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
1770
  }
1771
 
1772
  /**
1773
+ * Get all menu
1774
+ *
1775
  * @return array
1776
  */
1777
  public function getAllMenus()
1778
  {
1779
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1780
+ $post_types = get_post_types('', 'names');
1781
  unset($post_types['revision']);
1782
  unset($post_types['attachment']);
1783
  $ids_posts_custom = array(0);
1784
+ $ids_categories = array();
1785
 
1786
  if (empty($settings_sitemap['wpms_check_firstsave'])) {
1787
+ $args = array(
1788
+ 'posts_per_page' => - 1,
1789
+ 'post_type' => 'nav_menu_item',
1790
+ 'post_status' => 'publish'
1791
  );
1792
+ $query = new WP_Query($args);
1793
  $posts_menu = $query->get_posts();
1794
  foreach ($posts_menu as $k => $v) {
1795
+ $type = get_post_meta($v->ID, '_menu_item_type', true);
1796
  $post_meta_object_id = get_post_meta($v->ID, '_menu_item_object_id', true);
1797
+ if ($type !== 'taxonomy') {
1798
  $ids_posts_custom[] = $post_meta_object_id;
1799
  } else {
1800
  $ids_categories[] = $post_meta_object_id;
1804
  if (!empty($settings_sitemap['wpms_sitemap_menus'])) {
1805
  foreach ($settings_sitemap['wpms_sitemap_menus'] as $k => $v) {
1806
  if (!empty($v['menu_id'])) {
1807
+ $type = get_post_meta($k, '_menu_item_type', true);
1808
  $post_meta_object_id = get_post_meta($k, '_menu_item_object_id', true);
1809
+ if ($type !== 'taxonomy') {
1810
  $ids_posts_custom[] = $post_meta_object_id;
1811
  } else {
1812
  $ids_categories[] = $post_meta_object_id;
1816
  }
1817
  }
1818
 
1819
+ $args = array(
1820
+ 'posts_per_page' => - 1,
1821
+ 'post_type' => $post_types,
1822
+ 'post__in' => $ids_posts_custom,
1823
+ 'post_status' => 'publish'
1824
  );
1825
+ $query = new WP_Query($args);
1826
  $menus_post_custom = $query->get_posts();
1827
  return array('posts_custom' => $menus_post_custom, 'categories' => $ids_categories);
1828
  }
1829
 
1830
  /**
1831
+ * Get posts selected in sitemap setting
1832
+ *
1833
  * @return array
1834
  */
1835
  public function getPostsSitemap()
1836
  {
1837
+ $post_types = $this->getPostTypes();
1838
+ $ids = array(0);
1839
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1840
  if (!empty($settings_sitemap['wpms_sitemap_posts'])) {
1841
+ foreach ((array) $settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
1842
  if (!empty($v['post_id'])) {
1843
  $ids[] = $k;
1844
  }
1845
  }
1846
  }
1847
 
1848
+ $args = array(
1849
+ 'posts_per_page' => - 1,
1850
+ 'post_type' => $post_types,
1851
+ 'post__in' => $ids,
1852
+ 'post_status' => 'publish'
1853
  );
1854
  $query = new WP_Query($args);
1855
  $posts = $query->get_posts();
1858
 
1859
  /**
1860
  * Get a list of all registered post type objects.
1861
+ *
1862
  * @return array
1863
  */
1864
+ public function getPostTypes()
1865
  {
1866
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1867
  unset($post_types['attachment']);
1870
  }
1871
 
1872
  /**
1873
+ * Get pages selected in sitemap setting
1874
+ *
1875
  * @return array
1876
  */
1877
  public function getPagesSitemap()
1878
  {
1879
+ $ids = array(0);
1880
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1881
  if (!empty($settings_sitemap['wpms_sitemap_pages'])) {
1882
  foreach ($settings_sitemap['wpms_sitemap_pages'] as $k => $v) {
1886
  }
1887
  }
1888
 
1889
+ $args = array(
1890
+ 'posts_per_page' => - 1,
1891
+ 'post_type' => 'page',
1892
+ 'post__in' => $ids,
1893
+ 'post_status' => 'publish'
1894
  );
1895
  $query = new WP_Query($args);
1896
  $pages = $query->get_posts();
1898
  }
1899
 
1900
  /**
1901
+ * Get pages
1902
+ *
1903
  * @return array|null|object
1904
  */
1905
  public function getPages()
1906
  {
1907
  global $wpdb;
1908
+ $pages = $wpdb->get_results($wpdb->prepare('SELECT ID,post_title FROM ' . $wpdb->posts . ' WHERE
1909
+ post_status = %s AND post_type = %s ORDER BY post_date DESC', array('publish', 'page')));
 
1910
  return $pages;
1911
  }
1912
 
1913
  /**
1914
+ * Get posts by category
1915
+ *
1916
  * @return array
1917
  */
1918
  public function getPosts()
1919
  {
1920
+ $posts = array();
1921
+ $taxo = 'category';
1922
  $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1923
  global $wpdb;
1924
  foreach ($categorys as $cat) {
1925
+ $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title
1926
+ FROM ' . $wpdb->posts . ' AS p
1927
+ INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id)
1928
+ INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1929
+ INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id)
1930
+ WHERE p.post_status = %s
1931
+ AND p.post_type = %s
1932
  AND tt.taxonomy = %s AND t.slug=%s
1933
+ ORDER BY p.post_date DESC', array('publish', 'post', $taxo, $cat->slug)));
 
1934
  if (!empty($results)) {
1935
+ $obj = new StdClass();
1936
  $obj->cat_name = $cat->cat_name;
1937
+ $obj->cat_ID = $cat->cat_ID;
1938
+ $obj->taxo = $taxo;
1939
+ $obj->slug = $cat->slug;
1940
+ $obj->results = $results;
1941
+ $posts[] = $obj;
1942
  }
1943
  }
1944
 
1946
  }
1947
 
1948
  /**
1949
+ * Get posts by category
1950
+ *
1951
+ * @param string $post_type Post type
1952
+ *
1953
  * @return array
1954
  */
1955
  public function getPostsCustom($post_type)
1956
  {
1957
+ global $wpdb;
1958
+ $posts = array();
1959
  $taxonomy_objects = get_object_taxonomies($post_type, 'names');
1960
+ if (!empty($taxonomy_objects)) {
1961
+ foreach ($taxonomy_objects as $taxo) {
1962
+ $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1963
+ foreach ($categorys as $cat) {
1964
+ $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title
1965
+ FROM ' . $wpdb->posts . ' AS p
1966
+ INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id)
1967
+ INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
1968
+ INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id)
1969
+ WHERE p.post_status = %s
 
1970
  AND p.post_type = %s
1971
  AND tt.taxonomy = %s AND t.slug=%s
1972
+ ORDER BY p.post_date DESC', array('publish', $post_type, $taxo, $cat->slug)));
1973
+
1974
+ if (!empty($results)) {
1975
+ $obj = new StdClass();
1976
+ $obj->cat_name = $cat->cat_name;
1977
+ $obj->cat_ID = $cat->cat_ID;
1978
+ $obj->taxo = $taxo;
1979
+ $obj->slug = $cat->slug;
1980
+ $obj->results = $results;
1981
+ $posts[] = $obj;
1982
+ }
1983
  }
1984
  }
1985
+ } else {
1986
+ $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title
1987
+ FROM ' . $wpdb->posts . ' AS p
1988
+ WHERE p.post_status = "publish" AND p.post_type = %s
1989
+ ORDER BY p.post_date DESC', array($post_type)));
1990
+ if (!empty($results)) {
1991
+ $obj = new StdClass();
1992
+ $obj->cat_name = '';
1993
+ $obj->cat_ID = '';
1994
+ $obj->taxo = '';
1995
+ $obj->slug = '';
1996
+ $obj->results = $results;
1997
+ $posts[] = $obj;
1998
+ }
1999
  }
2000
 
2001
  return $posts;
2003
 
2004
  /**
2005
  * Display sitemap menu in front-end
2006
+ *
2007
+ * @param object $term Term
2008
+ * @param array $ids_menu List menu id
2009
+ *
2010
  * @return string
2011
  */
2012
  public function viewMenusFrontend($term, $ids_menu)
2013
  {
2014
+ $html = '';
2015
  $list_menus = array();
2016
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
2017
  $list_menus = $ids_menu;
2024
  }
2025
 
2026
  $args = array(
2027
+ 'orderby' => 'menu_order',
2028
+ 'order' => 'ASC',
2029
+ 'posts_per_page' => - 1,
2030
+ 'post_type' => 'nav_menu_item',
2031
+ 'post_status' => 'any',
2032
+ 'post__in' => $list_menus,
2033
+ 'tax_query' => array(
2034
  array(
2035
  'taxonomy' => 'nav_menu',
2036
+ 'field' => 'slug',
2037
+ 'terms' => $term->slug,
2038
  ),
2039
  ),
2040
  );
2041
 
2042
+ $query = new WP_Query($args);
2043
  $submenus = $query->get_posts();
2044
  if (!empty($submenus)) {
2045
+ $html .= '<h4>' . esc_html($term->name) . '</h4>';
2046
  $html .= '<ul class="wpms_frontend_menus_sitemap">';
2047
  foreach ($submenus as $menu) {
2048
+ $type = get_post_meta($menu->ID, '_menu_item_type', true);
2049
+ $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
2050
+ $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true);
2051
  $this->level[$menu->ID] = 0;
2052
+ $level = $this->countParent($menu->ID);
2053
+ if ($type === 'taxonomy') {
2054
  $post_submenu = get_post($menu->ID);
2055
+ $title = $post_submenu->post_title;
2056
  if (empty($title)) {
2057
+ $term = get_term($id_menu, $type_menu);
2058
  $title = $term->name;
2059
  }
2060
  } else {
2061
+ $post = get_post($menu->ID);
2062
  $title = $post->post_title;
2063
  if (empty($title)) {
2064
  $post_submenu = get_post($id_menu);
2065
+ $title = $post_submenu->post_title;
2066
  }
2067
  }
2068
+ $type = get_post_meta($menu->ID, '_menu_item_type', true);
2069
  $permalink = $this->getPermalinkSitemap($type, $id_menu);
2070
+ $margin = $level * 10;
2071
+ $style = '';
2072
+ if ((int) $level !== 0) {
2073
+ $style = 'style="' . esc_attr('margin-left:' . $margin . 'px') . '"';
2074
  }
2075
+ $html .= '<li class="' . esc_attr('wpms_menu_level_' . $level) . '" ' . $style . '>';
2076
+ $html .= '<a href="' . esc_url($permalink) . '">' . esc_html($title) . '</a>';
2077
  $html .= '</li>';
2078
  }
2079
 
2083
  }
2084
 
2085
  /**
2086
+ * Get count parent for a menu
2087
+ *
2088
+ * @param integer $menuID ID of menu
2089
+ *
2090
+ * @return integer
2091
  */
2092
  public function countParent($menuID)
2093
  {
2099
  $this->loopParent($parent, $menuID);
2100
  }
2101
 
2102
+ return (int) $this->level[$menuID];
2103
  }
2104
 
2105
  /**
2106
+ * Get level list menu
2107
+ *
2108
+ * @param integer $menuID Current menu id
2109
+ * @param integer $menuIDroot Root menu id
2110
+ *
2111
+ * @return void
2112
  */
2113
  public function loopParent($menuID, $menuIDroot)
2114
  {
2115
+ $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true);
2116
  $parent_1 = get_post_meta($parent, '_menu_item_menu_item_parent', true);
2117
  if ((!empty($this->settings_sitemap['wpms_sitemap_menus'][$parent]) && !empty($parent))
2118
  || (!empty($parent_1) && !empty($parent))) {
2123
 
2124
  /**
2125
  * Display list menu in sitemap settings
2126
+ *
2127
+ * @param object $term Current menu
2128
+ *
2129
  * @return string
2130
  */
2131
  public function viewMenus($term)
2132
  {
2133
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
2134
+ $args = array(
2135
+ 'orderby' => 'menu_order',
2136
+ 'order' => 'ASC',
2137
+ 'posts_per_page' => - 1,
2138
+ 'post_type' => 'nav_menu_item',
2139
+ 'post_status' => 'any',
2140
+ 'post__in' => $list_submenu_id,
2141
+ 'meta_key' => '_menu_item_menu_item_parent',
2142
+ 'meta_value' => 0
2143
  );
2144
 
2145
+ $query = new WP_Query($args);
2146
  $submenus = $query->get_posts();
2147
 
2148
  $this->html .= '<h3>';
2149
  $this->html .= '<div class="pure-checkbox">';
2150
+ $this->html .= '<input class="xm_cb_all" id="' . esc_attr('xm_cb_all_' . $term->slug) . '" type="checkbox">';
2151
+ $this->html .= '<label for="' . esc_attr('xm_cb_all_' . $term->slug) . '">' . esc_html($term->name) . '</label>';
2152
  $this->html .= '</div>';
2153
  $this->html .= '</h3>';
2154
  $this->html .= '<div class="wpms_xmp_custom_column" style="font-weight: bold;">';
2155
+ $this->html .= '<label>' . esc_html__('Display in column', 'wp-meta-seo') . '</label>';
2156
  $this->html .= '<select class="wpms_display_column wpms_display_column_menus"
2157
+ data-menu_id="' . esc_attr($term->term_id) . '">';
2158
+ for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i ++) {
2159
  if (isset($this->settings_sitemap['wpms_display_column_menus'][$term->term_id])
2160
+ && (int) $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] === (int) $i) {
2161
+ $this->html .= '<option selected value="' . esc_attr($i) . '">' . esc_html($this->columns[$i]) . '</option>';
2162
  } else {
2163
+ $this->html .= '<option value="' . esc_attr($i) . '">' . esc_html($this->columns[$i]) . '</option>';
2164
  }
2165
  }
2166
  $this->html .= '</select>';
2183
  $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency']
2184
  );
2185
 
2186
+ $type = get_post_meta($menu->ID, '_menu_item_type', true);
2187
  $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
2188
+ $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true);
2189
+ if ($type === 'taxonomy') {
2190
  $post_submenu = get_post($menu->ID);
2191
+ $title = $post_submenu->post_title;
2192
  if (empty($title)) {
2193
+ $term = get_term($id_menu, $type_menu);
2194
  $title = $term->name;
2195
  }
2196
  } else {
2197
+ $post = get_post($menu->ID);
2198
  $title = $post->post_title;
2199
  if (empty($title)) {
2200
  $post_submenu = get_post($id_menu);
2201
+ $title = $post_submenu->post_title;
2202
  }
2203
  }
2204
+ $level = 1;
2205
  $this->html .= '<div class="wpms_row wpms_row_record">';
2206
  $check_type = get_post_meta($menu->ID, '_menu_item_object', true);
2207
+ $permalink = $this->getPermalinkSitemap($check_type, $id_menu);
2208
  $this->html .= '<div style="float:left;line-height:30px">';
2209
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
2210
  $this->html .= '<input class="wpms_sitemap_input_link checked"
2211
+ type="hidden" data-type="menu" value="' . esc_attr($permalink) . '">';
2212
  $this->html .= '<div class="pure-checkbox">';
2213
+ $this->html .= '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '"
2214
+ id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox"
2215
+ name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '"
2216
+ value="' . esc_attr($menu->ID) . '" checked>';
2217
+ $this->html .= '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '">' . esc_html($title) . '</label>';
2218
  $this->html .= '</div>';
2219
  } else {
2220
  if (isset($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'])
2221
+ && (int) $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'] === (int) $menu->ID) {
2222
  $this->html .= '<input class="wpms_sitemap_input_link checked"
2223
+ type="hidden" data-type="menu" value="' . esc_url($permalink) . '">';
2224
  $this->html .= '<div class="pure-checkbox">';
2225
+ $this->html .= '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '"
2226
+ id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox"
2227
+ name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '"
2228
+ value="' . esc_attr($menu->ID) . '" checked>';
2229
+ $this->html .= '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '">' . esc_html($title) . '</label>';
2230
  $this->html .= '</div>';
2231
  } else {
2232
  $this->html .= '<input class="wpms_sitemap_input_link" type="hidden" data-type="menu"
2233
+ value="' . esc_url($permalink) . '">';
2234
  $this->html .= '<div class="pure-checkbox">';
2235
+ $this->html .= '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '"
2236
+ id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox"
2237
+ name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '"
2238
+ value="' . esc_attr($menu->ID) . '">';
2239
+ $this->html .= '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '">' . esc_html($title) . '</label>';
2240
  $this->html .= '</div>';
2241
  }
2242
  }
2252
 
2253
  /**
2254
  * Display list menu in sitemap settings
2255
+ *
2256
+ * @param integer $menuID ID of menu
2257
+ * @param integer $level Level of menu
2258
+ * @param array $settings_sitemap All settings
2259
+ * @param object $term Current menu
2260
+ *
2261
+ * @return void
2262
  */
2263
  public function loop($menuID, $level, $settings_sitemap, $term)
2264
  {
2265
+ $args = array(
2266
+ 'post_type' => 'nav_menu_item',
2267
+ 'posts_per_page' => - 1,
2268
+ 'meta_key' => '_menu_item_menu_item_parent',
2269
+ 'meta_value' => $menuID,
2270
+ 'orderby' => 'menu_order',
2271
+ 'order' => 'ASC'
2272
  );
2273
+ $query = new WP_Query($args);
2274
  $submenus = $query->get_posts();
2275
  if (!empty($submenus)) {
2276
  foreach ($submenus as $submenu) {
2277
+ $type = get_post_meta($submenu->ID, '_menu_item_type', true);
2278
+ $type_menu = get_post_meta($submenu->ID, '_menu_item_object', true);
2279
  $post_subid = get_post_meta($submenu->ID, '_menu_item_object_id', true);
2280
  if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'])) {
2281
  $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'] = 'monthly';
2283
  if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'])) {
2284
  $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'] = '1.0';
2285
  }
2286
+ if ($type === 'taxonomy') {
2287
  $post_submenu = get_post($submenu->ID);
2288
+ $title = $post_submenu->post_title;
2289
  if (empty($title)) {
2290
+ $term = get_term($post_subid, $type_menu);
2291
  $title = $term->name;
2292
  }
2293
  } else {
2294
  $post_submenu = get_post($submenu->ID);
2295
+ $title = $post_submenu->post_title;
2296
  if (empty($title)) {
2297
  $post_submenu = get_post($post_subid);
2298
+ $title = $post_submenu->post_title;
2299
  }
2300
  }
2301
 
2302
  $space = '';
2303
+ for ($i = 1; $i <= $level * 3; $i ++) {
2304
  $space .= '&nbsp;';
2305
  }
2306
  $slpr = $this->viewPriority(
2315
  );
2316
 
2317
  if (empty($settings_sitemap['wpms_check_firstsave'])) {
2318
+ $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '"
2319
+ class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '"
2320
+ checked name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '"
2321
  type="checkbox" value="' . $submenu->ID . '">';
2322
  } else {
2323
  if (isset($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'])
2324
+ && (int) $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'] === (int) $submenu->ID) {
2325
+ $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '"
2326
+ class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" checked
2327
+ name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '"
2328
+ type="checkbox" value="' . esc_attr($submenu->ID) . '">';
2329
  } else {
2330
+ $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '"
2331
+ class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '"
2332
+ name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '"
2333
+ type="checkbox" value="' . esc_attr($submenu->ID) . '">';
2334
  }
2335
  }
2336
 
2338
  $this->html .= '<div style="float:left;line-height:30px">';
2339
  $this->html .= '<div class="pure-checkbox">';
2340
  $this->html .= $checkbox;
2341
+ $this->html .= '<label for="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '">' . esc_html($title) . '</label>';
2342
  $this->html .= '</div>';
2343
  $this->html .= '</div>';
2344
  $this->html .= '<div style="margin-left:200px">' . $slpr . $slfr . '</div>';
2350
 
2351
  /**
2352
  * Ajax generate sitemap to xml file
2353
+ *
2354
+ * @return void
2355
  */
2356
  public function regenerateSitemaps()
2357
  {
2358
  $wpms_url_robot = get_home_path() . 'robots.txt';
2359
+ $wpms_url_home = site_url('/');
2360
+ $this->getSitemapSettings();
2361
  $this->createSitemap($this->wpms_sitemap_name);
2362
+ if ((int) $this->settings_sitemap['wpms_sitemap_root'] === 1) {
2363
  $this->createSitemap($this->wpms_sitemap_default_name);
2364
  }
2365
 
2366
+ if (isset($this->settings_sitemap['wpms_sitemap_add']) && (int) $this->settings_sitemap['wpms_sitemap_add'] === 1) {
2367
  if (!file_exists($wpms_url_robot) && !is_multisite()) {
2368
  ob_start();
2369
+ // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting -- Turn off all error reporting to write file
2370
  error_reporting(0);
2371
  do_robots();
2372
  $robots_content = ob_get_clean();
2378
 
2379
  if (file_exists($wpms_url_robot) && !is_multisite()) {
2380
  if (!is_writable($wpms_url_robot)) {
2381
+ chmod($wpms_url_robot, 0755);
2382
  }
2383
 
2384
  if (is_writable($wpms_url_robot)) {
2385
  $file_content = file_get_contents($wpms_url_robot);
2386
  if (isset($this->settings_sitemap['wpms_sitemap_add'])
2387
+ && (int) $this->settings_sitemap['wpms_sitemap_add'] === 1
2388
  && !preg_match('|Sitemap: ' . $wpms_url_home . $this->wpms_sitemap_name . '|', $file_content)) {
2389
  file_put_contents(
2390
  $wpms_url_robot,
2392
  );
2393
  }
2394
  } else {
2395
+ $error = esc_html__('Cannot edit "robots.txt". Check your permissions', 'wp-meta-seo');
2396
  wp_send_json(array('status' => false, 'message' => $error));
2397
  }
2398
  }
2404
 
2405
  /**
2406
  * Display priority for each item
2407
+ *
2408
+ * @param string $id Selectbox id
2409
+ * @param string $name Selectbox name
2410
+ * @param string $selected Selected value
2411
+ *
2412
  * @return string
2413
  */
2414
  public function viewPriority($id, $name, $selected)
2415
  {
2416
  $values = array('1' => '100%', '0.9' => '90%', '0.8' => '80%', '0.7' => '70%', '0.6' => '60%', '0.5' => '50%');
2417
+ $select = '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="wpmsleft">';
2418
+ $select .= '<option value="1">' . esc_html__('Priority', 'wp-meta-seo') . '</option>';
2419
  foreach ($values as $k => $v) {
2420
+ if ($k === $selected) {
2421
+ $select .= '<option selected value="' . esc_attr($k) . '">' . esc_html($v) . '</option>';
2422
  } else {
2423
+ $select .= '<option value="' . esc_attr($k) . '">' . esc_html($v) . '</option>';
2424
  }
2425
  }
2426
  $select .= '</select>';
2429
 
2430
  /**
2431
  * Display frequency for each item
2432
+ *
2433
+ * @param string $id Selectbox id
2434
+ * @param string $name Selectbox name
2435
+ * @param string $selected Selected value
2436
+ *
2437
  * @return string
2438
  */
2439
  public function viewFrequency($id, $name, $selected)
2440
  {
2441
  $values = array(
2442
+ 'always' => 'Always',
2443
+ 'hourly' => 'Hourly',
2444
+ 'daily' => 'Daily',
2445
+ 'weekly' => 'Weekly',
2446
  'monthly' => 'Monthly',
2447
+ 'yearly' => 'Yearly',
2448
+ 'never' => 'Never'
2449
  );
2450
+ $select = '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="wpmsleft">';
2451
+ $select .= '<option value="monthly">' . esc_html__('Frequency', 'wp-meta-seo') . '</option>';
2452
  foreach ($values as $k => $v) {
2453
+ if ($k === $selected) {
2454
+ $select .= '<option selected value="' . esc_attr($k) . '">' . esc_html($v) . '</option>';
2455
  } else {
2456
+ $select .= '<option value="' . esc_attr($k) . '">' . esc_html($v) . '</option>';
2457
  }
2458
  }
2459
  $select .= '</select>';
2462
 
2463
  /**
2464
  * Ajax update sitemap settings
2465
+ *
2466
+ * @return void
2467
  */
2468
  public function saveSitemapSettings()
2469
  {
2470
+ if (empty($_POST['wpms_nonce'])
2471
+ || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) {
2472
+ die();
2473
+ }
2474
+
2475
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
2476
+ $lists = array(
2477
+ 'wpms_sitemap_add' => 0,
2478
+ 'wpms_sitemap_root' => 0,
2479
+ 'wpms_sitemap_author' => 0,
2480
+ 'wpms_html_sitemap_page' => 0,
2481
+ 'wpms_html_sitemap_column' => 1,
2482
+ 'wpms_html_sitemap_theme' => 'default',
2483
+ 'wpms_html_sitemap_position' => 'after',
2484
+ 'wpms_sitemap_taxonomies' => array(),
2485
+ 'wpms_check_firstsave' => 0,
2486
+ 'wpms_display_column_posts' => 1,
2487
+ 'wpms_display_column_pages' => 1,
2488
+ 'wpms_category_link' => array(),
2489
+ 'wpms_display_order_menus' => 1,
2490
+ 'wpms_display_order_posts' => 2,
2491
+ 'wpms_display_order_pages' => 3,
2492
+ 'wpms_display_order_urls' => 4
2493
  );
2494
 
2495
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2496
  $custom_post_types = get_post_types(
2497
  array(
2498
+ 'public' => true,
2499
  'exclude_from_search' => false,
2500
+ '_builtin' => false
2501
  )
2502
  );
2503
  if (!empty($custom_post_types)) {
2504
  foreach ($custom_post_types as $post_type => $label) {
2505
  $lists['wpms_display_column_' . $post_type] = 1;
2506
+ $lists['wpms_public_name_' . $post_type] = '';
2507
+ $lists['wpms_sitemap_' . $post_type] = array();
2508
  }
2509
  }
2510
 
2511
  $lists['wpms_display_column_customUrl'] = 1;
2512
+ $lists['wpms_public_name_customUrl'] = '';
2513
+ $lists['wpms_sitemap_customUrl'] = array();
2514
  }
2515
 
2516
  $wpms_display_column_menus = json_decode(stripslashes($_POST['wpms_display_column_menus']), true);
2527
  }
2528
 
2529
  $lists_selected = array(
2530
+ 'wpms_sitemap_posts' => array(),
2531
+ 'wpms_sitemap_pages' => array(),
2532
+ 'wpms_sitemap_menus' => array()
2533
  );
2534
 
2535
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2536
  $custom_post_types = get_post_types(
2537
  array(
2538
+ 'public' => true,
2539
  'exclude_from_search' => false,
2540
+ '_builtin' => false
2541
  )
2542
  );
2543
  if (!empty($custom_post_types)) {
2544
  foreach ($custom_post_types as $post_type => $label) {
2545
+ $lists_selected['wpms_sitemap_' . $post_type] = array();
2546
  }
2547
  }
2548
 
2549
+ $lists_selected['wpms_sitemap_customUrl'] = array();
2550
 
2551
  // save setting include lang
2552
  if (isset($_POST['wpms_lang_list']) && is_array($_POST['wpms_lang_list'])) {
2555
  }
2556
 
2557
  foreach ($lists_selected as $k => $v) {
2558
+ if (isset($_POST[$k]) && $_POST[$k] !== '{}') {
2559
+ $values = json_decode(stripslashes($_POST[$k]), true);
2560
  $settings_sitemap[$k] = $values;
2561
  } else {
2562
  $settings_sitemap[$k] = array();
inc/class.metaseo-snippet-preview.php CHANGED
@@ -11,48 +11,67 @@ class WPMSEOSnippetPreview
11
  {
12
 
13
  /**
14
- * @var
 
 
15
  */
16
  protected $content;
17
  /**
18
- * @var
 
 
19
  */
20
  protected $options;
21
  /**
22
- * @var
 
 
23
  */
24
  protected $post;
25
  /**
 
 
26
  * @var string
27
  */
28
  protected $title;
29
  /**
 
 
30
  * @var string
31
  */
32
  protected $description;
33
  /**
 
 
34
  * @var string
35
  */
36
  protected $date = '';
37
  /**
38
- * @var
 
 
39
  */
40
  protected $url;
41
  /**
 
 
42
  * @var string
43
  */
44
  protected $slug = '';
45
 
46
  /**
47
  * WPMSEOSnippetPreview constructor.
48
- * @param $post
49
- * @param $title
50
- * @param $description
 
 
 
51
  */
52
  public function __construct($post, $title, $description)
53
  {
54
- $this->post = $post;
55
- $this->title = esc_html($title);
56
  $this->description = esc_html($description);
57
 
58
  $this->setDate();
@@ -70,15 +89,17 @@ class WPMSEOSnippetPreview
70
  return $this->content;
71
  }
72
 
73
- /*
74
- * Sets date if available
75
- */
 
 
76
  protected function setDate()
77
  {
78
  if (is_object($this->post) && isset($this->options['showdate-' . $this->post->post_type])
79
  && $this->options['showdate-' . $this->post->post_type] === true) {
80
- $date = $this->getPostDate();
81
- $this->date = '<span class="date">' . $date . ' - </span>';
82
  }
83
  }
84
 
@@ -86,21 +107,22 @@ class WPMSEOSnippetPreview
86
  * Retrieves a post date when post is published, or return current date when it's not.
87
  *
88
  * @return string
89
- *
90
  */
91
  protected function getPostDate()
92
  {
93
- if (isset($this->post->post_date) && $this->post->post_status == 'publish') {
94
  $date = date_i18n('j M Y', strtotime($this->post->post_date));
95
  } else {
96
  $date = date_i18n('j M Y');
97
  }
98
 
99
- return (string)$date;
100
  }
101
 
102
  /**
103
  * Generates the url that is displayed in the snippet preview.
 
 
104
  */
105
  protected function setUrl()
106
  {
@@ -112,13 +134,15 @@ class WPMSEOSnippetPreview
112
  * Sets the slug and adds it to the url if the post has been published and the post name exists.
113
  *
114
  * If the post is set to be the homepage the slug is also not included.
 
 
115
  */
116
  protected function setSlug()
117
  {
118
- $frontpage_post_id = (int)(get_option('page_on_front'));
119
  $permalink_structure = get_option('permalink_structure');
120
  if (is_object($this->post) && isset($this->post->post_name) && $this->post->post_name !== ''
121
- && $this->post->ID !== $frontpage_post_id) {
122
  $this->slug = sanitize_title($this->title);
123
  if (!empty($permalink_structure)) {
124
  $this->url .= esc_html($this->slug);
@@ -128,16 +152,16 @@ class WPMSEOSnippetPreview
128
 
129
  /**
130
  * Generates the html for the snippet preview and assign it to $this->content.
 
 
131
  */
132
  protected function setContent()
133
  {
134
- $content = <<<HTML
135
- <div id="wpmseosnippet">
136
- <a class="title" id="wpmseosnippet_title" href="#">$this->title</a>
137
- <span class="url">$this->url</span>
138
- <p class="desc">$this->date<span class="autogen"></span><span class="content">$this->description</span></p>
139
- </div>
140
- HTML;
141
  $this->setContentThroughFilter($content);
142
  }
143
 
@@ -145,11 +169,13 @@ HTML;
145
  * Sets the html for the snippet preview through a filter
146
  *
147
  * @param string $content Content string.
 
 
148
  */
149
  protected function setContentThroughFilter($content)
150
  {
151
- $properties = get_object_vars($this);
152
  $properties['desc'] = $properties['description'];
153
- $this->content = apply_filters('wpmseo_snippet', $content, $this->post, $properties);
154
  }
155
  }
11
  {
12
 
13
  /**
14
+ * Snippet content
15
+ *
16
+ * @var string
17
  */
18
  protected $content;
19
  /**
20
+ * Options
21
+ *
22
+ * @var array
23
  */
24
  protected $options;
25
  /**
26
+ * Current post
27
+ *
28
+ * @var object
29
  */
30
  protected $post;
31
  /**
32
+ * Snippet title
33
+ *
34
  * @var string
35
  */
36
  protected $title;
37
  /**
38
+ * Snippet description
39
+ *
40
  * @var string
41
  */
42
  protected $description;
43
  /**
44
+ * Snippet date
45
+ *
46
  * @var string
47
  */
48
  protected $date = '';
49
  /**
50
+ * Snippet URL
51
+ *
52
+ * @var string
53
  */
54
  protected $url;
55
  /**
56
+ * Snippet slug
57
+ *
58
  * @var string
59
  */
60
  protected $slug = '';
61
 
62
  /**
63
  * WPMSEOSnippetPreview constructor.
64
+ *
65
+ * @param object $post Current post
66
+ * @param string $title Title
67
+ * @param string $description Description
68
+ *
69
+ * @return void
70
  */
71
  public function __construct($post, $title, $description)
72
  {
73
+ $this->post = $post;
74
+ $this->title = esc_html($title);
75
  $this->description = esc_html($description);
76
 
77
  $this->setDate();
89
  return $this->content;
90
  }
91
 
92
+ /**
93
+ * Sets date if available
94
+ *
95
+ * @return void
96
+ */
97
  protected function setDate()
98
  {
99
  if (is_object($this->post) && isset($this->options['showdate-' . $this->post->post_type])
100
  && $this->options['showdate-' . $this->post->post_type] === true) {
101
+ $date = $this->getPostDate();
102
+ $this->date = '<span class="date">' . esc_html($date) . ' - </span>';
103
  }
104
  }
105
 
107
  * Retrieves a post date when post is published, or return current date when it's not.
108
  *
109
  * @return string
 
110
  */
111
  protected function getPostDate()
112
  {
113
+ if (isset($this->post->post_date) && $this->post->post_status === 'publish') {
114
  $date = date_i18n('j M Y', strtotime($this->post->post_date));
115
  } else {
116
  $date = date_i18n('j M Y');
117
  }
118
 
119
+ return (string) $date;
120
  }
121
 
122
  /**
123
  * Generates the url that is displayed in the snippet preview.
124
+ *
125
+ * @return void
126
  */
127
  protected function setUrl()
128
  {
134
  * Sets the slug and adds it to the url if the post has been published and the post name exists.
135
  *
136
  * If the post is set to be the homepage the slug is also not included.
137
+ *
138
+ * @return void
139
  */
140
  protected function setSlug()
141
  {
142
+ $frontpage_post_id = (int) (get_option('page_on_front'));
143
  $permalink_structure = get_option('permalink_structure');
144
  if (is_object($this->post) && isset($this->post->post_name) && $this->post->post_name !== ''
145
+ && (int) $this->post->ID !== (int) $frontpage_post_id) {
146
  $this->slug = sanitize_title($this->title);
147
  if (!empty($permalink_structure)) {
148
  $this->url .= esc_html($this->slug);
152
 
153
  /**
154
  * Generates the html for the snippet preview and assign it to $this->content.
155
+ *
156
+ * @return void
157
  */
158
  protected function setContent()
159
  {
160
+ $content = '<div id="wpmseosnippet">
161
+ <a class="title" id="wpmseosnippet_title" href="#">' . esc_html($this->title) . '</a>
162
+ <span class="url">' . esc_url($this->url) . '</span>
163
+ <p class="desc">' . esc_html($this->date) . '<span class="autogen"></span><span class="content">' . esc_html($this->description) . '</span></p>
164
+ </div>';
 
 
165
  $this->setContentThroughFilter($content);
166
  }
167
 
169
  * Sets the html for the snippet preview through a filter
170
  *
171
  * @param string $content Content string.
172
+ *
173
+ * @return void
174
  */
175
  protected function setContentThroughFilter($content)
176
  {
177
+ $properties = get_object_vars($this);
178
  $properties['desc'] = $properties['description'];
179
+ $this->content = apply_filters('wpmseo_snippet', $content, $this->post, $properties);
180
  }
181
  }
inc/class.wp-metaseo.php CHANGED
@@ -9,12 +9,16 @@ defined('ABSPATH') || die('No direct script access allowed!');
9
  class WpMetaSeo
10
  {
11
  /**
12
- * @var bool
 
 
13
  */
14
  private static $initiated = false;
15
 
16
  /**
17
  * Init
 
 
18
  */
19
  public static function init()
20
  {
@@ -26,6 +30,8 @@ class WpMetaSeo
26
 
27
  /**
28
  * Initializes WordPress hooks
 
 
29
  */
30
  private static function initHooks()
31
  {
@@ -34,8 +40,11 @@ class WpMetaSeo
34
 
35
  /**
36
  * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
37
- * @param string $wp default wordpress version
38
- * @param string $php default php version
 
 
 
39
  */
40
  public static function pluginActivation($wp = '4.0', $php = '5.3.0')
41
  {
@@ -54,14 +63,14 @@ class WpMetaSeo
54
  return;
55
  }
56
 
57
- $version = 'PHP' == $flag ? $php : $wp;
58
  deactivate_plugins(basename(__FILE__));
59
  wp_die(
60
  '<p>The <strong>WP Meta SEO</strong>
61
- plugin requires ' . $flag . ' version ' . $version . ' or greater.</p>',
62
  'Plugin Activation Error',
63
  array(
64
- 'response' => 200,
65
  'back_link' => true
66
  )
67
  );
@@ -72,20 +81,24 @@ class WpMetaSeo
72
  '<p>To active WP Meta SEO plugin , please install “dom” PHP extension </p>',
73
  'Plugin Activation Error',
74
  array(
75
- 'response' => 200,
76
  'back_link' => true
77
  )
78
  );
79
  }
80
  }
81
 
82
- /* create metaseo_images table */
 
 
 
 
83
  public static function installDb()
84
  {
85
  global $wpdb;
86
  $table_name = $wpdb->prefix . 'metaseo_images';
87
 
88
- $sql = "CREATE TABLE IF NOT EXISTS $table_name (
89
  `id` int(11) NOT NULL AUTO_INCREMENT,
90
  `post_id` int(11) NOT NULL,
91
  `posts_optimized_id` text COLLATE utf8_unicode_ci NOT NULL,
@@ -97,7 +110,7 @@ class WpMetaSeo
97
  `description` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
98
  `link` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
99
  PRIMARY KEY (`id`)
100
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
101
 
102
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
103
 
9
  class WpMetaSeo
10
  {
11
  /**
12
+ * Initiated
13
+ *
14
+ * @var boolean
15
  */
16
  private static $initiated = false;
17
 
18
  /**
19
  * Init
20
+ *
21
+ * @return void
22
  */
23
  public static function init()
24
  {
30
 
31
  /**
32
  * Initializes WordPress hooks
33
+ *
34
+ * @return void
35
  */
36
  private static function initHooks()
37
  {
40
 
41
  /**
42
  * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
43
+ *
44
+ * @param string $wp Default wordpress version
45
+ * @param string $php Default php version
46
+ *
47
+ * @return void
48
  */
49
  public static function pluginActivation($wp = '4.0', $php = '5.3.0')
50
  {
63
  return;
64
  }
65
 
66
+ $version = 'PHP' === $flag ? $php : $wp;
67
  deactivate_plugins(basename(__FILE__));
68
  wp_die(
69
  '<p>The <strong>WP Meta SEO</strong>
70
+ plugin requires ' . esc_html($flag) . ' version ' . esc_html($version) . ' or greater.</p>',
71
  'Plugin Activation Error',
72
  array(
73
+ 'response' => 200,
74
  'back_link' => true
75
  )
76
  );
81
  '<p>To active WP Meta SEO plugin , please install “dom” PHP extension </p>',
82
  'Plugin Activation Error',
83
  array(
84
+ 'response' => 200,
85
  'back_link' => true
86
  )
87
  );
88
  }
89
  }
90
 
91
+ /**
92
+ * Create metaseo_images table
93
+ *
94
+ * @return void
95
+ */
96
  public static function installDb()
97
  {
98
  global $wpdb;
99
  $table_name = $wpdb->prefix . 'metaseo_images';
100
 
101
+ $sql = 'CREATE TABLE IF NOT EXISTS ' . $table_name . ' (
102
  `id` int(11) NOT NULL AUTO_INCREMENT,
103
  `post_id` int(11) NOT NULL,
104
  `posts_optimized_id` text COLLATE utf8_unicode_ci NOT NULL,
110
  `description` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
111
  `link` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
112
  PRIMARY KEY (`id`)
113
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;';
114
 
115
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
116
 
inc/google_analytics/tracking/code-classic.php CHANGED
@@ -11,6 +11,7 @@
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $google_alanytics['tableid_jail']);
 
14
  ?>
15
  <script type="text/javascript">
16
  var _gaq = _gaq || [];
@@ -20,17 +21,21 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
20
  <?php }?>
21
  _gaq.push(['_setAccount', '<?php echo esc_html($profile[2]); ?>']);
22
  _gaq.push(['_trackPageview']<?php if ($this->ga_tracking['wpmsga_dash_anonim']) {?>, ['_gat._anonymizeIp']<?php }?>);
23
-
24
  (function () {
25
  var ga = document.createElement('script');
26
  ga.type = 'text/javascript';
27
  ga.async = true;
28
- <?php if ($this->ga_tracking['wpmsga_dash_remarketing']) { ?>
 
 
29
  ga.src = ('https:' === document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
30
- <?php }else{?>
 
 
31
  ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
32
- <?php }?>
33
  var s = document.getElementsByTagName('script')[0];
34
  s.parentNode.insertBefore(ga, s);
35
  })();
36
- </script>
 
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $google_alanytics['tableid_jail']);
14
+ // phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace, Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore -- Render google analytics script structure on frontend
15
  ?>
16
  <script type="text/javascript">
17
  var _gaq = _gaq || [];
21
  <?php }?>
22
  _gaq.push(['_setAccount', '<?php echo esc_html($profile[2]); ?>']);
23
  _gaq.push(['_trackPageview']<?php if ($this->ga_tracking['wpmsga_dash_anonim']) {?>, ['_gat._anonymizeIp']<?php }?>);
 
24
  (function () {
25
  var ga = document.createElement('script');
26
  ga.type = 'text/javascript';
27
  ga.async = true;
28
+ <?php
29
+ if ($this->ga_tracking['wpmsga_dash_remarketing']) {
30
+ ?>
31
  ga.src = ('https:' === document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
32
+ <?php
33
+ } else {
34
+ ?>
35
  ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
36
+ <?php } ?>
37
  var s = document.getElementsByTagName('script')[0];
38
  s.parentNode.insertBefore(ga, s);
39
  })();
40
+ </script>
41
+ <?php // phpcs:enable ?>
inc/google_analytics/tracking/code-universal.php CHANGED
@@ -11,6 +11,7 @@
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $google_alanytics['tableid_jail']);
 
14
  ?>
15
  <script>
16
  (function (i, s, o, g, r, a, m) {
@@ -26,11 +27,11 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
26
  })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
27
  <?php
28
  $create_options = '{';
29
- if ($this->ga_tracking['wpmsga_speed_samplerate'] != 1) {
30
- $create_options .= "'siteSpeedSampleRate' : " . (int)$this->ga_tracking['wpmsga_speed_samplerate'];
31
  }
32
- if ($this->ga_tracking['wpmsga_crossdomain_tracking'] && $this->ga_tracking['wpmsga_crossdomain_list'] != '') {
33
- if ($create_options != '{') {
34
  $create_options .= ', ';
35
  }
36
  $create_options .= "'allowLinker' : true";
@@ -46,21 +47,21 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
46
  $optionsArray['cookieName'] = $this->ga_tracking['wpmsga_cookiename'];
47
  }
48
  if (!empty($this->ga_tracking['wpmsga_cookieexpires'])) {
49
- $optionsArray['cookieExpires'] = (int)$this->ga_tracking['wpmsga_cookieexpires'];
50
  }
51
  if (!empty($optionsArray)) {
52
  $options = json_encode($optionsArray);
53
  }
54
  ?>
55
- ga('create', '<?php echo esc_html($profile[2]); ?>', <?php echo $options; ?><?php if ($create_options != '{}') {?>, <?php echo $create_options; }?>);
56
- <?php if ($this->ga_tracking ['wpmsga_crossdomain_tracking'] && $this->ga_tracking ['wpmsga_crossdomain_list'] != '') {?>
57
  ga('require', 'linker');
58
  <?php
59
  $crossdomain_list = explode(',', $this->ga_tracking['wpmsga_crossdomain_list']);
60
  $crossdomain_list = array_map('trim', $crossdomain_list);
61
  $crossdomain_list = strip_tags(implode("','", $crossdomain_list));
62
  ?>
63
- ga('linker:autoLink', ['<?php echo($crossdomain_list)?>']);
64
  <?php
65
  }
66
  if ( $this->ga_tracking['wpmsga_dash_remarketing'] ) {
@@ -78,19 +79,19 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
78
  $author_id = $post->post_author;
79
  $author_name = get_the_author_meta('display_name', $author_id);
80
  ?>
81
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_author_dimindex']; ?>', '<?php echo esc_attr($author_name); ?>');
82
  <?php
83
  }
84
  if ( $this->ga_tracking['wpmsga_pubyear_dimindex'] && is_single() ) {
85
  global $post;
86
  $date = get_the_date('Y', $post->ID);
87
  ?>
88
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_pubyear_dimindex']; ?>', '<?php echo (int)$date; ?>');
89
  <?php
90
  }
91
  if ( $this->ga_tracking['wpmsga_category_dimindex'] && is_category() ) {
92
  ?>
93
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr(single_tag_title()); ?>');
94
  <?php
95
  }
96
  if ( $this->ga_tracking['wpmsga_tag_dimindex'] && is_single() ) {
@@ -105,7 +106,7 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
105
  $post_tags_list = rtrim($post_tags_list, ', ');
106
  if ( $post_tags_list ) {
107
  ?>
108
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_tag_dimindex']; ?>', '<?php echo esc_attr($post_tags_list); ?>');
109
  <?php
110
  }
111
  }
@@ -114,14 +115,14 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
114
  $categories = get_the_category($post->ID);
115
  foreach ( $categories as $category ) {
116
  ?>
117
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr($category->name); ?>');
118
  <?php
119
  break;
120
  }
121
  }
122
  if ( $this->ga_tracking['wpmsga_user_dimindex'] ) {
123
  ?>
124
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_user_dimindex']; ?>', '<?php echo is_user_logged_in() ? 'registered' : 'guest'; ?>');
125
  <?php
126
  }
127
  do_action('wpmsga_dash_addtrackingcode');
@@ -135,3 +136,5 @@ $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $g
135
  window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
136
  <?php }?>
137
  </script>
 
 
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $profile = WpmsGaTools::getSelectedProfile($google_alanytics['profile_list'], $google_alanytics['tableid_jail']);
14
+ // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped, Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen, Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose, PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace, PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace, Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace, Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore, Generic.WhiteSpace.ScopeIndent.IncorrectExact -- Render google analytics script structure on frontend
15
  ?>
16
  <script>
17
  (function (i, s, o, g, r, a, m) {
27
  })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
28
  <?php
29
  $create_options = '{';
30
+ if ((int) $this->ga_tracking['wpmsga_speed_samplerate'] !== 1) {
31
+ $create_options .= "'siteSpeedSampleRate' : " . (int) $this->ga_tracking['wpmsga_speed_samplerate'];
32
  }
33
+ if ($this->ga_tracking['wpmsga_crossdomain_tracking'] && $this->ga_tracking['wpmsga_crossdomain_list'] !== '') {
34
+ if ($create_options !== '{') {
35
  $create_options .= ', ';
36
  }
37
  $create_options .= "'allowLinker' : true";
47
  $optionsArray['cookieName'] = $this->ga_tracking['wpmsga_cookiename'];
48
  }
49
  if (!empty($this->ga_tracking['wpmsga_cookieexpires'])) {
50
+ $optionsArray['cookieExpires'] = (int) $this->ga_tracking['wpmsga_cookieexpires'];
51
  }
52
  if (!empty($optionsArray)) {
53
  $options = json_encode($optionsArray);
54
  }
55
  ?>
56
+ ga('create', '<?php echo $profile[2]; ?>', <?php echo $options; ?><?php if ($create_options !== '{}') {?>, <?php echo $create_options; }?>);
57
+ <?php if ($this->ga_tracking ['wpmsga_crossdomain_tracking'] && $this->ga_tracking ['wpmsga_crossdomain_list'] !== '') {?>
58
  ga('require', 'linker');
59
  <?php
60
  $crossdomain_list = explode(',', $this->ga_tracking['wpmsga_crossdomain_list']);
61
  $crossdomain_list = array_map('trim', $crossdomain_list);
62
  $crossdomain_list = strip_tags(implode("','", $crossdomain_list));
63
  ?>
64
+ ga('linker:autoLink', ['<?php echo esc_html($crossdomain_list)?>']);
65
  <?php
66
  }
67
  if ( $this->ga_tracking['wpmsga_dash_remarketing'] ) {
79
  $author_id = $post->post_author;
80
  $author_name = get_the_author_meta('display_name', $author_id);
81
  ?>
82
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_author_dimindex']; ?>', '<?php echo esc_attr($author_name); ?>');
83
  <?php
84
  }
85
  if ( $this->ga_tracking['wpmsga_pubyear_dimindex'] && is_single() ) {
86
  global $post;
87
  $date = get_the_date('Y', $post->ID);
88
  ?>
89
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_pubyear_dimindex']; ?>', '<?php echo (int) $date; ?>');
90
  <?php
91
  }
92
  if ( $this->ga_tracking['wpmsga_category_dimindex'] && is_category() ) {
93
  ?>
94
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr(single_tag_title()); ?>');
95
  <?php
96
  }
97
  if ( $this->ga_tracking['wpmsga_tag_dimindex'] && is_single() ) {
106
  $post_tags_list = rtrim($post_tags_list, ', ');
107
  if ( $post_tags_list ) {
108
  ?>
109
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_tag_dimindex']; ?>', '<?php echo esc_attr($post_tags_list); ?>');
110
  <?php
111
  }
112
  }
115
  $categories = get_the_category($post->ID);
116
  foreach ( $categories as $category ) {
117
  ?>
118
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr($category->name); ?>');
119
  <?php
120
  break;
121
  }
122
  }
123
  if ( $this->ga_tracking['wpmsga_user_dimindex'] ) {
124
  ?>
125
+ ga('set', 'dimension<?php echo (int) $this->ga_tracking ['wpmsga_user_dimindex']; ?>', '<?php echo is_user_logged_in() ? 'registered' : 'guest'; ?>');
126
  <?php
127
  }
128
  do_action('wpmsga_dash_addtrackingcode');
136
  window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
137
  <?php }?>
138
  </script>
139
+ <?php // phpcs:enable ?>
140
+
inc/google_analytics/tracking/custom.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
- /* Prohibit direct script loading */
3
- defined('ABSPATH') || die('No direct script access allowed!');
4
- ?>
5
- <script type="text/javascript">
6
- <?php
7
- if (!empty($this->ga_tracking['wpmsga_code_tracking'])) {
8
- echo $this->ga_tracking['wpmsga_code_tracking'];
9
- }
10
-
11
- ?>
12
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
inc/google_analytics/tracking/events-universal.php CHANGED
@@ -11,6 +11,7 @@
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
 
14
  ?>
15
  <script type="text/javascript">
16
  (function ($) {
@@ -37,7 +38,7 @@ $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
37
  //Track Outbound Links
38
  $('a[href^="http"]').filter(function () {
39
  if (!this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/)) {
40
- if (this.href.indexOf('<?php echo $domaindata['domain']; ?>') === -1) return this.href;
41
  }
42
  }).click(function () {
43
  ga('send', 'event', 'outbound', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
@@ -47,7 +48,6 @@ $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
47
  <?php } ?>
48
  <?php } ?>
49
  <?php if ($this->ga_tracking['wpmsga_event_affiliates'] && $this->ga_tracking['wpmsga_aff_tracking']){ ?>
50
-
51
  //Track Affiliates
52
  $('a').filter(function () {
53
  if ('<?php echo esc_js($this->ga_tracking['wpmsga_event_affiliates']);?>' !== '') {
@@ -63,7 +63,7 @@ $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
63
 
64
  //Track Hashmarks
65
  $('a').filter(function () {
66
- if (this.href.indexOf('<?php echo $domaindata['domain']; ?>') !== -1 || this.href.indexOf('://') === -1) return this.hash;
67
  }).click(function () {
68
  ga('send', 'event', 'hashmark', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
69
  echo ", {'nonInteraction': 1}";
@@ -74,3 +74,4 @@ $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
74
  });
75
  })(jQuery);
76
  </script>
 
11
  /* Prohibit direct script loading */
12
  defined('ABSPATH') || die('No direct script access allowed!');
13
  $domaindata = WpmsGaTools::getRootDomain(esc_html(get_option('siteurl')));
14
+ // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped, Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis, PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket, Squiz.WhiteSpace.ScopeClosingBrace.Indent, Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen, PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace, PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace, Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace, Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore, Generic.WhiteSpace.ScopeIndent.IncorrectExact -- Render google analytics script structure on frontend
15
  ?>
16
  <script type="text/javascript">
17
  (function ($) {
38
  //Track Outbound Links
39
  $('a[href^="http"]').filter(function () {
40
  if (!this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/)) {
41
+ if (this.href.indexOf('<?php echo esc_html($domaindata['domain']); ?>') === -1) return this.href;
42
  }
43
  }).click(function () {
44
  ga('send', 'event', 'outbound', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
48
  <?php } ?>
49
  <?php } ?>
50
  <?php if ($this->ga_tracking['wpmsga_event_affiliates'] && $this->ga_tracking['wpmsga_aff_tracking']){ ?>
 
51
  //Track Affiliates
52
  $('a').filter(function () {
53
  if ('<?php echo esc_js($this->ga_tracking['wpmsga_event_affiliates']);?>' !== '') {
63
 
64
  //Track Hashmarks
65
  $('a').filter(function () {
66
+ if (this.href.indexOf('<?php echo esc_html($domaindata['domain']); ?>') !== -1 || this.href.indexOf('://') === -1) return this.hash;
67
  }).click(function () {
68
  ga('send', 'event', 'hashmark', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
69
  echo ", {'nonInteraction': 1}";
74
  });
75
  })(jQuery);
76
  </script>
77
+ <?php // phpcs:enable ?>
inc/google_analytics/wpmsga.php CHANGED
@@ -12,26 +12,38 @@ if (!class_exists('WpmsGaManager')) {
12
  final class WpmsGaManager
13
  {
14
  /**
 
 
15
  * @var null
16
  */
17
  private static $instance = null;
18
  /**
 
 
19
  * @var null
20
  */
21
  public $config = null;
22
  /**
 
 
23
  * @var null
24
  */
25
  public $tracking = null;
26
  /**
 
 
27
  * @var null
28
  */
29
  public $frontend_item_reports = null;
30
  /**
 
 
31
  * @var null
32
  */
33
  public $backend_item_reports = null;
34
  /**
 
 
35
  * @var null
36
  */
37
  public $controller = null;
@@ -44,13 +56,15 @@ if (!class_exists('WpmsGaManager')) {
44
  if (null !== self::$instance) {
45
  _doing_it_wrong(
46
  __FUNCTION__,
47
- __("This is not allowed, please read the documentation!", 'wp-meta-seo'),
48
  '4.6'
49
  );
50
  }
51
  }
52
 
53
  /**
 
 
54
  * @return null|WpmsGaManager
55
  */
56
  public static function instance()
@@ -65,6 +79,8 @@ if (!class_exists('WpmsGaManager')) {
65
 
66
  /**
67
  * Returns a unique instance of WPMSGA
 
 
68
  */
69
  function WPMSGA()
70
  {
12
  final class WpmsGaManager
13
  {
14
  /**
15
+ * Instance
16
+ *
17
  * @var null
18
  */
19
  private static $instance = null;
20
  /**
21
+ * Config
22
+ *
23
  * @var null
24
  */
25
  public $config = null;
26
  /**
27
+ * Tracking
28
+ *
29
  * @var null
30
  */
31
  public $tracking = null;
32
  /**
33
+ * Frontend item reports
34
+ *
35
  * @var null
36
  */
37
  public $frontend_item_reports = null;
38
  /**
39
+ * Backend item reports
40
+ *
41
  * @var null
42
  */
43
  public $backend_item_reports = null;
44
  /**
45
+ * Controller
46
+ *
47
  * @var null
48
  */
49
  public $controller = null;
56
  if (null !== self::$instance) {
57
  _doing_it_wrong(
58
  __FUNCTION__,
59
+ esc_html__('This is not allowed, please read the documentation!', 'wp-meta-seo'),
60
  '4.6'
61
  );
62
  }
63
  }
64
 
65
  /**
66
+ * Instance
67
+ *
68
  * @return null|WpmsGaManager
69
  */
70
  public static function instance()
79
 
80
  /**
81
  * Returns a unique instance of WPMSGA
82
+ *
83
+ * @return null|WpmsGaManager
84
  */
85
  function WPMSGA()
86
  {
inc/google_analytics/wpmsgapi.php CHANGED
@@ -22,18 +22,26 @@ if (!class_exists('WpmsGapiController')) {
22
  class WpmsGapiController extends MetaSeoAdmin
23
  {
24
  /**
 
 
25
  * @var Google_Service_Analytics
26
  */
27
  public $service;
28
  /**
29
- * @var
 
 
30
  */
31
  public $timeshift;
32
  /**
 
 
33
  * @var string
34
  */
35
  private $managequota;
36
  /**
 
 
37
  * @var null|WpmsGaManager
38
  */
39
  private $wpmsga;
@@ -45,7 +53,7 @@ if (!class_exists('WpmsGapiController')) {
45
  {
46
  parent::__construct();
47
  $google_alanytics = get_option('wpms_google_alanytics');
48
- $this->wpmsga = WPMSGA();
49
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/autoload.php');
50
  $config = new Google_Config();
51
  $config->setCacheClass('Google_Cache_Null');
@@ -72,8 +80,8 @@ if (!class_exists('WpmsGapiController')) {
72
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
73
  $this->setErrorTimeout();
74
  $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
75
- $this->client = WpmsGaTools::setClient($this->client, $google_alanytics, $this->access);
76
- $this->service = new Google_Service_Analytics($this->client);
77
  if (!empty($google_alanytics['googleCredentials'])) {
78
  $token = $google_alanytics['googleCredentials'];
79
  if ($token) {
@@ -88,7 +96,7 @@ if (!class_exists('WpmsGapiController')) {
88
  } catch (Google_Service_Exception $e) {
89
  WpmsGaTools::setCache(
90
  'wpmsga_dash_lasterror',
91
- date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
92
  $this->error_timeout
93
  );
94
  WpmsGaTools::setCache(
@@ -121,17 +129,17 @@ if (!class_exists('WpmsGapiController')) {
121
  return false;
122
  }
123
  if (isset($errors[1][0]['reason'])
124
- && ($errors[1][0]['reason'] == 'invalidCredentials'
125
- || $errors[1][0]['reason'] == 'authError'
126
- || $errors[1][0]['reason'] == 'insufficientPermissions'
127
- || $errors[1][0]['reason'] == 'required'
128
- || $errors[1][0]['reason'] == 'keyExpired')) {
129
  $this->resetToken(false);
130
  return true;
131
  }
132
  if (isset($errors[1][0]['reason'])
133
- && ($errors[1][0]['reason'] == 'userRateLimitExceeded'
134
- || $errors[1][0]['reason'] == 'quotaExceeded')) {
135
  if ($this->wpmsga->config->options['api_backoff'] <= 5) {
136
  usleep(rand(100000, 1500000));
137
  return false;
@@ -139,7 +147,7 @@ if (!class_exists('WpmsGapiController')) {
139
  return true;
140
  }
141
  }
142
- if ($errors[0] == 400 || $errors[0] == 401 || $errors[0] == 403) {
143
  return true;
144
  }
145
  return false;
@@ -148,47 +156,50 @@ if (!class_exists('WpmsGapiController')) {
148
  /**
149
  * Calculates proper timeouts for each GAPI query
150
  *
151
- * @param
152
- * $daily
153
  * @return number
154
  */
155
  public function getTimeouts($daily)
156
  {
157
  $local_time = time() + $this->timeshift;
158
  if ($daily) {
159
- $nextday = explode('-', date('n-j-Y', strtotime(' +1 day', $local_time)));
160
  $midnight = mktime(0, 0, 0, $nextday[0], $nextday[1], $nextday[2]);
161
  return $midnight - $local_time;
162
  } else {
163
  $nexthour = explode('-', date('H-n-j-Y', strtotime(' +1 hour', $local_time)));
164
- $newhour = mktime($nexthour[0], 0, 0, $nexthour[1], $nexthour[2], $nexthour[3]);
165
  return $newhour - $local_time;
166
  }
167
  }
168
 
169
  /**
170
  * Handles the token reset process
171
- * @param bool $all
 
172
  */
173
- public function resetToken($all = true)
174
  {
175
  update_option('wpms_google_alanytics', array());
176
  }
177
 
178
  /**
179
  * Get and cache Core Reports
180
- * @param $projectId
181
- * @param $from
182
- * @param $to
183
- * @param $metrics
184
- * @param $options
185
- * @param $serial
186
- * @return bool|Google_Service_Analytics_GaData|int|mixed
 
 
187
  */
188
  private function handleCorereports($projectId, $from, $to, $metrics, $options, $serial)
189
  {
190
  try {
191
- if ($from == "today") {
192
  $timeouts = 0;
193
  } else {
194
  $timeouts = 1;
@@ -196,7 +207,7 @@ if (!class_exists('WpmsGapiController')) {
196
  $transient = WpmsGaTools::getCache($serial);
197
  if ($transient === false) {
198
  if ($this->gapiErrorsHandler()) {
199
- return -23;
200
  }
201
  $data = $this->service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, $options);
202
  WpmsGaTools::setCache($serial, $data, $this->getTimeouts($timeouts));
@@ -206,7 +217,7 @@ if (!class_exists('WpmsGapiController')) {
206
  } catch (Google_Service_Exception $e) {
207
  WpmsGaTools::setCache(
208
  'last_error',
209
- date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
210
  $this->error_timeout
211
  );
212
  WpmsGaTools::setCache(
@@ -222,78 +233,80 @@ if (!class_exists('WpmsGapiController')) {
222
  if ($data->getRows() > 0) {
223
  return $data;
224
  } else {
225
- return -21;
226
  }
227
  }
228
 
229
  /**
230
  * Generates serials for transients
231
  *
232
- * @param
233
- * $serial
234
  * @return string
235
  */
236
  public function getSerial($serial)
237
  {
238
- return sprintf("%u", crc32($serial));
239
  }
240
 
241
  /**
242
  * Analytics data for Area Charts (Admin Dashboard Widget report)
243
- * @param $projectId
244
- * @param $from
245
- * @param $to
246
- * @param $query
247
- * @param string $filter
248
- * @return array|int|string
 
 
249
  */
250
  private function getAreachartData($projectId, $from, $to, $query, $filter = '')
251
  {
252
  switch ($query) {
253
  case 'users':
254
- $title = __("Users", 'wp-meta-seo');
255
  break;
256
  case 'pageviews':
257
- $title = __("Page Views", 'wp-meta-seo');
258
  break;
259
  case 'visitBounceRate':
260
- $title = __("Bounce Rate", 'wp-meta-seo');
261
  break;
262
  case 'organicSearches':
263
- $title = __("Organic Searches", 'wp-meta-seo');
264
  break;
265
  case 'uniquePageviews':
266
- $title = __("Unique Page Views", 'wp-meta-seo');
267
  break;
268
  default:
269
- $title = __("Sessions", 'wp-meta-seo');
270
  }
271
  $metrics = 'ga:' . $query;
272
- if ($from == "today" || $from == "yesterday") {
273
  $dimensions = 'ga:hour';
274
- $dayorhour = __("Hour", 'wp-meta-seo');
275
- } elseif ($from == "365daysAgo" || $from == "1095daysAgo") {
276
  $dimensions = 'ga:yearMonth, ga:month';
277
- $dayorhour = __("Date", 'wp-meta-seo');
278
  } else {
279
  $dimensions = 'ga:date,ga:dayOfWeekName';
280
- $dayorhour = __("Date", 'wp-meta-seo');
281
  }
282
  $options = array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId);
283
  if ($filter) {
284
  $options['filters'] = 'ga:pagePath==' . $filter;
285
  }
286
  $serial = 'qr2_' . $this->getSerial($projectId . $from . $metrics . $filter);
287
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
288
  if (is_numeric($data)) {
289
  return $data;
290
  }
291
  $wpmsga_data = array(array($dayorhour, $title));
292
- if ($from == "today" || $from == "yesterday") {
293
  foreach ($data->getRows() as $row) {
294
- $wpmsga_data[] = array((int)$row[0] . ':00', round($row[1], 2));
295
  }
296
- } elseif ($from == "365daysAgo" || $from == "1095daysAgo") {
297
  foreach ($data->getRows() as $row) {
298
  /*
299
  * translators:
@@ -301,7 +314,7 @@ if (!class_exists('WpmsGapiController')) {
301
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
302
  */
303
  $wpmsga_data[] = array(
304
- date_i18n(__('F, Y', 'wp-meta-seo'), strtotime($row[0] . '01')),
305
  round($row[2], 2)
306
  );
307
  }
@@ -313,7 +326,7 @@ if (!class_exists('WpmsGapiController')) {
313
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
314
  */
315
  $wpmsga_data[] = array(
316
- date_i18n(__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])),
317
  round($row[2], 2)
318
  );
319
  }
@@ -324,25 +337,27 @@ if (!class_exists('WpmsGapiController')) {
324
 
325
  /**
326
  * Analytics data for Bottom Stats (bottom stats on main report)
327
- * @param $projectId
328
- * @param $from
329
- * @param $to
330
- * @param string $filter
331
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
332
  */
333
  private function getNottomstats($projectId, $from, $to, $filter = '')
334
  {
335
  $options = array('dimensions' => null, 'quotaUser' => $this->managequota . 'p' . $projectId);
336
  if ($filter) {
337
  $options['filters'] = 'ga:pagePath==' . $filter;
338
- $metrics = 'ga:uniquePageviews,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
339
  } else {
340
  $metrics = 'ga:sessions,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
341
  }
342
  $serial = 'qr3_' . $this->getSerial($projectId . $from . $filter);
343
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
344
  if (is_numeric($data)) {
345
- if ($data == -21) {
346
  return array_fill(0, 6, 0);
347
  } else {
348
  return $data;
@@ -366,52 +381,56 @@ if (!class_exists('WpmsGapiController')) {
366
 
367
  /**
368
  * Analytics data for Org Charts & Table Charts (content pages)
369
- * @param $projectId
370
- * @param $from
371
- * @param $to
372
- * @param string $filter
373
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
374
  */
375
  private function getContentPages($projectId, $from, $to, $filter = '')
376
  {
377
- $metrics = 'ga:pageviews';
378
  $dimensions = 'ga:pageTitle';
379
- $options = array(
380
  'dimensions' => $dimensions,
381
- 'sort' => '-ga:pageviews',
382
- 'quotaUser' => $this->managequota . 'p' . $projectId
383
  );
384
  if ($filter) {
385
  $options['filters'] = 'ga:pagePath==' . $filter;
386
  }
387
  $serial = 'qr4_' . $this->getSerial($projectId . $from . $filter);
388
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
389
  if (is_numeric($data)) {
390
  return $data;
391
  }
392
- $wpmsga_data = array(array(__("Pages", 'wp-meta-seo'), __("Views", 'wp-meta-seo')));
393
  foreach ($data->getRows() as $row) {
394
- $wpmsga_data[] = array(esc_html($row[0]), (int)$row[1]);
395
  }
396
  return $wpmsga_data;
397
  }
398
 
399
  /**
400
  * Analytics data for Org Charts & Table Charts (referrers)
401
- * @param $projectId
402
- * @param $from
403
- * @param $to
404
- * @param string $filter
405
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
406
  */
407
  private function getReferrers($projectId, $from, $to, $filter = '')
408
  {
409
- $metrics = 'ga:sessions';
410
  $dimensions = 'ga:source';
411
- $options = array(
412
  'dimensions' => $dimensions,
413
- 'sort' => '-ga:sessions',
414
- 'quotaUser' => $this->managequota . 'p' . $projectId
415
  );
416
  if ($filter) {
417
  $options['filters'] = 'ga:medium==referral;ga:pagePath==' . $filter;
@@ -419,33 +438,35 @@ if (!class_exists('WpmsGapiController')) {
419
  $options['filters'] = 'ga:medium==referral';
420
  }
421
  $serial = 'qr5_' . $this->getSerial($projectId . $from . $filter);
422
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
423
  if (is_numeric($data)) {
424
  return $data;
425
  }
426
- $wpmsga_data = array(array(__("Referrers", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
427
  foreach ($data->getRows() as $row) {
428
- $wpmsga_data[] = array(esc_html($row[0]), (int)$row[1]);
429
  }
430
  return $wpmsga_data;
431
  }
432
 
433
  /**
434
  * Analytics data for Org Charts & Table Charts (searches)
435
- * @param $projectId
436
- * @param $from
437
- * @param $to
438
- * @param string $filter
439
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
440
  */
441
  private function getSearches($projectId, $from, $to, $filter = '')
442
  {
443
- $metrics = 'ga:sessions';
444
  $dimensions = 'ga:keyword';
445
- $options = array(
446
  'dimensions' => $dimensions,
447
- 'sort' => '-ga:sessions',
448
- 'quotaUser' => $this->managequota . 'p' . $projectId
449
  );
450
  if ($filter) {
451
  $options['filters'] = 'ga:keyword!=(not set);ga:pagePath==' . $filter;
@@ -453,37 +474,39 @@ if (!class_exists('WpmsGapiController')) {
453
  $options['filters'] = 'ga:keyword!=(not set)';
454
  }
455
  $serial = 'qr6_' . $this->getSerial($projectId . $from . $filter);
456
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
457
  if (is_numeric($data)) {
458
  return $data;
459
  }
460
 
461
- $wpmsga_data = array(array(__("Searches", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
462
  foreach ($data->getRows() as $row) {
463
- $wpmsga_data[] = array(esc_html($row[0]), (int)$row[1]);
464
  }
465
  return $wpmsga_data;
466
  }
467
 
468
  /**
469
  * Analytics data for Org Charts & Table Charts (location reports)
470
- * @param $projectId
471
- * @param $from
472
- * @param $to
473
- * @param string $filter
474
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
475
  */
476
  private function getLocations($projectId, $from, $to, $filter = '')
477
  {
478
- $metrics = 'ga:sessions';
479
- $title = __("Countries", 'wp-meta-seo');
480
- $serial = 'qr7_' . $this->getSerial($projectId . $from . $filter);
481
- $dimensions = 'ga:country';
482
  $local_filter = '';
483
- $options = array(
484
  'dimensions' => $dimensions,
485
- 'sort' => '-ga:sessions',
486
- 'quotaUser' => $this->managequota . 'p' . $projectId
487
  );
488
  if ($filter) {
489
  $options['filters'] = 'ga:pagePath==' . $filter;
@@ -499,12 +522,12 @@ if (!class_exists('WpmsGapiController')) {
499
  if (is_numeric($data)) {
500
  return $data;
501
  }
502
- $wpmsga_data = array(array($title, __("Sessions", 'wp-meta-seo')));
503
  foreach ($data->getRows() as $row) {
504
  if (isset($row[2])) {
505
- $wpmsga_data[] = array(esc_html($row[0]) . ', ' . esc_html($row[1]), (int)$row[2]);
506
  } else {
507
- $wpmsga_data[] = array(esc_html($row[0]), (int)$row[1]);
508
  }
509
  }
510
  return $wpmsga_data;
@@ -512,45 +535,47 @@ if (!class_exists('WpmsGapiController')) {
512
 
513
  /**
514
  * Analytics data for Org Charts (traffic channels, device categories)
515
- * @param $projectId
516
- * @param $from
517
- * @param $to
518
- * @param $query
519
- * @param string $filter
520
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
521
  */
522
  private function getOrgchartData($projectId, $from, $to, $query, $filter = '')
523
  {
524
- $metrics = 'ga:sessions';
525
  $dimensions = 'ga:' . $query;
526
- $options = array(
527
  'dimensions' => $dimensions,
528
- 'sort' => '-ga:sessions',
529
- 'quotaUser' => $this->managequota . 'p' . $projectId
530
  );
531
  if ($filter) {
532
  $options['filters'] = 'ga:pagePath==' . $filter;
533
  }
534
  $serial = 'qr8_' . $this->getSerial($projectId . $from . $query . $filter);
535
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
536
  if (is_numeric($data)) {
537
  return $data;
538
  }
539
- $block = ($query == 'channelGrouping') ? __("Channels", 'wp-meta-seo') : __("Devices", 'wp-meta-seo');
540
  $wpmsga_data = array(
541
  array(
542
  '<div style="color:black; font-size:1.1em">' . $block . '</div>
543
- <div style="color:darkblue; font-size:1.2em">' . (int)$data['totalsForAllResults']["ga:sessions"] . '</div>',
544
- ""
545
  )
546
  );
547
  foreach ($data->getRows() as $row) {
548
- $shrink = explode(" ", $row[0]);
549
  $wpmsga_data[] = array(
550
  '<div style="color:black; font-size:1.1em">' . esc_html($shrink[0]) . '</div>
551
- <div style="color:darkblue; font-size:1.2em">' . (int)$row[1] . '</div>',
552
  '<div style="color:black; font-size:1.1em">' . $block . '</div>
553
- <div style="color:darkblue; font-size:1.2em">' . (int)$data['totalsForAllResults']["ga:sessions"] . '</div>'
554
  );
555
  }
556
  return $wpmsga_data;
@@ -559,23 +584,25 @@ if (!class_exists('WpmsGapiController')) {
559
  /**
560
  * Analytics data for Pie Charts (traffic mediums,
561
  * serach engines, social networks, browsers, screen rsolutions, etc.)
562
- * @param $projectId
563
- * @param $from
564
- * @param $to
565
- * @param $query
566
- * @param string $filter
567
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
568
  */
569
  private function getPiechartData($projectId, $from, $to, $query, $filter = '')
570
  {
571
- $metrics = 'ga:sessions';
572
  $dimensions = 'ga:' . $query;
573
 
574
- if ($query == 'source') {
575
  $options = array(
576
  'dimensions' => $dimensions,
577
- 'sort' => '-ga:sessions',
578
- 'quotaUser' => $this->managequota . 'p' . $projectId
579
  );
580
  if ($filter) {
581
  $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set);ga:pagePath==' . $filter;
@@ -585,8 +612,8 @@ if (!class_exists('WpmsGapiController')) {
585
  } else {
586
  $options = array(
587
  'dimensions' => $dimensions,
588
- 'sort' => '-ga:sessions',
589
- 'quotaUser' => $this->managequota . 'p' . $projectId
590
  );
591
  if ($filter) {
592
  $options['filters'] = 'ga:' . $query . '!=(not set);ga:pagePath==' . $filter;
@@ -595,18 +622,18 @@ if (!class_exists('WpmsGapiController')) {
595
  }
596
  }
597
  $serial = 'qr10_' . $this->getSerial($projectId . $from . $query . $filter);
598
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
599
  if (is_numeric($data)) {
600
  return $data;
601
  }
602
- $wpmsga_data = array(array(__("Type", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
603
- $i = 0;
604
- $included = 0;
605
  foreach ($data->getRows() as $row) {
606
  if ($i < 20) {
607
- $wpmsga_data[] = array(str_replace("(none)", "direct", esc_html($row[0])), (int)$row[1]);
608
- $included += $row[1];
609
- $i++;
610
  } else {
611
  break;
612
  }
@@ -614,7 +641,7 @@ if (!class_exists('WpmsGapiController')) {
614
  $totals = $data->getTotalsForAllResults();
615
  $others = $totals['ga:sessions'] - $included;
616
  if ($others > 0) {
617
- $wpmsga_data[] = array(__('Other', 'wp-meta-seo'), $others);
618
  }
619
 
620
  return $wpmsga_data;
@@ -622,25 +649,27 @@ if (!class_exists('WpmsGapiController')) {
622
 
623
  /**
624
  * Analytics data for Frontend Widget (chart data and totals)
625
- * @param $projectId
626
- * @param $from
627
- * @param $anonim
628
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
629
  */
630
  public function frontendWidgetStats($projectId, $from, $anonim)
631
  {
632
- $content = '';
633
- $to = 'yesterday';
634
- $metrics = 'ga:sessions';
635
  $dimensions = 'ga:date,ga:dayOfWeekName';
636
- $options = array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId);
637
- $serial = 'qr2_' . $this->getSerial($projectId . $from . $metrics);
638
- $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
639
  if (is_numeric($data)) {
640
  return $data;
641
  }
642
- $wpmsga_data = array(array(__("Date", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
643
- $max = 1;
644
  if ($anonim) {
645
  $max_array = array();
646
  foreach ($data->getRows() as $item) {
@@ -650,8 +679,8 @@ if (!class_exists('WpmsGapiController')) {
650
  }
651
  foreach ($data->getRows() as $row) {
652
  $wpmsga_data[] = array(
653
- date_i18n(__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])),
654
- ($anonim ? round($row[2] * 100 / $max, 2) : (int)$row[2])
655
  );
656
  }
657
  $totals = $data->getTotalsForAllResults();
@@ -660,26 +689,28 @@ if (!class_exists('WpmsGapiController')) {
660
 
661
  /**
662
  * Analytics data for Realtime component (the real-time report)
663
- * @param $projectId
664
- * @return array|int|mixed
 
 
665
  */
666
  private function getRealtime($projectId)
667
  {
668
- $metrics = 'rt:activeUsers';
669
  $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
670
  try {
671
- $serial = 'qr_realtimecache_' . $this->getSerial($projectId);
672
  $transient = WpmsGaTools::getCache($serial);
673
  if ($transient === false) {
674
  if ($this->gapiErrorsHandler()) {
675
- return -23;
676
  }
677
  $data = $this->service->data_realtime->get(
678
  'ga:' . $projectId,
679
  $metrics,
680
  array(
681
  'dimensions' => $dimensions,
682
- 'quotaUser' => $this->managequota . 'p' . $projectId
683
  )
684
  );
685
  WpmsGaTools::setCache($serial, $data, 55);
@@ -689,7 +720,7 @@ if (!class_exists('WpmsGapiController')) {
689
  } catch (Google_Service_Exception $e) {
690
  WpmsGaTools::setCache(
691
  'last_error',
692
- date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
693
  $this->error_timeout
694
  );
695
  WpmsGaTools::setCache(
@@ -707,30 +738,32 @@ if (!class_exists('WpmsGapiController')) {
707
  return $e->getCode();
708
  }
709
  if ($data->getRows() < 1) {
710
- return -21;
711
  }
712
- $i = 0;
713
  $wpmsga_data = $data;
714
  foreach ($data->getRows() as $row) {
715
  $wpmsga_data->rows[$i] = array_map('esc_html', $row);
716
- $i++;
717
  }
718
  return array($wpmsga_data);
719
  }
720
 
721
  /**
722
  * Handles ajax requests and calls the needed methods
723
- * @param $projectId
724
- * @param $query
725
- * @param bool $from
726
- * @param bool $to
727
- * @param string $filter
728
- * @return array|bool|Google_Service_Analytics_GaData|int|mixed
 
 
729
  */
730
  public function get($projectId, $query, $from = false, $to = false, $filter = '')
731
  {
732
  if (empty($projectId) || !is_numeric($projectId)) {
733
- wp_die(-26);
734
  }
735
 
736
  $groups = array(
@@ -744,25 +777,25 @@ if (!class_exists('WpmsGapiController')) {
744
  if (in_array($query, $groups)) {
745
  return $this->getAreachartData($projectId, $from, $to, $query, $filter);
746
  }
747
- if ($query == 'bottomstats') {
748
  return $this->getNottomstats($projectId, $from, $to, $filter);
749
  }
750
- if ($query == 'locations') {
751
  return $this->getLocations($projectId, $from, $to, $filter);
752
  }
753
- if ($query == 'referrers') {
754
  return $this->getReferrers($projectId, $from, $to, $filter);
755
  }
756
- if ($query == 'contentpages') {
757
  return $this->getContentPages($projectId, $from, $to, $filter);
758
  }
759
- if ($query == 'searches') {
760
  return $this->getSearches($projectId, $from, $to, $filter);
761
  }
762
- if ($query == 'realtime') {
763
  return $this->getRealtime($projectId);
764
  }
765
- if ($query == 'channelGrouping' || $query == 'deviceCategory') {
766
  return $this->getOrgchartData($projectId, $from, $to, $query, $filter);
767
  }
768
 
@@ -779,7 +812,7 @@ if (!class_exists('WpmsGapiController')) {
779
  if (in_array($query, $arrs)) {
780
  return $this->getPiechartData($projectId, $from, $to, $query, $filter);
781
  }
782
- wp_die(-27);
783
  }
784
  }
785
  }
22
  class WpmsGapiController extends MetaSeoAdmin
23
  {
24
  /**
25
+ * Google service analytics
26
+ *
27
  * @var Google_Service_Analytics
28
  */
29
  public $service;
30
  /**
31
+ * Time shift
32
+ *
33
+ * @var null
34
  */
35
  public $timeshift;
36
  /**
37
+ * Managequota
38
+ *
39
  * @var string
40
  */
41
  private $managequota;
42
  /**
43
+ * Google analytics manager
44
+ *
45
  * @var null|WpmsGaManager
46
  */
47
  private $wpmsga;
53
  {
54
  parent::__construct();
55
  $google_alanytics = get_option('wpms_google_alanytics');
56
+ $this->wpmsga = WPMSGA();
57
  include_once(WPMETASEO_PLUGIN_DIR . 'inc/autoload.php');
58
  $config = new Google_Config();
59
  $config->setCacheClass('Google_Cache_Null');
80
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
81
  $this->setErrorTimeout();
82
  $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
83
+ $this->client = WpmsGaTools::setClient($this->client, $google_alanytics, $this->access);
84
+ $this->service = new Google_Service_Analytics($this->client);
85
  if (!empty($google_alanytics['googleCredentials'])) {
86
  $token = $google_alanytics['googleCredentials'];
87
  if ($token) {
96
  } catch (Google_Service_Exception $e) {
97
  WpmsGaTools::setCache(
98
  'wpmsga_dash_lasterror',
99
+ date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
100
  $this->error_timeout
101
  );
102
  WpmsGaTools::setCache(
129
  return false;
130
  }
131
  if (isset($errors[1][0]['reason'])
132
+ && ($errors[1][0]['reason'] === 'invalidCredentials'
133
+ || $errors[1][0]['reason'] === 'authError'
134
+ || $errors[1][0]['reason'] === 'insufficientPermissions'
135
+ || $errors[1][0]['reason'] === 'required'
136
+ || $errors[1][0]['reason'] === 'keyExpired')) {
137
  $this->resetToken(false);
138
  return true;
139
  }
140
  if (isset($errors[1][0]['reason'])
141
+ && ($errors[1][0]['reason'] === 'userRateLimitExceeded'
142
+ || $errors[1][0]['reason'] === 'quotaExceeded')) {
143
  if ($this->wpmsga->config->options['api_backoff'] <= 5) {
144
  usleep(rand(100000, 1500000));
145
  return false;
147
  return true;
148
  }
149
  }
150
+ if ((int) $errors[0] === 400 || (int) $errors[0] === 401 || (int) $errors[0] === 403) {
151
  return true;
152
  }
153
  return false;
156
  /**
157
  * Calculates proper timeouts for each GAPI query
158
  *
159
+ * @param string $daily Timeout
160
+ *
161
  * @return number
162
  */
163
  public function getTimeouts($daily)
164
  {
165
  $local_time = time() + $this->timeshift;
166
  if ($daily) {
167
+ $nextday = explode('-', date('n-j-Y', strtotime(' +1 day', $local_time)));
168
  $midnight = mktime(0, 0, 0, $nextday[0], $nextday[1], $nextday[2]);
169
  return $midnight - $local_time;
170
  } else {
171
  $nexthour = explode('-', date('H-n-j-Y', strtotime(' +1 hour', $local_time)));
172
+ $newhour = mktime($nexthour[0], 0, 0, $nexthour[1], $nexthour[2], $nexthour[3]);
173
  return $newhour - $local_time;
174
  }
175
  }
176
 
177
  /**
178
  * Handles the token reset process
179
+ *
180
+ * @return void
181
  */
182
+ public function resetToken()
183
  {
184
  update_option('wpms_google_alanytics', array());
185
  }
186
 
187
  /**
188
  * Get and cache Core Reports
189
+ *
190
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
191
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
192
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
193
+ * @param string $metrics A comma-separated list of Analytics metrics.
194
+ * @param array $options Optional parameters.
195
+ * @param string $serial Serial
196
+ *
197
+ * @return boolean|Google_Service_Analytics_GaData|int|mixed
198
  */
199
  private function handleCorereports($projectId, $from, $to, $metrics, $options, $serial)
200
  {
201
  try {
202
+ if ($from === 'today') {
203
  $timeouts = 0;
204
  } else {
205
  $timeouts = 1;
207
  $transient = WpmsGaTools::getCache($serial);
208
  if ($transient === false) {
209
  if ($this->gapiErrorsHandler()) {
210
+ return - 23;
211
  }
212
  $data = $this->service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, $options);
213
  WpmsGaTools::setCache($serial, $data, $this->getTimeouts($timeouts));
217
  } catch (Google_Service_Exception $e) {
218
  WpmsGaTools::setCache(
219
  'last_error',
220
+ date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
221
  $this->error_timeout
222
  );
223
  WpmsGaTools::setCache(
233
  if ($data->getRows() > 0) {
234
  return $data;
235
  } else {
236
+ return - 21;
237
  }
238
  }
239
 
240
  /**
241
  * Generates serials for transients
242
  *
243
+ * @param string $serial Serial
244
+ *
245
  * @return string
246
  */
247
  public function getSerial($serial)
248
  {
249
+ return sprintf('%u', crc32($serial));
250
  }
251
 
252
  /**
253
  * Analytics data for Area Charts (Admin Dashboard Widget report)
254
+ *
255
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
256
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
257
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
258
+ * @param string $query Query
259
+ * @param string $filter Filter
260
+ *
261
+ * @return array|integer|string
262
  */
263
  private function getAreachartData($projectId, $from, $to, $query, $filter = '')
264
  {
265
  switch ($query) {
266
  case 'users':
267
+ $title = esc_html__('Users', 'wp-meta-seo');
268
  break;
269
  case 'pageviews':
270
+ $title = esc_html__('Page Views', 'wp-meta-seo');
271
  break;
272
  case 'visitBounceRate':
273
+ $title = esc_html__('Bounce Rate', 'wp-meta-seo');
274
  break;
275
  case 'organicSearches':
276
+ $title = esc_html__('Organic Searches', 'wp-meta-seo');
277
  break;
278
  case 'uniquePageviews':
279
+ $title = esc_html__('Unique Page Views', 'wp-meta-seo');
280
  break;
281
  default:
282
+ $title = esc_html__('Sessions', 'wp-meta-seo');
283
  }
284
  $metrics = 'ga:' . $query;
285
+ if ($from === 'today' || $from === 'yesterday') {
286
  $dimensions = 'ga:hour';
287
+ $dayorhour = esc_html__('Hour', 'wp-meta-seo');
288
+ } elseif ($from === '365daysAgo' || $from === '1095daysAgo') {
289
  $dimensions = 'ga:yearMonth, ga:month';
290
+ $dayorhour = esc_html__('Date', 'wp-meta-seo');
291
  } else {
292
  $dimensions = 'ga:date,ga:dayOfWeekName';
293
+ $dayorhour = esc_html__('Date', 'wp-meta-seo');
294
  }
295
  $options = array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId);
296
  if ($filter) {
297
  $options['filters'] = 'ga:pagePath==' . $filter;
298
  }
299
  $serial = 'qr2_' . $this->getSerial($projectId . $from . $metrics . $filter);
300
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
301
  if (is_numeric($data)) {
302
  return $data;
303
  }
304
  $wpmsga_data = array(array($dayorhour, $title));
305
+ if ($from === 'today' || $from === 'yesterday') {
306
  foreach ($data->getRows() as $row) {
307
+ $wpmsga_data[] = array((int) $row[0] . ':00', round($row[1], 2));
308
  }
309
+ } elseif ($from === '365daysAgo' || $from === '1095daysAgo') {
310
  foreach ($data->getRows() as $row) {
311
  /*
312
  * translators:
314
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
315
  */
316
  $wpmsga_data[] = array(
317
+ date_i18n(esc_html__('F, Y', 'wp-meta-seo'), strtotime($row[0] . '01')),
318
  round($row[2], 2)
319
  );
320
  }
326
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
327
  */
328
  $wpmsga_data[] = array(
329
+ date_i18n(esc_html__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])),
330
  round($row[2], 2)
331
  );
332
  }
337
 
338
  /**
339
  * Analytics data for Bottom Stats (bottom stats on main report)
340
+ *
341
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
342
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
343
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
344
+ * @param string $filter Filter
345
+ *
346
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
347
  */
348
  private function getNottomstats($projectId, $from, $to, $filter = '')
349
  {
350
  $options = array('dimensions' => null, 'quotaUser' => $this->managequota . 'p' . $projectId);
351
  if ($filter) {
352
  $options['filters'] = 'ga:pagePath==' . $filter;
353
+ $metrics = 'ga:uniquePageviews,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
354
  } else {
355
  $metrics = 'ga:sessions,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
356
  }
357
  $serial = 'qr3_' . $this->getSerial($projectId . $from . $filter);
358
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
359
  if (is_numeric($data)) {
360
+ if ((int) $data === - 21) {
361
  return array_fill(0, 6, 0);
362
  } else {
363
  return $data;
381
 
382
  /**
383
  * Analytics data for Org Charts & Table Charts (content pages)
384
+ *
385
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
386
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
387
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
388
+ * @param string $filter Filter
389
+ *
390
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
391
  */
392
  private function getContentPages($projectId, $from, $to, $filter = '')
393
  {
394
+ $metrics = 'ga:pageviews';
395
  $dimensions = 'ga:pageTitle';
396
+ $options = array(
397
  'dimensions' => $dimensions,
398
+ 'sort' => '-ga:pageviews',
399
+ 'quotaUser' => $this->managequota . 'p' . $projectId
400
  );
401
  if ($filter) {
402
  $options['filters'] = 'ga:pagePath==' . $filter;
403
  }
404
  $serial = 'qr4_' . $this->getSerial($projectId . $from . $filter);
405
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
406
  if (is_numeric($data)) {
407
  return $data;
408
  }
409
+ $wpmsga_data = array(array(esc_html__('Pages', 'wp-meta-seo'), esc_html__('Views', 'wp-meta-seo')));
410
  foreach ($data->getRows() as $row) {
411
+ $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
412
  }
413
  return $wpmsga_data;
414
  }
415
 
416
  /**
417
  * Analytics data for Org Charts & Table Charts (referrers)
418
+ *
419
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
420
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
421
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
422
+ * @param string $filter Filter
423
+ *
424
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
425
  */
426
  private function getReferrers($projectId, $from, $to, $filter = '')
427
  {
428
+ $metrics = 'ga:sessions';
429
  $dimensions = 'ga:source';
430
+ $options = array(
431
  'dimensions' => $dimensions,
432
+ 'sort' => '-ga:sessions',
433
+ 'quotaUser' => $this->managequota . 'p' . $projectId
434
  );
435
  if ($filter) {
436
  $options['filters'] = 'ga:medium==referral;ga:pagePath==' . $filter;
438
  $options['filters'] = 'ga:medium==referral';
439
  }
440
  $serial = 'qr5_' . $this->getSerial($projectId . $from . $filter);
441
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
442
  if (is_numeric($data)) {
443
  return $data;
444
  }
445
+ $wpmsga_data = array(array(esc_html__('Referrers', 'wp-meta-seo'), esc_html__('Sessions', 'wp-meta-seo')));
446
  foreach ($data->getRows() as $row) {
447
+ $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
448
  }
449
  return $wpmsga_data;
450
  }
451
 
452
  /**
453
  * Analytics data for Org Charts & Table Charts (searches)
454
+ *
455
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
456
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
457
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
458
+ * @param string $filter Filter
459
+ *
460
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
461
  */
462
  private function getSearches($projectId, $from, $to, $filter = '')
463
  {
464
+ $metrics = 'ga:sessions';
465
  $dimensions = 'ga:keyword';
466
+ $options = array(
467
  'dimensions' => $dimensions,
468
+ 'sort' => '-ga:sessions',
469
+ 'quotaUser' => $this->managequota . 'p' . $projectId
470
  );
471
  if ($filter) {
472
  $options['filters'] = 'ga:keyword!=(not set);ga:pagePath==' . $filter;
474
  $options['filters'] = 'ga:keyword!=(not set)';
475
  }
476
  $serial = 'qr6_' . $this->getSerial($projectId . $from . $filter);
477
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
478
  if (is_numeric($data)) {
479
  return $data;
480
  }
481
 
482
+ $wpmsga_data = array(array(esc_html__('Searches', 'wp-meta-seo'), esc_html__('Sessions', 'wp-meta-seo')));
483
  foreach ($data->getRows() as $row) {
484
+ $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
485
  }
486
  return $wpmsga_data;
487
  }
488
 
489
  /**
490
  * Analytics data for Org Charts & Table Charts (location reports)
491
+ *
492
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
493
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
494
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
495
+ * @param string $filter Filter
496
+ *
497
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
498
  */
499
  private function getLocations($projectId, $from, $to, $filter = '')
500
  {
501
+ $metrics = 'ga:sessions';
502
+ $title = esc_html__('Countries', 'wp-meta-seo');
503
+ $serial = 'qr7_' . $this->getSerial($projectId . $from . $filter);
504
+ $dimensions = 'ga:country';
505
  $local_filter = '';
506
+ $options = array(
507
  'dimensions' => $dimensions,
508
+ 'sort' => '-ga:sessions',
509
+ 'quotaUser' => $this->managequota . 'p' . $projectId
510
  );
511
  if ($filter) {
512
  $options['filters'] = 'ga:pagePath==' . $filter;
522
  if (is_numeric($data)) {
523
  return $data;
524
  }
525
+ $wpmsga_data = array(array($title, esc_html__('Sessions', 'wp-meta-seo')));
526
  foreach ($data->getRows() as $row) {
527
  if (isset($row[2])) {
528
+ $wpmsga_data[] = array(esc_html($row[0]) . ', ' . esc_html($row[1]), (int) $row[2]);
529
  } else {
530
+ $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
531
  }
532
  }
533
  return $wpmsga_data;
535
 
536
  /**
537
  * Analytics data for Org Charts (traffic channels, device categories)
538
+ *
539
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
540
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
541
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
542
+ * @param string $query Query
543
+ * @param string $filter Filter
544
+ *
545
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
546
  */
547
  private function getOrgchartData($projectId, $from, $to, $query, $filter = '')
548
  {
549
+ $metrics = 'ga:sessions';
550
  $dimensions = 'ga:' . $query;
551
+ $options = array(
552
  'dimensions' => $dimensions,
553
+ 'sort' => '-ga:sessions',
554
+ 'quotaUser' => $this->managequota . 'p' . $projectId
555
  );
556
  if ($filter) {
557
  $options['filters'] = 'ga:pagePath==' . $filter;
558
  }
559
  $serial = 'qr8_' . $this->getSerial($projectId . $from . $query . $filter);
560
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
561
  if (is_numeric($data)) {
562
  return $data;
563
  }
564
+ $block = ($query === 'channelGrouping') ? esc_html__('Channels', 'wp-meta-seo') : esc_html__('Devices', 'wp-meta-seo');
565
  $wpmsga_data = array(
566
  array(
567
  '<div style="color:black; font-size:1.1em">' . $block . '</div>
568
+ <div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']['ga:sessions'] . '</div>',
569
+ ''
570
  )
571
  );
572
  foreach ($data->getRows() as $row) {
573
+ $shrink = explode(' ', $row[0]);
574
  $wpmsga_data[] = array(
575
  '<div style="color:black; font-size:1.1em">' . esc_html($shrink[0]) . '</div>
576
+ <div style="color:darkblue; font-size:1.2em">' . (int) esc_html($row[1]) . '</div>',
577
  '<div style="color:black; font-size:1.1em">' . $block . '</div>
578
+ <div style="color:darkblue; font-size:1.2em">' . (int) esc_html($data['totalsForAllResults']['ga:sessions']) . '</div>'
579
  );
580
  }
581
  return $wpmsga_data;
584
  /**
585
  * Analytics data for Pie Charts (traffic mediums,
586
  * serach engines, social networks, browsers, screen rsolutions, etc.)
587
+ *
588
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
589
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
590
+ * @param string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
591
+ * @param string $query Query
592
+ * @param string $filter Filter
593
+ *
594
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
595
  */
596
  private function getPiechartData($projectId, $from, $to, $query, $filter = '')
597
  {
598
+ $metrics = 'ga:sessions';
599
  $dimensions = 'ga:' . $query;
600
 
601
+ if ($query === 'source') {
602
  $options = array(
603
  'dimensions' => $dimensions,
604
+ 'sort' => '-ga:sessions',
605
+ 'quotaUser' => $this->managequota . 'p' . $projectId
606
  );
607
  if ($filter) {
608
  $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set);ga:pagePath==' . $filter;
612
  } else {
613
  $options = array(
614
  'dimensions' => $dimensions,
615
+ 'sort' => '-ga:sessions',
616
+ 'quotaUser' => $this->managequota . 'p' . $projectId
617
  );
618
  if ($filter) {
619
  $options['filters'] = 'ga:' . $query . '!=(not set);ga:pagePath==' . $filter;
622
  }
623
  }
624
  $serial = 'qr10_' . $this->getSerial($projectId . $from . $query . $filter);
625
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
626
  if (is_numeric($data)) {
627
  return $data;
628
  }
629
+ $wpmsga_data = array(array(esc_html__('Type', 'wp-meta-seo'), esc_html__('Sessions', 'wp-meta-seo')));
630
+ $i = 0;
631
+ $included = 0;
632
  foreach ($data->getRows() as $row) {
633
  if ($i < 20) {
634
+ $wpmsga_data[] = array(str_replace('(none)', 'direct', esc_html($row[0])), (int) $row[1]);
635
+ $included += $row[1];
636
+ $i ++;
637
  } else {
638
  break;
639
  }
641
  $totals = $data->getTotalsForAllResults();
642
  $others = $totals['ga:sessions'] - $included;
643
  if ($others > 0) {
644
+ $wpmsga_data[] = array(esc_html__('Other', 'wp-meta-seo'), $others);
645
  }
646
 
647
  return $wpmsga_data;
649
 
650
  /**
651
  * Analytics data for Frontend Widget (chart data and totals)
652
+ *
653
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
654
+ * @param string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
655
+ * @param string $anonim Anonim
656
+ *
657
+ * @return array|boolean|Google_Service_Analytics_GaData|integer|mixed
658
  */
659
  public function frontendWidgetStats($projectId, $from, $anonim)
660
  {
661
+ $content = '';
662
+ $to = 'yesterday';
663
+ $metrics = 'ga:sessions';
664
  $dimensions = 'ga:date,ga:dayOfWeekName';
665
+ $options = array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId);
666
+ $serial = 'qr2_' . $this->getSerial($projectId . $from . $metrics);
667
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
668
  if (is_numeric($data)) {
669
  return $data;
670
  }
671
+ $wpmsga_data = array(array(esc_html__('Date', 'wp-meta-seo'), esc_html__('Sessions', 'wp-meta-seo')));
672
+ $max = 1;
673
  if ($anonim) {
674
  $max_array = array();
675
  foreach ($data->getRows() as $item) {
679
  }
680
  foreach ($data->getRows() as $row) {
681
  $wpmsga_data[] = array(
682
+ date_i18n(esc_html__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])),
683
+ ($anonim ? round($row[2] * 100 / $max, 2) : (int) $row[2])
684
  );
685
  }
686
  $totals = $data->getTotalsForAllResults();
689
 
690
  /**
691
  * Analytics data for Realtime component (the real-time report)
692
+ *
693
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
694
+ *
695
+ * @return array|integer|mixed
696
  */
697
  private function getRealtime($projectId)
698
  {
699
+ $metrics = 'rt:activeUsers';
700
  $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
701
  try {
702
+ $serial = 'qr_realtimecache_' . $this->getSerial($projectId);
703
  $transient = WpmsGaTools::getCache($serial);
704
  if ($transient === false) {
705
  if ($this->gapiErrorsHandler()) {
706
+ return - 23;
707
  }
708
  $data = $this->service->data_realtime->get(
709
  'ga:' . $projectId,
710
  $metrics,
711
  array(
712
  'dimensions' => $dimensions,
713
+ 'quotaUser' => $this->managequota . 'p' . $projectId
714
  )
715
  );
716
  WpmsGaTools::setCache($serial, $data, 55);
720
  } catch (Google_Service_Exception $e) {
721
  WpmsGaTools::setCache(
722
  'last_error',
723
+ date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()),
724
  $this->error_timeout
725
  );
726
  WpmsGaTools::setCache(
738
  return $e->getCode();
739
  }
740
  if ($data->getRows() < 1) {
741
+ return - 21;
742
  }
743
+ $i = 0;
744
  $wpmsga_data = $data;
745
  foreach ($data->getRows() as $row) {
746
  $wpmsga_data->rows[$i] = array_map('esc_html', $row);
747
+ $i ++;
748
  }
749
  return array($wpmsga_data);
750
  }
751
 
752
  /**
753
  * Handles ajax requests and calls the needed methods
754
+ *
755
+ * @param string $projectId Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile)
756
+ * @param string $query QueryID.
757
+ * @param boolean|string $from Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date
758
+ * @param boolean|string $to End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM-DD, or as a relative date
759
+ * @param string $filter Filter
760
+ *
761
+ * @return array|boolean|Google_Service_Analytics_GaData|int|mixed
762
  */
763
  public function get($projectId, $query, $from = false, $to = false, $filter = '')
764
  {
765
  if (empty($projectId) || !is_numeric($projectId)) {
766
+ wp_die(- 26);
767
  }
768
 
769
  $groups = array(
777
  if (in_array($query, $groups)) {
778
  return $this->getAreachartData($projectId, $from, $to, $query, $filter);
779
  }
780
+ if ($query === 'bottomstats') {
781
  return $this->getNottomstats($projectId, $from, $to, $filter);
782
  }
783
+ if ($query === 'locations') {
784
  return $this->getLocations($projectId, $from, $to, $filter);
785
  }
786
+ if ($query === 'referrers') {
787
  return $this->getReferrers($projectId, $from, $to, $filter);
788
  }
789
+ if ($query === 'contentpages') {
790
  return $this->getContentPages($projectId, $from, $to, $filter);
791
  }
792
+ if ($query === 'searches') {
793
  return $this->getSearches($projectId, $from, $to, $filter);
794
  }
795
+ if ($query === 'realtime') {
796
  return $this->getRealtime($projectId);
797
  }
798
+ if ($query === 'channelGrouping' || $query === 'deviceCategory') {
799
  return $this->getOrgchartData($projectId, $from, $to, $query, $filter);
800
  }
801
 
812
  if (in_array($query, $arrs)) {
813
  return $this->getPiechartData($projectId, $from, $to, $query, $filter);
814
  }
815
+ wp_die(- 27);
816
  }
817
  }
818
  }
inc/google_analytics/wpmstools.php CHANGED
@@ -20,15 +20,17 @@ if (!class_exists('WpmsGaTools')) {
20
  class WpmsGaTools
21
  {
22
  /**
23
- * get google analytics client
24
- * @param object $client google analytics client
25
- * @param array $access access info to connect
26
- * @param array $access_default access default info to connect
 
 
27
  * @return mixed
28
  */
29
  public static function setClient($client, $access, $access_default)
30
  {
31
- if (isset($access['wpmsga_dash_userapi']) && $access['wpmsga_dash_userapi'] == 1) {
32
  if (!empty($access['wpmsga_dash_clientid']) && !empty($access['wpmsga_dash_clientsecret'])) {
33
  $client->setClientId($access['wpmsga_dash_clientid']);
34
  $client->setClientSecret($access['wpmsga_dash_clientsecret']);
@@ -45,16 +47,18 @@ if (!class_exists('WpmsGaTools')) {
45
  }
46
 
47
  /**
48
- * get selected profile
49
- * @param array $profiles list profiles
50
- * @param string $profile selected profile
51
- * @return bool
 
 
52
  */
53
  public static function getSelectedProfile($profiles, $profile)
54
  {
55
  if (!empty($profiles)) {
56
  foreach ($profiles as $item) {
57
- if ($item[1] == $profile) {
58
  return $item;
59
  }
60
  }
@@ -63,29 +67,31 @@ if (!class_exists('WpmsGaTools')) {
63
  }
64
 
65
  /**
66
- * get color
67
- * @param $colour
68
- * @param $per
 
 
69
  * @return string
70
  */
71
  public static function colourVariator($colour, $per)
72
  {
73
  $colour = substr($colour, 1);
74
- $rgb = '';
75
- $per = $per / 100 * 255;
76
  if ($per < 0) {
77
  // Darker
78
  $per = abs($per);
79
- for ($x = 0; $x < 3; $x++) {
80
- $c = hexdec(substr($colour, (2 * $x), 2)) - $per;
81
- $c = ($c < 0) ? 0 : dechex($c);
82
  $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
83
  }
84
  } else {
85
  // Lighter
86
- for ($x = 0; $x < 3; $x++) {
87
- $c = hexdec(substr($colour, (2 * $x), 2)) + $per;
88
- $c = ($c > 255) ? 'ff' : dechex($c);
89
  $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
90
  }
91
  }
@@ -93,32 +99,37 @@ if (!class_exists('WpmsGaTools')) {
93
  }
94
 
95
  /**
96
- * @param $base
 
 
 
97
  * @return array
98
  */
99
  public static function variations($base)
100
  {
101
  $variations[] = $base;
102
- $variations[] = self::colourVariator($base, -10);
103
- $variations[] = self::colourVariator($base, +10);
104
- $variations[] = self::colourVariator($base, +20);
105
- $variations[] = self::colourVariator($base, -20);
106
- $variations[] = self::colourVariator($base, +30);
107
- $variations[] = self::colourVariator($base, -30);
108
  return $variations;
109
  }
110
 
111
  /**
112
- * check roles
113
- * @param array $access_level access level
114
- * @param bool $tracking
115
- * @return bool
 
 
116
  */
117
  public static function checkRoles($access_level, $tracking = false)
118
  {
119
  if (is_user_logged_in() && isset($access_level)) {
120
  $current_user = wp_get_current_user();
121
- $roles = (array)$current_user->roles;
122
  if ((current_user_can('manage_options')) && !$tracking) {
123
  return true;
124
  }
@@ -132,20 +143,26 @@ if (!class_exists('WpmsGaTools')) {
132
  }
133
 
134
  /**
135
- * set cache
136
- * @param string $name option cache name
137
- * @param string $value option cache value
138
- * @param int $expiration
 
 
 
139
  */
140
  public static function setCache($name, $value, $expiration = 0)
141
  {
142
- $option = array('value' => $value, 'expires' => time() + (int)$expiration);
143
  update_option('wpmsga_cache_' . $name, $option);
144
  }
145
 
146
  /**
147
- * remove cache
148
- * @param string $name option cache name
 
 
 
149
  */
150
  public static function deleteCache($name)
151
  {
@@ -153,9 +170,11 @@ if (!class_exists('WpmsGaTools')) {
153
  }
154
 
155
  /**
156
- * get cache
157
- * @param string $name option cache name
158
- * @return bool
 
 
159
  */
160
  public static function getCache($name)
161
  {
@@ -174,23 +193,28 @@ if (!class_exists('WpmsGaTools')) {
174
  }
175
 
176
  /**
177
- * clear cache
 
 
178
  */
179
  public static function clearCache()
180
  {
181
  global $wpdb;
182
- $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wpmsga_cache_qr%%'");
183
  }
184
 
185
  /**
186
- * @param string $domain site domain
 
 
 
187
  * @return array
188
  */
189
  public static function getRootDomain($domain)
190
  {
191
  $root = explode('/', $domain);
192
  preg_match(
193
- "/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i",
194
  str_ireplace('www', '', isset($root[2]) ? $root[2] : $domain),
195
  $root
196
  );
@@ -198,12 +222,15 @@ if (!class_exists('WpmsGaTools')) {
198
  }
199
 
200
  /**
201
- * @param string $domain site domain
 
 
 
202
  * @return mixed
203
  */
204
  public static function stripProtocol($domain)
205
  {
206
- return str_replace(array("https://", "http://", " "), "", $domain);
207
  }
208
  }
209
 
20
  class WpmsGaTools
21
  {
22
  /**
23
+ * Get google analytics client
24
+ *
25
+ * @param object $client Google analytics client
26
+ * @param array $access Access info to connect
27
+ * @param array $access_default Access default info to connect
28
+ *
29
  * @return mixed
30
  */
31
  public static function setClient($client, $access, $access_default)
32
  {
33
+ if (isset($access['wpmsga_dash_userapi']) && (int) $access['wpmsga_dash_userapi'] === 1) {
34
  if (!empty($access['wpmsga_dash_clientid']) && !empty($access['wpmsga_dash_clientsecret'])) {
35
  $client->setClientId($access['wpmsga_dash_clientid']);
36
  $client->setClientSecret($access['wpmsga_dash_clientsecret']);
47
  }
48
 
49
  /**
50
+ * Get selected profile
51
+ *
52
+ * @param array $profiles List profiles
53
+ * @param string $profile Selected profile
54
+ *
55
+ * @return boolean
56
  */
57
  public static function getSelectedProfile($profiles, $profile)
58
  {
59
  if (!empty($profiles)) {
60
  foreach ($profiles as $item) {
61
+ if ($item[1] === $profile) {
62
  return $item;
63
  }
64
  }
67
  }
68
 
69
  /**
70
+ * Get color
71
+ *
72
+ * @param string $colour Color
73
+ * @param float $per Percent
74
+ *
75
  * @return string
76
  */
77
  public static function colourVariator($colour, $per)
78
  {
79
  $colour = substr($colour, 1);
80
+ $rgb = '';
81
+ $per = $per / 100 * 255;
82
  if ($per < 0) {
83
  // Darker
84
  $per = abs($per);
85
+ for ($x = 0; $x < 3; $x ++) {
86
+ $c = hexdec(substr($colour, (2 * $x), 2)) - $per;
87
+ $c = ($c < 0) ? 0 : dechex($c);
88
  $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
89
  }
90
  } else {
91
  // Lighter
92
+ for ($x = 0; $x < 3; $x ++) {
93
+ $c = hexdec(substr($colour, (2 * $x), 2)) + $per;
94
+ $c = ($c > 255) ? 'ff' : dechex($c);
95
  $rgb .= (strlen($c) < 2) ? '0' . $c : $c;
96
  }
97
  }
99
  }
100
 
101
  /**
102
+ * Variations
103
+ *
104
+ * @param string $base String
105
+ *
106
  * @return array
107
  */
108
  public static function variations($base)
109
  {
110
  $variations[] = $base;
111
+ $variations[] = self::colourVariator($base, - 10);
112
+ $variations[] = self::colourVariator($base, + 10);
113
+ $variations[] = self::colourVariator($base, + 20);
114
+ $variations[] = self::colourVariator($base, - 20);
115
+ $variations[] = self::colourVariator($base, + 30);
116
+ $variations[] = self::colourVariator($base, - 30);
117
  return $variations;
118
  }
119
 
120
  /**
121
+ * Check roles
122
+ *
123
+ * @param array $access_level Access level
124
+ * @param boolean $tracking Tracking
125
+ *
126
+ * @return boolean
127
  */
128
  public static function checkRoles($access_level, $tracking = false)
129
  {
130
  if (is_user_logged_in() && isset($access_level)) {
131
  $current_user = wp_get_current_user();
132
+ $roles = (array) $current_user->roles;
133
  if ((current_user_can('manage_options')) && !$tracking) {
134
  return true;
135
  }
143
  }
144
 
145
  /**
146
+ * Set cache
147
+ *
148
+ * @param string $name Option cache name
149
+ * @param string $value Option cache value
150
+ * @param integer $expiration Expiration
151
+ *
152
+ * @return void
153
  */
154
  public static function setCache($name, $value, $expiration = 0)
155
  {
156
+ $option = array('value' => $value, 'expires' => time() + (int) $expiration);
157
  update_option('wpmsga_cache_' . $name, $option);
158
  }
159
 
160
  /**
161
+ * Remove cache
162
+ *
163
+ * @param string $name Option cache name
164
+ *
165
+ * @return void
166
  */
167
  public static function deleteCache($name)
168
  {
170
  }
171
 
172
  /**
173
+ * Get cache
174
+ *
175
+ * @param string $name Option cache name
176
+ *
177
+ * @return boolean
178
  */
179
  public static function getCache($name)
180
  {
193
  }
194
 
195
  /**
196
+ * Clear cache
197
+ *
198
+ * @return void
199
  */
200
  public static function clearCache()
201
  {
202
  global $wpdb;
203
+ $wpdb->query('DELETE FROM $wpdb->options WHERE option_name LIKE "wpmsga_cache_qr%%"');
204
  }
205
 
206
  /**
207
+ * Get root domain
208
+ *
209
+ * @param string $domain Site domain
210
+ *
211
  * @return array
212
  */
213
  public static function getRootDomain($domain)
214
  {
215
  $root = explode('/', $domain);
216
  preg_match(
217
+ '/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i',
218
  str_ireplace('www', '', isset($root[2]) ? $root[2] : $domain),
219
  $root
220
  );
222
  }
223
 
224
  /**
225
+ * Strip protocol
226
+ *
227
+ * @param string $domain Site domain
228
+ *
229
  * @return mixed
230
  */
231
  public static function stripProtocol($domain)
232
  {
233
+ return str_replace(array('https://', 'http://', ' '), '', $domain);
234
  }
235
  }
236
 
inc/pages/content-meta.php CHANGED
@@ -7,6 +7,7 @@ $metaseo_list_table = new MetaSeoContentListTable();
7
  $metaseo_list_table->processAction();
8
  $metaseo_list_table->prepare_items();
9
 
 
10
  if (!empty($_REQUEST['_wp_http_referer'])) {
11
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
12
  exit;
@@ -15,10 +16,10 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
15
 
16
  <div class="wrap seo_extended_table_page">
17
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
18
- <?php echo '<h1>' . __('Content Meta', 'wp-meta-seo') . '</h1>'; ?>
19
  <form id="wp-seo-meta-form" action="" method="post">
20
  <?php
21
- $metaseo_list_table->search_box(__('Search Posts', 'wp-meta-seo'), 'wpms_content');
22
  $metaseo_list_table->display();
23
  ?>
24
  </form>
7
  $metaseo_list_table->processAction();
8
  $metaseo_list_table->prepare_items();
9
 
10
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
11
  if (!empty($_REQUEST['_wp_http_referer'])) {
12
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
13
  exit;
16
 
17
  <div class="wrap seo_extended_table_page">
18
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
19
+ <?php echo '<h1>' . esc_html__('Content Meta', 'wp-meta-seo') . '</h1>'; ?>
20
  <form id="wp-seo-meta-form" action="" method="post">
21
  <?php
22
+ $metaseo_list_table->search_box(esc_html__('Search Posts', 'wp-meta-seo'), 'wpms_content');
23
  $metaseo_list_table->display();
24
  ?>
25
  </form>
inc/pages/dashboard.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  if (!class_exists('MetaSeoDashboard')) {
4
  require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-dashboard.php');
5
  }
@@ -8,20 +7,20 @@ wp_enqueue_style('m-style-qtip');
8
  wp_enqueue_script('jquery-qtip');
9
  wp_enqueue_style('wpms-myqtip');
10
 
11
- $site_name = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', get_site_url());
12
- $pieces = explode("/", $site_name);
13
- $url = 'http://www.alexa.com/siteinfo/' . $pieces[0];
14
- $dashboard = new MetaSeoDashboard();
15
- $options_dashboard = get_option('options_dashboard');
16
- $error_404 = $dashboard->get404Link();
17
  $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.php';
18
  ?>
19
- <h1 style="text-align: center;"><?php _e('WP Meta SEO dashboard', 'wp-meta-seo') ?></h1>
20
  <div class="dashboard">
21
  <div class="col-md-9">
22
  <div class="row panel-statistics">
23
  <div class="wpms_dash_widgets wpms_dash_permalink"
24
- data-alt="<?php _e('It’s better using a permalink structure that is adding
25
  in your URL the category name and content title. This parameter can be changed
26
  in Settings > Permalinks WordPress menu.
27
  Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
@@ -32,10 +31,10 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
32
  <div class="row">
33
  <div class="wpms_dashboard_widgets_left">
34
  <h4 class="panel-title dashboard-title">
35
- <?php _e('PERMALINKS SETTINGS', 'wp-meta-seo') ?>
36
  </h4>
37
  <h3 class="dashboard-title percent_1">50%</h3>
38
- <p class="dashboard-title percent_2"><?php _e('Optimized at:', 'wp-meta-seo') ?>
39
  <span class="percent">50%</span></p>
40
  </div>
41
  <div class="wpms_dashboard_widgets_right">
@@ -51,7 +50,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
51
  </div>
52
 
53
  <div class="wpms_dash_widgets wpms_dash_metatitle"
54
- data-alt="<?php _e('Meta titles are displayed in search engine results
55
  as a page title. It’s a good thing for SEO to have some custom and attractive ones.
56
  Be sure to fill at least the met information on your most popular pages', 'wp-meta-seo') ?>">
57
  <div class="row panel-statistics">
@@ -61,11 +60,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
61
  <div class="row">
62
  <div class="wpms_dashboard_widgets_left">
63
  <h4 class="panel-title dashboard-title">
64
- <?php _e('META TITLE', 'wp-meta-seo') ?>
65
  </h4>
66
  <h3 class="dashboard-title percent_1">0%</h3>
67
  <p class="dashboard-title percent_2">
68
- <?php _e('Meta title filled:', 'wp-meta-seo') ?>
69
  <span class="percent">0/0</span>
70
  </p>
71
  </div>
@@ -82,7 +81,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
82
  </div>
83
 
84
  <div class="wpms_dash_widgets wpms_dash_metadesc"
85
- data-alt="<?php _e('Meta descriptions are displayed in search
86
  engine results as a page description. It’s a good thing for SEO to have some
87
  custom and attractive ones. Be sure to fill at least the meta information on
88
  your most popular pages.', 'wp-meta-seo') ?>">
@@ -93,11 +92,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
93
  <div class="row">
94
  <div class="wpms_dashboard_widgets_left">
95
  <h4 class="panel-title dashboard-title">
96
- <?php _e('META DESCRIPTION', 'wp-meta-seo') ?>
97
  </h4>
98
  <h3 class="dashboard-title percent_1">0%</h3>
99
  <p class="dashboard-title percent_2">
100
- <?php _e('Meta description filled:', 'wp-meta-seo') ?>
101
  <span class="percent">0/0</span>
102
  </p>
103
  </div>
@@ -118,16 +117,16 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
118
  if (!class_exists('MetaSeoAddonAdmin')) {
119
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
120
  }
121
- $metaseo_addon = new MetaSeoAddonAdmin();
122
  $duplicateTitle = $metaseo_addon->getDuplicateMetatitle();
123
- $duplicateDesc = $metaseo_addon->getDuplicateMetadesc();
124
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
125
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
126
  }
127
  ?>
128
 
129
  <div class="wpms_dash_widgets wpms_dash_imgsresize"
130
- data-alt="<?php _e('Display image at its natural size, do not use HTML resize.
131
  It happens usually when you use handles to resize an image. You have a bulk
132
  edition tool to fix that.', 'wp-meta-seo') ?>">
133
  <div class="row panel-statistics">
@@ -137,11 +136,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
137
  <div class="row">
138
  <div class="wpms_dashboard_widgets_left">
139
  <h4 class="panel-title dashboard-title">
140
- <?php _e('HTML IMAGE RESIZING', 'wp-meta-seo') ?>
141
  </h4>
142
  <h3 class="dashboard-title percent_1">0%</h3>
143
  <p class="dashboard-title percent_2">
144
- <?php _e('Wrong resized images:', 'wp-meta-seo') ?>
145
  <span class="percent">0/0</span>
146
  </p>
147
  </div>
@@ -158,7 +157,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
158
  </div>
159
 
160
  <div class="wpms_dash_widgets wpms_dash_imgsmeta"
161
- data-alt="<?php _e('We recommend to use both alt text.
162
  The main advantage is that it helps search engines discover your images and display
163
  them in image search results. Plus, these tags improve the accessibility of your site
164
  and give more information about your images. Use our bulk
@@ -170,11 +169,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
170
  <div class="row">
171
  <div class="wpms_dashboard_widgets_left">
172
  <h4 class="panel-title dashboard-title">
173
- <?php _e('IMAGE ALT', 'wp-meta-seo') ?>
174
  </h4>
175
  <h3 class="dashboard-title percent_1">0%</h3>
176
  <p class="dashboard-title percent_2">
177
- <?php _e('Image data filled (in content):', 'wp-meta-seo') ?>
178
  <span class="percent">0/0</span>
179
  </p>
180
  </div>
@@ -191,7 +190,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
191
  </div>
192
 
193
  <div class="wpms_dash_widgets wpms_dash_newcontent"
194
- data-alt="<?php _e('It is highly recommended to update or add new content on
195
  your website quite frequently. At least 3 updated or new
196
  content per month would be great :)', 'wp-meta-seo') ?>">
197
  <div class="row panel-statistics">
@@ -201,11 +200,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
201
  <div class="row">
202
  <div class="wpms_dashboard_widgets_left">
203
  <h4 class="panel-title dashboard-title">
204
- <?php _e('NEW OR UPDATED CONTENT', 'wp-meta-seo') ?>
205
  </h4>
206
  <h3 class="dashboard-title percent_1">0%</h3>
207
  <p class="dashboard-title percent_2">
208
- <?php _e('Latest month new or updated content:', 'wp-meta-seo') ?>
209
  <span class="percent">0</span>
210
  </p>
211
  </div>
@@ -222,7 +221,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
222
  </div>
223
 
224
  <div class="wpms_dash_widgets wpms_dash_linkmeta"
225
- data-alt="<?php _e('The link title attribute does not have any SEO
226
  value for links. BUT links titles can influence click behavior for users, which may
227
  indirectly affect your SEO performance', 'wp-meta-seo') ?>">
228
  <div class="row panel-statistics">
@@ -232,11 +231,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
232
  <div class="row">
233
  <div class="wpms_dashboard_widgets_left">
234
  <h4 class="panel-title dashboard-title">
235
- <?php _e('LINK TITLES', 'wp-meta-seo') ?>
236
  </h4>
237
  <h3 class="dashboard-title percent_1">0%</h3>
238
  <p class="dashboard-title percent_2">
239
- <?php _e('Links title completed:', 'wp-meta-seo') ?>
240
  <span class="percent">0/0</span>
241
  </p>
242
  </div>
@@ -253,7 +252,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
253
  </div>
254
 
255
  <div class="wpms_dash_widgets wpms_dash_404_error"
256
- data-alt="<?php _e('A website with a bunch of 404 errors doesn’t provide a good
257
  user experience, which is significantly important in content marketing and SEO.
258
  We recommend to use our internal broken link checker and redirect tool to fix all
259
  the 404 error you can periodically.', 'wp-meta-seo') ?>">
@@ -264,20 +263,20 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
264
  <div class="row">
265
  <div class="wpms_dashboard_widgets_left">
266
  <h4 class="panel-title dashboard-title">
267
- <?php _e('404 ERRORS', 'wp-meta-seo') ?>
268
  </h4>
269
- <h3 class="dashboard-title percent_1"><?php echo $error_404['percent'] ?>%</h3>
270
  <p class="dashboard-title percent_2">
271
  <?php
272
- _e('Redirected 404 errors:', 'wp-meta-seo');
273
- echo $error_404['count_404_redirected'] . '/' . $error_404['count_404'];
274
  ?>
275
  </p>
276
  </div>
277
  <div class="wpms_dashboard_widgets_right">
278
  <div class="progress-rating">
279
  <div class="determinate percent_3"
280
- style="width: <?php echo $error_404['percent'] ?>%"></div>
281
  </div>
282
  </div>
283
  </div>
@@ -292,7 +291,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
292
  if (!is_plugin_active($plugin_imgRecycle_file)) :
293
  ?>
294
  <div class="wpms_dash_widgets"
295
- data-alt="<?php _e('Images represent around 60% of a web page weight.
296
  An image compression reduce the image size by up to 70% while preserving
297
  the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
298
  <div class="row panel-statistics">
@@ -302,11 +301,11 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
302
  <div class="row">
303
  <div class="wpms_dashboard_widgets_left">
304
  <h4 class="panel-title dashboard-title">
305
- <?php _e('IMAGE COMPRESSION', 'wp-meta-seo') ?>
306
  </h4>
307
  <h3 class="dashboard-title percent_1">0%</h3>
308
  <p class="dashboard-title percent_2">
309
- <?php _e('Use ImageRecycle image compression
310
  plugin to activate this feature', 'wp-meta-seo') ?>
311
  : 0/0
312
  </p>
@@ -325,7 +324,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
325
  <?php else : ?>
326
  <?php $optimizer = $dashboard->getImagesCount(); ?>
327
  <div class="wpms_dash_widgets"
328
- data-alt="<?php _e('Images represent around 60% of a web page weight.
329
  An image compression reduce the image size by up to 70% while preserving
330
  the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
331
  <div class="row panel-statistics">
@@ -335,23 +334,23 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
335
  <div class="row">
336
  <div class="wpms_dashboard_widgets_left">
337
  <h4 class="panel-title dashboard-title">
338
- <?php _e('IMAGE COMPRESSION', 'wp-meta-seo') ?>
339
  </h4>
340
  <h3 class="dashboard-title percent_1">
341
- <?php echo $optimizer['percent'] . '%' ?>
342
  </h3>
343
  <p class="dashboard-title percent_2">
344
  <?php
345
- _e('Compressed images', 'wp-meta-seo');
346
  echo ': ';
347
- echo $optimizer['image_optimize'] . '/' . $optimizer['count_image'];
348
  ?>
349
  </p>
350
  </div>
351
  <div class="wpms_dashboard_widgets_right">
352
  <div class="progress-rating">
353
  <div class="determinate percent_3"
354
- style="width: <?php echo $optimizer['percent'] . '%' ?>">
355
  </div>
356
  </div>
357
  </div>
@@ -379,20 +378,20 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
379
  <div class="right">
380
  <div class="dashboard-right">
381
  <div style="display: none">
382
- <?php _e("We can't get rank of this site from Alexa.com!", "wp-meta-seo") ?>
383
  </div>
384
  <div style="clear:left"></div>
385
  <div id="wpmetaseo-update-version">
386
- <h4><?php echo __('Latest WP Meta SEO News', 'wp-meta-seo') ?></h4>
387
  <ul>
388
  <li><a target="_blank"
389
  href="https://www.joomunited.com/wordpress-products/wp-meta-seo">
390
- <?php _e('More information about WP Meta SEO', 'wp-meta-seo'); ?>
391
  </a>
392
  </li>
393
  <li><a target="_blank"
394
  href="https://www.joomunited.com/">
395
- <?php _e('Other plugins from JoomUnited', 'wp-meta-seo'); ?>
396
  </a>
397
  </li>
398
  </ul>
@@ -402,7 +401,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
402
  </div>
403
  <?php
404
  if (!empty($_COOKIE['close_dashboard'])) {
405
- $check = time() - (int)$_COOKIE['close_dashboard'];
406
  $month = 30 * 24 * 60 * 60;
407
  }
408
 
@@ -417,19 +416,19 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
417
  <div class="row">
418
  <div class="wpms_dashboard_widgets_content">
419
  <p class="dashboard_noti_title">
420
- <?php _e('WP META SEO PRO ADDON', 'wp-meta-seo') ?>
421
  </p>
422
  <p class="dashboard-title msg">
423
- <?php _e('Bring your WordPress website SEO to the next level with the PRO Addon:
424
  Email Report, Google Search Console Connect, Automatic Redirect,
425
  Advanced Sitemaps and more!', 'wp-meta-seo') ?>
426
  </p>
427
  <a class="more-info"
428
  href="https://www.joomunited.com/wordpress-products/wp-meta-seo"
429
- target="_blank"><?php _e('MORE INFORMATION', 'wp-meta-seo') ?></a>
430
  <a data-page="close_dashboard"
431
  class="dashboard-title wpmsclose_notification close_dashboard">
432
- <?php _e('CLOSE FOR ONE MONTH', 'wp-meta-seo') ?>
433
  </a>
434
  </div>
435
  </div>
@@ -447,7 +446,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
447
  });
448
 
449
  function replace_url_img() {
450
- var url = '<?php echo WPMETASEO_PLUGIN_URL; ?>';
451
  var icon_tip = url + 'img/icon_tip.png';
452
  var globe_sm = url + 'img/globe-sm.jpg';
453
  jQuery('.img-inline').attr('src', globe_sm);
1
  <?php
 
2
  if (!class_exists('MetaSeoDashboard')) {
3
  require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-dashboard.php');
4
  }
7
  wp_enqueue_script('jquery-qtip');
8
  wp_enqueue_style('wpms-myqtip');
9
 
10
+ $site_name = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', get_site_url());
11
+ $pieces = explode('/', $site_name);
12
+ $url = 'http://www.alexa.com/siteinfo/' . $pieces[0];
13
+ $dashboard = new MetaSeoDashboard();
14
+ $options_dashboard = get_option('options_dashboard');
15
+ $error_404 = $dashboard->get404Link();
16
  $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.php';
17
  ?>
18
+ <h1 style="text-align: center;"><?php esc_html_e('WP Meta SEO dashboard', 'wp-meta-seo') ?></h1>
19
  <div class="dashboard">
20
  <div class="col-md-9">
21
  <div class="row panel-statistics">
22
  <div class="wpms_dash_widgets wpms_dash_permalink"
23
+ data-alt="<?php esc_attr_e('It’s better using a permalink structure that is adding
24
  in your URL the category name and content title. This parameter can be changed
25
  in Settings > Permalinks WordPress menu.
26
  Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
31
  <div class="row">
32
  <div class="wpms_dashboard_widgets_left">
33
  <h4 class="panel-title dashboard-title">
34
+ <?php esc_html_e('PERMALINKS SETTINGS', 'wp-meta-seo') ?>
35
  </h4>
36
  <h3 class="dashboard-title percent_1">50%</h3>
37
+ <p class="dashboard-title percent_2"><?php esc_html_e('Optimized at:', 'wp-meta-seo') ?>
38
  <span class="percent">50%</span></p>
39
  </div>
40
  <div class="wpms_dashboard_widgets_right">
50
  </div>
51
 
52
  <div class="wpms_dash_widgets wpms_dash_metatitle"
53
+ data-alt="<?php esc_attr_e('Meta titles are displayed in search engine results
54
  as a page title. It’s a good thing for SEO to have some custom and attractive ones.
55
  Be sure to fill at least the met information on your most popular pages', 'wp-meta-seo') ?>">
56
  <div class="row panel-statistics">
60
  <div class="row">
61
  <div class="wpms_dashboard_widgets_left">
62
  <h4 class="panel-title dashboard-title">
63
+ <?php esc_html_e('META TITLE', 'wp-meta-seo') ?>
64
  </h4>
65
  <h3 class="dashboard-title percent_1">0%</h3>
66
  <p class="dashboard-title percent_2">
67
+ <?php esc_html_e('Meta title filled:', 'wp-meta-seo') ?>
68
  <span class="percent">0/0</span>
69
  </p>
70
  </div>
81
  </div>
82
 
83
  <div class="wpms_dash_widgets wpms_dash_metadesc"
84
+ data-alt="<?php esc_attr_e('Meta descriptions are displayed in search
85
  engine results as a page description. It’s a good thing for SEO to have some
86
  custom and attractive ones. Be sure to fill at least the meta information on
87
  your most popular pages.', 'wp-meta-seo') ?>">
92
  <div class="row">
93
  <div class="wpms_dashboard_widgets_left">
94
  <h4 class="panel-title dashboard-title">
95
+ <?php esc_html_e('META DESCRIPTION', 'wp-meta-seo') ?>
96
  </h4>
97
  <h3 class="dashboard-title percent_1">0%</h3>
98
  <p class="dashboard-title percent_2">
99
+ <?php esc_html_e('Meta description filled:', 'wp-meta-seo') ?>
100
  <span class="percent">0/0</span>
101
  </p>
102
  </div>
117
  if (!class_exists('MetaSeoAddonAdmin')) {
118
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
119
  }
120
+ $metaseo_addon = new MetaSeoAddonAdmin();
121
  $duplicateTitle = $metaseo_addon->getDuplicateMetatitle();
122
+ $duplicateDesc = $metaseo_addon->getDuplicateMetadesc();
123
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
124
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
125
  }
126
  ?>
127
 
128
  <div class="wpms_dash_widgets wpms_dash_imgsresize"
129
+ data-alt="<?php esc_attr_e('Display image at its natural size, do not use HTML resize.
130
  It happens usually when you use handles to resize an image. You have a bulk
131
  edition tool to fix that.', 'wp-meta-seo') ?>">
132
  <div class="row panel-statistics">
136
  <div class="row">
137
  <div class="wpms_dashboard_widgets_left">
138
  <h4 class="panel-title dashboard-title">
139
+ <?php esc_html_e('HTML IMAGE RESIZING', 'wp-meta-seo') ?>
140
  </h4>
141
  <h3 class="dashboard-title percent_1">0%</h3>
142
  <p class="dashboard-title percent_2">
143
+ <?php esc_html_e('Wrong resized images:', 'wp-meta-seo') ?>
144
  <span class="percent">0/0</span>
145
  </p>
146
  </div>
157
  </div>
158
 
159
  <div class="wpms_dash_widgets wpms_dash_imgsmeta"
160
+ data-alt="<?php esc_attr_e('We recommend to use both alt text.
161
  The main advantage is that it helps search engines discover your images and display
162
  them in image search results. Plus, these tags improve the accessibility of your site
163
  and give more information about your images. Use our bulk
169
  <div class="row">
170
  <div class="wpms_dashboard_widgets_left">
171
  <h4 class="panel-title dashboard-title">
172
+ <?php esc_html_e('IMAGE ALT', 'wp-meta-seo') ?>
173
  </h4>
174
  <h3 class="dashboard-title percent_1">0%</h3>
175
  <p class="dashboard-title percent_2">
176
+ <?php esc_html_e('Image data filled (in content):', 'wp-meta-seo') ?>
177
  <span class="percent">0/0</span>
178
  </p>
179
  </div>
190
  </div>
191
 
192
  <div class="wpms_dash_widgets wpms_dash_newcontent"
193
+ data-alt="<?php esc_attr_e('It is highly recommended to update or add new content on
194
  your website quite frequently. At least 3 updated or new
195
  content per month would be great :)', 'wp-meta-seo') ?>">
196
  <div class="row panel-statistics">
200
  <div class="row">
201
  <div class="wpms_dashboard_widgets_left">
202
  <h4 class="panel-title dashboard-title">
203
+ <?php esc_html_e('NEW OR UPDATED CONTENT', 'wp-meta-seo') ?>
204
  </h4>
205
  <h3 class="dashboard-title percent_1">0%</h3>
206
  <p class="dashboard-title percent_2">
207
+ <?php esc_html_e('Latest month new or updated content:', 'wp-meta-seo') ?>
208
  <span class="percent">0</span>
209
  </p>
210
  </div>
221
  </div>
222
 
223
  <div class="wpms_dash_widgets wpms_dash_linkmeta"
224
+ data-alt="<?php esc_attr_e('The link title attribute does not have any SEO
225
  value for links. BUT links titles can influence click behavior for users, which may
226
  indirectly affect your SEO performance', 'wp-meta-seo') ?>">
227
  <div class="row panel-statistics">
231
  <div class="row">
232
  <div class="wpms_dashboard_widgets_left">
233
  <h4 class="panel-title dashboard-title">
234
+ <?php esc_html_e('LINK TITLES', 'wp-meta-seo') ?>
235
  </h4>
236
  <h3 class="dashboard-title percent_1">0%</h3>
237
  <p class="dashboard-title percent_2">
238
+ <?php esc_html_e('Links title completed:', 'wp-meta-seo') ?>
239
  <span class="percent">0/0</span>
240
  </p>
241
  </div>
252
  </div>
253
 
254
  <div class="wpms_dash_widgets wpms_dash_404_error"
255
+ data-alt="<?php esc_attr_e('A website with a bunch of 404 errors doesn’t provide a good
256
  user experience, which is significantly important in content marketing and SEO.
257
  We recommend to use our internal broken link checker and redirect tool to fix all
258
  the 404 error you can periodically.', 'wp-meta-seo') ?>">
263
  <div class="row">
264
  <div class="wpms_dashboard_widgets_left">
265
  <h4 class="panel-title dashboard-title">
266
+ <?php esc_html_e('404 ERRORS', 'wp-meta-seo') ?>
267
  </h4>
268
+ <h3 class="dashboard-title percent_1"><?php echo esc_html($error_404['percent']) ?>%</h3>
269
  <p class="dashboard-title percent_2">
270
  <?php
271
+ esc_html_e('Redirected 404 errors: ', 'wp-meta-seo');
272
+ echo esc_html($error_404['count_404_redirected'] . '/' . $error_404['count_404']);
273
  ?>
274
  </p>
275
  </div>
276
  <div class="wpms_dashboard_widgets_right">
277
  <div class="progress-rating">
278
  <div class="determinate percent_3"
279
+ style="width: <?php echo esc_html($error_404['percent']) ?>%"></div>
280
  </div>
281
  </div>
282
  </div>
291
  if (!is_plugin_active($plugin_imgRecycle_file)) :
292
  ?>
293
  <div class="wpms_dash_widgets"
294
+ data-alt="<?php esc_attr_e('Images represent around 60% of a web page weight.
295
  An image compression reduce the image size by up to 70% while preserving
296
  the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
297
  <div class="row panel-statistics">
301
  <div class="row">
302
  <div class="wpms_dashboard_widgets_left">
303
  <h4 class="panel-title dashboard-title">
304
+ <?php esc_html_e('IMAGE COMPRESSION', 'wp-meta-seo') ?>
305
  </h4>
306
  <h3 class="dashboard-title percent_1">0%</h3>
307
  <p class="dashboard-title percent_2">
308
+ <?php esc_html_e('Use ImageRecycle image compression
309
  plugin to activate this feature', 'wp-meta-seo') ?>
310
  : 0/0
311
  </p>
324
  <?php else : ?>
325
  <?php $optimizer = $dashboard->getImagesCount(); ?>
326
  <div class="wpms_dash_widgets"
327
+ data-alt="<?php esc_attr_e('Images represent around 60% of a web page weight.
328
  An image compression reduce the image size by up to 70% while preserving
329
  the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
330
  <div class="row panel-statistics">
334
  <div class="row">
335
  <div class="wpms_dashboard_widgets_left">
336
  <h4 class="panel-title dashboard-title">
337
+ <?php esc_html_e('IMAGE COMPRESSION', 'wp-meta-seo') ?>
338
  </h4>
339
  <h3 class="dashboard-title percent_1">
340
+ <?php echo esc_html($optimizer['percent']) . '%' ?>
341
  </h3>
342
  <p class="dashboard-title percent_2">
343
  <?php
344
+ esc_html_e('Compressed images', 'wp-meta-seo');
345
  echo ': ';
346
+ echo esc_html($optimizer['image_optimize'] . '/' . $optimizer['count_image']);
347
  ?>
348
  </p>
349
  </div>
350
  <div class="wpms_dashboard_widgets_right">
351
  <div class="progress-rating">
352
  <div class="determinate percent_3"
353
+ style="width: <?php echo esc_html($optimizer['percent']) . '%' ?>">
354
  </div>
355
  </div>
356
  </div>
378
  <div class="right">
379
  <div class="dashboard-right">
380
  <div style="display: none">
381
+ <?php esc_html_e('We can\'t get rank of this site from Alexa.com!', 'wp-meta-seo') ?>
382
  </div>
383
  <div style="clear:left"></div>
384
  <div id="wpmetaseo-update-version">
385
+ <h4><?php esc_html_e('Latest WP Meta SEO News', 'wp-meta-seo') ?></h4>
386
  <ul>
387
  <li><a target="_blank"
388
  href="https://www.joomunited.com/wordpress-products/wp-meta-seo">
389
+ <?php esc_html_e('More information about WP Meta SEO', 'wp-meta-seo'); ?>
390
  </a>
391
  </li>
392
  <li><a target="_blank"
393
  href="https://www.joomunited.com/">
394
+ <?php esc_html_e('Other plugins from JoomUnited', 'wp-meta-seo'); ?>
395
  </a>
396
  </li>
397
  </ul>
401
  </div>
402
  <?php
403
  if (!empty($_COOKIE['close_dashboard'])) {
404
+ $check = time() - (int) $_COOKIE['close_dashboard'];
405
  $month = 30 * 24 * 60 * 60;
406
  }
407
 
416
  <div class="row">
417
  <div class="wpms_dashboard_widgets_content">
418
  <p class="dashboard_noti_title">
419
+ <?php esc_html_e('WP META SEO PRO ADDON', 'wp-meta-seo') ?>
420
  </p>
421
  <p class="dashboard-title msg">
422
+ <?php esc_html_e('Bring your WordPress website SEO to the next level with the PRO Addon:
423
  Email Report, Google Search Console Connect, Automatic Redirect,
424
  Advanced Sitemaps and more!', 'wp-meta-seo') ?>
425
  </p>
426
  <a class="more-info"
427
  href="https://www.joomunited.com/wordpress-products/wp-meta-seo"
428
+ target="_blank"><?php esc_html_e('MORE INFORMATION', 'wp-meta-seo') ?></a>
429
  <a data-page="close_dashboard"
430
  class="dashboard-title wpmsclose_notification close_dashboard">
431
+ <?php esc_html_e('CLOSE FOR ONE MONTH', 'wp-meta-seo') ?>
432
  </a>
433
  </div>
434
  </div>
446
  });
447
 
448
  function replace_url_img() {
449
+ var url = '<?php echo esc_url(WPMETASEO_PLUGIN_URL); ?>';
450
  var icon_tip = url + 'img/icon_tip.png';
451
  var globe_sm = url + 'img/globe-sm.jpg';
452
  jQuery('.img-inline').attr('src', globe_sm);
inc/pages/dashboard_widgets.php CHANGED
@@ -1,6 +1,6 @@
1
  <div class="wpms_dashboard_widgets">
2
  <div class="wpms_dash_widgets wpms_dash_permalink"
3
- data-alt="<?php _e('It’s better using a permalink structure that
4
  is adding in your URL the category name and content title.
5
  This parameter can be changed in Settings > Permalinks WordPress menu.
6
  Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
@@ -11,11 +11,11 @@
11
  <div class="row">
12
  <div class="wpms_dashboard_widgets_left">
13
  <h4 class="panel-title dashboard-title">
14
- <?php _e('PERMALINKS SETTINGS', 'wp-meta-seo') ?>
15
  </h4>
16
  <div class="panel-bottom">
17
  <h3 class="dashboard-title percent_1">50%</h3>
18
- <span class="dashboard-title percent_2"><?php _e('Optimized at:', 'wp-meta-seo') ?>
19
  <span class="percent">50%</span></span>
20
  </div>
21
  </div>
@@ -32,7 +32,7 @@
32
  </div>
33
 
34
  <div class="wpms_dash_widgets wpms_dash_metatitle"
35
- data-alt="<?php _e('Meta titles are displayed in search engine results as a page title.
36
  It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least
37
  the met information on your most popular pages', 'wp-meta-seo') ?>">
38
  <div class="row panel-statistics">
@@ -41,11 +41,11 @@
41
  <div class="panel-body">
42
  <div class="row">
43
  <div class="wpms_dashboard_widgets_left">
44
- <h4 class="panel-title dashboard-title"><?php _e('META TITLE', 'wp-meta-seo') ?></h4>
45
  <div class="panel-bottom">
46
  <h3 class="dashboard-title percent_1">0%</h3>
47
  <span class="dashboard-title percent_2">
48
- <?php _e('Meta title filled:', 'wp-meta-seo') ?>
49
  <span class="percent">0/0</span>
50
  </span>
51
  </div>
@@ -63,7 +63,7 @@
63
  </div>
64
 
65
  <div class="wpms_dash_widgets wpms_dash_metadesc"
66
- data-alt="<?php _e('Meta descriptions are displayed in search engine results as a page description.
67
  It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the meta
68
  information on your most popular pages.', 'wp-meta-seo') ?>">
69
  <div class="row panel-statistics">
@@ -73,12 +73,12 @@
73
  <div class="row">
74
  <div class="wpms_dashboard_widgets_left">
75
  <h4 class="panel-title dashboard-title">
76
- <?php _e('META DESCRIPTION', 'wp-meta-seo') ?>
77
  </h4>
78
  <div class="panel-bottom">
79
  <h3 class="dashboard-title percent_1">0%</h3>
80
  <span class="dashboard-title percent_2">
81
- <?php _e('Meta description filled:', 'wp-meta-seo') ?>
82
  <span class="percent">0/0</span>
83
  </span>
84
  </div>
@@ -100,16 +100,16 @@
100
  if (!class_exists('MetaSeoAddonAdmin')) {
101
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
102
  }
103
- $metaseo_addon = new MetaSeoAddonAdmin();
104
  $duplicateTitle = $metaseo_addon->getDuplicateMetatitle();
105
- $duplicateDesc = $metaseo_addon->getDuplicateMetadesc();
106
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
107
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
108
  }
109
  ?>
110
 
111
  <div class="wpms_dash_widgets wpms_dash_imgsresize"
112
- data-alt="<?php _e('Display image at its natural size, do not use HTML resize.
113
  It happens usually when you use handles to resize an image. You have a bulk
114
  edition tool to fix that.', 'wp-meta-seo') ?>">
115
  <div class="row panel-statistics">
@@ -119,12 +119,12 @@
119
  <div class="row">
120
  <div class="wpms_dashboard_widgets_left">
121
  <h4 class="panel-title dashboard-title">
122
- <?php _e('HTML IMAGE RESIZING', 'wp-meta-seo') ?>
123
  </h4>
124
  <div class="panel-bottom">
125
  <h3 class="dashboard-title percent_1">0%</h3>
126
  <span class="dashboard-title percent_2">
127
- <?php _e('Wrong resized images:', 'wp-meta-seo') ?>
128
  <span class="percent">0/0</span>
129
  </span>
130
  </div>
@@ -142,7 +142,7 @@
142
  </div>
143
 
144
  <div class="wpms_dash_widgets wpms_dash_imgsmeta"
145
- data-alt="<?php _e('We recommend to use both alt text.
146
  The main advantage is that it helps search engines discover your images and display
147
  them in image search results. Plus, these tags improve the accessibility of your site and
148
  give more information about your images. Use our bulk image
@@ -154,12 +154,12 @@
154
  <div class="row">
155
  <div class="wpms_dashboard_widgets_left">
156
  <h4 class="panel-title dashboard-title">
157
- <?php _e('IMAGE ALT', 'wp-meta-seo') ?>
158
  </h4>
159
  <div class="panel-bottom">
160
  <h3 class="dashboard-title percent_1">0%</h3>
161
  <span class="dashboard-title percent_2">
162
- <?php _e('Image data filled (in content):', 'wp-meta-seo') ?>
163
  <span class="percent">0/0</span>
164
  </span>
165
  </div>
@@ -177,7 +177,7 @@
177
  </div>
178
 
179
  <div class="wpms_dash_widgets wpms_dash_newcontent"
180
- data-alt="<?php _e('It is highly recommended to update or add new content on your website quite frequently.
181
  At least 3 updated or new content per month would be great :)', 'wp-meta-seo') ?>">
182
  <div class="row panel-statistics">
183
  <div class="tooltipped">
@@ -186,12 +186,12 @@
186
  <div class="row">
187
  <div class="wpms_dashboard_widgets_left">
188
  <h4 class="panel-title dashboard-title">
189
- <?php _e('NEW OR UPDATED CONTENT', 'wp-meta-seo') ?>
190
  </h4>
191
  <div class="panel-bottom">
192
  <h3 class="dashboard-title percent_1">0%</h3>
193
  <span class="dashboard-title percent_2">
194
- <?php _e('Latest month new or updated content:', 'wp-meta-seo') ?>
195
  <span class="percent">0</span>
196
  </span>
197
  </div>
@@ -209,7 +209,7 @@
209
  </div>
210
 
211
  <div class="wpms_dash_widgets wpms_dash_linkmeta"
212
- data-alt="<?php _e('The link title attribute does not have any SEO value for links.
213
  BUT links titles can influence click behavior for users, which may indirectly affect
214
  your SEO performance', 'wp-meta-seo') ?>">
215
  <div class="row panel-statistics">
@@ -218,11 +218,11 @@
218
  <div class="panel-body">
219
  <div class="row">
220
  <div class="wpms_dashboard_widgets_left">
221
- <h4 class="panel-title dashboard-title"><?php _e('LINK TITLES', 'wp-meta-seo') ?></h4>
222
  <div class="panel-bottom">
223
  <h3 class="dashboard-title percent_1">0%</h3>
224
  <span class="dashboard-title percent_2">
225
- <?php _e('Links title completed:', 'wp-meta-seo') ?>
226
  <span class="percent">0/0</span>
227
  </span>
228
  </div>
@@ -240,7 +240,7 @@
240
  </div>
241
 
242
  <div class="wpms_dash_widgets wpms_dash_404_error"
243
- data-alt="<?php _e('A website with a bunch of 404 errors doesn’t provide a good user experience,
244
  which is significantly important in content marketing and SEO. We recommend to use our internal
245
  broken link checker and redirect tool to fix all the 404 error you can periodically.', 'wp-meta-seo') ?>">
246
  <div class="row panel-statistics">
@@ -249,21 +249,21 @@
249
  <div class="panel-body">
250
  <div class="row">
251
  <div class="wpms_dashboard_widgets_left">
252
- <h4 class="panel-title dashboard-title"><?php _e('404 ERRORS', 'wp-meta-seo') ?></h4>
253
  <div class="panel-bottom">
254
- <h3 class="dashboard-title percent_1"><?php echo $error_404['percent'] ?>%</h3>
255
  <span class="dashboard-title percent_2">
256
  <?php
257
- _e('Redirected 404 errors', 'wp-meta-seo');
258
  echo ': ';
259
- echo $error_404['count_404_redirected'] . '/' . $error_404['count_404'];
260
  ?>
261
  </div>
262
  </div>
263
  <div class="wpms_dashboard_widgets_right">
264
  <div class="progress-rating">
265
  <div class="determinate percent_3"
266
- style="width: <?php echo $error_404['percent'] ?>%"></div>
267
  </div>
268
  </div>
269
  </div>
1
  <div class="wpms_dashboard_widgets">
2
  <div class="wpms_dash_widgets wpms_dash_permalink"
3
+ data-alt="<?php esc_attr_e('It’s better using a permalink structure that
4
  is adding in your URL the category name and content title.
5
  This parameter can be changed in Settings > Permalinks WordPress menu.
6
  Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
11
  <div class="row">
12
  <div class="wpms_dashboard_widgets_left">
13
  <h4 class="panel-title dashboard-title">
14
+ <?php esc_html_e('PERMALINKS SETTINGS', 'wp-meta-seo') ?>
15
  </h4>
16
  <div class="panel-bottom">
17
  <h3 class="dashboard-title percent_1">50%</h3>
18
+ <span class="dashboard-title percent_2"><?php esc_html_e('Optimized at:', 'wp-meta-seo') ?>
19
  <span class="percent">50%</span></span>
20
  </div>
21
  </div>
32
  </div>
33
 
34
  <div class="wpms_dash_widgets wpms_dash_metatitle"
35
+ data-alt="<?php esc_attr_e('Meta titles are displayed in search engine results as a page title.
36
  It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least
37
  the met information on your most popular pages', 'wp-meta-seo') ?>">
38
  <div class="row panel-statistics">
41
  <div class="panel-body">
42
  <div class="row">
43
  <div class="wpms_dashboard_widgets_left">
44
+ <h4 class="panel-title dashboard-title"><?php esc_html_e('META TITLE', 'wp-meta-seo') ?></h4>
45
  <div class="panel-bottom">
46
  <h3 class="dashboard-title percent_1">0%</h3>
47
  <span class="dashboard-title percent_2">
48
+ <?php esc_html_e('Meta title filled:', 'wp-meta-seo') ?>
49
  <span class="percent">0/0</span>
50
  </span>
51
  </div>
63
  </div>
64
 
65
  <div class="wpms_dash_widgets wpms_dash_metadesc"
66
+ data-alt="<?php esc_attr_e('Meta descriptions are displayed in search engine results as a page description.
67
  It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the meta
68
  information on your most popular pages.', 'wp-meta-seo') ?>">
69
  <div class="row panel-statistics">
73
  <div class="row">
74
  <div class="wpms_dashboard_widgets_left">
75
  <h4 class="panel-title dashboard-title">
76
+ <?php esc_html_e('META DESCRIPTION', 'wp-meta-seo') ?>
77
  </h4>
78
  <div class="panel-bottom">
79
  <h3 class="dashboard-title percent_1">0%</h3>
80
  <span class="dashboard-title percent_2">
81
+ <?php esc_html_e('Meta description filled:', 'wp-meta-seo') ?>
82
  <span class="percent">0/0</span>
83
  </span>
84
  </div>
100
  if (!class_exists('MetaSeoAddonAdmin')) {
101
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
102
  }
103
+ $metaseo_addon = new MetaSeoAddonAdmin();
104
  $duplicateTitle = $metaseo_addon->getDuplicateMetatitle();
105
+ $duplicateDesc = $metaseo_addon->getDuplicateMetadesc();
106
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
107
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
108
  }
109
  ?>
110
 
111
  <div class="wpms_dash_widgets wpms_dash_imgsresize"
112
+ data-alt="<?php esc_attr_e('Display image at its natural size, do not use HTML resize.
113
  It happens usually when you use handles to resize an image. You have a bulk
114
  edition tool to fix that.', 'wp-meta-seo') ?>">
115
  <div class="row panel-statistics">
119
  <div class="row">
120
  <div class="wpms_dashboard_widgets_left">
121
  <h4 class="panel-title dashboard-title">
122
+ <?php esc_html_e('HTML IMAGE RESIZING', 'wp-meta-seo') ?>
123
  </h4>
124
  <div class="panel-bottom">
125
  <h3 class="dashboard-title percent_1">0%</h3>
126
  <span class="dashboard-title percent_2">
127
+ <?php esc_html_e('Wrong resized images:', 'wp-meta-seo') ?>
128
  <span class="percent">0/0</span>
129
  </span>
130
  </div>
142
  </div>
143
 
144
  <div class="wpms_dash_widgets wpms_dash_imgsmeta"
145
+ data-alt="<?php esc_attr_e('We recommend to use both alt text.
146
  The main advantage is that it helps search engines discover your images and display
147
  them in image search results. Plus, these tags improve the accessibility of your site and
148
  give more information about your images. Use our bulk image
154
  <div class="row">
155
  <div class="wpms_dashboard_widgets_left">
156
  <h4 class="panel-title dashboard-title">
157
+ <?php esc_html_e('IMAGE ALT', 'wp-meta-seo') ?>
158
  </h4>
159
  <div class="panel-bottom">
160
  <h3 class="dashboard-title percent_1">0%</h3>
161
  <span class="dashboard-title percent_2">
162
+ <?php esc_html_e('Image data filled (in content):', 'wp-meta-seo') ?>
163
  <span class="percent">0/0</span>
164
  </span>
165
  </div>
177
  </div>
178
 
179
  <div class="wpms_dash_widgets wpms_dash_newcontent"
180
+ data-alt="<?php esc_attr_e('It is highly recommended to update or add new content on your website quite frequently.
181
  At least 3 updated or new content per month would be great :)', 'wp-meta-seo') ?>">
182
  <div class="row panel-statistics">
183
  <div class="tooltipped">
186
  <div class="row">
187
  <div class="wpms_dashboard_widgets_left">
188
  <h4 class="panel-title dashboard-title">
189
+ <?php esc_html_e('NEW OR UPDATED CONTENT', 'wp-meta-seo') ?>
190
  </h4>
191
  <div class="panel-bottom">
192
  <h3 class="dashboard-title percent_1">0%</h3>
193
  <span class="dashboard-title percent_2">
194
+ <?php esc_html_e('Latest month new or updated content:', 'wp-meta-seo') ?>
195
  <span class="percent">0</span>
196
  </span>
197
  </div>
209
  </div>
210
 
211
  <div class="wpms_dash_widgets wpms_dash_linkmeta"
212
+ data-alt="<?php esc_attr_e('The link title attribute does not have any SEO value for links.
213
  BUT links titles can influence click behavior for users, which may indirectly affect
214
  your SEO performance', 'wp-meta-seo') ?>">
215
  <div class="row panel-statistics">
218
  <div class="panel-body">
219
  <div class="row">
220
  <div class="wpms_dashboard_widgets_left">
221
+ <h4 class="panel-title dashboard-title"><?php esc_html_e('LINK TITLES', 'wp-meta-seo') ?></h4>
222
  <div class="panel-bottom">
223
  <h3 class="dashboard-title percent_1">0%</h3>
224
  <span class="dashboard-title percent_2">
225
+ <?php esc_html_e('Links title completed:', 'wp-meta-seo') ?>
226
  <span class="percent">0/0</span>
227
  </span>
228
  </div>
240
  </div>
241
 
242
  <div class="wpms_dash_widgets wpms_dash_404_error"
243
+ data-alt="<?php esc_attr_e('A website with a bunch of 404 errors doesn’t provide a good user experience,
244
  which is significantly important in content marketing and SEO. We recommend to use our internal
245
  broken link checker and redirect tool to fix all the 404 error you can periodically.', 'wp-meta-seo') ?>">
246
  <div class="row panel-statistics">
249
  <div class="panel-body">
250
  <div class="row">
251
  <div class="wpms_dashboard_widgets_left">
252
+ <h4 class="panel-title dashboard-title"><?php esc_html_e('404 ERRORS', 'wp-meta-seo') ?></h4>
253
  <div class="panel-bottom">
254
+ <h3 class="dashboard-title percent_1"><?php echo esc_html($error_404['percent']) ?>%</h3>
255
  <span class="dashboard-title percent_2">
256
  <?php
257
+ esc_html_e('Redirected 404 errors', 'wp-meta-seo');
258
  echo ': ';
259
+ echo esc_html($error_404['count_404_redirected'] . '/' . $error_404['count_404']);
260
  ?>
261
  </div>
262
  </div>
263
  <div class="wpms_dashboard_widgets_right">
264
  <div class="progress-rating">
265
  <div class="determinate percent_3"
266
+ style="width: <?php echo esc_html($error_404['percent']) ?>%"></div>
267
  </div>
268
  </div>
269
  </div>
inc/pages/google-analytics/form-connect.php CHANGED
@@ -4,7 +4,7 @@
4
  <tbody>
5
  <tr>
6
  <td colspan="2">
7
- <h2><?php _e('Plugin Authorization', 'wp-meta-seo') ?></h2>
8
  </td>
9
  </tr>
10
  <tr>
@@ -13,15 +13,15 @@
13
  <input id="wpmsga_dash_userapi" type="checkbox" name="wpmsga_dash_userapi"
14
  value="1" <?php checked($this->google_alanytics['wpmsga_dash_userapi'], 1) ?>>
15
  <label class="metaseo_tool" for="wpmsga_dash_userapi"
16
- alt="<?php _e('You have the option to create your own Google developer
17
  project and use your own API key for tracking (optional)', 'wp-meta-seo') ?>">
18
- <?php _e(' Use your own API Project credentials', 'wp-meta-seo') ?>
19
  </label>
20
  </div>
21
  </td>
22
  </tr>
23
  <tr>
24
- <td class="gadwp-settings-title"><label><?php _e('Client ID:', 'wp-meta-seo') ?></label></td>
25
  <td>
26
  <label>
27
  <?php
@@ -32,13 +32,14 @@
32
  }
33
  ?>
34
  <input type="text" name="wpmsga_dash_clientid"
35
- value="<?php echo $value ?>"
36
  size="40" required="required">
37
  </label>
 
38
  </td>
39
  </tr>
40
  <tr>
41
- <td class="gadwp-settings-title"><label><?php _e('Client Secret:', 'wp-meta-seo') ?></label></td>
42
  <td>
43
  <label>
44
  <?php
@@ -49,7 +50,7 @@
49
  }
50
  ?>
51
  <input type="text" name="wpmsga_dash_clientsecret"
52
- value="<?php echo $value ?>"
53
  size="40" required="required">
54
  </label>
55
  </td>
@@ -62,7 +63,7 @@
62
  <tr>
63
  <td colspan="2">
64
  <input type="submit" name="Authorize" class="wpmsbtn" id="authorize"
65
- value="<?php _e('Save Changes', 'wp-meta-seo') ?>">
66
  </td>
67
  </tr>
68
  </tbody>
@@ -78,19 +79,22 @@ if (!empty($this->google_alanytics['wpmsga_dash_clientid'])
78
  <table class="wpms-settings-options">
79
  <tr>
80
  <td colspan="2" class="wpms-settings-info">
81
- <?php echo __("Use this link to get your access code:", 'wp-meta-seo') . '
82
- <a href="' . $authUrl . '" id="gapi-access-code"
83
- target="_blank">' . __("Get Access Code", 'wp-meta-seo') . '</a>.'; ?>
84
  </td>
85
  </tr>
86
  <tr>
87
  <td class="wpms-settings-title">
88
  <label for="wpms_ga_code"
89
- title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>">
90
- <?php _e("Access Code:", 'wp-meta-seo'); ?></label>
 
 
 
 
 
91
  </td>
92
- <td><input type="text" id="ga_dash_code" name="wpms_ga_code" value="" size="61" required="required"
93
- title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>"></td>
94
  </tr>
95
 
96
  <tr>
@@ -101,7 +105,7 @@ if (!empty($this->google_alanytics['wpmsga_dash_clientid'])
101
  <tr>
102
  <td colspan="2">
103
  <input type="submit" class="button button-secondary wpmsga_authorize" name="ga_dash_authorize"
104
- value="<?php _e("Save Access Code", 'wp-meta-seo'); ?>"/>
105
  </td>
106
  </tr>
107
  </table>
4
  <tbody>
5
  <tr>
6
  <td colspan="2">
7
+ <h2><?php esc_html_e('Plugin Authorization', 'wp-meta-seo') ?></h2>
8
  </td>
9
  </tr>
10
  <tr>
13
  <input id="wpmsga_dash_userapi" type="checkbox" name="wpmsga_dash_userapi"
14
  value="1" <?php checked($this->google_alanytics['wpmsga_dash_userapi'], 1) ?>>
15
  <label class="metaseo_tool" for="wpmsga_dash_userapi"
16
+ alt="<?php esc_attr_e('You have the option to create your own Google developer
17
  project and use your own API key for tracking (optional)', 'wp-meta-seo') ?>">
18
+ <?php esc_html_e(' Use your own API Project credentials', 'wp-meta-seo') ?>
19
  </label>
20
  </div>
21
  </td>
22
  </tr>
23
  <tr>
24
+ <td class="gadwp-settings-title"><label><?php esc_html_e('Client ID:', 'wp-meta-seo') ?></label></td>
25
  <td>
26
  <label>
27
  <?php
32
  }
33
  ?>
34
  <input type="text" name="wpmsga_dash_clientid"
35
+ value="<?php echo esc_attr($value) ?>"
36
  size="40" required="required">
37
  </label>
38
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
39
  </td>
40
  </tr>
41
  <tr>
42
+ <td class="gadwp-settings-title"><label><?php esc_html_e('Client Secret:', 'wp-meta-seo') ?></label></td>
43
  <td>
44
  <label>
45
  <?php
50
  }
51
  ?>
52
  <input type="text" name="wpmsga_dash_clientsecret"
53
+ value="<?php echo esc_attr($value) ?>"
54
  size="40" required="required">
55
  </label>
56
  </td>
63
  <tr>
64
  <td colspan="2">
65
  <input type="submit" name="Authorize" class="wpmsbtn" id="authorize"
66
+ value="<?php esc_attr_e('Save Changes', 'wp-meta-seo') ?>">
67
  </td>
68
  </tr>
69
  </tbody>
79
  <table class="wpms-settings-options">
80
  <tr>
81
  <td colspan="2" class="wpms-settings-info">
82
+ <?php echo esc_html__('Use this link to get your access code:', 'wp-meta-seo') . '
83
+ <a href="' . esc_url($authUrl) . '" id="gapi-access-code"
84
+ target="_blank">' . esc_html__('Get Access Code', 'wp-meta-seo') . '</a>.'; ?>
85
  </td>
86
  </tr>
87
  <tr>
88
  <td class="wpms-settings-title">
89
  <label for="wpms_ga_code"
90
+ title="<?php esc_attr_e('Use the red link to get your access code!', 'wp-meta-seo') ?>">
91
+ <?php esc_html_e('Access Code:', 'wp-meta-seo'); ?></label>
92
+ </td>
93
+ <td>
94
+ <input type="text" id="ga_dash_code" name="wpms_ga_code" value="" size="61" required="required"
95
+ title="<?php esc_attr_e('Use the red link to get your access code!', 'wp-meta-seo') ?>">
96
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
97
  </td>
 
 
98
  </tr>
99
 
100
  <tr>
105
  <tr>
106
  <td colspan="2">
107
  <input type="submit" class="button button-secondary wpmsga_authorize" name="ga_dash_authorize"
108
+ value="<?php esc_attr_e('Save Access Code', 'wp-meta-seo'); ?>"/>
109
  </td>
110
  </tr>
111
  </table>
inc/pages/google-analytics/ga-trackcode.php CHANGED
@@ -28,16 +28,16 @@
28
  $trackExclude = $this->ga_tracking['wpmsga_track_exclude'];
29
 
30
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
31
- $message = "<div class='error'><p>" . __("The tracking component is disabled.
32
- You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'wp-meta-seo') . ".</p></div>";
33
- echo $message;
34
  }
35
 
36
  if (empty($this->google_alanytics['tableid_jail'])) {
37
- $message = "<div class='error'><p>" . __('You have to select a profile: ', 'wp-meta-seo') . '
38
- <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">
39
- ' . __("authorize the plugin", 'wp-meta-seo') . '</a></p></div>';
40
- echo $message;
 
41
  }
42
 
43
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
@@ -48,12 +48,12 @@
48
  <table class="wpmsga-settings-options">
49
  <tbody>
50
  <tr>
51
- <td colspan="2"><h2><?php _e('Tracking Settings', 'wp-meta-seo') ?></h2></td>
52
  </tr>
53
  <tr>
54
  <td class="wpmsga-settings-title"><label
55
  for="wpmsga_dash_tracking">
56
- <?php _e('Tracking Options:', 'wp-meta-seo') ?>
57
  </label>
58
  </td>
59
  <td>
@@ -61,16 +61,16 @@
61
  name="_metaseo_ggtracking_settings[wpmsga_dash_tracking]"
62
  onchange="this.form.submit()">
63
  <option value="0" <?php selected($this->ga_tracking['wpmsga_dash_tracking'], 0) ?>>
64
- <?php _e('Disabled', 'wp-meta-seo') ?>
65
  </option>
66
  <option value="1" <?php selected($this->ga_tracking['wpmsga_dash_tracking'], 1) ?>>
67
- <?php _e('Enabled', 'wp-meta-seo') ?>
68
  </option>
69
  </select>
70
  <div class="wpmsga_clear_author">
71
  <input type="button" name="wpmsClearauthor"
72
  class="wpmsClearauthor button button-secondary"
73
- value="<?php _e("!Remove tracking authorization!", 'wp-meta-seo') ?>">
74
  <span class="spinner"></span>
75
  </div>
76
  </td>
@@ -79,26 +79,27 @@
79
  <tr>
80
  <td class="wpmsga-settings-title"><label
81
  for="wpmsga_dash_tracking">
82
- <?php _e('Analytics profile:', 'wp-meta-seo') ?>
83
  </label>
84
  </td>
85
  <td>
86
  <label>
 
87
  <select id="tableid_jail" name="tableid_jail">
88
  <?php
89
- echo '<option value="0">' . __('Select a profile', 'wp-meta-seo') . '</option>';
90
  if (!empty($this->google_alanytics['profile_list'])) {
91
  foreach ($this->google_alanytics['profile_list'] as $items) {
92
  if ($items[3]) {
93
  echo '<optgroup
94
- label="' . esc_html(WpmsGaTools::stripProtocol($items[3])) . '">';
95
  if (isset($this->google_alanytics['tableid_jail'])
96
- && $this->google_alanytics['tableid_jail'] == $items[1]) {
97
  echo '<option value="' . esc_attr($items[1]) . '" selected';
98
- echo '>' . esc_attr($items[0]) . '</option>';
99
  } else {
100
  echo '<option value="' . esc_attr($items[1]) . '" ';
101
- echo '>' . esc_attr($items[0]) . '</option>';
102
  }
103
 
104
  echo '</optgroup >';
@@ -106,7 +107,7 @@
106
  }
107
  } else {
108
  echo '<option value="">
109
- ' . __('Property not found', 'wp-meta-seo') . '</option>';
110
  }
111
  ?>
112
  </select>
@@ -127,10 +128,10 @@
127
  );
128
  if (!empty($profile_info[0])
129
  && !empty($this->ga_tracking['wpmsga_dash_tracking'])) {
130
- echo '<pre>View Name: ' . $profile_info[0] . '<br>
131
- Tracking ID: ' . $profile_info[2] . '<br>
132
- Default URL: ' . $profile_info[3] . '<br>
133
- Time Zone: ' . $profile_info[5] . '</pre>';
134
  }
135
  }
136
  ?>
@@ -139,27 +140,27 @@ Time Zone: ' . $profile_info[5] . '</pre>';
139
  <tr>
140
  <td colspan="2">
141
  <hr>
142
- <h2><?php _e('Basic Tracking', 'wp-meta-seo') ?></h2></td>
143
  </tr>
144
  <tr>
145
  <td class="wpmsga-settings-title"><label
146
  for="wpmsga_dash_tracking_type">
147
- <?php _e('Tracking Type:', 'wp-meta-seo') ?></label>
148
  </td>
149
  <td><select id="wpmsga_dash_tracking_type"
150
  name="_metaseo_ggtracking_settings[wpmsga_dash_tracking_type]">
151
  <option value="classic"
152
  <?php selected($this->ga_tracking['wpmsga_dash_tracking_type'], 'classic') ?>>
153
- <?php _e('Classic Analytics', 'wp-meta-seo') ?></option>
154
  <option value="universal"
155
  <?php selected($this->ga_tracking['wpmsga_dash_tracking_type'], 'universal') ?>>
156
- <?php _e('Universal Analytics', 'wp-meta-seo') ?></option>
157
  </select></td>
158
  </tr>
159
  <tr>
160
  <td colspan="2" class="wpmsga-settings-title">
161
  <label class="wpms_label_100">
162
- <?php _e(' anonymize IPs while tracking', 'wp-meta-seo'); ?>
163
  </label>
164
  <div class="switch-optimization">
165
  <label class="switch switch-optimization">
@@ -177,7 +178,7 @@ Time Zone: ' . $profile_info[5] . '</pre>';
177
  <td colspan="2" class="wpmsga-settings-title">
178
  <label class="wpms_label_100">
179
  <?php
180
- _e(' enable remarketing, demographics and interests reports', 'wp-meta-seo');
181
  ?>
182
  </label>
183
  <div class="switch-optimization">
@@ -199,12 +200,12 @@ Time Zone: ' . $profile_info[5] . '</pre>';
199
  <table class="wpmsga-settings-options">
200
  <tbody>
201
  <tr>
202
- <td colspan="2"><h2><?php _e('Events Tracking', 'wp-meta-seo') ?></h2></td>
203
  </tr>
204
  <tr>
205
  <td colspan="2" class="wpmsga-settings-title">
206
  <label class="wpms_label_100">
207
- <?php _e(' track downloads, mailto and outbound links', 'wp-meta-seo'); ?>
208
  </label>
209
  <div class="switch-optimization">
210
  <label class="switch switch-optimization">
@@ -221,12 +222,12 @@ Time Zone: ' . $profile_info[5] . '</pre>';
221
  <tr>
222
  <td class="wpmsga-settings-title"><label
223
  for="wpmsga_event_downloads">
224
- <?php _e('Downloads Regex:', 'wp-meta-seo') ?>
225
  </label>
226
  </td>
227
  <td><input type="text" id="wpmsga_event_downloads"
228
  name="_metaseo_ggtracking_settings[wpmsga_event_downloads]"
229
- value="<?php echo $this->ga_tracking['wpmsga_event_downloads'] ?>" size="50">
230
  </td>
231
  </tr>
232
  </tbody>
@@ -237,12 +238,12 @@ Time Zone: ' . $profile_info[5] . '</pre>';
237
  <table class="wpmsga-settings-options">
238
  <tbody>
239
  <tr>
240
- <td colspan="2"><h2><?php _e('Exclude Tracking', 'wp-meta-seo') ?></h2></td>
241
  </tr>
242
  <tr>
243
  <td class="roles wpmsga-settings-title"><label
244
  for="wpmsga_track_exclude">
245
- <?php _e('Exclude tracking for:', 'wp-meta-seo') ?>
246
  </label>
247
  </td>
248
  <td class="wpmsga-settings-roles">
@@ -253,31 +254,31 @@ Time Zone: ' . $profile_info[5] . '</pre>';
253
  <div class="pure-checkbox">
254
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
255
  <?php
256
- echo (in_array('administrator', $trackExclude)) ? "checked" : ""
257
  ?>
258
  value="administrator" id="wpmsga_track_exclude_administrator"
259
  type="checkbox">
260
  <label for="wpmsga_track_exclude_administrator">
261
- <?php _e("Administrator", 'wp-meta-seo'); ?></label>
262
  </div>
263
  </td>
264
  <td>
265
  <div class="pure-checkbox">
266
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
267
- <?php echo (in_array('editor', $trackExclude)) ? "checked" : "" ?>
268
  value="editor" id="wpmsga_track_exclude_editor" type="checkbox">
269
  <label for="wpmsga_track_exclude_editor">
270
- <?php _e("Editor", 'wp-meta-seo'); ?>
271
  </label>
272
  </div>
273
  </td>
274
  <td>
275
  <div class="pure-checkbox">
276
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
277
- <?php echo (in_array('author', $trackExclude)) ? "checked" : "" ?>
278
  value="author" id="wpmsga_track_exclude_author" type="checkbox">
279
  <label for="wpmsga_track_exclude_author">
280
- <?php _e("Author", 'wp-meta-seo'); ?>
281
  </label>
282
  </div>
283
  </td>
@@ -285,12 +286,12 @@ Time Zone: ' . $profile_info[5] . '</pre>';
285
  <div class="pure-checkbox">
286
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
287
  <?php
288
- echo (in_array('contributor', $trackExclude)) ? "checked" : ""
289
  ?>
290
  value="contributor" id="wpmsga_track_exclude_contributor"
291
  type="checkbox">
292
  <label for="wpmsga_track_exclude_contributor">
293
- <?php _e("Contributor", 'wp-meta-seo'); ?>
294
  </label>
295
  </div>
296
  </td>
@@ -299,11 +300,11 @@ Time Zone: ' . $profile_info[5] . '</pre>';
299
  <td>
300
  <div class="pure-checkbox">
301
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
302
- <?php echo in_array('subscriber', $trackExclude) ? "checked" : "" ?>
303
  value="subscriber" id="wpmsga_track_exclude_subscriber"
304
  type="checkbox">
305
  <label for="wpmsga_track_exclude_subscriber">
306
- <?php _e("Subscriber", 'wp-meta-seo'); ?>
307
  </label>
308
  </div>
309
  </td>
28
  $trackExclude = $this->ga_tracking['wpmsga_track_exclude'];
29
 
30
  if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
31
+ echo '<div class="error"><p>' . esc_html__('The tracking component is disabled.
32
+ You should set Tracking Options to Enabled', 'wp-meta-seo') . '.</p></div>';
 
33
  }
34
 
35
  if (empty($this->google_alanytics['tableid_jail'])) {
36
+ echo "<div class='error'><p>";
37
+ esc_html_e('You have to select a profile: ', 'wp-meta-seo');
38
+ echo '<a href="' . esc_url(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) . '">';
39
+ esc_html_e('authorize the plugin', 'wp-meta-seo');
40
+ echo '</a></p></div>';
41
  }
42
 
43
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
48
  <table class="wpmsga-settings-options">
49
  <tbody>
50
  <tr>
51
+ <td colspan="2"><h2><?php esc_html_e('Tracking Settings', 'wp-meta-seo') ?></h2></td>
52
  </tr>
53
  <tr>
54
  <td class="wpmsga-settings-title"><label
55
  for="wpmsga_dash_tracking">
56
+ <?php esc_html_e('Tracking Options:', 'wp-meta-seo') ?>
57
  </label>
58
  </td>
59
  <td>
61
  name="_metaseo_ggtracking_settings[wpmsga_dash_tracking]"
62
  onchange="this.form.submit()">
63
  <option value="0" <?php selected($this->ga_tracking['wpmsga_dash_tracking'], 0) ?>>
64
+ <?php esc_html_e('Disabled', 'wp-meta-seo') ?>
65
  </option>
66
  <option value="1" <?php selected($this->ga_tracking['wpmsga_dash_tracking'], 1) ?>>
67
+ <?php esc_html_e('Enabled', 'wp-meta-seo') ?>
68
  </option>
69
  </select>
70
  <div class="wpmsga_clear_author">
71
  <input type="button" name="wpmsClearauthor"
72
  class="wpmsClearauthor button button-secondary"
73
+ value="<?php esc_attr_e('!Remove tracking authorization!', 'wp-meta-seo') ?>">
74
  <span class="spinner"></span>
75
  </div>
76
  </td>
79
  <tr>
80
  <td class="wpmsga-settings-title"><label
81
  for="wpmsga_dash_tracking">
82
+ <?php esc_html_e('Analytics profile:', 'wp-meta-seo') ?>
83
  </label>
84
  </td>
85
  <td>
86
  <label>
87
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
88
  <select id="tableid_jail" name="tableid_jail">
89
  <?php
90
+ echo '<option value="0">' . esc_html__('Select a profile', 'wp-meta-seo') . '</option>';
91
  if (!empty($this->google_alanytics['profile_list'])) {
92
  foreach ($this->google_alanytics['profile_list'] as $items) {
93
  if ($items[3]) {
94
  echo '<optgroup
95
+ label="' . esc_attr(WpmsGaTools::stripProtocol($items[3])) . '">';
96
  if (isset($this->google_alanytics['tableid_jail'])
97
+ && $this->google_alanytics['tableid_jail'] === $items[1]) {
98
  echo '<option value="' . esc_attr($items[1]) . '" selected';
99
+ echo '>' . esc_html($items[0]) . '</option>';
100
  } else {
101
  echo '<option value="' . esc_attr($items[1]) . '" ';
102
+ echo '>' . esc_html($items[0]) . '</option>';
103
  }
104
 
105
  echo '</optgroup >';
107
  }
108
  } else {
109
  echo '<option value="">
110
+ ' . esc_html__('Property not found', 'wp-meta-seo') . '</option>';
111
  }
112
  ?>
113
  </select>
128
  );
129
  if (!empty($profile_info[0])
130
  && !empty($this->ga_tracking['wpmsga_dash_tracking'])) {
131
+ echo '<pre>View Name: ' . esc_html($profile_info[0]) . '<br>
132
+ Tracking ID: ' . esc_html($profile_info[2]) . '<br>
133
+ Default URL: ' . esc_html($profile_info[3]) . '<br>
134
+ Time Zone: ' . esc_html($profile_info[5]) . '</pre>';
135
  }
136
  }
137
  ?>
140
  <tr>
141
  <td colspan="2">
142
  <hr>
143
+ <h2><?php esc_html_e('Basic Tracking', 'wp-meta-seo') ?></h2></td>
144
  </tr>
145
  <tr>
146
  <td class="wpmsga-settings-title"><label
147
  for="wpmsga_dash_tracking_type">
148
+ <?php esc_html_e('Tracking Type:', 'wp-meta-seo') ?></label>
149
  </td>
150
  <td><select id="wpmsga_dash_tracking_type"
151
  name="_metaseo_ggtracking_settings[wpmsga_dash_tracking_type]">
152
  <option value="classic"
153
  <?php selected($this->ga_tracking['wpmsga_dash_tracking_type'], 'classic') ?>>
154
+ <?php esc_html_e('Classic Analytics', 'wp-meta-seo') ?></option>
155
  <option value="universal"
156
  <?php selected($this->ga_tracking['wpmsga_dash_tracking_type'], 'universal') ?>>
157
+ <?php esc_html_e('Universal Analytics', 'wp-meta-seo') ?></option>
158
  </select></td>
159
  </tr>
160
  <tr>
161
  <td colspan="2" class="wpmsga-settings-title">
162
  <label class="wpms_label_100">
163
+ <?php esc_html_e(' anonymize IPs while tracking', 'wp-meta-seo'); ?>
164
  </label>
165
  <div class="switch-optimization">
166
  <label class="switch switch-optimization">
178
  <td colspan="2" class="wpmsga-settings-title">
179
  <label class="wpms_label_100">
180
  <?php
181
+ esc_html_e(' enable remarketing, demographics and interests reports', 'wp-meta-seo');
182
  ?>
183
  </label>
184
  <div class="switch-optimization">
200
  <table class="wpmsga-settings-options">
201
  <tbody>
202
  <tr>
203
+ <td colspan="2"><h2><?php esc_html_e('Events Tracking', 'wp-meta-seo') ?></h2></td>
204
  </tr>
205
  <tr>
206
  <td colspan="2" class="wpmsga-settings-title">
207
  <label class="wpms_label_100">
208
+ <?php esc_html_e(' track downloads, mailto and outbound links', 'wp-meta-seo'); ?>
209
  </label>
210
  <div class="switch-optimization">
211
  <label class="switch switch-optimization">
222
  <tr>
223
  <td class="wpmsga-settings-title"><label
224
  for="wpmsga_event_downloads">
225
+ <?php esc_html_e('Downloads Regex:', 'wp-meta-seo') ?>
226
  </label>
227
  </td>
228
  <td><input type="text" id="wpmsga_event_downloads"
229
  name="_metaseo_ggtracking_settings[wpmsga_event_downloads]"
230
+ value="<?php echo esc_attr($this->ga_tracking['wpmsga_event_downloads']) ?>" size="50">
231
  </td>
232
  </tr>
233
  </tbody>
238
  <table class="wpmsga-settings-options">
239
  <tbody>
240
  <tr>
241
+ <td colspan="2"><h2><?php esc_html_e('Exclude Tracking', 'wp-meta-seo') ?></h2></td>
242
  </tr>
243
  <tr>
244
  <td class="roles wpmsga-settings-title"><label
245
  for="wpmsga_track_exclude">
246
+ <?php esc_html_e('Exclude tracking for:', 'wp-meta-seo') ?>
247
  </label>
248
  </td>
249
  <td class="wpmsga-settings-roles">
254
  <div class="pure-checkbox">
255
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
256
  <?php
257
+ echo (in_array('administrator', $trackExclude)) ? 'checked' : ''
258
  ?>
259
  value="administrator" id="wpmsga_track_exclude_administrator"
260
  type="checkbox">
261
  <label for="wpmsga_track_exclude_administrator">
262
+ <?php esc_html_e('Administrator', 'wp-meta-seo'); ?></label>
263
  </div>
264
  </td>
265
  <td>
266
  <div class="pure-checkbox">
267
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
268
+ <?php echo (in_array('editor', $trackExclude)) ? 'checked' : '' ?>
269
  value="editor" id="wpmsga_track_exclude_editor" type="checkbox">
270
  <label for="wpmsga_track_exclude_editor">
271
+ <?php esc_html_e('Editor', 'wp-meta-seo'); ?>
272
  </label>
273
  </div>
274
  </td>
275
  <td>
276
  <div class="pure-checkbox">
277
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
278
+ <?php echo (in_array('author', $trackExclude)) ? 'checked' : '' ?>
279
  value="author" id="wpmsga_track_exclude_author" type="checkbox">
280
  <label for="wpmsga_track_exclude_author">
281
+ <?php esc_html_e('Author', 'wp-meta-seo'); ?>
282
  </label>
283
  </div>
284
  </td>
286
  <div class="pure-checkbox">
287
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
288
  <?php
289
+ echo (in_array('contributor', $trackExclude)) ? 'checked' : ''
290
  ?>
291
  value="contributor" id="wpmsga_track_exclude_contributor"
292
  type="checkbox">
293
  <label for="wpmsga_track_exclude_contributor">
294
+ <?php esc_html_e('Contributor', 'wp-meta-seo'); ?>
295
  </label>
296
  </div>
297
  </td>
300
  <td>
301
  <div class="pure-checkbox">
302
  <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
303
+ <?php echo in_array('subscriber', $trackExclude) ? 'checked' : '' ?>
304
  value="subscriber" id="wpmsga_track_exclude_subscriber"
305
  type="checkbox">
306
  <label for="wpmsga_track_exclude_subscriber">
307
+ <?php esc_html_e('Subscriber', 'wp-meta-seo'); ?>
308
  </label>
309
  </div>
310
  </td>
inc/pages/google-analytics/google-analytics.php CHANGED
@@ -2,12 +2,12 @@
2
  <?php
3
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
4
  ?>
5
- <h2 class="wpms_uppercase"><?php _e('Google Analytics tracking & report', 'wp-meta-seo') ?></h2>
6
- <p><?php _e('Enable Google Analytics tracking and reports using a Google Analytics
7
  direct connection. Require a Google Analytics login', 'wp-meta-seo') ?></p>
8
  <p>
9
- <a class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" href="<?php echo $authUrl ?>"
10
- target="_blank"><?php _e("Generate Access Code", 'wp-meta-seo') ?></a>
11
  </p>
12
  <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
13
  <?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
@@ -15,11 +15,14 @@
15
  <tr>
16
  <td class="wpms-settings-title">
17
  <label for="wpms_ga_code"
18
- title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>">
19
- <?php _e("Access Code:", 'wp-meta-seo'); ?></label>
 
 
 
 
 
20
  </td>
21
- <td><input type="text" id="ga_dash_code" name="wpms_ga_code" value="" size="61"
22
- title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>"></td>
23
  </tr>
24
  <tr>
25
  <td colspan="2">
@@ -27,9 +30,9 @@
27
  <input id="wpmsga_dash_userapi" type="checkbox" name="wpmsga_dash_userapi"
28
  value="1" <?php checked($this->google_alanytics['wpmsga_dash_userapi'], 1) ?>>
29
  <label class="metaseo_tool" for="wpmsga_dash_userapi"
30
- alt="<?php _e('You have the option to create your own Google developer
31
  project and use your own API key for tracking (optional)', 'wp-meta-seo') ?>">
32
- <?php _e(' Use your own API Project credentials', 'wp-meta-seo') ?></label>
33
  </div>
34
  </td>
35
  </tr>
@@ -37,37 +40,38 @@
37
  <div class="wpms_wrap_hr">
38
  <hr class="wpms_hr">
39
  </div>
40
- <h2 class="wpms_uppercase"><?php _e('Google analytics tracking only', 'wp-meta-seo') ?></h2>
41
- <p><?php _e('Enable Google Analytics tracking only. You won\'t be
42
  able to display statistics in your', 'wp-meta-seo') ?></p>
43
- <p><?php _e('Wordpress admin, only on Google Analytics website', 'wp-meta-seo') ?></p>
44
 
45
  <table class="wpms-settings-options">
46
  <tr>
47
  <td class="wpms-settings-title"><label for="wpms_ga_uax_reference"
48
- title="<?php _e("Analytics UA-X reference", 'wp-meta-seo') ?>">
49
- <?php _e("Analytics UA-X reference:", 'wp-meta-seo'); ?></label>
50
  </td>
51
  <td>
52
  <input type="text" id="wpms_ga_uax_reference" name="_metaseo_ga_disconnect[wpms_ga_uax_reference]"
53
- value="<?php echo $this->gaDisconnect['wpms_ga_uax_reference'] ?>" size="61">
 
54
  </td>
55
  </tr>
56
  <tr>
57
  <td class="wpms-settings-title"><label for="wpms_ga_uax_reference"
58
- title="<?php _e("Analytics tracking type", 'wp-meta-seo') ?>">
59
- <?php _e("Analytics tracking type", 'wp-meta-seo'); ?></label>
60
  </td>
61
  <td>
62
  <label>
63
  <select id="wpmsga_dash_tracking_type" name="_metaseo_ga_disconnect[wpmsga_dash_tracking_type]">
64
  <option value="classic"
65
  <?php selected($this->gaDisconnect['wpmsga_dash_tracking_type'], 'classic') ?>>
66
- <?php _e('Classic Analytics', 'wp-meta-seo') ?>
67
  </option>
68
  <option value="universal"
69
  <?php selected($this->gaDisconnect['wpmsga_dash_tracking_type'], 'universal') ?>>
70
- <?php _e('Universal Analytics', 'wp-meta-seo') ?>
71
  </option>
72
  </select>
73
  </label>
@@ -75,23 +79,23 @@
75
  </tr>
76
  </table>
77
  <p class="description">
78
- <?php _e('If you are using Universal Analytics make sure
79
  you have changed your account to a Universal Analytics', 'wp-meta-seo') ?>
80
  </p>
81
  <p class="description">
82
- <?php _e('property in Google Analytics Read more about Universal Analytics ', 'wp-meta-seo') ?>
83
  <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/upgrade/">here</a>
84
  </p>
85
- <p><?php _e('OR use Analytics JS code', 'wp-meta-seo') ?></p>
86
  <label>
87
  <textarea name="_metaseo_ga_disconnect[wpmsga_code_tracking]"
88
  class="wpmsga_code_tracking">
89
- <?php echo $this->gaDisconnect['wpmsga_code_tracking'] ?>
90
  </textarea>
91
  </label>
92
  <p>
93
  <input type="submit" class="wpmsbtn wpmsga_authorize" name="ga_dash_authorize"
94
- value="<?php _e("Save Changes", 'wp-meta-seo'); ?>"/>
95
  </p>
96
  </form>
97
  </div>
2
  <?php
3
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
4
  ?>
5
+ <h2 class="wpms_uppercase"><?php esc_html_e('Google Analytics tracking & report', 'wp-meta-seo') ?></h2>
6
+ <p><?php esc_html_e('Enable Google Analytics tracking and reports using a Google Analytics
7
  direct connection. Require a Google Analytics login', 'wp-meta-seo') ?></p>
8
  <p>
9
+ <a class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" href="<?php echo esc_url($authUrl) ?>"
10
+ target="_blank"><?php esc_html_e('Generate Access Code', 'wp-meta-seo') ?></a>
11
  </p>
12
  <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
13
  <?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
15
  <tr>
16
  <td class="wpms-settings-title">
17
  <label for="wpms_ga_code"
18
+ title="<?php esc_attr_e('Use the red link to get your access code!', 'wp-meta-seo') ?>">
19
+ <?php esc_html_e('Access Code:', 'wp-meta-seo'); ?></label>
20
+ </td>
21
+ <td>
22
+ <input type="text" id="ga_dash_code" name="wpms_ga_code" value="" size="61"
23
+ title="<?php esc_attr_e('Use the red link to get your access code!', 'wp-meta-seo') ?>">
24
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
25
  </td>
 
 
26
  </tr>
27
  <tr>
28
  <td colspan="2">
30
  <input id="wpmsga_dash_userapi" type="checkbox" name="wpmsga_dash_userapi"
31
  value="1" <?php checked($this->google_alanytics['wpmsga_dash_userapi'], 1) ?>>
32
  <label class="metaseo_tool" for="wpmsga_dash_userapi"
33
+ alt="<?php esc_attr_e('You have the option to create your own Google developer
34
  project and use your own API key for tracking (optional)', 'wp-meta-seo') ?>">
35
+ <?php esc_html_e(' Use your own API Project credentials', 'wp-meta-seo') ?></label>
36
  </div>
37
  </td>
38
  </tr>
40
  <div class="wpms_wrap_hr">
41
  <hr class="wpms_hr">
42
  </div>
43
+ <h2 class="wpms_uppercase"><?php esc_html_e('Google analytics tracking only', 'wp-meta-seo') ?></h2>
44
+ <p><?php esc_html_e('Enable Google Analytics tracking only. You won\'t be
45
  able to display statistics in your', 'wp-meta-seo') ?></p>
46
+ <p><?php esc_html_e('Wordpress admin, only on Google Analytics website', 'wp-meta-seo') ?></p>
47
 
48
  <table class="wpms-settings-options">
49
  <tr>
50
  <td class="wpms-settings-title"><label for="wpms_ga_uax_reference"
51
+ title="<?php esc_attr_e('Analytics UA-X reference', 'wp-meta-seo') ?>">
52
+ <?php esc_html_e('Analytics UA-X reference:', 'wp-meta-seo'); ?></label>
53
  </td>
54
  <td>
55
  <input type="text" id="wpms_ga_uax_reference" name="_metaseo_ga_disconnect[wpms_ga_uax_reference]"
56
+ value="<?php echo esc_attr($this->gaDisconnect['wpms_ga_uax_reference']) ?>" size="61">
57
+ <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>">
58
  </td>
59
  </tr>
60
  <tr>
61
  <td class="wpms-settings-title"><label for="wpms_ga_uax_reference"
62
+ title="<?php esc_attr_e('Analytics tracking type', 'wp-meta-seo') ?>">
63
+ <?php esc_html_e('Analytics tracking type', 'wp-meta-seo'); ?></label>
64
  </td>
65
  <td>
66
  <label>
67
  <select id="wpmsga_dash_tracking_type" name="_metaseo_ga_disconnect[wpmsga_dash_tracking_type]">
68
  <option value="classic"
69
  <?php selected($this->gaDisconnect['wpmsga_dash_tracking_type'], 'classic') ?>>
70
+ <?php esc_html_e('Classic Analytics', 'wp-meta-seo') ?>
71
  </option>
72
  <option value="universal"
73
  <?php selected($this->gaDisconnect['wpmsga_dash_tracking_type'], 'universal') ?>>
74
+ <?php esc_html_e('Universal Analytics', 'wp-meta-seo') ?>
75
  </option>
76
  </select>
77
  </label>
79
  </tr>
80
  </table>
81
  <p class="description">
82
+ <?php esc_html_e('If you are using Universal Analytics make sure
83
  you have changed your account to a Universal Analytics', 'wp-meta-seo') ?>
84
  </p>
85
  <p class="description">
86
+ <?php esc_html_e('property in Google Analytics Read more about Universal Analytics ', 'wp-meta-seo') ?>
87
  <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/upgrade/">here</a>
88
  </p>
89
+ <p><?php esc_html_e('OR use Analytics JS code', 'wp-meta-seo') ?></p>
90
  <label>
91
  <textarea name="_metaseo_ga_disconnect[wpmsga_code_tracking]"
92
  class="wpmsga_code_tracking">
93
+ <?php echo esc_textarea($this->gaDisconnect['wpmsga_code_tracking']); ?>
94
  </textarea>
95
  </label>
96
  <p>
97
  <input type="submit" class="wpmsbtn wpmsga_authorize" name="ga_dash_authorize"
98
+ value="<?php esc_attr_e('Save Changes', 'wp-meta-seo'); ?>"/>
99
  </p>
100
  </form>
101
  </div>
inc/pages/google-analytics/menu.php CHANGED
@@ -1,11 +1,14 @@
1
- <?php if (!empty($this->google_alanytics)): ?>
 
 
2
  <ul class="wpmstabs wpms-nav-tab-wrapper">
3
 
4
  <li class="tab wpmstab col" style="min-width: 240px">
5
- <a href="<?php echo admin_url('admin.php?page=metaseo_google_analytics') ?>">
6
- <?php _e('Google Analytics Report', 'wp-meta-seo') ?>
7
  </a>
8
  <?php
 
9
  if (empty($_GET['view'])) {
10
  echo '<div class="indicator" style="bottom: 0; left: 0;width:100%"></div>';
11
  }
@@ -13,11 +16,12 @@
13
  </li>
14
 
15
  <li class="tab wpmstab col">
16
- <a href="<?php echo admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') ?>">
17
- <?php _e('Tracking code', 'wp-meta-seo') ?>
18
  </a>
19
  <?php
20
- if (isset($_GET['view']) && $_GET['view'] == 'wpmsga_trackcode') {
 
21
  echo '<div class="indicator" style="bottom: 0; left: 0;width:100%"></div>';
22
  }
23
  ?>
1
+ <?php
2
+ if (!empty($this->google_alanytics)) :
3
+ ?>
4
  <ul class="wpmstabs wpms-nav-tab-wrapper">
5
 
6
  <li class="tab wpmstab col" style="min-width: 240px">
7
+ <a href="<?php echo esc_url(admin_url('admin.php?page=metaseo_google_analytics')) ?>">
8
+ <?php esc_html_e('Google Analytics Report', 'wp-meta-seo') ?>
9
  </a>
10
  <?php
11
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
12
  if (empty($_GET['view'])) {
13
  echo '<div class="indicator" style="bottom: 0; left: 0;width:100%"></div>';
14
  }
16
  </li>
17
 
18
  <li class="tab wpmstab col">
19
+ <a href="<?php echo esc_url(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) ?>">
20
+ <?php esc_html_e('Tracking code', 'wp-meta-seo') ?>
21
  </a>
22
  <?php
23
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
24
+ if (isset($_GET['view']) && $_GET['view'] === 'wpmsga_trackcode') {
25
  echo '<div class="indicator" style="bottom: 0; left: 0;width:100%"></div>';
26
  }
27
  ?>
inc/pages/image-meta.php CHANGED
@@ -10,6 +10,7 @@ $metaseo_list_table = new MetaSeoImageListTable();
10
  $metaseo_list_table->processAction();
11
  $metaseo_list_table->prepare_items();
12
 
 
13
  if (!empty($_REQUEST['_wp_http_referer'])) {
14
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
15
  exit;
@@ -18,7 +19,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
18
 
19
  <div class="wrap seo_extended_table_page">
20
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
21
- <?php echo '<h1>' . __('Image Meta', 'wp-meta-seo') . '</h1>'; ?>
22
  <form id="wp-seo-meta-form" action="" method="post">
23
  <?php $metaseo_list_table->searchBox1(); ?>
24
  <?php $metaseo_list_table->display(); ?>
10
  $metaseo_list_table->processAction();
11
  $metaseo_list_table->prepare_items();
12
 
13
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
14
  if (!empty($_REQUEST['_wp_http_referer'])) {
15
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
16
  exit;
19
 
20
  <div class="wrap seo_extended_table_page">
21
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
22
+ <?php echo '<h1>' . esc_html__('Image Meta', 'wp-meta-seo') . '</h1>'; ?>
23
  <form id="wp-seo-meta-form" action="" method="post">
24
  <?php $metaseo_list_table->searchBox1(); ?>
25
  <?php $metaseo_list_table->display(); ?>
inc/pages/link-meta.php CHANGED
@@ -7,6 +7,7 @@ $metaseo_list_table = new MetaSeoLinkListTable();
7
  $metaseo_list_table->processAction();
8
  $metaseo_list_table->prepare_items();
9
 
 
10
  if (!empty($_REQUEST['_wp_http_referer'])) {
11
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
12
  exit;
@@ -16,7 +17,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
16
  <div class="wrap seo_extended_table_page">
17
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
18
 
19
- <?php echo '<h1>' . __('Link editor', 'wp-meta-seo') . '</h1>'; ?>
20
 
21
  <form id="wp-seo-meta-form" action="" method="post">
22
  <?php $metaseo_list_table->searchBox1(); ?>
@@ -24,8 +25,8 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
24
  </form>
25
 
26
  <?php
27
- $w = '100%';
28
- $text = __('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report,
29
  Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo');
30
  $class_btn_close = 'close_linkmeta';
31
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
7
  $metaseo_list_table->processAction();
8
  $metaseo_list_table->prepare_items();
9
 
10
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
11
  if (!empty($_REQUEST['_wp_http_referer'])) {
12
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
13
  exit;
17
  <div class="wrap seo_extended_table_page">
18
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
19
 
20
+ <?php echo '<h1>' . esc_html__('Link editor', 'wp-meta-seo') . '</h1>'; ?>
21
 
22
  <form id="wp-seo-meta-form" action="" method="post">
23
  <?php $metaseo_list_table->searchBox1(); ?>
25
  </form>
26
 
27
  <?php
28
+ $w = '100%';
29
+ $text = esc_html__('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report,
30
  Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo');
31
  $class_btn_close = 'close_linkmeta';
32
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
inc/pages/metaseo-broken-link.php CHANGED
@@ -2,6 +2,7 @@
2
  if (!class_exists('MetaSeoBrokenLinkTable')) {
3
  require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-broken-link-table.php');
4
  }
 
5
  wp_enqueue_script('wplink');
6
  wp_enqueue_style('editor-buttons');
7
  wp_enqueue_style('metaseo-google-icon');
@@ -12,6 +13,8 @@ $metaseo_list_table = new MetaSeoBrokenLinkTable();
12
  $metaseo_list_table->processAction();
13
  $metaseo_list_table->prepare_items();
14
  $a = json_encode($metaseo_list_table->items);
 
 
15
  if (!empty($_REQUEST['_wp_http_referer'])) {
16
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
17
  exit;
@@ -21,7 +24,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
21
  <div class="wrap broken_link_table seo_extended_table_page">
22
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
23
 
24
- <?php echo '<h1>' . __('404 & Redirects', 'wp-meta-seo') . '</h1>'; ?>
25
 
26
  <form id="wp-seo-meta-form" action="" method="post">
27
 
@@ -31,8 +34,8 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
31
  </form>
32
 
33
  <?php
34
- $w = '100%';
35
- $text = __('Bring your WordPress website SEO to the next level with the PRO Addon: Automatic
36
  redirect based on rules, automatic 404 error index, redirect with link manager,
37
  Email notification and more!', 'wp-meta-seo');
38
  $class_btn_close = 'close_broken_link';
2
  if (!class_exists('MetaSeoBrokenLinkTable')) {
3
  require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-broken-link-table.php');
4
  }
5
+
6
  wp_enqueue_script('wplink');
7
  wp_enqueue_style('editor-buttons');
8
  wp_enqueue_style('metaseo-google-icon');
13
  $metaseo_list_table->processAction();
14
  $metaseo_list_table->prepare_items();
15
  $a = json_encode($metaseo_list_table->items);
16
+
17
+ // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No action, nonce is not required
18
  if (!empty($_REQUEST['_wp_http_referer'])) {
19
  wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
20
  exit;
24
  <div class="wrap broken_link_table seo_extended_table_page">
25
  <div id="icon-edit-pages" class="icon32 icon32-posts-page"></div>
26
 
27
+ <?php echo '<h1>' . esc_html__('404 & Redirects', 'wp-meta-seo') . '</h1>'; ?>
28
 
29
  <form id="wp-seo-meta-form" action="" method="post">
30
 
34
  </form>
35
 
36
  <?php
37
+ $w = '100%';
38
+ $text = esc_html__('Bring your WordPress website SEO to the next level with the PRO Addon: Automatic
39
  redirect based on rules, automatic 404 error index, redirect with link manager,
40
  Email notification and more!', 'wp-meta-seo');
41
  $class_btn_close = 'close_broken_link';
inc/pages/metaseo-image-compression.php CHANGED
@@ -1,70 +1,82 @@
1
  <?php
2
- if (!defined('IFRAME_REQUEST') && isset($_GET['action'])
3
- && in_array($_GET['action'], array('update-selected', 'activate-plugin', 'update-selected-themes'))) {
4
- /**
5
- * Iframe request
6
- */
7
- define('IFRAME_REQUEST', true);
8
- }
9
-
10
- require_once(ABSPATH . 'wp-admin/admin.php');
11
- include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
12
-
13
- $slug = 'imagerecycle-pdf-image-compression';
14
  $plugin_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.php';
15
  if (isset($_GET['action'])) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
17
  $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
18
- if ($action == 'install-plugin') {
19
  if (!current_user_can('install_plugins')) {
20
- wp_die(__('You do not have sufficient permissions to install plugins on this site.', 'wp-meta-seo'));
21
  }
22
 
23
  include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api..
24
 
25
  check_admin_referer('install-plugin_' . $plugin);
26
  $api = plugins_api('plugin_information', array(
27
- 'slug' => $plugin,
28
  'fields' => array(
29
  'short_description' => false,
30
- 'sections' => false,
31
- 'requires' => false,
32
- 'rating' => false,
33
- 'ratings' => false,
34
- 'downloaded' => false,
35
- 'last_updated' => false,
36
- 'added' => false,
37
- 'tags' => false,
38
- 'compatibility' => false,
39
- 'homepage' => false,
40
- 'donate_link' => false,
41
  ),
42
  ));
43
 
44
  if (is_wp_error($api)) {
 
45
  wp_die($api);
46
  }
47
 
48
- $title = __('Plugin Install', 'wp-meta-seo');
49
- $parent_file = 'plugins.php';
50
  $submenu_file = 'plugin-install.php';
51
 
52
- $title = sprintf(__('Installing Plugin: %s', 'wp-meta-seo'), $api->name . ' ' . $api->version);
53
  $nonce = 'install-plugin_' . $plugin;
54
- $url = 'update.php?action=install-plugin&plugin=' . urlencode($plugin);
55
  if (isset($_GET['from'])) {
56
  $url .= '&from=' . urlencode(stripslashes($_GET['from']));
57
  }
58
- $type = 'web'; //Install plugin type, From Web or an Upload.
59
  $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
60
  $upgrader->install($api->download_link);
61
- } elseif ('activate' == $action) {
62
  if (!current_user_can('activate_plugins')) {
63
- wp_die(__('You do not have sufficient permissions to activate plugins for this site.', 'wp-meta-seo'));
64
  }
65
 
66
  if (is_multisite() && !is_network_admin() && is_network_only_plugin($plugin)) {
67
- wp_redirect(self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s"));
68
  exit;
69
  }
70
 
@@ -76,8 +88,10 @@ if (isset($_GET['action'])) {
76
  is_network_admin()
77
  );
78
  if (is_wp_error($result)) {
79
- if ('unexpected_output' == $result->get_error_code()) {
80
- $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
 
 
81
  wp_redirect(
82
  add_query_arg(
83
  '_error_nonce',
@@ -87,32 +101,31 @@ if (isset($_GET['action'])) {
87
  );
88
  exit;
89
  } else {
 
90
  wp_die($result);
91
  }
92
  }
93
 
94
  if (!is_network_admin()) {
95
- $recent = (array)get_option('recently_activated');
96
  unset($recent[$plugin]);
97
  update_option('recently_activated', $recent);
98
  } else {
99
- $recent = (array)get_site_option('recently_activated');
100
  unset($recent[$plugin]);
101
  update_site_option('recently_activated', $recent);
102
  }
103
 
104
- if (isset($_GET['from']) && 'import' == $_GET['from']) {
105
- wp_redirect(self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin)))); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix
106
  } else {
107
  wp_redirect(
108
- self_admin_url(
109
- "admin.php?page=metaseo_image_compression&wpmsactive=imagerecycle"
110
- )
111
- ); // overrides the ?error=true one above
112
  }
113
  }
114
  }
115
- $button = '';
116
  $check_install = false;
117
  if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
118
  $url = wp_nonce_url(
@@ -121,10 +134,10 @@ if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
121
  );
122
  if (is_multisite()) {
123
  if (current_user_can('manage_network_plugins')) {
124
- $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center; color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" target="_blank" class="edit" data-slug="imagerecycle-pdf-image-compression" href="' . $url . '" aria-label="Install ImageRecycle pdf &amp; image compression 2.1.1 now" data-name="ImageRecycle pdf &amp; image compression 2.1.1">' . __('Install ImageRecycle plugin', 'wp-meta-seo') . '</a>';
125
  }
126
  } else {
127
- $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" target="_blank" class="edit" data-slug="imagerecycle-pdf-image-compression" href="' . $url . '" aria-label="Install ImageRecycle pdf &amp; image compression 2.1.1 now" data-name="ImageRecycle pdf &amp; image compression 2.1.1">' . __('Install ImageRecycle plugin', 'wp-meta-seo') . '</a>';
128
  }
129
  } else {
130
  if (!is_plugin_active($plugin_file)) {
@@ -134,19 +147,19 @@ if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
134
  );
135
  if (is_multisite()) {
136
  if (current_user_can('manage_network_plugins')) {
137
- $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center; color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" href="' . $url . '" class="edit" aria-label="Activate ImageRecycle pdf &amp; image compression">' . __('Activate Plugin', 'wp-meta-seo') . '</a>';
138
  }
139
  } else {
140
- $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" href="' . $url . '" class="edit" aria-label="Activate ImageRecycle pdf &amp; image compression">' . __('Activate Plugin', 'wp-meta-seo') . '</a>';
141
  }
142
  } else {
143
  $check_install = true;
144
- $button = '<a style="width: 250px; float: right; background: #554766; line-height: 18px; text-align: center; margin-left:4px;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 8px 20px; font-weight:bold;" class="edit" href="upload.php?page=wp-image-recycle-page" aria-label="Activate ImageRecycle pdf &amp; image compression">' . __('ImageRecycle is properly installed: manage images', 'wp-meta-seo') . '</a>';
145
  }
146
  }
147
  ?>
148
 
149
- <?php if ($check_install == true) : ?>
150
  <div class="main-presentation"
151
  style="margin: 0 auto; max-width: 1200px; background-color:#f0f1f4;font-family: helvetica,arial,sans-serif;">
152
  <div class="main-textcontent"
@@ -167,11 +180,12 @@ if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
167
  WordPress that run the images optimization automatically on your website &amp; PDF
168
  <br/>In order to start the optimization process, please install the WordPress plugin. Enjoy!</p>
169
  <p></p>
170
- <p><?php echo $button; ?></p>
 
 
171
  </div>
172
  </div>
173
  <?php else : ?>
174
-
175
  <div class="main-presentation"
176
  style="margin: 0 auto; max-width: 1200px; background-color:#f0f1f4;font-family: helvetica,arial,sans-serif;">
177
  <div class="main-textcontent"
@@ -195,7 +209,9 @@ if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
195
  website &amp; PDF<br/>In order to start the optimization process, please install the WordPress plugin.
196
  Enjoy!</p>
197
  <p></p>
198
- <p><?php echo $button; ?></p>
 
 
199
  </div>
200
  </div>
201
 
1
  <?php
2
+ $slug = 'imagerecycle-pdf-image-compression';
 
 
 
 
 
 
 
 
 
 
 
3
  $plugin_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.php';
4
  if (isset($_GET['action'])) {
5
+ if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
6
+ $ac = 'install-plugin_' . $slug;
7
+ } else {
8
+ $ac = 'activate-plugin_' . $plugin_file;
9
+ }
10
+
11
+ if (empty($_GET['_wpnonce'])
12
+ || !wp_verify_nonce($_GET['_wpnonce'], $ac)) {
13
+ die();
14
+ }
15
+
16
+ if (!defined('IFRAME_REQUEST') && in_array($_GET['action'], array(
17
+ 'update-selected',
18
+ 'activate-plugin',
19
+ 'update-selected-themes'
20
+ ))
21
+ ) {
22
+ define('IFRAME_REQUEST', true);
23
+ }
24
+
25
+ require_once(ABSPATH . 'wp-admin/admin.php');
26
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
27
  $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
28
  $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
29
+ if ($action === 'install-plugin') {
30
  if (!current_user_can('install_plugins')) {
31
+ wp_die(esc_html__('You do not have sufficient permissions to install plugins on this site.', 'wp-meta-seo'));
32
  }
33
 
34
  include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api..
35
 
36
  check_admin_referer('install-plugin_' . $plugin);
37
  $api = plugins_api('plugin_information', array(
38
+ 'slug' => $plugin,
39
  'fields' => array(
40
  'short_description' => false,
41
+ 'sections' => false,
42
+ 'requires' => false,
43
+ 'rating' => false,
44
+ 'ratings' => false,
45
+ 'downloaded' => false,
46
+ 'last_updated' => false,
47
+ 'added' => false,
48
+ 'tags' => false,
49
+ 'compatibility' => false,
50
+ 'homepage' => false,
51
+ 'donate_link' => false,
52
  ),
53
  ));
54
 
55
  if (is_wp_error($api)) {
56
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Variable is object|array|WP_Error
57
  wp_die($api);
58
  }
59
 
60
+ $title = esc_html__('Plugin Install', 'wp-meta-seo');
61
+ $parent_file = 'plugins.php';
62
  $submenu_file = 'plugin-install.php';
63
 
64
+ $title = sprintf(esc_html__('Installing Plugin: %s', 'wp-meta-seo'), $api->name . ' ' . $api->version);
65
  $nonce = 'install-plugin_' . $plugin;
66
+ $url = 'update.php?action=install-plugin&plugin=' . urlencode($plugin);
67
  if (isset($_GET['from'])) {
68
  $url .= '&from=' . urlencode(stripslashes($_GET['from']));
69
  }
70
+ $type = 'web'; //Install plugin type, From Web or an Upload.
71
  $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
72
  $upgrader->install($api->download_link);
73
+ } elseif ('activate' === $action) {
74
  if (!current_user_can('activate_plugins')) {
75
+ wp_die(esc_html__('You do not have sufficient permissions to activate plugins for this site.', 'wp-meta-seo'));
76
  }
77
 
78
  if (is_multisite() && !is_network_admin() && is_network_only_plugin($plugin)) {
79
+ wp_redirect(self_admin_url('plugins.php?plugin_status=' . $status . '&paged=' . $page . '&s=' . $s));
80
  exit;
81
  }
82
 
88
  is_network_admin()
89
  );
90
  if (is_wp_error($result)) {
91
+ if ('unexpected_output' === $result->get_error_code()) {
92
+ $u = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data());
93
+ $u .= '&plugin=' . $plugin . '&plugin_status=' . $status . '&paged=' . $page . '&s=' . $s;
94
+ $redirect = self_admin_url($u);
95
  wp_redirect(
96
  add_query_arg(
97
  '_error_nonce',
101
  );
102
  exit;
103
  } else {
104
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Variable is WP_Error|null
105
  wp_die($result);
106
  }
107
  }
108
 
109
  if (!is_network_admin()) {
110
+ $recent = (array) get_option('recently_activated');
111
  unset($recent[$plugin]);
112
  update_option('recently_activated', $recent);
113
  } else {
114
+ $recent = (array) get_site_option('recently_activated');
115
  unset($recent[$plugin]);
116
  update_site_option('recently_activated', $recent);
117
  }
118
 
119
+ if (isset($_GET['from']) && 'import' === $_GET['from']) {
120
+ wp_redirect(self_admin_url('import.php?import=' . str_replace('-importer', '', dirname($plugin)))); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix
121
  } else {
122
  wp_redirect(
123
+ self_admin_url('admin.php?page=metaseo_image_compression&wpmsactive=imagerecycle')
124
+ );
 
 
125
  }
126
  }
127
  }
128
+ $button = '';
129
  $check_install = false;
130
  if (!file_exists(WP_PLUGIN_DIR . '/imagerecycle-pdf-image-compression')) {
131
  $url = wp_nonce_url(
134
  );
135
  if (is_multisite()) {
136
  if (current_user_can('manage_network_plugins')) {
137
+ $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center; color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" target="_blank" class="edit" data-slug="imagerecycle-pdf-image-compression" href="' . esc_url($url) . '" aria-label="Install ImageRecycle pdf &amp; image compression 2.1.1 now" data-name="ImageRecycle pdf &amp; image compression 2.1.1">' . esc_html__('Install ImageRecycle plugin', 'wp-meta-seo') . '</a>';
138
  }
139
  } else {
140
+ $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" target="_blank" class="edit" data-slug="imagerecycle-pdf-image-compression" href="' . esc_url($url) . '" aria-label="Install ImageRecycle pdf &amp; image compression 2.1.1 now" data-name="ImageRecycle pdf &amp; image compression 2.1.1">' . esc_html__('Install ImageRecycle plugin', 'wp-meta-seo') . '</a>';
141
  }
142
  } else {
143
  if (!is_plugin_active($plugin_file)) {
147
  );
148
  if (is_multisite()) {
149
  if (current_user_can('manage_network_plugins')) {
150
+ $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center; color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" href="' . esc_url($url) . '" class="edit" aria-label="Activate ImageRecycle pdf &amp; image compression">' . esc_html__('Activate Plugin', 'wp-meta-seo') . '</a>';
151
  }
152
  } else {
153
+ $button = '<a style="float: right; background: #554766; line-height: 18px; text-align: center;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 5px 20px; font-weight:bold;" href="' . esc_url($url) . '" class="edit" aria-label="Activate ImageRecycle pdf &amp; image compression">' . esc_html__('Activate Plugin', 'wp-meta-seo') . '</a>';
154
  }
155
  } else {
156
  $check_install = true;
157
+ $button = '<a style="width: 250px; float: right; background: #554766; line-height: 18px; text-align: center; margin-left:4px;color: #fff;font-size: 14px;text-decoration: none; text-transform: uppercase; padding: 8px 20px; font-weight:bold;" class="edit" href="upload.php?page=wp-image-recycle-page" aria-label="Activate ImageRecycle pdf &amp; image compression">' . esc_html__('ImageRecycle is properly installed: manage images', 'wp-meta-seo') . '</a>';
158
  }
159
  }
160
  ?>
161
 
162
+ <?php if ($check_install) : ?>
163
  <div class="main-presentation"
164
  style="margin: 0 auto; max-width: 1200px; background-color:#f0f1f4;font-family: helvetica,arial,sans-serif;">
165
  <div class="main-textcontent"
180
  WordPress that run the images optimization automatically on your website &amp; PDF
181
  <br/>In order to start the optimization process, please install the WordPress plugin. Enjoy!</p>
182
  <p></p>
183
+ <p>
184
+ <?php echo $button; // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same file) ?>
185
+ </p>
186
  </div>
187
  </div>
188
  <?php else : ?>
 
189
  <div class="main-presentation"
190
  style="margin: 0 auto; max-width: 1200px; background-color:#f0f1f4;font-family: helvetica,arial,sans-serif;">
191
  <div class="main-textcontent"
209
  website &amp; PDF<br/>In order to start the optimization process, please install the WordPress plugin.
210
  Enjoy!</p>
211
  <p></p>
212
+ <p>
213
+ <?php echo $button; // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in previous line (same file) ?>
214
+ </p>
215
  </div>
216
  </div>
217
 
inc/pages/notification.php CHANGED
@@ -1,13 +1,13 @@
1
  <?php
2
  if (!empty($_COOKIE[$class_btn_close])) {
3
- $check = time() - (int)$_COOKIE[$class_btn_close];
4
  $month = 30 * 24 * 60 * 60;
5
  }
6
 
7
  if ((empty($_COOKIE[$class_btn_close]) || (!empty($_COOKIE[$class_btn_close]) && $check >= $month))
8
  && !is_plugin_active(WPMSEO_ADDON_FILENAME)) :
9
  ?>
10
- <div class="wpms_notification wpms_wrap_notification" style="width: <?php echo $w ?>">
11
  <div class="notification_dashboard">
12
  <div class="tooltipped">
13
  <div class="panel panel-updates dashboard-card">
@@ -15,14 +15,14 @@ if ((empty($_COOKIE[$class_btn_close]) || (!empty($_COOKIE[$class_btn_close]) &&
15
  <div class="row">
16
  <div class="wpms_dashboard_widgets_content">
17
  <span class="dashboard_noti_title">
18
- <?php _e('WP META SEO PRO ADDON', 'wp-meta-seo') ?>
19
  </span>
20
- <p class="dashboard-title msg"><?php echo $text ?></p>
21
  <a class="more-info" href="https://www.joomunited.com/wordpress-products/wp-meta-seo"
22
- target="_blank"><?php _e('MORE INFORMATION', 'wp-meta-seo') ?></a>
23
- <a data-page="<?php echo $class_btn_close ?>"
24
- class="dashboard-title wpmsclose_notification <?php echo $class_btn_close ?>">
25
- <?php _e('CLOSE FOR ONE MONTH', 'wp-meta-seo') ?></a>
26
  </div>
27
  </div>
28
  </div>
1
  <?php
2
  if (!empty($_COOKIE[$class_btn_close])) {
3
+ $check = time() - (int) $_COOKIE[$class_btn_close];
4
  $month = 30 * 24 * 60 * 60;
5
  }
6
 
7
  if ((empty($_COOKIE[$class_btn_close]) || (!empty($_COOKIE[$class_btn_close]) && $check >= $month))
8
  && !is_plugin_active(WPMSEO_ADDON_FILENAME)) :
9
  ?>
10
+ <div class="wpms_notification wpms_wrap_notification" style="width: <?php echo esc_html($w) ?>">
11
  <div class="notification_dashboard">
12
  <div class="tooltipped">
13
  <div class="panel panel-updates dashboard-card">
15
  <div class="row">
16
  <div class="wpms_dashboard_widgets_content">
17
  <span class="dashboard_noti_title">
18
+ <?php esc_html_e('WP META SEO PRO ADDON', 'wp-meta-seo') ?>
19
  </span>
20
+ <p class="dashboard-title msg"><?php echo esc_html($text) ?></p>
21
  <a class="more-info" href="https://www.joomunited.com/wordpress-products/wp-meta-seo"
22
+ target="_blank"><?php esc_html_e('MORE INFORMATION', 'wp-meta-seo') ?></a>
23
+ <a data-page="<?php echo esc_attr($class_btn_close) ?>"
24
+ class="<?php echo esc_attr('dashboard-title wpmsclose_notification ' . $class_btn_close) ?>">
25
+ <?php esc_html_e('CLOSE FOR ONE MONTH', 'wp-meta-seo') ?></a>
26
  </div>
27
  </div>
28
  </div>
inc/pages/settings.php CHANGED
@@ -3,23 +3,27 @@ wp_enqueue_style('m-style-qtip');
3
  wp_enqueue_script('jquery-qtip');
4
  ?>
5
  <div class="wrap wrap_wpms_settings">
6
- <h1><?php _e('WP Meta SEO global settings', 'wp-meta-seo') ?></h1>
7
  <div class="tab-header">
8
  <ul class="tabs wpmstabs">
9
- <li class="tab wpmstab col active"><a href="#wpms-global"><?php _e('Global', 'wp-meta-seo') ?></a></li>
 
10
  <li class="tab wpmstab col"><a
11
- href="#wpms-redirection"><?php _e('Redirections and 404', 'wp-meta-seo') ?></a></li>
12
- <li class="tab wpmstab col"><a href="#wpms-breadcrumb"><?php _e('Breadcrumb', 'wp-meta-seo') ?></a></li>
 
13
  <?php
14
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) :
15
  ?>
16
- <li class="tab wpmstab col"><a href="#wpms-email"><?php _e('Send Email', 'wp-meta-seo') ?></a></li>
 
17
  <li class="tab wpmstab col"><a
18
- href="#wpms-local_usiness"><?php _e('Local business', 'wp-meta-seo') ?></a></li>
19
  <?php
20
  endif;
21
  ?>
22
- <li class="tab wpmstab col"><a href="#wpms-jutranslation"><?php _e('Translation', 'wp-meta-seo') ?></a></li>
 
23
  </ul>
24
  </div>
25
  <div class="wpms_content_settings">
@@ -38,16 +42,16 @@ wp_enqueue_script('jquery-qtip');
38
  <table class="form-table">
39
  <tbody>
40
  <tr>
41
- <th scope="row"><?php _e('Global home redirect', 'wp-meta-seo') ?></th>
42
  <td>
43
  <input type="hidden" class="wpms_redirect_homepage" name="wpms_redirect[wpms_redirect_homepage]"
44
- value="<?php echo $defaul_settings_404['wpms_redirect_homepage'] ?>">
45
- <label><?php _e('Redirect all 404 errors to home page', 'wp-meta-seo'); ?></label>
46
  <div class="switch-optimization">
47
  <label class="switch switch-optimization">
48
  <?php
49
  if (isset($defaul_settings_404['wpms_redirect_homepage'])
50
- && $defaul_settings_404['wpms_redirect_homepage'] == 1) :
51
  ?>
52
  <input type="checkbox" class="cb_option" id="wpms_redirect_homepage"
53
  data-label="wpms_redirect_homepage"
@@ -63,31 +67,31 @@ wp_enqueue_script('jquery-qtip');
63
  </td>
64
  </tr>
65
  <tr>
66
- <th scope="row"><?php _e('Custom 404 page', 'wp-meta-seo') ?></th>
67
  <td>
68
  <label>
69
  <select name="wpms_redirect[wpms_type_404]"
70
  class="wpms_type_404"
71
- <?php echo ($defaul_settings_404['wpms_redirect_homepage'] == 1) ? "disabled" : "" ?>>
72
  <?php foreach ($types_404 as $k => $type_404) : ?>
73
  <option <?php selected($defaul_settings_404['wpms_type_404'], $k) ?>
74
- value="<?php echo $k ?>"><?php echo $type_404 ?></option>
75
  <?php endforeach; ?>
76
  </select>
77
  <?php
78
- if ($defaul_settings_404['wpms_redirect_homepage'] == 1
79
- || $defaul_settings_404['wpms_type_404'] != 'custom_page') {
80
  $disable = 'disabled';
81
  } else {
82
  $disable = '';
83
  }
84
  ?>
85
  <select name="wpms_redirect[wpms_page_redirected]"
86
- class="wpms_page_redirected" <?php echo $disable ?>>
87
- <option value="none"><?php _e('— Select —', 'wp-meta-seo') ?></option>
88
  <?php foreach ($posts as $post) : ?>
89
  <option <?php selected($defaul_settings_404['wpms_page_redirected'], $post->ID) ?>
90
- value="<?php echo $post->ID ?>"><?php echo $post->post_title ?></option>
91
  <?php endforeach; ?>
92
  </select>
93
  </label>
@@ -97,11 +101,12 @@ wp_enqueue_script('jquery-qtip');
97
  </table>
98
  <?php
99
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
 
100
  echo $link_settings_html;
101
  }
102
  ?>
103
- <div class="button wpms_save_settings404"><?php _e('Save', 'wp-meta-seo') ?></div>
104
- <span class="message_saved"><?php _e('Saved', 'wp-meta-seo') ?></span>
105
  </div>
106
 
107
  <div id="wpms-breadcrumb" class="content-box">
@@ -109,22 +114,22 @@ wp_enqueue_script('jquery-qtip');
109
  <tbody>
110
  <tr>
111
  <th scope="row">
112
- <label for="<?php _e('The separator that materialize the breadcrumb levels', 'wp-meta-seo') ?>">
113
- <?php _e('Breadcrumb separator', 'wp-meta-seo') ?>
114
  </label>
115
  </th>
116
  <td>
117
  <label>
118
  <input id="breadcrumbs_separator" name="_metaseo_breadcrumbs[separator]" type="text"
119
- value="<?php echo htmlentities($breadcrumbs['separator']) ?>" size="50">
120
  </label>
121
  </td>
122
  </tr>
123
 
124
  <tr>
125
  <th scope="row">
126
- <label for="<?php _e('Include the Home element in the breadcrumb', 'wp-meta-seo') ?>">
127
- <?php _e('Include Home', 'wp-meta-seo') ?></label>
128
  </th>
129
  <td>
130
  <input name="_metaseo_breadcrumbs[include_home]" type="hidden" value="0">
@@ -141,9 +146,9 @@ wp_enqueue_script('jquery-qtip');
141
 
142
  <tr>
143
  <th scope="row">
144
- <label for="<?php _e('If home is included, you may want to force a text.
145
  By default it’s the content title', 'wp-meta-seo') ?>">
146
- <?php _e('Home text', 'wp-meta-seo') ?>
147
  </label>
148
  </th>
149
  <td>
@@ -160,27 +165,27 @@ wp_enqueue_script('jquery-qtip');
160
  </tr>
161
 
162
  <?php
163
- if ($breadcrumbs['home_text_default'] == 0) {
164
  $class = 'hide';
165
  } else {
166
  $class = 'show';
167
  }
168
  ?>
169
- <tr class="tr_home_text <?php echo $class ?>">
170
  <th scope="row">
171
  <label></label>
172
  </th>
173
  <td>
174
  <label>
175
  <input id="breadcrumbs_home_text" name="_metaseo_breadcrumbs[home_text]" type="text"
176
- value="<?php echo $breadcrumbs['home_text'] ?>" size="50">
177
  </label>
178
  </td>
179
  </tr>
180
  <tr>
181
  <th scope="row">
182
- <label for="<?php _e('The breadcrumb element can be clickable or not', 'wp-meta-seo') ?>">
183
- <?php _e('Clickable breadcrumb', 'wp-meta-seo') ?></label>
184
  </th>
185
  <td>
186
  <input name="_metaseo_breadcrumbs[clickable]" type="hidden" value="0">
@@ -197,9 +202,9 @@ wp_enqueue_script('jquery-qtip');
197
 
198
  <tr>
199
  <th scope="row">
200
- <label for="<?php _e('Generate a breadcrumb navigation based on your categories or page levels.
201
  The shortcode can be included in theme layouts', 'wp-meta-seo') ?>">
202
- <?php _e('PHP Shortcode', 'wp-meta-seo') ?>
203
  </label>
204
  </th>
205
  <td>
@@ -223,9 +228,9 @@ wp_enqueue_script('jquery-qtip');
223
 
224
  <tr>
225
  <th scope="row">
226
- <label for="<?php _e('Generate a breadcrumb navigation based on your categories or page levels.
227
  The WordPress shortcode can be called anywhere in your content', 'wp-meta-seo') ?>">
228
- <?php _e('WordPress Shortcode', 'wp-meta-seo') ?>
229
  </label>
230
  </th>
231
  <td>
@@ -236,8 +241,8 @@ wp_enqueue_script('jquery-qtip');
236
  </tr>
237
  </tbody>
238
  </table>
239
- <div class="button wpms_save_settings_breadcrumb"><?php _e('Save', 'wp-meta-seo') ?></div>
240
- <span class="message_saved"><?php _e('Saved', 'wp-meta-seo') ?></span>
241
  </div>
242
 
243
  <div id="wpms-jutranslation" class="content-box">
@@ -246,7 +251,9 @@ wp_enqueue_script('jquery-qtip');
246
 
247
  <?php
248
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
 
249
  echo $html_tabemail;
 
250
  echo $local_business_html;
251
  }
252
  ?>
@@ -309,7 +316,8 @@ wp_enqueue_script('jquery-qtip');
309
  'home_text': home_text,
310
  'include_home': include_home,
311
  'clickable': clickable,
312
- 'home_text_default': home_text_default
 
313
  },
314
  success: function (res) {
315
  if (res) {
@@ -344,7 +352,8 @@ wp_enqueue_script('jquery-qtip');
344
  'wpms_redirect[wpms_page_redirected]': page_redirected,
345
  'enable': enable,
346
  'numberFrequency': $('#numberFrequency').val(),
347
- 'showlinkFrequency': $('#showlinkFrequency').val()
 
348
  },
349
  success: function (res) {
350
  if (res) {
@@ -375,7 +384,8 @@ wp_enqueue_script('jquery-qtip');
375
  port: $('#showSmtpPort').val(),
376
  autentication: $('[name="wpms_email_settings[autentication]"]:checked').val(),
377
  username: $('#showSmtpUser').val(),
378
- password: $('#showSmtpPass').val()
 
379
  },
380
  success: function (res) {
381
  if (res) {
@@ -408,7 +418,8 @@ wp_enqueue_script('jquery-qtip');
408
  city: $('#wpms_local_business_city').val(),
409
  state: $('#wpms_local_business_state').val(),
410
  phone: $('#wpms_local_business_phone').val(),
411
- pricerange: $('#wpms_local_business_pricerange').val()
 
412
  },
413
  success: function (res) {
414
  if (res) {
3
  wp_enqueue_script('jquery-qtip');
4
  ?>
5
  <div class="wrap wrap_wpms_settings">
6
+ <h1><?php esc_html_e('WP Meta SEO global settings', 'wp-meta-seo') ?></h1>
7
  <div class="tab-header">
8
  <ul class="tabs wpmstabs">
9
+ <li class="tab wpmstab col active"><a href="#wpms-global"><?php esc_html_e('Global', 'wp-meta-seo') ?></a>
10
+ </li>
11
  <li class="tab wpmstab col"><a
12
+ href="#wpms-redirection"><?php esc_html_e('Redirections and 404', 'wp-meta-seo') ?></a></li>
13
+ <li class="tab wpmstab col"><a href="#wpms-breadcrumb"><?php esc_html_e('Breadcrumb', 'wp-meta-seo') ?></a>
14
+ </li>
15
  <?php
16
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) :
17
  ?>
18
+ <li class="tab wpmstab col"><a href="#wpms-email"><?php esc_html_e('Send Email', 'wp-meta-seo') ?></a>
19
+ </li>
20
  <li class="tab wpmstab col"><a
21
+ href="#wpms-local_usiness"><?php esc_html_e('Local business', 'wp-meta-seo') ?></a></li>
22
  <?php
23
  endif;
24
  ?>
25
+ <li class="tab wpmstab col"><a
26
+ href="#wpms-jutranslation"><?php esc_html_e('Translation', 'wp-meta-seo') ?></a></li>
27
  </ul>
28
  </div>
29
  <div class="wpms_content_settings">
42
  <table class="form-table">
43
  <tbody>
44
  <tr>
45
+ <th scope="row"><?php esc_html_e('Global home redirect', 'wp-meta-seo') ?></th>
46
  <td>
47
  <input type="hidden" class="wpms_redirect_homepage" name="wpms_redirect[wpms_redirect_homepage]"
48
+ value="<?php echo esc_attr($defaul_settings_404['wpms_redirect_homepage']) ?>">
49
+ <label><?php esc_html_e('Redirect all 404 errors to home page', 'wp-meta-seo'); ?></label>
50
  <div class="switch-optimization">
51
  <label class="switch switch-optimization">
52
  <?php
53
  if (isset($defaul_settings_404['wpms_redirect_homepage'])
54
+ && (int) $defaul_settings_404['wpms_redirect_homepage'] === 1) :
55
  ?>
56
  <input type="checkbox" class="cb_option" id="wpms_redirect_homepage"
57
  data-label="wpms_redirect_homepage"
67
  </td>
68
  </tr>
69
  <tr>
70
+ <th scope="row"><?php esc_html_e('Custom 404 page', 'wp-meta-seo') ?></th>
71
  <td>
72
  <label>
73
  <select name="wpms_redirect[wpms_type_404]"
74
  class="wpms_type_404"
75
+ <?php echo ((int) $defaul_settings_404['wpms_redirect_homepage'] === 1) ? 'disabled' : '' ?>>
76
  <?php foreach ($types_404 as $k => $type_404) : ?>
77
  <option <?php selected($defaul_settings_404['wpms_type_404'], $k) ?>
78
+ value="<?php echo esc_attr($k) ?>"><?php echo esc_html($type_404) ?></option>
79
  <?php endforeach; ?>
80
  </select>
81
  <?php
82
+ if ((int) $defaul_settings_404['wpms_redirect_homepage'] === 1
83
+ || $defaul_settings_404['wpms_type_404'] !== 'custom_page') {
84
  $disable = 'disabled';
85
  } else {
86
  $disable = '';
87
  }
88
  ?>
89
  <select name="wpms_redirect[wpms_page_redirected]"
90
+ class="wpms_page_redirected" <?php echo esc_attr($disable) ?>>
91
+ <option value="none"><?php esc_html_e('— Select —', 'wp-meta-seo') ?></option>
92
  <?php foreach ($posts as $post) : ?>
93
  <option <?php selected($defaul_settings_404['wpms_page_redirected'], $post->ID) ?>
94
+ value="<?php echo esc_attr($post->ID) ?>"><?php echo esc_html($post->post_title) ?></option>
95
  <?php endforeach; ?>
96
  </select>
97
  </label>
101
  </table>
102
  <?php
103
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
104
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in 'wp-meta-seo-addon/inc/page/link_settings.php' file
105
  echo $link_settings_html;
106
  }
107
  ?>
108
+ <div class="button wpms_save_settings404"><?php esc_html_e('Save', 'wp-meta-seo') ?></div>
109
+ <span class="message_saved"><?php esc_html_e('Saved', 'wp-meta-seo') ?></span>
110
  </div>
111
 
112
  <div id="wpms-breadcrumb" class="content-box">
114
  <tbody>
115
  <tr>
116
  <th scope="row">
117
+ <label for="<?php esc_attr_e('The separator that materialize the breadcrumb levels', 'wp-meta-seo') ?>">
118
+ <?php esc_html_e('Breadcrumb separator', 'wp-meta-seo') ?>
119
  </label>
120
  </th>
121
  <td>
122
  <label>
123
  <input id="breadcrumbs_separator" name="_metaseo_breadcrumbs[separator]" type="text"
124
+ value="<?php echo esc_attr(htmlentities($breadcrumbs['separator'])) ?>" size="50">
125
  </label>
126
  </td>
127
  </tr>
128
 
129
  <tr>
130
  <th scope="row">
131
+ <label for="<?php esc_attr_e('Include the Home element in the breadcrumb', 'wp-meta-seo') ?>">
132
+ <?php esc_html_e('Include Home', 'wp-meta-seo') ?></label>
133
  </th>
134
  <td>
135
  <input name="_metaseo_breadcrumbs[include_home]" type="hidden" value="0">
146
 
147
  <tr>
148
  <th scope="row">
149
+ <label for="<?php esc_attr_e('If home is included, you may want to force a text.
150
  By default it’s the content title', 'wp-meta-seo') ?>">
151
+ <?php esc_html_e('Home text', 'wp-meta-seo') ?>
152
  </label>
153
  </th>
154
  <td>
165
  </tr>
166
 
167
  <?php
168
+ if ((int) $breadcrumbs['home_text_default'] === 0) {
169
  $class = 'hide';
170
  } else {
171
  $class = 'show';
172
  }
173
  ?>
174
+ <tr class="<?php echo esc_attr('tr_home_text ' . $class) ?>">
175
  <th scope="row">
176
  <label></label>
177
  </th>
178
  <td>
179
  <label>
180
  <input id="breadcrumbs_home_text" name="_metaseo_breadcrumbs[home_text]" type="text"
181
+ value="<?php echo esc_attr($breadcrumbs['home_text']) ?>" size="50">
182
  </label>
183
  </td>
184
  </tr>
185
  <tr>
186
  <th scope="row">
187
+ <label for="<?php esc_attr_e('The breadcrumb element can be clickable or not', 'wp-meta-seo') ?>">
188
+ <?php esc_html_e('Clickable breadcrumb', 'wp-meta-seo') ?></label>
189
  </th>
190
  <td>
191
  <input name="_metaseo_breadcrumbs[clickable]" type="hidden" value="0">
202
 
203
  <tr>
204
  <th scope="row">
205
+ <label for="<?php esc_attr_e('Generate a breadcrumb navigation based on your categories or page levels.
206
  The shortcode can be included in theme layouts', 'wp-meta-seo') ?>">
207
+ <?php esc_html_e('PHP Shortcode', 'wp-meta-seo') ?>
208
  </label>
209
  </th>
210
  <td>
228
 
229
  <tr>
230
  <th scope="row">
231
+ <label for="<?php esc_attr_e('Generate a breadcrumb navigation based on your categories or page levels.
232
  The WordPress shortcode can be called anywhere in your content', 'wp-meta-seo') ?>">
233
+ <?php esc_html_e('WordPress Shortcode', 'wp-meta-seo') ?>
234
  </label>
235
  </th>
236
  <td>
241
  </tr>
242
  </tbody>
243
  </table>
244
+ <div class="button wpms_save_settings_breadcrumb"><?php esc_html_e('Save', 'wp-meta-seo') ?></div>
245
+ <span class="message_saved"><?php esc_html_e('Saved', 'wp-meta-seo') ?></span>
246
  </div>
247
 
248
  <div id="wpms-jutranslation" class="content-box">
251
 
252
  <?php
253
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
254
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in 'wp-meta-seo-addon/inc/page/email_settings.php' file
255
  echo $html_tabemail;
256
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in 'wp-meta-seo-addon/inc/page/local_business.php' file
257
  echo $local_business_html;
258
  }
259
  ?>
316
  'home_text': home_text,
317
  'include_home': include_home,
318
  'clickable': clickable,
319
+ 'home_text_default': home_text_default,
320
+ 'wpms_nonce': wpms_localize.wpms_nonce
321
  },
322
  success: function (res) {
323
  if (res) {
352
  'wpms_redirect[wpms_page_redirected]': page_redirected,
353
  'enable': enable,
354
  'numberFrequency': $('#numberFrequency').val(),
355
+ 'showlinkFrequency': $('#showlinkFrequency').val(),
356
+ 'wpms_nonce': wpms_localize.wpms_nonce
357
  },
358
  success: function (res) {
359
  if (res) {
384
  port: $('#showSmtpPort').val(),
385
  autentication: $('[name="wpms_email_settings[autentication]"]:checked').val(),
386
  username: $('#showSmtpUser').val(),
387
+ password: $('#showSmtpPass').val(),
388
+ wpms_nonce: wpms_localize.wpms_nonce
389
  },
390
  success: function (res) {
391
  if (res) {
418
  city: $('#wpms_local_business_city').val(),
419
  state: $('#wpms_local_business_state').val(),
420
  phone: $('#wpms_local_business_phone').val(),
421
+ pricerange: $('#wpms_local_business_pricerange').val(),
422
+ wpms_nonce: wpms_localize.wpms_nonce
423
  },
424
  success: function (res) {
425
  if (res) {
inc/pages/sitemaps/metaseo-google-sitemap.php CHANGED
@@ -19,6 +19,7 @@
19
  require(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/posts_custom.php');
20
  $html = ob_get_contents();
21
  ob_end_clean();
 
22
  echo $html;
23
  }
24
  }
@@ -27,6 +28,7 @@
27
  require(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/custom_url.php');
28
  $html = ob_get_contents();
29
  ob_end_clean();
 
30
  echo $html;
31
  }
32
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
@@ -34,29 +36,29 @@
34
  }
35
  echo '<div class="div_wpms_save_sitemaps">
36
  <input type="button" class="wpmsbtn wpms_save_create_sitemaps"
37
- value="' . __('Regenerate and save sitemaps', 'wp-meta-seo') . '">
38
  <span class="spinner spinner_save_sitemaps"></span></div>';
39
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
40
  echo '<p class="description">
41
- ' . __("Sitemap automatic submission to Google Search Console on save, ", "wp-meta-seo") . '
42
- <a href="' . admin_url('admin.php?page=metaseo_console&tab=settings') . '">
43
- ' . __("requires authentication", "wp-meta-seo") . '</a></p>';
44
  }
45
  ?>
46
  </form>
47
  </div>
48
 
49
  <?php
50
- $w = '99%';
51
- $text = __('Bring your WordPress website SEO to the next level with the PRO Addon:
52
  Sitemap for any custom post type, auto submission to the Google Search Console and more!', 'wp-meta-seo');
53
  $class_btn_close = 'close_sitemap';
54
  if (!empty($_COOKIE['close_dashboard'])) {
55
- $check = time() - (int)$_COOKIE['close_dashboard'];
56
  $month = 30 * 24 * 60 * 60;
57
  }
58
 
59
  if ((empty($_COOKIE['close_dashboard']) || (!empty($_COOKIE['close_dashboard']) && $check >= $month))
60
- && !is_plugin_active(WPMSEO_ADDON_FILENAME)) {
61
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
62
  }
19
  require(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/posts_custom.php');
20
  $html = ob_get_contents();
21
  ob_end_clean();
22
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in 'wp-meta-seo-addon/inc/page/sitemaps/posts_custom.php' file
23
  echo $html;
24
  }
25
  }
28
  require(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/custom_url.php');
29
  $html = ob_get_contents();
30
  ob_end_clean();
31
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in 'wp-meta-seo-addon/inc/page/sitemaps/custom_url.php' file
32
  echo $html;
33
  }
34
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
36
  }
37
  echo '<div class="div_wpms_save_sitemaps">
38
  <input type="button" class="wpmsbtn wpms_save_create_sitemaps"
39
+ value="' . esc_attr__('Regenerate and save sitemaps', 'wp-meta-seo') . '">
40
  <span class="spinner spinner_save_sitemaps"></span></div>';
41
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
42
  echo '<p class="description">
43
+ ' . esc_html__('Sitemap automatic submission to Google Search Console on save, ', 'wp-meta-seo') . '
44
+ <a href="' . esc_url(admin_url('admin.php?page=metaseo_console&tab=settings')) . '">
45
+ ' . esc_html__('requires authentication', 'wp-meta-seo') . '</a></p>';
46
  }
47
  ?>
48
  </form>
49
  </div>
50
 
51
  <?php
52
+ $w = '99%';
53
+ $text = esc_html__('Bring your WordPress website SEO to the next level with the PRO Addon:
54
  Sitemap for any custom post type, auto submission to the Google Search Console and more!', 'wp-meta-seo');
55
  $class_btn_close = 'close_sitemap';
56
  if (!empty($_COOKIE['close_dashboard'])) {
57
+ $check = time() - (int) $_COOKIE['close_dashboard'];
58
  $month = 30 * 24 * 60 * 60;
59
  }
60
 
61
  if ((empty($_COOKIE['close_dashboard']) || (!empty($_COOKIE['close_dashboard']) && $check >= $month))
62
+ && !is_plugin_active(WPMSEO_ADDON_FILENAME)) {
63
  require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
64
  }
inc/pages/sitemaps/metaseo-source_menu.php CHANGED
@@ -5,20 +5,20 @@
5
  echo '<div class="div_sitemap_check_all">';
6
  echo '<div class="pure-checkbox">';
7
  echo '<input class="sitemap_check_all" data-type="menu" id="wpms_check_all_menus" type="checkbox">';
8
- echo '<label for="wpms_check_all_menus">' . __("Check all menus", 'wp-meta-seo') . '</label>';
9
  echo '</div>';
10
  echo '</div>';
11
  ?>
12
  <div class="div_sitemap_check_all wpms_xmp_order" style="font-weight: bold;">
13
- <label><?php _e('Order', 'wp-meta-seo'); ?></label>
14
  <label>
15
  <select class="wpms_display_order_menus">
16
  <?php
17
- for ($i = 1; $i <= 4; $i++) {
18
- if ($i == $sitemap->settings_sitemap['wpms_display_order_menus']) {
19
- echo '<option selected value="' . $i . '">' . $i . '</option>';
20
  } else {
21
- echo '<option value="' . $i . '">' . $i . '</option>';
22
  }
23
  }
24
  ?>
@@ -26,11 +26,13 @@
26
  </label>
27
  </div>
28
  <?php
 
29
  foreach ($terms as $term) {
30
  $viewmenu = $sitemap->viewMenus($term);
31
  }
32
  echo '<div class="wrap_sitemap_option">';
33
  echo '<input name="_metaseo_settings_sitemap[wpms_check_firstsave]" type="hidden" value="1">';
 
34
  echo $viewmenu;
35
  echo '</div>';
36
  }
5
  echo '<div class="div_sitemap_check_all">';
6
  echo '<div class="pure-checkbox">';
7
  echo '<input class="sitemap_check_all" data-type="menu" id="wpms_check_all_menus" type="checkbox">';
8
+ echo '<label for="wpms_check_all_menus">' . esc_html__('Check all menus', 'wp-meta-seo') . '</label>';
9
  echo '</div>';
10
  echo '</div>';
11
  ?>
12
  <div class="div_sitemap_check_all wpms_xmp_order" style="font-weight: bold;">
13
+ <label><?php esc_html_e('Order', 'wp-meta-seo'); ?></label>
14
  <label>
15
  <select class="wpms_display_order_menus">
16
  <?php
17
+ for ($i = 1; $i <= 4; $i ++) {
18
+ if ((int) $i === (int) $sitemap->settings_sitemap['wpms_display_order_menus']) {
19
+ echo '<option selected value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
20
  } else {
21
+ echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
22
  }
23
  }
24
  ?>
26
  </label>
27
  </div>
28
  <?php
29
+ $viewmenu = '';
30
  foreach ($terms as $term) {
31
  $viewmenu = $sitemap->viewMenus($term);
32
  }
33
  echo '<div class="wrap_sitemap_option">';
34
  echo '<input name="_metaseo_settings_sitemap[wpms_check_firstsave]" type="hidden" value="1">';
35
+ // phpcs:ignore WordPress.XSS.EscapeOutput -- Content escaped in the method MetaSeoSitemap::viewMenus
36
  echo $viewmenu;
37
  echo '</div>';
38
  }
inc/pages/sitemaps/metaseo-source_pages.php CHANGED
@@ -2,7 +2,7 @@
2
  <div class="div_sitemap_check_all">
3
  <div class="pure-checkbox">
4
  <input class="sitemap_check_all" data-type="pages" id="wpms_check_all_pages" type="checkbox">
5
- <label for="wpms_check_all_pages"><?php _e("Check all pages", 'wp-meta-seo'); ?></label>
6
  </div>
7
  </div>
8
 
@@ -11,29 +11,29 @@
11
  <input class="sitemap_check_all_posts_in_page" data-type="pages" id="wpms_check_all_posts_in_page_pages"
12
  type="checkbox">
13
  <label for="wpms_check_all_posts_in_page_pages">
14
- <?php _e("Check all posts in current page", 'wp-meta-seo'); ?>
15
  </label>
16
  </div>
17
  </div>
18
 
19
  <div class="div_sitemap_check_all" style="font-weight: bold;">
20
- <label><?php _e('Public name', 'wp-meta-seo'); ?></label>
21
  <label>
22
  <input type="text" class="public_name_pages"
23
- value="<?php echo $sitemap->settings_sitemap['wpms_public_name_pages'] ?>">
24
  </label>
25
  </div>
26
 
27
  <div class="div_sitemap_check_all wpms_xmp_custom_column" style="font-weight: bold;">
28
- <label><?php _e('Display in column', 'wp-meta-seo'); ?></label>
29
  <label>
30
  <select class="wpms_display_column wpms_display_column_pages">
31
  <?php
32
- for ($i = 1; $i <= $sitemap->settings_sitemap['wpms_html_sitemap_column']; $i++) {
33
- if ($sitemap->settings_sitemap['wpms_display_column_pages'] == $i) {
34
- echo '<option selected value="' . $i . '">' . $sitemap->columns[$i] . '</option>';
35
  } else {
36
- echo '<option value="' . $i . '">' . $sitemap->columns[$i] . '</option>';
37
  }
38
  }
39
  ?>
@@ -42,15 +42,15 @@
42
  </div>
43
 
44
  <div class="div_sitemap_check_all wpms_xmp_order" style="font-weight: bold;">
45
- <label><?php _e('Order', 'wp-meta-seo'); ?></label>
46
  <label>
47
  <select class="wpms_display_order_pages">
48
  <?php
49
- for ($i = 1; $i <= 4; $i++) {
50
- if ($sitemap->settings_sitemap['wpms_display_order_pages'] == $i) {
51
- echo '<option selected value="' . $i . '">' . $i . '</option>';
52
  } else {
53
- echo '<option value="' . $i . '">' . $i . '</option>';
54
  }
55
  }
56
  ?>
@@ -58,7 +58,7 @@
58
  </label>
59
  </div>
60
  <div id="wrap_sitemap_option_pages" class="wrap_sitemap_option">
61
- <h3><?php _e('Pages', 'wp-meta-seo') ?></h3>
62
  <?php
63
  $pages = $sitemap->getPages();
64
  foreach ($pages as $page) {
@@ -72,12 +72,12 @@
72
  } else {
73
  $pagepriority = $sitemap->settings_sitemap['wpms_sitemap_pages'][$page->ID]['priority'];
74
  }
75
- $slpr = $sitemap->viewPriority(
76
  'priority_pages_' . $page->ID,
77
  '_metaseo_settings_sitemap[wpms_sitemap_pages][' . $page->ID . '][priority]',
78
  $pagepriority
79
  );
80
- $slfr = $sitemap->viewFrequency(
81
  'frequency_pages_' . $page->ID,
82
  '_metaseo_settings_sitemap[wpms_sitemap_pages][' . $page->ID . '][frequency]',
83
  $pagefrequency
@@ -86,29 +86,30 @@
86
  echo '<div class="wpms_row wpms_row_record">';
87
  echo '<div style="float:left;line-height:30px">';
88
  if (isset($sitemap->settings_sitemap['wpms_sitemap_pages'][$page->ID]['post_id'])
89
- && $sitemap->settings_sitemap['wpms_sitemap_pages'][$page->ID]['post_id'] == $page->ID) {
2
  <div class="div_sitemap_check_all">
3
  <div class="pure-checkbox">
4
  <input class="sitemap_check_all" data-type="pages" id="wpms_check_all_pages" type="checkbox">
5
+ <label for="wpms_check_all_pages"><?php esc_html_e('Check all pages', 'wp-meta-seo'); ?></label>
6
  </div>
7
  </div>
8
 
11
  <input class="sitemap_check_all_posts_in_page" data-type="pages" id="wpms_check_all_posts_in_page_pages"
12
  type="checkbox">
13
  <label for="wpms_check_all_posts_in_page_pages">
14
+ <?php esc_html_e('Check all posts in current page', 'wp-meta-seo'); ?>
15
  </label>
16
  </div>
17
  </div>
18
 
19
  <div class="div_sitemap_check_all" style="font-weight: bold;">
20
+ <label><?php esc_html_e('Public name', 'wp-meta-seo'); ?></label>
21
  <label>
22
  <input type="text" class="public_name_pages"
23
+ value="<?php echo esc_attr($sitemap->settings_sitemap['wpms_public_name_pages']) ?>">
24
  </label>
25
  </div>
26
 
27
  <div class="div_sitemap_check_all wpms_xmp_custom_column" style="font-weight: bold;">
28
+ <label><?php esc_html_e('Display in column', 'wp-meta-seo'); ?></label>
29
  <label>
30
  <select class="wpms_display_column wpms_display_column_pages">
31
  <?php
32
+ for ($i = 1; $i <= $sitemap->settings_sitemap['wpms_html_sitemap_column']; $i ++) {
33
+ if ((int) $sitemap->settings_sitemap['wpms_display_column_pages'] === (int) $i) {
34
+ echo '<option selected value="' . esc_attr($i) . '">' . esc_html($sitemap->columns[$i]) . '</option>';
35
  } else {
36
+ echo '<option value="' . esc_attr($i) . '">' . esc_html($sitemap->columns[$i]) . '</option>';
37
  }
38
  }
39
  ?>
42
  </div>
43
 
44
  <div class="div_sitemap_check_all wpms_xmp_order" style="font-weight: bold;">
45
+ <label><?php esc_html_e('Order', 'wp-meta-seo'); ?></label>
46
  <label>
47
  <select class="wpms_display_order_pages">
48
  <?php
49
+ for ($i = 1; $i <= 4; $i ++) {
50
+ if ((int) $sitemap->settings_sitemap['wpms_display_order_pages'] === (int) $i) {
51
+ echo '<option selected value="' . esc_html($i) . '">' . esc_html($i) . '</option>';
52
  } else {
53
+ echo '<option value="' . esc_html($i) . '">' . esc_html($i) . '</option>';
54
  }
55
  }
56
  ?>
58
  </label>
59
  </div>
60
  <div id="wrap_sitemap_option_pages" class="wrap_sitemap_option">
61
+ <h3><?php esc_html_e('Pages', 'wp-meta-seo') ?></h3>
62
  <?php
63
  $pages = $sitemap->getPages();
64
  foreach ($pages as $page) {
72
  } else {
73
  $pagepriority = $sitemap->settings_sitemap['wpms_sitemap_pages'][$page->ID]['priority'];
74
  }
75
+ $slpr = $sitemap->viewPriority(
76
  'priority_pages_' . $page->ID,
77
  '_metaseo_settings_sitemap[wpms_sitemap_pages][' . $page->ID . '][priority]',
78
  $pagepriority
79
  );
80
+ $slfr = $sitemap->viewFrequency(
81
  'frequency_pages_' . $page->ID,
82
  '_metaseo_settings_sitemap[wpms_sitemap_pages][' . $page->ID . '][frequency]',
83
  $pagefrequency
86
  echo '<div class="wpms_row wpms_row_record">';
87
  echo '<div style="float:left;line-height:30px">';
88
  if (isset($sitemap->settings_sitemap['wpms_sitemap_pages'][$page->ID]['post_id'])
89
+