WP Meta SEO - Version 3.6.0

Version Description

  • Add : Full code reformating for better performance and code comments
  • Add : Using PHPCS to make standard definitions
Download this release

Release Info

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

Code changes from version 3.5.3 to 3.6.0

Files changed (58) hide show
  1. css/broken_link.css +1 -1
  2. css/category_field.css +3 -3
  3. css/chart.css +2 -2
  4. css/dashboard.css +4 -6
  5. css/dashboard_widgets.css +4 -5
  6. css/google-analytics/admin-widgets.css +22 -33
  7. css/google-analytics/nprogress.css +1 -29
  8. css/google-analytics/wpms-tracking-code.css +3 -4
  9. css/html_sitemap.css +83 -18
  10. css/jquery.qtip.css +1 -4
  11. css/materialize/materialize.css +6 -7
  12. css/materialize/materialize_frontend_tab_theme.css +1 -2
  13. css/metabox-tabs.css +6 -6
  14. css/metaseo-quirk.css +25 -28
  15. css/metaseo_admin.css +10 -13
  16. css/metaseo_sitemap.css +3 -3
  17. css/notification.css +8 -9
  18. css/style.css +7 -7
  19. css/tooltip-metaimage.css +1 -1
  20. css/tooltip.css +1 -1
  21. inc/autoload.php +10 -4
  22. inc/breadcrumb/class.metaseo-breadcrumb.php +287 -131
  23. inc/class.image-helper.php +169 -94
  24. inc/class.metaseo-admin.php +1849 -738
  25. inc/class.metaseo-broken-link-table.php +1245 -670
  26. inc/class.metaseo-content-list-table.php +360 -192
  27. inc/class.metaseo-dashboard.php +243 -197
  28. inc/class.metaseo-front_end.php +55 -32
  29. inc/class.metaseo-google-analytics.php +54 -44
  30. inc/class.metaseo-image-list-table.php +837 -554
  31. inc/class.metaseo-link-list-table.php +304 -178
  32. inc/class.metaseo-meta.php +94 -66
  33. inc/class.metaseo-metabox.php +725 -345
  34. inc/class.metaseo-sitemap.php +1100 -490
  35. inc/class.metaseo-snippet-preview.php +91 -52
  36. inc/class.wp-metaseo.php +47 -21
  37. inc/google_analytics/tracking/classic_disconnect.php +14 -8
  38. inc/google_analytics/tracking/code-classic.php +22 -21
  39. inc/google_analytics/tracking/code-universal.php +122 -117
  40. inc/google_analytics/tracking/custom.php +7 -7
  41. inc/google_analytics/tracking/events-classic.php +42 -41
  42. inc/google_analytics/tracking/events-universal.php +46 -38
  43. inc/google_analytics/tracking/universal_disconnect.php +14 -8
  44. inc/google_analytics/wpmsga.php +42 -12
  45. inc/google_analytics/wpmsgapi.php +349 -337
  46. inc/google_analytics/wpmstools.php +107 -128
  47. inc/pages/content-meta.php +15 -15
  48. inc/pages/dashboard.php +188 -72
  49. inc/pages/dashboard/imgsmeta.php +10 -4
  50. inc/pages/dashboard/imgsresize.php +8 -3
  51. inc/pages/dashboard/link_meta.php +8 -3
  52. inc/pages/dashboard/meta_desc.php +8 -3
  53. inc/pages/dashboard/meta_title.php +8 -3
  54. inc/pages/dashboard/new_content.php +6 -2
  55. inc/pages/dashboard/permalink.php +6 -2
  56. inc/pages/dashboard_widgets.php +97 -37
  57. inc/pages/google-analytics/form-connect.php +111 -0
  58. inc/pages/google-analytics/ga-trackcode.php +288 -0
css/broken_link.css CHANGED
@@ -37,7 +37,7 @@ table.metaseo_images .wpms-input-text-wrap input{
37
  }
38
 
39
  .custom_redirect_editor_content .wpms-input-text-wrap td{
40
- padding: 15px 0px;
41
  }
42
 
43
  .wpms-update-link-button{
37
  }
38
 
39
  .custom_redirect_editor_content .wpms-input-text-wrap td{
40
+ padding: 15px 0;
41
  }
42
 
43
  .wpms-update-link-button{
css/category_field.css CHANGED
@@ -1,18 +1,18 @@
1
  .cat-title-len , .cat-desc-len , .cat-keywords-len {
2
- background: none repeat scroll 0% 0% #7ad03a;
3
  color: #FFF;
4
  border-radius: 2px;
5
  min-width: 15px;
6
  text-align: center;
7
  float: left;
8
- padding: 0px 10px;
9
  position: relative;
10
  bottom: 12px;
11
  left: 15px;
12
  }
13
 
14
  .length-wrong {
15
- background: none repeat scroll 0% 0% #FFCC00;
16
  }
17
 
18
  .wpms_custom_cat_field{
1
  .cat-title-len , .cat-desc-len , .cat-keywords-len {
2
+ background: none repeat scroll 0 0 #7ad03a;
3
  color: #FFF;
4
  border-radius: 2px;
5
  min-width: 15px;
6
  text-align: center;
7
  float: left;
8
+ padding: 0 10px;
9
  position: relative;
10
  bottom: 12px;
11
  left: 15px;
12
  }
13
 
14
  .length-wrong {
15
+ background: none repeat scroll 0 0 #FFCC00;
16
  }
17
 
18
  .wpms_custom_cat_field{
css/chart.css CHANGED
@@ -10,11 +10,11 @@
10
  .dashboard .right{width: 30%; float: right;background: #fff;min-height: 150px}
11
 
12
  .dashboard h1 {
13
- padding: 10px 0px 10px 20px
14
  }
15
 
16
  .dashboard-left {
17
- margin: 10px 0px 10px 0px;
18
  width: 100%;
19
  float: left;
20
 
10
  .dashboard .right{width: 30%; float: right;background: #fff;min-height: 150px}
11
 
12
  .dashboard h1 {
13
+ padding: 10px 0 10px 20px
14
  }
15
 
16
  .dashboard-left {
17
+ margin: 10px 0 10px 0;
18
  width: 100%;
19
  float: left;
20
 
css/dashboard.css CHANGED
@@ -13,7 +13,7 @@
13
  background: #f8f8f8;
14
  border: solid 1px #ddd;
15
  padding: 10px;
16
- box-shadow: 0px 1px 3px #cacaca;
17
  box-sizing: border-box;
18
  font-size: 13px;
19
  color: #555;
@@ -60,8 +60,7 @@
60
  font-size: 13px;
61
  font-weight: normal;
62
  color: #666;
63
- margin: 0;
64
- margin-bottom: 10px;
65
  }
66
  #alexa-ranking .img-inline {
67
  margin-bottom: 10px;
@@ -104,7 +103,7 @@
104
  display: block;
105
  width: 100%;
106
  border-radius: 2px;
107
- margin: 32px 0px;
108
  overflow: hidden;
109
  background-color: rgba(255, 255, 255, 0.33);
110
  float: left;
@@ -112,7 +111,6 @@
112
 
113
  .dashboard .progress-rating .determinate {
114
  position: absolute;
115
- background-color: inherit;
116
  top: 0;
117
  left: 0;
118
  bottom: 0;
@@ -157,7 +155,7 @@
157
  }
158
 
159
  .dashboard .wpms_dashboard_widgets_left .percent_1{
160
- margin: 12px 0px 10px 0px !important;
161
  }
162
 
163
  .dashboard .wpms_dashboard_widgets_left .percent_2{
13
  background: #f8f8f8;
14
  border: solid 1px #ddd;
15
  padding: 10px;
16
+ box-shadow: 0 1px 3px #cacaca;
17
  box-sizing: border-box;
18
  font-size: 13px;
19
  color: #555;
60
  font-size: 13px;
61
  font-weight: normal;
62
  color: #666;
63
+ margin: 0 0 10px;
 
64
  }
65
  #alexa-ranking .img-inline {
66
  margin-bottom: 10px;
103
  display: block;
104
  width: 100%;
105
  border-radius: 2px;
106
+ margin: 32px 0;
107
  overflow: hidden;
108
  background-color: rgba(255, 255, 255, 0.33);
109
  float: left;
111
 
112
  .dashboard .progress-rating .determinate {
113
  position: absolute;
 
114
  top: 0;
115
  left: 0;
116
  bottom: 0;
155
  }
156
 
157
  .dashboard .wpms_dashboard_widgets_left .percent_1{
158
+ margin: 12px 0 10px 0 !important;
159
  }
160
 
161
  .dashboard .wpms_dashboard_widgets_left .percent_2{
css/dashboard_widgets.css CHANGED
@@ -1,9 +1,9 @@
1
  .wpms_dashboard_widgets h1 {
2
- padding: 10px 0px 10px 20px
3
  }
4
 
5
  .wpms_dash_widgets{
6
- margin: 7px 0px;
7
  }
8
 
9
  .wpms_dash_widgets .percent_1{
@@ -34,7 +34,7 @@
34
  display: block;
35
  width: 100%;
36
  border-radius: 2px;
37
- margin: 32px 0px;
38
  overflow: hidden;
39
  background-color: rgba(255, 255, 255, 0.33);
40
  float: left;
@@ -42,7 +42,6 @@
42
 
43
  .wpms_dashboard_widgets .progress-rating .determinate {
44
  position: absolute;
45
- background-color: inherit;
46
  top: 0;
47
  left: 0;
48
  bottom: 0;
@@ -100,7 +99,7 @@
100
  }
101
 
102
  .wpms_dashboard_widgets_left .percent_1{
103
- margin: 12px 0px 10px 0px !important;
104
  float: left;
105
  }
106
 
1
  .wpms_dashboard_widgets h1 {
2
+ padding: 10px 0 10px 20px
3
  }
4
 
5
  .wpms_dash_widgets{
6
+ margin: 7px 0;
7
  }
8
 
9
  .wpms_dash_widgets .percent_1{
34
  display: block;
35
  width: 100%;
36
  border-radius: 2px;
37
+ margin: 32px 0;
38
  overflow: hidden;
39
  background-color: rgba(255, 255, 255, 0.33);
40
  float: left;
42
 
43
  .wpms_dashboard_widgets .progress-rating .determinate {
44
  position: absolute;
 
45
  top: 0;
46
  left: 0;
47
  bottom: 0;
99
  }
100
 
101
  .wpms_dashboard_widgets_left .percent_1{
102
+ margin: 12px 0 10px 0 !important;
103
  float: left;
104
  }
105
 
css/google-analytics/admin-widgets.css CHANGED
@@ -4,9 +4,9 @@
4
  margin: 0 0;
5
  padding: 5px 0 5px 0;
6
  background: #fff;
7
- -moz-box-shadow: 0px 0px 3px 0px #BBB;
8
- -webkit-box-shadow: 0px 0px 3px 0px #BBB;
9
- box-shadow: 0px 0px 3px 0px #BBB;
10
  display: table;
11
  overflow: hidden;
12
  }
@@ -33,9 +33,9 @@
33
  margin: 0 0;
34
  background: #fff;
35
  text-align: center;
36
- -moz-box-shadow: 0px 0px 5px 0px #BBB;
37
- -webkit-box-shadow: 0px 0px 5px 0px #BBB;
38
- box-shadow: 0px 0px 5px 0px #BBB;
39
  display: table;
40
  }
41
 
@@ -48,7 +48,7 @@
48
 
49
  .wpms-tdo-right {
50
  width: 35%;
51
- margin: 0px 10px 0px 0;
52
  text-align: left;
53
  font-weight: bold;
54
  vertical-align: middle;
@@ -70,9 +70,9 @@
70
  margin: 0 0;
71
  padding: 5px 5px 5px 5px;
72
  background: #fff;
73
- -moz-box-shadow: 0px 0px 3px 0px #BBB;
74
- -webkit-box-shadow: 0px 0px 3px 0px #BBB;
75
- box-shadow: 0px 0px 3px 0px #BBB;
76
  display: table;
77
  overflow: hidden;
78
  }
@@ -98,7 +98,6 @@
98
 
99
  [id^=wpms-areachart-] {
100
  width: 98%;
101
- height: 100%;
102
  margin: 10px auto 10px 0;
103
  height: 250px;
104
  }
@@ -138,18 +137,18 @@
138
  [id^=wpms-progressbar-] {
139
  width: 100%;
140
  height: 3px;
141
- margin: 5px 0 0px 0;
142
  }
143
 
144
  [id^=wpms-bottomstats-] {
145
  width: 50%;
146
- margin: 0px auto;
147
  }
148
 
149
  [id^=wpms-bottomstats-] .inside {
150
  display: table;
151
  margin: 0 auto;
152
- padding: 0px;
153
  width: 100%;
154
  }
155
 
@@ -159,16 +158,16 @@
159
  margin: 0 5px 10px 5px;
160
  background: #fff;
161
  text-align: center;
162
- -moz-box-shadow: 0px 0px 7px 0px #BBB;
163
- -webkit-box-shadow: 0px 0px 7px 0px #BBB;
164
- box-shadow: 0px 0px 7px 0px #BBB;
165
  }
166
 
167
  .inside .small-box h3 {
168
  font-size: 1em;
169
  color: #777;
170
- padding: 0px 5px 0px 5px;
171
- margin: 0px 0px 0px 0px;
172
  text-overflow: ellipsis;
173
  overflow: hidden;
174
  white-space: nowrap;
@@ -176,7 +175,7 @@
176
 
177
  .inside .small-box p {
178
  font-size: 1.2em;
179
- margin: 0px 0px 2px 0px;
180
  }
181
 
182
  @media screen and (max-width: 410px) {
@@ -202,9 +201,7 @@
202
  }
203
 
204
  .google-visualization-table-th{
205
- padding-top: 4px;
206
  vertical-align: middle;
207
- padding: 11px 0 0 3px;
208
  font-weight: 400;
209
  padding: 8px !important;
210
  color: #0073aa;
@@ -227,27 +224,19 @@
227
  }
228
 
229
  .google-visualization-table-table th, .google-visualization-table-table td{
230
- border-width: 0 0px 1px 0 !important;
231
  }
232
 
233
  .google-visualization-table-page-number{
234
  width: 24px;
235
- padding: 2px 0px;
236
  border-radius: 0;
237
  border: #ddd 1px solid;
238
  color: #a0a5aa;
239
  }
240
-
241
- .charts-custom-button-inner-box{
242
- padding: 5px 8px 7px !important;
243
- border-radius: 0 !important;
244
- border-style: none !important;
245
- border: #ddd 1px solid;
246
- }
247
 
248
  .google-visualization-table .gradient{
249
- background-image: none;
250
- background-color: #fff;
251
  }
252
 
253
  .google-visualization-table-page-number.current{
4
  margin: 0 0;
5
  padding: 5px 0 5px 0;
6
  background: #fff;
7
+ -moz-box-shadow: 0 0 3px 0 #BBB;
8
+ -webkit-box-shadow: 0 0 3px 0 #BBB;
9
+ box-shadow: 0 0 3px 0 #BBB;
10
  display: table;
11
  overflow: hidden;
12
  }
33
  margin: 0 0;
34
  background: #fff;
35
  text-align: center;
36
+ -moz-box-shadow: 0 0 5px 0 #BBB;
37
+ -webkit-box-shadow: 0 0 5px 0 #BBB;
38
+ box-shadow: 0 0 5px 0 #BBB;
39
  display: table;
40
  }
41
 
48
 
49
  .wpms-tdo-right {
50
  width: 35%;
51
+ margin: 0 10px 0 0;
52
  text-align: left;
53
  font-weight: bold;
54
  vertical-align: middle;
70
  margin: 0 0;
71
  padding: 5px 5px 5px 5px;
72
  background: #fff;
73
+ -moz-box-shadow: 0 0 3px 0 #BBB;
74
+ -webkit-box-shadow: 0 0 3px 0 #BBB;
75
+ box-shadow: 0 0 3px 0 #BBB;
76
  display: table;
77
  overflow: hidden;
78
  }
98
 
99
  [id^=wpms-areachart-] {
100
  width: 98%;
 
101
  margin: 10px auto 10px 0;
102
  height: 250px;
103
  }
137
  [id^=wpms-progressbar-] {
138
  width: 100%;
139
  height: 3px;
140
+ margin: 5px 0 0 0;
141
  }
142
 
143
  [id^=wpms-bottomstats-] {
144
  width: 50%;
145
+ margin: 0 auto;
146
  }
147
 
148
  [id^=wpms-bottomstats-] .inside {
149
  display: table;
150
  margin: 0 auto;
151
+ padding: 0;
152
  width: 100%;
153
  }
154
 
158
  margin: 0 5px 10px 5px;
159
  background: #fff;
160
  text-align: center;
161
+ -moz-box-shadow: 0 0 7px 0 #BBB;
162
+ -webkit-box-shadow: 0 0 7px 0 #BBB;
163
+ box-shadow: 0 0 7px 0 #BBB;
164
  }
165
 
166
  .inside .small-box h3 {
167
  font-size: 1em;
168
  color: #777;
169
+ padding: 0 5px 0 5px;
170
+ margin: 0 0 0 0;
171
  text-overflow: ellipsis;
172
  overflow: hidden;
173
  white-space: nowrap;
175
 
176
  .inside .small-box p {
177
  font-size: 1.2em;
178
+ margin: 0 0 2px 0;
179
  }
180
 
181
  @media screen and (max-width: 410px) {
201
  }
202
 
203
  .google-visualization-table-th{
 
204
  vertical-align: middle;
 
205
  font-weight: 400;
206
  padding: 8px !important;
207
  color: #0073aa;
224
  }
225
 
226
  .google-visualization-table-table th, .google-visualization-table-table td{
227
+ border-width: 0 0 1px 0 !important;
228
  }
229
 
230
  .google-visualization-table-page-number{
231
  width: 24px;
232
+ padding: 2px 0;
233
  border-radius: 0;
234
  border: #ddd 1px solid;
235
  color: #a0a5aa;
236
  }
 
 
 
 
 
 
 
237
 
238
  .google-visualization-table .gradient{
239
+ background: #fff none;
 
240
  }
241
 
242
  .google-visualization-table-page-number.current{
css/google-analytics/nprogress.css CHANGED
@@ -16,7 +16,7 @@
16
  #nprogress .peg {
17
  display: block;
18
  position: absolute;
19
- right: 0px;
20
  width: 100px;
21
  height: 100%;
22
  box-shadow: 0 0 10px #29d, 0 0 5px #29d;
@@ -55,31 +55,3 @@
55
  .nprogress-custom-parent #nprogress .spinner, .nprogress-custom-parent #nprogress .bar {
56
  position: absolute;
57
  }
58
-
59
- @-webkit-keyframes nprogress-spinner { 0% {
60
- -webkit-transform: rotate(0deg);
61
- }
62
-
63
- 100%
64
- {
65
- -webkit-transform
66
- :
67
-
68
- rotate
69
- (360deg);
70
-
71
- }
72
- }
73
- @keyframes nprogress-spinner { 0% {
74
- transform: rotate(0deg);
75
- }
76
- 100%
77
- {
78
- transform
79
- :
80
-
81
- rotate
82
- (360deg);
83
-
84
- }
85
- }
16
  #nprogress .peg {
17
  display: block;
18
  position: absolute;
19
+ right: 0;
20
  width: 100px;
21
  height: 100%;
22
  box-shadow: 0 0 10px #29d, 0 0 5px #29d;
55
  .nprogress-custom-parent #nprogress .spinner, .nprogress-custom-parent #nprogress .bar {
56
  position: absolute;
57
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/google-analytics/wpms-tracking-code.css CHANGED
@@ -5,7 +5,7 @@ table.wpmsga-settings-options {
5
  }
6
 
7
  .wpmsga-settings-options td {
8
- padding: 0px 5px 5px 5px;
9
  }
10
 
11
  td.wpmsga-settings-title, td.info {
@@ -61,8 +61,7 @@ td.wpmsga-settings-roles {
61
  }
62
 
63
  #poststuff.wpmsga h2 {
64
- padding-bottom: 0;
65
- font-size: 19.5px;
66
  font-weight: normal;
67
  padding: 0;
68
  margin: 20px 0 15px 0;
@@ -183,7 +182,7 @@ input.wpmsga-settings-switchoo-checkbox {
183
  }
184
 
185
  .wpmsga-settings-switchoo-checkbox:checked+.wpmsga-settings-switchoo-label .wpmsga-settings-switchoo-switch {
186
- right: 0px;
187
  }
188
 
189
  .switch-desc {
5
  }
6
 
7
  .wpmsga-settings-options td {
8
+ padding: 0 5px 5px 5px;
9
  }
10
 
11
  td.wpmsga-settings-title, td.info {
61
  }
62
 
63
  #poststuff.wpmsga h2 {
64
+ font-size: 20px;
 
65
  font-weight: normal;
66
  padding: 0;
67
  margin: 20px 0 15px 0;
182
  }
183
 
184
  .wpmsga-settings-switchoo-checkbox:checked+.wpmsga-settings-switchoo-label .wpmsga-settings-switchoo-switch {
185
+ right: 0;
186
  }
187
 
188
  .switch-desc {
css/html_sitemap.css CHANGED
@@ -1,25 +1,90 @@
1
- #wpms_sitemap{width:100%; position:relative; clear:both;}
2
- #wpms_sitemap div{width:100%;}
3
- #wpms_sitemap h3{font-size:26px; line-height:32px; padding-bottom:0; margin-bottom:8px; width:100%}
4
- #wpms_sitemap h4{font-size:18px; line-height:20px; padding-bottom:0; margin-bottom:4px}
5
- #wpms_sitemap ul{list-style-type:disc; margin-bottom:0; padding-bottom:15px; margin-before:1em; margin-after:1em; padding-start:40px; font-size:15px; line-height:24px; font-weight:normal; background:none;}
6
- #wpms_sitemap ul ul , #sitemap_pages ul{margin-bottom:0; list-style-type:circle;}
7
- .wpms_frontend_menus_sitemap li{margin-bottom:0; list-style-type:circle;}
8
- #wpms_sitemap li{display:list-item;}
9
- .wpms_clearRow{width:100%; height:24px; display:block; clear:both; position:relative;}
10
- #credits_link{font-size:12px;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  /* Responsive */
13
- @media screen and (max-width:960px){
14
- #wpms_sitemap.columns_4{-moz-column-count: 3 !important; -webkit-column-count: 3 !important; column-count: 3 !important;}
 
 
 
 
15
  }
16
- @media screen and (max-width:640px){
17
- #wpms_sitemap.columns_3,#wpms_sitemap.columns_4{-moz-column-count: 2 !important; -webkit-column-count: 2 !important; column-count: 2 !important;}
 
 
 
 
 
18
  }
19
- @media screen and (max-width:480px){
20
- #wpms_sitemap.columns_4,#wpms_sitemap.columns_3,#wpms_sitemap.columns_2{-moz-column-count: 1 !important; -webkit-column-count: 1 !important; column-count: 1 !important;}
 
 
 
 
 
21
  }
22
- .wpms_li_cate .cat_name{
23
- font-weight:bold;
 
24
  font-size: 14px;
25
  }
1
+ #wpms_sitemap {
2
+ width: 100%;
3
+ position: relative;
4
+ clear: both;
5
+ }
6
+
7
+ #wpms_sitemap div {
8
+ width: 100%;
9
+ }
10
+
11
+ #wpms_sitemap h3 {
12
+ font-size: 26px;
13
+ line-height: 32px;
14
+ padding-bottom: 0;
15
+ margin-bottom: 8px;
16
+ width: 100%
17
+ }
18
+
19
+ #wpms_sitemap h4 {
20
+ font-size: 18px;
21
+ line-height: 20px;
22
+ padding-bottom: 0;
23
+ margin-bottom: 4px
24
+ }
25
+
26
+ #wpms_sitemap ul {
27
+ list-style-type: disc;
28
+ margin-bottom: 0;
29
+ padding-bottom: 15px;
30
+ font-size: 15px;
31
+ line-height: 24px;
32
+ font-weight: normal;
33
+ background: none;
34
+ }
35
+
36
+ #wpms_sitemap ul ul, #sitemap_pages ul {
37
+ margin-bottom: 0;
38
+ list-style-type: circle;
39
+ }
40
+
41
+ .wpms_frontend_menus_sitemap li {
42
+ margin-bottom: 0;
43
+ list-style-type: circle;
44
+ }
45
+
46
+ #wpms_sitemap li {
47
+ display: list-item;
48
+ }
49
+
50
+ .wpms_clearRow {
51
+ width: 100%;
52
+ height: 24px;
53
+ display: block;
54
+ clear: both;
55
+ position: relative;
56
+ }
57
+
58
+ #credits_link {
59
+ font-size: 12px;
60
+ }
61
 
62
  /* Responsive */
63
+ @media screen and (max-width: 960px) {
64
+ #wpms_sitemap.columns_4 {
65
+ -moz-column-count: 3 !important;
66
+ -webkit-column-count: 3 !important;
67
+ column-count: 3 !important;
68
+ }
69
  }
70
+
71
+ @media screen and (max-width: 640px) {
72
+ #wpms_sitemap.columns_3, #wpms_sitemap.columns_4 {
73
+ -moz-column-count: 2 !important;
74
+ -webkit-column-count: 2 !important;
75
+ column-count: 2 !important;
76
+ }
77
  }
78
+
79
+ @media screen and (max-width: 480px) {
80
+ #wpms_sitemap.columns_4, #wpms_sitemap.columns_3, #wpms_sitemap.columns_2 {
81
+ -moz-column-count: 1 !important;
82
+ -webkit-column-count: 1 !important;
83
+ column-count: 1 !important;
84
+ }
85
  }
86
+
87
+ .wpms_li_cate .cat_name {
88
+ font-weight: bold;
89
  font-size: 14px;
90
  }
css/jquery.qtip.css CHANGED
@@ -19,7 +19,7 @@
19
  max-width: 280px;
20
  padding: 0;
21
  box-shadow: none;
22
- font-size: 10.5px;
23
  line-height: 12px;
24
 
25
  direction: ltr;
@@ -272,7 +272,6 @@
272
 
273
  /* jQuery TOOLS Tooltip style */
274
  .qtip-jtools {
275
- border: 2px solid #ddd;
276
  border: 2px solid rgba(241,241,241,1);
277
  border-radius: 2px;
278
  background: #232323;
@@ -400,7 +399,6 @@
400
  .qtip-bootstrap {
401
  /** Taken from Bootstrap .popover */
402
  padding: 1px;
403
- border: 1px solid #ccc;
404
  border: 1px solid rgba(0, 0, 0, 0.2);
405
  border-radius: 6px;
406
  color: #333;
@@ -505,7 +503,6 @@
505
 
506
  /* Opera bug #357 - Incorrect tip position
507
  https://github.com/Craga89/qTip2/issues/367 */
508
- x:-o-prefocus,
509
  .qtip .qtip-tip {
510
  visibility: hidden;
511
  }
19
  max-width: 280px;
20
  padding: 0;
21
  box-shadow: none;
22
+ font-size: 11px;
23
  line-height: 12px;
24
 
25
  direction: ltr;
272
 
273
  /* jQuery TOOLS Tooltip style */
274
  .qtip-jtools {
 
275
  border: 2px solid rgba(241,241,241,1);
276
  border-radius: 2px;
277
  background: #232323;
399
  .qtip-bootstrap {
400
  /** Taken from Bootstrap .popover */
401
  padding: 1px;
 
402
  border: 1px solid rgba(0, 0, 0, 0.2);
403
  border-radius: 6px;
404
  color: #333;
503
 
504
  /* Opera bug #357 - Incorrect tip position
505
  https://github.com/Craga89/qTip2/issues/367 */
 
506
  .qtip .qtip-tip {
507
  visibility: hidden;
508
  }
css/materialize/materialize.css CHANGED
@@ -1,4 +1,4 @@
1
-
2
  .wpmsrow {
3
  margin-left: auto;
4
  margin-right: auto;
@@ -213,7 +213,7 @@ input:checked + .slider:before {
213
  height: 16px;
214
  display: block;
215
  float: left;
216
- margin: 10px 0px 10px 10px;
217
  border: 3px solid #ccc;
218
  border-radius: 50%;
219
  background-color: #fff;
@@ -235,7 +235,6 @@ input:checked + .slider:before {
235
  }
236
 
237
  /* checkbox */
238
- @import "https://fonts.googleapis.com/css?family=Raleway";
239
  .pure-checkbox input[type="checkbox"]{
240
  border: 0;
241
  clip: rect(0 0 0 0);
@@ -332,7 +331,7 @@ input:checked + .slider:before {
332
  color: #fff !important;
333
  background-color: #2196F3;
334
  text-align: center;
335
- letter-spacing: .5px;
336
  -webkit-transition: 0.2s ease-out;
337
  -moz-transition: 0.2s ease-out;
338
  -o-transition: 0.2s ease-out;
@@ -366,7 +365,7 @@ input:checked + .slider:before {
366
  color: #444 !important;
367
  border: #ccc 1px solid;
368
  text-transform: none;
369
- padding: 0px 7px;
370
  }
371
 
372
  .wpms_input_material{
@@ -376,7 +375,7 @@ input:checked + .slider:before {
376
 
377
  .wpms-nav-tab-wrapper{
378
  display: block !important;
379
- margin: 10px 0px 10px 0px;
380
  }
381
 
382
  .wpms-nav-tab-wrapper .wpmstab{
@@ -394,7 +393,7 @@ input:checked + .slider:before {
394
 
395
  .wpms_wrap_hr{
396
  width: 100%;
397
- margin: 15px 0px;
398
  float: left;
399
  }
400
 
1
+ @import "https://fonts.googleapis.com/css?family=Raleway";
2
  .wpmsrow {
3
  margin-left: auto;
4
  margin-right: auto;
213
  height: 16px;
214
  display: block;
215
  float: left;
216
+ margin: 10px 0 10px 10px;
217
  border: 3px solid #ccc;
218
  border-radius: 50%;
219
  background-color: #fff;
235
  }
236
 
237
  /* checkbox */
 
238
  .pure-checkbox input[type="checkbox"]{
239
  border: 0;
240
  clip: rect(0 0 0 0);
331
  color: #fff !important;
332
  background-color: #2196F3;
333
  text-align: center;
334
+ letter-spacing: 1px;
335
  -webkit-transition: 0.2s ease-out;
336
  -moz-transition: 0.2s ease-out;
337
  -o-transition: 0.2s ease-out;
365
  color: #444 !important;
366
  border: #ccc 1px solid;
367
  text-transform: none;
368
+ padding: 0 7px;
369
  }
370
 
371
  .wpms_input_material{
375
 
376
  .wpms-nav-tab-wrapper{
377
  display: block !important;
378
+ margin: 10px 0 10px 0;
379
  }
380
 
381
  .wpms-nav-tab-wrapper .wpmstab{
393
 
394
  .wpms_wrap_hr{
395
  width: 100%;
396
+ margin: 15px 0;
397
  float: left;
398
  }
399
 
css/materialize/materialize_frontend_tab_theme.css CHANGED
@@ -66,8 +66,7 @@
66
  line-height: 48px;
67
  height: 48px;
68
  padding: 0;
69
- margin: 0;
70
- margin: 0px 10px;
71
  }
72
 
73
  .wpmstabs .wpmstab a {
66
  line-height: 48px;
67
  height: 48px;
68
  padding: 0;
69
+ margin: 0 10px;
 
70
  }
71
 
72
  .wpmstabs .wpmstab a {
css/metabox-tabs.css CHANGED
@@ -367,13 +367,13 @@ div.wpmseo-tab-content {
367
 
368
  .metaseo_analysis{
369
  width: 60%;
370
- padding: 8px 10px 8px 0px;
371
  line-height: 20px;
372
  float: left;
373
  }
374
 
375
  .metaseo_left{
376
- margin: 0px auto;
377
  float: left;
378
  }
379
  .metaseo-progress-bar{
@@ -416,17 +416,17 @@ div.wpmseo-tab-content {
416
  position: absolute;
417
  left: 20px;
418
  bottom: 12px;
419
- background: none repeat scroll 0% 0% #7ad03a;
420
  color: #fff;
421
  border-radius: 2px;
422
  min-width: 15px;
423
  text-align: center;
424
  float: left;
425
- padding: 0px 10px;
426
  }
427
 
428
  #metaseo_wpmseo_desc-length.length-wrong,#metaseo_wpmseo_title-length.length-wrong,#metaseo_wpmseo_keywords-length.length-wrong{
429
- background: none repeat scroll 0% 0% #FFCC00;
430
  }
431
 
432
  .reload_analysis{
@@ -434,7 +434,7 @@ div.wpmseo-tab-content {
434
  }
435
 
436
  .gsc_keywords_filter{
437
- margin: 5px 0px;
438
  width: 100%;
439
  float: left;
440
  }
367
 
368
  .metaseo_analysis{
369
  width: 60%;
370
+ padding: 8px 10px 8px 0;
371
  line-height: 20px;
372
  float: left;
373
  }
374
 
375
  .metaseo_left{
376
+ margin: 0 auto;
377
  float: left;
378
  }
379
  .metaseo-progress-bar{
416
  position: absolute;
417
  left: 20px;
418
  bottom: 12px;
419
+ background: none repeat scroll 0 0 #7ad03a;
420
  color: #fff;
421
  border-radius: 2px;
422
  min-width: 15px;
423
  text-align: center;
424
  float: left;
425
+ padding: 0 10px;
426
  }
427
 
428
  #metaseo_wpmseo_desc-length.length-wrong,#metaseo_wpmseo_title-length.length-wrong,#metaseo_wpmseo_keywords-length.length-wrong{
429
+ background: none repeat scroll 0 0 #FFCC00;
430
  }
431
 
432
  .reload_analysis{
434
  }
435
 
436
  .gsc_keywords_filter{
437
+ margin: 5px 0;
438
  width: 100%;
439
  float: left;
440
  }
css/metaseo-quirk.css CHANGED
@@ -43,17 +43,16 @@ h4,.h4 {
43
 
44
  h3,.h3 {
45
  font-family: inherit;
46
- font-weight: bold;
47
  line-height: 1.1;
48
  color: #262b36;
49
  margin-top: 17px;
50
- margin-bottom: 8.5px;
51
  font-weight: 500 !important;
52
  }
53
 
54
  h4,.h4 {
55
- margin-top: 8.5px;
56
- margin-bottom: 8.5px;
57
  }
58
 
59
  .h1 {
@@ -86,7 +85,7 @@ h6,
86
  }
87
 
88
  p {
89
- margin: 0 0 8.5px;
90
  }
91
 
92
  .lead {
@@ -99,7 +98,7 @@ p {
99
  @media (min-width: 768px) {
100
  .lead {
101
  font-size: 18px;
102
- };
103
  }
104
 
105
  small,
@@ -241,7 +240,7 @@ a.bg-danger:focus {
241
  }
242
 
243
  .page-header {
244
- padding-bottom: 7.5px;
245
  margin: 34px 0 17px;
246
  border-bottom: 1px solid #eeeeee;
247
  }
@@ -249,7 +248,7 @@ a.bg-danger:focus {
249
  ul,
250
  ol {
251
  margin-top: 0;
252
- margin-bottom: 8.5px;
253
  }
254
 
255
  ul ul,
@@ -307,7 +306,7 @@ dd {
307
 
308
  .dl-horizontal dd {
309
  margin-left: 180px;
310
- };
311
  }
312
 
313
  abbr[title],
@@ -322,7 +321,7 @@ abbr[data-original-title] {
322
  }
323
 
324
  blockquote {
325
- padding: 8.5px 17px;
326
  margin: 0 0 17px;
327
  font-size: 15px;
328
  border-left: 5px solid #eeeeee;
@@ -416,7 +415,7 @@ kbd kbd {
416
  pre {
417
  display: block;
418
  padding: 8px;
419
- margin: 0 0 8.5px;
420
  font-size: 11px;
421
  line-height: 1.42857143;
422
  word-break: break-all;
@@ -451,19 +450,19 @@ pre code {
451
  @media (min-width: 768px) {
452
  .container {
453
  width: 740px;
454
- };
455
  }
456
 
457
  @media (min-width: 992px) {
458
  .container {
459
  width: 960px;
460
- };
461
  }
462
 
463
  @media (min-width: 1650px) {
464
  .container {
465
  width: 1160px;
466
- };
467
  }
468
 
469
  .container-fluid {
@@ -690,7 +689,7 @@ pre code {
690
  }
691
 
692
  .col-xs-offset-0 {
693
- margin-left: 0%;
694
  }
695
 
696
  @media (min-width: 768px) {
@@ -900,8 +899,8 @@ pre code {
900
  }
901
 
902
  .col-sm-offset-0 {
903
- margin-left: 0%;
904
- };
905
  }
906
 
907
  @media (min-width: 992px) {
@@ -923,8 +922,7 @@ pre code {
923
 
924
  .col-md-9 {
925
  width: 75%;
926
- margin: 0px auto;
927
- margin-top: 20px;
928
  }
929
 
930
  .col-md-8 {
@@ -1112,8 +1110,8 @@ pre code {
1112
  }
1113
 
1114
  .col-md-offset-0 {
1115
- margin-left: 0%;
1116
- };
1117
  }
1118
 
1119
  @media (min-width: 1650px) {
@@ -1322,8 +1320,8 @@ pre code {
1322
  }
1323
 
1324
  .col-lg-offset-0 {
1325
- margin-left: 0%;
1326
- };
1327
  }
1328
 
1329
  label {
@@ -1345,7 +1343,7 @@ label {
1345
 
1346
  .progress-bar {
1347
  float: left;
1348
- width: 0%;
1349
  height: 100%;
1350
  font-size: 11px;
1351
  line-height: 17px;
@@ -1509,7 +1507,7 @@ label {
1509
  font-size: 12px;
1510
  font-weight: 700;
1511
  color: #313745;
1512
- letter-spacing: .2px;
1513
  font-family: 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif;
1514
  }
1515
 
@@ -1615,14 +1613,13 @@ label {
1615
  @media (max-width: 480px) {
1616
  .panel-group .panel > .panel-heading .panel-title {
1617
  line-height: 18px;
1618
- };
1619
  }
1620
 
1621
  .panel-group .panel > .panel-heading .panel-title > a {
1622
  display: block;
1623
  position: relative;
1624
  padding: 18px 20px 15px;
1625
- color: #505b72;
1626
  color: #259dab;
1627
  background-color: #fff;
1628
  -webkit-transition: all 0.2s ease-out 0s;
@@ -2063,7 +2060,7 @@ a.text-danger:focus {
2063
 
2064
  .panel-statistics > div:last-child > .panel {
2065
  border-bottom-left-radius: 2px;
2066
- };
2067
  }
2068
 
2069
  .panel-updates h3 {
43
 
44
  h3,.h3 {
45
  font-family: inherit;
 
46
  line-height: 1.1;
47
  color: #262b36;
48
  margin-top: 17px;
49
+ margin-bottom: 9px;
50
  font-weight: 500 !important;
51
  }
52
 
53
  h4,.h4 {
54
+ margin-top: 9px;
55
+ margin-bottom: 9px;
56
  }
57
 
58
  .h1 {
85
  }
86
 
87
  p {
88
+ margin: 0 0 9px;
89
  }
90
 
91
  .lead {
98
  @media (min-width: 768px) {
99
  .lead {
100
  font-size: 18px;
101
+ }
102
  }
103
 
104
  small,
240
  }
241
 
242
  .page-header {
243
+ padding-bottom: 8px;
244
  margin: 34px 0 17px;
245
  border-bottom: 1px solid #eeeeee;
246
  }
248
  ul,
249
  ol {
250
  margin-top: 0;
251
+ margin-bottom: 9px;
252
  }
253
 
254
  ul ul,
306
 
307
  .dl-horizontal dd {
308
  margin-left: 180px;
309
+ }
310
  }
311
 
312
  abbr[title],
321
  }
322
 
323
  blockquote {
324
+ padding: 9px 17px;
325
  margin: 0 0 17px;
326
  font-size: 15px;
327
  border-left: 5px solid #eeeeee;
415
  pre {
416
  display: block;
417
  padding: 8px;
418
+ margin: 0 0 9px;
419
  font-size: 11px;
420
  line-height: 1.42857143;
421
  word-break: break-all;
450
  @media (min-width: 768px) {
451
  .container {
452
  width: 740px;
453
+ }
454
  }
455
 
456
  @media (min-width: 992px) {
457
  .container {
458
  width: 960px;
459
+ }
460
  }
461
 
462
  @media (min-width: 1650px) {
463
  .container {
464
  width: 1160px;
465
+ }
466
  }
467
 
468
  .container-fluid {
689
  }
690
 
691
  .col-xs-offset-0 {
692
+ margin-left: 0;
693
  }
694
 
695
  @media (min-width: 768px) {
899
  }
900
 
901
  .col-sm-offset-0 {
902
+ margin-left: 0;
903
+ }
904
  }
905
 
906
  @media (min-width: 992px) {
922
 
923
  .col-md-9 {
924
  width: 75%;
925
+ margin: 20px auto 0;
 
926
  }
927
 
928
  .col-md-8 {
1110
  }
1111
 
1112
  .col-md-offset-0 {
1113
+ margin-left: 0;
1114
+ }
1115
  }
1116
 
1117
  @media (min-width: 1650px) {
1320
  }
1321
 
1322
  .col-lg-offset-0 {
1323
+ margin-left: 0;
1324
+ }
1325
  }
1326
 
1327
  label {
1343
 
1344
  .progress-bar {
1345
  float: left;
1346
+ width: 0;
1347
  height: 100%;
1348
  font-size: 11px;
1349
  line-height: 17px;
1507
  font-size: 12px;
1508
  font-weight: 700;
1509
  color: #313745;
1510
+ letter-spacing: 0;
1511
  font-family: 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif;
1512
  }
1513
 
1613
  @media (max-width: 480px) {
1614
  .panel-group .panel > .panel-heading .panel-title {
1615
  line-height: 18px;
1616
+ }
1617
  }
1618
 
1619
  .panel-group .panel > .panel-heading .panel-title > a {
1620
  display: block;
1621
  position: relative;
1622
  padding: 18px 20px 15px;
 
1623
  color: #259dab;
1624
  background-color: #fff;
1625
  -webkit-transition: all 0.2s ease-out 0s;
2060
 
2061
  .panel-statistics > div:last-child > .panel {
2062
  border-bottom-left-radius: 2px;
2063
+ }
2064
  }
2065
 
2066
  .panel-updates h3 {
css/metaseo_admin.css CHANGED
@@ -8,7 +8,7 @@ and open the template in the editor.
8
  Author : Vien Nguyen
9
  */
10
 
11
- .search-box{padding: 0px 0px 20px 0px; float: left}
12
  .widefat .column-col_id {
13
  width: 2.2em;
14
  vertical-align: top;
@@ -35,18 +35,18 @@ and open the template in the editor.
35
  min-width: 15px;
36
  text-align: center;
37
  float: left;
38
- padding: 0px 10px;
39
  position: relative;
40
  bottom: 12px;
41
  left: 15px;
42
  }
43
 
44
  .title-len, .desc-len, .keywords-len {
45
- background: none repeat scroll 0% 0% #7ad03a;
46
 
47
  }
48
  .word-exceed {
49
- background: none repeat scroll 0% 0% #FFCC00;
50
  }
51
 
52
  .savedInfo {
@@ -162,7 +162,7 @@ a.info-content .tooltip-metacontent
162
  /* Alexa CSS */
163
  .rank-row, .metrics-row {
164
  margin-bottom: 25px;
165
- margin-top: 0px !important;
166
  }
167
  a.tt {
168
  cursor: help;
@@ -363,7 +363,6 @@ strong {
363
  display: none;
364
  float: left;
365
  background: #00a0d2;
366
- border-color: #0073aa;
367
  box-shadow: inset 0 1px 0 rgba( 120, 200, 230, 0.5 ), 0 1px 0 rgba( 0, 0, 0, 0.15 );
368
  color: #fff;
369
  text-decoration: none;
@@ -374,8 +373,7 @@ strong {
374
  margin: 0;
375
  padding: 0 10px 1px;
376
  cursor: pointer;
377
- border-width: 1px;
378
- border-style: solid;
379
  -webkit-appearance: none;
380
  border-radius: 3px;
381
  white-space: nowrap;
@@ -485,7 +483,7 @@ strong {
485
  .metaseo-dashicons.icons-mwarning {
486
  width: 20px;
487
  height: 20px;
488
- margin: 0px 5px;
489
  background-image: url(../img/warnig-red.png);
490
  background-size: 100% 100%;
491
  }
@@ -507,7 +505,7 @@ strong {
507
  .wpms_process{
508
  background:#81b5ee;
509
  height: 2px;
510
- width:0%;
511
  display: none;
512
  }
513
 
@@ -641,8 +639,7 @@ span.wpms-seoImgRemove{
641
 
642
  .wpmseotab th.header {
643
  cursor: pointer;
644
- background-repeat: no-repeat;
645
- background-position: center right;
646
  }
647
 
648
  .wpmseotab .column-first{
@@ -669,7 +666,7 @@ span.wpms-seoImgRemove{
669
  .wpms_process_meta{
670
  background: #81b5ee;
671
  height: 2px;
672
- width: 0%;
673
  position: absolute;
674
  top: -2px;
675
  }
8
  Author : Vien Nguyen
9
  */
10
 
11
+ .search-box{padding: 0 0 20px 0; float: left}
12
  .widefat .column-col_id {
13
  width: 2.2em;
14
  vertical-align: top;
35
  min-width: 15px;
36
  text-align: center;
37
  float: left;
38
+ padding: 0 10px;
39
  position: relative;
40
  bottom: 12px;
41
  left: 15px;
42
  }
43
 
44
  .title-len, .desc-len, .keywords-len {
45
+ background: none repeat scroll 0 0 #7ad03a;
46
 
47
  }
48
  .word-exceed {
49
+ background: none repeat scroll 0 0 #FFCC00;
50
  }
51
 
52
  .savedInfo {
162
  /* Alexa CSS */
163
  .rank-row, .metrics-row {
164
  margin-bottom: 25px;
165
+ margin-top: 0 !important;
166
  }
167
  a.tt {
168
  cursor: help;
363
  display: none;
364
  float: left;
365
  background: #00a0d2;
 
366
  box-shadow: inset 0 1px 0 rgba( 120, 200, 230, 0.5 ), 0 1px 0 rgba( 0, 0, 0, 0.15 );
367
  color: #fff;
368
  text-decoration: none;
373
  margin: 0;
374
  padding: 0 10px 1px;
375
  cursor: pointer;
376
+ border: 1px solid #0073aa;
 
377
  -webkit-appearance: none;
378
  border-radius: 3px;
379
  white-space: nowrap;
483
  .metaseo-dashicons.icons-mwarning {
484
  width: 20px;
485
  height: 20px;
486
+ margin: 0 5px;
487
  background-image: url(../img/warnig-red.png);
488
  background-size: 100% 100%;
489
  }
505
  .wpms_process{
506
  background:#81b5ee;
507
  height: 2px;
508
+ width:0;
509
  display: none;
510
  }
511
 
639
 
640
  .wpmseotab th.header {
641
  cursor: pointer;
642
+ background: no-repeat center right;
 
643
  }
644
 
645
  .wpmseotab .column-first{
666
  .wpms_process_meta{
667
  background: #81b5ee;
668
  height: 2px;
669
+ width: 0;
670
  position: absolute;
671
  top: -2px;
672
  }
css/metaseo_sitemap.css CHANGED
@@ -8,7 +8,7 @@
8
  }
9
 
10
  .spinner_save_sitemaps{
11
- margin: 8px 10px 0px;
12
  }
13
 
14
  .div_wpms_save_sitemaps{
@@ -21,7 +21,7 @@
21
  .div_sitemap_check_all{
22
  width: 100%;
23
  float: left;
24
- margin: 10px 10px 0px 0px;
25
  }
26
 
27
  .wpms_wrap .nav-tab{
@@ -50,7 +50,7 @@
50
 
51
 
52
  a:active {
53
- outline: 0px dashed red;
54
  }
55
 
56
  .wpmsleft{
8
  }
9
 
10
  .spinner_save_sitemaps{
11
+ margin: 8px 10px 0;
12
  }
13
 
14
  .div_wpms_save_sitemaps{
21
  .div_sitemap_check_all{
22
  width: 100%;
23
  float: left;
24
+ margin: 10px 10px 0 0;
25
  }
26
 
27
  .wpms_wrap .nav-tab{
50
 
51
 
52
  a:active {
53
+ outline: 0 dashed red;
54
  }
55
 
56
  .wpmsleft{
css/notification.css CHANGED
@@ -1,12 +1,12 @@
1
  /* dashboard */
2
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification{
3
  width: 75%;
4
- margin: 0px auto;
5
- padding: 0px 10px;
6
  }
7
 
8
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification h1 {
9
- padding: 10px 0px 10px 20px
10
  }
11
 
12
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification .dashboard_noti_title {
@@ -14,12 +14,12 @@
14
  width: 100%;
15
  font-size: 22px;
16
  color: #fff;
17
- margin: 10px 0px 15px 0px;
18
  }
19
 
20
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification .msg{
21
  font-size: 14px !important;
22
- margin: 10px 0px 30px 0px;
23
  float: left;
24
  }
25
 
@@ -51,13 +51,12 @@
51
  /* Sitemap */
52
  .wpms_notification{
53
  width: 99%;
54
- margin: 0px auto;
55
  float: left;
56
- margin-top: 10px;
57
  }
58
 
59
  .wpms_notification h1 {
60
- padding: 10px 0px 10px 20px
61
  }
62
 
63
  .wpms_notification .dashboard_noti_title {
@@ -65,7 +64,7 @@
65
  width: 100%;
66
  font-size: 22px;
67
  color: #fff;
68
- margin: 10px 0px 15px 0px;
69
  float: left;
70
  }
71
 
1
  /* dashboard */
2
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification{
3
  width: 75%;
4
+ margin: 0 auto;
5
+ padding: 0 10px;
6
  }
7
 
8
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification h1 {
9
+ padding: 10px 0 10px 20px
10
  }
11
 
12
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification .dashboard_noti_title {
14
  width: 100%;
15
  font-size: 22px;
16
  color: #fff;
17
+ margin: 10px 0 15px 0;
18
  }
19
 
20
  .toplevel_page_metaseo_dashboard .wpms_dashboard_notification .msg{
21
  font-size: 14px !important;
22
+ margin: 10px 0 30px 0;
23
  float: left;
24
  }
25
 
51
  /* Sitemap */
52
  .wpms_notification{
53
  width: 99%;
 
54
  float: left;
55
+ margin: 10px auto 0;
56
  }
57
 
58
  .wpms_notification h1 {
59
+ padding: 10px 0 10px 20px
60
  }
61
 
62
  .wpms_notification .dashboard_noti_title {
64
  width: 100%;
65
  font-size: 22px;
66
  color: #fff;
67
+ margin: 10px 0 15px 0;
68
  float: left;
69
  }
70
 
css/style.css CHANGED
@@ -1,5 +1,6 @@
1
- .search-box{padding: 0px 0px 20px 0px; float: left}
2
- .img_advan{border: #CCC 1px solid;border-radius: 0px 30px 30px 0px}
 
3
  .listpre img{float: left; padding: 5px}
4
 
5
  .metaseo_images div.popup-bg {
@@ -29,7 +30,7 @@
29
 
30
  .metaseo_images .popup-header .pop-title{
31
  background: #FFF;
32
- padding: 6px 0px 0px 15px;
33
  color:#555!important;
34
  margin:0;
35
  font-size:16px;
@@ -131,8 +132,8 @@ td.metaseo-action{
131
 
132
  .metaseo-img .img-choosen{
133
  position: absolute;
134
- top:0px;
135
- left: 0px;
136
  float:left;
137
  }
138
 
@@ -183,7 +184,6 @@ a.info .tooltip{
183
  a.info:hover .tooltip {
184
  display:inline;
185
  position:absolute;
186
- color:#111;
187
  border:1px solid #DCA;
188
  border-radius: 10px;
189
  background:rgba(51,51,51,0.8);
@@ -235,7 +235,7 @@ a.img-resize, a.fix-metas{
235
  float:right;
236
  margin-left:8px!important;
237
  text-transform: none;
238
- padding: 0px 7px;
239
  color: #fff;
240
  }
241
 
1
+ .search-box{padding: 0 0 20px 0; float: left}
2
+ .img_advan{border: #CCC 1px solid;border-radius: 0 30px 30px 0
3
+ }
4
  .listpre img{float: left; padding: 5px}
5
 
6
  .metaseo_images div.popup-bg {
30
 
31
  .metaseo_images .popup-header .pop-title{
32
  background: #FFF;
33
+ padding: 6px 0 0 15px;
34
  color:#555!important;
35
  margin:0;
36
  font-size:16px;
132
 
133
  .metaseo-img .img-choosen{
134
  position: absolute;
135
+ top:0;
136
+ left: 0;
137
  float:left;
138
  }
139
 
184
  a.info:hover .tooltip {
185
  display:inline;
186
  position:absolute;
 
187
  border:1px solid #DCA;
188
  border-radius: 10px;
189
  background:rgba(51,51,51,0.8);
235
  float:right;
236
  margin-left:8px!important;
237
  text-transform: none;
238
+ padding: 0 7px;
239
  color: #fff;
240
  }
241
 
css/tooltip-metaimage.css CHANGED
@@ -6,7 +6,7 @@ a.info .tooltip{
6
  width:250px; line-height:15px;
7
  }
8
  a.info:hover .tooltip {
9
- display:inline; position:absolute; color:#111;
10
  border:1px solid #DCA;
11
  border-radius: 10px;
12
  background:rgba(51,51,51,0.8);
6
  width:250px; line-height:15px;
7
  }
8
  a.info:hover .tooltip {
9
+ display:inline; position:absolute;
10
  border:1px solid #DCA;
11
  border-radius: 10px;
12
  background:rgba(51,51,51,0.8);
css/tooltip.css CHANGED
@@ -6,7 +6,7 @@ a.info .tooltip {
6
  width:250px; line-height:16px;
7
  }
8
  a.info:hover .tooltip{
9
- display:inline; position:absolute; color:#111;
10
  border:1px solid #DCA;
11
  border-radius: 10px;
12
  background:rgba(51,51,51,0.8);
6
  width:250px; line-height:16px;
7
  }
8
  a.info:hover .tooltip{
9
+ display:inline; position:absolute;
10
  border:1px solid #DCA;
11
  border-radius: 10px;
12
  background:rgba(51,51,51,0.8);
inc/autoload.php CHANGED
@@ -15,10 +15,16 @@
15
  * See the License for the specific language governing permissions and
16
  * limitations under the License.
17
  */
18
-
 
19
  if (!function_exists('google_api_php_client_autoload')) {
20
 
21
- function google_api_php_client_autoload($className) {
 
 
 
 
 
22
  $classPath = explode('_', $className);
23
  if ($classPath[0] != 'Google') {
24
  return;
@@ -29,9 +35,9 @@ if (!function_exists('google_api_php_client_autoload')) {
29
  }
30
  $filePath = dirname(__FILE__) . '/SrcGoogle/' . implode('/', $classPath) . '.php';
31
  if (file_exists($filePath)) {
32
- require_once ($filePath);
33
  }
34
  }
35
 
36
  spl_autoload_register('google_api_php_client_autoload');
37
- }
15
  * See the License for the specific language governing permissions and
16
  * limitations under the License.
17
  */
18
+ /* Prohibit direct script loading */
19
+ defined('ABSPATH') || die('No direct script access allowed!');
20
  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;
35
  }
36
  $filePath = dirname(__FILE__) . '/SrcGoogle/' . implode('/', $classPath) . '.php';
37
  if (file_exists($filePath)) {
38
+ require_once($filePath);
39
  }
40
  }
41
 
42
  spl_autoload_register('google_api_php_client_autoload');
43
+ }
inc/breadcrumb/class.metaseo-breadcrumb.php CHANGED
@@ -1,15 +1,34 @@
1
  <?php
 
 
2
 
3
- class MetaSeo_Breadcrumb
 
 
 
4
  {
 
 
 
5
  public $breadcrumbs = array();
 
 
 
6
  public $breadcrumb_settings = array();
 
 
 
7
  public $template_no_anchor;
8
 
9
- function __construct()
 
 
 
10
  {
11
- $home_title = get_the_title( get_option('page_on_front') );
12
- if(empty($home_title)) $home_title = get_bloginfo('title');
 
 
13
  $this->breadcrumb_settings = array(
14
  'separator' => ' &gt; ',
15
  'include_home' => 1,
@@ -25,33 +44,46 @@ class MetaSeo_Breadcrumb
25
  }
26
  }
27
 
28
- public function wpms_check_posts()
 
 
 
 
 
29
  {
30
  global $wp_query;
31
  //For the front page, as it may also validate as a page, do it first
32
  if (is_front_page()) {
33
  global $current_site;
34
  $site_name = get_option('blogname');
35
- $this->wpms_add_breadcrumb($site_name, WPMSEO_TEMPLATE_BREADCRUMB, array('home', 'current-item'));
36
  if (!is_main_site()) {
37
  $site_name = get_site_option('site_name');
38
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
39
- $this->wpms_add_breadcrumb($site_name, $template, array('main-home'), get_home_url($current_site->blog_id));
 
 
 
 
 
 
 
 
 
40
  }
41
- } else if (is_singular()) {
42
-
43
  if (is_attachment()) {
44
  // attachments
45
- $this->wpms_attachment();
46
  } else {
47
  // other post types
48
- $this->wpms_post(get_post());
49
  }
50
- } else if (is_search()) {
51
- $this->wpms_search();
52
- } else if (is_author()) {
53
- $this->wpms_author();
54
- } else if (is_archive()) {
55
  $type = $wp_query->get_queried_object();
56
  $type_str = get_query_var('post_type');
57
  if (is_array($type_str)) {
@@ -59,29 +91,35 @@ class MetaSeo_Breadcrumb
59
  }
60
  //For date based archives
61
  if (is_date()) {
62
- $this->wpms_archive_by_date($this->wpms_get_type());
63
- } else if (is_post_type_archive() && !isset($type->taxonomy) && (!is_numeric($this->breadcrumb_settings['apost_' . $type_str . '_root']))) {
64
- $this->wpms_archive_by_post_type();
65
- } else if (is_category() || is_tag() || is_tax()) {
66
- $this->wpms_archive_by_term();
 
67
  }
68
- } else if (is_404()) {
69
- $this->wpms_add_breadcrumb('404', WPMSEO_TEMPLATE_BREADCRUMB, array('404', 'current-item'));
70
  } else {
71
  $type = $wp_query->get_queried_object();
72
  if (isset($type->taxonomy)) {
73
- $this->wpms_archive_by_term();
74
  }
75
  }
76
  // home
77
  if (!is_front_page()) {
78
- if(!empty($this->breadcrumb_settings['include_home'])){
79
- $this->wpms_home();
80
  }
81
  }
82
  }
83
 
84
- public function wpms_breadcrumb_display($return = false, $reverse = false)
 
 
 
 
 
85
  {
86
  // order breadcrumb
87
  if ($reverse) {
@@ -105,7 +143,7 @@ class MetaSeo_Breadcrumb
105
  }
106
  }
107
 
108
- $html .= $this->wpms_breadcrumb_createhtml($breadcrumb,$position);
109
  $position++;
110
  }
111
 
@@ -117,9 +155,12 @@ class MetaSeo_Breadcrumb
117
  }
118
 
119
  /**
120
- * create html string
 
 
 
121
  */
122
- public function wpms_breadcrumb_createhtml($breadcrumb, $position)
123
  {
124
  $params = array(
125
  '%title%' => esc_attr(strip_tags($breadcrumb['name'])),
@@ -135,9 +176,9 @@ class MetaSeo_Breadcrumb
135
  $params['%type%'] = implode(' ', $params['%type%']);
136
  }
137
 
138
- if(empty($this->breadcrumb_settings['clickable'])){
139
  return str_replace(array_keys($params), $params, $this->template_no_anchor);
140
- }else{
141
  if ($breadcrumb['click']) {
142
  //Return template
143
  return str_replace(array_keys($params), $params, $breadcrumb['template']);
@@ -146,30 +187,16 @@ class MetaSeo_Breadcrumb
146
  return str_replace(array_keys($params), $params, $this->template_no_anchor);
147
  }
148
  }
149
-
150
-
151
- }
152
-
153
- /**
154
- * breadcrumb for front page
155
- */
156
- public function wpms_front_page()
157
- {
158
- global $current_site;
159
- $site_name = get_option('blogname');
160
- $this->wpms_add_breadcrumb($site_name, WPMSEO_TEMPLATE_BREADCRUMB, array('home', 'current-item'));
161
- if (!is_main_site()) {
162
- $site_name = get_site_option('site_name');
163
- // Add to breadcrumbs list
164
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
165
- $this->wpms_add_breadcrumb($site_name, $template, array('main-home'), get_home_url($current_site->blog_id));
166
- }
167
  }
168
 
169
  /**
170
- * breadcrumb for posts
 
 
 
 
171
  */
172
- public function wpms_post($post)
173
  {
174
  if (!($post instanceof WP_Post)) {
175
  return;
@@ -179,13 +206,15 @@ class MetaSeo_Breadcrumb
179
  'name' => get_the_title($post),
180
  'template' => WPMSEO_TEMPLATE_BREADCRUMB,
181
  'type' => array('post', 'post-' . $post->post_type, 'current-item'),
182
- 'url' => NULL,
183
  'id' => $post->ID,
184
  'click' => false
185
  );
186
 
187
  if (is_attachment()) {
188
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
 
 
189
  $arrays['template'] = $template;
190
  $arrays['url'] = get_permalink($post);
191
  $arrays['click'] = true;
@@ -194,61 +223,88 @@ class MetaSeo_Breadcrumb
194
  if ($post->post_type === 'page') {
195
  $frontpage = get_option('page_on_front');
196
  if ($post->post_parent && $post->ID != $post->post_parent && $frontpage != $post->post_parent) {
197
-
198
- $this->wpms_post_parents($post->post_parent, $frontpage);
199
  }
200
  } else {
201
- $this->wpms_post_hierarchy($post->ID);
202
  }
203
  }
204
 
205
- /*
206
- * find breadcrumb of parent
 
 
 
 
 
207
  */
208
- public function wpms_post_parents($id, $frontpage)
209
  {
210
  $parent = get_post($id);
211
  // Add to breadcrumbs list
212
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
213
- $this->wpms_add_breadcrumb(get_the_title($id), $template, array('post', 'post-' . $parent->post_type), get_permalink($id), $id);
214
- if($parent->post_parent >= 0 && $parent->post_parent != false && $id != $parent->post_parent && $frontpage != $parent->post_parent)
215
- {
 
 
 
 
 
 
 
 
216
  //If valid call this function
217
- $parent = $this->wpms_post_parents($parent->post_parent, $frontpage);
218
  }
219
  return $parent;
220
  }
221
 
222
  /**
223
- * breadcrumb for an attachment page.
 
 
224
  */
225
- public function wpms_attachment()
226
  {
227
  $post = get_post();
228
  // Add to breadcrumbs list
229
- $this->wpms_add_breadcrumb(get_the_title(), WPMSEO_TEMPLATE_BREADCRUMB, array('post', 'post-attachment', 'current-item'), NULL, $post->ID);
 
 
 
 
 
 
230
  //Done with the current item, now on to the parents
231
  $frontpage = get_option('page_on_front');
232
- if ($post->post_parent >= 0 && $post->post_parent != false && $post->ID != $post->post_parent && $frontpage != $post->post_parent) {
 
233
  $parent = get_post($post->post_parent);
234
  //set the parent's breadcrumb
235
- $this->wpms_post($parent);
236
  }
237
  }
238
 
239
  /**
240
- * breadcrumb for search
 
 
241
  */
242
- public function wpms_search()
243
  {
244
- $template = __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for &#39;%htitle%&#39;</span><meta property="position" content="%position%"></span>', 'wp-meta-seo');
245
- $this->wpms_add_breadcrumb(get_search_query(), $template, array('search', 'current-item'));
 
 
246
  }
247
 
248
  /**
249
- * breadcrumb for author
 
 
250
  */
251
- public function wpms_author()
252
  {
253
  if (get_query_var('author_name')) {
254
  $author = get_user_by('slug', get_query_var('author_name'));
@@ -259,28 +315,57 @@ class MetaSeo_Breadcrumb
259
  $author_name = array('display_name', 'nickname', 'first_name', 'last_name');
260
  if (in_array('display_name', $author_name)) {
261
  // Add to breadcrumbs list
262
- $template = __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: %htitle%</span><meta property="position" content="%position%"></span>', 'wp-meta-seo');
263
- $this->wpms_add_breadcrumb(get_the_author_meta('display_name', $author->ID), $template, array('author', 'current-item'), NULL, $author->ID);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  }
265
  }
266
 
267
  /**
268
- * breadcrumb for an archive by post_type.
 
 
269
  */
270
- public function wpms_archive_by_post_type()
271
  {
272
- $type = $this->wpms_get_type();
273
  // Add to breadcrumbs list
274
- $this->wpms_add_breadcrumb(post_type_archive_title('', false), WPMSEO_TEMPLATE_BREADCRUMB, array('archive', 'post-' . $type . '-archive', 'current-item'));
 
 
 
 
 
 
 
 
275
  }
276
 
277
  /**
278
- * breadcrumb for date
 
 
 
 
279
  */
280
- public function wpms_archive_by_date($type)
281
  {
282
- global $wp_query;
283
- $date_template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
 
284
  if (is_day() || is_single()) {
285
  $arrays = array(
286
  'name' => get_the_time(_x('d', 'day archive breadcrumb date format', 'wp-meta-seo')),
@@ -290,14 +375,14 @@ class MetaSeo_Breadcrumb
290
 
291
  if (is_day()) {
292
  $arrays['type'] = 'current-item';
293
- $arrays['url'] = NULL;
294
  $arrays['click'] = false;
295
  }
296
  // if is single
297
  if (is_single()) {
298
  $arrays['template'] = $date_template;
299
  $url = get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
300
- $url = $this->wpms_add_post_type_arg($url, $type);
301
  $arrays['url'] = $url;
302
  $arrays['click'] = true;
303
  }
@@ -315,14 +400,14 @@ class MetaSeo_Breadcrumb
315
 
316
  if (is_month()) {
317
  $arrays['type'] = 'current-item';
318
- $arrays['url'] = NULL;
319
  $arrays['click'] = false;
320
  }
321
 
322
  if (is_day() || is_single()) {
323
  $arrays['template'] = $date_template;
324
  $url = get_month_link(get_the_time('Y'), get_the_time('m'));
325
- $url = $this->wpms_add_post_type_arg($url, $type);
326
  $arrays['url'] = $url;
327
  $arrays['click'] = true;
328
  }
@@ -340,7 +425,7 @@ class MetaSeo_Breadcrumb
340
  //If this is a year archive, add current-item type
341
  if (is_year()) {
342
  $arrays['type'] = 'current-item';
343
- $arrays['url'] = NULL;
344
  $arrays['click'] = false;
345
  }
346
  // day or month or single
@@ -348,7 +433,7 @@ class MetaSeo_Breadcrumb
348
  //We're linking, so set the linked template
349
  $arrays['template'] = $date_template;
350
  $url = get_year_link(get_the_time('Y'));
351
- $url = $this->wpms_add_post_type_arg($url, $type);
352
  $arrays['url'] = $url;
353
  $arrays['click'] = true;
354
  }
@@ -356,57 +441,110 @@ class MetaSeo_Breadcrumb
356
  $this->breadcrumbs[] = $arrays;
357
  }
358
 
359
- public function wpms_archive_by_term()
 
 
 
 
 
360
  {
361
  global $wp_query;
362
  $term = $wp_query->get_queried_object();
363
  // Add to breadcrumbs list
364
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
365
- $this->wpms_add_breadcrumb($term->name, $template, array('archive', 'taxonomy', $term->taxonomy, 'current-item'), NULL, $term->term_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  //Get parents of current term
367
  if ($term->parent) {
368
- $this->term_parents($term->parent, $term->taxonomy);
369
  }
370
  }
371
 
372
- public function term_parents($id, $taxonomy)
 
 
 
 
 
 
 
 
373
  {
374
  //Get the current category
375
  $term = get_term($id, $taxonomy);
376
  // Add to breadcrumbs list
377
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
378
- $this->wpms_add_breadcrumb($term->name, $template, array('taxonomy', $taxonomy), $this->wpms_add_post_type_arg(get_term_link($term), NULL, $taxonomy), $id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  if ($term->parent && $term->parent != $id) {
380
- $term = $this->term_parents($term->parent, $taxonomy);
381
  }
382
  return $term;
383
  }
384
 
385
- /*
386
  * add a enlement to lists
 
 
 
 
 
387
  */
388
- public function wpms_add_breadcrumb($name = '', $template = '', array $type = array(), $url = '', $id = NULL , $click = true)
389
- {
 
 
 
 
 
390
  $allowed_html = wp_kses_allowed_html('post');
391
- $tmp = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
 
 
392
  $this->template_no_anchor = WPMSEO_TEMPLATE_BREADCRUMB;
393
- if ($template == NULL) {
394
- $template = wp_kses($tmp,$allowed_html);
395
  } else {
396
- //Loose comparison, evaluates to true if URL is '' or NULL
397
- if ($url == NULL) {
398
  $this->template_no_anchor = wp_kses($template, $allowed_html);
399
- $template = wp_kses($tmp,$allowed_html);
400
  } else {
401
- $template = wp_kses($template,$allowed_html);
402
  }
403
  }
404
 
405
  // check click or not
406
- if(empty($this->breadcrumb_settings['clickable'])){
407
  $click = false;
408
- }else{
409
- if ($url == NULL) {
410
  $click = false;
411
  } else {
412
  $click = true;
@@ -424,7 +562,13 @@ class MetaSeo_Breadcrumb
424
  );
425
  }
426
 
427
- public function wpms_post_hierarchy($id)
 
 
 
 
 
 
428
  {
429
  $taxonomy = 'category';
430
  if (is_taxonomy_hierarchical($taxonomy)) {
@@ -446,21 +590,27 @@ class MetaSeo_Breadcrumb
446
 
447
  if ($term instanceof WP_Term) {
448
  //Fill out the term hiearchy
449
- $parent = $this->term_parents($term->term_id, $taxonomy);
450
  }
451
- } else {
452
- $this->post_terms($id, $taxonomy);
453
  }
 
 
454
  }
455
 
456
  /**
457
- * Add post type argument to the URL
 
 
 
 
 
 
458
  */
459
- public function wpms_add_post_type_arg($url, $type = NULL, $taxonomy = NULL)
460
  {
461
  global $wp_taxonomies;
462
- if ($type == NULL) {
463
- $type = $this->wpms_get_type();
464
  }
465
 
466
  // add post_type to url
@@ -473,8 +623,10 @@ class MetaSeo_Breadcrumb
473
 
474
  /**
475
  * get post type
 
 
476
  */
477
- public function wpms_get_type($default = 'post')
478
  {
479
  $type = get_query_var('post_type', $default);
480
  if ($type === '' || is_array($type)) {
@@ -489,26 +641,30 @@ class MetaSeo_Breadcrumb
489
  }
490
 
491
  /**
492
- * breadcrumb for the home page.
 
 
493
  */
494
- public function wpms_home()
495
  {
496
  global $current_site;
497
  //Get the site name
498
  $site_name = get_option('blogname');
499
- $template = __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'wp-meta-seo');
 
 
500
 
501
- if(!empty($this->breadcrumb_settings['home_text_default'])){
502
  $title = $this->breadcrumb_settings['home_text'];
503
- }else{
504
  $title = $site_name;
505
  }
506
- $this->wpms_add_breadcrumb($title, $template, array('home'), get_home_url());
507
  if (!is_main_site()) {
508
  //Get the site name
509
  $site_name = get_site_option('site_name');
510
  // Add to breadcrumbs list
511
- $this->wpms_add_breadcrumb($site_name, $template, array('main-home'), get_home_url($current_site->blog_id));
512
  }
513
  }
514
- }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
 
5
+ /**
6
+ * Class MetaSeoBreadcrumb
7
+ */
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
 
23
+ /**
24
+ * MetaSeoBreadcrumb constructor.
25
+ */
26
+ public function __construct()
27
  {
28
+ $home_title = get_the_title(get_option('page_on_front'));
29
+ if (empty($home_title)) {
30
+ $home_title = get_bloginfo('title');
31
+ }
32
  $this->breadcrumb_settings = array(
33
  'separator' => ' &gt; ',
34
  'include_home' => 1,
44
  }
45
  }
46
 
47
+ /**
48
+ * Breadcrumb Trail Filling Function
49
+ *
50
+ * This functions fills the breadcrumb trail.
51
+ */
52
+ public function checkPosts()
53
  {
54
  global $wp_query;
55
  //For the front page, as it may also validate as a page, do it first
56
  if (is_front_page()) {
57
  global $current_site;
58
  $site_name = get_option('blogname');
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,
68
+ array(
69
+ 'main-home'
70
+ ),
71
+ get_home_url($current_site->blog_id)
72
+ );
73
  }
74
+ } elseif (is_singular()) {
 
75
  if (is_attachment()) {
76
  // attachments
77
+ $this->attachment();
78
  } else {
79
  // other post types
80
+ $this->post(get_post());
81
  }
82
+ } elseif (is_search()) {
83
+ $this->search();
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)) {
91
  }
92
  //For date based archives
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();
100
  }
101
+ } elseif (is_404()) {
102
+ $this->addBreadcrumb('404', WPMSEO_TEMPLATE_BREADCRUMB, array('404', 'current-item'));
103
  } else {
104
  $type = $wp_query->get_queried_object();
105
  if (isset($type->taxonomy)) {
106
+ $this->archiveByTerm();
107
  }
108
  }
109
  // home
110
  if (!is_front_page()) {
111
+ if (!empty($this->breadcrumb_settings['include_home'])) {
112
+ $this->home();
113
  }
114
  }
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)
123
  {
124
  // order breadcrumb
125
  if ($reverse) {
143
  }
144
  }
145
 
146
+ $html .= $this->generateBreadcrumb($breadcrumb, $position);
147
  $position++;
148
  }
149
 
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'])),
176
  $params['%type%'] = implode(' ', $params['%type%']);
177
  }
178
 
179
+ if (empty($this->breadcrumb_settings['clickable'])) {
180
  return str_replace(array_keys($params), $params, $this->template_no_anchor);
181
+ } else {
182
  if ($breadcrumb['click']) {
183
  //Return template
184
  return str_replace(array_keys($params), $params, $breadcrumb['template']);
187
  return str_replace(array_keys($params), $params, $this->template_no_anchor);
188
  }
189
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
191
 
192
  /**
193
+ * A Breadcrumb Trail Filling Function
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
  {
201
  if (!($post instanceof WP_Post)) {
202
  return;
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;
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 {
229
+ $this->postHierarchy($post->ID);
230
  }
231
  }
232
 
233
+ /**
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,
251
+ array('post', 'post-' . $parent->post_type),
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
  }
260
  return $parent;
261
  }
262
 
263
  /**
264
+ * A Breadcrumb Trail Filling Function
265
+ *
266
+ * This functions fills a breadcrumb for an attachment page.
267
  */
268
+ public function attachment()
269
  {
270
  $post = get_post();
271
  // Add to breadcrumbs list
272
+ $this->addBreadcrumb(
273
+ get_the_title(),
274
+ WPMSEO_TEMPLATE_BREADCRUMB,
275
+ array('post', 'post-attachment', 'current-item'),
276
+ null,
277
+ $post->ID
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);
286
  }
287
  }
288
 
289
  /**
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
 
302
  /**
303
+ * A Breadcrumb Trail Filling Function
304
+ *
305
+ * This functions fills a breadcrumb for an author page.
306
  */
307
+ public function author()
308
  {
309
  if (get_query_var('author_name')) {
310
  $author = get_user_by('slug', get_query_var('author_name'));
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',
324
+ $author->ID
325
+ ),
326
+ $template,
327
+ array(
328
+ 'author',
329
+ 'current-item'
330
+ ),
331
+ null,
332
+ $author->ID
333
+ );
334
  }
335
  }
336
 
337
  /**
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
  {
344
+ $type = $this->getType();
345
  // Add to breadcrumbs list
346
+ $this->addBreadcrumb(
347
+ post_type_archive_title('', false),
348
+ WPMSEO_TEMPLATE_BREADCRUMB,
349
+ array(
350
+ 'archive',
351
+ 'post-' . $type . '-archive',
352
+ 'current-item'
353
+ )
354
+ );
355
  }
356
 
357
  /**
358
+ * A Breadcrumb Trail Filling Function
359
+ *
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')),
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
  }
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
  }
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
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
  }
441
  $this->breadcrumbs[] = $arrays;
442
  }
443
 
444
+ /**
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,
460
+ array(
461
+ 'archive',
462
+ 'taxonomy',
463
+ $term->taxonomy,
464
+ 'current-item'
465
+ ),
466
+ null,
467
+ $term->term_id
468
+ );
469
  //Get parents of current term
470
  if ($term->parent) {
471
+ $this->termParents($term->parent, $term->taxonomy);
472
  }
473
  }
474
 
475
+ /**
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)
484
  {
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,
494
+ array(
495
+ 'taxonomy',
496
+ $taxonomy
497
+ ),
498
+ $this->addPosttypeArg(
499
+ get_term_link($term),
500
+ null,
501
+ $taxonomy
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 = '',
521
+ $template = '',
522
+ array $type = array(),
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
  }
541
  }
542
 
543
  // check click or not
544
+ if (empty($this->breadcrumb_settings['clickable'])) {
545
  $click = false;
546
+ } else {
547
+ if ($url == null) {
548
  $click = false;
549
  } else {
550
  $click = true;
562
  );
563
  }
564
 
565
+ /**
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)) {
590
 
591
  if ($term instanceof WP_Term) {
592
  //Fill out the term hiearchy
593
+ $this->termParents($term->term_id, $taxonomy);
594
  }
 
 
595
  }
596
+ //else {//$this->post_terms($id, $taxonomy);
597
+ //}
598
  }
599
 
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
 
616
  // add post_type to url
623
 
624
  /**
625
  * get post type
626
+ * @param string $default
627
+ * @return string
628
  */
629
+ public function getType($default = 'post')
630
  {
631
  $type = get_query_var('post_type', $default);
632
  if ($type === '' || is_array($type)) {
641
  }
642
 
643
  /**
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'];
659
+ } else {
660
  $title = $site_name;
661
  }
662
+ $this->addBreadcrumb($title, $template, array('home'), get_home_url());
663
  if (!is_main_site()) {
664
  //Get the site name
665
  $site_name = get_site_option('site_name');
666
  // Add to breadcrumbs list
667
+ $this->addBreadcrumb($site_name, $template, array('main-home'), get_home_url($current_site->blog_id));
668
  }
669
  }
670
+ }
inc/class.image-helper.php CHANGED
@@ -1,14 +1,26 @@
1
  <?php
2
- /*
 
 
 
 
3
  * This class implements some function for image optimize
4
- *
5
  */
 
 
6
 
7
- class ImageHelper {
8
-
 
 
9
  public static $src = '';
10
 
11
- public function __construct(array $params = array()) {
 
 
 
 
 
12
  $c = new ReflectionClass(__CLASS__);
13
  $statics = $c->getStaticProperties();
14
 
@@ -20,11 +32,14 @@ class ImageHelper {
20
  }
21
  }
22
  }
23
-
24
- /*
25
  * get image info
 
 
26
  */
27
- public static function IGetPart($src = '') {
 
28
  if ($src == '') {
29
  $src = self::$src;
30
  }
@@ -62,10 +77,13 @@ class ImageHelper {
62
  return $ipart;
63
  }
64
 
65
- /*
66
  * get Image width and height
 
 
67
  */
68
- public static function IGetDimension($src) {
 
69
  if (preg_match_all('/(\d+)x(\d+)/i', $src, $match)) {
70
  return count($match) > 0 ? end($match[0]) : '';
71
  }
@@ -73,18 +91,14 @@ class ImageHelper {
73
  return '';
74
  }
75
 
76
- public static function get($part, $src = '') {
77
- if ($src == '') {
78
- $src = self::$src;
79
- }
80
- $ipart = self::getIPart($src);
81
- return isset($ipart->{$part}) ? $ipart->{$part} : '';
82
- }
83
-
84
- /*
85
  * Replace image src
 
 
 
86
  */
87
- public static function IReplace($newName, $src = '') {
 
88
  if ($src == '') {
89
  $src = self::$src;
90
  }
@@ -97,7 +111,13 @@ class ImageHelper {
97
  return $src;
98
  }
99
 
100
- public static function IHasClone($img, $obj) {
 
 
 
 
 
 
101
  if (!is_array($img)) {
102
  $img = array($img);
103
  }
@@ -122,11 +142,15 @@ class ImageHelper {
122
 
123
  return false;
124
  }
125
-
126
- /*
127
  * get image info when scan post
 
 
 
128
  */
129
- public static function IScan($imgs = array(), $content) {
 
130
  $ifound = array();
131
  $doc = new DOMDocument();
132
  libxml_use_internal_errors(true);
@@ -162,40 +186,47 @@ class ImageHelper {
162
 
163
  return $ifound;
164
  }
165
-
166
- /*
167
  * get posts list
 
 
 
168
  */
169
- public static function _get_post_list($iID, $opt_type) {
170
- global $wpdb;
171
  //Get image info from wp_postmeta with key equals to _metaseo_img_meta_not_good
172
  $meta_key = '_metaseo_' . strtolower(trim($opt_type));
173
  $posts = get_post_meta($iID, $meta_key, true);
174
 
175
  if (is_array($posts) && !empty($posts)) {
176
- // $posts = metaseo_utf8($posts, 'decode');
177
  return $posts;
178
  }
179
 
180
  return array();
181
  }
182
 
183
- /*
184
  * get image not good
 
 
 
 
185
  */
186
- public static function IPrepare($imgs, $posts, $meta_checkout = array(), $forceScan = false) {
 
187
  $iNotGood = array();
188
  $iNotGoodTotal = array();
189
- $metaNotGood = array();
190
- $metaNotGoodTotal = array();
191
  $upload_dir = wp_upload_dir();
192
-
193
  // scan img tag for each post content
194
  foreach ($posts as $post) {
195
  if (empty($post->post_content)) {
196
  continue;
197
  }
198
- $ifound = self::IScan($imgs, $post->post_content);
199
  if (count($ifound) < 1) {
200
  continue;
201
  }
@@ -203,7 +234,7 @@ class ImageHelper {
203
  foreach ($ifound as $order => $img) {
204
  $iID = $img['id'];
205
  //Get image that its size is not good
206
- $imgpath = str_replace(site_url(), ABSPATH , $img['src']);
207
  if (!list($width_origin, $height_origin) = @getimagesize($imgpath)) {
208
  continue;
209
  }
@@ -225,13 +256,11 @@ class ImageHelper {
225
  $ibpart = ImageHelper::IGetPart($img_before);
226
 
227
  $img_after = $ibpart->base_path
228
- . (!empty($ibpart->name_prefix) ? $ibpart->name_prefix : $ibpart->name)
229
- . '-' . $width . 'x' . $height
230
- . $ibpart->name_suffix
231
- . $ibpart->ext;
232
 
233
- $destination = $upload_dir['basedir'] . '/' . $img_after;
234
-
235
  // create new image url and dir
236
  $srcs = array(
237
  'img_before_dir' => $upload_dir['basedir'] . $img_before,
@@ -239,7 +268,7 @@ class ImageHelper {
239
  'img_after_dir' => $upload_dir['basedir'] . $img_after,
240
  'img_after_url' => $upload_dir['baseurl'] . $img_after
241
  );
242
-
243
  // get size img
244
  $size = (filesize($srcs['img_before_dir']) / 1024);
245
  if ($size > 1024) {
@@ -276,7 +305,7 @@ class ImageHelper {
276
  if (!isset($iNotGoodTotal[$iID])) {
277
  $iNotGoodTotal[$iID] = 0;
278
  }
279
- $iNotGoodTotal[$iID] ++;
280
  } else {
281
  if (!isset($iNotGood[$iID])) {
282
  $iNotGood[$iID] = array();
@@ -285,7 +314,7 @@ class ImageHelper {
285
  $iNotGoodTotal[$iID] = 0;
286
  }
287
  }
288
-
289
  //Get image that its meta/metas is/are not good
290
  if (count($meta_checkout) > 0) {
291
  foreach ($meta_checkout as $key => $meta) {
@@ -299,7 +328,7 @@ class ImageHelper {
299
  if (!isset($imNotGoodTotal[$iID][$meta])) {
300
  $imNotGoodTotal[$iID][$meta] = 0;
301
  }
302
- $imNotGoodTotal[$iID][$meta] ++;
303
  }
304
  }
305
  }
@@ -333,32 +362,40 @@ class ImageHelper {
333
 
334
  unset($posts, $imgs);
335
 
336
- $ret = array('iNotGood' => $iNotGood, 'iNotGoodTotal' => $iNotGoodTotal, 'imNotGood' => $imNotGood, 'imNotGoodTotal' => $imNotGoodTotal);
 
 
 
 
 
337
 
338
  return $ret;
339
  }
340
 
341
- /*
342
  * Scan image that has not good size or not good meta(s), then update info to postmeta table
343
- * @return: array of message that will be responsed to ajax call
 
 
 
344
  */
345
-
346
- public static function IScanPosts($imgs, $meta_checking = false, $forceScan = false, $delete = false, $postID = 0) {
347
  global $wpdb;
348
  $imgs_1 = array_slice($imgs, 0, 1);
349
- $idPost = array_shift($imgs_1);
350
-
351
  // get list sizes image
352
  $metadats = get_post_meta($idPost, '_wp_attachment_metadata', true);
353
  $sizes = $metadats['sizes'];
354
-
355
  // get list url image and image thumbnail
356
  $list_thum_url = array();
357
  $imageUrl = wp_get_attachment_url($idPost);
358
  $list_thum_url[] = $imageUrl;
359
- if(!empty($sizes)){
360
- foreach ($sizes as $key => $size){
361
- $thum_url = wp_get_attachment_image_src($idPost,$key);
362
  $list_thum_url[] = $thum_url[0];
363
  }
364
  }
@@ -366,26 +403,25 @@ class ImageHelper {
366
  $msg = array();
367
  $meta_keys = array('alt', 'title');
368
  $_imgs = array_flip($imgs);
369
- $post_types = MetaSeo_Content_List_Table::get_post_types();
370
-
371
  // sql where
372
  $w = '';
373
  $w .= '(';
374
  $i = 0;
375
- foreach ($list_thum_url as $url){
376
- $url = str_replace(array('https','http'),array('',''),$url);
377
  $i++;
378
- if($i == count($list_thum_url)){
379
  $w .= ' post_content LIKE "%' . $url . '%"';
380
- }else{
381
  $w .= ' post_content LIKE "%' . $url . '%" OR';
382
  }
383
-
384
  }
385
-
386
  $w .= ')';
387
  $where = array();
388
- if($delete){
389
  $where[] = "ID != $postID";
390
  }
391
  $where[] = "post_type IN ($post_types)";
@@ -393,10 +429,10 @@ class ImageHelper {
393
  $where[] = $w;
394
  $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
395
  FROM $wpdb->posts
396
- WHERE ".implode(' AND ', $where)." ORDER BY ID";
397
  // query post
398
  $posts = $wpdb->get_results($query);
399
- $results = self::IPrepare($imgs, $posts, $meta_keys, $forceScan);
400
  //Update some value into fields in wp_postmeta
401
  if (count($results['iNotGood']) > 0) {
402
  foreach ($results['iNotGood'] as $iID => $post_group) {
@@ -408,10 +444,15 @@ class ImageHelper {
408
  $im = ' image ';
409
  }
410
 
411
- $msg[$iID]['iNotGood']['msg'] = __($results['iNotGoodTotal'][$iID] . $im . 'with wrong size', 'wp-meta-seo');
 
412
  $msg[$iID]['iNotGood']['warning'] = true;
413
 
414
- $msg[$iID]['iNotGood']['button'] = '<a href="javascript:void(0);" class=" img-resize wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '" data-post-id="' . $iID . '" data-opt-key="resize_image" onclick="showPostsList(this)">' . __('Resize image', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
 
 
 
 
415
 
416
  update_post_meta($iID, '_metaseo_resize_image_counter', $results['iNotGoodTotal'][$iID]);
417
  update_post_meta($iID, '_metaseo_resize_image', $post_group);
@@ -424,7 +465,7 @@ class ImageHelper {
424
  }
425
  }
426
  }
427
-
428
  // create list image wrong
429
  if (count($results['imNotGood']) > 0) {
430
  foreach ($results['imNotGood'] as $iID => $post_group) {
@@ -436,14 +477,21 @@ class ImageHelper {
436
  }
437
 
438
  if ($results['imNotGoodTotal'][$iID][$mkey] > 1) {
439
- $msg[$iID]['imNotGood']['msg'][$mkey] = __($results['imNotGoodTotal'][$iID][$mkey] . ' ' . $mkey . $text . 's are missing', 'wp-meta-seo');
 
440
  } elseif ($results['imNotGoodTotal'][$iID][$mkey] == 1) {
441
- $msg[$iID]['imNotGood']['msg'][$mkey] = __($results['imNotGoodTotal'][$iID][$mkey] . ' ' . $mkey . $text . ' is missing', 'wp-meta-seo');
 
442
  }
443
  }
444
 
445
  $msg[$iID]['imNotGood']['warning'] = true;
446
- $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);" class=" fix-metas wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '" data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)" alt="'.__('This image has been detected in your content, edit information here…','wp-meta-seo').'">' . __('Edit meta in content', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
 
 
 
 
 
447
 
448
 
449
  update_post_meta($iID, '_metaseo_fix_metas_counter', count($post_group));
@@ -452,7 +500,12 @@ class ImageHelper {
452
 
453
  if ($results['imNotGoodTotal'][$iID]['alt'] == 0 && $results['imNotGoodTotal'][$iID]['title'] == 0) {
454
  if ($results['iNotGoodTotal'][$iID] != -1) {
455
- $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);" class=" fix-metas wpmsbtn wpmsbtn_small wpmsbtn_secondary" data-img-name="' . $_imgs[$iID] . '" data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)" alt="'.__('This image has been detected in your content, edit information here…','wp-meta-seo').'">' . __('Edit meta', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
 
 
 
 
 
456
  } else {
457
  $msg[$iID]['imNotGood']['button'] = '';
458
  }
@@ -467,10 +520,15 @@ class ImageHelper {
467
  return $msg;
468
  }
469
 
470
- /*
471
  * Ajax optimize image and update content
 
 
 
 
472
  */
473
- public static function _optimizeImages($post_id, $img_post_id, $img_exclude) {
 
474
  global $wpdb;
475
  $ret = array('success' => false, 'msg' => '');
476
  $query = "SELECT `post_content` FROM $wpdb->posts WHERE `ID`=" . $post_id;
@@ -484,7 +542,6 @@ class ImageHelper {
484
  $imgs_to_resize = get_post_meta($img_post_id, '_metaseo_resize_image', true);
485
 
486
  if (preg_match_all('/<img [^<>]+ \/>/i', $post_content, $matches)) {
487
- $img_tags = $matches[0];
488
  $replacement = array();
489
  foreach ($matches[0] as $order => $tag) {
490
  $replacement[$order] = $tag;
@@ -496,8 +553,9 @@ class ImageHelper {
496
  foreach ($imgs_to_resize[$post_id]['img_after_optm'] as $key => $img) {
497
  if (!in_array($order, $img_exclude)) {
498
  if (stripos($tag, $img['src_origin']) !== false &&
499
- (('width' == $dimension[1] && $dimension[2] == $img['width']) || ('height' == $dimension[1] && $dimension[2] == $img['height']))) {
500
-
 
501
  $replacement[$order] = str_replace($img['src_origin'], $img['src'], $tag);
502
  }
503
  }
@@ -528,29 +586,43 @@ class ImageHelper {
528
 
529
  /**
530
  * create new size for image
 
 
 
 
 
531
  */
532
- public static function IResize($src, $width, $height, $destination) {
533
- $imgpath = str_replace(site_url(), ABSPATH , $src);
534
- if (!list($w_origin, $h_origin) = getimagesize($imgpath))
 
535
  return "Unsupported picture type!";
 
536
 
537
  if (is_readable($destination)) {
538
  return true;
539
  }
540
 
541
  $type = strtolower(substr(strrchr($imgpath, "."), 1));
542
- if ($type === 'jpeg')
543
  $type = 'jpg';
 
 
544
  switch ($type) {
545
- case 'bmp': $img = imagecreatefromwbmp($imgpath);
 
546
  break;
547
- case 'gif': $img = imagecreatefromgif($imgpath);
 
548
  break;
549
- case 'jpg': $img = imagecreatefromjpeg($imgpath);
 
550
  break;
551
- case 'png': $img = imagecreatefrompng($imgpath);
 
552
  break;
553
- default : return "Unsupported picture type!";
 
554
  }
555
 
556
  $new = imagecreatetruecolor($width, $height);
@@ -566,17 +638,20 @@ class ImageHelper {
566
 
567
  //Output
568
  switch ($type) {
569
- case 'bmp': imagewbmp($new, $destination);
 
570
  break;
571
- case 'gif': imagegif($new, $destination);
 
572
  break;
573
- case 'jpg': imagejpeg($new, $destination);
 
574
  break;
575
- case 'png': imagepng($new, $destination);
 
576
  break;
577
  }
578
 
579
  return true;
580
  }
581
-
582
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+
5
+ /**
6
+ * Class ImageHelper
7
  * This class implements some function for image optimize
 
8
  */
9
+ class ImageHelper
10
+ {
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
 
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
  }
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)
86
+ {
87
  if (preg_match_all('/(\d+)x(\d+)/i', $src, $match)) {
88
  return count($match) > 0 ? end($match[0]) : '';
89
  }
91
  return '';
92
  }
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
  }
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
+ {
121
  if (!is_array($img)) {
122
  $img = array($img);
123
  }
142
 
143
  return false;
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);
186
 
187
  return $ifound;
188
  }
189
+
190
+ /**
191
  * get posts list
192
+ * @param int $iID ID of post
193
+ * @param string $opt_type meta type
194
+ * @return array|mixed
195
  */
196
+ public static function getPostList($iID, $opt_type)
197
+ {
198
  //Get image info from wp_postmeta with key equals to _metaseo_img_meta_not_good
199
  $meta_key = '_metaseo_' . strtolower(trim($opt_type));
200
  $posts = get_post_meta($iID, $meta_key, true);
201
 
202
  if (is_array($posts) && !empty($posts)) {
 
203
  return $posts;
204
  }
205
 
206
  return array();
207
  }
208
 
209
+ /**
210
  * get image not good
211
+ * @param $imgs
212
+ * @param $posts
213
+ * @param array $meta_checkout
214
+ * @return array
215
  */
216
+ public static function IPrepare($imgs, $posts, $meta_checkout = array())
217
+ {
218
  $iNotGood = array();
219
  $iNotGoodTotal = array();
220
+ $imNotGoodTotal = array();
221
+ $imNotGood = array();
222
  $upload_dir = wp_upload_dir();
223
+
224
  // scan img tag for each post content
225
  foreach ($posts as $post) {
226
  if (empty($post->post_content)) {
227
  continue;
228
  }
229
+ $ifound = self::IScan($post->post_content, $imgs);
230
  if (count($ifound) < 1) {
231
  continue;
232
  }
234
  foreach ($ifound as $order => $img) {
235
  $iID = $img['id'];
236
  //Get image that its size is not good
237
+ $imgpath = str_replace(site_url(), ABSPATH, $img['src']);
238
  if (!list($width_origin, $height_origin) = @getimagesize($imgpath)) {
239
  continue;
240
  }
256
  $ibpart = ImageHelper::IGetPart($img_before);
257
 
258
  $img_after = $ibpart->base_path
259
+ . (!empty($ibpart->name_prefix) ? $ibpart->name_prefix : $ibpart->name)
260
+ . '-' . $width . 'x' . $height
261
+ . $ibpart->name_suffix
262
+ . $ibpart->ext;
263
 
 
 
264
  // create new image url and dir
265
  $srcs = array(
266
  'img_before_dir' => $upload_dir['basedir'] . $img_before,
268
  'img_after_dir' => $upload_dir['basedir'] . $img_after,
269
  'img_after_url' => $upload_dir['baseurl'] . $img_after
270
  );
271
+
272
  // get size img
273
  $size = (filesize($srcs['img_before_dir']) / 1024);
274
  if ($size > 1024) {
305
  if (!isset($iNotGoodTotal[$iID])) {
306
  $iNotGoodTotal[$iID] = 0;
307
  }
308
+ $iNotGoodTotal[$iID]++;
309
  } else {
310
  if (!isset($iNotGood[$iID])) {
311
  $iNotGood[$iID] = array();
314
  $iNotGoodTotal[$iID] = 0;
315
  }
316
  }
317
+
318
  //Get image that its meta/metas is/are not good
319
  if (count($meta_checkout) > 0) {
320
  foreach ($meta_checkout as $key => $meta) {
328
  if (!isset($imNotGoodTotal[$iID][$meta])) {
329
  $imNotGoodTotal[$iID][$meta] = 0;
330
  }
331
+ $imNotGoodTotal[$iID][$meta]++;
332
  }
333
  }
334
  }
362
 
363
  unset($posts, $imgs);
364
 
365
+ $ret = array(
366
+ 'iNotGood' => $iNotGood,
367
+ 'iNotGoodTotal' => $iNotGoodTotal,
368
+ 'imNotGood' => $imNotGood,
369
+ 'imNotGoodTotal' => $imNotGoodTotal
370
+ );
371
 
372
  return $ret;
373
  }
374
 
375
+ /**
376
  * Scan image that has not good size or not good meta(s), then update info to postmeta table
377
+ * @param $imgs
378
+ * @param bool $delete
379
+ * @param int $postID ID of post
380
+ * @return array
381
  */
382
+ public static function IScanPosts($imgs, $delete = false, $postID = 0)
383
+ {
384
  global $wpdb;
385
  $imgs_1 = array_slice($imgs, 0, 1);
386
+ $idPost = array_shift($imgs_1);
387
+
388
  // get list sizes image
389
  $metadats = get_post_meta($idPost, '_wp_attachment_metadata', true);
390
  $sizes = $metadats['sizes'];
391
+
392
  // get list url image and image thumbnail
393
  $list_thum_url = array();
394
  $imageUrl = wp_get_attachment_url($idPost);
395
  $list_thum_url[] = $imageUrl;
396
+ if (!empty($sizes)) {
397
+ foreach ($sizes as $key => $size) {
398
+ $thum_url = wp_get_attachment_image_src($idPost, $key);
399
  $list_thum_url[] = $thum_url[0];
400
  }
401
  }
403
  $msg = array();
404
  $meta_keys = array('alt', 'title');
405
  $_imgs = array_flip($imgs);
406
+ $post_types = MetaSeoContentListTable::getPostTypes();
407
+
408
  // sql where
409
  $w = '';
410
  $w .= '(';
411
  $i = 0;
412
+ foreach ($list_thum_url as $url) {
413
+ $url = str_replace(array('https', 'http'), array('', ''), $url);
414
  $i++;
415
+ if ($i == count($list_thum_url)) {
416
  $w .= ' post_content LIKE "%' . $url . '%"';
417
+ } else {
418
  $w .= ' post_content LIKE "%' . $url . '%" OR';
419
  }
 
420
  }
421
+
422
  $w .= ')';
423
  $where = array();
424
+ if ($delete) {
425
  $where[] = "ID != $postID";
426
  }
427
  $where[] = "post_type IN ($post_types)";
429
  $where[] = $w;
430
  $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
431
  FROM $wpdb->posts
432
+ WHERE " . implode(' AND ', $where) . " ORDER BY ID";
433
  // query post
434
  $posts = $wpdb->get_results($query);
435
+ $results = self::IPrepare($imgs, $posts, $meta_keys);
436
  //Update some value into fields in wp_postmeta
437
  if (count($results['iNotGood']) > 0) {
438
  foreach ($results['iNotGood'] as $iID => $post_group) {
444
  $im = ' image ';
445
  }
446
 
447
+ $msg[$iID]['iNotGood']['msg']
448
+ = __($results['iNotGoodTotal'][$iID] . $im . 'with wrong size', 'wp-meta-seo');
449
  $msg[$iID]['iNotGood']['warning'] = true;
450
 
451
+ $msg[$iID]['iNotGood']['button'] = '<a href="javascript:void(0);"
452
+ class=" img-resize wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '"
453
+ data-post-id="' . $iID . '" data-opt-key="resize_image"
454
+ onclick="showPostsList(this)">
455
+ ' . __('Resize image', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
456
 
457
  update_post_meta($iID, '_metaseo_resize_image_counter', $results['iNotGoodTotal'][$iID]);
458
  update_post_meta($iID, '_metaseo_resize_image', $post_group);
465
  }
466
  }
467
  }
468
+
469
  // create list image wrong
470
  if (count($results['imNotGood']) > 0) {
471
  foreach ($results['imNotGood'] as $iID => $post_group) {
477
  }
478
 
479
  if ($results['imNotGoodTotal'][$iID][$mkey] > 1) {
480
+ $i = $results['imNotGoodTotal'][$iID][$mkey] . ' ' . $mkey . $text;
481
+ $msg[$iID]['imNotGood']['msg'][$mkey] = $i . __('s are missing', 'wp-meta-seo');
482
  } elseif ($results['imNotGoodTotal'][$iID][$mkey] == 1) {
483
+ $i = $results['imNotGoodTotal'][$iID][$mkey] . ' ' . $mkey . $text;
484
+ $msg[$iID]['imNotGood']['msg'][$mkey] = $i . __(' is missing', 'wp-meta-seo');
485
  }
486
  }
487
 
488
  $msg[$iID]['imNotGood']['warning'] = true;
489
+ $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
490
+ class=" fix-metas wpmsbtn wpmsbtn_small" data-img-name="' . $_imgs[$iID] . '"
491
+ data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
492
+ alt="' . __('This image has been detected
493
+ in your content, edit information here…', 'wp-meta-seo') . '">
494
+ ' . __('Edit meta in content', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
495
 
496
 
497
  update_post_meta($iID, '_metaseo_fix_metas_counter', count($post_group));
500
 
501
  if ($results['imNotGoodTotal'][$iID]['alt'] == 0 && $results['imNotGoodTotal'][$iID]['title'] == 0) {
502
  if ($results['iNotGoodTotal'][$iID] != -1) {
503
+ $msg[$iID]['imNotGood']['button'] = '<a href="javascript:void(0);"
504
+ class=" fix-metas wpmsbtn wpmsbtn_small wpmsbtn_secondary" data-img-name="' . $_imgs[$iID] . '"
505
+ data-post-id="' . $iID . '" data-opt-key="fix_metas" onclick="showPostsList(this)"
506
+ alt="' . __('This image has been detected in your content,
507
+ edit information here…', 'wp-meta-seo') . '">
508
+ ' . __('Edit meta', 'wp-meta-seo') . '<span class="spinner-light"></span></a>';
509
  } else {
510
  $msg[$iID]['imNotGood']['button'] = '';
511
  }
520
  return $msg;
521
  }
522
 
523
+ /**
524
  * Ajax optimize image and update content
525
+ * @param $post_id
526
+ * @param $img_post_id
527
+ * @param $img_exclude
528
+ * @return array
529
  */
530
+ public static function optimizeImages($post_id, $img_post_id, $img_exclude)
531
+ {
532
  global $wpdb;
533
  $ret = array('success' => false, 'msg' => '');
534
  $query = "SELECT `post_content` FROM $wpdb->posts WHERE `ID`=" . $post_id;
542
  $imgs_to_resize = get_post_meta($img_post_id, '_metaseo_resize_image', true);
543
 
544
  if (preg_match_all('/<img [^<>]+ \/>/i', $post_content, $matches)) {
 
545
  $replacement = array();
546
  foreach ($matches[0] as $order => $tag) {
547
  $replacement[$order] = $tag;
553
  foreach ($imgs_to_resize[$post_id]['img_after_optm'] as $key => $img) {
554
  if (!in_array($order, $img_exclude)) {
555
  if (stripos($tag, $img['src_origin']) !== false &&
556
+ (('width' == $dimension[1] && $dimension[2] == $img['width'])
557
+ || ('height' == $dimension[1] && $dimension[2] == $img['height']))
558
+ ) {
559
  $replacement[$order] = str_replace($img['src_origin'], $img['src'], $tag);
560
  }
561
  }
586
 
587
  /**
588
  * create new size for image
589
+ * @param string $src source url of image
590
+ * @param float $width width of image
591
+ * @param float $height height of image
592
+ * @param $destination
593
+ * @return bool|string
594
  */
595
+ public static function IResize($src, $width, $height, $destination)
596
+ {
597
+ $imgpath = str_replace(site_url(), ABSPATH, $src);
598
+ if (!list($w_origin, $h_origin) = getimagesize($imgpath)) {
599
  return "Unsupported picture type!";
600
+ }
601
 
602
  if (is_readable($destination)) {
603
  return true;
604
  }
605
 
606
  $type = strtolower(substr(strrchr($imgpath, "."), 1));
607
+ if ($type === 'jpeg') {
608
  $type = 'jpg';
609
+ }
610
+
611
  switch ($type) {
612
+ case 'bmp':
613
+ $img = imagecreatefromwbmp($imgpath);
614
  break;
615
+ case 'gif':
616
+ $img = imagecreatefromgif($imgpath);
617
  break;
618
+ case 'jpg':
619
+ $img = imagecreatefromjpeg($imgpath);
620
  break;
621
+ case 'png':
622
+ $img = imagecreatefrompng($imgpath);
623
  break;
624
+ default:
625
+ return "Unsupported picture type!";
626
  }
627
 
628
  $new = imagecreatetruecolor($width, $height);
638
 
639
  //Output
640
  switch ($type) {
641
+ case 'bmp':
642
+ imagewbmp($new, $destination);
643
  break;
644
+ case 'gif':
645
+ imagegif($new, $destination);
646
  break;
647
+ case 'jpg':
648
+ imagejpeg($new, $destination);
649
  break;
650
+ case 'png':
651
+ imagepng($new, $destination);
652
  break;
653
  }
654
 
655
  return true;
656
  }
 
657
  }
inc/class.metaseo-admin.php CHANGED
@@ -1,24 +1,130 @@
1
  <?php
 
 
 
2
  /**
 
3
  * Class that holds most of the admin functionality for Meta SEO.
4
  */
 
 
5
 
6
- class MetaSeo_Admin {
7
-
8
- private $options;
 
9
  private $pagenow;
 
 
 
 
10
  public static $desc_length = 156;
 
 
 
 
11
  public static $title_length = 69;
 
 
 
 
12
  public $client;
 
 
 
 
13
  public $access = array(WPMS_CLIENTID, WPMS_CLIENTSECRET);
 
 
 
14
  public $error_timeout;
15
- private $wpmsga;
 
 
 
16
  public $ga_tracking;
17
- public $ga_tracking_disconnect;
 
 
 
 
 
 
 
 
18
  public $google_alanytics;
19
-
20
- function __construct() {
21
- $this->set_error_timeout();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  $this->settings = array(
23
  "metaseo_title_home" => "",
24
  "metaseo_desc_home" => "",
@@ -42,11 +148,16 @@ class MetaSeo_Admin {
42
  $this->settings = array_merge($this->settings, $settings);
43
  }
44
 
45
- $this->pagenow = $GLOBALS['pagenow'];
46
  if ((isset($this->settings['metaseo_showtmetablock']) && $this->settings['metaseo_showtmetablock'] == 1)) {
47
- $this->load_meta_boxes();
48
  }
49
-
 
 
 
 
 
 
50
  $this->ga_tracking = array(
51
  'wpmsga_dash_tracking' => 1,
52
  'wpmsga_dash_tracking_type' => 'universal',
@@ -72,92 +183,92 @@ class MetaSeo_Admin {
72
  'wpmsga_cookiename' => '',
73
  'wpmsga_cookieexpires' => '',
74
  'wpmsga_track_exclude' => array(),
75
- 'wpmsga_cookiename' => '',
76
  'wpmsga_code_tracking' => ''
77
  );
 
78
 
79
- if (!get_option('_wpms_dash_last_update', false)) {
80
- update_option('_wpms_dash_last_update',time());
81
- }
82
-
83
- add_action('admin_menu', array($this, 'register_menu_page'));
84
-
85
- /** Load admin js * */
86
- add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts'));
87
- $this->ajaxHandle();
88
-
89
- //register ajax update meta handler...
90
- add_action('wp_ajax_updateContentMeta', array($this, 'updateContentMeta_callback'));
91
- add_action('admin_init', array($this, 'metaseo_field_settings'));
92
-
93
- add_action('admin_init', array($this, 'metaseo_create_db'));
94
-
95
- add_action('init', array($this, 'wpms_load_langguage'));
96
-
97
- if (!get_option('wpms_set_ignore', false)) {
98
- add_option('wpms_set_ignore', 1, '', 'yes');
99
- }
100
-
101
- add_action('wp_ajax_wpms_set_ignore', array($this, 'wpms_set_ignore'));
102
- if ('0' == get_option('blog_public')) {
103
- add_action('admin_notices', array($this, 'wpms_public_warning'));
104
- }
105
- add_action('wp_enqueue_editor', array($this, 'wpms_link_title_field'), 20);
106
- add_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'), 10, 3);
107
- add_action('delete_post', array('MetaSeo_Broken_Link_Table', 'wpms_delete_post'));
108
- add_action('edit_comment', array('MetaSeo_Broken_Link_Table', 'wpms_update_comment'));
109
- add_action('deleted_comment', array('MetaSeo_Broken_Link_Table', 'wpms_deleted_comment'));
110
-
111
- add_action( 'wp_head', array( 'MetaSeo_Google_Analytics', 'tracking_code' ), 99 );
112
- add_action('admin_footer', array($this, 'add_editor_footer'));
113
- add_action('wp_dashboard_setup', array($this,'wpms_add_dashboard_widgets') );
114
- add_action( 'category_add_form_fields', array($this,'wpms_category_add_new_meta_field'), 10, 2 );
115
- add_action ('edit_category_form_fields', array($this,'wpms_category_fields'));
116
- add_action( 'edited_category', array($this,'wpms_save_category_custom_meta'), 10, 2 );
117
- add_action( 'create_category', array($this,'wpms_save_category_custom_meta'), 10, 2 );
118
- add_action('post_updated', array('MetaSeo_Image_List_Table', 'wpms_update_post'), 10, 3);
119
- add_action('delete_post', array('MetaSeo_Image_List_Table', 'wpmf_delete_attachment'));
120
-
121
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
122
- add_action( 'product_cat_add_form_fields', array( $this, 'wpms_category_add_new_meta_field' ) );
123
- add_action( 'product_cat_edit_form_fields', array( $this, 'wpms_category_fields' ), 10 );
124
- add_action( 'created_term', array( $this, 'wpms_save_category_custom_meta' ), 10, 3 );
125
- add_action( 'edit_term', array( $this, 'wpms_save_category_custom_meta' ), 10, 3 );
126
- }
127
  }
128
 
129
- public function wpms_category_add_new_meta_field() {
130
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
131
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  wp_enqueue_style('wpms-category-field');
133
  wp_enqueue_script('wpms-category-field');
134
  // this will add the custom meta field to the add new term page
135
  ?>
136
  <div class="form-field">
137
- <label class="wpms_custom_cat_field" alt="<?php _e('This is the title of your content that may be displayed in search engine results (meta title). By default it’s the content title (page title, post title…). 69 characters max allowed.','wp-meta-seo') ?>"><?php _e('Search engine title','wp-meta-seo'); ?></label>
138
- <textarea name="wpms_category_metatitle" class="wpms_category_metatitle"></textarea><br />
139
- <div class="cat-title-len"><?php echo WPMS_CAT_METATITLE_LENGTH; ?></div>
 
 
 
 
 
 
 
 
140
  </div>
141
 
142
  <?php
143
  $settings = get_option('_metaseo_settings');
144
  if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) :
145
- ?>
146
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
147
- <label class="wpms_custom_cat_field" alt="<?php _e('This is the keywords of your content that may be displayed in search engine results (meta keywords).','wp-meta-seo') ?>"><?php _e('Search engine keywords','wp-meta-seo'); ?></label>
148
- <textarea name="wpms_category_metakeywords" class="wpms_category_metakeywords"></textarea><br />
149
- <div class="cat-keywords-len"><?php echo WPMS_CAT_METAKEYWORDS_LENGTH; ?></div>
 
 
 
 
 
 
150
  </div>
151
  <?php endif; ?>
152
  <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;">
153
- <label for="extra1" class="wpms_custom_cat_field" alt="<?php _e('This is the title of your content that may be displayed in search engine results (meta title). By default it’s the content title (page title, post title…). 69 characters max allowed.','wp-meta-seo') ?>"><?php _e('Search engine description','wp-meta-seo'); ?></label>
154
- <textarea name="wpms_category_metadesc" class="wpms_category_metadesc"></textarea><br />
155
- <div class="cat-desc-len"><?php echo WPMS_CAT_METADESC_LENGTH; ?></div>
 
 
 
 
 
 
 
156
  </div>
157
  <?php
158
  }
159
 
160
- public function wpms_save_category_custom_meta( $term_id )
 
 
 
 
161
  {
162
  if (isset($_POST['wpms_category_metatitle'])) {
163
  update_term_meta($term_id, 'wpms_category_metatitle', $_POST['wpms_category_metatitle']);
@@ -175,75 +286,182 @@ class MetaSeo_Admin {
175
  }
176
  }
177
 
178
- //add extra fields to category edit form callback function
179
- public function wpms_category_fields( $tag ) {
180
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
181
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  wp_enqueue_style('wpms-category-field');
183
  wp_enqueue_script('wpms-category-field');
184
  $t_id = $tag->term_id;
185
- $cat_metatitle = get_term_meta($t_id,'wpms_category_metatitle',true);
186
- $cat_metadesc = get_term_meta($t_id,'wpms_category_metadesc',true);
187
- $cat_metakeywords = get_term_meta($t_id,'wpms_category_metakeywords',true);
188
  ?>
189
  <tr class="form-field">
190
- <th scope="row" valign="top"><label class="wpms_custom_cat_field" alt="<?php _e('This is the title of your content that may be displayed in search engine results (meta title). By default it’s the content title (page title, post title…). 69 characters max allowed.','wp-meta-seo') ?>"><?php _e('Search engine title','wp-meta-seo'); ?></label></th>
 
 
 
 
 
 
191
  <td>
192
- <textarea name="wpms_category_metatitle" class="wpms_category_metatitle"><?php echo (!empty($cat_metatitle)) ? $cat_metatitle : ''; ?></textarea><br />
193
- <div class="cat-title-len"><?php echo $cat_metatitle ? WPMS_CAT_METATITLE_LENGTH-strlen($cat_metatitle) : WPMS_CAT_METATITLE_LENGTH; ?></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  </td>
195
  </tr>
196
 
197
  <?php
198
  $settings = get_option('_metaseo_settings');
199
  if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) :
200
- ?>
201
- <tr class="form-field">
202
- <th scope="row" valign="top"><label for="extra1" class="wpms_custom_cat_field" alt="<?php _e('This is the keywords of your content that may be displayed in search engine results (meta keywords).','wp-meta-seo') ?>"><?php _e('Search engine keywords','wp-meta-seo'); ?></label></th>
203
- <td>
204
- <textarea name="wpms_category_metakeywords" class="wpms_category_metakeywords"><?php echo (!empty($cat_metakeywords)) ? $cat_metakeywords : ''; ?></textarea><br />
205
- <div class="cat-keywords-len"><?php echo $cat_metakeywords ? WPMS_CAT_METAKEYWORDS_LENGTH-strlen($cat_metakeywords) : WPMS_CAT_METAKEYWORDS_LENGTH; ?></div>
206
- </td>
207
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  <?php endif; ?>
209
  <tr class="form-field">
210
- <th scope="row" valign="top"><label for="extra1" class="wpms_custom_cat_field" alt="<?php _e('This is the title of your content that may be displayed in search engine results (meta title). By default it’s the content title (page title, post title…). 69 characters max allowed.','wp-meta-seo') ?>"><?php _e('Search engine description','wp-meta-seo'); ?></label></th>
 
 
 
 
 
 
 
211
  <td>
212
- <textarea name="wpms_category_metadesc" class="wpms_category_metadesc"><?php echo (!empty($cat_metadesc)) ? $cat_metadesc : ''; ?></textarea><br />
213
- <div class="cat-desc-len"><?php echo $cat_metadesc ? WPMS_CAT_METADESC_LENGTH-strlen($cat_metadesc) : WPMS_CAT_METADESC_LENGTH; ?></div>
 
 
 
 
 
 
 
 
 
 
 
214
  </td>
215
  </tr>
216
  <?php
217
  }
218
 
219
- // Function that outputs the contents of the dashboard widget
220
- public function wpms_dashboard_widget( $post, $callback_args ) {
221
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
222
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  wp_enqueue_style('wpms-dashboard-widgets');
224
- wp_enqueue_script('wpms-dashboard-widgets', plugins_url('js/dashboard_widgets.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION);
 
 
 
 
 
225
  wp_enqueue_style('wpms-myqtip');
226
- $error_404 = MetaSeo_Dashboard::get_404_link();
227
- require_once ( WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard_widgets.php' );
228
  }
229
 
230
- // Function used in the action hook
231
- public function wpms_add_dashboard_widgets() {
 
 
 
232
 
233
- wp_add_dashboard_widget('wpms_dashboard_widget', __('WP Meta SEO: Quick SEO preview','wp-meta-seo'), array($this,'wpms_dashboard_widget'));
 
 
 
 
 
 
 
234
  }
235
 
236
- public function add_editor_footer() {
237
- if ( ! class_exists( '_WP_Editors', false ) ){
 
 
 
 
238
  require_once ABSPATH . "wp-includes/class-wp-editor.php";
239
  _WP_Editors::wp_link_dialog();
240
  }
241
  }
242
 
243
- /*
244
  * Create wpms_links table
245
  */
246
- function metaseo_create_db() {
 
247
  global $wpdb;
248
  $option_v = 'metaseo_db_version3.3.0';
249
  $db_installed = get_option($option_v, false);
@@ -272,24 +490,33 @@ class MetaSeo_Admin {
272
  dbDelta($sql);
273
 
274
 
275
- $sql = $wpdb->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
276
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",array($wpdb->prefix . 'wpms_links','follow',$wpdb->dbname));
 
 
 
277
  $row = $wpdb->get_results($sql);
278
 
279
  if (empty($row)) {
280
  $wpdb->query("ALTER TABLE " . $wpdb->prefix . "wpms_links ADD follow tinyint(1) DEFAULT 1");
281
  }
282
-
283
- $sql = $wpdb->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
284
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",array($wpdb->prefix . 'wpms_links','meta_title',$wpdb->dbname));
 
 
 
285
  $row = $wpdb->get_results($sql);
286
 
287
  if (empty($row)) {
288
  $wpdb->query("ALTER TABLE " . $wpdb->prefix . "wpms_links ADD meta_title varchar(250) DEFAULT ''");
289
  }
290
-
291
- $sql = $wpdb->prepare("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
292
- WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s",array($wpdb->prefix . 'wpms_links','internal',$wpdb->dbname));
 
 
 
293
  $row = $wpdb->get_results($sql);
294
 
295
  if (empty($row)) {
@@ -297,17 +524,26 @@ class MetaSeo_Admin {
297
  }
298
 
299
  // create page 404
300
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s", array("WP Meta SEO 404 Page", "metaseo_404_page", "page"));
 
 
 
 
301
  $post_if = $wpdb->get_results($sql);
302
  if (empty($post_if)) {
303
- $content = '<div class="wall" style="background-color: #F2F3F7; border: 30px solid #fff; width: 90%; height: 90%; margin: 0 auto;">
 
304
 
305
- <h1 style="text-align: center; font-family:\'open-sans\', arial; color: #444; font-size: 60px; padding: 50px;">ERROR 404 <br />-<br />NOT FOUND</h1>
306
- <p style="text-align: center; font-family:\'open-sans\', arial; color: #444; font-size: 40px; padding: 20px; line-height: 55px;">
 
 
307
  // You may have mis-typed the URL,<br />
308
  // Or the page has been removed,<br />
309
  // Actually, there is nothing to see here...</p>
310
- <p style="text-align: center;"><a style=" font-family:\'open-sans\', arial; color: #444; font-size: 20px; padding: 20px; line-height: 30px; text-decoration: none;" href="' . get_home_url() . '"><< Go back to home page >></a></p>
 
 
311
  </div>';
312
  $_page404 = array(
313
  'post_title' => '404 error page',
@@ -317,16 +553,24 @@ class MetaSeo_Admin {
317
  'post_type' => 'page',
318
  );
319
  wp_insert_post($_page404);
320
- }else{
321
  $my_post = array(
322
- 'ID' => $post_if[0]->ID,
323
- 'post_title' => '404 error page'
324
  );
325
 
326
- wp_update_post( $my_post );
327
  }
328
 
329
- $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s", array("WPMS HTML Sitemap", "metaseo_html_sitemap", "page"));
 
 
 
 
 
 
 
 
330
  $post_if = $wpdb->get_var($sql);
331
  if ($post_if < 1) {
332
  $_sitemap_page = array(
@@ -342,35 +586,44 @@ class MetaSeo_Admin {
342
  update_option($option_v, true);
343
  }
344
  }
345
-
346
- /*
347
  * Add field title in dialog link when edit a link
348
  */
349
- function wpms_link_title_field() {
 
350
  if (isset($this->settings['metaseo_linkfield']) && $this->settings['metaseo_linkfield'] == 1) {
351
- wp_enqueue_script('wpmslinkTitle', plugins_url('js/wpms-link-title-field.js', dirname(__FILE__)), array('wplink'), WPMSEO_VERSION, true);
 
 
 
 
 
 
352
  wp_localize_script('wpmslinkTitle', 'wpmsLinkTitleL10n', array(
353
  'titleLabel' => __('Title', 'wp-meta-seo'),
354
  ));
355
  }
356
  }
357
-
358
- /*
359
  * Update option wpms_set_ignore
360
  */
361
- function wpms_set_ignore() {
 
362
  if (!current_user_can('manage_options')) {
363
  wp_send_json(false);
364
  }
365
  update_option('wpms_set_ignore', 0);
366
  wp_send_json(true);
367
  }
368
-
369
- /*
370
  * Render message error when disable search engines from indexing this site
371
  */
372
- function wpms_public_warning() {
373
- if (( function_exists('is_network_admin') && is_network_admin())) {
 
374
  return;
375
  }
376
 
@@ -378,57 +631,75 @@ class MetaSeo_Admin {
378
  return;
379
  }
380
 
381
- echo '<script type="text/javascript">' . PHP_EOL
382
- . 'function wpmsSetIgnore(option, hide, nonce){' . PHP_EOL
383
- . 'jQuery.post( ajaxurl, {' . PHP_EOL
384
- . 'action: "wpms_set_ignore"' . PHP_EOL
385
- . '}, function( data ) {' . PHP_EOL
386
- . 'if ( data ) {' . PHP_EOL
387
- . 'jQuery( "#" + hide ).hide();' . PHP_EOL
388
- . '}' . PHP_EOL
389
- . '}' . PHP_EOL
390
- . ');' . PHP_EOL
391
- . '}' . PHP_EOL
392
- . '</script>';
393
-
394
- printf('
395
- <div id="robotsmessage" class="error">
396
  <p>
397
  <strong>%1$s</strong>
398
  %2$s
399
- <a href="javascript:wpmsSetIgnore(\'wpms_public_warning\',\'robotsmessage\',\'%3$s\');" class="button">%4$s</a>
 
400
  </p>
401
- </div>', __('Your website is not indexed by search engine because of your WordPress settings.', 'wp-meta-seo'), sprintf(__('%sFix it now%s', 'wp-meta-seo'), sprintf('<a href="%s">', esc_url(admin_url('options-reading.php'))), '</a>'), esc_js(wp_create_nonce('wpseo-ignore')), __('OK I know that.', 'wp-meta-seo')
 
 
 
 
 
 
 
 
402
  );
403
  }
404
-
405
- /*
406
  * Loads translated strings.
407
  */
408
- function wpms_load_langguage() {
409
- load_plugin_textdomain('wp-meta-seo', false, dirname(plugin_basename(__FILE__)) . DIRECTORY_SEPARATOR . 'languages' .DIRECTORY_SEPARATOR);
 
 
 
 
 
410
  }
411
 
412
- function metaseo_create_field($data_title, $alt, $dashicon, $label, $value_hidden) {
413
- $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . $data_title . '" alt="' . $alt . '"><i class="metaseo-dashicons material-icons dashicons-before" style="' . ($dashicon == 'done' ? 'color:#46B450' : 'color:#FFB900') . '">' . $dashicon . '</i>' . $label . '</div>';
414
- $output .= '<input type="hidden" class="wpms_analysis_hidden" name="wpms[' . $data_title . ']" value="' . $value_hidden . '">';
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  return $output;
416
  }
417
-
418
- /*
419
- * Ajax load page analysis
420
  */
421
- function metaseo_reload_analysis() {
 
422
  if (!current_user_can('manage_options')) {
423
  wp_send_json(array('status' => false));
424
  }
425
  $tooltip_page = array();
426
- $tooltip_page['title_in_heading'] = __('Check if a word of this content title is also in a title heading (h1, h2...)', 'wp-meta-seo');
427
- $tooltip_page['title_in_content'] = __('Check if a word of this content title is also in the text', 'wp-meta-seo');
 
 
428
  $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
429
  $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
430
  $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
431
- $tooltip_page['image_resize'] = __('Check for image HTML resizing in content (usually image resized using handles)', 'wp-meta-seo');
 
432
  $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
433
  if (empty($_POST['datas'])) {
434
  wp_send_json(false);
@@ -442,30 +713,50 @@ class MetaSeo_Admin {
442
  $output = '';
443
 
444
  // title heading
445
- $words_post_title = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower($_POST['datas']['title']), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
446
  if ($_POST['datas']['content'] == '') {
447
- $output .= $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
448
  } else {
449
  $dom = new DOMDocument;
450
  libxml_use_internal_errors(true);
451
- $content = apply_filters('the_content', '<div>' . html_entity_decode(stripcslashes($_POST['datas']['content'])) . '</div>');
 
 
 
452
  if ($dom->loadHTML($content)) {
453
  // Extracting the specified elements from the web page
454
- $tags_h1 = $dom->getElementsByTagName('h1');
455
- $tags_h2 = $dom->getElementsByTagName('h2');
456
- $tags_h3 = $dom->getElementsByTagName('h3');
457
- $tags_h4 = $dom->getElementsByTagName('h4');
458
- $tags_h5 = $dom->getElementsByTagName('h5');
459
- $tags_h6 = $dom->getElementsByTagName('h6');
460
 
461
  $test = false;
462
- if (count($tags_h1) == 0 && count($tags_h2) == 0 && count($tags_h3) == 0 && count($tags_h4) == 0 && count($tags_h5) == 0 && count($tags_h6) == 0) {
 
463
  $test = false;
464
  } else {
465
  // check tag h1
466
  if (!empty($tags_h1)) {
467
  foreach ($tags_h1 as $order => $tagh1) {
468
- $words_tagh1 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh1->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
469
  if (is_array($words_tagh1) && is_array($words_post_title)) {
470
  foreach ($words_tagh1 as $mh) {
471
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -479,7 +770,12 @@ class MetaSeo_Admin {
479
  // check tag h2
480
  if (!empty($tags_h2)) {
481
  foreach ($tags_h2 as $order => $tagh2) {
482
- $words_tagh2 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh2->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
483
  if (is_array($words_tagh2) && is_array($words_post_title)) {
484
  foreach ($words_tagh2 as $mh) {
485
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -489,11 +785,16 @@ class MetaSeo_Admin {
489
  }
490
  }
491
  }
492
-
493
  // check tag h3
494
  if (!empty($tags_h3)) {
495
  foreach ($tags_h3 as $order => $tagh3) {
496
- $words_tagh3 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh3->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
497
  if (is_array($words_tagh3) && is_array($words_post_title)) {
498
  foreach ($words_tagh3 as $mh) {
499
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -503,11 +804,16 @@ class MetaSeo_Admin {
503
  }
504
  }
505
  }
506
-
507
  // check tag h4
508
  if (!empty($tags_h4)) {
509
  foreach ($tags_h4 as $order => $tagh4) {
510
- $words_tagh4 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh4->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
511
  if (is_array($words_tagh4) && is_array($words_post_title)) {
512
  foreach ($words_tagh4 as $mh) {
513
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -517,11 +823,16 @@ class MetaSeo_Admin {
517
  }
518
  }
519
  }
520
-
521
  // check tag h5
522
  if (!empty($tags_h5)) {
523
  foreach ($tags_h5 as $order => $tagh5) {
524
- $words_tagh5 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh5->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
525
  if (is_array($words_tagh5) && is_array($words_post_title)) {
526
  foreach ($words_tagh5 as $mh) {
527
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -531,11 +842,16 @@ class MetaSeo_Admin {
531
  }
532
  }
533
  }
534
-
535
  // check tag h6
536
  if (!empty($tags_h6)) {
537
  foreach ($tags_h6 as $order => $tagh6) {
538
- $words_tagh6 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh6->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
539
  if (is_array($words_tagh6) && is_array($words_post_title)) {
540
  foreach ($words_tagh6 as $mh) {
541
  if (in_array($mh, $words_post_title) && $mh != '') {
@@ -548,20 +864,48 @@ class MetaSeo_Admin {
548
  }
549
 
550
  if ($test || (!empty($meta_analysis) && !empty($meta_analysis['heading_title']))) {
551
- $output .= $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
552
- $check ++;
 
 
 
 
 
 
553
  } else {
554
- $output .= $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
555
  }
556
  } else {
557
- $output .= $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
558
  }
559
  }
560
 
561
  // title content
562
  $content = apply_filters('the_content', html_entity_decode(stripcslashes($_POST['datas']['content'])));
563
- $words_title = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower($_POST['datas']['title']), -1, PREG_SPLIT_NO_EMPTY);
564
- $words_post_content = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower(strip_tags($content)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
 
 
 
 
 
565
 
566
  $test1 = false;
567
  if (is_array($words_title) && is_array($words_post_content)) {
@@ -576,41 +920,103 @@ class MetaSeo_Admin {
576
  }
577
 
578
  if ($test1) {
579
- $output .= $this->metaseo_create_field('content_title', $tooltip_page['title_in_content'], 'done', __('Page title word in content', 'wp-meta-seo'), 1);
580
- $check ++;
 
 
 
 
 
 
581
  } else {
582
- $output .= $this->metaseo_create_field('content_title', $tooltip_page['title_in_content'], 'warning', __('Page title word in content', 'wp-meta-seo'), 0);
 
 
 
 
 
 
583
  }
584
 
585
  // page url matches page title
586
  $mtitle = $_POST['datas']['title'];
587
  if ($_POST['datas']['mpageurl'] == sanitize_title($mtitle)) {
588
- $output .= $this->metaseo_create_field('pageurl', $tooltip_page['page_url'], 'done', __('Page url matches with page title', 'wp-meta-seo'), 1);
589
- $check ++;
 
 
 
 
 
 
590
  } else {
591
- $output .= $this->metaseo_create_field('pageurl', $tooltip_page['page_url'], 'warning', __('Page url matches with page title', 'wp-meta-seo'), 0);
 
 
 
 
 
 
592
  }
593
 
594
  // meta title filled
595
- if (($_POST['datas']['meta_title'] != '' && mb_strlen($_POST['datas']['meta_title'],'UTF-8') <= self::$title_length)) {
596
- $output .= $this->metaseo_create_field('metatitle', $tooltip_page['meta_title'], 'done', __('Meta title filled', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
597
  $check++;
598
  } else {
599
- $output .= $this->metaseo_create_field('metatitle', $tooltip_page['meta_title'], 'warning', __('Meta title filled', 'wp-meta-seo'), 0);
 
 
 
 
 
 
600
  }
601
 
602
  // desc filled
603
- if (($_POST['datas']['meta_desc'] != '' && mb_strlen($_POST['datas']['meta_desc'],'UTF-8') <= self::$desc_length)) {
604
- $output .= $this->metaseo_create_field('metadesc', $tooltip_page['meta_desc'], 'done', __('Meta description filled', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
605
  $check++;
606
  } else {
607
- $output .= $this->metaseo_create_field('metadesc', $tooltip_page['meta_desc'], 'warning', __('Meta description filled', 'wp-meta-seo'), 0);
 
 
 
 
 
 
608
  }
609
 
610
  // image resize
611
  if ($_POST['datas']['content'] == '') {
612
- $output .= $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'done', __('Wrong image resize', 'wp-meta-seo'), 1);
613
- $output .= $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'done', __('Image have meta title or alt', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
 
 
 
 
 
614
  $check += 2;
615
  } else {
616
  $dom = new DOMDocument;
@@ -628,7 +1034,8 @@ class MetaSeo_Admin {
628
  $string_wh = substr($src, $b + 1, $e - $b - 1);
629
  $array_wh = explode('x', $string_wh);
630
  if (!empty($array_wh[0]) && !empty($array_wh[1])) {
631
- if (((int) $array_wh[0] != (int) $tag->getAttribute('width')) || ((int) $array_wh[1] != (int) $tag->getAttribute('height'))) {
 
632
  $img_wrong = true;
633
  }
634
  }
@@ -641,32 +1048,69 @@ class MetaSeo_Admin {
641
  }
642
 
643
  if ($img_wrong == false) {
644
- $output .= $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'done', __('Wrong image resize', 'wp-meta-seo'), 1);
 
 
 
 
 
 
645
  $check++;
646
  } else {
647
- $output .= $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'warning', __('Wrong image resize', 'wp-meta-seo'), 0);
 
 
 
 
 
 
648
  }
649
 
650
  if ($img_wrong_alt == false) {
651
- $output .= $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'done', __('Image have meta title or alt', 'wp-meta-seo'), 1);
 
 
 
 
 
 
652
  $check++;
653
  } else {
654
- $output .= $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'warning', __('Image have meta title or alt', 'wp-meta-seo'), 0);
 
 
 
 
 
 
655
  }
656
  } else {
657
- $output .= $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'warning', __('Wrong image resize', 'wp-meta-seo'), 0);
658
- $output .= $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'warning', __('Image have meta title or alt', 'wp-meta-seo'), 0);
 
 
 
 
 
 
 
 
 
 
 
 
659
  }
660
  }
661
 
662
  $circliful = ceil(100 * ($check) / 7);
663
  wp_send_json(array('circliful' => $circliful, 'output' => $output, 'check' => $check));
664
  }
665
-
666
- /*
667
  * validate propertyin page optimization
668
  */
669
- function metaseo_validate_analysis() {
 
670
  if (!current_user_can('manage_options')) {
671
  wp_send_json(false);
672
  }
@@ -681,47 +1125,64 @@ class MetaSeo_Admin {
681
  update_post_meta($post_id, $key, $analysis);
682
  wp_send_json(true);
683
  }
684
-
685
- /*
686
  * Ajax update link meta title and content editor
687
  */
688
- function metaseo_update_link() {
 
689
  if (!current_user_can('manage_options')) {
690
  wp_send_json(false);
691
  }
692
  if (isset($_POST['link_id'])) {
693
  global $wpdb;
694
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($_POST['link_id']));
 
 
 
 
 
695
  $link_detail = $wpdb->get_row($sql);
696
- if (empty($link_detail))
697
  wp_send_json(false);
 
698
 
699
  $value = array('meta_title' => $_POST['meta_title']);
700
  $wpdb->update(
701
- $wpdb->prefix . 'wpms_links', $value, array('id' => $_POST['link_id'])
 
 
702
  );
703
 
704
 
705
  $post = get_post($link_detail->source_id);
706
  if (!empty($post)) {
707
  $old_value = $post->post_content;
708
- $edit_result = $this->wpms_edit_linkhtml($old_value, $link_detail->link_url, $link_detail->link_url, $_POST['meta_title'] , $link_detail->follow);
 
 
 
 
 
 
 
709
  $my_post = array(
710
  'ID' => $link_detail->source_id,
711
  'post_content' => $edit_result['content']
712
  );
713
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
714
  wp_update_post($my_post);
715
  wp_send_json(array('status' => true));
716
  }
717
  }
718
  wp_send_json(false);
719
  }
720
-
721
- /*
722
  * Ajax update meta index for page
723
  */
724
- function metaseo_update_pageindex() {
 
725
  if (!current_user_can('manage_options')) {
726
  wp_send_json(array('status' => false));
727
  }
@@ -731,11 +1192,12 @@ class MetaSeo_Admin {
731
  }
732
  wp_send_json(array('status' => false));
733
  }
734
-
735
- /*
736
  * Ajax update meta follow for page
737
  */
738
- function metaseo_update_pagefollow() {
 
739
  if (!current_user_can('manage_options')) {
740
  wp_send_json(array('status' => false));
741
  }
@@ -745,25 +1207,27 @@ class MetaSeo_Admin {
745
  }
746
  wp_send_json(array('status' => false));
747
  }
748
-
749
- /*
750
  * Ajax update meta follow for link
751
  */
752
- function metaseo_update_follow() {
 
753
  if (!current_user_can('manage_options')) {
754
  wp_send_json(array('status' => false));
755
  }
756
  if (isset($_POST['link_id'])) {
757
- $this->update_follow($_POST['link_id'], $_POST['follow']);
758
  wp_send_json(array('status' => true));
759
  }
760
  wp_send_json(array('status' => false));
761
  }
762
-
763
- /*
764
  * Ajax update multitle meta follow for link
765
  */
766
- function metaseo_update_multiplefollow() {
 
767
  if (!current_user_can('manage_options')) {
768
  wp_send_json(array('status' => false));
769
  }
@@ -773,23 +1237,27 @@ class MetaSeo_Admin {
773
 
774
  switch ($follow_value) {
775
  case 'follow_selected':
776
- if (empty($_POST['linkids']))
777
  wp_send_json(array('status' => true));
 
 
778
  $follow = 1;
779
  foreach ($_POST['linkids'] as $linkId) {
780
- $this->update_follow($linkId, $follow);
781
  }
782
  break;
783
 
784
  case 'follow_all':
785
  $follow = 1;
786
  $i = 0;
787
- $links = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=0 AND type='url'");
 
 
788
  foreach ($links as $link) {
789
  if ($i > $limit) {
790
  wp_send_json(array('status' => false, 'message' => 'limit'));
791
  } else {
792
- $this->update_follow($link->id, $follow);
793
  $i++;
794
  }
795
  }
@@ -798,22 +1266,26 @@ class MetaSeo_Admin {
798
 
799
  case 'nofollow_selected':
800
  $follow = 0;
801
- if (empty($_POST['linkids']))
802
  wp_send_json(array('status' => true));
 
 
803
  foreach ($_POST['linkids'] as $linkId) {
804
- $this->update_follow($linkId, $follow);
805
  }
806
  break;
807
 
808
  case 'nofollow_all':
809
  $follow = 0;
810
  $i = 0;
811
- $links = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=1 AND type='url'");
 
 
812
  foreach ($links as $link) {
813
  if ($i > $limit) {
814
  wp_send_json(array('status' => false, 'message' => 'limit'));
815
  } else {
816
- $this->update_follow($link->id, $follow);
817
  $i++;
818
  }
819
  }
@@ -821,39 +1293,65 @@ class MetaSeo_Admin {
821
  }
822
  wp_send_json(array('status' => true));
823
  }
824
-
825
- /*
826
  * Ajax update meta follow for link
 
 
827
  */
828
- function update_follow($linkId, $follow) {
 
829
  global $wpdb;
830
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($linkId));
 
 
 
 
 
831
  $link_detail = $wpdb->get_row($sql);
832
- if (empty($link_detail))
833
  wp_send_json(array('status' => false));
 
 
834
 
835
  $value = array('follow' => $follow);
836
  $wpdb->update(
837
- $wpdb->prefix . 'wpms_links', $value, array('id' => $linkId)
 
 
838
  );
839
 
840
  $post = get_post($link_detail->source_id);
841
  if (!empty($post)) {
842
  $old_value = $post->post_content;
843
- $edit_result = $this->wpms_edit_linkhtml($old_value, $link_detail->link_url, $link_detail->link_url, $link_detail->meta_title, $follow);
 
 
 
 
 
 
844
  $my_post = array(
845
  'ID' => $link_detail->source_id,
846
  'post_content' => $edit_result['content']
847
  );
848
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
849
  wp_update_post($my_post);
850
  }
851
  }
852
-
853
- /*
854
  * Render new content when edit a link
 
 
 
 
 
 
 
855
  */
856
- public function wpms_edit_linkhtml($content, $new_url, $old_url, $meta_title, $follow , $new_text = null) {
 
857
  //Save the old & new URLs for use in the edit callback.
858
  $args = array(
859
  'old_url' => $old_url,
@@ -864,7 +1362,14 @@ class MetaSeo_Admin {
864
  );
865
 
866
  //Find all links and replace those that match $old_url.
867
- $content = MetaSeo_Broken_Link_Table::wpms_multi_edit($content, array('MetaSeo_Broken_Link_Table', 'wpms_edithtml_callback'), $args);
 
 
 
 
 
 
 
868
 
869
  $result = array(
870
  'content' => $content,
@@ -876,312 +1381,566 @@ class MetaSeo_Admin {
876
  return $result;
877
  }
878
 
879
- /*
880
  * Update option wpms_settings_404
881
  */
882
- function wpms_save_settings404() {
 
883
  if (!current_user_can('manage_options')) {
884
  wp_send_json(false);
885
  }
886
 
887
  if (isset($_POST['wpms_redirect'])) {
888
  update_option('wpms_settings_404', $_POST['wpms_redirect']);
889
-
890
  }
891
 
892
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
893
- $params = array('enable','numberFrequency','showlinkFrequency');
894
  $settinglink = array();
895
- foreach ($params as $param){
896
- if(isset($_POST[$param])){
897
  $settinglink[$param] = $_POST[$param];
898
  }
899
  }
900
 
901
- if(empty($settinglink['wpms_lastRun_scanlink'])){
902
- $settinglink['wpms_lastRun_scanlink'] = time();
903
  }
904
- update_option('wpms_link_settings',$settinglink);
905
  }
906
 
907
  wp_send_json(true);
908
  }
909
 
910
- /*
911
  * Update breadcrumb settings
912
  */
913
- function wpms_save_settings_breadcrumb() {
 
914
  if (!current_user_can('manage_options')) {
915
  wp_send_json(false);
916
  }
917
 
918
- $params = array('separator','include_home','home_text','clickable','home_text_default');
919
  $settinglink = array();
920
- foreach ($params as $param){
921
- if(isset($_POST[$param])){
922
  $settinglink[$param] = $_POST[$param];
923
  }
924
  }
925
 
926
- update_option('_metaseo_breadcrumbs',$settinglink);
927
  wp_send_json(true);
928
  }
929
 
930
- /*
931
  * Add a new field to a section of a settings page
932
  */
933
- function metaseo_field_settings() {
 
934
  register_setting('Wp Meta SEO', '_metaseo_settings');
935
  add_settings_section('metaseo_dashboard', '', array($this, 'showSettings'), 'metaseo_settings');
936
- add_settings_field('metaseo_title_home', __('Homepage meta title', 'wp-meta-seo'), array($this, 'metaseo_title_home'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('You can define your home page meta title in the content itself (a page, a post category…), if for some reason it’s not possible, use this setting', 'wp-meta-seo')));
937
- add_settings_field('metaseo_desc_home', __('Homepage meta description', 'wp-meta-seo'), array($this, 'metaseo_desc_home'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('You can define your home page meta description in the content itself (a page, a post category…), if for some reason it’s not possible, use this setting', 'wp-meta-seo')));
938
- add_settings_field('metaseo_showfacebook', __('Facebook profile URL', 'wp-meta-seo'), array($this, 'showfacebook'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Used as profile in case of social sharing content on Facebook', 'wp-meta-seo')));
939
- add_settings_field('metaseo_showfbappid', __('Facebook App ID', 'wp-meta-seo'), array($this, 'showfbappid'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Used as facebook app ID in case of social sharing content on Facebook', 'wp-meta-seo')));
940
- add_settings_field('metaseo_showtwitter', __('Twitter Username', 'wp-meta-seo'), array($this, 'showtwitter'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Used as profile in case of social sharing content on Twitter', 'wp-meta-seo')));
941
- add_settings_field('metaseo_twitter_card', __('The default card type to use', 'wp-meta-seo'), array($this, 'showtwittercard'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Choose the Twitter card size generated when sharing a content', 'wp-meta-seo')));
942
- add_settings_field('metaseo_metatitle_tab', __('Meta title as page title', 'wp-meta-seo'), array($this, 'showmetatitletab'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Usually not recommended as meta information is for search engines and content title for readers, but in some case... :)', 'wp-meta-seo')));
943
- add_settings_field('metaseo_showkeywords', __('Meta keywords', 'wp-meta-seo'), array($this, 'showkeywords'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Not used directly by search engine to index content, but in some case it can be helpful (multilingual is an example)', 'wp-meta-seo')));
944
- add_settings_field('metaseo_showtmetablock', __('Meta block edition', 'wp-meta-seo'), array($this, 'showtmetablock'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Load the onpage meta edition and analysis block', 'wp-meta-seo')));
945
- add_settings_field('metaseo_showsocial', __('Social sharing block', 'wp-meta-seo'), array($this, 'showsocial'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Activate the custom social sharing tool, above the meta block', 'wp-meta-seo')));
946
- add_settings_field('metaseo_seovalidate', __('Force SEO validation', 'wp-meta-seo'), array($this, 'showseovalidate'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Possibility to force a criteria validation in the content analysis tool', 'wp-meta-seo')));
947
- add_settings_field('metaseo_linkfield', __('Link text field', 'wp-meta-seo'), array($this, 'showlinkfield'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Add the link title field in the text editor and in the bulk link edition view', 'wp-meta-seo')));
948
- add_settings_field('metaseo_follow', __('Post/Page follow', 'wp-meta-seo'), array($this, 'showfollow'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Add an option to setup Follow/Nofollow instruction for each content', 'wp-meta-seo')));
949
- add_settings_field('metaseo_index', __('Post/Page index', 'wp-meta-seo'), array($this, 'showindex'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Add an option to say to search engine: hey! Do not index this content', 'wp-meta-seo')));
950
- add_settings_field('metaseo_overridemeta', __('Auto override Meta', 'wp-meta-seo'), array($this, 'showoverridemeta'), 'metaseo_settings', 'metaseo_dashboard', array('label_for' => __('Auto override image meta in post content when update meta', 'wp-meta-seo')));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
  }
952
-
953
- /*
954
  * Display metatitle_tab input
955
  */
956
- public function showmetatitletab() {
 
957
  echo '<input name="_metaseo_settings[metaseo_metatitle_tab]" type="hidden" value="0"/>';
958
  ?>
959
- <label><?php _e('When meta title is filled use it as page title instead of the content title', 'wp-meta-seo'); ?></label>
 
 
960
  <div class="switch-optimization">
961
  <label class="switch switch-optimization">
962
- <input type="checkbox" id="metaseo_metatitle_tab" name="_metaseo_settings[metaseo_metatitle_tab]" value="1" <?php if (isset($this->settings['metaseo_metatitle_tab']) && $this->settings['metaseo_metatitle_tab'] == 1) echo 'checked' ?>>
963
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
964
  </label>
965
  </div>
966
  <?php
967
  }
968
 
969
- public function showSettings() {
970
-
971
  }
972
-
973
- /*
974
  * Display title_home input
975
  */
976
- public function metaseo_title_home() {
 
977
  $home_title = isset($this->settings['metaseo_title_home']) ? $this->settings['metaseo_title_home'] : '';
978
- echo '<input id="metaseo_title_home" name="_metaseo_settings[metaseo_title_home]" type="text" value="' . esc_attr($home_title) . '" size="50"/>';
 
979
  }
980
-
981
- /*
982
  * Display desc_home input
983
  */
984
- public function metaseo_desc_home() {
 
985
  $home_desc = isset($this->settings['metaseo_desc_home']) ? $this->settings['metaseo_desc_home'] : '';
986
- echo '<input id="metaseo_desc_home" name="_metaseo_settings[metaseo_desc_home]" type="text" value="' . esc_attr($home_desc) . '" size="50"/>';
 
987
  }
988
 
989
- /*
990
  * Display showkeywords input
991
  */
992
- public function showkeywords() {
 
993
  echo '<input name="_metaseo_settings[metaseo_showkeywords]" type="hidden" value="0"/>';
994
  ?>
995
  <label><?php _e('Active meta keywords', 'wp-meta-seo'); ?></label>
996
  <div class="switch-optimization">
997
  <label class="switch switch-optimization">
998
- <input type="checkbox" id="metaseo_showkeywords" name="_metaseo_settings[metaseo_showkeywords]" value="1" <?php if (isset($this->settings['metaseo_showkeywords']) && $this->settings['metaseo_showkeywords'] == 1) echo 'checked' ?>>
999
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1000
  </label>
1001
  </div>
1002
  <?php
1003
  }
1004
-
1005
- /*
1006
  * Display showtmetablock input
1007
  */
1008
- public function showtmetablock() {
 
1009
  echo '<input name="_metaseo_settings[metaseo_showtmetablock]" type="hidden" value="0"/>';
1010
  ?>
1011
  <label><?php _e('Activate meta block edition below content', 'wp-meta-seo'); ?></label>
1012
  <div class="switch-optimization">
1013
  <label class="switch switch-optimization">
1014
- <input type="checkbox" id="metaseo_showtmetablock" name="_metaseo_settings[metaseo_showtmetablock]" value="1" <?php if (isset($this->settings['metaseo_showtmetablock']) && $this->settings['metaseo_showtmetablock'] == 1) echo 'checked' ?>>
1015
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
 
1016
  </label>
1017
  </div>
1018
  <?php
1019
  }
1020
-
1021
- /*
1022
  * Display showsocial input
1023
  */
1024
- public function showsocial() {
 
1025
  echo '<input name="_metaseo_settings[metaseo_showsocial]" type="hidden" value="0"/>';
1026
  ?>
1027
  <label><?php _e('Activate social edition', 'wp-meta-seo'); ?></label>
1028
  <div class="switch-optimization">
1029
  <label class="switch switch-optimization">
1030
- <input type="checkbox" id="metaseo_showsocial" name="_metaseo_settings[metaseo_showsocial]" value="1" <?php if (isset($this->settings['metaseo_showsocial']) && $this->settings['metaseo_showsocial'] == 1) echo 'checked' ?>>
1031
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1032
  </label>
1033
  </div>
1034
  <?php
1035
  }
1036
-
1037
- /*
1038
  * Display seovalidate input
1039
  */
1040
- public function showseovalidate() {
 
1041
  echo '<input name="_metaseo_settings[metaseo_seovalidate]" type="hidden" value="0"/>';
1042
  ?>
1043
- <label><?php _e('Allow user to force on page SEO criteria validation by clicking on the icon', 'wp-meta-seo'); ?></label>
 
 
1044
  <div class="switch-optimization">
1045
  <label class="switch switch-optimization">
1046
- <input type="checkbox" id="metaseo_seovalidate" name="_metaseo_settings[metaseo_seovalidate]" value="1" <?php if (isset($this->settings['metaseo_seovalidate']) && $this->settings['metaseo_seovalidate'] == 1) echo 'checked' ?>>
1047
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1048
  </label>
1049
  </div>
1050
  <?php
1051
  }
1052
-
1053
- /*
1054
  * Display linkfield input
1055
  */
1056
- public function showlinkfield() {
 
1057
  echo '<input name="_metaseo_settings[metaseo_linkfield]" type="hidden" value="0"/>';
1058
  ?>
1059
  <label><?php _e("Adds back the missing 'title' field in the Insert/Edit URL box", "wp-meta-seo"); ?></label>
1060
  <div class="switch-optimization">
1061
  <label class="switch switch-optimization">
1062
- <input type="checkbox" id="metaseo_linkfield" name="_metaseo_settings[metaseo_linkfield]" value="1" <?php if (isset($this->settings['metaseo_linkfield']) && $this->settings['metaseo_linkfield'] == 1) echo 'checked' ?>>
1063
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1064
  </label>
1065
  </div>
1066
  <?php
1067
  }
1068
-
1069
- /*
1070
  * Display follow input
1071
  */
1072
- public function showfollow() {
 
1073
  echo '<input name="_metaseo_settings[metaseo_follow]" type="hidden" value="0"/>';
1074
  ?>
1075
- <label><?php _e("Provides a way for webmasters to tell search engines don't follow links on the page.", "wp-meta-seo"); ?></label>
 
 
 
1076
  <div class="switch-optimization">
1077
  <label class="switch switch-optimization">
1078
- <input type="checkbox" id="metaseo_follow" name="_metaseo_settings[metaseo_follow]" value="1" <?php if (isset($this->settings['metaseo_follow']) && $this->settings['metaseo_follow'] == 1) echo 'checked' ?>>
1079
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1080
  </label>
1081
  </div>
1082
  <?php
1083
  }
1084
-
1085
- /*
1086
  * Display index input
1087
  */
1088
- public function showindex() {
 
1089
  echo '<input name="_metaseo_settings[metaseo_index]" type="hidden" value="0"/>';
1090
  ?>
1091
- <label><?php _e("Provides show or do not show this page in search results in search results.", "wp-meta-seo"); ?></label>
 
 
 
1092
  <div class="switch-optimization">
1093
  <label class="switch switch-optimization">
1094
- <input type="checkbox" id="metaseo_index" name="_metaseo_settings[metaseo_index]" value="1" <?php if (isset($this->settings['metaseo_index']) && $this->settings['metaseo_index'] == 1) echo 'checked' ?>>
1095
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1096
  </label>
1097
  </div>
1098
  <?php
1099
  }
1100
 
1101
- /*
1102
  * Display override meta
1103
  */
1104
- public function showoverridemeta() {
 
1105
  echo '<input name="_metaseo_settings[metaseo_overridemeta]" type="hidden" value="0"/>';
1106
  ?>
1107
  <label><?php _e("Override meta image in post content when update meta", "wp-meta-seo"); ?></label>
1108
  <div class="switch-optimization">
1109
  <label class="switch switch-optimization">
1110
- <input type="checkbox" id="metaseo_overridemeta" name="_metaseo_settings[metaseo_overridemeta]" value="1" <?php if (isset($this->settings['metaseo_overridemeta']) && $this->settings['metaseo_overridemeta'] == 1) echo 'checked' ?>>
1111
- <div class="slider round"></div>
 
 
 
 
 
 
 
 
1112
  </label>
1113
  </div>
1114
  <?php
1115
  }
1116
 
1117
- /*
1118
  * Display showfacebook input
1119
  */
1120
- public function showfacebook() {
 
1121
  $face = isset($this->settings['metaseo_showfacebook']) ? $this->settings['metaseo_showfacebook'] : '';
1122
- echo '<input id="metaseo_showfacebook" name="_metaseo_settings[metaseo_showfacebook]" type="text" value="' . esc_attr($face) . '" size="50"/>';
 
1123
  }
1124
 
1125
- /*
1126
  * Display fb app id input
1127
  */
1128
- public function showfbappid() {
 
1129
  $appid = isset($this->settings['metaseo_showfbappid']) ? $this->settings['metaseo_showfbappid'] : '';
1130
- echo '<input id="metaseo_showfbappid" name="_metaseo_settings[metaseo_showfbappid]" type="text" value="' . esc_attr($appid) . '" size="50"/>';
 
1131
  }
1132
 
1133
- /*
1134
  * Display showtwitter input
1135
  */
1136
- public function showtwitter() {
 
1137
  $twitter = isset($this->settings['metaseo_showtwitter']) ? $this->settings['metaseo_showtwitter'] : '';
1138
- echo '<input id="metaseo_showtwitter" name="_metaseo_settings[metaseo_showtwitter]" type="text" value="' . esc_attr($twitter) . '" size="50"/>';
 
1139
  }
1140
-
1141
- /*
1142
  * Display twitter_card input
1143
  */
1144
- public function showtwittercard() {
1145
- $twitter_card = isset($this->settings['metaseo_twitter_card']) ? $this->settings['metaseo_twitter_card'] : 'summary';
 
 
 
 
 
1146
  ?>
1147
- <select class="select" name="_metaseo_settings[metaseo_twitter_card]" id="metaseo_twitter_card">
1148
- <option <?php if ($twitter_card == 'summary') echo 'selected' ?> value="summary"><?php _e('Summary', 'wp-meta-seo'); ?></option>
1149
- <option <?php if ($twitter_card == 'summary_large_image') echo 'selected' ?> value="summary_large_image"><?php _e('Summary with large image', 'wp-meta-seo'); ?></option>
1150
- </select>
 
 
 
 
1151
  <?php
1152
  }
1153
 
1154
- private function load_meta_boxes() {
 
 
 
 
1155
  if (in_array($this->pagenow, array(
1156
- 'edit.php',
1157
- 'post.php',
1158
- 'post-new.php',
1159
- )) || apply_filters('wpmseo_always_register_metaboxes_on_admin', false)
1160
  ) {
1161
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-metabox.php' );
1162
- $GLOBALS['wpmseo_metabox'] = new WPMSEO_Metabox;
1163
  }
1164
  }
1165
 
1166
- function stop_heartbeat() {
1167
- global $pagenow;
1168
- if ('post.php' != $pagenow && 'post-new.php' != $pagenow)
1169
- wp_deregister_script('heartbeat');
1170
- }
1171
-
1172
- /*
1173
  * Update meta title , meta description , meta keyword for content
1174
  */
1175
- function updateContentMeta_callback() {
 
 
1176
  if (!current_user_can('manage_options')) {
1177
  wp_send_json(array('status' => false));
1178
  }
1179
- global $wpdb;
1180
  $_POST = stripslashes_deep($_POST);
1181
  $response = new stdClass();
1182
-
1183
- if (!empty($_POST['metakey']) && !empty($_POST['postid']) && !empty($_POST['value']))
1184
- ;
1185
  $metakey = strtolower(trim($_POST['metakey']));
1186
  $postID = intval($_POST['postid']);
1187
  $value = trim($_POST['value']);
@@ -1215,7 +1974,7 @@ class MetaSeo_Admin {
1215
  $response->msg = __('Meta keywords was saved', 'wp-meta-seo');
1216
  }
1217
  }
1218
- update_option('wpms_last_update_post',time());
1219
  echo json_encode($response);
1220
  wp_die();
1221
  }
@@ -1223,9 +1982,10 @@ class MetaSeo_Admin {
1223
  /**
1224
  * Loads js/ajax scripts
1225
  */
1226
- public function loadAdminScripts($hook) {
1227
- global $pagenow , $current_screen;
1228
- wp_enqueue_script('jquery');
 
1229
  $array_menu = array(
1230
  'wp-meta-seo_page_metaseo_dashboard',
1231
  'wp-meta-seo_page_metaseo_image_optimize',
@@ -1236,7 +1996,7 @@ class MetaSeo_Admin {
1236
  'wp-meta-seo_page_metaseo_content_meta',
1237
  'wp-meta-seo_page_metaseo_image_meta',
1238
  'wp-meta-seo_page_metaseo_link_meta'
1239
- );
1240
 
1241
  $lists_pages = array(
1242
  'toplevel_page_metaseo_dashboard',
@@ -1250,39 +2010,113 @@ class MetaSeo_Admin {
1250
  'wp-meta-seo_page_metaseo_sendemail',
1251
  'wp-meta-seo_page_metaseo_settings'
1252
  );
1253
- if(in_array($current_screen->base,$lists_pages)){
1254
- wp_enqueue_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons');
1255
- wp_enqueue_style('wpms_materialize_style', plugins_url('css/materialize/materialize.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1256
- wp_enqueue_script('wpms_materialize_js', plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1257
  }
1258
 
1259
  wp_enqueue_script(
1260
- 'wpmetaseoAdmin', plugins_url('js/metaseo_admin.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true
 
 
 
 
1261
  );
1262
 
1263
- if(in_array($current_screen->base, $array_menu) || $pagenow == 'post.php' || $pagenow == 'post-new.php'){
1264
- wp_enqueue_style('wpmetaseoAdmin', plugins_url('css/metaseo_admin.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1265
- wp_enqueue_style('tooltip-metaimage', plugins_url('/css/tooltip-metaimage.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
 
 
 
 
 
1266
  wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1267
  }
1268
-
1269
- if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta' || $current_screen->base == 'wp-meta-seo_page_metaseo_content_meta') {
1270
- wp_enqueue_script('wpms-bulk', plugins_url('js/wpms-bulk-action.js', dirname(__FILE__)), array('jquery'), time(), true);
1271
- wp_localize_script('wpms-bulk', 'wpmseobulkL10n', $this->meta_seo_localize_script());
 
 
 
 
 
 
 
1272
  }
1273
 
1274
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_broken_link') {
1275
- wp_enqueue_style('wpms_brokenlink_style', plugins_url('css/broken_link.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
1276
  }
1277
 
1278
  if ($current_screen->base == 'toplevel_page_metaseo_dashboard') {
1279
- wp_enqueue_script('Chart', plugins_url('js/Chart.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1280
- wp_enqueue_script('jquery-knob', plugins_url('js/jquery.knob.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1281
- wp_enqueue_script('metaseo-dashboard', plugins_url('js/dashboard.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1282
- wp_enqueue_style('chart', plugins_url('/css/chart.css', dirname(__FILE__)));
1283
- wp_enqueue_style('metaseo-quirk', plugins_url('/css/metaseo-quirk.css', dirname(__FILE__)));
1284
- wp_enqueue_style('m-style-dashboard', plugins_url('css/dashboard.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1285
- wp_enqueue_style('m-font-awesome', plugins_url('css/font-awesome.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1286
  }
1287
 
1288
  $lists_pages = array(
@@ -1291,108 +2125,214 @@ class MetaSeo_Admin {
1291
  'wp-meta-seo_page_metaseo_link_meta',
1292
  'wp-meta-seo_page_metaseo_broken_link',
1293
  'wp-meta-seo_page_metaseo_google_analytics');
1294
- if(in_array($current_screen->base,$lists_pages)){
1295
- wp_enqueue_style('wpms_notification_style', plugins_url('css/notification.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1296
- wp_enqueue_script('wpms_notification_script', plugins_url('js/notification.js', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
 
 
 
 
 
1297
  }
1298
 
1299
- wp_register_style('wpms-dashboard-widgets', plugins_url('css/dashboard_widgets.css', dirname(__FILE__)), null, WPMSEO_VERSION);
1300
- wp_register_style('wpms-category-field', plugins_url('css/category_field.css', dirname(__FILE__)), null, WPMSEO_VERSION);
1301
- wp_register_script('wpms-category-field', plugins_url('js/category_field.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1302
- wp_register_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1303
- wp_register_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
1304
- wp_register_style('wpms-myqtip', plugins_url('css/my_qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1305
- wp_register_script('wpms-broken-link', plugins_url('js/wpms-broken-link.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1306
 
1307
  wp_register_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons');
1308
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta') {
1309
- wp_enqueue_script('mautosize', plugins_url('js/autosize.js', dirname(__FILE__)), array('jquery'), '0.1', true);
 
 
 
 
 
 
1310
  }
1311
 
1312
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_google_analytics') {
1313
  $lang = get_bloginfo('language');
1314
  $lang = explode('-', $lang);
1315
  $lang = $lang[0];
1316
- wp_enqueue_style('wpms-nprogress', plugins_url('css/google-analytics/nprogress.css', dirname(__FILE__)), null, WPMSEO_VERSION);
 
 
 
 
 
1317
 
1318
- wp_register_style('wpms-backend-item-reports', plugins_url('css/google-analytics/admin-widgets.css', dirname(__FILE__)), null, WPMSEO_VERSION);
1319
- wp_register_style('wpms-backend-tracking-code', plugins_url('css/google-analytics/wpms-tracking-code.css', dirname(__FILE__)), null, WPMSEO_VERSION);
1320
-
1321
- wp_register_style('jquery-ui-tooltip-html', plugins_url('css/google-analytics/jquery.ui.tooltip.html.css', dirname(__FILE__)));
 
 
 
 
 
 
 
 
 
 
 
 
 
1322
 
1323
  wp_enqueue_style('jquery-ui-tooltip-html');
1324
 
1325
- wp_enqueue_script('wpmsgooglejsapi', 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27', array(), null);
 
 
 
 
 
1326
 
1327
- wp_enqueue_script('wpms-nprogress', plugins_url('js/google-analytics/nprogress.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION);
 
 
 
 
 
1328
 
1329
- wp_enqueue_script('wpms-google-analytics', plugins_url('js/google-analytics/google_analytics.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
 
 
 
 
 
 
1330
 
1331
  /* @formatter:off */
1332
- wp_localize_script('wpms-google-analytics', 'wpmsItemData', array(
1333
- 'ajaxurl' => admin_url('admin-ajax.php'),
1334
- 'security' => wp_create_nonce('wpms_backend_item_reports'),
1335
- 'dateList' => array(
1336
- 'realtime' => __("Real-Time", 'wp-meta-seo'),
1337
- 'today' => __("Today", 'wp-meta-seo'),
1338
- 'yesterday' => __("Yesterday", 'wp-meta-seo'),
1339
- '7daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 7),
1340
- '14daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 14),
1341
- '30daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 30),
1342
- '90daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 90),
1343
- '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'wp-meta-seo'), __('One', 'wp-meta-seo')),
1344
- '1095daysAgo' => sprintf(_n("%s Year", "%s Years", 3, 'wp-meta-seo'), __('Three', 'wp-meta-seo')),
1345
- ),
1346
- 'reportList' => array(
1347
- 'sessions' => __("Sessions", 'wp-meta-seo'),
1348
- 'users' => __("Users", 'wp-meta-seo'),
1349
- 'organicSearches' => __("Organic", 'wp-meta-seo'),
1350
- 'pageviews' => __("Page Views", 'wp-meta-seo'),
1351
- 'visitBounceRate' => __("Bounce Rate", 'wp-meta-seo'),
1352
- 'locations' => __("Location", 'wp-meta-seo'),
1353
- 'contentpages' => __("Pages", 'wp-meta-seo'),
1354
- 'referrers' => __("Referrers", 'wp-meta-seo'),
1355
- 'searches' => __("Searches", 'wp-meta-seo'),
1356
- 'trafficdetails' => __("Traffic", 'wp-meta-seo'),
1357
- 'technologydetails' => __("Technology", 'wp-meta-seo'),
1358
- ),
1359
- 'i18n' => array(
1360
- __("A JavaScript Error is blocking plugin resources!", 'wp-meta-seo'), //0
1361
- __("Traffic Mediums", 'wp-meta-seo'),
1362
- __("Visitor Type", 'wp-meta-seo'),
1363
- __("Search Engines", 'wp-meta-seo'),
1364
- __("Social Networks", 'wp-meta-seo'),
1365
- __("Sessions", 'wp-meta-seo'),
1366
- __("Users", 'wp-meta-seo'),
1367
- __("Page Views", 'wp-meta-seo'),
1368
- __("Bounce Rate", 'wp-meta-seo'),
1369
- __("Organic Search", 'wp-meta-seo'),
1370
- __("Pages/Session", 'wp-meta-seo'),
1371
- __("Invalid response", 'wp-meta-seo'),
1372
- __("Not enough data collected", 'wp-meta-seo'),
1373
- __("This report is unavailable", 'wp-meta-seo'),
1374
- __("report generated by", 'wp-meta-seo'), //14
1375
- __("This plugin needs an authorization:", 'wp-meta-seo') . ' <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
1376
- __("Browser", 'wp-meta-seo'), //16
1377
- __("Operating System", 'wp-meta-seo'),
1378
- __("Screen Resolution", 'wp-meta-seo'),
1379
- __("Mobile Brand", 'wp-meta-seo'),
1380
- __("REFERRALS", 'wp-meta-seo'), //20
1381
- __("KEYWORDS", 'wp-meta-seo'),
1382
- __("SOCIAL", 'wp-meta-seo'),
1383
- __("CAMPAIGN", 'wp-meta-seo'),
1384
- __("DIRECT", 'wp-meta-seo'),
1385
- __("NEW", 'wp-meta-seo'), //25
1386
- __("You need select a profile:", 'wp-meta-seo') . ' <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
1387
- ),
1388
- 'rtLimitPages' => 10,
1389
- 'colorVariations' => array('#1e73be', '#0459a4', '#378cd7', '#51a6f1', '#00408b', '#6abfff', '#002671'),
1390
- 'region' => false,
1391
- 'language' => get_bloginfo('language'),
1392
- 'viewList' => false,
1393
- 'scope' => 'admin-widgets',
1394
- 'admin_url' => admin_url()
1395
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1396
  );
1397
  }
1398
 
@@ -1400,36 +2340,49 @@ class MetaSeo_Admin {
1400
  wp_localize_script('wpmetaseoAdmin', 'wpms_localize', array(
1401
  'ajax_url' => admin_url('admin-ajax.php'),
1402
  'settings' => $this->settings,
1403
- 'wpms_cat_metatitle_length' => WPMS_CAT_METATITLE_LENGTH,
1404
- 'wpms_cat_metadesc_length' => WPMS_CAT_METADESC_LENGTH,
1405
- 'wpms_cat_metakeywords_length' => WPMS_CAT_METAKEYWORDS_LENGTH
1406
  ));
1407
  }
1408
 
1409
  /**
1410
  * Localize a script.
1411
  *
1412
- * Works only if the script has already been added.
1413
  */
1414
- public function meta_seo_localize_script() {
 
1415
  return array(
1416
- 'metaseo_message_false_copy' => __('Warning, you\'re about to replace existing image alt or tile content, are you sire about that?', 'wp-meta-seo'),
 
1417
  );
1418
  }
1419
-
1420
- /**
1421
- * Add a top-level menu page.
1422
- *
1423
- * This function takes a capability which will be used to determine whether
1424
- * or not a page is included in the menu.
1425
- */
1426
- function register_menu_page() {
 
1427
  // Add main page
1428
- $admin_page = add_menu_page(__('WP Meta SEO:', 'wp-meta-seo') . ' ' . __('Dashboard', 'wp-meta-seo'), __('WP Meta SEO', 'wp-meta-seo'), 'manage_options', 'metaseo_dashboard', array(
1429
- $this, 'load_page',), 'dashicons-chart-area');
 
 
 
 
 
 
 
 
 
1430
 
1431
  /**
1432
- * Filter: 'metaseo_manage_options_capability' - Allow changing the capability users need to view the settings pages
 
1433
  *
1434
  * @api string unsigned The capability
1435
  */
@@ -1443,7 +2396,7 @@ class MetaSeo_Admin {
1443
  __('Content meta', 'wp-meta-seo'),
1444
  $manage_options_cap,
1445
  'metaseo_content_meta',
1446
- array($this, 'load_page'),
1447
  null,
1448
  ),
1449
  array(
@@ -1452,7 +2405,7 @@ class MetaSeo_Admin {
1452
  __('Sitemap', 'wp-meta-seo'),
1453
  $manage_options_cap,
1454
  'metaseo_google_sitemap',
1455
- array($this, 'load_page'),
1456
  null,
1457
  ),
1458
  array(
@@ -1461,7 +2414,7 @@ class MetaSeo_Admin {
1461
  __('Image information', 'wp-meta-seo'),
1462
  $manage_options_cap,
1463
  'metaseo_image_meta',
1464
- array($this, 'load_page'),
1465
  null,
1466
  ),
1467
  array(
@@ -1470,7 +2423,7 @@ class MetaSeo_Admin {
1470
  __('Image compression', 'wp-meta-seo'),
1471
  $manage_options_cap,
1472
  'metaseo_image_compression',
1473
- array($this, 'load_page'),
1474
  null,
1475
  ),
1476
  array(
@@ -1479,7 +2432,7 @@ class MetaSeo_Admin {
1479
  __('Link editor', 'wp-meta-seo'),
1480
  $manage_options_cap,
1481
  'metaseo_link_meta',
1482
- array($this, 'load_page'),
1483
  null,
1484
  ),
1485
  array(
@@ -1488,7 +2441,7 @@ class MetaSeo_Admin {
1488
  __('404 & Redirects', 'wp-meta-seo'),
1489
  $manage_options_cap,
1490
  'metaseo_broken_link',
1491
- array($this, 'load_page'),
1492
  null,
1493
  ),
1494
  array(
@@ -1497,7 +2450,7 @@ class MetaSeo_Admin {
1497
  __('Google Analytics', 'wp-meta-seo'),
1498
  $manage_options_cap,
1499
  'metaseo_google_analytics',
1500
- array($this, 'load_page'),
1501
  null,
1502
  ),
1503
  array(
@@ -1506,7 +2459,7 @@ class MetaSeo_Admin {
1506
  __('Settings', 'wp-meta-seo'),
1507
  $manage_options_cap,
1508
  'metaseo_settings',
1509
- array($this, 'load_page'),
1510
  null,
1511
  ),
1512
  );
@@ -1517,12 +2470,19 @@ class MetaSeo_Admin {
1517
  // Loop through submenu pages and add them
1518
  if (count($submenu_pages)) {
1519
  foreach ($submenu_pages as $submenu_page) {
1520
-
1521
  // Add submenu page
1522
- $admin_page = add_submenu_page($submenu_page[0], $submenu_page[2] . ' - ' . __('WP Meta SEO:', 'wp-meta-seo'), $submenu_page[2], $submenu_page[3], $submenu_page[4], $submenu_page[5]);
 
 
 
 
 
 
 
1523
 
1524
  // Check if we need to hook
1525
- if (isset($submenu_page[6]) && null != $submenu_page[6] && is_array($submenu_page[6]) && count($submenu_page[6]) > 0) {
 
1526
  foreach ($submenu_page[6] as $submenu_page_action) {
1527
  add_action('load-' . $admin_page, $submenu_page_action);
1528
  }
@@ -1536,119 +2496,141 @@ class MetaSeo_Admin {
1536
  }
1537
  }
1538
 
1539
- public function set_error_timeout() {
 
 
 
 
1540
  $midnight = strtotime("tomorrow 00:00:00"); // UTC midnight
1541
  $midnight = $midnight + 8 * 3600; // UTC 8 AM
1542
  $this->error_timeout = $midnight - time();
1543
  return;
1544
  }
1545
 
1546
- public function refresh_profiles() {
 
 
 
 
 
 
1547
  try {
1548
-
1549
  $ga_dash_profile_list = array();
1550
  $startindex = 1;
1551
  $totalresults = 65535; // use something big
1552
  while ($startindex < $totalresults) {
1553
-
1554
- $profiles = $this->service->management_profiles->listManagementProfiles('~all', '~all', array('start-index' => $startindex));
 
 
 
 
 
1555
  $items = $profiles->getItems();
1556
 
1557
  $totalresults = $profiles->getTotalResults();
1558
 
1559
  if ($totalresults > 0) {
1560
-
1561
  foreach ($items as $profile) {
1562
  $timetz = new DateTimeZone($profile->getTimezone());
1563
  $localtime = new DateTime('now', $timetz);
1564
  $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
1565
- $ga_dash_profile_list[] = array($profile->getName(), $profile->getId(), $profile->getwebPropertyId(), $profile->getwebsiteUrl(), $timeshift, $profile->getTimezone(), $profile->getDefaultPage());
 
 
 
 
 
 
 
 
1566
  $startindex++;
1567
  }
1568
  }
1569
  }
1570
 
1571
  if (empty($ga_dash_profile_list)) {
1572
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': No properties were found in this account!', $this->error_timeout);
 
 
 
 
1573
  } else {
1574
- WPMSGA_Tools::delete_cache('last_error');
1575
  }
1576
  return $ga_dash_profile_list;
1577
  } catch (Google_IO_Exception $e) {
1578
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
 
 
 
 
1579
  return $ga_dash_profile_list;
1580
  } catch (Google_Service_Exception $e) {
1581
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
1582
- WPMSGA_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
 
 
 
 
 
 
 
 
 
1583
  } catch (Exception $e) {
1584
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
 
 
 
 
1585
  return $ga_dash_profile_list;
1586
  }
1587
  }
1588
 
1589
- public static function guess_default_domain($profiles) {
1590
- $domain = get_option('siteurl');
1591
- $domain = str_ireplace(array('http://', 'https://'), '', $domain);
1592
- if (!empty($profiles)) {
1593
- foreach ($profiles as $items) {
1594
- if (strpos($items[3], $domain)) {
1595
- return $items[1];
1596
- }
1597
- }
1598
- return $profiles[0][1];
1599
- } else {
1600
- return '';
1601
- }
1602
- }
1603
-
1604
- public static function get_selected_profile($profiles, $profile) {
1605
- if (!empty($profiles)) {
1606
- foreach ($profiles as $item) {
1607
- if ($item[1] == $profile) {
1608
- return $item;
1609
- }
1610
- }
1611
- }
1612
- }
1613
-
1614
  /**
1615
  * Load the form for a WPSEO admin page
1616
  */
1617
- function load_page() {
 
1618
  if (isset($_GET['page'])) {
1619
  switch ($_GET['page']) {
1620
  case 'metaseo_google_analytics':
1621
- $message_ublock = "<div class='error wpms_msg_ublock'><p>" . __('It seems that you use an adblocker, you need to deactivate it for this page in order to load the Google Analytics scripts. ', 'wp-meta-seo' ) . ".</p></div>";
 
 
 
1622
  echo $message_ublock;
1623
  $this->google_alanytics = get_option('wpms_google_alanytics');
1624
- if(isset($_POST['_metaseo_ggtracking_settings'])) {
1625
- update_option ('_metaseo_ggtracking_settings', $_POST['_metaseo_ggtracking_settings']);
1626
- echo '<div id="setting-error-settings_updated" class="updated settings-error notice is-dismissible">
1627
- <p><strong>'.__('Settings saved.','wp-meta-seo').'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
 
 
1628
  }
1629
-
1630
- if(!empty($_POST['tableid_jail'])) {
1631
  $this->google_alanytics['tableid_jail'] = $_POST['tableid_jail'];
1632
- update_option ('wpms_google_alanytics', $this->google_alanytics);
1633
  }
1634
-
1635
-
1636
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
1637
  if (is_array($ga_tracking)) {
1638
  $this->ga_tracking = array_merge($this->ga_tracking, $ga_tracking);
1639
  }
1640
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php' );
1641
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php' );
1642
  wp_enqueue_style('m-style-qtip');
1643
  wp_enqueue_script('jquery-qtip');
1644
- if(isset($_GET['view']) && $_GET['view'] == 'wpmsga_trackcode'){
1645
  wp_enqueue_style('wpms-backend-tracking-code');
1646
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/metaseo-google-analytics-trackcode.php' );
1647
- }else{
1648
  wp_enqueue_style('wpms-backend-item-reports');
1649
 
1650
 
1651
- if(isset($_POST['wpmsga_dash_clientid']) && isset($_POST['wpmsga_dash_clientsecret'])){
1652
  $this->google_alanytics['wpmsga_dash_clientid'] = $_POST['wpmsga_dash_clientid'];
1653
  $this->google_alanytics['wpmsga_dash_clientsecret'] = $_POST['wpmsga_dash_clientsecret'];
1654
  update_option('wpms_google_alanytics', $this->google_alanytics);
@@ -1662,153 +2644,186 @@ class MetaSeo_Admin {
1662
  $this->client->setAccessType('offline');
1663
  $this->client->setApplicationName('WP Meta SEO');
1664
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
1665
- $this->set_error_timeout();
1666
- $this->client = WPMSGA_Tools::setClient($this->client , $this->google_alanytics , $this->access);
1667
  $authUrl = $this->client->createAuthUrl();
1668
  $this->service = new Google_Service_Analytics($this->client);
1669
- $wpmsga_controller = new WPMS_GAPI_Controller();
1670
 
1671
  if (!empty($_POST['wpms_ga_code'])) {
1672
  if (!stripos('x' . $_POST['wpms_ga_code'], 'UA-', 1) == 1) {
1673
-
1674
- WPMSGA_Tools::delete_cache('gapi_errors');
1675
- WPMSGA_Tools::delete_cache('last_error');
1676
- WPMSGA_Tools::clear_cache();
1677
  try {
1678
  $this->client->authenticate($_POST['wpms_ga_code']);
1679
- $getAccessToken = $this->client->getAccessToken();
1680
- if ( $getAccessToken ) {
1681
- try {
1682
- $this->client->setAccessToken( $getAccessToken );
1683
- $this->google_alanytics['googleCredentials'] = $this->client->getAccessToken();
1684
- } catch ( Google_IO_Exception $e ) {
1685
- WPMSGA_Tools::set_cache( 'wpmsga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
1686
- } catch ( Google_Service_Exception $e ) {
1687
- WPMSGA_Tools::set_cache( 'wpmsga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
1688
- WPMSGA_Tools::set_cache( 'wpmsga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
1689
- $this->reset_token();
1690
- } catch ( Exception $e ) {
1691
- WPMSGA_Tools::set_cache( 'wpmsga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
1692
- $this->reset_token();
1693
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1694
  }
1695
-
1696
  if (!empty($this->google_alanytics['profile_list'])) {
1697
  $profiles = $this->google_alanytics['profile_list'];
1698
  } else {
1699
- $profiles = $this->refresh_profiles();
1700
  }
1701
-
1702
  $this->google_alanytics['code'] = $_POST['wpms_ga_code'];
1703
  $this->google_alanytics['googleCredentials'] = $getAccessToken;
1704
  $this->google_alanytics['profile_list'] = $profiles;
1705
  update_option('wpms_google_alanytics', $this->google_alanytics);
1706
-
1707
  } catch (Google_IO_Exception $e) {
1708
- return false;
1709
  } catch (Google_Service_Exception $e) {
1710
- return $e->getCode();
1711
  } catch (Exception $e) {
1712
-
1713
  }
1714
  } else {
1715
- echo "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'wp-meta-seo') . ".</p></div>";
 
 
1716
  }
1717
 
1718
-
1719
  update_option('wpms_google_alanytics', $this->google_alanytics);
1720
- wp_redirect( admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') );
1721
  exit;
1722
  }
1723
- $this->ga_tracking_disconnect = array(
1724
  'wpms_ga_uax_reference' => '',
1725
  'wpmsga_dash_tracking_type' => 'classic',
1726
  'wpmsga_code_tracking' => ''
1727
  );
1728
- $ga_tracking_disconnect = get_option('_metaseo_ggtracking_disconnect_settings');
1729
- if (is_array($ga_tracking_disconnect)) {
1730
- $this->ga_tracking_disconnect = array_merge($this->ga_tracking_disconnect, $ga_tracking_disconnect);
 
 
 
1731
  }
1732
- if(isset($_POST['_metaseo_ga_disconnect'])){
1733
- update_option('_metaseo_ggtracking_disconnect_settings',$_POST['_metaseo_ga_disconnect']);
1734
- $ga_tracking_disconnect = get_option('_metaseo_ggtracking_disconnect_settings');
1735
- if (is_array($ga_tracking_disconnect)) {
1736
- $this->ga_tracking_disconnect = array_merge($this->ga_tracking_disconnect, $ga_tracking_disconnect);
 
 
 
1737
  }
1738
  }
1739
 
1740
  $this->google_alanytics = get_option('wpms_google_alanytics');
1741
  if (!empty($this->google_alanytics['googleCredentials'])) {
1742
- if ( empty($this->ga_tracking['wpmsga_dash_tracking'])) {
1743
- $message = "<div class='error'><p>" . __( "The tracking component is disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'wp-meta-seo' ) . ".</p></div>";
 
 
1744
  echo $message;
1745
  }
1746
  echo '<div class="wrap wpmsga_wrap">';
1747
  echo '<div>';
1748
- require_once ( WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php' );
1749
- echo '<h2>'.__("Google Analytics Settings","wp-meta-seo").'</h2>';
1750
  echo '<div id="wpms-window-1"></div>';
1751
  echo '</div>';
1752
  echo '</div>';
1753
  } else {
1754
- if ( empty($this->ga_tracking['wpmsga_dash_tracking'])) {
1755
- $message = "<div class='error'><p>" . __( "The tracking component is disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'wp-meta-seo' ) . ".</p></div>";
 
 
1756
  echo $message;
1757
  }
1758
-
1759
- if(isset($this->google_alanytics['wpmsga_dash_userapi']) && $this->google_alanytics['wpmsga_dash_userapi'] == 1){
1760
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/metaseo-form-clientID.php' );
1761
- }else{
1762
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/metaseo-google-analytics.php' );
 
1763
  }
1764
  }
1765
  }
1766
 
1767
  $w = '99%';
1768
- $text = __('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report, Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!','wp-meta-seo');
 
1769
  $class_btn_close = 'close_gga';
1770
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php' );
1771
  break;
1772
  case 'metaseo_google_sitemap':
1773
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1774
  // remove filter by lang
1775
  if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
1776
  global $sitepress;
1777
- remove_filter('terms_clauses', array($sitepress,'terms_clauses'));
1778
- }elseif(is_plugin_active('polylang/polylang.php')){
1779
  global $polylang;
1780
  $filters_term = $polylang->filters_term;
1781
  remove_filter('terms_clauses', array($filters_term, 'terms_clauses'));
1782
  }
1783
  }
1784
 
1785
- if (!class_exists('MetaSeo_Content_List_Table')) {
1786
- require_once( WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-sitemap.php' );
1787
  }
1788
 
1789
- $metaseo_sitemap = new MetaSeo_Sitemap();
1790
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/sitemaps/metaseo-google-sitemap.php' );
1791
  break;
1792
  case 'metaseo_image_compression':
1793
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-image-compression.php' );
1794
  break;
1795
  case 'metaseo_broken_link':
1796
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php' );
1797
  break;
1798
  case 'metaseo_settings':
1799
  $posts = get_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'numberposts' => -1));
1800
- $types_404 = array('none' => 'None', 'wp-meta-seo-page' => __('WP Meta SEO page', 'wp-meta-seo'), 'custom_page' => __('Custom page', 'wp-meta-seo'));
 
 
 
 
1801
 
1802
  // get settings 404
1803
- $defaul_settings_404 = array('wpms_redirect_homepage' => 0, 'wpms_type_404' => 'none', 'wpms_page_redirected' => 'none');
 
 
 
 
1804
  $wpms_settings_404 = get_option('wpms_settings_404');
1805
  if (is_array($wpms_settings_404)) {
1806
  $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404);
1807
  }
1808
 
1809
  // get settings breadcrumb
1810
- $home_title = get_the_title( get_option('page_on_front') );
1811
- if(empty($home_title)) $home_title = get_bloginfo('title');
 
 
1812
  $breadcrumbs = array(
1813
  'separator' => ' &gt; ',
1814
  'include_home' => 1,
@@ -1823,13 +2838,13 @@ class MetaSeo_Admin {
1823
 
1824
  // email settings
1825
  $email_settings = array(
1826
- "enable" => 0,
1827
- "host" => "smtp.gmail.com",
1828
- "type_encryption" => "ssl",
1829
- "port" => "465",
1830
- "autentication" => "yes",
1831
- "username" => "",
1832
- "password" => "",
1833
  );
1834
 
1835
  $mailsettings = get_option('wpms_email_settings');
@@ -1837,7 +2852,7 @@ class MetaSeo_Admin {
1837
  $email_settings = array_merge($email_settings, $mailsettings);
1838
  }
1839
 
1840
- $html_tabemail = apply_filters('wpmsaddon_emailsettings','',$email_settings);
1841
 
1842
  // link settings
1843
  $link_settings = array(
@@ -1851,7 +2866,7 @@ class MetaSeo_Admin {
1851
  $link_settings = array_merge($link_settings, $linksettings);
1852
  }
1853
 
1854
- $link_settings_html = apply_filters('wpmsaddon_linksettings','',$link_settings);
1855
 
1856
  // local business settings
1857
  $local_business = array(
@@ -1870,40 +2885,41 @@ class MetaSeo_Admin {
1870
  if (is_array($business)) {
1871
  $local_business = array_merge($local_business, $business);
1872
  }
1873
- $countrys = apply_filters('wpms_get_countryList',array());
1874
- $local_business_html = apply_filters('wpmsaddon_local_business','',$local_business,$countrys);
1875
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php' );
1876
  break;
1877
 
1878
  case 'metaseo_content_meta':
1879
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/content-meta.php' );
1880
  break;
1881
 
1882
 
1883
  case 'metaseo_image_meta':
1884
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/image-meta.php' );
1885
  break;
1886
 
1887
  case 'metaseo_link_meta':
1888
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/link-meta.php' );
1889
  break;
1890
 
1891
  case 'metaseo_image_optimize':
1892
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/image-optimize.php' );
1893
  break;
1894
 
1895
  case 'metaseo_dashboard':
1896
  default:
1897
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard.php' );
1898
  break;
1899
  }
1900
  }
1901
  }
1902
-
1903
- /*
1904
  * Ajax check attachment have alt empty
1905
  */
1906
- function wpms_ajax_check_exist() {
 
1907
  if (isset($_POST['type'])) {
1908
  if ($_POST['type'] == 'alt') {
1909
  $margs = array(
@@ -1927,7 +2943,11 @@ class MetaSeo_Admin {
1927
  }
1928
  } else {
1929
  global $wpdb;
1930
- $sql = $wpdb->prepare("SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts WHERE posts.post_type = %s AND post_title != %s",array('attachment',''));
 
 
 
 
1931
  $check_title = $wpdb->get_var($sql);
1932
  if ($check_title > 0) {
1933
  wp_send_json(true);
@@ -1937,36 +2957,33 @@ class MetaSeo_Admin {
1937
  }
1938
  }
1939
  }
1940
-
1941
- /*
1942
  * Ajax update image alt and image title
1943
  */
1944
- function wpms_bulk_image_copy() {
 
1945
  global $wpdb;
1946
- if (empty($_POST['mtype']))
1947
  wp_send_json(false);
 
 
1948
  if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') {
1949
  // select all
1950
  $limit = 500;
1951
- // check image alt and title empty
1952
- $margs = array(
1953
- 'posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'any'
1954
- );
1955
-
1956
- $m_newquery = new WP_Query($margs);
1957
- $mposts_empty_alt = $m_newquery->get_posts();
1958
- $sql = $wpdb->prepare("SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts WHERE posts.post_type = %s AND post_title = %s",array('attachment',''));
1959
- $check_title = $wpdb->get_var($sql);
1960
-
1961
  // query attachment and update meta
1962
- $sql = $wpdb->prepare("SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts WHERE posts.post_type = %s",array('attachment'));
 
 
 
 
1963
  $total = $wpdb->get_var($sql);
1964
 
1965
- $j = ceil((int) $total / $limit);
1966
  for ($i = 0; $i <= $j; $i++) {
1967
  $ofset = $i * $limit;
1968
  $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts as posts
1969
- WHERE posts.post_type = %s LIMIT %d OFFSET %d",array('attachment',$limit,$ofset));
1970
  $attachments = $wpdb->get_results($sql);
1971
 
1972
  foreach ($attachments as $attachment) {
@@ -2033,18 +3050,29 @@ class MetaSeo_Admin {
2033
  }
2034
  }
2035
  }
2036
-
2037
- /*
2038
  * Ajax bulk update meta title for a post/page
2039
  */
2040
- function wpms_bulk_post_copy_title() {
 
2041
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
2042
  unset($post_types['attachment']);
2043
- if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') {
 
2044
  $margs = array(
2045
  'posts_per_page' => -1,
2046
  'post_type' => $post_types,
2047
- 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
 
 
 
 
 
 
 
 
 
2048
  'meta_query' => array(
2049
  'relation' => 'OR',
2050
  array(
@@ -2056,14 +3084,23 @@ class MetaSeo_Admin {
2056
  'value' => false,
2057
  'type' => 'BOOLEAN'
2058
  ),
2059
- ));
2060
- } else {
2061
  if (isset($_POST['ids'])) {
2062
  $ids = $_POST['ids'];
2063
  $margs = array(
2064
  'posts_per_page' => -1,
2065
  'post_type' => $post_types,
2066
- 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
 
 
 
 
 
 
 
 
 
2067
  'post__in' => $ids,
2068
  'meta_query' => array(
2069
  'relation' => 'OR',
@@ -2076,7 +3113,7 @@ class MetaSeo_Admin {
2076
  'value' => false,
2077
  'type' => 'BOOLEAN'
2078
  ),
2079
- ));
2080
  } else {
2081
  wp_send_json(false);
2082
  }
@@ -2090,7 +3127,6 @@ class MetaSeo_Admin {
2090
  }
2091
  wp_send_json(true);
2092
  } else {
2093
-
2094
  wp_send_json(false);
2095
  }
2096
  }
@@ -2098,56 +3134,131 @@ class MetaSeo_Admin {
2098
  /**
2099
  * set cookie notification
2100
  */
2101
- public function wpms_setcookie_notification(){
2102
- if(isset($_POST['page'])){
 
2103
  setcookie($_POST['page'], time(), time() + (86400 * 30), "/");
2104
  wp_send_json(true);
2105
  }
2106
  wp_send_json(false);
2107
  }
2108
-
2109
- /*
2110
- * Add ajax
2111
- */
2112
- private function ajaxHandle() {
2113
- add_action('wp_ajax_scanPosts', array('MetaSeo_Image_List_Table', 'scan_posts_callback'));
2114
- add_action('wp_ajax_load_posts', array('MetaSeo_Image_List_Table', 'load_posts_callback'));
2115
- add_action('wp_ajax_optimize_imgs', array('MetaSeo_Image_List_Table', 'optimizeImages'));
2116
- add_action('wp_ajax_updateMeta', array('MetaSeo_Image_List_Table', 'updateMeta_callback'));
2117
- add_action('wp_ajax_import_meta_data', array('MetaSeo_Content_List_Table', 'importMetaData'));
2118
- add_action('wp_ajax_dismiss_import_meta', array('MetaSeo_Content_List_Table', 'dismissImport'));
2119
- add_action('wp_ajax_wpms_bulk_post_copy', array($this, 'wpms_bulk_post_copy_title'));
2120
- add_action('wp_ajax_wpms_bulk_image_copy', array($this, 'wpms_bulk_image_copy'));
2121
- add_action('wp_ajax_wpms_ajax_check_exist', array($this, 'wpms_ajax_check_exist'));
2122
- add_action('added_post_meta', array('MetaSeo_Content_List_Table', 'updateMetaSync'), 99, 4);
2123
- add_action('updated_post_meta', array('MetaSeo_Content_List_Table', 'updateMetaSync'), 99, 4);
2124
- add_action('deleted_post_meta', array('MetaSeo_Content_List_Table', 'deleteMetaSync'), 99, 4);
2125
- add_action('wp_ajax_metaseo_reload_analysis', array($this, 'metaseo_reload_analysis'));
2126
- add_action('wp_ajax_metaseo_validate_analysis', array($this, 'metaseo_validate_analysis'));
2127
- add_action('wp_ajax_metaseo_update_link', array($this, 'metaseo_update_link'));
2128
- add_action('wp_ajax_wpms_save_settings404', array($this, 'wpms_save_settings404'));
2129
- add_action('wp_ajax_wpms_save_settings_breadcrumb', array($this, 'wpms_save_settings_breadcrumb'));
2130
- add_action('wp_ajax_wpms_update_link', array('MetaSeo_Broken_Link_Table', 'wpms_update_link'));
2131
- add_action('wp_ajax_wpms_add_custom_redirect', array('MetaSeo_Broken_Link_Table', 'wpms_add_custom_redirect'));
2132
- add_action('wp_ajax_wpms_unlink', array('MetaSeo_Broken_Link_Table', 'wpms_unlink'));
2133
- add_action('wp_ajax_wpms_recheck_link', array('MetaSeo_Broken_Link_Table', 'wpms_recheck_link'));
2134
- add_action('wp_ajax_wpms_scan_link', array('MetaSeo_Broken_Link_Table', 'wpms_scan_link'));
2135
- add_action('wp_ajax_wpms_flush_link', array('MetaSeo_Broken_Link_Table', 'wpms_flush_link'));
2136
- add_action('wp_ajax_metaseo_update_follow', array($this, 'metaseo_update_follow'));
2137
- add_action('wp_ajax_metaseo_update_multiplefollow', array($this, 'metaseo_update_multiplefollow'));
2138
- add_action('wp_ajax_metaseo_update_pagefollow', array($this, 'metaseo_update_pagefollow'));
2139
- add_action('wp_ajax_metaseo_update_pageindex', array($this, 'metaseo_update_pageindex'));
2140
- add_action('wp_ajax_wpms_backend_item_reports', array('MetaSeo_Google_Analytics', 'ajax_item_reports'));
2141
- add_action('wp_ajax_wpmsga_wpmsClearauthor', array('MetaSeo_Google_Analytics', 'wpmsga_wpmsClearauthor'));
2142
- add_action('wp_ajax_wpmsga_update_option', array('MetaSeo_Google_Analytics', 'wpmsga_update_option'));
2143
-
2144
- add_action('wp_ajax_wpms_dash_permalink', array('MetaSeo_Dashboard', 'wpms_dash_permalink'));
2145
- add_action('wp_ajax_wpms_dash_newcontent', array('MetaSeo_Dashboard', 'wpms_dash_newcontent'));
2146
- add_action('wp_ajax_wpms_dash_linkmeta', array('MetaSeo_Dashboard', 'wpms_dash_linkmeta'));
2147
- add_action('wp_ajax_wpms_dash_metatitle', array('MetaSeo_Dashboard', 'wpms_dash_metatitle'));
2148
- add_action('wp_ajax_wpms_dash_metadesc', array('MetaSeo_Dashboard', 'wpms_dash_metadesc'));
2149
- add_action('wp_ajax_wpms_dash_imgsmeta', array('MetaSeo_Dashboard', 'wpms_dash_imgsmeta'));
2150
- add_action('wp_ajax_wpms_setcookie_notification', array($this, 'wpms_setcookie_notification'));
2151
- add_action('wp_ajax_wpms_image_scan_meta', array('MetaSeo_Image_List_Table', 'wpms_image_scan_meta'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2152
  }
2153
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+
5
  /**
6
+ * Class MetaSeoAdmin
7
  * Class that holds most of the admin functionality for Meta SEO.
8
  */
9
+ class MetaSeoAdmin
10
+ {
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 = 156;
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
+
69
+ /**
70
+ * MetaSeoAdmin constructor.
71
+ */
72
+ public function __construct()
73
+ {
74
+ $this->pagenow = $GLOBALS['pagenow'];
75
+ $this->setErrorTimeout();
76
+ $this->initSettings();
77
+ $this->initGaSettings();
78
+ if (!get_option('_wpms_dash_last_update', false)) {
79
+ update_option('_wpms_dash_last_update', time());
80
+ }
81
+
82
+ add_action('admin_init', array($this, 'adminInit'));
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);
90
+ add_action('deleted_post_meta', array('MetaSeoContentListTable', 'deleteMetaSync'), 99, 4);
91
+ if (!get_option('wpms_set_ignore', false)) {
92
+ add_option('wpms_set_ignore', 1, '', 'yes');
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);
100
+ add_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'), 10, 3);
101
+ add_action('delete_post', array('MetaSeoBrokenLinkTable', 'deletePost'));
102
+ add_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
103
+ add_action('deleted_comment', array('MetaSeoBrokenLinkTable', 'deletedComment'));
104
+
105
+ add_action('admin_footer', array($this, 'editorFooter'));
106
+ add_action('wp_dashboard_setup', array($this, 'addDashboardWidgets'));
107
+ add_action('category_add_form_fields', array($this, 'categoryField'), 10, 2);
108
+ add_action('edit_category_form_fields', array($this, 'editCategoryFields'));
109
+ add_action('edited_category', array($this, 'saveCategoryMeta'), 10, 2);
110
+ add_action('create_category', array($this, 'saveCategoryMeta'), 10, 2);
111
+ add_action('post_updated', array('MetaSeoImageListTable', 'updatePost'), 10, 3);
112
+ add_action('delete_post', array('MetaSeoImageListTable', 'deleteAttachment'));
113
+
114
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
115
+ add_action('product_cat_add_form_fields', array($this, 'categoryField'));
116
+ add_action('product_cat_edit_form_fields', array($this, 'editCategoryFields'), 10);
117
+ add_action('created_term', array($this, 'saveCategoryMeta'), 10, 3);
118
+ add_action('edit_term', array($this, 'saveCategoryMeta'), 10, 3);
119
+ }
120
+ add_action('wp_ajax_wpms', array($this, 'startProcess'));
121
+ }
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" => "",
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',
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
+ {
204
+ wp_enqueue_style(
205
+ 'm-style-qtip',
206
+ plugins_url('css/jquery.qtip.css', dirname(__FILE__)),
207
+ array(),
208
+ WPMSEO_VERSION
209
+ );
210
+
211
+ wp_enqueue_script(
212
+ 'jquery-qtip',
213
+ plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)),
214
+ array('jquery'),
215
+ '2.2.1',
216
+ true
217
+ );
218
  wp_enqueue_style('wpms-category-field');
219
  wp_enqueue_script('wpms-category-field');
220
  // this will add the custom meta field to the add new term page
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']);
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
+ {
295
+ wp_enqueue_style(
296
+ 'm-style-qtip',
297
+ plugins_url('css/jquery.qtip.css', dirname(__FILE__)),
298
+ array(),
299
+ WPMSEO_VERSION
300
+ );
301
+ wp_enqueue_script(
302
+ 'jquery-qtip',
303
+ plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)),
304
+ array('jquery'),
305
+ '2.2.1',
306
+ true
307
+ );
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>
332
+ <?php endif; ?>
333
+ <br/>
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>
341
  </tr>
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>
363
+ <?php endif; ?>
364
+ <br/>
365
+ </label>
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>
373
+ </tr>
374
  <?php endif; ?>
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>
400
  <?php
401
  }
402
 
403
+ /**
404
+ * Function that outputs the contents of the dashboard widget
405
+ */
406
+ public function dashboardWidget()
407
+ {
408
+ wp_enqueue_style(
409
+ 'm-style-qtip',
410
+ plugins_url('css/jquery.qtip.css', dirname(__FILE__)),
411
+ array(),
412
+ WPMSEO_VERSION
413
+ );
414
+ wp_enqueue_script(
415
+ 'jquery-qtip',
416
+ plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)),
417
+ array('jquery'),
418
+ '2.2.1',
419
+ true
420
+ );
421
  wp_enqueue_style('wpms-dashboard-widgets');
422
+ wp_enqueue_script(
423
+ 'wpms-dashboard-widgets',
424
+ plugins_url('js/dashboard_widgets.js', dirname(__FILE__)),
425
+ array('jquery'),
426
+ WPMSEO_VERSION
427
+ );
428
  wp_enqueue_style('wpms-myqtip');
429
+ $error_404 = MetaSeoDashboard::get404Link();
430
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard_widgets.php');
431
  }
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'
445
+ )
446
+ );
447
  }
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);
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)) {
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',
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(
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__)),
599
+ array('wplink'),
600
+ WPMSEO_VERSION,
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
+ {
614
  if (!current_user_can('manage_options')) {
615
  wp_send_json(false);
616
  }
617
  update_option('wpms_set_ignore', 0);
618
  wp_send_json(true);
619
  }
620
+
621
+ /**
622
  * Render message error when disable search engines from indexing this site
623
  */
624
+ public function publicWarning()
625
+ {
626
+ if ((function_exists('is_network_admin') && is_network_admin())) {
627
  return;
628
  }
629
 
631
  return;
632
  }
633
 
634
+ printf(
635
+ '<div id="robotsmessage" class="error">
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  <p>
637
  <strong>%1$s</strong>
638
  %2$s
639
+ <a href="javascript:wpmsIgnore(\'wpms_public_warning\',\'robotsmessage\',\'%3$s\');"
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
+ {
659
+ load_plugin_textdomain(
660
+ 'wp-meta-seo',
661
+ false,
662
+ dirname(plugin_basename(__FILE__)) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR
663
+ );
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
+ <i class="metaseo-dashicons material-icons dashicons-before"
678
+ style="' . ($dashicon == 'done' ? 'color:#46B450' : 'color:#FFB900') . '">
679
+ ' . $dashicon . '</i>' . $label . '</div>';
680
+ $output .= '<input type="hidden" class="wpms_analysis_hidden"
681
+ name="wpms[' . $data_title . ']" value="' . $value_hidden . '">';
682
  return $output;
683
  }
684
+
685
+ /**
686
+ * Ajax load page analysis
687
  */
688
+ public function reloadAnalysis()
689
+ {
690
  if (!current_user_can('manage_options')) {
691
  wp_send_json(array('status' => false));
692
  }
693
  $tooltip_page = array();
694
+ $tooltip_page['title_in_heading'] = __('Check if a word of this content title
695
+ is also in a title heading (h1, h2...)', 'wp-meta-seo');
696
+ $tooltip_page['title_in_content'] = __('Check if a word of this content
697
+ title is also in the text', 'wp-meta-seo');
698
  $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
699
  $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
700
  $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
701
+ $tooltip_page['image_resize'] = __('Check for image HTML resizing in content
702
+ (usually image resized using handles)', 'wp-meta-seo');
703
  $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
704
  if (empty($_POST['datas'])) {
705
  wp_send_json(false);
713
  $output = '';
714
 
715
  // title heading
716
+ $words_post_title = preg_split(
717
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
718
+ strtolower($_POST['datas']['title']),
719
+ -1,
720
+ PREG_SPLIT_NO_EMPTY
721
+ );
722
  if ($_POST['datas']['content'] == '') {
723
+ $output .= $this->createFieldAnalysis(
724
+ 'heading_title',
725
+ $tooltip_page['title_in_heading'],
726
+ 'warning',
727
+ __('Page title word in content heading', 'wp-meta-seo'),
728
+ 0
729
+ );
730
  } else {
731
  $dom = new DOMDocument;
732
  libxml_use_internal_errors(true);
733
+ $content = apply_filters(
734
+ 'the_content',
735
+ '<div>' . html_entity_decode(stripcslashes($_POST['datas']['content'])) . '</div>'
736
+ );
737
  if ($dom->loadHTML($content)) {
738
  // Extracting the specified elements from the web page
739
+ $tags_h1 = (array)$dom->getElementsByTagName('h1');
740
+ $tags_h2 = (array)$dom->getElementsByTagName('h2');
741
+ $tags_h3 = (array)$dom->getElementsByTagName('h3');
742
+ $tags_h4 = (array)$dom->getElementsByTagName('h4');
743
+ $tags_h5 = (array)$dom->getElementsByTagName('h5');
744
+ $tags_h6 = (array)$dom->getElementsByTagName('h6');
745
 
746
  $test = false;
747
+ if (count($tags_h1) == 0 && count($tags_h2) == 0 && count($tags_h3) == 0
748
+ && count($tags_h4) == 0 && count($tags_h5) == 0 && count($tags_h6) == 0) {
749
  $test = false;
750
  } else {
751
  // check tag h1
752
  if (!empty($tags_h1)) {
753
  foreach ($tags_h1 as $order => $tagh1) {
754
+ $words_tagh1 = preg_split(
755
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
756
+ utf8_decode(strtolower($tagh1->nodeValue)),
757
+ -1,
758
+ PREG_SPLIT_NO_EMPTY
759
+ );
760
  if (is_array($words_tagh1) && is_array($words_post_title)) {
761
  foreach ($words_tagh1 as $mh) {
762
  if (in_array($mh, $words_post_title) && $mh != '') {
770
  // check tag h2
771
  if (!empty($tags_h2)) {
772
  foreach ($tags_h2 as $order => $tagh2) {
773
+ $words_tagh2 = preg_split(
774
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
775
+ utf8_decode(strtolower($tagh2->nodeValue)),
776
+ -1,
777
+ PREG_SPLIT_NO_EMPTY
778
+ );
779
  if (is_array($words_tagh2) && is_array($words_post_title)) {
780
  foreach ($words_tagh2 as $mh) {
781
  if (in_array($mh, $words_post_title) && $mh != '') {
785
  }
786
  }
787
  }
788
+
789
  // check tag h3
790
  if (!empty($tags_h3)) {
791
  foreach ($tags_h3 as $order => $tagh3) {
792
+ $words_tagh3 = preg_split(
793
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
794
+ utf8_decode(strtolower($tagh3->nodeValue)),
795
+ -1,
796
+ PREG_SPLIT_NO_EMPTY
797
+ );
798
  if (is_array($words_tagh3) && is_array($words_post_title)) {
799
  foreach ($words_tagh3 as $mh) {
800
  if (in_array($mh, $words_post_title) && $mh != '') {
804
  }
805
  }
806
  }
807
+
808
  // check tag h4
809
  if (!empty($tags_h4)) {
810
  foreach ($tags_h4 as $order => $tagh4) {
811
+ $words_tagh4 = preg_split(
812
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
813
+ utf8_decode(strtolower($tagh4->nodeValue)),
814
+ -1,
815
+ PREG_SPLIT_NO_EMPTY
816
+ );
817
  if (is_array($words_tagh4) && is_array($words_post_title)) {
818
  foreach ($words_tagh4 as $mh) {
819
  if (in_array($mh, $words_post_title) && $mh != '') {
823
  }
824
  }
825
  }
826
+
827
  // check tag h5
828
  if (!empty($tags_h5)) {
829
  foreach ($tags_h5 as $order => $tagh5) {
830
+ $words_tagh5 = preg_split(
831
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
832
+ utf8_decode(strtolower($tagh5->nodeValue)),
833
+ -1,
834
+ PREG_SPLIT_NO_EMPTY
835
+ );
836
  if (is_array($words_tagh5) && is_array($words_post_title)) {
837
  foreach ($words_tagh5 as $mh) {
838
  if (in_array($mh, $words_post_title) && $mh != '') {
842
  }
843
  }
844
  }
845
+
846
  // check tag h6
847
  if (!empty($tags_h6)) {
848
  foreach ($tags_h6 as $order => $tagh6) {
849
+ $words_tagh6 = preg_split(
850
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
851
+ utf8_decode(strtolower($tagh6->nodeValue)),
852
+ -1,
853
+ PREG_SPLIT_NO_EMPTY
854
+ );
855
  if (is_array($words_tagh6) && is_array($words_post_title)) {
856
  foreach ($words_tagh6 as $mh) {
857
  if (in_array($mh, $words_post_title) && $mh != '') {
864
  }
865
 
866
  if ($test || (!empty($meta_analysis) && !empty($meta_analysis['heading_title']))) {
867
+ $output .= $this->createFieldAnalysis(
868
+ 'heading_title',
869
+ $tooltip_page['title_in_heading'],
870
+ 'done',
871
+ __('Page title word in content heading', 'wp-meta-seo'),
872
+ 1
873
+ );
874
+ $check++;
875
  } else {
876
+ $output .= $this->createFieldAnalysis(
877
+ 'heading_title',
878
+ $tooltip_page['title_in_heading'],
879
+ 'warning',
880
+ __('Page title word in content heading', 'wp-meta-seo'),
881
+ 0
882
+ );
883
  }
884
  } else {
885
+ $output .= $this->createFieldAnalysis(
886
+ 'heading_title',
887
+ $tooltip_page['title_in_heading'],
888
+ 'warning',
889
+ __('Page title word in content heading', 'wp-meta-seo'),
890
+ 0
891
+ );
892
  }
893
  }
894
 
895
  // title content
896
  $content = apply_filters('the_content', html_entity_decode(stripcslashes($_POST['datas']['content'])));
897
+ $words_title = preg_split(
898
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
899
+ strtolower($_POST['datas']['title']),
900
+ -1,
901
+ PREG_SPLIT_NO_EMPTY
902
+ );
903
+ $words_post_content = preg_split(
904
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
905
+ strtolower(strip_tags($content)),
906
+ -1,
907
+ PREG_SPLIT_NO_EMPTY
908
+ );
909
 
910
  $test1 = false;
911
  if (is_array($words_title) && is_array($words_post_content)) {
920
  }
921
 
922
  if ($test1) {
923
+ $output .= $this->createFieldAnalysis(
924
+ 'content_title',
925
+ $tooltip_page['title_in_content'],
926
+ 'done',
927
+ __('Page title word in content', 'wp-meta-seo'),
928
+ 1
929
+ );
930
+ $check++;
931
  } else {
932
+ $output .= $this->createFieldAnalysis(
933
+ 'content_title',
934
+ $tooltip_page['title_in_content'],
935
+ 'warning',
936
+ __('Page title word in content', 'wp-meta-seo'),
937
+ 0
938
+ );
939
  }
940
 
941
  // page url matches page title
942
  $mtitle = $_POST['datas']['title'];
943
  if ($_POST['datas']['mpageurl'] == sanitize_title($mtitle)) {
944
+ $output .= $this->createFieldAnalysis(
945
+ 'pageurl',
946
+ $tooltip_page['page_url'],
947
+ 'done',
948
+ __('Page url matches with page title', 'wp-meta-seo'),
949
+ 1
950
+ );
951
+ $check++;
952
  } else {
953
+ $output .= $this->createFieldAnalysis(
954
+ 'pageurl',
955
+ $tooltip_page['page_url'],
956
+ 'warning',
957
+ __('Page url matches with page title', 'wp-meta-seo'),
958
+ 0
959
+ );
960
  }
961
 
962
  // meta title filled
963
+ if (($_POST['datas']['meta_title'] != ''
964
+ && mb_strlen($_POST['datas']['meta_title'], 'UTF-8') <= self::$title_length)) {
965
+ $output .= $this->createFieldAnalysis(
966
+ 'metatitle',
967
+ $tooltip_page['meta_title'],
968
+ 'done',
969
+ __('Meta title filled', 'wp-meta-seo'),
970
+ 1
971
+ );
972
  $check++;
973
  } else {
974
+ $output .= $this->createFieldAnalysis(
975
+ 'metatitle',
976
+ $tooltip_page['meta_title'],
977
+ 'warning',
978
+ __('Meta title filled', 'wp-meta-seo'),
979
+ 0
980
+ );
981
  }
982
 
983
  // desc filled
984
+ if ($_POST['datas']['meta_desc'] != ''
985
+ && mb_strlen($_POST['datas']['meta_desc'], 'UTF-8') <= self::$desc_length) {
986
+ $output .= $this->createFieldAnalysis(
987
+ 'metadesc',
988
+ $tooltip_page['meta_desc'],
989
+ 'done',
990
+ __('Meta description filled', 'wp-meta-seo'),
991
+ 1
992
+ );
993
  $check++;
994
  } else {
995
+ $output .= $this->createFieldAnalysis(
996
+ 'metadesc',
997
+ $tooltip_page['meta_desc'],
998
+ 'warning',
999
+ __('Meta description filled', 'wp-meta-seo'),
1000
+ 0
1001
+ );
1002
  }
1003
 
1004
  // image resize
1005
  if ($_POST['datas']['content'] == '') {
1006
+ $output .= $this->createFieldAnalysis(
1007
+ 'imgresize',
1008
+ $tooltip_page['image_resize'],
1009
+ 'done',
1010
+ __('Wrong image resize', 'wp-meta-seo'),
1011
+ 1
1012
+ );
1013
+ $output .= $this->createFieldAnalysis(
1014
+ 'imgalt',
1015
+ $tooltip_page['image_alt'],
1016
+ 'done',
1017
+ __('Image have meta title or alt', 'wp-meta-seo'),
1018
+ 1
1019
+ );
1020
  $check += 2;
1021
  } else {
1022
  $dom = new DOMDocument;
1034
  $string_wh = substr($src, $b + 1, $e - $b - 1);
1035
  $array_wh = explode('x', $string_wh);
1036
  if (!empty($array_wh[0]) && !empty($array_wh[1])) {
1037
+ if (((int)$array_wh[0] != (int)$tag->getAttribute('width'))
1038
+ || ((int)$array_wh[1] != (int)$tag->getAttribute('height'))) {
1039
  $img_wrong = true;
1040
  }
1041
  }
1048
  }
1049
 
1050
  if ($img_wrong == false) {
1051
+ $output .= $this->createFieldAnalysis(
1052
+ 'imgresize',
1053
+ $tooltip_page['image_resize'],
1054
+ 'done',
1055
+ __('Wrong image resize', 'wp-meta-seo'),
1056
+ 1
1057
+ );
1058
  $check++;
1059
  } else {
1060
+ $output .= $this->createFieldAnalysis(
1061
+ 'imgresize',
1062
+ $tooltip_page['image_resize'],
1063
+ 'warning',
1064
+ __('Wrong image resize', 'wp-meta-seo'),
1065
+ 0
1066
+ );
1067
  }
1068
 
1069
  if ($img_wrong_alt == false) {
1070
+ $output .= $this->createFieldAnalysis(
1071
+ 'imgalt',
1072
+ $tooltip_page['image_alt'],
1073
+ 'done',
1074
+ __('Image have meta title or alt', 'wp-meta-seo'),
1075
+ 1
1076
+ );
1077
  $check++;
1078
  } else {
1079
+ $output .= $this->createFieldAnalysis(
1080
+ 'imgalt',
1081
+ $tooltip_page['image_alt'],
1082
+ 'warning',
1083
+ __('Image have meta title or alt', 'wp-meta-seo'),
1084
+ 0
1085
+ );
1086
  }
1087
  } else {
1088
+ $output .= $this->createFieldAnalysis(
1089
+ 'imgresize',
1090
+ $tooltip_page['image_resize'],
1091
+ 'warning',
1092
+ __('Wrong image resize', 'wp-meta-seo'),
1093
+ 0
1094
+ );
1095
+ $output .= $this->createFieldAnalysis(
1096
+ 'imgalt',
1097
+ $tooltip_page['image_alt'],
1098
+ 'warning',
1099
+ __('Image have meta title or alt', 'wp-meta-seo'),
1100
+ 0
1101
+ );
1102
  }
1103
  }
1104
 
1105
  $circliful = ceil(100 * ($check) / 7);
1106
  wp_send_json(array('circliful' => $circliful, 'output' => $output, 'check' => $check));
1107
  }
1108
+
1109
+ /**
1110
  * validate propertyin page optimization
1111
  */
1112
+ public function validateAnalysis()
1113
+ {
1114
  if (!current_user_can('manage_options')) {
1115
  wp_send_json(false);
1116
  }
1125
  update_post_meta($post_id, $key, $analysis);
1126
  wp_send_json(true);
1127
  }
1128
+
1129
+ /**
1130
  * Ajax update link meta title and content editor
1131
  */
1132
+ public function updateLink()
1133
+ {
1134
  if (!current_user_can('manage_options')) {
1135
  wp_send_json(false);
1136
  }
1137
  if (isset($_POST['link_id'])) {
1138
  global $wpdb;
1139
+ $sql = $wpdb->prepare(
1140
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1141
+ array(
1142
+ $_POST['link_id']
1143
+ )
1144
+ );
1145
  $link_detail = $wpdb->get_row($sql);
1146
+ if (empty($link_detail)) {
1147
  wp_send_json(false);
1148
+ }
1149
 
1150
  $value = array('meta_title' => $_POST['meta_title']);
1151
  $wpdb->update(
1152
+ $wpdb->prefix . 'wpms_links',
1153
+ $value,
1154
+ array('id' => $_POST['link_id'])
1155
  );
1156
 
1157
 
1158
  $post = get_post($link_detail->source_id);
1159
  if (!empty($post)) {
1160
  $old_value = $post->post_content;
1161
+ $edit_result = $this->editLinkHtml(
1162
+ $old_value,
1163
+ $link_detail->link_url,
1164
+ $link_detail->link_url,
1165
+ $_POST['meta_title'],
1166
+ $link_detail->follow
1167
+ );
1168
+
1169
  $my_post = array(
1170
  'ID' => $link_detail->source_id,
1171
  'post_content' => $edit_result['content']
1172
  );
1173
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1174
  wp_update_post($my_post);
1175
  wp_send_json(array('status' => true));
1176
  }
1177
  }
1178
  wp_send_json(false);
1179
  }
1180
+
1181
+ /**
1182
  * Ajax update meta index for page
1183
  */
1184
+ public function updatePageIndex()
1185
+ {
1186
  if (!current_user_can('manage_options')) {
1187
  wp_send_json(array('status' => false));
1188
  }
1192
  }
1193
  wp_send_json(array('status' => false));
1194
  }
1195
+
1196
+ /**
1197
  * Ajax update meta follow for page
1198
  */
1199
+ public function updatePageFollow()
1200
+ {
1201
  if (!current_user_can('manage_options')) {
1202
  wp_send_json(array('status' => false));
1203
  }
1207
  }
1208
  wp_send_json(array('status' => false));
1209
  }
1210
+
1211
+ /**
1212
  * Ajax update meta follow for link
1213
  */
1214
+ public function updateFollow()
1215
+ {
1216
  if (!current_user_can('manage_options')) {
1217
  wp_send_json(array('status' => false));
1218
  }
1219
  if (isset($_POST['link_id'])) {
1220
+ $this->doUpdateFollow($_POST['link_id'], $_POST['follow']);
1221
  wp_send_json(array('status' => true));
1222
  }
1223
  wp_send_json(array('status' => false));
1224
  }
1225
+
1226
+ /**
1227
  * Ajax update multitle meta follow for link
1228
  */
1229
+ public function updateMultipleFollow()
1230
+ {
1231
  if (!current_user_can('manage_options')) {
1232
  wp_send_json(array('status' => false));
1233
  }
1237
 
1238
  switch ($follow_value) {
1239
  case 'follow_selected':
1240
+ if (empty($_POST['linkids'])) {
1241
  wp_send_json(array('status' => true));
1242
+ }
1243
+
1244
  $follow = 1;
1245
  foreach ($_POST['linkids'] as $linkId) {
1246
+ $this->doUpdateFollow($linkId, $follow);
1247
  }
1248
  break;
1249
 
1250
  case 'follow_all':
1251
  $follow = 1;
1252
  $i = 0;
1253
+ $links = $wpdb->get_results(
1254
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=0 AND type='url'"
1255
+ );
1256
  foreach ($links as $link) {
1257
  if ($i > $limit) {
1258
  wp_send_json(array('status' => false, 'message' => 'limit'));
1259
  } else {
1260
+ $this->doUpdateFollow($link->id, $follow);
1261
  $i++;
1262
  }
1263
  }
1266
 
1267
  case 'nofollow_selected':
1268
  $follow = 0;
1269
+ if (empty($_POST['linkids'])) {
1270
  wp_send_json(array('status' => true));
1271
+ }
1272
+
1273
  foreach ($_POST['linkids'] as $linkId) {
1274
+ $this->doUpdateFollow($linkId, $follow);
1275
  }
1276
  break;
1277
 
1278
  case 'nofollow_all':
1279
  $follow = 0;
1280
  $i = 0;
1281
+ $links = $wpdb->get_results(
1282
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE follow=1 AND type='url'"
1283
+ );
1284
  foreach ($links as $link) {
1285
  if ($i > $limit) {
1286
  wp_send_json(array('status' => false, 'message' => 'limit'));
1287
  } else {
1288
+ $this->doUpdateFollow($link->id, $follow);
1289
  $i++;
1290
  }
1291
  }
1293
  }
1294
  wp_send_json(array('status' => true));
1295
  }
1296
+
1297
+ /**
1298
  * Ajax update meta follow for link
1299
+ * @param int $linkId link id
1300
+ * @param int $follow follow value
1301
  */
1302
+ public function doUpdateFollow($linkId, $follow)
1303
+ {
1304
  global $wpdb;
1305
+ $sql = $wpdb->prepare(
1306
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1307
+ array(
1308
+ $linkId
1309
+ )
1310
+ );
1311
  $link_detail = $wpdb->get_row($sql);
1312
+ if (empty($link_detail)) {
1313
  wp_send_json(array('status' => false));
1314
+ }
1315
+
1316
 
1317
  $value = array('follow' => $follow);
1318
  $wpdb->update(
1319
+ $wpdb->prefix . 'wpms_links',
1320
+ $value,
1321
+ array('id' => $linkId)
1322
  );
1323
 
1324
  $post = get_post($link_detail->source_id);
1325
  if (!empty($post)) {
1326
  $old_value = $post->post_content;
1327
+ $edit_result = $this->editLinkHtml(
1328
+ $old_value,
1329
+ $link_detail->link_url,
1330
+ $link_detail->link_url,
1331
+ $link_detail->meta_title,
1332
+ $follow
1333
+ );
1334
  $my_post = array(
1335
  'ID' => $link_detail->source_id,
1336
  'post_content' => $edit_result['content']
1337
  );
1338
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1339
  wp_update_post($my_post);
1340
  }
1341
  }
1342
+
1343
+ /**
1344
  * Render new content when edit a link
1345
+ * @param string $content post content
1346
+ * @param string $new_url new url
1347
+ * @param string $old_url old url
1348
+ * @param string $meta_title meta title
1349
+ * @param int $follow follow value
1350
+ * @param null $new_text new text of link
1351
+ * @return array
1352
  */
1353
+ public function editLinkHtml($content, $new_url, $old_url, $meta_title, $follow, $new_text = null)
1354
+ {
1355
  //Save the old & new URLs for use in the edit callback.
1356
  $args = array(
1357
  'old_url' => $old_url,
1362
  );
1363
 
1364
  //Find all links and replace those that match $old_url.
1365
+ $content = MetaSeoBrokenLinkTable::multiEdit(
1366
+ $content,
1367
+ array(
1368
+ 'MetaSeoBrokenLinkTable',
1369
+ 'editHtmlCallback'
1370
+ ),
1371
+ $args
1372
+ );
1373
 
1374
  $result = array(
1375
  'content' => $content,
1381
  return $result;
1382
  }
1383
 
1384
+ /**
1385
  * Update option wpms_settings_404
1386
  */
1387
+ public function save404Settings()
1388
+ {
1389
  if (!current_user_can('manage_options')) {
1390
  wp_send_json(false);
1391
  }
1392
 
1393
  if (isset($_POST['wpms_redirect'])) {
1394
  update_option('wpms_settings_404', $_POST['wpms_redirect']);
 
1395
  }
1396
 
1397
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1398
+ $params = array('enable', 'numberFrequency', 'showlinkFrequency');
1399
  $settinglink = array();
1400
+ foreach ($params as $param) {
1401
+ if (isset($_POST[$param])) {
1402
  $settinglink[$param] = $_POST[$param];
1403
  }
1404
  }
1405
 
1406
+ if (empty($settinglink['wpms_lastRun_scanlink'])) {
1407
+ $settinglink['wpms_lastRun_scanlink'] = time();
1408
  }
1409
+ update_option('wpms_link_settings', $settinglink);
1410
  }
1411
 
1412
  wp_send_json(true);
1413
  }
1414
 
1415
+ /**
1416
  * Update breadcrumb settings
1417
  */
1418
+ public function saveBreadcrumbSettings()
1419
+ {
1420
  if (!current_user_can('manage_options')) {
1421
  wp_send_json(false);
1422
  }
1423
 
1424
+ $params = array('separator', 'include_home', 'home_text', 'clickable', 'home_text_default');
1425
  $settinglink = array();
1426
+ foreach ($params as $param) {
1427
+ if (isset($_POST[$param])) {
1428
  $settinglink[$param] = $_POST[$param];
1429
  }
1430
  }
1431
 
1432
+ update_option('_metaseo_breadcrumbs', $settinglink);
1433
  wp_send_json(true);
1434
  }
1435
 
1436
+ /**
1437
  * Add a new field to a section of a settings page
1438
  */
1439
+ public function fieldSettings()
1440
+ {
1441
  register_setting('Wp Meta SEO', '_metaseo_settings');
1442
  add_settings_section('metaseo_dashboard', '', array($this, 'showSettings'), 'metaseo_settings');
1443
+ add_settings_field(
1444
+ 'metaseo_title_home',
1445
+ __('Homepage meta title', 'wp-meta-seo'),
1446
+ array($this, 'titleHome'),
1447
+ 'metaseo_settings',
1448
+ 'metaseo_dashboard',
1449
+ array(
1450
+ 'label_for' => __('You can define your home page meta title in the content
1451
+ itself (a page, a post category…),
1452
+ if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1453
+ )
1454
+ );
1455
+ add_settings_field(
1456
+ 'metaseo_desc_home',
1457
+ __('Homepage meta description', 'wp-meta-seo'),
1458
+ array($this, 'descHome'),
1459
+ 'metaseo_settings',
1460
+ 'metaseo_dashboard',
1461
+ array(
1462
+ 'label_for' => __('You can define your home page meta description in the content
1463
+ itself (a page, a post category…),
1464
+ if for some reason it’s not possible, use this setting', 'wp-meta-seo')
1465
+ )
1466
+ );
1467
+ add_settings_field(
1468
+ 'metaseo_showfacebook',
1469
+ __('Facebook profile URL', 'wp-meta-seo'),
1470
+ array($this, 'showfacebook'),
1471
+ 'metaseo_settings',
1472
+ 'metaseo_dashboard',
1473
+ array(
1474
+ 'label_for' => __('Used as profile in case of social sharing content on Facebook', 'wp-meta-seo')
1475
+ )
1476
+ );
1477
+ add_settings_field(
1478
+ 'metaseo_showfbappid',
1479
+ __('Facebook App ID', 'wp-meta-seo'),
1480
+ array($this, 'showfbappid'),
1481
+ 'metaseo_settings',
1482
+ 'metaseo_dashboard',
1483
+ array(
1484
+ 'label_for' => __('Used as facebook app ID in case of
1485
+ social sharing content on Facebook', 'wp-meta-seo')
1486
+ )
1487
+ );
1488
+ add_settings_field(
1489
+ 'metaseo_showtwitter',
1490
+ __('Twitter Username', 'wp-meta-seo'),
1491
+ array($this, 'showtwitter'),
1492
+ 'metaseo_settings',
1493
+ 'metaseo_dashboard',
1494
+ array(
1495
+ 'label_for' => __('Used as profile in case of social sharing content on Twitter', 'wp-meta-seo')
1496
+ )
1497
+ );
1498
+ add_settings_field(
1499
+ 'metaseo_twitter_card',
1500
+ __('The default card type to use', 'wp-meta-seo'),
1501
+ array($this, 'showtwittercard'),
1502
+ 'metaseo_settings',
1503
+ 'metaseo_dashboard',
1504
+ array(
1505
+ 'label_for' => __('Choose the Twitter card size generated when sharing a content', 'wp-meta-seo')
1506
+ )
1507
+ );
1508
+ add_settings_field(
1509
+ 'metaseo_metatitle_tab',
1510
+ __('Meta title as page title', 'wp-meta-seo'),
1511
+ array($this, 'showmetatitletab'),
1512
+ 'metaseo_settings',
1513
+ 'metaseo_dashboard',
1514
+ array(
1515
+ 'label_for' => __('Usually not recommended as meta information is
1516
+ for search engines and content title for readers, but in some case... :)', 'wp-meta-seo')
1517
+ )
1518
+ );
1519
+ add_settings_field(
1520
+ 'metaseo_showkeywords',
1521
+ __('Meta keywords', 'wp-meta-seo'),
1522
+ array($this, 'showkeywords'),
1523
+ 'metaseo_settings',
1524
+ 'metaseo_dashboard',
1525
+ array(
1526
+ 'label_for' => __('Not used directly by search engine to index content,
1527
+ but in some case it can be helpful (multilingual is an example)', 'wp-meta-seo')
1528
+ )
1529
+ );
1530
+ add_settings_field(
1531
+ 'metaseo_showtmetablock',
1532
+ __('Meta block edition', 'wp-meta-seo'),
1533
+ array($this, 'showtmetablock'),
1534
+ 'metaseo_settings',
1535
+ 'metaseo_dashboard',
1536
+ array(
1537
+ 'label_for' => __('Load the onpage meta edition and analysis block', 'wp-meta-seo')
1538
+ )
1539
+ );
1540
+ add_settings_field(
1541
+ 'metaseo_showsocial',
1542
+ __('Social sharing block', 'wp-meta-seo'),
1543
+ array($this, 'showsocial'),
1544
+ 'metaseo_settings',
1545
+ 'metaseo_dashboard',
1546
+ array(
1547
+ 'label_for' => __('Activate the custom social sharing tool, above the meta block', 'wp-meta-seo')
1548
+ )
1549
+ );
1550
+ add_settings_field(
1551
+ 'metaseo_seovalidate',
1552
+ __('Force SEO validation', 'wp-meta-seo'),
1553
+ array($this, 'showseovalidate'),
1554
+ 'metaseo_settings',
1555
+ 'metaseo_dashboard',
1556
+ array(
1557
+ 'label_for' => __('Possibility to force a criteria validation
1558
+ in the content analysis tool', 'wp-meta-seo')
1559
+ )
1560
+ );
1561
+ add_settings_field(
1562
+ 'metaseo_linkfield',
1563
+ __('Link text field', 'wp-meta-seo'),
1564
+ array($this, 'showlinkfield'),
1565
+ 'metaseo_settings',
1566
+ 'metaseo_dashboard',
1567
+ array(
1568
+ 'label_for' => __('Add the link title field in the text editor and
1569
+ in the bulk link edition view', 'wp-meta-seo')
1570
+ )
1571
+ );
1572
+ add_settings_field(
1573
+ 'metaseo_follow',
1574
+ __('Post/Page follow', 'wp-meta-seo'),
1575
+ array($this, 'showfollow'),
1576
+ 'metaseo_settings',
1577
+ 'metaseo_dashboard',
1578
+ array(
1579
+ 'label_for' => __('Add an option to setup Follow/Nofollow instruction for each content', 'wp-meta-seo')
1580
+ )
1581
+ );
1582
+ add_settings_field(
1583
+ 'metaseo_index',
1584
+ __('Post/Page index', 'wp-meta-seo'),
1585
+ array($this, 'showindex'),
1586
+ 'metaseo_settings',
1587
+ 'metaseo_dashboard',
1588
+ array(
1589
+ 'label_for' => __('Add an option to say to search engine: hey!
1590
+ Do not index this content', 'wp-meta-seo')
1591
+ )
1592
+ );
1593
+ add_settings_field(
1594
+ 'metaseo_overridemeta',
1595
+ __('Auto override Meta', 'wp-meta-seo'),
1596
+ array($this, 'showoverridemeta'),
1597
+ 'metaseo_settings',
1598
+ 'metaseo_dashboard',
1599
+ array(
1600
+ 'label_for' => __('Auto override image meta in post content when update meta', 'wp-meta-seo')
1601
+ )
1602
+ );
1603
  }
1604
+
1605
+ /**
1606
  * Display metatitle_tab input
1607
  */
1608
+ public function showmetatitletab()
1609
+ {
1610
  echo '<input name="_metaseo_settings[metaseo_metatitle_tab]" type="hidden" value="0"/>';
1611
  ?>
1612
+ <label>
1613
+ <?php _e('When meta title is filled use it as page title instead of the content title', 'wp-meta-seo'); ?>
1614
+ </label>
1615
  <div class="switch-optimization">
1616
  <label class="switch switch-optimization">
1617
+ <?php
1618
+ if (isset($this->settings['metaseo_metatitle_tab']) && $this->settings['metaseo_metatitle_tab'] == 1) :
1619
+ ?>
1620
+ <input type="checkbox" id="metaseo_metatitle_tab" name="_metaseo_settings[metaseo_metatitle_tab]"
1621
+ value="1" checked>
1622
+ <?php else : ?>
1623
+ <input type="checkbox" id="metaseo_metatitle_tab" name="_metaseo_settings[metaseo_metatitle_tab]"
1624
+ value="1">
1625
+ <?php endif; ?>
1626
+ <span class="slider round"></span>
1627
  </label>
1628
  </div>
1629
  <?php
1630
  }
1631
 
1632
+ public function showSettings()
1633
+ {
1634
  }
1635
+
1636
+ /**
1637
  * Display title_home input
1638
  */
1639
+ public function titleHome()
1640
+ {
1641
  $home_title = isset($this->settings['metaseo_title_home']) ? $this->settings['metaseo_title_home'] : '';
1642
+ echo '<input id="metaseo_title_home" name="_metaseo_settings[metaseo_title_home]"
1643
+ type="text" value="' . esc_attr($home_title) . '" size="50"/>';
1644
  }
1645
+
1646
+ /**
1647
  * Display desc_home input
1648
  */
1649
+ public function descHome()
1650
+ {
1651
  $home_desc = isset($this->settings['metaseo_desc_home']) ? $this->settings['metaseo_desc_home'] : '';
1652
+ echo '<input id="metaseo_desc_home" name="_metaseo_settings[metaseo_desc_home]"
1653
+ type="text" value="' . esc_attr($home_desc) . '" size="50"/>';
1654
  }
1655
 
1656
+ /**
1657
  * Display showkeywords input
1658
  */
1659
+ public function showkeywords()
1660
+ {
1661
  echo '<input name="_metaseo_settings[metaseo_showkeywords]" type="hidden" value="0"/>';
1662
  ?>
1663
  <label><?php _e('Active meta keywords', 'wp-meta-seo'); ?></label>
1664
  <div class="switch-optimization">
1665
  <label class="switch switch-optimization">
1666
+ <?php
1667
+ if (isset($this->settings['metaseo_showkeywords']) && $this->settings['metaseo_showkeywords'] == 1) :
1668
+ ?>
1669
+ <input type="checkbox" id="metaseo_showkeywords" name="_metaseo_settings[metaseo_showkeywords]"
1670
+ value="1" checked>
1671
+ <?php else : ?>
1672
+ <input type="checkbox" id="metaseo_showkeywords" name="_metaseo_settings[metaseo_showkeywords]"
1673
+ value="1">
1674
+ <?php endif; ?>
1675
+ <span class="slider round"></span>
1676
  </label>
1677
  </div>
1678
  <?php
1679
  }
1680
+
1681
+ /**
1682
  * Display showtmetablock input
1683
  */
1684
+ public function showtmetablock()
1685
+ {
1686
  echo '<input name="_metaseo_settings[metaseo_showtmetablock]" type="hidden" value="0"/>';
1687
  ?>
1688
  <label><?php _e('Activate meta block edition below content', 'wp-meta-seo'); ?></label>
1689
  <div class="switch-optimization">
1690
  <label class="switch switch-optimization">
1691
+ <?php
1692
+ if (isset($this->settings['metaseo_showtmetablock'])
1693
+ && $this->settings['metaseo_showtmetablock'] == 1) :
1694
+ ?>
1695
+ <input type="checkbox" id="metaseo_showtmetablock" name="_metaseo_settings[metaseo_showtmetablock]"
1696
+ value="1" checked>
1697
+ <?php else : ?>
1698
+ <input type="checkbox" id="metaseo_showtmetablock" name="_metaseo_settings[metaseo_showtmetablock]"
1699
+ value="1">
1700
+ <?php endif; ?>
1701
+ <span class="slider round"></span>
1702
  </label>
1703
  </div>
1704
  <?php
1705
  }
1706
+
1707
+ /**
1708
  * Display showsocial input
1709
  */
1710
+ public function showsocial()
1711
+ {
1712
  echo '<input name="_metaseo_settings[metaseo_showsocial]" type="hidden" value="0"/>';
1713
  ?>
1714
  <label><?php _e('Activate social edition', 'wp-meta-seo'); ?></label>
1715
  <div class="switch-optimization">
1716
  <label class="switch switch-optimization">
1717
+ <?php
1718
+ if (isset($this->settings['metaseo_showsocial']) && $this->settings['metaseo_showsocial'] == 1) :
1719
+ ?>
1720
+ <input type="checkbox" id="metaseo_showsocial" name="_metaseo_settings[metaseo_showsocial]"
1721
+ value="1" checked>
1722
+ <?php else : ?>
1723
+ <input type="checkbox" id="metaseo_showsocial" name="_metaseo_settings[metaseo_showsocial]"
1724
+ value="1">
1725
+ <?php endif; ?>
1726
+ <span class="slider round"></span>
1727
  </label>
1728
  </div>
1729
  <?php
1730
  }
1731
+
1732
+ /**
1733
  * Display seovalidate input
1734
  */
1735
+ public function showseovalidate()
1736
+ {
1737
  echo '<input name="_metaseo_settings[metaseo_seovalidate]" type="hidden" value="0"/>';
1738
  ?>
1739
+ <label>
1740
+ <?php _e('Allow user to force on page SEO criteria validation by clicking on the icon', 'wp-meta-seo'); ?>
1741
+ </label>
1742
  <div class="switch-optimization">
1743
  <label class="switch switch-optimization">
1744
+ <?php
1745
+ if (isset($this->settings['metaseo_seovalidate']) && $this->settings['metaseo_seovalidate'] == 1) :
1746
+ ?>
1747
+ <input type="checkbox" id="metaseo_seovalidate" name="_metaseo_settings[metaseo_seovalidate]"
1748
+ value="1" checked>
1749
+ <?php else : ?>
1750
+ <input type="checkbox" id="metaseo_seovalidate" name="_metaseo_settings[metaseo_seovalidate]"
1751
+ value="1">
1752
+ <?php endif; ?>
1753
+ <span class="slider round"></span>
1754
  </label>
1755
  </div>
1756
  <?php
1757
  }
1758
+
1759
+ /**
1760
  * Display linkfield input
1761
  */
1762
+ public function showlinkfield()
1763
+ {
1764
  echo '<input name="_metaseo_settings[metaseo_linkfield]" type="hidden" value="0"/>';
1765
  ?>
1766
  <label><?php _e("Adds back the missing 'title' field in the Insert/Edit URL box", "wp-meta-seo"); ?></label>
1767
  <div class="switch-optimization">
1768
  <label class="switch switch-optimization">
1769
+ <?php
1770
+ if (isset($this->settings['metaseo_linkfield']) && $this->settings['metaseo_linkfield'] == 1) :
1771
+ ?>
1772
+ <input type="checkbox" id="metaseo_linkfield" name="_metaseo_settings[metaseo_linkfield]"
1773
+ value="1" checked>
1774
+ <?php else : ?>
1775
+ <input type="checkbox" id="metaseo_linkfield" name="_metaseo_settings[metaseo_linkfield]"
1776
+ value="1">
1777
+ <?php endif; ?>
1778
+ <span class="slider round"></span>
1779
  </label>
1780
  </div>
1781
  <?php
1782
  }
1783
+
1784
+ /**
1785
  * Display follow input
1786
  */
1787
+ public function showfollow()
1788
+ {
1789
  echo '<input name="_metaseo_settings[metaseo_follow]" type="hidden" value="0"/>';
1790
  ?>
1791
+ <label>
1792
+ <?php _e("Provides a way for webmasters to tell
1793
+ search engines don't follow links on the page.", "wp-meta-seo"); ?>
1794
+ </label>
1795
  <div class="switch-optimization">
1796
  <label class="switch switch-optimization">
1797
+ <?php
1798
+ if (isset($this->settings['metaseo_follow']) && $this->settings['metaseo_follow'] == 1) :
1799
+ ?>
1800
+ <input type="checkbox" id="metaseo_follow" name="_metaseo_settings[metaseo_follow]"
1801
+ value="1" checked>
1802
+ <?php else : ?>
1803
+ <input type="checkbox" id="metaseo_follow" name="_metaseo_settings[metaseo_follow]"
1804
+ value="1">
1805
+ <?php endif; ?>
1806
+ <span class="slider round"></span>
1807
  </label>
1808
  </div>
1809
  <?php
1810
  }
1811
+
1812
+ /**
1813
  * Display index input
1814
  */
1815
+ public function showindex()
1816
+ {
1817
  echo '<input name="_metaseo_settings[metaseo_index]" type="hidden" value="0"/>';
1818
  ?>
1819
+ <label>
1820
+ <?php _e("Provides show or do not show this page in search
1821
+ results in search results.", "wp-meta-seo"); ?>
1822
+ </label>
1823
  <div class="switch-optimization">
1824
  <label class="switch switch-optimization">
1825
+ <?php
1826
+ if (isset($this->settings['metaseo_index']) && $this->settings['metaseo_index'] == 1) :
1827
+ ?>
1828
+ <input type="checkbox" id="metaseo_index" name="_metaseo_settings[metaseo_index]"
1829
+ value="1" checked>
1830
+ <?php else : ?>
1831
+ <input type="checkbox" id="metaseo_index" name="_metaseo_settings[metaseo_index]"
1832
+ value="1">
1833
+ <?php endif; ?>
1834
+ <span class="slider round"></span>
1835
  </label>
1836
  </div>
1837
  <?php
1838
  }
1839
 
1840
+ /**
1841
  * Display override meta
1842
  */
1843
+ public function showoverridemeta()
1844
+ {
1845
  echo '<input name="_metaseo_settings[metaseo_overridemeta]" type="hidden" value="0"/>';
1846
  ?>
1847
  <label><?php _e("Override meta image in post content when update meta", "wp-meta-seo"); ?></label>
1848
  <div class="switch-optimization">
1849
  <label class="switch switch-optimization">
1850
+ <?php
1851
+ if (isset($this->settings['metaseo_overridemeta']) && $this->settings['metaseo_overridemeta'] == 1) :
1852
+ ?>
1853
+ <input type="checkbox" id="metaseo_overridemeta" name="_metaseo_settings[metaseo_overridemeta]"
1854
+ value="1" checked>
1855
+ <?php else : ?>
1856
+ <input type="checkbox" id="metaseo_overridemeta" name="_metaseo_settings[metaseo_overridemeta]"
1857
+ value="1">
1858
+ <?php endif; ?>
1859
+ <span class="slider round"></span>
1860
  </label>
1861
  </div>
1862
  <?php
1863
  }
1864
 
1865
+ /**
1866
  * Display showfacebook input
1867
  */
1868
+ public function showfacebook()
1869
+ {
1870
  $face = isset($this->settings['metaseo_showfacebook']) ? $this->settings['metaseo_showfacebook'] : '';
1871
+ echo '<input id="metaseo_showfacebook" name="_metaseo_settings[metaseo_showfacebook]"
1872
+ type="text" value="' . esc_attr($face) . '" size="50"/>';
1873
  }
1874
 
1875
+ /**
1876
  * Display fb app id input
1877
  */
1878
+ public function showfbappid()
1879
+ {
1880
  $appid = isset($this->settings['metaseo_showfbappid']) ? $this->settings['metaseo_showfbappid'] : '';
1881
+ echo '<input id="metaseo_showfbappid" name="_metaseo_settings[metaseo_showfbappid]"
1882
+ type="text" value="' . esc_attr($appid) . '" size="50"/>';
1883
  }
1884
 
1885
+ /**
1886
  * Display showtwitter input
1887
  */
1888
+ public function showtwitter()
1889
+ {
1890
  $twitter = isset($this->settings['metaseo_showtwitter']) ? $this->settings['metaseo_showtwitter'] : '';
1891
+ echo '<input id="metaseo_showtwitter" name="_metaseo_settings[metaseo_showtwitter]"
1892
+ type="text" value="' . esc_attr($twitter) . '" size="50"/>';
1893
  }
1894
+
1895
+ /**
1896
  * Display twitter_card input
1897
  */
1898
+ public function showtwittercard()
1899
+ {
1900
+ if (isset($this->settings['metaseo_twitter_card'])) {
1901
+ $twitter_card = $this->settings['metaseo_twitter_card'];
1902
+ } else {
1903
+ $twitter_card = 'summary';
1904
+ }
1905
  ?>
1906
+ <label>
1907
+ <select class="select" name="_metaseo_settings[metaseo_twitter_card]" id="metaseo_twitter_card">
1908
+ <option <?php selected($twitter_card, 'summary') ?>
1909
+ value="summary"><?php _e('Summary', 'wp-meta-seo'); ?></option>
1910
+ <option <?php selected($twitter_card, 'summary_large_image') ?>
1911
+ value="summary_large_image"><?php _e('Summary with large image', 'wp-meta-seo'); ?></option>
1912
+ </select>
1913
+ </label>
1914
  <?php
1915
  }
1916
 
1917
+ /**
1918
+ * Show meta box in single post
1919
+ */
1920
+ private function loadMetaBoxes()
1921
+ {
1922
  if (in_array($this->pagenow, array(
1923
+ 'edit.php',
1924
+ 'post.php',
1925
+ 'post-new.php',
1926
+ )) || apply_filters('wpmseo_always_register_metaboxes_on_admin', false)
1927
  ) {
1928
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-metabox.php');
1929
+ $GLOBALS['wpmseo_metabox'] = new WPMSEOMetabox;
1930
  }
1931
  }
1932
 
1933
+ /**
 
 
 
 
 
 
1934
  * Update meta title , meta description , meta keyword for content
1935
  */
1936
+ public function updateContentMetaCallback()
1937
+ {
1938
+
1939
  if (!current_user_can('manage_options')) {
1940
  wp_send_json(array('status' => false));
1941
  }
 
1942
  $_POST = stripslashes_deep($_POST);
1943
  $response = new stdClass();
 
 
 
1944
  $metakey = strtolower(trim($_POST['metakey']));
1945
  $postID = intval($_POST['postid']);
1946
  $value = trim($_POST['value']);
1974
  $response->msg = __('Meta keywords was saved', 'wp-meta-seo');
1975
  }
1976
  }
1977
+ update_option('wpms_last_update_post', time());
1978
  echo json_encode($response);
1979
  wp_die();
1980
  }
1982
  /**
1983
  * Loads js/ajax scripts
1984
  */
1985
+ public function loadAdminScripts()
1986
+ {
1987
+ global $pagenow, $current_screen;
1988
+ wp_enqueue_script('jquery');
1989
  $array_menu = array(
1990
  'wp-meta-seo_page_metaseo_dashboard',
1991
  'wp-meta-seo_page_metaseo_image_optimize',
1996
  'wp-meta-seo_page_metaseo_content_meta',
1997
  'wp-meta-seo_page_metaseo_image_meta',
1998
  'wp-meta-seo_page_metaseo_link_meta'
1999
+ );
2000
 
2001
  $lists_pages = array(
2002
  'toplevel_page_metaseo_dashboard',
2010
  'wp-meta-seo_page_metaseo_sendemail',
2011
  'wp-meta-seo_page_metaseo_settings'
2012
  );
2013
+ if (in_array($current_screen->base, $lists_pages)) {
2014
+ wp_enqueue_style(
2015
+ 'metaseo-google-icon',
2016
+ '//fonts.googleapis.com/icon?family=Material+Icons'
2017
+ );
2018
+ wp_enqueue_style(
2019
+ 'wpms_materialize_style',
2020
+ plugins_url('css/materialize/materialize.css', dirname(__FILE__)),
2021
+ array(),
2022
+ WPMSEO_VERSION
2023
+ );
2024
+ wp_enqueue_script(
2025
+ 'wpms_materialize_js',
2026
+ plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)),
2027
+ array('jquery'),
2028
+ WPMSEO_VERSION,
2029
+ true
2030
+ );
2031
  }
2032
 
2033
  wp_enqueue_script(
2034
+ 'wpmetaseoAdmin',
2035
+ plugins_url('js/metaseo_admin.js', dirname(__FILE__)),
2036
+ array('jquery'),
2037
+ WPMSEO_VERSION,
2038
+ true
2039
  );
2040
 
2041
+ if (in_array($current_screen->base, $array_menu) || $pagenow == 'post.php' || $pagenow == 'post-new.php') {
2042
+ wp_enqueue_style(
2043
+ 'wpmetaseoAdmin',
2044
+ plugins_url('css/metaseo_admin.css', dirname(__FILE__)),
2045
+ array(),
2046
+ WPMSEO_VERSION
2047
+ );
2048
+ wp_enqueue_style(
2049
+ 'tooltip-metaimage',
2050
+ plugins_url('/css/tooltip-metaimage.css', dirname(__FILE__)),
2051
+ array(),
2052
+ WPMSEO_VERSION
2053
+ );
2054
  wp_enqueue_style('style', plugins_url('/css/style.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
2055
  }
2056
+
2057
+ if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta'
2058
+ || $current_screen->base == 'wp-meta-seo_page_metaseo_content_meta') {
2059
+ wp_enqueue_script(
2060
+ 'wpms-bulk',
2061
+ plugins_url('js/wpms-bulk-action.js', dirname(__FILE__)),
2062
+ array('jquery'),
2063
+ WPMSEO_VERSION,
2064
+ true
2065
+ );
2066
+ wp_localize_script('wpms-bulk', 'wpmseobulkL10n', $this->localizeScript());
2067
  }
2068
 
2069
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_broken_link') {
2070
+ wp_enqueue_style(
2071
+ 'wpms_brokenlink_style',
2072
+ plugins_url('css/broken_link.css', dirname(__FILE__)),
2073
+ array(),
2074
+ WPMSEO_VERSION
2075
+ );
2076
  }
2077
 
2078
  if ($current_screen->base == 'toplevel_page_metaseo_dashboard') {
2079
+ wp_enqueue_script(
2080
+ 'Chart',
2081
+ plugins_url('js/Chart.js', dirname(__FILE__)),
2082
+ array('jquery'),
2083
+ WPMSEO_VERSION,
2084
+ true
2085
+ );
2086
+ wp_enqueue_script(
2087
+ 'jquery-knob',
2088
+ plugins_url('js/jquery.knob.js', dirname(__FILE__)),
2089
+ array('jquery'),
2090
+ WPMSEO_VERSION,
2091
+ true
2092
+ );
2093
+ wp_enqueue_script(
2094
+ 'metaseo-dashboard',
2095
+ plugins_url('js/dashboard.js', dirname(__FILE__)),
2096
+ array('jquery'),
2097
+ WPMSEO_VERSION,
2098
+ true
2099
+ );
2100
+ wp_enqueue_style(
2101
+ 'chart',
2102
+ plugins_url('/css/chart.css', dirname(__FILE__))
2103
+ );
2104
+ wp_enqueue_style(
2105
+ 'metaseo-quirk',
2106
+ plugins_url('/css/metaseo-quirk.css', dirname(__FILE__))
2107
+ );
2108
+ wp_enqueue_style(
2109
+ 'm-style-dashboard',
2110
+ plugins_url('css/dashboard.css', dirname(__FILE__)),
2111
+ array(),
2112
+ WPMSEO_VERSION
2113
+ );
2114
+ wp_enqueue_style(
2115
+ 'm-font-awesome',
2116
+ plugins_url('css/font-awesome.css', dirname(__FILE__)),
2117
+ array(),
2118
+ WPMSEO_VERSION
2119
+ );
2120
  }
2121
 
2122
  $lists_pages = array(
2125
  'wp-meta-seo_page_metaseo_link_meta',
2126
  'wp-meta-seo_page_metaseo_broken_link',
2127
  'wp-meta-seo_page_metaseo_google_analytics');
2128
+ if (in_array($current_screen->base, $lists_pages)) {
2129
+ wp_enqueue_style(
2130
+ 'wpms_notification_style',
2131
+ plugins_url('css/notification.css', dirname(__FILE__)),
2132
+ array(),
2133
+ WPMSEO_VERSION
2134
+ );
2135
+ wp_enqueue_script(
2136
+ 'wpms_notification_script',
2137
+ plugins_url('js/notification.js', dirname(__FILE__)),
2138
+ array(),
2139
+ WPMSEO_VERSION
2140
+ );
2141
  }
2142
 
2143
+ wp_register_style(
2144
+ 'wpms-dashboard-widgets',
2145
+ plugins_url('css/dashboard_widgets.css', dirname(__FILE__)),
2146
+ null,
2147
+ WPMSEO_VERSION
2148
+ );
2149
+ wp_register_style(
2150
+ 'wpms-category-field',
2151
+ plugins_url('css/category_field.css', dirname(__FILE__)),
2152
+ null,
2153
+ WPMSEO_VERSION
2154
+ );
2155
+ wp_register_script(
2156
+ 'wpms-category-field',
2157
+ plugins_url('js/category_field.js', dirname(__FILE__)),
2158
+ array('jquery'),
2159
+ WPMSEO_VERSION,
2160
+ true
2161
+ );
2162
+ wp_register_style(
2163
+ 'm-style-qtip',
2164
+ plugins_url('css/jquery.qtip.css', dirname(__FILE__)),
2165
+ array(),
2166
+ WPMSEO_VERSION
2167
+ );
2168
+ wp_register_script(
2169
+ 'jquery-qtip',
2170
+ plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)),
2171
+ array('jquery'),
2172
+ '2.2.1',
2173
+ true
2174
+ );
2175
+ wp_register_style(
2176
+ 'wpms-myqtip',
2177
+ plugins_url('css/my_qtip.css', dirname(__FILE__)),
2178
+ array(),
2179
+ WPMSEO_VERSION
2180
+ );
2181
+ wp_register_script(
2182
+ 'wpms-broken-link',
2183
+ plugins_url('js/wpms-broken-link.js', dirname(__FILE__)),
2184
+ array('jquery'),
2185
+ WPMSEO_VERSION,
2186
+ true
2187
+ );
2188
 
2189
  wp_register_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons');
2190
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_image_meta') {
2191
+ wp_enqueue_script(
2192
+ 'mautosize',
2193
+ plugins_url('js/autosize.js', dirname(__FILE__)),
2194
+ array('jquery'),
2195
+ '0.1',
2196
+ true
2197
+ );
2198
  }
2199
 
2200
  if ($current_screen->base == 'wp-meta-seo_page_metaseo_google_analytics') {
2201
  $lang = get_bloginfo('language');
2202
  $lang = explode('-', $lang);
2203
  $lang = $lang[0];
2204
+ wp_enqueue_style(
2205
+ 'wpms-nprogress',
2206
+ plugins_url('css/google-analytics/nprogress.css', dirname(__FILE__)),
2207
+ null,
2208
+ WPMSEO_VERSION
2209
+ );
2210
 
2211
+ wp_register_style(
2212
+ 'wpms-backend-item-reports',
2213
+ plugins_url('css/google-analytics/admin-widgets.css', dirname(__FILE__)),
2214
+ null,
2215
+ WPMSEO_VERSION
2216
+ );
2217
+ wp_register_style(
2218
+ 'wpms-backend-tracking-code',
2219
+ plugins_url('css/google-analytics/wpms-tracking-code.css', dirname(__FILE__)),
2220
+ null,
2221
+ WPMSEO_VERSION
2222
+ );
2223
+
2224
+ wp_register_style(
2225
+ 'jquery-ui-tooltip-html',
2226
+ plugins_url('css/google-analytics/jquery.ui.tooltip.html.css', dirname(__FILE__))
2227
+ );
2228
 
2229
  wp_enqueue_style('jquery-ui-tooltip-html');
2230
 
2231
+ wp_enqueue_script(
2232
+ 'wpmsgooglejsapi',
2233
+ 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27',
2234
+ array(),
2235
+ null
2236
+ );
2237
 
2238
+ wp_enqueue_script(
2239
+ 'wpms-nprogress',
2240
+ plugins_url('js/google-analytics/nprogress.js', dirname(__FILE__)),
2241
+ array('jquery'),
2242
+ WPMSEO_VERSION
2243
+ );
2244
 
2245
+ wp_enqueue_script(
2246
+ 'wpms-google-analytics',
2247
+ plugins_url('js/google-analytics/google_analytics.js', dirname(__FILE__)),
2248
+ array('jquery'),
2249
+ WPMSEO_VERSION,
2250
+ true
2251
+ );
2252
 
2253
  /* @formatter:off */
2254
+ wp_localize_script(
2255
+ 'wpms-google-analytics',
2256
+ 'wpmsItemData',
2257
+ array(
2258
+ 'ajaxurl' => admin_url('admin-ajax.php'),
2259
+ 'security' => wp_create_nonce('wpms_backend_item_reports'),
2260
+ 'dateList' => array(
2261
+ 'realtime' => __("Real-Time", 'wp-meta-seo'),
2262
+ 'today' => __("Today", 'wp-meta-seo'),
2263
+ 'yesterday' => __("Yesterday", 'wp-meta-seo'),
2264
+ '7daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 7),
2265
+ '14daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 14),
2266
+ '30daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 30),
2267
+ '90daysAgo' => sprintf(__("Last %d Days", 'wp-meta-seo'), 90),
2268
+ '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'wp-meta-seo'), __('One', 'wp-meta-seo')),
2269
+ '1095daysAgo' => sprintf(
2270
+ _n("%s Year", "%s Years", 3, 'wp-meta-seo'),
2271
+ __('Three', 'wp-meta-seo')
2272
+ ),
2273
+ ),
2274
+ 'reportList' => array(
2275
+ 'sessions' => __("Sessions", 'wp-meta-seo'),
2276
+ 'users' => __("Users", 'wp-meta-seo'),
2277
+ 'organicSearches' => __("Organic", 'wp-meta-seo'),
2278
+ 'pageviews' => __("Page Views", 'wp-meta-seo'),
2279
+ 'visitBounceRate' => __("Bounce Rate", 'wp-meta-seo'),
2280
+ 'locations' => __("Location", 'wp-meta-seo'),
2281
+ 'contentpages' => __("Pages", 'wp-meta-seo'),
2282
+ 'referrers' => __("Referrers", 'wp-meta-seo'),
2283
+ 'searches' => __("Searches", 'wp-meta-seo'),
2284
+ 'trafficdetails' => __("Traffic", 'wp-meta-seo'),
2285
+ 'technologydetails' => __("Technology", 'wp-meta-seo'),
2286
+ ),
2287
+ 'i18n' => array(
2288
+ __("A JavaScript Error is blocking plugin resources!", 'wp-meta-seo'), //0
2289
+ __("Traffic Mediums", 'wp-meta-seo'),
2290
+ __("Visitor Type", 'wp-meta-seo'),
2291
+ __("Search Engines", 'wp-meta-seo'),
2292
+ __("Social Networks", 'wp-meta-seo'),
2293
+ __("Sessions", 'wp-meta-seo'),
2294
+ __("Users", 'wp-meta-seo'),
2295
+ __("Page Views", 'wp-meta-seo'),
2296
+ __("Bounce Rate", 'wp-meta-seo'),
2297
+ __("Organic Search", 'wp-meta-seo'),
2298
+ __("Pages/Session", 'wp-meta-seo'),
2299
+ __("Invalid response", 'wp-meta-seo'),
2300
+ __("Not enough data collected", 'wp-meta-seo'),
2301
+ __("This report is unavailable", 'wp-meta-seo'),
2302
+ __("report generated by", 'wp-meta-seo'), //14
2303
+ __("This plugin needs an authorization:", 'wp-meta-seo') . '
2304
+ <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">
2305
+ ' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
2306
+ __("Browser", 'wp-meta-seo'), //16
2307
+ __("Operating System", 'wp-meta-seo'),
2308
+ __("Screen Resolution", 'wp-meta-seo'),
2309
+ __("Mobile Brand", 'wp-meta-seo'),
2310
+ __("REFERRALS", 'wp-meta-seo'), //20
2311
+ __("KEYWORDS", 'wp-meta-seo'),
2312
+ __("SOCIAL", 'wp-meta-seo'),
2313
+ __("CAMPAIGN", 'wp-meta-seo'),
2314
+ __("DIRECT", 'wp-meta-seo'),
2315
+ __("NEW", 'wp-meta-seo'), //25
2316
+ __("You need select a profile:", 'wp-meta-seo') . '
2317
+ <a href="' . admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode') . '">
2318
+ ' . __("authorize the plugin", 'wp-meta-seo') . '</a>.',
2319
+ ),
2320
+ 'rtLimitPages' => 10,
2321
+ 'colorVariations' => array(
2322
+ '#1e73be',
2323
+ '#0459a4',
2324
+ '#378cd7',
2325
+ '#51a6f1',
2326
+ '#00408b',
2327
+ '#6abfff',
2328
+ '#002671'
2329
+ ),
2330
+ 'region' => false,
2331
+ 'language' => get_bloginfo('language'),
2332
+ 'viewList' => false,
2333
+ 'scope' => 'admin-widgets',
2334
+ 'admin_url' => admin_url()
2335
+ )
2336
  );
2337
  }
2338
 
2340
  wp_localize_script('wpmetaseoAdmin', 'wpms_localize', array(
2341
  'ajax_url' => admin_url('admin-ajax.php'),
2342
  'settings' => $this->settings,
2343
+ 'wpms_cat_metatitle_length' => MPMSCAT_TITLE_LENGTH,
2344
+ 'wpms_cat_metadesc_length' => MPMSCAT_DESC_LENGTH,
2345
+ 'wpms_cat_metakeywords_length' => MPMSCAT_KEYWORDS_LENGTH
2346
  ));
2347
  }
2348
 
2349
  /**
2350
  * Localize a script.
2351
  *
2352
+ * Works only if the script has already been added.
2353
  */
2354
+ public function localizeScript()
2355
+ {
2356
  return array(
2357
+ 'metaseo_message_false_copy' => __('Warning, you\'re about to replace existing image
2358
+ alt or tile content, are you sire about that?', 'wp-meta-seo'),
2359
  );
2360
  }
2361
+
2362
+ /**
2363
+ * Add a top-level menu page.
2364
+ *
2365
+ * This function takes a capability which will be used to determine whether
2366
+ * or not a page is included in the menu.
2367
+ */
2368
+ public function addMenuPage()
2369
+ {
2370
  // Add main page
2371
+ add_menu_page(
2372
+ __('WP Meta SEO: Dashboard', 'wp-meta-seo'),
2373
+ __('WP Meta SEO', 'wp-meta-seo'),
2374
+ 'manage_options',
2375
+ 'metaseo_dashboard',
2376
+ array(
2377
+ $this,
2378
+ 'loadPage'
2379
+ ),
2380
+ 'dashicons-chart-area'
2381
+ );
2382
 
2383
  /**
2384
+ * Filter: 'metaseo_manage_options_capability'
2385
+ * - Allow changing the capability users need to view the settings pages
2386
  *
2387
  * @api string unsigned The capability
2388
  */
2396
  __('Content meta', 'wp-meta-seo'),
2397
  $manage_options_cap,
2398
  'metaseo_content_meta',
2399
+ array($this, 'loadPage'),
2400
  null,
2401
  ),
2402
  array(
2405
  __('Sitemap', 'wp-meta-seo'),
2406
  $manage_options_cap,
2407
  'metaseo_google_sitemap',
2408
+ array($this, 'loadPage'),
2409
  null,
2410
  ),
2411
  array(
2414
  __('Image information', 'wp-meta-seo'),
2415
  $manage_options_cap,
2416
  'metaseo_image_meta',
2417
+ array($this, 'loadPage'),
2418
  null,
2419
  ),
2420
  array(
2423
  __('Image compression', 'wp-meta-seo'),
2424
  $manage_options_cap,
2425
  'metaseo_image_compression',
2426
+ array($this, 'loadPage'),
2427
  null,
2428
  ),
2429
  array(
2432
  __('Link editor', 'wp-meta-seo'),
2433
  $manage_options_cap,
2434
  'metaseo_link_meta',
2435
+ array($this, 'loadPage'),
2436
  null,
2437
  ),
2438
  array(
2441
  __('404 & Redirects', 'wp-meta-seo'),
2442
  $manage_options_cap,
2443
  'metaseo_broken_link',
2444
+ array($this, 'loadPage'),
2445
  null,
2446
  ),
2447
  array(
2450
  __('Google Analytics', 'wp-meta-seo'),
2451
  $manage_options_cap,
2452
  'metaseo_google_analytics',
2453
+ array($this, 'loadPage'),
2454
  null,
2455
  ),
2456
  array(
2459
  __('Settings', 'wp-meta-seo'),
2460
  $manage_options_cap,
2461
  'metaseo_settings',
2462
+ array($this, 'loadPage'),
2463
  null,
2464
  ),
2465
  );
2470
  // Loop through submenu pages and add them
2471
  if (count($submenu_pages)) {
2472
  foreach ($submenu_pages as $submenu_page) {
 
2473
  // Add submenu page
2474
+ $admin_page = add_submenu_page(
2475
+ $submenu_page[0],
2476
+ $submenu_page[2] . ' - ' . __('WP Meta SEO:', 'wp-meta-seo'),
2477
+ $submenu_page[2],
2478
+ $submenu_page[3],
2479
+ $submenu_page[4],
2480
+ $submenu_page[5]
2481
+ );
2482
 
2483
  // Check if we need to hook
2484
+ if (isset($submenu_page[6]) && null != $submenu_page[6]
2485
+ && is_array($submenu_page[6]) && count($submenu_page[6]) > 0) {
2486
  foreach ($submenu_page[6] as $submenu_page_action) {
2487
  add_action('load-' . $admin_page, $submenu_page_action);
2488
  }
2496
  }
2497
  }
2498
 
2499
+ /**
2500
+ * Set error time out
2501
+ */
2502
+ public function setErrorTimeout()
2503
+ {
2504
  $midnight = strtotime("tomorrow 00:00:00"); // UTC midnight
2505
  $midnight = $midnight + 8 * 3600; // UTC 8 AM
2506
  $this->error_timeout = $midnight - time();
2507
  return;
2508
  }
2509
 
2510
+ /**
2511
+ * Retrieves all Google Analytics Views with details
2512
+ *
2513
+ * @return array
2514
+ */
2515
+ public function refreshProfiles()
2516
+ {
2517
  try {
 
2518
  $ga_dash_profile_list = array();
2519
  $startindex = 1;
2520
  $totalresults = 65535; // use something big
2521
  while ($startindex < $totalresults) {
2522
+ $profiles = $this->service->management_profiles->listManagementProfiles(
2523
+ '~all',
2524
+ '~all',
2525
+ array(
2526
+ 'start-index' => $startindex
2527
+ )
2528
+ );
2529
  $items = $profiles->getItems();
2530
 
2531
  $totalresults = $profiles->getTotalResults();
2532
 
2533
  if ($totalresults > 0) {
 
2534
  foreach ($items as $profile) {
2535
  $timetz = new DateTimeZone($profile->getTimezone());
2536
  $localtime = new DateTime('now', $timetz);
2537
  $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
2538
+ $ga_dash_profile_list[] = array(
2539
+ $profile->getName(),
2540
+ $profile->getId(),
2541
+ $profile->getwebPropertyId(),
2542
+ $profile->getwebsiteUrl(),
2543
+ $timeshift,
2544
+ $profile->getTimezone(),
2545
+ $profile->getDefaultPage()
2546
+ );
2547
  $startindex++;
2548
  }
2549
  }
2550
  }
2551
 
2552
  if (empty($ga_dash_profile_list)) {
2553
+ WpmsGaTools::setCache(
2554
+ 'last_error',
2555
+ date('Y-m-d H:i:s') . ': No properties were found in this account!',
2556
+ $this->error_timeout
2557
+ );
2558
  } else {
2559
+ WpmsGaTools::deleteCache('last_error');
2560
  }
2561
  return $ga_dash_profile_list;
2562
  } catch (Google_IO_Exception $e) {
2563
+ WpmsGaTools::setCache(
2564
+ 'last_error',
2565
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
2566
+ $this->error_timeout
2567
+ );
2568
  return $ga_dash_profile_list;
2569
  } catch (Google_Service_Exception $e) {
2570
+ WpmsGaTools::setCache(
2571
+ 'last_error',
2572
+ date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
2573
+ $this->error_timeout
2574
+ );
2575
+ WpmsGaTools::setCache(
2576
+ 'gapi_errors',
2577
+ $e->getCode(),
2578
+ $this->error_timeout
2579
+ );
2580
+ return $ga_dash_profile_list;
2581
  } catch (Exception $e) {
2582
+ WpmsGaTools::setCache(
2583
+ 'last_error',
2584
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
2585
+ $this->error_timeout
2586
+ );
2587
  return $ga_dash_profile_list;
2588
  }
2589
  }
2590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2591
  /**
2592
  * Load the form for a WPSEO admin page
2593
  */
2594
+ public function loadPage()
2595
+ {
2596
  if (isset($_GET['page'])) {
2597
  switch ($_GET['page']) {
2598
  case 'metaseo_google_analytics':
2599
+ $message_ublock = "<div class='error wpms_msg_ublock'><p>";
2600
+ $message_ublock .= __('It seems that you use an adblocker, you need to
2601
+ deactivate it for this page in order to load the Google Analytics scripts. ', 'wp-meta-seo');
2602
+ $message_ublock .= "</p></div>";
2603
  echo $message_ublock;
2604
  $this->google_alanytics = get_option('wpms_google_alanytics');
2605
+ if (isset($_POST['_metaseo_ggtracking_settings'])) {
2606
+ update_option('_metaseo_ggtracking_settings', $_POST['_metaseo_ggtracking_settings']);
2607
+ echo '<div id="setting-error-settings_updated"
2608
+ class="updated settings-error notice is-dismissible">
2609
+ <p><strong>' . __('Settings saved.', 'wp-meta-seo') . '</strong></p><button type="button" class="notice-dismiss">
2610
+ <span class="screen-reader-text">Dismiss this notice.</span></button></div>';
2611
  }
2612
+
2613
+ if (!empty($_POST['tableid_jail'])) {
2614
  $this->google_alanytics['tableid_jail'] = $_POST['tableid_jail'];
2615
+ update_option('wpms_google_alanytics', $this->google_alanytics);
2616
  }
2617
+
 
2618
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
2619
  if (is_array($ga_tracking)) {
2620
  $this->ga_tracking = array_merge($this->ga_tracking, $ga_tracking);
2621
  }
2622
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php');
2623
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
2624
  wp_enqueue_style('m-style-qtip');
2625
  wp_enqueue_script('jquery-qtip');
2626
+ if (isset($_GET['view']) && $_GET['view'] == 'wpmsga_trackcode') {
2627
  wp_enqueue_style('wpms-backend-tracking-code');
2628
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/ga-trackcode.php');
2629
+ } else {
2630
  wp_enqueue_style('wpms-backend-item-reports');
2631
 
2632
 
2633
+ if (isset($_POST['wpmsga_dash_clientid']) && isset($_POST['wpmsga_dash_clientsecret'])) {
2634
  $this->google_alanytics['wpmsga_dash_clientid'] = $_POST['wpmsga_dash_clientid'];
2635
  $this->google_alanytics['wpmsga_dash_clientsecret'] = $_POST['wpmsga_dash_clientsecret'];
2636
  update_option('wpms_google_alanytics', $this->google_alanytics);
2644
  $this->client->setAccessType('offline');
2645
  $this->client->setApplicationName('WP Meta SEO');
2646
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
2647
+ $this->setErrorTimeout();
2648
+ $this->client = WpmsGaTools::setClient($this->client, $this->google_alanytics, $this->access);
2649
  $authUrl = $this->client->createAuthUrl();
2650
  $this->service = new Google_Service_Analytics($this->client);
2651
+ $controller = new WpmsGapiController();
2652
 
2653
  if (!empty($_POST['wpms_ga_code'])) {
2654
  if (!stripos('x' . $_POST['wpms_ga_code'], 'UA-', 1) == 1) {
2655
+ WpmsGaTools::deleteCache('gapi_errors');
2656
+ WpmsGaTools::deleteCache('last_error');
2657
+ WpmsGaTools::clearCache();
 
2658
  try {
2659
  $this->client->authenticate($_POST['wpms_ga_code']);
2660
+ $getAccessToken = $this->client->getAccessToken();
2661
+ if ($getAccessToken) {
2662
+ try {
2663
+ $this->client->setAccessToken($getAccessToken);
2664
+ $this->google_alanytics['googleCredentials']
2665
+ = $this->client->getAccessToken();
2666
+ } catch (Google_IO_Exception $e) {
2667
+ WpmsGaTools::setCache(
2668
+ 'wpmsga_dash_lasterror',
2669
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
2670
+ $this->error_timeout
2671
+ );
2672
+ } catch (Google_Service_Exception $e) {
2673
+ WpmsGaTools::setCache(
2674
+ 'wpmsga_dash_lasterror',
2675
+ date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()),
2676
+ $this->error_timeout
2677
+ );
2678
+ WpmsGaTools::setCache(
2679
+ 'wpmsga_dash_gapi_errors',
2680
+ $e->getCode(),
2681
+ $this->error_timeout
2682
+ );
2683
+ } catch (Exception $e) {
2684
+ WpmsGaTools::setCache(
2685
+ 'wpmsga_dash_lasterror',
2686
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
2687
+ $this->error_timeout
2688
+ );
2689
+ }
2690
  }
2691
+
2692
  if (!empty($this->google_alanytics['profile_list'])) {
2693
  $profiles = $this->google_alanytics['profile_list'];
2694
  } else {
2695
+ $profiles = $this->refreshProfiles();
2696
  }
2697
+
2698
  $this->google_alanytics['code'] = $_POST['wpms_ga_code'];
2699
  $this->google_alanytics['googleCredentials'] = $getAccessToken;
2700
  $this->google_alanytics['profile_list'] = $profiles;
2701
  update_option('wpms_google_alanytics', $this->google_alanytics);
 
2702
  } catch (Google_IO_Exception $e) {
 
2703
  } catch (Google_Service_Exception $e) {
 
2704
  } catch (Exception $e) {
 
2705
  }
2706
  } else {
2707
+ echo "<div class='error'><p>" . __("The access code is
2708
+ <strong>NOT</strong> your <strong>Tracking ID</strong>
2709
+ (UA-XXXXX-X). Try again, and use the red link to get your access code", 'wp-meta-seo') . ".</p></div>";
2710
  }
2711
 
 
2712
  update_option('wpms_google_alanytics', $this->google_alanytics);
2713
+ wp_redirect(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode'));
2714
  exit;
2715
  }
2716
+ $this->gaDisconnect = array(
2717
  'wpms_ga_uax_reference' => '',
2718
  'wpmsga_dash_tracking_type' => 'classic',
2719
  'wpmsga_code_tracking' => ''
2720
  );
2721
+ $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
2722
+ if (is_array($gaDisconnect)) {
2723
+ $this->gaDisconnect = array_merge(
2724
+ $this->gaDisconnect,
2725
+ $gaDisconnect
2726
+ );
2727
  }
2728
+ if (isset($_POST['_metaseo_ga_disconnect'])) {
2729
+ update_option('_metaseo_ggtracking_disconnect_settings', $_POST['_metaseo_ga_disconnect']);
2730
+ $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings');
2731
+ if (is_array($gaDisconnect)) {
2732
+ $this->gaDisconnect = array_merge(
2733
+ $this->gaDisconnect,
2734
+ $gaDisconnect
2735
+ );
2736
  }
2737
  }
2738
 
2739
  $this->google_alanytics = get_option('wpms_google_alanytics');
2740
  if (!empty($this->google_alanytics['googleCredentials'])) {
2741
+ if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
2742
+ $message = "<div class='error'><p>" . __("The tracking component is
2743
+ disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
2744
+ ", 'wp-meta-seo') . ".</p></div>";
2745
  echo $message;
2746
  }
2747
  echo '<div class="wrap wpmsga_wrap">';
2748
  echo '<div>';
2749
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/menu.php');
2750
+ echo '<h2>' . __("Google Analytics Settings", "wp-meta-seo") . '</h2>';
2751
  echo '<div id="wpms-window-1"></div>';
2752
  echo '</div>';
2753
  echo '</div>';
2754
  } else {
2755
+ if (empty($this->ga_tracking['wpmsga_dash_tracking'])) {
2756
+ $message = "<div class='error'><p>" . __("The tracking component is disabled.
2757
+ You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>
2758
+ ", 'wp-meta-seo') . ".</p></div>";
2759
  echo $message;
2760
  }
2761
+
2762
+ if (isset($this->google_alanytics['wpmsga_dash_userapi'])
2763
+ && $this->google_alanytics['wpmsga_dash_userapi'] == 1) {
2764
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/form-connect.php');
2765
+ } else {
2766
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-analytics/google-analytics.php');
2767
  }
2768
  }
2769
  }
2770
 
2771
  $w = '99%';
2772
+ $text = __('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report,
2773
+ Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo');
2774
  $class_btn_close = 'close_gga';
2775
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php');
2776
  break;
2777
  case 'metaseo_google_sitemap':
2778
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
2779
  // remove filter by lang
2780
  if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
2781
  global $sitepress;
2782
+ remove_filter('terms_clauses', array($sitepress, 'terms_clauses'));
2783
+ } elseif (is_plugin_active('polylang/polylang.php')) {
2784
  global $polylang;
2785
  $filters_term = $polylang->filters_term;
2786
  remove_filter('terms_clauses', array($filters_term, 'terms_clauses'));
2787
  }
2788
  }
2789
 
2790
+ if (!class_exists('MetaSeoSitemap')) {
2791
+ require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-sitemap.php');
2792
  }
2793
 
2794
+ $sitemap = new MetaSeoSitemap();
2795
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/sitemaps/metaseo-google-sitemap.php');
2796
  break;
2797
  case 'metaseo_image_compression':
2798
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-image-compression.php');
2799
  break;
2800
  case 'metaseo_broken_link':
2801
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php');
2802
  break;
2803
  case 'metaseo_settings':
2804
  $posts = get_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'numberposts' => -1));
2805
+ $types_404 = array(
2806
+ 'none' => 'None',
2807
+ 'wp-meta-seo-page' => __('WP Meta SEO page', 'wp-meta-seo'),
2808
+ 'custom_page' => __('Custom page', 'wp-meta-seo')
2809
+ );
2810
 
2811
  // get settings 404
2812
+ $defaul_settings_404 = array(
2813
+ 'wpms_redirect_homepage' => 0,
2814
+ 'wpms_type_404' => 'none',
2815
+ 'wpms_page_redirected' => 'none'
2816
+ );
2817
  $wpms_settings_404 = get_option('wpms_settings_404');
2818
  if (is_array($wpms_settings_404)) {
2819
  $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404);
2820
  }
2821
 
2822
  // get settings breadcrumb
2823
+ $home_title = get_the_title(get_option('page_on_front'));
2824
+ if (empty($home_title)) {
2825
+ $home_title = get_bloginfo('title');
2826
+ }
2827
  $breadcrumbs = array(
2828
  'separator' => ' &gt; ',
2829
  'include_home' => 1,
2838
 
2839
  // email settings
2840
  $email_settings = array(
2841
+ "enable" => 0,
2842
+ "host" => "smtp.gmail.com",
2843
+ "type_encryption" => "ssl",
2844
+ "port" => "465",
2845
+ "autentication" => "yes",
2846
+ "username" => "",
2847
+ "password" => "",
2848
  );
2849
 
2850
  $mailsettings = get_option('wpms_email_settings');
2852
  $email_settings = array_merge($email_settings, $mailsettings);
2853
  }
2854
 
2855
+ $html_tabemail = apply_filters('wpmsaddon_emailsettings', '', $email_settings);
2856
 
2857
  // link settings
2858
  $link_settings = array(
2866
  $link_settings = array_merge($link_settings, $linksettings);
2867
  }
2868
 
2869
+ $link_settings_html = apply_filters('wpmsaddon_linksettings', '', $link_settings);
2870
 
2871
  // local business settings
2872
  $local_business = array(
2885
  if (is_array($business)) {
2886
  $local_business = array_merge($local_business, $business);
2887
  }
2888
+ $countrys = apply_filters('wpms_get_countryList', array());
2889
+ $local_business_html = apply_filters('wpmsaddon_local_business', '', $local_business, $countrys);
2890
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php');
2891
  break;
2892
 
2893
  case 'metaseo_content_meta':
2894
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/content-meta.php');
2895
  break;
2896
 
2897
 
2898
  case 'metaseo_image_meta':
2899
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/image-meta.php');
2900
  break;
2901
 
2902
  case 'metaseo_link_meta':
2903
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/link-meta.php');
2904
  break;
2905
 
2906
  case 'metaseo_image_optimize':
2907
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/image-optimize.php');
2908
  break;
2909
 
2910
  case 'metaseo_dashboard':
2911
  default:
2912
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard.php');
2913
  break;
2914
  }
2915
  }
2916
  }
2917
+
2918
+ /**
2919
  * Ajax check attachment have alt empty
2920
  */
2921
+ public function checkExist()
2922
+ {
2923
  if (isset($_POST['type'])) {
2924
  if ($_POST['type'] == 'alt') {
2925
  $margs = array(
2943
  }
2944
  } else {
2945
  global $wpdb;
2946
+ $sql = $wpdb->prepare(
2947
+ "SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts
2948
+ WHERE posts.post_type = %s AND post_title != %s",
2949
+ array('attachment', '')
2950
+ );
2951
  $check_title = $wpdb->get_var($sql);
2952
  if ($check_title > 0) {
2953
  wp_send_json(true);
2957
  }
2958
  }
2959
  }
2960
+
2961
+ /**
2962
  * Ajax update image alt and image title
2963
  */
2964
+ public function bulkImageCopy()
2965
+ {
2966
  global $wpdb;
2967
+ if (empty($_POST['mtype'])) {
2968
  wp_send_json(false);
2969
+ }
2970
+
2971
  if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') {
2972
  // select all
2973
  $limit = 500;
 
 
 
 
 
 
 
 
 
 
2974
  // query attachment and update meta
2975
+ $sql = $wpdb->prepare(
2976
+ "SELECT COUNT(posts.ID) as total FROM " . $wpdb->prefix . "posts as posts
2977
+ WHERE posts.post_type = %s",
2978
+ array('attachment')
2979
+ );
2980
  $total = $wpdb->get_var($sql);
2981
 
2982
+ $j = ceil((int)$total / $limit);
2983
  for ($i = 0; $i <= $j; $i++) {
2984
  $ofset = $i * $limit;
2985
  $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts as posts
2986
+ WHERE posts.post_type = %s LIMIT %d OFFSET %d", array('attachment', $limit, $ofset));
2987
  $attachments = $wpdb->get_results($sql);
2988
 
2989
  foreach ($attachments as $attachment) {
3050
  }
3051
  }
3052
  }
3053
+
3054
+ /**
3055
  * Ajax bulk update meta title for a post/page
3056
  */
3057
+ public function bulkPostCopyTitle()
3058
+ {
3059
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
3060
  unset($post_types['attachment']);
3061
+ $margs = array();
3062
+ if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] == 'all') { // for select a;;
3063
  $margs = array(
3064
  'posts_per_page' => -1,
3065
  'post_type' => $post_types,
3066
+ 'post_status' => array(
3067
+ 'publish',
3068
+ 'pending',
3069
+ 'draft',
3070
+ 'auto-draft',
3071
+ 'future',
3072
+ 'private',
3073
+ 'inherit',
3074
+ 'trash'
3075
+ ),
3076
  'meta_query' => array(
3077
  'relation' => 'OR',
3078
  array(
3084
  'value' => false,
3085
  'type' => 'BOOLEAN'
3086
  ),
3087
+ ));
3088
+ } else { // for select some post
3089
  if (isset($_POST['ids'])) {
3090
  $ids = $_POST['ids'];
3091
  $margs = array(
3092
  'posts_per_page' => -1,
3093
  'post_type' => $post_types,
3094
+ 'post_status' => array(
3095
+ 'publish',
3096
+ 'pending',
3097
+ 'draft',
3098
+ 'auto-draft',
3099
+ 'future',
3100
+ 'private',
3101
+ 'inherit',
3102
+ 'trash'
3103
+ ),
3104
  'post__in' => $ids,
3105
  'meta_query' => array(
3106
  'relation' => 'OR',
3113
  'value' => false,
3114
  'type' => 'BOOLEAN'
3115
  ),
3116
+ ));
3117
  } else {
3118
  wp_send_json(false);
3119
  }
3127
  }
3128
  wp_send_json(true);
3129
  } else {
 
3130
  wp_send_json(false);
3131
  }
3132
  }
3134
  /**
3135
  * set cookie notification
3136
  */
3137
+ public function setcookieNotification()
3138
+ {
3139
+ if (isset($_POST['page'])) {
3140
  setcookie($_POST['page'], time(), time() + (86400 * 30), "/");
3141
  wp_send_json(true);
3142
  }
3143
  wp_send_json(false);
3144
  }
3145
+
3146
+ /**
3147
+ * Run ajax
3148
+ */
3149
+ public function startProcess()
3150
+ {
3151
+ if (isset($_REQUEST['task'])) {
3152
+ switch ($_REQUEST['task']) {
3153
+ case 'updateContentMeta':
3154
+ $this->updateContentMetaCallback();
3155
+ break;
3156
+ case 'scanPosts':
3157
+ MetaSeoImageListTable::scanPostsCallback();
3158
+ break;
3159
+ case 'load_posts':
3160
+ MetaSeoImageListTable::loadPostsCallback();
3161
+ break;
3162
+ case 'optimize_imgs':
3163
+ MetaSeoImageListTable::optimizeImages();
3164
+ break;
3165
+ case 'updateMeta':
3166
+ MetaSeoImageListTable::updateMetaCallback();
3167
+ break;
3168
+ case 'import_meta_data':
3169
+ MetaSeoContentListTable::importMetaData();
3170
+ break;
3171
+ case 'dismiss_import_meta':
3172
+ MetaSeoContentListTable::dismissImport();
3173
+ break;
3174
+ case 'bulk_post_copy':
3175
+ $this->bulkPostCopyTitle();
3176
+ break;
3177
+ case 'bulk_image_copy':
3178
+ $this->bulkImageCopy();
3179
+ break;
3180
+ case 'ajax_check_exist':
3181
+ $this->checkExist();
3182
+ break;
3183
+ case 'reload_analysis':
3184
+ $this->reloadAnalysis();
3185
+ break;
3186
+ case 'validate_analysis':
3187
+ $this->validateAnalysis();
3188
+ break;
3189
+ case 'update_link':
3190
+ $this->updateLink();
3191
+ break;
3192
+ case 'save_settings404':
3193
+ $this->save404Settings();
3194
+ break;
3195
+ case 'save_settings_breadcrumb':
3196
+ $this->saveBreadcrumbSettings();
3197
+ break;
3198
+ case 'update_link_redirect':
3199
+ MetaSeoBrokenLinkTable::updateLinkRedirect();
3200
+ break;
3201
+ case 'add_custom_redirect':
3202
+ MetaSeoBrokenLinkTable::addCustomRedirect();
3203
+ break;
3204
+ case 'unlink':
3205
+ MetaSeoBrokenLinkTable::unlink();
3206
+ break;
3207
+ case 'recheck_link':
3208
+ MetaSeoBrokenLinkTable::reCheckLink();
3209
+ break;
3210
+ case 'scan_link':
3211
+ MetaSeoBrokenLinkTable::scanLink();
3212
+ break;
3213
+ case 'flush_link':
3214
+ MetaSeoBrokenLinkTable::flushLink();
3215
+ break;
3216
+ case 'update_follow':
3217
+ $this->updateFollow();
3218
+ break;
3219
+ case 'update_multiplefollow':
3220
+ $this->updateMultipleFollow();
3221
+ break;
3222
+ case 'update_pagefollow':
3223
+ $this->updatePageFollow();
3224
+ break;
3225
+ case 'update_pageindex':
3226
+ $this->updatePageIndex();
3227
+ break;
3228
+ case 'backend_item_reports':
3229
+ MetaSeoGoogleAnalytics::itemsReport();
3230
+ break;
3231
+ case 'ga_clearauthor':
3232
+ MetaSeoGoogleAnalytics::clearAuthor();
3233
+ break;
3234
+ case 'ga_update_option':
3235
+ MetaSeoGoogleAnalytics::updateOption();
3236
+ break;
3237
+ case 'dash_permalink':
3238
+ MetaSeoDashboard::dashboardPermalink();
3239
+ break;
3240
+ case 'dash_newcontent':
3241
+ MetaSeoDashboard::dashboardNewContent();
3242
+ break;
3243
+ case 'dash_linkmeta':
3244
+ MetaSeoDashboard::dashboardLinkMeta();
3245
+ break;
3246
+ case 'dash_metatitle':
3247
+ MetaSeoDashboard::dashboardMetaTitle();
3248
+ break;
3249
+ case 'dash_metadesc':
3250
+ MetaSeoDashboard::dashboardMetaDesc();
3251
+ break;
3252
+ case 'dash_imgsmeta':
3253
+ MetaSeoDashboard::dashImgsMeta();
3254
+ break;
3255
+ case 'setcookie_notification':
3256
+ $this->setcookieNotification();
3257
+ break;
3258
+ case 'image_scan_meta':
3259
+ MetaSeoImageListTable::imageScanMeta();
3260
+ break;
3261
+ }
3262
+ }
3263
  }
3264
  }
inc/class.metaseo-broken-link-table.php CHANGED
@@ -1,80 +1,106 @@
1
  <?php
2
- /**
3
- * Base class for displaying a list of links in an ajaxified HTML table.
4
- *
5
- */
6
  if (!class_exists('WP_List_Table')) {
7
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
8
  }
9
 
10
- class MetaSeo_Broken_Link_Table extends WP_List_Table {
11
-
 
 
 
 
 
 
 
12
  public $link_view = array();
 
 
 
13
  public static $img_pattern = '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i';
 
 
 
14
  public static $old_url = '';
 
 
 
15
  public static $new_url = '';
16
 
17
- function __construct() {
 
 
 
 
18
  parent::__construct(array(
19
  'singular' => 'metaseo_image',
20
  'plural' => 'metaseo_images',
21
  'ajax' => true
22
  ));
23
  }
24
-
25
  /**
26
- * Generate the table navigation above or below the table
27
- * @param string $which
28
- */
29
- function display_tablenav($which) {
 
30
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
31
- if (!empty($post_types['attachment']))
32
  unset($post_types['attachment']);
33
- $p_type = "('" . implode("','", $post_types) . "')";
34
  ?>
35
  <div class="tablenav <?php echo esc_attr($which); ?>">
36
 
37
- <?php if ($which == 'top'): ?>
38
- <input type="hidden" name="page" value="metaseo_image_meta" />
39
 
40
  <div class="alignleft actions bulkactions">
41
- <?php $this->broken_fillter('sl_broken'); ?>
42
- <?php $this->redirect_fillter('sl_redirect'); ?>
43
- <?php $this->type_fillter('sltype'); ?>
44
- <?php $this->flush_fillter('sl_flush'); ?>
45
  </div>
46
- <?php elseif ($which == 'bottom'): ?>
47
- <input type="hidden" name="page" value="metaseo_image_meta" />
48
  <div class="alignleft actions bulkactions">
49
- <?php $this->broken_fillter('sl_broken1'); ?>
50
- <?php $this->redirect_fillter('sl_redirect1'); ?>
51
- <?php $this->type_fillter('sltype1'); ?>
52
  </div>
53
  <?php endif ?>
54
 
55
- <input type="hidden" name="page" value="metaseo_image_meta" />
56
- <?php if (!empty($_REQUEST['post_status'])): ?>
57
- <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>" />
58
  <?php endif ?>
59
 
60
  <div style="float:right;margin-left:8px;">
61
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>" maxlength="3" name="metaseo_broken_link_per_page" class="metaseo_imgs_per_page screen-per-page" max="999" min="1" step="1">
62
- <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply" >
 
 
 
 
 
 
63
  </div>
64
 
65
- <?php $this->pagination($which); ?>
66
- <br class="clear" />
67
  </div>
68
 
69
  <?php
70
  }
71
-
72
  /**
73
- * Get a list of columns. The format is:
74
- * 'internal-name' => 'Title'
75
- * @return array
76
- */
77
- function get_columns() {
 
78
  return $columns = array(
79
  'col_link_url' => __('URL', 'wp-meta-seo'),
80
  'col_hit' => __('Hits number', 'wp-meta-seo'),
@@ -83,17 +109,18 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
83
  'col_source' => __('Source', 'wp-meta-seo'),
84
  );
85
  }
86
-
87
  /**
88
- * Get a list of sortable columns. The format is:
89
- * 'internal-name' => 'orderby'
90
- * or
91
- * 'internal-name' => array( 'orderby', true )
92
- *
93
- * The second format will make the initial sorting order be descending
94
- * @return array
95
- */
96
- function get_sortable_columns() {
 
97
  return $sortable = array(
98
  'col_status' => array('status_text', true),
99
  'col_link_url' => array('link_url', true)
@@ -108,26 +135,30 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
108
  *
109
  * @param bool $with_id Whether to set the id attribute or not
110
  */
111
- public function print_column_headers($with_id = true) {
112
- list( $columns, $hidden, $sortable ) = $this->get_column_info();
 
113
 
114
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
115
  $current_url = remove_query_arg('paged', $current_url);
116
 
117
- if (isset($_GET['orderby']))
118
  $current_orderby = $_GET['orderby'];
119
- else
120
  $current_orderby = '';
 
121
 
122
- if (isset($_GET['order']) && 'desc' == $_GET['order'])
123
  $current_order = 'desc';
124
- else
125
  $current_order = 'asc';
 
126
 
127
  if (!empty($columns['cb'])) {
128
  static $cb_counter = 1;
129
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All', 'wp-meta-seo') . '</label>'
130
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
 
131
  $cb_counter++;
132
  }
133
 
@@ -135,18 +166,19 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
135
  $class = array('manage-column', "column-$column_key");
136
 
137
  $style = '';
138
- if (in_array($column_key, $hidden))
139
  $style = 'display:none;';
140
-
141
  $style = ' style="' . $style . '"';
142
 
143
- if ('cb' == $column_key)
144
  $class[] = 'check-column';
145
- elseif (in_array($column_key, array('posts', 'comments', 'links')))
146
  $class[] = 'num';
 
147
 
148
  if (isset($sortable[$column_key])) {
149
- list( $orderby, $desc_first ) = $sortable[$column_key];
150
 
151
  if ($current_orderby == $orderby) {
152
  $order = 'asc' == $current_order ? 'desc' : 'asc';
@@ -157,14 +189,18 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
157
  $class[] = 'sortable';
158
  $class[] = $desc_first ? 'asc' : 'desc';
159
  }
160
-
161
- $column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
 
 
 
162
  }
163
 
164
  $id = $with_id ? "id='$column_key'" : '';
165
 
166
- if (!empty($class))
167
  $class = "class='" . join(' ', $class) . "'";
 
168
 
169
  if ($column_key === 'cb') {
170
  echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
@@ -173,13 +209,14 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
173
  }
174
  }
175
  }
176
-
177
  /**
178
- * Prepares the list of items for displaying.
179
- * @uses WP_List_Table::set_pagination_args()
180
- */
181
- function prepare_items() {
182
- global $wpdb, $_wp_column_headers;
 
183
  $where = array('1=1');
184
  if (!empty($_REQUEST['sltype']) && $_REQUEST['sltype'] != 'all') {
185
  if ($_REQUEST['sltype'] != 'other') {
@@ -192,7 +229,7 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
192
  if (!empty($_REQUEST['sl_broken']) && $_REQUEST['sl_broken'] != 'all') {
193
  if ($_REQUEST['sl_broken'] == 'custom_redirect_url') {
194
  $where[] = "link_url_redirect !=''";
195
- } else if ($_REQUEST['sl_broken'] == 'valid_links') {
196
  $where[] = "broken_internal = 0 AND broken_indexed = 0";
197
  } elseif ($_REQUEST['sl_broken'] == 'internal_broken_links') {
198
  $where[] = "broken_internal = 1";
@@ -219,7 +256,7 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
219
  $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
220
  $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
221
  $sortable = $this->get_sortable_columns();
222
- $orderby_array = array($orderby,true);
223
  if (in_array($orderby_array, $sortable)) {
224
  $orderStr = $orderby;
225
  } else {
@@ -243,7 +280,7 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
243
  $hidden = array();
244
  $sortable = $this->get_sortable_columns();
245
  $this->_column_headers = array($columns, $hidden, $sortable);
246
-
247
  $query = "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
248
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
249
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
@@ -275,7 +312,7 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
275
 
276
  if (!empty($paged) && !empty($per_page)) {
277
  $offset = ($paged - 1) * $per_page;
278
- $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
279
  }
280
 
281
  $this->set_pagination_args(array(
@@ -287,41 +324,66 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
287
 
288
  $this->items = $wpdb->get_results($query);
289
  }
290
-
291
  /**
292
- * Displays the search box.
293
- */
294
- function search_box1() {
295
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
296
- require_once (WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/custom_redirect_form.php');
 
297
  }
298
- if (empty($_REQUEST['txtkeyword']) && !$this->has_items())
299
  return;
 
 
300
  $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
301
- if (!empty($_REQUEST['orderby']))
302
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
303
- if (!empty($_REQUEST['order']))
 
 
304
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
305
- if (!empty($_REQUEST['post_mime_type']))
 
 
306
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
307
- if (!empty($_REQUEST['detached']))
 
 
308
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
 
 
309
  ?>
310
  <p class="search-box">
311
- <input type="search" id="image-search-input" name="txtkeyword" value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>" />
 
 
 
 
312
  <?php submit_button('Search URL', 'button', 'search', false, array('id' => 'search-submit')); ?>
313
  </p>
314
  <?php
315
  }
316
-
317
- /* Add fillter redirect */
318
- function redirect_fillter($name) {
319
- $redirects = array('not_yet_redirect' => __('Not yet redirected', 'wp-meta-seo'), 'already_redirect' => __('Already redirected', 'wp-meta-seo'));
 
 
 
 
 
 
 
320
  $curent_redirect = isset($_REQUEST['sl_redirect']) ? $_REQUEST['sl_redirect'] : 'all';
321
  ?>
322
- <label for="filter-by-redirect" class="screen-reader-text"><?php _e('Filter by redirect', 'wp-meta-seo'); ?></label>
 
323
  <select name="<?php echo $name ?>" id="filter-by-redirect" class="redirect_fillter">
324
- <option<?php selected($curent_redirect, 'all'); ?> value="all"><?php _e('Status', 'wp-meta-seo'); ?></option>
 
 
325
  <?php
326
  foreach ($redirects as $k => $redirect) {
327
  if ($curent_redirect == $k) {
@@ -335,15 +397,19 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
335
 
336
  <?php
337
  }
338
-
339
- /* Add fillter broken */
340
- function broken_fillter($name) {
 
 
 
 
341
  $brokens = array(
342
  'valid_links' => __('Valid links', 'wp-meta-seo'),
343
  'automaticaly_indexed' => __('404 automaticaly indexed', 'wp-meta-seo'),
344
  'internal_broken_links' => __('Internal broken links', 'wp-meta-seo')
345
- );
346
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
347
  $brokens['custom_redirect_url'] = __('Custom redirect URL', 'wp-meta-seo');
348
  }
349
  $curent_broken = isset($_REQUEST['sl_broken']) ? $_REQUEST['sl_broken'] : 'all';
@@ -365,9 +431,17 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
365
  <?php
366
  }
367
 
368
- /* Add fillter type */
369
- function type_fillter($name) {
370
- $types = array('url' => __('URL','wp-meta-seo') , 'image' => __('Image','wp-meta-seo'), 'other' => __('Other','wp-meta-seo'));
 
 
 
 
 
 
 
 
371
  $curent_type = isset($_REQUEST['sltype']) ? $_REQUEST['sltype'] : 'all';
372
  ?>
373
  <label for="filter-by-type" class="screen-reader-text"><?php _e('Filter by type', 'wp-meta-seo'); ?></label>
@@ -383,16 +457,27 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
383
  }
384
  ?>
385
  </select>
386
- <input type="submit" name="filter_type_action" id="broken-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="<?php _e('Filter', 'wp-meta-seo') ?>">
 
387
  <?php
388
  echo '<div style="float:left;padding-left: 5px;"><div class="wpms_process" data-w="0"></div>';
389
- echo '<div data-comment_paged="1" data-paged="1" class="wpmsbtn wpmsbtn_small wpms_scan_link">' . __('Index internal broken links', 'wp-meta-seo') . '</div></div>';
 
 
390
  echo '<span class="spinner"></span>';
391
  }
392
-
393
- /* Add fillter flush */
394
- function flush_fillter($name) {
395
- $flushs = array('automaticaly_indexed' => __('Automatic indexed 404', 'wp-meta-seo'), 'internal_broken_links' => __('Internal broken links', 'wp-meta-seo'), 'all' => __('Flush all 404', 'wp-meta-seo'));
 
 
 
 
 
 
 
 
396
  ?>
397
  <label for="filter-by-flush" class="screen-reader-text"><?php _e('Filter by flush', 'wp-meta-seo'); ?></label>
398
  <select name="<?php echo $name ?>" id="filter-by-flush">
@@ -405,35 +490,25 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
405
  </select>
406
 
407
  <?php
408
- echo '<div class="wpmsbtn wpmsbtn_small wpmsbtn_secondary wpms_flush_link">' . __('Flush', 'wp-meta-seo') . '</div>';
 
 
409
  }
410
-
411
  /**
412
- * Generate the table rows
413
- */
414
- function display_rows() {
415
- $url = URL;
416
- $url = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', $url);
417
  $records = $this->items;
418
  $i = 0;
419
- $alternate = "";
420
-
421
- list( $columns, $hidden ) = $this->get_column_info();
422
  if (!empty($records)) {
423
  foreach ($records as $rec) {
424
  $i++;
425
- echo '<tr id="record_' . $i . '" data-linkid="'.$rec->id.'" data-link="' . $i . '" data-post_id="' . $rec->source_id . '">';
 
426
  foreach ($columns as $column_name => $column_display_name) {
427
-
428
- $class = sprintf('class="%1$s column-%1$s"', $column_name);
429
- $style = "";
430
-
431
- if (in_array($column_name, $hidden)) {
432
- $style = ' style="display:none;"';
433
- }
434
-
435
- $attributes = $class . $style;
436
-
437
  switch ($column_name) {
438
  case 'col_link_url':
439
  if ($rec->type == 'url') {
@@ -442,29 +517,53 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
442
  $value_url = $rec->link_url;
443
  }
444
  echo '<td class="wpms_link_html" colspan="3">';
445
- echo '<input type="hidden" class="wpms_link_text" value="' . esc_attr($rec->link_text) . '">';
 
446
  if ($rec->type == 'add_custom') {
447
- echo '<a class="link_html" target="_blank" href="' . esc_url(site_url() . '/' . $rec->link_url) . '">' . $value_url . '</a>';
448
- if($rec->link_url_redirect != ''){
 
449
  echo ' to ';
450
- echo '<a class="link_html" target="_blank" href="' . esc_url($rec->link_url_redirect) . '">' . str_replace(site_url(),'',$rec->link_url_redirect) . '</a>';
 
 
451
  }
452
- }else{
453
- echo '<a class="link_html" target="_blank" href="' . esc_url($value_url) . '">' . $value_url . '</a>';
 
454
  }
455
 
456
  $row_action = array(
457
- 'edit' => '<a class="wpms_action_link wpms-edit-button" title="'.__('Edit redirect','wp-meta-seo').'"><div class="wpms_icon_action"><i class="material-icons">mode_edit</i></div><span>' . __('Edit', 'wp-meta-seo') . '</span></a>',
458
- 'delete' => '<a class="wpms_action_link submitdelete wpms-unlink-button" data-link_id="' . $rec->id . '" data-type="' . $rec->type . '" data-source_id="' . $rec->source_id . '" title="' . __('Remove redirect or link', 'wp-meta-seo') . '"><div class="wpms_icon_action"><i class="material-icons">delete_forever</i></div><span>' . __('Remove redirect', 'wp-meta-seo') . '</span></a>',
459
- 'recheck' => '<a class="wpms_action_link wpms-recheck-button" data-link_id="' . $rec->id . '" data-type="' . $rec->type . '" data-source_id="' . $rec->source_id . '" title="' . __('Check the link', 'wp-meta-seo') . '"><div class="wpms_icon_action"><i class="material-icons">loop</i></div><span>' . __('Check', 'wp-meta-seo') . '</span></a>'
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  );
461
  echo $this->row_actions($row_action, false);
 
 
462
  if (!empty($rec->source_id)) {
463
  if ($rec->type == 'url') {
464
- $iii = 0;
465
  $pos = get_post($rec->source_id);
466
  if (!empty($pos)) {
467
- preg_match_all("#<a[^>]*>.*?</a>#si", $pos->post_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
468
  foreach ($matches[0] as $i => $content) {
469
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
470
  $href = $matches[1];
@@ -474,10 +573,14 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
474
  }
475
  }
476
  } elseif ($rec->type == 'comment_content_url') {
477
- $jjj = 0;
478
  $com = get_comment($rec->source_id);
479
  if (!empty($pos)) {
480
- preg_match_all("#<a[^>]*>.*?</a>#si", $com->comment_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
481
  foreach ($matches[0] as $i => $content) {
482
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
483
  $href = $matches[1];
@@ -491,51 +594,91 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
491
  ?>
492
  <div class="wpms-inline-editor-content">
493
  <h4><?php echo _x('Edit Link', 'inline editor title', 'wp-meta-seo'); ?></h4>
494
- <?php
495
- if ($rec->type == 'url') {
496
- if ($iii > 1) {
497
- echo '<span class="wpms-input-text-wrap"><span class="title">' . __('Text', 'wp-meta-seo') . '</span><input type="text" name="link_text" class="wpms-link-text-field" placeholder="' . __('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
498
- } else {
499
- echo '<span class="wpms-input-text-wrap"><span class="title">' . __('Text', 'wp-meta-seo') . '</span><input type="text" name="link_text" class="wpms-link-text-field" value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
500
- }
501
- } elseif ($rec->type == 'comment_content_url') {
502
- if ($jjj > 1) {
503
- echo '<span class="wpms-input-text-wrap"><span class="title">' . __('Text', 'wp-meta-seo') . '</span><input type="text" name="link_text" class="wpms-link-text-field" placeholder="' . __('Multiple link', 'wp-meta-seo') . '" data-type="multi" /></span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  } else {
505
- echo '<span class="wpms-input-text-wrap"><span class="title">' . __('Text', 'wp-meta-seo') . '</span><input type="text" name="link_text" class="wpms-link-text-field" value="' . esc_attr($rec->link_text) . '" data-type="only" /></span>';
506
- }
507
- } else {
508
- if($rec->type != 'add_custom'){
509
- echo '<span class="wpms-input-text-wrap"><span class="title">' . __('Text', 'wp-meta-seo') . '</span><input readonly type="text" name="link_text" class="wpms-link-text-field" value="(None)" data-type="only" /></span>';
510
- }else{
511
- ?>
512
- <p class="wpms-input-text-wrap">
513
  <span class="title">
514
  <?php _e('Status', 'wp-meta-seo') ?>
515
  </span>
516
- <select name="custom_redirect_status" class="custom_redirect_status">
517
- <option value="301" <?php selected($rec->meta_title,301) ?>>301</option>
518
- <option value="302" <?php selected($rec->meta_title,302) ?>>302</option>
519
- <option value="307" <?php selected($rec->meta_title,307) ?>>307</option>
520
- </select>
521
- </p>
522
- <?php
 
 
 
 
 
 
523
  }
524
- }
525
- ?>
526
 
527
- <p class="wpms-input-text-wrap"><span class="title"><?php _e('URL', 'wp-meta-seo'); ?></span><input <?php echo ($rec->type == '404_automaticaly') ? 'readonly' : '' ?> type="text" name="link_url" class="wpms-link-url-field" value="<?php echo esc_attr($value_url); ?>" /></p>
 
 
 
 
 
 
 
 
 
 
528
  <p class="wpms-input-text-wrap">
529
  <span class="title"><?php _e('Redirect', 'wp-meta-seo'); ?></span>
530
- <input type="text" name="link_url_redirect" class="wpms-link-redirect-field" value="<?php echo esc_attr($rec->link_url_redirect); ?>" />
531
- <span class="wlink-btn"><i class="mce-ico mce-i-link link-btn" id="link-btn"></i></span>
 
 
 
 
 
532
  </p>
533
- </label>
534
 
535
- <div class="submit wpms-inline-editor-buttons">
536
- <input type="button" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary cancel alignleft wpms-cancel-button" value="<?php echo esc_attr(__('Cancel', 'wp-meta-seo')); ?>" />
537
- <input type="button" data-type="<?php echo $rec->type ?>" data-link_id="<?php echo $rec->id ?>" data-source_id="<?php echo $rec->source_id ?>" class="wpmsbtn wpmsbtn_small save alignright wpms-update-link-button" value="<?php echo esc_attr(__('Add custom redirect', 'wp-meta-seo')); ?>" />
538
- </div>
 
 
 
 
 
 
 
539
  </div>
540
  <?php
541
  echo '</td>';
@@ -551,15 +694,22 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
551
  if (strpos($rec->status_text, '200') !== false) {
552
  echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Link is OK">done</i>';
553
  } elseif (strpos($rec->status_text, '301') !== false) {
554
- echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Permanent redirect">done</i>';
 
555
  } elseif (strpos($rec->status_text, '302') !== false) {
556
- echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Moved temporarily">done</i>';
557
- } elseif (strpos($rec->status_text, '404') !== false || $rec->status_text == 'Server Not Found') {
 
 
558
  $wpms_settings_404 = get_option('wpms_settings_404');
559
- if ((isset($wpms_settings_404['wpms_redirect_homepage']) && $wpms_settings_404['wpms_redirect_homepage'] == 1) || $rec->link_url_redirect != '') {
560
- echo '<i class="material-icons wpms_ok metaseo_help_status" alt="Permanent redirect">done</i>';
 
 
 
561
  } else {
562
- echo '<i class="material-icons wpms_warning metaseo_help_status" alt="404 error, not found">warning</i>';
 
563
  }
564
  } else {
565
  echo $rec->status_text;
@@ -570,50 +720,76 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
570
 
571
  case 'col_link_text':
572
  if ($rec->type == 'image' || $rec->type == 'comment_content_image') {
573
- echo '<td colspan="3" class="link_text"><span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="Images">photo</i></span><span> ' . __('Image', 'wp-meta-seo') . '</span></td>';
 
 
574
  } elseif ($rec->type == 'comment') {
575
  echo '<td colspan="3" class="link_text"><span> ' . $rec->link_text . '</span></td>';
576
  } else {
577
  if (strip_tags($rec->link_text) != '') {
578
  echo '<td colspan="3" class="link_text">' . strip_tags($rec->link_text) . '</td>';
579
  } else {
580
- echo '<td colspan="3" class="link_text"><i>' . __('No text on this link', 'wp-meta-seo') . '</i></td>';
 
581
  }
582
  }
583
 
584
  break;
585
 
586
  case 'col_source':
 
 
587
  if ($rec->type == '404_automaticaly') {
588
- $source_inner = '<span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="External URL indexed">link</i></span>';
 
589
  $source_inner .= __('404 automaticaly indexed', 'wp-meta-seo');
590
  echo '<td colspan="3">' . $source_inner . '</td>';
591
  } else {
592
- if ($rec->type == 'comment' || $rec->type == 'comment_content_url' || $rec->type == 'comment_content_image') {
 
593
  $source = get_comment($rec->source_id);
594
  if (!empty($source)) {
595
  $row_action = array(
596
- 'edit' => '<a target="_blank" href="' . get_edit_comment_link($rec->source_id) . '" title="'.__('Edit this item','wp-meta-seo').'">'.__('Edit','wp-meta-seo','wp-meta-seo').'</a>',
597
- 'view' => '<a target="_blank" href="' . get_comment_link($rec->source_id) . '" title="View &#8220;'.$source->comment_author.'&#8221;" rel="permalink">'.__('View','wp-meta-seo').'</a>'
 
 
 
 
 
 
598
  );
599
 
600
  if ($rec->type == 'comment') {
601
- $source_inner = '<span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="Comments">person_outline</i></span>';
 
602
  } else {
603
- $source_inner = '<span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="Comments content">chat_bubble</i></span>';
 
604
  }
605
- $source_inner .= '<a target="_blank" href="' . get_edit_comment_link($rec->source_id) . '">' . $source->comment_author . '</a>';
 
 
606
  }
607
  } else {
608
  $source = get_post($rec->source_id);
609
  if (!empty($source)) {
610
  $row_action = array(
611
- 'edit' => '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '" title="'.__('Edit this item','wp-meta-seo').'">'.__('Edit','wp-meta-seo').'</a>',
612
- 'view' => '<a target="_blank" href="' . get_post_permalink($rec->source_id) . '" title="View &#8220;'.$source->post_title.'&#8221;" rel="permalink">View</a>'
 
 
 
 
 
 
613
  );
614
 
615
- $source_inner = '<span style="float: left;margin-right: 5px;"><i class="material-icons metaseo_help_status" alt="Post , Page , Custom post">layers</i></span>';
616
- $source_inner .= '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '">' . $source->post_title . '</a>';
 
 
 
617
  }
618
  }
619
 
@@ -622,10 +798,11 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
622
  echo $source_inner;
623
  echo $this->row_actions($row_action, false);
624
  } else {
625
- if($rec->type == 'add_custom' || $rec->type == 'add_rule'){
626
- echo '<a><i title="'.__('Custom redirect','wp-meta-seo').'" class="wpms_outgoing material-icons">call_missed_outgoing</i></a>';
627
- }else{
628
- echo '<a>'.__('Source Not Found','wp-meta-seo').'</a>';
 
629
  }
630
  }
631
  echo '</td>';
@@ -638,22 +815,34 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
638
  }
639
  }
640
  }
641
-
642
  /*
643
  * Retrieves a modified URL query string.
644
  */
645
- public function process_action() {
646
- global $wpdb;
647
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
648
  $redirect = false;
649
 
650
  if (isset($_POST['search'])) {
651
- $current_url = add_query_arg(array("search" => "Search", "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))), $current_url);
 
 
 
 
 
652
  $redirect = true;
653
  }
654
 
655
  if (isset($_POST['filter_type_action'])) {
656
- $current_url = add_query_arg(array("sltype" => $_POST["sltype"], 'sl_redirect' => $_POST["sl_redirect"], 'sl_broken' => $_POST["sl_broken"]), $current_url);
 
 
 
 
 
 
 
657
  $redirect = true;
658
  }
659
 
@@ -663,7 +852,12 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
663
  }
664
 
665
  if (!empty($_POST['metaseo_broken_link_per_page'])) {
666
- $current_url = add_query_arg(array("metaseo_broken_link_per_page" => intval($_POST['metaseo_broken_link_per_page'])), $current_url);
 
 
 
 
 
667
  $redirect = true;
668
  }
669
 
@@ -673,103 +867,36 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
673
  exit();
674
  }
675
  }
676
-
677
- /*
678
- * Scan link in post content
679
- */
680
- public static function wpms_get_links() {
681
- global $wpdb, $_wp_column_headers;
682
-
683
- $where = array();
684
- $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
685
- if ($post_type == "-1") {
686
- $post_type = "";
687
- }
688
-
689
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
690
- unset($post_types['attachment']);
691
- if (!empty($post_type) && !in_array($post_type, $post_types))
692
- $post_type = '\'post\'';
693
- else if (empty($post_type)) {
694
- $post_type = "'" . implode("', '", esc_sql($post_types)) . "'";
695
- } else {
696
- $post_type = "'" . $post_type . "'";
697
- }
698
-
699
- $where[] = "post_type IN ($post_type)";
700
- $states = get_post_stati(array('show_in_admin_all_list' => true));
701
- $states['trash'] = 'trash';
702
- $all_states = "'" . implode("', '", esc_sql($states)) . "'";
703
-
704
- if (empty($_REQUEST['post_status'])) {
705
- $where[] = "post_status IN ($all_states)";
706
- } else {
707
- $requested_state = $_REQUEST['post_status'];
708
- if (in_array($requested_state, $states)) {
709
- $where[] = "post_status IN ('$requested_state')";
710
- } else {
711
- $where[] = "post_status IN ($all_states)";
712
- }
713
- }
714
-
715
- $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
716
- . " FROM $wpdb->posts "
717
- . " WHERE " . implode(' AND ', $where);
718
-
719
- $results = $wpdb->get_results($query);
720
- $list_link = array();
721
-
722
- // get link from comments
723
- $comments = get_comments();
724
- foreach ($comments as $comment) {
725
- if (!empty($comment->comment_author_url)) {
726
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
727
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($comment->comment_author_url);
728
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
729
- $list_link[$comment->comment_author_url . $comment->comment_ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $comment->comment_author_url, $comment->comment_author, 'comment', $status, $status_type);
730
- }
731
- }
732
-
733
- // get link from posts
734
- foreach ($results as $post) {
735
- if ($post->post_excerpt != 'metaseo_404_page') {
736
- $dom = new DOMDocument;
737
- libxml_use_internal_errors(true);
738
- if (isset($post->post_content) && $post->post_content != '') {
739
- preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
740
- foreach (array_unique($matches[0]) as $i => $content) {
741
- preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
742
- $href = $matches[1];
743
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
744
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
745
- $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
746
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
747
- $list_link[$href . 'url' . $post->ID . $link_text] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $href, $link_text, 'url', $status, $status_type);
748
- }
749
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
750
- foreach (array_unique($matches[0]) as $content) {
751
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
752
- preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
753
- $src = $matches[1];
754
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
755
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
756
- $link_text = '';
757
- $list_link[$src . 'img' . $post->ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $src, $link_text, 'image', $status, $status_type);
758
- }
759
- }
760
- }
761
- }
762
 
763
- return $list_link;
764
- }
765
-
766
- /*
767
- * Return detail link
 
 
 
 
 
 
 
 
768
  */
769
- public static function get_result_link($source_link, $source_id, $url, $link_text, $type, $status, $status_type, $meta_title = '', $rel = '', $postID = 0) {
 
 
 
 
 
 
 
 
 
 
 
770
  $res = array(
771
  'source_link' => $source_link,
772
- 'source_id' => (int) $source_id,
773
  'link_url' => $url,
774
  'link_text' => $link_text,
775
  'type' => $type,
@@ -811,17 +938,21 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
811
  }
812
  }
813
 
814
-
815
  return $res;
816
  }
817
 
818
- /*
819
  * Get link status
 
 
820
  */
821
- public static function get_urlstatus($url) {
 
822
  $status = @get_headers($url, 0);
823
- if (strpos($url, 'mailto:') !== false)
824
  return 'Not checked';
 
 
825
  if (strpos($url, '#') === 0 || strpos($url, 'tel:') === 0) {
826
  return 'HTTP/1.1 200 OK';
827
  }
@@ -831,23 +962,30 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
831
  return 'Server Not Found';
832
  }
833
  }
834
-
835
- /*
836
  * Get link status type
 
 
837
  */
838
- public static function get_urlstatus_type($status) {
839
- if (isset($status) && $status == 'Not checked')
 
840
  return 'ok';
 
 
841
  if (isset($status) && $status != 'Server Not Found') {
842
- if (((int) substr($status, 9, 3) >= 200 && (int) substr($status, 9, 3) <= 204) || (int) substr($status, 9, 3) == 401) {
 
843
  $type = 'ok';
844
- } elseif (((int) substr($status, 9, 3) >= 400 && (int) substr($status, 9, 3) <= 503 && (int) substr($status, 9, 3) != 401)) {
845
- if (in_array((int) substr($status, 9, 3), array(404, 410))) {
 
846
  $type = 'broken_internal';
847
  } else {
848
  $type = 'warning';
849
  }
850
- } elseif (((int) substr($status, 9, 3) >= 301 && (int) substr($status, 9, 3) <= 304)) {
851
  $type = 'ok';
852
  } else {
853
  $type = 'dismissed';
@@ -857,49 +995,66 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
857
  }
858
  return $type;
859
  }
860
-
861
- /*
862
  * Delete link comment in wpms_links table when delete comment
 
863
  */
864
- public static function wpms_deleted_comment($comment_ID) {
865
-
866
  global $wpdb;
867
  $wpdb->query(
868
- $wpdb->prepare(
869
- "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
870
  AND (type = %s || type = %s || type = %s)
871
- ", $comment_ID, 'comment', 'comment_content_url', 'comment_content_image'
872
- )
 
 
 
 
873
  );
874
  }
875
-
876
- /*
877
  * Delete link post in wpms_links table when delete post
 
878
  */
879
- public static function wpms_delete_post($post_id) {
 
880
  global $wpdb;
881
  $wpdb->query(
882
- $wpdb->prepare(
883
- "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
884
  AND type != %s
885
- ", $post_id, 'comment'
886
- )
 
 
887
  );
888
  }
889
-
890
- /*
891
  * Update wpms_links table when update comment
 
892
  */
893
- public static function wpms_update_comment($comment_ID) {
 
894
  global $wpdb;
895
  $comment = get_comment($comment_ID);
896
  $status = wp_get_comment_status($comment_ID);
897
  if ($status == 'approved') {
898
  if (!empty($comment->comment_author_url)) {
899
- $status = MetaSeo_Broken_Link_Table::get_urlstatus(($comment->comment_author_url));
900
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
901
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
902
- $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type=%s ", array($comment_ID, 'comment'));
 
 
 
 
 
 
903
  $check = $wpdb->get_var($sql);
904
  if ($check == 0) {
905
  $value = array(
@@ -918,7 +1073,8 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
918
  $value[$status_type] = 1;
919
  }
920
  $wpdb->insert(
921
- $wpdb->prefix . 'wpms_links', $value
 
922
  );
923
  } else {
924
  $value = array('link_url' => $comment->comment_author_url,
@@ -930,85 +1086,144 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
930
  'dismissed' => 0,
931
  );
932
 
933
- if (isset($_POST['link_redirect']))
934
  $value['link_url_redirect'] = ($_POST['link_redirect']);
 
935
 
936
  if (isset($status_type) && $status_type != 'ok') {
937
  $value[$status_type] = 1;
938
  }
939
  $wpdb->update(
940
- $wpdb->prefix . 'wpms_links', $value, array('source_id' => $comment_ID, 'type' => 'comment'), array('%s', '%s', '%s', '%d', '%d', '%d', '%d'), array('%d', '%s')
 
 
 
 
 
 
 
941
  );
942
  }
943
  } else {
944
  $wpdb->query(
945
- $wpdb->prepare("DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d AND (type = %s)", array($comment_ID, 'comment'))
 
 
 
 
 
 
946
  );
947
  }
948
 
949
-
950
  if (isset($comment->comment_content) && $comment->comment_content != '') {
951
  preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
952
  foreach (array_unique($matches[0]) as $i => $content) {
953
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
954
  $href = $matches[1];
955
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
956
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
957
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
958
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
959
- $links_in_content[$href . 'comment_content_url' . $comment->comment_ID . $link_text] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $href, $link_text, 'comment_content_url', $status, $status_type);
 
 
 
 
 
 
 
 
 
 
 
960
  }
961
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $comment->comment_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
962
  foreach (array_unique($matches[0]) as $content) {
963
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
964
  $src = $matches[1];
965
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
966
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
967
  $link_text = '';
968
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
969
- $links_in_content[$src . 'comment_content_image' . $comment->comment_ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $src, $link_text, 'comment_content_image', $status, $status_type);
 
 
 
 
 
 
 
 
 
 
 
970
  }
971
  }
972
 
973
- global $wpdb;
974
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND (type = %s || type = %s)", array($comment->comment_ID, "comment_content_url", "comment_content_image"));
 
 
 
 
 
 
975
  $links = $wpdb->get_results($sql);
976
  foreach ($links as $link) {
977
- if (empty($links_in_content[$link->link_url . $link->type])) {
978
  $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
979
  } else {
980
- unset($links_in_content[$link->link_url . $link->type . $link->link_text]);
981
  }
982
  }
983
 
984
- if (!empty($links_in_content)) {
985
- foreach ($links_in_content as $link) {
986
- MetaSeo_Broken_Link_Table::wpms_insert_link($link, $wpdb);
987
  }
988
  }
989
  } else {
990
- global $wpdb;
991
  $wpdb->query(
992
- $wpdb->prepare("DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d AND (type = %s || type = %s || type = %s)", array($comment_ID, 'comment', 'comment_content_url', 'comment_content_image'))
 
 
 
 
 
 
 
 
 
993
  );
994
  }
995
 
996
- update_option('wpms_last_update_post',time());
997
  }
998
-
999
- /*
1000
  * Update wpms_links table when update post
 
 
 
1001
  */
1002
- public static function wpms_update_post($post_ID, $post_after, $post_before) {
 
 
1003
  $post = $post_after;
1004
  $dom = new DOMDocument;
1005
  libxml_use_internal_errors(true);
1006
- $links_in_content = array();
1007
 
1008
  if ($post->post_excerpt != 'metaseo_404_page') {
1009
  if ($post->post_status == 'publish') {
1010
  if (isset($post->post_content) && $post->post_content != '') {
1011
-
1012
  preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
1013
  foreach (array_unique($matches[0]) as $i => $content) {
1014
  $dom->loadHTML($content);
@@ -1018,57 +1233,97 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1018
 
1019
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1020
  $href = $matches[1];
1021
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
1022
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1023
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1024
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
1025
- $links_in_content[$href . 'url' . $post->ID . $link_text] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $href, $link_text, 'url', $status, $status_type, $meta_title, $rel);
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  }
1027
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
1028
  foreach (array_unique($matches[0]) as $content) {
1029
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
 
 
1030
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1031
  $src = $matches[1];
1032
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
1033
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1034
  $link_text = '';
1035
- $links_in_content[$src . 'img' . $post->ID] = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $src, $link_text, 'image', $status, $status_type);
 
 
 
 
 
 
 
 
1036
  }
1037
  }
1038
 
1039
- global $wpdb;
1040
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type != %s", array($post->ID, "comment"));
 
 
 
 
 
1041
  $links = $wpdb->get_results($sql);
1042
  foreach ($links as $link) {
1043
- if (empty($links_in_content[$link->link_url . $link->type])) {
1044
  $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
1045
  } else {
1046
- unset($links_in_content[$link->link_url . $link->type . $link->link_text]);
1047
  }
1048
  }
1049
 
1050
- if (!empty($links_in_content)) {
1051
- foreach ($links_in_content as $link) {
1052
- MetaSeo_Broken_Link_Table::wpms_insert_link($link, $wpdb);
1053
  }
1054
  }
1055
  } else {
1056
- global $wpdb;
1057
  $wpdb->query(
1058
- $wpdb->prepare("DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d AND (type = %s || type = %s)", array($post->ID, 'image', 'url'))
 
 
 
 
 
 
 
 
1059
  );
1060
  }
1061
  }
1062
 
1063
- update_option('wpms_last_update_post',time());
1064
  }
1065
-
1066
- /*
1067
  * Scan link in comment , post
1068
  */
1069
- public static function wpms_scan_link() {
1070
-
1071
- global $wpdb, $_wp_column_headers;
1072
  $limit_comment_content = 1;
1073
  $limit_comment = 10;
1074
  $limit_post = 1;
@@ -1081,9 +1336,9 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1081
 
1082
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1083
  unset($post_types['attachment']);
1084
- if (!empty($post_type) && !in_array($post_type, $post_types))
1085
  $post_type = '\'post\'';
1086
- else if (empty($post_type)) {
1087
  $post_type = "'" . implode("', '", $post_types) . "'";
1088
  } else {
1089
  $post_type = "'" . $post_type . "'";
@@ -1094,37 +1349,60 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1094
  $where[] = "post_status = '$states'";
1095
  $total_comments = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "comments");
1096
  $total_posts = $wpdb->get_var("SELECT COUNT(*)"
1097
- . " FROM $wpdb->posts "
1098
- . " WHERE " . implode(' AND ', $where));
1099
 
1100
- $total_link = (int) $total_comments + (int) $total_posts;
1101
  $percent_comment_content = 33.33;
1102
  $percent_comment = 33.33;
1103
  $percent_post = 33.33;
1104
 
1105
- if (!empty($total_comments))
1106
  $percent_comment_content = 33.33 / $total_comments;
1107
- if ($total_comments < $limit_comment_content)
 
 
1108
  $percent_comment_content = 33.33;
1109
- if (!empty($total_comments))
 
 
1110
  $percent_comment = 33.33 / $total_comments;
1111
- if ($total_comments < $limit_comment)
 
 
1112
  $percent_comment = 33.33;
1113
- if (!empty($total_posts))
 
 
1114
  $percent_post = 33.33 / $total_posts;
1115
- if ($total_posts < $limit_post)
 
 
1116
  $percent_post = 33.33;
 
1117
 
1118
  // scan link in comment url
1119
- $comments = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "comments WHERE comment_approved = 1 AND comment_author_url != '' AND comment_author_url NOT IN (SELECT link_url FROM " . $wpdb->prefix . "wpms_links WHERE type='comment') LIMIT $limit_comment");
 
 
 
1120
  if (!empty($comments)) {
1121
  foreach ($comments as $comment) {
1122
  if (!empty($comment->comment_author_url)) {
1123
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
1124
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($comment->comment_author_url);
1125
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1126
- $coms = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $comment->comment_author_url, $comment->comment_author, 'comment', $status, $status_type);
1127
- MetaSeo_Broken_Link_Table::wpms_insert_link($coms, $wpdb);
 
 
 
 
 
 
 
 
 
 
1128
  }
1129
  }
1130
  wp_send_json(array('status' => false, 'type' => 'limit', 'percent' => $percent_comment));
@@ -1133,41 +1411,72 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1133
  // scan link in comment content
1134
  $k = 0;
1135
  $off_set = ($_POST['comment_paged'] - 1) * $limit_comment_content;
1136
- $query = "SELECT * FROM " . $wpdb->prefix . "comments WHERE comment_approved = 1 AND comment_content != '' LIMIT $limit_comment_content OFFSET $off_set";
 
1137
  $comments_content = $wpdb->get_results($query);
1138
  if (!empty($comments_content)) {
1139
  foreach ($comments_content as $comment) {
1140
- $dom = new DOMDocument;
1141
- libxml_use_internal_errors(true);
1142
  if (isset($comment->comment_content) && $comment->comment_content != '') {
1143
  preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1144
  foreach (array_unique($matches[0]) as $i => $content) {
1145
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1146
  $href = $matches[1];
1147
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
1148
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1149
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1150
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
1151
- $link_a = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $href, $link_text, 'comment_content_url', $status, $status_type);
1152
- MetaSeo_Broken_Link_Table::wpms_insert_link($link_a, $wpdb);
 
 
 
 
 
 
 
 
 
 
1153
  }
1154
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $comment->comment_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
1155
  foreach (array_unique($matches[0]) as $content) {
1156
- $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '"><b>' . $comment->comment_author . '</b></a>';
 
 
1157
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1158
  $src = $matches[1];
1159
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
1160
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1161
  $link_text = '';
1162
- $link_sou = MetaSeo_Broken_Link_Table::get_result_link($source_link, $comment->comment_ID, $src, $link_text, 'comment_content_image', $status, $status_type);
1163
- MetaSeo_Broken_Link_Table::wpms_insert_link($link_sou, $wpdb);
 
 
 
 
 
 
 
 
1164
  }
1165
  }
1166
  }
1167
 
1168
  $k++;
1169
  if ($k >= $limit_comment_content) {
1170
- wp_send_json(array('status' => false, 'type' => 'limit_comment_content', 'paged' => $_POST['comment_paged'], 'percent' => $percent_comment_content * count($comments_content)));
 
 
 
 
 
 
 
1171
  }
1172
  }
1173
 
@@ -1175,12 +1484,13 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1175
  $j = 0;
1176
  $off_set = ($_POST['paged'] - 1) * $limit_post;
1177
  $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
1178
- . " FROM $wpdb->posts "
1179
- . " WHERE " . implode(' AND ', $where) . "LIMIT $limit_post OFFSET $off_set";
1180
 
1181
  $results = $wpdb->get_results($query);
1182
- if (empty($results))
1183
  wp_send_json(array('status' => true));
 
1184
 
1185
  foreach ($results as $post) {
1186
  if ($post->post_excerpt != 'metaseo_404_page') {
@@ -1195,29 +1505,64 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1195
  $rel = $tags->item(0)->getAttribute('rel');
1196
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1197
  $href = $matches[1];
1198
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($href);
1199
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1200
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1201
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
1202
- $link_a = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $href, $link_text, 'url', $status, $status_type, $meta_title, $rel, $post->ID);
1203
- MetaSeo_Broken_Link_Table::wpms_insert_link($link_a, $wpdb);
 
 
 
 
 
 
 
 
 
 
 
 
 
1204
  }
1205
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches, PREG_PATTERN_ORDER);
 
 
 
 
 
1206
  foreach (array_unique($matches[0]) as $content) {
1207
- $source_link = '<a href="' . get_edit_post_link($post->ID) . '"><b>' . $post->post_title . '</b></a>';
 
 
1208
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1209
  $src = $matches[1];
1210
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($src);
1211
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1212
  $link_text = '';
1213
- $link_sou = MetaSeo_Broken_Link_Table::get_result_link($source_link, $post->ID, $src, $link_text, 'image', $status, $status_type);
1214
- MetaSeo_Broken_Link_Table::wpms_insert_link($link_sou, $wpdb);
 
 
 
 
 
 
 
 
1215
  }
1216
  }
1217
  }
1218
  $j++;
1219
  if ($j >= $limit_post) {
1220
- wp_send_json(array('status' => false, 'type' => 'limit_post', 'paged' => $_POST['paged'], 'percent' => $percent_post * count($results)));
 
 
 
 
 
 
 
1221
  }
1222
  }
1223
 
@@ -1236,16 +1581,26 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1236
  update_option('wpms_link_settings', $link_settings);
1237
  wp_send_json(array('status' => true));
1238
  }
1239
-
1240
- /*
1241
  * Insert link to wpms_link table
 
 
1242
  */
1243
- public static function wpms_insert_link($link, $wpdb) {
1244
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE link_url=%s AND type=%s AND source_id=%d ", array($link['link_url'], $link['type'], $link['source_id']));
 
 
 
 
 
 
 
 
1245
  $links = $wpdb->get_results($sql);
1246
  if (count($links) == 0) {
1247
- $status = MetaSeo_Broken_Link_Table::get_urlstatus(($link['link_url']));
1248
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
1249
  $value = array(
1250
  'link_url' => $link['link_url'],
1251
  'link_final_url' => $link['link_final_url'],
@@ -1264,12 +1619,13 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1264
  if (isset($link['status_type']) && $link['status_type'] != 'ok') {
1265
  $value[$link['status_type']] = 1;
1266
  }
1267
-
1268
  $site_url = get_site_url();
1269
- $value = MetaSeo_Broken_Link_Table::wpms_check_internal_link($link['link_url'], $site_url, $value);
1270
 
1271
  $wpdb->insert(
1272
- $wpdb->prefix . 'wpms_links', $value
 
1273
  );
1274
  } else {
1275
  $value = array(
@@ -1277,32 +1633,43 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1277
  'follow' => $link['follow']
1278
  );
1279
  $site_url = get_site_url();
 
 
 
1280
 
1281
- $status = MetaSeo_Broken_Link_Table::get_urlstatus(($link['link_url']));
1282
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
1283
-
1284
- $value = MetaSeo_Broken_Link_Table::wpms_check_internal_link($links[0]->link_url, $site_url, $value);
1285
  $value['status_code'] = $status;
1286
  $value['status_text'] = $status_text;
1287
- if ($links[0]->follow != $link['follow'] || $links[0]->meta_title != $link['meta_title'] || $links[0]->internal != $value['internal'] || $links[0]->status_code != $value['status_code']) {
 
 
1288
  $wpdb->update(
1289
- $wpdb->prefix . 'wpms_links', $value, array('id' => $links[0]->id)
 
 
 
 
1290
  );
1291
  }
1292
  }
1293
  }
1294
-
1295
- /*
1296
  * Check internal link
 
 
 
 
1297
  */
1298
- public static function wpms_check_internal_link($link, $siteUrl, $value) {
 
1299
  $info_link = parse_url($link);
1300
- if(empty($info_link['path'])){
1301
  $value['internal'] = 0;
1302
  return $value;
1303
  }
1304
 
1305
- if(empty($info_link['host'])){
1306
  $value['internal'] = 0;
1307
  return $value;
1308
  }
@@ -1318,43 +1685,47 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1318
 
1319
  return $value;
1320
  }
1321
-
1322
- /*
1323
  * Flush link
1324
  */
1325
- public static function wpms_flush_link() {
 
1326
  global $wpdb;
1327
  if (isset($_POST['type']) && $_POST['type'] != 'none') {
1328
  switch ($_POST['type']) {
1329
  case 'automaticaly_indexed':
1330
  $wpdb->query(
1331
- $wpdb->prepare(
1332
- "
1333
  DELETE FROM " . $wpdb->prefix . "wpms_links
1334
  WHERE broken_indexed = %d AND link_url_redirect = %s
1335
- ", array(1, '')
1336
- )
 
1337
  );
1338
  break;
1339
  case 'internal_broken_links':
1340
  $wpdb->query(
1341
- $wpdb->prepare(
1342
- "
1343
  DELETE FROM " . $wpdb->prefix . "wpms_links
1344
  WHERE broken_internal = %d AND link_url_redirect = %s
1345
- ", array(1, '')
1346
- )
 
1347
  );
1348
  break;
1349
  case 'all':
1350
  $wpdb->query(
1351
- $wpdb->prepare(
1352
- "
1353
  DELETE FROM " . $wpdb->prefix . "wpms_links
1354
  WHERE (broken_internal = %d
1355
  OR broken_indexed = %d) AND link_url_redirect = %s
1356
- ", array(1, 1, '')
1357
- )
 
1358
  );
1359
 
1360
  break;
@@ -1363,13 +1734,17 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1363
  }
1364
  wp_send_json(false);
1365
  }
1366
-
1367
- /*
1368
  * Get status text
 
 
1369
  */
1370
- public static function wpms_get_status_text($status) {
1371
- if ($status == 'Not checked')
 
1372
  return 'Not checked';
 
1373
  if ($status == 'Server Not Found') {
1374
  $status_text = 'Server Not Found';
1375
  } else {
@@ -1378,41 +1753,48 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1378
  return $status_text;
1379
  }
1380
 
1381
- /*
1382
  * Add custom redirect
1383
  */
1384
- public static function wpms_add_custom_redirect() {
 
1385
  do_action('wpms_add_custom_redirect');
1386
- wp_send_json(array('status' => true , 'message' => __('Done!','wp-meta-seo')));
1387
  }
1388
-
1389
- /*
1390
  * Update link
1391
  */
1392
- public static function wpms_update_link() {
 
1393
 
1394
  if (isset($_POST['link_id'])) {
1395
  global $wpdb;
1396
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($_POST['link_id']));
 
 
 
1397
  $link_detail = $wpdb->get_row($sql);
1398
- if (empty($link_detail))
1399
  wp_send_json(false);
 
 
1400
  $new_link = stripslashes($_POST['new_link']);
1401
  $link_redirect = stripslashes($_POST['link_redirect']);
1402
- if(isset($_POST['new_text'])){
1403
  $new_text = stripcslashes($_POST['new_text']);
1404
- }else{
1405
  $new_text = '';
1406
  }
1407
 
1408
- if($link_redirect != ''){
1409
  $status = 'HTTP/1.1 200 OK';
1410
- }else{
1411
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($new_link);
1412
  }
1413
 
1414
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
1415
- $status_type = MetaSeo_Broken_Link_Table::get_urlstatus_type($status);
1416
  if ($link_detail->type != '404_automaticaly') {
1417
  $value = array('link_url' => $new_link,
1418
  'link_final_url' => '',
@@ -1444,14 +1826,16 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1444
  }
1445
  }
1446
 
1447
- if (!empty($link_redirect))
1448
  $value['link_url_redirect'] = $link_redirect;
 
 
1449
  if (isset($status_type) && $status_type != 'ok') {
1450
  $value[$status_type] = 1;
1451
  }
1452
  } else {
1453
- $status = MetaSeo_Broken_Link_Table::get_urlstatus($link_redirect);
1454
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
1455
 
1456
  $value = array(
1457
  'link_url_redirect' => stripslashes($link_redirect),
@@ -1461,47 +1845,80 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1461
  );
1462
  }
1463
 
1464
- if($link_detail->type == 'add_custom'){
1465
  $value['meta_title'] = $_POST['status_redirect'];
1466
  }
1467
 
1468
  $site_url = get_site_url();
1469
- $value = MetaSeo_Broken_Link_Table::wpms_check_internal_link($new_link, $site_url, $value);
1470
 
1471
  $wpdb->update(
1472
- $wpdb->prefix . 'wpms_links', $value, array('id' => $_POST['link_id'])
 
 
 
 
1473
  );
1474
 
1475
  switch ($link_detail->type) {
1476
  case '404_automaticaly':
1477
- wp_send_json(array('status' => true, 'type' => '404_automaticaly', 'status_text' => $status_text, 'new_link' => esc_url($new_link)));
 
 
 
 
 
 
 
1478
  break;
1479
  case 'comment_content_image':
1480
  $comment = get_comment($link_detail->source_id);
1481
  if (!empty($comment)) {
1482
  $old_value = $comment->comment_content;
1483
- $edit_result = MetaSeo_Broken_Link_Table::edit_linkimg($old_value, $new_link, $link_detail->link_url);
 
 
 
 
1484
  $my_comment = array(
1485
  'comment_ID' => $link_detail->source_id,
1486
  'comment_content' => $edit_result['content']
1487
  );
1488
- remove_action('edit_comment', array('MetaSeo_Broken_Link_Table', 'wpms_update_comment'));
1489
  wp_update_comment($my_comment);
1490
- wp_send_json(array('status' => true, 'type' => 'image', 'status_text' => $status_text, 'new_link' => esc_url($edit_result['raw_url'])));
 
 
 
 
 
 
 
1491
  }
1492
  break;
1493
  case 'image':
1494
  $post = get_post($link_detail->source_id);
1495
  if (!empty($post)) {
1496
  $old_value = $post->post_content;
1497
- $edit_result = MetaSeo_Broken_Link_Table::edit_linkimg($old_value, $new_link, $link_detail->link_url);
 
 
 
 
1498
  $my_post = array(
1499
  'ID' => $link_detail->source_id,
1500
  'post_content' => $edit_result['content']
1501
  );
1502
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1503
  wp_update_post($my_post);
1504
- wp_send_json(array('status' => true, 'type' => 'image', 'status_text' => $status_text, 'new_link' => esc_url($edit_result['raw_url'])));
 
 
 
 
 
 
 
1505
  }
1506
  break;
1507
 
@@ -1510,10 +1927,19 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1510
  if (!empty($comment)) {
1511
  $old_value = $comment->comment_content;
1512
  if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1513
- $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $new_link, $link_detail->link_url);
 
 
 
 
1514
  $new_text = '';
1515
  } else {
1516
- $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $new_link, $link_detail->link_url, $new_text);
 
 
 
 
 
1517
  $new_text = strip_tags($edit_result['link_text']);
1518
  }
1519
 
@@ -1521,9 +1947,17 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1521
  'comment_ID' => $link_detail->source_id,
1522
  'comment_content' => $edit_result['content']
1523
  );
1524
- remove_action('edit_comment', array('MetaSeo_Broken_Link_Table', 'wpms_update_comment'));
1525
  wp_update_comment($my_comment);
1526
- wp_send_json(array('status' => true, 'type' => 'url', 'status_text' => $status_text, 'new_link' => $edit_result['raw_url'], 'new_text' => $new_text));
 
 
 
 
 
 
 
 
1527
  }
1528
 
1529
  break;
@@ -1533,10 +1967,19 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1533
  if (!empty($post)) {
1534
  $old_value = $post->post_content;
1535
  if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1536
- $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $new_link, $link_detail->link_url);
 
 
 
 
1537
  $new_text = '';
1538
  } else {
1539
- $edit_result = MetaSeo_Broken_Link_Table::wpms_edit_linkhtml($old_value, $new_link, $link_detail->link_url, $new_text);
 
 
 
 
 
1540
  $new_text = strip_tags($edit_result['link_text']);
1541
  }
1542
 
@@ -1544,35 +1987,68 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1544
  'ID' => $link_detail->source_id,
1545
  'post_content' => $edit_result['content']
1546
  );
1547
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1548
  wp_update_post($my_post);
1549
- wp_send_json(array('status' => true, 'type' => 'url', 'status_text' => $status_text, 'new_link' => $edit_result['raw_url'], 'new_text' => $new_text));
 
 
 
 
 
 
 
 
1550
  }
1551
 
1552
  break;
1553
  case 'comment':
1554
- wp_update_comment(array('comment_ID' => $link_detail->source_id, 'comment_author_url' => $new_link));
1555
- wp_send_json(array('status' => true, 'type' => 'orther', 'status_text' => $status_text, 'new_link' => $new_link));
 
 
 
 
 
 
 
 
 
 
 
 
1556
  break;
1557
 
1558
  case 'add_custom':
1559
- wp_send_json(array('status' => true, 'type' => 'orther', 'status_text' => $status_text, 'new_link' => $new_link));
 
 
 
 
 
 
 
1560
  break;
1561
  }
1562
  }
1563
  wp_send_json(false);
1564
  }
1565
-
1566
- /*
1567
  * Remove link
1568
  */
1569
- public static function wpms_unlink() {
 
1570
  if (isset($_POST['link_id'])) {
1571
  global $wpdb;
1572
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($_POST['link_id']));
 
 
 
1573
  $link_detail = $wpdb->get_row($sql);
1574
- if (empty($link_detail))
1575
  wp_send_json(false);
 
 
1576
  $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => $_POST['link_id']));
1577
  switch ($link_detail->type) {
1578
  case 'add_rule':
@@ -1584,8 +2060,8 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1584
  $comment = get_comment($link_detail->source_id);
1585
  if (!empty($comment)) {
1586
  $old_value = $comment->comment_content;
1587
- $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_img($old_value, $link_detail->link_url);
1588
- remove_action('edit_comment', array('MetaSeo_Broken_Link_Table', 'wpms_update_comment'));
1589
  $my_comment = array(
1590
  'comment_ID' => $link_detail->source_id,
1591
  'comment_content' => $new_content
@@ -1599,8 +2075,8 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1599
  $post = get_post($link_detail->source_id);
1600
  if (!empty($post)) {
1601
  $old_value = $post->post_content;
1602
- $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_img($old_value, $link_detail->link_url);
1603
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1604
  $my_post = array(
1605
  'ID' => $link_detail->source_id,
1606
  'post_content' => $new_content
@@ -1614,8 +2090,8 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1614
  $comment = get_comment($link_detail->source_id);
1615
  if (!empty($comment)) {
1616
  $old_value = $comment->comment_content;
1617
- $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_html($old_value, $link_detail->link_url);
1618
- remove_action('edit_comment', array('MetaSeo_Broken_Link_Table', 'wpms_update_comment'));
1619
  $my_comment = array(
1620
  'comment_ID' => $link_detail->source_id,
1621
  'comment_content' => $new_content
@@ -1629,8 +2105,8 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1629
  $post = get_post($link_detail->source_id);
1630
  if (!empty($post)) {
1631
  $old_value = $post->post_content;
1632
- $new_content = MetaSeo_Broken_Link_Table::wpms_unlink_html($old_value, $link_detail->link_url);
1633
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1634
  $my_post = array(
1635
  'ID' => $link_detail->source_id,
1636
  'post_content' => $new_content
@@ -1650,30 +2126,43 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1650
  }
1651
  wp_send_json(false);
1652
  }
1653
-
1654
  /**
1655
- * Change all occurrences of a given plaintext URLs to a new URL.
1656
- *
1657
- * @param string $content Look for URLs in this string.
1658
- * @param string $new_url Change them to this URL.
1659
- * @param string $old_url The URL to look for.
1660
- *
1661
- * @return array|WP_Error If successful, the return value will be an associative array with two
1662
- * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
1663
- * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
1664
- */
1665
- public static function edit_linkimg($content, $new_url, $old_url) {
 
1666
  self::$old_url = $old_url;
1667
  self::$new_url = htmlentities($new_url);
1668
- $content = preg_replace_callback(self::$img_pattern, array('MetaSeo_Broken_Link_Table', 'editimg_callback'), $content);
 
 
 
 
 
 
 
1669
 
1670
  return array(
1671
  'content' => $content,
1672
  'raw_url' => self::$new_url,
1673
  );
1674
  }
1675
-
1676
- public static function editimg_callback($matches) {
 
 
 
 
 
1677
  $url = $matches[3];
1678
  if (($url) == self::$old_url) {
1679
  return $matches[1] . '"' . self::$new_url . '"' . $matches[4];
@@ -1681,21 +2170,35 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1681
  return $matches[0];
1682
  }
1683
  }
1684
-
1685
  /**
1686
- * Remove all occurrences of a specific plaintext URL.
1687
- *
1688
- * @param string $content Look for URLs in this string.
1689
- * @param string $url The URL to look for.
1690
- * @return string Input string with all matching plaintext URLs removed.
1691
- */
1692
- public static function wpms_unlink_img($content, $url) {
 
1693
  self::$old_url = $url; //used by the callback
1694
- $content = preg_replace_callback(self::$img_pattern, array('MetaSeo_Broken_Link_Table', 'wpms_unlink_img_callback'), $content);
 
 
 
 
 
 
 
1695
  return $content;
1696
  }
1697
 
1698
- public static function wpms_unlink_img_callback($matches) {
 
 
 
 
 
 
1699
  $url = $matches[3];
1700
  if (($url) == self::$old_url) {
1701
  return ''; //Completely remove the IMG tag
@@ -1703,44 +2206,60 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1703
  return $matches[0]; //return the image unchanged
1704
  }
1705
  }
1706
-
1707
  /**
1708
- * Remove all occurrences of a specific plaintext URL.
1709
- *
1710
- * @param string $content Look for URLs in this string.
1711
- * @param string $url The URL to look for.
1712
- * @return string Input string with all matching plaintext URLs removed.
1713
- */
1714
- public static function wpms_unlink_html($content, $url) {
 
1715
  $args = array(
1716
  'old_url' => $url,
1717
  );
1718
 
1719
- $content = MetaSeo_Broken_Link_Table::wpms_multi_edit($content, array('MetaSeo_Broken_Link_Table', 'wpms_unlink_html_callback'), $args);
 
 
 
 
 
 
 
1720
 
1721
  return $content;
1722
  }
1723
-
1724
- public static function wpms_unlink_html_callback($link, $params) {
 
 
 
 
 
 
 
1725
  if ($link['href'] != $params['old_url']) {
1726
  return $link['#raw'];
1727
  }
1728
 
1729
  return $link['#link_text'];
1730
  }
1731
-
1732
  /**
1733
- * Change all occurrences of a given plaintext URLs to a new URL.
1734
- *
1735
- * @param string $content Look for URLs in this string.
1736
- * @param string $new_url Change them to this URL.
1737
- * @param string $old_url The URL to look for.
1738
- * @param string $new_text new text of this URL.
1739
- * @return array|WP_Error If successful, the return value will be an associative array with two
1740
- * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
1741
- * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
1742
- */
1743
- public static function wpms_edit_linkhtml($content, $new_url, $old_url, $new_text = null) {
 
1744
  //Save the old & new URLs for use in the edit callback.
1745
  $args = array(
1746
  'old_url' => $old_url,
@@ -1749,7 +2268,14 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1749
  );
1750
 
1751
  //Find all links and replace those that match $old_url.
1752
- $content = MetaSeo_Broken_Link_Table::wpms_multi_edit($content, array('MetaSeo_Broken_Link_Table', 'wpms_edithtml_callback'), $args);
 
 
 
 
 
 
 
1753
 
1754
  $result = array(
1755
  'content' => $content,
@@ -1760,8 +2286,15 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1760
  }
1761
  return $result;
1762
  }
1763
-
1764
- public static function wpms_edithtml_callback($link, $params) {
 
 
 
 
 
 
 
1765
  if ($link['href'] == $params['old_url']) {
1766
  $modified = array(
1767
  'href' => $params['new_url'],
@@ -1784,21 +2317,22 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1784
  return $link['#raw'];
1785
  }
1786
  }
1787
-
1788
  /**
1789
- * Helper function for blcHtmlLink::multi_edit()
1790
- * Applies the specified callback function to each link and merges
1791
- * the result with the current link attributes. If the callback returns
1792
- * a replacement HTML tag instead, it will be stored in the '#new_raw'
1793
- * key of the return array.
1794
- *
1795
- * @access protected
1796
- *
1797
- * @param array $link
1798
- * @param array $info The callback function and the extra argument to pass to that function (if any).
1799
- * @return array
1800
- */
1801
- public static function wpms_edit_callback($link, $info) {
 
1802
  list($callback, $extra) = $info;
1803
 
1804
  //Prepare arguments for the callback
@@ -1817,22 +2351,33 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1817
 
1818
  return $link;
1819
  }
1820
-
1821
  /**
1822
- * Modify all HTML links found in a string using a callback function.
1823
- * The callback function should return either an associative array or a string. If
1824
- * a string is returned, the parser will replace the current link with the contents
1825
- * of that string. If an array is returned, the current link will be modified/rebuilt
1826
- * by substituting the new values for the old ones.
1827
- * htmlentities() will be automatically applied to attribute values (but not to #link_text).
1828
- * @param string $content A text string containing the links to edit.
1829
- * @param callback $callback Callback function used to modify the links.
1830
- * @param mixed $extra If supplied, $extra will be passed as the second parameter to the function $callback.
1831
- * @return string The modified input string.
1832
- */
1833
- public static function wpms_multi_edit($content, $callback, $extra = null) {
 
1834
  //Just reuse map() + a little helper func. to apply the callback to all links and get modified links
1835
- $modified_links = MetaSeo_Broken_Link_Table::map($content, array('MetaSeo_Broken_Link_Table', 'wpms_edit_callback'), array($callback, $extra));
 
 
 
 
 
 
 
 
 
 
1836
  //Replace each old link with the modified one
1837
  $offset = 0;
1838
  foreach ($modified_links as $link) {
@@ -1854,44 +2399,63 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1854
 
1855
  $content = substr_replace($content, $new_html, $link['#offset'] + $offset, strlen($link['#raw']));
1856
  //Update the replacement offset
1857
- $offset += ( strlen($new_html) - strlen($link['#raw']) );
1858
  }
1859
 
1860
  return $content;
1861
  }
1862
-
1863
  /**
1864
- * extract_tags()
1865
- * Extract specific HTML tags and their attributes from a string.
1866
- *
1867
- * You can either specify one tag, an array of tag names, or a regular expression that matches the tag name(s).
1868
- * If multiple tags are specified you must also set the $selfclosing parameter and it must be the same for
1869
- * all specified tags (so you can't extract both normal and self-closing tags in one go).
1870
- *
1871
- * The function returns a numerically indexed array of extracted tags. Each entry is an associative array
1872
- * with these keys :
1873
- * tag_name - the name of the extracted tag, e.g. "a" or "img".
1874
- * offset - the numberic offset of the first character of the tag within the HTML source.
1875
- * contents - the inner HTML of the tag. This is always empty for self-closing tags.
1876
- * attributes - a name -> value array of the tag's attributes, or an empty array if the tag has none.
1877
- * full_tag - the entire matched tag, e.g. '<a href="http://example.com">example.com</a>'. This key
1878
- * will only be present if you set $return_the_entire_tag to true.
1879
- *
1880
- * @param string $html The HTML code to search for tags.
1881
- * @param string|array $tag The tag(s) to extract.
1882
- * @param bool $selfclosing Whether the tag is self-closing or not. Setting it to null will force the script to try and make an educated guess.
1883
- * @param bool $return_the_entire_tag Return the entire matched tag in 'full_tag' key of the results array.
1884
- * @param string $charset The character set of the HTML code. Defaults to ISO-8859-1.
1885
- *
1886
- * @return array An array of extracted tags, or an empty array if no matching tags were found.
1887
- */
1888
- public static function extract_tags($html, $tag, $selfclosing = null, $return_the_entire_tag = false, $charset = 'ISO-8859-1') {
 
 
 
 
 
 
 
1889
 
1890
  if (is_array($tag)) {
1891
  $tag = implode('|', $tag);
1892
  }
1893
 
1894
- $selfclosing_tags = array('area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta', 'col', 'param');
 
 
 
 
 
 
 
 
 
 
 
 
1895
  if (is_null($selfclosing)) {
1896
  $selfclosing = in_array($tag, $selfclosing_tags);
1897
  }
@@ -1916,11 +2480,11 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1916
  (
1917
  (?P<quote>[\"\'])(?P<value_quoted>.*?)(?P=quote) # a quoted value
1918
  | # or
1919
- (?P<value_unquoted>[^\s"\']+?)(?:\s+|$) # an unquoted value (terminated by whitespace or EOF)
1920
  )
1921
  @xsi';
1922
 
1923
- //Find all tags
1924
  if (!preg_match_all($tag_pattern, $html, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
1925
  //Return an empty array if we didn't find anything
1926
  return array();
@@ -1928,17 +2492,15 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1928
 
1929
  $tags = array();
1930
  foreach ($matches as $match) {
1931
-
1932
  //Parse tag attributes, if any
1933
  $attributes = array();
1934
  if (!empty($match['attributes'][0])) {
1935
-
1936
  if (preg_match_all($attribute_pattern, $match['attributes'][0], $attribute_data, PREG_SET_ORDER)) {
1937
  //Turn the attribute data into a name->value array
1938
  foreach ($attribute_data as $attr) {
1939
  if (!empty($attr['value_quoted'])) {
1940
  $value = $attr['value_quoted'];
1941
- } else if (!empty($attr['value_unquoted'])) {
1942
  $value = $attr['value_unquoted'];
1943
  } else {
1944
  $value = '';
@@ -1969,41 +2531,43 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
1969
 
1970
  return $tags;
1971
  }
1972
-
1973
  /**
1974
- * Apply a callback function to all HTML links found in a string and return the results.
1975
- *
1976
- * The link data array will contain at least these keys :
1977
- * 'href' - the URL of the link (with htmlentitydecode() already applied).
1978
- * '#raw' - the raw link code, e.g. the entire '<a href="...">...</a>' tag of a HTML link.
1979
- * '#offset' - the offset within $content at which the first character of the link tag was found.
1980
- * '#link_text' - the link's anchor text, if any. May contain HTML tags.
1981
- *
1982
- * Any attributes of the link tag will also be included in the returned array as attr_name => attr_value
1983
- * pairs. This function will also automatically decode any HTML entities found in attribute values.
1984
- * @param string $content A text string to parse for links.
1985
- * @param callback $callback Callback function to apply to all found links.
1986
- * @param mixed $extra If the optional $extra param. is supplied, it will be passed as the second parameter to the function $callback.
1987
- * @return array An array of all detected links after applying $callback to each of them.
1988
- */
1989
- public static function map($content, $callback, $extra = null) {
 
 
1990
  $results = array();
1991
 
1992
  //Find all links
1993
- $links = MetaSeo_Broken_Link_Table::extract_tags($content, 'a', false, true);
1994
 
1995
  //Iterate over the links and apply $callback to each
1996
  foreach ($links as $link) {
1997
-
1998
  //Massage the found link into a form required for the callback function
1999
  $param = $link['attributes'];
2000
  $param = array_merge(
2001
- $param, array(
2002
- '#raw' => $link['full_tag'],
2003
- '#offset' => $link['offset'],
2004
- '#link_text' => $link['contents'],
2005
- 'href' => isset($link['attributes']['href']) ? $link['attributes']['href'] : '',
2006
- )
 
2007
  );
2008
 
2009
  //Prepare arguments for the callback
@@ -2018,33 +2582,41 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
2018
 
2019
  return $results;
2020
  }
2021
-
2022
  /*
2023
  * Ajax recheck link
2024
  */
2025
- public static function wpms_recheck_link() {
 
2026
  if (isset($_POST['link_id'])) {
2027
  global $wpdb;
2028
  $linkId = $_POST['link_id'];
2029
  $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($linkId));
2030
  $link = $wpdb->get_row($sql);
2031
  if (!empty($link)) {
2032
- if($link->link_url_redirect != ''){
2033
  $status = 'HTTP/1.1 200 OK';
2034
- }else{
2035
- $status = MetaSeo_Broken_Link_Table::get_urlstatus(($link->link_url));
2036
  }
2037
 
2038
- $status_text = MetaSeo_Broken_Link_Table::wpms_get_status_text($status);
2039
 
2040
  if ($link->type == '404_automaticaly') {
2041
- if (((int) substr($status, 9, 3) >= 301 && (int) substr($status, 9, 3) <= 304) || ((int) substr($status, 9, 3) >= 400 && (int) substr($status, 9, 3) <= 503 && (int) substr($status, 9, 3) != 401) || $status == 'Server Not Found') {
 
 
 
 
2042
  $type = array('broken_indexed' => 1, 'broken_internal' => 0);
2043
  } else {
2044
  $type = array('broken_indexed' => 0, 'broken_internal' => 0);
2045
  }
2046
  } else {
2047
- if (((int) substr($status, 9, 3) >= 400 && (int) substr($status, 9, 3) <= 503 && (int) substr($status, 9, 3) != 401) || $status == 'Server Not Found') {
 
 
 
2048
  $type = array('broken_internal' => 1, 'broken_indexed' => 0);
2049
  } else {
2050
  $type = array('broken_internal' => 0, 'broken_indexed' => 0);
@@ -2059,12 +2631,15 @@ class MetaSeo_Broken_Link_Table extends WP_List_Table {
2059
  );
2060
 
2061
  $wpdb->update(
2062
- $wpdb->prefix . 'wpms_links', $value, array('ID' => $_POST['link_id'])
 
 
 
 
2063
  );
2064
  wp_send_json(array('status' => true, 'status_text' => $status_text));
2065
  }
2066
  wp_send_json(array('status' => false));
2067
  }
2068
  }
2069
-
2070
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
 
4
  if (!class_exists('WP_List_Table')) {
5
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6
  }
7
 
8
+ /**
9
+ * Class MetaSeoBrokenLinkTable
10
+ * Base class for displaying a list of links in an ajaxified HTML table.
11
+ */
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 = '';
30
 
31
+ /**
32
+ * MetaSeoBrokenLinkTable constructor.
33
+ */
34
+ public function __construct()
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">
85
+ </label>
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>
93
 
94
  <?php
95
  }
96
+
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'),
109
  'col_source' => __('Source', 'wp-meta-seo'),
110
  );
111
  }
112
+
113
  /**
114
+ * Get a list of sortable columns. The format is:
115
+ * 'internal-name' => 'orderby'
116
+ * or
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)
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
 
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';
178
+ }
179
 
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';
189
  $class[] = 'sortable';
190
  $class[] = $desc_first ? 'asc' : 'desc';
191
  }
192
+ $hr = esc_url(add_query_arg(compact('orderby', 'order'), $current_url));
193
+ $column_display_name = '<a href="' . $hr . '">';
194
+ $column_display_name .= '<span>' . $column_display_name . '</span>';
195
+ $column_display_name .= '<span class="sorting-indicator"></span>';
196
+ $column_display_name .= '</a>';
197
  }
198
 
199
  $id = $with_id ? "id='$column_key'" : '';
200
 
201
+ if (!empty($class)) {
202
  $class = "class='" . join(' ', $class) . "'";
203
+ }
204
 
205
  if ($column_key === 'cb') {
206
  echo "<th scope='col' $id $class style='padding:8px 10px;'>$column_display_name</th>";
209
  }
210
  }
211
  }
212
+
213
  /**
214
+ * Prepares the list of items for displaying.
215
+ * @uses WP_List_Table::set_pagination_args()
216
+ */
217
+ public function prepare_items()
218
+ {
219
+ global $wpdb;
220
  $where = array('1=1');
221
  if (!empty($_REQUEST['sltype']) && $_REQUEST['sltype'] != 'all') {
222
  if ($_REQUEST['sltype'] != 'other') {
229
  if (!empty($_REQUEST['sl_broken']) && $_REQUEST['sl_broken'] != 'all') {
230
  if ($_REQUEST['sl_broken'] == 'custom_redirect_url') {
231
  $where[] = "link_url_redirect !=''";
232
+ } elseif ($_REQUEST['sl_broken'] == 'valid_links') {
233
  $where[] = "broken_internal = 0 AND broken_indexed = 0";
234
  } elseif ($_REQUEST['sl_broken'] == 'internal_broken_links') {
235
  $where[] = "broken_internal = 1";
256
  $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
257
  $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
258
  $sortable = $this->get_sortable_columns();
259
+ $orderby_array = array($orderby, true);
260
  if (in_array($orderby_array, $sortable)) {
261
  $orderStr = $orderby;
262
  } else {
280
  $hidden = array();
281
  $sortable = $this->get_sortable_columns();
282
  $this->_column_headers = array($columns, $hidden, $sortable);
283
+
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']);
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(
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
+ }
344
+
345
+ if (!empty($_REQUEST['order'])) {
346
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
347
+ }
348
+
349
+ if (!empty($_REQUEST['post_mime_type'])) {
350
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
351
+ }
352
+
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>
360
+ <input type="search" id="image-search-input" name="txtkeyword"
361
+ value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>"/>
362
+ </label>
363
+
364
  <?php submit_button('Search URL', 'button', 'search', false, array('id' => 'search-submit')); ?>
365
  </p>
366
  <?php
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) {
397
 
398
  <?php
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';
431
  <?php
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>
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">
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') {
517
  $value_url = $rec->link_url;
518
  }
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
566
+ );
567
  foreach ($matches[0] as $i => $content) {
568
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
569
  $href = $matches[1];
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
583
+ );
584
  foreach ($matches[0] as $i => $content) {
585
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
586
  $href = $matches[1];
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">
635
+ <option value="301" <?php selected($rec->meta_title, 301) ?>>301
636
+ </option>
637
+ <option value="302" <?php selected($rec->meta_title, 302) ?>>302
638
+ </option>
639
+ <option value="307" <?php selected($rec->meta_title, 307) ?>>307
640
+ </option>
641
+ </select>
642
+ </label>
643
+ </p>
644
+ <?php
645
+ }
646
  }
647
+ ?>
 
648
 
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); ?>"/>
665
+ </label>
666
+ <span class="wlink-btn">
667
+ <i class="mce-ico mce-i-link link-btn" id="link-btn"></i>
668
+ </span>
669
  </p>
 
670
 
671
+ <div class="submit wpms-inline-editor-buttons">
672
+ <input type="button"
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>
682
  </div>
683
  <?php
684
  echo '</td>';
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;
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
 
737
  break;
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
 
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>';
815
  }
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
 
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
 
867
  exit();
868
  }
869
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(
886
+ $source_link,
887
+ $source_id,
888
+ $url,
889
+ $link_text,
890
+ $type,
891
+ $status,
892
+ $status_type,
893
+ $meta_title = '',
894
+ $rel = '',
895
+ $postID = 0
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,
938
  }
939
  }
940
 
 
941
  return $res;
942
  }
943
 
944
+ /**
945
  * Get link status
946
+ * @param string $url url to get status
947
+ * @return string
948
  */
949
+ public static function getUrlStatus($url)
950
+ {
951
  $status = @get_headers($url, 0);
952
+ if (strpos($url, 'mailto:') !== false) {
953
  return 'Not checked';
954
+ }
955
+
956
  if (strpos($url, '#') === 0 || strpos($url, 'tel:') === 0) {
957
  return 'HTTP/1.1 200 OK';
958
  }
962
  return 'Server Not Found';
963
  }
964
  }
965
+
966
+ /**
967
  * Get link status type
968
+ * @param string $status status label
969
+ * @return string
970
  */
971
+ public static function getUrlStatusType($status)
972
+ {
973
+ if (isset($status) && $status == 'Not checked') {
974
  return 'ok';
975
+ }
976
+
977
  if (isset($status) && $status != 'Server Not Found') {
978
+ if (((int)substr($status, 9, 3) >= 200
979
+ && (int)substr($status, 9, 3) <= 204) || (int)substr($status, 9, 3) == 401) {
980
  $type = 'ok';
981
+ } elseif (((int)substr($status, 9, 3) >= 400
982
+ && (int)substr($status, 9, 3) <= 503 && (int)substr($status, 9, 3) != 401)) {
983
+ if (in_array((int)substr($status, 9, 3), array(404, 410))) {
984
  $type = 'broken_internal';
985
  } else {
986
  $type = 'warning';
987
  }
988
+ } elseif (((int)substr($status, 9, 3) >= 301 && (int)substr($status, 9, 3) <= 304)) {
989
  $type = 'ok';
990
  } else {
991
  $type = 'dismissed';
995
  }
996
  return $type;
997
  }
998
+
999
+ /**
1000
  * Delete link comment in wpms_links table when delete comment
1001
+ * @param int $comment_ID comment id
1002
  */
1003
+ public static function deletedComment($comment_ID)
1004
+ {
1005
  global $wpdb;
1006
  $wpdb->query(
1007
+ $wpdb->prepare(
1008
+ "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
1009
  AND (type = %s || type = %s || type = %s)
1010
+ ",
1011
+ $comment_ID,
1012
+ 'comment',
1013
+ 'comment_content_url',
1014
+ 'comment_content_image'
1015
+ )
1016
  );
1017
  }
1018
+
1019
+ /**
1020
  * Delete link post in wpms_links table when delete post
1021
+ * @param $post_id
1022
  */
1023
+ public static function deletePost($post_id)
1024
+ {
1025
  global $wpdb;
1026
  $wpdb->query(
1027
+ $wpdb->prepare(
1028
+ "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d
1029
  AND type != %s
1030
+ ",
1031
+ $post_id,
1032
+ 'comment'
1033
+ )
1034
  );
1035
  }
1036
+
1037
+ /**
1038
  * Update wpms_links table when update comment
1039
+ * @param int $comment_ID Id of current comment
1040
  */
1041
+ public static function updateComment($comment_ID)
1042
+ {
1043
  global $wpdb;
1044
  $comment = get_comment($comment_ID);
1045
  $status = wp_get_comment_status($comment_ID);
1046
  if ($status == 'approved') {
1047
  if (!empty($comment->comment_author_url)) {
1048
+ $status = MetaSeoBrokenLinkTable::getUrlStatus(($comment->comment_author_url));
1049
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1050
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1051
+ $sql = $wpdb->prepare(
1052
+ "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type=%s ",
1053
+ array(
1054
+ $comment_ID,
1055
+ 'comment'
1056
+ )
1057
+ );
1058
  $check = $wpdb->get_var($sql);
1059
  if ($check == 0) {
1060
  $value = array(
1073
  $value[$status_type] = 1;
1074
  }
1075
  $wpdb->insert(
1076
+ $wpdb->prefix . 'wpms_links',
1077
+ $value
1078
  );
1079
  } else {
1080
  $value = array('link_url' => $comment->comment_author_url,
1086
  'dismissed' => 0,
1087
  );
1088
 
1089
+ if (isset($_POST['link_redirect'])) {
1090
  $value['link_url_redirect'] = ($_POST['link_redirect']);
1091
+ }
1092
 
1093
  if (isset($status_type) && $status_type != 'ok') {
1094
  $value[$status_type] = 1;
1095
  }
1096
  $wpdb->update(
1097
+ $wpdb->prefix . 'wpms_links',
1098
+ $value,
1099
+ array(
1100
+ 'source_id' => $comment_ID,
1101
+ 'type' => 'comment'
1102
+ ),
1103
+ array('%s', '%s', '%s', '%d', '%d', '%d', '%d'),
1104
+ array('%d', '%s')
1105
  );
1106
  }
1107
  } else {
1108
  $wpdb->query(
1109
+ $wpdb->prepare(
1110
+ "DELETE FROM " . $wpdb->prefix . "wpms_links WHERE source_id = %d AND (type = %s)",
1111
+ array(
1112
+ $comment_ID,
1113
+ 'comment'
1114
+ )
1115
+ )
1116
  );
1117
  }
1118
 
1119
+ $linkscontent = array();
1120
  if (isset($comment->comment_content) && $comment->comment_content != '') {
1121
  preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1122
  foreach (array_unique($matches[0]) as $i => $content) {
1123
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1124
  $href = $matches[1];
1125
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1126
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1127
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1128
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1129
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1130
+ $source_link .= '</a>';
1131
+ $key = $href . 'comment_content_url' . $comment->comment_ID . $link_text;
1132
+ $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1133
+ $source_link,
1134
+ $comment->comment_ID,
1135
+ $href,
1136
+ $link_text,
1137
+ 'comment_content_url',
1138
+ $status,
1139
+ $status_type
1140
+ );
1141
  }
1142
+ preg_match_all(
1143
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1144
+ $comment->comment_content,
1145
+ $matches,
1146
+ PREG_PATTERN_ORDER
1147
+ );
1148
  foreach (array_unique($matches[0]) as $content) {
1149
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1150
  $src = $matches[1];
1151
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1152
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1153
  $link_text = '';
1154
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1155
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1156
+ $source_link .= '</a>';
1157
+ $key = $src . 'comment_content_image' . $comment->comment_ID;
1158
+ $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1159
+ $source_link,
1160
+ $comment->comment_ID,
1161
+ $src,
1162
+ $link_text,
1163
+ 'comment_content_image',
1164
+ $status,
1165
+ $status_type
1166
+ );
1167
  }
1168
  }
1169
 
1170
+ $sql = $wpdb->prepare(
1171
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND (type = %s || type = %s)",
1172
+ array(
1173
+ $comment->comment_ID,
1174
+ "comment_content_url",
1175
+ "comment_content_image"
1176
+ )
1177
+ );
1178
  $links = $wpdb->get_results($sql);
1179
  foreach ($links as $link) {
1180
+ if (empty($linkscontent[$link->link_url . $link->type])) {
1181
  $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
1182
  } else {
1183
+ unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1184
  }
1185
  }
1186
 
1187
+ if (!empty($linkscontent)) {
1188
+ foreach ($linkscontent as $link) {
1189
+ MetaSeoBrokenLinkTable::insertLink($link, $wpdb);
1190
  }
1191
  }
1192
  } else {
 
1193
  $wpdb->query(
1194
+ $wpdb->prepare(
1195
+ "DELETE FROM " . $wpdb->prefix . "wpms_links
1196
+ WHERE source_id = %d AND (type = %s || type = %s || type = %s)",
1197
+ array(
1198
+ $comment_ID,
1199
+ 'comment',
1200
+ 'comment_content_url',
1201
+ 'comment_content_image'
1202
+ )
1203
+ )
1204
  );
1205
  }
1206
 
1207
+ update_option('wpms_last_update_post', time());
1208
  }
1209
+
1210
+ /**
1211
  * Update wpms_links table when update post
1212
+ * @param int $post_ID Id of current post
1213
+ * @param $post_after
1214
+ * @param $post_before
1215
  */
1216
+ public static function updatePost($post_ID, $post_after, $post_before)
1217
+ {
1218
+ global $wpdb;
1219
  $post = $post_after;
1220
  $dom = new DOMDocument;
1221
  libxml_use_internal_errors(true);
1222
+ $linkscontent = array();
1223
 
1224
  if ($post->post_excerpt != 'metaseo_404_page') {
1225
  if ($post->post_status == 'publish') {
1226
  if (isset($post->post_content) && $post->post_content != '') {
 
1227
  preg_match_all("#<a[^>]*>.*?</a>#si", $post->post_content, $matches, PREG_PATTERN_ORDER);
1228
  foreach (array_unique($matches[0]) as $i => $content) {
1229
  $dom->loadHTML($content);
1233
 
1234
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1235
  $href = $matches[1];
1236
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1237
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1238
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1239
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1240
+ $source_link .= '<b>' . $post->post_title . '</b>';
1241
+ $source_link .= '</a>';
1242
+ $key = $href . 'url' . $post->ID . $link_text;
1243
+ $linkscontent[$key] = MetaSeoBrokenLinkTable::getResultLink(
1244
+ $source_link,
1245
+ $post->ID,
1246
+ $href,
1247
+ $link_text,
1248
+ 'url',
1249
+ $status,
1250
+ $status_type,
1251
+ $meta_title,
1252
+ $rel
1253
+ );
1254
  }
1255
+ preg_match_all(
1256
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1257
+ $post->post_content,
1258
+ $matches,
1259
+ PREG_PATTERN_ORDER
1260
+ );
1261
  foreach (array_unique($matches[0]) as $content) {
1262
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1263
+ $source_link .= '<b>' . $post->post_title . '</b>';
1264
+ $source_link .= '</a>';
1265
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1266
  $src = $matches[1];
1267
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1268
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1269
  $link_text = '';
1270
+ $linkscontent[$src . 'img' . $post->ID] = MetaSeoBrokenLinkTable::getResultLink(
1271
+ $source_link,
1272
+ $post->ID,
1273
+ $src,
1274
+ $link_text,
1275
+ 'image',
1276
+ $status,
1277
+ $status_type
1278
+ );
1279
  }
1280
  }
1281
 
1282
+ $sql = $wpdb->prepare(
1283
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE source_id=%d AND type != %s",
1284
+ array(
1285
+ $post->ID,
1286
+ "comment"
1287
+ )
1288
+ );
1289
  $links = $wpdb->get_results($sql);
1290
  foreach ($links as $link) {
1291
+ if (empty($linkscontent[$link->link_url . $link->type])) {
1292
  $wpdb->delete($wpdb->prefix . "wpms_links", array('id' => $link->id), array('%d'));
1293
  } else {
1294
+ unset($linkscontent[$link->link_url . $link->type . $link->link_text]);
1295
  }
1296
  }
1297
 
1298
+ if (!empty($linkscontent)) {
1299
+ foreach ($linkscontent as $link) {
1300
+ MetaSeoBrokenLinkTable::insertLink($link, $wpdb);
1301
  }
1302
  }
1303
  } else {
 
1304
  $wpdb->query(
1305
+ $wpdb->prepare(
1306
+ "DELETE FROM " . $wpdb->prefix . "wpms_links
1307
+ WHERE source_id = %d AND (type = %s || type = %s)",
1308
+ array(
1309
+ $post->ID,
1310
+ 'image',
1311
+ 'url'
1312
+ )
1313
+ )
1314
  );
1315
  }
1316
  }
1317
 
1318
+ update_option('wpms_last_update_post', time());
1319
  }
1320
+
1321
+ /**
1322
  * Scan link in comment , post
1323
  */
1324
+ public static function scanLink()
1325
+ {
1326
+ global $wpdb;
1327
  $limit_comment_content = 1;
1328
  $limit_comment = 10;
1329
  $limit_post = 1;
1336
 
1337
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1338
  unset($post_types['attachment']);
1339
+ if (!empty($post_type) && !in_array($post_type, $post_types)) {
1340
  $post_type = '\'post\'';
1341
+ } elseif (empty($post_type)) {
1342
  $post_type = "'" . implode("', '", $post_types) . "'";
1343
  } else {
1344
  $post_type = "'" . $post_type . "'";
1349
  $where[] = "post_status = '$states'";
1350
  $total_comments = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "comments");
1351
  $total_posts = $wpdb->get_var("SELECT COUNT(*)"
1352
+ . " FROM $wpdb->posts "
1353
+ . " WHERE " . implode(' AND ', $where));
1354
 
 
1355
  $percent_comment_content = 33.33;
1356
  $percent_comment = 33.33;
1357
  $percent_post = 33.33;
1358
 
1359
+ if (!empty($total_comments)) {
1360
  $percent_comment_content = 33.33 / $total_comments;
1361
+ }
1362
+
1363
+ if ($total_comments < $limit_comment_content) {
1364
  $percent_comment_content = 33.33;
1365
+ }
1366
+
1367
+ if (!empty($total_comments)) {
1368
  $percent_comment = 33.33 / $total_comments;
1369
+ }
1370
+
1371
+ if ($total_comments < $limit_comment) {
1372
  $percent_comment = 33.33;
1373
+ }
1374
+
1375
+ if (!empty($total_posts)) {
1376
  $percent_post = 33.33 / $total_posts;
1377
+ }
1378
+
1379
+ if ($total_posts < $limit_post) {
1380
  $percent_post = 33.33;
1381
+ }
1382
 
1383
  // scan link in comment url
1384
+ $comments = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "comments
1385
+ WHERE comment_approved = 1 AND comment_author_url != '' AND comment_author_url NOT IN (SELECT link_url
1386
+ FROM " . $wpdb->prefix . "wpms_links WHERE type='comment') LIMIT $limit_comment");
1387
+
1388
  if (!empty($comments)) {
1389
  foreach ($comments as $comment) {
1390
  if (!empty($comment->comment_author_url)) {
1391
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1392
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1393
+ $source_link .= '</a>';
1394
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($comment->comment_author_url);
1395
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1396
+ $coms = MetaSeoBrokenLinkTable::getResultLink(
1397
+ $source_link,
1398
+ $comment->comment_ID,
1399
+ $comment->comment_author_url,
1400
+ $comment->comment_author,
1401
+ 'comment',
1402
+ $status,
1403
+ $status_type
1404
+ );
1405
+ MetaSeoBrokenLinkTable::insertLink($coms, $wpdb);
1406
  }
1407
  }
1408
  wp_send_json(array('status' => false, 'type' => 'limit', 'percent' => $percent_comment));
1411
  // scan link in comment content
1412
  $k = 0;
1413
  $off_set = ($_POST['comment_paged'] - 1) * $limit_comment_content;
1414
+ $query = "SELECT * FROM " . $wpdb->prefix . "comments
1415
+ WHERE comment_approved = 1 AND comment_content != '' LIMIT $limit_comment_content OFFSET $off_set";
1416
  $comments_content = $wpdb->get_results($query);
1417
  if (!empty($comments_content)) {
1418
  foreach ($comments_content as $comment) {
 
 
1419
  if (isset($comment->comment_content) && $comment->comment_content != '') {
1420
  preg_match_all("#<a[^>]*>.*?</a>#si", $comment->comment_content, $matches, PREG_PATTERN_ORDER);
1421
  foreach (array_unique($matches[0]) as $i => $content) {
1422
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1423
  $href = $matches[1];
1424
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1425
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1426
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1427
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1428
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1429
+ $source_link .= '</a>';
1430
+ $link_a = MetaSeoBrokenLinkTable::getResultLink(
1431
+ $source_link,
1432
+ $comment->comment_ID,
1433
+ $href,
1434
+ $link_text,
1435
+ 'comment_content_url',
1436
+ $status,
1437
+ $status_type
1438
+ );
1439
+ MetaSeoBrokenLinkTable::insertLink($link_a, $wpdb);
1440
  }
1441
+ preg_match_all(
1442
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1443
+ $comment->comment_content,
1444
+ $matches,
1445
+ PREG_PATTERN_ORDER
1446
+ );
1447
  foreach (array_unique($matches[0]) as $content) {
1448
+ $source_link = '<a href="' . get_edit_comment_link($comment->comment_ID) . '">';
1449
+ $source_link .= '<b>' . $comment->comment_author . '</b>';
1450
+ $source_link .= '</a>';
1451
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1452
  $src = $matches[1];
1453
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1454
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1455
  $link_text = '';
1456
+ $link_sou = MetaSeoBrokenLinkTable::getResultLink(
1457
+ $source_link,
1458
+ $comment->comment_ID,
1459
+ $src,
1460
+ $link_text,
1461
+ 'comment_content_image',
1462
+ $status,
1463
+ $status_type
1464
+ );
1465
+ MetaSeoBrokenLinkTable::insertLink($link_sou, $wpdb);
1466
  }
1467
  }
1468
  }
1469
 
1470
  $k++;
1471
  if ($k >= $limit_comment_content) {
1472
+ wp_send_json(
1473
+ array(
1474
+ 'status' => false,
1475
+ 'type' => 'limit_comment_content',
1476
+ 'paged' => $_POST['comment_paged'],
1477
+ 'percent' => $percent_comment_content * count($comments_content)
1478
+ )
1479
+ );
1480
  }
1481
  }
1482
 
1484
  $j = 0;
1485
  $off_set = ($_POST['paged'] - 1) * $limit_post;
1486
  $query = "SELECT ID, post_title, post_excerpt , post_content ,post_name, post_type, post_status"
1487
+ . " FROM $wpdb->posts "
1488
+ . " WHERE " . implode(' AND ', $where) . "LIMIT $limit_post OFFSET $off_set";
1489
 
1490
  $results = $wpdb->get_results($query);
1491
+ if (empty($results)) {
1492
  wp_send_json(array('status' => true));
1493
+ }
1494
 
1495
  foreach ($results as $post) {
1496
  if ($post->post_excerpt != 'metaseo_404_page') {
1505
  $rel = $tags->item(0)->getAttribute('rel');
1506
  preg_match('/< *a[^>]*href *= *["\']?([^"\']*)/i', $content, $matches);
1507
  $href = $matches[1];
1508
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($href);
1509
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1510
  $link_text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "$2", $content);
1511
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1512
+ $source_link .= '<b>' . $post->post_title . '</b>';
1513
+ $source_link .= '</a>';
1514
+ $link_a = MetaSeoBrokenLinkTable::getResultLink(
1515
+ $source_link,
1516
+ $post->ID,
1517
+ $href,
1518
+ $link_text,
1519
+ 'url',
1520
+ $status,
1521
+ $status_type,
1522
+ $meta_title,
1523
+ $rel,
1524
+ $post->ID
1525
+ );
1526
+ MetaSeoBrokenLinkTable::insertLink($link_a, $wpdb);
1527
  }
1528
+ preg_match_all(
1529
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1530
+ $post->post_content,
1531
+ $matches,
1532
+ PREG_PATTERN_ORDER
1533
+ );
1534
  foreach (array_unique($matches[0]) as $content) {
1535
+ $source_link = '<a href="' . get_edit_post_link($post->ID) . '">';
1536
+ $source_link .= '<b>' . $post->post_title . '</b>';
1537
+ $source_link .= '</a>';
1538
  preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
1539
  $src = $matches[1];
1540
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($src);
1541
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1542
  $link_text = '';
1543
+ $link_src = MetaSeoBrokenLinkTable::getResultLink(
1544
+ $source_link,
1545
+ $post->ID,
1546
+ $src,
1547
+ $link_text,
1548
+ 'image',
1549
+ $status,
1550
+ $status_type
1551
+ );
1552
+ MetaSeoBrokenLinkTable::insertLink($link_src, $wpdb);
1553
  }
1554
  }
1555
  }
1556
  $j++;
1557
  if ($j >= $limit_post) {
1558
+ wp_send_json(
1559
+ array(
1560
+ 'status' => false,
1561
+ 'type' => 'limit_post',
1562
+ 'paged' => $_POST['paged'],
1563
+ 'percent' => $percent_post * count($results)
1564
+ )
1565
+ );
1566
  }
1567
  }
1568
 
1581
  update_option('wpms_link_settings', $link_settings);
1582
  wp_send_json(array('status' => true));
1583
  }
1584
+
1585
+ /**
1586
  * Insert link to wpms_link table
1587
+ * @param array $link link details to insert
1588
+ * @param object $wpdb global wordpress database
1589
  */
1590
+ public static function insertLink($link, $wpdb)
1591
+ {
1592
+ $sql = $wpdb->prepare(
1593
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE link_url=%s AND type=%s AND source_id=%d ",
1594
+ array(
1595
+ $link['link_url'],
1596
+ $link['type'],
1597
+ $link['source_id']
1598
+ )
1599
+ );
1600
  $links = $wpdb->get_results($sql);
1601
  if (count($links) == 0) {
1602
+ $status = MetaSeoBrokenLinkTable::getUrlStatus(($link['link_url']));
1603
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1604
  $value = array(
1605
  'link_url' => $link['link_url'],
1606
  'link_final_url' => $link['link_final_url'],
1619
  if (isset($link['status_type']) && $link['status_type'] != 'ok') {
1620
  $value[$link['status_type']] = 1;
1621
  }
1622
+
1623
  $site_url = get_site_url();
1624
+ $value = MetaSeoBrokenLinkTable::checkInternalLink($link['link_url'], $site_url, $value);
1625
 
1626
  $wpdb->insert(
1627
+ $wpdb->prefix . 'wpms_links',
1628
+ $value
1629
  );
1630
  } else {
1631
  $value = array(
1633
  'follow' => $link['follow']
1634
  );
1635
  $site_url = get_site_url();
1636
+ // get status
1637
+ $status = MetaSeoBrokenLinkTable::getUrlStatus(($link['link_url']));
1638
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1639
 
1640
+ $value = MetaSeoBrokenLinkTable::checkInternalLink($links[0]->link_url, $site_url, $value);
 
 
 
1641
  $value['status_code'] = $status;
1642
  $value['status_text'] = $status_text;
1643
+ if ($links[0]->follow != $link['follow'] || $links[0]->meta_title != $link['meta_title']
1644
+ || $links[0]->internal != $value['internal'] || $links[0]->status_code != $value['status_code']) {
1645
+ // update link status
1646
  $wpdb->update(
1647
+ $wpdb->prefix . 'wpms_links',
1648
+ $value,
1649
+ array(
1650
+ 'id' => $links[0]->id
1651
+ )
1652
  );
1653
  }
1654
  }
1655
  }
1656
+
1657
+ /**
1658
  * Check internal link
1659
+ * @param string $link current link url
1660
+ * @param string $siteUrl site url
1661
+ * @param $value
1662
+ * @return mixed
1663
  */
1664
+ public static function checkInternalLink($link, $siteUrl, $value)
1665
+ {
1666
  $info_link = parse_url($link);
1667
+ if (empty($info_link['path'])) {
1668
  $value['internal'] = 0;
1669
  return $value;
1670
  }
1671
 
1672
+ if (empty($info_link['host'])) {
1673
  $value['internal'] = 0;
1674
  return $value;
1675
  }
1685
 
1686
  return $value;
1687
  }
1688
+
1689
+ /**
1690
  * Flush link
1691
  */
1692
+ public static function flushLink()
1693
+ {
1694
  global $wpdb;
1695
  if (isset($_POST['type']) && $_POST['type'] != 'none') {
1696
  switch ($_POST['type']) {
1697
  case 'automaticaly_indexed':
1698
  $wpdb->query(
1699
+ $wpdb->prepare(
1700
+ "
1701
  DELETE FROM " . $wpdb->prefix . "wpms_links
1702
  WHERE broken_indexed = %d AND link_url_redirect = %s
1703
+ ",
1704
+ array(1, '')
1705
+ )
1706
  );
1707
  break;
1708
  case 'internal_broken_links':
1709
  $wpdb->query(
1710
+ $wpdb->prepare(
1711
+ "
1712
  DELETE FROM " . $wpdb->prefix . "wpms_links
1713
  WHERE broken_internal = %d AND link_url_redirect = %s
1714
+ ",
1715
+ array(1, '')
1716
+ )
1717
  );
1718
  break;
1719
  case 'all':
1720
  $wpdb->query(
1721
+ $wpdb->prepare(
1722
+ "
1723
  DELETE FROM " . $wpdb->prefix . "wpms_links
1724
  WHERE (broken_internal = %d
1725
  OR broken_indexed = %d) AND link_url_redirect = %s
1726
+ ",
1727
+ array(1, 1, '')
1728
+ )
1729
  );
1730
 
1731
  break;
1734
  }
1735
  wp_send_json(false);
1736
  }
1737
+
1738
+ /**
1739
  * Get status text
1740
+ * @param string $status statue of link
1741
+ * @return bool|string
1742
  */
1743
+ public static function getStatusText($status)
1744
+ {
1745
+ if ($status == 'Not checked') {
1746
  return 'Not checked';
1747
+ }
1748
  if ($status == 'Server Not Found') {
1749
  $status_text = 'Server Not Found';
1750
  } else {
1753
  return $status_text;
1754
  }
1755
 
1756
+ /**
1757
  * Add custom redirect
1758
  */
1759
+ public static function addCustomRedirect()
1760
+ {
1761
  do_action('wpms_add_custom_redirect');
1762
+ wp_send_json(array('status' => true, 'message' => __('Done!', 'wp-meta-seo')));
1763
  }
1764
+
1765
+ /**
1766
  * Update link
1767
  */
1768
+ public static function updateLinkRedirect()
1769
+ {
1770
 
1771
  if (isset($_POST['link_id'])) {
1772
  global $wpdb;
1773
+ $sql = $wpdb->prepare(
1774
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
1775
+ array($_POST['link_id'])
1776
+ );
1777
  $link_detail = $wpdb->get_row($sql);
1778
+ if (empty($link_detail)) {
1779
  wp_send_json(false);
1780
+ }
1781
+
1782
  $new_link = stripslashes($_POST['new_link']);
1783
  $link_redirect = stripslashes($_POST['link_redirect']);
1784
+ if (isset($_POST['new_text'])) {
1785
  $new_text = stripcslashes($_POST['new_text']);
1786
+ } else {
1787
  $new_text = '';
1788
  }
1789
 
1790
+ if ($link_redirect != '') {
1791
  $status = 'HTTP/1.1 200 OK';
1792
+ } else {
1793
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($new_link);
1794
  }
1795
 
1796
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1797
+ $status_type = MetaSeoBrokenLinkTable::getUrlStatusType($status);
1798
  if ($link_detail->type != '404_automaticaly') {
1799
  $value = array('link_url' => $new_link,
1800
  'link_final_url' => '',
1826
  }
1827
  }
1828
 
1829
+ if (!empty($link_redirect)) {
1830
  $value['link_url_redirect'] = $link_redirect;
1831
+ }
1832
+
1833
  if (isset($status_type) && $status_type != 'ok') {
1834
  $value[$status_type] = 1;
1835
  }
1836
  } else {
1837
+ $status = MetaSeoBrokenLinkTable::getUrlStatus($link_redirect);
1838
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
1839
 
1840
  $value = array(
1841
  'link_url_redirect' => stripslashes($link_redirect),
1845
  );
1846
  }
1847
 
1848
+ if ($link_detail->type == 'add_custom') {
1849
  $value['meta_title'] = $_POST['status_redirect'];
1850
  }
1851
 
1852
  $site_url = get_site_url();
1853
+ $value = MetaSeoBrokenLinkTable::checkInternalLink($new_link, $site_url, $value);
1854
 
1855
  $wpdb->update(
1856
+ $wpdb->prefix . 'wpms_links',
1857
+ $value,
1858
+ array(
1859
+ 'id' => $_POST['link_id']
1860
+ )
1861
  );
1862
 
1863
  switch ($link_detail->type) {
1864
  case '404_automaticaly':
1865
+ wp_send_json(
1866
+ array(
1867
+ 'status' => true,
1868
+ 'type' => '404_automaticaly',
1869
+ 'status_text' => $status_text,
1870
+ 'new_link' => esc_url($new_link)
1871
+ )
1872
+ );
1873
  break;
1874
  case 'comment_content_image':
1875
  $comment = get_comment($link_detail->source_id);
1876
  if (!empty($comment)) {
1877
  $old_value = $comment->comment_content;
1878
+ $edit_result = MetaSeoBrokenLinkTable::editLinkImg(
1879
+ $old_value,
1880
+ $new_link,
1881
+ $link_detail->link_url
1882
+ );
1883
  $my_comment = array(
1884
  'comment_ID' => $link_detail->source_id,
1885
  'comment_content' => $edit_result['content']
1886
  );
1887
+ remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
1888
  wp_update_comment($my_comment);
1889
+ wp_send_json(
1890
+ array(
1891
+ 'status' => true,
1892
+ 'type' => 'image',
1893
+ 'status_text' => $status_text,
1894
+ 'new_link' => esc_url($edit_result['raw_url'])
1895
+ )
1896
+ );
1897
  }
1898
  break;
1899
  case 'image':
1900
  $post = get_post($link_detail->source_id);
1901
  if (!empty($post)) {
1902
  $old_value = $post->post_content;
1903
+ $edit_result = MetaSeoBrokenLinkTable::editLinkImg(
1904
+ $old_value,
1905
+ $new_link,
1906
+ $link_detail->link_url
1907
+ );
1908
  $my_post = array(
1909
  'ID' => $link_detail->source_id,
1910
  'post_content' => $edit_result['content']
1911
  );
1912
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1913
  wp_update_post($my_post);
1914
+ wp_send_json(
1915
+ array(
1916
+ 'status' => true,
1917
+ 'type' => 'image',
1918
+ 'status_text' => $status_text,
1919
+ 'new_link' => esc_url($edit_result['raw_url'])
1920
+ )
1921
+ );
1922
  }
1923
  break;
1924
 
1927
  if (!empty($comment)) {
1928
  $old_value = $comment->comment_content;
1929
  if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1930
+ $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1931
+ $old_value,
1932
+ $new_link,
1933
+ $link_detail->link_url
1934
+ );
1935
  $new_text = '';
1936
  } else {
1937
+ $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1938
+ $old_value,
1939
+ $new_link,
1940
+ $link_detail->link_url,
1941
+ $new_text
1942
+ );
1943
  $new_text = strip_tags($edit_result['link_text']);
1944
  }
1945
 
1947
  'comment_ID' => $link_detail->source_id,
1948
  'comment_content' => $edit_result['content']
1949
  );
1950
+ remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
1951
  wp_update_comment($my_comment);
1952
+ wp_send_json(
1953
+ array(
1954
+ 'status' => true,
1955
+ 'type' => 'url',
1956
+ 'status_text' => $status_text,
1957
+ 'new_link' => $edit_result['raw_url'],
1958
+ 'new_text' => $new_text
1959
+ )
1960
+ );
1961
  }
1962
 
1963
  break;
1967
  if (!empty($post)) {
1968
  $old_value = $post->post_content;
1969
  if (isset($_POST['data_type']) && $_POST['data_type'] == 'multi' && $new_text == '') {
1970
+ $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1971
+ $old_value,
1972
+ $new_link,
1973
+ $link_detail->link_url
1974
+ );
1975
  $new_text = '';
1976
  } else {
1977
+ $edit_result = MetaSeoBrokenLinkTable::editLinkHtml(
1978
+ $old_value,
1979
+ $new_link,
1980
+ $link_detail->link_url,
1981
+ $new_text
1982
+ );
1983
  $new_text = strip_tags($edit_result['link_text']);
1984
  }
1985
 
1987
  'ID' => $link_detail->source_id,
1988
  'post_content' => $edit_result['content']
1989
  );
1990
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1991
  wp_update_post($my_post);
1992
+ wp_send_json(
1993
+ array(
1994
+ 'status' => true,
1995
+ 'type' => 'url',
1996
+ 'status_text' => $status_text,
1997
+ 'new_link' => $edit_result['raw_url'],
1998
+ 'new_text' => $new_text
1999
+ )
2000
+ );
2001
  }
2002
 
2003
  break;
2004
  case 'comment':
2005
+ wp_update_comment(
2006
+ array(
2007
+ 'comment_ID' => $link_detail->source_id,
2008
+ 'comment_author_url' => $new_link
2009
+ )
2010
+ );
2011
+ wp_send_json(
2012
+ array(
2013
+ 'status' => true,
2014
+ 'type' => 'orther',
2015
+ 'status_text' => $status_text,
2016
+ 'new_link' => $new_link
2017
+ )
2018
+ );
2019
  break;
2020
 
2021
  case 'add_custom':
2022
+ wp_send_json(
2023
+ array(
2024
+ 'status' => true,
2025
+ 'type' => 'orther',
2026
+ 'status_text' => $status_text,
2027
+ 'new_link' => $new_link
2028
+ )
2029
+ );
2030
  break;
2031
  }
2032
  }
2033
  wp_send_json(false);
2034
  }
2035
+
2036
+ /**
2037
  * Remove link
2038
  */
2039
+ public static function unlink()
2040
+ {
2041
  if (isset($_POST['link_id'])) {
2042
  global $wpdb;
2043
+ $sql = $wpdb->prepare(
2044
+ "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d",
2045
+ array($_POST['link_id'])
2046
+ );
2047
  $link_detail = $wpdb->get_row($sql);
2048
+ if (empty($link_detail)) {
2049
  wp_send_json(false);
2050
+ }
2051
+
2052
  $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => $_POST['link_id']));
2053
  switch ($link_detail->type) {
2054
  case 'add_rule':
2060
  $comment = get_comment($link_detail->source_id);
2061
  if (!empty($comment)) {
2062
  $old_value = $comment->comment_content;
2063
+ $new_content = MetaSeoBrokenLinkTable::unlinkImg($old_value, $link_detail->link_url);
2064
+ remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2065
  $my_comment = array(
2066
  'comment_ID' => $link_detail->source_id,
2067
  'comment_content' => $new_content
2075
  $post = get_post($link_detail->source_id);
2076
  if (!empty($post)) {
2077
  $old_value = $post->post_content;
2078
+ $new_content = MetaSeoBrokenLinkTable::unlinkImg($old_value, $link_detail->link_url);
2079
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2080
  $my_post = array(
2081
  'ID' => $link_detail->source_id,
2082
  'post_content' => $new_content
2090
  $comment = get_comment($link_detail->source_id);
2091
  if (!empty($comment)) {
2092
  $old_value = $comment->comment_content;
2093
+ $new_content = MetaSeoBrokenLinkTable::unlinkHtml($old_value, $link_detail->link_url);
2094
+ remove_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment'));
2095
  $my_comment = array(
2096
  'comment_ID' => $link_detail->source_id,
2097
  'comment_content' => $new_content
2105
  $post = get_post($link_detail->source_id);
2106
  if (!empty($post)) {
2107
  $old_value = $post->post_content;
2108
+ $new_content = MetaSeoBrokenLinkTable::unlinkHtml($old_value, $link_detail->link_url);
2109
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
2110
  $my_post = array(
2111
  'ID' => $link_detail->source_id,
2112
  'post_content' => $new_content
2126
  }
2127
  wp_send_json(false);
2128
  }
2129
+
2130
  /**
2131
+ * Change all occurrences of a given plaintext URLs to a new URL.
2132
+ *
2133
+ * @param string $content Look for URLs in this string.
2134
+ * @param string $new_url Change them to this URL.
2135
+ * @param string $old_url The URL to look for.
2136
+ *
2137
+ * @return array|WP_Error If successful, the return value will be an associative array with two
2138
+ * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
2139
+ * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
2140
+ */
2141
+ public static function editLinkImg($content, $new_url, $old_url)
2142
+ {
2143
  self::$old_url = $old_url;
2144
  self::$new_url = htmlentities($new_url);
2145
+ $content = preg_replace_callback(
2146
+ self::$img_pattern,
2147
+ array(
2148
+ 'MetaSeoBrokenLinkTable',
2149
+ 'editImgCallback'
2150
+ ),
2151
+ $content
2152
+ );
2153
 
2154
  return array(
2155
  'content' => $content,
2156
  'raw_url' => self::$new_url,
2157
  );
2158
  }
2159
+
2160
+ /**
2161
+ * @param $matches
2162
+ * @return string
2163
+ */
2164
+ public static function editImgCallback($matches)
2165
+ {
2166
  $url = $matches[3];
2167
  if (($url) == self::$old_url) {
2168
  return $matches[1] . '"' . self::$new_url . '"' . $matches[4];
2170
  return $matches[0];
2171
  }
2172
  }
2173
+
2174
  /**
2175
+ * Remove all occurrences of a specific plaintext URL.
2176
+ *
2177
+ * @param string $content Look for URLs in this string.
2178
+ * @param string $url The URL to look for.
2179
+ * @return string Input string with all matching plaintext URLs removed.
2180
+ */
2181
+ public static function unlinkImg($content, $url)
2182
+ {
2183
  self::$old_url = $url; //used by the callback
2184
+ $content = preg_replace_callback(
2185
+ self::$img_pattern,
2186
+ array(
2187
+ 'MetaSeoBrokenLinkTable',
2188
+ 'unlinkImgCallback'
2189
+ ),
2190
+ $content
2191
+ );
2192
  return $content;
2193
  }
2194
 
2195
+ /**
2196
+ * get image unchanged
2197
+ * @param $matches
2198
+ * @return string
2199
+ */
2200
+ public static function unlinkImgCallback($matches)
2201
+ {
2202
  $url = $matches[3];
2203
  if (($url) == self::$old_url) {
2204
  return ''; //Completely remove the IMG tag
2206
  return $matches[0]; //return the image unchanged
2207
  }
2208
  }
2209
+
2210
  /**
2211
+ * Remove all occurrences of a specific plaintext URL.
2212
+ *
2213
+ * @param string $content Look for URLs in this string.
2214
+ * @param string $url The URL to look for.
2215
+ * @return string Input string with all matching plaintext URLs removed.
2216
+ */
2217
+ public static function unlinkHtml($content, $url)
2218
+ {
2219
  $args = array(
2220
  'old_url' => $url,
2221
  );
2222
 
2223
+ $content = MetaSeoBrokenLinkTable::multiEdit(
2224
+ $content,
2225
+ array(
2226
+ 'MetaSeoBrokenLinkTable',
2227
+ 'unlinkHtmlCallback'
2228
+ ),
2229
+ $args
2230
+ );
2231
 
2232
  return $content;
2233
  }
2234
+
2235
+ /**
2236
+ * Get link to remove
2237
+ * @param $link
2238
+ * @param $params
2239
+ * @return mixed
2240
+ */
2241
+ public static function unlinkHtmlCallback($link, $params)
2242
+ {
2243
  if ($link['href'] != $params['old_url']) {
2244
  return $link['#raw'];
2245
  }
2246
 
2247
  return $link['#link_text'];
2248
  }
2249
+
2250
  /**
2251
+ * Change all occurrences of a given plaintext URLs to a new URL.
2252
+ *
2253
+ * @param string $content Look for URLs in this string.
2254
+ * @param string $new_url Change them to this URL.
2255
+ * @param string $old_url The URL to look for.
2256
+ * @param string $new_text new text of this URL.
2257
+ * @return array|WP_Error If successful, the return value will be an associative array with two
2258
+ * keys : 'content' - the modified content, and 'raw_url' - the new raw, non-normalized URL used
2259
+ * for the modified links. In most cases, the returned raw_url will be equal to the new_url.
2260
+ */
2261
+ public static function editLinkHtml($content, $new_url, $old_url, $new_text = null)
2262
+ {
2263
  //Save the old & new URLs for use in the edit callback.
2264
  $args = array(
2265
  'old_url' => $old_url,
2268
  );
2269
 
2270
  //Find all links and replace those that match $old_url.
2271
+ $content = MetaSeoBrokenLinkTable::multiEdit(
2272
+ $content,
2273
+ array(
2274
+ 'MetaSeoBrokenLinkTable',
2275
+ 'editHtmlCallback'
2276
+ ),
2277
+ $args
2278
+ );
2279
 
2280
  $result = array(
2281
  'content' => $content,
2286
  }
2287
  return $result;
2288
  }
2289
+
2290
+ /**
2291
+ * get url in content
2292
+ * @param array $link link details
2293
+ * @param array $params new params to edit
2294
+ * @return array
2295
+ */
2296
+ public static function editHtmlCallback($link, $params)
2297
+ {
2298
  if ($link['href'] == $params['old_url']) {
2299
  $modified = array(
2300
  'href' => $params['new_url'],
2317
  return $link['#raw'];
2318
  }
2319
  }
2320
+
2321
  /**
2322
+ * Helper function for blcHtmlLink::multi_edit()
2323
+ * Applies the specified callback function to each link and merges
2324
+ * the result with the current link attributes. If the callback returns
2325
+ * a replacement HTML tag instead, it will be stored in the '#new_raw'
2326
+ * key of the return array.
2327
+ *
2328
+ * @access protected
2329
+ *
2330
+ * @param array $link
2331
+ * @param array $info The callback function and the extra argument to pass to that function (if any).
2332
+ * @return array
2333
+ */
2334
+ public static function editCallback($link, $info)
2335
+ {
2336
  list($callback, $extra) = $info;
2337
 
2338
  //Prepare arguments for the callback
2351
 
2352
  return $link;
2353
  }
2354
+
2355
  /**
2356
+ * Modify all HTML links found in a string using a callback function.
2357
+ * The callback function should return either an associative array or a string. If
2358
+ * a string is returned, the parser will replace the current link with the contents
2359
+ * of that string. If an array is returned, the current link will be modified/rebuilt
2360
+ * by substituting the new values for the old ones.
2361
+ * htmlentities() will be automatically applied to attribute values (but not to #link_text).
2362
+ * @param string $content A text string containing the links to edit.
2363
+ * @param callback $callback Callback function used to modify the links.
2364
+ * @param mixed $extra If supplied, $extra will be passed as the second parameter to the function $callback.
2365
+ * @return string The modified input string.
2366
+ */
2367
+ public static function multiEdit($content, $callback, $extra = null)
2368
+ {
2369
  //Just reuse map() + a little helper func. to apply the callback to all links and get modified links
2370
+ $modified_links = MetaSeoBrokenLinkTable::map(
2371
+ $content,
2372
+ array(
2373
+ 'MetaSeoBrokenLinkTable',
2374
+ 'editCallback'
2375
+ ),
2376
+ array(
2377
+ $callback,
2378
+ $extra
2379
+ )
2380
+ );
2381
  //Replace each old link with the modified one
2382
  $offset = 0;
2383
  foreach ($modified_links as $link) {
2399
 
2400
  $content = substr_replace($content, $new_html, $link['#offset'] + $offset, strlen($link['#raw']));
2401
  //Update the replacement offset
2402
+ $offset += (strlen($new_html) - strlen($link['#raw']));
2403
  }
2404
 
2405
  return $content;
2406
  }
2407
+
2408
  /**
2409
+ * extractTags()
2410
+ * Extract specific HTML tags and their attributes from a string.
2411
+ *
2412
+ * You can either specify one tag, an array of tag names, or a regular expression that matches the tag name(s).
2413
+ * If multiple tags are specified you must also set the $selfclosing parameter and it must be the same for
2414
+ * all specified tags (so you can't extract both normal and self-closing tags in one go).
2415
+ *
2416
+ * The function returns a numerically indexed array of extracted tags. Each entry is an associative array
2417
+ * with these keys :
2418
+ * tag_name - the name of the extracted tag, e.g. "a" or "img".
2419
+ * offset - the numberic offset of the first character of the tag within the HTML source.
2420
+ * contents - the inner HTML of the tag. This is always empty for self-closing tags.
2421
+ * attributes - a name -> value array of the tag's attributes, or an empty array if the tag has none.
2422
+ * full_tag - the entire matched tag, e.g. '<a href="http://example.com">example.com</a>'. This key
2423
+ * will only be present if you set $return_the_entire_tag to true.
2424
+ *
2425
+ * @param string $html The HTML code to search for tags.
2426
+ * @param string|array $tag The tag(s) to extract.
2427
+ * @param bool $selfclosing Whether the tag is self-closing or not.
2428
+ * Setting it to null will force the script to try and make an educated guess.
2429
+ * @param bool $return_the_entire_tag Return the entire matched tag in 'full_tag' key of the results array.
2430
+ * @param string $charset The character set of the HTML code. Defaults to ISO-8859-1.
2431
+ *
2432
+ * @return array An array of extracted tags, or an empty array if no matching tags were found.
2433
+ */
2434
+ public static function extractTags(
2435
+ $html,
2436
+ $tag,
2437
+ $selfclosing = null,
2438
+ $return_the_entire_tag = false,
2439
+ $charset = 'ISO-8859-1'
2440
+ ) {
2441
 
2442
  if (is_array($tag)) {
2443
  $tag = implode('|', $tag);
2444
  }
2445
 
2446
+ $selfclosing_tags = array(
2447
+ 'area',
2448
+ 'base',
2449
+ 'basefont',
2450
+ 'br',
2451
+ 'hr',
2452
+ 'input',
2453
+ 'img',
2454
+ 'link',
2455
+ 'meta',
2456
+ 'col',
2457
+ 'param'
2458
+ );
2459
  if (is_null($selfclosing)) {
2460
  $selfclosing = in_array($tag, $selfclosing_tags);
2461
  }
2480
  (
2481
  (?P<quote>[\"\'])(?P<value_quoted>.*?)(?P=quote) # a quoted value
2482
  | # or
2483
+ (?P<value_unquoted>[^\s"\']+?)(?:\s+|$) # an unquoted value (terminated by whitespace or EOF)
2484
  )
2485
  @xsi';
2486
 
2487
+ //Find all tags
2488
  if (!preg_match_all($tag_pattern, $html, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
2489
  //Return an empty array if we didn't find anything
2490
  return array();
2492
 
2493
  $tags = array();
2494
  foreach ($matches as $match) {
 
2495
  //Parse tag attributes, if any
2496
  $attributes = array();
2497
  if (!empty($match['attributes'][0])) {
 
2498
  if (preg_match_all($attribute_pattern, $match['attributes'][0], $attribute_data, PREG_SET_ORDER)) {
2499
  //Turn the attribute data into a name->value array
2500
  foreach ($attribute_data as $attr) {
2501
  if (!empty($attr['value_quoted'])) {
2502
  $value = $attr['value_quoted'];
2503
+ } elseif (!empty($attr['value_unquoted'])) {
2504
  $value = $attr['value_unquoted'];
2505
  } else {
2506
  $value = '';
2531
 
2532
  return $tags;
2533
  }
2534
+
2535
  /**
2536
+ * Apply a callback function to all HTML links found in a string and return the results.
2537
+ *
2538
+ * The link data array will contain at least these keys :
2539
+ * 'href' - the URL of the link (with htmlentitydecode() already applied).
2540
+ * '#raw' - the raw link code, e.g. the entire '<a href="...">...</a>' tag of a HTML link.
2541
+ * '#offset' - the offset within $content at which the first character of the link tag was found.
2542
+ * '#link_text' - the link's anchor text, if any. May contain HTML tags.
2543
+ *
2544
+ * Any attributes of the link tag will also be included in the returned array as attr_name => attr_value
2545
+ * pairs. This function will also automatically decode any HTML entities found in attribute values.
2546
+ * @param string $content A text string to parse for links.
2547
+ * @param callback $callback Callback function to apply to all found links.
2548
+ * @param mixed $extra If the optional $extra param. is supplied,
2549
+ * it will be passed as the second parameter to the function $callback.
2550
+ * @return array An array of all detected links after applying $callback to each of them.
2551
+ */
2552
+ public static function map($content, $callback, $extra = null)
2553
+ {
2554
  $results = array();
2555
 
2556
  //Find all links
2557
+ $links = MetaSeoBrokenLinkTable::extractTags($content, 'a', false, true);
2558
 
2559
  //Iterate over the links and apply $callback to each
2560
  foreach ($links as $link) {
 
2561
  //Massage the found link into a form required for the callback function
2562
  $param = $link['attributes'];
2563
  $param = array_merge(
2564
+ $param,
2565
+ array(
2566
+ '#raw' => $link['full_tag'],
2567
+ '#offset' => $link['offset'],
2568
+ '#link_text' => $link['contents'],
2569
+ 'href' => isset($link['attributes']['href']) ? $link['attributes']['href'] : '',
2570
+ )
2571
  );
2572
 
2573
  //Prepare arguments for the callback
2582
 
2583
  return $results;
2584
  }
2585
+
2586
  /*
2587
  * Ajax recheck link
2588
  */
2589
+ public static function reCheckLink()
2590
+ {
2591
  if (isset($_POST['link_id'])) {
2592
  global $wpdb;
2593
  $linkId = $_POST['link_id'];
2594
  $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE id=%d", array($linkId));
2595
  $link = $wpdb->get_row($sql);
2596
  if (!empty($link)) {
2597
+ if ($link->link_url_redirect != '') {
2598
  $status = 'HTTP/1.1 200 OK';
2599
+ } else {
2600
+ $status = MetaSeoBrokenLinkTable::getUrlStatus(($link->link_url));
2601
  }
2602
 
2603
+ $status_text = MetaSeoBrokenLinkTable::getStatusText($status);
2604
 
2605
  if ($link->type == '404_automaticaly') {
2606
+ if (((int)substr($status, 9, 3) >= 301
2607
+ && (int)substr($status, 9, 3) <= 304)
2608
+ || ((int)substr($status, 9, 3) >= 400
2609
+ && (int)substr($status, 9, 3) <= 503
2610
+ && (int)substr($status, 9, 3) != 401) || $status == 'Server Not Found') {
2611
  $type = array('broken_indexed' => 1, 'broken_internal' => 0);
2612
  } else {
2613
  $type = array('broken_indexed' => 0, 'broken_internal' => 0);
2614
  }
2615
  } else {
2616
+ if (((int)substr($status, 9, 3) >= 400
2617
+ && (int)substr($status, 9, 3) <= 503
2618
+ && (int)substr($status, 9, 3) != 401)
2619
+ || $status == 'Server Not Found') {
2620
  $type = array('broken_internal' => 1, 'broken_indexed' => 0);
2621
  } else {
2622
  $type = array('broken_internal' => 0, 'broken_indexed' => 0);
2631
  );
2632
 
2633
  $wpdb->update(
2634
+ $wpdb->prefix . 'wpms_links',
2635
+ $value,
2636
+ array(
2637
+ 'ID' => $_POST['link_id']
2638
+ )
2639
  );
2640
  wp_send_json(array('status' => true, 'status_text' => $status_text));
2641
  }
2642
  wp_send_json(array('status' => false));
2643
  }
2644
  }
 
2645
  }
inc/class.metaseo-content-list-table.php CHANGED
@@ -1,16 +1,26 @@
1
  <?php
2
- /**
3
- * Base class for displaying a list of posts/pages in an ajaxified HTML table.
4
- *
5
- */
6
-
7
  if (!class_exists('WP_List_Table')) {
8
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
9
  }
10
 
11
- class MetaSeo_Content_List_Table extends WP_List_Table {
 
 
 
 
 
 
 
 
12
  public $post_types;
13
- function __construct() {
 
 
 
 
 
14
  parent::__construct(array(
15
  'singular' => 'metaseo_content',
16
  'plural' => 'metaseo_contents',
@@ -19,44 +29,47 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
19
  }
20
 
21
  /**
22
- * Generate the table navigation above or below the table
23
- * @param string $which
24
- */
25
- function display_tablenav($which) {
 
26
  ?>
27
  <div class="tablenav <?php echo esc_attr($which); ?>">
28
 
29
- <input type="hidden" name="page" value="metaseo_content_meta" />
30
- <input type="hidden" name="page" value="metaseo_content_meta" />
31
- <?php if (!empty($_REQUEST['post_status'])): ?>
32
- <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>" />
33
  <?php endif ?>
34
 
35
  <?php $this->extra_tablenav($which); ?>
36
 
37
  <div style="float:right;margin-left:8px;">
38
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>" maxlength="3" name="metaseo_posts_per_page" class="metaseo_imgs_per_page screen-per-page" max="999" min="1" step="1">
39
- <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply" >
 
 
 
 
40
  </div>
41
 
42
- <?php $this->pagination($which); ?>
43
- <br class="clear" />
44
  </div>
45
 
46
  <?php
47
  }
48
-
49
  /**
50
- * Get an associative array ( id => link ) with the list
51
- * of views available on this table.
52
- * @return array
53
- */
54
- function get_views() {
 
55
  global $wpdb;
56
-
57
-
58
  $status_links = array();
59
-
60
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
61
  $post_types = "'" . implode("', '", $post_types) . "'";
62
 
@@ -64,16 +77,29 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
64
  $states['trash'] = 'trash';
65
  $all_states = "'" . implode("', '", $states) . "'";
66
 
67
- $total_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)");
 
 
68
 
69
  $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
70
- $status_links['all'] = "<a href='admin.php?page=metaseo_content_meta'$class>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts'), number_format_i18n($total_posts)) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
73
-
74
  $status_name = $status->name;
75
-
76
- $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$status_name') AND post_type IN ($post_types)");
 
77
 
78
  if ($total == 0) {
79
  continue;
@@ -85,20 +111,42 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
85
  $class = '';
86
  }
87
 
88
- $status_links[$status_name] = "<a href='admin.php?page=metaseo_content_meta&amp;post_status=$status_name'$class>" . sprintf(translate_nooped_plural($status->label_count, $total), number_format_i18n($total)) . '</a>';
89
- }
90
- $trashed_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)");
91
- $class = ( isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status'] ) ? 'class="current"' : '';
92
- $status_links['trash'] = "<a href='admin.php?page=metaseo_content_meta&amp;post_status=trash'$class>" . sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $trashed_posts, 'posts'), number_format_i18n($trashed_posts)) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  return $status_links;
95
  }
96
-
97
  /**
98
- * Extra controls to be displayed between bulk actions and pagination
99
- * @param string $which
100
- */
101
- function extra_tablenav($which) {
 
102
  echo '<div class="alignleft actions">';
103
  $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
104
 
@@ -106,49 +154,67 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
106
 
107
  foreach ($this->post_types as $post_type) {
108
  $obj = get_post_type_object($post_type->post_type);
109
- $options .= sprintf('<option value="%2$s" %3$s>%1$s</option>', $obj->labels->name, $post_type->post_type, selected($selected, $post_type->post_type, false));
110
- }
111
-
112
- $sl_bulk = '<select name="mbulk_copy" class="mbulk_copy"><option value="0">' . __('Bulk copy', 'wp-meta-seo') . '</option><option value="all">' . __('All Posts', 'wp-meta-seo') . '</option><option value="bulk-copy-metatitle">' . __('Selected posts', 'wp-meta-seo') . '</option></select>';
113
- $btn_bulk = '<input type="button" name="do_copy" id="post_do_copy" class="wpmsbtn wpmsbtn_small btn_do_copy post_do_copy" value="' . __('Content title as meta title', 'wp-meta-seo') . '"><span class="spinner"></span>';
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  $selected_duplicate = !empty($_REQUEST['wpms_duplicate_meta']) ? $_REQUEST['wpms_duplicate_meta'] : 'none';
116
- $options_dups = array('none' => __('All meta information', 'wp-meta-seo') , 'duplicate_title' => __('Duplicated meta titles', 'wp-meta-seo') , 'duplicate_desc' => __('Duplicated meta descriptions', 'wp-meta-seo'));
 
 
 
 
117
  $sl_duplicate = '<select name="wpms_duplicate_meta" class="wpms_duplicate_meta">';
118
- foreach ($options_dups as $key => $label){
119
- if($selected_duplicate == $key){
120
- $sl_duplicate .= '<option selected value="'.$key.'">'.$label.'</option>';
121
- }else{
122
- $sl_duplicate .= '<option value="'.$key.'">'.$label.'</option>';
123
  }
124
  }
125
  $sl_duplicate .= '</select>';
126
 
127
  echo sprintf('<select name="post_type_filter" class="metaseo-filter">%1$s</select>', $options);
128
  echo $sl_duplicate;
129
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && (is_plugin_active('sitepress-multilingual-cms/sitepress.php') || is_plugin_active('polylang/polylang.php'))){
 
 
130
  $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
131
- $sl_lang = apply_filters('wpms_get_languagesList','',$lang);
132
  echo $sl_lang;
133
  }
134
- echo '<input type="submit" name="do_filter" id="post-query-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="'.__('Filter', 'wp-meta-seo').'">';
 
135
  echo $sl_bulk . $btn_bulk;
136
-
137
-
138
  echo "</div>";
139
  }
140
-
141
  /**
142
- * Get a list of columns. The format is:
143
- * 'internal-name' => 'Title'
144
- * @return array
145
- */
146
- function get_columns() {
147
- $preview = __(" This is a rendering of what this post might look like in Google's search results.", 'wp-meta-seo');
 
 
148
  $info = sprintf('<a class="info-content"><img src=' . WPMETASEO_PLUGIN_URL . 'img/info.png>'
149
- . '<p class="tooltip-metacontent">'
150
- . $preview
151
- . '</p></a>');
152
 
153
  $columns = array(
154
  'cb' => '<input id="cb-select-all-1" type="checkbox" style="margin:0">',
@@ -176,49 +242,50 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
176
  }
177
 
178
  /**
179
- * Get a list of sortable columns. The format is:
180
- * 'internal-name' => 'orderby'
181
- * or
182
- * 'internal-name' => array( 'orderby', true )
183
- *
184
- * The second format will make the initial sorting order be descending
185
- * @return array
186
- */
187
- function get_sortable_columns() {
 
188
  return $sortable = array(
189
  'col_title' => array('post_title', true),
190
  'col_meta_title' => array('metatitle', true),
191
  'col_meta_desc' => array('metadesc', true)
192
  );
193
  }
194
-
195
  /**
196
- * Get a list of all registered post type objects.
197
- */
198
- function wpms_get_post_type(){
 
199
  global $wpdb;
200
-
201
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
202
  $post_types = "'" . implode("', '", esc_sql($post_types)) . "'";
203
 
204
  $states = get_post_stati(array('show_in_admin_all_list' => true));
205
  $states['trash'] = 'trash';
206
  $all_states = "'" . implode("', '", esc_sql($states)) . "'";
207
-
208
- $query = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
 
209
  $post_types = $wpdb->get_results($query);
210
  return $post_types;
211
  }
212
-
213
- /**
214
- * Prepares the list of items for displaying.
215
- * @uses WP_List_Table::set_pagination_args()
216
- */
217
- function prepare_items() {
218
- global $wpdb, $_wp_column_headers;
219
- $this->post_types = $this->wpms_get_post_type();
220
- $screen = get_current_screen();
221
 
 
 
 
 
 
 
 
 
222
  $where = array();
223
  $post_type = isset($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : "";
224
  if ($post_type == "-1") {
@@ -226,9 +293,9 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
226
  }
227
 
228
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
229
- if (!empty($post_type) && !in_array($post_type, $post_types))
230
  $post_type = '\'post\'';
231
- else if (empty($post_type)) {
232
  $post_type = "'" . implode("', '", esc_sql($post_types)) . "'";
233
  } else {
234
  $post_type = "'" . $post_type . "'";
@@ -251,7 +318,8 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
251
 
252
  $keyword = !empty($_GET["s"]) ? $_GET["s"] : '';
253
  if (isset($keyword) && $keyword != '') {
254
- $where[] = '(post_title LIKE "%' . $keyword . '%" OR mt.meta_value LIKE "%' . $keyword . '%" OR md.meta_value LIKE "%' . $keyword . '%")';
 
255
  }
256
 
257
  //Order By block
@@ -259,7 +327,7 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
259
  $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
260
 
261
  $sortable = $this->get_sortable_columns();
262
- $orderby_array = array($orderby,true);
263
  if (in_array($orderby_array, $sortable)) {
264
  $orderStr = $orderby;
265
  } else {
@@ -277,47 +345,56 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
277
  $orderStr = str_replace("'", "", $orderStr);
278
  }
279
 
280
- if(isset($_GET['wpms_duplicate_meta']) && $_GET['wpms_duplicate_meta'] != 'none'){
281
- if($_GET['wpms_duplicate_meta'] == 'duplicate_title'){
282
  $where[] = "mt.meta_key = '_metaseo_metatitle'";
283
  $where[] = "mt.meta_value = mt.meta_value AND mt.meta_value !=''";
284
- }elseif($_GET['wpms_duplicate_meta'] == 'duplicate_desc'){
285
  $where[] = "md.meta_key = '_metaseo_metadesc'";
286
  $where[] = "md.meta_value = md.meta_value AND md.meta_value !=''";
287
  }
288
  }
289
-
290
  $query = "SELECT COUNT(ID) "
291
- . " FROM $wpdb->posts "
292
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metatitle') mt ON mt.post_id = $wpdb->posts.ID "
293
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metadesc') md ON md.post_id = $wpdb->posts.ID "
294
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metakeywords') mk ON mk.post_id = $wpdb->posts.ID "
295
- . " WHERE " . implode(' AND ', $where) . $orderStr;
 
 
 
296
 
297
  $total_items = $wpdb->get_var($query);
298
-
299
- $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 "
300
- . " FROM $wpdb->posts "
301
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metatitle') mt ON mt.post_id = $wpdb->posts.ID "
302
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metadesc') md ON md.post_id = $wpdb->posts.ID "
303
- . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metakeywords') mk ON mk.post_id = $wpdb->posts.ID ";
 
 
 
 
304
  // query post by lang with polylang plugin
305
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')){
306
- if(isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0'){
307
- $query .= " INNER JOIN (SELECT * FROM $wpdb->term_relationships as ml INNER JOIN (SELECT * FROM $wpdb->terms WHERE slug='".$_GET['wpms_lang_list']."') mp ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = $wpdb->posts.ID ";
 
 
308
  }
309
  }
310
 
311
  // query post by lang with WPML plugin
312
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')){
313
- if(isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0'){
314
- $query .= " INNER JOIN (SELECT * FROM ".$wpdb->prefix."icl_translations WHERE element_type LIKE 'post_%' AND language_code='".$_GET['wpms_lang_list']."') t ON t.element_id = $wpdb->posts.ID ";
 
 
315
  }
316
  }
317
 
318
  $query .= " WHERE " . implode(' AND ', $where) . $orderStr;
319
-
320
-
321
  if (!empty($_REQUEST['metaseo_posts_per_page'])) {
322
  $_per_page = intval($_REQUEST['metaseo_posts_per_page']);
323
  } else {
@@ -348,7 +425,7 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
348
 
349
  if (!empty($paged) && !empty($per_page)) {
350
  $offset = ($paged - 1) * $per_page;
351
- $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
352
  }
353
 
354
  $this->set_pagination_args(array(
@@ -364,17 +441,18 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
364
 
365
  $this->items = $wpdb->get_results($query);
366
  }
367
-
368
  /**
369
- * Generate the table rows
370
- */
371
- function display_rows() {
 
372
  $records = $this->items;
373
  $i = 0;
374
  $alternate = "";
375
  $url = preg_replace('/(http|https):\/\/[w]*[.]?/', '', network_site_url('/'));
376
 
377
- list( $columns, $hidden ) = $this->get_column_info();
378
 
379
  if (!empty($records)) {
380
  foreach ($records as $rec) {
@@ -386,7 +464,6 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
386
  echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
387
 
388
  foreach ($columns as $column_name => $column_display_name) {
389
-
390
  $class = sprintf('class="%1$s column-%1$s"', $column_name);
391
  $style = "";
392
 
@@ -399,7 +476,8 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
399
  switch ($column_name) {
400
  case 'cb':
401
  echo '<th scope="row" class="check-column">';
402
- echo '<input id="cb-select-' . $rec->ID . '" class="metaseo_post" type="checkbox" name="post[]" value="' . $rec->ID . '">';
 
403
  echo '</th>';
404
 
405
  break;
@@ -413,9 +491,16 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
413
 
414
  case 'col_title':
415
  $post_title = stripslashes($rec->post_title);
416
- if ($post_title == '')
417
  $post_title = __('(no title)', 'wp-meta-seo');
418
- echo sprintf('<td %2$s><div class="action-wrapper"><strong id="post-title-' . $rec->ID . '">%1$s</strong>', $post_title, $attributes);
 
 
 
 
 
 
 
419
 
420
  $post_type_object = get_post_type_object($rec->post_type);
421
  $can_edit_post = current_user_can($post_type_object->cap->edit_post, $rec->ID);
@@ -423,15 +508,33 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
423
  $actions = array();
424
 
425
  if ($can_edit_post && 'trash' != $rec->post_status) {
426
- $actions['edit'] = '<a href="' . get_edit_post_link($rec->ID, true) . '" title="' . esc_attr(__('Edit this item','wp-meta-seo')) . '">' . __('Edit', 'wp-meta-seo') . '</a>';
 
 
427
  }
428
 
429
  if ($post_type_object->public) {
430
  if (in_array($rec->post_status, array('pending', 'draft', 'future'))) {
431
- if ($can_edit_post)
432
- $actions['view'] = '<a href="' . esc_url(add_query_arg('preview', 'true', get_permalink($rec->ID))) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;', 'wp-meta-seo'), $rec->post_title)) . '" rel="permalink">' . __('Preview', 'wp-meta-seo') . '</a>';
 
 
 
 
 
 
 
 
 
433
  } elseif ('trash' != $rec->post_status) {
434
- $actions['view'] = '<a target="_blank" href="' . get_permalink($rec->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'wp-meta-seo'), $rec->post_title)) . '" rel="permalink">' . __('View', 'wp-meta-seo') . '</a>';
 
 
 
 
 
 
 
435
  }
436
  }
437
 
@@ -443,45 +546,85 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
443
  case 'col_snippet':
444
  echo '<td><div class="snippet-wrapper">';
445
  echo '<div class="snippet">
446
- <a id="snippet_title' . $rec->ID . '" class="snippet_metatitle">' . (!empty($rec->metatitle) ? $rec->metatitle : $rec->post_title) . '</a>';
447
-
448
- echo '<span class="snippet_metalink" id="snippet_metalink_' . $rec->ID . '">' . $rec->link . '</span>';
449
-
450
- echo '<p id="snippet_desc' . $rec->ID . '" class="snippet_metades">' . $rec->metadesc . '</p></div>';
451
- echo '<img class="wpms_loader' . $rec->ID . ' wpms_content_loader" src=' . WPMETASEO_PLUGIN_URL . 'img/update_loading.gif>';
452
- echo '<span id="savedInfo' . $rec->ID . '" style="position: relative; display: block;float:right" class="saved-info metaseo-msg-success"><span style="position:absolute; float:right" class="spinner"></span></span>';
 
 
 
 
 
 
453
  echo '</div></td>';
454
  break;
455
  case 'col_page_slug':
456
  $permalink = get_permalink($rec->ID);
457
  $display_slug = str_replace(get_bloginfo('url'), '', $permalink);
458
- echo sprintf('<td %2$s><a href="%3$s" target="_blank">%1$s</a></td>', stripslashes($display_slug), $attributes, $permalink);
 
 
 
 
 
459
  break;
460
 
461
  case 'col_meta_title':
462
- $input = sprintf('</br><textarea class="large-text metaseo-metatitle" rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>', 'metaseo-metatitle-' . $rec->ID, 'metatitle[' . $rec->ID . ']', ( ($rec->metatitle ) ? $rec->metatitle : ''));
463
- $input .= sprintf('<div class="title-len" id="%1$s"></div>', 'metaseo-metatitle-len' . $rec->ID);
 
 
 
 
 
 
 
 
 
464
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
465
  break;
466
 
467
  case 'col_meta_keywords':
468
- $input = sprintf('</br><textarea class="large-text metaseo-metakeywords" rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>', 'metaseo-metakeywords-' . $rec->ID, 'metakeywords[' . $rec->ID . ']', ( ($rec->metakeywords ) ? $rec->metakeywords : ''));
469
- $input .= sprintf('<div class="keywords-len" id="%1$s"></div>', 'metaseo-metakeywords-len' . $rec->ID);
 
 
 
 
 
 
 
 
 
470
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
471
  break;
472
 
473
  case 'col_meta_desc':
474
- $input = sprintf('</br><textarea class="large-text metaseo-metadesc" rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>', 'metaseo-metadesc-' . $rec->ID, ' metades[' . $rec->ID . ']', (($rec->metadesc ) ? $rec->metadesc : ''));
475
- $input .= sprintf('<div class="desc-len" id="%1$s"></div>', 'metaseo-metadesc-len' . $rec->ID);
 
 
 
 
 
 
 
 
 
476
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
477
  break;
478
 
479
  case 'col_index':
480
  $page_index = get_post_meta($rec->ID, '_metaseo_metaindex', true);
481
  if (isset($page_index) && $page_index == 'noindex') {
482
- $input = '<input class="metaseo_post_index" name="index[]" type="checkbox" value="' . $rec->ID . '">';
 
483
  } else {
484
- $input = '<input checked class="metaseo_post_index" name="index[]" type="checkbox" value="' . $rec->ID . '">';
 
485
  }
486
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
487
  break;
@@ -489,9 +632,11 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
489
  case 'col_follow':
490
  $page_follow = get_post_meta($rec->ID, '_metaseo_metafollow', true);
491
  if (isset($page_follow) && $page_follow == 'nofollow') {
492
- $input = '<input class="metaseo_post_follow" name="follow[]" type="checkbox" value="' . $rec->ID . '">';
 
493
  } else {
494
- $input = '<input checked class="metaseo_post_follow" name="follow[]" type="checkbox" value="' . $rec->ID . '">';
 
495
  }
496
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
497
  break;
@@ -503,20 +648,11 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
503
  }
504
  }
505
 
506
- protected function get_bulk_actions() {
507
- $actions = array();
508
- $actions = array(
509
- 'update' => 'Update',
510
- );
511
-
512
- return $actions;
513
- }
514
-
515
- /*
516
  * Retrieves a modified URL query string.
517
  */
518
- function process_action() {
519
-
520
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
521
  $redirect = false;
522
  if (isset($_POST['do_filter'])) {
@@ -532,7 +668,11 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
532
  }
533
 
534
  if (!empty($_POST['metaseo_posts_per_page'])) {
535
- $current_url = add_query_arg(array("metaseo_posts_per_page" => intval($_POST['metaseo_posts_per_page'])), $current_url);
 
 
 
 
536
  $redirect = true;
537
  }
538
 
@@ -550,9 +690,10 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
550
 
551
  /**
552
  * Get all posts that is public and contain images with a string seperated by comma
 
553
  */
554
- public static function get_post_types() {
555
- global $wpdb;
556
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
557
  if (!empty($post_types)) {
558
  $post_types = "'" . implode("', '", $post_types) . "'";
@@ -560,12 +701,15 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
560
 
561
  return $post_types;
562
  }
563
-
564
- /* import meta from other plugin */
565
- public static function importMetaData() {
 
 
 
566
  global $wpdb;
567
  $meta_metaseo_keys = array('_metaseo_metatitle', '_metaseo_metadesc');
568
- $meta_other_keys = array(
569
  '_aio_' => array('_aioseop_title', '_aioseop_description'),
570
  '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
571
  );
@@ -574,7 +718,7 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
574
  $plugin = strtolower(trim($_POST['plugin']));
575
  $metakeys = '';
576
  foreach ($meta_metaseo_keys as $k => $mkey) {
577
- $metakeys .= ' OR `meta_key` = \'' . $mkey . '\' OR `meta_key` = \'' . $meta_other_keys[$plugin][$k] . '\'';
578
  }
579
 
580
  $metakeys = ltrim($metakeys, ' OR ');
@@ -585,6 +729,7 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
585
  $posts_metas = $wpdb->get_results($query);
586
 
587
  if (is_array($posts_metas) && count($posts_metas) > 0) {
 
588
  foreach ($posts_metas as $postmeta) {
589
  $_posts_metas[$postmeta->pID][$postmeta->meta_key] = $postmeta->meta_value;
590
  }
@@ -592,12 +737,12 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
592
  foreach ($_posts_metas as $pID => $pmeta) {
593
  foreach ($meta_metaseo_keys as $k => $mkey) {
594
  $mvalue = $pmeta[$mkey];
595
- $msynckey = $meta_other_keys[$plugin][$k];
596
  $msyncvalue = $pmeta[$msynckey];
597
 
598
- if (is_null($mvalue) || ( $mvalue == '' && $msynckey != '' )) {
599
  update_post_meta($pID, $mkey, $msyncvalue);
600
- } elseif (is_null($msyncvalue) || ( $msyncvalue == '' && $mvalue != '' )) {
601
  update_post_meta($pID, $msynckey, $mvalue);
602
  } elseif ($mvalue != '' && $msyncvalue != '') {
603
  update_post_meta($pID, $mkey, $msyncvalue);
@@ -621,11 +766,12 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
621
  echo json_encode($ret);
622
  wp_die();
623
  }
624
-
625
- /*
626
  * Dismiss import message
627
  */
628
- public static function dismissImport() {
 
629
  if (!empty($_POST['plugin']) and in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
630
  $plugin = strtolower(trim($_POST['plugin']));
631
 
@@ -641,13 +787,19 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
641
 
642
  /**
643
  * Update meta sync
 
 
 
 
 
644
  */
645
- public static function updateMetaSync($meta_id, $object_id, $meta_key, $meta_value) {
646
- if (!self::is_updateSync($meta_key)) {
 
647
  return null;
648
  }
649
 
650
- if (self::_updateMetaSync('update', $object_id, $meta_key, $meta_value)) {
651
  return true;
652
  }
653
 
@@ -656,25 +808,36 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
656
 
657
  /**
658
  * deletes all custom fields with the specified key
 
 
 
 
 
659
  */
660
- public static function deleteMetaSync($meta_ids, $object_id, $meta_key, $meta_value) {
661
-
662
- if (!self::is_updateSync($meta_key)) {
663
  return null;
664
  }
665
 
666
- if (self::_updateMetaSync('delete', $object_id, $meta_key, $meta_value)) {
667
  return true;
668
  }
669
 
670
  return null;
671
  }
672
-
673
  /**
674
  * Update meta sync
 
 
 
 
 
675
  */
676
- private static function _updateMetaSync($type = '', $object_id, $meta_key, $meta_value) {
677
- if (!( $sync = get_option('plugin_to_sync_with') ) or ! in_array($sync, array('_aio_', '_yoast_'))) {
 
678
  return false;
679
  }
680
 
@@ -714,7 +877,13 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
714
  return false;
715
  }
716
 
717
- public static function is_updateSync($meta_key) {
 
 
 
 
 
 
718
  $mkey_prefix = array('_metaseo_', '_yoast_', '_aio');
719
  foreach ($mkey_prefix as $prefix) {
720
  if (strpos($meta_key, $prefix) === 0) {
@@ -724,5 +893,4 @@ class MetaSeo_Content_List_Table extends WP_List_Table {
724
 
725
  return false;
726
  }
727
-
728
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
 
 
4
  if (!class_exists('WP_List_Table')) {
5
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6
  }
7
 
8
+ /**
9
+ * Class MetaSeoContentListTable
10
+ * Base class for displaying a list of posts/pages in an ajaxified HTML table.
11
+ */
12
+ class MetaSeoContentListTable extends WP_List_Table
13
+ {
14
+ /**
15
+ * @var
16
+ */
17
  public $post_types;
18
+
19
+ /**
20
+ * MetaSeoContentListTable constructor.
21
+ */
22
+ public function __construct()
23
+ {
24
  parent::__construct(array(
25
  'singular' => 'metaseo_content',
26
  'plural' => 'metaseo_contents',
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>
60
 
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
 
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;
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
 
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">',
242
  }
243
 
244
  /**
245
+ * Get a list of sortable columns. The format is:
246
+ * 'internal-name' => 'orderby'
247
+ * or
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") {
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 . "'";
318
 
319
  $keyword = !empty($_GET["s"]) ? $_GET["s"] : '';
320
  if (isset($keyword) && $keyword != '') {
321
+ $where[] = '(post_title LIKE "%' . $keyword . '%"
322
+ OR mt.meta_value LIKE "%' . $keyword . '%" OR md.meta_value LIKE "%' . $keyword . '%")';
323
  }
324
 
325
  //Order By block
327
  $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
328
 
329
  $sortable = $this->get_sortable_columns();
330
+ $orderby_array = array($orderby, true);
331
  if (in_array($orderby_array, $sortable)) {
332
  $orderStr = $orderby;
333
  } else {
345
  $orderStr = str_replace("'", "", $orderStr);
346
  }
347
 
348
+ if (isset($_GET['wpms_duplicate_meta']) && $_GET['wpms_duplicate_meta'] != 'none') {
349
+ if ($_GET['wpms_duplicate_meta'] == 'duplicate_title') {
350
  $where[] = "mt.meta_key = '_metaseo_metatitle'";
351
  $where[] = "mt.meta_value = mt.meta_value AND mt.meta_value !=''";
352
+ } elseif ($_GET['wpms_duplicate_meta'] == 'duplicate_desc') {
353
  $where[] = "md.meta_key = '_metaseo_metadesc'";
354
  $where[] = "md.meta_value = md.meta_value AND md.meta_value !=''";
355
  }
356
  }
357
+
358
  $query = "SELECT COUNT(ID) "
359
+ . " FROM $wpdb->posts "
360
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
361
+ WHERE meta_key = '_metaseo_metatitle') mt ON mt.post_id = $wpdb->posts.ID "
362
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
363
+ WHERE meta_key = '_metaseo_metadesc') md ON md.post_id = $wpdb->posts.ID "
364
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta
365
+ WHERE meta_key = '_metaseo_metakeywords') mk ON mk.post_id = $wpdb->posts.ID "
366
+ . " WHERE " . implode(' AND ', $where) . $orderStr;
367
 
368
  $total_items = $wpdb->get_var($query);
369
+
370
+ $query = "SELECT DISTINCT ID, post_title, post_name, post_type, post_status,
371
+ mt.meta_value AS metatitle, md.meta_value AS metadesc ,mk.meta_value AS metakeywords "
372
+ . " FROM $wpdb->posts "
373
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metatitle')
374
+ mt ON mt.post_id = $wpdb->posts.ID "
375
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metadesc')
376
+ md ON md.post_id = $wpdb->posts.ID "
377
+ . " LEFT JOIN (SELECT * FROM $wpdb->postmeta WHERE meta_key = '_metaseo_metakeywords')
378
+ mk ON mk.post_id = $wpdb->posts.ID ";
379
  // query post by lang with polylang plugin
380
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) {
381
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
382
+ $query .= " INNER JOIN (SELECT * FROM $wpdb->term_relationships as ml
383
+ INNER JOIN (SELECT * FROM $wpdb->terms WHERE slug='" . $_GET['wpms_lang_list'] . "')
384
+ mp ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = $wpdb->posts.ID ";
385
  }
386
  }
387
 
388
  // query post by lang with WPML plugin
389
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
390
+ if (isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0') {
391
+ $query .= " INNER JOIN (SELECT * FROM " . $wpdb->prefix . "icl_translations
392
+ WHERE element_type LIKE 'post_%' AND language_code='" . $_GET['wpms_lang_list'] . "') t
393
+ ON t.element_id = $wpdb->posts.ID ";
394
  }
395
  }
396
 
397
  $query .= " WHERE " . implode(' AND ', $where) . $orderStr;
 
 
398
  if (!empty($_REQUEST['metaseo_posts_per_page'])) {
399
  $_per_page = intval($_REQUEST['metaseo_posts_per_page']);
400
  } else {
425
 
426
  if (!empty($paged) && !empty($per_page)) {
427
  $offset = ($paged - 1) * $per_page;
428
+ $query .= ' LIMIT ' . (int)$offset . ',' . (int)$per_page;
429
  }
430
 
431
  $this->set_pagination_args(array(
441
 
442
  $this->items = $wpdb->get_results($query);
443
  }
444
+
445
  /**
446
+ * Generate the table rows
447
+ */
448
+ public function display_rows()
449
+ {
450
  $records = $this->items;
451
  $i = 0;
452
  $alternate = "";
453
  $url = preg_replace('/(http|https):\/\/[w]*[.]?/', '', network_site_url('/'));
454
 
455
+ list($columns, $hidden) = $this->get_column_info();
456
 
457
  if (!empty($records)) {
458
  foreach ($records as $rec) {
464
  echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
465
 
466
  foreach ($columns as $column_name => $column_display_name) {
 
467
  $class = sprintf('class="%1$s column-%1$s"', $column_name);
468
  $style = "";
469
 
476
  switch ($column_name) {
477
  case 'cb':
478
  echo '<th scope="row" class="check-column">';
479
+ echo '<input id="cb-select-' . $rec->ID . '"
480
+ class="metaseo_post" type="checkbox" name="post[]" value="' . $rec->ID . '">';
481
  echo '</th>';
482
 
483
  break;
491
 
492
  case 'col_title':
493
  $post_title = stripslashes($rec->post_title);
494
+ if ($post_title == '') {
495
  $post_title = __('(no title)', 'wp-meta-seo');
496
+ }
497
+
498
+ echo sprintf(
499
+ '<td %2$s><div class="action-wrapper">
500
+ <strong id="post-title-' . $rec->ID . '">%1$s</strong>',
501
+ $post_title,
502
+ $attributes
503
+ );
504
 
505
  $post_type_object = get_post_type_object($rec->post_type);
506
  $can_edit_post = current_user_can($post_type_object->cap->edit_post, $rec->ID);
508
  $actions = array();
509
 
510
  if ($can_edit_post && 'trash' != $rec->post_status) {
511
+ $actions['edit'] = '<a href="' . get_edit_post_link($rec->ID, true) . '"
512
+ title="' . esc_attr(__('Edit this item', 'wp-meta-seo')) . '"
513
+ >' . __('Edit', 'wp-meta-seo') . '</a>';
514
  }
515
 
516
  if ($post_type_object->public) {
517
  if (in_array($rec->post_status, array('pending', 'draft', 'future'))) {
518
+ if ($can_edit_post) {
519
+ $hr = esc_url(add_query_arg('preview', 'true', get_permalink($rec->ID)));
520
+ $t = esc_attr(
521
+ sprintf(
522
+ __('Preview &#8220;%s&#8221;', 'wp-meta-seo'),
523
+ $rec->post_title
524
+ )
525
+ );
526
+ $actions['view'] = '<a href="' . $hr . '" title="' . $t . '" rel="permalink"
527
+ >' . __('Preview', 'wp-meta-seo') . '</a>';
528
+ }
529
  } elseif ('trash' != $rec->post_status) {
530
+ $t = esc_attr(
531
+ sprintf(
532
+ __('View &#8220;%s&#8221;', 'wp-meta-seo'),
533
+ $rec->post_title
534
+ )
535
+ );
536
+ $actions['view'] = '<a target="_blank" href="' . get_permalink($rec->ID) . '"
537
+ title="' . $t . '" rel="permalink">' . __('View', 'wp-meta-seo') . '</a>';
538
  }
539
  }
540
 
546
  case 'col_snippet':
547
  echo '<td><div class="snippet-wrapper">';
548
  echo '<div class="snippet">
549
+ <a id="snippet_title' . $rec->ID . '" class="snippet_metatitle">
550
+ ' . (!empty($rec->metatitle) ? $rec->metatitle : $rec->post_title) . '</a>';
551
+
552
+ echo '<span class="snippet_metalink" id="snippet_metalink_' . $rec->ID . '">
553
+ ' . $rec->link . '</span>';
554
+
555
+ echo '<p id="snippet_desc' . $rec->ID . '" class="snippet_metades">
556
+ ' . $rec->metadesc . '</p></div>';
557
+ echo '<img class="wpms_loader' . $rec->ID . ' wpms_content_loader"
558
+ src=' . WPMETASEO_PLUGIN_URL . 'img/update_loading.gif>';
559
+ echo '<span id="savedInfo' . $rec->ID . '"
560
+ style="position: relative; display: block;float:right"
561
+ class="saved-info metaseo-msg-success"><span style="position:absolute; float:right" class="spinner"></span></span>';
562
  echo '</div></td>';
563
  break;
564
  case 'col_page_slug':
565
  $permalink = get_permalink($rec->ID);
566
  $display_slug = str_replace(get_bloginfo('url'), '', $permalink);
567
+ echo sprintf(
568
+ '<td %2$s><a href="%3$s" target="_blank">%1$s</a></td>',
569
+ stripslashes($display_slug),
570
+ $attributes,
571
+ $permalink
572
+ );
573
  break;
574
 
575
  case 'col_meta_title':
576
+ $input = sprintf(
577
+ '</br><textarea class="large-text metaseo-metatitle"
578
+ rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
579
+ 'metaseo-metatitle-' . $rec->ID,
580
+ 'metatitle[' . $rec->ID . ']',
581
+ ($rec->metatitle) ? $rec->metatitle : ''
582
+ );
583
+ $input .= sprintf(
584
+ '<div class="title-len" id="%1$s"></div>',
585
+ 'metaseo-metatitle-len' . $rec->ID
586
+ );
587
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
588
  break;
589
 
590
  case 'col_meta_keywords':
591
+ $input = sprintf(
592
+ '</br><textarea class="large-text metaseo-metakeywords"
593
+ rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
594
+ 'metaseo-metakeywords-' . $rec->ID,
595
+ 'metakeywords[' . $rec->ID . ']',
596
+ ($rec->metakeywords) ? $rec->metakeywords : ''
597
+ );
598
+ $input .= sprintf(
599
+ '<div class="keywords-len" id="%1$s"></div>',
600
+ 'metaseo-metakeywords-len' . $rec->ID
601
+ );
602
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
603
  break;
604
 
605
  case 'col_meta_desc':
606
+ $input = sprintf(
607
+ '</br><textarea class="large-text metaseo-metadesc"
608
+ rows="3" id="%1$s" name="%2$s" autocomplete="off">%3$s</textarea>',
609
+ 'metaseo-metadesc-' . $rec->ID,
610
+ ' metades[' . $rec->ID . ']',
611
+ ($rec->metadesc) ? $rec->metadesc : ''
612
+ );
613
+ $input .= sprintf(
614
+ '<div class="desc-len" id="%1$s"></div>',
615
+ 'metaseo-metadesc-len' . $rec->ID
616
+ );
617
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
618
  break;
619
 
620
  case 'col_index':
621
  $page_index = get_post_meta($rec->ID, '_metaseo_metaindex', true);
622
  if (isset($page_index) && $page_index == 'noindex') {
623
+ $input = '<input class="metaseo_post_index"
624
+ name="index[]" type="checkbox" value="' . $rec->ID . '">';
625
  } else {
626
+ $input = '<input checked class="metaseo_post_index"
627
+ name="index[]" type="checkbox" value="' . $rec->ID . '">';
628
  }
629
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
630
  break;
632
  case 'col_follow':
633
  $page_follow = get_post_meta($rec->ID, '_metaseo_metafollow', true);
634
  if (isset($page_follow) && $page_follow == 'nofollow') {
635
+ $input = '<input class="metaseo_post_follow"
636
+ name="follow[]" type="checkbox" value="' . $rec->ID . '">';
637
  } else {
638
+ $input = '<input checked class="metaseo_post_follow"
639
+ name="follow[]" type="checkbox" value="' . $rec->ID . '">';
640
  }
641
  echo sprintf('<td %2$s>%1$s</td>', $input, $attributes);
642
  break;
648
  }
649
  }
650
 
651
+ /**
 
 
 
 
 
 
 
 
 
652
  * Retrieves a modified URL query string.
653
  */
654
+ public function processAction()
655
+ {
656
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
657
  $redirect = false;
658
  if (isset($_POST['do_filter'])) {
668
  }
669
 
670
  if (!empty($_POST['metaseo_posts_per_page'])) {
671
+ $current_url = add_query_arg(
672
+ array(
673
+ "metaseo_posts_per_page" => intval($_POST['metaseo_posts_per_page'])),
674
+ $current_url
675
+ );
676
  $redirect = true;
677
  }
678
 
690
 
691
  /**
692
  * Get all posts that is public and contain images with a string seperated by comma
693
+ * @return array|string
694
  */
695
+ public static function getPostTypes()
696
+ {
697
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
698
  if (!empty($post_types)) {
699
  $post_types = "'" . implode("', '", $post_types) . "'";
701
 
702
  return $post_types;
703
  }
704
+
705
+ /**
706
+ * import meta from other plugin
707
+ */
708
+ public static function importMetaData()
709
+ {
710
  global $wpdb;
711
  $meta_metaseo_keys = array('_metaseo_metatitle', '_metaseo_metadesc');
712
+ $key = array(
713
  '_aio_' => array('_aioseop_title', '_aioseop_description'),
714
  '_yoast_' => array('_yoast_wpseo_title', '_yoast_wpseo_metadesc')
715
  );
718
  $plugin = strtolower(trim($_POST['plugin']));
719
  $metakeys = '';
720
  foreach ($meta_metaseo_keys as $k => $mkey) {
721
+ $metakeys .= ' OR `meta_key` = \'' . $mkey . '\' OR `meta_key` = \'' . $key[$plugin][$k] . '\'';
722
  }
723
 
724
  $metakeys = ltrim($metakeys, ' OR ');
729
  $posts_metas = $wpdb->get_results($query);
730
 
731
  if (is_array($posts_metas) && count($posts_metas) > 0) {
732
+ $_posts_metas = array();
733
  foreach ($posts_metas as $postmeta) {
734
  $_posts_metas[$postmeta->pID][$postmeta->meta_key] = $postmeta->meta_value;
735
  }
737
  foreach ($_posts_metas as $pID => $pmeta) {
738
  foreach ($meta_metaseo_keys as $k => $mkey) {
739
  $mvalue = $pmeta[$mkey];
740
+ $msynckey = $key[$plugin][$k];
741
  $msyncvalue = $pmeta[$msynckey];
742
 
743
+ if (is_null($mvalue) || ($mvalue == '' && $msynckey != '')) {
744
  update_post_meta($pID, $mkey, $msyncvalue);
745
+ } elseif (is_null($msyncvalue) || ($msyncvalue == '' && $mvalue != '')) {
746
  update_post_meta($pID, $msynckey, $mvalue);
747
  } elseif ($mvalue != '' && $msyncvalue != '') {
748
  update_post_meta($pID, $mkey, $msyncvalue);
766
  echo json_encode($ret);
767
  wp_die();
768
  }
769
+
770
+ /**
771
  * Dismiss import message
772
  */
773
+ public static function dismissImport()
774
+ {
775
  if (!empty($_POST['plugin']) and in_array(strtolower(trim($_POST['plugin'])), array('_aio_', '_yoast_'))) {
776
  $plugin = strtolower(trim($_POST['plugin']));
777
 
787
 
788
  /**
789
  * Update meta sync
790
+ * @param int $meta_id meta id
791
+ * @param int $object_id object id
792
+ * @param string $meta_key meta key
793
+ * @param string $meta_value meta value
794
+ * @return bool|null
795
  */
796
+ public static function updateMetaSync($meta_id, $object_id, $meta_key, $meta_value)
797
+ {
798
+ if (!self::isUpdateSync($meta_key)) {
799
  return null;
800
  }
801
 
802
+ if (self::doUpdateMetaSync($object_id, $meta_key, $meta_value, 'update')) {
803
  return true;
804
  }
805
 
808
 
809
  /**
810
  * deletes all custom fields with the specified key
811
+ * @param int $meta_ids meta id
812
+ * @param int $object_id object id
813
+ * @param string $meta_key meta key
814
+ * @param string $meta_value meta value
815
+ * @return bool|null
816
  */
817
+ public static function deleteMetaSync($meta_ids, $object_id, $meta_key, $meta_value)
818
+ {
819
+ if (!self::isUpdateSync($meta_key)) {
820
  return null;
821
  }
822
 
823
+ if (self::doUpdateMetaSync($object_id, $meta_key, $meta_value, 'delete')) {
824
  return true;
825
  }
826
 
827
  return null;
828
  }
829
+
830
  /**
831
  * Update meta sync
832
+ * @param string $type
833
+ * @param int $object_id object id
834
+ * @param string $meta_key meta key
835
+ * @param string $meta_value meta value
836
+ * @return bool
837
  */
838
+ private static function doUpdateMetaSync($object_id, $meta_key, $meta_value, $type = '')
839
+ {
840
+ if (!($sync = get_option('plugin_to_sync_with')) or !in_array($sync, array('_aio_', '_yoast_'))) {
841
  return false;
842
  }
843
 
877
  return false;
878
  }
879
 
880
+ /**
881
+ * Check is update sync
882
+ * @param $meta_key
883
+ * @return bool
884
+ */
885
+ public static function isUpdateSync($meta_key)
886
+ {
887
  $mkey_prefix = array('_metaseo_', '_yoast_', '_aio');
888
  foreach ($mkey_prefix as $prefix) {
889
  if (strpos($meta_key, $prefix) === 0) {
893
 
894
  return false;
895
  }
 
896
  }
inc/class.metaseo-dashboard.php CHANGED
@@ -1,44 +1,44 @@
1
  <?php
2
- /*
 
 
 
 
3
  * This class implements the statistical criteria of Meta SEO
4
- *
5
  */
6
-
7
- class MetaSeo_Dashboard {
8
-
 
 
 
9
  public static $meta_title_length = 69;
 
 
 
 
10
  public static $meta_desc_length = 156;
11
- public static $metatitle_filled = 0;
12
- public static $metadesc_filled = 0;
13
- public static $imageresizing_filled = 0;
14
- public static $imagemeta_filled = 0;
15
- public static $image_in_post = 0;
16
- public static $mpostname_inurl = 0;
17
- public static $mcategory_inurl = 0;
18
- public static $mpermalink = 50;
19
- public static $mlink_complete = 0;
20
- public static $mcount_link = 0;
21
-
22
- /*
23
- * Get image optimize
24
  */
25
- public static function moptimizationChecking() {
 
26
  global $wpdb;
27
  $imgs = 0;
28
- $imgs_metas = array('alt' => 0, 'title' => 0);
29
  $imgs_are_good = 0;
30
  $imgs_metas_are_good = array();
31
  $meta_keys = array('alt', 'title');
32
  $response = array(
33
- 'imgs_statis' => array(0, 0 ,100),
34
- 'imgs_metas_statis' => array(0, 0 ,100),
35
  );
36
  foreach ($meta_keys as $meta_key) {
37
  $imgs_metas_are_good[$meta_key] = 0;
38
  $imgs_metas_are_not_good[$meta_key] = 0;
39
  }
40
 
41
- $post_types = MetaSeo_Content_List_Table::get_post_types();
42
  $query = "SELECT `ID`,`post_content`
43
  FROM $wpdb->posts
44
  WHERE `post_type` IN ($post_types)
@@ -54,9 +54,11 @@ class MetaSeo_Dashboard {
54
 
55
  foreach ($posts as $post) {
56
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
57
- if (empty($meta_analysis))
58
  $meta_analysis = array();
59
- $dom = $doc->loadHTML($post->post_content);
 
 
60
  $tags = $doc->getElementsByTagName('img');
61
  foreach ($tags as $tag) {
62
  $img_src = $tag->getAttribute('src');
@@ -84,13 +86,15 @@ class MetaSeo_Dashboard {
84
  $width = $height * ($ratio_origin);
85
  }
86
 
87
- if (($real_width <= $width && $real_height <= $height) || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
 
88
  $imgs_are_good++;
89
  }
90
- foreach ($meta_keys as $meta_key) {
91
 
92
- if (trim($tag->getAttribute($meta_key)) || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
93
- $imgs_metas_are_good[$meta_key] ++;
 
 
94
  }
95
  }
96
  }
@@ -122,11 +126,13 @@ class MetaSeo_Dashboard {
122
 
123
  return $response;
124
  }
125
-
126
- /*
127
  * Display rank of site
 
128
  */
129
- public function displayRank($url) {
 
130
  $rank = $this->getRank($url);
131
  if ($rank !== '') {
132
  echo $rank;
@@ -134,11 +140,14 @@ class MetaSeo_Dashboard {
134
  echo __('We can\'t get rank of this site from Alexa.com!', 'wp-meta-seo');
135
  }
136
  }
137
-
138
- /*
139
  * Get rank of site
 
 
140
  */
141
- public function getRank($url) {
 
142
  if (!function_exists('curl_version')) {
143
  if (!$content = @file_get_contents($url)) {
144
  return '';
@@ -147,7 +156,7 @@ class MetaSeo_Dashboard {
147
  if (!is_array($url)) {
148
  $url = array($url);
149
  }
150
- $contents = $this->get_contents($url);
151
  $content = $contents[0];
152
  }
153
 
@@ -175,11 +184,14 @@ class MetaSeo_Dashboard {
175
  $html = str_replace('"/topsites/countries', '"http://www.alexa.com/topsites/countries', $html);
176
  return $html;
177
  }
178
-
179
- /*
180
  * Get content a file
 
 
181
  */
182
- public function get_contents($urls) {
 
183
  $mh = curl_multi_init();
184
  $curl_array = array();
185
  $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36';
@@ -187,13 +199,13 @@ class MetaSeo_Dashboard {
187
  $curl_array[$i] = curl_init($url);
188
  curl_setopt($curl_array[$i], CURLOPT_URL, $url);
189
  curl_setopt($curl_array[$i], CURLOPT_USERAGENT, $useragent); // set user agent
190
- curl_setopt($curl_array[$i], CURLOPT_RETURNTRANSFER, TRUE);
191
  curl_setopt($curl_array[$i], CURLOPT_CONNECTTIMEOUT, 5);
192
  curl_setopt($curl_array[$i], CURLOPT_ENCODING, "UTF-8");
193
  curl_multi_add_handle($mh, $curl_array[$i]);
194
  }
195
 
196
- $running = NULL;
197
  do {
198
  usleep(10000);
199
  curl_multi_exec($mh, $running);
@@ -214,10 +226,13 @@ class MetaSeo_Dashboard {
214
 
215
  /**
216
  * update option dashboard
 
 
217
  */
218
- public static function update_dashboard($name){
 
219
  $options_dashboard = get_option('options_dashboard');
220
- MetaSeo_Dashboard::_wpms_update_option_dash($options_dashboard,$name);
221
  $options_dashboard = get_option('options_dashboard');
222
  $results = $options_dashboard[$name];
223
  return $results;
@@ -226,49 +241,58 @@ class MetaSeo_Dashboard {
226
  /**
227
  * get Count posts
228
  */
229
- public static function getCountPost(){
 
230
  global $wpdb;
231
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
232
  $post_types = "'" . implode("', '", $post_types) . "'";
233
  $states = get_post_stati(array('show_in_admin_all_list' => true));
234
  $states['trash'] = 'trash';
235
  $all_states = "'" . implode("', '", $states) . "'";
236
- $total_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)");
 
 
237
  return $total_posts;
238
  }
239
 
240
- /*
241
  * get params meta title filled for dashboard
 
242
  */
243
- public static function wpms_metatitle(){
244
- $total_posts = MetaSeo_Dashboard::getCountPost();
 
245
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
246
- if (!empty($post_types['attachment']))
247
  unset($post_types['attachment']);
 
 
248
  $results = array(0, array(0, (int)$total_posts));
249
  $args = array(
250
  'posts_per_page' => -1,
251
- 'post_type' => $post_types,
252
- 'meta_key' => '_metaseo_metatitle',
253
  'meta_query' => array(
254
  array(
255
- 'key' => '_metaseo_metatitle',
256
- 'value' => '',
257
  'compare' => '!=',
258
  ),
259
  ),
260
  );
261
- $query = new WP_Query( $args );
262
  $posts = $query->get_posts();
263
  $metatitle_filled = 0;
264
  if (!empty($posts)) {
265
  foreach ($posts as $post) {
266
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
267
- if (empty($meta_analysis))
268
  $meta_analysis = array();
 
269
 
270
  $meta_title = get_post_meta($post->ID, '_metaseo_metatitle', true);
271
- if (($meta_title != '' && mb_strlen($meta_title,'UTF-8') <= self::$meta_title_length ) || (!empty($meta_analysis) && !empty($meta_analysis['metatitle']))) {
 
272
  $metatitle_filled++;
273
  }
274
  }
@@ -279,12 +303,13 @@ class MetaSeo_Dashboard {
279
  return $results;
280
  }
281
 
282
- /*
283
  * get html meta title filled for dashboard
284
  */
285
- public static function wpms_dash_metatitle(){
286
- $results = MetaSeo_Dashboard::update_dashboard('metatitle');
287
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
 
288
  wp_send_json($results);
289
  }
290
  ob_start();
@@ -294,38 +319,44 @@ class MetaSeo_Dashboard {
294
  wp_send_json($html);
295
  }
296
 
297
- /*
298
  * get params meta description filled for dashboard
 
299
  */
300
- public static function wpms_metadesc(){
301
- $total_posts = MetaSeo_Dashboard::getCountPost();
 
302
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
303
- if (!empty($post_types['attachment']))
304
  unset($post_types['attachment']);
 
 
305
  $results = array(0, array(0, $total_posts));
306
  $args = array(
307
  'posts_per_page' => -1,
308
- 'post_type' => $post_types,
309
- 'meta_key' => '_metaseo_metadesc',
310
  'meta_query' => array(
311
  array(
312
- 'key' => '_metaseo_metadesc',
313
- 'value' => '',
314
  'compare' => '!=',
315
  ),
316
  ),
317
  );
318
- $query = new WP_Query( $args );
319
  $posts = $query->get_posts();
320
  $metadesc_filled = 0;
321
  if (!empty($posts)) {
322
  foreach ($posts as $post) {
323
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
324
- if (empty($meta_analysis))
325
  $meta_analysis = array();
 
326
 
327
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
328
- if (($meta_desc != '' && mb_strlen($meta_desc,'UTF-8') <= self::$meta_desc_length ) || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
 
329
  $metadesc_filled++;
330
  }
331
  }
@@ -336,12 +367,13 @@ class MetaSeo_Dashboard {
336
  return $results;
337
  }
338
 
339
- /*
340
  * Return html description filled for dashboard
341
  */
342
- public static function wpms_dash_metadesc(){
343
- $results = MetaSeo_Dashboard::update_dashboard('metadesc');
344
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
 
345
  wp_send_json($results);
346
  }
347
  ob_start();
@@ -351,14 +383,17 @@ class MetaSeo_Dashboard {
351
  wp_send_json($html);
352
  }
353
 
354
- /*
355
  * Return link_meta for dashboard
 
356
  */
357
- public static function wpms_linkmeta(){
 
358
  global $wpdb;
359
- $mcount_link = 0;
360
- $mlink_complete = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."wpms_links WHERE meta_title !=''");
361
- $mcount_link = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."wpms_links WHERE type !='404_automaticaly'");
 
362
 
363
  if ($mcount_link == 0) {
364
  $link_percent = 100;
@@ -370,13 +405,13 @@ class MetaSeo_Dashboard {
370
  return $results;
371
  }
372
 
373
-
374
- /*
375
  * Return html link_meta for dashboard
376
  */
377
- public static function wpms_dash_linkmeta(){
378
- $results = MetaSeo_Dashboard::wpms_linkmeta();
379
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
 
380
  wp_send_json($results);
381
  }
382
  ob_start();
@@ -386,28 +421,33 @@ class MetaSeo_Dashboard {
386
  wp_send_json($html);
387
  }
388
 
389
- /*
390
  * Return permalink for dashboard
 
391
  */
392
- public static function wpms_permalink(){
 
393
  $permalink = 50;
394
  $permalink_structure = get_option('permalink_structure');
395
  if (strpos($permalink_structure, 'postname') == false && strpos($permalink_structure, 'category') == false) {
396
  $permalink = 0;
397
- } else if (strpos($permalink_structure, 'postname') == true && strpos($permalink_structure, 'category') == true) {
 
398
  $permalink = 100;
399
- } else if (strpos($permalink_structure, 'postname') == true || strpos($permalink_structure, 'category') == true) {
 
400
  $permalink = 50;
401
  }
402
  return $permalink;
403
  }
404
 
405
- /*
406
  * Return html permalink for dashboard
407
  */
408
- public static function wpms_dash_permalink(){
409
- $permalink = MetaSeo_Dashboard::wpms_permalink();
410
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
 
411
  wp_send_json($permalink);
412
  }
413
  ob_start();
@@ -417,11 +457,13 @@ class MetaSeo_Dashboard {
417
  wp_send_json($html);
418
  }
419
 
420
- /*
421
  * Return count new content updated for dashboard
 
422
  */
423
- public static function wpms_newcontent(){
424
- $total_posts = MetaSeo_Dashboard::getCountPost();
 
425
  $newcontent_args = array(
426
  'date_query' => array(
427
  array(
@@ -444,12 +486,13 @@ class MetaSeo_Dashboard {
444
  return $results;
445
  }
446
 
447
- /*
448
  * Return html new content updated for dashboard
449
  */
450
- public static function wpms_dash_newcontent(){
451
- $results = MetaSeo_Dashboard::update_dashboard('newcontent');
452
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
 
453
  wp_send_json($results);
454
  }
455
  ob_start();
@@ -458,16 +501,25 @@ class MetaSeo_Dashboard {
458
  ob_end_clean();
459
  wp_send_json($html);
460
  }
461
-
462
- /*
463
  * Return count link 404 , count link 404 is redirected , percent
 
464
  */
465
- public static function get_404_link() {
 
466
  global $wpdb;
467
- $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE (broken_internal=%d OR broken_indexed=%d) ", array(1, 1));
 
 
 
468
  $count_404 = $wpdb->get_var($sql);
469
 
470
- $sql = $wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE link_url_redirect != '' AND (broken_internal=%d OR broken_indexed=%d) ", array(1, 1));
 
 
 
 
471
  $count_404_redirected = $wpdb->get_var($sql);
472
  if ($count_404 != 0) {
473
  $percent = ceil($count_404_redirected / $count_404 * 100);
@@ -476,16 +528,18 @@ class MetaSeo_Dashboard {
476
  }
477
  return array('count_404' => $count_404, 'count_404_redirected' => $count_404_redirected, 'percent' => $percent);
478
  }
479
-
480
- /*
481
  * Return count image is optimized
 
482
  */
483
- public function wpms_getImages_optimizer() {
 
484
  global $wpdb;
485
  $sql = $wpdb->prepare("SELECT * FROM INFORMATION_SCHEMA.TABLES
486
- WHERE table_name = %s AND TABLE_SCHEMA = %s",array($wpdb->prefix . 'wpio_images',$wpdb->dbname));
487
  $row = $wpdb->get_results($sql);
488
- if(!empty($row)){
489
  $query = 'SELECT distinct file FROM ' . $wpdb->prefix . 'wpio_images';
490
  $files = $wpdb->get_results($query);
491
  $image_optimize = 0;
@@ -495,26 +549,19 @@ class MetaSeo_Dashboard {
495
  }
496
  }
497
  return $image_optimize;
498
- }else{
499
  return 0;
500
  }
501
  }
502
-
503
- /*
504
  * Get count image
 
505
  */
506
- public function wpms_getImages_count() {
507
- $wpio_settings = get_option('_wpio_settings');
508
- $include_folders = $wpio_settings['wpio_api_include'];
509
- $allowedPath = explode(',', $include_folders);
510
- $images = array();
511
- $image_optimize = $this->wpms_getImages_optimizer();
512
-
513
  $allowed_ext = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf');
514
- $min_size = (int) $wpio_settings['wpio_api_minfilesize'] * 1024;
515
- $max_size = (int) $wpio_settings['wpio_api_maxfilesize'] * 1024;
516
- if ($max_size == 0)
517
- $max_size = 5 * 1024 * 1024;
518
  $count_image = 0;
519
  $scan_dir = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH);
520
  foreach (new RecursiveIteratorIterator(new IgnorantRecursiveDirectoryIterator($scan_dir)) as $filename) {
@@ -535,20 +582,24 @@ class MetaSeo_Dashboard {
535
 
536
  /**
537
  * get meta data dashboard
 
 
538
  */
539
- public static function getMetaDataDashBoard($name){
540
- switch ($name){
 
 
541
  case 'metatitle':
542
- $results = MetaSeo_Dashboard::wpms_metatitle();
543
  break;
544
  case 'metadesc':
545
- $results = MetaSeo_Dashboard::wpms_metadesc();
546
  break;
547
  case 'newcontent':
548
- $results = MetaSeo_Dashboard::wpms_newcontent();
549
  break;
550
  case 'image_meta':
551
- $results = MetaSeo_Dashboard::moptimizationChecking();
552
  break;
553
  }
554
 
@@ -557,84 +608,84 @@ class MetaSeo_Dashboard {
557
 
558
  /**
559
  * update time dashboard update
 
560
  */
561
- public static function _wpms_dash_last_update($name){
562
- if($name == 'metadesc'){
563
- update_option('_wpms_dash_last_update',time());
 
564
  }
565
  }
566
 
567
  /**
568
  * update option dashboard
 
 
569
  */
570
- public static function _wpms_update_option_dash($options_dashboard,$name){
571
- if(!empty($options_dashboard) && is_array($options_dashboard)){
 
572
  if (empty($options_dashboard[$name])) {
573
- $results = MetaSeo_Dashboard::getMetaDataDashBoard($name);
574
  $options_dashboard[$name] = $results;
575
- update_option('options_dashboard',$options_dashboard);
576
- MetaSeo_Dashboard::_wpms_dash_last_update($name);
577
- }else{
578
  $option_last_update_post = get_option('wpms_last_update_post');
579
  $option_last_dash_update = get_option('_wpms_dash_last_update');
580
- if(!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update){
581
- $results = MetaSeo_Dashboard::getMetaDataDashBoard($name);
582
  $options_dashboard[$name] = $results;
583
- update_option('options_dashboard',$options_dashboard);
584
- MetaSeo_Dashboard::_wpms_dash_last_update($name);
585
  }
586
  }
587
- }else{
588
- $results = MetaSeo_Dashboard::getMetaDataDashBoard($name);
589
  $options_dashboard[$name] = $results;
590
- update_option('options_dashboard',$options_dashboard);
591
- MetaSeo_Dashboard::_wpms_dash_last_update($name);
592
  }
593
  }
594
 
595
-
596
-
597
- public static function wpms_dash_imgsmeta() {
 
 
598
  global $wpdb;
599
  $imgs = 0;
600
- $imgs_metas = array('alt' => 0, 'title' => 0);
601
  $imgs_are_good = 0;
602
  $imgs_metas_are_good = array();
603
  $meta_keys = array('alt', 'title');
 
604
  $response = array(
605
- 'imgs_statis' => array(0, 0 ,100),
606
- 'imgs_metas_statis' => array(0, 0 ,100),
607
  );
608
 
609
  $options_dashboard = get_option('options_dashboard');
610
  $option_last_update_post = get_option('wpms_last_update_post');
611
  $option_last_dash_update = get_option('_wpms_dash_last_update');
612
- if(!empty($options_dashboard) && is_array($options_dashboard) && !empty($options_dashboard['image_meta']) && $option_last_update_post < $option_last_dash_update){
 
 
613
  $results = $options_dashboard['image_meta'];
614
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
615
  $results['status'] = true;
616
  wp_send_json($results);
617
  }
618
- ob_start();
619
- require_once WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard/imgsresize.php';
620
- $html_imgresize = ob_get_contents();
621
- ob_end_clean();
622
-
623
- ob_start();
624
- require_once WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard/imgsmeta.php';
625
- $html_imgsmeta = ob_get_contents();
626
- ob_end_clean();
627
- wp_send_json(array('status' => true ,'html_imgresize' => $html_imgresize , 'html_imgsmeta' => $html_imgsmeta));
628
  }
629
 
 
630
  foreach ($meta_keys as $meta_key) {
631
  $imgs_metas_are_good[$meta_key] = 0;
632
  $imgs_metas_are_not_good[$meta_key] = 0;
633
  }
634
 
635
  $limit = 50;
636
- $offset = ($_POST['page']-1)*$limit;
637
- $post_types = MetaSeo_Content_List_Table::get_post_types();
638
  $query = "SELECT `ID`,`post_content`
639
  FROM $wpdb->posts
640
  WHERE `post_type` IN ($post_types)
@@ -650,9 +701,11 @@ class MetaSeo_Dashboard {
650
 
651
  foreach ($posts as $post) {
652
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
653
- if (empty($meta_analysis))
654
  $meta_analysis = array();
655
- $dom = $doc->loadHTML($post->post_content);
 
 
656
  $tags = $doc->getElementsByTagName('img');
657
  foreach ($tags as $tag) {
658
  $img_src = $tag->getAttribute('src');
@@ -680,13 +733,14 @@ class MetaSeo_Dashboard {
680
  $width = $height * ($ratio_origin);
681
  }
682
 
683
- if (($real_width <= $width && $real_height <= $height) || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
 
684
  $imgs_are_good++;
685
  }
686
  foreach ($meta_keys as $meta_key) {
687
-
688
- if (trim($tag->getAttribute($meta_key)) || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
689
- $imgs_metas_are_good[$meta_key] ++;
690
  }
691
  }
692
  }
@@ -703,7 +757,7 @@ class MetaSeo_Dashboard {
703
  $response['imgs_metas_statis'][1] = $imgs + (int)$_POST['imgs_count'];
704
  $response['imgs_count'] = $imgs + (int)$_POST['imgs_count'];
705
  $response['page'] = (int)$_POST['page'];
706
- }else{
707
  if (!empty($_POST['imgs_count'])) {
708
  $percent_iresizing = ceil($_POST['imgs_statis'] / $_POST['imgs_count'] * 100);
709
  } else {
@@ -718,43 +772,35 @@ class MetaSeo_Dashboard {
718
 
719
  $response['imgs_metas_statis'][2] = $percent_imeta;
720
  $options_dashboard['image_meta'] = array(
721
- 'imgs_statis' => array($_POST['imgs_statis'],$_POST['imgs_count'],$percent_iresizing),
722
- 'imgs_metas_statis' => array($_POST['imgs_metas_statis'],$_POST['imgs_count'],$percent_imeta)
723
  );
724
 
725
- if(!empty($options_dashboard) && is_array($options_dashboard)){
 
726
  if (empty($options_dashboard['image_meta'])) {
727
- update_option('options_dashboard',$options_dashboard);
728
- MetaSeo_Dashboard::_wpms_dash_last_update('image_meta');
729
- }else{
730
  $option_last_update_post = get_option('wpms_last_update_post');
731
  $option_last_dash_update = get_option('_wpms_dash_last_update');
732
- if((!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update) || empty($option_last_update_post)){
733
- update_option('options_dashboard',$options_dashboard);
734
- MetaSeo_Dashboard::_wpms_dash_last_update('image_meta');
 
735
  }
736
  }
737
- }else{
738
- update_option('options_dashboard',$options_dashboard);
739
- MetaSeo_Dashboard::_wpms_dash_last_update('image_meta');
740
  }
741
 
742
  $options_dashboard = get_option('options_dashboard');
743
  $results = $options_dashboard['image_meta'];
744
- if(isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets'){
745
  $results['status'] = true;
746
  wp_send_json($results);
747
  }
748
- ob_start();
749
- require_once WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard/imgsresize.php';
750
- $html_imgresize = ob_get_contents();
751
- ob_end_clean();
752
-
753
- ob_start();
754
- require_once WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard/imgsmeta.php';
755
- $html_imgsmeta = ob_get_contents();
756
- ob_end_clean();
757
- wp_send_json(array('status' => true ,'html_imgresize' => $html_imgresize , 'html_imgsmeta' => $html_imgsmeta));
758
  }
759
 
760
  wp_send_json($response);
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+
5
+ /**
6
+ * Class MetaSeoDashboard
7
  * This class implements the statistical criteria of Meta SEO
 
8
  */
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 = 156;
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
  $meta_keys = array('alt', 'title');
32
  $response = array(
33
+ 'imgs_statis' => array(0, 0, 100),
34
+ 'imgs_metas_statis' => array(0, 0, 100),
35
  );
36
  foreach ($meta_keys as $meta_key) {
37
  $imgs_metas_are_good[$meta_key] = 0;
38
  $imgs_metas_are_not_good[$meta_key] = 0;
39
  }
40
 
41
+ $post_types = MetaSeoContentListTable::getPostTypes();
42
  $query = "SELECT `ID`,`post_content`
43
  FROM $wpdb->posts
44
  WHERE `post_type` IN ($post_types)
54
 
55
  foreach ($posts as $post) {
56
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
57
+ if (empty($meta_analysis)) {
58
  $meta_analysis = array();
59
+ }
60
+
61
+ $doc->loadHTML($post->post_content);
62
  $tags = $doc->getElementsByTagName('img');
63
  foreach ($tags as $tag) {
64
  $img_src = $tag->getAttribute('src');
86
  $width = $height * ($ratio_origin);
87
  }
88
 
89
+ if (($real_width <= $width && $real_height <= $height)
90
+ || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
91
  $imgs_are_good++;
92
  }
 
93
 
94
+ foreach ($meta_keys as $meta_key) {
95
+ if (trim($tag->getAttribute($meta_key))
96
+ || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
97
+ $imgs_metas_are_good[$meta_key]++;
98
  }
99
  }
100
  }
126
 
127
  return $response;
128
  }
129
+
130
+ /**
131
  * Display rank of site
132
+ * @param $url
133
  */
134
+ public function displayRank($url)
135
+ {
136
  $rank = $this->getRank($url);
137
  if ($rank !== '') {
138
  echo $rank;
140
  echo __('We can\'t get rank of this site from Alexa.com!', 'wp-meta-seo');
141
  }
142
  }
143
+
144
+ /**
145
  * Get rank of site
146
+ * @param $url
147
+ * @return mixed|string
148
  */
149
+ public function getRank($url)
150
+ {
151
  if (!function_exists('curl_version')) {
152
  if (!$content = @file_get_contents($url)) {
153
  return '';
156
  if (!is_array($url)) {
157
  $url = array($url);
158
  }
159
+ $contents = $this->getContents($url);
160
  $content = $contents[0];
161
  }
162
 
184
  $html = str_replace('"/topsites/countries', '"http://www.alexa.com/topsites/countries', $html);
185
  return $html;
186
  }
187
+
188
+ /**
189
  * Get content a file
190
+ * @param $urls
191
+ * @return array
192
  */
193
+ public function getContents($urls)
194
+ {
195
  $mh = curl_multi_init();
196
  $curl_array = array();
197
  $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36';
199
  $curl_array[$i] = curl_init($url);
200
  curl_setopt($curl_array[$i], CURLOPT_URL, $url);
201
  curl_setopt($curl_array[$i], CURLOPT_USERAGENT, $useragent); // set user agent
202
+ curl_setopt($curl_array[$i], CURLOPT_RETURNTRANSFER, true);
203
  curl_setopt($curl_array[$i], CURLOPT_CONNECTTIMEOUT, 5);
204
  curl_setopt($curl_array[$i], CURLOPT_ENCODING, "UTF-8");
205
  curl_multi_add_handle($mh, $curl_array[$i]);
206
  }
207
 
208
+ $running = null;
209
  do {
210
  usleep(10000);
211
  curl_multi_exec($mh, $running);
226
 
227
  /**
228
  * update option dashboard
229
+ * @param $name
230
+ * @return mixed
231
  */
232
+ public static function updateDashboard($name)
233
+ {
234
  $options_dashboard = get_option('options_dashboard');
235
+ MetaSeoDashboard::updateOptionDash($options_dashboard, $name);
236
  $options_dashboard = get_option('options_dashboard');
237
  $results = $options_dashboard[$name];
238
  return $results;
241
  /**
242
  * get Count posts
243
  */
244
+ public static function getCountPost()
245
+ {
246
  global $wpdb;
247
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
248
  $post_types = "'" . implode("', '", $post_types) . "'";
249
  $states = get_post_stati(array('show_in_admin_all_list' => true));
250
  $states['trash'] = 'trash';
251
  $all_states = "'" . implode("', '", $states) . "'";
252
+ $total_posts = $wpdb->get_var(
253
+ "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)"
254
+ );
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
  }
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
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
313
  wp_send_json($results);
314
  }
315
  ob_start();
319
  wp_send_json($html);
320
  }
321
 
322
+ /**
323
  * get params meta description filled for dashboard
324
+ * @return array
325
  */
326
+ public static function metaDesc()
327
+ {
328
+ $total_posts = MetaSeoDashboard::getCountPost();
329
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
330
+ if (!empty($post_types['attachment'])) {
331
  unset($post_types['attachment']);
332
+ }
333
+
334
  $results = array(0, array(0, $total_posts));
335
  $args = array(
336
  'posts_per_page' => -1,
337
+ 'post_type' => $post_types,
338
+ 'meta_key' => '_metaseo_metadesc',
339
  'meta_query' => array(
340
  array(
341
+ 'key' => '_metaseo_metadesc',
342
+ 'value' => '',
343
  'compare' => '!=',
344
  ),
345
  ),
346
  );
347
+ $query = new WP_Query($args);
348
  $posts = $query->get_posts();
349
  $metadesc_filled = 0;
350
  if (!empty($posts)) {
351
  foreach ($posts as $post) {
352
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
353
+ if (empty($meta_analysis)) {
354
  $meta_analysis = array();
355
+ }
356
 
357
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
358
+ if (($meta_desc != '' && mb_strlen($meta_desc, 'UTF-8') <= self::$meta_desc_length)
359
+ || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
360
  $metadesc_filled++;
361
  }
362
  }
367
  return $results;
368
  }
369
 
370
+ /**
371
  * Return html description filled for dashboard
372
  */
373
+ public static function dashboardMetaDesc()
374
+ {
375
+ $results = MetaSeoDashboard::updateDashboard('metadesc');
376
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
377
  wp_send_json($results);
378
  }
379
  ob_start();
383
  wp_send_json($html);
384
  }
385
 
386
+ /**
387
  * Return link_meta for dashboard
388
+ * @return array
389
  */
390
+ public static function linkMeta()
391
+ {
392
  global $wpdb;
393
+ $mlink_complete = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE meta_title !=''");
394
+ $mcount_link = $wpdb->get_var(
395
+ "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE type !='404_automaticaly'"
396
+ );
397
 
398
  if ($mcount_link == 0) {
399
  $link_percent = 100;
405
  return $results;
406
  }
407
 
408
+ /**
 
409
  * Return html link_meta for dashboard
410
  */
411
+ public static function dashboardLinkMeta()
412
+ {
413
+ $results = MetaSeoDashboard::linkMeta();
414
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
415
  wp_send_json($results);
416
  }
417
  ob_start();
421
  wp_send_json($html);
422
  }
423
 
424
+ /**
425
  * Return permalink for dashboard
426
+ * @return int
427
  */
428
+ public static function permalink()
429
+ {
430
  $permalink = 50;
431
  $permalink_structure = get_option('permalink_structure');
432
  if (strpos($permalink_structure, 'postname') == false && strpos($permalink_structure, 'category') == false) {
433
  $permalink = 0;
434
+ } elseif (strpos($permalink_structure, 'postname') == true
435
+ && strpos($permalink_structure, 'category') == true) {
436
  $permalink = 100;
437
+ } elseif (strpos($permalink_structure, 'postname') == true
438
+ || strpos($permalink_structure, 'category') == true) {
439
  $permalink = 50;
440
  }
441
  return $permalink;
442
  }
443
 
444
+ /**
445
  * Return html permalink for dashboard
446
  */
447
+ public static function dashboardPermalink()
448
+ {
449
+ $permalink = MetaSeoDashboard::permalink();
450
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
451
  wp_send_json($permalink);
452
  }
453
  ob_start();
457
  wp_send_json($html);
458
  }
459
 
460
+ /**
461
  * Return count new content updated for dashboard
462
+ * @return array
463
  */
464
+ public static function newContent()
465
+ {
466
+ $total_posts = MetaSeoDashboard::getCountPost();
467
  $newcontent_args = array(
468
  'date_query' => array(
469
  array(
486
  return $results;
487
  }
488
 
489
+ /**
490
  * Return html new content updated for dashboard
491
  */
492
+ public static function dashboardNewContent()
493
+ {
494
+ $results = MetaSeoDashboard::updateDashboard('newcontent');
495
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
496
  wp_send_json($results);
497
  }
498
  ob_start();
501
  ob_end_clean();
502
  wp_send_json($html);
503
  }
504
+
505
+ /**
506
  * Return count link 404 , count link 404 is redirected , percent
507
+ * @return array
508
  */
509
+ public static function get404Link()
510
+ {
511
  global $wpdb;
512
+ $sql = $wpdb->prepare(
513
+ "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links WHERE (broken_internal=%d OR broken_indexed=%d) ",
514
+ array(1, 1)
515
+ );
516
  $count_404 = $wpdb->get_var($sql);
517
 
518
+ $sql = $wpdb->prepare(
519
+ "SELECT COUNT(*) FROM " . $wpdb->prefix . "wpms_links
520
+ WHERE link_url_redirect != '' AND (broken_internal=%d OR broken_indexed=%d) ",
521
+ array(1, 1)
522
+ );
523
  $count_404_redirected = $wpdb->get_var($sql);
524
  if ($count_404 != 0) {
525
  $percent = ceil($count_404_redirected / $count_404 * 100);
528
  }
529
  return array('count_404' => $count_404, 'count_404_redirected' => $count_404_redirected, 'percent' => $percent);
530
  }
531
+
532
+ /**
533
  * Return count image is optimized
534
+ * @return int
535
  */
536
+ public function getImagesOptimizer()
537
+ {
538
  global $wpdb;
539
  $sql = $wpdb->prepare("SELECT * FROM INFORMATION_SCHEMA.TABLES
540
+ WHERE table_name = %s AND TABLE_SCHEMA = %s", array($wpdb->prefix . 'wpio_images', $wpdb->dbname));
541
  $row = $wpdb->get_results($sql);
542
+ if (!empty($row)) {
543
  $query = 'SELECT distinct file FROM ' . $wpdb->prefix . 'wpio_images';
544
  $files = $wpdb->get_results($query);
545
  $image_optimize = 0;
549
  }
550
  }
551
  return $image_optimize;
552
+ } else {
553
  return 0;
554
  }
555
  }
556
+
557
+ /**
558
  * Get count image
559
+ * @return array
560
  */
561
+ public function getImagesCount()
562
+ {
563
+ $image_optimize = $this->getImagesOptimizer();
 
 
 
 
564
  $allowed_ext = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf');
 
 
 
 
565
  $count_image = 0;
566
  $scan_dir = str_replace('/', DIRECTORY_SEPARATOR, ABSPATH);
567
  foreach (new RecursiveIteratorIterator(new IgnorantRecursiveDirectoryIterator($scan_dir)) as $filename) {
582
 
583
  /**
584
  * get meta data dashboard
585
+ * @param string $name param name
586
+ * @return array
587
  */
588
+ public static function getMetaDataDashBoard($name)
589
+ {
590
+ $results = array();
591
+ switch ($name) {
592
  case 'metatitle':
593
+ $results = MetaSeoDashboard::metaTitle();
594
  break;
595
  case 'metadesc':
596
+ $results = MetaSeoDashboard::metaDesc();
597
  break;
598
  case 'newcontent':
599
+ $results = MetaSeoDashboard::newContent();
600
  break;
601
  case 'image_meta':
602
+ $results = MetaSeoDashboard::moptimizationChecking();
603
  break;
604
  }
605
 
608
 
609
  /**
610
  * update time dashboard update
611
+ * @param $name
612
  */
613
+ public static function dashLastUpdate($name)
614
+ {
615
+ if ($name == 'metadesc') {
616
+ update_option('_wpms_dash_last_update', time());
617
  }
618
  }
619
 
620
  /**
621
  * update option dashboard
622
+ * @param array $options_dashboard all criteria in dashboard
623
+ * @param string $name option name
624
  */
625
+ public static function updateOptionDash($options_dashboard, $name)
626
+ {
627
+ if (!empty($options_dashboard) && is_array($options_dashboard)) {
628
  if (empty($options_dashboard[$name])) {
629
+ $results = MetaSeoDashboard::getMetaDataDashBoard($name);
630
  $options_dashboard[$name] = $results;
631
+ update_option('options_dashboard', $options_dashboard);
632
+ MetaSeoDashboard::dashLastUpdate($name);
633
+ } else {
634
  $option_last_update_post = get_option('wpms_last_update_post');
635
  $option_last_dash_update = get_option('_wpms_dash_last_update');
636
+ if (!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update) {
637
+ $results = MetaSeoDashboard::getMetaDataDashBoard($name);
638
  $options_dashboard[$name] = $results;
639
+ update_option('options_dashboard', $options_dashboard);
640
+ MetaSeoDashboard::dashLastUpdate($name);
641
  }
642
  }
643
+ } else {
644
+ $results = MetaSeoDashboard::getMetaDataDashBoard($name);
645
  $options_dashboard[$name] = $results;
646
+ update_option('options_dashboard', $options_dashboard);
647
+ MetaSeoDashboard::dashLastUpdate($name);
648
  }
649
  }
650
 
651
+ /**
652
+ * get image metas
653
+ */
654
+ public static function dashImgsMeta()
655
+ {
656
  global $wpdb;
657
  $imgs = 0;
 
658
  $imgs_are_good = 0;
659
  $imgs_metas_are_good = array();
660
  $meta_keys = array('alt', 'title');
661
+ // create default value
662
  $response = array(
663
+ 'imgs_statis' => array(0, 0, 100),
664
+ 'imgs_metas_statis' => array(0, 0, 100),
665
  );
666
 
667
  $options_dashboard = get_option('options_dashboard');
668
  $option_last_update_post = get_option('wpms_last_update_post');
669
  $option_last_dash_update = get_option('_wpms_dash_last_update');
670
+ // get response from options_dashboard option
671
+ if (!empty($options_dashboard) && is_array($options_dashboard)
672
+ && !empty($options_dashboard['image_meta']) && $option_last_update_post < $option_last_dash_update) {
673
  $results = $options_dashboard['image_meta'];
674
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
675
  $results['status'] = true;
676
  wp_send_json($results);
677
  }
 
 
 
 
 
 
 
 
 
 
678
  }
679
 
680
+ // find img good and not good in post content to update
681
  foreach ($meta_keys as $meta_key) {
682
  $imgs_metas_are_good[$meta_key] = 0;
683
  $imgs_metas_are_not_good[$meta_key] = 0;
684
  }
685
 
686
  $limit = 50;
687
+ $offset = ($_POST['page'] - 1) * $limit;
688
+ $post_types = MetaSeoContentListTable::getPostTypes();
689
  $query = "SELECT `ID`,`post_content`
690
  FROM $wpdb->posts
691
  WHERE `post_type` IN ($post_types)
701
 
702
  foreach ($posts as $post) {
703
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
704
+ if (empty($meta_analysis)) {
705
  $meta_analysis = array();
706
+ }
707
+ // load dom html
708
+ $doc->loadHTML($post->post_content);
709
  $tags = $doc->getElementsByTagName('img');
710
  foreach ($tags as $tag) {
711
  $img_src = $tag->getAttribute('src');
733
  $width = $height * ($ratio_origin);
734
  }
735
 
736
+ if (($real_width <= $width && $real_height <= $height)
737
+ || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
738
  $imgs_are_good++;
739
  }
740
  foreach ($meta_keys as $meta_key) {
741
+ if (trim($tag->getAttribute($meta_key))
742
+ || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
743
+ $imgs_metas_are_good[$meta_key]++;
744
  }
745
  }
746
  }
757
  $response['imgs_metas_statis'][1] = $imgs + (int)$_POST['imgs_count'];
758
  $response['imgs_count'] = $imgs + (int)$_POST['imgs_count'];
759
  $response['page'] = (int)$_POST['page'];
760
+ } else {
761
  if (!empty($_POST['imgs_count'])) {
762
  $percent_iresizing = ceil($_POST['imgs_statis'] / $_POST['imgs_count'] * 100);
763
  } else {
772
 
773
  $response['imgs_metas_statis'][2] = $percent_imeta;
774
  $options_dashboard['image_meta'] = array(
775
+ 'imgs_statis' => array($_POST['imgs_statis'], $_POST['imgs_count'], $percent_iresizing),
776
+ 'imgs_metas_statis' => array($_POST['imgs_metas_statis'], $_POST['imgs_count'], $percent_imeta)
777
  );
778
 
779
+ // update options_dashboard option
780
+ if (!empty($options_dashboard) && is_array($options_dashboard)) {
781
  if (empty($options_dashboard['image_meta'])) {
782
+ update_option('options_dashboard', $options_dashboard);
783
+ MetaSeoDashboard::dashLastUpdate('image_meta');
784
+ } else {
785
  $option_last_update_post = get_option('wpms_last_update_post');
786
  $option_last_dash_update = get_option('_wpms_dash_last_update');
787
+ if ((!empty($option_last_update_post) && $option_last_update_post > $option_last_dash_update)
788
+ || empty($option_last_update_post)) {
789
+ update_option('options_dashboard', $options_dashboard);
790
+ MetaSeoDashboard::dashLastUpdate('image_meta');
791
  }
792
  }
793
+ } else {
794
+ update_option('options_dashboard', $options_dashboard);
795
+ MetaSeoDashboard::dashLastUpdate('image_meta');
796
  }
797
 
798
  $options_dashboard = get_option('options_dashboard');
799
  $results = $options_dashboard['image_meta'];
800
+ if (isset($_POST['type']) && $_POST['type'] == 'dashboard_widgets') {
801
  $results['status'] = true;
802
  wp_send_json($results);
803
  }
 
 
 
 
 
 
 
 
 
 
804
  }
805
 
806
  wp_send_json($response);
inc/class.metaseo-front_end.php CHANGED
@@ -1,12 +1,29 @@
1
  <?php
 
 
 
 
 
2
  /**
 
3
  * Class that holds most of the admin functionality for Meta SEO.
4
  */
5
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php' );
6
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php' );
 
 
 
 
 
 
 
 
7
 
8
- class MetaSeo_Front {
9
- function __construct() {
 
 
 
10
  $this->ga_tracking = array(
11
  'wpmsga_dash_tracking' => 1,
12
  'wpmsga_dash_tracking_type' => 'universal',
@@ -32,71 +49,77 @@ class MetaSeo_Front {
32
  'wpmsga_cookiename' => '',
33
  'wpmsga_cookieexpires' => '',
34
  'wpmsga_track_exclude' => array(),
35
- 'wpmsga_cookiename' => ''
36
  );
37
-
38
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
39
  if (is_array($ga_tracking)) {
40
  $this->ga_tracking = array_merge($this->ga_tracking, $ga_tracking);
41
  }
42
 
43
- $this->ga_tracking_disconnect = array(
44
  'wpms_ga_uax_reference' => '',
45
  'wpmsga_dash_tracking_type' => 'classic',
46
  'wpmsga_code_tracking' => ''
47
  );
48
- $ga_tracking_disconnect = get_option('_metaseo_ggtracking_disconnect_settings');
49
- if (is_array($ga_tracking_disconnect)) {
50
- $this->ga_tracking_disconnect = array_merge($this->ga_tracking_disconnect, $ga_tracking_disconnect);
51
  }
52
-
53
- add_action( 'wp_head', array( $this, 'tracking_code' ), 99 );
54
  }
55
-
56
- public function tracking_code() {
57
- if(!empty($this->ga_tracking['wpmsga_code_tracking'])){
 
 
 
 
 
58
  require_once 'google_analytics/tracking/custom.php';
59
- return;
60
  }
61
-
62
- if (WPMSGA_Tools::check_roles($this->ga_tracking['wpmsga_track_exclude'], true)) {
63
- return;
64
  }
65
-
66
  $google_alanytics = get_option('wpms_google_alanytics');
67
  $traking_mode = $this->ga_tracking['wpmsga_dash_tracking'];
68
  $traking_type = $this->ga_tracking['wpmsga_dash_tracking_type'];
69
  if ($traking_mode > 0) {
70
  if (empty($google_alanytics['tableid_jail'])) {
71
- if(!empty($this->ga_tracking_disconnect['wpmsga_code_tracking'])){
72
  echo '<script type="text/javascript">';
73
- echo strip_tags($this->ga_tracking_disconnect['wpmsga_code_tracking'],'</script>');
74
  echo '</script>';
75
- }else{
76
- if(empty($this->ga_tracking_disconnect['wpms_ga_uax_reference'])){
77
- return;
78
  }
79
  if ($traking_type == "classic") {
80
- echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Classic Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
 
81
  require_once 'google_analytics/tracking/classic_disconnect.php';
82
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
83
  } else {
84
- echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Universal Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
85
  require_once 'google_analytics/tracking/universal_disconnect.php';
86
  echo "\n<!-- END WPMSGA Universal Tracking -->\n\n";
87
  }
88
  }
89
- }else{
90
  if ($traking_type == "classic") {
91
- echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Classic Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
92
  if ($this->ga_tracking['wpmsga_event_tracking']) {
93
  require_once 'google_analytics/tracking/events-classic.php';
94
  }
95
  require_once 'google_analytics/tracking/code-classic.php';
96
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
97
  } else {
98
- echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Universal Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
99
- if ($this->ga_tracking['wpmsga_event_tracking'] || $this->ga_tracking['wpmsga_aff_tracking'] || $this->ga_tracking['wpmsga_hash_tracking']) {
 
100
  require_once 'google_analytics/tracking/events-universal.php';
101
  }
102
  require_once 'google_analytics/tracking/code-universal.php';
@@ -104,6 +127,6 @@ class MetaSeo_Front {
104
  }
105
  }
106
  }
 
107
  }
108
-
109
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php');
5
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
6
+
7
  /**
8
+ * Class MetaSeoFront
9
  * Class that holds most of the admin functionality for Meta SEO.
10
  */
11
+ class MetaSeoFront
12
+ {
13
+ /**
14
+ * @var array
15
+ */
16
+ public $ga_tracking;
17
+ /**
18
+ * @var array
19
+ */
20
+ public $gaDisconnect;
21
 
22
+ /**
23
+ * MetaSeoFront constructor.
24
+ */
25
+ public function __construct()
26
+ {
27
  $this->ga_tracking = array(
28
  'wpmsga_dash_tracking' => 1,
29
  'wpmsga_dash_tracking_type' => 'universal',
49
  'wpmsga_cookiename' => '',
50
  'wpmsga_cookieexpires' => '',
51
  'wpmsga_track_exclude' => array(),
 
52
  );
53
+
54
  $ga_tracking = get_option('_metaseo_ggtracking_settings');
55
  if (is_array($ga_tracking)) {
56
  $this->ga_tracking = array_merge($this->ga_tracking, $ga_tracking);
57
  }
58
 
59
+ $this->gaDisconnect = array(
60
  'wpms_ga_uax_reference' => '',
61
  'wpmsga_dash_tracking_type' => 'classic',
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
  }
68
+
69
+ add_action('wp_head', array($this, 'trackingCode'), 99);
70
  }
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
  $traking_type = $this->ga_tracking['wpmsga_dash_tracking_type'];
90
  if ($traking_mode > 0) {
91
  if (empty($google_alanytics['tableid_jail'])) {
92
+ if (!empty($this->gaDisconnect['wpmsga_code_tracking'])) {
93
  echo '<script type="text/javascript">';
94
+ echo strip_tags($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
  if ($traking_type == "classic") {
101
+ echo "\n<!-- BEGIN WPMSGA v" . WPMSEO_VERSION . " Classic Tracking
102
+ - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
103
  require_once 'google_analytics/tracking/classic_disconnect.php';
104
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
105
  } else {
106
+ echo "\n<!-- Universal Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
107
  require_once 'google_analytics/tracking/universal_disconnect.php';
108
  echo "\n<!-- END WPMSGA Universal Tracking -->\n\n";
109
  }
110
  }
111
+ } else {
112
  if ($traking_type == "classic") {
113
+ echo "\n<!-- Classic Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
114
  if ($this->ga_tracking['wpmsga_event_tracking']) {
115
  require_once 'google_analytics/tracking/events-classic.php';
116
  }
117
  require_once 'google_analytics/tracking/code-classic.php';
118
  echo "\n<!-- END WPMSGA Classic Tracking -->\n\n";
119
  } else {
120
+ echo "\n<!-- Universal Tracking - https://wordpress.org/plugins/wp-meta-seo/ -->\n";
121
+ if ($this->ga_tracking['wpmsga_event_tracking']
122
+ || $this->ga_tracking['wpmsga_aff_tracking'] || $this->ga_tracking['wpmsga_hash_tracking']) {
123
  require_once 'google_analytics/tracking/events-universal.php';
124
  }
125
  require_once 'google_analytics/tracking/code-universal.php';
127
  }
128
  }
129
  }
130
+ return true;
131
  }
 
132
  }
inc/class.metaseo-google-analytics.php CHANGED
@@ -1,21 +1,25 @@
1
  <?php
 
 
2
 
3
  /**
 
4
  * Base class for displaying your google analytics.
5
- *
6
  */
7
- class MetaSeo_Google_Analytics {
8
-
9
- /*
10
  * ajax display google analytics
11
  */
12
- public static function ajax_item_reports() {
13
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php' );
14
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php' );
 
15
  $google_alanytics = get_option('wpms_google_alanytics');
16
 
17
- if (!isset($_POST['wpms_security_backend_item_reports']) || !wp_verify_nonce($_POST['wpms_security_backend_item_reports'], 'wpms_backend_item_reports')) {
18
- wp_die(- 30);
 
19
  }
20
 
21
  if (isset($_POST['projectId']) && $_POST['projectId'] !== 'false') {
@@ -34,68 +38,69 @@ class MetaSeo_Google_Analytics {
34
  if (ob_get_length()) {
35
  ob_clean();
36
  }
37
-
38
  if (!empty($google_alanytics['tableid_jail'])) {
39
- if (empty($wpmsga_controller)) {
40
- $wpmsga_controller = new WPMS_GAPI_Controller();
41
  }
42
  } else {
43
- wp_die(- 99);
44
  }
45
 
46
- if (!empty($google_alanytics['googleCredentials']) && !empty($google_alanytics['tableid_jail']) && isset($from) && isset($to)) {
47
- if (empty($wpmsga_controller)) {
48
- $wpmsga_controller = new WPMS_GAPI_Controller();
 
49
  }
50
  } else {
51
- wp_die(- 24);
52
  }
53
 
54
  if ($projectId == false) {
55
  $projectId = $google_alanytics['tableid_jail'];
56
  }
57
- $profile_info = WPMSGA_Tools::get_selected_profile($google_alanytics['profile_list'], $projectId);
58
  if (isset($profile_info[4])) {
59
- $wpmsga_controller->timeshift = $profile_info[4];
60
  } else {
61
- $wpmsga_controller->timeshift = (int) current_time('timestamp') - time();
62
  }
63
 
 
64
  if ($filter_id) {
65
  $uri_parts = explode('/', get_permalink($filter_id), 4);
66
 
67
  if (isset($uri_parts[3])) {
68
  $uri = '/' . $uri_parts[3];
69
- } else {
70
- wp_die(- 25);
71
- }
72
 
73
- // allow URL correction before sending an API request
74
- $filter = apply_filters('wpmsga_backenditem_uri', $uri);
75
- $lastchar = substr($filter, - 1);
76
 
77
- if (isset($profile_info[6]) && $profile_info[6] && $lastchar == '/') {
78
- $filter = $filter . $profile_info[6];
 
 
79
  }
80
-
81
- // Encode URL
82
- $filter = rawurlencode(rawurldecode($filter));
83
- } else {
84
- $filter = false;
85
  }
86
 
87
  $queries = explode(',', $query);
88
-
89
  $results = array();
90
-
91
  foreach ($queries as $value) {
92
- $results[] = $wpmsga_controller->get($projectId, $value, $from, $to, $filter);
93
  }
94
 
95
  wp_send_json($results);
96
  }
97
 
98
- public static function wpmsga_update_option() {
 
 
 
 
99
  $options = get_option('wpms_google_alanytics');
100
  if (isset($_POST['userapi'])) {
101
  $options['wpmsga_dash_userapi'] = $_POST['userapi'];
@@ -103,16 +108,22 @@ class MetaSeo_Google_Analytics {
103
  }
104
  wp_send_json(true);
105
  }
106
-
107
- /*
108
- * ajax clear author
109
- */
110
- public static function wpmsga_wpmsClearauthor() {
 
111
  delete_option('wpms_google_alanytics');
112
  wp_send_json(true);
113
  }
114
 
115
- public static function map($map) {
 
 
 
 
 
116
  $map = explode('.', $map);
117
  if (isset($map[1])) {
118
  $map[0] += ord('map');
@@ -121,5 +132,4 @@ class MetaSeo_Google_Analytics {
121
  return str_ireplace('map', chr(112), $map[0]);
122
  }
123
  }
124
-
125
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
 
5
  /**
6
+ * Class MetaSeoGoogleAnalytics
7
  * Base class for displaying your google analytics.
 
8
  */
9
+ class MetaSeoGoogleAnalytics
10
+ {
11
+ /**
12
  * ajax display google analytics
13
  */
14
+ public static function itemsReport()
15
+ {
16
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php');
17
+ include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php');
18
  $google_alanytics = get_option('wpms_google_alanytics');
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') {
38
  if (ob_get_length()) {
39
  ob_clean();
40
  }
41
+
42
  if (!empty($google_alanytics['tableid_jail'])) {
43
+ if (empty($controller)) {
44
+ $controller = new WpmsGapiController();
45
  }
46
  } else {
47
+ wp_die(-99);
48
  }
49
 
50
+ if (!empty($google_alanytics['googleCredentials']) && !empty($google_alanytics['tableid_jail'])
51
+ && isset($from) && isset($to)) {
52
+ if (empty($controller)) {
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;
70
  if ($filter_id) {
71
  $uri_parts = explode('/', get_permalink($filter_id), 4);
72
 
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
 
90
  $queries = explode(',', $query);
 
91
  $results = array();
 
92
  foreach ($queries as $value) {
93
+ $results[] = $controller->get($projectId, $value, $from, $to, $filter);
94
  }
95
 
96
  wp_send_json($results);
97
  }
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'];
108
  }
109
  wp_send_json(true);
110
  }
111
+
112
+ /**
113
+ * ajax clear author
114
+ */
115
+ public static function clearAuthor()
116
+ {
117
  delete_option('wpms_google_alanytics');
118
  wp_send_json(true);
119
  }
120
 
121
+ /**
122
+ * @param $map
123
+ * @return mixed|string
124
+ */
125
+ public static function map($map)
126
+ {
127
  $map = explode('.', $map);
128
  if (isset($map[1])) {
129
  $map[0] += ord('map');
132
  return str_ireplace('map', chr(112), $map[0]);
133
  }
134
  }
 
135
  }
inc/class.metaseo-image-list-table.php CHANGED
@@ -1,59 +1,74 @@
1
  <?php
2
- /**
3
- * Base class for displaying a list of image files in an ajaxified HTML table.
4
- *
5
- */
6
-
7
  if (!class_exists('WP_List_Table')) {
8
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
9
  }
10
 
11
  if (!class_exists('ImageHelper')) {
12
- require_once( 'class.image-helper.php' );
13
  }
14
 
15
- class MetaSeo_Image_List_Table extends WP_List_Table {
 
 
 
 
 
 
 
 
16
  public $months;
17
- function __construct() {
 
 
 
 
 
18
  parent::__construct(array(
19
  'singular' => 'metaseo_image',
20
  'plural' => 'metaseo_images',
21
  'ajax' => true
22
  ));
23
  }
24
-
25
  /**
26
- * Generate the table navigation above or below the table
27
- * @param string $which
28
- */
29
- function display_tablenav($which) {
 
30
  ?>
31
  <div class="tablenav <?php echo esc_attr($which); ?>">
32
 
33
- <?php if ($which == 'top'): ?>
34
- <input type="hidden" name="page" value="metaseo_image_meta" />
35
  <div class="alignleft actions bulkactions">
36
  <?php
37
- $this->months_fillter('sldate');
38
- $this->meta_fillter('slmeta', 'filter_meta_action');
39
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && (is_plugin_active('sitepress-multilingual-cms/sitepress.php') || is_plugin_active('polylang/polylang.php'))){
40
- $lang = !empty($_REQUEST['wpms_lang_list']) ? $_REQUEST['wpms_lang_list'] : '0';
41
- $sl_lang = apply_filters('wpms_get_languagesList','',$lang);
42
- echo $sl_lang;
43
- }
 
 
44
  ?>
45
  </div>
46
- <?php elseif ($which == 'bottom'): ?>
47
- <input type="hidden" name="page" value="metaseo_image_meta" />
48
  <div class="alignleft actions bulkactions">
49
  <?php
50
- $this->months_fillter('sldate1');
51
- $this->meta_fillter('slmeta1', 'filter_meta_action');
52
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && (is_plugin_active('sitepress-multilingual-cms/sitepress.php') || 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 endif ?>
@@ -61,50 +76,62 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
61
 
62
  ?>
63
  <div class="alignleft actions">
64
- <select name="image_mbulk_copy" class="mbulk_copy">
65
- <option value="0"><?php _e('Bulk copy', 'wp-meta-seo') ?></option>
66
- <option value="all"><?php _e('All Images', 'wp-meta-seo') ?></option>
67
- <option value="bulk-copy-title-alt"><?php _e('Selected images', 'wp-meta-seo') ?></option>
68
- </select>
69
- <input type="button" name="image_do_copy_alt" class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_alt" value="<?php _e('Image name as alt text', 'wp-meta-seo') ?>">
70
- <input type="button" name="image_do_copy_title" class="wpmsbtn wpmsbtn_small btn_do_copy image_do_copy_title" value="<?php _e('Image name as image title', 'wp-meta-seo') ?>">
71
- <?php if($which == 'top'): ?>
 
 
 
 
 
 
72
  <div style="float:left;position: relative;">
73
  <div class="wpms_process_meta" data-w="0" style="position: absolute;top: -2px;"></div>
74
- <input alt="<?php _e('Index images is required to use the Images filtering system above. Beware it may take a while depending of the quantity of images you got. Check the progress bar and be patient :)','wp-meta-seo') ?>" type="button" name="image_scan_meta" class="wpmsbtn wpmsbtn_small image_scan_meta" data-paged="1" value="<?php _e('Index images', 'wp-meta-seo') ?>">
 
 
 
 
75
  </div>
76
  <?php endif; ?>
77
  <span class="spinner"></span>
78
  </div>
79
 
80
- <input type="hidden" name="page" value="metaseo_image_meta" />
81
- <?php if (!empty($_REQUEST['post_status'])): ?>
82
- <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>" />
83
  <?php endif ?>
84
 
85
  <div style="float:right;margin-left:8px;">
86
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>" maxlength="3" name="metaseo_imgs_per_page" class="metaseo_imgs_per_page screen-per-page" max="999" min="1" step="1">
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>
93
 
94
  <?php
95
  }
96
-
97
  /**
98
- * Get an associative array ( id => link ) with the list
99
- * of views available on this table.
100
- * @return array
101
- */
102
- function get_views() {
 
103
  global $wpdb;
104
-
105
-
106
  $status_links = array();
107
-
108
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
109
  $post_types = "'" . implode("', '", $post_types) . "'";
110
 
@@ -112,41 +139,75 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
112
  $states['trash'] = 'trash';
113
  $all_states = "'" . implode("', '", $states) . "'";
114
 
115
- $total_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)");
 
 
116
 
117
  $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
118
- $status_links['all'] = "<a href='admin.php?page=metaseo_image_meta'$class>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts'), number_format_i18n($total_posts)) . '</a>';
119
-
 
 
 
 
 
 
 
 
 
 
 
120
  foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
 
121
 
122
- $status_name = $status->name;
123
-
124
- $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$status_name') AND post_type IN ($post_types)");
125
 
126
  if ($total == 0) {
127
  continue;
128
  }
129
 
130
- if (isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status']) {
131
  $class = ' class="current"';
132
  } else {
133
  $class = '';
134
  }
135
 
136
- $status_links[$status_name] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=$status_name'$class>" . sprintf(translate_nooped_plural($status->label_count, $total), number_format_i18n($total)) . '</a>';
 
 
 
 
 
137
  }
138
- $trashed_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)");
139
- $class = ( isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status'] ) ? 'class="current"' : '';
140
- $status_links['trash'] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=trash'$class>" . sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $trashed_posts, 'posts'), number_format_i18n($trashed_posts)) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
  return $status_links;
143
  }
144
-
145
  /**
146
- * Extra controls to be displayed between bulk actions and pagination
147
- * @param string $which
148
- */
149
- function extra_tablenav($which) {
 
150
  echo '<div class="alignleft actions">';
151
  global $wpdb;
152
 
@@ -157,7 +218,8 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
157
  $states['trash'] = 'trash';
158
  $all_states = "'" . implode("', '", esc_sql($states)) . "'";
159
 
160
- $query = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
 
161
  $post_types = $wpdb->get_results($query);
162
 
163
  $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
@@ -166,18 +228,24 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
166
 
167
  foreach ($post_types as $post_type) {
168
  $obj = get_post_type_object($post_type->post_type);
169
- $options .= sprintf('<option value="%2$s" %3$s>%1$s</option>', $obj->labels->name, $post_type->post_type, selected($selected, $post_type->post_type, false));
 
 
 
 
 
170
  }
171
 
172
  echo "</div>";
173
  }
174
-
175
  /**
176
- * Get a list of columns. The format is:
177
- * 'internal-name' => 'Title'
178
- * @return array
179
- */
180
- function get_columns() {
 
181
  return $columns = array(
182
  'cb' => '<input id="cb-select-all-1" type="checkbox">',
183
  'col_id' => __('ID', 'wp-meta-seo'),
@@ -192,15 +260,16 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
192
  }
193
 
194
  /**
195
- * Get a list of sortable columns. The format is:
196
- * 'internal-name' => 'orderby'
197
- * or
198
- * 'internal-name' => array( 'orderby', true )
199
- *
200
- * The second format will make the initial sorting order be descending
201
- * @return array
202
- */
203
- function get_sortable_columns() {
 
204
  return $sortable = array(
205
  'col_image_name' => array('post_name', true),
206
  'col_image_title' => array('post_title', true),
@@ -215,26 +284,29 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
215
  *
216
  * @param bool $with_id Whether to set the id attribute or not
217
  */
218
- public function print_column_headers($with_id = true) {
219
- list( $columns, $hidden, $sortable ) = $this->get_column_info();
220
-
221
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
222
  $current_url = remove_query_arg('paged', $current_url);
223
 
224
- if (isset($_GET['orderby']))
225
  $current_orderby = $_GET['orderby'];
226
- else
227
  $current_orderby = '';
 
228
 
229
- if (isset($_GET['order']) && 'desc' == $_GET['order'])
230
  $current_order = 'desc';
231
- else
232
  $current_order = 'asc';
 
233
 
234
  if (!empty($columns['cb'])) {
235
  static $cb_counter = 1;
236
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All', 'wp-meta-seo') . '</label>'
237
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
 
238
  $cb_counter++;
239
  }
240
 
@@ -242,18 +314,20 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
242
  $class = array('manage-column', "column-$column_key");
243
 
244
  $style = '';
245
- if (in_array($column_key, $hidden))
246
  $style = 'display:none;';
 
247
 
248
  $style = ' style="' . $style . '"';
249
 
250
- if ('cb' == $column_key)
251
  $class[] = 'check-column';
252
- elseif (in_array($column_key, array('posts', 'comments', 'links')))
253
  $class[] = 'num';
 
254
 
255
  if (isset($sortable[$column_key])) {
256
- list( $orderby, $desc_first ) = $sortable[$column_key];
257
 
258
  if ($current_orderby == $orderby) {
259
  $order = 'asc' == $current_order ? 'desc' : 'asc';
@@ -265,13 +339,17 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
265
  $class[] = $desc_first ? 'asc' : 'desc';
266
  }
267
 
268
- $column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
 
 
 
269
  }
270
 
271
  $id = $with_id ? "id='$column_key'" : '';
272
 
273
- if (!empty($class))
274
  $class = "class='" . join(' ', $class) . "'";
 
275
 
276
  if ($column_key === 'col_id') {
277
  echo "<th scope='col' $id $class $style colspan=\"1\">$column_display_name</th>";
@@ -286,96 +364,113 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
286
  }
287
  }
288
  }
289
-
290
  /**
291
- * Get months
292
- */
293
- function wpms_get_months(){
 
294
  global $wpdb;
295
- $where = " AND ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg') OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
296
- $months = $wpdb->get_results($wpdb->prepare("
 
 
297
  SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
298
  FROM $wpdb->posts
299
  WHERE post_type = %s" . $where . "
300
  ORDER BY post_date DESC
301
- ", 'attachment'));
 
302
 
303
  $months = apply_filters('months_dropdown_results', $months, 'attachment');
304
  return $months;
305
  }
306
-
307
- /**
308
- * Prepares the list of items for displaying.
309
- * @uses WP_List_Table::set_pagination_args()
310
- */
311
- function prepare_items() {
312
- global $wpdb, $_wp_column_headers;
313
- $this->months = $this->wpms_get_months();
314
- $screen = get_current_screen();
315
 
 
 
 
 
 
 
 
 
316
  $where = array();
317
  $post_type = 'attachment';
318
  $where[] = " post_type='$post_type' ";
319
- $where[] = " ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg') OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
 
320
 
321
  if (!empty($_REQUEST["search"])) {
322
  if (!empty($_REQUEST["txtkeyword"])) {
323
  $_REQUEST["txtkeyword"] = stripslashes($_REQUEST["txtkeyword"]);
324
  $_REQUEST["txtkeyword"] = $wpdb->esc_like($_REQUEST["txtkeyword"]);
325
- $where[] = $wpdb->prepare(" (post_title Like %s or post_name Like %s)", "%" . $_REQUEST["txtkeyword"] . "%", "%" . $_REQUEST["txtkeyword"] . "%");
 
 
 
 
326
  }
327
  }
328
 
329
  if (!empty($_REQUEST['sldate'])) {
330
  $where[] = $wpdb->prepare(" post_date Like %s", "%" . $_REQUEST['sldate'] . "%");
331
  }
332
-
333
  $sortable = $this->get_sortable_columns();
334
- $order_array = array('ASC','asc','DESC','desc');
335
- if(isset($_GET["orderby"])){
336
- $orderby_array = array($_GET["orderby"],true);
337
- }else{
338
- $orderby_array = array('post_name',true);
339
  }
340
  $orderby = (!empty($_GET["orderby"]) && in_array($orderby_array, $sortable)) ? ($_GET["orderby"]) : 'post_name';
341
  $order = (!empty($_GET["order"]) && in_array($_GET["order"], $order_array)) ? ($_GET["order"]) : 'ASC';
342
-
 
343
  if (!empty($orderby) & !empty($order)) {
344
  $orderStr = $wpdb->prepare(' ORDER BY %s %s', $orderby, $order);
345
  $orderStr = str_replace("'", "", $orderStr);
346
  }
347
 
348
- if(isset($_GET['slmeta']) && $_GET['slmeta'] == 'missing_information'){
349
- $join = "INNER JOIN (SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key = 'wpms_missing_information') mt ON mt.post_id = posts.ID ";
350
- }elseif(isset($_GET['slmeta']) && $_GET['slmeta'] == 'resizeimages'){
351
- $join = "INNER JOIN (SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key = 'wpms_resizeimages' AND meta_value = 1) mt ON mt.post_id = posts.ID ";
352
- }else{
353
- $join = "LEFT JOIN (SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key = '_wp_attachment_image_alt') mt ON mt.post_id = posts.ID ";
 
 
 
354
  }
355
 
356
  // query post by lang with polylang plugin
357
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')){
358
- if(isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0'){
359
- $join .= " INNER JOIN (SELECT * FROM $wpdb->term_relationships as ml INNER JOIN (SELECT * FROM $wpdb->terms WHERE slug='".$_GET['wpms_lang_list']."') mp ON mp.term_id = ml.term_taxonomy_id) ml ON ml.object_id = posts.ID ";
 
 
360
  }
361
  }
362
 
363
  // query post by lang with WPML plugin
364
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')){
365
- if(isset($_GET['wpms_lang_list']) && $_GET['wpms_lang_list'] != '0'){
366
- $join .= " INNER JOIN (SELECT * FROM ".$wpdb->prefix."icl_translations WHERE element_type LIKE 'post_%' AND language_code='".$_GET['wpms_lang_list']."') t ON t.element_id = $wpdb->posts.ID ";
 
 
367
  }
368
  }
369
 
370
  $query = "SELECT COUNT(ID)
371
  FROM $wpdb->posts as posts
372
- ". $join ."
373
  WHERE " . implode(" and ", $where) . $orderStr;
374
 
375
  $total_items = $wpdb->get_var($query);
376
- $query = "SELECT ID, post_title as title, post_name as name, post_content as des, post_excerpt as legend, guid, post_type , post_mime_type, post_status, mt.meta_value AS alt
 
377
  FROM $wpdb->posts as posts
378
- ". $join ."
379
  WHERE " . implode(" and ", $where) . $orderStr;
380
 
381
  if (!empty($_REQUEST['metaseo_imgs_per_page'])) {
@@ -408,7 +503,7 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
408
 
409
  if (!empty($paged) && !empty($per_page)) {
410
  $offset = ($paged - 1) * $per_page;
411
- $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
412
  }
413
 
414
  $this->set_pagination_args(array(
@@ -424,37 +519,55 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
424
 
425
  $this->items = $wpdb->get_results($query);
426
  }
427
-
428
  /**
429
- * Displays the search box.
430
- */
431
- function search_box1() {
432
- if (empty($_REQUEST['txtkeyword']) && !$this->has_items())
 
433
  return;
 
 
434
  $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
435
- if (!empty($_REQUEST['orderby']))
436
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
437
- if (!empty($_REQUEST['order']))
 
 
438
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
439
- if (!empty($_REQUEST['post_mime_type']))
 
 
440
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
441
- if (!empty($_REQUEST['detached']))
 
 
442
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
 
 
443
  ?>
444
  <p class="search-box">
445
-
446
- <input type="search" id="image-search-input" name="txtkeyword" value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>" />
 
 
447
  <?php submit_button('Search', 'button', 'search', false, array('id' => 'search-submit')); ?>
448
  </p>
449
  <?php
450
  }
451
-
452
- /* Add fillter month */
453
- function months_fillter($name) {
454
- global $wpdb, $wp_locale;
 
 
 
 
455
  $month_count = count($this->months);
456
- if (!$month_count || ( 1 == $month_count && 0 == $this->months[0]->month ))
457
  return;
 
458
 
459
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
460
  ?>
@@ -463,12 +576,21 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
463
  <option<?php selected($m, 0); ?> value="0"><?php _e('All dates', 'wp-meta-seo'); ?></option>
464
  <?php
465
  foreach ($this->months as $arc_row) {
466
-
467
- if (0 == $arc_row->year)
468
  continue;
 
 
469
  $month = zeroise($arc_row->month, 2);
470
  $year = $arc_row->year;
471
- printf("<option %s value='%s' >%s</option>\n", selected($m, "$year-$month", false), esc_attr("$arc_row->year-$month"), sprintf(__('%1$s %2$d', 'wp-meta-seo'), $wp_locale->get_month($month), $year)
 
 
 
 
 
 
 
 
472
  );
473
  }
474
  ?>
@@ -477,37 +599,47 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
477
  <?php
478
  }
479
 
480
- function meta_fillter($name, $namebutton) {
 
 
 
 
481
  $m = isset($_REQUEST['slmeta']) ? $_REQUEST['slmeta'] : 0;
482
  ?>
483
- <select name="<?php echo $name ?>" id="filter-by-meta" class="meta_filter">
484
- <option <?php selected($m,'all') ?> value="all"><?php _e('All images','wp-meta-seo') ?></option>
485
- <option <?php selected($m,'missing_information') ?> value="missing_information"><?php _e('Image with missing information','wp-meta-seo') ?></option>
486
- <option <?php selected($m,'resizeimages') ?> value="resizeimages"><?php _e('HTML resized images','wp-meta-seo') ?></option>
487
- </select>
488
- <input type="submit" name="filter_meta_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="<?php _e('Filter', 'wp-meta-seo') ?>">
 
 
 
 
 
 
 
489
  <span class="spinner imgspinner"></span>
490
  <?php
491
  }
492
 
493
  /**
494
- * Generate the table rows
495
- */
496
- function display_rows() {
497
- $url = URL;
498
- $url = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', $url);
499
  $records = $this->items;
500
  $i = 0;
501
  $alternate = "";
502
 
503
- list( $columns, $hidden ) = $this->get_column_info();
504
 
505
  if (!empty($records)) {
506
  foreach ($records as $rec) {
507
  $alternate = 'alternate' == $alternate ? '' : 'alternate';
508
  $i++;
509
  $classes = $alternate;
510
- $img_meta = get_post_meta($rec->ID, '_wp_attachment_metadata', TRUE);
511
  $thumb = wp_get_attachment_image_src($rec->ID, 'thumbnail');
512
  if (!$thumb) {
513
  $thumb_url = $rec->guid;
@@ -525,7 +657,9 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
525
 
526
  $upload_dir = wp_upload_dir();
527
  $img_path = $upload_dir['basedir'] . '/' . $img_meta['file'];
528
- if(file_exists($img_path)){
 
 
529
  if (is_readable($img_path)) {
530
  //Get image attributes including width and height
531
  list($img_width, $img_height, $img_type) = getimagesize($img_path);
@@ -538,13 +672,15 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
538
  $img_sizes = ' KB';
539
  }
540
  $img_size = round($img_size, 1);
541
- //Get the date that image was uploaded
542
- $img_date = get_the_date("", $rec->ID);
 
 
 
543
  }
544
 
545
  echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
546
  foreach ($columns as $column_name => $column_display_name) {
547
-
548
  $class = sprintf('class="%1$s column-%1$s"', $column_name);
549
  $style = "";
550
 
@@ -557,7 +693,8 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
557
  switch ($column_name) {
558
  case 'cb':
559
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
560
- echo '<input id="cb-select-1" class="metaseo_post" type="checkbox" name="post[]" value="' . $rec->ID . '">';
 
561
  echo '</td>';
562
  break;
563
 
@@ -568,14 +705,21 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
568
  break;
569
 
570
  case 'col_image':
571
- $img = sprintf("<img src='$thumb_url' width='100px' height='100px' class=\"metaseo-image\" data-name=\"$img_name$type\" data-img-post-id=\"$rec->ID\" />");
 
 
 
572
 
573
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $img, $attributes);
574
  break;
575
 
576
  case 'col_image_name':
577
  $info = '<div class="img-name-wrapper">';
578
- $info .= '<textarea name="name_image[' . $rec->ID . ']" class="metaseo-img-meta metaseo-img-name" data-meta-type="change_image_name" id="img-name-' . $rec->ID . '" data-post-id="' . $rec->ID . '" rows="2" data-extension="' . $type . '">' . $img_name . '</textarea><span class="img_type">' . $type . '</span>';
 
 
 
 
579
  $info .= '<p>size: ' . $img_size . $img_sizes . '</p>';
580
  $info .= '<p>' . $img_width . 'x' . $img_height . '</p>';
581
  $info .= '<p>' . $img_date . '</p>';
@@ -587,8 +731,6 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
587
  break;
588
 
589
  case 'col_image_info':
590
- $icon = '<img src= "' . WPMETASEO_PLUGIN_URL . 'img/view.png" />';
591
- $icon = '';
592
  $info = "<div class=\"opt-info\" id=\"opt-info-$rec->ID\"></div>";
593
  $info .= '<span class="metaseo-loading"></span>';
594
  $info .= '
@@ -596,14 +738,19 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
596
  <div class="popup post-list">
597
  <span class="popup-close" title="Close">x</span>
598
  <div class="popup-content"></div>
599
- </div>
600
- ';
601
 
602
- echo sprintf('<td %2$s colspan="5" style="position:relative">%1$s</td>', $info, $attributes);
 
 
 
 
603
  break;
604
 
605
  case 'col_image_alternative':
606
- $input = ("<textarea name='img_alternative[$rec->ID]' class='metaseo-img-meta' data-meta-type='alt_text' id='img-alt-$rec->ID' data-post-id='$rec->ID' rows='2'>" . esc_attr($rec->alt) . "</textarea>");
 
 
607
  $input .= ('<span class="saved-info" style="position:relative">
608
  <span class="spinner"></span>
609
  </span>');
@@ -611,7 +758,9 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
611
  break;
612
 
613
  case 'col_image_title':
614
- $input = ("<textarea name='img_title[$rec->ID]' class='metaseo-img-meta' data-meta-type='image_title' id='img-title-$rec->ID' data-post-id='$rec->ID' rows='2'>" . esc_attr($rec->title) . "</textarea>");
 
 
615
  $input .= ('<span class="saved-info" style="position:relative">
616
  <span class="spinner"></span>
617
  </span>');
@@ -619,15 +768,19 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
619
  break;
620
 
621
  case 'col_image_legend':
622
- $input = ("<textarea name='img_legend[$rec->ID]' class='metaseo-img-meta' data-meta-type='image_caption' id='img-legend-$rec->ID' data-post-id='$rec->ID' rows='2'>" . esc_attr($rec->legend) . "</textarea>");
623
- $input .= ('<span class="saved-info" style="position:relative">
 
 
624
  <span class="spinner"></span>
625
- </span>');
626
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
627
  break;
628
 
629
  case 'col_image_desc':
630
- $input = ("<textarea name='img_desc[$rec->ID]' class='metaseo-img-meta' data-meta-type='image_description' id='img-desc-$rec->ID' data-post-id='$rec->ID' rows='2'>" . esc_attr($rec->des) . "</textarea>");
 
 
631
  $input .= ('<span class="saved-info" style="position:relative">
632
  <span class="spinner"></span>
633
  </span>');
@@ -641,11 +794,15 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
641
  }
642
  }
643
  }
644
-
645
- /*
646
  * Add a size for image
 
 
 
647
  */
648
- public static function add_more_attachment_sizes_js($response, $attachment) {
 
649
  $metaseo_imgs_sizes = get_post_meta($attachment->ID, '_metaseo_sizes_optional', true);
650
 
651
  if (!empty($metaseo_imgs_sizes)) {
@@ -656,18 +813,21 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
656
 
657
  return $response;
658
  }
659
-
660
- /*
661
  * Add to the list of image sizes that are available to administrators in the WordPress Media Library.
 
 
662
  */
663
- public static function add_more_attachment_sizes_choose($sizes) {
 
664
  global $wpdb;
665
- $query = "SELECT `meta_value` FROM $wpdb->postmeta WHERE `meta_key` = '_metaseo_sizes_optional' AND `meta_value` <> ''";
 
666
 
667
- $metaseo_imgs_sizes = $wpdb->get_results($query);
668
- if (!empty($metaseo_imgs_sizes)) {
669
- $_sizes = array();
670
- foreach ($metaseo_imgs_sizes as $metaseo_img_sizes) {
671
  $metaseo_img_sizes = @unserialize($metaseo_img_sizes->meta_value);
672
  if (!empty($metaseo_img_sizes)) {
673
  foreach ($metaseo_img_sizes as $key => $size) {
@@ -697,13 +857,22 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
697
 
698
  return $new_sizes;
699
  }
700
-
701
- /*
702
  * Display page fix meta list
 
 
 
 
 
703
  */
704
- private static function display_fix_metas_list($img_post_id, $posts, $meta_counter, $p, $im) {
 
705
  if ($meta_counter) {
706
- $header = sprintf(__('We found %s image with missing Title or Alt text', 'wp-meta-seo'), $meta_counter . $im . $p);
 
 
 
707
  } else {
708
  $header = __('We found 0 image with missing Title or Alt text', 'wp-meta-seo');
709
  }
@@ -718,76 +887,106 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
718
  <table class="wp-list-table widefat fixed posts">
719
  <thead></thead>
720
  <tbody>
721
- <?php $alternate = ''; ?>
722
- <?php if (count($posts) < 1): ?>
723
- <tr><td colspan="10" style="height:95%"><?php echo __('This image has still not been inserted in any post!', 'wp-meta-seo') ?></td></tr>
724
- <?php else: ?>
725
- <tr class="metaseo-border-bottom">
726
- <td colspan="1"><?php _e('ID','wp-meta-seo') ?></td>
727
- <td colspan="2"><?php _e('Title','wp-meta-seo') ?></td>
728
- <td colspan="2"><?php _e('Image','wp-meta-seo') ?></td>
729
- <td colspan="5"><?php _e('Image information','wp-meta-seo') ?></td>
730
- </tr>
731
- <?php foreach ($posts as $post): ?>
732
- <?php foreach (metaseo_utf8($post['meta'],'decode') as $k => $meta): ?>
733
- <?php
734
- $alternate = 'alternate' == $alternate ? '' : 'alternate';
735
- $file_name = substr($meta['img_src'], strrpos($meta['img_src'], '/') + 1);
736
- ?>
737
- <tr class="<?php echo $alternate ?>">
738
- <td colspan="1"><?php echo $post['ID'] ?></td>
739
- <td colspan="2">
740
- <p><?php echo $post['title'] ?></p>
741
- </td>
742
- <td colspan="2">
 
 
 
 
 
 
 
 
 
 
743
  <div class="metaseo-img-wrapper">
744
- <img src="<?php echo $meta['img_src'] ?>" />
745
- </div>
746
- </td>
747
- <td colspan="5">
748
- <?php foreach ($meta['type'] as $type => $value): ?>
749
- <div class="metaseo-img-wrapper">
750
- <?php
751
- $specialChr = array('"', '\'');
752
- foreach ($specialChr as $chr) {
753
- $value = str_replace($chr, htmlentities2($chr), $value);
754
- }
755
- if($type == 'alt'){
756
- $lb = __('Image Alt','wp-meta-seo');
757
- }else{
758
- $lb = __('Image Title','wp-meta-seo');
759
- }
760
- ?>
761
- <div>
762
- <label class="metaseo-img-lb"><?php echo $lb; ?></label>
763
- <input type="text" value="<?php echo esc_attr($value) ?>" id="metaseo-img-<?php echo $type . '-' . $post['ID'] ?>" class="metaseo-fix-meta metaseo-img-<?php echo $type ?>" data-meta-key="_metaseo_fix_metas" data-post-id="<?php echo $post['ID'] ?>" data-img-post-id="<?php echo $img_post_id ?>" data-meta-type="<?php echo $type ?>" data-meta-order="<?php echo $k ?>" data-file-name="<?php echo $file_name; ?>" placeholder="<?php echo ($value == '' ? __(ucfirst($type) . ' is empty', 'wp-meta-seo') : '') ?>" onfocus="metaseo_fix_meta(this);" onblur="updateInputBlur(this)" onkeydown="return checkeyCode(event, this)" />
764
- </div>
765
-
766
- <?php if (trim($$type) != '' && trim($$type) != $value): ?>
767
- <a class="meta-default wpmsbtn wpmsbtn_small" href="#" data-default-value="<?php echo esc_attr($$type) ?>" title="Add to input box" onclick="add_meta_default(this)"><?php _e('Copy ','wp-meta-seo'); echo $lb ?></a>
768
- <span class="img_seo_type"><?php echo $$type; ?></span>
769
- <?php endif ?>
770
- <span class="spinner"></span>
 
 
 
771
  </div>
772
- <?php endforeach ?>
773
- <span class="saved-info"></span>
774
- </td>
775
- </tr>
776
- <?php endforeach ?>
 
 
 
 
 
 
 
 
 
 
777
  <?php endforeach ?>
778
- <?php endif ?>
 
779
  </tbody>
780
  <tfoot></tfoot>
781
  </table>
782
  </div>
783
- <div style="padding:5px"></div>
784
  <?php
785
  }
786
-
787
- /*
788
  * Display page resize image list
 
 
 
 
 
789
  */
790
- private static function display_resize_image_list($img_post_id, $posts, $img_counter, $p, $im) {
 
791
 
792
  $header = __('We found some images you can resize...', 'wp-meta-seo');
793
  ?>
@@ -796,88 +995,98 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
796
  <table class="wp-list-table widefat fixed posts">
797
  <thead></thead>
798
  <tbody>
799
- <tr class="metaseo-border-bottom">
800
- <td colspan="1">ID</td>
801
- <td colspan="3">Title</td>
802
- <td colspan="4">Current Images</td>
803
- <td colspan="2" class="metaseo-action">Action</td>
804
- <td colspan="4">After Replacing</td>
805
- </tr>
806
- <?php
807
- $alternate = "";
808
- foreach ($posts as $post):
809
- ?>
810
- <?php $alternate = 'alternate' == $alternate ? '' : 'alternate'; ?>
811
- <tr class="<?php echo $alternate ?>">
812
- <td colspan="1"><?php echo $post['ID'] ?></td>
813
- <td colspan="3">
814
- <p><?php echo $post['title'] ?></p>
815
- </td>
816
- <td colspan="4" style="overflow: hidden;">
817
- <?php foreach ($post['img_before_optm'] as $key => $src): ?>
818
- <div class="metaseo-img-wrapper">
819
- <div class="metaseo-img">
820
- <img width="<?php echo @$src['width']; ?>" height="<?php #echo @$src['height'] ; ?>" src="<?php echo $src['src'] ?>" />
821
- <div class="img-choosen">
822
-
823
- <div class="pure-checkbox">
824
- <input id="checkin-<?php echo $post['ID'] ?>" checked type="checkbox" class="metaseo-checkin checkin-<?php echo $post['ID'] ?>" value="<?php echo $key ?>" id="checkin-<?php echo $post['ID'] . '-' . $key ?>" onclick="uncheck(this)">
825
- <label for="checkin-<?php echo $post['ID'] ?>"></label>
826
- </div>
 
 
 
 
827
  </div>
828
- <p class="metaseo-msg"></p>
829
- </div>
830
- <div class="dimension">
831
- Orig. </br>
832
- <span>Dimensions</span>: <?php echo $src['dimension'] ?></br>
833
- <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
834
  </div>
 
835
  </div>
836
- <?php endforeach ?>
837
- </td>
838
- <td colspan="2" class="metaseo-action">
839
- <a href="javascript:void(0);" class="metaseo-optimize wpmsbtn wpmsbtn_small wpmsbtn_secondary" data-img-post-id="<?php echo $img_post_id ?>" data-post-id="<?php echo $post['ID'] ?>" onclick="optimize_imgs(this)"><?php echo __('Replace?', 'wp-meta-seo') ?></a>
840
- <span class="optimizing spinner"></span>
841
- </td>
842
- <td colspan="4">
843
- <?php foreach ($post['img_after_optm'] as $src): ?>
844
- <div class="metaseo-img-wrapper">
845
- <div class="metaseo-img">
846
- <img src="<?php echo $src['src'] ?>" />
847
- </div>
848
- <div class="dimension">
849
- OPT </br>
850
- <span>Dimensions</span>: <?php echo $src['dimension'] ?></br>
851
- <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
852
- </div>
853
  </div>
854
- <?php endforeach ?>
855
- </td>
856
- </tr>
857
-
858
- <?php endforeach ?>
859
- <tr class="metaseo-border-top">
860
- <td colspan="8"></td>
861
- <td colspan="2">
862
- <a href="javascript:void(0);" id="metaseo-replace-all" class="wpmsbtn wpmsbtn_small" onclick="optimize_imgs_group(this)">
863
- <?php echo __('Replace All', 'wp-meta-seo') ?>
864
- </a>
865
  <span class="optimizing spinner"></span>
866
  </td>
867
- <td colspan="4"></td>
 
 
 
 
 
 
 
 
 
 
 
 
 
868
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
869
  </tbody>
870
  <tfoot></tfoot>
871
  </table>
872
- </div>
873
  <div style="padding:5px"></div>
874
  <?php
875
  }
876
-
877
  /*
878
  * Ajax optimize image and update content
879
  */
880
- public static function optimizeImages() {
 
881
  if (!empty($_POST['post_id']) && !empty($_POST['img_post_id'])) {
882
  $post_id = intval($_POST['post_id']);
883
  $img_post_id = intval($_POST['img_post_id']);
@@ -887,7 +1096,7 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
887
  $img_exclude = array();
888
  }
889
 
890
- $ret = ImageHelper::_optimizeImages($post_id, $img_post_id, $img_exclude);
891
  } else {
892
  $ret = array(
893
  'success' => false,
@@ -898,17 +1107,22 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
898
  echo json_encode($ret);
899
  wp_die();
900
  }
901
-
902
  /*
903
  * Retrieves a modified URL query string.
904
  */
905
- public function process_action() {
906
- global $wpdb;
907
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
908
  $redirect = false;
909
 
910
  if (isset($_POST['search']) and $_POST['search'] === 'Search') {
911
- $current_url = add_query_arg(array("search" => "Search", "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))), $current_url);
 
 
 
 
 
912
  $redirect = true;
913
  }
914
 
@@ -928,7 +1142,12 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
928
  }
929
 
930
  if (!empty($_POST['metaseo_imgs_per_page'])) {
931
- $current_url = add_query_arg(array("metaseo_imgs_per_page" => intval($_POST['metaseo_imgs_per_page'])), $current_url);
 
 
 
 
 
932
  $redirect = true;
933
  }
934
 
@@ -938,39 +1157,38 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
938
  }
939
 
940
 
941
-
942
  if ($redirect === true) {
943
  wp_redirect($current_url);
944
  ob_end_flush();
945
  exit();
946
  }
947
  }
948
-
949
- /*
950
  * Ajax get list of posts contain this image and its clones
951
  */
952
- public static function load_posts_callback() {
953
- global $wpdb;
954
  $_POST = stripslashes_deep($_POST);
955
  $post_id = intval($_POST['post_id']);
956
  $img = trim($_POST['img_name']);
957
  $opt_key = strtolower(trim($_POST['opt_key']));
958
- $btn = preg_replace('/[_]+/i', ' ', $opt_key);
959
- $btn = ucwords($btn);
960
- $gotIt = false;
961
-
962
  if ($post_id && !empty($img) && !empty($opt_key)) {
963
  $fn = "display_{$opt_key}_list";
964
- if (method_exists('MetaSeo_Image_List_Table', $fn)) {
965
  //Get list of posts contain this image and its clones
966
- $posts = ImageHelper::_get_post_list($post_id, $opt_key);
967
 
968
  if (count($posts) > 0) {
969
  $img_counter = 0;
970
  //Now the time to resize the images
971
  if ($opt_key === 'resize_image') {
972
  $upload_dir = wp_upload_dir();
973
- $metaseo_sizes_optional = get_post_meta($post_id, '_metaseo_sizes_optional', TRUE);
 
 
 
 
974
  if (!is_array($metaseo_sizes_optional)) {
975
  $metaseo_sizes_optional = array();
976
  }
@@ -980,8 +1198,14 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
980
  foreach ($post['img_after_optm'] as &$img) {
981
  $img_counter++;
982
  $destination = $upload_dir['basedir'] . '/' . $img['path'];
983
- if (@ImageHelper::IResize($img['src_origin'], $img['width'], $img['height'], $destination)) {
984
-
 
 
 
 
 
 
985
  $size = (filesize($destination) / 1024);
986
  if ($size > 1024) {
987
  $size = $size / 1024;
@@ -1053,40 +1277,41 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1053
  }
1054
  //-----------------------------
1055
  }
1056
- }
1057
- }
1058
 
1059
- //This is a bit crazy but could give more exact information
1060
- if (count($posts) > 1) {
1061
- $p = ' in ' . count($posts) . ' posts ';
1062
- } else {
1063
- $p = '';
1064
- }
1065
 
1066
- if (isset($img_counter) and $img_counter > 1) {
1067
- $im = ' images ';
1068
- } else {
1069
- if (!isset($img_counter)) {
1070
- $img_counter = 0;
 
 
 
 
 
 
1071
  }
1072
- $im = ' image ';
1073
  }
1074
-
1075
- self::$fn($post_id, $posts, $img_counter, $p, $im);
1076
- wp_die();
1077
  }
1078
-
1079
- /*
1080
  * Scan post to find image good and not good
1081
  */
1082
- public static function scan_posts_callback() {
 
1083
  $_POST = stripslashes_deep($_POST);
1084
  $imgs = $_POST['imgs'];
1085
  if (!empty($imgs)) {
1086
  if (!is_array($imgs)) {
1087
  $ret['success'] = false;
1088
  $ret['msg'] = 'No images are available, please check again!';
1089
- return $ret;
1090
  }
1091
 
1092
  $_imgs = array();
@@ -1096,23 +1321,23 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1096
  if (!count($_imgs)) {
1097
  $ret['success'] = false;
1098
  $ret['msg'] = 'No images are available, please check again!';
1099
- return $ret;
1100
  }
1101
-
1102
  $msg = ImageHelper::IScanPosts($_imgs, true);
1103
  $ret['msg'] = $msg;
1104
  $ret['success'] = true;
1105
 
1106
- if(isset($_POST['imgs']['type']) && $_POST['imgs']['type'] == 'update_meta'){
1107
- if($ret['msg'][$_POST['imgs']['img_post_id']]['imNotGood']['warning']){
1108
- update_post_meta($_POST['imgs']['img_post_id'],'wpms_missing_information',1);
1109
- }else{
1110
- delete_post_meta($_POST['imgs']['img_post_id'],'wpms_missing_information');
1111
  }
1112
- if($ret['msg'][$_POST['imgs']['img_post_id']]['iNotGood']['warning']){
1113
- update_post_meta($_POST['imgs']['img_post_id'],'wpms_resizeimages',1);
1114
- }else{
1115
- delete_post_meta($_POST['imgs']['img_post_id'],'wpms_resizeimages');
1116
  }
1117
  }
1118
  } else {
@@ -1120,23 +1345,22 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1120
  $ret['msg'] = 'No images are available, please check again!';
1121
  }
1122
 
1123
- echo json_encode($ret);
1124
- wp_die();
1125
  }
1126
-
1127
- /*
1128
  * Ajax update image meta
1129
  */
1130
- public static function updateMeta_callback() {
1131
- global $wpdb;
1132
  $response = new stdClass();
1133
  $response->updated = false;
1134
  if (!empty($_POST['addition']['meta_key'])) {
1135
- self::updateImgMeta_call_back($_POST['addition'],true);
1136
  }
1137
 
1138
  if (!empty($_POST['meta_type']) and $_POST['meta_type'] == 'change_image_name') {
1139
- self::updateImageName_callback($_POST,true);
1140
  }
1141
 
1142
  if (!empty($_POST['meta_type']) && !empty($_POST['post_id'])) {
@@ -1159,7 +1383,12 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1159
  $label = str_replace('_', ' ', $meta_type);
1160
  $label = ucfirst($label);
1161
 
1162
- $aliases = array('image_title' => 'post_title', 'image_caption' => 'post_excerpt', 'image_description' => 'post_content', 'alt_text' => '_wp_attachment_image_alt');
 
 
 
 
 
1163
 
1164
  if ($meta_type != 'alt_text') {
1165
  $data = array('ID' => $post_id, $aliases[$meta_type] => $meta_value);
@@ -1174,11 +1403,12 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1174
  $response->msg = __($label . ' was saved', 'wp-meta-seo');
1175
  }
1176
 
1177
- if($meta_type == 'alt_text' || $meta_type == 'image_title'){
1178
  $settings = get_option('_metaseo_settings');
1179
- if(!isset($settings['metaseo_overridemeta']) || (!empty($settings['metaseo_overridemeta']) && $settings['metaseo_overridemeta'] == 1)){
 
1180
  // call function auto override in content
1181
- self::wpms_auto_update_post_content($post_id,$meta_type,$meta_value);
1182
  $response->type = 'auto_override';
1183
  $response->pid = $post_id;
1184
  $response->imgname = $_POST['img_name'];
@@ -1194,15 +1424,19 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1194
 
1195
  /**
1196
  * function auto override in content
 
 
 
1197
  */
1198
- public function wpms_auto_update_post_content($post_id,$meta_type,$meta_value){
 
1199
  $_POST = stripslashes_deep($_POST);
1200
  $img = trim($_POST['img_name']);
1201
  if ($post_id && !empty($img)) {
1202
  $fn = "display_fix_metas_list";
1203
- if (method_exists('MetaSeo_Image_List_Table', $fn)) {
1204
  //Get list of posts contain this image and its clones
1205
- $posts = ImageHelper::_get_post_list($post_id, 'fix_metas');
1206
 
1207
  if (count($posts) > 0) {
1208
  $img_counter = 0;
@@ -1240,14 +1474,14 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1240
  }
1241
  }
1242
  }
1243
- if(!empty($posts)){
1244
- foreach ($posts as $p){
1245
- foreach ($p['meta'] as $k => $meta){
1246
  $addition = array();
1247
  $addition['meta_key'] = '_metaseo_fix_metas';
1248
- if($meta_type == 'image_title'){
1249
  $addition['meta_type'] = 'title';
1250
- }else{
1251
  $addition['meta_type'] = 'alt';
1252
  }
1253
 
@@ -1255,25 +1489,25 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1255
  $addition['post_id'] = $p['ID'];
1256
  $addition['meta_order'] = $k;
1257
  $addition['img_post_id'] = $post_id;
1258
- self::updateImgMeta_call_back($addition,false);
1259
  }
1260
  }
1261
  }
1262
  }
1263
-
1264
- /*
1265
  * Update image name
1266
  */
1267
- public static function updateImageName_callback() {
1268
-
1269
  global $wpdb;
1270
- $postID = (int) $_POST['post_id'];
1271
  $name = trim($_POST['meta_value']);
1272
  $iname = preg_replace('/(\s{1,})/', '-', $name);
1273
- $img_meta = get_post_meta($postID, '_wp_attachment_metadata', TRUE);
1274
  $linkold = $img_meta['file'];
1275
  $response = new stdClass();
1276
- $response->updated = FALSE;
1277
  $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
1278
 
1279
  $upload_dirs = wp_upload_dir();
@@ -1288,12 +1522,18 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1288
  if (!file_exists($upload_dir . "/" . $newFileName)) {
1289
  if (rename($upload_dir . "/" . $linkold, $upload_dir . "/" . $newFileName)) {
1290
  $post_title = get_the_title($postID);
1291
- $data_post = array('ID' => $postID, 'post_name' => $name);
1292
- //if (wp_update_post($data_post)) {
1293
  $where = array('ID' => $postID);
1294
  $guid = $upload_dirs['baseurl'] . "/" . $newFileName;
1295
  if (!$post_title) {
1296
- $id = $wpdb->update($wpdb->posts, array('guid' => $guid, 'post_title' => $name, 'post_name' => strtolower($iname)), $where);
 
 
 
 
 
 
 
 
1297
  } else {
1298
  $id = $wpdb->update($wpdb->posts, array('guid' => $guid), $where);
1299
  }
@@ -1303,8 +1543,6 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1303
  $attached_metadata["file"] = $newFileName;
1304
 
1305
  $images_to_rename = array($oldpart->name . $oldpart->ext => $iname . $oldpart->ext);
1306
- $old_path = $upload_dir . "/" . $linkold;
1307
-
1308
  foreach ($attached_metadata['sizes'] as &$clone) {
1309
  $clone_file_new = ImageHelper::IReplace($iname, $clone['file']);
1310
  $clone_path = $upload_dir . '/' . $oldpart->base_path . $clone['file'];
@@ -1315,31 +1553,30 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1315
  $clone['file'] = $clone_file_new;
1316
  }
1317
  }
1318
-
1319
  $metadats = get_post_meta($postID, '_wp_attachment_metadata', true);
1320
  $sizes = $metadats['sizes'];
1321
-
1322
  // get list image url and image thumbnail url
1323
  $list_thum_url = array();
1324
  $imageUrl = wp_get_attachment_url($postID);
1325
  $list_thum_url[] = $imageUrl;
1326
- foreach ($sizes as $key => $size){
1327
- $thum_url = wp_get_attachment_image_src($postID,$key);
1328
  $list_thum_url[] = $thum_url[0];
1329
  }
1330
-
1331
  $w = '';
1332
  $w .= '(';
1333
 
1334
  $i = 0;
1335
- foreach ($list_thum_url as $url){
1336
  $i++;
1337
- if($i == count($list_thum_url)){
1338
  $w .= ' post_content LIKE "%' . $url . '%"';
1339
- }else{
1340
  $w .= ' post_content LIKE "%' . $url . '%" OR';
1341
  }
1342
-
1343
  }
1344
 
1345
  $w .= ')';
@@ -1349,18 +1586,18 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1349
  $where[] = $w;
1350
  $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
1351
  FROM $wpdb->posts
1352
- WHERE ".implode(' AND ', $where)." ORDER BY ID";
1353
  // query post
1354
  $posts = $wpdb->get_results($query);
1355
  $imgs = array($old_name . $oldpart->ext => $postID);
1356
  $posts_contain_img = array();
1357
  foreach ($posts as $post) {
1358
- $ifound = ImageHelper::IScan($imgs, $post->post_content);
1359
  if (count($ifound) > 0) {
1360
  $posts_contain_img[] = $post->ID;
1361
  }
1362
  }
1363
-
1364
  // update post
1365
  foreach ($posts_contain_img as $id) {
1366
  if ($post = get_post($id)) {
@@ -1369,18 +1606,18 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1369
  $src_after = '/' . $src_after;
1370
  $post->post_content = str_replace($src_before, $src_after, $post->post_content);
1371
  }
1372
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1373
- wp_update_post(array(
1374
- 'ID' => $post->ID,
1375
- 'post_content' => $post->post_content)
 
1376
  );
1377
-
1378
  unset($post, $posts_contain_img);
1379
  //---------------------------------
1380
  }
1381
  }
1382
-
1383
- /* * ************************************************** */
1384
  /** Update Image registered to Attachment sizes on Add media page* */
1385
  $sizeOptional = get_post_meta($postID, '_metaseo_sizes_optional', true);
1386
  $newOptional = array();
@@ -1395,7 +1632,7 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1395
  update_post_meta($postID, '_metaseo_sizes_optional', $newOptional);
1396
  unset($sizeOptional, $newOptional);
1397
  }
1398
- /* * ************************************************* */
1399
  //Need to update optimization info of this image
1400
  ImageHelper::IScanPosts(array($iname . $oldpart->ext => $postID), true);
1401
 
@@ -1410,7 +1647,6 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1410
  }
1411
  }
1412
  } else {
1413
-
1414
  $response->msg = __('File name already given!', 'wp-meta-seo');
1415
  $response->iname = $old_name;
1416
  }
@@ -1425,12 +1661,14 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1425
  echo json_encode($response);
1426
  wp_die();
1427
  }
1428
-
1429
- /*
1430
  * Update image meta
 
 
1431
  */
1432
- public static function updateImgMeta_call_back($wpmspost,$return = true) {
1433
- global $wpdb;
1434
  $response = new stdClass();
1435
  $response->updated = false;
1436
 
@@ -1451,34 +1689,41 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1451
  $post_id = intval($wpmspost['post_id']);
1452
  $meta = get_post_meta($img_post_id, $meta_key, true);
1453
  //Update new value for meta info of this image in wp_postmeta
1454
- $meta[$post_id]['meta'][$meta_order]['type'][$meta_type] = metaseo_utf8($meta_value);
1455
  update_post_meta($img_post_id, $meta_key, $meta);
1456
- $meta = get_post_meta($img_post_id, $meta_key, true);
1457
 
1458
  //Then we must update this meta info in the appropriate post content
1459
  if (!$post = get_post($post_id)) {
1460
  $response->msg = __('The post has been deleted before, please check again!', 'wp-meta-seo');
1461
  } else {
1462
  if ($post->post_content !== '') {
1463
-
1464
  //Split content part that do not contain img tag
1465
- $post_content_split = preg_split('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content);
 
 
 
1466
  //Get all img tag from the content
1467
- preg_match_all('/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i', $post->post_content, $matches);
 
 
 
 
1468
  $img_tags = $matches[0];
1469
  if (isset($img_tags[$meta_order])) {
1470
  $pattern = '/' . $meta_type . '\s*?\=?\"[^\"]*\"/i';
1471
- $replacement = $meta_type . '="' . $meta_value . '"';
1472
-
1473
- if (!preg_match($pattern, $img_tags[$meta_order], $match)) {
1474
- $pattern = '/\/>/i';
1475
- $replacement = $meta_type . '="' . $meta_value . '" />';
1476
- }
1477
  // remove attr
1478
- $img_tags[$meta_order] = preg_replace('#(<img.+?)'.$meta_type.'=(["\']?)\d*\2(.*?/?>)#i', '$1$3', $img_tags[$meta_order]);
1479
- preg_match('/'.$meta_type.'="(.+?)"/', $img_tags[$meta_order], $matches);
 
 
 
 
1480
  // update attr
1481
- $img_tags[$meta_order] = preg_replace('/(<img\b[^><]*)>/i', '$1 '.$meta_type.'="'.$meta_value.'">', $img_tags[$meta_order]);
 
 
 
 
1482
  // create new post content
1483
  $post_content = '';
1484
  foreach ($post_content_split as $key => $split) {
@@ -1490,7 +1735,7 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1490
  $post_content .= $split . $img_tag;
1491
  }
1492
 
1493
- remove_action('post_updated', array('MetaSeo_Broken_Link_Table', 'wpms_update_post'));
1494
 
1495
  //Update content of this post.
1496
  if (!wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content))) {
@@ -1500,38 +1745,50 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1500
  $response->msg = __(ucfirst($meta_type) . ' was saved', 'wp-meta-seo');
1501
  }
1502
  } else {
1503
- $response->msg = __('This image has been removed from the post, please check again!', 'wp-meta-seo');
 
1504
  }
1505
  } else {
1506
  $response->msg = __('Content of the post is empty, please check again', 'wp-meta-seo');
1507
  }
1508
  }
1509
 
1510
- if($return == true){
1511
  echo json_encode($response);
1512
  wp_die();
1513
  }
1514
  }
1515
 
1516
- public static function wpms_image_scan_meta(){
 
 
 
 
1517
  if (!current_user_can('manage_options')) {
1518
  wp_send_json(false);
1519
  }
1520
  global $wpdb;
1521
  $limit = 1;
1522
- $ofset = ((int) $_POST['paged'] - 1) * $limit;
1523
 
1524
  $where = array();
1525
  $where[] = " post_type='attachment' ";
1526
- $where[] = " ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg') OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
 
1527
  $query = "SELECT COUNT(ID) FROM $wpdb->posts as posts WHERE " . implode(" and ", $where);
1528
  $count_images = $wpdb->get_var($query);
1529
  $present = (100 / $count_images) * $limit;
1530
 
1531
  $k = 0;
1532
- $sql = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE " . implode(" AND ", $where) . " LIMIT %d OFFSET %d",array($limit,$ofset));
 
 
 
 
 
 
1533
  $attachments = $wpdb->get_results($sql);
1534
- if (empty($attachments)){
1535
  wp_send_json(array('status' => 'ok'));
1536
  }
1537
 
@@ -1539,29 +1796,36 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1539
  $path = get_attached_file($image->ID);
1540
  $infos = pathinfo($path);
1541
  $img_name = $infos['basename'];
1542
- $imgs = array('name' => $img_name , 'img_post_id' => $image->ID);
1543
- $results = MetaSeo_Image_List_Table::wpms_scan_posts_meta($imgs,false,0);
1544
- if($results['msg'][$image->ID]['imNotGood']['warning']){
1545
- update_post_meta($image->ID,'wpms_missing_information',1);
1546
- }else{
1547
- delete_post_meta($image->ID,'wpms_missing_information');
1548
  }
1549
- if($results['msg'][$image->ID]['iNotGood']['warning']){
1550
- update_post_meta($image->ID,'wpms_resizeimages',1);
1551
- }else{
1552
- delete_post_meta($image->ID,'wpms_resizeimages');
1553
  }
1554
  $k++;
1555
  }
1556
 
1557
  if ($k >= $limit) {
1558
- wp_send_json(array('status' => 'error_time', 'paged' => $_POST['paged'] ,'precent' => $present));
1559
- }else{
1560
  wp_send_json(array('status' => 'ok'));
1561
  }
1562
  }
1563
 
1564
- public static function wpms_scan_posts_meta($imgs,$delete = false,$pid = 0) {
 
 
 
 
 
 
 
1565
  if (!empty($imgs)) {
1566
  if (!is_array($imgs)) {
1567
  $ret['success'] = false;
@@ -1579,7 +1843,7 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1579
  return $ret;
1580
  }
1581
 
1582
- $msg = ImageHelper::IScanPosts($_imgs, true, false, $delete, $pid);
1583
  $ret['msg'] = $msg;
1584
  $ret['success'] = true;
1585
  } else {
@@ -1590,154 +1854,173 @@ class MetaSeo_Image_List_Table extends WP_List_Table {
1590
  return $ret;
1591
  }
1592
 
1593
- /*
1594
  * update meta missing info and meta resize after delete post
 
1595
  */
1596
- public static function wpmf_delete_attachment($pid) {
 
1597
  $post = get_post($pid);
1598
- if(!empty($post)){
1599
  $post_type = get_post_type($pid);
1600
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1601
- if(isset($post_types['attachment'])){
1602
  unset($post_types['attachment']);
1603
  }
1604
 
1605
  if (in_array($post_type, $post_types)) {
1606
  $dom = new DOMDocument();
1607
- libxml_use_internal_errors( true );
1608
  @$dom->loadHtml($post->post_content);
1609
  $tags = $dom->getElementsByTagName('img');
1610
- if(!empty($tags)){
1611
- foreach($tags as $tag){
1612
  $url = $tag->getAttribute('src');
1613
- $postid = MetaSeo_Image_List_Table::get_attachment_id($url);
1614
  $path = get_attached_file($postid);
1615
  $infos = pathinfo($path);
1616
  $img_name = $infos['basename'];
1617
- $imgs = array('name' => $img_name , 'img_post_id' => $postid);
1618
- $results = MetaSeo_Image_List_Table::wpms_scan_posts_meta($imgs,true,$pid);
1619
 
1620
  // update or delete meta
1621
- if($results['msg'][$postid]['imNotGood']['warning']){
1622
- update_post_meta($postid,'wpms_missing_information',1);
1623
- }else{
1624
- delete_post_meta($postid,'wpms_missing_information');
1625
  }
1626
- if($results['msg'][$postid]['iNotGood']['warning']){
1627
- update_post_meta($postid,'wpms_resizeimages',1);
1628
- }else{
1629
- delete_post_meta($postid,'wpms_resizeimages');
1630
  }
1631
-
1632
  }
1633
  }
1634
  }
1635
  }
1636
  }
1637
 
1638
- /*
1639
  * update meta missing info and meta resize after update post
 
 
 
1640
  */
1641
- public static function wpms_update_post($post_ID, $post_after, $post_before) {
1642
- $old_imgs = MetaSeo_Image_List_Table::wpms_get_img_in_content($post_before); // return list img in post before
 
1643
  $dom = new DOMDocument();
1644
- libxml_use_internal_errors( true );
1645
  @$dom->loadHtml($post_after->post_content);
1646
  $tags = $dom->getElementsByTagName('img');
1647
  $new_imgs = array(); // return list img in post after
1648
- if(!empty($tags)){
1649
- foreach($tags as $tag){
1650
  $url = $tag->getAttribute('src');
1651
- $postid = MetaSeo_Image_List_Table::get_attachment_id($url);
1652
  $new_imgs[] = $postid;
1653
  $post = get_post($postid);
1654
- if(!empty($post)){
1655
  $path = get_attached_file($postid);
1656
  $infos = pathinfo($path);
1657
  $img_name = $infos['basename'];
1658
- $imgs = array('name' => $img_name , 'img_post_id' => $postid);
1659
- $results = MetaSeo_Image_List_Table::wpms_scan_posts_meta($imgs,false,0);
1660
 
1661
  // update or delete meta
1662
- if($results['msg'][$postid]['imNotGood']['warning']){
1663
- update_post_meta($postid,'wpms_missing_information',1);
1664
- }else{
1665
- delete_post_meta($postid,'wpms_missing_information');
1666
  }
1667
- if($results['msg'][$postid]['iNotGood']['warning']){
1668
- update_post_meta($postid,'wpms_resizeimages',1);
1669
- }else{
1670
- delete_post_meta($postid,'wpms_resizeimages');
1671
  }
1672
  }
1673
  }
1674
  }
1675
 
1676
  // remove post meta
1677
- $imgs_diff = array_diff($old_imgs,$new_imgs);
1678
- if(!empty($imgs_diff)){
1679
- foreach ($imgs_diff as $id){
1680
  $path = get_attached_file($id);
1681
  $infos = pathinfo($path);
1682
  $img_name = $infos['basename'];
1683
- $imgs = array('name' => $img_name , 'img_post_id' => $id);
1684
- $results = MetaSeo_Image_List_Table::wpms_scan_posts_meta($imgs,true,$post_ID);
1685
 
1686
  // update or delete meta
1687
- if($results['msg'][$id]['imNotGood']['warning']){
1688
- update_post_meta($id,'wpms_missing_information',1);
1689
- }else{
1690
- delete_post_meta($id,'wpms_missing_information');
1691
  }
1692
- if($results['msg'][$id]['iNotGood']['warning']){
1693
- update_post_meta($id,'wpms_resizeimages',1);
1694
- }else{
1695
- delete_post_meta($id,'wpms_resizeimages');
1696
  }
1697
  }
1698
  }
1699
  }
1700
 
1701
- public static function wpms_get_img_in_content($post_before) {
 
 
 
 
 
 
1702
  $dom = new DOMDocument();
1703
- libxml_use_internal_errors( true );
1704
  @$dom->loadHtml($post_before->post_content);
1705
  $tags = $dom->getElementsByTagName('img');
1706
  $ids = array();
1707
- if(empty($tags)) return $ids;
1708
- foreach($tags as $tag){
 
 
1709
  $url = $tag->getAttribute('src');
1710
- $postid = MetaSeo_Image_List_Table::get_attachment_id($url);
1711
  $ids[] = $postid;
1712
  }
1713
  return $ids;
1714
  }
1715
 
1716
- public static function get_attachment_id( $url ) {
 
 
 
 
 
 
1717
  $attachment_id = 0;
1718
  $dir = wp_upload_dir();
1719
- if ( false !== strpos( $url, $dir['baseurl'] . '/' ) ) { // Is URL in uploads directory?
1720
- $file = basename( $url );
1721
  $query_args = array(
1722
- 'post_type' => 'attachment',
1723
  'post_status' => 'inherit',
1724
- 'fields' => 'ids',
1725
- 'meta_query' => array(
1726
  array(
1727
- 'value' => $file,
1728
  'compare' => 'LIKE',
1729
- 'key' => '_wp_attachment_metadata',
1730
  ),
1731
  )
1732
  );
1733
- $query = new WP_Query( $query_args );
1734
- if ( $query->have_posts() ) {
1735
- foreach ( $query->posts as $post_id ) {
1736
- $meta = wp_get_attachment_metadata( $post_id );
1737
- if(!empty($meta['file']) && !empty($meta['sizes'])){
1738
- $original_file = basename( $meta['file'] );
1739
- $cropped_image_files = wp_list_pluck( $meta['sizes'], 'file' );
1740
- if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) {
1741
  $attachment_id = $post_id;
1742
  break;
1743
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
 
 
4
  if (!class_exists('WP_List_Table')) {
5
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6
  }
7
 
8
  if (!class_exists('ImageHelper')) {
9
+ require_once('class.image-helper.php');
10
  }
11
 
12
+ /**
13
+ * Class MetaSeoImageListTable
14
+ * Base class for displaying a list of image files in an ajaxified HTML table.
15
+ */
16
+ class MetaSeoImageListTable extends WP_List_Table
17
+ {
18
+ /**
19
+ * @var
20
+ */
21
  public $months;
22
+
23
+ /**
24
+ * MetaSeoImageListTable constructor.
25
+ */
26
+ public function __construct()
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
48
+ $this->monthsFilter('sldate');
49
+ $this->metaFilter('slmeta');
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
63
+ $this->monthsFilter('sldate1');
64
+ $this->metaFilter('slmeta1');
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
  ?>
73
  </div>
74
  <?php endif ?>
76
 
77
  ?>
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>
122
 
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
 
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
 
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;
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'),
260
  }
261
 
262
  /**
263
+ * Get a list of sortable columns. The format is:
264
+ * 'internal-name' => 'orderby'
265
+ * or
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),
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
 
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';
327
+ }
328
 
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';
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>";
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');
386
  return $months;
387
  }
 
 
 
 
 
 
 
 
 
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'])) {
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(
519
 
520
  $this->items = $wpdb->get_results($query);
521
  }
522
+
523
  /**
524
+ * Displays the search box.
525
+ */
526
+ public function searchBox1()
527
+ {
528
+ if (empty($_REQUEST['txtkeyword']) && !$this->has_items()) {
529
  return;
530
+ }
531
+
532
  $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
533
+ if (!empty($_REQUEST['orderby'])) {
534
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
535
+ }
536
+
537
+ if (!empty($_REQUEST['order'])) {
538
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
539
+ }
540
+
541
+ if (!empty($_REQUEST['post_mime_type'])) {
542
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
543
+ }
544
+
545
+ if (!empty($_REQUEST['detached'])) {
546
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
547
+ }
548
+
549
  ?>
550
  <p class="search-box">
551
+ <label>
552
+ <input type="search" id="image-search-input" name="txtkeyword"
553
+ value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>"/>
554
+ </label>
555
  <?php submit_button('Search', 'button', 'search', false, array('id' => 'search-submit')); ?>
556
  </p>
557
  <?php
558
  }
559
+
560
+ /**
561
+ * Add fillter month
562
+ * @param $name
563
+ */
564
+ public function monthsFilter($name)
565
+ {
566
+ global $wp_locale;
567
  $month_count = count($this->months);
568
+ if (!$month_count || (1 == $month_count && 0 == $this->months[0]->month)) {
569
  return;
570
+ }
571
 
572
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
573
  ?>
576
  <option<?php selected($m, 0); ?> value="0"><?php _e('All dates', 'wp-meta-seo'); ?></option>
577
  <?php
578
  foreach ($this->months as $arc_row) {
579
+ if (0 == $arc_row->year) {
 
580
  continue;
581
+ }
582
+
583
  $month = zeroise($arc_row->month, 2);
584
  $year = $arc_row->year;
585
+ printf(
586
+ "<option %s value='%s' >%s</option>\n",
587
+ selected($m, "$year-$month", false),
588
+ esc_attr("$arc_row->year-$month"),
589
+ sprintf(
590
+ __('%1$s %2$d', 'wp-meta-seo'),
591
+ $wp_locale->get_month($month),
592
+ $year
593
+ )
594
  );
595
  }
596
  ?>
599
  <?php
600
  }
601
 
602
+ /**
603
+ * @param $name
604
+ */
605
+ public function metaFilter($name)
606
+ {
607
  $m = isset($_REQUEST['slmeta']) ? $_REQUEST['slmeta'] : 0;
608
  ?>
609
+ <label>
610
+ <select name="<?php echo $name ?>" id="filter-by-meta" class="meta_filter">
611
+ <option <?php selected($m, 'all') ?> value="all"><?php _e('All images', 'wp-meta-seo') ?></option>
612
+ <option <?php selected($m, 'missing_information') ?>
613
+ value="missing_information">
614
+ <?php _e('Image with missing information', 'wp-meta-seo') ?>
615
+ </option>
616
+ <option <?php selected($m, 'resizeimages') ?>
617
+ value="resizeimages"><?php _e('HTML resized images', 'wp-meta-seo') ?></option>
618
+ </select>
619
+ </label>
620
+ <input type="submit" name="filter_meta_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary"
621
+ value="<?php _e('Filter', 'wp-meta-seo') ?>">
622
  <span class="spinner imgspinner"></span>
623
  <?php
624
  }
625
 
626
  /**
627
+ * Generate the table rows
628
+ */
629
+ public function display_rows()
630
+ {
 
631
  $records = $this->items;
632
  $i = 0;
633
  $alternate = "";
634
 
635
+ list($columns, $hidden) = $this->get_column_info();
636
 
637
  if (!empty($records)) {
638
  foreach ($records as $rec) {
639
  $alternate = 'alternate' == $alternate ? '' : 'alternate';
640
  $i++;
641
  $classes = $alternate;
642
+ $img_meta = get_post_meta($rec->ID, '_wp_attachment_metadata', true);
643
  $thumb = wp_get_attachment_image_src($rec->ID, 'thumbnail');
644
  if (!$thumb) {
645
  $thumb_url = $rec->guid;
657
 
658
  $upload_dir = wp_upload_dir();
659
  $img_path = $upload_dir['basedir'] . '/' . $img_meta['file'];
660
+ //Get the date that image was uploaded
661
+ $img_date = get_the_date("", $rec->ID);
662
+ if (file_exists($img_path)) {
663
  if (is_readable($img_path)) {
664
  //Get image attributes including width and height
665
  list($img_width, $img_height, $img_type) = getimagesize($img_path);
672
  $img_sizes = ' KB';
673
  }
674
  $img_size = round($img_size, 1);
675
+ } else {
676
+ $img_size = 0;
677
+ $img_sizes = ' MB';
678
+ $img_width = 0;
679
+ $img_height = 0;
680
  }
681
 
682
  echo '<tr id="record_' . $rec->ID . '" class="' . $classes . '" >';
683
  foreach ($columns as $column_name => $column_display_name) {
 
684
  $class = sprintf('class="%1$s column-%1$s"', $column_name);
685
  $style = "";
686
 
693
  switch ($column_name) {
694
  case 'cb':
695
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
696
+ echo '<input id="cb-select-1" class="metaseo_post" type="checkbox"
697
+ name="post[]" value="' . $rec->ID . '">';
698
  echo '</td>';
699
  break;
700
 
705
  break;
706
 
707
  case 'col_image':
708
+ $img = sprintf(
709
+ "<img src='$thumb_url' width='100px' height='100px' class='metaseo-image'
710
+ data-name='$img_name$type' data-img-post-id='$rec->ID' />"
711
+ );
712
 
713
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $img, $attributes);
714
  break;
715
 
716
  case 'col_image_name':
717
  $info = '<div class="img-name-wrapper">';
718
+ $info .= '<textarea name="name_image[' . $rec->ID . ']"
719
+ class="metaseo-img-meta metaseo-img-name" data-meta-type="change_image_name"
720
+ id="img-name-' . $rec->ID . '" data-post-id="' . $rec->ID . '" rows="2"
721
+ data-extension="' . $type . '">' . $img_name . '</textarea>
722
+ <span class="img_type">' . $type . '</span>';
723
  $info .= '<p>size: ' . $img_size . $img_sizes . '</p>';
724
  $info .= '<p>' . $img_width . 'x' . $img_height . '</p>';
725
  $info .= '<p>' . $img_date . '</p>';
731
  break;
732
 
733
  case 'col_image_info':
 
 
734
  $info = "<div class=\"opt-info\" id=\"opt-info-$rec->ID\"></div>";
735
  $info .= '<span class="metaseo-loading"></span>';
736
  $info .= '
738
  <div class="popup post-list">
739
  <span class="popup-close" title="Close">x</span>
740
  <div class="popup-content"></div>
741
+ </div>';
 
742
 
743
+ echo sprintf(
744
+ '<td %2$s colspan="5" style="position:relative">%1$s</td>',
745
+ $info,
746
+ $attributes
747
+ );
748
  break;
749
 
750
  case 'col_image_alternative':
751
+ $input = "<textarea name='img_alternative[$rec->ID]' class='metaseo-img-meta'
752
+ data-meta-type='alt_text' id='img-alt-$rec->ID' data-post-id='$rec->ID'
753
+ rows='2'>" . esc_attr($rec->alt) . "</textarea>";
754
  $input .= ('<span class="saved-info" style="position:relative">
755
  <span class="spinner"></span>
756
  </span>');
758
  break;
759
 
760
  case 'col_image_title':
761
+ $input = "<textarea name='img_title[$rec->ID]' class='metaseo-img-meta'
762
+ data-meta-type='image_title' id='img-title-$rec->ID' data-post-id='$rec->ID'
763
+ rows='2'>" . esc_attr($rec->title) . "</textarea>";
764
  $input .= ('<span class="saved-info" style="position:relative">
765
  <span class="spinner"></span>
766
  </span>');
768
  break;
769
 
770
  case 'col_image_legend':
771
+ $input = "<textarea name='img_legend[$rec->ID]' class='metaseo-img-meta'
772
+ data-meta-type='image_caption' id='img-legend-$rec->ID' data-post-id='$rec->ID'
773
+ rows='2'>" . esc_attr($rec->legend) . "</textarea>";
774
+ $input .= '<span class="saved-info" style="position:relative">
775
  <span class="spinner"></span>
776
+ </span>';
777
  echo sprintf('<td %2$s colspan="3">%1$s</td>', $input, $attributes);
778
  break;
779
 
780
  case 'col_image_desc':
781
+ $input = "<textarea name='img_desc[$rec->ID]' class='metaseo-img-meta'
782
+ data-meta-type='image_description' id='img-desc-$rec->ID' data-post-id='$rec->ID'
783
+ rows='2'>" . esc_attr($rec->des) . "</textarea>";
784
  $input .= ('<span class="saved-info" style="position:relative">
785
  <span class="spinner"></span>
786
  </span>');
794
  }
795
  }
796
  }
797
+
798
+ /**
799
  * Add a size for image
800
+ * @param $response
801
+ * @param $attachment
802
+ * @return mixed
803
  */
804
+ public static function addMoreAttachmentSizes($response, $attachment)
805
+ {
806
  $metaseo_imgs_sizes = get_post_meta($attachment->ID, '_metaseo_sizes_optional', true);
807
 
808
  if (!empty($metaseo_imgs_sizes)) {
813
 
814
  return $response;
815
  }
816
+
817
+ /**
818
  * Add to the list of image sizes that are available to administrators in the WordPress Media Library.
819
+ * @param $sizes
820
+ * @return array
821
  */
822
+ public static function addMoreAttachmentSizesChoose($sizes)
823
+ {
824
  global $wpdb;
825
+ $query = "SELECT `meta_value` FROM $wpdb->postmeta WHERE
826
+ `meta_key` = '_metaseo_sizes_optional' AND `meta_value` <> ''";
827
 
828
+ $imgSizes = $wpdb->get_results($query);
829
+ if (!empty($imgSizes)) {
830
+ foreach ($imgSizes as $metaseo_img_sizes) {
 
831
  $metaseo_img_sizes = @unserialize($metaseo_img_sizes->meta_value);
832
  if (!empty($metaseo_img_sizes)) {
833
  foreach ($metaseo_img_sizes as $key => $size) {
857
 
858
  return $new_sizes;
859
  }
860
+
861
+ /**
862
  * Display page fix meta list
863
+ * @param $img_post_id
864
+ * @param $posts
865
+ * @param $meta_counter
866
+ * @param $p
867
+ * @param $im
868
  */
869
+ private static function display_fix_metas_list($img_post_id, $posts, $meta_counter, $p, $im)
870
+ {
871
  if ($meta_counter) {
872
+ $header = sprintf(
873
+ __('We found %s image with missing Title or Alt text', 'wp-meta-seo'),
874
+ $meta_counter . $im . $p
875
+ );
876
  } else {
877
  $header = __('We found 0 image with missing Title or Alt text', 'wp-meta-seo');
878
  }
887
  <table class="wp-list-table widefat fixed posts">
888
  <thead></thead>
889
  <tbody>
890
+ <?php $alternate = ''; ?>
891
+ <?php if (count($posts) < 1) : ?>
892
+ <tr>
893
+ <td colspan="10" style="height:95%">
894
+ <?php echo __('This image has still not been inserted in any post!', 'wp-meta-seo') ?>
895
+ </td>
896
+ </tr>
897
+ <?php else : ?>
898
+ <tr class="metaseo-border-bottom">
899
+ <td colspan="1"><?php _e('ID', 'wp-meta-seo') ?></td>
900
+ <td colspan="2"><?php _e('Title', 'wp-meta-seo') ?></td>
901
+ <td colspan="2"><?php _e('Image', 'wp-meta-seo') ?></td>
902
+ <td colspan="5"><?php _e('Image information', 'wp-meta-seo') ?></td>
903
+ </tr>
904
+ <?php foreach ($posts as $post) : ?>
905
+ <?php foreach (wpmsUtf8($post['meta'], 'decode') as $k => $meta) : ?>
906
+ <?php
907
+ $alternate = 'alternate' == $alternate ? '' : 'alternate';
908
+ $file_name = substr($meta['img_src'], strrpos($meta['img_src'], '/') + 1);
909
+ ?>
910
+ <tr class="<?php echo $alternate ?>">
911
+ <td colspan="1"><?php echo $post['ID'] ?></td>
912
+ <td colspan="2">
913
+ <p><?php echo $post['title'] ?></p>
914
+ </td>
915
+ <td colspan="2">
916
+ <div class="metaseo-img-wrapper">
917
+ <img src="<?php echo $meta['img_src'] ?>"/>
918
+ </div>
919
+ </td>
920
+ <td colspan="5">
921
+ <?php foreach ($meta['type'] as $type => $value) : ?>
922
  <div class="metaseo-img-wrapper">
923
+ <?php
924
+ $specialChr = array('"', '\'');
925
+ foreach ($specialChr as $chr) {
926
+ $value = str_replace($chr, htmlentities2($chr), $value);
927
+ }
928
+ if ($type == 'alt') {
929
+ $lb = __('Image Alt', 'wp-meta-seo');
930
+ } else {
931
+ $lb = __('Image Title', 'wp-meta-seo');
932
+ }
933
+ if ($value == '') {
934
+ $placeholder = __(ucfirst($type) . ' is empty', 'wp-meta-seo');
935
+ } else {
936
+ $placeholder = '';
937
+ }
938
+ ?>
939
+ <div>
940
+ <label class="metaseo-img-lb"><?php echo $lb; ?></label>
941
+ <input type="text" value="<?php echo esc_attr($value) ?>"
942
+ id="metaseo-img-<?php echo $type . '-' . $post['ID'] ?>"
943
+ class="metaseo-fix-meta metaseo-img-<?php echo $type ?>"
944
+ data-meta-key="_metaseo_fix_metas"
945
+ data-post-id="<?php echo $post['ID'] ?>"
946
+ data-img-post-id="<?php echo $img_post_id ?>"
947
+ data-meta-type="<?php echo $type ?>"
948
+ data-meta-order="<?php echo $k ?>"
949
+ data-file-name="<?php echo $file_name; ?>"
950
+ placeholder="<?php echo $placeholder ?>"
951
+ onfocus="metaseo_fix_meta(this);" onblur="updateInputBlur(this)"
952
+ onkeydown="return checkeyCode(event)"/>
953
  </div>
954
+
955
+ <?php if (trim($$type) != '' && trim($$type) != $value) : ?>
956
+ <a class="meta-default wpmsbtn wpmsbtn_small" href="#"
957
+ data-default-value="<?php echo esc_attr($$type) ?>"
958
+ title="Add to input box"
959
+ onclick="add_meta_default(this)"><?php _e('Copy ', 'wp-meta-seo');
960
+ echo $lb ?></a>
961
+ <span class="img_seo_type"><?php echo $$type; ?></span>
962
+ <?php endif ?>
963
+ <span class="spinner"></span>
964
+ </div>
965
+ <?php endforeach ?>
966
+ <span class="saved-info"></span>
967
+ </td>
968
+ </tr>
969
  <?php endforeach ?>
970
+ <?php endforeach ?>
971
+ <?php endif ?>
972
  </tbody>
973
  <tfoot></tfoot>
974
  </table>
975
  </div>
976
+ <div style="padding:5px"></div>
977
  <?php
978
  }
979
+
980
+ /**
981
  * Display page resize image list
982
+ * @param $img_post_id
983
+ * @param $posts
984
+ * @param $img_counter
985
+ * @param $p
986
+ * @param $im
987
  */
988
+ private static function display_resize_image_list($img_post_id, $posts, $img_counter, $p, $im)
989
+ {
990
 
991
  $header = __('We found some images you can resize...', 'wp-meta-seo');
992
  ?>
995
  <table class="wp-list-table widefat fixed posts">
996
  <thead></thead>
997
  <tbody>
998
+ <tr class="metaseo-border-bottom">
999
+ <td colspan="1">ID</td>
1000
+ <td colspan="3">Title</td>
1001
+ <td colspan="4">Current Images</td>
1002
+ <td colspan="2" class="metaseo-action">Action</td>
1003
+ <td colspan="4">After Replacing</td>
1004
+ </tr>
1005
+ <?php
1006
+ $alternate = "";
1007
+ foreach ($posts as $post) :
1008
+ ?>
1009
+ <?php $alternate = 'alternate' == $alternate ? '' : 'alternate'; ?>
1010
+ <tr class="<?php echo $alternate ?>">
1011
+ <td colspan="1"><?php echo $post['ID'] ?></td>
1012
+ <td colspan="3">
1013
+ <p><?php echo $post['title'] ?></p>
1014
+ </td>
1015
+ <td colspan="4" style="overflow: hidden;">
1016
+ <?php foreach ($post['img_before_optm'] as $key => $src) : ?>
1017
+ <div class="metaseo-img-wrapper">
1018
+ <div class="metaseo-img">
1019
+ <img width="<?php echo @$src['width']; ?>"
1020
+ height="<?php #echo @$src['height'] ; ?>" src="<?php echo $src['src'] ?>"/>
1021
+ <div class="img-choosen">
1022
+
1023
+ <div class="pure-checkbox">
1024
+ <input id="checkin-<?php echo $post['ID'] ?>" checked type="checkbox"
1025
+ class="metaseo-checkin checkin-<?php echo $post['ID'] ?>"
1026
+ value="<?php echo $key ?>"
1027
+ id="checkin-<?php echo $post['ID'] . '-' . $key ?>"
1028
+ onclick="uncheck(this)">
1029
+ <label for="checkin-<?php echo $post['ID'] ?>"></label>
1030
  </div>
 
 
 
 
 
 
1031
  </div>
1032
+ <p class="metaseo-msg"></p>
1033
  </div>
1034
+ <div class="dimension">
1035
+ Orig. <br>
1036
+ <span>Dimensions</span>: <?php echo $src['dimension'] ?><br>
1037
+ <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
1038
  </div>
1039
+ </div>
1040
+ <?php endforeach ?>
1041
+ </td>
1042
+ <td colspan="2" class="metaseo-action">
1043
+ <a href="javascript:void(0);"
1044
+ class="metaseo-optimize wpmsbtn wpmsbtn_small wpmsbtn_secondary"
1045
+ data-img-post-id="<?php echo $img_post_id ?>" data-post-id="<?php echo $post['ID'] ?>"
1046
+ onclick="optimize_imgs(this)"><?php echo __('Replace?', 'wp-meta-seo') ?></a>
 
 
 
1047
  <span class="optimizing spinner"></span>
1048
  </td>
1049
+ <td colspan="4">
1050
+ <?php foreach ($post['img_after_optm'] as $src) : ?>
1051
+ <div class="metaseo-img-wrapper">
1052
+ <div class="metaseo-img">
1053
+ <img src="<?php echo $src['src'] ?>"/>
1054
+ </div>
1055
+ <div class="dimension">
1056
+ OPT <br>
1057
+ <span>Dimensions</span>: <?php echo $src['dimension'] ?><br>
1058
+ <span>File size</span>: <?php echo $src['size'] . ' ' . $src['sizes'] ?>
1059
+ </div>
1060
+ </div>
1061
+ <?php endforeach ?>
1062
+ </td>
1063
  </tr>
1064
+
1065
+ <?php endforeach ?>
1066
+ <tr class="metaseo-border-top">
1067
+ <td colspan="8"></td>
1068
+ <td colspan="2">
1069
+ <a href="javascript:void(0);" id="metaseo-replace-all" class="wpmsbtn wpmsbtn_small"
1070
+ onclick="optimize_imgs_group(this)">
1071
+ <?php echo __('Replace All', 'wp-meta-seo') ?>
1072
+ </a>
1073
+ <span class="optimizing spinner"></span>
1074
+ </td>
1075
+ <td colspan="4"></td>
1076
+ </tr>
1077
  </tbody>
1078
  <tfoot></tfoot>
1079
  </table>
1080
+ </div>
1081
  <div style="padding:5px"></div>
1082
  <?php
1083
  }
1084
+
1085
  /*
1086
  * Ajax optimize image and update content
1087
  */
1088
+ public static function optimizeImages()
1089
+ {
1090
  if (!empty($_POST['post_id']) && !empty($_POST['img_post_id'])) {
1091
  $post_id = intval($_POST['post_id']);
1092
  $img_post_id = intval($_POST['img_post_id']);
1096
  $img_exclude = array();
1097
  }
1098
 
1099
+ $ret = ImageHelper::optimizeImages($post_id, $img_post_id, $img_exclude);
1100
  } else {
1101
  $ret = array(
1102
  'success' => false,
1107
  echo json_encode($ret);
1108
  wp_die();
1109
  }
1110
+
1111
  /*
1112
  * Retrieves a modified URL query string.
1113
  */
1114
+ public function processAction()
1115
+ {
1116
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
1117
  $redirect = false;
1118
 
1119
  if (isset($_POST['search']) and $_POST['search'] === 'Search') {
1120
+ $current_url = add_query_arg(
1121
+ array(
1122
+ "search" => "Search",
1123
+ "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))),
1124
+ $current_url
1125
+ );
1126
  $redirect = true;
1127
  }
1128
 
1142
  }
1143
 
1144
  if (!empty($_POST['metaseo_imgs_per_page'])) {
1145
+ $current_url = add_query_arg(
1146
+ array(
1147
+ "metaseo_imgs_per_page" => intval($_POST['metaseo_imgs_per_page'])
1148
+ ),
1149
+ $current_url
1150
+ );
1151
  $redirect = true;
1152
  }
1153
 
1157
  }
1158
 
1159
 
 
1160
  if ($redirect === true) {
1161
  wp_redirect($current_url);
1162
  ob_end_flush();
1163
  exit();
1164
  }
1165
  }
1166
+
1167
+ /**
1168
  * Ajax get list of posts contain this image and its clones
1169
  */
1170
+ public static function loadPostsCallback()
1171
+ {
1172
  $_POST = stripslashes_deep($_POST);
1173
  $post_id = intval($_POST['post_id']);
1174
  $img = trim($_POST['img_name']);
1175
  $opt_key = strtolower(trim($_POST['opt_key']));
 
 
 
 
1176
  if ($post_id && !empty($img) && !empty($opt_key)) {
1177
  $fn = "display_{$opt_key}_list";
1178
+ if (method_exists('MetaSeoImageListTable', $fn)) {
1179
  //Get list of posts contain this image and its clones
1180
+ $posts = ImageHelper::getPostList($post_id, $opt_key);
1181
 
1182
  if (count($posts) > 0) {
1183
  $img_counter = 0;
1184
  //Now the time to resize the images
1185
  if ($opt_key === 'resize_image') {
1186
  $upload_dir = wp_upload_dir();
1187
+ $metaseo_sizes_optional = get_post_meta(
1188
+ $post_id,
1189
+ '_metaseo_sizes_optional',
1190
+ true
1191
+ );
1192
  if (!is_array($metaseo_sizes_optional)) {
1193
  $metaseo_sizes_optional = array();
1194
  }
1198
  foreach ($post['img_after_optm'] as &$img) {
1199
  $img_counter++;
1200
  $destination = $upload_dir['basedir'] . '/' . $img['path'];
1201
+ $iresize = ImageHelper::IResize(
1202
+ $img['src_origin'],
1203
+ $img['width'],
1204
+ $img['height'],
1205
+ $destination
1206
+ );
1207
+
1208
+ if ($iresize) {
1209
  $size = (filesize($destination) / 1024);
1210
  if ($size > 1024) {
1211
  $size = $size / 1024;
1277
  }
1278
  //-----------------------------
1279
  }
 
 
1280
 
1281
+ //This is a bit crazy but could give more exact information
1282
+ if (count($posts) > 1) {
1283
+ $p = ' in ' . count($posts) . ' posts ';
1284
+ } else {
1285
+ $p = '';
1286
+ }
1287
 
1288
+ if (isset($img_counter) and $img_counter > 1) {
1289
+ $im = ' images ';
1290
+ } else {
1291
+ if (!isset($img_counter)) {
1292
+ $img_counter = 0;
1293
+ }
1294
+ $im = ' image ';
1295
+ }
1296
+
1297
+ self::$fn($post_id, $posts, $img_counter, $p, $im);
1298
+ wp_die();
1299
  }
 
1300
  }
 
 
 
1301
  }
1302
+
1303
+ /**
1304
  * Scan post to find image good and not good
1305
  */
1306
+ public static function scanPostsCallback()
1307
+ {
1308
  $_POST = stripslashes_deep($_POST);
1309
  $imgs = $_POST['imgs'];
1310
  if (!empty($imgs)) {
1311
  if (!is_array($imgs)) {
1312
  $ret['success'] = false;
1313
  $ret['msg'] = 'No images are available, please check again!';
1314
+ wp_send_json($ret);
1315
  }
1316
 
1317
  $_imgs = array();
1321
  if (!count($_imgs)) {
1322
  $ret['success'] = false;
1323
  $ret['msg'] = 'No images are available, please check again!';
1324
+ wp_send_json($ret);
1325
  }
1326
+
1327
  $msg = ImageHelper::IScanPosts($_imgs, true);
1328
  $ret['msg'] = $msg;
1329
  $ret['success'] = true;
1330
 
1331
+ if (isset($_POST['imgs']['type']) && $_POST['imgs']['type'] == 'update_meta') {
1332
+ if ($ret['msg'][$_POST['imgs']['img_post_id']]['imNotGood']['warning']) {
1333
+ update_post_meta($_POST['imgs']['img_post_id'], 'wpms_missing_information', 1);
1334
+ } else {
1335
+ delete_post_meta($_POST['imgs']['img_post_id'], 'wpms_missing_information');
1336
  }
1337
+ if ($ret['msg'][$_POST['imgs']['img_post_id']]['iNotGood']['warning']) {
1338
+ update_post_meta($_POST['imgs']['img_post_id'], 'wpms_resizeimages', 1);
1339
+ } else {
1340
+ delete_post_meta($_POST['imgs']['img_post_id'], 'wpms_resizeimages');
1341
  }
1342
  }
1343
  } else {
1345
  $ret['msg'] = 'No images are available, please check again!';
1346
  }
1347
 
1348
+ wp_send_json($ret);
 
1349
  }
1350
+
1351
+ /**
1352
  * Ajax update image meta
1353
  */
1354
+ public static function updateMetaCallback()
1355
+ {
1356
  $response = new stdClass();
1357
  $response->updated = false;
1358
  if (!empty($_POST['addition']['meta_key'])) {
1359
+ self::updateImgMetaCallback($_POST['addition'], true);
1360
  }
1361
 
1362
  if (!empty($_POST['meta_type']) and $_POST['meta_type'] == 'change_image_name') {
1363
+ self::updateImageNameCallback();
1364
  }
1365
 
1366
  if (!empty($_POST['meta_type']) && !empty($_POST['post_id'])) {
1383
  $label = str_replace('_', ' ', $meta_type);
1384
  $label = ucfirst($label);
1385
 
1386
+ $aliases = array(
1387
+ 'image_title' => 'post_title',
1388
+ 'image_caption' => 'post_excerpt',
1389
+ 'image_description' => 'post_content',
1390
+ 'alt_text' => '_wp_attachment_image_alt'
1391
+ );
1392
 
1393
  if ($meta_type != 'alt_text') {
1394
  $data = array('ID' => $post_id, $aliases[$meta_type] => $meta_value);
1403
  $response->msg = __($label . ' was saved', 'wp-meta-seo');
1404
  }
1405
 
1406
+ if ($meta_type == 'alt_text' || $meta_type == 'image_title') {
1407
  $settings = get_option('_metaseo_settings');
1408
+ if (!isset($settings['metaseo_overridemeta']) || (!empty($settings['metaseo_overridemeta'])
1409
+ && $settings['metaseo_overridemeta'] == 1)) {
1410
  // call function auto override in content
1411
+ self::autoUpdatePostContent($post_id, $meta_type, $meta_value);
1412
  $response->type = 'auto_override';
1413
  $response->pid = $post_id;
1414
  $response->imgname = $_POST['img_name'];
1424
 
1425
  /**
1426
  * function auto override in content
1427
+ * @param $post_id
1428
+ * @param $meta_type
1429
+ * @param $meta_value
1430
  */
1431
+ public static function autoUpdatePostContent($post_id, $meta_type, $meta_value)
1432
+ {
1433
  $_POST = stripslashes_deep($_POST);
1434
  $img = trim($_POST['img_name']);
1435
  if ($post_id && !empty($img)) {
1436
  $fn = "display_fix_metas_list";
1437
+ if (method_exists('MetaSeoImageListTable', $fn)) {
1438
  //Get list of posts contain this image and its clones
1439
+ $posts = ImageHelper::getPostList($post_id, 'fix_metas');
1440
 
1441
  if (count($posts) > 0) {
1442
  $img_counter = 0;
1474
  }
1475
  }
1476
  }
1477
+ if (!empty($posts)) {
1478
+ foreach ($posts as $p) {
1479
+ foreach ($p['meta'] as $k => $meta) {
1480
  $addition = array();
1481
  $addition['meta_key'] = '_metaseo_fix_metas';
1482
+ if ($meta_type == 'image_title') {
1483
  $addition['meta_type'] = 'title';
1484
+ } else {
1485
  $addition['meta_type'] = 'alt';
1486
  }
1487
 
1489
  $addition['post_id'] = $p['ID'];
1490
  $addition['meta_order'] = $k;
1491
  $addition['img_post_id'] = $post_id;
1492
+ self::updateImgMetaCallback($addition, false);
1493
  }
1494
  }
1495
  }
1496
  }
1497
+
1498
+ /**
1499
  * Update image name
1500
  */
1501
+ public static function updateImageNameCallback()
1502
+ {
1503
  global $wpdb;
1504
+ $postID = (int)$_POST['post_id'];
1505
  $name = trim($_POST['meta_value']);
1506
  $iname = preg_replace('/(\s{1,})/', '-', $name);
1507
+ $img_meta = get_post_meta($postID, '_wp_attachment_metadata', true);
1508
  $linkold = $img_meta['file'];
1509
  $response = new stdClass();
1510
+ $response->updated = false;
1511
  $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
1512
 
1513
  $upload_dirs = wp_upload_dir();
1522
  if (!file_exists($upload_dir . "/" . $newFileName)) {
1523
  if (rename($upload_dir . "/" . $linkold, $upload_dir . "/" . $newFileName)) {
1524
  $post_title = get_the_title($postID);
 
 
1525
  $where = array('ID' => $postID);
1526
  $guid = $upload_dirs['baseurl'] . "/" . $newFileName;
1527
  if (!$post_title) {
1528
+ $id = $wpdb->update(
1529
+ $wpdb->posts,
1530
+ array(
1531
+ 'guid' => $guid,
1532
+ 'post_title' => $name,
1533
+ 'post_name' => strtolower($iname)
1534
+ ),
1535
+ $where
1536
+ );
1537
  } else {
1538
  $id = $wpdb->update($wpdb->posts, array('guid' => $guid), $where);
1539
  }
1543
  $attached_metadata["file"] = $newFileName;
1544
 
1545
  $images_to_rename = array($oldpart->name . $oldpart->ext => $iname . $oldpart->ext);
 
 
1546
  foreach ($attached_metadata['sizes'] as &$clone) {
1547
  $clone_file_new = ImageHelper::IReplace($iname, $clone['file']);
1548
  $clone_path = $upload_dir . '/' . $oldpart->base_path . $clone['file'];
1553
  $clone['file'] = $clone_file_new;
1554
  }
1555
  }
1556
+
1557
  $metadats = get_post_meta($postID, '_wp_attachment_metadata', true);
1558
  $sizes = $metadats['sizes'];
1559
+
1560
  // get list image url and image thumbnail url
1561
  $list_thum_url = array();
1562
  $imageUrl = wp_get_attachment_url($postID);
1563
  $list_thum_url[] = $imageUrl;
1564
+ foreach ($sizes as $key => $size) {
1565
+ $thum_url = wp_get_attachment_image_src($postID, $key);
1566
  $list_thum_url[] = $thum_url[0];
1567
  }
1568
+
1569
  $w = '';
1570
  $w .= '(';
1571
 
1572
  $i = 0;
1573
+ foreach ($list_thum_url as $url) {
1574
  $i++;
1575
+ if ($i == count($list_thum_url)) {
1576
  $w .= ' post_content LIKE "%' . $url . '%"';
1577
+ } else {
1578
  $w .= ' post_content LIKE "%' . $url . '%" OR';
1579
  }
 
1580
  }
1581
 
1582
  $w .= ')';
1586
  $where[] = $w;
1587
  $query = "SELECT `ID`, `post_title`, `post_content`, `post_type`, `post_date`
1588
  FROM $wpdb->posts
1589
+ WHERE " . implode(' AND ', $where) . " ORDER BY ID";
1590
  // query post
1591
  $posts = $wpdb->get_results($query);
1592
  $imgs = array($old_name . $oldpart->ext => $postID);
1593
  $posts_contain_img = array();
1594
  foreach ($posts as $post) {
1595
+ $ifound = ImageHelper::IScan($post->post_content, $imgs);
1596
  if (count($ifound) > 0) {
1597
  $posts_contain_img[] = $post->ID;
1598
  }
1599
  }
1600
+
1601
  // update post
1602
  foreach ($posts_contain_img as $id) {
1603
  if ($post = get_post($id)) {
1606
  $src_after = '/' . $src_after;
1607
  $post->post_content = str_replace($src_before, $src_after, $post->post_content);
1608
  }
1609
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1610
+ wp_update_post(
1611
+ array(
1612
+ 'ID' => $post->ID,
1613
+ 'post_content' => $post->post_content)
1614
  );
1615
+
1616
  unset($post, $posts_contain_img);
1617
  //---------------------------------
1618
  }
1619
  }
1620
+
 
1621
  /** Update Image registered to Attachment sizes on Add media page* */
1622
  $sizeOptional = get_post_meta($postID, '_metaseo_sizes_optional', true);
1623
  $newOptional = array();
1632
  update_post_meta($postID, '_metaseo_sizes_optional', $newOptional);
1633
  unset($sizeOptional, $newOptional);
1634
  }
1635
+
1636
  //Need to update optimization info of this image
1637
  ImageHelper::IScanPosts(array($iname . $oldpart->ext => $postID), true);
1638
 
1647
  }
1648
  }
1649
  } else {
 
1650
  $response->msg = __('File name already given!', 'wp-meta-seo');
1651
  $response->iname = $old_name;
1652
  }
1661
  echo json_encode($response);
1662
  wp_die();
1663
  }
1664
+
1665
+ /**
1666
  * Update image meta
1667
+ * @param $wpmspost
1668
+ * @param bool $return
1669
  */
1670
+ public static function updateImgMetaCallback($wpmspost, $return = true)
1671
+ {
1672
  $response = new stdClass();
1673
  $response->updated = false;
1674
 
1689
  $post_id = intval($wpmspost['post_id']);
1690
  $meta = get_post_meta($img_post_id, $meta_key, true);
1691
  //Update new value for meta info of this image in wp_postmeta
1692
+ $meta[$post_id]['meta'][$meta_order]['type'][$meta_type] = wpmsUtf8($meta_value);
1693
  update_post_meta($img_post_id, $meta_key, $meta);
 
1694
 
1695
  //Then we must update this meta info in the appropriate post content
1696
  if (!$post = get_post($post_id)) {
1697
  $response->msg = __('The post has been deleted before, please check again!', 'wp-meta-seo');
1698
  } else {
1699
  if ($post->post_content !== '') {
 
1700
  //Split content part that do not contain img tag
1701
+ $post_content_split = preg_split(
1702
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1703
+ $post->post_content
1704
+ );
1705
  //Get all img tag from the content
1706
+ preg_match_all(
1707
+ '/(<img[\s]+[^>]*src\s*=\s*)([\"\'])([^>]+?)\2([^<>]*>)/i',
1708
+ $post->post_content,
1709
+ $matches
1710
+ );
1711
  $img_tags = $matches[0];
1712
  if (isset($img_tags[$meta_order])) {
1713
  $pattern = '/' . $meta_type . '\s*?\=?\"[^\"]*\"/i';
 
 
 
 
 
 
1714
  // remove attr
1715
+ $img_tags[$meta_order] = preg_replace(
1716
+ '#(<img.+?)' . $meta_type . '=(["\']?)\d*\2(.*?/?>)#i',
1717
+ '$1$3',
1718
+ $img_tags[$meta_order]
1719
+ );
1720
+ preg_match('/' . $meta_type . '="(.+?)"/', $img_tags[$meta_order], $matches);
1721
  // update attr
1722
+ $img_tags[$meta_order] = preg_replace(
1723
+ '/(<img\b[^><]*)>/i',
1724
+ '$1 ' . $meta_type . '="' . $meta_value . '">',
1725
+ $img_tags[$meta_order]
1726
+ );
1727
  // create new post content
1728
  $post_content = '';
1729
  foreach ($post_content_split as $key => $split) {
1735
  $post_content .= $split . $img_tag;
1736
  }
1737
 
1738
+ remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'));
1739
 
1740
  //Update content of this post.
1741
  if (!wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content))) {
1745
  $response->msg = __(ucfirst($meta_type) . ' was saved', 'wp-meta-seo');
1746
  }
1747
  } else {
1748
+ $response->msg = __('This image has been removed from
1749
+ the post, please check again!', 'wp-meta-seo');
1750
  }
1751
  } else {
1752
  $response->msg = __('Content of the post is empty, please check again', 'wp-meta-seo');
1753
  }
1754
  }
1755
 
1756
+ if ($return == true) {
1757
  echo json_encode($response);
1758
  wp_die();
1759
  }
1760
  }
1761
 
1762
+ /**
1763
+ * Scan image metas
1764
+ */
1765
+ public static function imageScanMeta()
1766
+ {
1767
  if (!current_user_can('manage_options')) {
1768
  wp_send_json(false);
1769
  }
1770
  global $wpdb;
1771
  $limit = 1;
1772
+ $ofset = ((int)$_POST['paged'] - 1) * $limit;
1773
 
1774
  $where = array();
1775
  $where[] = " post_type='attachment' ";
1776
+ $where[] = " ((post_mime_type='image/jpeg') OR (post_mime_type='image/jpg')
1777
+ OR (post_mime_type='image/png') OR (post_mime_type='image/gif')) ";
1778
  $query = "SELECT COUNT(ID) FROM $wpdb->posts as posts WHERE " . implode(" and ", $where);
1779
  $count_images = $wpdb->get_var($query);
1780
  $present = (100 / $count_images) * $limit;
1781
 
1782
  $k = 0;
1783
+ $sql = $wpdb->prepare(
1784
+ "SELECT ID FROM " . $wpdb->posts . " WHERE " . implode(" AND ", $where) . " LIMIT %d OFFSET %d",
1785
+ array(
1786
+ $limit,
1787
+ $ofset
1788
+ )
1789
+ );
1790
  $attachments = $wpdb->get_results($sql);
1791
+ if (empty($attachments)) {
1792
  wp_send_json(array('status' => 'ok'));
1793
  }
1794
 
1796
  $path = get_attached_file($image->ID);
1797
  $infos = pathinfo($path);
1798
  $img_name = $infos['basename'];
1799
+ $imgs = array('name' => $img_name, 'img_post_id' => $image->ID);
1800
+ $results = MetaSeoImageListTable::scanPostsMeta($imgs, false, 0);
1801
+ if ($results['msg'][$image->ID]['imNotGood']['warning']) {
1802
+ update_post_meta($image->ID, 'wpms_missing_information', 1);
1803
+ } else {
1804
+ delete_post_meta($image->ID, 'wpms_missing_information');
1805
  }
1806
+ if ($results['msg'][$image->ID]['iNotGood']['warning']) {
1807
+ update_post_meta($image->ID, 'wpms_resizeimages', 1);
1808
+ } else {
1809
+ delete_post_meta($image->ID, 'wpms_resizeimages');
1810
  }
1811
  $k++;
1812
  }
1813
 
1814
  if ($k >= $limit) {
1815
+ wp_send_json(array('status' => 'error_time', 'paged' => $_POST['paged'], 'precent' => $present));
1816
+ } else {
1817
  wp_send_json(array('status' => 'ok'));
1818
  }
1819
  }
1820
 
1821
+ /**
1822
+ * @param $imgs
1823
+ * @param bool $delete
1824
+ * @param int $pid
1825
+ * @return mixed
1826
+ */
1827
+ public static function scanPostsMeta($imgs, $delete = false, $pid = 0)
1828
+ {
1829
  if (!empty($imgs)) {
1830
  if (!is_array($imgs)) {
1831
  $ret['success'] = false;
1843
  return $ret;
1844
  }
1845
 
1846
+ $msg = ImageHelper::IScanPosts($_imgs, $delete, $pid);
1847
  $ret['msg'] = $msg;
1848
  $ret['success'] = true;
1849
  } else {
1854
  return $ret;
1855
  }
1856
 
1857
+ /**
1858
  * update meta missing info and meta resize after delete post
1859
+ * @param $pid
1860
  */
1861
+ public static function deleteAttachment($pid)
1862
+ {
1863
  $post = get_post($pid);
1864
+ if (!empty($post)) {
1865
  $post_type = get_post_type($pid);
1866
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1867
+ if (isset($post_types['attachment'])) {
1868
  unset($post_types['attachment']);
1869
  }
1870
 
1871
  if (in_array($post_type, $post_types)) {
1872
  $dom = new DOMDocument();
1873
+ libxml_use_internal_errors(true);
1874
  @$dom->loadHtml($post->post_content);
1875
  $tags = $dom->getElementsByTagName('img');
1876
+ if (!empty($tags)) {
1877
+ foreach ($tags as $tag) {
1878
  $url = $tag->getAttribute('src');
1879
+ $postid = MetaSeoImageListTable::getAttachmentId($url);
1880
  $path = get_attached_file($postid);
1881
  $infos = pathinfo($path);
1882
  $img_name = $infos['basename'];
1883
+ $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1884
+ $results = MetaSeoImageListTable::scanPostsMeta($imgs, true, $pid);
1885
 
1886
  // update or delete meta
1887
+ if ($results['msg'][$postid]['imNotGood']['warning']) {
1888
+ update_post_meta($postid, 'wpms_missing_information', 1);
1889
+ } else {
1890
+ delete_post_meta($postid, 'wpms_missing_information');
1891
  }
1892
+ if ($results['msg'][$postid]['iNotGood']['warning']) {
1893
+ update_post_meta($postid, 'wpms_resizeimages', 1);
1894
+ } else {
1895
+ delete_post_meta($postid, 'wpms_resizeimages');
1896
  }
 
1897
  }
1898
  }
1899
  }
1900
  }
1901
  }
1902
 
1903
+ /**
1904
  * update meta missing info and meta resize after update post
1905
+ * @param $post_ID
1906
+ * @param $post_after
1907
+ * @param $post_before
1908
  */
1909
+ public static function updatePost($post_ID, $post_after, $post_before)
1910
+ {
1911
+ $old_imgs = MetaSeoImageListTable::getImagesInContent($post_before); // return list img in post before
1912
  $dom = new DOMDocument();
1913
+ libxml_use_internal_errors(true);
1914
  @$dom->loadHtml($post_after->post_content);
1915
  $tags = $dom->getElementsByTagName('img');
1916
  $new_imgs = array(); // return list img in post after
1917
+ if (!empty($tags)) {
1918
+ foreach ($tags as $tag) {
1919
  $url = $tag->getAttribute('src');
1920
+ $postid = MetaSeoImageListTable::getAttachmentId($url);
1921
  $new_imgs[] = $postid;
1922
  $post = get_post($postid);
1923
+ if (!empty($post)) {
1924
  $path = get_attached_file($postid);
1925
  $infos = pathinfo($path);
1926
  $img_name = $infos['basename'];
1927
+ $imgs = array('name' => $img_name, 'img_post_id' => $postid);
1928
+ $results = MetaSeoImageListTable::scanPostsMeta($imgs, false, 0);
1929
 
1930
  // update or delete meta
1931
+ if ($results['msg'][$postid]['imNotGood']['warning']) {
1932
+ update_post_meta($postid, 'wpms_missing_information', 1);
1933
+ } else {
1934
+ delete_post_meta($postid, 'wpms_missing_information');
1935
  }
1936
+ if ($results['msg'][$postid]['iNotGood']['warning']) {
1937
+ update_post_meta($postid, 'wpms_resizeimages', 1);
1938
+ } else {
1939
+ delete_post_meta($postid, 'wpms_resizeimages');
1940
  }
1941
  }
1942
  }
1943
  }
1944
 
1945
  // remove post meta
1946
+ $imgs_diff = array_diff($old_imgs, $new_imgs);
1947
+ if (!empty($imgs_diff)) {
1948
+ foreach ($imgs_diff as $id) {
1949
  $path = get_attached_file($id);
1950
  $infos = pathinfo($path);
1951
  $img_name = $infos['basename'];
1952
+ $imgs = array('name' => $img_name, 'img_post_id' => $id);
1953
+ $results = MetaSeoImageListTable::scanPostsMeta($imgs, true, $post_ID);
1954
 
1955
  // update or delete meta
1956
+ if ($results['msg'][$id]['imNotGood']['warning']) {
1957
+ update_post_meta($id, 'wpms_missing_information', 1);
1958
+ } else {
1959
+ delete_post_meta($id, 'wpms_missing_information');
1960
  }
1961
+ if ($results['msg'][$id]['iNotGood']['warning']) {
1962
+ update_post_meta($id, 'wpms_resizeimages', 1);
1963
+ } else {
1964
+ delete_post_meta($id, 'wpms_resizeimages');
1965
  }
1966
  }
1967
  }
1968
  }
1969
 
1970
+ /**
1971
+ * Get all images id in post content
1972
+ * @param $post_before
1973
+ * @return array
1974
+ */
1975
+ public static function getImagesInContent($post_before)
1976
+ {
1977
  $dom = new DOMDocument();
1978
+ libxml_use_internal_errors(true);
1979
  @$dom->loadHtml($post_before->post_content);
1980
  $tags = $dom->getElementsByTagName('img');
1981
  $ids = array();
1982
+ if (empty($tags)) {
1983
+ return $ids;
1984
+ }
1985
+ foreach ($tags as $tag) {
1986
  $url = $tag->getAttribute('src');
1987
+ $postid = MetaSeoImageListTable::getAttachmentId($url);
1988
  $ids[] = $postid;
1989
  }
1990
  return $ids;
1991
  }
1992
 
1993
+ /**
1994
+ * Get attachment ID
1995
+ * @param $url
1996
+ * @return int
1997
+ */
1998
+ public static function getAttachmentId($url)
1999
+ {
2000
  $attachment_id = 0;
2001
  $dir = wp_upload_dir();
2002
+ if (false !== strpos($url, $dir['baseurl'] . '/')) { // Is URL in uploads directory?
2003
+ $file = basename($url);
2004
  $query_args = array(
2005
+ 'post_type' => 'attachment',
2006
  'post_status' => 'inherit',
2007
+ 'fields' => 'ids',
2008
+ 'meta_query' => array(
2009
  array(
2010
+ 'value' => $file,
2011
  'compare' => 'LIKE',
2012
+ 'key' => '_wp_attachment_metadata',
2013
  ),
2014
  )
2015
  );
2016
+ $query = new WP_Query($query_args);
2017
+ if ($query->have_posts()) {
2018
+ foreach ($query->posts as $post_id) {
2019
+ $meta = wp_get_attachment_metadata($post_id);
2020
+ if (!empty($meta['file']) && !empty($meta['sizes'])) {
2021
+ $original_file = basename($meta['file']);
2022
+ $cropped_image_files = wp_list_pluck($meta['sizes'], 'file');
2023
+ if ($original_file === $file || in_array($file, $cropped_image_files)) {
2024
  $attachment_id = $post_id;
2025
  break;
2026
  }
inc/class.metaseo-link-list-table.php CHANGED
@@ -1,17 +1,27 @@
1
  <?php
2
- /**
3
- * Base class for displaying a list of links in an ajaxified HTML table.
4
- *
5
- */
6
-
7
  if (!class_exists('WP_List_Table')) {
8
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
9
  }
10
  wp_enqueue_style('metaseo-google-icon');
11
 
12
- class MetaSeo_Link_List_Table extends WP_List_Table {
 
 
 
 
 
 
 
 
13
  public $months;
14
- function __construct() {
 
 
 
 
 
15
  parent::__construct(array(
16
  'singular' => 'metaseo_image',
17
  'plural' => 'metaseo_images',
@@ -20,61 +30,67 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
20
  }
21
 
22
  /**
23
- * Generate the table navigation above or below the table
24
- * @param string $which
25
- */
26
- function display_tablenav($which) {
 
27
  ?>
28
  <div class="tablenav <?php echo esc_attr($which); ?>">
29
 
30
- <?php if ($which == 'top'): ?>
31
- <input type="hidden" name="page" value="metaseo_image_meta" />
32
  <div class="alignleft actions bulkactions">
33
- <?php $this->months_fillter('sldate', 'filter_date_action'); ?>
34
- <?php $this->link_source_fillter(); ?>
35
  </div>
36
 
37
- <?php elseif ($which == 'bottom'): ?>
38
- <input type="hidden" name="page" value="metaseo_image_meta" />
39
  <div class="alignleft actions bulkactions">
40
- <?php $this->months_fillter('sldate1', 'filter_date_action'); ?>
41
- <?php $this->link_source_fillter(); ?>
42
  </div>
43
  <?php endif ?>
44
 
45
- <input type="hidden" name="page" value="metaseo_image_meta" />
46
- <?php if (!empty($_REQUEST['post_status'])): ?>
47
- <input type="hidden" name="post_status" value="<?php echo esc_attr($_REQUEST['post_status']); ?>" />
48
  <?php endif ?>
49
 
50
  <div style="float:right;margin-left:8px;">
51
- <input type="number" required min="1" value="<?php echo $this->_pagination_args['per_page'] ?>" maxlength="3" name="metaseo_link_per_page" class="metaseo_imgs_per_page screen-per-page" max="999" min="1" step="1">
52
- <input type="submit" name="btn_perpage" class="button_perpage button" id="button_perpage" value="Apply" >
 
 
 
 
53
  </div>
54
 
55
- <?php if ($which == 'top'): ?>
56
  <div class="alignleft actions bulkactions">
57
- <?php $this->follow_action(); ?>
58
  </div>
59
- <?php elseif ($which == 'bottom'): ?>
60
  <div class="alignleft actions bulkactions">
61
- <?php $this->follow_action(); ?>
62
  </div>
63
- <?php endif ?>
64
 
65
- <?php $this->pagination($which); ?>
66
- <br class="clear" />
67
  </div>
68
 
69
  <?php
70
  }
71
-
72
  /**
73
- * Get an associative array ( id => link ) with the list
74
- * of views available on this table.
75
- * @return array
76
- */
77
- function get_views() {
 
78
  global $wpdb;
79
 
80
 
@@ -87,41 +103,75 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
87
  $states['trash'] = 'trash';
88
  $all_states = "'" . implode("', '", esc_sql($states)) . "'";
89
 
90
- $total_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types)");
 
 
91
 
92
  $class = empty($_REQUEST['post_status']) ? ' class="current"' : '';
93
- $status_links['all'] = "<a href='admin.php?page=metaseo_image_meta'$class>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts'), number_format_i18n($total_posts)) . '</a>';
94
-
 
 
 
 
 
 
 
 
 
95
  foreach (get_post_stati(array('show_in_admin_all_list' => true), 'objects') as $status) {
96
-
97
- $status_name = $status->name;
98
-
99
- $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('$status_name') AND post_type IN ($post_types)");
100
 
101
  if ($total == 0) {
102
  continue;
103
  }
104
 
105
- if (isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status']) {
106
  $class = ' class="current"';
107
  } else {
108
  $class = '';
109
  }
110
 
111
- $status_links[$status_name] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=$status_name'$class>" . sprintf(translate_nooped_plural($status->label_count, $total), number_format_i18n($total)) . '</a>';
 
 
 
 
 
 
 
 
 
 
112
  }
113
- $trashed_posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('trash') AND post_type IN ($post_types)");
114
- $class = ( isset($_REQUEST['post_status']) && 'trash' == $_REQUEST['post_status'] ) ? 'class="current"' : '';
115
- $status_links['trash'] = "<a href='admin.php?page=metaseo_image_meta&amp;post_status=trash'$class>" . sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $trashed_posts, 'posts'), number_format_i18n($trashed_posts)) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  return $status_links;
118
  }
119
-
120
  /**
121
- * Extra controls to be displayed between bulk actions and pagination
122
- * @param string $which
123
- */
124
- function extra_tablenav($which) {
 
125
  echo '<div class="alignleft actions">';
126
  global $wpdb;
127
 
@@ -132,7 +182,8 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
132
  $states['trash'] = 'trash';
133
  $all_states = "'" . implode("', '", $states) . "'";
134
 
135
- $query = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_status IN ($all_states) AND post_type IN ($post_types) ORDER BY 'post_type' ASC";
 
136
  $post_types = $wpdb->get_results($query);
137
 
138
  $selected = !empty($_REQUEST['post_type_filter']) ? $_REQUEST['post_type_filter'] : -1;
@@ -141,18 +192,24 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
141
 
142
  foreach ($post_types as $post_type) {
143
  $obj = get_post_type_object($post_type->post_type);
144
- $options .= sprintf('<option value="%2$s" %3$s>%1$s</option>', $obj->labels->name, $post_type->post_type, selected($selected, $post_type->post_type, false));
 
 
 
 
 
145
  }
146
 
147
  echo "</div>";
148
  }
149
-
150
  /**
151
- * Get a list of columns. The format is:
152
- * 'internal-name' => 'Title'
153
- * @return array
154
- */
155
- function get_columns() {
 
156
  return $columns = array(
157
  'cb' => '<input id="cb-select-all-1" type="checkbox">',
158
  'post_id' => __('Source', 'wp-meta-seo'),
@@ -162,17 +219,18 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
162
  'col_follow' => __('Follow', 'wp-meta-seo')
163
  );
164
  }
165
-
166
  /**
167
- * Get a list of sortable columns. The format is:
168
- * 'internal-name' => 'orderby'
169
- * or
170
- * 'internal-name' => array( 'orderby', true )
171
- *
172
- * The second format will make the initial sorting order be descending
173
- * @return array
174
- */
175
- function get_sortable_columns() {
 
176
  return $sortable = array(
177
  'post_id' => array('post_title', true),
178
  'col_link_url' => array('link_url', true),
@@ -189,26 +247,31 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
189
  *
190
  * @param bool $with_id Whether to set the id attribute or not
191
  */
192
- public function print_column_headers($with_id = true) {
193
- list( $columns, $hidden, $sortable ) = $this->get_column_info();
 
194
 
195
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
196
  $current_url = remove_query_arg('paged', $current_url);
197
 
198
- if (isset($_GET['orderby']))
199
  $current_orderby = $_GET['orderby'];
200
- else
201
  $current_orderby = '';
 
 
202
 
203
- if (isset($_GET['order']) && 'desc' == $_GET['order'])
204
  $current_order = 'desc';
205
- else
206
  $current_order = 'asc';
 
207
 
208
  if (!empty($columns['cb'])) {
209
  static $cb_counter = 1;
210
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All', 'wp-meta-seo') . '</label>'
211
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" style="margin:0;" />';
 
212
  $cb_counter++;
213
  }
214
 
@@ -216,18 +279,20 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
216
  $class = array('manage-column', "column-$column_key");
217
 
218
  $style = '';
219
- if (in_array($column_key, $hidden))
220
  $style = 'display:none;';
 
221
 
222
  $style = ' style="' . $style . '"';
223
 
224
- if ('cb' == $column_key)
225
  $class[] = 'check-column';
226
- elseif (in_array($column_key, array('posts', 'comments', 'links')))
227
  $class[] = 'num';
 
228
 
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';
@@ -239,13 +304,16 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
239
  $class[] = $desc_first ? 'asc' : 'desc';
240
  }
241
 
242
- $column_display_name = '<a href="' . esc_url(add_query_arg(compact('orderby', 'order'), $current_url)) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
 
 
 
243
  }
244
 
245
  $id = $with_id ? "id='$column_key'" : '';
246
-
247
- if (!empty($class))
248
  $class = "class='" . join(' ', $class) . "'";
 
249
 
250
  if ($column_key === 'col_id') {
251
  echo "<th scope='col' $id $class $style colspan=\"1\">$column_display_name</th>";
@@ -260,15 +328,18 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
260
  }
261
  }
262
  }
263
-
264
  /**
265
- * Get months
266
- */
267
- function wpms_get_months(){
 
268
  global $wpdb;
269
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
270
- if (!empty($post_types['attachment']))
271
  unset($post_types['attachment']);
 
 
272
  $p_type = "('" . implode("','", $post_types) . "')";
273
  $months = $wpdb->get_results("
274
  SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
@@ -280,15 +351,16 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
280
  $months = apply_filters('months_dropdown_results', $months, $p_type);
281
  return $months;
282
  }
283
-
284
  /**
285
- * Prepares the list of items for displaying.
286
- * @uses WP_List_Table::set_pagination_args()
287
- */
288
- function prepare_items() {
289
- global $wpdb, $_wp_column_headers;
290
- $this->months = $this->wpms_get_months();
291
-
 
292
  $where = array('1=1');
293
 
294
  $keyword = !empty($_GET["txtkeyword"]) ? $_GET["txtkeyword"] : '';
@@ -309,7 +381,7 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
309
  $orderby = !empty($_GET["orderby"]) ? ($_GET["orderby"]) : 'id';
310
  $order = !empty($_GET["order"]) ? ($_GET["order"]) : 'asc';
311
  $sortable = $this->get_sortable_columns();
312
- $orderby_array = array($orderby,true);
313
  if (in_array($orderby_array, $sortable)) {
314
  $orderStr = $orderby;
315
  } else {
@@ -333,7 +405,7 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
333
  $hidden = array();
334
  $sortable = $this->get_sortable_columns();
335
  $this->_column_headers = array($columns, $hidden, $sortable);
336
-
337
  $query = "SELECT * FROM " . $wpdb->prefix . "wpms_links WHERE " . implode(' AND ', $where) . $orderStr;
338
  if (!empty($_REQUEST['metaseo_broken_link_per_page'])) {
339
  $_per_page = intval($_REQUEST['metaseo_broken_link_per_page']);
@@ -365,7 +437,7 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
365
 
366
  if (!empty($paged) && !empty($per_page)) {
367
  $offset = ($paged - 1) * $per_page;
368
- $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
369
  }
370
 
371
  $this->set_pagination_args(array(
@@ -376,69 +448,108 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
376
 
377
  $this->items = $wpdb->get_results($query);
378
  }
379
-
380
  /**
381
- * Displays the search box.
382
- */
383
- function search_box1() {
384
- if (empty($_REQUEST['txtkeyword']) && !$this->has_items())
 
385
  return;
 
 
386
  $txtkeyword = (!empty($_REQUEST['txtkeyword'])) ? urldecode(stripslashes($_REQUEST['txtkeyword'])) : "";
387
- if (!empty($_REQUEST['orderby']))
388
  echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
389
- if (!empty($_REQUEST['order']))
 
 
390
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
391
- if (!empty($_REQUEST['post_mime_type']))
 
 
392
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
393
- if (!empty($_REQUEST['detached']))
 
 
394
  echo '<input type="hidden" name="detached" value="' . esc_attr($_REQUEST['detached']) . '" />';
 
 
395
  ?>
396
  <p class="search-box">
397
- <input type="search" id="image-search-input" name="txtkeyword" value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>" />
 
 
 
398
  <?php submit_button('Search', 'button', 'search', false, array('id' => 'search-submit')); ?>
399
  </p>
400
  <?php
401
  }
402
-
403
- /* Add fillter follow */
404
- function follow_action() {
 
 
 
405
  ?>
406
- <select name="metaseo_follow_action" class="metaseo_follow_action">
407
- <option value="0"><?php _e('-- Selection --', 'wp-meta-seo') ?></option>
408
- <option value="follow_selected"><?php _e('Follow selected', 'wp-meta-seo') ?></option>
409
- <option value="nofollow_selected"><?php _e('Nofollow selected', 'wp-meta-seo') ?></option>
410
- <option value="follow_all"><?php _e('Follow all', 'wp-meta-seo') ?></option>
411
- <option value="nofollow_all"><?php _e('Nofollow all', 'wp-meta-seo') ?></option>
412
- </select>
413
- <input type="button" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary btn_apply_follow" value="<?php _e('Apply', 'wp-meta-seo') ?>">
414
- <div data-comment_paged="1" data-paged="1" class="wpmsbtn wpmsbtn_small wpms_scan_link page_link_meta"><?php _e('Re-index content links', 'wp-meta-seo') ?></div>
 
 
 
 
 
 
415
  <span class="spinner spinner_apply_follow"></span>
416
  <?php
417
  }
418
-
419
- /* Add fillter link source */
420
- function link_source_fillter() {
 
 
 
421
  if (isset($_GET['metaseo_link_source'])) {
422
  $link_source = $_GET['metaseo_link_source'];
423
  } else {
424
  $link_source = 0;
425
  }
426
  ?>
427
- <select name="metaseo_link_source" class="metaseo_link_source">
428
- <option value="0" <?php selected($link_source, 0) ?>><?php _e('Link source', 'wp-meta-seo') ?></option>
429
- <option value="internal" <?php selected($link_source, 'internal') ?>><?php _e('Internal', 'wp-meta-seo') ?></option>
430
- <option value="external" <?php selected($link_source, 'external') ?>><?php _e('External', 'wp-meta-seo') ?></option>
431
- </select>
 
 
 
 
 
 
 
 
432
  <?php
433
  }
434
-
435
- /* Add fillter months */
436
- function months_fillter($name, $namebutton) {
437
- global $wpdb, $wp_locale;
 
 
 
 
438
  $month_count = count($this->months);
439
 
440
- if (!$month_count || ( 1 == $month_count && 0 == $this->months[0]->month ))
441
  return;
 
442
 
443
  $m = isset($_REQUEST['sldate']) ? $_REQUEST['sldate'] : 0;
444
  ?>
@@ -447,59 +558,61 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
447
  <option<?php selected($m, 0); ?> value="0"><?php _e('All dates', 'wp-meta-seo'); ?></option>
448
  <?php
449
  foreach ($this->months as $arc_row) {
450
-
451
- if (0 == $arc_row->year)
452
  continue;
 
 
453
  $month = zeroise($arc_row->month, 2);
454
  $year = $arc_row->year;
455
- printf("<option %s value='%s' >%s</option>\n", selected($m, "$year-$month", false), esc_attr("$arc_row->year-$month"), sprintf(__('%1$s %2$d', 'wp-meta-seo'), $wp_locale->get_month($month), $year)
 
 
 
 
 
 
 
 
456
  );
457
  }
458
  ?>
459
  </select>
460
- <input type="submit" name="filter_date_action" id="image-submit" class="wpmsbtn wpmsbtn_small wpmsbtn_secondary" value="<?php _e('Filter', 'wp-meta-seo') ?>">
 
461
  <?php
462
  }
463
-
464
  /**
465
- * Generate the table rows
466
- */
467
- function display_rows() {
468
- $url = URL;
469
- $url = preg_replace('/(^(http|https):\/\/[w]*\.*)/', '', $url);
470
  $records = $this->items;
471
- $alternate = "";
472
-
473
- list( $columns, $hidden ) = $this->get_column_info();
474
  if (!empty($records)) {
475
  foreach ($records as $rec) {
476
- echo '<tr id="record_' . $rec->id . '" data-link="' . $rec->id . '" data-post_id="' . $rec->source_id . '">';
 
477
  foreach ($columns as $column_name => $column_display_name) {
478
-
479
- $class = sprintf('class="%1$s column-%1$s"', $column_name);
480
- $style = "";
481
-
482
- if (in_array($column_name, $hidden)) {
483
- $style = ' style="display:none;"';
484
- }
485
-
486
- $attributes = $class . $style;
487
-
488
  switch ($column_name) {
489
  case 'cb':
490
  echo '<td scope="row" class="check-column" style="padding:8px 10px;">';
491
- echo '<input id="cb-select-' . $rec->id . '" class="metaseo_link" type="checkbox" name="link[' . $rec->id . ']" value="' . $rec->id . '">';
 
492
  echo '</td>';
493
  break;
494
 
495
  case 'post_id':
496
  $post = get_post($rec->source_id);
497
  $row_action = array(
498
- 'edit' => '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '" title="Edit this item">Edit</a>',
499
- 'view' => '<a target="_blank" href="' . get_permalink($rec->source_id) . '" title="View &#8220;test&#8221;" rel="permalink">View</a>'
 
 
500
  );
501
  echo '<td class="col_id" colspan="3">';
502
- echo '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '">' . $post->post_title . '</a>';
 
503
  echo $this->row_actions($row_action, false);
504
  echo '</td>';
505
  break;
@@ -512,8 +625,10 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
512
 
513
  case 'col_link_title':
514
  echo '<td colspan="3">';
515
- echo '<input type="text" data-post_id="' . $rec->source_id . '" name="metaseo_link_title" id="metaseo_link_title" class="metaseo_link_title" value="' . $rec->meta_title . '">';
516
- echo '<div data-post_id="' . $rec->source_id . '" class="wpms_update_link">' . __('Update', 'wp-meta-seo') . '</div>';
 
 
517
  echo '<strong class="wpms_mesage_link">' . __('Saved.', 'wp-meta-seo') . '</strong>';
518
  echo '<strong class="wpms_error_mesage_link">' . __('Error.', 'wp-meta-seo') . '</strong>';
519
  echo '</td>';
@@ -525,9 +640,11 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
525
 
526
  case 'col_follow':
527
  if ($rec->follow == 1) {
528
- $follow = '<i class="material-icons wpms_ok wpms_change_follow" data-type="done">done</i>';
 
529
  } else {
530
- $follow = '<i class="material-icons wpms_warning wpms_change_follow" data-type="warning">warning</i>';
 
531
  }
532
  echo '<td colspan="3">' . $follow . '</td>';
533
  break;
@@ -538,17 +655,23 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
538
  }
539
  }
540
  }
541
-
542
- /*
543
  * Retrieves a modified URL query string.
544
  */
545
- public function process_action() {
546
- global $wpdb;
547
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
548
  $redirect = false;
549
 
550
  if (isset($_POST['search']) and $_POST['search'] === 'Search') {
551
- $current_url = add_query_arg(array("search" => "Search", "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))), $current_url);
 
 
 
 
 
 
552
  $redirect = true;
553
  }
554
 
@@ -568,7 +691,11 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
568
  }
569
 
570
  if (!empty($_POST['metaseo_link_per_page'])) {
571
- $current_url = add_query_arg(array("metaseo_link_per_page" => intval($_POST['metaseo_link_per_page'])), $current_url);
 
 
 
 
572
  $redirect = true;
573
  }
574
 
@@ -578,5 +705,4 @@ class MetaSeo_Link_List_Table extends WP_List_Table {
578
  exit();
579
  }
580
  }
581
-
582
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
 
 
4
  if (!class_exists('WP_List_Table')) {
5
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6
  }
7
  wp_enqueue_style('metaseo-google-icon');
8
 
9
+ /**
10
+ * Class MetaSeoLinkListTable
11
+ * Base class for displaying a list of links in an ajaxified HTML table.
12
+ */
13
+ class MetaSeoLinkListTable extends WP_List_Table
14
+ {
15
+ /**
16
+ * @var
17
+ */
18
  public $months;
19
+
20
+ /**
21
+ * MetaSeoLinkListTable constructor.
22
+ */
23
+ public function __construct()
24
+ {
25
  parent::__construct(array(
26
  'singular' => 'metaseo_image',
27
  'plural' => 'metaseo_images',
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'); ?>
52
+ <?php $this->sourceFilter(); ?>
53
  </div>
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>
78
+ <?php endif ?>
79
 
80
+ <?php $this->pagination($which); ?>
81
+ <br class="clear"/>
82
  </div>
83
 
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
 
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
 
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;
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'),
219
  'col_follow' => __('Follow', 'wp-meta-seo')
220
  );
221
  }
222
+
223
  /**
224
+ * Get a list of sortable columns. The format is:
225
+ * 'internal-name' => 'orderby'
226
+ * or
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),
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';
268
+ }
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
 
279
  $class = array('manage-column', "column-$column_key");
280
 
281
  $style = '';
282
+ if (in_array($column_key, $hidden)) {
283
  $style = 'display:none;';
284
+ }
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';
292
+ }
293
 
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';
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>";
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
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"] : '';
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 {
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']);
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(
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
+ }
465
+
466
+ if (!empty($_REQUEST['order'])) {
467
  echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
468
+ }
469
+
470
+ if (!empty($_REQUEST['post_mime_type'])) {
471
  echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($_REQUEST['post_mime_type']) . '" />';
472
+ }
473
+
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>
481
+ <input type="search" id="image-search-input" name="txtkeyword"
482
+ value="<?php echo esc_attr(stripslashes($txtkeyword)); ?>"/>
483
+ </label>
484
  <?php submit_button('Search', 'button', 'search', false, array('id' => 'search-submit')); ?>
485
  </p>
486
  <?php
487
  }
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>
538
  <?php
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
  ?>
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
 
605
  case 'post_id':
606
  $post = get_post($rec->source_id);
607
  $row_action = array(
608
+ 'edit' => '<a target="_blank" href="' . get_edit_post_link($rec->source_id) . '"
609
+ title="Edit this item">Edit</a>',
610
+ 'view' => '<a target="_blank" href="' . get_permalink($rec->source_id) . '"
611
+ title="View &#8220;test&#8221;" rel="permalink">View</a>'
612
  );
613
  echo '<td class="col_id" colspan="3">';
614
+ echo '<a target="_blank"
615
+ href="' . get_edit_post_link($rec->source_id) . '">' . $post->post_title . '</a>';
616
  echo $this->row_actions($row_action, false);
617
  echo '</td>';
618
  break;
625
 
626
  case 'col_link_title':
627
  echo '<td colspan="3">';
628
+ echo '<input type="text" data-post_id="' . $rec->source_id . '" name="metaseo_link_title"
629
+ id="metaseo_link_title" class="metaseo_link_title" value="' . $rec->meta_title . '">';
630
+ echo '<div data-post_id="' . $rec->source_id . '"
631
+ class="wpms_update_link">' . __('Update', 'wp-meta-seo') . '</div>';
632
  echo '<strong class="wpms_mesage_link">' . __('Saved.', 'wp-meta-seo') . '</strong>';
633
  echo '<strong class="wpms_error_mesage_link">' . __('Error.', 'wp-meta-seo') . '</strong>';
634
  echo '</td>';
640
 
641
  case 'col_follow':
642
  if ($rec->follow == 1) {
643
+ $follow = '<i class="material-icons wpms_ok wpms_change_follow"
644
+ data-type="done">done</i>';
645
  } else {
646
+ $follow = '<i class="material-icons wpms_warning wpms_change_follow"
647
+ data-type="warning">warning</i>';
648
  }
649
  echo '<td colspan="3">' . $follow . '</td>';
650
  break;
655
  }
656
  }
657
  }
658
+
659
+ /**
660
  * Retrieves a modified URL query string.
661
  */
662
+ public function processAction()
663
+ {
664
  $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
665
  $redirect = false;
666
 
667
  if (isset($_POST['search']) and $_POST['search'] === 'Search') {
668
+ $current_url = add_query_arg(
669
+ array(
670
+ "search" => "Search",
671
+ "txtkeyword" => urlencode(stripslashes($_POST["txtkeyword"]))
672
+ ),
673
+ $current_url
674
+ );
675
  $redirect = true;
676
  }
677
 
691
  }
692
 
693
  if (!empty($_POST['metaseo_link_per_page'])) {
694
+ $current_url = add_query_arg(
695
+ array(
696
+ "metaseo_link_per_page" => intval($_POST['metaseo_link_per_page'])),
697
+ $current_url
698
+ );
699
  $redirect = true;
700
  }
701
 
705
  exit();
706
  }
707
  }
 
708
  }
inc/class.metaseo-meta.php CHANGED
@@ -1,19 +1,41 @@
1
  <?php
 
 
2
 
3
- /*
 
4
  * This class implements defaults and value validation for all WPMSEO Post Meta values.
5
- *
6
- * Based on some work of Yoast SEO plugin
7
  */
8
-
9
- class WPMSEO_Meta {
10
-
 
 
11
  public static $meta_prefix = '_metaseo_meta';
 
 
 
12
  public static $form_prefix = 'metaseo_wpmseo_';
 
 
 
13
  public static $meta_length = 156;
 
 
 
14
  public static $meta_title_length = 69;
 
 
 
15
  public static $meta_keywords_length = 256;
 
 
 
16
  public static $meta_length_reason = '';
 
 
 
17
  public static $meta_fields = array(
18
  'general' => array(
19
  'snippetpreview' => array(
@@ -113,35 +135,36 @@ class WPMSEO_Meta {
113
  ),
114
  ),
115
  );
 
 
 
116
  public static $fields_index = array();
 
 
 
117
  public static $defaults = array();
118
- private static $social_networks = array(
119
- 'opengraph' => 'opengraph',
120
- 'twitter' => 'twitter',
121
- 'googleplus' => 'google-plus',
122
- );
123
- private static $social_fields = array(
124
- 'title' => 'text',
125
- 'description' => 'textarea',
126
- 'image' => 'upload',
127
- );
128
 
129
- public static function init() {
 
 
 
 
130
  add_filter('update_post_metadata', array(__CLASS__, 'remove_meta_if_default'), 10, 5);
131
  add_filter('add_post_metadata', array(__CLASS__, 'dont_save_meta_if_default'), 10, 4);
132
  }
133
-
134
  /**
135
- * Retrieve the meta box form field definitions for the given tab and post type.
136
- *
137
- * @static
138
- *
139
- * @param string $tab Tab for which to retrieve the field definitions.
140
- * @param string $post_type Post type of the current post.
141
- *
142
- * @return array Array containing the meta box field definitions
143
- */
144
- public static function get_meta_field_defs($tab, $post_type = 'post') {
 
145
  if (!isset(self::$meta_fields[$tab])) {
146
  return array();
147
  }
@@ -156,7 +179,12 @@ class WPMSEO_Meta {
156
  case 'general':
157
  $options = get_option('wpmseo_titles');
158
  if ($options['usemetakeywords'] === true) {
159
- $field_defs['metakeywords']['description'] = sprintf($field_defs['metakeywords']['description'], '<a target="_blank" href="' . esc_url(admin_url('admin.php?page=wpmseo_titles#top#post_types')) . '">', '</a>');
 
 
 
 
 
160
  } else {
161
  unset($field_defs['metakeywords']);
162
  }
@@ -171,33 +199,35 @@ class WPMSEO_Meta {
171
 
172
  return apply_filters('wpmseo_metabox_entries_' . $tab, $field_defs, $post_type);
173
  }
174
-
175
  /**
176
- * Get a custom post meta value
177
- * Returns the default value if the meta value has not been set
178
- *
179
- * @internal Unfortunately there isn't a filter available to hook into before returning the results
180
- * for get_post_meta(), get_post_custom() and the likes. That would have been the preferred solution.
181
- *
182
- * @static
183
- *
184
- * @param string $key Internal key of the value to get (without prefix).
185
- * @param int $postid Post ID of the post to get the value for.
186
- *
187
- * @return string All 'normal' values returned from get_post_meta() are strings.
188
- * Objects and arrays are possible, but not used by this plugin
189
- * and therefore discarted (except when the special 'serialized' field def
190
- * value is set to true - only used by add-on plugins for now).
191
- * Will return the default value if no value was found..
192
- * Will return empty string if no default was found (not one of our keys) or
193
- * if the post does not exist.
194
- */
195
- public static function get_value($key, $postid = 0) {
 
196
  global $post;
197
 
198
  $postid = absint($postid);
199
  if ($postid === 0) {
200
- if (( isset($post) && is_object($post) ) && ( isset($post->post_status) && $post->post_status !== 'auto-draft' )) {
 
201
  $postid = $post->ID;
202
  } else {
203
  return '';
@@ -221,22 +251,20 @@ class WPMSEO_Meta {
221
  return '';
222
  }
223
  }
224
-
225
  /**
226
- * Update a meta value for a post
227
- *
228
- * @static
229
- *
230
- * @param string $key The internal key of the meta value to change (without prefix).
231
- * @param mixed $meta_value The value to set the meta to.
232
- * @param int $post_id The ID of the post to change the meta for.
233
- *
234
- * @return bool whether the value was changed
235
- */
236
- public static function set_value($key, $meta_value, $post_id) {
 
237
  return update_post_meta($post_id, self::$meta_prefix . $key, $meta_value);
238
  }
239
-
240
  }
241
-
242
- /* End of class */
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
 
5
+ /**
6
+ * Class WPMSEOMeta
7
  * This class implements defaults and value validation for all WPMSEO Post Meta values.
8
+ * Based on some work of Yoast SEO plugin
 
9
  */
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 = 156;
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(
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
+ {
152
  add_filter('update_post_metadata', array(__CLASS__, 'remove_meta_if_default'), 10, 5);
153
  add_filter('add_post_metadata', array(__CLASS__, 'dont_save_meta_if_default'), 10, 4);
154
  }
155
+
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
+ */
166
+ public static function getMetaFieldDefs($tab, $post_type = 'post')
167
+ {
168
  if (!isset(self::$meta_fields[$tab])) {
169
  return array();
170
  }
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 . '">',
186
+ '</a>'
187
+ );
188
  } else {
189
  unset($field_defs['metakeywords']);
190
  }
199
 
200
  return apply_filters('wpmseo_metabox_entries_' . $tab, $field_defs, $post_type);
201
  }
202
+
203
  /**
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
217
+ * and therefore discarted (except when the special 'serialized' field def
218
+ * value is set to true - only used by add-on plugins for now).
219
+ * Will return the default value if no value was found..
220
+ * Will return empty string if no default was found (not one of our keys) or
221
+ * if the post does not exist.
222
+ */
223
+ public static function getValue($key, $postid = 0)
224
+ {
225
  global $post;
226
 
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 '';
251
  return '';
252
  }
253
  }
254
+
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
+ {
268
  return update_post_meta($post_id, self::$meta_prefix . $key, $meta_value);
269
  }
 
270
  }
 
 
inc/class.metaseo-metabox.php CHANGED
@@ -1,29 +1,48 @@
1
  <?php
 
 
 
 
 
2
  /**
 
3
  * This class generates the metabox on the edit post / page as well as contains all page analysis functionality.
4
  */
5
-
6
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-meta.php' );
7
- require_once( WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-snippet-preview.php' );
8
-
9
- class WPMSEO_Metabox extends WPMSEO_Meta {
10
-
11
  public $perc_score = 0;
 
 
 
 
 
 
 
 
 
12
 
13
- public function __construct() {
14
- add_action('add_meta_boxes', array($this, 'add_meta_box'));
15
- add_action('admin_enqueue_scripts', array($this, 'metaseo_enqueue'));
16
- add_action('wp_insert_post', array($this, 'metaseo_save_postdata'));
17
- add_action('edit_attachment', array($this, 'metaseo_save_postdata'));
18
- add_action('add_attachment', array($this, 'metaseo_save_postdata'));
19
- add_action('admin_init', array($this, 'translate_meta_boxes'));
20
- }
21
-
22
- /*
23
- * Update post meta data
24
  */
25
- function metaseo_save_postdata($post_id) {
 
 
 
 
 
 
 
 
26
 
 
 
 
 
 
 
27
  if ($post_id === null) {
28
  return false;
29
  }
@@ -42,7 +61,15 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
42
  do_action('wpmseo_save_compare_data', $post);
43
 
44
  $meta_boxes = apply_filters('wpmseo_save_metaboxes', array());
45
- $meta_boxes = array_merge($meta_boxes, $this->get_meta_field_defs('general', $post->post_type), $this->get_meta_field_defs('advanced'), $this->get_meta_field_defs('social'));
 
 
 
 
 
 
 
 
46
  foreach ($meta_boxes as $key => $meta_box) {
47
  $data = null;
48
  if ('checkbox' === $meta_box['type']) {
@@ -53,95 +80,162 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
53
  }
54
  }
55
  if (isset($data)) {
56
- self::set_value($key, $data, $post_id);
57
  }
58
  }
59
  do_action('wpmseo_saved_postdata');
 
60
  }
61
 
62
  /**
63
- * Translate text strings for use in the meta box
64
- */
65
- public static function translate_meta_boxes() {
 
66
  self::$meta_fields['general']['snippetpreview']['title'] = __('Results preview', 'wp-meta-seo');
67
- self::$meta_fields['general']['snippetpreview']['help'] = sprintf(__('This is a preview of what your content will looks like in search engine results: title, description and URL', 'wp-meta-seo'), '<a target="_blank" href="https://www.joomunited.com/wordpress-products/wpms">', '</a>');
 
 
 
 
 
68
 
69
  self::$meta_fields['general']['title']['title'] = __('Search engine title', 'wp-meta-seo');
70
- self::$meta_fields['general']['title']['description'] = sprintf('<span id="metaseo_wpmseo_title-length">%s</span>', self::$meta_length_reason);
71
- self::$meta_fields['general']['title']['help'] = __('This is the title of your content that may be displayed in search engine results (meta title). By default it’s the content title (page title, post title…). 69 characters max allowed.', 'wp-meta-seo');
 
 
 
 
 
72
 
73
  $settings = get_option('_metaseo_settings');
74
  if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
75
  self::$meta_fields['general']['keywords']['title'] = __('Search engine keywords', 'wp-meta-seo');
76
- self::$meta_fields['general']['keywords']['description'] = '<span id="metaseo_wpmseo_keywords-length"></span>';
77
- self::$meta_fields['general']['keywords']['help'] = __('This is the keywords of your content that may be displayed in search engine results (meta keywords).', 'wp-meta-seo');
 
 
78
  } else {
79
  unset(self::$meta_fields['general']['keywords']);
80
  }
81
 
82
 
83
  self::$meta_fields['general']['desc']['title'] = __('Search engine description', 'wp-meta-seo');
84
- self::$meta_fields['general']['desc']['description'] = sprintf('<span id="metaseo_wpmseo_desc-length">%s</span>', self::$meta_length_reason);
85
- self::$meta_fields['general']['desc']['help'] = __('The description of your content that may be displayed in search engine results aka meta description. By default search engine take an excerpt from your content (depending on the search query). 156 characters max allowed.', 'wp-meta-seo');
 
 
 
 
 
 
86
 
87
  self::$meta_fields['social']['opengraph-title']['title'] = __('Facebook Title', 'wp-meta-seo');
88
- self::$meta_fields['social']['opengraph-title']['description'] = __('Custom title to display when sharing this content on facebook, content title override', 'wp-meta-seo');
 
89
 
90
  self::$meta_fields['social']['opengraph-desc']['title'] = __('Facebook Description', 'wp-meta-seo');
91
- self::$meta_fields['social']['opengraph-desc']['description'] = __('Custom description to display when sharing this content on facebook, content description override', 'wp-meta-seo');
 
92
 
93
  self::$meta_fields['social']['opengraph-image']['title'] = __('Facebook Image', 'wp-meta-seo');
94
- self::$meta_fields['social']['opengraph-image']['description'] = __('Custom image to display when sharing this content on facebook, content description override, recommended size is 1200px x 630px', 'wp-meta-seo');
 
95
 
96
  self::$meta_fields['social']['twitter-title']['title'] = __('Twitter Title', 'wp-meta-seo');
97
- self::$meta_fields['social']['twitter-title']['description'] = __('Custom title to display when sharing this content on twitter, content title override', 'wp-meta-seo');
 
98
 
99
  self::$meta_fields['social']['twitter-desc']['title'] = __('Twitter Description', 'wp-meta-seo');
100
- self::$meta_fields['social']['twitter-desc']['description'] = __('Custom description to display when sharing this content on twitter, content description override', 'wp-meta-seo');
 
101
 
102
  self::$meta_fields['social']['twitter-image']['title'] = __('Twitter Image', 'wp-meta-seo');
103
- self::$meta_fields['social']['twitter-image']['description'] = __('Custom image to display when sharing this content on facebook, content description override, recommended min size 440px X 220px', 'wp-meta-seo');
 
104
 
105
  do_action('wpmseo_tab_translate');
106
  }
107
-
108
- /* load script and style */
109
- public function metaseo_enqueue() {
 
 
 
110
  global $pagenow;
111
  if ((!in_array($pagenow, array(
112
- 'post-new.php',
113
- 'post.php',
114
- 'edit.php',
115
- ), true) && apply_filters('wpmseo_always_register_metaboxes_on_admin', false) === false ) || $this->is_metabox_hidden() === true
 
116
  ) {
117
  return;
118
  }
119
 
120
-
121
- $color = get_user_meta(get_current_user_id(), 'admin_color', true);
122
- if ('' == $color || in_array($color, array('classic', 'fresh'), true) === false) {
123
- $color = 'fresh';
124
- }
125
-
126
  if ($pagenow != 'edit.php') {
127
  if (0 != get_queried_object_id()) {
128
- wp_enqueue_media(array('post' => get_queried_object_id())); // Enqueue files needed for upload functionality.
 
 
 
 
 
129
  }
130
- wp_enqueue_style('m-metabox-tabs', plugins_url('css/metabox-tabs.css', WPMSEO_FILE), array(), WPMSEO_VERSION);
131
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', WPMSEO_FILE), array(), WPMSEO_VERSION);
132
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', WPMSEO_FILE), array('jquery'), '2.2.1', true);
133
- wp_enqueue_script('m-wp-seo-metabox', plugins_url('js/wp-metaseo-metabox.js', WPMSEO_FILE), array('jquery', 'jquery-ui-core',), WPMSEO_VERSION, true);
134
- wp_enqueue_script('mwpseo-admin-media', plugins_url('js/wp-metaseo-admin-media.js', WPMSEO_FILE), array('jquery', 'jquery-ui-core',), WPMSEO_VERSION, true);
135
- wp_enqueue_script('metaseo-cliffpyles', plugins_url('js/cliffpyles.js', WPMSEO_FILE), array('jquery'), WPMSEO_VERSION, true);
136
- wp_localize_script('m-wp-seo-metabox', 'wpmseoMetaboxL10n', $this->meta_seo_localize_script());
137
- $localize = $this->metaseo_localize_media_script();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  wp_localize_script('mwpseo-admin-media', 'wpmseoMediaL10n', $localize);
139
  wp_localize_script('metaseo-cliffpyles', 'wpmscliffpyles', $localize);
140
  }
141
  }
142
-
143
- /* Localize a script */
144
- public function metaseo_localize_media_script() {
 
 
 
 
145
  $this->settings = array(
146
  "metaseo_title_home" => "",
147
  "metaseo_desc_home" => "",
@@ -164,45 +258,24 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
164
  'use_validate' => $this->settings['metaseo_seovalidate']
165
  );
166
  }
167
-
168
- /* Localize a script */
169
- public function meta_seo_localize_script() {
170
- $post = $this->get_metabox_post();
171
-
172
- if ((!is_object($post) || !isset($post->post_type) ) || $this->is_metabox_hidden($post->post_type) === true) {
173
- return array();
174
- }
175
-
176
- $options = get_option('wpmseo_titles');
177
 
178
- $date = '';
179
- if (isset($options['showdate-' . $post->post_type]) && $options['showdate-' . $post->post_type] === true) {
180
- $date = $this->get_post_date($post);
 
 
 
 
181
 
182
- self::$meta_length = ( self::$meta_length - ( strlen($date) + 5 ) );
183
- self::$meta_length_reason = __(' (because of date display)', 'wp-meta-seo');
184
  }
185
 
186
  self::$meta_length_reason = apply_filters('wpmseo_desc_length_reason', self::$meta_length_reason, $post);
187
  self::$meta_length = apply_filters('wpmseo_desc_length', self::$meta_length, $post);
188
-
189
- unset($date);
190
-
191
- $title_template = '';
192
- if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') {
193
- $title_template = $options['title-' . $post->post_type];
194
- }
195
-
196
- // If there's no title template set, use the default, otherwise title preview won't work.
197
- if ($title_template == '') {
198
- $title_template = '%%title%% - %%sitename%%';
199
- }
200
 
201
  $desc_template = '';
202
- if (isset($options['desc-' . $post->post_type]) && $options['desc-' . $post->post_type] !== '') {
203
- $desc_template = $options['desc-' . $post->post_type];
204
- }
205
-
206
  $sample_permalink = get_sample_permalink($post->ID);
207
  $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
208
 
@@ -240,59 +313,29 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
240
 
241
  return array_merge($cached_replacement_vars, $array_keyword);
242
  }
243
-
244
- /**
245
- * Test whether the metabox should be hidden either by choice of the admin or because
246
- * the post type is not a public post type
247
- *
248
- * @since 1.5.0
249
- *
250
- * @param string $post_type (optional) The post type to test, defaults to the current post post_type.
251
- *
252
- * @return bool Whether or not the meta box (and associated columns etc) should be hidden
253
- */
254
- function is_metabox_hidden($post_type = null) {
255
- if (!isset($post_type)) {
256
- if (isset($GLOBALS['post']) && ( is_object($GLOBALS['post']) && isset($GLOBALS['post']->post_type) )) {
257
- $post_type = $GLOBALS['post']->post_type;
258
- } elseif (isset($_GET['post_type']) && $_GET['post_type'] !== '') {
259
- $post_type = sanitize_text_field($_GET['post_type']);
260
- }
261
- }
262
 
263
- if (isset($post_type)) {
264
- // Don't make static as post_types may still be added during the run.
265
- $cpts = get_post_types(array('public' => true), 'names');
266
- $options = get_option('wpmseo_titles');
267
-
268
- return ( ( isset($options['hideeditbox-' . $post_type]) && $options['hideeditbox-' . $post_type] === true ) || in_array($post_type, $cpts) === false );
269
- }
270
- return false;
271
- }
272
-
273
  /**
274
- * Adds the Meta SEO meta box to the edit boxes in the edit post / page / cpt pages.
275
- */
276
- public function add_meta_box() {
 
277
  $post_types = get_post_types(array('public' => true));
278
-
279
  if (is_array($post_types) && $post_types !== array()) {
280
  foreach ($post_types as $post_type) {
281
- if ($this->is_metabox_hidden($post_type) === false) {
282
- add_meta_box('wpmseo_meta', __('WP Meta SEO - Page optimization', 'wp-meta-seo'), array(
283
- $this,
284
- 'meta_box',
285
- ), $post_type, 'normal', apply_filters('wpmseo_metabox_prio', 'core'));
286
- }
287
  }
288
  }
289
  }
290
-
291
  /**
292
- * Output the meta box
293
- */
294
- function meta_box() {
295
- $post = $this->get_metabox_post();
 
296
  $default_settings = array(
297
  "metaseo_title_home" => "",
298
  "metaseo_desc_home" => "",
@@ -306,77 +349,85 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
306
  if (is_array($settings)) {
307
  $default_settings = array_merge($default_settings, $settings);
308
  }
 
 
309
  ?>
310
  <div class="wpmseo-metabox-tabs-div">
311
- <ul class="wpmseo-metabox-tabs" id="wpmseo-metabox-tabs">
312
- <li class="general">
313
- <a class="wpmseo_tablink" data-link="wpmseo_general"><?php _e('SEO Page optimization', 'wp-meta-seo'); ?></a>
314
- </li>
315
- <?php
316
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
317
- $service = $this->wpms_server_webmaster();
318
- $check_connected = false;
319
- if(!empty($service)){
320
- // get domain
321
- $option = get_option(WPMS_GSC, array('profile' => ''));
322
- if (!empty($option['profile'])) {
323
- $check_connected = true;
324
- }
325
- }
326
- if($check_connected){
327
- echo '<li class="gsckeywords">';
328
- echo '<a class="wpmseo_tablink" data-link="wpmseo_gsc_keywords">'.__('Search console keywords', 'wp-meta-seo').'</a>';
329
- echo '</li>';
330
  }
331
  }
332
- ?>
333
-
 
 
 
 
 
 
 
334
 
335
- <?php if ((isset($default_settings['metaseo_showsocial']) && $default_settings['metaseo_showsocial'] == 1)): ?>
 
336
  <li class="social">
337
- <a class="wpmseo_tablink" data-link="wpmseo_social"><?php _e('Social for search engine', 'wp-meta-seo') ?></a>
 
338
  </li>
339
- <?php endif; ?>
340
- <?php do_action('wpmseo_tab_header'); ?>
341
- </ul>
342
- <?php
343
- $content = '';
344
- if (is_object($post) && isset($post->post_type)) {
345
- foreach ($this->get_meta_field_defs('general', $post->post_type) as $key => $meta_field) {
346
- $content .= $this->do_meta_box($meta_field, $key);
347
- }
348
- unset($key, $meta_field);
349
  }
350
- $this->do_tab('general', __('General', 'wp-meta-seo'), $content);
351
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
352
- if($check_connected){
353
- echo apply_filters('wpmsaddon_google_search_keywords' , '' ,$post->post_content,$service);
354
- }
 
355
  }
 
356
 
357
 
358
- $content = '';
359
- foreach ($this->get_meta_field_defs('social') as $meta_key => $meta_field) {
360
- $content .= $this->do_meta_box($meta_field, $meta_key);
361
- }
362
 
363
- if ((isset($default_settings['metaseo_showsocial']) && $default_settings['metaseo_showsocial'] == 1)) {
364
- $this->do_tab('social', __('Social', 'wp-meta-seo'), $content);
365
- }
366
 
367
- do_action('wpmseo_tab_content');
368
 
369
  echo '</div>';
370
  }
371
 
372
- public function wpms_server_webmaster() {
 
 
 
 
373
  try {
374
  if (!class_exists('Wpms_Api_Google', false)) {
375
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/google-api/' . 'class-api-google.php';
376
  new Wpms_Api_Google();
377
  }
378
  } catch (Exception $exception) {
379
-
380
  }
381
 
382
  $conn = get_option('wpms_gsc_connect');
@@ -397,27 +448,61 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
397
  );
398
 
399
  $this->client = new Wpms_Api_Google_Client($gsc, 'wpms-gsc', 'https://www.googleapis.com/webmasters/v3/');
400
- if($this->client->getAccessToken() != null) {
401
- $service = new Wpms_Google_Service_Webmasters ($this->client);
402
  return $service;
403
  }
404
  return false;
405
  }
406
-
407
- /*
408
- * return html field settings
 
 
 
 
 
 
409
  */
410
- function metaseo_create_field($data_title, $alt, $dashicon, $label, $value_hidden) {
411
- $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . $data_title . '" alt="' . $alt . '"><i class="metaseo-dashicons material-icons dashicons-before" style="' . ($dashicon == 'done' ? 'color:#46B450' : 'color:#FFB900') . '">' . $dashicon . '</i>' . $label . '</div>';
412
- $output .= '<input type="hidden" class="wpms_analysis_hidden" name="wpms[' . $data_title . ']" value="' . $value_hidden . '">';
 
 
 
 
 
 
 
 
 
 
413
  return $output;
414
  }
415
 
416
- /* load param heading title */
417
- function metaseo_check_headingtitle($post, $meta_title, $tooltip_page, $meta_analysis) {
418
- $words_post_title = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower($post->post_title), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
 
 
 
 
 
 
 
419
  if ($post->post_content == '') {
420
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
421
  return $output;
422
  }
423
  $dom = new DOMDocument;
@@ -425,25 +510,36 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
425
  $content = apply_filters('the_content', $post->post_content);
426
  if ($dom->loadHTML($content)) {
427
  // Extracting the specified elements from the web page
428
- $tags_h1 = $dom->getElementsByTagName('h1');
429
- $tags_h2 = $dom->getElementsByTagName('h2');
430
- $tags_h3 = $dom->getElementsByTagName('h3');
431
- $tags_h4 = $dom->getElementsByTagName('h4');
432
- $tags_h5 = $dom->getElementsByTagName('h5');
433
- $tags_h6 = $dom->getElementsByTagName('h6');
434
 
435
  $test = false;
436
- if (count($tags_h1) == 0 && count($tags_h2) == 0 && count($tags_h3) == 0 && count($tags_h4) == 0 && count($tags_h5) == 0 && count($tags_h6) == 0) {
437
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
438
  } else {
439
  if (!empty($tags_h1)) {
440
  foreach ($tags_h1 as $order => $tagh1) {
441
- $words_tagh1 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh1->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
442
  if (is_array($words_tagh1) && is_array($words_post_title)) {
443
  foreach ($words_tagh1 as $mh) {
444
  if (in_array($mh, $words_post_title) && $mh != '') {
445
  $test = true;
446
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
447
  $this->perc_score++;
448
  return $output;
449
  }
@@ -454,12 +550,23 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
454
 
455
  if (!empty($tags_h2)) {
456
  foreach ($tags_h2 as $order => $tagh2) {
457
- $words_tagh2 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh2->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
458
  if (is_array($words_tagh2) && is_array($words_post_title)) {
459
  foreach ($words_tagh2 as $mh) {
460
  if (in_array($mh, $words_post_title) && $mh != '') {
461
  $test = true;
462
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
463
  $this->perc_score++;
464
  return $output;
465
  }
@@ -470,12 +577,23 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
470
 
471
  if (!empty($tags_h3)) {
472
  foreach ($tags_h3 as $order => $tagh3) {
473
- $words_tagh3 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh3->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
474
  if (is_array($words_tagh3) && is_array($words_post_title)) {
475
  foreach ($words_tagh3 as $mh) {
476
  if (in_array($mh, $words_post_title) && $mh != '') {
477
  $test = true;
478
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
479
  $this->perc_score++;
480
  return $output;
481
  }
@@ -486,12 +604,23 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
486
 
487
  if (!empty($tags_h4)) {
488
  foreach ($tags_h4 as $order => $tagh4) {
489
- $words_tagh4 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh4->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
490
  if (is_array($words_tagh4) && is_array($words_post_title)) {
491
  foreach ($words_tagh4 as $mh) {
492
  if (in_array($mh, $words_post_title) && $mh != '') {
493
  $test = true;
494
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
495
  $this->perc_score++;
496
  return $output;
497
  }
@@ -502,12 +631,23 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
502
 
503
  if (!empty($tags_h5)) {
504
  foreach ($tags_h5 as $order => $tagh5) {
505
- $words_tagh5 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh5->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
506
  if (is_array($words_tagh5) && is_array($words_post_title)) {
507
  foreach ($words_tagh5 as $mh) {
508
  if (in_array($mh, $words_post_title) && $mh != '') {
509
  $test = true;
510
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
511
  $this->perc_score++;
512
  return $output;
513
  }
@@ -518,12 +658,23 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
518
 
519
  if (!empty($tags_h6)) {
520
  foreach ($tags_h6 as $order => $tagh6) {
521
- $words_tagh6 = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', utf8_decode(strtolower($tagh6->nodeValue)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
522
  if (is_array($words_tagh6) && is_array($words_post_title)) {
523
  foreach ($words_tagh6 as $mh) {
524
  if (in_array($mh, $words_post_title) && $mh != '') {
525
  $test = true;
526
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
527
  $this->perc_score++;
528
  return $output;
529
  }
@@ -534,23 +685,58 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
534
  }
535
 
536
  if ($test || (!empty($meta_analysis) && !empty($meta_analysis['heading_title']))) {
537
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'done', __('Page title word in content heading', 'wp-meta-seo'), 1);
 
 
 
 
 
 
538
  $this->perc_score++;
539
  } else {
540
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
541
  }
542
  } else {
543
- $output = $this->metaseo_create_field('heading_title', $tooltip_page['title_in_heading'], 'warning', __('Page title word in content heading', 'wp-meta-seo'), 0);
 
 
 
 
 
 
544
  }
545
 
546
  return $output;
547
  }
548
 
549
- /* load param word content */
550
- function metaseo_check_content($post, $tooltip_page, $meta_analysis) {
 
 
 
 
 
 
 
551
  $content = apply_filters('the_content', $post->post_content);
552
- $words_meta_title = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower($post->post_title), -1, PREG_SPLIT_NO_EMPTY);
553
- $words_post_content = preg_split('/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', strtolower(strip_tags($content)), -1, PREG_SPLIT_NO_EMPTY);
 
 
 
 
 
 
 
 
 
 
554
  $test1 = false;
555
  if (is_array($words_meta_title) && is_array($words_post_content)) {
556
  foreach ($words_meta_title as $mtitle) {
@@ -564,62 +750,153 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
564
  }
565
 
566
  if ($test1 || (!empty($meta_analysis) && !empty($meta_analysis['content_title']))) {
567
- $output = $this->metaseo_create_field('content_title', $tooltip_page['title_in_content'], 'done', __('Page title word in content', 'wp-meta-seo'), 1);
 
 
 
 
 
 
568
  $this->perc_score++;
569
  } else {
570
- $output = $this->metaseo_create_field('content_title', $tooltip_page['title_in_content'], 'warning', __('Page title word in content', 'wp-meta-seo'), 0);
 
 
 
 
 
 
571
  }
572
 
573
  return $output;
574
  }
575
-
576
- /* load param page url */
577
- function metaseo_check_pageurl($post, $tooltip_page, $meta_analysis) {
 
 
 
 
 
 
 
578
  $pageurl = get_permalink($post->ID);
579
  $info = pathinfo($pageurl);
580
 
581
  $page_on_front = get_option('page_on_front');
582
- if(!empty($page_on_front) && $page_on_front == $post->ID){
583
- $output = $this->metaseo_create_field('pageurl', $tooltip_page['page_url'], 'done', __('Page url matches with page title', 'wp-meta-seo'), 1);
 
 
 
 
 
 
584
  $this->perc_score++;
585
- }else{
586
- if ($info['filename'] == sanitize_title($post->post_title) || (!empty($meta_analysis) && !empty($meta_analysis['pageurl']))) {
587
- $output = $this->metaseo_create_field('pageurl', $tooltip_page['page_url'], 'done', __('Page url matches with page title', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
588
  $this->perc_score++;
589
  } else {
590
- $output = $this->metaseo_create_field('pageurl', $tooltip_page['page_url'], 'warning', __('Page url matches with page title', 'wp-meta-seo'), 0);
 
 
 
 
 
 
591
  }
592
  }
593
 
594
  return $output;
595
  }
596
-
597
- /* load param meta title */
598
- function metaseo_check_metatitle($meta_title, $tooltip_page, $meta_analysis) {
599
- if (($meta_title != '' && mb_strlen($meta_title,'UTF-8') <= self::$meta_title_length) || (!empty($meta_analysis) && !empty($meta_analysis['metatitle']))) {
600
- $output = $this->metaseo_create_field('metatitle', $tooltip_page['meta_title'], 'done', __('Meta title filled', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  $this->perc_score++;
602
  } else {
603
- $output = $this->metaseo_create_field('metatitle', $tooltip_page['meta_title'], 'warning', __('Meta title filled', 'wp-meta-seo'), 0);
 
 
 
 
 
 
604
  }
605
  return $output;
606
  }
607
 
608
- /* load param meta description */
609
- function metaseo_check_metadesc($meta_desc, $tooltip_page, $meta_analysis) {
610
- if (($meta_desc != '' && mb_strlen($meta_desc,'UTF-8') <= self::$meta_length) || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
611
- $output = $this->metaseo_create_field('metadesc', $tooltip_page['meta_desc'], 'done', __('Meta description filled', 'wp-meta-seo'), 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  $this->perc_score++;
613
  } else {
614
- $output = $this->metaseo_create_field('metadesc', $tooltip_page['meta_desc'], 'warning', __('Meta description filled', 'wp-meta-seo'), 0);
 
 
 
 
 
 
615
  }
616
  return $output;
617
  }
618
-
619
- /* load param image resize */
620
- function metaseo_check_imageresize($content, $tooltip_page, $meta_analysis) {
 
 
 
 
 
 
 
621
  if ($content == '') {
622
- $output = $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'done', __('Wrong image resize', 'wp-meta-seo'), 1);
 
 
 
 
 
 
623
  $this->perc_score++;
624
  return $output;
625
  }
@@ -637,28 +914,60 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
637
  $string_wh = substr($src, $b + 1, $e - $b - 1);
638
  $array_wh = explode('x', $string_wh);
639
  if (!empty($array_wh[0]) && !empty($array_wh[1])) {
640
- if (((int) $array_wh[0] != (int) $tag->getAttribute('width')) || ((int) $array_wh[1] != (int) $tag->getAttribute('height'))) {
 
641
  $img_wrong = true;
642
  }
643
  }
644
  }
645
 
646
  if ($img_wrong == false || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
647
- $output = $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'done', __('Wrong image resize', 'wp-meta-seo'), 1);
 
 
 
 
 
 
648
  $this->perc_score++;
649
  } else {
650
- $output = $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'warning', __('Wrong image resize', 'wp-meta-seo'), 0);
 
 
 
 
 
 
651
  }
652
  } else {
653
- $output = $this->metaseo_create_field('imgresize', $tooltip_page['image_resize'], 'warning', __('Wrong image resize', 'wp-meta-seo'), 0);
 
 
 
 
 
 
654
  }
655
  return $output;
656
  }
657
-
658
- /* load param image alt */
659
- function metaseo_check_imagealt($content, $tooltip_page, $meta_analysis) {
 
 
 
 
 
 
 
660
  if ($content == '') {
661
- $output = $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'done', __('Image have meta title or alt', 'wp-meta-seo'), 1);
 
 
 
 
 
 
662
  $this->perc_score++;
663
  return $output;
664
  }
@@ -677,49 +986,75 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
677
  }
678
 
679
  if ($img_wrong == false || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
680
- $output = $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'done', __('Image have meta title or alt', 'wp-meta-seo'), 1);
 
 
 
 
 
 
681
  $this->perc_score++;
682
  } else {
683
- $output = $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'warning', __('Image have meta title or alt', 'wp-meta-seo'), 0);
 
 
 
 
 
 
684
  }
685
  } else {
686
- $output = $this->metaseo_create_field('imgalt', $tooltip_page['image_alt'], 'warning', __('Image have meta title or alt', 'wp-meta-seo'), 0);
 
 
 
 
 
 
687
  }
688
  return $output;
689
  }
690
-
691
- /*
692
- * Load page analysis
 
 
693
  */
694
- function metaseo_page_analysis($post) {
 
695
  $tooltip_page = array();
696
- $tooltip_page['title_in_heading'] = __('Check if a word of this content title is also in a title heading (h1, h2...)', 'wp-meta-seo');
697
- $tooltip_page['title_in_content'] = __('Check if a word of this content title is also in the text', 'wp-meta-seo');
 
 
698
  $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
699
  $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
700
  $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
701
- $tooltip_page['image_resize'] = __('Check for image HTML resizing in content (usually image resized using handles)', 'wp-meta-seo');
 
702
  $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
703
 
704
  $meta_title = get_post_meta($post->ID, '_metaseo_metatitle', true);
705
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
706
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
707
- if (empty($meta_analysis))
708
  $meta_analysis = array();
709
- $headingtitle = $this->metaseo_check_headingtitle($post, $meta_title, $tooltip_page, $meta_analysis);
710
- $contenttitle = $this->metaseo_check_content($post, $tooltip_page, $meta_analysis);
711
- $output_pageurl = $this->metaseo_check_pageurl($post, $tooltip_page, $meta_analysis);
712
- $output_metatitle = $this->metaseo_check_metatitle($meta_title, $tooltip_page, $meta_analysis);
713
- $output_metadesc = $this->metaseo_check_metadesc($meta_desc, $tooltip_page, $meta_analysis);
714
- $output_imagewrong = $this->metaseo_check_imageresize($post->post_content, $tooltip_page, $meta_analysis);
715
- $output_imagealt = $this->metaseo_check_imagealt($post->post_content, $tooltip_page, $meta_analysis);
 
 
716
 
717
  $output = '';
718
  $circliful = ceil(100 * ($this->perc_score) / 7);
719
  $output .= '<div style="width:100%;float:left;">';
720
  $output .= '<div class="metaseo_left">
721
  <div class="metaseo-progress-bar" data-post_id="' . $post->ID . '">
722
- <canvas id="inactiveProgress" class="metaseo-progress-inactive" height="275px" width="275px"></canvas>
723
  <canvas id="activeProgress" class="metaseo-progress-active" height="275px" width="275px"></canvas>
724
  <p>0%</p>
725
  </div>
@@ -728,79 +1063,91 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
728
  </div>';
729
 
730
  $output .= '<div class="metaseo_right">';
731
- $output .= $headingtitle . $contenttitle . $output_pageurl . $output_metatitle . $output_metadesc . $output_imagewrong . $output_imagealt;
732
  $output .= '</div>';
733
  $output .= '</div>';
734
  return $output;
735
  }
736
-
737
- /**
738
- * Get a sample permalink based off of the post name.
739
- */
740
- function get_sample_permalink($post) {
741
- if (!function_exists('get_sample_permalink')) {
742
- include_once( ABSPATH . 'wp-admin/includes/post.php' );
743
- }
744
 
745
- return get_sample_permalink($post);
746
- }
747
-
748
- /* Display html content for current tab */
749
- public function do_tab($id, $heading, $content) {
 
 
750
  global $post;
751
  ?>
752
  <div class="wpmseotab <?php echo esc_attr($id) ?>">
753
- <?php if ($id == 'general'): ?>
754
- <p class="reload_analysis"><span class="spinner" style="float: left;"></span><input type="button" name="reload_analysis" id="reload_analysis" class="button button-primary" value="<?php _e('Reload analysis', 'wp-meta-seo'); ?>"></p>
 
 
 
 
755
  <?php endif; ?>
756
  <table class="form-table">
757
  <?php echo $content; ?>
758
  </table>
759
  <?php
760
  if ($id == 'general') {
761
- echo $this->metaseo_page_analysis($post);
762
  $settings = get_option('_metaseo_settings');
763
  if (!empty($settings['metaseo_follow'])) {
764
  $page_follow = get_post_meta($post->ID, '_metaseo_metafollow', true);
765
- $select_follow = '<select class="metaseo_metabox_follow" data-post_id="' . $post->ID . '">';
766
  if ($page_follow == 'nofollow') {
767
- $select_follow .= '<option value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
768
- $select_follow .= '<option selected value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
769
  } else {
770
- $select_follow .= '<option selected value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
771
- $select_follow .= '<option value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
772
  }
773
- $select_follow .= '</select>';
774
- echo '<p><span class="wpmslabel">' . __('Follow', 'wp-meta-seo') . '<i class="material-icons alignright metaseo_help" id="deschelp" alt="' . __('Nofollow provides a way for webmasters to tell search engines: don\'t follow this link. So it may influence the link target’s ranking', 'wp-meta-seo') . '" style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $select_follow . '</p>';
 
 
 
 
775
  }
776
 
777
  if (!empty($settings['metaseo_index'])) {
778
  $page_index = get_post_meta($post->ID, '_metaseo_metaindex', true);
779
- $select_index = '<select class="metaseo_metabox_index" data-post_id="' . $post->ID . '">';
780
  if ($page_index == 'noindex') {
781
- $select_index .= '<option value="index">' . __('Index', 'wp-meta-seo') . '</option>';
782
- $select_index .= '<option selected value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
783
  } else {
784
- $select_index .= '<option selected value="index">' . __('Index', 'wp-meta-seo') . '</option>';
785
- $select_index .= '<option value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
786
  }
787
 
788
- $select_index .= '</select>';
789
- echo '<p><span class="wpmslabel">' . __('Index', 'wp-meta-seo') . '<i class="material-icons alignright metaseo_help" id="deschelp" alt="' . __('Allow search engines robots to index this content, as default your content is indexed', 'wp-meta-seo') . '" style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $select_index . '</p>';
 
 
 
 
790
  }
791
  }
792
  ?>
793
  </div>
794
  <?php
795
  }
796
-
797
- /* Display html content for current tab */
798
- function do_meta_box($meta_field_def, $key = '') {
 
 
 
 
 
 
799
  wp_enqueue_style('metaseo-google-icon');
800
  $content = '';
801
  $esc_form_key = esc_attr(self::$form_prefix . $key);
802
- $post = $this->get_metabox_post();
803
- $meta_value = self::get_value($key, $post->ID);
804
 
805
  $class = '';
806
  if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
@@ -825,7 +1172,9 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
825
  if ($placeholder !== '') {
826
  $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
827
  }
828
- $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . 'name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" class="large-text' . $class . '"/><br />';
 
 
829
  break;
830
 
831
  case 'textarea':
@@ -833,15 +1182,20 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
833
  if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
834
  $rows = $meta_field_def['rows'];
835
  }
836
- $content .= '<textarea class="large-text' . $class . '" rows="' . esc_attr($rows) . '" id="' . $esc_form_key . '" name="' . $esc_form_key . '">' . esc_textarea($meta_value) . '</textarea>';
 
 
837
  break;
838
 
839
  case 'select':
840
- if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
841
- $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '" class="metaseo' . $class . '">';
 
 
842
  foreach ($meta_field_def['options'] as $val => $option) {
843
  $selected = selected($meta_value, $val, false);
844
- $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
 
845
  }
846
  unset($val, $option, $selected);
847
  $content .= '</select>';
@@ -849,25 +1203,29 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
849
  break;
850
 
851
  case 'multiselect':
852
- if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
 
853
  $selected_arr = $meta_value;
854
- if ('meta-robots-adv' === $key) {
855
  $selected_arr = explode(',', $meta_value);
856
  }
857
 
858
  if (!is_array($selected_arr)) {
859
- $selected_arr = (array) $selected_arr;
860
  }
861
 
862
  $options_count = count($meta_field_def['options']);
863
 
864
- $content .= '<select multiple="multiple" size="' . esc_attr($options_count) . '" style="height: ' . esc_attr(( $options_count * 20 ) + 4) . 'px;" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="metaseo' . $class . '">';
 
 
865
  foreach ($meta_field_def['options'] as $val => $option) {
866
  $selected = '';
867
  if (in_array($val, $selected_arr)) {
868
  $selected = ' selected="selected"';
869
  }
870
- $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
 
871
  }
872
  $content .= '</select>';
873
  unset($val, $option, $selected, $selected_arr, $options_count);
@@ -876,48 +1234,64 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
876
 
877
  case 'checkbox':
878
  $checked = checked($meta_value, 'on', false);
879
- $expl = ( isset($meta_field_def['expl']) ) ? esc_html($meta_field_def['expl']) : '';
880
- $content .= '<label for="' . $esc_form_key . '"><input type="checkbox" id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . ' value="on" class="metaseo' . $class . '"/> ' . $expl . '</label><br />';
 
 
881
  unset($checked, $expl);
882
  break;
883
 
884
  case 'radio':
885
- if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
 
886
  foreach ($meta_field_def['options'] as $val => $option) {
887
  $checked = checked($meta_value, $val, false);
888
- $content .= '<input type="radio" ' . $checked . ' id="' . $esc_form_key . '_' . esc_attr($val) . '" name="' . $esc_form_key . '" value="' . esc_attr($val) . '"/> <label for="' . $esc_form_key . '_' . esc_attr($val) . '">' . esc_html($option) . '</label> ';
 
 
 
889
  }
890
  unset($val, $option, $checked);
891
  }
892
  break;
893
 
894
  case 'upload':
895
- $content .= '<input id="' . $esc_form_key . '" type="text" size="36" class="' . $class . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" />';
896
- $content .= '<input id="' . $esc_form_key . '_button" class="wpmseo_image_upload_button button" type="button" value="' . __('Upload Image', 'wp-meta-seo') . '" />';
 
 
897
  break;
898
  }
899
 
900
 
901
  $html = '';
902
  if ($content === '') {
903
- $content = apply_filters('wpmseo_do_meta_box_field_' . $key, $content, $meta_value, $esc_form_key, $meta_field_def, $key);
 
 
 
 
 
 
 
904
  }
905
 
906
  if ($content !== '') {
907
-
908
  $label = esc_html($meta_field_def['title']);
909
  if (in_array($meta_field_def['type'], array(
910
- 'snippetpreview',
911
- 'radio',
912
- 'checkbox',
913
- ), true) === false
914
  ) {
915
  $label = '<label for="' . $esc_form_key . '">' . $label . ':</label>';
916
  }
917
 
918
  $help = '';
919
  if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
920
- $help = '<i class="material-icons alignright metaseo_help" id="' . esc_attr($key . 'help') . '" alt="' . esc_attr($meta_field_def['help']) . '" style="color:#32373C">chat_bubble</i>';
 
 
921
  }
922
 
923
  $html = '
@@ -938,9 +1312,13 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
938
  return $html;
939
  }
940
 
941
- private function get_metabox_post() {
 
 
 
 
942
  if (isset($_GET['post'])) {
943
- $post_id = (int) $_GET['post'];
944
  $post = get_post($post_id);
945
  } else {
946
  $post = $GLOBALS['post'];
@@ -949,15 +1327,17 @@ class WPMSEO_Metabox extends WPMSEO_Meta {
949
  return $post;
950
  }
951
 
952
- function snippet() {
953
- $post = $this->get_metabox_post();
954
- $title = self::get_value('title', $post->ID);
955
- $description = self::get_value('desc', $post->ID);
 
 
 
 
956
 
957
- $snippet_preview = new WPMSEO_Snippet_Preview($post, $title, $description);
958
 
959
- return $snippet_preview->get_content();
960
  }
961
  }
962
-
963
- /* End of class */
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-meta.php');
5
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-snippet-preview.php');
6
+
7
  /**
8
+ * Class WPMSEOMetabox
9
  * This class generates the metabox on the edit post / page as well as contains all page analysis functionality.
10
  */
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
 
27
+ /**
28
+ * WPMSEOMetabox constructor.
 
 
 
 
 
 
 
 
 
29
  */
30
+ public function __construct()
31
+ {
32
+ add_action('add_meta_boxes', array($this, 'addMetaBox'));
33
+ add_action('admin_enqueue_scripts', array($this, 'metaseoEnqueue'));
34
+ add_action('wp_insert_post', array($this, 'savePostData'));
35
+ add_action('edit_attachment', array($this, 'savePostData'));
36
+ add_action('add_attachment', array($this, 'savePostData'));
37
+ add_action('admin_init', array($this, 'translateMetaBoxes'));
38
+ }
39
 
40
+ /**
41
+ * @param $post_id
42
+ * @return bool
43
+ */
44
+ public function savePostData($post_id)
45
+ {
46
  if ($post_id === null) {
47
  return false;
48
  }
61
  do_action('wpmseo_save_compare_data', $post);
62
 
63
  $meta_boxes = apply_filters('wpmseo_save_metaboxes', array());
64
+ $meta_boxes = array_merge(
65
+ $meta_boxes,
66
+ $this->getMetaFieldDefs(
67
+ 'general',
68
+ $post->post_type
69
+ ),
70
+ $this->getMetaFieldDefs('advanced'),
71
+ $this->getMetaFieldDefs('social')
72
+ );
73
  foreach ($meta_boxes as $key => $meta_box) {
74
  $data = null;
75
  if ('checkbox' === $meta_box['type']) {
80
  }
81
  }
82
  if (isset($data)) {
83
+ self::setValue($key, $data, $post_id);
84
  }
85
  }
86
  do_action('wpmseo_saved_postdata');
87
+ return true;
88
  }
89
 
90
  /**
91
+ * Translate text strings for use in the meta box
92
+ */
93
+ public static function translateMetaBoxes()
94
+ {
95
  self::$meta_fields['general']['snippetpreview']['title'] = __('Results preview', 'wp-meta-seo');
96
+ self::$meta_fields['general']['snippetpreview']['help'] = sprintf(
97
+ __('This is a preview of what your content will looks like
98
+ in search engine results: title, description and URL', 'wp-meta-seo'),
99
+ '<a target="_blank" href="https://www.joomunited.com/wordpress-products/wpms">',
100
+ '</a>'
101
+ );
102
 
103
  self::$meta_fields['general']['title']['title'] = __('Search engine title', 'wp-meta-seo');
104
+ self::$meta_fields['general']['title']['description'] = sprintf(
105
+ '<span id="metaseo_wpmseo_title-length">%s</span>',
106
+ self::$meta_length_reason
107
+ );
108
+ self::$meta_fields['general']['title']['help'] = __('This is the title of your content that may be displayed
109
+ in search engine results (meta title). By default it’s the content title (page title, post title…).
110
+ 69 characters max allowed.', 'wp-meta-seo');
111
 
112
  $settings = get_option('_metaseo_settings');
113
  if (isset($settings['metaseo_showkeywords']) && $settings['metaseo_showkeywords'] == 1) {
114
  self::$meta_fields['general']['keywords']['title'] = __('Search engine keywords', 'wp-meta-seo');
115
+ self::$meta_fields['general']['keywords']['description']
116
+ = '<span id="metaseo_wpmseo_keywords-length"></span>';
117
+ self::$meta_fields['general']['keywords']['help'] = __('This is the keywords of your content that may be
118
+ displayed in search engine results (meta keywords).', 'wp-meta-seo');
119
  } else {
120
  unset(self::$meta_fields['general']['keywords']);
121
  }
122
 
123
 
124
  self::$meta_fields['general']['desc']['title'] = __('Search engine description', 'wp-meta-seo');
125
+ self::$meta_fields['general']['desc']['description'] = sprintf(
126
+ '<span id="metaseo_wpmseo_desc-length">%s</span>',
127
+ self::$meta_length_reason
128
+ );
129
+ self::$meta_fields['general']['desc']['help'] = __('The description of your content that may be displayed
130
+ in search engine results aka meta description.
131
+ By default search engine take an excerpt from your content (depending on the search query).
132
+ 156 characters max allowed.', 'wp-meta-seo');
133
 
134
  self::$meta_fields['social']['opengraph-title']['title'] = __('Facebook Title', 'wp-meta-seo');
135
+ self::$meta_fields['social']['opengraph-title']['description'] = __('Custom title to display when
136
+ sharing this content on facebook, content title override', 'wp-meta-seo');
137
 
138
  self::$meta_fields['social']['opengraph-desc']['title'] = __('Facebook Description', 'wp-meta-seo');
139
+ self::$meta_fields['social']['opengraph-desc']['description'] = __('Custom description to display when sharing
140
+ this content on facebook, content description override', 'wp-meta-seo');
141
 
142
  self::$meta_fields['social']['opengraph-image']['title'] = __('Facebook Image', 'wp-meta-seo');
143
+ self::$meta_fields['social']['opengraph-image']['description'] = __('Custom image to display when sharing
144
+ this content on facebook, content description override, recommended size is 1200px x 630px', 'wp-meta-seo');
145
 
146
  self::$meta_fields['social']['twitter-title']['title'] = __('Twitter Title', 'wp-meta-seo');
147
+ self::$meta_fields['social']['twitter-title']['description'] = __('Custom title to display when sharing this
148
+ content on twitter, content title override', 'wp-meta-seo');
149
 
150
  self::$meta_fields['social']['twitter-desc']['title'] = __('Twitter Description', 'wp-meta-seo');
151
+ self::$meta_fields['social']['twitter-desc']['description'] = __('Custom description to display when sharing
152
+ this content on twitter, content description override', 'wp-meta-seo');
153
 
154
  self::$meta_fields['social']['twitter-image']['title'] = __('Twitter Image', 'wp-meta-seo');
155
+ self::$meta_fields['social']['twitter-image']['description'] = __('Custom image to display when sharing
156
+ this content on facebook, content description override, recommended min size 440px X 220px', 'wp-meta-seo');
157
 
158
  do_action('wpmseo_tab_translate');
159
  }
160
+
161
+ /**
162
+ * load script and style
163
+ */
164
+ public function metaseoEnqueue()
165
+ {
166
  global $pagenow;
167
  if ((!in_array($pagenow, array(
168
+ 'post-new.php',
169
+ 'post.php',
170
+ 'edit.php',
171
+ ), true)
172
+ && apply_filters('wpmseo_always_register_metaboxes_on_admin', false) === false)
173
  ) {
174
  return;
175
  }
176
 
 
 
 
 
 
 
177
  if ($pagenow != 'edit.php') {
178
  if (0 != get_queried_object_id()) {
179
+ // Enqueue files needed for upload functionality.
180
+ wp_enqueue_media(
181
+ array(
182
+ 'post' => get_queried_object_id()
183
+ )
184
+ );
185
  }
186
+ wp_enqueue_style(
187
+ 'm-metabox-tabs',
188
+ plugins_url('css/metabox-tabs.css', WPMSEO_FILE),
189
+ array(),
190
+ WPMSEO_VERSION
191
+ );
192
+ wp_enqueue_style(
193
+ 'm-style-qtip',
194
+ plugins_url('css/jquery.qtip.css', WPMSEO_FILE),
195
+ array(),
196
+ WPMSEO_VERSION
197
+ );
198
+ wp_enqueue_script(
199
+ 'jquery-qtip',
200
+ plugins_url('js/jquery.qtip.min.js', WPMSEO_FILE),
201
+ array('jquery'),
202
+ '2.2.1',
203
+ true
204
+ );
205
+ wp_enqueue_script(
206
+ 'm-wp-seo-metabox',
207
+ plugins_url('js/wp-metaseo-metabox.js', WPMSEO_FILE),
208
+ array('jquery', 'jquery-ui-core'),
209
+ WPMSEO_VERSION,
210
+ true
211
+ );
212
+ wp_enqueue_script(
213
+ 'mwpseo-admin-media',
214
+ plugins_url('js/wp-metaseo-admin-media.js', WPMSEO_FILE),
215
+ array('jquery', 'jquery-ui-core'),
216
+ WPMSEO_VERSION,
217
+ true
218
+ );
219
+ wp_enqueue_script(
220
+ 'metaseo-cliffpyles',
221
+ plugins_url('js/cliffpyles.js', WPMSEO_FILE),
222
+ array('jquery'),
223
+ WPMSEO_VERSION,
224
+ true
225
+ );
226
+ wp_localize_script('m-wp-seo-metabox', 'wpmseoMetaboxL10n', $this->localizeScript());
227
+ $localize = $this->localizeSettingsScript();
228
  wp_localize_script('mwpseo-admin-media', 'wpmseoMediaL10n', $localize);
229
  wp_localize_script('metaseo-cliffpyles', 'wpmscliffpyles', $localize);
230
  }
231
  }
232
+
233
+ /**
234
+ * Localize a script
235
+ * @return array
236
+ */
237
+ public function localizeSettingsScript()
238
+ {
239
  $this->settings = array(
240
  "metaseo_title_home" => "",
241
  "metaseo_desc_home" => "",
258
  'use_validate' => $this->settings['metaseo_seovalidate']
259
  );
260
  }
 
 
 
 
 
 
 
 
 
 
261
 
262
+ /**
263
+ * Localize a script
264
+ * @return array
265
+ */
266
+ public function localizeScript()
267
+ {
268
+ $post = $this->getMetaboxPost();
269
 
270
+ if ((!is_object($post) || !isset($post->post_type))) {
271
+ return array();
272
  }
273
 
274
  self::$meta_length_reason = apply_filters('wpmseo_desc_length_reason', self::$meta_length_reason, $post);
275
  self::$meta_length = apply_filters('wpmseo_desc_length', self::$meta_length, $post);
276
+ $title_template = '%%title%% - %%sitename%%';
 
 
 
 
 
 
 
 
 
 
 
277
 
278
  $desc_template = '';
 
 
 
 
279
  $sample_permalink = get_sample_permalink($post->ID);
280
  $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
281
 
313
 
314
  return array_merge($cached_replacement_vars, $array_keyword);
315
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
 
 
 
 
 
 
 
 
 
 
317
  /**
318
+ * Adds the Meta SEO meta box to the edit boxes in the edit post / page / cpt pages.
319
+ */
320
+ public function addMetaBox()
321
+ {
322
  $post_types = get_post_types(array('public' => true));
 
323
  if (is_array($post_types) && $post_types !== array()) {
324
  foreach ($post_types as $post_type) {
325
+ add_meta_box('wpmseo_meta', __('WP Meta SEO - Page optimization', 'wp-meta-seo'), array(
326
+ $this,
327
+ 'metaBox',
328
+ ), $post_type, 'normal', apply_filters('wpmseo_metabox_prio', 'core'));
 
 
329
  }
330
  }
331
  }
332
+
333
  /**
334
+ * Output the meta box
335
+ */
336
+ public function metaBox()
337
+ {
338
+ $post = $this->getMetaboxPost();
339
  $default_settings = array(
340
  "metaseo_title_home" => "",
341
  "metaseo_desc_home" => "",
349
  if (is_array($settings)) {
350
  $default_settings = array_merge($default_settings, $settings);
351
  }
352
+ $check_connected = false;
353
+ $service = false;
354
  ?>
355
  <div class="wpmseo-metabox-tabs-div">
356
+ <ul class="wpmseo-metabox-tabs" id="wpmseo-metabox-tabs">
357
+ <li class="general">
358
+ <a class="wpmseo_tablink"
359
+ data-link="wpmseo_general"><?php _e('SEO Page optimization', 'wp-meta-seo'); ?></a>
360
+ </li>
361
+ <?php
362
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
363
+ $service = $this->serverWebmaster();
364
+ if (!empty($service)) {
365
+ // get domain
366
+ $option = get_option(WPMS_GSC, array('profile' => ''));
367
+ if (!empty($option['profile'])) {
368
+ $check_connected = true;
 
 
 
 
 
 
369
  }
370
  }
371
+ if ($check_connected) {
372
+ echo '<li class="gsckeywords">';
373
+ echo '<a class="wpmseo_tablink" data-link="wpmseo_gsc_keywords">';
374
+ echo __('Search console keywords', 'wp-meta-seo');
375
+ echo '</a>';
376
+ echo '</li>';
377
+ }
378
+ }
379
+ ?>
380
 
381
+ <?php if ((isset($default_settings['metaseo_showsocial'])
382
+ && $default_settings['metaseo_showsocial'] == 1)) : ?>
383
  <li class="social">
384
+ <a class="wpmseo_tablink"
385
+ data-link="wpmseo_social"><?php _e('Social for search engine', 'wp-meta-seo') ?></a>
386
  </li>
387
+ <?php endif; ?>
388
+ <?php do_action('wpmseo_tab_header'); ?>
389
+ </ul>
390
+ <?php
391
+ $content = '';
392
+ if (is_object($post) && isset($post->post_type)) {
393
+ foreach ($this->getMetaFieldDefs('general', $post->post_type) as $key => $meta_field) {
394
+ $content .= $this->doMetaBox($meta_field, $key);
 
 
395
  }
396
+ unset($key, $meta_field);
397
+ }
398
+ $this->doTab('general', $content);
399
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
400
+ if ($check_connected) {
401
+ echo apply_filters('wpmsaddon_google_search_keywords', '', $post->post_content, $service);
402
  }
403
+ }
404
 
405
 
406
+ $content = '';
407
+ foreach ($this->getMetaFieldDefs('social') as $meta_key => $meta_field) {
408
+ $content .= $this->doMetaBox($meta_field, $meta_key);
409
+ }
410
 
411
+ if ((isset($default_settings['metaseo_showsocial']) && $default_settings['metaseo_showsocial'] == 1)) {
412
+ $this->doTab('social', $content);
413
+ }
414
 
415
+ do_action('wpmseo_tab_content');
416
 
417
  echo '</div>';
418
  }
419
 
420
+ /**
421
+ * @return bool|Wpms_Google_Service_Webmasters
422
+ */
423
+ public function serverWebmaster()
424
+ {
425
  try {
426
  if (!class_exists('Wpms_Api_Google', false)) {
427
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/google-api/' . 'class-api-google.php';
428
  new Wpms_Api_Google();
429
  }
430
  } catch (Exception $exception) {
 
431
  }
432
 
433
  $conn = get_option('wpms_gsc_connect');
448
  );
449
 
450
  $this->client = new Wpms_Api_Google_Client($gsc, 'wpms-gsc', 'https://www.googleapis.com/webmasters/v3/');
451
+ if ($this->client->getAccessToken() != null) {
452
+ $service = new Wpms_Google_Service_Webmasters($this->client);
453
  return $service;
454
  }
455
  return false;
456
  }
457
+
458
+ /**
459
+ * Generate html field settings
460
+ * @param $data_title
461
+ * @param $alt
462
+ * @param $dashicon
463
+ * @param $label
464
+ * @param $value_hidden
465
+ * @return string
466
  */
467
+ public function createFieldAnalysis($data_title, $alt, $dashicon, $label, $value_hidden)
468
+ {
469
+ $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . $data_title . '" data-alt="' . $alt . '">';
470
+ if ($dashicon == 'done') {
471
+ $output .= '<i class="metaseo-dashicons material-icons dashicons-before"
472
+ style="color:#46B450")">done</i>' . $label . '</div>';
473
+ } else {
474
+ $output .= '<i class="metaseo-dashicons material-icons dashicons-before"
475
+ style="color:#FFB900")">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 $post
486
+ * @param $tooltip_page
487
+ * @param $meta_analysis
488
+ * @return string
489
+ */
490
+ public function headingTitle($post, $tooltip_page, $meta_analysis)
491
+ {
492
+ $words_post_title = preg_split(
493
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
494
+ strtolower($post->post_title),
495
+ -1,
496
+ PREG_SPLIT_NO_EMPTY
497
+ );
498
  if ($post->post_content == '') {
499
+ $output = $this->createFieldAnalysis(
500
+ 'heading_title',
501
+ $tooltip_page['title_in_heading'],
502
+ 'warning',
503
+ __('Page title word in content heading', 'wp-meta-seo'),
504
+ 0
505
+ );
506
  return $output;
507
  }
508
  $dom = new DOMDocument;
510
  $content = apply_filters('the_content', $post->post_content);
511
  if ($dom->loadHTML($content)) {
512
  // Extracting the specified elements from the web page
513
+ $tags_h1 = (array)$dom->getElementsByTagName('h1');
514
+ $tags_h2 = (array)$dom->getElementsByTagName('h2');
515
+ $tags_h3 = (array)$dom->getElementsByTagName('h3');
516
+ $tags_h4 = (array)$dom->getElementsByTagName('h4');
517
+ $tags_h5 = (array)$dom->getElementsByTagName('h5');
518
+ $tags_h6 = (array)$dom->getElementsByTagName('h6');
519
 
520
  $test = false;
521
+ if (count($tags_h1) == 0 && count($tags_h2) == 0 && count($tags_h3) == 0
522
+ && count($tags_h4) == 0 && count($tags_h5) == 0 && count($tags_h6) == 0) {
523
  } else {
524
  if (!empty($tags_h1)) {
525
  foreach ($tags_h1 as $order => $tagh1) {
526
+ $words_tagh1 = preg_split(
527
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
528
+ utf8_decode(strtolower($tagh1->nodeValue)),
529
+ -1,
530
+ PREG_SPLIT_NO_EMPTY
531
+ );
532
  if (is_array($words_tagh1) && is_array($words_post_title)) {
533
  foreach ($words_tagh1 as $mh) {
534
  if (in_array($mh, $words_post_title) && $mh != '') {
535
  $test = true;
536
+ $output = $this->createFieldAnalysis(
537
+ 'heading_title',
538
+ $tooltip_page['title_in_heading'],
539
+ 'done',
540
+ __('Page title word in content heading', 'wp-meta-seo'),
541
+ 1
542
+ );
543
  $this->perc_score++;
544
  return $output;
545
  }
550
 
551
  if (!empty($tags_h2)) {
552
  foreach ($tags_h2 as $order => $tagh2) {
553
+ $words_tagh2 = preg_split(
554
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
555
+ utf8_decode(strtolower($tagh2->nodeValue)),
556
+ -1,
557
+ PREG_SPLIT_NO_EMPTY
558
+ );
559
  if (is_array($words_tagh2) && is_array($words_post_title)) {
560
  foreach ($words_tagh2 as $mh) {
561
  if (in_array($mh, $words_post_title) && $mh != '') {
562
  $test = true;
563
+ $output = $this->createFieldAnalysis(
564
+ 'heading_title',
565
+ $tooltip_page['title_in_heading'],
566
+ 'done',
567
+ __('Page title word in content heading', 'wp-meta-seo'),
568
+ 1
569
+ );
570
  $this->perc_score++;
571
  return $output;
572
  }
577
 
578
  if (!empty($tags_h3)) {
579
  foreach ($tags_h3 as $order => $tagh3) {
580
+ $words_tagh3 = preg_split(
581
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
582
+ utf8_decode(strtolower($tagh3->nodeValue)),
583
+ -1,
584
+ PREG_SPLIT_NO_EMPTY
585
+ );
586
  if (is_array($words_tagh3) && is_array($words_post_title)) {
587
  foreach ($words_tagh3 as $mh) {
588
  if (in_array($mh, $words_post_title) && $mh != '') {
589
  $test = true;
590
+ $output = $this->createFieldAnalysis(
591
+ 'heading_title',
592
+ $tooltip_page['title_in_heading'],
593
+ 'done',
594
+ __('Page title word in content heading', 'wp-meta-seo'),
595
+ 1
596
+ );
597
  $this->perc_score++;
598
  return $output;
599
  }
604
 
605
  if (!empty($tags_h4)) {
606
  foreach ($tags_h4 as $order => $tagh4) {
607
+ $words_tagh4 = preg_split(
608
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
609
+ utf8_decode(strtolower($tagh4->nodeValue)),
610
+ -1,
611
+ PREG_SPLIT_NO_EMPTY
612
+ );
613
  if (is_array($words_tagh4) && is_array($words_post_title)) {
614
  foreach ($words_tagh4 as $mh) {
615
  if (in_array($mh, $words_post_title) && $mh != '') {
616
  $test = true;
617
+ $output = $this->createFieldAnalysis(
618
+ 'heading_title',
619
+ $tooltip_page['title_in_heading'],
620
+ 'done',
621
+ __('Page title word in content heading', 'wp-meta-seo'),
622
+ 1
623
+ );
624
  $this->perc_score++;
625
  return $output;
626
  }
631
 
632
  if (!empty($tags_h5)) {
633
  foreach ($tags_h5 as $order => $tagh5) {
634
+ $words_tagh5 = preg_split(
635
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
636
+ utf8_decode(strtolower($tagh5->nodeValue)),
637
+ -1,
638
+ PREG_SPLIT_NO_EMPTY
639
+ );
640
  if (is_array($words_tagh5) && is_array($words_post_title)) {
641
  foreach ($words_tagh5 as $mh) {
642
  if (in_array($mh, $words_post_title) && $mh != '') {
643
  $test = true;
644
+ $output = $this->createFieldAnalysis(
645
+ 'heading_title',
646
+ $tooltip_page['title_in_heading'],
647
+ 'done',
648
+ __('Page title word in content heading', 'wp-meta-seo'),
649
+ 1
650
+ );
651
  $this->perc_score++;
652
  return $output;
653
  }
658
 
659
  if (!empty($tags_h6)) {
660
  foreach ($tags_h6 as $order => $tagh6) {
661
+ $words_tagh6 = preg_split(
662
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
663
+ utf8_decode(strtolower($tagh6->nodeValue)),
664
+ -1,
665
+ PREG_SPLIT_NO_EMPTY
666
+ );
667
  if (is_array($words_tagh6) && is_array($words_post_title)) {
668
  foreach ($words_tagh6 as $mh) {
669
  if (in_array($mh, $words_post_title) && $mh != '') {
670
  $test = true;
671
+ $output = $this->createFieldAnalysis(
672
+ 'heading_title',
673
+ $tooltip_page['title_in_heading'],
674
+ 'done',
675
+ __('Page title word in content heading', 'wp-meta-seo'),
676
+ 1
677
+ );
678
  $this->perc_score++;
679
  return $output;
680
  }
685
  }
686
 
687
  if ($test || (!empty($meta_analysis) && !empty($meta_analysis['heading_title']))) {
688
+ $output = $this->createFieldAnalysis(
689
+ 'heading_title',
690
+ $tooltip_page['title_in_heading'],
691
+ 'done',
692
+ __('Page title word in content heading', 'wp-meta-seo'),
693
+ 1
694
+ );
695
  $this->perc_score++;
696
  } else {
697
+ $output = $this->createFieldAnalysis(
698
+ 'heading_title',
699
+ $tooltip_page['title_in_heading'],
700
+ 'warning',
701
+ __('Page title word in content heading', 'wp-meta-seo'),
702
+ 0
703
+ );
704
  }
705
  } else {
706
+ $output = $this->createFieldAnalysis(
707
+ 'heading_title',
708
+ $tooltip_page['title_in_heading'],
709
+ 'warning',
710
+ __('Page title word in content heading', 'wp-meta-seo'),
711
+ 0
712
+ );
713
  }
714
 
715
  return $output;
716
  }
717
 
718
+ /**
719
+ * load meta title in content status in page optimize
720
+ * @param $post
721
+ * @param $tooltip_page
722
+ * @param $meta_analysis
723
+ * @return string
724
+ */
725
+ public function titleContent($post, $tooltip_page, $meta_analysis)
726
+ {
727
  $content = apply_filters('the_content', $post->post_content);
728
+ $words_meta_title = preg_split(
729
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
730
+ strtolower($post->post_title),
731
+ -1,
732
+ PREG_SPLIT_NO_EMPTY
733
+ );
734
+ $words_post_content = preg_split(
735
+ '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/',
736
+ strtolower(strip_tags($content)),
737
+ -1,
738
+ PREG_SPLIT_NO_EMPTY
739
+ );
740
  $test1 = false;
741
  if (is_array($words_meta_title) && is_array($words_post_content)) {
742
  foreach ($words_meta_title as $mtitle) {
750
  }
751
 
752
  if ($test1 || (!empty($meta_analysis) && !empty($meta_analysis['content_title']))) {
753
+ $output = $this->createFieldAnalysis(
754
+ 'content_title',
755
+ $tooltip_page['title_in_content'],
756
+ 'done',
757
+ __('Page title word in content', 'wp-meta-seo'),
758
+ 1
759
+ );
760
  $this->perc_score++;
761
  } else {
762
+ $output = $this->createFieldAnalysis(
763
+ 'content_title',
764
+ $tooltip_page['title_in_content'],
765
+ 'warning',
766
+ __('Page title word in content', 'wp-meta-seo'),
767
+ 0
768
+ );
769
  }
770
 
771
  return $output;
772
  }
773
+
774
+ /**
775
+ * load page url status in page optimize
776
+ * @param $post
777
+ * @param $tooltip_page
778
+ * @param $meta_analysis
779
+ * @return string
780
+ */
781
+ public function pageUrl($post, $tooltip_page, $meta_analysis)
782
+ {
783
  $pageurl = get_permalink($post->ID);
784
  $info = pathinfo($pageurl);
785
 
786
  $page_on_front = get_option('page_on_front');
787
+ if (!empty($page_on_front) && $page_on_front == $post->ID) {
788
+ $output = $this->createFieldAnalysis(
789
+ 'pageurl',
790
+ $tooltip_page['page_url'],
791
+ 'done',
792
+ __('Page url matches with page title', 'wp-meta-seo'),
793
+ 1
794
+ );
795
  $this->perc_score++;
796
+ } else {
797
+ if ($info['filename'] == sanitize_title($post->post_title)
798
+ || (!empty($meta_analysis) && !empty($meta_analysis['pageurl']))) {
799
+ $output = $this->createFieldAnalysis(
800
+ 'pageurl',
801
+ $tooltip_page['page_url'],
802
+ 'done',
803
+ __('Page url matches with page title', 'wp-meta-seo'),
804
+ 1
805
+ );
806
  $this->perc_score++;
807
  } else {
808
+ $output = $this->createFieldAnalysis(
809
+ 'pageurl',
810
+ $tooltip_page['page_url'],
811
+ 'warning',
812
+ __('Page url matches with page title', 'wp-meta-seo'),
813
+ 0
814
+ );
815
  }
816
  }
817
 
818
  return $output;
819
  }
820
+
821
+ /**
822
+ * load meta title status in page optimize
823
+ * @param $meta_title
824
+ * @param $tooltip_page
825
+ * @param $meta_analysis
826
+ * @return string
827
+ */
828
+ public function metaTitle($meta_title, $tooltip_page, $meta_analysis)
829
+ {
830
+ if (($meta_title != '' && mb_strlen($meta_title, 'UTF-8') <= self::$meta_title_length)
831
+ || (!empty($meta_analysis) && !empty($meta_analysis['metatitle']))) {
832
+ $output = $this->createFieldAnalysis(
833
+ 'metatitle',
834
+ $tooltip_page['meta_title'],
835
+ 'done',
836
+ __('Meta title filled', 'wp-meta-seo'),
837
+ 1
838
+ );
839
  $this->perc_score++;
840
  } else {
841
+ $output = $this->createFieldAnalysis(
842
+ 'metatitle',
843
+ $tooltip_page['meta_title'],
844
+ 'warning',
845
+ __('Meta title filled', 'wp-meta-seo'),
846
+ 0
847
+ );
848
  }
849
  return $output;
850
  }
851
 
852
+ /**
853
+ * load meta description status in page optimize
854
+ * @param $meta_desc
855
+ * @param $tooltip_page
856
+ * @param $meta_analysis
857
+ * @return string
858
+ */
859
+ public function metaDesc($meta_desc, $tooltip_page, $meta_analysis)
860
+ {
861
+ if (($meta_desc != '' && mb_strlen($meta_desc, 'UTF-8') <= self::$meta_length)
862
+ || (!empty($meta_analysis) && !empty($meta_analysis['metadesc']))) {
863
+ $output = $this->createFieldAnalysis(
864
+ 'metadesc',
865
+ $tooltip_page['meta_desc'],
866
+ 'done',
867
+ __('Meta description filled', 'wp-meta-seo'),
868
+ 1
869
+ );
870
  $this->perc_score++;
871
  } else {
872
+ $output = $this->createFieldAnalysis(
873
+ 'metadesc',
874
+ $tooltip_page['meta_desc'],
875
+ 'warning',
876
+ __('Meta description filled', 'wp-meta-seo'),
877
+ 0
878
+ );
879
  }
880
  return $output;
881
  }
882
+
883
+ /**
884
+ * load image resize status in page optimize
885
+ * @param $content
886
+ * @param $tooltip_page
887
+ * @param $meta_analysis
888
+ * @return string
889
+ */
890
+ public function imageResize($content, $tooltip_page, $meta_analysis)
891
+ {
892
  if ($content == '') {
893
+ $output = $this->createFieldAnalysis(
894
+ 'imgresize',
895
+ $tooltip_page['image_resize'],
896
+ 'done',
897
+ __('Wrong image resize', 'wp-meta-seo'),
898
+ 1
899
+ );
900
  $this->perc_score++;
901
  return $output;
902
  }
914
  $string_wh = substr($src, $b + 1, $e - $b - 1);
915
  $array_wh = explode('x', $string_wh);
916
  if (!empty($array_wh[0]) && !empty($array_wh[1])) {
917
+ if (((int)$array_wh[0] != (int)$tag->getAttribute('width'))
918
+ || ((int)$array_wh[1] != (int)$tag->getAttribute('height'))) {
919
  $img_wrong = true;
920
  }
921
  }
922
  }
923
 
924
  if ($img_wrong == false || (!empty($meta_analysis) && !empty($meta_analysis['imgresize']))) {
925
+ $output = $this->createFieldAnalysis(
926
+ 'imgresize',
927
+ $tooltip_page['image_resize'],
928
+ 'done',
929
+ __('Wrong image resize', 'wp-meta-seo'),
930
+ 1
931
+ );
932
  $this->perc_score++;
933
  } else {
934
+ $output = $this->createFieldAnalysis(
935
+ 'imgresize',
936
+ $tooltip_page['image_resize'],
937
+ 'warning',
938
+ __('Wrong image resize', 'wp-meta-seo'),
939
+ 0
940
+ );
941
  }
942
  } else {
943
+ $output = $this->createFieldAnalysis(
944
+ 'imgresize',
945
+ $tooltip_page['image_resize'],
946
+ 'warning',
947
+ __('Wrong image resize', 'wp-meta-seo'),
948
+ 0
949
+ );
950
  }
951
  return $output;
952
  }
953
+
954
+ /**
955
+ * load image alt status in page optimize
956
+ * @param $content
957
+ * @param $tooltip_page
958
+ * @param $meta_analysis
959
+ * @return string
960
+ */
961
+ public function imageAlt($content, $tooltip_page, $meta_analysis)
962
+ {
963
  if ($content == '') {
964
+ $output = $this->createFieldAnalysis(
965
+ 'imgalt',
966
+ $tooltip_page['image_alt'],
967
+ 'done',
968
+ __('Image have meta title or alt', 'wp-meta-seo'),
969
+ 1
970
+ );
971
  $this->perc_score++;
972
  return $output;
973
  }
986
  }
987
 
988
  if ($img_wrong == false || (!empty($meta_analysis) && !empty($meta_analysis['imgalt']))) {
989
+ $output = $this->createFieldAnalysis(
990
+ 'imgalt',
991
+ $tooltip_page['image_alt'],
992
+ 'done',
993
+ __('Image have meta title or alt', 'wp-meta-seo'),
994
+ 1
995
+ );
996
  $this->perc_score++;
997
  } else {
998
+ $output = $this->createFieldAnalysis(
999
+ 'imgalt',
1000
+ $tooltip_page['image_alt'],
1001
+ 'warning',
1002
+ __('Image have meta title or alt', 'wp-meta-seo'),
1003
+ 0
1004
+ );
1005
  }
1006
  } else {
1007
+ $output = $this->createFieldAnalysis(
1008
+ 'imgalt',
1009
+ $tooltip_page['image_alt'],
1010
+ 'warning',
1011
+ __('Image have meta title or alt', 'wp-meta-seo'),
1012
+ 0
1013
+ );
1014
  }
1015
  return $output;
1016
  }
1017
+
1018
+ /**
1019
+ * Load page analysis
1020
+ * @param $post
1021
+ * @return string
1022
  */
1023
+ public function pageAnalysis($post)
1024
+ {
1025
  $tooltip_page = array();
1026
+ $tooltip_page['title_in_heading'] = __('Check if a word of this
1027
+ content title is also in a title heading (h1, h2...)', 'wp-meta-seo');
1028
+ $tooltip_page['title_in_content'] = __('Check if a word of this content
1029
+ title is also in the text', 'wp-meta-seo');
1030
  $tooltip_page['page_url'] = __('Does the page title match with the permalink (URL structure)', 'wp-meta-seo');
1031
  $tooltip_page['meta_title'] = __('Is the meta title of this page filled?', 'wp-meta-seo');
1032
  $tooltip_page['meta_desc'] = __('Is the meta description of this page filled?', 'wp-meta-seo');
1033
+ $tooltip_page['image_resize'] = __('Check for image HTML resizing
1034
+ in content (usually image resized using handles)', 'wp-meta-seo');
1035
  $tooltip_page['image_alt'] = __('Check for image Alt text and title', 'wp-meta-seo');
1036
 
1037
  $meta_title = get_post_meta($post->ID, '_metaseo_metatitle', true);
1038
  $meta_desc = get_post_meta($post->ID, '_metaseo_metadesc', true);
1039
  $meta_analysis = get_post_meta($post->ID, 'wpms_validate_analysis', true);
1040
+ if (empty($meta_analysis)) {
1041
  $meta_analysis = array();
1042
+ }
1043
+
1044
+ $headingtitle = $this->headingTitle($post, $tooltip_page, $meta_analysis);
1045
+ $contenttitle = $this->titleContent($post, $tooltip_page, $meta_analysis);
1046
+ $pageurl = $this->pageUrl($post, $tooltip_page, $meta_analysis);
1047
+ $metatitle = $this->metaTitle($meta_title, $tooltip_page, $meta_analysis);
1048
+ $metadesc = $this->metaDesc($meta_desc, $tooltip_page, $meta_analysis);
1049
+ $imagewrong = $this->imageResize($post->post_content, $tooltip_page, $meta_analysis);
1050
+ $imagealt = $this->imageAlt($post->post_content, $tooltip_page, $meta_analysis);
1051
 
1052
  $output = '';
1053
  $circliful = ceil(100 * ($this->perc_score) / 7);
1054
  $output .= '<div style="width:100%;float:left;">';
1055
  $output .= '<div class="metaseo_left">
1056
  <div class="metaseo-progress-bar" data-post_id="' . $post->ID . '">
1057
+ <canvas id="inactiveProgress" class="metaseo-progress-inactive" height="275px" width="275px"></canvas>
1058
  <canvas id="activeProgress" class="metaseo-progress-active" height="275px" width="275px"></canvas>
1059
  <p>0%</p>
1060
  </div>
1063
  </div>';
1064
 
1065
  $output .= '<div class="metaseo_right">';
1066
+ $output .= $headingtitle . $contenttitle . $pageurl . $metatitle . $metadesc . $imagewrong . $imagealt;
1067
  $output .= '</div>';
1068
  $output .= '</div>';
1069
  return $output;
1070
  }
 
 
 
 
 
 
 
 
1071
 
1072
+ /**
1073
+ * Display html content for current tab
1074
+ * @param $id
1075
+ * @param $content
1076
+ */
1077
+ public function doTab($id, $content)
1078
+ {
1079
  global $post;
1080
  ?>
1081
  <div class="wpmseotab <?php echo esc_attr($id) ?>">
1082
+ <?php if ($id == 'general') : ?>
1083
+ <p class="reload_analysis">
1084
+ <span class="spinner" style="float: left;"></span>
1085
+ <input type="button" name="reload_analysis" id="reload_analysis" class="button button-primary"
1086
+ value="<?php _e('Reload analysis', 'wp-meta-seo'); ?>">
1087
+ </p>
1088
  <?php endif; ?>
1089
  <table class="form-table">
1090
  <?php echo $content; ?>
1091
  </table>
1092
  <?php
1093
  if ($id == 'general') {
1094
+ echo $this->pageAnalysis($post);
1095
  $settings = get_option('_metaseo_settings');
1096
  if (!empty($settings['metaseo_follow'])) {
1097
  $page_follow = get_post_meta($post->ID, '_metaseo_metafollow', true);
1098
+ $slf = '<select class="metaseo_metabox_follow" data-post_id="' . $post->ID . '">';
1099
  if ($page_follow == 'nofollow') {
1100
+ $slf .= '<option value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
1101
+ $slf .= '<option selected value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
1102
  } else {
1103
+ $slf .= '<option selected value="follow">' . __('Follow', 'wp-meta-seo') . '</option>';
1104
+ $slf .= '<option value="nofollow">' . __('Nofollow', 'wp-meta-seo') . '</option>';
1105
  }
1106
+ $slf .= '</select>';
1107
+ echo '<p><span class="wpmslabel">' . __('Follow', 'wp-meta-seo') . '
1108
+ <i class="material-icons alignright metaseo_help" id="deschelp"
1109
+ alt="' . __('Nofollow provides a way for webmasters to tell search engines:
1110
+ don\'t follow this link. So it may influence the link target’s ranking', 'wp-meta-seo') . '"
1111
+ style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $slf . '</p>';
1112
  }
1113
 
1114
  if (!empty($settings['metaseo_index'])) {
1115
  $page_index = get_post_meta($post->ID, '_metaseo_metaindex', true);
1116
+ $sli = '<select class="metaseo_metabox_index" data-post_id="' . $post->ID . '">';
1117
  if ($page_index == 'noindex') {
1118
+ $sli .= '<option value="index">' . __('Index', 'wp-meta-seo') . '</option>';
1119
+ $sli .= '<option selected value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
1120
  } else {
1121
+ $sli .= '<option selected value="index">' . __('Index', 'wp-meta-seo') . '</option>';
1122
+ $sli .= '<option value="noindex">' . __('Noindex', 'wp-meta-seo') . '</option>';
1123
  }
1124
 
1125
+ $sli .= '</select>';
1126
+ echo '<p><span class="wpmslabel">' . __('Index', 'wp-meta-seo') . '
1127
+ <i class="material-icons alignright metaseo_help" id="deschelp"
1128
+ alt="' . __('Allow search engines robots to index this content,
1129
+ as default your content is indexed', 'wp-meta-seo') . '"
1130
+ style="color:#32373C" data-hasqtip="2">chat_bubble</i></span>' . $sli . '</p>';
1131
  }
1132
  }
1133
  ?>
1134
  </div>
1135
  <?php
1136
  }
1137
+
1138
+ /**
1139
+ * Display html content for current tab
1140
+ * @param $meta_field_def
1141
+ * @param string $key
1142
+ * @return string
1143
+ */
1144
+ public function doMetaBox($meta_field_def, $key = '')
1145
+ {
1146
  wp_enqueue_style('metaseo-google-icon');
1147
  $content = '';
1148
  $esc_form_key = esc_attr(self::$form_prefix . $key);
1149
+ $post = $this->getMetaboxPost();
1150
+ $meta_value = self::getValue($key, $post->ID);
1151
 
1152
  $class = '';
1153
  if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
1172
  if ($placeholder !== '') {
1173
  $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
1174
  }
1175
+ $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . '
1176
+ name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '"
1177
+ class="large-text' . $class . '"/><br />';
1178
  break;
1179
 
1180
  case 'textarea':
1182
  if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
1183
  $rows = $meta_field_def['rows'];
1184
  }
1185
+ $content .= '<textarea class="large-text' . $class . '"
1186
+ rows="' . esc_attr($rows) . '" id="' . $esc_form_key . '"
1187
+ name="' . $esc_form_key . '">' . esc_textarea($meta_value) . '</textarea>';
1188
  break;
1189
 
1190
  case 'select':
1191
+ if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
1192
+ && $meta_field_def['options'] !== array()) {
1193
+ $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '"
1194
+ class="metaseo' . $class . '">';
1195
  foreach ($meta_field_def['options'] as $val => $option) {
1196
  $selected = selected($meta_value, $val, false);
1197
+ $content .= '<option ' . $selected . '
1198
+ value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
1199
  }
1200
  unset($val, $option, $selected);
1201
  $content .= '</select>';
1203
  break;
1204
 
1205
  case 'multiselect':
1206
+ if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
1207
+ && $meta_field_def['options'] !== array()) {
1208
  $selected_arr = $meta_value;
1209
+ if ('meta-robots-adv' == $key) {
1210
  $selected_arr = explode(',', $meta_value);
1211
  }
1212
 
1213
  if (!is_array($selected_arr)) {
1214
+ $selected_arr = (array)$selected_arr;
1215
  }
1216
 
1217
  $options_count = count($meta_field_def['options']);
1218
 
1219
+ $content .= '<select multiple="multiple" size="' . esc_attr($options_count) . '"
1220
+ style="height: ' . esc_attr(($options_count * 20) + 4) . 'px;"
1221
+ name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="metaseo' . $class . '">';
1222
  foreach ($meta_field_def['options'] as $val => $option) {
1223
  $selected = '';
1224
  if (in_array($val, $selected_arr)) {
1225
  $selected = ' selected="selected"';
1226
  }
1227
+ $content .= '<option ' . $selected . '
1228
+ value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
1229
  }
1230
  $content .= '</select>';
1231
  unset($val, $option, $selected, $selected_arr, $options_count);
1234
 
1235
  case 'checkbox':
1236
  $checked = checked($meta_value, 'on', false);
1237
+ $expl = (isset($meta_field_def['expl'])) ? esc_html($meta_field_def['expl']) : '';
1238
+ $content .= '<label for="' . $esc_form_key . '"><input type="checkbox"
1239
+ id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . '
1240
+ value="on" class="metaseo' . $class . '"/> ' . $expl . '</label><br />';
1241
  unset($checked, $expl);
1242
  break;
1243
 
1244
  case 'radio':
1245
+ if (isset($meta_field_def['options']) && is_array($meta_field_def['options'])
1246
+ && $meta_field_def['options'] !== array()) {
1247
  foreach ($meta_field_def['options'] as $val => $option) {
1248
  $checked = checked($meta_value, $val, false);
1249
+ $content .= '<input type="radio" ' . $checked . '
1250
+ id="' . $esc_form_key . '_' . esc_attr($val) . '" name="' . $esc_form_key . '"
1251
+ value="' . esc_attr($val) . '"/> <label for="' . $esc_form_key . '_' . esc_attr($val) . '">
1252
+ ' . esc_html($option) . '</label> ';
1253
  }
1254
  unset($val, $option, $checked);
1255
  }
1256
  break;
1257
 
1258
  case 'upload':
1259
+ $content .= '<input id="' . $esc_form_key . '" type="text" size="36" class="' . $class . '"
1260
+ name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" />';
1261
+ $content .= '<input id="' . $esc_form_key . '_button" class="wpmseo_image_upload_button button"
1262
+ type="button" value="' . __('Upload Image', 'wp-meta-seo') . '" />';
1263
  break;
1264
  }
1265
 
1266
 
1267
  $html = '';
1268
  if ($content === '') {
1269
+ $content = apply_filters(
1270
+ 'wpmseo_do_meta_box_field_' . $key,
1271
+ $content,
1272
+ $meta_value,
1273
+ $esc_form_key,
1274
+ $meta_field_def,
1275
+ $key
1276
+ );
1277
  }
1278
 
1279
  if ($content !== '') {
 
1280
  $label = esc_html($meta_field_def['title']);
1281
  if (in_array($meta_field_def['type'], array(
1282
+ 'snippetpreview',
1283
+ 'radio',
1284
+ 'checkbox',
1285
+ ), true) === false
1286
  ) {
1287
  $label = '<label for="' . $esc_form_key . '">' . $label . ':</label>';
1288
  }
1289
 
1290
  $help = '';
1291
  if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
1292
+ $help = '<i class="material-icons alignright metaseo_help"
1293
+ id="' . esc_attr($key . 'help') . '" alt="' . esc_attr($meta_field_def['help']) . '"
1294
+ style="color:#32373C">chat_bubble</i>';
1295
  }
1296
 
1297
  $html = '
1312
  return $html;
1313
  }
1314
 
1315
+ /**
1316
+ * @return array|mixed|null|WP_Post
1317
+ */
1318
+ private function getMetaboxPost()
1319
+ {
1320
  if (isset($_GET['post'])) {
1321
+ $post_id = (int)$_GET['post'];
1322
  $post = get_post($post_id);
1323
  } else {
1324
  $post = $GLOBALS['post'];
1327
  return $post;
1328
  }
1329
 
1330
+ /**
1331
+ * @return string
1332
+ */
1333
+ public function snippet()
1334
+ {
1335
+ $post = $this->getMetaboxPost();
1336
+ $title = self::getValue('title', $post->ID);
1337
+ $description = self::getValue('desc', $post->ID);
1338
 
1339
+ $snippet_preview = new WPMSEOSnippetPreview($post, $title, $description);
1340
 
1341
+ return $snippet_preview->getContent();
1342
  }
1343
  }
 
 
inc/class.metaseo-sitemap.php CHANGED
@@ -1,14 +1,44 @@
1
  <?php
 
 
2
 
3
- class MetaSeo_Sitemap {
 
 
 
 
 
4
 
 
 
 
5
  public $html = '';
 
 
 
6
  public $wpms_sitemap_name = 'wpms-sitemap.xml';
 
 
 
7
  public $wpms_sitemap_default_name = 'sitemap.xml';
 
 
 
8
  public $columns = array('Zezo', 'One', 'Two', 'Three');
 
 
 
9
  public $level = array();
 
 
 
 
10
 
11
- function __construct() {
 
 
 
 
12
  $this->settings_sitemap = array(
13
  "wpms_sitemap_add" => 0,
14
  "wpms_sitemap_root" => 0,
@@ -33,11 +63,17 @@ class MetaSeo_Sitemap {
33
  "wpms_sitemap_include_lang" => array()
34
  );
35
 
36
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
37
  $this->settings_sitemap['wpms_sitemap_customUrl'] = array();
38
  $this->settings_sitemap['wpms_display_column_customUrl'] = 1;
39
  $this->settings_sitemap['wpms_public_name_customUrl'] = "";
40
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false, '_builtin' => false));
 
 
 
 
 
 
41
  if (!empty($custom_post_types)) {
42
  foreach ($custom_post_types as $post_type => $label) {
43
  $this->settings_sitemap['wpms_display_column_' . $post_type] = 1;
@@ -48,181 +84,410 @@ class MetaSeo_Sitemap {
48
  }
49
 
50
  $settings = get_option('_metaseo_settings_sitemap');
51
- if(is_object($settings['wpms_sitemap_pages']) || is_object($settings['wpms_sitemap_posts']) || is_object($settings['wpms_sitemap_menus'])){
52
- $settings_array = json_decode(json_encode($settings),true);
53
- update_option('_metaseo_settings_sitemap', $settings_array);
 
54
  }
55
-
56
  $settings = get_option('_metaseo_settings_sitemap');
57
  if (is_array($settings)) {
58
  $this->settings_sitemap = array_merge($this->settings_sitemap, $settings);
59
  }
60
 
61
- add_action('admin_init', array($this, 'metaseo_field_settings_sitemap'));
62
- add_action('admin_enqueue_scripts', array($this, 'metaseo_sitemap_scripts'));
63
- add_action('wp_enqueue_scripts', array($this, 'site_metaseo_sitemap_scripts'));
64
- add_filter('the_content', array($this, 'wpms_html_sitemap_content'));
65
- add_shortcode('wpms_html_sitemap', array($this, 'wpms_sitemap_shortcode'));
66
- add_action('wp_ajax_wpms_regenerate_sitemaps', array($this, 'wpms_regenerate_sitemaps'));
67
- add_action('wp_ajax_wpms_save_sitemap_settings', array($this, 'wpms_save_sitemap_settings'));
68
  }
69
 
70
- /* load metaseo script and style front-end */
71
- public function site_metaseo_sitemap_scripts() {
 
 
 
72
  global $post;
73
- if (empty($post))
74
  return;
75
- if (!empty($this->settings_sitemap) && $this->settings_sitemap['wpms_html_sitemap_page'] != $post->ID)
 
 
76
  return;
77
- wp_enqueue_script('site-jPages-js', plugins_url('js/site-jPages.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
78
- wp_localize_script('site-jPages-js', 'wpms_avarible', $this->wpms_localize_script());
79
- wp_enqueue_script('jpage-js', plugins_url('js/jPages.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
80
- wp_enqueue_style('jpage-css', plugins_url('css/jPages.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
-
83
- /* Localize a script */
84
- public function wpms_localize_script() {
85
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
 
 
 
 
 
 
 
 
 
 
86
  $arrays = array(
87
  'wpms_display_column_menus' => $this->settings_sitemap['wpms_display_column_menus'],
88
  'post_type' => $custom_post_types
89
  );
90
  return $arrays;
91
  }
92
-
93
- /* load metaseo script and style back-end */
94
- public function metaseo_sitemap_scripts() {
 
 
 
95
  global $current_screen;
96
- if (!empty($current_screen) && $current_screen->base != 'wp-meta-seo_page_metaseo_google_sitemap')
97
  return;
 
98
 
99
- wp_enqueue_script('metaseositemap', plugins_url('js/metaseo_sitemap.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
100
- wp_localize_script('metaseositemap', 'wpmseositemap', $this->meta_seo_localize_script());
101
- wp_enqueue_script('jpage-js', plugins_url('js/jPages.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
102
- wp_enqueue_style('metaseositemapstyle', plugins_url('css/metaseo_sitemap.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
103
- wp_enqueue_style('jpage-css', plugins_url('css/jPages.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
104
- wp_enqueue_style('m-style-qtip', plugins_url('css/jquery.qtip.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
105
- wp_enqueue_script('jquery-qtip', plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)), array('jquery'), '2.2.1', true);
106
- }
107
 
108
- /**
109
- * Localize a script.
110
- *
111
- * Works only if the script has already been added.
112
- */
113
- public function meta_seo_localize_script(){
114
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
115
- return array(
116
- 'post_type' => $custom_post_types
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  );
118
  }
119
 
120
- /* Add a new field to a section of a sitemap settings page */
121
- public function metaseo_field_settings_sitemap() {
 
 
 
122
  register_setting('MetaSEO Sitemap', '_metaseo_settings_sitemap');
123
  add_settings_section('metaseo_sitemap', '', array($this, 'showSettingSitemap'), 'metaseo_settings_sitemap');
124
- add_settings_field('wpms_sitemap_link', __('XML sitemap link', 'wp-meta-seo'), array($this, 'wpms_sitemap_link'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('Link to the xml file generated. It’s highly recommended to add this sitemap link to your Google search console', 'wp-meta-seo')));
125
- add_settings_field('wpms_html_sitemap_page', __('HTML Sitemap page', 'wp-meta-seo'), array($this, 'wpms_html_sitemap_page'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('A page is automatically generated to display your HTML sitemap. You can also use any of the existing pages', 'wp-meta-seo')));
126
- add_settings_field('wpms_sitemap_taxonomies', __('Additional content', 'wp-meta-seo'), array($this, 'wpms_sitemap_taxonomies'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('The additional WordPress taxonomies that you want to load in your sitemaps', 'wp-meta-seo')));
127
- add_settings_field('wpms_sitemap_author', __('Display author posts', 'wp-meta-seo'), array($this, 'wpms_sitemap_author'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('You can include a list of posts by author in your sitemaps', 'wp-meta-seo')));
128
- add_settings_field('wpms_html_sitemap_column', __('HTML Sitemap display', 'wp-meta-seo'), array($this, 'wpms_html_sitemap_column'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('Number of columns of the HTML sitemap. You can also setup where your content will be displayed using the tabs above', 'wp-meta-seo')));
129
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
130
- add_settings_field('wpms_html_sitemap_theme', __('HTML Sitemap theme', 'wp-meta-seo'), array($this, 'wpms_html_sitemap_theme'), 'metaseo_settings_sitemap', 'metaseo_sitemap');
131
- }
132
- add_settings_field('wpms_html_sitemap_position', __('HTML Sitemap Position', 'wp-meta-seo'), array($this, 'wpms_html_sitemap_position'), 'metaseo_settings_sitemap', 'metaseo_sitemap');
133
- add_settings_field('wpms_sitemap_add', __('Sitemap and robot.txt', 'wp-meta-seo'), array($this, 'wpms_sitemap_add'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('You can include a link to your xml sitemap in the robot.txt. It helps some search engines to find it', 'wp-meta-seo')));
134
- add_settings_field('wpms_sitemap_root', __('Sitemap root', 'wp-meta-seo'), array($this, 'wpms_sitemap_root'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('Add a copy of the lastest version of your .xml sitemap at the root of your WordPress install named sitemap.xml. Some SEO tools and search engines bots are searching for it.', 'wp-meta-seo')));
135
-
136
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
138
  $label = __('WPML language', 'wp-meta-seo');
139
- add_settings_field('wpms_sitemap_include_lang', $label, array($this, 'wpms_sitemap_include_lang'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('Select a language to include in your sitemap, it will add the relative menu, post, page… content automatically', 'wp-meta-seo')));
140
- }elseif(is_plugin_active('polylang/polylang.php')){
 
 
 
 
 
 
 
 
 
 
141
  $label = __('Polylang language', 'wp-meta-seo');
142
- add_settings_field('wpms_sitemap_include_lang', $label, array($this, 'wpms_sitemap_include_lang'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('Select a language to include in your sitemap, it will add the relative menu, post, page… content automatically', 'wp-meta-seo')));
 
 
 
 
 
 
 
 
 
 
143
  }
144
  }
145
 
146
 
147
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
148
- add_settings_field('wpms_sitemap_link_check', __('Sitemap link check', 'wp-meta-seo'), array($this, 'wpms_sitemap_link_check'), 'metaseo_settings_sitemap', 'metaseo_sitemap', array('label_for' => __('A page is automatically generated to display your HTML sitemap. You can also use any of the existing pages.', 'wp-meta-seo')));
 
 
 
 
 
 
 
 
 
 
149
  }
150
  }
151
 
152
- public function showSettingSitemap() {
153
-
154
  }
155
-
156
- /* Display field sitemap link */
157
- public function wpms_sitemap_link() {
158
- echo '<input id="wpms_check_firstsave" name="_metaseo_settings_sitemap[wpms_check_firstsave]" type="hidden" value="1">';
 
 
 
 
159
  if (is_multisite()) {
160
- $home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\s]/", "_", str_replace('http://', '', str_replace('https://', '', ABSPATH)));
161
- $value = trim(ABSPATH,'/') . '/wpms-sitemap_' . $home_url . '.xml';
 
 
 
 
162
  $link = get_option('siteurl') . '/wpms-sitemap_' . $home_url . '.xml';
163
  } else {
164
- $value = trim(ABSPATH,'/') . '/' . $this->wpms_sitemap_name;
165
  $link = get_option('siteurl') . '/' . $this->wpms_sitemap_name;
166
  }
167
- echo '<input readonly id="wpms_sitemap_link" name="_metaseo_settings_sitemap[wpms_sitemap_link]" type="text" value="' . esc_attr($value) . '" size="50"/>';
 
168
  echo '<a class="button" href="' . $link . '" target="_blank">' . __('Open', 'wp-meta-seo') . '</a>';
169
  }
170
-
171
- /* Display field add sitemap robots */
172
- public function wpms_sitemap_add() {
 
 
 
173
  ?>
174
  <?php if (is_multisite()) { ?>
175
- <div class="pure-checkbox">
176
- <input id="wpms_sitemap_add" disabled="disabled" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_add]" value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
177
- <label for="wpms_sitemap_add"><?php _e("add sitemap file path in robots.txt", 'wp-meta-seo'); ?></label>
178
- </div>
179
- <p style="color:red"><?php _e("Since you are using multisite, the plugin does not allow to add a sitemap to robots.txt", 'wp-meta-seo'); ?></p>
 
 
 
 
 
180
  <?php } else { ?>
181
- <!-- for robots.txt we need to use site_url instead home_url ! -->
182
- <div class="pure-checkbox">
183
- <input id="wpms_sitemap_add" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_add]" value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_add']); ?>>
184
- <label for="wpms_sitemap_add"><?php _e("add sitemap link in the", 'wp-meta-seo'); ?> <a href="<?php echo site_url('/'); ?>robots.txt" target="_new">robots.txt</a></label>
185
- </div>
186
- <?php
187
- }
 
188
  }
189
 
190
- /* Display field sitemap lang */
191
- public function wpms_sitemap_include_lang() {
 
 
 
192
  $lang = $this->settings_sitemap['wpms_sitemap_include_lang'];
193
- $sl_lang = apply_filters('wpms_get_languagesList','',$lang,'multiple');
194
  echo $sl_lang;
195
  }
196
-
197
- /* Display field sitemap root */
198
- public function wpms_sitemap_root() {
 
 
 
199
  ?>
200
  <div class="pure-checkbox">
201
- <input id="wpms_sitemap_root" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_root]" value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_root']); ?>>
 
202
  <label for="wpms_sitemap_root"><?php _e("Add a sitemap.xml copy @ the site root", 'wp-meta-seo'); ?></label>
203
  </div>
204
  <?php
205
  }
206
 
207
- /* Display field sitemap link check */
208
- public function wpms_sitemap_link_check() {
 
 
 
209
  ?>
210
- <input type="button" class="button wpms_run_linkcheck" value="<?php _e('Run a link check', 'wp-meta-seo') ?>"><span class="spinner spinner_run_linkchecker"></span></p>
 
211
  <?php
212
  }
213
 
214
- /* Display field sitemap author */
215
- public function wpms_sitemap_author() {
 
 
 
216
  ?>
217
  <div class="pure-checkbox">
218
- <input id="wpms_sitemap_author" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_author]" value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_author']); ?>>
 
219
  <label for="wpms_sitemap_author"><?php _e("Display author post archive", 'wp-meta-seo'); ?></label>
220
  </div>
221
  <?php
222
  }
223
-
224
- /* Display field sitemap taxonomies */
225
- public function wpms_sitemap_taxonomies() {
 
 
 
226
  $wpms_taxonomies = array(
227
  'category' => 'Post category',
228
  'post_tag' => 'Post tag'
@@ -230,78 +495,134 @@ class MetaSeo_Sitemap {
230
  foreach ($wpms_taxonomies as $key => $value) {
231
  ?>
232
  <div class="pure-checkbox">
233
- <input class="wpms_sitemap_taxonomies" id="wpms_sitemap_taxonomies_<?php echo $key; ?>" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]" value="<?php echo $key ?>" <?php if (in_array($key, $this->settings_sitemap['wpms_sitemap_taxonomies'])) echo 'checked' ?>>
 
 
 
 
 
 
 
 
 
 
234
  <label for="wpms_sitemap_taxonomies_<?php echo $key; ?>"><?php echo $value ?></label>
235
  </div>
236
  <?php
237
  }
238
  }
239
 
240
- /* Display field sitemap list page */
241
- public function wpms_html_sitemap_page() {
 
 
 
242
  global $wpdb;
243
  $pages = get_pages();
244
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s", array("WPMS HTML Sitemap", "metaseo_html_sitemap", "page"));
 
 
 
 
 
 
 
245
  $sitemap_page = $wpdb->get_row($sql);
246
 
247
- if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page))
248
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
 
249
  ?>
250
- <select id="wpms_html_sitemap_page" name="_metaseo_settings_sitemap[wpms_html_sitemap_page]">
251
- <option value="0"><?php _e('- Choose Your Sitemap Page -', 'wp-meta-seo') ?></option>
252
- <?php
253
- foreach ($pages as $page) {
254
- if ($this->settings_sitemap['wpms_html_sitemap_page'] == $page->ID) {
255
- echo '<option selected value="' . $page->ID . '">' . $page->post_title . '</option>';
256
- } else {
257
- echo '<option value="' . $page->ID . '">' . $page->post_title . '</option>';
 
 
258
  }
259
- }
260
- ?>
261
- </select>
262
  <?php
263
  if (!empty($this->settings_sitemap['wpms_html_sitemap_page'])) {
264
- echo '<a class="button" href="' . get_post_permalink($this->settings_sitemap['wpms_html_sitemap_page']) . '" target="_blank">' . __('Open', 'wp-meta-seo') . '</a>';
 
265
  }
266
  }
267
 
268
- /* Display field sitemap column */
269
- public function wpms_html_sitemap_column() {
 
 
 
270
  ?>
271
- <select id="wpms_html_sitemap_column" name="_metaseo_settings_sitemap[wpms_html_sitemap_column]">
272
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 1) ?> value="1"><?php _e('1 column', 'wp-meta-seo') ?></option>
273
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 2) ?> value="2"><?php _e('2 column', 'wp-meta-seo') ?></option>
274
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 3) ?> value="3"><?php _e('3 column', 'wp-meta-seo') ?></option>
275
- </select>
 
 
 
 
 
276
  <?php
277
  }
278
 
279
-
280
- /* Display field sitemap position */
281
- public function wpms_html_sitemap_theme() {
 
 
282
  ?>
283
- <select id="wpms_html_sitemap_theme" name="_metaseo_settings_sitemap[wpms_html_sitemap_theme]">
284
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'default') ?> value="default"><?php _e('Simple list', 'wp-meta-seo') ?></option>
285
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'accordions') ?> value="accordions"><?php _e('List with accordions', 'wp-meta-seo') ?></option>
286
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'tab') ?> value="tab"><?php _e('Tab layout', 'wp-meta-seo') ?></option>
287
- </select>
 
 
 
 
 
288
  <?php
289
  }
290
 
291
- /* Display field sitemap position */
292
- public function wpms_html_sitemap_position() {
 
 
 
293
  ?>
294
- <select id="wpms_html_sitemap_position" name="_metaseo_settings_sitemap[wpms_html_sitemap_position]">
295
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'replace') ?> value="replace"><?php _e('Replace the Page Content', 'wp-meta-seo') ?></option>
296
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'before') ?> value="before"><?php _e('Before Page Content', 'wp-meta-seo') ?></option>
297
- <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'after') ?> value="after"><?php _e('After Page Content', 'wp-meta-seo') ?></option>
298
- </select>
 
 
 
 
 
299
  <?php
300
  }
301
-
302
- function wpms_get_path_filename_sitemap() {
 
 
 
 
 
303
  if (is_multisite()) {
304
- $home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\s]/", "_", str_replace('http://', '', str_replace('https://', '', site_url())));
 
 
 
 
305
  $xml_file = 'wpms-sitemap_' . $home_url . '.xml';
306
  } else {
307
  $xml_file = $this->wpms_sitemap_name;
@@ -309,9 +630,13 @@ class MetaSeo_Sitemap {
309
  $xml_path = ABSPATH . $xml_file;
310
  return array('path' => $xml_path, 'name' => $xml_file);
311
  }
312
-
313
- /* create sitemap */
314
- function metaseo_create_sitemap($sitemap_xml_name) {
 
 
 
 
315
  global $wpdb;
316
  $taxonomies = array();
317
  $list_links = array();
@@ -320,13 +645,21 @@ class MetaSeo_Sitemap {
320
  }
321
 
322
  $xml = new DomDocument('1.0', 'utf-8');
323
- $home_url = site_url('/');
324
  $xml_stylesheet_path = content_url();
325
- $xml_stylesheet_path .= ( defined('WP_PLUGIN_DIR') ) ? '/' . basename(WP_PLUGIN_DIR) . '/wp-meta-seo/wpms-sitemap.xsl' : '/plugins/wp-meta-seo/sitemap.xsl';
 
 
 
 
326
 
327
  $xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"$xml_stylesheet_path\"");
328
  $xml->appendChild($xslt);
329
- $gglstmp_urlset = $xml->appendChild($xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'));
 
 
 
 
 
330
 
331
  /* add home page */
332
  $list_links[] = home_url('/');
@@ -341,18 +674,21 @@ class MetaSeo_Sitemap {
341
  $priority->appendChild($xml->createTextNode(1.0));
342
 
343
  // add menus post custom
344
- $menus = $this->wpms_get_menus_all();
345
  $res = $menus['posts_custom'];
346
  if (!empty($res)) {
347
  foreach ($res as $val) {
348
- $sql = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key=%s AND meta_value=%d", array("_menu_item_object_id", $val->ID));
 
 
 
349
  $menu_object = $wpdb->get_results($sql);
350
  if (!empty($menu_object)) {
351
  foreach ($menu_object as $menu) {
352
- $menu_id = $menu->post_id;
353
- $type = get_post_meta($menu_id, '_menu_item_type', true);
354
- $check_type = get_post_meta($menu_id, '_menu_item_object', true);
355
- $permalink = $this->wpms_get_permalink_sitemap($check_type, $val->ID);
356
  if ($permalink != '#') {
357
  if (!in_array($permalink, $list_links)) {
358
  $list_links[] = $permalink;
@@ -368,23 +704,36 @@ class MetaSeo_Sitemap {
368
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
369
  $changefreq->appendChild($xml->createTextNode('monthly'));
370
  } else {
371
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['frequency'])){
372
- $this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['frequency'] = 'monthly';
373
  }
374
- $changefreq->appendChild($xml->createTextNode($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['frequency']));
 
 
 
 
375
  }
376
 
377
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
378
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
379
  $priority->appendChild($xml->createTextNode('1.0'));
380
  } else {
381
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['priority'])){
382
- $this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['priority'] = '1.0';
383
  }
384
- $priority->appendChild($xml->createTextNode($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['priority']));
 
 
 
 
385
  }
386
 
387
- $this->wpms_create_xml_lang($xml,$menu_id,'wpms_sitemap_menus','post_post',$loc);
 
 
 
 
 
388
  }
389
  }
390
  }
@@ -397,16 +746,24 @@ class MetaSeo_Sitemap {
397
  $res = $menus['categories'];
398
  if (!empty($res)) {
399
  foreach ($res as $k => $val) {
400
- $sql = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key=%s AND meta_value=%d", array("_menu_item_object_id", $val));
 
 
 
 
 
 
401
  $menu_object = $wpdb->get_results($sql);
402
  if (!empty($menu_object)) {
403
  foreach ($menu_object as $menu) {
404
- $menu_id = $menu->post_id;
405
- $type = get_post_meta($menu_id, '_menu_item_type', true);
406
- $check_type = get_post_meta($menu_id, '_menu_item_object', true);
407
- $permalink = get_term_link((int) $val, $check_type);
408
- if (empty($permalink))
409
- $permalink = get_permalink($menu_id);
 
 
410
  if (!in_array($permalink, $list_links)) {
411
  $list_links[] = $permalink;
412
  if ($type == 'taxonomy') {
@@ -414,7 +771,7 @@ class MetaSeo_Sitemap {
414
  $loc = $gglstmp_url->appendChild($xml->createElement('loc'));
415
  $loc->appendChild($xml->createTextNode($permalink));
416
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
417
- $ps = get_post($menu_id);
418
 
419
  if (!empty($ps)) {
420
  $now = $ps->post_modified;
@@ -426,26 +783,26 @@ class MetaSeo_Sitemap {
426
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
427
  $changefreq->appendChild($xml->createTextNode('monthly'));
428
  } else {
429
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['frequency'])){
430
- $menufrequency = 'monthly';
431
- }else{
432
- $menufrequency = $this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['frequency'];
433
  }
434
- $changefreq->appendChild($xml->createTextNode($menufrequency));
435
  }
436
 
437
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
438
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
439
  $priority->appendChild($xml->createTextNode('1.0'));
440
  } else {
441
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['priority'])){
442
  $menupriority = '1.0';
443
- }else{
444
- $menupriority = $this->settings_sitemap['wpms_sitemap_menus'][$menu_id]['priority'];
445
  }
446
  $priority->appendChild($xml->createTextNode($menupriority));
447
  }
448
- $this->wpms_create_xml_lang($xml,$menu_id,'wpms_sitemap_menus','post_post',$loc);
449
  }
450
  }
451
  }
@@ -453,8 +810,8 @@ class MetaSeo_Sitemap {
453
  }
454
  }
455
 
456
- // add posts
457
- $res = $this->wpms_get_posts_sitemap();
458
  if (!empty($res)) {
459
  foreach ($res as $val) {
460
  /* get translation post id */
@@ -472,9 +829,9 @@ class MetaSeo_Sitemap {
472
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
473
  $changefreq->appendChild($xml->createTextNode('monthly'));
474
  } else {
475
- if(empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency'])){
476
  $postfrequency = 'monthly';
477
- }else{
478
  $postfrequency = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency'];
479
  }
480
  $changefreq->appendChild($xml->createTextNode($postfrequency));
@@ -484,29 +841,35 @@ class MetaSeo_Sitemap {
484
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
485
  $priority->appendChild($xml->createTextNode('1.0'));
486
  } else {
487
- if(empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority'])){
488
  $postpriority = '1.0';
489
- }else{
490
  $postpriority = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority'];
491
  }
492
  $priority->appendChild($xml->createTextNode($postpriority));
493
  }
494
 
495
- $this->wpms_create_xml_lang($xml,$val->ID,'wpms_sitemap_posts','post_post',$loc);
496
  }
497
  }
498
  }
499
 
500
  // run when WP Meta SEO Addon active
501
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
502
  // add custom post type
503
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
504
- if(!empty($custom_post_types)) {
505
- foreach ($custom_post_types as $post_type => $label) {
 
 
 
 
 
 
506
  $ids = array(0);
507
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
508
- if (!empty($settings_sitemap['wpms_sitemap_'.$post_type])) {
509
- foreach ((array) $settings_sitemap['wpms_sitemap_'.$post_type] as $k => $v) {
510
  if (!empty($v['post_id'])) {
511
  $ids[] = $v['post_id'];
512
  }
@@ -515,7 +878,7 @@ class MetaSeo_Sitemap {
515
 
516
  $args = array(
517
  'posts_per_page' => -1,
518
- 'post_type' => $post_type,
519
  'post__in' => $ids,
520
  'post_status' => 'any'
521
  );
@@ -537,40 +900,44 @@ class MetaSeo_Sitemap {
537
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
538
  $changefreq->appendChild($xml->createTextNode('monthly'));
539
  } else {
540
- if(empty($this->settings_sitemap['wpms_sitemap_'.$post_type][$val->ID]['frequency'])){
541
- $postfrequency = 'monthly';
542
- }else{
543
- $postfrequency = $this->settings_sitemap['wpms_sitemap_'.$post_type][$val->ID]['frequency'];
544
  }
545
- $changefreq->appendChild($xml->createTextNode($postfrequency));
546
  }
547
 
548
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
549
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
550
  $priority->appendChild($xml->createTextNode('1.0'));
551
  } else {
552
- if(empty($this->settings_sitemap['wpms_sitemap_'.$post_type][$val->ID]['priority'])){
553
- $postpriority = '1.0';
554
- }else{
555
- $postpriority = $this->settings_sitemap['wpms_sitemap_'.$post_type][$val->ID]['priority'];
556
  }
557
- $priority->appendChild($xml->createTextNode($postpriority));
558
  }
559
 
560
- $this->wpms_create_xml_lang($xml,$val->ID,'wpms_sitemap_'.$post_type,'post_post',$loc);
 
 
 
 
 
561
  }
562
  }
563
  }
564
-
565
  }
566
  }
567
 
568
  // add custom Url
569
  $listUrls = get_option('wpms_customUrls_list');
570
  $settings = get_option('_metaseo_settings_sitemap');
571
- if(!empty($settings['wpms_sitemap_customUrl'])){
572
- foreach ($settings['wpms_sitemap_customUrl'] as $key => $customUrl){
573
- if(!empty($listUrls[$key])){
574
  if (!in_array($listUrls[$key]['link'], $list_links)) {
575
  $list_links[] = $listUrls[$key]['link'];
576
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
@@ -578,23 +945,22 @@ class MetaSeo_Sitemap {
578
 
579
  $loc->appendChild($xml->createTextNode($listUrls[$key]['link']));
580
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
581
- $now = $val->post_modified;
582
- $date = date('Y-m-d\TH:i:sP', strtotime($now));
583
  $lastmod->appendChild($xml->createTextNode($date));
584
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
585
 
586
- if(empty($customUrl['frequency'])){
587
  $pagefrequency = 'monthly';
588
- }else{
589
  $pagefrequency = $customUrl['frequency'];
590
  }
591
  $changefreq->appendChild($xml->createTextNode($pagefrequency));
592
 
593
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
594
 
595
- if(empty($customUrl['priority'])){
596
  $pagepriority = '1.0';
597
- }else{
598
  $pagepriority = $customUrl['priority'];
599
  }
600
  $priority->appendChild($xml->createTextNode($pagepriority));
@@ -604,11 +970,9 @@ class MetaSeo_Sitemap {
604
  }
605
  }
606
  // ========================================
607
-
608
- // add pages
609
- $res = $this->wpms_get_pages_sitemap();
610
  if (!empty($res)) {
611
- $page_on_front = get_option('page_on_front');
612
  foreach ($res as $val) {
613
  /* get translation post id */
614
  $permalink = get_permalink($val->ID);
@@ -626,9 +990,9 @@ class MetaSeo_Sitemap {
626
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
627
  $changefreq->appendChild($xml->createTextNode('monthly'));
628
  } else {
629
- if(empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency'])){
630
  $pagefrequency = 'monthly';
631
- }else{
632
  $pagefrequency = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency'];
633
  }
634
  $changefreq->appendChild($xml->createTextNode($pagefrequency));
@@ -637,15 +1001,15 @@ class MetaSeo_Sitemap {
637
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
638
  $priority->appendChild($xml->createTextNode('1.0'));
639
  } else {
640
- if(empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority'])){
641
  $pagepriority = '1.0';
642
- }else{
643
  $pagepriority = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority'];
644
  }
645
  $priority->appendChild($xml->createTextNode($pagepriority));
646
  }
647
 
648
- $this->wpms_create_xml_lang($xml,$val->ID,'wpms_sitemap_pages','post_page',$loc);
649
  }
650
  }
651
  }
@@ -656,7 +1020,7 @@ class MetaSeo_Sitemap {
656
  $terms = get_terms($value, 'hide_empty=1');
657
  if (!empty($terms) && !is_wp_error($terms)) {
658
  foreach ($terms as $term_value) {
659
- $permalink = get_term_link((int) $term_value->term_id, $value);
660
  if (!in_array($permalink, $list_links)) {
661
  $list_links[] = $permalink;
662
  $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url'));
@@ -665,7 +1029,11 @@ class MetaSeo_Sitemap {
665
  $loc->appendChild($xml->createTextNode($permalink));
666
  $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod'));
667
 
668
- $now = $wpdb->get_var("SELECT `post_modified` FROM $wpdb->posts, $wpdb->term_relationships WHERE `post_status` = 'publish' AND `term_taxonomy_id` = " . $term_value->term_taxonomy_id . " AND $wpdb->posts.ID= $wpdb->term_relationships.object_id ORDER BY `post_modified` DESC");
 
 
 
 
669
  $date = date('Y-m-d\TH:i:sP', strtotime($now));
670
  $lastmod->appendChild($xml->createTextNode($date));
671
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
@@ -680,56 +1048,49 @@ class MetaSeo_Sitemap {
680
 
681
  $xml->formatOutput = true;
682
 
683
- if (!is_writable(ABSPATH))
684
  @chmod(ABSPATH, 0755);
 
685
 
686
  if (is_multisite()) {
687
- $home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\s]/", "_", str_replace('http://', '', str_replace('https://', '', site_url())));
 
 
 
 
688
  $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
689
  } else {
690
  $xml->save(ABSPATH . $sitemap_xml_name);
691
  }
692
- $this->wpms_sitemap_info();
693
  }
694
 
695
- /*
696
- * return translation post id
697
- */
698
- public function wpms_get_translation_id($id,$el_type,$setting_name) {
699
- $valID = $id;
700
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')){
701
- global $sitepress;
702
- if(!empty($this->settings_sitemap[$setting_name][$id]['lang'])){
703
- $trid = $sitepress->get_element_trid($id, $el_type);
704
- if ($trid) {
705
- $translations = $sitepress->get_element_translations($trid, $el_type, true, true, true);
706
- foreach ($translations as $translation) {
707
- if(isset($translation->language_code) && $translation->language_code == $this->settings_sitemap[$setting_name][$id]['lang']){
708
- $valID = $translation->element_id;
709
- break;
710
- }
711
- }
712
- }
713
- }
714
- }
715
- return $valID;
716
- }
717
-
718
- /*
719
  * create xml language
 
 
 
 
720
  */
721
- public function wpms_create_xml_lang($xml,$id,$setting_name,$el_type,$loc){
722
- if(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')){
723
- if(!empty($this->settings_sitemap['wpms_sitemap_include_lang'])){
 
724
  global $sitepress;
725
  $trid = $sitepress->get_element_trid($id, $el_type);
726
  if ($trid) {
727
  // get post $translation
728
  $translations = $sitepress->get_element_translations($trid, $el_type, true, true, true);
729
  foreach ($translations as $translation) {
730
- if(isset($translation->language_code) && in_array($translation->language_code,$this->settings_sitemap['wpms_sitemap_include_lang'])){
 
 
 
 
731
  $permalink = get_permalink($translation->element_id);
732
- $node = $xml->appendChild($xml->createElement('xhtml:link')); // can use $xml->appendChild($xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link'));
 
 
733
  $node->setAttribute('rel', 'alternate');
734
  $node->setAttribute('hreflang', $translation->language_code);
735
  $node->setAttribute('href', $permalink);
@@ -738,20 +1099,20 @@ class MetaSeo_Sitemap {
738
  }
739
  }
740
  }
741
- }elseif(is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')){
742
- if(!empty($this->settings_sitemap['wpms_sitemap_include_lang'])){
743
  global $polylang;
744
  $model = $polylang->filters->links_model->model;
745
  $model_post = $polylang->filters->links_model->model->post;
746
- foreach ( $model->get_languages_list() as $language ) {
747
- $value = $model_post->get_translation( $id, $language );
748
- if ( ! $value ) {
749
-
750
- }else{
751
  $lang = pll_get_post_language($value);
752
- if(isset($lang) && in_array($lang,$this->settings_sitemap['wpms_sitemap_include_lang'])){
753
  $permalink = get_permalink($value);
754
- $node = $xml->appendChild($xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link'));
 
 
755
  $node->setAttribute('rel', 'alternate');
756
  $node->setAttribute('hreflang', $lang);
757
  $node->setAttribute('href', $permalink);
@@ -763,8 +1124,14 @@ class MetaSeo_Sitemap {
763
  }
764
  }
765
 
766
- /* Retrieves the full permalink for the current post or post ID */
767
- public function wpms_get_permalink_sitemap($type, $id) {
 
 
 
 
 
 
768
  if (isset($type) && $type == 'custom') {
769
  $permalink = get_post_meta($id, '_menu_item_url', true);
770
  } elseif ($type == 'taxonomy') {
@@ -774,10 +1141,13 @@ class MetaSeo_Sitemap {
774
  }
775
  return $permalink;
776
  }
777
-
778
- /* update sitemap setting */
779
- function wpms_sitemap_info() {
780
- $info_file = $this->wpms_get_path_filename_sitemap();
 
 
 
781
  $xml_url = site_url('/') . $info_file['name'];
782
  if (file_exists($info_file['path'])) {
783
  $this->settings_sitemap['sitemap'] = array(
@@ -789,11 +1159,14 @@ class MetaSeo_Sitemap {
789
  update_option('_metaseo_settings_sitemap', $this->settings_sitemap);
790
  }
791
  }
792
-
793
- /* display sitemap posts by column in front-end */
794
- public function wpms_display_column_posts() {
 
 
 
 
795
  $html = '';
796
- $postsTest = get_posts();
797
  $postTitle = get_post_type_object('post');
798
  $postTitle = $postTitle->label;
799
 
@@ -815,18 +1188,16 @@ class MetaSeo_Sitemap {
815
  }
816
  $html .= '</h4><ul>';
817
 
818
-
819
  //Categories
820
  $ids = array(0);
821
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
822
- foreach ((array) $this->settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
823
  if (!empty($v['post_id'])) {
824
  $ids[] = $k;
825
  }
826
  }
827
  }
828
 
829
- $posts = array();
830
  $cats = get_categories();
831
  foreach ($cats as $cat) {
832
  if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
@@ -834,14 +1205,17 @@ class MetaSeo_Sitemap {
834
  } else {
835
  $cat_link = $cat->cat_name;
836
  }
837
-
838
  $html .= "<li class='wpms_li_cate'><div class='cat_name'>$cat_link</div>";
839
  if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
840
  $html .= "<ul>";
841
  query_posts(array('post__in' => $ids, 'posts_per_page' => -1, 'cat' => $cat->cat_ID));
842
  while (have_posts()) {
843
  the_post();
844
- if (( get_post_meta(get_the_ID(), '_yoast_wpseo_meta-robots-noindex', true) === '1' && get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) !== 'always' ) || ( get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) === 'never' ) || ( get_post_meta(get_the_ID(), '_yoast_wpms_redirect', true) !== '' )) {
 
 
 
845
  continue;
846
  }
847
 
@@ -861,12 +1235,15 @@ class MetaSeo_Sitemap {
861
 
862
  return $html;
863
  }
864
-
865
- /* display sitemap pages by column in front-end */
866
- public function wpms_display_column_pages() {
 
 
 
 
867
  $html = '';
868
  if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) {
869
-
870
  $pageTitle = get_post_type_object('page');
871
  $pageTitle = $pageTitle->label;
872
  if (!empty($this->settings_sitemap['wpms_public_name_pages'])) {
@@ -875,10 +1252,14 @@ class MetaSeo_Sitemap {
875
  $html .= '<div id="sitemap_pages" class="wpms_sitemap_pages"><h4>' . $pageTitle . '</h4>
876
  <ul>';
877
  $pageInc = '';
878
- $getPages = $this->wpms_get_pages_sitemap();
879
  foreach ($getPages as $page) {
880
- if (isset($this->settings_sitemap['wpms_html_sitemap_page']) && $page->ID !== $this->settings_sitemap['wpms_html_sitemap_page']) {
881
- if (( get_post_meta($page->ID, '_yoast_wpseo_meta-robots-noindex', true) === '1' && get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) !== 'always' ) || ( get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) === 'never' ) || ( get_post_meta($page->ID, '_yoast_wpms_redirect', true) !== '' )) {
 
 
 
 
882
  continue;
883
  }
884
  if ($pageInc == '') {
@@ -890,7 +1271,15 @@ class MetaSeo_Sitemap {
890
  }
891
 
892
  if ($pageInc != '') {
893
- $html .= wp_list_pages(array('include' => $pageInc, 'title_li' => '', 'sort_column' => 'post_title', 'sort_order' => 'ASC', 'echo' => false));
 
 
 
 
 
 
 
 
894
  }
895
 
896
  $html .= '</ul></div>';
@@ -899,24 +1288,28 @@ class MetaSeo_Sitemap {
899
  return $html;
900
  }
901
 
902
- /* display sitemap customUrl by column in front-end */
903
- public function wpms_display_column_customUrl() {
 
 
 
 
904
  $html = '';
905
- $lists = $this->settings_sitemap['wpms_sitemap_customUrl'];
906
  $links = get_option('wpms_customUrls_list');
907
- if(!empty($lists)){
908
  $html .= '<div id="sitemap_customUrl" class="wpms_sitemap_customUrl">';
909
  if (!empty($this->settings_sitemap['wpms_public_name_customUrl'])) {
910
  $publictitle = $this->settings_sitemap['wpms_public_name_customUrl'];
911
- }else{
912
- $publictitle = __('Custom Url' , 'wp-meta-seo');
913
  }
914
  $html .= '<h4>' . $publictitle . '</h4>';
915
  $html .= '<ul>';
916
  foreach ($lists as $key => $list) {
917
- if(!empty($links[$key])){
918
  $html .= "<li>";
919
- $html .= '<a href="'. $links[$key]['link'] .'">'.$links[$key]['title'].'</a>';
920
  $html .= "</li>";
921
  }
922
  }
@@ -928,14 +1321,16 @@ class MetaSeo_Sitemap {
928
  }
929
 
930
  /**
931
- * @return array
932
  */
933
- public function wpms_sitemap_theme_default(){
 
934
  $html = '';
935
- $html .= '<div id="wpms_sitemap" class="theme_default columns_' . $this->settings_sitemap['wpms_html_sitemap_column'] . '">';
936
- $arrs = array("wpms_display_column_posts", "wpms_display_column_pages");
 
937
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
938
- $arrs[] = "wpms_display_column_customUrl";
939
  }
940
  $checkColumn = array();
941
  for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i++) {
@@ -946,17 +1341,22 @@ class MetaSeo_Sitemap {
946
  $html .= '<div id="sitemap_authors"><h3>' . __('Authors', 'wp-meta-seo') . '</h3>
947
  <ul>';
948
 
949
- $authEx = implode(", ", get_users('orderby=nicename&meta_key=wpms_excludeauthorsitemap&meta_value=on'));
 
 
 
950
  $html .= wp_list_authors(array('exclude_admin' => false, 'exclude' => $authEx, 'echo' => false));
951
  $html .= '</ul></div>';
952
  }
953
  }
954
 
955
  foreach ($arrs as $arr) {
956
- if (empty($this->settings_sitemap[$arr]))
957
  $this->settings_sitemap[$arr] = 1;
 
 
958
  if (!in_array($arr, $checkColumn)) {
959
- if ($i == (int) $this->settings_sitemap[$arr]) {
960
  $checkColumn[] = $arr;
961
  $output = $this->{$arr}();
962
  $html .= $output;
@@ -965,14 +1365,22 @@ class MetaSeo_Sitemap {
965
  }
966
  // custom post type
967
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
968
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false, '_builtin' => false));
 
 
 
 
 
 
969
  if (!empty($custom_post_types)) {
970
  foreach ($custom_post_types as $post_type => $label) {
971
- if (!empty($this->settings_sitemap['wpms_display_column_' . $post_type]) && $i == (int)$this->settings_sitemap['wpms_display_column_' . $post_type]) {
 
972
  //=====================================================================================
973
- if(isset($this->settings_sitemap['wpms_public_name_'.$post_type]) && $this->settings_sitemap['wpms_public_name_'.$post_type] != ''){
974
- $postTitle = $this->settings_sitemap['wpms_public_name_'.$post_type];
975
- }else{
 
976
  $postTitle = get_post_type_object($post_type);
977
  $postTitle = $postTitle->label;
978
  }
@@ -991,10 +1399,8 @@ class MetaSeo_Sitemap {
991
  }
992
  }
993
  foreach ($taxonomy_objects as $taxo) {
994
-
995
  $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
996
  foreach ($categorys as $cat) {
997
-
998
  $sql = "SELECT p.ID as ID,p.post_title as post_title
999
  FROM $wpdb->posts AS p
1000
  INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id)
@@ -1007,17 +1413,21 @@ ORDER BY p.post_date DESC";
1007
  $results = $wpdb->get_results($sql);
1008
  if (!empty($results)) {
1009
  if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
1010
- $cat_link = "<a href='" . esc_url(get_term_link($cat)) . "'>" . $cat->cat_name . "</a>";
 
1011
  } else {
1012
  $cat_link = $cat->cat_name;
1013
  }
1014
- $html .= "<li class='wpms_li_cate wpms_li_cate'><div class='cat_name'>$cat_link</div>";
 
1015
 
1016
  if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) {
1017
  $html .= "<ul>";
1018
  foreach ($results as $p) {
1019
- if (isset($this->settings_sitemap['wpms_sitemap_' . $post_type][$cat->cat_ID . '-' . $p->ID])) {
1020
- $html .= '<li><a href="' . get_permalink($p->ID) . '">' . $p->post_title . '</a></li>';
 
 
1021
  }
1022
  }
1023
  $html .= "</ul>";
@@ -1035,7 +1445,6 @@ ORDER BY p.post_date DESC";
1035
  }
1036
  }
1037
  }
1038
-
1039
  }
1040
  // ====================
1041
 
@@ -1053,17 +1462,16 @@ ORDER BY p.post_date DESC";
1053
 
1054
  if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
1055
  if (!empty($terms)) {
1056
-
1057
-
1058
  foreach ($terms as $term) {
1059
  if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
1060
- if (empty($this->settings_sitemap['wpms_display_column_menus'][$term->term_id]))
1061
  $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] = 1;
1062
- if ($i == (int) $this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) {
1063
 
 
1064
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1065
  $html .= '<div id="sitemap_menus_' . $term->term_id . '" class="wpms_sitemap_menus">';
1066
- $viewmenu = $this->wpms_view_menus_frontend($term, $ids_menu);
1067
  $html .= $viewmenu;
1068
 
1069
  $html .= '</div>';
@@ -1084,28 +1492,52 @@ ORDER BY p.post_date DESC";
1084
  return $html;
1085
  }
1086
 
1087
- /* display html sitemap in front-end */
1088
- public function wpms_sitemap_shortcode() {
 
 
 
 
1089
  $html = '';
1090
  // include style
1091
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1092
  $theme = $this->settings_sitemap['wpms_html_sitemap_theme'];
1093
- }else{
1094
  $theme = 'default';
1095
  }
1096
 
1097
- if($theme == 'default'){
1098
- echo '<link rel="stylesheet" type="text/css" href="' . plugin_dir_url(dirname(__FILE__)) . 'css/html_sitemap.css" media="screen" />';
1099
- $html = $this->wpms_sitemap_theme_default();
1100
- }elseif($theme == 'tab'){
1101
- wp_enqueue_script('wpms_materialize_js', plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1102
- wp_enqueue_style('wpms_materialize_style', plugins_url('css/materialize/materialize_frontend_tab_theme.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
1103
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1104
  echo '<div id="wpms_sitemap" class="theme_tab">';
1105
- require_once( WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/menu_bar.php' );
1106
- require_once( WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_posts.php' );
1107
- require_once( WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_pages.php' );
1108
- require_once( WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php' );
1109
 
1110
  // source menu
1111
  $ids_menu = array(0);
@@ -1122,13 +1554,12 @@ ORDER BY p.post_date DESC";
1122
 
1123
  if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
1124
  if (!empty($terms)) {
1125
-
1126
  echo '<div id="menu_source_menus">';
1127
  foreach ($terms as $term) {
1128
  if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
1129
  $check_menu[] = 'sitemap_menus_' . $term->term_id;
1130
  echo '<div id="sitemap_menus_' . $term->term_id . '" class="wpms_sitemap_menus">';
1131
- $viewmenu = $this->wpms_view_menus_frontend($term, $ids_menu);
1132
  echo $viewmenu;
1133
 
1134
  echo '</div>';
@@ -1139,30 +1570,44 @@ ORDER BY p.post_date DESC";
1139
  }
1140
  }
1141
  echo '</div>';
1142
- }elseif($theme == 'accordions'){
1143
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
1144
- wp_enqueue_script('wpms_materialize_js', plugins_url('js/materialize/materialize.min.js', dirname(__FILE__)), array('jquery'), WPMSEO_VERSION, true);
1145
- wp_enqueue_style('wpms_materialize_style', plugins_url('css/materialize/materialize_frontend_accordions_theme.css', dirname(__FILE__)), array(), WPMSEO_VERSION);
 
 
 
 
 
 
 
 
 
 
1146
  echo '<div id="wpms_sitemap" class="theme_accordions">';
1147
  echo '<ul class="collapsible wpms_collapsible" data-collapsible="accordion">';
1148
  $arrays = array();
1149
- if(!empty($this->settings_sitemap['wpms_sitemap_menus'])){
1150
- $arrays['wpms_display_order_menus'] = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_menu.php';
 
1151
  }
1152
- if(!empty($this->settings_sitemap['wpms_sitemap_posts'])){
1153
- $arrays['wpms_display_order_posts'] = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_posts.php';
 
1154
  }
1155
- if(!empty($this->settings_sitemap['wpms_sitemap_pages'])){
1156
- $arrays['wpms_display_order_pages'] = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_pages.php';
 
1157
  }
1158
- if(!empty($this->settings_sitemap['wpms_sitemap_customUrl'])){
1159
- $arrays['wpms_display_order_urls'] = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_urlcustom.php';
 
1160
  }
1161
 
1162
- for($i = 1; $i<=4;$i++){
1163
- foreach ($arrays as $key => $item){
1164
- if($this->settings_sitemap[$key] == $i){
1165
- require_once( $item );
1166
  }
1167
  }
1168
  }
@@ -1174,15 +1619,31 @@ ORDER BY p.post_date DESC";
1174
  return $html;
1175
  }
1176
 
1177
- /* add wpms_html_sitemap shortcode in content */
1178
- public function wpms_html_sitemap_content($content) {
 
 
 
 
 
1179
  global $wpdb;
1180
- $sql = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s", array("WPMS HTML Sitemap", "metaseo_html_sitemap", "page"));
 
 
 
 
 
 
 
 
1181
  $sitemap_page = $wpdb->get_row($sql);
1182
 
1183
- if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page))
1184
  $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID;
1185
- if (!empty($this->settings_sitemap['wpms_html_sitemap_page']) && is_page($this->settings_sitemap['wpms_html_sitemap_page'])) {
 
 
 
1186
  $sitemap = '[wpms_html_sitemap]';
1187
  switch ($this->settings_sitemap['wpms_html_sitemap_position']) {
1188
  case 'after':
@@ -1194,15 +1655,19 @@ ORDER BY p.post_date DESC";
1194
  case 'replace':
1195
  $content = $sitemap;
1196
  break;
1197
- default :
1198
  $content .= $sitemap;
1199
  }
1200
  }
1201
  return $content;
1202
  }
1203
-
1204
- /* get all menu */
1205
- public function wpms_get_menus_all() {
 
 
 
 
1206
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1207
  $post_types = get_post_types('', 'names');
1208
  unset($post_types['revision']);
@@ -1220,7 +1685,6 @@ ORDER BY p.post_date DESC";
1220
  $posts_menu = $query->get_posts();
1221
  foreach ($posts_menu as $k => $v) {
1222
  $type = get_post_meta($v->ID, '_menu_item_type', true);
1223
- $type_menu = get_post_meta($v->ID, '_menu_item_object', true);
1224
  $post_meta_object_id = get_post_meta($v->ID, '_menu_item_object_id', true);
1225
  if ($type != 'taxonomy') {
1226
  $ids_posts_custom[] = $post_meta_object_id;
@@ -1233,7 +1697,6 @@ ORDER BY p.post_date DESC";
1233
  foreach ($settings_sitemap['wpms_sitemap_menus'] as $k => $v) {
1234
  if (!empty($v['menu_id'])) {
1235
  $type = get_post_meta($k, '_menu_item_type', true);
1236
- $type_menu = get_post_meta($k, '_menu_item_object', true);
1237
  $post_meta_object_id = get_post_meta($k, '_menu_item_object_id', true);
1238
  if ($type != 'taxonomy') {
1239
  $ids_posts_custom[] = $post_meta_object_id;
@@ -1255,14 +1718,18 @@ ORDER BY p.post_date DESC";
1255
  $menus_post_custom = $query->get_posts();
1256
  return array('posts_custom' => $menus_post_custom, 'categories' => $ids_categories);
1257
  }
1258
-
1259
- /* get posts selected in sitemap setting */
1260
- public function wpms_get_posts_sitemap() {
1261
- $post_types = $this->wpms_get_post_type();
 
 
 
 
1262
  $ids = array(0);
1263
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1264
  if (!empty($settings_sitemap['wpms_sitemap_posts'])) {
1265
- foreach ((array) $settings_sitemap['wpms_sitemap_posts'] as $k => $v) {
1266
  if (!empty($v['post_id'])) {
1267
  $ids[] = $k;
1268
  }
@@ -1279,19 +1746,25 @@ ORDER BY p.post_date DESC";
1279
  $posts = $query->get_posts();
1280
  return $posts;
1281
  }
1282
-
1283
- /*
1284
  * Get a list of all registered post type objects.
 
1285
  */
1286
- public function wpms_get_post_type() {
 
1287
  $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false));
1288
  unset($post_types['attachment']);
1289
  unset($post_types['page']);
1290
  return $post_types;
1291
  }
1292
 
1293
- /* get pages selected in sitemap setting */
1294
- public function wpms_get_pages_sitemap() {
 
 
 
 
1295
  $ids = array(0);
1296
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1297
  if (!empty($settings_sitemap['wpms_sitemap_pages'])) {
@@ -1313,17 +1786,25 @@ ORDER BY p.post_date DESC";
1313
  return $pages;
1314
  }
1315
 
1316
-
1317
- /* get pages */
1318
- public function wpms_get_pages() {
 
 
 
1319
  global $wpdb;
1320
- $sql = "SELECT ID,post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date DESC";
 
1321
  $pages = $wpdb->get_results($sql);
1322
  return $pages;
1323
  }
1324
 
1325
- /* get posts by category */
1326
- public function wpms_get_posts() {
 
 
 
 
1327
  $posts = array();
1328
  $taxo = 'category';
1329
  $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
@@ -1337,7 +1818,7 @@ INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
1337
  WHERE p.post_status = 'publish'
1338
  AND p.post_type = 'post'
1339
  AND tt.taxonomy = %s AND t.slug=%s
1340
- ORDER BY p.post_date DESC",array($taxo,$cat->slug));
1341
  $results = $wpdb->get_results($sql);
1342
  if (!empty($results)) {
1343
  $obj = new StdClass();
@@ -1353,11 +1834,16 @@ ORDER BY p.post_date DESC",array($taxo,$cat->slug));
1353
  return $posts;
1354
  }
1355
 
1356
- /* get posts by category */
1357
- public function wpms_get_posts_custom($post_type) {
 
 
 
 
 
1358
  $posts = array();
1359
- $taxonomy_objects = get_object_taxonomies($post_type, 'names' );
1360
- foreach ($taxonomy_objects as $taxo){
1361
  $categorys = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
1362
  global $wpdb;
1363
 
@@ -1370,7 +1856,7 @@ INNER JOIN $wpdb->terms AS t ON (t.term_id = tt.term_id)
1370
  WHERE p.post_status = 'publish'
1371
  AND p.post_type = %s
1372
  AND tt.taxonomy = %s AND t.slug=%s
1373
- ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1374
  $results = $wpdb->get_results($sql);
1375
 
1376
  if (!empty($results)) {
@@ -1387,10 +1873,17 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1387
 
1388
  return $posts;
1389
  }
1390
-
1391
- /* Display sitemap menu in front-end */
1392
- public function wpms_view_menus_frontend($term, $ids_menu) {
 
 
 
 
 
 
1393
  $html = '';
 
1394
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1395
  $list_menus = $ids_menu;
1396
  } else {
@@ -1419,7 +1912,6 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1419
 
1420
  $query = new WP_Query($args);
1421
  $submenus = $query->get_posts();
1422
- $settings_sitemap = get_option('_metaseo_settings_sitemap');
1423
  if (!empty($submenus)) {
1424
  $html .= '<h4>' . $term->name . '</h4>';
1425
  $html .= '<ul class="wpms_frontend_menus_sitemap">';
@@ -1428,7 +1920,7 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1428
  $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
1429
  $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true);
1430
  $this->level[$menu->ID] = 0;
1431
- $level = $this->wpms_count_parent($menu->ID);
1432
  if ($type == 'taxonomy') {
1433
  $post_submenu = get_post($menu->ID);
1434
  $title = $post_submenu->post_title;
@@ -1445,12 +1937,12 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1445
  }
1446
  }
1447
  $type = get_post_meta($menu->ID, '_menu_item_type', true);
1448
- $check_type = get_post_meta($menu->ID, '_menu_item_object', true);
1449
- $permalink = $this->wpms_get_permalink_sitemap($type, $id_menu);
1450
  $margin = $level * 10;
1451
  $style = '';
1452
- if ($level != 0)
1453
  $style = 'style="margin-left:' . $margin . 'px"';
 
1454
  $html .= '<li class="wpms_menu_level_' . $level . '" ' . $style . '>';
1455
  $html .= '<a href="' . $permalink . '">' . $title . '</a>';
1456
  $html .= '</li>';
@@ -1460,32 +1952,47 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1460
  }
1461
  return $html;
1462
  }
1463
-
1464
- /* get count parent for a menu */
1465
- public function wpms_count_parent($menuID) {
 
 
 
 
 
1466
  $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true);
1467
- $parent_1 = get_post_meta($parent, '_menu_item_menu_item_parent', true);
1468
  if (!empty($this->settings_sitemap['wpms_sitemap_menus']->{$parent}) && !empty($parent)) {
1469
- $this->level[$menuID]+=1;
1470
- $this->loop_parent($parent, $this->level[$menuID], $menuID);
1471
  } else {
1472
- $this->loop_parent($parent, $this->level[$menuID], $menuID);
1473
  }
1474
 
1475
- return (int) $this->level[$menuID];
1476
  }
1477
 
1478
- public function loop_parent($menuID, $level, $menuIDroot) {
 
 
 
 
 
1479
  $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true);
1480
  $parent_1 = get_post_meta($parent, '_menu_item_menu_item_parent', true);
1481
- if ((!empty($this->settings_sitemap['wpms_sitemap_menus'][$parent]) && !empty($parent)) || (!empty($parent_1) && !empty($parent))) {
1482
- $this->level[$menuIDroot]+=1;
1483
- $this->loop_parent($parent, $this->level[$menuIDroot], $menuIDroot);
 
1484
  }
1485
  }
1486
-
1487
- /* Display list menu in sitemap settings */
1488
- public function wpms_view_menus($term) {
 
 
 
 
 
1489
  $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu');
1490
  $args = array(
1491
  'orderby' => 'menu_order',
@@ -1497,22 +2004,23 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1497
  'meta_key' => '_menu_item_menu_item_parent',
1498
  'meta_value' => 0
1499
  );
1500
-
1501
  $query = new WP_Query($args);
1502
  $submenus = $query->get_posts();
1503
- $settings_sitemap = get_option('_metaseo_settings_sitemap');
1504
 
1505
  $this->html .= '<h3>';
1506
  $this->html .= '<div class="pure-checkbox">';
1507
- $this->html .= '<input class="sitemap_check_all_posts_categories" id="sitemap_check_all_posts_categories_' . $term->slug . '" type="checkbox">';
1508
- $this->html .= '<label for="sitemap_check_all_posts_categories_' . $term->slug . '">'. $term->name .'</label>';
1509
  $this->html .= '</div>';
1510
  $this->html .= '</h3>';
1511
  $this->html .= '<div class="wpms_xmp_custom_column" style="font-weight: bold;">';
1512
- $this->html .= '<label>'.__('Display in column', 'wp-meta-seo').'</label>';
1513
- $this->html .= '<select class="wpms_display_column wpms_display_column_menus" data-menu_id="' . $term->term_id . '">';
 
1514
  for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i++) {
1515
- if (isset($this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) && $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] == $i) {
 
1516
  $this->html .= '<option selected value="' . $i . '">' . $this->columns[$i] . '</option>';
1517
  } else {
1518
  $this->html .= '<option value="' . $i . '">' . $this->columns[$i] . '</option>';
@@ -1521,10 +2029,22 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1521
  $this->html .= '</select>';
1522
  $this->html .= '</div>';
1523
  foreach ($submenus as $menu) {
1524
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'])) $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'] = 'monthly';
1525
- if(empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'])) $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'] = '1.0';
1526
- $select_priority = $this->wpms_view_select_priority('priority_menu_' . $menu->ID, '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][priority]', $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority']);
1527
- $select_frequency = $this->wpms_view_select_frequency('frequency_menu_' . $menu->ID, '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][frequency]', $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency']);
 
 
 
 
 
 
 
 
 
 
 
 
1528
 
1529
  $type = get_post_meta($menu->ID, '_menu_item_type', true);
1530
  $type_menu = get_post_meta($menu->ID, '_menu_item_object', true);
@@ -1547,43 +2067,61 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1547
  $level = 1;
1548
  $this->html .= '<div class="wpms_row wpms_row_record">';
1549
  $check_type = get_post_meta($menu->ID, '_menu_item_object', true);
1550
- $permalink = $this->wpms_get_permalink_sitemap($check_type, $id_menu);
1551
  $this->html .= '<div style="float:left;line-height:30px">';
1552
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1553
- $this->html .= '<input class="wpms_sitemap_input_link checked" type="hidden" data-type="menu" value="'.$permalink.'">';
 
1554
  $this->html .= '<div class="pure-checkbox">';
1555
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]" value="' . $menu->ID . '" checked>';
1556
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">'. $title .'</label>';
 
 
 
1557
  $this->html .= '</div>';
1558
  } else {
1559
- if (isset($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id']) && $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'] == $menu->ID) {
1560
- $this->html .= '<input class="wpms_sitemap_input_link checked" type="hidden" data-type="menu" value="'.$permalink.'">';
 
 
1561
  $this->html .= '<div class="pure-checkbox">';
1562
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]" value="' . $menu->ID . '" checked>';
1563
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">'. $title .'</label>';
 
 
 
1564
  $this->html .= '</div>';
1565
  } else {
1566
- $this->html .= '<input class="wpms_sitemap_input_link" type="hidden" data-type="menu" value="'.$permalink.'">';
 
1567
  $this->html .= '<div class="pure-checkbox">';
1568
- $this->html .= '<input class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" id="wpms_sitemap_menus_' . $menu->ID . '" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]" value="' . $menu->ID . '">';
1569
- $this->html .= '<label for="wpms_sitemap_menus_' . $menu->ID . '">'. $title .'</label>';
 
 
 
1570
  $this->html .= '</div>';
1571
  }
1572
  }
1573
 
1574
  $this->html .= '</div>';
1575
- $this->html .= '<div style="margin-left:200px">' . $select_priority . $select_frequency . '</div>';
1576
  $this->html .= '</div>';
1577
- $this->html .= $this->wpms_loop($menu->ID, $level + 1, $this->settings_sitemap, $term);
1578
  }
1579
 
1580
  return $this->html;
1581
  }
1582
-
1583
- /*
1584
- * Display list menu in sitemap settings
 
 
 
 
1585
  */
1586
- public function wpms_loop($menuID, $level, $settings_sitemap, $term) {
 
1587
  $args = array(
1588
  'post_type' => 'nav_menu_item',
1589
  'posts_per_page' => -1,
@@ -1599,8 +2137,12 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1599
  $type = get_post_meta($submenu->ID, '_menu_item_type', true);
1600
  $type_menu = get_post_meta($submenu->ID, '_menu_item_object', true);
1601
  $post_subid = get_post_meta($submenu->ID, '_menu_item_object_id', true);
1602
- if(empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'])) $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'] = 'monthly';
1603
- if(empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'])) $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'] = '1.0';
 
 
 
 
1604
  if ($type == 'taxonomy') {
1605
  $post_submenu = get_post($submenu->ID);
1606
  $title = $post_submenu->post_title;
@@ -1621,16 +2163,34 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1621
  for ($i = 1; $i <= $level * 3; $i++) {
1622
  $space .= '&nbsp;';
1623
  }
1624
- $select_priority = $this->wpms_view_select_priority('priority_menu_' . $submenu->ID, '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][priority]', $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority']);
1625
- $select_frequency = $this->wpms_view_select_frequency('frequency_menu_' . $submenu->ID, '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][frequency]', $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency']);
 
 
 
 
 
 
 
 
1626
 
1627
  if (empty($settings_sitemap['wpms_check_firstsave'])) {
1628
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '" class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" checked name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]" type="checkbox" value="' . $submenu->ID . '">';
 
 
 
1629
  } else {
1630
- if (isset($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id']) && $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'] == $submenu->ID) {
1631
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '" class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" checked name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]" type="checkbox" value="' . $submenu->ID . '">';
 
 
 
 
1632
  } else {
1633
- $checkbox = $space . '<input id="wpms_sitemap_menus_' . $submenu->ID . '" class="cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug . '" name="_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]" type="checkbox" value="' . $submenu->ID . '">';
 
 
 
1634
  }
1635
  }
1636
 
@@ -1638,45 +2198,54 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1638
  $this->html .= '<div style="float:left;line-height:30px">';
1639
  $this->html .= '<div class="pure-checkbox">';
1640
  $this->html .= $checkbox;
1641
- $this->html .= '<label for="wpms_sitemap_menus_' . $submenu->ID . '">'. $title .'</label>';
1642
  $this->html .= '</div>';
1643
  $this->html .= '</div>';
1644
- $this->html .= '<div style="margin-left:200px">' . $select_priority . $select_frequency . '</div>';
1645
  $this->html .= '</div>';
1646
- $this->wpms_loop($submenu->ID, $level + 1, $settings_sitemap, $term);
1647
  }
1648
  }
1649
  }
1650
 
1651
- /* Ajax generate sitemap to xml file */
1652
- public function wpms_regenerate_sitemaps() {
1653
- $info_file = $this->wpms_get_path_filename_sitemap();
 
 
1654
  $wpms_url_robot = get_home_path() . 'robots.txt';
1655
  $wpms_url_home = site_url('/');
1656
- $this->metaseo_create_sitemap($this->wpms_sitemap_name);
1657
  if ($this->settings_sitemap['wpms_sitemap_root'] == 1) {
1658
- $this->metaseo_create_sitemap($this->wpms_sitemap_default_name);
1659
  }
1660
 
1661
  if (isset($this->settings_sitemap['wpms_sitemap_add']) && $this->settings_sitemap['wpms_sitemap_add'] == 1) {
1662
- if (!file_exists($wpms_url_robot) && !is_multisite() ) {
1663
  ob_start();
1664
- error_reporting( 0 );
1665
  do_robots();
1666
  $robots_content = ob_get_clean();
1667
 
1668
- $f = fopen( $wpms_url_robot, 'x' );
1669
- fwrite( $f, $robots_content );
1670
  }
1671
  }
1672
 
1673
  if (file_exists($wpms_url_robot) && !is_multisite()) {
1674
- if (!is_writable($wpms_url_robot))
1675
  @chmod($wpms_url_robot, 0755);
 
 
1676
  if (is_writable($wpms_url_robot)) {
1677
  $file_content = file_get_contents($wpms_url_robot);
1678
- if (isset($this->settings_sitemap['wpms_sitemap_add']) && $this->settings_sitemap['wpms_sitemap_add'] == 1 && !preg_match('|Sitemap: ' . $wpms_url_home . $this->wpms_sitemap_name . '|', $file_content)) {
1679
- file_put_contents($wpms_url_robot, $file_content . "\nSitemap: " . $wpms_url_home . $this->wpms_sitemap_name);
 
 
 
 
 
1680
  }
1681
  } else {
1682
  $error = __('Cannot edit "robots.txt". Check your permissions', 'wp-meta-seo');
@@ -1688,9 +2257,16 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1688
  do_action('wpms_submit_sitemap');
1689
  wp_send_json(array('status' => true, 'message' => 'success'));
1690
  }
1691
-
1692
- /* Display priority for each item */
1693
- public function wpms_view_select_priority($id, $name, $selected) {
 
 
 
 
 
 
 
1694
  $values = array('1' => '100%', '0.9' => '90%', '0.8' => '80%', '0.7' => '70%', '0.6' => '60%', '0.5' => '50%');
1695
  $select = '<select id="' . $id . '" name="' . $name . '" class="wpmsleft">';
1696
  $select .= '<option value="1">' . __('Priority', 'wp-meta-seo') . '</option>';
@@ -1705,9 +2281,24 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1705
  return $select;
1706
  }
1707
 
1708
- /* Display frequency for each item */
1709
- public function wpms_view_select_frequency($id, $name, $selected) {
1710
- $values = array('always' => 'Always', 'hourly' => 'Hourly', 'daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'yearly' => 'Yearly', 'never' => 'Never');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1711
  $select = '<select id="' . $id . '" name="' . $name . '" class="wpmsleft">';
1712
  $select .= '<option value="monthly">' . __('Frequency', 'wp-meta-seo') . '</option>';
1713
  foreach ($values as $k => $v) {
@@ -1720,9 +2311,12 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1720
  $select .= '</select>';
1721
  return $select;
1722
  }
1723
-
1724
- /* Ajax update sitemap settings */
1725
- public function wpms_save_sitemap_settings() {
 
 
 
1726
  $settings_sitemap = get_option('_metaseo_settings_sitemap');
1727
  $lists = array(
1728
  "wpms_sitemap_add" => 0,
@@ -1743,8 +2337,14 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1743
  "wpms_display_order_urls" => 4
1744
  );
1745
 
1746
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1747
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false, '_builtin' => false));
 
 
 
 
 
 
1748
  if (!empty($custom_post_types)) {
1749
  foreach ($custom_post_types as $post_type => $label) {
1750
  $lists['wpms_display_column_' . $post_type] = 1;
@@ -1758,7 +2358,7 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1758
  $lists['wpms_sitemap_customUrl'] = array();
1759
  }
1760
 
1761
- $wpms_display_column_menus = json_decode(stripslashes($_POST['wpms_display_column_menus']),true);
1762
  if (!empty($wpms_display_column_menus)) {
1763
  $settings_sitemap['wpms_display_column_menus'] = $wpms_display_column_menus;
1764
  }
@@ -1777,35 +2377,45 @@ ORDER BY p.post_date DESC",array($post_type,$taxo,$cat->slug));
1777
  "wpms_sitemap_menus" => array()
1778
  );
1779
 
1780
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
1781
- $custom_post_types = get_post_types(array('public' => true, 'exclude_from_search' => false ,'_builtin' => false));
1782
- if(!empty($custom_post_types)) {
 
 
 
 
 
 
1783
  foreach ($custom_post_types as $post_type => $label) {
1784
- $lists_selected["wpms_sitemap_".$post_type] = array();
1785
  }
1786
  }
1787
 
1788
  $lists_selected["wpms_sitemap_customUrl"] = array();
1789
 
1790
  // save setting include lang
1791
- if(isset($_POST['wpms_lang_list']) && is_array($_POST['wpms_lang_list'])){
1792
  $settings_sitemap['wpms_sitemap_include_lang'] = $_POST['wpms_lang_list'];
1793
  }
1794
  }
1795
 
1796
  foreach ($lists_selected as $k => $v) {
1797
  if (isset($_POST[$k]) && $_POST[$k] != '{}') {
1798
- $values = json_decode(stripslashes($_POST[$k]),true);
1799
  $settings_sitemap[$k] = $values;
1800
  } else {
1801
  $settings_sitemap[$k] = array();
1802
  }
1803
  }
1804
 
1805
- if (isset($_POST['wpms_public_name_posts']))
1806
  $settings_sitemap['wpms_public_name_posts'] = $_POST['wpms_public_name_posts'];
1807
- if (isset($_POST['wpms_public_name_pages']))
 
 
1808
  $settings_sitemap['wpms_public_name_pages'] = $_POST['wpms_public_name_pages'];
 
 
1809
  update_option('_metaseo_settings_sitemap', $settings_sitemap);
1810
 
1811
  wp_send_json(true);
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
 
5
+ /**
6
+ * Class MetaSeoSitemap
7
+ * Class that holds most of the sitemap functionality for Meta SEO.
8
+ */
9
+ 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;
36
 
37
+ /**
38
+ * MetaSeoSitemap constructor.
39
+ */
40
+ public function __construct()
41
+ {
42
  $this->settings_sitemap = array(
43
  "wpms_sitemap_add" => 0,
44
  "wpms_sitemap_root" => 0,
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;
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
  }
92
+
93
  $settings = get_option('_metaseo_settings_sitemap');
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
+ {
112
  global $post;
113
+ if (empty($post)) {
114
  return;
115
+ }
116
+
117
+ if (!empty($this->settings_sitemap) && $this->settings_sitemap['wpms_html_sitemap_page'] != $post->ID) {
118
  return;
119
+ }
120
+
121
+ wp_enqueue_script(
122
+ 'site-jPages-js',
123
+ plugins_url('js/site-jPages.js', dirname(__FILE__)),
124
+ array('jquery'),
125
+ WPMSEO_VERSION,
126
+ true
127
+ );
128
+ wp_localize_script(
129
+ 'site-jPages-js',
130
+ 'wpms_avarible',
131
+ $this->localizeScript()
132
+ );
133
+ wp_enqueue_script(
134
+ 'jpage-js',
135
+ plugins_url('js/jPages.js', dirname(__FILE__)),
136
+ array('jquery'),
137
+ WPMSEO_VERSION,
138
+ true
139
+ );
140
+ wp_enqueue_style(
141
+ 'jpage-css',
142
+ plugins_url('css/jPages.css', dirname(__FILE__)),
143
+ array(),
144
+ WPMSEO_VERSION
145
+ );
146
  }
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
 
186
+ wp_enqueue_script(
187
+ 'metaseositemap',
188
+ plugins_url('js/metaseo_sitemap.js', dirname(__FILE__)),
189
+ array('jquery'),
190
+ WPMSEO_VERSION,
191
+ true
192
+ );
193
+ wp_localize_script(
194
+ 'metaseositemap',
195
+ 'wpmseositemap',
196
+ array(
197
+ 'post_type' => $custom_post_types
198
+ )
199
+ );
200
+ wp_enqueue_script(
201
+ 'jpage-js',
202
+ plugins_url('js/jPages.js', dirname(__FILE__)),
203
+ array('jquery'),
204
+ WPMSEO_VERSION,
205
+ true
206
+ );
207
+ wp_enqueue_style(
208
+ 'metaseositemapstyle',
209
+ plugins_url('css/metaseo_sitemap.css', dirname(__FILE__)),
210
+ array(),
211
+ WPMSEO_VERSION
212
+ );
213
+ wp_enqueue_style(
214
+ 'jpage-css',
215
+ plugins_url('css/jPages.css', dirname(__FILE__)),
216
+ array(),
217
+ WPMSEO_VERSION
218
+ );
219
+ wp_enqueue_style(
220
+ 'm-style-qtip',
221
+ plugins_url('css/jquery.qtip.css', dirname(__FILE__)),
222
+ array(),
223
+ WPMSEO_VERSION
224
+ );
225
+ wp_enqueue_script(
226
+ 'jquery-qtip',
227
+ plugins_url('js/jquery.qtip.min.js', dirname(__FILE__)),
228
+ array('jquery'),
229
+ '2.2.1',
230
+ true
231
  );
232
  }
233
 
234
+ /**
235
+ * Add a new field to a section of a sitemap settings page
236
+ */
237
+ public function settingsSitemap()
238
+ {
239
  register_setting('MetaSEO Sitemap', '_metaseo_settings_sitemap');
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'
302
+ );
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
+ )
333
+ );
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,
341
+ array($this, 'wpms_sitemap_include_lang'),
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,
354
+ array($this, 'sitemapIncludeLanguages'),
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
+ {
390
+ echo '<input id="wpms_check_firstsave" name="_metaseo_settings_sitemap[wpms_check_firstsave]"
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
+ {
452
  ?>
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
+ {
477
  ?>
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
+ {
491
  $wpms_taxonomies = array(
492
  'category' => 'Post category',
493
  'post_tag' => 'Post tag'
495
  foreach ($wpms_taxonomies as $key => $value) {
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
  }
513
  }
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;
534
+ }
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
+ ?>
548
+ </select>
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
+ {
562
  ?>
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
574
  }
575
 
576
+ /**
577
+ * Display field sitemap position
578
+ */
579
+ public function sitemapTheme()
580
+ {
581
  ?>
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
593
  }
594
 
595
+ /**
596
+ * Display field sitemap position
597
+ */
598
+ public function sitemapPosition()
599
+ {
600
  ?>
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
612
  }
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';
627
  } else {
628
  $xml_file = $this->wpms_sitemap_name;
630
  $xml_path = ABSPATH . $xml_file;
631
  return array('path' => $xml_path, 'name' => $xml_file);
632
  }
633
+
634
+ /**
635
+ * create sitemap
636
+ * @param $sitemap_xml_name
637
+ */
638
+ public function createSitemap($sitemap_xml_name)
639
+ {
640
  global $wpdb;
641
  $taxonomies = array();
642
  $list_links = array();
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';
651
+ } else {
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(
659
+ 'http://www.sitemaps.org/schemas/sitemap/0.9',
660
+ 'urlset'
661
+ )
662
+ );
663
 
664
  /* add home page */
665
  $list_links[] = home_url('/');
674
  $priority->appendChild($xml->createTextNode(1.0));
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;
704
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
705
  $changefreq->appendChild($xml->createTextNode('monthly'));
706
  } else {
707
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'])) {
708
+ $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'] = 'monthly';
709
  }
710
+ $changefreq->appendChild(
711
+ $xml->createTextNode(
712
+ $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency']
713
+ )
714
+ );
715
  }
716
 
717
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
718
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
719
  $priority->appendChild($xml->createTextNode('1.0'));
720
  } else {
721
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'])) {
722
+ $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'] = '1.0';
723
  }
724
+ $priority->appendChild(
725
+ $xml->createTextNode(
726
+ $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority']
727
+ )
728
+ );
729
  }
730
 
731
+ $this->createXmlLang(
732
+ $xml,
733
+ $id,
734
+ 'post_post',
735
+ $loc
736
+ );
737
  }
738
  }
739
  }
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') {
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;
783
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
784
  $changefreq->appendChild($xml->createTextNode('monthly'));
785
  } else {
786
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'])) {
787
+ $menufre = 'monthly';
788
+ } else {
789
+ $menufre = $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'];
790
  }
791
+ $changefreq->appendChild($xml->createTextNode($menufre));
792
  }
793
 
794
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
795
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
796
  $priority->appendChild($xml->createTextNode('1.0'));
797
  } else {
798
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'])) {
799
  $menupriority = '1.0';
800
+ } else {
801
+ $menupriority = $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'];
802
  }
803
  $priority->appendChild($xml->createTextNode($menupriority));
804
  }
805
+ $this->createXmlLang($xml, $id, 'post_post', $loc);
806
  }
807
  }
808
  }
810
  }
811
  }
812
 
813
+ // add posts
814
+ $res = $this->getPostsSitemap();
815
  if (!empty($res)) {
816
  foreach ($res as $val) {
817
  /* get translation post id */
829
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
830
  $changefreq->appendChild($xml->createTextNode('monthly'));
831
  } else {
832
+ if (empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency'])) {
833
  $postfrequency = 'monthly';
834
+ } else {
835
  $postfrequency = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency'];
836
  }
837
  $changefreq->appendChild($xml->createTextNode($postfrequency));
841
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
842
  $priority->appendChild($xml->createTextNode('1.0'));
843
  } else {
844
+ if (empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority'])) {
845
  $postpriority = '1.0';
846
+ } else {
847
  $postpriority = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority'];
848
  }
849
  $priority->appendChild($xml->createTextNode($postpriority));
850
  }
851
 
852
+ $this->createXmlLang($xml, $val->ID, 'post_post', $loc);
853
  }
854
  }
855
  }
856
 
857
  // run when WP Meta SEO Addon active
858
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
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
  }
878
 
879
  $args = array(
880
  'posts_per_page' => -1,
881
+ 'post_type' => $pt,
882
  'post__in' => $ids,
883
  'post_status' => 'any'
884
  );
900
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
901
  $changefreq->appendChild($xml->createTextNode('monthly'));
902
  } else {
903
+ if (empty($this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['frequency'])) {
904
+ $postfr = 'monthly';
905
+ } else {
906
+ $postfr = $this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['frequency'];
907
  }
908
+ $changefreq->appendChild($xml->createTextNode($postfr));
909
  }
910
 
911
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
912
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
913
  $priority->appendChild($xml->createTextNode('1.0'));
914
  } else {
915
+ if (empty($this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['priority'])) {
916
+ $postpri = '1.0';
917
+ } else {
918
+ $postpri = $this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['priority'];
919
  }
920
+ $priority->appendChild($xml->createTextNode($postpri));
921
  }
922
 
923
+ $this->createXmlLang(
924
+ $xml,
925
+ $val->ID,
926
+ 'post_post',
927
+ $loc
928
+ );
929
  }
930
  }
931
  }
 
932
  }
933
  }
934
 
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'));
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
 
952
+ if (empty($customUrl['frequency'])) {
953
  $pagefrequency = 'monthly';
954
+ } else {
955
  $pagefrequency = $customUrl['frequency'];
956
  }
957
  $changefreq->appendChild($xml->createTextNode($pagefrequency));
958
 
959
  $priority = $gglstmp_url->appendChild($xml->createElement('priority'));
960
 
961
+ if (empty($customUrl['priority'])) {
962
  $pagepriority = '1.0';
963
+ } else {
964
  $pagepriority = $customUrl['priority'];
965
  }
966
  $priority->appendChild($xml->createTextNode($pagepriority));
970
  }
971
  }
972
  // ========================================
973
+ // add pages
974
+ $res = $this->getPagesSitemap();
 
975
  if (!empty($res)) {
 
976
  foreach ($res as $val) {
977
  /* get translation post id */
978
  $permalink = get_permalink($val->ID);
990
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
991
  $changefreq->appendChild($xml->createTextNode('monthly'));
992
  } else {
993
+ if (empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency'])) {
994
  $pagefrequency = 'monthly';
995
+ } else {
996
  $pagefrequency = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency'];
997
  }
998
  $changefreq->appendChild($xml->createTextNode($pagefrequency));
1001
  if (empty($this->settings_sitemap['wpms_check_firstsave'])) {
1002
  $priority->appendChild($xml->createTextNode('1.0'));
1003
  } else {
1004
+ if (empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority'])) {
1005
  $pagepriority = '1.0';
1006
+ } else {
1007
  $pagepriority = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority'];
1008
  }
1009
  $priority->appendChild($xml->createTextNode($pagepriority));
1010
  }
1011
 
1012
+ $this->createXmlLang($xml, $val->ID, 'post_page', $loc);
1013
  }
1014
  }
1015
  }
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'));
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));
1039
  $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq'));
1048
 
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');
1062
  } else {
1063
  $xml->save(ABSPATH . $sitemap_xml_name);
1064
  }
1065
+ $this->sitemapInfos();
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
+ {
1077
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) {
1078
+ if (!empty($this->settings_sitemap['wpms_sitemap_include_lang'])) {
1079
  global $sitepress;
1080
  $trid = $sitepress->get_element_trid($id, $el_type);
1081
  if ($trid) {
1082
  // get post $translation
1083
  $translations = $sitepress->get_element_translations($trid, $el_type, true, true, true);
1084
  foreach ($translations as $translation) {
1085
+ if (isset($translation->language_code)
1086
+ && in_array(
1087
+ $translation->language_code,
1088
+ $this->settings_sitemap['wpms_sitemap_include_lang']
1089
+ )) {
1090
  $permalink = get_permalink($translation->element_id);
1091
+ // can use
1092
+ // $xml->appendChild($xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link'));
1093
+ $node = $xml->appendChild($xml->createElement('xhtml:link'));
1094
  $node->setAttribute('rel', 'alternate');
1095
  $node->setAttribute('hreflang', $translation->language_code);
1096
  $node->setAttribute('href', $permalink);
1099
  }
1100
  }
1101
  }
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);
1109
+ if ($value) {
 
 
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');
1117
  $node->setAttribute('hreflang', $lang);
1118
  $node->setAttribute('href', $permalink);
1124
  }
1125
  }
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') {
1141
  }
1142
  return $permalink;
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(
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
 
1188
  }
1189
  $html .= '</h4><ul>';
1190
 
 
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
  }
1198
  }
1199
  }
1200
 
 
1201
  $cats = get_categories();
1202
  foreach ($cats as $cat) {
1203
  if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) {
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;
1220
  }
1221
 
1235
 
1236
  return $html;
1237
  }
1238
+
1239
+ /**
1240
+ * display sitemap pages by column in front-end
1241
+ * @return string
1242
+ */
1243
+ public function displayPages()
1244
+ {
1245
  $html = '';
1246
  if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) {
 
1247
  $pageTitle = get_post_type_object('page');
1248
  $pageTitle = $pageTitle->label;
1249
  if (!empty($this->settings_sitemap['wpms_public_name_pages'])) {
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 == '') {
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
  }
1284
 
1285
  $html .= '</ul></div>';
1288
  return $html;
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)) {
1301
  $html .= '<div id="sitemap_customUrl" class="wpms_sitemap_customUrl">';
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
  }
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", "displayPages");
1332
  if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1333
+ $arrs[] = "displayCustomUrl";
1334
  }
1335
  $checkColumn = array();
1336
  for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i++) {
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
 
1353
  foreach ($arrs as $arr) {
1354
+ if (empty($this->settings_sitemap[$arr])) {
1355
  $this->settings_sitemap[$arr] = 1;
1356
+ }
1357
+
1358
  if (!in_array($arr, $checkColumn)) {
1359
+ if ($i == (int)$this->settings_sitemap[$arr]) {
1360
  $checkColumn[] = $arr;
1361
  $output = $this->{$arr}();
1362
  $html .= $output;
1365
  }
1366
  // custom post type
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);
1385
  $postTitle = $postTitle->label;
1386
  }
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)
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>";
1445
  }
1446
  }
1447
  }
 
1448
  }
1449
  // ====================
1450
 
1462
 
1463
  if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
1464
  if (!empty($terms)) {
 
 
1465
  foreach ($terms as $term) {
1466
  if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) {
1467
+ if (empty($this->settings_sitemap['wpms_display_column_menus'][$term->term_id])) {
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>';
1492
  return $html;
1493
  }
1494
 
1495
+ /**
1496
+ * display html sitemap in front-end
1497
+ * @return array|string
1498
+ */
1499
+ public function sitemapShortcode()
1500
+ {
1501
  $html = '';
1502
  // include style
1503
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
1504
  $theme = $this->settings_sitemap['wpms_html_sitemap_theme'];
1505
+ } else {
1506
  $theme = 'default';
1507
  }
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__)),
1526
+ array('jquery'),
1527
+ WPMSEO_VERSION,
1528
+ true
1529
+ );
1530
+ wp_enqueue_style(
1531
+ 'wpms_materialize_style',
1532
+ plugins_url('css/materialize/materialize_frontend_tab_theme.css', dirname(__FILE__)),
1533
+ array(),
1534
+ WPMSEO_VERSION
1535
+ );
1536
  echo '<div id="wpms_sitemap" class="theme_tab">';
1537
+ require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/menu_bar.php');
1538
+ require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_posts.php');
1539
+ require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_pages.php');
1540
+ require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php');
1541
 
1542
  // source menu
1543
  $ids_menu = array(0);
1554
 
1555
  if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
1556
  if (!empty($terms)) {
 
1557
  echo '<div id="menu_source_menus">';
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>';
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__)),
1577
+ array('jquery'),
1578
+ WPMSEO_VERSION,
1579
+ true
1580
+ );
1581
+ wp_enqueue_style(
1582
+ 'wpms_materialize_style',
1583
+ plugins_url('css/materialize/materialize_frontend_accordions_theme.css', dirname(__FILE__)),
1584
+ array(),
1585
+ WPMSEO_VERSION
1586
+ );
1587
  echo '<div id="wpms_sitemap" class="theme_accordions">';
1588
  echo '<ul class="collapsible wpms_collapsible" data-collapsible="accordion">';
1589
  $arrays = array();
1590
+ if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) {
1591
+ $arrays['wpms_display_order_menus']
1592
+ = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_menu.php';
1593
  }
1594
+ if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) {
1595
+ $arrays['wpms_display_order_posts']
1596
+ = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_posts.php';
1597
  }
1598
+ if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) {
1599
+ $arrays['wpms_display_order_pages']
1600
+ = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_pages.php';
1601
  }
1602
+ if (!empty($this->settings_sitemap['wpms_sitemap_customUrl'])) {
1603
+ $arrays['wpms_display_order_urls']
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
  }
1613
  }
1619
  return $html;
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;
1643
+ }
1644
+
1645
+ if (!empty($this->settings_sitemap['wpms_html_sitemap_page'])
1646
+ && is_page($this->settings_sitemap['wpms_html_sitemap_page'])) {
1647
  $sitemap = '[wpms_html_sitemap]';
1648
  switch ($this->settings_sitemap['wpms_html_sitemap_position']) {
1649
  case 'after':
1655
  case 'replace':
1656
  $content = $sitemap;
1657
  break;
1658
+ default:
1659
  $content .= $sitemap;
1660
  }
1661
  }
1662
  return $content;
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']);
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;
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;
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
  }
1746
  $posts = $query->get_posts();
1747
  return $posts;
1748
  }
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']);
1758
  unset($post_types['page']);
1759
  return $post_types;
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'])) {
1786
  return $pages;
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));
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();
1834
  return $posts;
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
 
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)) {
1873
 
1874
  return $posts;
1875
  }
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;
1889
  } else {
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">';
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;
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>';
1952
  }
1953
  return $html;
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
+ {
1963
  $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true);
 
1964
  if (!empty($this->settings_sitemap['wpms_sitemap_menus']->{$parent}) && !empty($parent)) {
1965
+ $this->level[$menuID] += 1;
1966
+ $this->loopParent($parent, $menuID);
1967
  } else {
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))) {
1984
+ $this->level[$menuIDroot] += 1;
1985
+ $this->loopParent($parent, $menuIDroot);
1986
  }
1987
  }
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',
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>';
2029
  $this->html .= '</select>';
2030
  $this->html .= '</div>';
2031
  foreach ($submenus as $menu) {
2032
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'])) {
2033
+ $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'] = 'monthly';
2034
+ }
2035
+ if (empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'])) {
2036
+ $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'] = '1.0';
2037
+ }
2038
+ $slpr = $this->viewPriority(
2039
+ 'priority_menu_' . $menu->ID,
2040
+ '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][priority]',
2041
+ $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority']
2042
+ );
2043
+ $slfr = $this->viewFrequency(
2044
+ 'frequency_menu_' . $menu->ID,
2045
+ '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][frequency]',
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);
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
  }
2106
 
2107
  $this->html .= '</div>';
2108
+ $this->html .= '<div style="margin-left:200px">' . $slpr . $slfr . '</div>';
2109
  $this->html .= '</div>';
2110
+ $this->loop($menu->ID, $level + 1, $this->settings_sitemap, $term);
2111
  }
2112
 
2113
  return $this->html;
2114
  }
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,
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';
2142
+ }
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;
2163
  for ($i = 1; $i <= $level * 3; $i++) {
2164
  $space .= '&nbsp;';
2165
  }
2166
+ $slpr = $this->viewPriority(
2167
+ 'priority_menu_' . $submenu->ID,
2168
+ '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][priority]',
2169
+ $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority']
2170
+ );
2171
+ $slfr = $this->viewFrequency(
2172
+ 'frequency_menu_' . $submenu->ID,
2173
+ '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][frequency]',
2174
+ $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency']
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
  $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>';
2205
  $this->html .= '</div>';
2206
+ $this->loop($submenu->ID, $level + 1, $settings_sitemap, $term);
2207
  }
2208
  }
2209
  }
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();
2229
 
2230
+ $f = fopen($wpms_url_robot, 'x');
2231
+ fwrite($f, $robots_content);
2232
  }
2233
  }
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,
2247
+ $file_content . "\nSitemap: " . $wpms_url_home . $this->wpms_sitemap_name
2248
+ );
2249
  }
2250
  } else {
2251
  $error = __('Cannot edit "robots.txt". Check your permissions', 'wp-meta-seo');
2257
  do_action('wpms_submit_sitemap');
2258
  wp_send_json(array('status' => true, 'message' => 'success'));
2259
  }
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>';
2281
  return $select;
2282
  }
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) {
2311
  $select .= '</select>';
2312
  return $select;
2313
  }
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,
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;
2358
  $lists['wpms_sitemap_customUrl'] = array();
2359
  }
2360
 
2361
+ $wpms_display_column_menus = json_decode(stripslashes($_POST['wpms_display_column_menus']), true);
2362
  if (!empty($wpms_display_column_menus)) {
2363
  $settings_sitemap['wpms_display_column_menus'] = $wpms_display_column_menus;
2364
  }
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'])) {
2398
  $settings_sitemap['wpms_sitemap_include_lang'] = $_POST['wpms_lang_list'];
2399
  }
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();
2408
  }
2409
  }
2410
 
2411
+ if (isset($_POST['wpms_public_name_posts'])) {
2412
  $settings_sitemap['wpms_public_name_posts'] = $_POST['wpms_public_name_posts'];
2413
+ }
2414
+
2415
+ if (isset($_POST['wpms_public_name_pages'])) {
2416
  $settings_sitemap['wpms_public_name_pages'] = $_POST['wpms_public_name_pages'];
2417
+ }
2418
+
2419
  update_option('_metaseo_settings_sitemap', $settings_sitemap);
2420
 
2421
  wp_send_json(true);
inc/class.metaseo-snippet-preview.php CHANGED
@@ -1,95 +1,134 @@
1
  <?php
 
 
 
2
  /**
3
- * Class WPMSEO_Snippet_Preview
4
- *
5
  * Generates a Google Search snippet preview.
6
- *
7
  * Takes a $post, $title and $description
8
- *
9
  */
 
 
10
 
11
- class WPMSEO_Snippet_Preview {
12
-
 
13
  protected $content;
 
 
 
14
  protected $options;
 
 
 
15
  protected $post;
 
 
 
16
  protected $title;
 
 
 
17
  protected $description;
 
 
 
18
  protected $date = '';
 
 
 
19
  protected $url;
 
 
 
20
  protected $slug = '';
21
 
22
- public function __construct($post, $title, $description) {
 
 
 
 
 
 
 
23
  $this->post = $post;
24
  $this->title = esc_html($title);
25
  $this->description = esc_html($description);
26
 
27
- $this->set_date();
28
- $this->set_url();
29
- $this->set_content();
30
  }
31
-
32
  /**
33
- * Getter for $this->content
34
- *
35
- * @return string html for snippet preview
36
- */
37
- public function get_content() {
 
38
  return $this->content;
39
  }
40
 
41
  /*
42
  * Sets date if available
43
  */
44
- protected function set_date() {
45
- if (is_object($this->post) && isset($this->options['showdate-' . $this->post->post_type]) && $this->options['showdate-' . $this->post->post_type] === true) {
46
- $date = $this->get_post_date();
 
 
47
  $this->date = '<span class="date">' . $date . ' - </span>';
48
  }
49
  }
50
-
51
  /**
52
- * Retrieves a post date when post is published, or return current date when it's not.
53
- *
54
- * @return string
55
- *
56
- */
57
- protected function get_post_date() {
 
58
  if (isset($this->post->post_date) && $this->post->post_status == 'publish') {
59
  $date = date_i18n('j M Y', strtotime($this->post->post_date));
60
  } else {
61
  $date = date_i18n('j M Y');
62
  }
63
 
64
- return (string) $date;
65
  }
66
-
67
  /**
68
- * Generates the url that is displayed in the snippet preview.
69
- */
70
- protected function set_url() {
 
71
  $this->url = str_replace(array('http://', 'https://'), '', get_bloginfo('url')) . '/';
72
- $this->set_slug();
73
  }
74
-
75
  /**
76
- * Sets the slug and adds it to the url if the post has been published and the post name exists.
77
- *
78
- * If the post is set to be the homepage the slug is also not included.
79
- */
80
- protected function set_slug() {
81
- $frontpage_post_id = (int) ( get_option('page_on_front') );
 
82
 
83
- if (is_object($this->post) && isset($this->post->post_name) && $this->post->post_name !== '' && $this->post->ID !== $frontpage_post_id) {
 
84
  $this->slug = sanitize_title($this->title);
85
  $this->url .= esc_html($this->slug);
86
  }
87
  }
88
-
89
  /**
90
- * Generates the html for the snippet preview and assign it to $this->content.
91
- */
92
- protected function set_content() {
 
93
  $content = <<<HTML
94
  <div id="wpmseosnippet">
95
  <a class="title" id="wpmseosnippet_title" href="#">$this->title</a>
@@ -97,18 +136,18 @@ class WPMSEO_Snippet_Preview {
97
  <p class="desc">$this->date<span class="autogen"></span><span class="content">$this->description</span></p>
98
  </div>
99
  HTML;
100
- $this->set_content_through_filter($content);
101
  }
102
-
103
  /**
104
- * Sets the html for the snippet preview through a filter
105
- *
106
- * @param string $content Content string.
107
- */
108
- protected function set_content_through_filter($content) {
 
109
  $properties = get_object_vars($this);
110
  $properties['desc'] = $properties['description'];
111
  $this->content = apply_filters('wpmseo_snippet', $content, $this->post, $properties);
112
  }
113
-
114
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
+
5
  /**
6
+ * Class WPMSEOSnippetPreview
 
7
  * Generates a Google Search snippet preview.
 
8
  * Takes a $post, $title and $description
 
9
  */
10
+ 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();
59
+ $this->setUrl();
60
+ $this->setContent();
61
  }
62
+
63
  /**
64
+ * Getter for $this->content
65
+ *
66
+ * @return string html for snippet preview
67
+ */
68
+ public function getContent()
69
+ {
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
+
85
  /**
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
+ {
107
  $this->url = str_replace(array('http://', 'https://'), '', get_bloginfo('url')) . '/';
108
+ $this->setSlug();
109
  }
110
+
111
  /**
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
 
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
  $this->url .= esc_html($this->slug);
124
  }
125
  }
126
+
127
  /**
128
+ * Generates the html for the snippet preview and assign it to $this->content.
129
+ */
130
+ protected function setContent()
131
+ {
132
  $content = <<<HTML
133
  <div id="wpmseosnippet">
134
  <a class="title" id="wpmseosnippet_title" href="#">$this->title</a>
136
  <p class="desc">$this->date<span class="autogen"></span><span class="content">$this->description</span></p>
137
  </div>
138
  HTML;
139
+ $this->setContentThroughFilter($content);
140
  }
141
+
142
  /**
143
+ * Sets the html for the snippet preview through a filter
144
+ *
145
+ * @param string $content Content string.
146
+ */
147
+ protected function setContentThroughFilter($content)
148
+ {
149
  $properties = get_object_vars($this);
150
  $properties['desc'] = $properties['description'];
151
  $this->content = apply_filters('wpmseo_snippet', $content, $this->post, $properties);
152
  }
 
153
  }
inc/class.wp-metaseo.php CHANGED
@@ -1,60 +1,87 @@
1
  <?php
 
 
2
 
3
- //Main plugin functions here
4
- class WpMetaSeo {
5
-
 
 
 
 
 
 
6
  private static $initiated = false;
7
 
8
- public function __construct() {
9
- add_action('admin_notices', array($this, 'plugin_activation_notices'));
10
- }
11
-
12
- public static function init() {
13
  ob_start();
14
  if (!self::$initiated) {
15
- self::init_hooks();
16
  }
17
  }
18
 
19
  /**
20
  * Initializes WordPress hooks
21
  */
22
- private static function init_hooks() {
 
23
  self::$initiated = true;
24
  }
25
 
26
  /**
27
  * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
28
- * @static
 
29
  */
30
- public static function plugin_activation($wp = '4.0', $php = '5.3.0') {
 
31
  global $wp_version;
32
  if (version_compare(PHP_VERSION, $php, '<')) {
33
  $flag = 'PHP';
34
  } elseif (version_compare($wp_version, $wp, '<')) {
35
  $flag = 'WordPress';
36
  } else {
37
- global $wpdb;
38
- //Set two param as flags that determine whether show import meta data from other SEO plugin button or not to 0
39
  update_option('_aio_import_notice_flag', 0);
40
  update_option('_yoast_import_notice_flag', 0);
41
  update_option('plugin_to_sync_with', 0);
42
- self::install_db();
43
  return;
44
  }
45
 
46
  $version = 'PHP' == $flag ? $php : $wp;
47
  deactivate_plugins(basename(__FILE__));
48
- wp_die('<p>The <strong>WP Meta SEO</strong> plugin requires ' . $flag . ' version ' . $version . ' or greater.</p>', 'Plugin Activation Error', array('response' => 200, 'back_link' => TRUE));
 
 
 
 
 
 
 
 
49
 
50
  if (!class_exists('DOMDocument')) {
51
  deactivate_plugins(basename(__FILE__));
52
- wp_die('<p>To active WP Meta SEO plugin , please install “dom” PHP extension </p>', 'Plugin Activation Error', array('response' => 200, 'back_link' => TRUE));
 
 
 
 
 
 
 
53
  }
54
  }
55
-
56
  /* create metaseo_images table */
57
- public static function install_db() {
 
58
  global $wpdb;
59
  $table_name = $wpdb->prefix . 'metaseo_images';
60
 
@@ -72,9 +99,8 @@ class WpMetaSeo {
72
  PRIMARY KEY (`id`)
73
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
74
 
75
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
76
 
77
  dbDelta($sql);
78
  }
79
-
80
  }
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
4
 
5
+ /**
6
+ * Class WpMetaSeo
7
+ * Main plugin functions here
8
+ */
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
+ {
21
  ob_start();
22
  if (!self::$initiated) {
23
+ self::initHooks();
24
  }
25
  }
26
 
27
  /**
28
  * Initializes WordPress hooks
29
  */
30
+ private static function initHooks()
31
+ {
32
  self::$initiated = true;
33
  }
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
+ {
42
  global $wp_version;
43
  if (version_compare(PHP_VERSION, $php, '<')) {
44
  $flag = 'PHP';
45
  } elseif (version_compare($wp_version, $wp, '<')) {
46
  $flag = 'WordPress';
47
  } else {
48
+ //Set two param as flags that determine whether show import meta data
49
+ // from other SEO plugin button or not to 0
50
  update_option('_aio_import_notice_flag', 0);
51
  update_option('_yoast_import_notice_flag', 0);
52
  update_option('plugin_to_sync_with', 0);
53
+ self::installDb();
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
+ );
68
 
69
  if (!class_exists('DOMDocument')) {
70
  deactivate_plugins(basename(__FILE__));
71
+ wp_die(
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
 
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
 
104
  dbDelta($sql);
105
  }
 
106
  }
inc/google_analytics/tracking/classic_disconnect.php CHANGED
@@ -1,16 +1,22 @@
1
  <?php
2
- // Exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) )
4
- exit();
5
  ?>
6
  <script type="text/javascript">
7
  var _gaq = _gaq || [];
8
- _gaq.push(['_setAccount', '<?php echo esc_html($this->ga_tracking_disconnect['wpms_ga_uax_reference']); ?>']);
9
  _gaq.push(['_trackPageview']);
10
 
11
- (function() {
12
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
13
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
14
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 
 
 
 
 
 
 
15
  })();
16
  </script>
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
4
  ?>
5
  <script type="text/javascript">
6
  var _gaq = _gaq || [];
7
+ _gaq.push(['_setAccount', '<?php echo esc_html($this->gaDisconnect['wpms_ga_uax_reference']); ?>']);
8
  _gaq.push(['_trackPageview']);
9
 
10
+ (function () {
11
+ var ga = document.createElement('script');
12
+ ga.type = 'text/javascript';
13
+ ga.async = true;
14
+ if ('https:' === document.location.protocol) {
15
+ ga.src = 'https://ssl.google-analytics.com/ga.js';
16
+ } else {
17
+ ga.src = 'http://www.google-analytics.com/ga.js';
18
+ }
19
+ var s = document.getElementsByTagName('script')[0];
20
+ s.parentNode.insertBefore(ga, s);
21
  })();
22
  </script>
inc/google_analytics/tracking/code-classic.php CHANGED
@@ -8,28 +8,29 @@
8
  * Modified by Joomunited
9
  */
10
 
11
- // Exit if accessed directly
12
- if ( ! defined( 'ABSPATH' ) )
13
- exit();
14
-
15
- $profile = WPMSGA_Tools::get_selected_profile( $google_alanytics['profile_list'], $google_alanytics['tableid_jail'] );
16
  ?>
17
  <script type="text/javascript">
18
- var _gaq = _gaq || [];
19
- <?php if ($this->ga_tracking['wpmsga_enhanced_links']) {?>
20
- var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
21
- _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
22
- <?php }?>
23
- _gaq.push(['_setAccount', '<?php echo esc_html($profile[2]); ?>']);
24
- _gaq.push(['_trackPageview']<?php if ($this->ga_tracking['wpmsga_dash_anonim']) {?>, ['_gat._anonymizeIp']<?php }?>);
25
 
26
- (function() {
27
- var ga = document.createElement('script'); ga.type = 'text/javascript'; 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]; s.parentNode.insertBefore(ga, s);
34
- })();
 
 
 
35
  </script>
8
  * Modified by Joomunited
9
  */
10
 
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 || [];
17
+ <?php if ($this->ga_tracking['wpmsga_enhanced_links']) {?>
18
+ var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
19
+ _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
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>
inc/google_analytics/tracking/code-universal.php CHANGED
@@ -8,125 +8,130 @@
8
  * Modified by Joomunited
9
  */
10
 
11
- // Exit if accessed directly
12
- if ( ! defined( 'ABSPATH' ) )
13
- exit();
14
-
15
- $profile = WPMSGA_Tools::get_selected_profile( $google_alanytics['profile_list'], $google_alanytics['tableid_jail'] );
16
  ?>
17
  <script>
18
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
19
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
20
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
21
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
22
- <?php
23
- $create_options = '{';
24
- if ( $this->ga_tracking['wpmsga_speed_samplerate'] != 1 ) {
25
- $create_options .= "'siteSpeedSampleRate' : " . (int) $this->ga_tracking['wpmsga_speed_samplerate'];
26
- }
27
- if ( $this->ga_tracking['wpmsga_crossdomain_tracking'] && $this->ga_tracking['wpmsga_crossdomain_list'] != '' ) {
28
- if ( $create_options != '{' ) {
29
- $create_options .= ', ';
30
- }
31
- $create_options .= "'allowLinker' : true";
32
- }
33
- $create_options .= '}';
 
 
 
 
 
 
 
34
 
35
- $options = "'auto'";
36
- $optionsArray = array();
37
- if ( ! empty( $this->ga_tracking['wpmsga_cookiedomain'] ) ) {
38
- $optionsArray['cookieDomain'] = $this->ga_tracking['wpmsga_cookiedomain'];
39
- }
40
- if ( ! empty( $this->ga_tracking['wpmsga_cookiename'] ) ) {
41
- $optionsArray['cookieName'] = $this->ga_tracking['wpmsga_cookiename'];
42
- }
43
- if ( ! empty( $this->ga_tracking['wpmsga_cookieexpires'] ) ) {
44
- $optionsArray['cookieExpires'] = (int) $this->ga_tracking['wpmsga_cookieexpires'];
45
- }
46
- if ( ! empty( $optionsArray ) ) {
47
- $options = json_encode( $optionsArray );
48
- }
49
- ?>
50
- ga('create', '<?php echo esc_html($profile[2]); ?>', <?php echo $options; ?><?php if ($create_options != '{}') {?>, <?php echo $create_options; }?>);
51
- <?php if ($this->ga_tracking ['wpmsga_crossdomain_tracking'] && $this->ga_tracking ['wpmsga_crossdomain_list']!='') {?>
52
- ga('require', 'linker');
53
- <?php
54
- $crossdomain_list = explode( ',', $this->ga_tracking['wpmsga_crossdomain_list'] );
55
- $crossdomain_list = array_map( 'trim', $crossdomain_list );
56
- $crossdomain_list = strip_tags( implode( "','", $crossdomain_list ) );
57
- ?>
58
- ga('linker:autoLink', ['<?php echo ($crossdomain_list)?>'] );
59
- <?php
60
- }
61
- if ( $this->ga_tracking['wpmsga_dash_remarketing'] ) {
62
- ?>
63
- ga('require', 'displayfeatures');
64
- <?php
65
- }
66
- if ( $this->ga_tracking['wpmsga_enhanced_links'] ) {
67
- ?>
68
- ga('require', 'linkid', 'linkid.js');
69
- <?php
70
- }
71
- if ( $this->ga_tracking['wpmsga_author_dimindex'] && ( is_single() || is_page() ) ) {
72
- global $post;
73
- $author_id = $post->post_author;
74
- $author_name = get_the_author_meta( 'display_name', $author_id );
75
- ?>
76
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_author_dimindex']; ?>', '<?php echo esc_attr($author_name); ?>');
77
- <?php
78
- }
79
- if ( $this->ga_tracking['wpmsga_pubyear_dimindex'] && is_single() ) {
80
- global $post;
81
- $date = get_the_date( 'Y', $post->ID );
82
- ?>
83
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_pubyear_dimindex']; ?>', '<?php echo (int)$date; ?>');
84
- <?php
85
- }
86
- if ( $this->ga_tracking['wpmsga_category_dimindex'] && is_category() ) {
87
- ?>
88
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr(single_tag_title()); ?>');
89
- <?php
90
- }
91
- if ( $this->ga_tracking['wpmsga_tag_dimindex'] && is_single() ) {
92
- global $post;
93
- $post_tags_list = '';
94
- $post_tags_array = get_the_tags( $post->ID );
95
- if ( $post_tags_array ) {
96
- foreach ( $post_tags_array as $tag ) {
97
- $post_tags_list .= $tag->name . ', ';
98
- }
99
- }
100
- $post_tags_list = rtrim( $post_tags_list, ', ' );
101
- if ( $post_tags_list ) {
102
- ?>
103
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_tag_dimindex']; ?>', '<?php echo esc_attr($post_tags_list); ?>');
104
- <?php
105
- }
106
- }
107
- if ( $this->ga_tracking['wpmsga_category_dimindex'] && is_single() ) {
108
- global $post;
109
- $categories = get_the_category( $post->ID );
110
- foreach ( $categories as $category ) {
111
- ?>
112
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_category_dimindex']; ?>', '<?php echo esc_attr($category->name); ?>');
113
- <?php
114
- break;
115
- }
116
- }
117
- if ( $this->ga_tracking['wpmsga_user_dimindex'] ) {
118
- ?>
119
- ga('set', 'dimension<?php echo (int)$this->ga_tracking ['wpmsga_user_dimindex']; ?>', '<?php echo is_user_logged_in()?'registered':'guest'; ?>');
120
- <?php
121
- }
122
- do_action( 'wpmsga_dash_addtrackingcode' );
123
- if ( $this->ga_tracking['wpmsga_dash_anonim'] ) {
124
- ?> ga('send', 'pageview', {'anonymizeIp': true});<?php } else {?> ga('send', 'pageview');
125
- <?php
126
- }
127
- if ( $this->ga_tracking['wpmsga_dash_adsense'] ) {
128
- ?>
129
 
130
- window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
131
- <?php }?>
132
  </script>
8
  * Modified by Joomunited
9
  */
10
 
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) {
17
+ i['GoogleAnalyticsObject'] = r;
18
+ i[r] = i[r] || function () {
19
+ (i[r].q = i[r].q || []).push(arguments)
20
+ }, i[r].l = 1 * new Date();
21
+ a = s.createElement(o),
22
+ m = s.getElementsByTagName(o)[0];
23
+ a.async = 1;
24
+ a.src = g;
25
+ m.parentNode.insertBefore(a, m)
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";
37
+ }
38
+ $create_options .= '}';
39
 
40
+ $options = "'auto'";
41
+ $optionsArray = array();
42
+ if (!empty($this->ga_tracking['wpmsga_cookiedomain'])) {
43
+ $optionsArray['cookieDomain'] = $this->ga_tracking['wpmsga_cookiedomain'];
44
+ }
45
+ if (!empty($this->ga_tracking['wpmsga_cookiename'])) {
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'] ) {
67
+ ?>
68
+ ga('require', 'displayfeatures');
69
+ <?php
70
+ }
71
+ if ( $this->ga_tracking['wpmsga_enhanced_links'] ) {
72
+ ?>
73
+ ga('require', 'linkid', 'linkid.js');
74
+ <?php
75
+ }
76
+ if ( $this->ga_tracking['wpmsga_author_dimindex'] && (is_single() || is_page()) ) {
77
+ global $post;
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() ) {
97
+ global $post;
98
+ $post_tags_list = '';
99
+ $post_tags_array = get_the_tags($post->ID);
100
+ if ($post_tags_array) {
101
+ foreach ($post_tags_array as $tag) {
102
+ $post_tags_list .= $tag->name . ', ';
103
+ }
104
+ }
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
+ }
112
+ if ( $this->ga_tracking['wpmsga_category_dimindex'] && is_single() ) {
113
+ global $post;
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');
128
+ if ( $this->ga_tracking['wpmsga_dash_anonim'] ) {
129
+ ?> ga('send', 'pageview', {'anonymizeIp': true});<?php } else {?> ga('send', 'pageview');
130
+ <?php
131
+ }
132
+ if ( $this->ga_tracking['wpmsga_dash_adsense'] ) {
133
+ ?>
134
 
135
+ window.google_analytics_uacct = "<?php echo esc_html($profile[2]); ?>";
136
+ <?php }?>
137
  </script>
inc/google_analytics/tracking/custom.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) )
3
- exit();
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>
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-classic.php CHANGED
@@ -8,49 +8,50 @@
8
  * Modified by Joomunited
9
  */
10
 
11
- // Exit if accessed directly
12
- if ( ! defined( 'ABSPATH' ) )
13
- exit();
14
  ?>
15
  <script type="text/javascript">
16
- (function($){
17
- $(window).load(function() {
18
- if (this._gat) {
19
- tks = this._gat._getTrackers();
20
- ga_track = function(p) {
21
- for (i=0; i < tks.length; i++) {
22
- var n = tks[i]._getName() !== "" ? tks[i]._getName()+"." : "";
23
- a = [];
24
- for (i2=0; i2 < p.length; i2++) {
25
- var b = i2===0 ? n+p[i2] : p[i2];
26
- a.push(b);
 
 
27
  }
28
- _gaq.push(a);
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
- };
31
- $('a').filter(function() {
32
- return this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/);
33
- }).click(function(e) {
34
- ga_track(['_trackEvent', 'download', 'click', this.href]);
35
- });
36
- $('a[href^="mailto"]').click(function(e) {
37
- ga_track(['_trackSocial', 'email', 'send', this.href]);
38
- });
39
- var loc = location.host.split('.');
40
- while (loc.length > 2) { loc.shift(); }
41
- loc = loc.join('.');
42
- var localURLs = [
43
- loc,
44
- '<?php echo esc_html(get_option('siteurl'));?>'
45
- ];
46
- $('a[href^="http"]').filter(function() {
47
- for (var i = 0; i < localURLs.length; i++) {
48
- if (this.href.indexOf(localURLs[i]) == -1) return this.href;
49
- }
50
- }).click(function(e) {
51
- ga_track(['_trackEvent', 'outbound', 'click', this.href]);
52
- });
53
- }
54
- });
55
- })(jQuery);
56
  </script>
8
  * Modified by Joomunited
9
  */
10
 
11
+ /* Prohibit direct script loading */
12
+ defined('ABSPATH') || die('No direct script access allowed!');
 
13
  ?>
14
  <script type="text/javascript">
15
+ (function ($) {
16
+ $(window).load(function () {
17
+ if (this._gat) {
18
+ tks = this._gat._getTrackers();
19
+ ga_track = function (p) {
20
+ for (i = 0; i < tks.length; i++) {
21
+ var n = tks[i]._getName() !== "" ? tks[i]._getName() + "." : "";
22
+ a = [];
23
+ for (i2 = 0; i2 < p.length; i2++) {
24
+ var b = i2 === 0 ? n + p[i2] : p[i2];
25
+ a.push(b);
26
+ }
27
+ _gaq.push(a);
28
  }
29
+ };
30
+ $('a').filter(function () {
31
+ return this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/);
32
+ }).click(function () {
33
+ ga_track(['_trackEvent', 'download', 'click', this.href]);
34
+ });
35
+ $('a[href^="mailto"]').click(function () {
36
+ ga_track(['_trackSocial', 'email', 'send', this.href]);
37
+ });
38
+ var loc = location.host.split('.');
39
+ while (loc.length > 2) {
40
+ loc.shift();
41
  }
42
+ loc = loc.join('.');
43
+ var localURLs = [
44
+ loc,
45
+ '<?php echo esc_html(get_option('siteurl'));?>'
46
+ ];
47
+ $('a[href^="http"]').filter(function () {
48
+ for (var i = 0; i < localURLs.length; i++) {
49
+ if (this.href.indexOf(localURLs[i]) === -1) return this.href;
50
+ }
51
+ }).click(function () {
52
+ ga_track(['_trackEvent', 'outbound', 'click', this.href]);
53
+ });
54
+ }
55
+ });
56
+ })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
57
  </script>
inc/google_analytics/tracking/events-universal.php CHANGED
@@ -8,61 +8,69 @@
8
  * Modified by Joomunited
9
  */
10
 
11
- // Exit if accessed directly
12
- if ( ! defined( 'ABSPATH' ) )
13
- exit();
14
-
15
- $domaindata = WPMSGA_Tools::get_root_domain( esc_html( get_option( 'siteurl' ) ) );
16
  ?>
17
  <script type="text/javascript">
18
- (function($){
19
- $(window).load(function() {
20
- <?php if ($this->ga_tracking['wpmsga_event_tracking']){ ?>
21
 
22
  //Track Downloads
23
- $('a').filter(function() {
24
  return this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/);
25
- }).click(function(e) {
26
- ga('send','event', 'download', 'click', this.href<?php if(isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']){echo ", {'nonInteraction': 1}";}?>);
 
 
27
  });
28
 
29
  //Track Mailto
30
- $('a[href^="mailto"]').click(function(e) {
31
- ga('send','event', 'email', 'send', this.href<?php if(isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']){echo ", {'nonInteraction': 1}";}?>);
32
- });
33
- <?php if (isset ( $domaindata ['domain'] ) && $domaindata ['domain']) { ?>
 
 
34
 
35
  //Track Outbound Links
36
- $('a[href^="http"]').filter(function() {
37
- if (!this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/)){
38
- if (this.href.indexOf('<?php echo $domaindata['domain']; ?>') == -1) return this.href;
39
  }
40
- }).click(function(e) {
41
- ga('send','event', 'outbound', 'click', this.href<?php if(isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']){echo ", {'nonInteraction': 1}";}?>);
 
 
42
  });
43
- <?php } ?>
44
- <?php } ?>
45
- <?php if ($this->ga_tracking['wpmsga_event_affiliates'] && $this->ga_tracking['wpmsga_aff_tracking']){ ?>
46
 
47
  //Track Affiliates
48
- $('a').filter(function() {
49
- if ('<?php echo esc_js($this->ga_tracking['wpmsga_event_affiliates']);?>'!=''){
50
- return this.href.match(/(<?php echo str_replace('/','\/',(esc_js($this->ga_tracking['wpmsga_event_affiliates'])));?>)/);
51
- }
52
- }).click(function(event) {
53
- ga('send','event', 'affiliates', 'click', this.href<?php if(isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']){echo ", {'nonInteraction': 1}";}?>);
 
 
54
  });
55
- <?php } ?>
56
- <?php if (isset ( $domaindata ['domain'] ) && $domaindata ['domain'] && $this->ga_tracking ['wpmsga_hash_tracking']) { ?>
57
 
58
  //Track Hashmarks
59
- $('a').filter(function() {
60
- if (this.href.indexOf('<?php echo $domaindata['domain']; ?>') != -1 || this.href.indexOf('://') == -1) return this.hash;
61
- }).click(function(e) {
62
- ga('send','event', 'hashmark', 'click', this.href<?php if(isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']){echo ", {'nonInteraction': 1}";}?>);
 
 
63
  });
64
 
65
- <?php } ?>
66
- });
67
- })(jQuery);
68
  </script>
8
  * Modified by Joomunited
9
  */
10
 
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 ($) {
17
+ $(window).load(function () {
18
+ <?php if ($this->ga_tracking['wpmsga_event_tracking']) { ?>
19
 
20
  //Track Downloads
21
+ $('a').filter(function () {
22
  return this.href.match(/.*\.(<?php echo esc_js($this->ga_tracking['wpmsga_event_downloads']);?>)(\?.*)?$/);
23
+ }).click(function () {
24
+ ga('send', 'event', 'download', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
25
+ echo ", {'nonInteraction': 1}";
26
+ }?>);
27
  });
28
 
29
  //Track Mailto
30
+ $('a[href^="mailto"]').click(function () {
31
+ ga('send', 'event', 'email', 'send', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
32
+ echo ", {'nonInteraction': 1}";
33
+ }?>);
34
+ });
35
+ <?php if (isset ($domaindata ['domain']) && $domaindata ['domain']) { ?>
36
 
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']) {
44
+ echo ", {'nonInteraction': 1}";
45
+ }?>);
46
  });
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']);?>' !== '') {
54
+ return this.href.match(/(<?php echo str_replace('/', '\/', (esc_js($this->ga_tracking['wpmsga_event_affiliates'])));?>)/);
55
+ }
56
+ }).click(function () {
57
+ ga('send', 'event', 'affiliates', 'click', this.href<?php if (isset($this->ga_tracking['wpmsga_event_bouncerate']) && $this->ga_tracking['wpmsga_event_bouncerate']) {
58
+ echo ", {'nonInteraction': 1}";
59
+ }?>);
60
  });
61
+ <?php } ?>
62
+ <?php if (isset ($domaindata ['domain']) && $domaindata ['domain'] && $this->ga_tracking ['wpmsga_hash_tracking']) { ?>
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}";
70
+ }?>);
71
  });
72
 
73
+ <?php } ?>
74
+ });
75
+ })(jQuery);
76
  </script>
inc/google_analytics/tracking/universal_disconnect.php CHANGED
@@ -1,13 +1,19 @@
1
  <?php
2
- // Exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) )
4
- exit();
5
  ?>
6
  <script>
7
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
8
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
9
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
10
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
11
- ga('create', '<?php echo esc_html($this->ga_tracking_disconnect['wpms_ga_uax_reference']); ?>', 'auto');
 
 
 
 
 
 
 
12
  ga('send', 'pageview');
13
  </script>
1
  <?php
2
+ /* Prohibit direct script loading */
3
+ defined('ABSPATH') || die('No direct script access allowed!');
 
4
  ?>
5
  <script>
6
+ (function (i, s, o, g, r, a, m) {
7
+ i['GoogleAnalyticsObject'] = r;
8
+ i[r] = i[r] || function () {
9
+ (i[r].q = i[r].q || []).push(arguments)
10
+ }, i[r].l = 1 * new Date();
11
+ a = s.createElement(o),
12
+ m = s.getElementsByTagName(o)[0];
13
+ a.async = 1;
14
+ a.src = g;
15
+ m.parentNode.insertBefore(a, m)
16
+ })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
17
+ ga('create', '<?php echo esc_html($this->gaDisconnect['wpms_ga_uax_reference']); ?>', 'auto');
18
  ga('send', 'pageview');
19
  </script>
inc/google_analytics/wpmsga.php CHANGED
@@ -2,43 +2,73 @@
2
  /**
3
  * Class manage instance of WPMSGA
4
  */
 
 
 
5
 
6
- if (!class_exists('WPMSGA_Manager')) {
7
-
8
- final class WPMSGA_Manager {
9
-
 
 
 
 
10
  private static $instance = null;
 
 
 
11
  public $config = null;
 
 
 
12
  public $tracking = null;
 
 
 
13
  public $frontend_item_reports = null;
 
 
 
14
  public $backend_item_reports = null;
15
- public $wpmsga_controller = null;
 
 
 
16
 
17
  /**
18
  * Construct forbidden
19
  */
20
- private function __construct() {
 
21
  if (null !== self::$instance) {
22
- _doing_it_wrong(__FUNCTION__, __("This is not allowed, please read the documentation!", 'wp-meta-seo'), '4.6');
 
 
 
 
23
  }
24
  }
25
 
26
- public static function instance() {
 
 
 
 
27
  if (null === self::$instance) {
28
  self::$instance = new self();
29
  }
30
  return self::$instance;
31
  }
32
-
33
  }
34
-
35
  }
36
 
37
  /**
38
  * Returns a unique instance of WPMSGA
39
  */
40
- function WPMSGA() {
41
- return WPMSGA_Manager::instance();
 
42
  }
43
 
44
  /*
2
  /**
3
  * Class manage instance of WPMSGA
4
  */
5
+ /* Prohibit direct script loading */
6
+ defined('ABSPATH') || die('No direct script access allowed!');
7
+ if (!class_exists('WpmsGaManager')) {
8
 
9
+ /**
10
+ * Class WpmsGaManager
11
+ */
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;
38
 
39
  /**
40
  * Construct forbidden
41
  */
42
+ private function __construct()
43
+ {
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()
57
+ {
58
  if (null === self::$instance) {
59
  self::$instance = new self();
60
  }
61
  return self::$instance;
62
  }
 
63
  }
 
64
  }
65
 
66
  /**
67
  * Returns a unique instance of WPMSGA
68
  */
69
+ function WPMSGA()
70
+ {
71
+ return WpmsGaManager::instance();
72
  }
73
 
74
  /*
inc/google_analytics/wpmsgapi.php CHANGED
@@ -10,39 +10,69 @@
10
 
11
  // Exit if accessed directly
12
 
13
- if (!defined('ABSPATH'))
14
- exit();
15
 
16
- if (!class_exists('WPMS_GAPI_Controller')) {
17
- require_once ( WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-admin.php' );
18
- class WPMS_GAPI_Controller extends MetaSeo_Admin {
19
 
 
 
 
 
 
 
 
 
20
  public $service;
 
 
 
21
  public $timeshift;
 
 
 
22
  private $managequota;
 
 
 
23
  private $wpmsga;
24
 
25
- public function __construct() {
 
 
 
 
 
26
  $google_alanytics = get_option('wpms_google_alanytics');
27
  $this->wpmsga = WPMSGA();
28
- include_once ( WPMETASEO_PLUGIN_DIR . 'inc/autoload.php' );
29
  $config = new Google_Config();
30
  $config->setCacheClass('Google_Cache_Null');
31
  if (function_exists('curl_version')) {
32
  $curlversion = curl_version();
33
- if (isset($curlversion['version']) && ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION') && GADWP_IP_VERSION) {
34
- $config->setClassConfig('Google_IO_Curl', array('options' => array(CURLOPT_IPRESOLVE => GADWP_IP_VERSION))); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6
 
 
 
 
 
 
 
 
 
35
  }
36
  }
37
-
38
  $this->client = new Google_Client($config);
39
- $this->client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
40
  $this->client->setAccessType('offline');
41
  $this->client->setApplicationName('WP Meta SEO');
42
  $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
43
- $this->set_error_timeout();
44
  $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id();
45
- $this->client = WPMSGA_Tools::setClient($this->client , $google_alanytics , $this->access);
46
  $this->service = new Google_Service_Analytics($this->client);
47
  if (!empty($google_alanytics['googleCredentials'])) {
48
  $token = $google_alanytics['googleCredentials'];
@@ -50,14 +80,30 @@ if (!class_exists('WPMS_GAPI_Controller')) {
50
  try {
51
  $this->client->setAccessToken($token);
52
  } catch (Google_IO_Exception $e) {
53
- WPMSGA_Tools::set_cache('wpmsga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
 
 
 
 
54
  } catch (Google_Service_Exception $e) {
55
- WPMSGA_Tools::set_cache('wpmsga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
56
- WPMSGA_Tools::set_cache('wpmsga_dash_gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
57
- $this->reset_token();
 
 
 
 
 
 
 
 
58
  } catch (Exception $e) {
59
- WPMSGA_Tools::set_cache('wpmsga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
60
- $this->reset_token();
 
 
 
 
61
  }
62
  }
63
  }
@@ -68,16 +114,24 @@ if (!class_exists('WPMS_GAPI_Controller')) {
68
  *
69
  * @return boolean
70
  */
71
- public function gapi_errors_handler() {
72
- $errors = WPMSGA_Tools::get_cache('gapi_errors');
 
73
  if ($errors === false || !isset($errors[0])) { // invalid error
74
  return false;
75
  }
76
- if (isset($errors[1][0]['reason']) && ( $errors[1][0]['reason'] == 'invalidCredentials' || $errors[1][0]['reason'] == 'authError' || $errors[1][0]['reason'] == 'insufficientPermissions' || $errors[1][0]['reason'] == 'required' || $errors[1][0]['reason'] == 'keyExpired' )) {
77
- $this->reset_token(false);
 
 
 
 
 
78
  return true;
79
  }
80
- if (isset($errors[1][0]['reason']) && ( $errors[1][0]['reason'] == 'userRateLimitExceeded' || $errors[1][0]['reason'] == 'quotaExceeded' )) {
 
 
81
  if ($this->wpmsga->config->options['api_backoff'] <= 5) {
82
  usleep(rand(100000, 1500000));
83
  return false;
@@ -98,7 +152,8 @@ if (!class_exists('WPMS_GAPI_Controller')) {
98
  * $daily
99
  * @return number
100
  */
101
- public function get_timeouts($daily) {
 
102
  $local_time = time() + $this->timeshift;
103
  if ($daily) {
104
  $nextday = explode('-', date('n-j-Y', strtotime(' +1 day', $local_time)));
@@ -111,140 +166,63 @@ if (!class_exists('WPMS_GAPI_Controller')) {
111
  }
112
  }
113
 
114
- /**
115
- * Generates and retrieves the Access Code
116
- */
117
- public function token_request() {
118
- $authUrl = $this->client->createAuthUrl();
119
- ?>
120
- <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
121
- <table class="wpmsga-settings-options">
122
- <tr>
123
- <td colspan="2" class="wpmsga-settings-info">
124
- <?php echo __("Use this link to get your access code:", 'wp-meta-seo') . ' <a href="' . $authUrl . '" id="gapi-access-code" target="_blank">' . __("Get Access Code", 'wp-meta-seo') . '</a>.'; ?>
125
- </td>
126
- </tr>
127
- <tr>
128
- <td class="wpmsga-settings-title"><label for="ga_dash_code" title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>"><?php echo _e("Access Code:", 'wp-meta-seo'); ?></label></td>
129
- <td><input type="text" id="ga_dash_code" name="ga_dash_code" value="" size="61" required="required" title="<?php _e("Use the red link to get your access code!", 'wp-meta-seo') ?>"></td>
130
- </tr>
131
- <tr>
132
- <td colspan="2"><hr></td>
133
- </tr>
134
- <tr>
135
- <td colspan="2"><input type="submit" class="button button-secondary" name="ga_dash_authorize" value="<?php _e("Save Access Code", 'wp-meta-seo'); ?>" /></td>
136
- </tr>
137
- </table>
138
- </form>
139
- <?php
140
- }
141
-
142
- /**
143
- * Retrieves all Google Analytics Views with details
144
- *
145
- * @return array
146
- */
147
- public function refresh_profiles() {
148
- try {
149
-
150
- $ga_dash_profile_list = array();
151
- $startindex = 1;
152
- $totalresults = 65535; // use something big
153
-
154
- while ($startindex < $totalresults) {
155
-
156
- $profiles = $this->service->management_profiles->listManagementProfiles('~all', '~all', array('start-index' => $startindex));
157
-
158
- $items = $profiles->getItems();
159
-
160
- $totalresults = $profiles->getTotalResults();
161
-
162
- if ($totalresults > 0) {
163
-
164
- foreach ($items as $profile) {
165
- $timetz = new DateTimeZone($profile->getTimezone());
166
- $localtime = new DateTime('now', $timetz);
167
- $timeshift = strtotime($localtime->format('Y-m-d H:i:s')) - time();
168
- $ga_dash_profile_list[] = array($profile->getName(), $profile->getId(), $profile->getwebPropertyId(), $profile->getwebsiteUrl(), $timeshift, $profile->getTimezone(), $profile->getDefaultPage());
169
- $startindex++;
170
- }
171
- }
172
- }
173
-
174
- if (empty($ga_dash_profile_list)) {
175
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': No properties were found in this account!', $this->error_timeout);
176
- } else {
177
- WPMSGA_Tools::delete_cache('last_error');
178
- }
179
- return $ga_dash_profile_list;
180
- } catch (Google_IO_Exception $e) {
181
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
182
- return $ga_dash_profile_list;
183
- } catch (Google_Service_Exception $e) {
184
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
185
- WPMSGA_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
186
- } catch (Exception $e) {
187
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
188
- return $ga_dash_profile_list;
189
- }
190
- }
191
-
192
  /**
193
  * Handles the token reset process
194
- *
195
- * @param
196
- * $all
197
  */
198
- public function reset_token($all = true) {
 
199
  update_option('wpms_google_alanytics', array());
200
  }
201
 
202
  /**
203
  * Get and cache Core Reports
204
- *
205
- * @param
206
- * $projecId
207
- * @param
208
- * $from
209
- * @param
210
- * $to
211
- * @param
212
- * $metrics
213
- * @param
214
- * $options
215
- * @param
216
- * $serial
217
- * @return int|Google_Service_Analytics_GaData
218
  */
219
- private function handle_corereports($projectId, $from, $to, $metrics, $options, $serial) {
 
220
  try {
221
  if ($from == "today") {
222
  $timeouts = 0;
223
  } else {
224
  $timeouts = 1;
225
  }
226
- $transient = WPMSGA_Tools::get_cache($serial);
227
  if ($transient === false) {
228
- if ($this->gapi_errors_handler()) {
229
- return - 23;
230
  }
231
  $data = $this->service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, $options);
232
- WPMSGA_Tools::set_cache($serial, $data, $this->get_timeouts($timeouts));
233
  } else {
234
  $data = $transient;
235
  }
236
  } catch (Google_Service_Exception $e) {
237
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
238
- WPMSGA_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
 
 
 
 
 
 
 
 
239
  return $e->getCode();
240
  } catch (Exception $e) {
241
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
242
  return $e->getCode();
243
  }
244
  if ($data->getRows() > 0) {
245
  return $data;
246
  } else {
247
- return - 21;
248
  }
249
  }
250
 
@@ -255,50 +233,46 @@ if (!class_exists('WPMS_GAPI_Controller')) {
255
  * $serial
256
  * @return string
257
  */
258
- public function get_serial($serial) {
 
259
  return sprintf("%u", crc32($serial));
260
  }
261
 
262
  /**
263
  * Analytics data for Area Charts (Admin Dashboard Widget report)
264
- *
265
- * @param
266
- * $projectId
267
- * @param
268
- * $from
269
- * @param
270
- * $to
271
- * @param
272
- * $query
273
- * @param
274
- * $filter
275
- * @return array|int
276
  */
277
- private function get_areachart_data($projectId, $from, $to, $query, $filter = '') {
 
278
  switch ($query) {
279
- case 'users' :
280
  $title = __("Users", 'wp-meta-seo');
281
  break;
282
- case 'pageviews' :
283
  $title = __("Page Views", 'wp-meta-seo');
284
  break;
285
- case 'visitBounceRate' :
286
  $title = __("Bounce Rate", 'wp-meta-seo');
287
  break;
288
- case 'organicSearches' :
289
  $title = __("Organic Searches", 'wp-meta-seo');
290
  break;
291
- case 'uniquePageviews' :
292
  $title = __("Unique Page Views", 'wp-meta-seo');
293
  break;
294
- default :
295
  $title = __("Sessions", 'wp-meta-seo');
296
  }
297
  $metrics = 'ga:' . $query;
298
  if ($from == "today" || $from == "yesterday") {
299
  $dimensions = 'ga:hour';
300
  $dayorhour = __("Hour", 'wp-meta-seo');
301
- } else if ($from == "365daysAgo" || $from == "1095daysAgo") {
302
  $dimensions = 'ga:yearMonth, ga:month';
303
  $dayorhour = __("Date", 'wp-meta-seo');
304
  } else {
@@ -309,24 +283,27 @@ if (!class_exists('WPMS_GAPI_Controller')) {
309
  if ($filter) {
310
  $options['filters'] = 'ga:pagePath==' . $filter;
311
  }
312
- $serial = 'qr2_' . $this->get_serial($projectId . $from . $metrics . $filter);
313
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
314
  if (is_numeric($data)) {
315
  return $data;
316
  }
317
  $wpmsga_data = array(array($dayorhour, $title));
318
  if ($from == "today" || $from == "yesterday") {
319
  foreach ($data->getRows() as $row) {
320
- $wpmsga_data[] = array((int) $row[0] . ':00', round($row[1], 2));
321
  }
322
- } else if ($from == "365daysAgo" || $from == "1095daysAgo") {
323
  foreach ($data->getRows() as $row) {
324
  /*
325
  * translators:
326
  * Example: 'F, Y' will become 'November, 2015'
327
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
328
  */
329
- $wpmsga_data[] = array(date_i18n(__('F, Y', 'wp-meta-seo'), strtotime($row[0] . '01')), round($row[2], 2));
 
 
 
330
  }
331
  } else {
332
  foreach ($data->getRows() as $row) {
@@ -335,7 +312,10 @@ if (!class_exists('WPMS_GAPI_Controller')) {
335
  * Example: 'l, F j, Y' will become 'Thusday, November 17, 2015'
336
  * For details see: http://php.net/manual/en/function.date.php#refsect1-function.date-parameters
337
  */
338
- $wpmsga_data[] = array(date_i18n(__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])), round($row[2], 2));
 
 
 
339
  }
340
  }
341
 
@@ -344,18 +324,14 @@ if (!class_exists('WPMS_GAPI_Controller')) {
344
 
345
  /**
346
  * Analytics data for Bottom Stats (bottom stats on main report)
347
- *
348
- * @param
349
- * $projectId
350
- * @param
351
- * $from
352
- * @param
353
- * $to
354
- * @param
355
- * $filter
356
- * @return array|int
357
  */
358
- private function get_bottomstats($projectId, $from, $to, $filter = '') {
 
359
  $options = array('dimensions' => null, 'quotaUser' => $this->managequota . 'p' . $projectId);
360
  if ($filter) {
361
  $options['filters'] = 'ga:pagePath==' . $filter;
@@ -363,10 +339,10 @@ if (!class_exists('WPMS_GAPI_Controller')) {
363
  } else {
364
  $metrics = 'ga:sessions,ga:users,ga:pageviews,ga:BounceRate,ga:organicSearches,ga:pageviewsPerSession';
365
  }
366
- $serial = 'qr3_' . $this->get_serial($projectId . $from . $filter);
367
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
368
  if (is_numeric($data)) {
369
- if ($data == - 21) {
370
  return array_fill(0, 6, 0);
371
  } else {
372
  return $data;
@@ -390,126 +366,125 @@ if (!class_exists('WPMS_GAPI_Controller')) {
390
 
391
  /**
392
  * Analytics data for Org Charts & Table Charts (content pages)
393
- *
394
- * @param
395
- * $projectId
396
- * @param
397
- * $from
398
- * @param
399
- * $to
400
- * @param
401
- * $filter
402
- * @return array|int
403
  */
404
- private function get_contentpages($projectId, $from, $to, $filter = '') {
 
405
  $metrics = 'ga:pageviews';
406
  $dimensions = 'ga:pageTitle';
407
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:pageviews', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
408
  if ($filter) {
409
  $options['filters'] = 'ga:pagePath==' . $filter;
410
  }
411
- $serial = 'qr4_' . $this->get_serial($projectId . $from . $filter);
412
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
413
  if (is_numeric($data)) {
414
  return $data;
415
  }
416
  $wpmsga_data = array(array(__("Pages", 'wp-meta-seo'), __("Views", 'wp-meta-seo')));
417
  foreach ($data->getRows() as $row) {
418
- $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
419
  }
420
  return $wpmsga_data;
421
  }
422
 
423
  /**
424
  * Analytics data for Org Charts & Table Charts (referrers)
425
- *
426
- * @param
427
- * $projectId
428
- * @param
429
- * $from
430
- * @param
431
- * $to
432
- * @param
433
- * $filter
434
- * @return array|int
435
  */
436
- private function get_referrers($projectId, $from, $to, $filter = '') {
 
437
  $metrics = 'ga:sessions';
438
  $dimensions = 'ga:source';
439
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
440
  if ($filter) {
441
  $options['filters'] = 'ga:medium==referral;ga:pagePath==' . $filter;
442
  } else {
443
  $options['filters'] = 'ga:medium==referral';
444
  }
445
- $serial = 'qr5_' . $this->get_serial($projectId . $from . $filter);
446
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
447
  if (is_numeric($data)) {
448
  return $data;
449
  }
450
  $wpmsga_data = array(array(__("Referrers", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
451
  foreach ($data->getRows() as $row) {
452
- $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
453
  }
454
  return $wpmsga_data;
455
  }
456
 
457
  /**
458
  * Analytics data for Org Charts & Table Charts (searches)
459
- *
460
- * @param
461
- * $projectId
462
- * @param
463
- * $from
464
- * @param
465
- * $to
466
- * @param
467
- * $filter
468
- * @return array|int
469
  */
470
- private function get_searches($projectId, $from, $to, $filter = '') {
 
471
  $metrics = 'ga:sessions';
472
  $dimensions = 'ga:keyword';
473
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
474
  if ($filter) {
475
  $options['filters'] = 'ga:keyword!=(not set);ga:pagePath==' . $filter;
476
  } else {
477
  $options['filters'] = 'ga:keyword!=(not set)';
478
  }
479
- $serial = 'qr6_' . $this->get_serial($projectId . $from . $filter);
480
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
481
  if (is_numeric($data)) {
482
  return $data;
483
  }
484
 
485
  $wpmsga_data = array(array(__("Searches", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
486
  foreach ($data->getRows() as $row) {
487
- $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
488
  }
489
  return $wpmsga_data;
490
  }
491
 
492
  /**
493
  * Analytics data for Org Charts & Table Charts (location reports)
494
- *
495
- * @param
496
- * $projectId
497
- * @param
498
- * $from
499
- * @param
500
- * $to
501
- * @param
502
- * $filter
503
- * @return array|int
504
  */
505
- private function get_locations($projectId, $from, $to, $filter = '') {
 
506
  $metrics = 'ga:sessions';
507
- $options = "";
508
  $title = __("Countries", 'wp-meta-seo');
509
- $serial = 'qr7_' . $this->get_serial($projectId . $from . $filter);
510
  $dimensions = 'ga:country';
511
  $local_filter = '';
512
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
513
  if ($filter) {
514
  $options['filters'] = 'ga:pagePath==' . $filter;
515
  if ($local_filter) {
@@ -520,16 +495,16 @@ if (!class_exists('WPMS_GAPI_Controller')) {
520
  $options['filters'] = $local_filter;
521
  }
522
  }
523
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
524
  if (is_numeric($data)) {
525
  return $data;
526
  }
527
  $wpmsga_data = array(array($title, __("Sessions", 'wp-meta-seo')));
528
  foreach ($data->getRows() as $row) {
529
  if (isset($row[2])) {
530
- $wpmsga_data[] = array(esc_html($row[0]) . ', ' . esc_html($row[1]), (int) $row[2]);
531
  } else {
532
- $wpmsga_data[] = array(esc_html($row[0]), (int) $row[1]);
533
  }
534
  }
535
  return $wpmsga_data;
@@ -537,76 +512,90 @@ if (!class_exists('WPMS_GAPI_Controller')) {
537
 
538
  /**
539
  * Analytics data for Org Charts (traffic channels, device categories)
540
- *
541
- * @param
542
- * $projectId
543
- * @param
544
- * $from
545
- * @param
546
- * $to
547
- * @param
548
- * $query
549
- * @param
550
- * $filter
551
- * @return array|int
552
  */
553
- private function get_orgchart_data($projectId, $from, $to, $query, $filter = '') {
 
554
  $metrics = 'ga:sessions';
555
  $dimensions = 'ga:' . $query;
556
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
557
  if ($filter) {
558
  $options['filters'] = 'ga:pagePath==' . $filter;
559
  }
560
- $serial = 'qr8_' . $this->get_serial($projectId . $from . $query . $filter);
561
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
562
  if (is_numeric($data)) {
563
  return $data;
564
  }
565
- $block = ( $query == 'channelGrouping' ) ? __("Channels", 'wp-meta-seo') : __("Devices", 'wp-meta-seo');
566
- $wpmsga_data = array(array('<div style="color:black; font-size:1.1em">' . $block . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>', ""));
 
 
 
 
 
 
567
  foreach ($data->getRows() as $row) {
568
  $shrink = explode(" ", $row[0]);
569
- $wpmsga_data[] = array('<div style="color:black; font-size:1.1em">' . esc_html($shrink[0]) . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $row[1] . '</div>', '<div style="color:black; font-size:1.1em">' . $block . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>');
 
 
 
 
 
570
  }
571
  return $wpmsga_data;
572
  }
573
 
574
  /**
575
- * Analytics data for Pie Charts (traffic mediums, serach engines, social networks, browsers, screen rsolutions, etc.)
576
- *
577
- * @param
578
- * $projectId
579
- * @param
580
- * $from
581
- * @param
582
- * $to
583
- * @param
584
- * $query
585
- * @param
586
- * $filter
587
- * @return array|int
588
  */
589
- private function get_piechart_data($projectId, $from, $to, $query, $filter = '') {
 
590
  $metrics = 'ga:sessions';
591
  $dimensions = 'ga:' . $query;
592
 
593
  if ($query == 'source') {
594
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
595
  if ($filter) {
596
  $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set);ga:pagePath==' . $filter;
597
  } else {
598
  $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set)';
599
  }
600
  } else {
601
- $options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
 
 
 
 
602
  if ($filter) {
603
  $options['filters'] = 'ga:' . $query . '!=(not set);ga:pagePath==' . $filter;
604
  } else {
605
  $options['filters'] = 'ga:' . $query . '!=(not set)';
606
  }
607
  }
608
- $serial = 'qr10_' . $this->get_serial($projectId . $from . $query . $filter);
609
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
610
  if (is_numeric($data)) {
611
  return $data;
612
  }
@@ -615,7 +604,7 @@ if (!class_exists('WPMS_GAPI_Controller')) {
615
  $included = 0;
616
  foreach ($data->getRows() as $row) {
617
  if ($i < 20) {
618
- $wpmsga_data[] = array(str_replace("(none)", "direct", esc_html($row[0])), (int) $row[1]);
619
  $included += $row[1];
620
  $i++;
621
  } else {
@@ -633,27 +622,25 @@ if (!class_exists('WPMS_GAPI_Controller')) {
633
 
634
  /**
635
  * Analytics data for Frontend Widget (chart data and totals)
636
- *
637
- * @param
638
- * $projectId
639
- * @param
640
- * $period
641
- * @param
642
- * $anonim
643
- * @return array|int
644
  */
645
- public function frontend_widget_stats($projectId, $from, $anonim) {
 
646
  $content = '';
647
  $to = 'yesterday';
648
  $metrics = 'ga:sessions';
649
  $dimensions = 'ga:date,ga:dayOfWeekName';
650
  $options = array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId);
651
- $serial = 'qr2_' . $this->get_serial($projectId . $from . $metrics);
652
- $data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
653
  if (is_numeric($data)) {
654
  return $data;
655
  }
656
  $wpmsga_data = array(array(__("Date", 'wp-meta-seo'), __("Sessions", 'wp-meta-seo')));
 
657
  if ($anonim) {
658
  $max_array = array();
659
  foreach ($data->getRows() as $item) {
@@ -662,7 +649,10 @@ if (!class_exists('WPMS_GAPI_Controller')) {
662
  $max = max($max_array) ? max($max_array) : 1;
663
  }
664
  foreach ($data->getRows() as $row) {
665
- $wpmsga_data[] = array(date_i18n(__('l, F j, Y', 'wp-meta-seo'), strtotime($row[0])), ( $anonim ? round($row[2] * 100 / $max, 2) : (int) $row[2] ));
 
 
 
666
  }
667
  $totals = $data->getTotalsForAllResults();
668
  return array($wpmsga_data, $anonim ? 0 : number_format_i18n($totals['ga:sessions']));
@@ -670,36 +660,54 @@ if (!class_exists('WPMS_GAPI_Controller')) {
670
 
671
  /**
672
  * Analytics data for Realtime component (the real-time report)
673
- *
674
- * @param
675
- * $projectId
676
- * @return array|int
677
  */
678
- private function get_realtime($projectId) {
 
679
  $metrics = 'rt:activeUsers';
680
  $dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
681
  try {
682
- $serial = 'qr_realtimecache_' . $this->get_serial($projectId);
683
- $transient = WPMSGA_Tools::get_cache($serial);
684
  if ($transient === false) {
685
- if ($this->gapi_errors_handler()) {
686
- return - 23;
687
  }
688
- $data = $this->service->data_realtime->get('ga:' . $projectId, $metrics, array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId));
689
- WPMSGA_Tools::set_cache($serial, $data, 55);
 
 
 
 
 
 
 
690
  } else {
691
  $data = $transient;
692
  }
693
  } catch (Google_Service_Exception $e) {
694
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
695
- WPMSGA_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
 
 
 
 
 
 
 
 
696
  return $e->getCode();
697
  } catch (Exception $e) {
698
- WPMSGA_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
 
 
 
 
699
  return $e->getCode();
700
  }
701
  if ($data->getRows() < 1) {
702
- return - 21;
703
  }
704
  $i = 0;
705
  $wpmsga_data = $data;
@@ -710,64 +718,68 @@ if (!class_exists('WPMS_GAPI_Controller')) {
710
  return array($wpmsga_data);
711
  }
712
 
713
- private function map($map) {
714
- $map = explode('.', $map);
715
- if (isset($map[1])) {
716
- $map[0] += ord('map');
717
- return implode('.', $map);
718
- } else {
719
- return str_ireplace('map', chr(112), $map[0]);
720
- }
721
- }
722
-
723
  /**
724
  * Handles ajax requests and calls the needed methods
725
- * @param
726
- * $projectId
727
- * @param
728
- * $query
729
- * @param
730
- * $from
731
- * @param
732
- * $to
733
- * @param
734
- * $filter
735
- * @return number|Google_Service_Analytics_GaData
736
  */
737
- public function get($projectId, $query, $from = false, $to = false, $filter = '') {
 
738
  if (empty($projectId) || !is_numeric($projectId)) {
739
- wp_die(- 26);
740
  }
741
- if (in_array($query, array('sessions', 'users', 'organicSearches', 'visitBounceRate', 'pageviews', 'uniquePageviews'))) {
742
- return $this->get_areachart_data($projectId, $from, $to, $query, $filter);
 
 
 
 
 
 
 
 
 
743
  }
744
  if ($query == 'bottomstats') {
745
- return $this->get_bottomstats($projectId, $from, $to, $filter);
746
  }
747
  if ($query == 'locations') {
748
- return $this->get_locations($projectId, $from, $to, $filter);
749
  }
750
  if ($query == 'referrers') {
751
- return $this->get_referrers($projectId, $from, $to, $filter);
752
  }
753
  if ($query == 'contentpages') {
754
- return $this->get_contentpages($projectId, $from, $to, $filter);
755
  }
756
  if ($query == 'searches') {
757
- return $this->get_searches($projectId, $from, $to, $filter);
758
  }
759
  if ($query == 'realtime') {
760
- return $this->get_realtime($projectId);
761
  }
762
  if ($query == 'channelGrouping' || $query == 'deviceCategory') {
763
- return $this->get_orgchart_data($projectId, $from, $to, $query, $filter);
764
- }
765
- if (in_array($query, array('medium', 'visitorType', 'socialNetwork', 'source', 'browser', 'operatingSystem', 'screenResolution', 'mobileDeviceBranding'))) {
766
- return $this->get_piechart_data($projectId, $from, $to, $query, $filter);
767
- }
768
- wp_die(- 27);
 
 
 
 
 
 
 
 
 
 
 
769
  }
770
-
771
  }
772
-
773
  }
10
 
11
  // Exit if accessed directly
12
 
13
+ /* Prohibit direct script loading */
14
+ defined('ABSPATH') || die('No direct script access allowed!');
15
 
16
+ if (!class_exists('WpmsGapiController')) {
17
+ require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-admin.php');
 
18
 
19
+ /**
20
+ * Class WpmsGapiController
21
+ */
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;
40
 
41
+ /**
42
+ * WpmsGapiController constructor.
43
+ */
44
+ public function __construct()
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');
52
  if (function_exists('curl_version')) {
53
  $curlversion = curl_version();
54
+ if (isset($curlversion['version']) && (version_compare(PHP_VERSION, '5.3.0') >= 0)
55
+ && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION')
56
+ && GADWP_IP_VERSION) {
57
+ $config->setClassConfig(
58
+ 'Google_IO_Curl',
59
+ array(
60
+ 'options' => array(
61
+ CURLOPT_IPRESOLVE => GADWP_IP_VERSION
62
+ )
63
+ )
64
+ ); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6
65
  }
66
  }
67
+
68
  $this->client = new Google_Client($config);
69
+ $this->client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
70
  $this->client->setAccessType('offline');
71
  $this->client->setApplicationName('WP Meta SEO');
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'];
80
  try {
81
  $this->client->setAccessToken($token);
82
  } catch (Google_IO_Exception $e) {
83
+ WpmsGaTools::setCache(
84
+ 'wpmsga_dash_lasterror',
85
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
86
+ $this->error_timeout
87
+ );
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(
95
+ 'wpmsga_dash_gapi_errors',
96
+ $e->getCode(),
97
+ $this->error_timeout
98
+ );
99
+ $this->resetToken();
100
  } catch (Exception $e) {
101
+ WpmsGaTools::setCache(
102
+ 'wpmsga_dash_lasterror',
103
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
104
+ $this->error_timeout
105
+ );
106
+ $this->resetToken();
107
  }
108
  }
109
  }
114
  *
115
  * @return boolean
116
  */
117
+ public function gapiErrorsHandler()
118
+ {
119
+ $errors = WpmsGaTools::getCache('gapi_errors');
120
  if ($errors === false || !isset($errors[0])) { // invalid error
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;
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)));
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;
195
  }
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));
203
  } else {
204
  $data = $transient;
205
  }
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(
213
+ 'gapi_errors',
214
+ $e->getCode(),
215
+ $this->error_timeout
216
+ );
217
  return $e->getCode();
218
  } catch (Exception $e) {
219
+ WpmsGaTools::setCache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
220
  return $e->getCode();
221
  }
222
  if ($data->getRows() > 0) {
223
  return $data;
224
  } else {
225
+ return -21;
226
  }
227
  }
228
 
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 {
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:
300
  * Example: 'F, Y' will become 'November, 2015'
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
  }
308
  } else {
309
  foreach ($data->getRows() as $row) {
312
  * Example: 'l, F j, Y' will become 'Thusday, November 17, 2015'
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
  }
320
  }
321
 
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;
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
 
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;
418
  } else {
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;
452
  } else {
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;
490
  if ($local_filter) {
495
  $options['filters'] = $local_filter;
496
  }
497
  }
498
+ $data = $this->handleCorereports($projectId, $from, $to, $metrics, $options, $serial);
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
 
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;
557
  }
558
 
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;
582
  } else {
583
  $options['filters'] = 'ga:medium==organic;ga:keyword!=(not set)';
584
  }
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;
593
  } else {
594
  $options['filters'] = 'ga:' . $query . '!=(not set)';
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
  }
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 {
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) {
649
  $max = max($max_array) ? max($max_array) : 1;
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();
658
  return array($wpmsga_data, $anonim ? 0 : number_format_i18n($totals['ga:sessions']));
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);
686
  } else {
687
  $data = $transient;
688
  }
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(
696
+ 'gapi_errors',
697
+ $e->getCode(),
698
+ $this->error_timeout
699
+ );
700
  return $e->getCode();
701
  } catch (Exception $e) {
702
+ WpmsGaTools::setCache(
703
+ 'last_error',
704
+ date('Y-m-d H:i:s') . ': ' . esc_html($e),
705
+ $this->error_timeout
706
+ );
707
  return $e->getCode();
708
  }
709
  if ($data->getRows() < 1) {
710
+ return -21;
711
  }
712
  $i = 0;
713
  $wpmsga_data = $data;
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(
737
+ 'sessions',
738
+ 'users',
739
+ 'organicSearches',
740
+ 'visitBounceRate',
741
+ 'pageviews',
742
+ 'uniquePageviews'
743
+ );
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
+
769
+ $arrs = array(
770
+ 'medium',
771
+ 'visitorType',
772
+ 'socialNetwork',
773
+ 'source',
774
+ 'browser',
775
+ 'operatingSystem',
776
+ 'screenResolution',
777
+ 'mobileDeviceBranding'
778
+ );
779
+ if (in_array($query, $arrs)) {
780
+ return $this->getPiechartData($projectId, $from, $to, $query, $filter);
781
+ }
782
+ wp_die(-27);
783
  }
 
784
  }
 
785
  }
inc/google_analytics/wpmstools.php CHANGED
@@ -9,65 +9,49 @@
9
  * Modified by Joomunited
10
  */
11
 
12
- // Exit if accessed directly
 
13
 
14
- if (!defined('ABSPATH'))
15
- exit();
16
 
17
- if (!class_exists('WPMSGA_Tools')) {
18
-
19
- class WPMSGA_Tools {
20
-
21
- /*
 
22
  * get google analytics client
 
 
 
 
23
  */
24
- public static function setClient($client , $access , $access_default) {
25
- if(isset($access['wpmsga_dash_userapi']) && $access['wpmsga_dash_userapi'] == 1){
26
- if(!empty($access['wpmsga_dash_clientid']) && !empty($access['wpmsga_dash_clientsecret'])){
 
27
  $client->setClientId($access['wpmsga_dash_clientid']);
28
  $client->setClientSecret($access['wpmsga_dash_clientsecret']);
29
- }else{
30
  $client->setClientId($access_default[0]);
31
  $client->setClientSecret($access_default[1]);
32
  }
33
- }else{
34
  $client->setClientId($access_default[0]);
35
  $client->setClientSecret($access_default[1]);
36
  }
37
 
38
  return $client;
39
  }
40
-
41
- /*
42
- * get country code
43
- */
44
- public static function get_countrycodes() {
45
- include_once 'iso3166.php';
46
- return $country_codes;
47
- }
48
-
49
- /*
50
- * get_default domain
51
- */
52
- public static function guess_default_domain($profiles) {
53
- $domain = get_option('siteurl');
54
- $domain = str_ireplace(array('http://', 'https://'), '', $domain);
55
- if (!empty($profiles)) {
56
- foreach ($profiles as $items) {
57
- if (strpos($items[3], $domain)) {
58
- return $items[1];
59
- }
60
- }
61
- return $profiles[0][1];
62
- } else {
63
- return '';
64
- }
65
- }
66
-
67
- /*
68
- * get_selected_profile
69
  */
70
- public static function get_selected_profile($profiles, $profile) {
 
71
  if (!empty($profiles)) {
72
  foreach ($profiles as $item) {
73
  if ($item[1] == $profile) {
@@ -75,12 +59,17 @@ if (!class_exists('WPMSGA_Tools')) {
75
  }
76
  }
77
  }
 
78
  }
79
-
80
- /*
81
  * get color
 
 
 
82
  */
83
- public static function colourVariator($colour, $per) {
 
84
  $colour = substr($colour, 1);
85
  $rgb = '';
86
  $per = $per / 100 * 255;
@@ -88,40 +77,49 @@ if (!class_exists('WPMSGA_Tools')) {
88
  // Darker
89
  $per = abs($per);
90
  for ($x = 0; $x < 3; $x++) {
91
- $c = hexdec(substr($colour, ( 2 * $x), 2)) - $per;
92
- $c = ( $c < 0 ) ? 0 : dechex($c);
93
- $rgb .= ( strlen($c) < 2 ) ? '0' . $c : $c;
94
  }
95
  } else {
96
  // Lighter
97
  for ($x = 0; $x < 3; $x++) {
98
- $c = hexdec(substr($colour, ( 2 * $x), 2)) + $per;
99
- $c = ( $c > 255 ) ? 'ff' : dechex($c);
100
- $rgb .= ( strlen($c) < 2 ) ? '0' . $c : $c;
101
  }
102
  }
103
  return '#' . $rgb;
104
  }
105
 
106
- public static function variations($base) {
 
 
 
 
 
107
  $variations[] = $base;
108
- $variations[] = self::colourVariator($base, - 10);
109
- $variations[] = self::colourVariator($base, + 10);
110
- $variations[] = self::colourVariator($base, + 20);
111
- $variations[] = self::colourVariator($base, - 20);
112
- $variations[] = self::colourVariator($base, + 30);
113
- $variations[] = self::colourVariator($base, - 30);
114
  return $variations;
115
  }
116
-
117
- /*
118
  * check roles
 
 
 
119
  */
120
- public static function check_roles($access_level, $tracking = false) {
 
121
  if (is_user_logged_in() && isset($access_level)) {
122
  $current_user = wp_get_current_user();
123
- $roles = (array) $current_user->roles;
124
- if (( current_user_can('manage_options') ) && !$tracking) {
125
  return true;
126
  }
127
  if (count(array_intersect($roles, $access_level)) > 0) {
@@ -130,37 +128,37 @@ if (!class_exists('WPMSGA_Tools')) {
130
  return false;
131
  }
132
  }
 
133
  }
134
-
135
- /*
136
- * remove cookie
137
- */
138
- public static function unset_cookie($name) {
139
- $name = 'wpmsga_wg_' . $name;
140
- setcookie($name, '', time() - 3600, '/');
141
- $name = 'wpmsga_ir_' . $name;
142
- setcookie($name, '', time() - 3600, '/');
143
- }
144
-
145
- /*
146
  * set cache
 
 
 
147
  */
148
- public static function set_cache($name, $value, $expiration = 0) {
149
- $option = array('value' => $value, 'expires' => time() + (int) $expiration);
 
150
  update_option('wpmsga_cache_' . $name, $option);
151
  }
152
-
153
- /*
154
  * remove cache
 
155
  */
156
- public static function delete_cache($name) {
 
157
  delete_option('wpmsga_cache_' . $name);
158
  }
159
-
160
- /*
161
  * get cache
 
 
162
  */
163
- public static function get_cache($name) {
 
164
  $option = get_option('wpmsga_cache_' . $name);
165
 
166
  if (false === $option || !isset($option['value']) || !isset($option['expires'])) {
@@ -174,58 +172,39 @@ if (!class_exists('WPMSGA_Tools')) {
174
  return $option['value'];
175
  }
176
  }
177
-
178
- /*
179
- * get site cache
180
- */
181
- public static function set_site_cache($name, $value, $expiration = 0) {
182
- $option = array('value' => $value, 'expires' => time() + (int) $expiration);
183
- update_site_option('wpmsga_cache_' . $name, $option);
184
- }
185
-
186
- /*
187
- * remove site cache
188
- */
189
- public static function delete_site_cache($name) {
190
- delete_site_option('wpmsga_cache_' . $name);
191
- }
192
-
193
- /*
194
- * get site cache
195
- */
196
- public static function get_site_cache($name) {
197
- $option = get_site_option('wpmsga_cache_' . $name);
198
 
199
- if (false === $option || !isset($option['value']) || !isset($option['expires'])) {
200
- return false;
201
- }
202
-
203
- if ($option['expires'] < time()) {
204
- delete_option('wpmsga_cache_' . $name);
205
- return false;
206
- } else {
207
- return $option['value'];
208
- }
209
- }
210
-
211
- /*
212
  * clear cache
213
  */
214
- public static function clear_cache() {
 
215
  global $wpdb;
216
- $sqlquery = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'wpmsga_cache_qr%%'");
217
  }
218
-
219
- public static function get_root_domain( $domain ) {
220
- $root = explode( '/', $domain );
221
- preg_match( "/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", str_ireplace( 'www', '', isset( $root[2] ) ? $root[2] : $domain ), $root );
 
 
 
 
 
 
 
 
 
222
  return $root;
223
  }
224
-
225
- public static function strip_protocol( $domain ) {
226
- return str_replace( array( "https://", "http://", " " ), "", $domain );
227
- }
228
 
 
 
 
 
 
 
 
 
229
  }
230
 
231
  }
9
  * Modified by Joomunited
10
  */
11
 
12
+ /* Prohibit direct script loading */
13
+ defined('ABSPATH') || die('No direct script access allowed!');
14
 
15
+ if (!class_exists('WpmsGaTools')) {
 
16
 
17
+ /**
18
+ * Class WpmsGaTools
19
+ */
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']);
35
+ } else {
36
  $client->setClientId($access_default[0]);
37
  $client->setClientSecret($access_default[1]);
38
  }
39
+ } else {
40
  $client->setClientId($access_default[0]);
41
  $client->setClientSecret($access_default[1]);
42
  }
43
 
44
  return $client;
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) {
59
  }
60
  }
61
  }
62
+ return false;
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;
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
  }
92
  return '#' . $rgb;
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
  }
125
  if (count(array_intersect($roles, $access_level)) > 0) {
128
  return false;
129
  }
130
  }
131
+ return false;
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
+ {
152
  delete_option('wpmsga_cache_' . $name);
153
  }
154
+
155
+ /**
156
  * get cache
157
+ * @param string $name option cache name
158
+ * @return bool
159
  */
160
+ public static function getCache($name)
161
+ {
162
  $option = get_option('wpmsga_cache_' . $name);
163
 
164
  if (false === $option || !isset($option['value']) || !isset($option['expires'])) {
172
  return $option['value'];
173
  }
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
+ );
197
  return $root;
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
 
210
  }
inc/pages/content-meta.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
- if (!class_exists('MetaSeo_Content_List_Table')) {
3
- require_once( WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-content-list-table.php' );
4
  }
5
 
6
- $metaseo_list_table = new MetaSeo_Content_List_Table();
7
- $metaseo_list_table->process_action();
8
  $metaseo_list_table->prepare_items();
9
 
10
  if (!empty($_REQUEST['_wp_http_referer'])) {
@@ -31,7 +31,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
31
  if ($(this).is(':checked')) {
32
  var follow = 'follow';
33
  } else {
34
- var follow = 'nofollow';
35
  }
36
  metaseo_update_pagefollow(page_id, follow);
37
  });
@@ -41,28 +41,28 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
41
  if ($(this).is(':checked')) {
42
  var index = 'index';
43
  } else {
44
- var index = 'noindex';
45
  }
46
  metaseo_update_pageindex(page_id, index);
47
  });
48
 
49
  $('.metaseo-metatitle').each(function () {
50
- metaseo_titlelength(this.id, false, false);
51
- metaseo_updateTitle(this.id, false, false);
52
  });
53
 
54
  $('.metaseo-metakeywords').each(function () {
55
- metaseo_keywordlength(this.id, false, false);
56
- metaseo_updatekeywords(this.id, false, false);
57
  });
58
 
59
  $('.metaseo-metadesc').each(function () {
60
- metaseo_desclength(this.id, false, false);
61
  metaseo_updateDesc(this.id, false);
62
  });
63
 
64
  $('.metaseo-metatitle').bind('input propertychange', function () {
65
- metaseo_titlelength(this.id, true);
66
  });
67
 
68
  $('.metaseo-metatitle').blur(function () {
@@ -70,7 +70,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
70
  });
71
 
72
  $('.metaseo-metakeywords').bind('input propertychange', function () {
73
- metaseo_keywordlength(this.id, true);
74
  });
75
 
76
  $('.metaseo-metakeywords').blur(function () {
@@ -78,7 +78,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
78
  });
79
 
80
  $('.metaseo-metadesc').bind('input propertychange', function () {
81
- metaseo_desclength(this.id, true);
82
  });
83
 
84
  $('.metaseo-metadesc').blur(function () {
@@ -87,7 +87,7 @@ if (!empty($_REQUEST['_wp_http_referer'])) {
87
 
88
  $('.metaseo-metadesc, .metaseo-metatitle').bind('input propertychange', function () {
89
  var idNumber = this.id.substr(this.id.lastIndexOf('-') + 1);
90
- if (this.id == 'metaseo-metatitle-' + idNumber) {
91
  if (!$(this).val()) {
92
  var post_title = $('#post-title-' + idNumber).text();
93
  $('#snippet_title' + idNumber).text(post_title);
1
  <?php
2
+ if (!class_exists('MetaSeoContentListTable')) {
3
+ require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-content-list-table.php');
4
  }
5
 
6
+ $metaseo_list_table = new MetaSeoContentListTable();
7
+ $metaseo_list_table->processAction();
8
  $metaseo_list_table->prepare_items();
9
 
10
  if (!empty($_REQUEST['_wp_http_referer'])) {
31
  if ($(this).is(':checked')) {
32
  var follow = 'follow';
33
  } else {
34
+ follow = 'nofollow';
35
  }
36
  metaseo_update_pagefollow(page_id, follow);
37
  });
41
  if ($(this).is(':checked')) {
42
  var index = 'index';
43
  } else {
44
+ index = 'noindex';
45
  }
46
  metaseo_update_pageindex(page_id, index);
47
  });
48
 
49
  $('.metaseo-metatitle').each(function () {
50
+ metaseo_titlelength(this.id, false);
51
+ metaseo_updateTitle(this.id, false);
52
  });
53
 
54
  $('.metaseo-metakeywords').each(function () {
55
+ metaseo_keywordlength(this.id);
56
+ metaseo_updatekeywords(this.id, false);
57
  });
58
 
59
  $('.metaseo-metadesc').each(function () {
60
+ metaseo_desclength(this.id);
61
  metaseo_updateDesc(this.id, false);
62
  });
63
 
64
  $('.metaseo-metatitle').bind('input propertychange', function () {
65
+ metaseo_titlelength(this.id, false);
66
  });
67
 
68
  $('.metaseo-metatitle').blur(function () {
70
  });
71
 
72
  $('.metaseo-metakeywords').bind('input propertychange', function () {
73
+ metaseo_keywordlength(this.id);
74
  });
75
 
76
  $('.metaseo-metakeywords').blur(function () {
78
  });
79
 
80
  $('.metaseo-metadesc').bind('input propertychange', function () {
81
+ metaseo_desclength(this.id);
82
  });
83
 
84
  $('.metaseo-metadesc').blur(function () {
87
 
88
  $('.metaseo-metadesc, .metaseo-metatitle').bind('input propertychange', function () {
89
  var idNumber = this.id.substr(this.id.lastIndexOf('-') + 1);
90
+ if (this.id === 'metaseo-metatitle-' + idNumber) {
91
  if (!$(this).val()) {
92
  var post_title = $('#post-title-' + idNumber).text();
93
  $('#snippet_title' + idNumber).text(post_title);
inc/pages/dashboard.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
- if (!class_exists('MetaSeo_Dashboard')) {
3
- require_once( WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-dashboard.php' );
 
4
  }
5
 
6
  wp_enqueue_style('m-style-qtip');
@@ -10,25 +11,32 @@ wp_enqueue_style('wpms-myqtip');
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 MetaSeo_Dashboard();
14
  $options_dashboard = get_option('options_dashboard');
15
- $error_404 = $dashboard->get_404_link();
16
  $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.php';
17
  ?>
18
  <h1 style="text-align: center;"><?php _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" alt="<?php _e('It’s better using a permalink structure that is adding in your URL the category name and content title. This parameter can be changed in Settings > Permalinks WordPress menu. Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
 
 
 
 
23
  <div class="row panel-statistics">
24
  <div class="tooltipped">
25
  <div class="panel panel-updates dashboard-card">
26
  <div class="panel-body">
27
  <div class="row">
28
  <div class="wpms_dashboard_widgets_left">
29
- <h4 class="panel-title dashboard-title"><?php _e('PERMALINKS SETTINGS','wp-meta-seo') ?></h4>
 
 
30
  <h3 class="dashboard-title percent_1">50%</h3>
31
- <p class="dashboard-title percent_2"><?php _e('Optimized at:','wp-meta-seo') ?> <span class="percent">50%</span></p>
 
32
  </div>
33
  <div class="wpms_dashboard_widgets_right">
34
  <div class="progress-rating">
@@ -42,20 +50,28 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
42
  </div>
43
  </div>
44
 
45
- <div class="wpms_dash_widgets wpms_dash_metatitle" alt="<?php _e('Meta titles are displayed in search engine results as a page title. It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the met information on your most popular pages', 'wp-meta-seo') ?>">
 
 
 
46
  <div class="row panel-statistics">
47
  <div class="tooltipped">
48
  <div class="panel panel-updates dashboard-card">
49
  <div class="panel-body">
50
  <div class="row">
51
  <div class="wpms_dashboard_widgets_left">
52
- <h4 class="panel-title dashboard-title"><?php _e('META TITLE','wp-meta-seo') ?></h4>
 
 
53
  <h3 class="dashboard-title percent_1">0%</h3>
54
- <p class="dashboard-title percent_2"><?php _e('Meta title filled:','wp-meta-seo') ?> <span class="percent">0/0</span></p>
 
 
 
55
  </div>
56
  <div class="wpms_dashboard_widgets_right">
57
  <div class="progress-rating">
58
- <div class="determinate percent_3" style="width: 0%"></div>
59
  </div>
60
  </div>
61
  </div>
@@ -65,20 +81,29 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
65
  </div>
66
  </div>
67
 
68
- <div class="wpms_dash_widgets wpms_dash_metadesc" alt="<?php _e('Meta descriptions are displayed in search engine results as a page description. It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the meta information on your most popular pages.', 'wp-meta-seo') ?>">
 
 
 
 
69
  <div class="row panel-statistics">
70
  <div class="tooltipped">
71
  <div class="panel panel-updates dashboard-card">
72
  <div class="panel-body">
73
  <div class="row">
74
  <div class="wpms_dashboard_widgets_left">
75
- <h4 class="panel-title dashboard-title"><?php _e('META DESCRIPTION','wp-meta-seo') ?></h4>
 
 
76
  <h3 class="dashboard-title percent_1">0%</h3>
77
- <p class="dashboard-title percent_2"><?php _e('Meta description filled:','wp-meta-seo') ?> <span class="percent">0/0</span></p>
 
 
 
78
  </div>
79
  <div class="wpms_dashboard_widgets_right">
80
  <div class="progress-rating">
81
- <div class="determinate percent_3" style="width: 0%"></div>
82
  </div>
83
  </div>
84
  </div>
@@ -89,33 +114,40 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
89
  </div>
90
 
91
  <?php
92
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
93
- if(!class_exists('MetaSeo_Addon_Admin')){
94
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
95
  }
96
- $metaseo_addon = new MetaSeo_Addon_Admin();
97
- $duplicate_metatitle = $metaseo_addon->wpms_get_duplicate_metatitle();
98
- $duplicate_metadesc = $metaseo_addon->wpms_get_duplicate_metadesc();
99
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
100
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
101
-
102
  }
103
  ?>
104
 
105
- <div class="wpms_dash_widgets wpms_dash_imgsresize" alt="<?php _e('Display image at its natural size, do not use HTML resize. It happens usually when you use handles to resize an image. You have a bulk edition tool to fix that.', 'wp-meta-seo') ?>">
 
 
 
106
  <div class="row panel-statistics">
107
  <div class="tooltipped">
108
  <div class="panel panel-updates dashboard-card">
109
  <div class="panel-body">
110
  <div class="row">
111
  <div class="wpms_dashboard_widgets_left">
112
- <h4 class="panel-title dashboard-title"><?php _e('HTML IMAGE RESIZING','wp-meta-seo') ?></h4>
 
 
113
  <h3 class="dashboard-title percent_1">0%</h3>
114
- <p class="dashboard-title percent_2"><?php _e('Wrong resized images:','wp-meta-seo') ?> <span class="percent">0/0</span></p>
 
 
 
115
  </div>
116
  <div class="wpms_dashboard_widgets_right">
117
  <div class="progress-rating">
118
- <div class="determinate percent_3" style="width: 0%"></div>
119
  </div>
120
  </div>
121
  </div>
@@ -125,20 +157,30 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
125
  </div>
126
  </div>
127
 
128
- <div class="wpms_dash_widgets wpms_dash_imgsmeta" alt="<?php _e('We recommend to use both alt text and image title. The main advantage is that it helps search engines discover your images and display them in image search results. Plus, these tags improve the accessibility of your site and give more information about your images. Use our bulk image tool to quickly check and fix that.', 'wp-meta-seo') ?>">
 
 
 
 
 
129
  <div class="row panel-statistics">
130
  <div class="tooltipped">
131
  <div class="panel panel-updates dashboard-card">
132
  <div class="panel-body">
133
  <div class="row">
134
  <div class="wpms_dashboard_widgets_left">
135
- <h4 class="panel-title dashboard-title"><?php _e('IMAGE TITLE/ALT','wp-meta-seo') ?></h4>
 
 
136
  <h3 class="dashboard-title percent_1">0%</h3>
137
- <p class="dashboard-title percent_2"><?php _e('Image data filled (in content):','wp-meta-seo') ?> <span class="percent">0/0</span></p>
 
 
 
138
  </div>
139
  <div class="wpms_dashboard_widgets_right">
140
  <div class="progress-rating">
141
- <div class="determinate percent_3" style="width: 0%"></div>
142
  </div>
143
  </div>
144
  </div>
@@ -148,20 +190,28 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
148
  </div>
149
  </div>
150
 
151
- <div class="wpms_dash_widgets wpms_dash_newcontent" alt="<?php _e('It is highly recommended to update or add new content on your website quite frequently. At least 3 updated or new content per month would be great :)', 'wp-meta-seo') ?>">
 
 
 
152
  <div class="row panel-statistics">
153
  <div class="tooltipped">
154
  <div class="panel panel-updates dashboard-card">
155
  <div class="panel-body">
156
  <div class="row">
157
  <div class="wpms_dashboard_widgets_left">
158
- <h4 class="panel-title dashboard-title"><?php _e('NEW OR UPDATED CONTENT','wp-meta-seo') ?></h4>
 
 
159
  <h3 class="dashboard-title percent_1">0%</h3>
160
- <p class="dashboard-title percent_2"><?php _e('Latest month new or updated content:','wp-meta-seo') ?> <span class="percent">0</span></p>
 
 
 
161
  </div>
162
  <div class="wpms_dashboard_widgets_right">
163
  <div class="progress-rating">
164
- <div class="determinate percent_3" style="width: 0%"></div>
165
  </div>
166
  </div>
167
  </div>
@@ -171,20 +221,28 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
171
  </div>
172
  </div>
173
 
174
- <div class="wpms_dash_widgets wpms_dash_linkmeta" alt="<?php _e('The link title attribute does not have any SEO value for links. BUT links titles can influence click behavior for users, which may indirectly affect your SEO performance', 'wp-meta-seo') ?>">
 
 
 
175
  <div class="row panel-statistics">
176
  <div class="tooltipped">
177
  <div class="panel panel-updates dashboard-card">
178
  <div class="panel-body">
179
  <div class="row">
180
  <div class="wpms_dashboard_widgets_left">
181
- <h4 class="panel-title dashboard-title"><?php _e('LINK TITLES','wp-meta-seo') ?></h4>
 
 
182
  <h3 class="dashboard-title percent_1">0%</h3>
183
- <p class="dashboard-title percent_2"><?php _e('Links title completed:','wp-meta-seo') ?> <span class="percent">0/0</span></p>
 
 
 
184
  </div>
185
  <div class="wpms_dashboard_widgets_right">
186
  <div class="progress-rating">
187
- <div class="determinate percent_3" style="width: 0%"></div>
188
  </div>
189
  </div>
190
  </div>
@@ -194,20 +252,32 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
194
  </div>
195
  </div>
196
 
197
- <div class="wpms_dash_widgets wpms_dash_404_error" alt="<?php _e('A website with a bunch of 404 errors doesn’t provide a good user experience, which is significantly important in content marketing and SEO. We recommend to use our internal broken link checker and redirect tool to fix all the 404 error you can periodically.', 'wp-meta-seo') ?>">
 
 
 
 
198
  <div class="row panel-statistics">
199
  <div class="tooltipped">
200
  <div class="panel panel-updates dashboard-card">
201
  <div class="panel-body">
202
  <div class="row">
203
  <div class="wpms_dashboard_widgets_left">
204
- <h4 class="panel-title dashboard-title"><?php _e('404 ERRORS','wp-meta-seo') ?></h4>
 
 
205
  <h3 class="dashboard-title percent_1"><?php echo $error_404['percent'] ?>%</h3>
206
- <p class="dashboard-title percent_2"><?php _e('Redirected 404 errors:','wp-meta-seo') ?> <?php echo $error_404['count_404_redirected'] . '/' . $error_404['count_404'] ?></p>
 
 
 
 
 
207
  </div>
208
  <div class="wpms_dashboard_widgets_right">
209
  <div class="progress-rating">
210
- <div class="determinate percent_3" style="width: <?php echo $error_404['percent'] ?>%"></div>
 
211
  </div>
212
  </div>
213
  </div>
@@ -221,20 +291,29 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
221
  <?php
222
  if (!is_plugin_active($plugin_imgRecycle_file)) :
223
  ?>
224
- <div class="wpms_dash_widgets" alt="<?php _e('Images represent around 60% of a web page weight. An image compression reduce the image size by up to 70% while preserving the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
 
 
 
225
  <div class="row panel-statistics">
226
  <div class="tooltipped">
227
  <div class="panel panel-updates dashboard-card">
228
  <div class="panel-body">
229
  <div class="row">
230
  <div class="wpms_dashboard_widgets_left">
231
- <h4 class="panel-title dashboard-title"><?php _e('IMAGE COMPRESSION','wp-meta-seo') ?></h4>
 
 
232
  <h3 class="dashboard-title percent_1">0%</h3>
233
- <p class="dashboard-title percent_2"><?php _e('Use ImageRecycle image compression plugin to activate this feature', 'wp-meta-seo') ?>: 0/0</p>
 
 
 
 
234
  </div>
235
  <div class="wpms_dashboard_widgets_right">
236
  <div class="progress-rating">
237
- <div class="determinate percent_3" style="width: 0%"></div>
238
  </div>
239
  </div>
240
  </div>
@@ -243,22 +322,37 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
243
  </div>
244
  </div>
245
  </div>
246
- <?php else: ?>
247
- <?php $optimizer_results = $dashboard->wpms_getImages_count(); ?>
248
- <div class="wpms_dash_widgets" alt="<?php _e('Images represent around 60% of a web page weight. An image compression reduce the image size by up to 70% while preserving the same visual quality. Small loading time is great for SEO!', 'wp-meta-seo') ?>">
 
 
 
249
  <div class="row panel-statistics">
250
  <div class="tooltipped">
251
  <div class="panel panel-updates dashboard-card">
252
  <div class="panel-body">
253
  <div class="row">
254
  <div class="wpms_dashboard_widgets_left">
255
- <h4 class="panel-title dashboard-title"><?php _e('IMAGE COMPRESSION','wp-meta-seo') ?></h4>
256
- <h3 class="dashboard-title percent_1"><?php echo $optimizer_results['percent'] . '%' ?></h3>
257
- <p class="dashboard-title percent_2"><?php _e('Compressed images', 'wp-meta-seo') ?>: <?php echo $optimizer_results['image_optimize'] . '/' . $optimizer_results['count_image'] ?></p>
 
 
 
 
 
 
 
 
 
 
258
  </div>
259
  <div class="wpms_dashboard_widgets_right">
260
  <div class="progress-rating">
261
- <div class="determinate percent_3" style="width: <?php echo $optimizer_results['percent'] . '%' ?>"></div>
 
 
262
  </div>
263
  </div>
264
  </div>
@@ -273,7 +367,7 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
273
  </div>
274
  </div>
275
 
276
- <div style="width:75%;margin: 0px auto;min-height: 200px;padding: 0px 10px 0px 10px;">
277
  <div class="left">
278
  <div class="dashboard-left" id='dashboard-left'>
279
  <div id="alexa-ranking">
@@ -284,44 +378,66 @@ $plugin_imgRecycle_file = 'imagerecycle-pdf-image-compression/wp-image-recycle.p
284
 
285
  <div class="right">
286
  <div class="dashboard-right">
287
- <div style="display: none"><?php _e("We can't get rank of this site from Alexa.com!", "wp-meta-seo") ?></div>
 
 
288
  <div style="clear:left"></div>
289
  <div id="wpmetaseo-update-version">
290
  <h4><?php echo __('Latest WP Meta SEO News', 'wp-meta-seo') ?></h4>
291
  <ul>
292
- <li><a target="_blank" href="https://www.joomunited.com/wordpress-products/wp-meta-seo"><?php _e('More information about WP Meta SEO', 'wp-meta-seo'); ?></a></li>
293
- <li><a target="_blank" href="https://www.joomunited.com/"><?php _e('Other plugins from JoomUnited', 'wp-meta-seo'); ?></a></li>
 
 
 
 
 
 
 
 
294
  </ul>
295
  </div>
296
  </div>
297
  </div>
298
  </div>
299
  <?php
300
- if(!empty($_COOKIE['close_dashboard'])){
301
  $check = time() - (int)$_COOKIE['close_dashboard'];
302
- $month = 30*24*60*60;
303
  }
304
 
305
- if((empty($_COOKIE['close_dashboard']) || (!empty($_COOKIE['close_dashboard']) && $check >= $month )) && !is_plugin_active(WPMSEO_ADDON_FILENAME)):
306
- ?>
307
- <div class="wpms_dashboard_notification wpms_wrap_notification">
308
- <div class="notification_dashboard">
309
- <div class="tooltipped">
310
- <div class="panel panel-updates dashboard-card">
311
- <div class="panel-body">
312
- <div class="row">
313
- <div class="wpms_dashboard_widgets_content">
314
- <p class="dashboard_noti_title"><?php _e('WP META SEO PRO ADDON','wp-meta-seo') ?></p>
315
- <p class="dashboard-title msg"><?php _e('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report, Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!','wp-meta-seo') ?></p>
316
- <a class="more-info" href="https://www.joomunited.com/wordpress-products/wp-meta-seo" target="_blank"><?php _e('MORE INFORMATION','wp-meta-seo') ?></a>
317
- <a data-page="close_dashboard" class="dashboard-title wpmsclose_notification close_dashboard"><?php _e('CLOSE FOR ONE MONTH','wp-meta-seo') ?></a>
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  </div>
319
  </div>
320
  </div>
321
  </div>
322
  </div>
323
  </div>
324
- </div>
325
  <?php endif; ?>
326
  </div>
327
 
1
  <?php
2
+
3
+ if (!class_exists('MetaSeoDashboard')) {
4
+ require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-dashboard.php');
5
  }
6
 
7
  wp_enqueue_style('m-style-qtip');
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
+ 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') ?>">
28
  <div class="row panel-statistics">
29
  <div class="tooltipped">
30
  <div class="panel panel-updates dashboard-card">
31
  <div class="panel-body">
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">
42
  <div class="progress-rating">
50
  </div>
51
  </div>
52
 
53
+ <div class="wpms_dash_widgets wpms_dash_metatitle"
54
+ 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">
58
  <div class="tooltipped">
59
  <div class="panel panel-updates dashboard-card">
60
  <div class="panel-body">
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>
72
  <div class="wpms_dashboard_widgets_right">
73
  <div class="progress-rating">
74
+ <div class="determinate percent_3" style="width: 0"></div>
75
  </div>
76
  </div>
77
  </div>
81
  </div>
82
  </div>
83
 
84
+ <div class="wpms_dash_widgets wpms_dash_metadesc"
85
+ 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') ?>">
89
  <div class="row panel-statistics">
90
  <div class="tooltipped">
91
  <div class="panel panel-updates dashboard-card">
92
  <div class="panel-body">
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>
104
  <div class="wpms_dashboard_widgets_right">
105
  <div class="progress-rating">
106
+ <div class="determinate percent_3" style="width: 0"></div>
107
  </div>
108
  </div>
109
  </div>
114
  </div>
115
 
116
  <?php
117
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
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
+ 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">
134
  <div class="tooltipped">
135
  <div class="panel panel-updates dashboard-card">
136
  <div class="panel-body">
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>
148
  <div class="wpms_dashboard_widgets_right">
149
  <div class="progress-rating">
150
+ <div class="determinate percent_3" style="width: 0"></div>
151
  </div>
152
  </div>
153
  </div>
157
  </div>
158
  </div>
159
 
160
+ <div class="wpms_dash_widgets wpms_dash_imgsmeta"
161
+ alt="<?php _e('We recommend to use both alt text and image title.
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
165
+ image tool to quickly check and fix that.', 'wp-meta-seo') ?>">
166
  <div class="row panel-statistics">
167
  <div class="tooltipped">
168
  <div class="panel panel-updates dashboard-card">
169
  <div class="panel-body">
170
  <div class="row">
171
  <div class="wpms_dashboard_widgets_left">
172
+ <h4 class="panel-title dashboard-title">
173
+ <?php _e('IMAGE TITLE/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>
181
  <div class="wpms_dashboard_widgets_right">
182
  <div class="progress-rating">
183
+ <div class="determinate percent_3" style="width: 0"></div>
184
  </div>
185
  </div>
186
  </div>
190
  </div>
191
  </div>
192
 
193
+ <div class="wpms_dash_widgets wpms_dash_newcontent"
194
+ 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">
198
  <div class="tooltipped">
199
  <div class="panel panel-updates dashboard-card">
200
  <div class="panel-body">
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>
212
  <div class="wpms_dashboard_widgets_right">
213
  <div class="progress-rating">
214
+ <div class="determinate percent_3" style="width: 0"></div>
215
  </div>
216
  </div>
217
  </div>
221
  </div>
222
  </div>
223
 
224
+ <div class="wpms_dash_widgets wpms_dash_linkmeta"
225
+ 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">
229
  <div class="tooltipped">
230
  <div class="panel panel-updates dashboard-card">
231
  <div class="panel-body">
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>
243
  <div class="wpms_dashboard_widgets_right">
244
  <div class="progress-rating">
245
+ <div class="determinate percent_3" style="width: 0"></div>
246
  </div>
247
  </div>
248
  </div>
252
  </div>
253
  </div>
254
 
255
+ <div class="wpms_dash_widgets wpms_dash_404_error"
256
+ 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') ?>">
260
  <div class="row panel-statistics">
261
  <div class="tooltipped">
262
  <div class="panel panel-updates dashboard-card">
263
  <div class="panel-body">
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>
291
  <?php
292
  if (!is_plugin_active($plugin_imgRecycle_file)) :
293
  ?>
294
+ <div class="wpms_dash_widgets"
295
+ 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">
299
  <div class="tooltipped">
300
  <div class="panel panel-updates dashboard-card">
301
  <div class="panel-body">
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>
313
  </div>
314
  <div class="wpms_dashboard_widgets_right">
315
  <div class="progress-rating">
316
+ <div class="determinate percent_3" style="width: 0"></div>
317
  </div>
318
  </div>
319
  </div>
322
  </div>
323
  </div>
324
  </div>
325
+ <?php else : ?>
326
+ <?php $optimizer = $dashboard->getImagesCount(); ?>
327
+ <div class="wpms_dash_widgets"
328
+ 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">
332
  <div class="tooltipped">
333
  <div class="panel panel-updates dashboard-card">
334
  <div class="panel-body">
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>
358
  </div>
367
  </div>
368
  </div>
369
 
370
+ <div style="width:75%;margin: 0 auto;min-height: 200px;padding: 0 10px 0 10px;">
371
  <div class="left">
372
  <div class="dashboard-left" id='dashboard-left'>
373
  <div id="alexa-ranking">
378
 
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>
399
  </div>
400
  </div>
401
  </div>
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
 
409
+ if ((empty($_COOKIE['close_dashboard']) || (!empty($_COOKIE['close_dashboard']) && $check >= $month))
410
+ && !is_plugin_active(WPMSEO_ADDON_FILENAME)) :
411
+ ?>
412
+ <div class="wpms_dashboard_notification wpms_wrap_notification">
413
+ <div class="notification_dashboard">
414
+ <div class="tooltipped">
415
+ <div class="panel panel-updates dashboard-card">
416
+ <div class="panel-body">
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>
436
  </div>
437
  </div>
438
  </div>
439
  </div>
440
  </div>
 
441
  <?php endif; ?>
442
  </div>
443
 
inc/pages/dashboard/imgsmeta.php CHANGED
@@ -5,14 +5,20 @@
5
  <h4 class="panel-title text-success"><?php _e('Image title/alt', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results['imgs_metas_statis'][2] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results['imgs_metas_statis'][2] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results['imgs_metas_statis'][2] ?>" role="progressbar" class="progress-bar progress-bar-info">
9
- <span class="sr-only"><?php echo $results['imgs_metas_statis'][2] . '%' ?> Complete (success)</span>
 
 
 
10
  </div>
11
  </div>
12
- <p><?php _e('Image data filled (in content)', 'wp-meta-seo') ?>: <?php echo $results['imgs_metas_statis'][0] . '/' . $results['imgs_metas_statis'][1] ?></p>
 
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results['imgs_metas_statis'][2] ?>" class="dial-info">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-success"><?php _e('Image title/alt', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results['imgs_metas_statis'][2] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results['imgs_metas_statis'][2] . '%' ?>" aria-valuemax="100"
9
+ aria-valuemin="0" aria-valuenow="<?php echo $results['imgs_metas_statis'][2] ?>"
10
+ role="progressbar" class="progress-bar progress-bar-info">
11
+ <span class="sr-only"><?php echo $results['imgs_metas_statis'][2] . '%' ?>
12
+ Complete (success)</span>
13
  </div>
14
  </div>
15
+ <p><?php _e('Image data filled (in content)', 'wp-meta-seo') ?>
16
+ : <?php echo $results['imgs_metas_statis'][0] . '/' . $results['imgs_metas_statis'][1] ?></p>
17
  </div>
18
  <div class="col-xs-5 col-lg-4 text-right">
19
+ <label>
20
+ <input type="text" value="<?php echo $results['imgs_metas_statis'][2] ?>" class="dial-info">
21
+ </label>
22
  </div>
23
  </div>
24
  </div>
inc/pages/dashboard/imgsresize.php CHANGED
@@ -5,14 +5,19 @@
5
  <h4 class="panel-title text-warning"><?php _e('HTML image resizing', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results['imgs_statis'][2] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results['imgs_statis'][2] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results['imgs_statis'][2] ?>" role="progressbar" class="progress-bar progress-bar-warning">
 
 
9
  <span class="sr-only"><?php echo $results['imgs_statis'][2] . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
- <p><?php _e('Wrong resized images', 'wp-meta-seo') ?>: <?php echo $results['imgs_statis'][0] . '/' . $results['imgs_statis'][1] ?></p>
 
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results['imgs_statis'][2] ?>" class="dial-warning">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-warning"><?php _e('HTML image resizing', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results['imgs_statis'][2] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results['imgs_statis'][2] . '%' ?>" aria-valuemax="100"
9
+ aria-valuemin="0" aria-valuenow="<?php echo $results['imgs_statis'][2] ?>" role="progressbar"
10
+ class="progress-bar progress-bar-warning">
11
  <span class="sr-only"><?php echo $results['imgs_statis'][2] . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
+ <p><?php _e('Wrong resized images', 'wp-meta-seo') ?>
15
+ : <?php echo $results['imgs_statis'][0] . '/' . $results['imgs_statis'][1] ?></p>
16
  </div>
17
  <div class="col-xs-5 col-lg-4 text-right">
18
+ <label>
19
+ <input type="text" value="<?php echo $results['imgs_statis'][2] ?>" class="dial-warning">
20
+ </label>
21
  </div>
22
  </div>
23
  </div>
inc/pages/dashboard/link_meta.php CHANGED
@@ -5,14 +5,19 @@
5
  <h4 class="panel-title text-success"><?php _e('Link titles', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results[0] ?>" role="progressbar" class="progress-bar progress-bar-success">
 
 
9
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
- <p><?php _e('Links title completed', 'wp-meta-seo') ?>: <?php echo $results[1][0] . '/' . $results[1][1]; ?></p>
 
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results[0] ?>" class="dial-success">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-success"><?php _e('Link titles', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0"
9
+ aria-valuenow="<?php echo $results[0] ?>" role="progressbar"
10
+ class="progress-bar progress-bar-success">
11
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
+ <p><?php _e('Links title completed', 'wp-meta-seo') ?>
15
+ : <?php echo $results[1][0] . '/' . $results[1][1]; ?></p>
16
  </div>
17
  <div class="col-xs-5 col-lg-4 text-right">
18
+ <label>
19
+ <input type="text" value="<?php echo $results[0] ?>" class="dial-success">
20
+ </label>
21
  </div>
22
  </div>
23
  </div>
inc/pages/dashboard/meta_desc.php CHANGED
@@ -5,14 +5,19 @@
5
  <h4 class="panel-title text-success"><?php _e('Meta Description', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results[0] ?>" role="progressbar" class="progress-bar progress-bar-info">
 
 
9
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
- <p><?php _e('Meta description filled', 'wp-meta-seo') ?>: <?php echo $results[1][0] . '/' . $results[1][1] ?></p>
 
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results[0] ?>" class="dial-info">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-success"><?php _e('Meta Description', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0"
9
+ aria-valuenow="<?php echo $results[0] ?>" role="progressbar"
10
+ class="progress-bar progress-bar-info">
11
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
+ <p><?php _e('Meta description filled', 'wp-meta-seo') ?>
15
+ : <?php echo $results[1][0] . '/' . $results[1][1] ?></p>
16
  </div>
17
  <div class="col-xs-5 col-lg-4 text-right">
18
+ <label>
19
+ <input type="text" value="<?php echo $results[0] ?>" class="dial-info">
20
+ </label>
21
  </div>
22
  </div>
23
  </div>
inc/pages/dashboard/meta_title.php CHANGED
@@ -5,14 +5,19 @@
5
  <h4 class="panel-title text-warning"><?php _e('Meta Title', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results[0] ?>" role="progressbar" class="progress-bar progress-bar-warning">
 
 
9
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
- <p><?php _e('Meta title filled', 'wp-meta-seo') ?>: <?php echo $results[1][0] . '/' . $results[1][1] ?></p>
 
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results[0] ?>" class="dial-warning">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-warning"><?php _e('Meta Title', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0"
9
+ aria-valuenow="<?php echo $results[0] ?>" role="progressbar"
10
+ class="progress-bar progress-bar-warning">
11
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
+ <p><?php _e('Meta title filled', 'wp-meta-seo') ?>
15
+ : <?php echo $results[1][0] . '/' . $results[1][1] ?></p>
16
  </div>
17
  <div class="col-xs-5 col-lg-4 text-right">
18
+ <label>
19
+ <input type="text" value="<?php echo $results[0] ?>" class="dial-warning">
20
+ </label>
21
  </div>
22
  </div>
23
  </div>
inc/pages/dashboard/new_content.php CHANGED
@@ -5,14 +5,18 @@
5
  <h4 class="panel-title text-danger"><?php _e('New or updated content', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $results[0] ?>" role="progressbar" class="progress-bar progress-bar-danger">
 
 
9
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
  <p><?php _e('Latest month new or updated content', 'wp-meta-seo') ?>: <?php echo $results[1][0] ?></p>
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $results[0] ?>" class="dial-danger">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-danger"><?php _e('New or updated content', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $results[0] . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $results[0] . '%' ?>" aria-valuemax="100" aria-valuemin="0"
9
+ aria-valuenow="<?php echo $results[0] ?>" role="progressbar"
10
+ class="progress-bar progress-bar-danger">
11
  <span class="sr-only"><?php echo $results[0] . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
  <p><?php _e('Latest month new or updated content', 'wp-meta-seo') ?>: <?php echo $results[1][0] ?></p>
15
  </div>
16
  <div class="col-xs-5 col-lg-4 text-right">
17
+ <label>
18
+ <input type="text" value="<?php echo $results[0] ?>" class="dial-danger">
19
+ </label>
20
  </div>
21
  </div>
22
  </div>
inc/pages/dashboard/permalink.php CHANGED
@@ -5,14 +5,18 @@
5
  <h4 class="panel-title text-success"><?php _e('Permalinks settings', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $permalink . '%' ?></h3>
7
  <div class="progress">
8
- <div style="width: <?php echo $permalink . '%' ?>" aria-valuemax="100" aria-valuemin="0" aria-valuenow="<?php echo $permalink ?>" role="progressbar" class="progress-bar progress-bar-success">
 
 
9
  <span class="sr-only"><?php echo $permalink . '%' ?> Complete (success)</span>
10
  </div>
11
  </div>
12
  <p><?php _e('Optimized at', 'wp-meta-seo') ?>: <?php echo $permalink . '%' ?></p>
13
  </div>
14
  <div class="col-xs-5 col-lg-4 text-right">
15
- <input type="text" value="<?php echo $permalink ?>" class="dial-success">
 
 
16
  </div>
17
  </div>
18
  </div>
5
  <h4 class="panel-title text-success"><?php _e('Permalinks settings', 'wp-meta-seo') ?></h4>
6
  <h3><?php echo $permalink . '%' ?></h3>
7
  <div class="progress">
8
+ <div style="width: <?php echo $permalink . '%' ?>" aria-valuemax="100" aria-valuemin="0"
9
+ aria-valuenow="<?php echo $permalink ?>" role="progressbar"
10
+ class="progress-bar progress-bar-success">
11
  <span class="sr-only"><?php echo $permalink . '%' ?> Complete (success)</span>
12
  </div>
13
  </div>
14
  <p><?php _e('Optimized at', 'wp-meta-seo') ?>: <?php echo $permalink . '%' ?></p>
15
  </div>
16
  <div class="col-xs-5 col-lg-4 text-right">
17
+ <label>
18
+ <input type="text" value="<?php echo $permalink ?>" class="dial-success">
19
+ </label>
20
  </div>
21
  </div>
22
  </div>
inc/pages/dashboard_widgets.php CHANGED
@@ -1,15 +1,22 @@
1
  <div class="wpms_dashboard_widgets">
2
- <div class="wpms_dash_widgets wpms_dash_permalink" alt="<?php _e('It’s better using a permalink structure that is adding in your URL the category name and content title. This parameter can be changed in Settings > Permalinks WordPress menu. Tag recommended is %category%/%postname%', 'wp-meta-seo') ?>">
 
 
 
 
3
  <div class="row panel-statistics">
4
  <div class="tooltipped">
5
  <div class="panel panel-updates dashboard-card">
6
  <div class="panel-body">
7
  <div class="row">
8
  <div class="wpms_dashboard_widgets_left">
9
- <h4 class="panel-title dashboard-title"><?php _e('PERMALINKS SETTINGS','wp-meta-seo') ?></h4>
 
 
10
  <div class="panel-bottom">
11
  <h3 class="dashboard-title percent_1">50%</h3>
12
- <span class="dashboard-title percent_2"><?php _e('Optimized at:','wp-meta-seo') ?> <span class="percent">50%</span></span>
 
13
  </div>
14
  </div>
15
  <div class="wpms_dashboard_widgets_right">
@@ -24,22 +31,28 @@
24
  </div>
25
  </div>
26
 
27
- <div class="wpms_dash_widgets wpms_dash_metatitle" alt="<?php _e('Meta titles are displayed in search engine results as a page title. It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the met information on your most popular pages', 'wp-meta-seo') ?>">
 
 
 
28
  <div class="row panel-statistics">
29
  <div class="tooltipped">
30
  <div class="panel panel-updates dashboard-card">
31
  <div class="panel-body">
32
  <div class="row">
33
  <div class="wpms_dashboard_widgets_left">
34
- <h4 class="panel-title dashboard-title"><?php _e('META TITLE','wp-meta-seo') ?></h4>
35
  <div class="panel-bottom">
36
  <h3 class="dashboard-title percent_1">0%</h3>
37
- <span class="dashboard-title percent_2"><?php _e('Meta title filled:','wp-meta-seo') ?> <span class="percent">0/0</span></span>
 
 
 
38
  </div>
39
  </div>
40
  <div class="wpms_dashboard_widgets_right">
41
  <div class="progress-rating">
42
- <div class="determinate percent_3" style="width: 0%"></div>
43
  </div>
44
  </div>
45
  </div>
@@ -49,22 +62,30 @@
49
  </div>
50
  </div>
51
 
52
- <div class="wpms_dash_widgets wpms_dash_metadesc" alt="<?php _e('Meta descriptions are displayed in search engine results as a page description. It’s a good thing for SEO to have some custom and attractive ones. Be sure to fill at least the meta information on your most popular pages.', 'wp-meta-seo') ?>">
 
 
 
53
  <div class="row panel-statistics">
54
  <div class="tooltipped">
55
  <div class="panel panel-updates dashboard-card">
56
  <div class="panel-body">
57
  <div class="row">
58
  <div class="wpms_dashboard_widgets_left">
59
- <h4 class="panel-title dashboard-title"><?php _e('META DESCRIPTION','wp-meta-seo') ?></h4>
 
 
60
  <div class="panel-bottom">
61
  <h3 class="dashboard-title percent_1">0%</h3>
62
- <span class="dashboard-title percent_2"><?php _e('Meta description filled:','wp-meta-seo') ?> <span class="percent">0/0</span></span>
 
 
 
63
  </div>
64
  </div>
65
  <div class="wpms_dashboard_widgets_right">
66
  <div class="progress-rating">
67
- <div class="determinate percent_3" style="width: 0%"></div>
68
  </div>
69
  </div>
70
  </div>
@@ -75,35 +96,42 @@
75
  </div>
76
 
77
  <?php
78
- if(is_plugin_active(WPMSEO_ADDON_FILENAME)){
79
- if(!class_exists('MetaSeo_Addon_Admin')){
80
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/class.metaseo-addon-admin.php';
81
  }
82
- $metaseo_addon = new MetaSeo_Addon_Admin();
83
- $duplicate_metatitle = $metaseo_addon->wpms_get_duplicate_metatitle();
84
- $duplicate_metadesc = $metaseo_addon->wpms_get_duplicate_metadesc();
85
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metatitle_widgets.php';
86
  require_once WPMETASEO_ADDON_PLUGIN_DIR . '/inc/page/dashboard/duplicate_metadesc_widgets.php';
87
-
88
  }
89
  ?>
90
 
91
- <div class="wpms_dash_widgets wpms_dash_imgsresize" alt="<?php _e('Display image at its natural size, do not use HTML resize. It happens usually when you use handles to resize an image. You have a bulk edition tool to fix that.', 'wp-meta-seo') ?>">
 
 
 
92
  <div class="row panel-statistics">
93
  <div class="tooltipped">
94
  <div class="panel panel-updates dashboard-card">
95
  <div class="panel-body">
96
  <div class="row">
97
  <div class="wpms_dashboard_widgets_left">
98
- <h4 class="panel-title dashboard-title"><?php _e('HTML IMAGE RESIZING','wp-meta-seo') ?></h4>
 
 
99
  <div class="panel-bottom">
100
  <h3 class="dashboard-title percent_1">0%</h3>
101
- <span class="dashboard-title percent_2"><?php _e('Wrong resized images:','wp-meta-seo') ?> <span class="percent">0/0</span></span>
 
 
 
102
  </div>
103
  </div>
104
  <div class="wpms_dashboard_widgets_right">
105
  <div class="progress-rating">
106
- <div class="determinate percent_3" style="width: 0%"></div>
107
  </div>
108
  </div>
109
  </div>
@@ -113,22 +141,32 @@
113
  </div>
114
  </div>
115
 
116
- <div class="wpms_dash_widgets wpms_dash_imgsmeta" alt="<?php _e('We recommend to use both alt text and image title. The main advantage is that it helps search engines discover your images and display them in image search results. Plus, these tags improve the accessibility of your site and give more information about your images. Use our bulk image tool to quickly check and fix that.', 'wp-meta-seo') ?>">
 
 
 
 
 
117
  <div class="row panel-statistics">
118
  <div class="tooltipped">
119
  <div class="panel panel-updates dashboard-card">
120
  <div class="panel-body">
121
  <div class="row">
122
  <div class="wpms_dashboard_widgets_left">
123
- <h4 class="panel-title dashboard-title"><?php _e('IMAGE TITLE/ALT','wp-meta-seo') ?></h4>
 
 
124
  <div class="panel-bottom">
125
  <h3 class="dashboard-title percent_1">0%</h3>
126
- <span class="dashboard-title percent_2"><?php _e('Image data filled (in content):','wp-meta-seo') ?> <span class="percent">0/0</span></span>
 
 
 
127
  </div>
128
  </div>
129
  <div class="wpms_dashboard_widgets_right">
130
  <div class="progress-rating">
131
- <div class="determinate percent_3" style="width: 0%"></div>
132
  </div>
133
  </div>
134
  </div>
@@ -138,22 +176,29 @@
138
  </div>
139
  </div>
140
 
141
- <div class="wpms_dash_widgets wpms_dash_newcontent" alt="<?php _e('It is highly recommended to update or add new content on your website quite frequently. At least 3 updated or new content per month would be great :)', 'wp-meta-seo') ?>">
 
 
142
  <div class="row panel-statistics">
143
  <div class="tooltipped">
144
  <div class="panel panel-updates dashboard-card">
145
  <div class="panel-body">
146
  <div class="row">
147
  <div class="wpms_dashboard_widgets_left">
148
- <h4 class="panel-title dashboard-title"><?php _e('NEW OR UPDATED CONTENT','wp-meta-seo') ?></h4>
 
 
149
  <div class="panel-bottom">
150
  <h3 class="dashboard-title percent_1">0%</h3>
151
- <span class="dashboard-title percent_2"><?php _e('Latest month new or updated content:','wp-meta-seo') ?> <span class="percent">0</span></span>
 
 
 
152
  </div>
153
  </div>
154
  <div class="wpms_dashboard_widgets_right">
155
  <div class="progress-rating">
156
- <div class="determinate percent_3" style="width: 0%"></div>
157
  </div>
158
  </div>
159
  </div>
@@ -163,22 +208,28 @@
163
  </div>
164
  </div>
165
 
166
- <div class="wpms_dash_widgets wpms_dash_linkmeta" alt="<?php _e('The link title attribute does not have any SEO value for links. BUT links titles can influence click behavior for users, which may indirectly affect your SEO performance', 'wp-meta-seo') ?>">
 
 
 
167
  <div class="row panel-statistics">
168
  <div class="tooltipped">
169
  <div class="panel panel-updates dashboard-card">
170
  <div class="panel-body">
171
  <div class="row">
172
  <div class="wpms_dashboard_widgets_left">
173
- <h4 class="panel-title dashboard-title"><?php _e('LINK TITLES','wp-meta-seo') ?></h4>
174
  <div class="panel-bottom">
175
  <h3 class="dashboard-title percent_1">0%</h3>
176
- <span class="dashboard-title percent_2"><?php _e('Links title completed:','wp-meta-seo') ?> <span class="percent">0/0</span></span>
 
 
 
177
  </div>
178
  </div>
179
  <div class="wpms_dashboard_widgets_right">
180
  <div class="progress-rating">
181
- <div class="determinate percent_3" style="width: 0%"></div>
182
  </div>
183
  </div>
184
  </div>
@@ -188,22 +239,31 @@
188
  </div>
189
  </div>
190
 
191
- <div class="wpms_dash_widgets wpms_dash_404_error" alt="<?php _e('A website with a bunch of 404 errors doesn’t provide a good user experience, which is significantly important in content marketing and SEO. We recommend to use our internal broken link checker and redirect tool to fix all the 404 error you can periodically.', 'wp-meta-seo') ?>">
 
 
 
192
  <div class="row panel-statistics">
193
  <div class="tooltipped">
194
  <div class="panel panel-updates dashboard-card">
195
  <div class="panel-body">
196
  <div class="row">
197
  <div class="wpms_dashboard_widgets_left">
198
- <h4 class="panel-title dashboard-title"><?php _e('404 ERRORS','wp-meta-seo') ?></h4>
199
  <div class="panel-bottom">
200
  <h3 class="dashboard-title percent_1"><?php echo $error_404['percent'] ?>%</h3>
201
- <span class="dashboard-title percent_2">Redirected 404 errors: <?php echo $error_404['count_404_redirected'] . '/' . $error_404['count_404'] ?></span>
 
 
 
 
 
202
  </div>
203
  </div>
204
  <div class="wpms_dashboard_widgets_right">
205
  <div class="progress-rating">
206
- <div class="determinate percent_3" style="width: <?php echo $error_404['percent'] ?>%"></div>
 
207
  </div>
208
  </div>
209
  </div>
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') ?>">
7
  <div class="row panel-statistics">
8
  <div class="tooltipped">
9
  <div class="panel panel-updates dashboard-card">
10
  <div class="panel-body">
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>
22
  <div class="wpms_dashboard_widgets_right">
31
  </div>
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">
39
  <div class="tooltipped">
40
  <div class="panel panel-updates dashboard-card">
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>
52
  </div>
53
  <div class="wpms_dashboard_widgets_right">
54
  <div class="progress-rating">
55
+ <div class="determinate percent_3" style="width: 0"></div>
56
  </div>
57
  </div>
58
  </div>
62
  </div>
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">
70
  <div class="tooltipped">
71
  <div class="panel panel-updates dashboard-card">
72
  <div class="panel-body">
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>
85
  </div>
86
  <div class="wpms_dashboard_widgets_right">
87
  <div class="progress-rating">
88
+ <div class="determinate percent_3" style="width: 0"></div>
89
  </div>
90
  </div>
91
  </div>
96
  </div>
97
 
98
  <?php
99
+ if (is_plugin_active(WPMSEO_ADDON_FILENAME)) {
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">
116
  <div class="tooltipped">
117
  <div class="panel panel-updates dashboard-card">
118
  <div class="panel-body">
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>
131
  </div>
132
  <div class="wpms_dashboard_widgets_right">
133
  <div class="progress-rating">
134
+ <div class="determinate percent_3" style="width: 0"></div>
135
  </div>
136
  </div>
137
  </div>
141
  </div>
142
  </div>
143
 
144
+ <div class="wpms_dash_widgets wpms_dash_imgsmeta"
145
+ data-alt="<?php _e('We recommend to use both alt text and image title.
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
149
+ tool to quickly check and fix that.', 'wp-meta-seo') ?>">
150
  <div class="row panel-statistics">
151
  <div class="tooltipped">
152
  <div class="panel panel-updates dashboard-card">
153
  <div class="panel-body">
154
  <div class="row">
155
  <div class="wpms_dashboard_widgets_left">
156
+ <h4 class="panel-title dashboard-title">
157
+ <?php _e('IMAGE TITLE/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>
166
  </div>
167
  <div class="wpms_dashboard_widgets_right">
168
  <div class="progress-rating">
169
+ <div class="determinate percent_3" style="width: 0"></div>
170
  </div>
171
  </div>
172
  </div>
176
  </div>
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">
184
  <div class="panel panel-updates dashboard-card">
185
  <div class="panel-body">
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>
198
  </div>
199
  <div class="wpms_dashboard_widgets_right">
200
  <div class="progress-rating">
201
+ <div class="determinate percent_3" style="width: 0"></div>
202
  </div>
203
  </div>
204
  </div>
208
  </div>
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">
216
  <div class="tooltipped">
217
  <div class="panel panel-updates dashboard-card">
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>
229
  </div>
230
  <div class="wpms_dashboard_widgets_right">
231
  <div class="progress-rating">
232
+ <div class="determinate percent_3" style="width: 0"></div>
233
  </div>
234
  </div>
235
  </div>
239
  </div>
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">
247
  <div class="tooltipped">
248
  <div class="panel panel-updates dashboard-card">
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>
inc/pages/google-analytics/form-connect.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form name="ga_dash_form" method="post" action="">
2
+ <?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
3
+ <table class="gadwp-settings-options">
4
+ <tbody>
5
+ <tr>
6
+ <td colspan="2">
7
+ <h2><?php _e('Plugin Authorization', 'wp-meta-seo') ?></h2>
8
+ </td>
9
+ </tr>
10
+ <tr>
11
+ <td colspan="2">
12
+ <div class="pure-checkbox">
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
28
+ if ((!empty($this->google_alanytics['wpmsga_dash_clientid']))) {
29
+ $value = $this->google_alanytics['wpmsga_dash_clientid'];
30
+ } else {
31
+ $value = '';
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
45
+ if ((!empty($this->google_alanytics['wpmsga_dash_clientsecret']))) {
46
+ $value = $this->google_alanytics['wpmsga_dash_clientsecret'];
47
+ } else {
48
+ $value = '';
49
+ }
50
+ ?>
51
+ <input type="text" name="wpmsga_dash_clientsecret"
52
+ value="<?php echo $value ?>"
53
+ size="40" required="required">
54
+ </label>
55
+ </td>
56
+ </tr>
57
+ <tr>
58
+ <td colspan="2">
59
+ <hr>
60
+ </td>
61
+ </tr>
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>
69
+ </table>
70
+ </form>
71
+
72
+ <?php
73
+ if (!empty($this->google_alanytics['wpmsga_dash_clientid'])
74
+ && !empty($this->google_alanytics['wpmsga_dash_clientsecret'])) :
75
+ ?>
76
+ <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
77
+ <?php wp_nonce_field('gadash_form', 'gadash_security'); ?>
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>
97
+ <td colspan="2">
98
+ <hr>
99
+ </td>
100
+ </tr>
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>
108
+ </form>
109
+ <?php
110
+ endif;
111
+ ?>
inc/pages/google-analytics/ga-trackcode.php ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="post-body-content">
2
+ <div class="settings-wrapper">
3
+ <?php
4
+ $lists_dimension = array(
5
+ 'Disabled',
6
+ 'dimension 1',
7
+ 'dimension 2',
8
+ 'dimension 3',
9
+ 'dimension 4',
10
+ 'dimension 5',
11
+ 'dimension 6',
12
+ 'dimension 7',
13
+ 'dimension 8',
14
+ 'dimension 9',
15
+ 'dimension 10',
16
+ 'dimension 11',
17
+ 'dimension 12',
18
+ 'dimension 13',
19
+ 'dimension 14',
20
+ 'dimension 15',
21
+ 'dimension 16',
22
+ 'dimension 17',
23
+ 'dimension 18',
24
+ 'dimension 19',
25
+ 'dimension 20'
26
+ );
27
+
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');
44
+ ?>
45
+ <div class="inside">
46
+ <form method="post" action="">
47
+ <div id="wpmsga-basic">
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>
60
+ <select id="wpmsga_dash_tracking"
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>
77
+ </tr>
78
+
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 >';
105
+ }
106
+ }
107
+ } else {
108
+ echo '<option value="">
109
+ ' . __('Property not found', 'wp-meta-seo') . '</option>';
110
+ }
111
+ ?>
112
+ </select>
113
+ </label>
114
+ </td>
115
+ </tr>
116
+
117
+
118
+ <tr>
119
+ <td class="wpmsga-settings-title"></td>
120
+ <td>
121
+ <?php
122
+ if (isset($this->google_alanytics['tableid_jail'])
123
+ && isset($this->google_alanytics['profile_list'])) {
124
+ $profile_info = WpmsGaTools::getSelectedProfile(
125
+ $this->google_alanytics['profile_list'],
126
+ $this->google_alanytics['tableid_jail']
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
+ ?>
137
+ </td>
138
+ </tr>
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">
166
+ <input type="checkbox"
167
+ name="_metaseo_ggtracking_settings[wpmsga_dash_anonim]"
168
+ <?php checked($this->ga_tracking['wpmsga_dash_anonim'], 1) ?>
169
+ value="1" class="wpmsga-settings-switchoo-checkbox"
170
+ id="wpmsga_dash_anonim">
171
+ <span class="slider round"></span>
172
+ </label>
173
+ </div>
174
+ </td>
175
+ </tr>
176
+ <tr>
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">
184
+ <label class="switch switch-optimization">
185
+ <input type="checkbox"
186
+ name="_metaseo_ggtracking_settings[wpmsga_dash_remarketing]"
187
+ <?php checked($this->ga_tracking['wpmsga_dash_remarketing'], 1) ?>
188
+ value="1" class="wpmsga-settings-switchoo-checkbox"
189
+ id="wpmsga_dash_remarketing">
190
+ <span class="slider round"></span>
191
+ </label>
192
+ </div>
193
+ </td>
194
+ </tr>
195
+ </tbody>
196
+ </table>
197
+ </div>
198
+ <div id="wpmsga-events">
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">
211
+ <input type="checkbox"
212
+ name="_metaseo_ggtracking_settings[wpmsga_event_tracking]"
213
+ <?php checked($this->ga_tracking['wpmsga_event_tracking'], 1) ?>
214
+ value="1" class="wpmsga-settings-switchoo-checkbox"
215
+ id="wpmsga_event_tracking">
216
+ <span class="slider round"></span>
217
+ </label>
218
+ </div>
219
+ </td>
220
+ </tr>
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>
233
+ </table>
234
+ </div>
235
+
236
+ <div id="wpmsga-exclude">
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">
249
+ <table>
250
+ <tbody>
251
+ <tr>
252
+ <td>
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>
284
+ <td>
285
+ <div class="pure-checkbox">
286
+ <input name="_metaseo_ggtracking_settings[wpmsga_track_exclude][]"
287
+ <?php
288
+ echo (in_array('contributor', $trackE