plugins.trac.wordpress.org
Open in
urlscan Pro
198.143.164.244
Public Scan
Submitted URL: https://plugins.trac.wordpress.org/changeset/2870465/wp-meta-seo/trunk?contextall=1&old=2869205&old_path=/wp-meta-seo/trunk#file2
Effective URL: https://plugins.trac.wordpress.org/changeset/2870465/wp-meta-seo/trunk?contextall=1&old=2869205&old_path=/wp-meta-seo/trunk
Submission: On March 08 via api from US — Scanned from DE
Effective URL: https://plugins.trac.wordpress.org/changeset/2870465/wp-meta-seo/trunk?contextall=1&old=2869205&old_path=/wp-meta-seo/trunk
Submission: On March 08 via api from US — Scanned from DE
Form analysis
3 forms found in the DOMGET https://wordpress.org/search/do-search.php
<form action="https://wordpress.org/search/do-search.php" method="get">
<label for="global-search" class="screen-reader-text">Search WordPress.org for:</label>
<input id="global-search" class="text" name="search" type="text" value="" maxlength="150" placeholder="Search WordPress.org">
<button type="submit" class="button"><span class="screen-reader-text">Submit</span></button>
</form>
GET /search
<form id="search" action="/search" method="get">
<div>
<label for="proj-search">Search:</label>
<input type="text" id="proj-search" name="q" size="18" value="">
<input type="submit" value="Search">
</div>
</form>
<form id="prefs" action="">
<div>
<input type="hidden" name="old_path" value="/wp-meta-seo/trunk">
<input type="hidden" name="new_path" value="/wp-meta-seo/trunk">
<input type="hidden" name="old" value="2869205">
<input type="hidden" name="new" value="2870465">
<label for="style">View differences</label>
<select id="style" name="style">
<option selected="selected" value="inline">inline</option>
<option value="sidebyside">side by side</option>
</select>
<div class="field">
<label><input type="radio" name="contextall" value="0"> Show</label>
<label><input type="text" name="contextlines" id="contextlines" size="2" maxlength="3" value="2"> lines around each change</label><br>
<label><input type="radio" name="contextall" value="1" checked="checked"> Show the changes in full context</label>
</div>
<fieldset id="ignore">
<legend>Ignore:</legend>
<div class="field">
<input type="checkbox" id="ignoreblanklines" name="ignoreblanklines">
<label for="ignoreblanklines">Blank lines</label>
</div>
<div class="field">
<input type="checkbox" id="ignorecase" name="ignorecase">
<label for="ignorecase">Case changes</label>
</div>
<div class="field">
<input type="checkbox" id="ignorewhitespace" name="ignorewhitespace">
<label for="ignorewhitespace">White space changes</label>
</div>
</fieldset>
<div style="display:none;"><input type="text" name="sfp_email" value=""><input type="hidden" name="sfph_mail" value=""></div>
<div class="buttons">
<input type="submit" name="update" value="Update">
</div>
</div>
</form>
Text Content
Toggle Menu WORDPRESS.ORG Search WordPress.org for: Submit * Showcase * Themes * Plugins * Mobile * Support * Forums * Documentation * Get Involved * About * Blog * Hosting * Download WordPress PLUGIN DIRECTORY Search: * Login * Timeline * View Tickets * Browse Source CONTEXT NAVIGATION * Reverse Diff -------------------------------------------------------------------------------- CHANGES IN WP-META-SEO/TRUNK [2869205:2870465] View differences inline side by side Show lines around each change Show the changes in full context Ignore: Blank lines Case changes White space changes Location: wp-meta-seo/trunk Files: 7 edited * assets/js/metaseo_admin.js (modified) (1 diff) * assets/js/metaseo_sitemap.js (modified) (1 diff) * inc/class.metaseo-admin.php (modified) (1 diff) * inc/class.metaseo-sitemap.php (modified) (1 diff) * languages/wp-meta-seo-en_US.mo (modified) (previous) * readme.txt (modified) (1 diff) * wp-meta-seo.php (modified) (1 diff) LEGEND: Unmodified Added Removed * TABULARUNIFIED WP-META-SEO/TRUNK/ASSETS/JS/METASEO_ADMIN.JS ¶ r2869205 r2870465 11/* 22 * To change this license header, choose License Headers in Project Properties. 33 * To change this template file, choose Tools | Templates 44 * and open the template in the editor. 55 */ 66var title_max_len = 60; 77var desc_max_len = 143; 88var keywords_max_len = 256; 99var metaseoValueHolder = {}; 1010 1111/** 1212 * Set option when disable search engines from indexing this site 1313 * @param option 1414 * @param hide 1515 * @param nonce 1616 */ 1717function wpmsIgnore(option, hide, nonce) { 1818 jQuery.post(ajaxurl, { 19 action: "wpms_set_ignore" 19 action: "wpms_set_ignore", 20 wpms_nonce: wpms_localize.wpms_nonce 2021 }, function (data) { 2122 if (data) { 2223 jQuery("#" + hide).hide(); 2324 } 2425 } 2526 ) 2627} 2728 2829/** 2930 * Clean meta 3031 * @param str string need clean 3132 * @returns {*} 3233 */ 3334function metaseo_clean(str) { 3435 if (str === '' || typeof str === "undefined") 3536 return ''; 3637 try { 3738 str = jQuery('<div/>').html(str).text(); 3839 str = str.replace(/<\/?[^>]+>/gi, ''); 3940 str = str.replace(/\[(.+?)\](.+?\[\/\\1\])?/g, ''); 4041 } catch (e) { 4142 } 4243 4344 return str; 4445} 4546 4647var oldTitleValues = {}; 4748var oldKeywordsValues = {}; 4849var oldDescValues = {}; 4950 5051/** 5152 * Update length number of meta title for post, page, custom post type 5253 * @param metatitle_id string id of element tag 5354 * @param updateSnippet 5455 */ 5556function metaseo_titlelength(metatitle_id, updateSnippet) { 5657 var title = (metaseo_clean(jQuery('#' + metatitle_id).val())).trim(); 5758 var postid = metatitle_id.replace('metaseo-metatitle-', ''); 5859 var counter_id = 'metaseo-metatitle-len' + postid; 5960 jQuery('#' + counter_id).text(title_max_len - title.length); 6061 if (title.length >= title_max_len) { 6162 jQuery('#' + counter_id).removeClass('word-74B6FC').addClass('word-exceed');//#FEFB04 6263 } else if (title.length <= 50) { 6364 jQuery('#' + counter_id).removeClass('word-exceed').addClass('word-74B6FC');//#74B6FC 6465 } else { 6566 jQuery('#' + counter_id).removeClass('word-exceed word-74B6FC'); 6667 } 6768 6869 if (title.length > title_max_len) { 6970 jQuery('#snippet_title' + postid).empty().text(title.substr(0, title_max_len)); 7071 } 7172 7273 if (typeof updateSnippet === "undefined" || updateSnippet !== false) { 7374 jQuery('#snippet_title' + postid).text(title.substr(0, title_max_len)); 7475 } 7576} 7677 7778/** 7879 * Update meta title for post, page, custom post type 7980 * @param metatitle_id string id of element tag 8081 * @param needToSave 8182 */ 8283function metaseo_updateTitle(metatitle_id, needToSave) { 8384 var title = (metaseo_clean(jQuery('#' + metatitle_id).val())).trim(); 8485 var postid = metatitle_id.replace('metaseo-metatitle-', ''); 8586 if (needToSave === true && oldTitleValues[postid] !== title) { 8687 saveMetaContentChanges('metatitle', postid, title); 8788 } 8889 8990 //Push the new value into the array 9091 oldTitleValues[postid] = title; 9192} 9293 9394/** 9495 * Update length number of meta keyword for post, page, custom post type 9596 * @param metakeywords_id string id of element tag 9697 */ 9798function metaseo_keywordlength(metakeywords_id) { 9899 var keywords = (metaseo_clean(jQuery('#' + metakeywords_id).val())).trim(); 99100 var postid = metakeywords_id.replace('metaseo-metakeywords-', ''); 100101 101102 var counter_id = 'metaseo-metakeywords-len' + postid; 102103 jQuery('#' + counter_id).text(keywords_max_len - keywords.length); 103104 104105 if (keywords.length >= keywords_max_len) { 105106 jQuery('#' + counter_id).addClass('word-exceed'); 106107 } else { 107108 jQuery('#' + counter_id).removeClass('word-exceed'); 108109 } 109110} 110111 111112/** 112113 * Update meta keyword for post, page, custom post type 113114 * @param metakeywords_id string id of element tag 114115 * @param needToSave 115116 */ 116117function metaseo_updatekeywords(metakeywords_id, needToSave) { 117118 var keywords = (metaseo_clean(jQuery('#' + metakeywords_id).val())).trim(); 118119 var postid = metakeywords_id.replace('metaseo-metakeywords-', ''); 119120 if (needToSave === true && oldKeywordsValues[postid] !== keywords) { 120121 saveMetaContentChanges('metakeywords', postid, keywords); 121122 } 122123 123124 //Push the new value into the array 124125 oldKeywordsValues[postid] = keywords; 125126} 126127 127128 128129/** 129130 * remove link 130131 * @param link_id id of this link 131132 */ 132133function wpmsRemoveLink(link_id) { 133134 jQuery.ajax({ 134135 url: ajaxurl, 135136 method: 'POST', 136137 dataType: 'json', 137138 data: { 138139 'action': 'wpms', 139140 'task': 'remove_link', 140141 'link_id': link_id, 141142 'wpms_nonce': wpms_localize.wpms_nonce 142143 }, 143144 success: function (response) { 144145 if (response.status) { 145146 jQuery('#record_' + link_id).remove(); 146147 } 147148 } 148149 }); 149150} 150151 151152/** 152153 * Update meta title for link 153154 * @param button_update 154155 */ 155156function saveMetaLinkChanges(button_update) { 156157 var link_id = jQuery(button_update).closest('tr').data('link'); 157158 var meta_title = jQuery(button_update).closest('tr').find('.metaseo_link_title').val(); 158159 meta_title = (metaseo_clean(meta_title)).trim(); 159160 jQuery.ajax({ 160161 url: ajaxurl, 161162 method: 'POST', 162163 dataType: 'json', 163164 data: { 164165 'action': 'wpms', 165166 'task': 'update_link', 166167 'link_id': link_id, 167168 'meta_title': meta_title, 168169 'wpms_nonce': wpms_localize.wpms_nonce 169170 }, 170171 success: function (response) { 171172 jQuery(button_update).closest('tr').find('.wpms_update_link').hide(); 172173 if (response !== false) { 173174 jQuery(button_update).closest('tr').find('.wpms_old_link').val(response.link_new).change(); 174175 jQuery(button_update).closest('tr').find('.wpms_mesage_link').show().fadeIn(3000).delay(200).fadeOut(3000); 175176 } else { 176177 jQuery(button_update).closest('tr').find('.wpms_error_mesage_link').show().fadeIn(3000).delay(200).fadeOut(3000); 177178 } 178179 179180 } 180181 }); 181182} 182183 183184/** 184185 * Update index for page 185186 * @param page_id int page ID 186187 * @param index int index value 187188 */ 188189function metaseo_update_pageindex(page_id, index) { 189190 jQuery.ajax({ 190191 url: ajaxurl, 191192 method: 'POST', 192193 dataType: 'json', 193194 data: { 194195 'action': 'wpms', 195196 'task': 'update_pageindex', 196197 'page_id': page_id, 197198 'index': index, 198199 'wpms_nonce': wpms_localize.wpms_nonce 199200 } 200201 }); 201202} 202203 203204/** 204205 * Update follow for page 205206 * @param page_id int page ID 206207 * @param follow int follow value 207208 */ 208209function metaseo_update_pagefollow(page_id, follow) { 209210 jQuery.ajax({ 210211 url: ajaxurl, 211212 method: 'POST', 212213 dataType: 'json', 213214 data: { 214215 'action': 'wpms', 215216 'task': 'update_pagefollow', 216217 'page_id': page_id, 217218 'follow': follow, 218219 'wpms_nonce': wpms_localize.wpms_nonce 219220 } 220221 }); 221222} 222223 223224/** 224225 * update follow for link 225226 * @param button 226227 */ 227228function wpmsChangeFollow(button) { 228229 var link_id = jQuery(button).closest('tr').data('link'); 229230 var type = jQuery(button).data('type'); 230231 var follow = 1; 231232 if (type === 'done') { 232233 jQuery(button).data('type', 'warning').html('warning'); 233234 jQuery(button).removeClass('wpms_ok').addClass('wpms_warning'); 234235 follow = 0; 235236 } else { 236237 jQuery(button).data('type', 'done').html('done'); 237238 jQuery(button).removeClass('wpms_warning').addClass('wpms_ok'); 238239 follow = 1; 239240 } 240241 241242 jQuery.ajax({ 242243 url: ajaxurl, 243244 method: 'POST', 244245 dataType: 'json', 245246 data: { 246247 'action': 'wpms', 247248 'task': 'update_follow', 248249 'link_id': link_id, 249250 'follow': follow, 250251 'wpms_nonce': wpms_localize.wpms_nonce 251252 } 252253 }); 253254} 254255 255256/** 256257 * Scan link to save to database 257258 * @param $this 258259 */ 259260function wpmsScanLink($this) { 260261 $this.addClass('scaning'); 261262 jQuery.ajax({ 262263 url: ajaxurl, 263264 method: 'POST', 264265 dataType: 'json', 265266 data: { 266267 'action': 'wpms', 267268 'task': 'scan_link', 268269 'paged': $this.data('paged'), 269270 'comment_paged': $this.data('comment_paged'), 270271 'wpms_nonce': wpms_localize.wpms_nonce 271272 }, 272273 success: function (res) { 273274 if (!res.status) { 274275 if (res.type === 'limit') { 275276 var wpms_process = jQuery('.wpms_process').data('w'); 276277 var wpms_process_new = parseFloat(wpms_process) + parseFloat(res.percent); 277278 if (wpms_process_new > 100) 278279 wpms_process_new = 100; 279280 jQuery('.wpms_process').data('w', wpms_process_new).html('<span>' + parseInt(wpms_process_new) + '%</span>').css('width', wpms_process_new + '%').show(); 280281 $this.trigger('click'); 281282 } else if (res.type === 'limit_comment_content') { 282283 wpms_process = jQuery('.wpms_process').data('w'); 283284 if (wpms_process < 33.33) 284285 wpms_process = 33.33; 285286 wpms_process_new = parseFloat(wpms_process) + parseFloat(res.percent); 286287 if (wpms_process_new > 100) 287288 wpms_process_new = 100; 288289 jQuery('.wpms_process').data('w', wpms_process_new).html('<span>' + parseInt(wpms_process_new) + '%</span>').css('width', wpms_process_new + '%').show(); 289290 $this.data('comment_paged', parseInt(res.paged) + 1); 290291 $this.trigger('click'); 291292 } else { 292293 wpms_process = jQuery('.wpms_process').data('w'); 293294 if (wpms_process < 66.66) 294295 wpms_process = 66.66; 295296 wpms_process_new = parseFloat(wpms_process) + parseFloat(res.percent); 296297 if (wpms_process_new > 100) 297298 wpms_process_new = 100; 298299 jQuery('.wpms_process').data('w', wpms_process_new).html('<span>' + parseInt(wpms_process_new) + '%</span>').css('width', wpms_process_new + '%').show(); 299300 $this.data('paged', parseInt(res.paged) + 1); 300301 $this.trigger('click'); 301302 } 302303 } else { 303304 $this.removeClass('scaning'); 304305 jQuery('.wpms_process').data('w', 100).html('<span>100%</span>').css('width', '100%'); 305306 jQuery('#wp-seo-meta-form .spinner').hide(); 306307 window.location.assign(document.URL); 307308 } 308309 } 309310 }); 310311} 311312 312313/** 313314 * Update follow for link 314315 * @param button 315316 */ 316317function wpmsLinkDoAction(button) { 317318 var $this = jQuery(button); 318319 var apply = jQuery('.link-apply-action:checked').val(); 319320 var type_follow = jQuery('.link-bulk-action:checked').val(); 320321 if (typeof type_follow === "undefined" || typeof apply === "undefined") { 321322 return; 322323 } 323324 324325 var action_name = type_follow + '_' + apply; 325326 if (action_name === 'follow_selected' || action_name === 'nofollow_selected' || action_name === 'copy_title_selected') { 326327 if (parseInt(action_name) === 0) 327328 return; 328329 329330 var link_selected = []; 330331 jQuery(".metaseo_link").each(function () { 331332 if (jQuery(this).is(':checked')) { 332333 link_selected.push(jQuery(this).val()); 333334 } 334335 }); 335336 if (link_selected.length === 0) 336337 return; 337338 var data = { 338339 action: 'wpms', 339340 task: 'update_multiplefollow', 340341 linkids: link_selected, 341342 action_name: action_name, 342343 wpms_nonce: wpms_localize.wpms_nonce 343344 }; 344345 } else { 345346 data = { 346347 action: 'wpms', 347348 task: 'update_multiplefollow', 348349 action_name: action_name, 349350 wpms_nonce: wpms_localize.wpms_nonce 350351 }; 351352 } 352353 353354 jQuery('.spinner_apply_follow').css('visibility', 'visible').show(); 354355 jQuery.ajax({ 355356 url: ajaxurl, 356357 method: 'POST', 357358 dataType: 'json', 358359 data: data, 359360 success: function (response) { 360361 if (response.status) { 361362 jQuery('.spinner_apply_follow').hide(); 362363 window.location.assign(document.URL); 363364 } else { 364365 if (action_name === 'follow_all' || action_name === 'nofollow_all' || action_name === 'copy_title_all') { 365366 if (response.message === 'limit') { 366367 $this.trigger('click'); 367368 } 368369 } 369370 } 370371 } 371372 }); 372373} 373374 374375/** 375376 * Update length number of meta description for post, page, custom post type 376377 * @param metadesc_id string id of element tag 377378 */ 378379function metaseo_desclength(metadesc_id) { 379380 var desc = (metaseo_clean(jQuery('#' + metadesc_id).val())).trim(); 380381 var postid = metadesc_id.replace('metaseo-metadesc-', ''); 381382 var counter_id = 'metaseo-metadesc-len' + postid; 382383 jQuery('#' + counter_id).text(desc_max_len - desc.length); 383384 if (desc.length >= desc_max_len) { 384385 jQuery('#' + counter_id).removeClass('word-74B6FC').addClass('word-exceed');//#FEFB04 385386 } else if (desc.length <= 120) { 386387 jQuery('#' + counter_id).removeClass('word-exceed').addClass('word-74B6FC');//#74B6FC 387388 } else { 388389 jQuery('#' + counter_id).removeClass('word-exceed word-74B6FC'); 389390 } 390391 391392 jQuery('#snippet_desc' + postid).text(desc.substr(0, desc_max_len)); 392393} 393394 394395 395396/** 396397 * Update meta description for post, page, custom post type 397398 * @param metadesc_id 398399 * @param needToSave 399400 */ 400401function metaseo_updateDesc(metadesc_id, needToSave) { 401402 var desc = (metaseo_clean(jQuery('#' + metadesc_id).val())).trim(); 402403 var postid = metadesc_id.replace('metaseo-metadesc-', ''); 403404 if (needToSave === true && oldDescValues[postid] !== desc) { 404405 saveMetaContentChanges('metadesc', postid, desc); 405406 } 406407 407408 //Push the new value into the array 408409 oldDescValues[postid] = desc; 409410} 410411 411412var autosaveNotification; 412413 413414/** 414415 * Update content meta 415416 * @param metakey 416417 * @param postid 417418 * @param data 418419 */ 419420function saveMetaContentChanges(metakey, postid, data) { 420421 jQuery('.wpms_loader' + postid).show(); 421422 var postData = { 422423 'action': 'wpms', 423424 'task': 'updateContentMeta', 424425 'metakey': metakey, 425426 'postid': postid, 426427 'value': data, 427428 'wpms_nonce': wpms_localize.wpms_nonce 428429 }; 429430 // We can also pass the url value separately from ajaxurl for front end AJAX implementations 430431 jQuery.post(wpms_localize.ajax_url, postData, function (response) { 431432 jQuery('.wpms_loader' + postid).hide(); 432433 result = JSON.parse(response); 433434 434435 if (result.updated) { 435436 autosaveNotification = setTimeout(function () { 436437 jQuery('#savedInfo' + postid).text(result.msg); 437438 jQuery('#savedInfo' + postid).css('visibility', 'visible'); 438439 setTimeout(function () { 439440 jQuery('#savedInfo' + postid).css('visibility', 'hidden'); 440441 }, 1000); 441442 }, 1000); 442443 } else { 443444 alert(result.msg); 444445 } 445446 446447 }); 447448} 448449 449450function checkspecial(element_id) { 450451 var element = jQuery(element_id); 451452 var meta_type = element.data('meta-type'); 452453 453454 if (meta_type === 'change_image_name') { 454455 var str = (element.val()); 455456 return /^[\w\d\-\s+_.$]*$/.test(str) != false; 456457 } else { 457458 return true; 458459 } 459460} 460461 461462function metaseo_update(element_id) { 462463 var element = jQuery(element_id); 463464 element.data('post-id'); 464465 element.data('meta-type'); 465466 element.val(); 466467} 467468 468469/** 469470 * Update meta 470471 * @param element_id string element id 471472 * @param post_id int post id 472473 * @param meta_type string meta type name 473474 * @param meta_value string meta value 474475 * @returns {boolean} 475476 */ 476477function saveChanges(element_id, post_id, meta_type, meta_value) { 477478 478479 var element = jQuery(element_id); 479480 var savedInfo = element.parent().find('span.saved-info'); 480481 if (savedInfo.length < 1) { 481482 savedInfo = element.closest('td').find('span.saved-info'); 482483 } 483484 484485 var updated = false; 485486 var postData = { 486487 'action': 'wpms', 487488 'task': 'updateMeta', 488489 'post_id': post_id, 489490 'meta_type': meta_type, 490491 'meta_value': meta_value, 491492 'img_name': element.closest('tr').find('.fix-metas').data('img-name'), 492493 'opt_key': element.closest('tr').find('.fix-metas').data('opt-key'), 493494 'addition': { 494495 'meta_key': element.data('meta-key'), 495496 'meta_type': element.data('meta-type'), 496497 'meta_value': element.val(), 497498 'meta_order': element.data('meta-order'), 498499 'img_post_id': element.data('img-post-id'), 499500 'post_id': element.data('post-id') 500501 }, 501502 'wpms_nonce': wpms_localize.wpms_nonce 502503 }; 503504 504505 // We can also pass the url value separately from ajaxurl for front end AJAX implementations 505506 jQuery.ajax({ 506507 url: wpms_localize.ajax_url, 507508 type: 'post', 508509 data: postData, 509510 dataType: 'json', 510511 beforeSend: function () { 511512 savedInfo.empty().append('<span class="spinner"></span>'); 512513 if (element.hasClass('metaseo-fix-meta')) { 513514 element.closest('.metaseo-img-wrapper').find('.spinner').css('visibility', 'visible').show(); 514515 } else { 515516 element.parent().find('.spinner').css('visibility', 'visible').show(); 516517 } 517518 }, 518519 success: function (response) { 519520 if (parseInt(response) === 0) { 520521 saveChanges(element_id, post_id, meta_type, meta_value); 521522 } 522523 523524 updated = response.updated; 524525 525526 if (updated) { 526527 autosaveNotification = setTimeout(function () { 527528 528529 if (element.hasClass('metaseo-fix-meta')) { 529530 element.closest('.metaseo-img-wrapper').find('.spinner').hide(); 530531 } else { 531532 element.parent().find('.spinner').hide(); 532533 } 533534 534535 savedInfo.removeClass('metaseo-msg-warning').addClass('metaseo-msg-success') 535536 .text(response.msg).fadeIn(200); 536537 setTimeout(function () { 537538 savedInfo.empty().append('<span class="spinner"></span>'); 538539 savedInfo.hide(); 539540 }, 3000); 540541 541542 }, 200); 542543 543544 //update image's data-name attribute 544545 if (typeof element.data('extension') !== 'undefined') { 545546 jQuery('[data-img-post-id="' + element.data('post-id') + '"]').data('name', element.val() + element.data('extension')); 546547 } 547548 //Scan post and update post_meta 548549 var img = jQuery('[data-img-post-id="' + postData['addition']['img_post_id'] + '"]'); 549550 if (img.length > 0) { 550551 _metaSeoScanImages( 551552 { 552553 'name': img.data('name'), 553554 'img_post_id': postData['addition']['img_post_id'], 554555 'type': 'update_meta' 555556 } 556557 ); 557558 } 558559 559560 if (typeof response.type !== "undefined" && response.type === 'auto_override') { 560561 _metaSeoScanImages( 561562 { 562563 'name': response.imgname, 563564 'img_post_id': response.pid, 564565 'type': 'update_meta' 565566 } 566567 ); 567568 } 568569 569570 if (typeof response.type_change !== "undefined" && response.type_change === 'edit_meta_alt') { 570571 jQuery('#img-alt-' + element.data('img-post-id')).val(element.val()); 571572 } 572573 } else { 573574 element.val(response.iname); 574575 savedInfo.removeClass('metaseo-msg-success').addClass('metaseo-msg-warning') 575576 .text(response.msg).fadeIn(200).delay(2000).fadeOut(200); 576577 } 577578 }, 578579 error: function () { 579580 580581 } 581582 }); 582583 583584 return updated; 584585} 585586 586587/** 587588 * Scan all posts to find a group of images in their content 588589 */ 589590function metaSeoScanImages() { 590591 var imgs = []; 591592 jQuery('.metaseo-image').each(function (i) { 592593 if (jQuery(this).data('name') !== '') { 593594 imgs[i] = { 594595 'name': jQuery(this).data('name'), 595596 'img_post_id': jQuery(this).data('img-post-id') 596597 }; 597598 } 598599 }); 599600 600601 jQuery.each(imgs, function (i, v) { 601602 _metaSeoScanImages(v); 602603 }); 603604 604605} 605606 606607/** 607608 * Scan images good and not good in post content 608609 * @param imgs array current image info 609610 * @returns {boolean} 610611 * @private 611612 */ 612613function _metaSeoScanImages(imgs) { 613614 if (imgs.length < 1) { 614615 //alert('No images choosen for scanning, please check again!'); 615616 return false; 616617 } 617618 618619 jQuery.ajax({ 619620 url: wpms_localize.ajax_url, 620621 method: 'post', 621622 data: { 622623 'action': 'wpms', 623624 'task': 'scanPosts', 624625 'imgs': imgs, 625626 'wpms_nonce': wpms_localize.wpms_nonce 626627 }, 627628 dataType: 'json', 628629 beforeSend: function () { 629630 }, 630631 success: function (response) { 631632 if (parseInt(response) === 0) { 632633 _metaSeoScanImages(imgs); 633634 } 634635 //clog(imgs); 635636 if (response.success === true) { 636637 //Clear content holder first 637638 if (imgs.length === 1) { 638639 jQuery('#opt-info-' + imgs[0]['img_post_id']).removeClass('opt-info-warning').empty(); 639640 } 640641 //id is refered to image post id 641642 for (var iID in response.msg) { 642643 jQuery('#opt-info-' + iID).html(null); 643644 //Change css position property of td tag to default 644645 jQuery('#opt-info-' + iID).parent().css('position', 'static'); 645646 jQuery('#opt-info-' + iID).append('<p class="btn-wrapper"></p>'); 646647 647648 for (var msgType in response.msg[iID]) { 648649 if (response.msg[iID][msgType]['warning'] 649650 && !jQuery('#opt-info-' + iID).hasClass('opt-info-warning')) { 650651 jQuery('#opt-info-' + iID).addClass('opt-info-warning'); 651652 } 652653 653654 jQuery('#opt-info-' + iID).find('p.btn-wrapper').append(response.msg[iID][msgType]['button']); 654655 if (typeof response.msg[iID][msgType]['msg'] !== 'object') { 655656 var hlight = !response.msg[iID][msgType]['warning'] ? 'metaseo-msg-success' : ''; 656657 jQuery('#opt-info-' + iID).prepend('<p class="' + hlight + '">' + response.msg[iID][msgType]['msg'] + '</p>'); 657658 } else { 658659 for (var k in response.msg[iID][msgType]['msg']) { 659660 jQuery('#opt-info-' + iID).prepend('<p>' + response.msg[iID][msgType]['msg'][k] + '</p>'); 660661 } 661662 } 662663 663664 } 664665 665666 jQuery('#opt-info-' + iID).parent().find('span.metaseo-loading').hide(); 666667 } 667668 668669 jQuery('.opt-info-warning').fadeIn(200); 669670 jQuery('input.metaseo-checkin').each(function (i, input) { 670671 uncheck(input); 671672 }); 672673 } 673674 674675 // show tooltip when hover 'Fix meta/Edit meta' button 675676 tippy('.fix-metas', { 676677 animation: 'scale', 677678 duration: 0, 678679 arrow: false, 679680 placement: 'top', 680681 theme: 'wpms-widgets-tippy_show_arow', 681682 onShow(instance) { 682683 instance.popper.hidden = instance.reference.dataset.tippy ? false : true; 683684 instance.setContent(instance.reference.dataset.tippy); 684685 } 685686 }); 686687 }, 687688 error: function () { 688689 // alert('Errors occured while scanning posts for optimization'); 689690 } 690691 }); 691692} 692693 693694/** 694695 * To fix meta of a specified image 695696 * @param that 696697 */ 697698function metaseo_fix_meta(that) { 698699 var $this = jQuery(that); 699700 700701 if (checkspecial(that) === true) { 701702 702703 if (that.jquery === undefined) { 703704 $this.bind('input propertychange', function () { 704705 metaseo_update(that); 705706 }); 706707 } else { 707708 metaseo_update(that); 708709 } 709710 710711 } 711712} 712713 713714/** 714715 * Add meta default 715716 * @param that 716717 */ 717718function add_meta_default(that) { 718719 var $this = jQuery(that); 719720 var input = $this.parent().find('input'); 720721 input.val($this.data('default-value')).focus(); 721722} 722723 723724//-------------------------------- 724725/** 725726 * Optimize a single post 726727 * @param element string current element 727728 * @returns {boolean} 728729 */ 729730function optimize_imgs(element) { 730731 var $this = jQuery(element); 731732 var post_id = $this.data('post-id'); 732733 var img_post_id = $this.data('img-post-id'); 733734 var checkin = jQuery('.checkin-' + post_id); 734735 var img_exclude = []; 735736 var not_checked_counter = 0; 736737 var updated = false; 737738 738739 var j = 0; 739740 checkin.each(function (i, el) { 740741 if (!(jQuery(el).is(':checked'))) { 741742 not_checked_counter++; 742743 if (jQuery(el).val() !== '' || jQuery(el).val() !== 'undefined') { 743744 img_exclude[j] = parseInt(jQuery(el).val()); 744745 j++; 745746 } 746747 } 747748 }); 748749 749750 if (checkin.length <= not_checked_counter) { 750751 //alert('No images has choosen. \\nPlease click on the checkbox in what image you want to replace!'); 751752 return false; 752753 } 753754 754755 if (!post_id && !img_post_id) { 755756 alert('Cant do the optimization because of missing image ID.\\nPlease check again!'); 756757 } else { 757758 jQuery.ajax({ 758759 url: wpms_localize.ajax_url, 759760 async: false, 760761 data: { 761762 'action': 'wpms', 762763 'task': 'optimize_imgs', 763764 'post_id': post_id, 764765 'img_post_id': img_post_id, 765766 'img_exclude': img_exclude, 766767 'wpms_nonce': wpms_localize.wpms_nonce 767768 }, 768769 dataType: 'json', 769770 type: 'post', 770771 beforeSend: function () { 771772 $this.parent().find('span.spinner').css('visibility', 'visible').show(); 772773 }, 773774 success: function (response) { 774775 if (parseInt(response) === 0) { 775776 optimize_imgs(element); 776777 } 777778 778779 if (response.success) { 779780 updated = true; 780781 781782 checkin.each(function () { 782783 if (jQuery.inArray(parseInt(jQuery(this).val()), img_exclude) === -1) { 783784 784785 var img_choosen = jQuery(this).parent(); 785786 jQuery(this).remove(); 786787 787788 img_choosen.empty().append('<span class="metaseo-checked"></span>'); 788789 img_choosen.parent().find('p.metaseo-msg').removeClass('msg-error').addClass('msg-success').empty().text(response.msg).fadeIn(200); 789790 setTimeout(function () { 790791 img_choosen.find('p.metaseo-msg').fadeOut(300); 791792 }, 5000); 792793 793794 } 794795 }); 795796 796797 var checked = jQuery('.checkin-' + post_id); 797798 if (checked.length === 0) { 798799 $this.addClass('disabled replaced').removeClass('ju-button waves-effect waves-light').html(wpms_localize.replaced); 799800 } 800801 801802 $this.parent().find('span.spinner').fadeOut(300); 802803 //Disable Replace all button if all image were resized 803804 var metaseo_checkin = jQuery('.metaseo-checkin'); 804805 805806 if (metaseo_checkin.length === 0) { 806807 jQuery('#metaseo-replace-all').addClass('disabled'); 807808 } 808809 //Scan post and update post_meta 809810 var img = jQuery('[data-img-post-id="' + img_post_id + '"]'); 810811 _metaSeoScanImages({'name': img.data('name'), 'img_post_id': img_post_id}); 811812 812813 setTimeout(function () { 813814 window.location.reload(true); 814815 }, 1000); 815816 } else { 816817 $this.parent().find('span.spinner').hide(); 817818 $this.parent().find('p.metaseo-msg').removeClass('msg-success').addClass('msg-error'); 818819 } 819820 820821 }, 821822 error: function () { 822823 823824 } 824825 }); 825826 } 826827 827828 img_exclude = []; 828829 return updated; 829830} 830831 831832/** 832833 * Optimize all posts in list displayed 833834 * @param that 834835 */ 835836function optimize_imgs_group(that) { 836837 jQuery('a.metaseo-optimize').each(function (i, el) { 837838 if (parseInt(i) === 0) { 838839 jQuery(that).parent().find('span.spinner').show(); 839840 } 840841 841842 jQuery(this).trigger('click'); 842843 843844 if (parseInt(i) === (jQuery(el).length - 1)) { 844845 jQuery(that).parent().find('span.spinner').hide(); 845846 } 846847 }); 847848 848849} 849850 850851/** 851852 * disable Replace images 852853 * @param that 853854 */ 854855function uncheck(that) { 855856 var post_id = that.get(0).className.substr(that.get(0).className.lastIndexOf('-') + 1); 856857 var checked = jQuery('.checkin-' + post_id); 857858 var not_checked_counter = 0; 858859 859860 checked.each(function () { 860861 if (!(jQuery(this).is(':checked'))) { 861862 not_checked_counter++; 862863 } 863864 }); 864865 865866 //Toggle disable Replace button if all images in a post were resized 866867 if (not_checked_counter >= checked.length) { 867868 jQuery('a.metaseo-optimize[data-post-id="' + post_id + '"]').addClass('disabled'); 868869 } else { 869870 jQuery('a.metaseo-optimize[data-post-id="' + post_id + '"]').removeClass('disabled'); 870871 } 871872 872873 //Toggle disable Replace all button if all images in posts were resized 873874 var replaceBtns = jQuery('.metaseo-optimize'); 874875 var disable = true; 875876 replaceBtns.each(function (i, btn) { 876877 if (!jQuery(btn).hasClass('disabled')) { 877878 disable = false; 878879 } 879880 }); 880881 881882 if (disable === true) { 882883 jQuery('#metaseo-replace-all').addClass('disabled'); 883884 } else { 884885 jQuery('#metaseo-replace-all').removeClass('disabled'); 885886 } 886887} 887888 888889/** 889890 * Show posts list for resizing or update meta info of an image with specified id 890891 * @param element 891892 */ 892893function showPostsList(element) { 893894 var that = jQuery(element); 894895 var data = { 895896 'action': 'wpms', 896897 'task': 'load_posts', 897898 'img_name': that.data('img-name'), 898899 'post_id': that.data('post-id'), 899900 'opt_key': that.data('opt-key'), 900901 'wpms_nonce': wpms_localize.wpms_nonce 901902 }; 902903 903904 if (that.data('img-name') !== '') { 904905 jQuery.ajax({ 905906 url: wpms_localize.ajax_url, 906907 type: 'post', 907908 dataType: 'html', 908909 data: data, 909910 beforeSend: function () { 910911 that.find('.spinner-light').show(); 911912 }, 912913 success: function (response) { 913914 if (parseInt(response) === 0) { 914915 showPostsList(element); 915916 } 916917 that.parent().find('.spinner-light').hide(); 917918 that.closest('td.col_image_info').find('div.popup > .popup-content').empty().html(response).fadeIn(300); 918919 919920 jQuery('.metaseo-img img').on('click', function () { 920921 if (jQuery(this).closest('.metaseo-img-wrapper').hasClass('checked')) { 921922 jQuery(this).closest('.metaseo-img-wrapper').removeClass('checked'); 922923 jQuery(this).closest('.metaseo-img-wrapper').find('.metaseo-checkin').prop('checked', false); 923924 uncheck(jQuery(this).closest('.metaseo-img-wrapper').find('.metaseo-checkin')); 924925 } else { 925926 jQuery(this).closest('.metaseo-img-wrapper').addClass('checked'); 926927 jQuery(this).closest('.metaseo-img-wrapper').find('.metaseo-checkin').prop('checked', true); 927928 } 928929 }); 929930 930931 //to set background-color of popup-header to like adminmenu active 931932 var metaseo_bg = jQuery('#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu').css('background-color'); 932933 933934 if (metaseo_bg !== 'undified') { 934935 jQuery('.popup-content .content-header').css({'background-color': metaseo_bg, 'color': '#FFF'}); 935936 jQuery('span.popup-close').css({'color': '#FFF'}); 936937 } 937938 938939 that.showPopup(that); 939940 } 940941 }); 941942 } else { 942943 alert('Something went wrong, please check Image name if it\'s empty before click Resize button'); 943944 } 944945} 945946 946947/** 947948 * Import meta data from other plugin into Wp Meta Seo 948949 * @param that 949950 * @param event 950951 */ 951952function importMetaData(that, event) { 952953 var element = jQuery('#' + that.id); 953954 954955 event.preventDefault(); 955956 if (that.id === '_aio_' || that.id === '_yoast_') { 956957 jQuery.ajax({ 957958 url: wpms_localize.ajax_url, 958959 type: 'post', 959960 data: { 960961 'action': 'wpms', 961962 'task': 'import_meta_data', 962963 'plugin': that.id, 963964 'wpms_nonce': wpms_localize.wpms_nonce 964965 }, 965966 dataType: 'json', 966967 beforeSend: function () { 967968 element.find('span.spinner-light').show(); 968969 }, 969970 success: function (response) { 970971 if (response.success) { 971972 element.find('span.spinner-light').fadeOut(500); 972973 jQuery('.metaseo-import-wrn').closest('.error').fadeOut(1500); 973974 //Refresh the page to see al changed after import Yoast or AIO data into MetaSEO 974975 if (location.href.search('page=metaseo_content_meta') !== -1) { 975976 location.reload(); 976977 } 977978 } 978979 }, 979980 error: function () { 980981 alert('Something went wrong in import processing!'); 981982 } 982983 983984 }); 984985 } 985986} 986987 987988/** 988989 * Update once input changed and blur 989990 * @param that 990991 */ 991992function updateInputBlur(that) { 992993 var element = jQuery(that); 993994 var post_id = element.data('post-id'); 994995 var meta_type = element.data('meta-type'); 995996 var meta_value = element.val(); 996997 if (saveChanges(that, post_id, meta_type, meta_value)) { 997998 if (meta_type === 'change_image_name') { 998999 jQuery('a.img-resize[data-post-id="' + post_id + '"]').data('img-name', meta_value); 9991000 } 10001001 } 10011002} 10021003 10031004/** 10041005 * Check keypress Code 10051006 * @param event 10061007 * @returns {boolean} 10071008 */ 10081009function checkeyCode(event) { 10091010 if (parseInt(event.which) === 13 || parseInt(event.keyCode) === 13) { 10101011 return false; 10111012 } 10121013} 10131014 10141015/** 10151016 * Check if a image name is valid or not 10161017 * @param iname string name of image 10171018 * @returns {*} 10181019 */ 10191020function validateiName(iname) { 10201021 var is_only_spaces = iname.length > 0; 10211022 iname = iname.trim(); 10221023 var msg = ''; 10231024 10241025 if (iname.length < 1) { 10251026 msg = !is_only_spaces ? 'Should not be empty' : 'Should not only spaces'; 10261027 return {msg: msg, name: ''}; 10271028 } 10281029 10291030 return {msg: '', name: iname}; 10301031} 10311032 10321033/** 10331034 * Scan meta image 10341035 * @param $this 10351036 */ 10361037function wpms_image_scan_meta($this) { 10371038 $this.addClass('scaning'); 10381039 jQuery.ajax({ 10391040 type: 'POST', 10401041 url: ajaxurl, 10411042 data: { 10421043 action: "wpms", 10431044 task: "image_scan_meta", 10441045 paged: $this.data('paged'), 10451046 wpms_nonce: wpms_localize.wpms_nonce 10461047 }, 10471048 success: function (res) { 10481049 var w = jQuery('.wpms_process_meta').data('w'); 10491050 10501051 10511052 if (res.status === 'error_time') { 10521053 if (typeof res.percent !== "undefined") { 10531054 var wpms_process = jQuery('.wpms_process').data('w'); 10541055 var wpms_process_new = parseFloat(wpms_process) + parseFloat(res.percent); 10551056 if (wpms_process_new > 100) 10561057 wpms_process_new = 100; 10571058 $this.data('paged', parseInt(res.paged) + 1); 10581059 jQuery('.wpms_process').data('w', wpms_process_new).html('<span>' + parseInt(wpms_process_new) + '%</span>').css('width', wpms_process_new + '%').show(); 10591060 jQuery('.image_scan_meta').trigger('click'); 10601061 } 10611062 } else { 10621063 $this.removeClass('scaning'); 10631064 jQuery('.wpms_process').data('w', 100).html('<span>100%</span>').css('width', '100%'); 10641065 jQuery('#wp-seo-meta-form .spinner').hide(); 10651066 window.location.assign(document.URL); 10661067 } 10671068 } 10681069 }); 10691070} 10701071 10711072jQuery(document).ready(function ($) { 10721073 $('.mbulk_copy').on('click', function () { 10731074 $('.mbulk_copy').prop('checked', false); 10741075 $(this).prop('checked', true); 10751076 }); 10761077 10771078 $('.bulk-action-follow').on('click', function () { 10781079 $('.bulk-action-follow').prop('checked', false); 10791080 $(this).prop('checked', true); 10801081 }); 10811082 10821083 $('[name="post_type_filter"], .wpms_duplicate_meta, .wpms_lang_list, .wpms_post_visibility').on('change', function () { 10831084 $('#wp-seo-meta-form').submit() 10841085 }); 10851086 $('[name="taxonomy_filter"], .wpms_duplicate_cat_meta').on('change', function () { 10861087 $('#wp-seo-meta-form').submit() 10871088 }); 10881089 10891090 $('#home_text_default').on('change', function () { 10901091 if ($(this).is(':checked')) { 10911092 $('.tr_home_text').addClass('show').removeClass('hide'); 10921093 } else { 10931094 $('.tr_home_text').addClass('hide').removeClass('show'); 10941095 } 10951096 }); 10961097 10971098 $('.image_scan_meta').on('click', function () { 10981099 wpms_image_scan_meta($(this)); 10991100 }); 11001101 11011102 $('.wp-meta-seo_page_metaseo_image_meta #image-submit').on('click', function (e) { 11021103 e.preventDefault(); 11031104 $('.imgspinner').show().css('visibility', 'visible'); 11041105 $('#wp-seo-meta-form').submit(); 11051106 }); 11061107 11071108 //Cursor changes on any ajax start and end 11081109 //Thanks to iambriansreed from stacoverflow.com 11091110 $(document).ajaxStart(function () { 11101111 $('body').css({'cursor': 'wait'}); 11111112 }).ajaxStop(function () { 11121113 $('body').css({'cursor': 'default'}); 11131114 }); 11141115 11151116 $('span.pagination-links a.disabled').on('click', function (e) { 11161117 e.preventDefault(); 11171118 }); 11181119 11191120 // when change value of per page input in image view 11201121 $('.metaseo_imgs_per_page').on('input propertychange', function () { 11211122 var perpage = $(this).val(); 11221123 $('.metaseo_imgs_per_page').each(function (i, e) { 11231124 if ($(e).val() !== perpage) { 11241125 $(e).val(perpage); 11251126 } 11261127 }); 11271128 }); 11281129 11291130 // when change link source filter in link view 11301131 $('.metaseo_link_source').on('change', function () { 11311132 var value = $(this).val(); 11321133 $('.metaseo_link_source').each(function (i, e) { 11331134 if ($(e).val() !== value) { 11341135 $(e).val(value); 11351136 } 11361137 }); 11371138 }); 11381139 11391140 // when change follow value of link in link view 11401141 $('.metaseo_follow_action').on('change', function () { 11411142 var value = $(this).val(); 11421143 $('.metaseo_follow_action').each(function (i, e) { 11431144 if ($(e).val() !== value) { 11441145 $(e).val(value); 11451146 } 11461147 }); 11471148 }); 11481149 11491150 // when change the filter 11501151 $('.metaseo-filter').on('change', function () { 11511152 var value = $(this).val(); 11521153 $('.metaseo-filter').each(function (i, e) { 11531154 if ($(e).val() !== value) { 11541155 $(e).val(value); 11551156 } 11561157 }); 11571158 }); 11581159 11591160 // when change 'All images' filter in image view 11601161 $('.meta_filter').on('change', function () { 11611162 var value = $(this).val(); 11621163 $('.meta_filter').each(function (i, e) { 11631164 if ($(e).val() !== value) { 11641165 $(e).val(value); 11651166 } 11661167 }); 11671168 }); 11681169 11691170 // when change 'Status' filter in 404 view 11701171 $('.redirect_filter').on('change', function () { 11711172 var value = $(this).val(); 11721173 $('.redirect_filter').each(function (i, e) { 11731174 if ($(e).val() !== value) { 11741175 $(e).val(value); 11751176 } 11761177 }); 11771178 }); 11781179 11791180 // when change broken filter in 404 view 11801181 $('.broken_filter').on('change', function () { 11811182 var value = $(this).val(); 11821183 $('.broken_filter').each(function (i, e) { 11831184 if ($(e).val() !== value) { 11841185 $(e).val(value); 11851186 } 11861187 }); 11871188 }); 11881189 11891190 // when change 'All meta infomation' filter in content view 11901191 $('.wpms_duplicate_meta').on('change', function () { 11911192 var value = $(this).val(); 11921193 $('.wpms_duplicate_meta').each(function (i, e) { 11931194 if ($(e).val() !== value) { 11941195 $(e).val(value); 11951196 } 11961197 }); 11971198 }); 11981199 11991200 $('.wpms_post_visibility').on('change', function () { 12001201 var value = $(this).val(); 12011202 $('.wpms_post_visibility').each(function (i, e) { 12021203 if ($(e).val() !== value) { 12031204 $(e).val(value); 12041205 } 12051206 }); 12061207 }); 12071208 12081209 $('.wpms_lang_list').on('change', function () { 12091210 var value = $(this).val(); 12101211 $('.wpms_lang_list').each(function (i, e) { 12111212 if ($(e).val() !== value) { 12121213 $(e).val(value); 12131214 } 12141215 }); 12151216 }); 12161217 12171218 $('.metaseo-img-name').on('input propertychange', function () { 12181219 var savedInfo = $(this).parent().find('span.saved-info'); 12191220 var iname = validateiName($(this).val()); 12201221 var msg = iname.msg; 12211222 if (iname.name.length > 0) { 12221223 if (!checkspecial(this)) { 12231224 msg = 'Should not special char'; 12241225 } 12251226 } 12261227 12271228 if (msg.length > 0) { 12281229 //Set this value to metaseoValueHolder 12291230 metaseoValueHolder[this.id] = iname.name.substr(0, iname.name.length - 1); 12301231 12311232 savedInfo.removeClass('metaseo-msg-success') 12321233 .addClass('metaseo-msg-warning').empty().text(msg); 12331234 } 12341235 }); 12351236 12361237 $('.metaseo-img-meta').each(function (i, element) { 12371238 if ($(this).hasClass('metaseo-img-name')) { 12381239 metaseoValueHolder[this.id + '_prev'] = jQuery(this).val(); 12391240 } 12401241 $(element).on('keydown', function (event) { 12411242 if (parseInt(event.which) === 13 || parseInt(event.keyCode) === 13) { 12421243 return false; 12431244 } 12441245 }); 12451246 }); 12461247 12471248 $('.metaseo-img-meta').on('change', function () { 12481249 if (jQuery(this).val() === '') { 12491250 jQuery(this).val(metaseoValueHolder[this.id + '_prev']); 12501251 $(this).parent().find('span.saved-info').empty().append('<span class="spinner"></span>'); 12511252 } 12521253 if (checkspecial(this) === true) { 12531254 updateInputBlur(this); 12541255 } 12551256 }); 12561257 12571258 // when import meta 12581259 $('.dissmiss-import').on('click', function (e) { 12591260 e.preventDefault(); 12601261 $(this).closest('.error').fadeOut(1000); 12611262 setTimeout(function () { 12621263 $(this).closest('.error').remove(); 12631264 }, 5000); 12641265 12651266 var plugin = $(this).parent().find('a.button').attr('id'); 12661267 12671268 if (plugin === '_aio_' || plugin === '_yoast_') { 12681269 $.ajax({ 12691270 url: wpms_localize.ajax_url, 12701271 type: 'post', 12711272 data: { 12721273 'action': 'wpms', 12731274 'task': 'dismiss_import_meta', 12741275 'plugin': plugin, 12751276 'wpms_nonce': wpms_localize.wpms_nonce 12761277 }, 12771278 dataType: 'json', 12781279 beforeSend: function () { 12791280 12801281 }, 12811282 success: function (response) { 12821283 if (response.success !== true) { 12831284 alert('Dismiss failed!'); 12841285 } 12851286 } 12861287 }); 12871288 } 12881289 }); 12891290 12901291 // when change follow of post/page in metabox view 12911292 $('.metaseo_metabox_follow').on('change', function () { 12921293 var page_id = $(this).data('post_id'); 12931294 var follow = $(this).val(); 12941295 metaseo_update_pagefollow(page_id, follow); 12951296 }); 12961297 12971298 // when change index of post/page in metabox view 12981299 $('.metaseo_metabox_index').on('change', function () { 12991300 var page_id = $(this).data('post_id'); 13001301 var index = $(this).val(); 13011302 metaseo_update_pageindex(page_id, index); 13021303 }); 13031304 //---------------------------------------------------------- 13041305 //Pop-up declaration 13051306 $.fn.absoluteCenter = function () { 13061307 this.each(function () { 13071308 $(this).css({ 13081309 'position': 'fixed', 13091310 'top': $('div.wrap').offset().top, 13101311 'left': $('div.wrap').offset().left, 13111312 'right': '25px', 13121313 'bottom': '10px' 13131314 }); 13141315 return this; 13151316 }); 13161317 }; 13171318 13181319 $.fn.showPopup = function (that) { 13191320 var bg = $('div.popup-bg'); 13201321 var obj = that.closest('.col_image_info').find('div.popup'); 13211322 var btnClose = obj.find('.popup-close'); 13221323 bg.animate({opacity: 0.2}, 0).fadeIn(200); 13231324 obj.fadeIn(200).absoluteCenter(); 13241325 btnClose.on('click', function () { 13251326 bg.fadeOut(100); 13261327 obj.fadeOut(100).find('div.popup-content').empty(); 13271328 }); 13281329 bg.on('click', function () { 13291330 btnClose.trigger('click'); 13301331 }); 13311332 $(document).keydown(function (e) { 13321333 if (parseInt(e.keyCode) === 27) { 13331334 btnClose.trigger('click'); 13341335 } 13351336 }); 13361337 return false; 13371338 }; 13381339 $('a.show-popup').on('click', function () { 13391340 $(this).showPopup($(this)); 13401341 }); 13411342 13421343 13431344 $(".wpms-blocks-active").attr('disabled', 'disabled'); 13441345 13451346 $('.custom-bulk-metaseo-metadesc, .custom-bulk-metaseo-metatitle, .wpms-category-title-input, .wpms-category-desc-textarea').on('mouseover', function () { 13461347 $(this).addClass('wpms-mouseover-frame'); 13471348 }).on('mouseout', function () { 13481349 $(this).removeClass('wpms-mouseover-frame'); 13491350 }); 13501351}); 13511352 13521353function changeSettingProfile(profileId, profileList) { 13531354 let selectedProfile; 13541355 for (let i = 0; i < profileList.length; i++) { 13551356 if (profileList[i][1] === profileId) { 13561357 selectedProfile = profileList[i]; 13571358 break; 13581359 } 13591360 } 13601361 // Select element 13611362 let anonymizeIpElement = document.getElementById('anonymize-ip-tracking'); 13621363 let trackingTypeElement = document.getElementById('gg-tracking-type'); 13631364 let profileElement = document.getElementById('tracking-profile-info'); 13641365 if (profileId == 0 && profileElement != null) { 13651366 profileElement.innerHTML = ''; 13661367 } 13671368 if (profileId != 0 && selectedProfile !== 'undefined') { 13681369 // Setting basic tracking 13691370 if (typeof selectedProfile !== 'undefined' && selectedProfile[4] === 'GA4') { 13701371 anonymizeIpElement.style.display = 'none'; 13711372 trackingTypeElement.style.display = 'none'; 13721373 } else { 13731374 anonymizeIpElement.style.display = 'block'; 13741375 trackingTypeElement.style.display = 'block'; 13751376 } 13761377 13771378 // Display select profile info 13781379 let profileInfoHtml = ''; 13791380 if (typeof selectedProfile[0] !== 'undefined' && selectedProfile[0]) profileInfoHtml += 'Profile Name: ' + selectedProfile[0] + '<br>'; 13801381 if (typeof selectedProfile[1] !== 'undefined' && selectedProfile[1]) profileInfoHtml += 'Profile ID: ' + selectedProfile[1] + '<br>'; 13811382 if (typeof selectedProfile[2] !== 'undefined' && selectedProfile[2]) profileInfoHtml += 'Property ID: ' + selectedProfile[2] + '<br>'; 13821383 if (typeof selectedProfile[3] !== 'undefined' && selectedProfile[3]) profileInfoHtml += 'Default URL: ' + selectedProfile[3] + '<br>'; 13831384 if (typeof selectedProfile[4] !== 'undefined' && selectedProfile[4]) profileInfoHtml += 'Property Type: ' + selectedProfile[4] + '<br>'; 13841385 if (typeof selectedProfile[5] !== 'undefined' && selectedProfile[5]) profileInfoHtml += 'Time Shift: ' + selectedProfile[5] + '<br>'; 13851386 if (typeof selectedProfile[6] !== 'undefined' && selectedProfile[6]) profileInfoHtml += 'Time Zone: ' + selectedProfile[6] + '<br>'; 13861387 if (typeof selectedProfile[7] !== 'undefined' && selectedProfile[7]) profileInfoHtml += 'Default Page: ' + selectedProfile[7] + '<br>'; 13871388 if (typeof selectedProfile[8] !== 'undefined' && selectedProfile[8]) profileInfoHtml += 'Measurement ID: ' + selectedProfile[8]; 13881389 13891390 if (profileElement != null) { 13901391 profileElement.innerHTML = profileInfoHtml; 13911392 } 13921393 } 13931394 13941395 13951396} 13961397 13971398function requireTrackingIdTitle(propertyType) { 13981399 if (propertyType !== 'undefined') { 13991400 if (propertyType === 'analytics4') { 14001401 jQuery('#wpms-trackingId-title > label').text(wpms_localize.gg_disconnect_title.ga4); 14011402 } else if(propertyType === 'tagmanager') { 14021403 jQuery('#wpms-trackingId-title > label').text(wpms_localize.gg_disconnect_title.tagmanager); 14031404 } else { 14041405 jQuery('#wpms-trackingId-title > label').text(wpms_localize.gg_disconnect_title.universal); 14051406 } 14061407 } 14071408} 14081409 14091410function reloadSelectContainer(data) { 14101411 let selectElement = document.getElementById('wpms-displaySelectContainers'); 14111412 let html = '<option value="0">Select a container</option>'; 14121413 for (let i = 0; i < data.length; i++) { 14131414 html += '<optgroup label="containers/' + data[i]['containerId'] + '">' + 14141415 '<option value="' + data[i]['containerId'] + '">' + data[i]['name'] + '</option>' + 14151416 '</optgroup>' 14161417 } 14171418 if (selectElement) { 14181419 selectElement.innerHTML = html; 14191420 } 14201421} 14211422 14221423function tagmanagerDisplayAccountInfo(accountList, selectedID) { 14231424 let accountInfo = document.getElementById('wpms-tagmanager-account-info'); 14241425 if (typeof accountList !== 'undefined' && typeof selectedID !== 'undefined') { 14251426 let html = ''; 14261427 let i = 0 14271428 for (; i < accountList.length; i++) { 14281429 if (accountList[i]['accountId'] === selectedID) { 14291430 break; 14301431 } 14311432 } 14321433 if (accountList[i]['accountId']) html += 'Account ID: ' + accountList[i]['accountId'] + '<br>'; 14331434 if (accountList[i]['name']) html += 'Account Name: ' + accountList[i]['name'] + '<br>'; 14341435 14351436 if (accountInfo) { 14361437 accountInfo.innerHTML = html; 14371438 } 14381439 } 14391440} 14401441 14411442function getSelectedTagManagerAccount(accountList, selectedID) { 14421443 let titleInfo = document.getElementById('wpms-tagmanager-title-info'); 14431444 let accountDiv = document.getElementById('wpms-tagmanager-account-div'); 14441445 let wpmstmInformationDiv = document.getElementById('wpmstm-information'); 14451446 14461447 if (typeof selectedID !== 'undefined' && typeof accountList !== 'undefined') { 14471448 if (0 === parseInt(selectedID)) { 14481449 titleInfo.style.display = 'none'; 14491450 accountDiv.style.display = 'none'; 14501451 wpmstmInformationDiv.style.display = 'none'; 14511452 document.getElementById('wpms-displaySelectContainers').innerHTML = '<option value="0">Select a container</option>'; 14521453 document.getElementById('wpms-tagmanager-container-div').style.display = 'none'; 14531454 } 14541455 14551456 // Call Tag Manager API to get containers 14561457 if (0 < parseInt(selectedID)) { 14571458 titleInfo.style.display = 'block'; 14581459 wpmstmInformationDiv.style.display = 'block'; 14591460 accountDiv.style.display = 'block'; 14601461 tagmanagerDisplayAccountInfo(accountList, selectedID); 14611462 jQuery.ajax({ 14621463 url: wpms_localize.ajax_url, 14631464 type: 'post', 14641465 data: { 14651466 'accountID': selectedID, 14661467 'action': 'wpms', 14671468 'task': 'wpms_tagmanager_request_containers', 14681469 'wpms_nonce': wpms_localize.wpms_nonce 14691470 }, 14701471 dataType: 'json', 14711472 beforeSend: function () { 14721473 jQuery('.load-containers-spinner').css('visibility', 'visible'); 14731474 }, 14741475 success: function (response) { 14751476 reloadSelectContainer(response); 14761477 jQuery('.load-containers-spinner').css('visibility', 'hidden'); 14771478 } 14781479 }); 14791480 } 14801481 } 14811482} 14821483 14831484function tagmanagerDisplayContainerInfo(container) { 14841485 // Selected element 14851486 let containerInfo = document.getElementById('wpms-tagmanager-container-info'); 14861487 14871488 if (typeof container !== 'undefined' && container) { 14881489 let html = ''; 14891490 14901491 if (container['containerId']) html += 'Container ID: ' + container['containerId'] + '<br>'; 14911492 if (container['name']) html += 'Container Name: ' + container['name'] + '<br>'; 14921493 if (container['path']) html += 'Container Path: ' + container['path'] + '<br>'; 14931494 if (container['publicId']) html += 'Public ID: ' + container['publicId'] + '<br>'; 14941495 if (container['usageContext']) html += 'Usage Context: ' + container['usageContext'][0] + '<br>'; 14951496 if (container['notes']) html += 'Notes: ' + container['notes'] + '<br>'; 14961497 if (containerInfo) { 14971498 containerInfo.innerHTML = html; 14981499 } 14991500 } 15001501} 15011502 15021503function getSelectedTagManagerContainer(selectedID) { 15031504 let containerDiv = document.getElementById('wpms-tagmanager-container-div'); 15041505 if (typeof selectedID !== 'undefined' && selectedID > 1) { 15051506 if (containerDiv) { 15061507 containerDiv.style.display = 'block'; 15071508 } 15081509 jQuery.ajax({ 15091510 url: wpms_localize.ajax_url, 15101511 type: 'post', 15111512 data: { 15121513 'containerID': selectedID, 15131514 'action': 'wpms', 15141515 'task': 'wpms_tagmanager_container_info', 15151516 'wpms_nonce': wpms_localize.wpms_nonce 15161517 }, 15171518 dataType: 'json', 15181519 beforeSend: function () { 15191520 15201521 }, 15211522 success: function (response) { 15221523 tagmanagerDisplayContainerInfo(response); 15231524 } 15241525 }); 15251526 } else { 15261527 if (containerDiv) { 15271528 containerDiv.style.display = 'none'; 15281529 } 15291530 } 15301531} 15311532 15321533function reloadContainerInfo() { 15331534 // Selected element 15341535 let containerDiv = document.getElementById('wpms-tagmanager-container-div'); 15351536 if (containerDiv) { 15361537 containerDiv.style.display = 'none'; 15371538 } 15381539} 15391540 15401541// Javascript display setting account after reload connect with GTM 15411542function tagmanagerDisplayAccountSetting(accList) { 15421543 // Hide old information 15431544 accountList = accList; // global variable 15441545 document.getElementById('wpmstm-information').style.display = 'none'; 15451546 document.getElementById('wpms-tagmanager-title-info').style.display = 'none'; 15461547 document.getElementById('wpms-displaySelectContainers').innerHTML = '<option value="0">Select a container</option>'; 15471548 15481549 // Selected element 15491550 const selectedEl = document.getElementById('wpms-tagmanager-account-setting'); 15501551 let elementHtml = '<lable class="ju-setting-label wpms_width_100">' + 'Account:' + '</lable>'; 15511552 if (typeof accList !== 'undefined' && accList[0] !== null) { 15521553 elementHtml += '<p class="p-d-20">' + 15531554 '<label>' + 15541555 '<input type="hidden" name="wpms_nonce" value="' + wpms_localize.wpms_nonce + '">' + 15551556 '<select id="wpms-tagmanager-accounts" class="wpms-large-input wpms_width_100" ' + 15561557 'onchange="reloadContainerInfo()" onclick="getSelectedTagManagerAccount(accountList, this.value)"' + 15571558 'name="wpms-tagmanager-accounts">' + 15581559 '<option value="0">Select an account</option>'; 15591560 accList.forEach(function (account) { 15601561 elementHtml += '<optgroup label="' + account['path'] + '"><option value="' + account['accountId'] + '">' + account['name'] + '</option></optgroup>'; 15611562 }) 15621563 elementHtml += '</select></label></p>'; 15631564 if (selectedEl) { 15641565 selectedEl.innerHTML = elementHtml; 15651566 } 15661567 } else { 15671568 elementHtml += '<p class="wpms_width_50" style="margin: auto;" id="wpms-create-tagmanager-account">' + 15681569 '<a style="border: none; background-color: #00a0d2" class="ju-button orange-button" href="https://tagmanager.google.com/#/admin/accounts/create" target="_blank">' + 15691570 'Create an account</a></p>'; 15701571 if (selectedEl) { 15711572 selectedEl.innerHTML = elementHtml; 15721573 } 15731574 } 15741575} 15751576 15761577// Refresh connection with google tag manager 15771578function refreshTagmanagerConnect() { 15781579 wpmstm_refresh_process = document.getElementById('wpms-refresh-gtm-process'); 15791580 jQuery.ajax({ 15801581 url: wpms_localize.ajax_url, 15811582 type: 'post', 15821583 data: { 15831584 'action': 'wpms', 15841585 'task': 'wpms_tagmanager_refresh_connect', 15851586 'wpms_nonce': wpms_localize.wpms_nonce 15861587 }, 15871588 dataType: 'json', 15881589 beforeSend: function () { 15891590 jQuery('.refresh-tm-spinner').css('visibility', 'visible'); 15901591 }, 15911592 success: function (response) { 15921593 if (response) { 15931594 tagmanagerDisplayAccountSetting(response); 15941595 jQuery('.refresh-tm-spinner').css('visibility', 'hidden'); 15951596 wpmsSnackbarModule.show({ 15961597 id: 'wpms-refresh-gtm-success', 15971598 content: "Refresh successfully", 15981599 auto_close: true, 15991600 is_progress: true 16001601 }); 16011602 } 16021603 }, 16031604 error: function (jqXHR, textStatus, errorThrown) { 16041605 jQuery('.refresh-tm-spinner').css('visibility', 'hidden'); 16051606 if (textStatus === 'error' && errorThrown === 'Internal Server Error') { 16061607 jQuery('.wpmstm-error-enable-api').removeClass('hidden'); 16071608 setTimeout(function () { 16081609 jQuery('.wpmstm-error-enable-api').addClass('hidden'); 16091610 }, 5000); 16101611 } else { 16111612 jQuery('.wpmstm-error-access-code').removeClass('hidden'); 16121613 setTimeout(function () { 16131614 jQuery('.wpmstm-error-access-code').addClass('hidden'); 16141615 }, 5000); 16151616 } 16161617 } 16171618 }); 16181619} * TABULARUNIFIED WP-META-SEO/TRUNK/ASSETS/JS/METASEO_SITEMAP.JS ¶ r2869205 r2870465 11(function ($) { 22 $.fn.hScroll = function (amount) { 33 amount = amount || 120; 44 $(this).on("DOMMouseScroll mousewheel", function (event) { 55 var oEvent = event.originalEvent, 66 direction = oEvent.detail ? oEvent.detail * -amount : oEvent.wheelDelta, 77 position = $(this).scrollLeft(); 88 position += direction > 0 ? -amount : amount; 99 $(this).scrollLeft(position); 1010 event.preventDefault(); 1111 }) 1212 }; 1313 1414 $(document).ready(function () { 1515 $('.ju-horizontal-tabs').hScroll(60); 1616 1717 $('.open-popup-posts-list').magnificPopup({ 1818 type:'inline', 1919 midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href. 2020 }); 2121 2222 $('.open-popup-posts-list').on('click', function () { 2323 var category_id = $(this).data('category'); 2424 var slug = $(this).data('slug'); 2525 if (typeof category_id === "undefined") { 2626 return; 2727 } 2828 2929 $('#open-popup-posts-list-'+category_id+' .list_posts_sitemap').html(''); 3030 $('.img-links-loader').show(); 3131 3232 $('.list_posts_sitemap .img-links-loader').show(); 3333 $.ajax({ 3434 url: wpms_localize.ajax_url, 3535 type: 'POST', 3636 dataType: 'json', 3737 data: { 3838 action: 'wpms_list_posts_category', 3939 category_id: category_id, 4040 slug: slug, 4141 wpms_nonce: wpms_localize.wpms_nonce 4242 }, 4343 success: function (res) { 4444 $('.img-links-loader').hide(); 4545 $('#open-popup-posts-list-'+category_id+' .list_posts_sitemap').html(res); 4646 if ($('#category' + slug + ':checked').length) { 4747 $('.category' + slug).prop('checked', true); 4848 } 4949 } 5050 }); 5151 }); 5252 5353 /* 5454 * Paging list posts in sitemap settings 5555 */ 5656 $(".holder_posts").jPages({ 5757 containerID: "wrap_sitemap_option_posts", 5858 previous: "←", 5959 next: "→", 6060 perPage: 100, 6161 delay: 20 6262 }); 6363 6464 $.each(wpmseositemap.post_type,function(i,v){ 6565 $(".holder_"+v).jPages({ 6666 containerID: "wrap_sitemap_option_"+v, 6767 previous: "←", 6868 next: "→", 6969 perPage: 100, 7070 delay: 20 7171 }); 7272 }); 7373 7474 /* 7575 * Paging list pages in sitemap settings 7676 */ 7777 $(".holder_pages").jPages({ 7878 containerID: "wrap_sitemap_option_pages", 7979 previous: "←", 8080 next: "→", 8181 perPage: 100, 8282 delay: 20 8383 }); 8484 8585 /* 8686 * Paging list custom link 8787 */ 8888 $(".holder_custom_url").jPages({ 8989 containerID: "wrap_sitemap_option_customUrl", 9090 previous: "←", 9191 next: "→", 9292 perPage: 100, 9393 delay: 20 9494 }); 9595 9696 // Open tippy 9797 tippy('.wpms_source .ju-setting-label', { 9898 animation: 'scale', 9999 duration: 0, 100100 arrow: false, 101101 placement: 'top', 102102 theme: 'metaseo-tippy tippy-rounded', 103103 onShow(instance) { 104104 instance.popper.hidden = instance.reference.dataset.tippy ? false : true; 105105 instance.setContent(instance.reference.dataset.tippy); 106106 } 107107 }); 108108 109109 if($('#wpms_html_sitemap_theme').length > 0 && $('#wpms_html_sitemap_theme').val() !== 'default'){ 110110 $('#wpms_html_sitemap_column').closest('tr').hide(); 111111 $('.wpms_xmp_custom_column').hide(); 112112 $('.wpms_xmp_order').show(); 113113 }else{ 114114 $('#wpms_html_sitemap_column').closest('tr').show(); 115115 $('.wpms_xmp_custom_column').show(); 116116 $('.wpms_xmp_order').hide(); 117117 } 118118 119119 $('#wpms_html_sitemap_theme').on('change',function(){ 120120 if($('#wpms_html_sitemap_theme').length > 0 && $('#wpms_html_sitemap_theme').val() !== 'default'){ 121121 $('#wpms_html_sitemap_column').closest('tr').hide(); 122122 $('.wpms_xmp_custom_column').hide(); 123123 $('.wpms_xmp_order').show(); 124124 }else{ 125125 $('#wpms_html_sitemap_column').closest('tr').show(); 126126 $('.wpms_xmp_custom_column').show(); 127127 $('.wpms_xmp_order').hide(); 128128 } 129129 }); 130130 131131 $('.wpms_save_create_sitemaps').on('click', function () { 132132 wpms_save_create_sitemaps(); 133133 }); 134134 135135 $('.wpms-sitemap-xml-link-button').on('click', function (e) { 136136 e.preventDefault(); 137137 138138 var link_sitemap = $(this).attr('href'); 139139 wpms_save_create_sitemaps(link_sitemap); 140140 }); 141141 142142 $('.wpms-save-popup-posts-button').on('click', function() { 143143 wpms_save_create_sitemaps(); 144144 }); 145145 146146 /** 147147 * Create sitemap 148148 */ 149149 var wpms_save_create_sitemaps = function (link_sitemap) { 150150 // show spinner 151151 $('.spinner_save_sitemaps').css({'visibility': 'visible'}).show(); 152152 var posts = {}, pages = {}, menus = {}, customUrl = {} ,taxonomies = [], columns_menu = {}, wpms_category_link = [], check_all_menu_items = [], wpms_category_select_all = []; 153153 var custom_post_type = {}; 154154 // get custom post type params to save to sitemap 155155 $.each(wpmseositemap.post_type,function(i,post_type){ 156156 custom_post_type[post_type] = {}; 157157 $(".wpms_xmap_"+post_type).each(function (i, v) { 158158 if ($(v).is(':checked')) { 159159 var id = $(v).val(); 160160 var priority = $('#priority_'+post_type+'_' + id).val(); 161161 var frequency = $('#frequency_'+post_type+'_' + id).val(); 162162 custom_post_type[post_type][id] = {'post_id': id, 'priority': priority, 'frequency': frequency}; 163163 } 164164 }); 165165 }); 166166 167167 // get custom url params to save to sitemap 168168 $(".wpms_xmap_customUrl").each(function (i, v) { 169169 if ($(v).is(':checked')) { 170170 var id = $(v).val(); 171171 var priority = $('#priority_customUrl_' + id).val(); 172172 var frequency = $('#frequency_customUrl_' + id).val(); 173173 customUrl[id] = {'customUrl_id': id, 'priority': priority, 'frequency': frequency}; 174174 } 175175 }); 176176 177177 // get post params to save to sitemap 178178 $(".wpms_xmap_posts").each(function (i, v) { 179179 if ($(v).is(':checked')) { 180180 var id = $(v).val(); 181181 var priority = $('#priority_posts_' + id).val(); 182182 var frequency = $('#frequency_posts_' + id).val(); 183183 posts[id] = {'post_id': id, 'priority': priority, 'frequency': frequency}; 184184 } 185185 }); 186186 187187 // get page params to save to sitemap 188188 $(".wpms_xmap_pages").each(function (i, v) { 189189 if ($(v).is(':checked')) { 190190 var id = $(v).val(); 191191 var priority = $('#priority_pages_' + id).val(); 192192 var frequency = $('#frequency_pages_' + id).val(); 193193 pages[id] = {'post_id': id, 'priority': priority, 'frequency': frequency}; 194194 } 195195 }); 196196 197197 // get menu params to save to sitemap 198198 $(".wpms_xmap_menu").each(function (i, v) { 199199 if ($(v).is(':checked')) { 200200 var id = $(v).val(); 201201 var priority = $('#priority_menu_' + id).val(); 202202 var frequency = $('#frequency_menu_' + id).val(); 203203 menus[id] = {'menu_id': id, 'priority': priority, 'frequency': frequency}; 204204 } 205205 }); 206206 207207 // get category params to save to sitemap 208208 $('.wpms_sitemap_taxonomies').each(function (i, v) { 209209 if ($(v).is(':checked')) { 210210 taxonomies.push($(v).val()); 211211 } 212212 }); 213213 214214 $(".xm_category_select_all").each(function (i, v) { 215215 if ($(v).is(':checked')) { 216216 wpms_category_select_all.push($(v).val()); 217217 } 218218 }); 219219 220220 $('.sitemap_addlink_categories').each(function (i, v) { 221221 if ($(v).is(':checked')) { 222222 wpms_category_link.push($(v).val()); 223223 } 224224 }); 225225 226226 $('.check_all_menu_items').each(function (i, v) { 227227 if ($(v).is(':checked')) { 228228 check_all_menu_items.push($(v).val()); 229229 } 230230 }); 231231 232232 // get author params to save to sitemap 233233 if ($('#wpms_sitemap_author').is(':checked')) { 234234 var wpms_sitemap_author = 1; 235235 } else { 236236 wpms_sitemap_author = 0; 237237 } 238238 239239 if ($('#wpms_sitemap_root').is(':checked')) { 240240 var wpms_sitemap_root = 1; 241241 } else { 242242 wpms_sitemap_root = 0; 243243 } 244244 245245 if ($('#wpms_sitemap_add').is(':checked')) { 246246 var wpms_sitemap_add = 1; 247247 } else { 248248 wpms_sitemap_add = 0; 249249 } 250250 251251 if ($('#wpms_sitemap_enable_core').is(':checked')) { 252252 var wpms_sitemap_enable_core = 1; 253253 } else { 254254 wpms_sitemap_enable_core = 0; 255255 } 256256 257257 // get position of menu to save to sitemap 258258 $('.wpms_display_column_menus').each(function (i, v) { 259259 var menu_id = $(v).data('menu_id'); 260260 columns_menu[menu_id] = $(v).val() 261261 }); 262262 263263 var datas = { 264264 action: 'wpms_save_sitemap_settings', 265265 wpms_sitemap_posts: JSON.stringify(posts), 266266 wpms_sitemap_pages: JSON.stringify(pages), 267267 wpms_sitemap_menus: JSON.stringify(menus), 268268 wpms_sitemap_customUrl: JSON.stringify(customUrl), 269269 wpms_html_sitemap_page: $('#wpms_html_sitemap_page').val(), 270270 wpms_html_sitemap_column: $('#wpms_html_sitemap_column').val(), 271271 wpms_html_sitemap_theme: $('#wpms_html_sitemap_theme').val(), 272272 wpms_html_sitemap_position: $('#wpms_html_sitemap_position').val(), 273273 wpms_check_firstsave: $('#wpms_check_firstsave').val(), 274274 wpms_sitemap_author: wpms_sitemap_author, 275275 wpms_sitemap_root: wpms_sitemap_root, 276276 wpms_sitemap_add: wpms_sitemap_add, 277277 wpms_sitemap_enable_core: wpms_sitemap_enable_core, 278278 wpms_category_link: wpms_category_link, 279279 wpms_category_select_all: wpms_category_select_all, 280280 check_all_menu_items: check_all_menu_items, 281281 wpms_sitemap_taxonomies: taxonomies, 282282 wpms_public_name_posts: $('.public_name_posts').val(), 283283 wpms_public_name_pages: $('.public_name_pages').val(), 284284 wpms_public_name_customUrl: $('.public_name_customUrl').val(), 285285 wpms_display_column_menus: JSON.stringify(columns_menu), 286286 wpms_display_column_posts: $('.wpms_display_column_posts').val(), 287287 wpms_display_column_pages: $('.wpms_display_column_pages').val(), 288288 wpms_display_column_customUrl: $('.wpms_display_column_customUrl').val(), 289289 wpms_display_order_posts: $('.wpms_display_order_posts').val(), 290290 wpms_display_order_pages: $('.wpms_display_order_pages').val(), 291291 wpms_display_order_menus: $('.wpms_display_order_menus').val(), 292292 wpms_display_order_urls: $('.wpms_display_order_urls').val(), 293293 wpms_lang_list: $('.wpms_lang_list').val(), 294294 wpms_nonce: wpms_localize.wpms_nonce 295295 }; 296296 297297 $.each(wpmseositemap.post_type,function(i,post_type){ 298298 datas['wpms_sitemap_'+post_type] = JSON.stringify(custom_post_type[post_type]); 299299 datas['wpms_display_column_'+post_type] = $('.wpms_display_column_'+post_type).val(); 300300 datas['wpms_public_name_'+post_type] = $('.public_name_'+post_type).val(); 301301 }); 302302 303303 $.ajax({ 304304 url: ajaxurl, 305305 method: 'POST', 306306 dataType: 'json', 307307 data: datas, 308308 success: function () { 309309 wpms_regen_sitemaps(link_sitemap); 310310 } 311311 }); 312312 }; 313313 314314 /** 315315 * Generate sitemaps 316316 */ 317317 var wpms_regen_sitemaps = function (link_sitemap) { 318318 $.ajax({ 319319 url: ajaxurl, 320320 method: 'POST', 321321 dataType: 'json', 322322 data: { 323 action: 'wpms_regenerate_sitemaps' 323 action: 'wpms_regenerate_sitemaps', 324 wpms_nonce: wpms_localize.wpms_nonce 324325 }, 325326 success: function () { 326327 $('.spinner_save_sitemaps').hide(); 327328 $('.div_wpms_save_sitemaps .msg-success').fadeIn(100).delay(1000).fadeOut(3000); 328329 329330 if (typeof link_sitemap !== 'undefined') { 330331 window.open(link_sitemap, '_blank'); 331332 window.location.reload(); 332333 } 333334 } 334335 }); 335336 }; 336337 337338 /** 338339 * Remove custom url 339340 */ 340341 var wpms_clear_customUrl = function(){ 341342 $('.wpms_clear_customUrl').on('click',function(){ 342343 var $this = $(this); 343344 var idUrl = $this.closest('.wpms_row').data('id'); 344345 $.ajax({ 345346 url: ajaxurl, 346347 method: 'POST', 347348 dataType: 'json', 348349 data: { 349350 action: 'wpms_clear_customUrl', 350351 idUrl: idUrl, 351352 wpms_nonce: wpms_localize.wpms_nonce 352353 }, 353354 success: function (res) { 354355 if(res){ 355356 $this.closest('.wpms_row').remove(); 356357 wpms_regen_sitemaps(); 357358 } 358359 } 359360 }); 360361 }); 361362 }; 362363 363364 var wpms_columns = ['Zezo', 'One', 'Two', 'Three']; 364365 $('#wpms_html_sitemap_column').on('change', function () { 365366 $('.wpms_display_column').html(null); 366367 for (var i = 1; i <= parseInt($(this).val()); i++) { 367368 $('.wpms_display_column').append('<option value="' + i + '">' + wpms_columns[i] + '</option>'); 368369 } 369370 }); 370371 371372 $('.xm_cb_all').on('click', function () { 372373 var category = $(this).data('category'); 373374 if ($(this).is(':checked')) { 374375 $('.' + category).prop('checked', true); 375376 } else { 376377 $('.' + category).prop('checked', false); 377378 } 378379 // Create sitemap automatic 379380 wpms_save_create_sitemaps(); 380381 }); 381382 382383 $('.xml_cb_customposttype_all').on('click', function () { 383384 var posttype = $(this).data('posttype'); 384385 385386 if ($(this).is(':checked')) { 386387 $('.cb_sitemaps_' + posttype).prop('checked', true); 387388 } else { 388389 $('.cb_sitemaps_' + posttype).prop('checked', false); 389390 } 390391 }); 391392 392393 393394 $('.xm_category_select_all').on('click', function () { 394395 var categoryID = $(this).val(); 395396 var category = $(this).data('category'); 396397 397398 if ($(this).is(':checked')) { 398399 $('.' + category).prop('checked', true); 399400 is_all = 1; 400401 } else { 401402 $('.' + category).prop('checked', false); 402403 is_all = 0; 403404 } 404405 405406 var datas = { 406407 action: 'wpms_sitemap_check_all_category', 407408 wpms_sitemap_category_id: categoryID, 408409 wpms_sitemap_cateogry_is_all: is_all, 409410 wpms_nonce: wpms_localize.wpms_nonce 410411 }; 411412 412413 $.ajax({ 413414 url: ajaxurl, 414415 method: 'POST', 415416 dataType: 'json', 416417 data: datas, 417418 success: function () { 418419 wpms_regen_sitemaps(); 419420 } 420421 }); 421422 }); 422423 423424 // check all 424425 $('.sitemap_check_all').on('click', function () { 425426 var type = $(this).data('type'); 426427 if ($(this).is(':checked')) { 427428 $('.cb_sitemaps_' + type).prop('checked', true); 428429 $('.check_all_menu_items').prop('checked', true); 429430 $('.xm_category_select_all_'+ type).prop('checked', true); 430431 $('.xml_cb_customposttype_all_' + type).prop('checked', true); 431432 } else { 432433 $('.cb_sitemaps_' + type).prop('checked', false); 433434 $('.check_all_menu_items').prop('checked', false); 434435 $('.xm_category_select_all_'+ type).prop('checked', false); 435436 $('.xml_cb_customposttype_all_' + type).prop('checked', false); 436437 } 437438 // Create sitemap automatic 438439 wpms_save_create_sitemaps(); 439440 }); 440441 441442 // Add custom url 442443 $('.wpms_add_customurl').on('click', function () { 443444 if ($('#custom_url_link').val() === '' || $('#custom_url_title').val() === '') { 444445 return; 445446 } 446447 $('.wpms_customurl_spinner').css('visibility','visible').show(); 447448 $.ajax({ 448449 url: ajaxurl, 449450 method: 'POST', 450451 dataType: 'json', 451452 data: { 452453 action : 'wpms_sitemaps_add_customUrl', 453454 link: $('#custom_url_link').val(), 454455 title: $('#custom_url_title').val(), 455456 wpms_nonce: wpms_localize.wpms_nonce 456457 }, 457458 success: function (res) { 458459 if(res.status){ 459460 $('#wrap_sitemap_option_customUrl').append(res.html); 460461 wpms_clear_customUrl(); 461462 } 462463 $('.wpms_customurl_spinner').hide(); 463464 } 464465 }); 465466 }); 466467 467468 wpms_clear_customUrl(); 468469 }); 469470}(jQuery)); * TABULARUNIFIED WP-META-SEO/TRUNK/INC/CLASS.METASEO-ADMIN.PHP ¶ r2869205 r2870465 11<?php 22/* Prohibit direct script loading */ 33defined('ABSPATH') || die('No direct script access allowed!'); 44 55/** 66 * Class MetaSeoAdmin 77 * Class that holds most of the admin functionality for Meta SEO. 88 */ 99class MetaSeoAdmin 1010{ 1111 1212 /** 1313 * Current page 1414 * 1515 * @var mixed 1616 */ 1717 private $pagenow; 1818 /** 1919 * Max length meta description 2020 * 2121 * @var integer 2222 */ 2323 public static $desc_length = 158; 2424 /** 2525 * Max length meta title 2626 * 2727 * @var integer 2828 */ 2929 public static $title_length = 60; 3030 /** 3131 * Google client 3232 * 3333 * @var object 3434 */ 3535 public $client; 3636 /** 3737 * Default access to connect to google 3838 * 3939 * @var array 4040 */ 4141 public $access = array(WPMS_CLIENTID, WPMS_CLIENTSECRET); 4242 /** 4343 * Error timeout 4444 * 4545 * @var integer 4646 */ 4747 public $error_timeout; 4848 /** 4949 * List google analytics options 5050 * 5151 * @var array 5252 */ 5353 public $ga_tracking; 5454 /** 5555 * Option to check connect status 5656 * 5757 * @var array 5858 */ 5959 public $gaDisconnect; 6060 /** 6161 * Google alanytics options 6262 * 6363 * @var array 6464 */ 6565 public $google_alanytics; 6666 6767 /** 6868 * Google Tag Manager options setting 6969 * 7070 * @var Google tag manager options 7171 */ 7272 public $google_tagmanager; 7373 7474 /** 7575 * All settings for meta seo 7676 * 7777 * @var array 7878 */ 7979 public $settings; 8080 8181 /** 8282 * Google service 8383 * 8484 * @var object 8585 */ 8686 public $service; 8787 8888 /** 8989 * MetaSeoAdmin constructor. 9090 */ 9191 public function __construct() 9292 { 9393 $this->pagenow = $GLOBALS['pagenow']; 9494 $this->setErrorTimeout(); 9595 $this->initSettings(); 9696 $this->initGaSettings(); 9797 $this->initGADisconnect(); 9898 if (!get_option('_wpms_dash_last_update', false)) { 9999 update_option('_wpms_dash_last_update', time()); 100100 } 101101 102102 add_action('admin_init', array($this, 'adminRedirects')); 103103 add_action('init', array($this, 'install')); 104104 add_action('admin_init', array($this, 'adminInit')); 105105 add_action('init', array($this, 'loadLangguage')); 106106 add_action('admin_menu', array($this, 'addMenuPage')); 107107 /** 108108 * Load admin js 109109 */ 110110 add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts')); 111111 112112 if (!class_exists('MetaSeoContentListTable')) { 113113 require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-content-list-table.php'); 114114 } 115115 add_action('added_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4); 116116 add_action('updated_post_meta', array('MetaSeoContentListTable', 'updateMetaSync'), 99, 4); 117117 add_action('deleted_post_meta', array('MetaSeoContentListTable', 'deleteMetaSync'), 99, 4); 118118 119119 if (!get_option('wpms_set_ignore', false)) { 120120 add_option('wpms_set_ignore', 1, '', 'yes'); 121121 } 122122 123123 add_action('wp_ajax_wpms_set_ignore', array($this, 'setIgnore')); 124124 if (0 === (int)get_option('blog_public')) { 125125 add_action('admin_notices', array($this, 'publicWarning')); 126126 } 127127 add_action('wp_enqueue_editor', array($this, 'linkTitleField'), 20); 128128 129129 if (!class_exists('MetaSeoBrokenLinkTable')) { 130130 require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-broken-link-table.php'); 131131 } 132132 add_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost'), 10, 3); 133133 add_action('delete_post', array('MetaSeoBrokenLinkTable', 'deletePost')); 134134 add_action('edit_comment', array('MetaSeoBrokenLinkTable', 'updateComment')); 135135 add_action('deleted_comment', array('MetaSeoBrokenLinkTable', 'deletedComment')); 136136 add_action('admin_head', array('MetaSeoContentListTable', 'customStyles')); 137137 138138 add_action('admin_footer', array($this, 'editorFooter')); 139139 add_action('wp_dashboard_setup', array($this, 'addDashboardWidgets')); 140140 add_action('category_add_form_fields', array($this, 'categoryField'), 10, 2); 141141 add_action('category_edit_form_fields', array($this, 'editCategoryFields')); 142142 add_action('edited_category', array($this, 'saveCategoryMeta'), 10, 2); 143143 add_action('create_category', array($this, 'saveCategoryMeta'), 10, 2); 144144 145145 if (!class_exists('MetaSeoImageListTable')) { 146146 require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-image-list-table.php'); 147147 } 148148 add_action('post_updated', array('MetaSeoImageListTable', 'updatePost'), 10, 3); 149149 add_action('delete_post', array('MetaSeoImageListTable', 'deletePost')); 150150 151151 // Category meta hook 152152 add_action('admin_head', array('WPMSCategoryMetaTable', 'customStyles')); 153153 154154 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 155155 add_action('product_cat_add_form_fields', array($this, 'categoryField')); 156156 add_action('product_cat_edit_form_fields', array($this, 'editCategoryFields'), 10); 157157 add_action('created_term', array($this, 'saveCategoryMeta'), 10, 3); 158158 add_action('edit_term', array($this, 'saveCategoryMeta'), 10, 3); 159159 } 160160 add_action('wp_ajax_wpms', array($this, 'startProcess')); 161161 add_action('wp_ajax_wpms_gg_save_information', array($this, 'wpmsGGSaveInformation')); 162162 add_filter('wpms_the_content', array($this, 'wpmsTheContent'), 10, 2); 163163 164164 $settings = get_option('_metaseo_settings'); 165165 if (isset($settings['metaseo_removecatprefix']) && $settings['metaseo_removecatprefix'] === '1') { 166166 add_action('created_category', array($this, 'wpmsScheduleRewriteFlush')); 167167 add_action('edited_category', array($this, 'wpmsScheduleRewriteFlush')); 168168 add_action('delete_category', array($this, 'wpmsScheduleRewriteFlush')); 169169 } 170170 } 171171 172172 /** 173173 * Init Meta seo settings 174174 * 175175 * @return void 176176 */ 177177 public function initSettings() 178178 { 179179 $this->settings = wpmsGetDefaultSettings(); 180180 $settings = get_option('_metaseo_settings'); 181181 182182 if (is_array($settings)) { 183183 $this->settings = array_merge($this->settings, $settings); 184184 } 185185 186186 if ((isset($this->settings['metaseo_showtmetablock']) && (int)$this->settings['metaseo_showtmetablock'] === 1)) { 187187 $this->loadMetaBoxes(); 188188 } 189189 } 190190 191191 /** 192192 * Init google analytics tracking options 193193 * 194194 * @return void 195195 */ 196196 public function initGaSettings() 197197 { 198198 $this->ga_tracking = array( 199199 'wpmsga_dash_tracking' => 1, 200200 'wpmsga_dash_tracking_type' => 'universal', 201201 'wpmsga_dash_anonim' => 0, 202202 'wpmsga_dash_remarketing' => 0, 203203 'wpmsga_event_tracking' => 0, 204204 'wpmsga_event_downloads' => 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*', 205205 'wpmsga_aff_tracking' => 0, 206206 'wpmsga_event_affiliates' => '/out/', 207207 'wpmsga_hash_tracking' => 0, 208208 'wpmsga_author_dimindex' => 0, 209209 'wpmsga_pubyear_dimindex' => 0, 210210 'wpmsga_category_dimindex' => 0, 211211 'wpmsga_user_dimindex' => 0, 212212 'wpmsga_tag_dimindex' => 0, 213213 'wpmsga_speed_samplerate' => 1, 214214 'wpmsga_event_bouncerate' => 0, 215215 'wpmsga_enhanced_links' => 0, 216216 'wpmsga_dash_adsense' => 0, 217217 'wpmsga_crossdomain_tracking' => 0, 218218 'wpmsga_crossdomain_list' => '', 219219 'wpmsga_cookiedomain' => '', 220220 'wpmsga_cookiename' => '', 221221 'wpmsga_cookieexpires' => '', 222222 'wpmsga_track_exclude' => array(), 223223 'wpmsga_code_tracking' => '' 224224 ); 225225 } 226226 227227 /** 228228 * Init GTM setting 229229 * 230230 * @return void 231231 */ 232232 public function initGADisconnect() 233233 { 234234 $this->gaDisconnect = array( 235235 'wpms_gg_service_tracking_id' => '', 236236 'wpms_gg_service_tracking_type' => 'universal', 237237 'wpmsga_code_tracking' => '', 238238 'wpmstm_header_code_tracking' => '', 239239 'wpmstm_body_code_tracking' => '' 240240 ); 241241 } 242242 243243 /** 244244 * Ajax request google tag manager containers list 245245 * 246246 * @return mixed 247247 */ 248248 public function tagmanagerContainersReport() 249249 { 250250 if (empty($_POST['wpms_nonce']) 251251 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 252252 die(); 253253 } 254254 $accont_id = $_POST['accountID']; 255255 if (isset($accont_id) && $accont_id) { 256256 $accont_id = sanitize_text_field($accont_id); 257257 require_once(WPMETASEO_PLUGIN_DIR . 'inc/google-tag-manager/wpms-tagmanager-api.php'); 258258 $wpmstm = new WpmsTagManagerController(); 259259 $list_containers = $wpmstm->getListContainers($accont_id); 260260 $this->google_tagmanager = get_option('wpms_tagmanager_setting'); 261261 $listsContainer = $list_containers->getContainer(); 262262 $lists = array(); 263263 foreach ($listsContainer as $container) { 264264 $lists[] = array( 265265 'containerId' => $container->getContainerId(), 266266 'name' => $container->getName(), 267267 'path' => $container->getPath(), 268268 'publicId' => $container->getPublicId(), 269269 'usageContext' => $container->getUsageContext(), 270270 'notes' => $container->getNotes(), 271271 ); 272272 } 273273 $this->google_tagmanager['list_containers'] = $lists; 274274 update_option('wpms_tagmanager_setting', $this->google_tagmanager); 275275 return wp_send_json($list_containers->getContainer()); 276276 } 277277 } 278278 279279 /** 280280 * Ajax return tag manager container information 281281 * 282282 * @return mixed 283283 */ 284284 public function tagmanagerContainerInfo() 285285 { 286286 if (empty($_POST['wpms_nonce']) 287287 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 288288 die(); 289289 } 290290 $container_id = $_POST['containerID']; 291291 if (isset($container_id) && $container_id) { 292292 $container_id = sanitize_text_field($container_id); 293293 $gg_tagmanager = get_option('wpms_tagmanager_setting'); 294294 $gg_tagmanager_containers = $gg_tagmanager['list_containers']; 295295 $containerIndex = 0; 296296 foreach ($gg_tagmanager_containers as $container) { 297297 if ($container['containerId'] === $container_id) { 298298 break; 299299 } 300300 $containerIndex++; 301301 } 302302 303303 return wp_send_json($gg_tagmanager_containers[$containerIndex]); 304304 } 305305 } 306306 307307 /** 308308 * Ajax refresh tag manager connect 309309 * 310310 * @return mixed 311311 */ 312312 public function tagmanagerRefreshConnect() 313313 { 314314 // Update list accounts tag managers 315315 require_once(WPMETASEO_PLUGIN_DIR . 'inc/google-tag-manager/wpms-tagmanager-api.php'); 316316 $wpmstm_controller = new WpmsTagManagerController(); 317317 $wpmstm_listAccounts = $wpmstm_controller->getListAccounts(); 318318 $wpmstm_accounts = $wpmstm_listAccounts->getAccount(); 319319 if (isset($wpmstm_accounts[0])) { 320320 $lists_acc = array(); 321321 foreach ($wpmstm_accounts as $account) { 322322 $lists_acc[] = array( 323323 'accountId' => $account->getAccountId(), 324324 'name' => $account->getName(), 325325 'path' => $account->getPath(), 326326 ); 327327 } 328328 $this->google_tagmanager['list_accounts'] = $lists_acc; 329329 update_option('wpms_tagmanager_setting', $this->google_tagmanager); 330330 return wp_send_json($this->google_tagmanager['list_accounts']); 331331 } else { 332332 return false; 333333 } 334334 } 335335 336336 /** 337337 * Admin init 338338 * 339339 * @return void 340340 */ 341341 public function adminInit() 342342 { 343343 $this->createDatabase(); 344344 $this->updateLinksTable(); 345345 346346 // Column Content. 347347 $this->registerPostColumns(); 348348 add_filter('metaseo_seokeywords_details_column', array($this, 'getColumnSeoKeywordsDetails'), 5); 349349 } 350350 351351 /** 352352 * Add category meta field 353353 * 354354 * @return void 355355 */ 356356 public function categoryField() 357357 { 358358 wp_enqueue_style('wpms-tippy-style'); 359359 wp_enqueue_script('wpms-tippy-core'); 360360 wp_enqueue_script('wpms-tippy'); 361361 wp_enqueue_script('wpms-my-tippy'); 362362 363363 wp_enqueue_style('wpms-category-field'); 364364 wp_enqueue_script('wpms-category-field'); 365365 // this will add the custom meta field to the add new term page 366366 ?> 367367 <div class="form-field"> 368368 <label class="wpms_custom_cat_field" 369369 data-tippy="<?php esc_attr_e('This is the title of your content that may be displayed in search engine 370370 results (meta title). By default it’s the content title (page title, post title…). 371371 69 characters max allowed.', 'wp-meta-seo') ?>"> 372372 <?php esc_html_e('Search engine title', 'wp-meta-seo'); ?> 373373 </label> 374374 <label> 375375 <textarea name="wpms_category_metatitle" class="wpms_category_metatitle"></textarea> 376376 <br/> 377377 </label> 378378 <div class="cat-title-len"><?php echo esc_html(MPMSCAT_TITLE_LENGTH); ?></div> 379379 </div> 380380 381381 <?php 382382 $settings = get_option('_metaseo_settings'); 383383 if (isset($settings['metaseo_showkeywords']) && (int)$settings['metaseo_showkeywords'] === 1) : 384384 ?> 385385 <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;"> 386386 <label class="wpms_custom_cat_field" 387387 data-tippy="<?php esc_attr_e('This is the keywords of your content that may be 388388 displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>"> 389389 <?php esc_html_e('Search engine keywords', 'wp-meta-seo'); ?> 390390 </label> 391391 <label> 392392 <textarea name="wpms_category_metakeywords" class="wpms_cat_keywords"></textarea><br/> 393393 </label> 394394 <div class="cat-keywords-len"><?php echo esc_html(MPMSCAT_KEYWORDS_LENGTH); ?></div> 395395 </div> 396396 <?php endif; ?> 397397 <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;"> 398398 <label for="extra1" class="wpms_custom_cat_field" 399399 data-tippy="<?php esc_attr_e('This is the title of your content that may be displayed in search 400400 engine results (meta title). By default it’s the content title (page title, post title…). 401401 69 characters max allowed.', 'wp-meta-seo') ?>"> 402402 <?php esc_html_e('Search engine description', 'wp-meta-seo'); ?> 403403 </label> 404404 <label> 405405 <textarea name="wpms_category_metadesc" class="wpms_category_metadesc"></textarea><br/> 406406 <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>"> 407407 </label> 408408 <div class="cat-desc-len"><?php echo esc_html(MPMSCAT_DESC_LENGTH); ?></div> 409409 </div> 410410 <?php 411411 if (isset($settings['metaseo_canonical']) && (int)$settings['metaseo_canonical'] === 1) : ?> 412412 <div class="form-field" style="margin-top: 20px;margin-bottom: 20px;"> 413413 <label class="wpms_custom_cat_field" 414414 data-tippy="<?php esc_attr_e('Put the canonical URL which this page should point to. By default, it\'s the permalink', 'wp-meta-seo') ?>"> 415415 <?php esc_html_e('Canonical URL', 'wp-meta-seo'); ?> 416416 </label> 417417 <label> 418418 <textarea name="wpms_category_canonical" class="wpms_category_canonical"></textarea><br/> 419419 </label> 420420 </div> 421421 <?php endif; 422422 } 423423 424424 /** 425425 * Save category meta 426426 * 427427 * @param integer $term_id Current category id 428428 * 429429 * @return void 430430 */ 431431 public function saveCategoryMeta($term_id) 432432 { 433433 global $pagenow; 434434 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce used in next lines 435435 if ($pagenow === 'edit-tags.php' || (isset($_POST['action'], $_POST['screen']) && $_POST['action'] === 'add-tag' && ($_POST['screen'] === 'edit-category' || $_POST['screen'] === 'edit-product_cat'))) { 436436 if (isset($_POST['taxonomy']) && ($_POST['taxonomy'] === 'product_cat' || $_POST['taxonomy'] === 'category')) { 437437 if (empty($_POST['wpms_nonce']) 438438 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 439439 die(); 440440 } 441441 442442 if (isset($_POST['wpms_category_metatitle'])) { 443443 update_term_meta($term_id, 'wpms_category_metatitle', $_POST['wpms_category_metatitle']); 444444 } 445445 446446 if (isset($_POST['wpms_category_metadesc'])) { 447447 update_term_meta($term_id, 'wpms_category_metadesc', $_POST['wpms_category_metadesc']); 448448 } 449449 450450 $settings = get_option('_metaseo_settings'); 451451 if (isset($settings['metaseo_showkeywords']) && (int)$settings['metaseo_showkeywords'] === 1) { 452452 if (isset($_POST['wpms_category_metakeywords'])) { 453453 update_term_meta($term_id, 'wpms_category_metakeywords', $_POST['wpms_category_metakeywords']); 454454 } 455455 } 456456 457457 if (isset($settings['metaseo_canonical']) && (int)$settings['metaseo_canonical'] === 1) { 458458 if (isset($_POST['wpms_category_canonical'])) { 459459 // Set link to field 460460 $canonical = self::convertCanonicalUrlToSave($_POST['wpms_category_canonical']); 461461 462462 update_term_meta($term_id, 'wpms_category_canonical', $canonical); 463463 } 464464 } 465465 } 466466 } 467467 //phpcs:enable 468468 } 469469 470470 /** 471471 * Add extra fields to category edit form callback function 472472 * 473473 * @param object $tag Current category 474474 * 475475 * @return void 476476 */ 477477 public function editCategoryFields($tag) 478478 { 479479 wp_enqueue_style('wpms-tippy-style'); 480480 wp_enqueue_script('wpms-tippy-core'); 481481 wp_enqueue_script('wpms-tippy'); 482482 wp_enqueue_script('wpms-my-tippy'); 483483 484484 wp_enqueue_style('wpms-category-field'); 485485 wp_enqueue_script('wpms-category-field'); 486486 $t_id = $tag->term_id; 487487 $metatitle = get_term_meta($t_id, 'wpms_category_metatitle', true); 488488 $metadesc = get_term_meta($t_id, 'wpms_category_metadesc', true); 489489 $metakeywords = get_term_meta($t_id, 'wpms_category_metakeywords', true); 490490 $metacanonical = get_term_meta($t_id, 'wpms_category_canonical', true); 491491 $metacanonical = self::convertCanonicalUrlToDisplay($metacanonical); 492492 ?> 493493 <tr class="form-field"> 494494 <th scope="row" valign="top"> 495495 <label class="wpms_custom_cat_field" data-tippy="<?php esc_attr_e('This is the title of your content that may 496496 be displayed in search engine results (meta title). By default it’s the content title 497497 (page title, post title…).69 characters max allowed.', 'wp-meta-seo') ?>"> 498498 <?php esc_html_e('Search engine title', 'wp-meta-seo'); ?> 499499 </label> 500500 </th> 501501 <td> 502502 <label> 503503 <?php if ((!empty($metatitle))) : ?> 504504 <textarea name="wpms_category_metatitle" 505505 class="wpms_category_metatitle"><?php echo esc_textarea($metatitle); ?></textarea> 506506 <?php else : ?> 507507 <textarea name="wpms_category_metatitle" 508508 class="wpms_category_metatitle"></textarea> 509509 <?php endif; ?> 510510 <br/> 511511 </label> 512512 <div class="cat-title-len"> 513513 <?php 514514 echo esc_html($metatitle ? MPMSCAT_TITLE_LENGTH - strlen($metatitle) : MPMSCAT_TITLE_LENGTH); 515515 ?> 516516 </div> 517517 </td> 518518 </tr> 519519 520520 <?php 521521 $settings = get_option('_metaseo_settings'); 522522 if (isset($settings['metaseo_showkeywords']) && (int)$settings['metaseo_showkeywords'] === 1) : 523523 ?> 524524 <tr class="form-field"> 525525 <th scope="row" valign="top"> 526526 <label for="extra1" class="wpms_custom_cat_field" 527527 data-tippy="<?php esc_attr_e('This is the keywords of your content that may be 528528 displayed in search engine results (meta keywords).', 'wp-meta-seo') ?>"> 529529 <?php esc_html_e('Search engine keywords', 'wp-meta-seo'); ?> 530530 </label> 531531 </th> 532532 <td> 533533 <label> 534534 <?php if ((!empty($metakeywords))) : ?> 535535 <textarea name="wpms_category_metakeywords" 536536 class="wpms_cat_keywords"><?php echo esc_textarea($metakeywords); ?></textarea> 537537 <?php else : ?> 538538 <textarea name="wpms_category_metakeywords" 539539 class="wpms_cat_keywords"></textarea> 540540 <?php endif; ?> 541541 <br/> 542542 </label> 543543 544544 <div class="cat-keywords-len"> 545545 <?php 546546 echo esc_html($metakeywords ? MPMSCAT_KEYWORDS_LENGTH - strlen($metakeywords) : MPMSCAT_KEYWORDS_LENGTH); 547547 ?> 548548 </div> 549549 </td> 550550 </tr> 551551 <?php endif; ?> 552552 <tr class="form-field"> 553553 <th scope="row" valign="top"> 554554 <label for="extra1" class="wpms_custom_cat_field" 555555 data-tippy="<?php esc_attr_e('This is the title of your content that may be displayed in 556556 search engine results (meta title). By default it’s the content title (page title, post title…). 557557 69 characters max allowed.', 'wp-meta-seo') ?>"> 558558 <?php esc_html_e('Search engine description', 'wp-meta-seo'); ?> 559559 </label> 560560 </th> 561561 <td> 562562 <label> 563563 <?php if ((!empty($metadesc))) : ?> 564564 <textarea name="wpms_category_metadesc" 565565 class="wpms_category_metadesc"><?php echo esc_textarea($metadesc); ?></textarea> 566566 <?php else : ?> 567567 <textarea name="wpms_category_metadesc" 568568 class="wpms_category_metadesc"></textarea> 569569 <?php endif; ?> 570570 <br/> 571571 </label> 572572 <input type="hidden" name="wpms_nonce" value="<?php echo esc_attr(wp_create_nonce('wpms_nonce')) ?>"> 573573 <div class="cat-desc-len"> 574574 <?php echo esc_html($metadesc ? MPMSCAT_DESC_LENGTH - strlen($metadesc) : MPMSCAT_DESC_LENGTH); ?> 575575 </div> 576576 </td> 577577 </tr> 578578 <?php 579579 if (isset($settings['metaseo_canonical']) && (int)$settings['metaseo_canonical'] === 1) : ?> 580580 <tr class="form-field"> 581581 <th scope="row" valign="top"> 582582 <label for="extra1" class="wpms_custom_cat_field" 583583 data-tippy="<?php esc_attr_e('Put the canonical URL which this page should point to. By default, it\'s the permalink', 'wp-meta-seo') ?>"> 584584 <?php esc_html_e('Canonical URL', 'wp-meta-seo'); ?> 585585 </label> 586586 </th> 587587 <td> 588588 <label> 589589 <?php if ((!empty($metacanonical))) : ?> 590590 <textarea name="wpms_category_canonical" 591591 class="wpms_category_canonical"><?php echo esc_textarea($metacanonical); ?></textarea> 592592 <?php else : ?> 593593 <textarea name="wpms_category_canonical" 594594 class="wpms_category_canonical"></textarea> 595595 <?php endif; ?> 596596 <br/> 597597 </label> 598598 </td> 599599 </tr> 600600 <?php endif; 601601 } 602602 603603 /** 604604 * Function that outputs the contents of the dashboard widget 605605 * 606606 * @return void 607607 */ 608608 public function dashboardWidget() 609609 { 610610 wp_enqueue_style('wpms-tippy-style'); 611611 wp_enqueue_style('wpms-mytippy-style'); 612612 wp_enqueue_script('wpms-tippy-core'); 613613 wp_enqueue_script('wpms-tippy'); 614614 wp_enqueue_script('wpms-my-tippy'); 615615 wp_enqueue_style('wpms-dashboard-widgets'); 616616 wp_enqueue_script( 617617 'wpms-dashboard-widgets', 618618 plugins_url('assets/js/dashboard_widgets/dashboard_widgets.js', dirname(__FILE__)), 619619 array('jquery'), 620620 WPMSEO_VERSION 621621 ); 622622 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard-widgets/dashboard_widgets.php'); 623623 } 624624 625625 /** 626626 * Generate dasboard Analytics widget 627627 * 628628 * @return void 629629 */ 630630 public function dashboardAnalyticsWidget() 631631 { 632632 // Jsapi 633633 $lang = get_bloginfo('language'); 634634 $lang = explode('-', $lang); 635635 $lang = $lang[0]; 636636 wp_enqueue_script( 637637 'wpmsgooglejsapi', 638638 '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%22imagechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D', 639639 array(), 640640 null 641641 ); 642642 // WPMS style 643643 wp_enqueue_style( 644644 'wpms-dashboard-analytics-widgets', 645645 plugins_url('assets/css/dashboard-widgets/analytics-widgets.css', dirname(__FILE__)), 646646 array(), 647647 WPMSEO_VERSION 648648 ); 649649 // WPMS script 650650 wp_enqueue_script( 651651 'wpms-dashboard-analytics-widgets', 652652 plugins_url('assets/js/dashboard_widgets/analytics-widgets.js', dirname(__FILE__)), 653653 array('jquery'), 654654 WPMSEO_VERSION, 655655 true 656656 ); 657657 658658 wp_localize_script('wpms-dashboard-analytics-widgets', 'wpmsDashboardAnalytics', $this->localizeDashoardWidgets()); 659659 660660 $requestDates = array( 661661 array('value' => 'today', 'html' => 'TODAY'), 662662 array('value' => 'yesterday', 'html' => 'YESTERDAY'), 663663 array('value' => '7daysAgo', 'html' => 'LAST 7 DAYS'), 664664 array('value' => '14daysAgo', 'html' => 'LAST 14 DAYS'), 665665 array('value' => '30daysAgo', 'html' => 'LAST 30 DAYS'), 666666 array('value' => '90daysAgo', 'html' => 'LAST 90 DAYS'), 667667 array('value' => '365daysAgo', 'html' => 'ONE YEAR'), 668668 array('value' => '1095daysAgo', 'html' => 'THREE YEARS'), 669669 ); 670670 $requestQuery = array( 671671 array('value' => 'sessions', 'html' => 'SESSIONS'), 672672 array('value' => 'users', 'html' => 'USERS'), 673673 array('value' => 'pageviews', 'html' => 'PAGE VIEWS'), 674674 array('value' => 'visitBounceRate', 'html' => 'ENGAGEMENT'), 675675 array('value' => 'organicSearches', 'html' => 'TRANSACTIONS'), 676676 array('value' => 'contentpages', 'html' => 'PAGES'), 677677 array('value' => 'locations', 'html' => 'LOCATION'), 678678 array('value' => 'referrers', 'html' => 'REFERRERS'), 679679 array('value' => 'searches', 'html' => 'SEARCHES'), 680680 array('value' => 'channelGrouping', 'html' => 'TRAFFIC'), 681681 array('value' => 'deviceCategory', 'html' => 'TECHNOLOGY') 682682 ); 683683 $google_analytics = get_option('wpms_google_alanytics'); 684684 if (!empty($google_analytics['tableid_jail'])) { 685685 require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php'; 686686 $profile = WpmsGaTools::getSelectedProfile($google_analytics['profile_list'], $google_analytics['tableid_jail']); 687687 if (!empty($profile[4]) && $profile[4] === 'UA') { 688688 $requestQuery[3] = array('value' => 'visitBounceRate', 'html' => 'BOUNCE RATE'); 689689 $requestQuery[4] = array('value' => 'organicSearches', 'html' => 'ORGANIC'); 690690 } 691691 } 692692 693693 $selectedDate = 'today'; 694694 $selectedQuery = 'sessions'; 695695 if (!empty($google_analytics['dashboard_analytics_widgets'])) { 696696 $selectedDate = $google_analytics['dashboard_analytics_widgets']['requestDate']; 697697 $selectedQuery = $google_analytics['dashboard_analytics_widgets']['requestQuery']; 698698 } 699699 700700 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard-widgets/analytics_widgets.php'); 701701 } 702702 703703 /** 704704 * Function used in the action hook 705705 * 706706 * @return void 707707 */ 708708 public function addDashboardWidgets() 709709 { 710710 wp_add_dashboard_widget( 711711 'wpms_dashboard_widget', 712712 esc_html__('WP Meta SEO: Quick SEO preview', 'wp-meta-seo'), 713713 array( 714714 $this, 715715 'dashboardWidget' 716716 ) 717717 ); 718718 719719 // Add Google Analytics Overview dashboard widget 720720 wp_add_dashboard_widget( 721721 'wpms_dashboard_analytics_widget', 722722 esc_html__('Google Analytics Overview', 'wp-meta-seo'), 723723 array( 724724 $this, 725725 'dashboardAnalyticsWidget' 726726 ) 727727 ); 728728 } 729729 730730 /** 731731 * Localize dashboard widget 732732 * 733733 * @return array 734734 */ 735735 public function localizeDashoardWidgets() 736736 { 737737 return array( 738738 'ajaxUrl' => admin_url('admin-ajax.php'), 739739 'wpms_nonce' => wp_create_nonce('wpms_nonce'), 740740 'wpms_security' => wp_create_nonce('dashboard_analytics_widgets_security'), 741741 'colorVariations' => array( 742742 esc_attr('#1e73be'), 743743 esc_attr('#0459a4'), 744744 esc_attr('#378cd7'), 745745 esc_attr('#51a6f1'), 746746 esc_attr('#00408b'), 747747 esc_attr('#6abfff'), 748748 esc_attr('#002671') 749749 ), 750750 'region' => false, 751751 'language' => get_bloginfo('language'), 752752 'viewList' => false 753753 ); 754754 } 755755 756756 /** 757757 * Create link dialog 758758 * 759759 * @return void 760760 */ 761761 public function editorFooter() 762762 { 763763 if (!class_exists('_WP_Editors', false)) { 764764 require_once ABSPATH . 'wp-includes/class-wp-editor.php'; 765765 _WP_Editors::wp_link_dialog(); 766766 } 767767 } 768768 769769 /** 770770 * Create or update 404 page 771771 * 772772 * @param string $title Old page title 773773 * @param string $newtitle New page title 774774 * 775775 * @return void 776776 */ 777777 public function create404Page($title, $newtitle) 778778 { 779779 global $wpdb; 780780 $post_if = $wpdb->get_results($wpdb->prepare( 781781 'SELECT * FROM ' . $wpdb->prefix . 'posts 782782 WHERE post_title = %s AND post_excerpt = %s AND post_type = %s', 783783 array($title, 'metaseo_404_page', 'page') 784784 )); 785785 786786 if (empty($post_if)) { 787787 $content = '<div class="wall" 788788 style="background-color: #F2F3F7; border: 30px solid #fff; width: 90%; height: 90%; margin: 0 auto;"> 789789 790790 <h1 style="text-align: center; font-family:\'open-sans\', arial; 791791 color: #444; font-size: 60px; padding: 50px;">ERROR 404 <br />-<br />NOT FOUND</h1> 792792 <p style="text-align: center; font-family:\'open-sans\', arial; color: #444; 793793 font-size: 40px; padding: 20px; line-height: 55px;"> 794794 // You may have mis-typed the URL,<br /> 795795 // Or the page has been removed,<br /> 796796 // Actually, there is nothing to see here...</p> 797797 <p style="text-align: center;"><a style=" font-family:\'open-sans\', arial; color: #444; 798798 font-size: 20px; padding: 20px; line-height: 30px; text-decoration: none;" 799799 href="' . get_home_url() . '"><< Go back to home page >></a></p> 800800 </div>'; 801801 $_page404 = array( 802802 'post_title' => $newtitle, 803803 'post_content' => $content, 804804 'post_status' => 'publish', 805805 'post_excerpt' => 'metaseo_404_page', 806806 'post_type' => 'page' 807807 ); 808808 wp_insert_post($_page404); 809809 } else { 810810 $my_post = array( 811811 'ID' => $post_if[0]->ID, 812812 'post_title' => $newtitle 813813 ); 814814 815815 wp_update_post($my_post); 816816 } 817817 } 818818 819819 /** 820820 * Update links table 821821 * 822822 * @return void 823823 */ 824824 public function updateLinksTable() 825825 { 826826 global $wpdb; 827827 $option_v = 'metaseo_db_version3.7.2'; 828828 $db_installed = get_option($option_v, false); 829829 if (!$db_installed) { 830830 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links MODIFY `link_url` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'); 831831 update_option($option_v, true); 832832 } 833833 834834 // Add index for wpms links 835835 $option_v = 'metaseo_db_version4.0.4'; 836836 $db_installed = get_option($option_v, false); 837837 if (!$db_installed) { 838838 // Add index for wpms_links table; 839839 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD INDEX linkurl(link_url(256))'); 840840 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD INDEX typeurl(type(50))'); 841841 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD INDEX sourceid(source_id)'); 842842 843843 // Add index for metaseo_images table; 844844 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'metaseo_images ADD INDEX postid(post_id)'); 845845 // Update option metaseo_db 846846 update_option($option_v, true); 847847 } 848848 } 849849 850850 /** 851851 * Create wpms_links table 852852 * 853853 * @return void 854854 */ 855855 public function createDatabase() 856856 { 857857 global $wpdb; 858858 $option_v = 'metaseo_db_version3.3.0'; 859859 $db_installed = get_option($option_v, false); 860860 if (!$db_installed) { 861861 // create table wpms_links 862862 $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'wpms_links( 863863 `id` int(20) unsigned NOT NULL AUTO_INCREMENT, 864864 `link_url` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL, 865865 `link_final_url` text CHARACTER SET latin1 COLLATE latin1_general_cs, 866866 `link_url_redirect` text CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL, 867867 `link_text` text NOT NULL DEFAULT "", 868868 `source_id` int(20) DEFAULT "0", 869869 `type` varchar(100) DEFAULT "", 870870 `status_code` varchar(100) DEFAULT "", 871871 `status_text` varchar(250) DEFAULT "", 872872 `hit` int(20) NOT NULL DEFAULT "1", 873873 `redirect` tinyint(1) NOT NULL DEFAULT "0", 874874 `broken_indexed` tinyint(1) unsigned NOT NULL DEFAULT "0", 875875 `broken_internal` tinyint(1) unsigned NOT NULL DEFAULT "0", 876876 `warning` tinyint(1) unsigned NOT NULL DEFAULT "0", 877877 `dismissed` tinyint(1) NOT NULL DEFAULT "0", 878878 PRIMARY KEY (id))'; 879879 880880 881881 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 882882 dbDelta($sql); 883883 884884 $row = $wpdb->get_results($wpdb->prepare( 885885 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 886886 WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s', 887887 array($wpdb->prefix . 'wpms_links', 'follow', $wpdb->dbname) 888888 )); 889889 890890 if (empty($row)) { 891891 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD follow tinyint(1) DEFAULT 1'); 892892 } 893893 894894 $row = $wpdb->get_results($wpdb->prepare( 895895 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 896896 WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s', 897897 array($wpdb->prefix . 'wpms_links', 'meta_title', $wpdb->dbname) 898898 )); 899899 900900 if (empty($row)) { 901901 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD meta_title varchar(250) DEFAULT ""'); 902902 } 903903 904904 $row = $wpdb->get_results($wpdb->prepare( 905905 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 906906 WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s', 907907 array($wpdb->prefix . 'wpms_links', 'internal', $wpdb->dbname) 908908 )); 909909 910910 if (empty($row)) { 911911 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD internal tinyint(1) DEFAULT 1'); 912912 } 913913 914914 // create page 404 915915 $this->create404Page('WP Meta SEO 404 Page', '404 error page'); 916916 // create sitemap page 917917 $post_if = $wpdb->get_var( 918918 $wpdb->prepare('SELECT COUNT(*) FROM ' . $wpdb->prefix . 'posts 919919 WHERE post_title = %s AND post_excerpt = %s AND post_type = %s', array( 920920 'WPMS HTML Sitemap', 921921 'metaseo_html_sitemap', 922922 'page' 923923 )) 924924 ); 925925 if ($post_if < 1) { 926926 $_sitemap_page = array( 927927 'post_title' => 'WPMS HTML Sitemap', 928928 'post_content' => '', 929929 'post_status' => 'publish', 930930 'post_excerpt' => 'metaseo_html_sitemap', 931931 'post_type' => 'page', 932932 ); 933933 wp_insert_post($_sitemap_page); 934934 } 935935 936936 update_option($option_v, true); 937937 } 938938 939939 940940 $option_v = 'metaseo_db_version3.7.3'; 941941 $db_installed = get_option($option_v, false); 942942 if (!$db_installed) { 943943 // create page 404 944944 $this->create404Page('404 error page', '404 Error, content does not exist anymore'); 945945 update_option($option_v, true); 946946 } 947947 948948 $option_v = 'metaseo_db_version4.0.0'; 949949 $db_installed = get_option($option_v, false); 950950 if (!$db_installed) { 951951 $row = $wpdb->get_results($wpdb->prepare( 952952 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 953953 WHERE table_name = %s AND column_name = %s AND TABLE_SCHEMA = %s', 954954 array($wpdb->prefix . 'wpms_links', 'referrer', $wpdb->dbname) 955955 )); 956956 957957 if (empty($row)) { 958958 $wpdb->query('ALTER TABLE ' . $wpdb->prefix . 'wpms_links ADD referrer text DEFAULT ""'); 959959 } 960960 update_option($option_v, true); 961961 } 962962 963963 $option_v = 'metaseo_db_version4.0.4'; 964964 $db_installed = get_option($option_v, false); 965965 $wpms_db_version = get_option('metaseo_db_version', false); 966966 // update plugin v4.3.5 967967 if ($db_installed && !$wpms_db_version) { 968968 // Get old settings 969969 $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings'); 970970 971971 // Update value to new ga parameters 972972 if ($gaDisconnect) { 973973 $this->gaDisconnect['wpms_gg_service_tracking_id'] = $gaDisconnect['wpms_ga_uax_reference']; 974974 $this->gaDisconnect['wpms_gg_service_tracking_type'] = $gaDisconnect['wpmsga_dash_tracking_type']; 975975 $this->gaDisconnect['wpmsga_code_tracking'] = $gaDisconnect['wpmsga_code_tracking']; 976976 $this->gaDisconnect['wpmstm_header_code_tracking'] = ''; 977977 $this->gaDisconnect['wpmstm_body_code_tracking'] = ''; 978978 update_option('_metaseo_ggtracking_disconnect_settings', $this->gaDisconnect); 979979 } 980980 update_option('metaseo_db_version', WPMSEO_VERSION); 981981 } 982982 } 983983 984984 /** 985985 * Add field title in dialog link when edit a link 986986 * 987987 * @return void 988988 */ 989989 public function linkTitleField() 990990 { 991991 if (isset($this->settings['metaseo_linkfield']) && (int)$this->settings['metaseo_linkfield'] === 1) { 992992 wp_enqueue_script( 993993 'wpmslinkTitle', 994994 plugins_url('assets/js/wpms-link-title-field.js', dirname(__FILE__)), 995995 array('wplink'), 996996 WPMSEO_VERSION, 997997 true 998998 ); 999999 wp_localize_script('wpmslinkTitle', 'wpmsLinkTitleL10n', array( 10001000 'titleLabel' => esc_html__('Title', 'wp-meta-seo'), 10011001 )); 10021002 } 10031003 } 10041004 10051005 /** 10061006 * Update option wpms_set_ignore 10071007 * 10081008 * @return void 10091009 */ 10101010 public function setIgnore() 10111011 { 1012 if (empty($_POST['wpms_nonce']) 1013 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 1014 die(); 1015 } 10121016 if (!current_user_can('manage_options')) { 10131017 wp_send_json(false); 10141018 } 10151019 update_option('wpms_set_ignore', 0); 10161020 wp_send_json(true); 10171021 } 10181022 10191023 /** 10201024 * Render message error when disable search engines from indexing this site 10211025 * 10221026 * @return void 10231027 */ 10241028 public function publicWarning() 10251029 { 10261030 if ((function_exists('is_network_admin') && is_network_admin())) { 10271031 return; 10281032 } 10291033 10301034 if ((int)get_option('wpms_set_ignore') === 0) { 10311035 return; 10321036 } 10331037 10341038 printf( 10351039 '<div id="robotsmessage" class="error"> 10361040 <p> 10371041 <strong>%1$s</strong> 10381042 %2$s 10391043 <a href="javascript:wpmsIgnore(\'wpms_public_warning\',\'robotsmessage\',\'%3$s\');" 10401044 class="button">%4$s</a> 10411045 </p> 10421046 </div>', 10431047 esc_html__('Your website is not indexed by search engine because of your WordPress settings.', 'wp-meta-seo'), 10441048 sprintf( 10451049 esc_html__('%1$sFix it now%2$s', 'wp-meta-seo'), 10461050 sprintf('<a href="%s">', esc_url(admin_url('options-reading.php'))), 10471051 '</a>' 10481052 ), 10491053 esc_js(wp_create_nonce('wpseo-ignore')), 10501054 esc_html__('OK I know that.', 'wp-meta-seo') 10511055 ); 10521056 } 10531057 10541058 /** 10551059 * Loads translated strings. 10561060 * 10571061 * @return void 10581062 */ 10591063 public function loadLangguage() 10601064 { 10611065 load_plugin_textdomain( 10621066 'wp-meta-seo', 10631067 false, 10641068 dirname(plugin_basename(__FILE__)) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR 10651069 ); 10661070 } 10671071 10681072 /** 10691073 * Handle redirects to setup/welcome page after install and updates. 10701074 * 10711075 * For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. 10721076 * 10731077 * @return void 10741078 */ 10751079 public function adminRedirects() 10761080 { 10771081 // Disable all admin notice for page belong to plugin 10781082 add_action('admin_print_scripts', function () { 10791083 global $wp_filter; 10801084 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action, nonce is not required 10811085 if ((!empty($_GET['page']) && in_array($_GET['page'], array('wpms-setup', 'metaseo_settings', 'metaseo_console')))) { 10821086 if (is_user_admin()) { 10831087 if (isset($wp_filter['user_admin_notices'])) { 10841088 unset($wp_filter['user_admin_notices']); 10851089 } 10861090 } elseif (isset($wp_filter['admin_notices'])) { 10871091 unset($wp_filter['admin_notices']); 10881092 } 10891093 if (isset($wp_filter['all_admin_notices'])) { 10901094 unset($wp_filter['all_admin_notices']); 10911095 } 10921096 } 10931097 }); 10941098 10951099 // Setup wizard redirect 10961100 if (is_null(get_option('_wpmf_activation_redirect', null)) && is_null(get_option('wpms_version', null))) { 10971101 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- View request, no action 10981102 if ((!empty($_GET['page']) && in_array($_GET['page'], array('wpms-setup')))) { 10991103 return; 11001104 } 11011105 update_option('wpms_version', WPMSEO_VERSION); 11021106 wp_safe_redirect(admin_url('index.php?page=wpms-setup')); 11031107 exit; 11041108 } 11051109 } 11061110 11071111 /** 11081112 * Includes WP Media Folder setup 11091113 * 11101114 * @return void 11111115 */ 11121116 public function install() 11131117 { 11141118 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- View request, no action 11151119 if (!empty($_GET['page'])) { 11161120 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- View request, no action 11171121 switch ($_GET['page']) { 11181122 case 'wpms-setup': 11191123 require_once WPMETASEO_PLUGIN_DIR . '/inc/install-wizard/install-wizard.php'; 11201124 break; 11211125 } 11221126 } 11231127 } 11241128 11251129 /** 11261130 * Create field analysis 11271131 * 11281132 * @param string $data_title Title 11291133 * @param string $alt Alt text 11301134 * @param string $dashicon Type 11311135 * @param string $label Label 11321136 * @param string $value_hidden Value 11331137 * 11341138 * @return string 11351139 */ 11361140 public function createFieldAnalysis($data_title, $alt, $dashicon, $label, $value_hidden) 11371141 { 11381142 $output = '<div class="metaseo_analysis metaseo_tool" data-title="' . esc_attr($data_title) . '" data-tippy="' . esc_attr($alt) . '">'; 11391143 if ($dashicon === 'done') { 11401144 $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxdone">done</i>'; 11411145 } else { 11421146 $output .= '<i class="metaseo-dashicons material-icons dashicons-before icons-mboxwarning">error_outline</i>'; 11431147 } 11441148 11451149 $output .= esc_html($label); 11461150 $output .= '</div>'; 11471151 $output .= '<input type="hidden" class="wpms_analysis_hidden" 11481152 name="' . esc_attr('wpms[' . $data_title . ']') . '" value="' . esc_attr($value_hidden) . '">'; 11491153 return $output; 11501154 } 11511155 11521156 /** 11531157 * Get content 11541158 * 11551159 * @param string $content Post content 11561160 * @param integer $post_id Post ID 11571161 * 11581162 * @return string 11591163 */ 11601164 public function wpmsTheContent($content, $post_id) 11611165 { 11621166 $content = apply_filters( 11631167 'the_content', 11641168 $content, 11651169 $post_id 11661170 ); 11671171 11681172 if (is_plugin_active('oxygen/functions.php')) { 11691173 $shortcodes = get_post_meta($post_id, 'ct_builder_shortcodes', true); 11701174 $cf = do_shortcode($shortcodes); 11711175 $content = $content . $cf; 11721176 } 11731177 11741178 return $content; 11751179 } 11761180 11771181 /** 11781182 * Get all the values of an array 11791183 * 11801184 * @param array $array List array to get value 11811185 * 11821186 * @return array|string 11831187 */ 11841188 public function getValues($array) 11851189 { 11861190 if (is_array($array)) { 11871191 $array = array_values($array); 11881192 } 11891193 11901194 return $array; 11911195 } 11921196 11931197 /** 11941198 * Check strpos with list array 11951199 * 11961200 * @param string $haystack String to compare 11971201 * @param array $needle List array need compare 11981202 * @param integer $offset Offset value 11991203 * 12001204 * @return boolean 12011205 */ 12021206 public function strPosArray($haystack, $needle, $offset = 0) 12031207 { 12041208 if (!is_array($needle)) { 12051209 $needle = array($needle); 12061210 } 12071211 foreach ($needle as $query) { 12081212 // stop on first true result 12091213 if (strpos($haystack, $query, $offset) !== false) { 12101214 return true; 12111215 } 12121216 } 12131217 return false; 12141218 } 12151219 12161220 /** 12171221 * Recursion to get specific value of file 12181222 * 12191223 * @param array $fields List specific value of field 12201224 * 12211225 * @return string 12221226 */ 12231227 public function getACFData($fields) 12241228 { 12251229 $values = $this->getValues($fields); 12261230 $data = ''; 12271231 12281232 if (is_array($values)) { 12291233 foreach ($values as $item) { 12301234 switch (gettype($item)) { 12311235 case 'array': 12321236 $data .= $this->getACFData($item); 12331237 break; 12341238 case 'string': 12351239 // Check link 12361240 if (filter_var($item, FILTER_VALIDATE_URL)) { 12371241 $checkImageLink = $this->strPosArray($item, array('.jpg', '.png', '.jpeg', 'svg', 'gif')); 12381242 if (!$checkImageLink) { 12391243 $item = '<a href="' . $item . '">' . $item . '</a>'; 12401244 } 12411245 } 12421246 $data .= ' ' . $item; 12431247 break; 12441248 } 12451249 } 12461250 } 12471251 if (is_string($values)) { 12481252 $data .= ' ' . $values; 12491253 } 12501254 return $data; 12511255 } 12521256 12531257 /** 12541258 * Inject ACF field to content 12551259 * 12561260 * @param string $content Post content 12571261 * @param integer $post_id Post ID 12581262 * 12591263 * @return string 12601264 */ 12611265 public function injectAcfField($content, $post_id) 12621266 { 12631267 if (class_exists('ACF')) { 12641268 $fields = get_field_objects($post_id); 12651269 12661270 if (!empty($fields)) { 12671271 $inject = ''; 12681272 foreach ($fields as $name => $field) { 12691273 if ($field['type'] === 'image') { 12701274 $size = $field['preview_size']; 12711275 if (is_array($field['value'])) { 12721276 $caption = $field['value']['caption']; 12731277 // Get image link if field is array 12741278 if ($caption) { 12751279 $inject .= '<div class="wp-caption">'; 12761280 } 12771281 $inject = '<a href="' . $field['value']['url'] . '" title="' . $field['value']['title'] . '">'; 12781282 $inject .= '<img src="' . $field['value']['sizes'][$size] . '" alt="' . $field['value']['alt'] . '" width="' . $field['value']['sizes'][$size . '-width'] . '" height="' . $field['value']['sizes'][$size . '-height'] . '" />'; 12791283 $inject .= '</a>'; 12801284 if ($caption) { 12811285 $inject .= '<p class="wp-caption-text">' . $caption . '</p>'; 12821286 } 12831287 $inject .= '</div>'; 12841288 } elseif (is_string($field['value'])) { 12851289 $inject = '<img src="' . $field['value'] . '" />'; 12861290 } else { 12871291 $inject = wp_get_attachment_image($field['value'], $size); 12881292 } 12891293 } elseif ($field['type'] === 'link') { 12901294 // Get link if field is array 12911295 if (is_array($field['value'])) { 12921296 $inject = '<a class="link-url" href="' . $field['value']['url'] . '" target="' . ($field['value']['target'] ? $field['value']['target'] : '_self') . '">' . esc_html($field['value']['title']) . '</a>'; 12931297 } else { 12941298 $inject = '<a class="link-url" href="' . $field['value'] . '">' . esc_html($field['value']) . '</a>'; 12951299 } 12961300 } else { 12971301 $inject = $this->getACFData($field['value']); 12981302 } 12991303 13001304 $content .= ' ' . $inject; 13011305 } 13021306 } 13031307 } 13041308 13051309 return $content; 13061310 } 13071311 13081312 /** 13091313 * Inject Woocommerce short description to content 13101314 * 13111315 * @param string $content Post content 13121316 * @param integer $post_id Post ID 13131317 * 13141318 * @return string 13151319 */ 13161320 public function injectWooCommerce($content, $post_id) 13171321 { 13181322 if (class_exists('WooCommerce')) { 13191323 $post = get_post($post_id); 13201324 13211325 if (!empty($post->post_excerpt)) { 13221326 $content .= '' . $post->post_excerpt; 13231327 } 13241328 } 13251329 13261330 return $content; 13271331 } 13281332 13291333 /** 13301334 * Ajax load page analysis 13311335 * 13321336 * @return void 13331337 */ 13341338 public function reloadAnalysis() 13351339 { 13361340 if (empty($_POST['wpms_nonce']) 13371341 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 13381342 die(); 13391343 } 13401344 13411345 if (!current_user_can('edit_posts')) { 13421346 wp_send_json(array('status' => false)); 13431347 } 13441348 $tooltip_page = array(); 13451349 $tooltip_page['title_in_heading'] = esc_attr__('Check if a word of this content title 13461350 is also in a title heading (h1, h2...)', 'wp-meta-seo'); 13471351 $tooltip_page['title_in_content'] = esc_attr__('Check if a word of this content 13481352 title is also in the text', 'wp-meta-seo'); 13491353 $tooltip_page['page_url'] = esc_attr__('Does the page title match with the permalink (URL structure)', 'wp-meta-seo'); 13501354 $tooltip_page['meta_title'] = esc_attr__('Is the meta title of this page filled?', 'wp-meta-seo'); 13511355 $tooltip_page['meta_desc'] = esc_attr__('Is the meta description of this page filled?', 'wp-meta-seo'); 13521356 $tooltip_page['image_resize'] = esc_attr__('Check for image HTML resizing in content 13531357 (usually image resized using handles)', 'wp-meta-seo'); 13541358 $tooltip_page['image_alt'] = esc_attr__('Check for image Alt text and title', 'wp-meta-seo'); 13551359 if (empty($_POST['datas'])) { 13561360 wp_send_json(false); 13571361 } 13581362 13591363 if (isset($_POST['datas']['post_id']) && empty($_POST['datas']['first_load'])) { 13601364 update_post_meta($_POST['datas']['post_id'], 'wpms_validate_analysis', ''); 13611365 } 13621366 13631367 $meta_analysis = get_post_meta((int)$_POST['datas']['post_id'], 'wpms_validate_analysis', true); 13641368 $check = 0; 13651369 $output = ''; 13661370 13671371 // title heading 13681372 $words_post_title = preg_split( 13691373 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 13701374 strtolower($_POST['datas']['title']), 13711375 -1, 13721376 PREG_SPLIT_NO_EMPTY 13731377 ); 13741378 13751379 // do shortcode js_composer plugin 13761380 if (is_plugin_active('js_composer_theme/js_composer.php')) { 13771381 add_shortcode('mk_fancy_title', 'vc_do_shortcode'); 13781382 } 13791383 13801384 $content = apply_filters( 13811385 'wpms_the_content', 13821386 '<div>' . html_entity_decode(stripcslashes($_POST['datas']['content']), ENT_COMPAT, 'UTF-8') . '</div>', 13831387 $_POST['datas']['post_id'] 13841388 ); 13851389 13861390 $content = $this->injectAcfField($content, $_POST['datas']['post_id']); 13871391 13881392 $content = $this->injectWooCommerce($content, $_POST['datas']['post_id']); 13891393 13901394 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['heading_title'])) { 13911395 $output .= $this->createFieldAnalysis( 13921396 'heading_title', 13931397 $tooltip_page['title_in_heading'], 13941398 'done', 13951399 esc_html__('Page title word in content heading', 'wp-meta-seo'), 13961400 1 13971401 ); 13981402 $check++; 13991403 } else { 14001404 if ($content === '') { 14011405 $output .= $this->createFieldAnalysis( 14021406 'heading_title', 14031407 $tooltip_page['title_in_heading'], 14041408 'warning', 14051409 esc_html__('Page title word in content heading', 'wp-meta-seo'), 14061410 0 14071411 ); 14081412 } else { 14091413 // Extracting the specified elements from the web page 14101414 $tags_h1 = wpmsExtractTags($content, 'h1', false, true); 14111415 $tags_h2 = wpmsExtractTags($content, 'h2', false, true); 14121416 $tags_h3 = wpmsExtractTags($content, 'h3', false, true); 14131417 $tags_h4 = wpmsExtractTags($content, 'h4', false, true); 14141418 $tags_h5 = wpmsExtractTags($content, 'h5', false, true); 14151419 $tags_h6 = wpmsExtractTags($content, 'h6', false, true); 14161420 14171421 // extract heading tags from WPBakery plugin shortcode 14181422 if (is_plugin_active('js_composer/js_composer.php') && isset($_POST['datas']['content'])) { 14191423 $textContent = $_POST['datas']['content']; 14201424 $textContent = html_entity_decode(stripcslashes($textContent), ENT_COMPAT, 'UTF-8'); 14211425 $msPostTitle = isset($_POST['datas']['title']) ? $_POST['datas']['title'] : ''; 14221426 $vcCustomHeading = $this->wpmsShortcodeExtract($msPostTitle, $textContent, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6')); 14231427 if (!empty($vcCustomHeading)) { 14241428 $tags_h1 = array_merge($tags_h1, $vcCustomHeading['h1']); 14251429 $tags_h2 = array_merge($tags_h2, $vcCustomHeading['h2']); 14261430 $tags_h3 = array_merge($tags_h3, $vcCustomHeading['h3']); 14271431 $tags_h4 = array_merge($tags_h4, $vcCustomHeading['h4']); 14281432 $tags_h5 = array_merge($tags_h5, $vcCustomHeading['h5']); 14291433 $tags_h6 = array_merge($tags_h6, $vcCustomHeading['h6']); 14301434 } 14311435 } 14321436 $test = false; 14331437 if (empty($tags_h1) && empty($tags_h2) && empty($tags_h3) 14341438 && empty($tags_h4) && empty($tags_h5) && empty($tags_h6)) { 14351439 $test = false; 14361440 } else { 14371441 // check tag h1 14381442 if (!empty($tags_h1)) { 14391443 foreach ($tags_h1 as $order => $tagh1) { 14401444 $words_tagh1 = preg_split( 14411445 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 14421446 strtolower($tagh1['contents']), 14431447 -1, 14441448 PREG_SPLIT_NO_EMPTY 14451449 ); 14461450 14471451 if (is_array($words_tagh1) && is_array($words_post_title)) { 14481452 foreach ($words_tagh1 as $mh) { 14491453 if (in_array($mh, $words_post_title) && $mh !== '') { 14501454 $test = true; 14511455 } 14521456 } 14531457 } 14541458 } 14551459 } 14561460 14571461 // check tag h2 14581462 if (!empty($tags_h2)) { 14591463 foreach ($tags_h2 as $order => $tagh2) { 14601464 $words_tagh2 = preg_split( 14611465 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 14621466 strtolower($tagh2['contents']), 14631467 -1, 14641468 PREG_SPLIT_NO_EMPTY 14651469 ); 14661470 if (is_array($words_tagh2) && is_array($words_post_title)) { 14671471 foreach ($words_tagh2 as $mh) { 14681472 if (in_array($mh, $words_post_title) && $mh !== '') { 14691473 $test = true; 14701474 } 14711475 } 14721476 } 14731477 } 14741478 } 14751479 14761480 // check tag h3 14771481 if (!empty($tags_h3)) { 14781482 foreach ($tags_h3 as $order => $tagh3) { 14791483 $words_tagh3 = preg_split( 14801484 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 14811485 strtolower($tagh3['contents']), 14821486 -1, 14831487 PREG_SPLIT_NO_EMPTY 14841488 ); 14851489 if (is_array($words_tagh3) && is_array($words_post_title)) { 14861490 foreach ($words_tagh3 as $mh) { 14871491 if (in_array($mh, $words_post_title) && $mh !== '') { 14881492 $test = true; 14891493 } 14901494 } 14911495 } 14921496 } 14931497 } 14941498 14951499 // check tag h4 14961500 if (!empty($tags_h4)) { 14971501 foreach ($tags_h4 as $order => $tagh4) { 14981502 $words_tagh4 = preg_split( 14991503 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 15001504 strtolower($tagh4['contents']), 15011505 -1, 15021506 PREG_SPLIT_NO_EMPTY 15031507 ); 15041508 if (is_array($words_tagh4) && is_array($words_post_title)) { 15051509 foreach ($words_tagh4 as $mh) { 15061510 if (in_array($mh, $words_post_title) && $mh !== '') { 15071511 $test = true; 15081512 } 15091513 } 15101514 } 15111515 } 15121516 } 15131517 15141518 // check tag h5 15151519 if (!empty($tags_h5)) { 15161520 foreach ($tags_h5 as $order => $tagh5) { 15171521 $words_tagh5 = preg_split( 15181522 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 15191523 strtolower($tagh5['contents']), 15201524 -1, 15211525 PREG_SPLIT_NO_EMPTY 15221526 ); 15231527 if (is_array($words_tagh5) && is_array($words_post_title)) { 15241528 foreach ($words_tagh5 as $mh) { 15251529 if (in_array($mh, $words_post_title) && $mh !== '') { 15261530 $test = true; 15271531 } 15281532 } 15291533 } 15301534 } 15311535 } 15321536 15331537 // check tag h6 15341538 if (!empty($tags_h6)) { 15351539 foreach ($tags_h6 as $order => $tagh6) { 15361540 $words_tagh6 = preg_split( 15371541 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 15381542 strtolower($tagh6['contents']), 15391543 -1, 15401544 PREG_SPLIT_NO_EMPTY 15411545 ); 15421546 if (is_array($words_tagh6) && is_array($words_post_title)) { 15431547 foreach ($words_tagh6 as $mh) { 15441548 if (in_array($mh, $words_post_title) && $mh !== '') { 15451549 $test = true; 15461550 } 15471551 } 15481552 } 15491553 } 15501554 } 15511555 } 15521556 15531557 if ($test) { 15541558 $output .= $this->createFieldAnalysis( 15551559 'heading_title', 15561560 $tooltip_page['title_in_heading'], 15571561 'done', 15581562 esc_html__('Page title word in content heading', 'wp-meta-seo'), 15591563 1 15601564 ); 15611565 $check++; 15621566 } else { 15631567 $output .= $this->createFieldAnalysis( 15641568 'heading_title', 15651569 $tooltip_page['title_in_heading'], 15661570 'warning', 15671571 esc_html__('Page title word in content heading', 'wp-meta-seo'), 15681572 0 15691573 ); 15701574 } 15711575 } 15721576 } 15731577 15741578 // title content 15751579 $words_title = preg_split( 15761580 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 15771581 strtolower($_POST['datas']['title']), 15781582 -1, 15791583 PREG_SPLIT_NO_EMPTY 15801584 ); 15811585 $words_post_content = preg_split( 15821586 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 15831587 strtolower(strip_tags($content)), 15841588 -1, 15851589 PREG_SPLIT_NO_EMPTY 15861590 ); 15871591 15881592 $test1 = false; 15891593 if (is_array($words_title) && is_array($words_post_content)) { 15901594 foreach ($words_title as $mtitle) { 15911595 if (in_array($mtitle, $words_post_content) && $mtitle !== '') { 15921596 $test1 = true; 15931597 break; 15941598 } 15951599 } 15961600 } else { 15971601 $test1 = false; 15981602 } 15991603 16001604 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['content_title'])) { 16011605 $output .= $this->createFieldAnalysis( 16021606 'content_title', 16031607 $tooltip_page['title_in_content'], 16041608 'done', 16051609 esc_html__('Page title word in content', 'wp-meta-seo'), 16061610 1 16071611 ); 16081612 $check++; 16091613 } else { 16101614 if ($test1) { 16111615 $output .= $this->createFieldAnalysis( 16121616 'content_title', 16131617 $tooltip_page['title_in_content'], 16141618 'done', 16151619 esc_html__('Page title word in content', 'wp-meta-seo'), 16161620 1 16171621 ); 16181622 $check++; 16191623 } else { 16201624 $output .= $this->createFieldAnalysis( 16211625 'content_title', 16221626 $tooltip_page['title_in_content'], 16231627 'warning', 16241628 esc_html__('Page title word in content', 'wp-meta-seo'), 16251629 0 16261630 ); 16271631 } 16281632 } 16291633 16301634 // page url matches page title 16311635 $mtitle = $_POST['datas']['title']; 16321636 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['pageurl'])) { 16331637 $output .= $this->createFieldAnalysis( 16341638 'pageurl', 16351639 $tooltip_page['page_url'], 16361640 'done', 16371641 esc_html__('Page url matches with page title', 'wp-meta-seo'), 16381642 1 16391643 ); 16401644 $check++; 16411645 } else { 16421646 $mpageurl = ''; 16431647 if (isset($_POST['datas']['mpageurl'])) { 16441648 $infos = pathinfo($_POST['datas']['mpageurl']); 16451649 $mpageurl = $infos['filename']; 16461650 if ($mpageurl[0] === '?') { 16471651 $mpageurl = ltrim($mpageurl, '?'); // remove ? from ?page=abc 16481652 } 16491653 } 16501654 16511655 //check is home page 16521656 $home_url = home_url(); 16531657 $home_url_1 = explode('//', $home_url); 16541658 $is_home = false; 16551659 if (!empty($home_url_1[1]) && isset($_POST['datas']['mpageurl'])) { 16561660 $home_url_2 = explode($home_url_1[1], $_POST['datas']['mpageurl']); 16571661 if (!isset($home_url_2[1]) || (!empty($home_url_2[1]) && $home_url_2[1] === '/')) { 16581662 $is_home = true; 16591663 } 16601664 } 16611665 16621666 if ((isset($_POST['datas']['mpageurl']) && $is_home) || (!empty($mpageurl) && !empty($mtitle) && strpos(sanitize_title($mtitle), sanitize_title($mpageurl)) !== false)) { 16631667 $output .= $this->createFieldAnalysis( 16641668 'pageurl', 16651669 $tooltip_page['page_url'], 16661670 'done', 16671671 esc_html__('Page url matches with page title', 'wp-meta-seo'), 16681672 1 16691673 ); 16701674 $check++; 16711675 } else { 16721676 $output .= $this->createFieldAnalysis( 16731677 'pageurl', 16741678 $tooltip_page['page_url'], 16751679 'warning', 16761680 esc_html__('Page url matches with page title', 'wp-meta-seo'), 16771681 0 16781682 ); 16791683 } 16801684 } 16811685 16821686 // meta title filled 16831687 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['metatitle'])) { 16841688 $output .= $this->createFieldAnalysis( 16851689 'metatitle', 16861690 $tooltip_page['meta_title'], 16871691 'done', 16881692 esc_html__('Meta title filled', 'wp-meta-seo'), 16891693 1 16901694 ); 16911695 $check++; 16921696 } else { 16931697 if (($_POST['datas']['meta_title'] !== '' 16941698 && mb_strlen($_POST['datas']['meta_title'], 'UTF-8') <= self::$title_length)) { 16951699 $output .= $this->createFieldAnalysis( 16961700 'metatitle', 16971701 $tooltip_page['meta_title'], 16981702 'done', 16991703 esc_html__('Meta title filled', 'wp-meta-seo'), 17001704 1 17011705 ); 17021706 $check++; 17031707 } else { 17041708 $output .= $this->createFieldAnalysis( 17051709 'metatitle', 17061710 $tooltip_page['meta_title'], 17071711 'warning', 17081712 esc_html__('Meta title filled', 'wp-meta-seo'), 17091713 0 17101714 ); 17111715 } 17121716 } 17131717 17141718 // desc filled 17151719 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['metadesc'])) { 17161720 $output .= $this->createFieldAnalysis( 17171721 'metadesc', 17181722 $tooltip_page['meta_desc'], 17191723 'done', 17201724 esc_html__('Meta description filled', 'wp-meta-seo'), 17211725 1 17221726 ); 17231727 $check++; 17241728 } else { 17251729 if ($_POST['datas']['meta_desc'] !== '' 17261730 && mb_strlen($_POST['datas']['meta_desc'], 'UTF-8') <= self::$desc_length) { 17271731 $output .= $this->createFieldAnalysis( 17281732 'metadesc', 17291733 $tooltip_page['meta_desc'], 17301734 'done', 17311735 esc_html__('Meta description filled', 'wp-meta-seo'), 17321736 1 17331737 ); 17341738 $check++; 17351739 } else { 17361740 $output .= $this->createFieldAnalysis( 17371741 'metadesc', 17381742 $tooltip_page['meta_desc'], 17391743 'warning', 17401744 esc_html__('Meta description filled', 'wp-meta-seo'), 17411745 0 17421746 ); 17431747 } 17441748 } 17451749 17461750 // image resize 17471751 if ($content === '') { 17481752 $output .= $this->createFieldAnalysis( 17491753 'imgresize', 17501754 $tooltip_page['image_resize'], 17511755 'done', 17521756 esc_html__('Wrong image resize', 'wp-meta-seo'), 17531757 1 17541758 ); 17551759 $output .= $this->createFieldAnalysis( 17561760 'imgalt', 17571761 $tooltip_page['image_alt'], 17581762 'done', 17591763 esc_html__('Image alt information filled', 'wp-meta-seo'), 17601764 1 17611765 ); 17621766 $check += 2; 17631767 } else { 17641768 // Extracting the specified elements from the web page 17651769 $img_tags = wpmsExtractTags($content, 'img', true, true); 17661770 $img_wrong = false; 17671771 $img_wrong_alt = false; 17681772 foreach ($img_tags as $order => $tag) { 17691773 if (!isset($tag['attributes']['src'])) { 17701774 continue; 17711775 } 17721776 17731777 $src = $tag['attributes']['src']; 17741778 $imgpath = str_replace(site_url(), ABSPATH, $src); 17751779 if (!file_exists($imgpath)) { 17761780 continue; 17771781 } 17781782 if (!list($width_origin, $height_origin) = getimagesize($imgpath)) { 17791783 continue; 17801784 } 17811785 17821786 if (empty($tag['attributes']['width']) && empty($tag['attributes']['height'])) { 17831787 $img_wrong = false; 17841788 } else { 17851789 if (!empty($width_origin) && !empty($height_origin)) { 17861790 if ((isset($tag['attributes']['width']) && (int)$width_origin !== (int)$tag['attributes']['width']) 17871791 || (isset($tag['attributes']['height']) && (int)$height_origin !== (int)$tag['attributes']['height'])) { 17881792 $img_wrong = true; 17891793 } 17901794 } 17911795 } 17921796 17931797 if (empty($tag['attributes']['alt'])) { 17941798 $img_wrong_alt = true; 17951799 } 17961800 } 17971801 17981802 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['imgresize'])) { 17991803 $output .= $this->createFieldAnalysis( 18001804 'imgresize', 18011805 $tooltip_page['image_resize'], 18021806 'done', 18031807 esc_html__('Wrong image resize', 'wp-meta-seo'), 18041808 1 18051809 ); 18061810 $check++; 18071811 } else { 18081812 if (!$img_wrong) { 18091813 $output .= $this->createFieldAnalysis( 18101814 'imgresize', 18111815 $tooltip_page['image_resize'], 18121816 'done', 18131817 esc_html__('Wrong image resize', 'wp-meta-seo'), 18141818 1 18151819 ); 18161820 $check++; 18171821 } else { 18181822 $output .= $this->createFieldAnalysis( 18191823 'imgresize', 18201824 $tooltip_page['image_resize'], 18211825 'warning', 18221826 esc_html__('Wrong image resize', 'wp-meta-seo'), 18231827 0 18241828 ); 18251829 } 18261830 } 18271831 18281832 if (isset($_POST['datas']['first_load']) && !empty($meta_analysis) && !empty($meta_analysis['imgalt'])) { 18291833 $output .= $this->createFieldAnalysis( 18301834 'imgalt', 18311835 $tooltip_page['image_alt'], 18321836 'done', 18331837 esc_html__('Image alt information filled', 'wp-meta-seo'), 18341838 1 18351839 ); 18361840 $check++; 18371841 } else { 18381842 if (!$img_wrong_alt) { 18391843 $output .= $this->createFieldAnalysis( 18401844 'imgalt', 18411845 $tooltip_page['image_alt'], 18421846 'done', 18431847 esc_html__('Image alt information filled', 'wp-meta-seo'), 18441848 1 18451849 ); 18461850 $check++; 18471851 } else { 18481852 $output .= $this->createFieldAnalysis( 18491853 'imgalt', 18501854 $tooltip_page['image_alt'], 18511855 'warning', 18521856 esc_html__('Image alt information filled', 'wp-meta-seo'), 18531857 0 18541858 ); 18551859 } 18561860 } 18571861 18581862 $output .= $this->createFieldAnalysis( 18591863 'seokeyword', 18601864 esc_html__('At least one of the SEO keywords are found in the page title OR meta title OR SEO meta description OR page content heading OR the page content', 'wp-meta-seo'), 18611865 'warning', 18621866 esc_html__('SEO keywords are found', 'wp-meta-seo'), 18631867 0 18641868 ); 18651869 18661870 $right_output = '<div class="metaseo_analysis metaseo_tool"><span style="font-weight: 700">' . esc_html__('Page SEO keywords check', 'wp-meta-seo') . '</span></div>'; 18671871 18681872 $right_output .= $this->createFieldAnalysis( 18691873 'keyintitle', 18701874 esc_html__('The SEO keywords are found in page title', 'wp-meta-seo'), 18711875 'warning', 18721876 esc_html__('The keywords are found in page title', 'wp-meta-seo'), 18731877 0 18741878 ); 18751879 18761880 $right_output .= $this->createFieldAnalysis( 18771881 'keyincontent', 18781882 esc_html__('The SEO keywords are found in page content', 'wp-meta-seo'), 18791883 'warning', 18801884 esc_html__('The keywords are found in page content', 'wp-meta-seo'), 18811885 0 18821886 ); 18831887 18841888 18851889 $right_output .= $this->createFieldAnalysis( 18861890 'keyinmetatitle', 18871891 esc_html__('The SEO keywords are found in meta title', 'wp-meta-seo'), 18881892 'warning', 18891893 esc_html__('The keywords are found in meta title', 'wp-meta-seo'), 18901894 0 18911895 ); 18921896 18931897 $right_output .= $this->createFieldAnalysis( 18941898 'keyinmetadescription', 18951899 esc_html__('The SEO keywords are found in meta description', 'wp-meta-seo'), 18961900 'warning', 18971901 esc_html__('The keywords are found in meta description', 'wp-meta-seo'), 18981902 0 18991903 ); 19001904 19011905 $right_output .= $this->createFieldAnalysis( 19021906 'keyincontentheading', 19031907 esc_html__('The SEO keywords are found in page content heading', 'wp-meta-seo'), 19041908 'warning', 19051909 esc_html__('The keywords are found in page content heading', 'wp-meta-seo'), 19061910 0 19071911 ); 19081912 } 19091913 $total_check = 7; 19101914 if (isset($_POST['datas']['seo_keywords']) && !empty($_POST['datas']['seo_keywords'])) { 19111915 $total_check++; 19121916 } 19131917 $circliful = ceil(100 * ($check) / $total_check); 19141918 /** 19151919 * Reload analytics 19161920 * 19171921 * @param integer Post ID 19181922 * @param array All the datas 19191923 */ 19201924 do_action('wpms_reload_analytics', $_POST['datas']['post_id'], $_POST['datas']); 19211925 wp_send_json(array('circliful' => $circliful, 'output' => $output, 'check' => $check, 'right_output' => $right_output)); 19221926 } 19231927 19241928 /** 19251929 * Extract html heading tags from WPBakery Page Builder shortcode 19261930 * 19271931 * @param string $postTitle Post title 19281932 * @param string $textContent Text content page/post 19291933 * @param array $search Html heading tags to extract 19301934 * 19311935 * @return array 19321936 */ 19331937 public function wpmsShortcodeExtract($postTitle, $textContent, $search) 19341938 { 19351939 $extracted = array(); 19361940 // Capture vc_custom_heading shortcode from post content 19371941 if (preg_match_all('/\[vc_custom_heading(.*?)\]/i', $textContent, $matches)) { 19381942 if (!empty($matches)) { 19391943 foreach ($matches[1] as $vcCustomHeading) { 19401944 $attrs = shortcode_parse_atts(trim($vcCustomHeading)); 19411945 if (!empty($attrs['font_container'])) { 19421946 foreach ($search as $s) { 19431947 if (strpos($attrs['font_container'], 'tag:' . $s . '|') !== false) { 19441948 $tag = $s; 19451949 break; // find out html tag 19461950 } 19471951 } 19481952 } else { 19491953 $tag = 'h2'; // default by WPBakery page builder if empty font_container attr 19501954 } 19511955 19521956 // Check case source="post_title" 19531957 $content = ''; 19541958 if (isset($attrs['source']) && $attrs['source'] === 'post_title') { 19551959 $content = $postTitle; 19561960 } elseif (isset($attrs['text']) && !empty($attrs['text'])) { 19571961 $content = $attrs['text']; 19581962 } 19591963 19601964 if (!empty($attrs) && isset($tag)) { 19611965 $extracted[$tag][] = array( 19621966 'tag_name' => $tag, 19631967 'offset' => '', 19641968 'contents' => $content, 19651969 'attributes' => array(), 19661970 'full_tag' => '[vc_custom_heading ' . $vcCustomHeading . ']' 19671971 ); 19681972 } 19691973 } 19701974 } 19711975 } 19721976 19731977 // Capture trx_sc_title shortcode from post content 19741978 if (preg_match_all('/\[trx_sc_title(.*?)\]/i', $textContent, $matches)) { 19751979 if (!empty($matches)) { 19761980 foreach ($matches[1] as $trxScTitle) { 19771981 $attrs = shortcode_parse_atts(trim($trxScTitle)); 19781982 if (!empty($attrs['title_tag'])) { 19791983 $titleTag = $attrs['title_tag']; 19801984 } else { 19811985 $titleTag = 'h2'; // default by WPBakery page builder if empty title_tag attr 19821986 } 19831987 19841988 // Check case source="post_title" 19851989 $title = ''; 19861990 if (isset($attrs['title'])) { 19871991 $title = $attrs['title']; 19881992 } 19891993 19901994 if (!empty($attrs) && !empty($title)) { 19911995 $extracted[$titleTag][] = array( 19921996 'tag_name' => $titleTag, 19931997 'offset' => '', 19941998 'contents' => $title, 19951999 'attributes' => array(), 19962000 'full_tag' => '[trx_sc_title ' . $trxScTitle . ']' 19972001 ); 19982002 } 19992003 } 20002004 } 20012005 } 20022006 20032007 return $extracted; 20042008 } 20052009 /** 20062010 * Validate propertyin page optimization 20072011 * 20082012 * @return void 20092013 */ 20102014 public function validateAnalysis() 20112015 { 20122016 if (empty($_POST['wpms_nonce']) 20132017 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 20142018 die(); 20152019 } 20162020 20172021 if (!current_user_can('manage_options')) { 20182022 wp_send_json(false); 20192023 } 20202024 $post_id = $_POST['post_id']; 20212025 $key = 'wpms_validate_analysis'; 20222026 $analysis = get_post_meta($post_id, $key, true); 20232027 if (empty($analysis)) { 20242028 $analysis = array(); 20252029 } 20262030 20272031 $analysis[$_POST['field']] = 1; 20282032 update_post_meta($post_id, $key, $analysis); 20292033 wp_send_json(true); 20302034 } 20312035 20322036 /** 20332037 * Remove link in source 404 20342038 * 20352039 * @return void 20362040 */ 20372041 public function removeLink() 20382042 { 20392043 if (empty($_POST['wpms_nonce']) 20402044 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 20412045 die(); 20422046 } 20432047 20442048 if (!current_user_can('manage_options')) { 20452049 wp_send_json(array('status' => false)); 20462050 } 20472051 20482052 global $wpdb; 20492053 if (isset($_POST['link_id'])) { 20502054 $wpdb->delete($wpdb->prefix . 'wpms_links', array('id' => (int)$_POST['link_id'])); 20512055 wp_send_json(array('status' => true)); 20522056 } 20532057 20542058 wp_send_json(array('status' => false)); 20552059 } 20562060 20572061 /** 20582062 * Ajax update link meta title and content editor 20592063 * 20602064 * @param string $type Action type 20612065 * @param string $link_detail Link details 20622066 * @param string $title Title value 20632067 * @param integer $link_id Link ID 20642068 * 20652069 * @return void 20662070 */ 20672071 public function updateLink1($type, $link_detail, $title, $link_id) 20682072 { 20692073 global $wpdb; 20702074 global $wp_version; 20712075 // Purge title 20722076 $title = strip_tags($title); 20732077 $title = str_replace("'", '', $title); 20742078 $title = str_replace('"', '', $title); 20752079 20762080 $value = array('meta_title' => $title); 20772081 $wpdb->update( 20782082 $wpdb->prefix . 'wpms_links', 20792083 $value, 20802084 array('id' => (int)$link_id) 20812085 ); 20822086 $post = get_post($link_detail->source_id); 20832087 20842088 if (!empty($post)) { 20852089 if (version_compare($wp_version, '5.0', '>=')) { 20862090 if (function_exists('has_blocks')) { 20872091 if (has_blocks((int)$link_detail->source_id)) { 20882092 // Gutenberg 20892093 $post_content = $this->gutenbergUpdateContent($post->post_content, $link_detail, $title); 20902094 } else { 20912095 // Classic editor 20922096 $post_content = $this->replaceNewTitle($post->post_content, $link_detail, $title); 20932097 } 20942098 } 20952099 } else { 20962100 // Classic editor 20972101 $post_content = $this->replaceNewTitle($post->post_content, $link_detail, $title); 20982102 } 20992103 21002104 $my_post = array( 21012105 'ID' => (int)$link_detail->source_id, 21022106 'post_content' => $post_content 21032107 ); 21042108 remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost')); 21052109 wp_update_post($my_post); 21062110 if ($type === 'ajax') { 21072111 wp_send_json(array('status' => true)); 21082112 } 21092113 } 21102114 } 21112115 21122116 /** 21132117 * Update link meta title and content editor in gutenberg 21142118 * 21152119 * @param string $post_content Content of posts 21162120 * @param string $link_detail Link details 21172121 * @param string $title Title value 21182122 * 21192123 * @return string 21202124 */ 21212125 public function gutenbergUpdateContent($post_content, $link_detail, $title) 21222126 { 21232127 $blocks = parse_blocks($post_content); 21242128 // phpcs:disable Generic.PHP.LowerCaseConstant.Found -- In special case the block returns NULL 21252129 $allowed_blocks = array( 21262130 // Classic blocks have their blockName set to null. 21272131 null, 21282132 NULL, 21292133 'core/button', 21302134 'core/paragraph', 21312135 'core/heading', 21322136 'core/list', 21332137 'core/quote', 21342138 'core/cover', 21352139 'core/html', 21362140 'core/verse', 21372141 'core/preformatted', 21382142 'core/pullquote', 21392143 'core/table', 21402144 'core/media-text' 21412145 ); 21422146 // phpcs:enable 21432147 foreach ($blocks as $block) { 21442148 // Gutenberg block 21452149 if (in_array($block['blockName'], $allowed_blocks, true)) { 21462150 if (!empty($block['innerBlocks'])) { 21472151 // Skip the block if it has disallowed or nested inner blocks. 21482152 foreach ($block['innerBlocks'] as $inner_block) { 21492153 if (!in_array($inner_block['blockName'], $allowed_blocks, true) || 21502154 !empty($inner_block['innerBlocks']) 21512155 ) { 21522156 continue; 21532157 } 21542158 } 21552159 } 21562160 21572161 if (strpos($block['innerHTML'], $link_detail->link_text) !== false) { 21582162 $post_content = $this->replaceNewTitle($post_content, $link_detail, $title); 21592163 } 21602164 } 21612165 } 21622166 21632167 return $post_content; 21642168 } 21652169 21662170 /** 21672171 * Filter and replace new title 21682172 * 21692173 * @param string $post_content Content of posts 21702174 * @param string $link_detail Link details 21712175 * @param string $title Title value 21722176 * 21732177 * @return string 21742178 */ 21752179 protected function replaceNewTitle($post_content, $link_detail, $title) 21762180 { 21772181 $links = wpmsExtractTags($post_content, 'a', false, true); 21782182 $title_tag = sprintf('%s="%s"', 'title', esc_attr($title)); 21792183 if (!empty($links)) { 21802184 foreach ($links as $link) { 21812185 if ($link['contents'] === $link_detail->link_text) { 21822186 if (!isset($link['attributes']['title'])) { 21832187 // Not titlte, add new 21842188 $new_html = preg_replace( 21852189 '/<a/is', 21862190 '<a ' . $title_tag, 21872191 $link['full_tag'] 21882192 ); 21892193 } else { 21902194 $new_html = preg_replace( 21912195 '/title=(["\'])(.*?)["\']/is', 21922196 $title_tag, 21932197 $link['full_tag'] 21942198 ); 21952199 } 21962200 // Replace tag 21972201 $post_content = str_replace($link['full_tag'], $new_html, $post_content); 21982202 } 21992203 } 22002204 } 22012205 22022206 return $post_content; 22032207 } 22042208 22052209 /** 22062210 * Ajax update link meta title and content editor 22072211 * 22082212 * @return void 22092213 */ 22102214 public function updateLink() 22112215 { 22122216 if (empty($_POST['wpms_nonce']) 22132217 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 22142218 die(); 22152219 } 22162220 22172221 if (!current_user_can('manage_options')) { 22182222 wp_send_json(false); 22192223 } 22202224 if (isset($_POST['link_id'])) { 22212225 global $wpdb; 22222226 $link_detail = $wpdb->get_row($wpdb->prepare( 22232227 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d', 22242228 array( 22252229 (int)$_POST['link_id'] 22262230 ) 22272231 )); 22282232 if (empty($link_detail)) { 22292233 wp_send_json(false); 22302234 } 22312235 $this->updateLink1('ajax', $link_detail, $_POST['meta_title'], $_POST['link_id']); 22322236 } 22332237 wp_send_json(false); 22342238 } 22352239 22362240 /** 22372241 * Ajax update meta index for page 22382242 * 22392243 * @return void 22402244 */ 22412245 public function updatePageIndex() 22422246 { 22432247 if (empty($_POST['wpms_nonce']) 22442248 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 22452249 die(); 22462250 } 22472251 22482252 if (!current_user_can('manage_options')) { 22492253 wp_send_json(array('status' => false)); 22502254 } 22512255 if (isset($_POST['page_id']) && isset($_POST['index'])) { 22522256 update_post_meta($_POST['page_id'], '_metaseo_metaindex', $_POST['index']); 22532257 /** 22542258 * Update index/noindex for robots meta tag of a page 22552259 * 22562260 * @param integer Page ID 22572261 * @param string Page meta index 22582262 * @param integer Page index value 22592263 */ 22602264 do_action('wpms_update_page_index', $_POST['page_id'], '_metaseo_metaindex', $_POST['index']); 22612265 wp_send_json(array('status' => true)); 22622266 } 22632267 wp_send_json(array('status' => false)); 22642268 } 22652269 22662270 /** 22672271 * Ajax update meta follow for page 22682272 * 22692273 * @return void 22702274 */ 22712275 public function updatePageFollow() 22722276 { 22732277 if (empty($_POST['wpms_nonce']) 22742278 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 22752279 die(); 22762280 } 22772281 22782282 if (!current_user_can('manage_options')) { 22792283 wp_send_json(array('status' => false)); 22802284 } 22812285 if (isset($_POST['page_id']) && isset($_POST['follow'])) { 22822286 update_post_meta((int)$_POST['page_id'], '_metaseo_metafollow', $_POST['follow']); 22832287 22842288 /** 22852289 * Update follow/nofollow for robots meta tag of a page 22862290 * 22872291 * @param integer Page ID 22882292 * @param string Page meta follow 22892293 * @param integer Page follow value 22902294 */ 22912295 do_action('wpms_update_page_follow', $_POST['page_id'], '_metaseo_metafollow', $_POST['follow']); 22922296 wp_send_json(array('status' => true)); 22932297 } 22942298 wp_send_json(array('status' => false)); 22952299 } 22962300 22972301 /** 22982302 * Ajax update meta follow for link 22992303 * 23002304 * @return void 23012305 */ 23022306 public function updateFollow() 23032307 { 23042308 if (empty($_POST['wpms_nonce']) 23052309 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 23062310 die(); 23072311 } 23082312 23092313 if (!current_user_can('manage_options')) { 23102314 wp_send_json(array('status' => false)); 23112315 } 23122316 if (isset($_POST['link_id'])) { 23132317 $this->doUpdateFollow($_POST['link_id'], $_POST['follow']); 23142318 /** 23152319 * Update follow/nofollow for rel attribute of a link 23162320 * 23172321 * @param integer Link ID 23182322 * @param integer Link follow 23192323 */ 23202324 do_action('wpms_update_link_follow', $_POST['link_id'], $_POST['follow']); 23212325 wp_send_json(array('status' => true)); 23222326 } 23232327 wp_send_json(array('status' => false)); 23242328 } 23252329 23262330 /** 23272331 * Ajax update multitle meta follow for link 23282332 * 23292333 * @return void 23302334 */ 23312335 public function updateMultipleFollow() 23322336 { 23332337 if (empty($_POST['wpms_nonce']) 23342338 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 23352339 die(); 23362340 } 23372341 23382342 if (!current_user_can('manage_options')) { 23392343 wp_send_json(array('status' => false)); 23402344 } 23412345 global $wpdb; 23422346 $action_name = $_POST['action_name']; 23432347 $limit = 20; 23442348 23452349 switch ($action_name) { 23462350 case 'copy_title_selected': 23472351 if (empty($_POST['linkids'])) { 23482352 wp_send_json(array('status' => true)); 23492353 } 23502354 foreach ($_POST['linkids'] as $linkId) { 23512355 $link = $wpdb->get_row( 23522356 $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id = %d', $linkId) 23532357 ); 23542358 $link_text = $link->link_text; 23552359 if ($link_text !== '') { 23562360 $this->updateLink1('bulk', $link, $link_text, $linkId); 23572361 } 23582362 } 23592363 23602364 break; 23612365 case 'copy_title_all': 23622366 $links = $wpdb->get_results( 23632367 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE type="url"' 23642368 ); 23652369 foreach ($links as $link) { 23662370 $link_text = $link->link_text; 23672371 if ($link_text !== '') { 23682372 $this->updateLink1('bulk', $link, $link_text, $link->id); 23692373 } 23702374 } 23712375 break; 23722376 case 'follow_selected': 23732377 if (empty($_POST['linkids'])) { 23742378 wp_send_json(array('status' => true)); 23752379 } 23762380 23772381 $follow = 1; 23782382 foreach ($_POST['linkids'] as $linkId) { 23792383 $this->doUpdateFollow($linkId, $follow); 23802384 /** 23812385 * Update follow/nofollow for rel attribute of a link 23822386 * 23832387 * @param integer Link ID 23842388 * @param integer Link follow 23852389 * 23862390 * @ignore Hook already documented 23872391 */ 23882392 do_action('wpms_update_link_follow', $linkId, $follow); 23892393 } 23902394 break; 23912395 case 'follow_all': 23922396 $follow = 1; 23932397 $i = 0; 23942398 $links = $wpdb->get_results( 23952399 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE follow=0 AND type="url"' 23962400 ); 23972401 foreach ($links as $link) { 23982402 if ($i > $limit) { 23992403 wp_send_json(array('status' => false, 'message' => 'limit')); 24002404 } else { 24012405 $this->doUpdateFollow($link->id, $follow); 24022406 $i++; 24032407 /** 24042408 * Update follow/nofollow for rel attribute of a link 24052409 * 24062410 * @param integer Link ID 24072411 * @param integer Link follow 24082412 * 24092413 * @ignore Hook already documented 24102414 */ 24112415 do_action('wpms_update_link_follow', $link->id, $follow); 24122416 } 24132417 } 24142418 break; 24152419 case 'nofollow_selected': 24162420 $follow = 0; 24172421 if (empty($_POST['linkids'])) { 24182422 wp_send_json(array('status' => true)); 24192423 } 24202424 24212425 foreach ($_POST['linkids'] as $linkId) { 24222426 $this->doUpdateFollow($linkId, $follow); 24232427 /** 24242428 * Update follow/nofollow for rel attribute of a link 24252429 * 24262430 * @param integer Link ID 24272431 * @param integer Link follow 24282432 * 24292433 * @ignore Hook already documented 24302434 */ 24312435 do_action('wpms_update_link_follow', $linkId, $follow); 24322436 } 24332437 break; 24342438 case 'nofollow_all': 24352439 $follow = 0; 24362440 $i = 0; 24372441 $links = $wpdb->get_results( 24382442 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE follow=1 AND type="url"' 24392443 ); 24402444 foreach ($links as $link) { 24412445 if ($i > $limit) { 24422446 wp_send_json(array('status' => false, 'message' => 'limit')); 24432447 } else { 24442448 $this->doUpdateFollow($link->id, $follow); 24452449 $i++; 24462450 /** 24472451 * Update follow/nofollow for rel attribute of a link 24482452 * 24492453 * @param integer Link ID 24502454 * @param integer Link follow 24512455 * 24522456 * @ignore Hook already documented 24532457 */ 24542458 do_action('wpms_update_link_follow', $link->id, $follow); 24552459 } 24562460 } 24572461 break; 24582462 } 24592463 wp_send_json(array('status' => true)); 24602464 } 24612465 24622466 /** 24632467 * Ajax update meta follow for link 24642468 * 24652469 * @param integer $linkId Link id 24662470 * @param integer $follow Follow value 24672471 * 24682472 * @return void 24692473 */ 24702474 public function doUpdateFollow($linkId, $follow) 24712475 { 24722476 global $wpdb; 24732477 $link_detail = $wpdb->get_row($wpdb->prepare( 24742478 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE id=%d', 24752479 array((int)$linkId) 24762480 )); 24772481 if (empty($link_detail)) { 24782482 wp_send_json(array('status' => false)); 24792483 } 24802484 24812485 $value = array('follow' => $follow); 24822486 $wpdb->update( 24832487 $wpdb->prefix . 'wpms_links', 24842488 $value, 24852489 array('id' => (int)$linkId) 24862490 ); 24872491 24882492 $post = get_post($link_detail->source_id); 24892493 if (!empty($post)) { 24902494 $old_value = $post->post_content; 24912495 $edit_result = $this->editLinkHtml( 24922496 $old_value, 24932497 $link_detail->link_url, 24942498 $link_detail->link_url, 24952499 $link_detail->meta_title, 24962500 $follow 24972501 ); 24982502 $my_post = array( 24992503 'ID' => (int)$link_detail->source_id, 25002504 'post_content' => $edit_result['content'] 25012505 ); 25022506 remove_action('post_updated', array('MetaSeoBrokenLinkTable', 'updatePost')); 25032507 wp_update_post($my_post); 25042508 } 25052509 } 25062510 25072511 /** 25082512 * Render new content when edit a link 25092513 * 25102514 * @param string $content Post content 25112515 * @param string $new_url New url 25122516 * @param string $old_url Old url 25132517 * @param string $meta_title Meta title 25142518 * @param integer $follow Follow value 25152519 * @param null $new_text New text of link 25162520 * 25172521 * @return array 25182522 */ 25192523 public function editLinkHtml($content, $new_url, $old_url, $meta_title, $follow, $new_text = null) 25202524 { 25212525 //Save the old & new URLs for use in the edit callback. 25222526 $args = array( 25232527 'old_url' => $old_url, 25242528 'new_url' => $new_url, 25252529 'new_text' => $new_text, 25262530 'meta_title' => $meta_title, 25272531 'follow' => $follow 25282532 ); 25292533 25302534 //Find all links and replace those that match $old_url. 25312535 $content = MetaSeoBrokenLinkTable::multiEdit( 25322536 $content, 25332537 array( 25342538 'MetaSeoBrokenLinkTable', 25352539 'editHtmlCallback' 25362540 ), 25372541 $args 25382542 ); 25392543 25402544 $result = array( 25412545 'content' => $content, 25422546 'raw_url' => $new_url, 25432547 ); 25442548 if (isset($new_text)) { 25452549 $result['link_text'] = $new_text; 25462550 } 25472551 return $result; 25482552 } 25492553 25502554 /** 25512555 * Update option wpms_settings_404 25522556 * 25532557 * @return void 25542558 */ 25552559 public function save404Settings() 25562560 { 25572561 if (empty($_POST['wpms_nonce']) 25582562 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 25592563 die(); 25602564 } 25612565 25622566 if (!current_user_can('manage_options')) { 25632567 wp_send_json(false); 25642568 } 25652569 25662570 if (isset($_POST['wpms_redirect'])) { 25672571 update_option('wpms_settings_404', $_POST['wpms_redirect']); 25682572 } 25692573 25702574 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 25712575 $params = array('enable', 'numberFrequency', 'showlinkFrequency'); 25722576 $settinglink = array(); 25732577 foreach ($params as $param) { 25742578 if (isset($_POST[$param])) { 25752579 $settinglink[$param] = $_POST[$param]; 25762580 } 25772581 } 25782582 25792583 if (empty($settinglink['wpms_lastRun_scanlink'])) { 25802584 $settinglink['wpms_lastRun_scanlink'] = time(); 25812585 } 25822586 update_option('wpms_link_settings', $settinglink); 25832587 } 25842588 25852589 wp_send_json(true); 25862590 } 25872591 25882592 /** 25892593 * Update breadcrumb settings 25902594 * 25912595 * @return void 25922596 */ 25932597 public function saveBreadcrumbSettings() 25942598 { 25952599 if (empty($_POST['wpms_nonce']) 25962600 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 25972601 die(); 25982602 } 25992603 26002604 if (!current_user_can('manage_options')) { 26012605 wp_send_json(false); 26022606 } 26032607 26042608 $params = array('separator', 'include_home', 'home_text', 'clickable', 'home_text_default'); 26052609 $settinglink = array(); 26062610 foreach ($params as $param) { 26072611 if (isset($_POST[$param])) { 26082612 $settinglink[$param] = $_POST[$param]; 26092613 } 26102614 } 26112615 26122616 update_option('_metaseo_breadcrumbs', $settinglink); 26132617 wp_send_json(true); 26142618 } 26152619 26162620 /** 26172621 * Show meta box in single post, on elementor plugin 26182622 * 26192623 * @return void 26202624 */ 26212625 private function loadMetaBoxes() 26222626 { 26232627 if (in_array($this->pagenow, array( 26242628 'edit.php', 26252629 'post.php', 26262630 'post-new.php', 26272631 )) || apply_filters('wpmseo_always_register_metaboxes_on_admin', false) 26282632 ) { 26292633 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-metabox.php'); 26302634 $GLOBALS['wpmseo_metabox'] = new WPMSEOMetabox; 26312635 } 26322636 } 26332637 26342638 /** 26352639 * Update meta title , meta description , meta keyword for content 26362640 * 26372641 * @return void 26382642 */ 26392643 public function updateContentMetaCallback() 26402644 { 26412645 if (empty($_POST['wpms_nonce']) 26422646 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 26432647 die(); 26442648 } 26452649 26462650 if (!current_user_can('manage_options')) { 26472651 wp_send_json(array('status' => false)); 26482652 } 26492653 $_POST = stripslashes_deep($_POST); 26502654 $response = new stdClass(); 26512655 $metakey = strtolower(trim($_POST['metakey'])); 26522656 $postID = intval($_POST['postid']); 26532657 $value = trim($_POST['value']); 26542658 $response->msg = esc_html__('Modification was saved', 'wp-meta-seo'); 26552659 if ($metakey === 'metatitle') { 26562660 if (!update_post_meta($postID, '_metaseo_metatitle', $value)) { 26572661 $response->updated = false; 26582662 $response->msg = esc_html__('Meta title was not saved', 'wp-meta-seo'); 26592663 } else { 26602664 $response->updated = true; 26612665 $response->msg = esc_html__('Meta title was saved', 'wp-meta-seo'); 26622666 } 26632667 } 26642668 26652669 if ($metakey === 'metadesc') { 26662670 if (!update_post_meta($postID, '_metaseo_metadesc', $value)) { 26672671 $response->updated = false; 26682672 $response->msg = esc_html__('Meta description was not saved', 'wp-meta-seo'); 26692673 } else { 26702674 $response->updated = true; 26712675 $response->msg = esc_html__('Meta description was saved', 'wp-meta-seo'); 26722676 } 26732677 } 26742678 26752679 if ($metakey === 'metakeywords') { 26762680 if (!update_post_meta($postID, '_metaseo_metakeywords', $value)) { 26772681 $response->updated = false; 26782682 $response->msg = esc_html__('Meta keywords was not saved', 'wp-meta-seo'); 26792683 } else { 26802684 $response->updated = true; 26812685 $response->msg = esc_html__('Meta keywords was saved', 'wp-meta-seo'); 26822686 } 26832687 } 26842688 update_option('wpms_last_update_post', time()); 26852689 echo json_encode($response); 26862690 wp_die(); 26872691 } 26882692 26892693 /** 26902694 * Loads js/ajax scripts 26912695 * 26922696 * @return void 26932697 */ 26942698 public function loadAdminScripts() 26952699 { 26962700 global $pagenow, $current_screen; 26972701 wp_enqueue_script('jquery'); 26982702 $array_menu = array( 26992703 'wp-meta-seo_page_metaseo_dashboard', 27002704 'wp-meta-seo_page_metaseo_image_optimize', 27012705 'wp-meta-seo_page_metaseo_google_sitemap', 27022706 'wp-meta-seo_page_metaseo_image_compression', 27032707 'wp-meta-seo_page_metaseo_broken_link', 27042708 'wp-meta-seo_page_metaseo_settings', 27052709 'wp-meta-seo_page_metaseo_content_meta', 27062710 'wp-meta-seo_page_metaseo_category_meta', 27072711 'wp-meta-seo_page_metaseo_image_meta', 27082712 'wp-meta-seo_page_metaseo_link_meta' 27092713 ); 27102714 27112715 $lists_pages = array( 27122716 'toplevel_page_metaseo_dashboard', 27132717 'wp-meta-seo_page_metaseo_content_meta', 27142718 'wp-meta-seo_page_metaseo_category_meta', 27152719 'wp-meta-seo_page_metaseo_google_sitemap', 27162720 'wp-meta-seo_page_metaseo_image_meta', 27172721 'wp-meta-seo_page_metaseo_link_meta', 27182722 'wp-meta-seo_page_metaseo_broken_link', 27192723 'wp-meta-seo_page_metaseo_console', 27202724 'wp-meta-seo_page_metaseo_google_analytics', 27212725 'wp-meta-seo_page_metaseo_sendemail', 27222726 'wp-meta-seo_page_metaseo_settings' 27232727 ); 27242728 27252729 wp_enqueue_style( 27262730 'metaseo-google-icon', 27272731 '//fonts.googleapis.com/icon?family=Material+Icons' 27282732 ); 27292733 27302734 if (!empty($current_screen) && in_array($current_screen->base, $lists_pages)) { 27312735 wp_enqueue_style( 27322736 'wpms-magnific-popup-style', 27332737 plugins_url('assets/css/magnific-popup.css', dirname(__FILE__)), 27342738 array(), 27352739 WPMSEO_VERSION 27362740 ); 27372741 27382742 wp_enqueue_style( 27392743 'wpms_ju_waves_css', 27402744 plugins_url('assets/wordpress-css-framework/css/waves.min.css', dirname(__FILE__)), 27412745 array(), 27422746 WPMSEO_VERSION 27432747 ); 27442748 27452749 wp_enqueue_script( 27462750 'wpms-magnific-popup-script', 27472751 plugins_url('assets/js/jquery.magnific-popup.min.js', dirname(__FILE__)), 27482752 array(), 27492753 WPMSEO_VERSION 27502754 ); 27512755 27522756 wp_enqueue_style( 27532757 'wpms_ju_framework_styles', 27542758 plugins_url('assets/wordpress-css-framework/css/style.min.css', dirname(__FILE__)), 27552759 array(), 27562760 WPMSEO_VERSION 27572761 ); 27582762 27592763 wp_enqueue_script( 27602764 'wpms_ju_velocity_js', 27612765 plugins_url('assets/wordpress-css-framework/js/velocity.min.js', dirname(__FILE__)), 27622766 array(), 27632767 WPMSEO_VERSION 27642768 ); 27652769 wp_enqueue_script( 27662770 'wpms_ju_waves_js', 27672771 plugins_url('assets/wordpress-css-framework/js/waves.min.js', dirname(__FILE__)), 27682772 array(), 27692773 WPMSEO_VERSION 27702774 ); 27712775 27722776 wp_enqueue_script( 27732777 'wpms_ju_tabs_js', 27742778 plugins_url('assets/wordpress-css-framework/js/tabs.js', dirname(__FILE__)), 27752779 array(), 27762780 WPMSEO_VERSION 27772781 ); 27782782 27792783 wp_enqueue_script( 27802784 'wpms_ju_framework_js', 27812785 plugins_url('assets/wordpress-css-framework/js/script.js', dirname(__FILE__)), 27822786 array('wpms_ju_tabs_js'), 27832787 WPMSEO_VERSION 27842788 ); 27852789 27862790 if ($current_screen->base !== 'wp-meta-seo_page_metaseo_settings') { 27872791 wp_enqueue_style( 27882792 'wpms_materialize_style', 27892793 plugins_url('assets/css/materialize/materialize.css', dirname(__FILE__)), 27902794 array(), 27912795 WPMSEO_VERSION 27922796 ); 27932797 } else { 27942798 // Register CSS 27952799 wp_enqueue_style( 27962800 'wpms-settings-styles', 27972801 plugins_url('assets/css/settings.css', dirname(__FILE__)), 27982802 array('wpms_main'), 27992803 WPMSEO_VERSION 28002804 ); 28012805 28022806 wp_enqueue_script( 28032807 'wpms-settings-script', 28042808 plugins_url('assets/js/settings.js', dirname(__FILE__)), 28052809 array('jquery'), 28062810 WPMSEO_VERSION, 28072811 true 28082812 ); 28092813 28102814 wp_localize_script('wpms-settings-script', 'wpmsSettingsL10n', array( 28112815 'choose_image' => esc_html__('Use Image', 'wp-meta-seo') 28122816 )); 28132817 } 28142818 28152819 wp_enqueue_style( 28162820 'wpms_main', 28172821 plugins_url('assets/css/main.css', dirname(__FILE__)), 28182822 array(), 28192823 WPMSEO_VERSION 28202824 ); 28212825 } 28222826 28232827 wp_enqueue_script( 28242828 'wpmetaseoAdmin', 28252829 plugins_url('assets/js/metaseo_admin.js', dirname(__FILE__)), 28262830 array('jquery'), 28272831 WPMSEO_VERSION, 28282832 true 28292833 ); 28302834 28312835 if (!empty($current_screen) && (in_array($current_screen->base, $array_menu) || $pagenow === 'post.php' || $pagenow === 'post-new.php')) { 28322836 wp_enqueue_style( 28332837 'wpmetaseoAdmin', 28342838 plugins_url('assets/css/metaseo_admin.css', dirname(__FILE__)), 28352839 array(), 28362840 WPMSEO_VERSION 28372841 ); 28382842 wp_enqueue_style( 28392843 'tooltip-metaimage', 28402844 plugins_url('assets/css/tooltip-metaimage.css', dirname(__FILE__)), 28412845 array(), 28422846 WPMSEO_VERSION 28432847 ); 28442848 28452849 wp_enqueue_style('style', plugins_url('assets/css/style.css', dirname(__FILE__)), array(), WPMSEO_VERSION); 28462850 } 28472851 28482852 if (!empty($current_screen) && ($current_screen->base === 'wp-meta-seo_page_metaseo_image_meta' 28492853 || $current_screen->base === 'wp-meta-seo_page_metaseo_content_meta')) { 28502854 wp_enqueue_script( 28512855 'wpms-bulk', 28522856 plugins_url('assets/js/wpms-bulk-action.js', dirname(__FILE__)), 28532857 array('jquery'), 28542858 WPMSEO_VERSION, 28552859 true 28562860 ); 28572861 wp_localize_script('wpms-bulk', 'wpmseobulkL10n', $this->localizeScript()); 28582862 } 28592863 28602864 if (!empty($current_screen) && $current_screen->base === 'wp-meta-seo_page_metaseo_broken_link') { 28612865 wp_enqueue_style( 28622866 'wpms_brokenlink_style', 28632867 plugins_url('assets/css/broken_link.css', dirname(__FILE__)), 28642868 array(), 28652869 WPMSEO_VERSION 28662870 ); 28672871 28682872 wp_enqueue_style( 28692873 'wpms-bootstrap-style', 28702874 plugins_url('assets/css/bootstrap/bootstrap.min.css', dirname(__FILE__)), 28712875 array(), 28722876 WPMSEO_VERSION 28732877 ); 28742878 28752879 wp_enqueue_style( 28762880 'wpms-bootstrap-multiselect-style', 28772881 plugins_url('assets/css/bootstrap/bootstrap-multiselect.css', dirname(__FILE__)), 28782882 array(), 28792883 WPMSEO_VERSION 28802884 ); 28812885 28822886 wp_enqueue_script( 28832887 'wpms-bootstrap-multiselect-script', 28842888 plugins_url('assets/css/bootstrap/bootstrap-multiselect.js', dirname(__FILE__)), 28852889 array('jquery'), 28862890 WPMSEO_VERSION, 28872891 true 28882892 ); 28892893 } 28902894 28912895 if (!empty($current_screen) && $current_screen->base === 'toplevel_page_metaseo_dashboard') { 28922896 wp_enqueue_script( 28932897 'metaseo-dashboard', 28942898 plugins_url('assets/js/dashboard.js', dirname(__FILE__)), 28952899 array('jquery'), 28962900 WPMSEO_VERSION, 28972901 true 28982902 ); 28992903 29002904 wp_enqueue_style( 29012905 'metaseo-quirk', 29022906 plugins_url('assets/css/metaseo-quirk.css', dirname(__FILE__)) 29032907 ); 29042908 29052909 wp_enqueue_style( 29062910 'm-style-dashboard', 29072911 plugins_url('assets/css/dashboard.css', dirname(__FILE__)), 29082912 array(), 29092913 WPMSEO_VERSION 29102914 ); 29112915 29122916 wp_enqueue_style( 29132917 'wpms-ju-css-framwork', 29142918 plugins_url('assets/css/main.css', dirname(__FILE__)), 29152919 array(), 29162920 WPMSEO_VERSION 29172921 ); 29182922 29192923 if (class_exists('MetaSeoAddonAdmin')) { 29202924 wp_enqueue_style( 29212925 'msaddon-style-dashboard', 29222926 WPMETASEO_ADDON_PLUGIN_URL . 'assets/css/dashboard.css', 29232927 array(), 29242928 WPMSEO_ADDON_VERSION 29252929 ); 29262930 } 29272931 } 29282932 29292933 if (!empty($current_screen) && $current_screen->base === 'wp-meta-seo_page_metaseo_better_ranking') { 29302934 wp_enqueue_style( 29312935 'wpms-better-seo', 29322936 plugins_url('assets/css/better_seo.css', dirname(__FILE__)), 29332937 array(), 29342938 WPMSEO_VERSION 29352939 ); 29362940 29372941 wp_enqueue_style( 29382942 'wpms-ju-css-framwork', 29392943 plugins_url('assets/css/main.css', dirname(__FILE__)), 29402944 array(), 29412945 WPMSEO_VERSION 29422946 ); 29432947 } 29442948 29452949 $lists_pages = array( 29462950 'toplevel_page_metaseo_dashboard', 29472951 'wp-meta-seo_page_metaseo_google_sitemap', 29482952 'wp-meta-seo_page_metaseo_link_meta', 29492953 'wp-meta-seo_page_metaseo_broken_link', 29502954 'wp-meta-seo_page_metaseo_google_analytics' 29512955 ); 29522956 if (!empty($current_screen) && in_array($current_screen->base, $lists_pages)) { 29532957 wp_enqueue_style( 29542958 'wpms_notification_style', 29552959 plugins_url('assets/css/notification.css', dirname(__FILE__)), 29562960 array(), 29572961 WPMSEO_VERSION 29582962 ); 29592963 wp_enqueue_script( 29602964 'wpms_notification_script', 29612965 plugins_url('assets/js/notification.js', dirname(__FILE__)), 29622966 array(), 29632967 WPMSEO_VERSION 29642968 ); 29652969 } 29662970 29672971 wp_register_style( 29682972 'wpms-dashboard-widgets', 29692973 plugins_url('assets/css/dashboard-widgets/dashboard_widgets.css', dirname(__FILE__)), 29702974 null, 29712975 WPMSEO_VERSION 29722976 ); 29732977 wp_register_style( 29742978 'wpms-category-field', 29752979 plugins_url('assets/css/category_field.css', dirname(__FILE__)), 29762980 null, 29772981 WPMSEO_VERSION 29782982 ); 29792983 wp_register_script( 29802984 'wpms-category-field', 29812985 plugins_url('assets/js/category_field.js', dirname(__FILE__)), 29822986 array('jquery'), 29832987 WPMSEO_VERSION, 29842988 true 29852989 ); 29862990 29872991 // Enqueue for category meta page 29882992 if (!empty($current_screen) && $current_screen->base === 'wp-meta-seo_page_metaseo_category_meta') { 29892993 wp_enqueue_style( 29902994 'wpmsCategoryMeta', 29912995 plugins_url('assets/css/metaseo-category-meta-bulk.css', dirname(__FILE__)), 29922996 array(), 29932997 WPMSEO_VERSION 29942998 ); 29952999 29963000 wp_enqueue_script( 29973001 'wpmsCategoryMeta', 29983002 plugins_url('assets/js/wpms-category-meta.js', dirname(__FILE__)), 29993003 array('jquery'), 30003004 WPMSEO_VERSION, 30013005 true 30023006 ); 30033007 wp_enqueue_script('wpms-category-field'); 30043008 } 30053009 30063010 wp_register_style( 30073011 'wpms-tippy-style', 30083012 plugins_url('assets/tippy/tippy.css', dirname(__FILE__)), 30093013 array(), 30103014 WPMSEO_VERSION 30113015 ); 30123016 30133017 wp_register_script( 30143018 'wpms-tippy-core', 30153019 plugins_url('assets/tippy/tippy-core.js', dirname(__FILE__)), 30163020 array('jquery'), 30173021 '2.2.1', 30183022 true 30193023 ); 30203024 30213025 wp_register_script( 30223026 'wpms-tippy', 30233027 plugins_url('assets/tippy/tippy.js', dirname(__FILE__)), 30243028 array('jquery'), 30253029 '2.2.1', 30263030 true 30273031 ); 30283032 30293033 wp_register_script( 30303034 'wpms-my-tippy', 30313035 plugins_url('assets/tippy/my-tippy.js', dirname(__FILE__)), 30323036 array('jquery'), 30333037 WPMSEO_VERSION, 30343038 true 30353039 ); 30363040 30373041 wp_enqueue_style( 30383042 'wpms-mytippy-style', 30393043 plugins_url('assets/tippy/my-tippy.css', dirname(__FILE__)), 30403044 array(), 30413045 WPMSEO_VERSION 30423046 ); 30433047 // Register snackbar script alert 30443048 wp_register_script( 30453049 'wpms-snackbar-script', 30463050 plugins_url('assets/js/snackbar.js', dirname(__FILE__)), 30473051 array('jquery'), 30483052 WPMSEO_VERSION, 30493053 true 30503054 ); 30513055 // Register snackbar style alert 30523056 wp_register_style( 30533057 'wpms-snackbar-style', 30543058 plugins_url('assets/css/snackbar.css', dirname(__FILE__)), 30553059 array(), 30563060 WPMSEO_VERSION 30573061 ); 30583062 wp_register_script( 30593063 'wpms-broken-link', 30603064 plugins_url('assets/js/wpms-broken-link.js', dirname(__FILE__)), 30613065 array('jquery'), 30623066 WPMSEO_VERSION, 30633067 true 30643068 ); 30653069 30663070 wp_register_style('metaseo-google-icon', '//fonts.googleapis.com/icon?family=Material+Icons'); 30673071 if (!empty($current_screen) && $current_screen->base === 'wp-meta-seo_page_metaseo_google_analytics') { 30683072 $lang = get_bloginfo('language'); 30693073 $lang = explode('-', $lang); 30703074 $lang = $lang[0]; 30713075 wp_enqueue_style( 30723076 'wpms-nprogress', 30733077 plugins_url('assets/css/google-analytics/nprogress.css', dirname(__FILE__)), 30743078 null, 30753079 WPMSEO_VERSION 30763080 ); 30773081 30783082 wp_register_style( 30793083 'wpms-backend-item-reports', 30803084 plugins_url('assets/css/google-analytics/admin-widgets.css', dirname(__FILE__)), 30813085 null, 30823086 WPMSEO_VERSION 30833087 ); 30843088 wp_register_style( 30853089 'wpms-backend-tracking-code', 30863090 plugins_url('assets/css/google-analytics/wpms-tracking-code.css', dirname(__FILE__)), 30873091 null, 30883092 WPMSEO_VERSION 30893093 ); 30903094 30913095 wp_register_style( 30923096 'jquery-ui-tooltip-html', 30933097 plugins_url('assets/css/google-analytics/jquery.ui.tooltip.html.css', dirname(__FILE__)) 30943098 ); 30953099 30963100 wp_enqueue_style('jquery-ui-tooltip-html'); 30973101 30983102 wp_enqueue_script( 30993103 'wpmsgooglejsapi', 31003104 '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%22imagechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D', 31013105 array(), 31023106 null 31033107 ); 31043108 31053109 wp_enqueue_script( 31063110 'wpms-nprogress', 31073111 plugins_url('assets/js/google-analytics/nprogress.js', dirname(__FILE__)), 31083112 array('jquery'), 31093113 WPMSEO_VERSION 31103114 ); 31113115 31123116 wp_enqueue_script( 31133117 'wpms-google-analytics', 31143118 plugins_url('assets/js/google-analytics/google_analytics.js', dirname(__FILE__)), 31153119 array('jquery'), 31163120 WPMSEO_VERSION, 31173121 true 31183122 ); 31193123 31203124 // Select toolbar 31213125 require_once 'google_analytics/wpmstools.php'; 31223126 $wpms_google_analytics = get_option('wpms_google_alanytics'); 31233127 if (isset($wpms_google_analytics['tableid_jail']) && isset($wpms_google_analytics['profile_list'])) { 31243128 $wpms_profile = WpmsGaTools::getSelectedProfile($wpms_google_analytics['profile_list'], $wpms_google_analytics['tableid_jail']); 31253129 } 31263130 if (isset($wpms_profile[4])) { 31273131 $property_type = $wpms_profile[4]; 31283132 } else { 31293133 $property_type = 'UA'; 31303134 } 31313135 /* @formatter:off */ 31323136 wp_localize_script( 31333137 'wpms-google-analytics', 31343138 'wpmsItemData', 31353139 array( 31363140 'ajaxurl' => admin_url('admin-ajax.php'), 31373141 'security' => wp_create_nonce('wpms_backend_item_reports'), 31383142 'dateList' => array( 31393143 'realtime' => esc_html__('Real-Time', 'wp-meta-seo'), 31403144 'today' => esc_html__('Today', 'wp-meta-seo'), 31413145 'yesterday' => esc_html__('Yesterday', 'wp-meta-seo'), 31423146 '7daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 7), 31433147 '14daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 14), 31443148 '30daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 30), 31453149 '90daysAgo' => sprintf(esc_html__('Last %d Days', 'wp-meta-seo'), 90), 31463150 '365daysAgo' => sprintf(_n('%s Year', '%s Years', 1, 'wp-meta-seo'), esc_html__('One', 'wp-meta-seo')), 31473151 '1095daysAgo' => sprintf( 31483152 _n('%s Year', '%s Years', 3, 'wp-meta-seo'), 31493153 esc_html__('Three', 'wp-meta-seo') 31503154 ), 31513155 ), 31523156 'property_type' => $property_type, 31533157 'reportList' => array( 31543158 'sessions' => esc_html__('Sessions', 'wp-meta-seo'), 31553159 'users' => esc_html__('Users', 'wp-meta-seo'), 31563160 'organicSearches' => esc_html__('Organic', 'wp-meta-seo'), 31573161 'pageviews' => esc_html__('Page Views', 'wp-meta-seo'), 31583162 'visitBounceRate' => esc_html__('Bounce Rate', 'wp-meta-seo'), 31593163 'locations' => esc_html__('Location', 'wp-meta-seo'), 31603164 'contentpages' => esc_html__('Pages', 'wp-meta-seo'), 31613165 'referrers' => esc_html__('Referrers', 'wp-meta-seo'), 31623166 'searches' => esc_html__('Searches', 'wp-meta-seo'), 31633167 'trafficdetails' => esc_html__('Traffic', 'wp-meta-seo'), 31643168 'technologydetails' => esc_html__('Technology', 'wp-meta-seo'), 31653169 ), 31663170 'reportList_ga4' => array( 31673171 'sessions' => esc_html__('Sessions', 'wp-meta-seo'), 31683172 'users' => esc_html__('Users', 'wp-meta-seo'), 31693173 'pageviews' => esc_html__('Page Views', 'wp-meta-seo'), 31703174 'visitBounceRate' => esc_html__('Engagement', 'wp-meta-seo'), 31713175 'organicSearches' => esc_html__('Transactions', 'wp-meta-seo'), 31723176 'locations' => esc_html__('Location', 'wp-meta-seo'), 31733177 'contentpages' => esc_html__('Pages', 'wp-meta-seo'), 31743178 'referrers' => esc_html__('Referrers', 'wp-meta-seo'), 31753179 'searches' => esc_html__('Searches', 'wp-meta-seo'), 31763180 'trafficdetails' => esc_html__('Traffic', 'wp-meta-seo'), 31773181 'technologydetails' => esc_html__('Technology', 'wp-meta-seo'), 31783182 ), 31793183 'i18n' => array( 31803184 esc_html__('A JavaScript Error is blocking plugin resources!', 'wp-meta-seo'), //0 31813185 esc_html__('Traffic Mediums', 'wp-meta-seo'), 31823186 esc_html__('Visitor Type', 'wp-meta-seo'), 31833187 esc_html__('Search Engines', 'wp-meta-seo'), 31843188 esc_html__('Social Networks', 'wp-meta-seo'), 31853189 esc_html__('Sessions', 'wp-meta-seo'), //5 31863190 esc_html__('Users', 'wp-meta-seo'), 31873191 esc_html__('Page Views', 'wp-meta-seo'), 31883192 esc_html__('Bounce Rate', 'wp-meta-seo'), 31893193 esc_html__('Organic Search', 'wp-meta-seo'), 31903194 esc_html__('Pages/Session', 'wp-meta-seo'), //10 31913195 esc_html__('Invalid response', 'wp-meta-seo'), 31923196 esc_html__('Not enough data collected', 'wp-meta-seo'), 31933197 esc_html__('This report is unavailable', 'wp-meta-seo'), 31943198 esc_html__('report generated by', 'wp-meta-seo'), //14 31953199 esc_html__('This plugin needs an authorization:', 'wp-meta-seo') . ' 31963200 <a href="' . esc_html(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) . '"> 31973201 ' . esc_html__('authorize the plugin', 'wp-meta-seo') . '</a>.', 31983202 esc_html__('Browser', 'wp-meta-seo'), //16 31993203 esc_html__('Operating System', 'wp-meta-seo'), 32003204 esc_html__('Screen Resolution', 'wp-meta-seo'), 32013205 esc_html__('Mobile Brand', 'wp-meta-seo'), 32023206 esc_html__('REFERRALS', 'wp-meta-seo'), //20 32033207 esc_html__('KEYWORDS', 'wp-meta-seo'), 32043208 esc_html__('SOCIAL', 'wp-meta-seo'), 32053209 esc_html__('CAMPAIGN', 'wp-meta-seo'), 32063210 esc_html__('DIRECT', 'wp-meta-seo'), 32073211 esc_html__('NEW', 'wp-meta-seo'), //25 32083212 esc_html__('You need select a profile:', 'wp-meta-seo') . ' 32093213 <a href="' . esc_html(admin_url('admin.php?page=metaseo_google_analytics&view=wpmsga_trackcode')) . '"> 32103214 ' . esc_html__('authorize the plugin', 'wp-meta-seo') . '</a>.', 32113215 esc_html__('Engagement', 'wp-meta-seo'), 32123216 esc_html__('Transactions', 'wp-meta-seo'), 32133217 ), 32143218 'rtLimitPages' => 10, 32153219 'colorVariations' => array( 32163220 '#1e73be', 32173221 '#0459a4', 32183222 '#378cd7', 32193223 '#51a6f1', 32203224 '#00408b', 32213225 '#6abfff', 32223226 '#002671' 32233227 ), 32243228 'region' => false, 32253229 'language' => get_bloginfo('language'), 32263230 'viewList' => false, 32273231 'scope' => 'admin-widgets', 32283232 'admin_url' => admin_url() 32293233 ) 32303234 ); 32313235 32323236 wp_enqueue_script( 32333237 'wpms-cookie', 32343238 plugins_url('assets/js/jquery.cookie.js', dirname(__FILE__)), 32353239 array(), 32363240 '1.4.1' 32373241 ); 32383242 } 32393243 32403244 // Add intro text on each wpms topic 32413245 $tippy_pages = array( 32423246 'wp-meta-seo_page_metaseo_content_meta', 32433247 'wp-meta-seo_page_metaseo_category_meta', 32443248 'wp-meta-seo_page_metaseo_image_meta', 32453249 'wp-meta-seo_page_metaseo_google_sitemap', 32463250 'wp-meta-seo_page_metaseo_link_meta', 32473251 'wp-meta-seo_page_metaseo_broken_link', 32483252 'wp-meta-seo_page_metaseo_google_analytics', 32493253 'wp-meta-seo_page_metaseo_sendemail' 32503254 ); 32513255 if (!empty($current_screen) && in_array($current_screen->base, $tippy_pages)) { 32523256 wp_enqueue_style('wpms-tippy-style'); 32533257 wp_enqueue_script('wpms-tippy-core'); 32543258 wp_enqueue_script('wpms-tippy'); 32553259 wp_enqueue_script('wpms-my-tippy'); 32563260 } 32573261 32583262 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 32593263 $addon_active = 1; 32603264 } else { 32613265 $addon_active = 0; 32623266 } 32633267 // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value 32643268 wp_localize_script('wpmetaseoAdmin', 'wpms_localize', array( 32653269 'filter_by' => esc_html__('Select to filter', 'wp-meta-seo'), 32663270 'replaced' => esc_html__('Replaced', 'wp-meta-seo'), 32673271 'index_link' => esc_html__('Loading...', 'wp-meta-seo'), 32683272 'addon_active' => $addon_active, 32693273 'ajax_url' => admin_url('admin-ajax.php'), 32703274 'settings' => $this->settings, 32713275 'wpms_cat_metatitle_length' => MPMSCAT_TITLE_LENGTH, 32723276 'wpms_cat_metadesc_length' => MPMSCAT_DESC_LENGTH, 32733277 'wpms_cat_metakeywords_length' => MPMSCAT_KEYWORDS_LENGTH, 32743278 'wpms_nonce' => wp_create_nonce('wpms_nonce'), 32753279 'home_url' => home_url(), 32763280 'images_url' => WPMETASEO_PLUGIN_URL . 'assets/images/', 32773281 'dashboard_tooltips' => array( 32783282 'url_rewwrite' => esc_html__('Optimized at: ', 'wp-meta-seo'), 32793283 'images_resized' => esc_html__('HTML image resized (using handles) count: ', 'wp-meta-seo'), 32803284 'metatitle' => esc_html__('Meta title filled: ', 'wp-meta-seo'), 32813285 'image_alt' => esc_html__('Image data filled (in content): ', 'wp-meta-seo'), 32823286 'metadesc' => esc_html__('Meta description filled: ', 'wp-meta-seo'), 32833287 'link_title' => esc_html__('Links title completed: ', 'wp-meta-seo'), 32843288 'fresh_content' => esc_html__('Last month new or updated content: ', 'wp-meta-seo'), 32853289 'elements' => esc_html__(' elements', 'wp-meta-seo'), 32863290 'duplicate_title' => esc_html__('Duplicate Meta Titles: ', 'wp-meta-seo'), 32873291 'duplicate_desc' => esc_html__('Duplicate Meta Descriptions: ', 'wp-meta-seo'), 32883292 '404' => esc_html__('Redirected 404 errors: ', 'wp-meta-seo') 32893293 ), 32903294 'gg_disconnect_title' => array ( 32913295 'universal' => esc_html__('UA-Tracking ID', 'wp-meta-seo'), 32923296 'ga4' => esc_html__('Measurement ID', 'wp-meta-seo'), 32933297 'tagmanager' => esc_html__('Container ID', 'wp-meta-seo'), 32943298 ) 32953299 )); 32963300 32973301 32983302 $this->columnsEnqueue(); 32993303 } 33003304 33013305 /** 33023306 * Enqueue styles and scripts. 33033307 * 33043308 * @return void 33053309 */ 33063310 public function columnsEnqueue() 33073311 { 33083312 if (function_exists('get_current_screen')) { 33093313 $screen = get_current_screen(); 33103314 $allowed_post_types = self::getAccessiblePostTypes(); 33113315 33123316 if (!empty($current_screen) && !in_array($screen->post_type, $allowed_post_types, true)) { 33133317 return; 33143318 } 33153319 } 33163320 33173321 wp_enqueue_style( 33183322 'wpms-post-bulk-edit', 33193323 plugins_url('assets/css/wpms-post-bulk-edit.css', dirname(__FILE__)), 33203324 null, 33213325 WPMSEO_VERSION 33223326 ); 33233327 33243328 wp_enqueue_script( 33253329 'wpms-post-bulk-edit-js', 33263330 plugins_url('assets/js/wpms-post-bulk-edit.js', dirname(__FILE__)), 33273331 array('jquery'), 33283332 WPMSEO_VERSION, 33293333 true 33303334 ); 33313335 wp_localize_script('wpms-post-bulk-edit-js', 'wpms_post_bulk', array( 33323336 'title' => esc_attr__('Bulk Edit This Field', 'wp-meta-seo'), 33333337 'saveAll' => esc_attr__('Save all', 'wp-meta-seo'), 33343338 'cancelButton' => esc_attr__('Cancel all', 'wp-meta-seo'), 33353339 'nonce' => wp_create_nonce('wpms_nonce') 33363340 )); 33373341 } 33383342 33393343 /** 33403344 * Add content for title column. 33413345 * 33423346 * @param integer $post_id The current post ID. 33433347 * 33443348 * @return void 33453349 */ 33463350 public function getColumnSeoKeywordsDetails($post_id) 33473351 { 33483352 $score = get_post_meta($post_id, 'wp_metaseo_seoscore', true); 33493353 $keywords = get_post_meta($post_id, '_metaseo_metaspecific_keywords', true); 33503354 $class = !empty($score) ? $this->getScoreClass((int)$score) : 'wpms-no-score'; 33513355 $score = !empty($score) ? $score . ' / 100' : 'N/A'; 33523356 33533357 ?> 33543358 <span class="wpms-column-display score <?php echo esc_attr($class); ?> <?php echo empty($score) ? 'disabled' : ''; ?>"> 33553359 <strong><?php echo esc_html($score); ?></strong> 33563360 </span> 33573361 <span class="wpms-column-display keyword" <?php echo (empty($keywords)) ? 'style="display:none"' : ''; ?> > 33583362 <strong title="SEO Keyword" class="title"><?php esc_html_e('Keyword', 'wp-meta-seo'); ?>:</strong> 33593363 <span><?php echo $keywords ? esc_html($keywords) : ''; ?></span> 33603364 </span> 33613365 <span class="wpms-column-value" data-field="seo_keyword" contenteditable="true" tabindex="11"> 33623366 <span><?php echo esc_html($keywords); ?></span> 33633367 </span> 33643368 <div class="wpms-column-edit"> 33653369 <a href="#" class="wpms-column-save"><?php esc_html_e('Save', 'wp-meta-seo'); ?></a> 33663370 <a href="#" class="button-link-delete wpms-column-cancel"><?php esc_html_e('Cancel', 'wp-meta-seo'); ?></a> 33673371 </div> 33683372 <?php 33693373 } 33703374 33713375 /** 33723376 * Get SEO score rating string: great/good/bad. 33733377 * 33743378 * @param integer $score Score. 33753379 * 33763380 * @return string 33773381 */ 33783382 private function getScoreClass($score) 33793383 { 33803384 if ($score > 75) { 33813385 return 'wpms-great-score'; 33823386 } 33833387 33843388 return 'wpms-bad-score'; 33853389 } 33863390 33873391 /** 33883392 * Register post column hooks. 33893393 * 33903394 * @return void 33913395 */ 33923396 public function registerPostColumns() 33933397 { 33943398 foreach (self::getAccessiblePostTypes() as $post_type) { 33953399 add_filter('edd_download_columns', array($this, 'addColumns'), 11); 33963400 add_filter('manage_' . $post_type . '_posts_columns', array($this, 'addColumns'), 11); 33973401 33983402 33993403 add_action('manage_' . $post_type . '_posts_custom_column', array($this, 'columnsContents'), 11, 2); 34003404 add_filter('manage_edit-' . $post_type . '_sortable_columns', array($this, 'sortableColumns'), 11); 34013405 } 34023406 } 34033407 34043408 /** 34053409 * Make the SEO Score column sortable. 34063410 * 34073411 * @param array $columns Array of column names. 34083412 * 34093413 * @return array 34103414 */ 34113415 public function sortableColumns($columns) 34123416 { 34133417 34143418 $columns['metaseo_seokeywords_details_column'] = 'wp_metaseo_seoscore'; 34153419 34163420 return $columns; 34173421 } 34183422 34193423 /** 34203424 * Add content for custom column. 34213425 * 34223426 * @param string $column_name The name of the column to display. 34233427 * @param integer $post_id The current post ID. 34243428 * 34253429 * @return void 34263430 */ 34273431 public function columnsContents($column_name, $post_id) 34283432 { 34293433 do_action($column_name, $post_id); 34303434 } 34313435 34323436 /** 34333437 * Add new columns for SEO title, description and focus keywords. 34343438 * 34353439 * @param array $columns Array of column names. 34363440 * 34373441 * @return array 34383442 */ 34393443 public function addColumns($columns) 34403444 { 34413445 $columns['metaseo_seokeywords_details_column'] = esc_html__('SEO score', 'wp-meta-seo'); 34423446 34433447 return $columns; 34443448 } 34453449 34463450 /** 34473451 * Get post types that are public and not set to noindex. 34483452 * 34493453 * @codeCoverageIgnore 34503454 * 34513455 * @return array All the accessible post types. 34523456 */ 34533457 public static function getAccessiblePostTypes() 34543458 { 34553459 static $accessible_post_types; 34563460 34573461 if (isset($accessible_post_types) && did_action('wp_loaded')) { 34583462 return $accessible_post_types; 34593463 } 34603464 34613465 $accessible_post_types = get_post_types(array('public' => true)); 34623466 $accessible_post_types = array_filter($accessible_post_types, 'is_post_type_viewable'); 34633467 34643468 if (!is_array($accessible_post_types)) { 34653469 $accessible_post_types = array(); 34663470 } 34673471 34683472 if (isset($accessible_post_types['elementor_library'])) { 34693473 unset($accessible_post_types['elementor_library']); 34703474 } 34713475 34723476 return $accessible_post_types; 34733477 } 34743478 34753479 /** 34763480 * Update post meta keywords 34773481 * 34783482 * @return void 34793483 */ 34803484 public function updateSeokeywordBulkEdit() 34813485 { 34823486 if (empty($_POST['wpms_nonce']) 34833487 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 34843488 die(); 34853489 } 34863490 34873491 if (!isset($_POST['listData']) || empty($_POST['listData'])) { 34883492 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 34893493 wp_die(__('Unspecified list data', 'wp-meta-seo')); 34903494 } 34913495 34923496 $result = array(); 34933497 foreach ($_POST['listData'] as $data) { 34943498 if (empty($data['idpost'])) { 34953499 continue; 34963500 } 34973501 34983502 $circliful = $this->doAnalysisFromBulkEdit((int)$data['idpost'], $data['keyword']); 34993503 update_post_meta((int)$data['idpost'], '_metaseo_metaspecific_keywords', $data['keyword']); 35003504 update_post_meta((int)$data['idpost'], 'wp_metaseo_seoscore', $circliful); 35013505 $result[(int)$data['idpost']] = array($circliful, $data['keyword']); 35023506 } 35033507 35043508 wp_send_json(array('status' => true, 'res_back' => $result)); 35053509 } 35063510 35073511 /** 35083512 * Ajax load analysis from post edit 35093513 * 35103514 * @param integer $post_id Id post 35113515 * @param string $keywords Keyword search 35123516 * 35133517 * @return mixed 35143518 */ 35153519 public function doAnalysisFromBulkEdit($post_id, $keywords) 35163520 { 35173521 if (empty($_POST['wpms_nonce']) || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 35183522 die(); 35193523 } 35203524 35213525 if (!current_user_can('edit_posts')) { 35223526 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 35233527 wp_die(__('There is no edit permission here', 'wp-meta-seo')); 35243528 } 35253529 35263530 $content_post = get_post($post_id); 35273531 $content = apply_filters('the_content', $content_post->post_content); 35283532 $title = !(empty($content_post->post_title)) ? $content_post->post_title : null; 35293533 $meta_title = get_post_meta($post_id, '_metaseo_metatitle', true); 35303534 $meta_desc = get_post_meta($post_id, '_metaseo_metadesc', true); 35313535 $check = 0; 35323536 35333537 // title heading 35343538 $words_post_title = preg_split( 35353539 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 35363540 strtolower($title), 35373541 -1, 35383542 PREG_SPLIT_NO_EMPTY 35393543 ); 35403544 35413545 // do shortcode js_composer plugin 35423546 if (is_plugin_active('js_composer_theme/js_composer.php')) { 35433547 add_shortcode('mk_fancy_title', 'vc_do_shortcode'); 35443548 } 35453549 35463550 $content = apply_filters('wpms_the_content', '<div>' . html_entity_decode(stripcslashes($content), ENT_COMPAT, 'UTF-8') . '</div>', $post_id); 35473551 $content = $this->injectAcfField($content, $post_id); 35483552 $content = $this->injectWooCommerce($content, $post_id); 35493553 35503554 if ($content !== '') { 35513555 // Extracting the specified elements from the web page 35523556 $tags_h1 = wpmsExtractTags($content, 'h1', false, true); 35533557 $tags_h2 = wpmsExtractTags($content, 'h2', false, true); 35543558 $tags_h3 = wpmsExtractTags($content, 'h3', false, true); 35553559 $tags_h4 = wpmsExtractTags($content, 'h4', false, true); 35563560 $tags_h5 = wpmsExtractTags($content, 'h5', false, true); 35573561 $tags_h6 = wpmsExtractTags($content, 'h6', false, true); 35583562 35593563 $test = false; 35603564 if (empty($tags_h1) && empty($tags_h2) && empty($tags_h3) 35613565 && empty($tags_h4) && empty($tags_h5) && empty($tags_h6)) { 35623566 $test = false; 35633567 } else { 35643568 // check tag h1 35653569 if (!empty($tags_h1)) { 35663570 foreach ($tags_h1 as $order => $tagh1) { 35673571 $words_tagh1 = preg_split( 35683572 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 35693573 utf8_decode(strtolower($tagh1['contents'])), 35703574 -1, 35713575 PREG_SPLIT_NO_EMPTY 35723576 ); 35733577 35743578 if (is_array($words_tagh1) && is_array($words_post_title)) { 35753579 foreach ($words_tagh1 as $mh) { 35763580 if (in_array($mh, $words_post_title) && $mh !== '') { 35773581 $test = true; 35783582 } 35793583 } 35803584 } 35813585 } 35823586 } 35833587 35843588 // check tag h2 35853589 if (!empty($tags_h2)) { 35863590 foreach ($tags_h2 as $order => $tagh2) { 35873591 $words_tagh2 = preg_split( 35883592 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 35893593 utf8_decode(strtolower($tagh2['contents'])), 35903594 -1, 35913595 PREG_SPLIT_NO_EMPTY 35923596 ); 35933597 if (is_array($words_tagh2) && is_array($words_post_title)) { 35943598 foreach ($words_tagh2 as $mh) { 35953599 if (in_array($mh, $words_post_title) && $mh !== '') { 35963600 $test = true; 35973601 } 35983602 } 35993603 } 36003604 } 36013605 } 36023606 36033607 // check tag h3 36043608 if (!empty($tags_h3)) { 36053609 foreach ($tags_h3 as $order => $tagh3) { 36063610 $words_tagh3 = preg_split( 36073611 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36083612 utf8_decode(strtolower($tagh3['contents'])), 36093613 -1, 36103614 PREG_SPLIT_NO_EMPTY 36113615 ); 36123616 if (is_array($words_tagh3) && is_array($words_post_title)) { 36133617 foreach ($words_tagh3 as $mh) { 36143618 if (in_array($mh, $words_post_title) && $mh !== '') { 36153619 $test = true; 36163620 } 36173621 } 36183622 } 36193623 } 36203624 } 36213625 36223626 // check tag h4 36233627 if (!empty($tags_h4)) { 36243628 foreach ($tags_h4 as $order => $tagh4) { 36253629 $words_tagh4 = preg_split( 36263630 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36273631 utf8_decode(strtolower($tagh4['contents'])), 36283632 -1, 36293633 PREG_SPLIT_NO_EMPTY 36303634 ); 36313635 if (is_array($words_tagh4) && is_array($words_post_title)) { 36323636 foreach ($words_tagh4 as $mh) { 36333637 if (in_array($mh, $words_post_title) && $mh !== '') { 36343638 $test = true; 36353639 } 36363640 } 36373641 } 36383642 } 36393643 } 36403644 36413645 // check tag h5 36423646 if (!empty($tags_h5)) { 36433647 foreach ($tags_h5 as $order => $tagh5) { 36443648 $words_tagh5 = preg_split( 36453649 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36463650 utf8_decode(strtolower($tagh5['contents'])), 36473651 -1, 36483652 PREG_SPLIT_NO_EMPTY 36493653 ); 36503654 if (is_array($words_tagh5) && is_array($words_post_title)) { 36513655 foreach ($words_tagh5 as $mh) { 36523656 if (in_array($mh, $words_post_title) && $mh !== '') { 36533657 $test = true; 36543658 } 36553659 } 36563660 } 36573661 } 36583662 } 36593663 36603664 // check tag h6 36613665 if (!empty($tags_h6)) { 36623666 foreach ($tags_h6 as $order => $tagh6) { 36633667 $words_tagh6 = preg_split( 36643668 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36653669 utf8_decode(strtolower($tagh6['contents'])), 36663670 -1, 36673671 PREG_SPLIT_NO_EMPTY 36683672 ); 36693673 if (is_array($words_tagh6) && is_array($words_post_title)) { 36703674 foreach ($words_tagh6 as $mh) { 36713675 if (in_array($mh, $words_post_title) && $mh !== '') { 36723676 $test = true; 36733677 } 36743678 } 36753679 } 36763680 } 36773681 } 36783682 } 36793683 36803684 if ($test) { 36813685 $check++; 36823686 } 36833687 } 36843688 36853689 // title content 36863690 $words_title = preg_split( 36873691 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36883692 strtolower($title), 36893693 -1, 36903694 PREG_SPLIT_NO_EMPTY 36913695 ); 36923696 $words_post_content = preg_split( 36933697 '/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))/', 36943698 strtolower(strip_tags($content)), 36953699 -1, 36963700 PREG_SPLIT_NO_EMPTY 36973701 ); 36983702 36993703 $test1 = false; 37003704 if (is_array($words_title) && is_array($words_post_content)) { 37013705 foreach ($words_title as $mtitle) { 37023706 if (in_array($mtitle, $words_post_content) && $mtitle !== '') { 37033707 $test1 = true; 37043708 break; 37053709 } 37063710 } 37073711 } else { 37083712 $test1 = false; 37093713 } 37103714 37113715 if ($test1) { 37123716 $check++; 37133717 } 37143718 37153719 // page url matches page title 37163720 $mtitle = $title; 37173721 $pageurl = pathinfo(get_permalink($post_id)); 37183722 $mpageurl = $pageurl['filename']; 37193723 37203724 if (!empty($mpageurl) && !empty($mtitle) && $mpageurl === sanitize_title($mtitle)) { 37213725 $check++; 37223726 } 37233727 37243728 // meta title filled 37253729 if (($meta_title !== '' && mb_strlen($meta_title, 'UTF-8') <= self::$title_length)) { 37263730 $check++; 37273731 } 37283732 37293733 // desc filled 37303734 if ($meta_desc !== '' && mb_strlen($meta_desc, 'UTF-8') <= self::$desc_length) { 37313735 $check++; 37323736 } 37333737 37343738 // image resize 37353739 if ($content === '') { 37363740 $check += 2; 37373741 } else { 37383742 // Extracting the specified elements from the web page 37393743 $img_tags = wpmsExtractTags($content, 'img', true, true); 37403744 $img_wrong = false; 37413745 $img_wrong_alt = false; 37423746 foreach ($img_tags as $order => $tag) { 37433747 if (!isset($tag['attributes']['src'])) { 37443748 continue; 37453749 } 37463750 37473751 $src = $tag['attributes']['src']; 37483752 $imgpath = str_replace(site_url(), ABSPATH, $src); 37493753 if (!file_exists($imgpath)) { 37503754 continue; 37513755 } 37523756 if (!list($width_origin, $height_origin) = getimagesize($imgpath)) { 37533757 continue; 37543758 } 37553759 37563760 if (empty($tag['attributes']['width']) && empty($tag['attributes']['height'])) { 37573761 $img_wrong = false; 37583762 } else { 37593763 if (!empty($width_origin) && !empty($height_origin)) { 37603764 if ((isset($tag['attributes']['width']) && (int)$width_origin !== (int)$tag['attributes']['width']) 37613765 || (isset($tag['attributes']['height']) && (int)$height_origin !== (int)$tag['attributes']['height'])) { 37623766 $img_wrong = true; 37633767 } 37643768 } 37653769 } 37663770 37673771 if (empty($tag['attributes']['alt'])) { 37683772 $img_wrong_alt = true; 37693773 } 37703774 } 37713775 37723776 if (!$img_wrong) { 37733777 $check++; 37743778 } 37753779 37763780 37773781 if (!$img_wrong_alt) { 37783782 $check++; 37793783 } 37803784 } 37813785 37823786 $total_check = 7; 37833787 if (!empty($keywords)) { 37843788 $total_check++; 37853789 37863790 $listkeywords = array_map('trim', explode(',', strtolower($keywords))); 37873791 37883792 foreach ($listkeywords as $key) { 37893793 if (strpos(strtolower($title), $key) !== false) { 37903794 $check++; 37913795 break; 37923796 } 37933797 37943798 if (strpos(strtolower($content), $key) !== false) { 37953799 $check++; 37963800 break; 37973801 } 37983802 37993803 if (strpos(strtolower($meta_title), $key) !== false) { 38003804 $check++; 38013805 break; 38023806 } 38033807 38043808 if (strpos(strtolower($meta_desc), $key) !== false) { 38053809 $check++; 38063810 break; 38073811 } 38083812 38093813 $pattern = '/<h[2-6][^>]*>.*' . $key . '.*<\/h[2-6]>/'; 38103814 if (preg_match($pattern, $content)) { 38113815 $check++; 38123816 break; 38133817 } 38143818 } 38153819 } 38163820 38173821 $circliful = ceil(100 * ($check) / $total_check); 38183822 38193823 return $circliful; 38203824 } 38213825 38223826 /** 38233827 * Localize a script. 38243828 * 38253829 * Works only if the script has already been added. 38263830 * 38273831 * @return array 38283832 */ 38293833 public function localizeScript() 38303834 { 38313835 return array( 38323836 'metaseo_message_false_copy' => esc_html__('Warning, you\'re about to replace existing image 38333837 alt or tile content, are you sire about that?', 'wp-meta-seo'), 38343838 ); 38353839 } 38363840 38373841 /** 38383842 * Add a top-level menu page. 38393843 * 38403844 * This function takes a capability which will be used to determine whether 38413845 * or not a page is included in the menu. 38423846 * 38433847 * @return void 38443848 */ 38453849 public function addMenuPage() 38463850 { 38473851 // Add main page 38483852 add_menu_page( 38493853 esc_html__('WP Meta SEO: Dashboard', 'wp-meta-seo'), 38503854 esc_html__('WP Meta SEO', 'wp-meta-seo'), 38513855 'manage_options', 38523856 'metaseo_dashboard', 38533857 array( 38543858 $this, 38553859 'loadPage' 38563860 ), 38573861 'dashicons-chart-area' 38583862 ); 38593863 38603864 /** 38613865 * Allow changing the capability users need to view the settings pages 38623866 * 38633867 * @return string 38643868 * @api string Default capability 38653869 */ 38663870 $manage_options_cap = apply_filters('metaseo_manage_options_capability', 'manage_options'); 38673871 38683872 // Sub menu pages 38693873 $submenu_pages = array( 38703874 array( 38713875 'metaseo_dashboard', 38723876 '', 38733877 esc_html__('Dashboard', 'wp-meta-seo'), 38743878 $manage_options_cap, 38753879 'metaseo_dashboard', 38763880 array($this, 'loadPage'), 38773881 null 38783882 ), 38793883 array( 38803884 'metaseo_dashboard', 38813885 '', 38823886 esc_html__('Content meta', 'wp-meta-seo'), 38833887 $manage_options_cap, 38843888 'metaseo_content_meta', 38853889 array($this, 'loadPage'), 38863890 null 38873891 ), 38883892 array( 38893893 'metaseo_dashboard', 38903894 '', 38913895 esc_html__('Category meta', 'wp-meta-seo'), 38923896 $manage_options_cap, 38933897 'metaseo_category_meta', 38943898 array($this, 'loadPage'), 38953899 null 38963900 ), 38973901 array( 38983902 'metaseo_dashboard', 38993903 '', 39003904 esc_html__('Image editor', 'wp-meta-seo'), 39013905 $manage_options_cap, 39023906 'metaseo_image_meta', 39033907 array($this, 'loadPage'), 39043908 null 39053909 ), 39063910 array( 39073911 'metaseo_dashboard', 39083912 '', 39093913 esc_html__('Sitemap', 'wp-meta-seo'), 39103914 $manage_options_cap, 39113915 'metaseo_google_sitemap', 39123916 array($this, 'loadPage'), 39133917 null, 39143918 ), 39153919 array( 39163920 'metaseo_dashboard', 39173921 '', 39183922 esc_html__('Link editor', 'wp-meta-seo'), 39193923 $manage_options_cap, 39203924 'metaseo_link_meta', 39213925 array($this, 'loadPage'), 39223926 null 39233927 ), 39243928 array( 39253929 'metaseo_dashboard', 39263930 '', 39273931 esc_html__('404 & Redirects', 'wp-meta-seo'), 39283932 $manage_options_cap, 39293933 'metaseo_broken_link', 39303934 array($this, 'loadPage'), 39313935 null 39323936 ), 39333937 array( 39343938 'metaseo_dashboard', 39353939 '', 39363940 esc_html__('Google Analytics', 'wp-meta-seo'), 39373941 $manage_options_cap, 39383942 'metaseo_google_analytics', 39393943 array($this, 'loadPage'), 39403944 null 39413945 ) 39423946 ); 39433947 39443948 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 39453949 global $metaseo_addon; 39463950 $submenu_pages[] = array( 39473951 'metaseo_dashboard', 39483952 esc_html__('WP Meta SEO Send email', 'wp-meta-seo'), 39493953 esc_html__('Email report', 'wp-meta-seo'), 39503954 $manage_options_cap, 39513955 'metaseo_sendemail', 39523956 array($metaseo_addon, 'loadPageSendEmail'), 39533957 null 39543958 ); 39553959 39563960 // REMOVE SEARCH CONSOLE TAB, WAIT NEW API FROM GOOGLE GUYS 39573961 // 39583962 // 39593963 // 39603964// $submenu_pages[] = array( 39613965// 'metaseo_dashboard', 39623966// esc_html__('Search Console', 'wp-meta-seo'), 39633967// esc_html__('Search Console', 'wp-meta-seo'), 39643968// $manage_options_cap, 39653969// 'metaseo_console', 39663970// array($metaseo_addon->admin_features['metaseo_gsc'], 'display'), 39673971// null 39683972// ); 39693973 } 39703974 39713975 $submenu_pages[] = array( 39723976 'metaseo_dashboard', 39733977 '', 39743978 esc_html__('Settings', 'wp-meta-seo'), 39753979 $manage_options_cap, 39763980 'metaseo_settings', 39773981 array($this, 'loadPage'), 39783982 null 39793983 ); 39803984 39813985 if (!is_plugin_active(WPMSEO_ADDON_FILENAME)) { 39823986 $submenu_pages[] = array( 39833987 'metaseo_dashboard', 39843988 '', 39853989 '<span style="color:orange">' . esc_html__('Better SEO ranking', 'wp-meta-seo') . '</span>', 39863990 $manage_options_cap, 39873991 'metaseo_better_ranking', 39883992 array($this, 'loadPage'), 39893993 null 39903994 ); 39913995 } 39923996 39933997 // Allow submenu pages manipulation 39943998 $submenu_pages = apply_filters('metaseo_submenu_pages', $submenu_pages); 39953999 39964000 // Loop through submenu pages and add them 39974001 if (count($submenu_pages)) { 39984002 foreach ($submenu_pages as $submenu_page) { 39994003 // Add submenu page 40004004 $admin_page = add_submenu_page( 40014005 $submenu_page[0], 40024006 $submenu_page[2] . ' - ' . esc_html__('WP Meta SEO:', 'wp-meta-seo'), 40034007 $submenu_page[2], 40044008 $submenu_page[3], 40054009 $submenu_page[4], 40064010 $submenu_page[5] 40074011 ); 40084012 40094013 // Check if we need to hook 40104014 if (isset($submenu_page[6]) && null !== $submenu_page[6] 40114015 && is_array($submenu_page[6]) && count($submenu_page[6]) > 0) { 40124016 foreach ($submenu_page[6] as $submenu_page_action) { 40134017 add_action('load-' . $admin_page, $submenu_page_action); 40144018 } 40154019 } 40164020 } 40174021 } 40184022 } 40194023 40204024 /** 40214025 * Set error time out 40224026 * 40234027 * @return void 40244028 */ 40254029 public function setErrorTimeout() 40264030 { 40274031 $midnight = strtotime('tomorrow 00:00:00'); // UTC midnight 40284032 $midnight = $midnight + 8 * 3600; // UTC 8 AM 40294033 $this->error_timeout = $midnight - time(); 40304034 } 40314035 40324036 /** 40334037 * Load the form for a WPSEO admin page 40344038 * 40354039 * @return void 40364040 */ 40374041 public function loadPage() 40384042 { 40394043 if (isset($_GET['page'])) { 40404044 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action, nonce is not required 40414045 switch ($_GET['page']) { 40424046 case 'metaseo_google_analytics': 40434047 $this->google_alanytics = get_option('wpms_google_alanytics'); 40444048 if (isset($this->google_alanytics['setting_success']) && $this->google_alanytics['setting_success'] === 1) { 40454049 echo '<div id="setting-error-settings_updated" 40464050 class="updated settings-error notice is-dismissible"> 40474051<p><strong>' . esc_html__('Settings saved.', 'wp-meta-seo') . '</strong></p><button type="button" class="notice-dismiss"> 40484052<span class="screen-reader-text">Dismiss this notice.</span></button></div>'; 40494053 $this->google_alanytics['setting_success'] = 0; 40504054 update_option('wpms_google_alanytics', $this->google_alanytics); 40514055 } 40524056 if (isset($_POST['_metaseo_ggtracking_settings'])) { 40534057 if (empty($_POST['gadash_security']) 40544058 || !wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { 40554059 die(); 40564060 } 40574061 update_option('_metaseo_ggtracking_settings', $_POST['_metaseo_ggtracking_settings']); 40584062 echo '<div id="setting-error-settings_updated" 40594063 class="updated settings-error notice is-dismissible"> 40604064<p><strong>' . esc_html__('Settings saved.', 'wp-meta-seo') . '</strong></p><button type="button" class="notice-dismiss"> 40614065<span class="screen-reader-text">Dismiss this notice.</span></button></div>'; 40624066 } 40634067 40644068 // Update selected profile 40654069 if (!empty($_POST['tableid_jail'])) { 40664070 if (empty($_POST['wpms_nonce']) 40674071 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 40684072 die(); 40694073 } 40704074 if ($this->google_alanytics['tableid_jail'] !== $_POST['tableid_jail']) { 40714075 $this->google_alanytics['tableid_jail'] = $_POST['tableid_jail']; 40724076 $this->google_alanytics['setting_success'] = 1; 40734077 update_option('wpms_google_alanytics', $this->google_alanytics); 40744078 wp_redirect($_SERVER['HTTP_REFERER']); 40754079 } 40764080 } 40774081 40784082 $ga_tracking = get_option('_metaseo_ggtracking_settings'); 40794083 if (is_array($ga_tracking)) { 40804084 $this->ga_tracking = array_merge($this->ga_tracking, $ga_tracking); 40814085 } 40824086 include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php'); 40834087 include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsgapi.php'); 40844088 wp_enqueue_style('wpms-tippy-style'); 40854089 wp_enqueue_script('wpms-tippy-core'); 40864090 wp_enqueue_script('wpms-tippy'); 40874091 // Enqueue snackbar 40884092 wp_enqueue_style('wpms-snackbar-style'); 40894093 wp_enqueue_script('wpms-snackbar-script'); 40904094 40914095 // WPMS Google Analytics Data 40924096 if (isset($_GET['view']) && $_GET['view'] === 'wpms_gg_service_data') { 40934097 wp_enqueue_style('wpms-backend-tracking-code'); 40944098 wp_enqueue_style('wpms-backend-item-reports'); 40954099 40964100 // When user save access code 40974101 if (isset($_POST['wpmsga_dash_clientid']) && isset($_POST['wpmsga_dash_clientsecret'])) { 40984102 // Check nonce field 40994103 if (empty($_POST['wpms_nonce']) 41004104 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 41014105 die(); 41024106 } 41034107 $this->google_alanytics['wpmsga_dash_clientid'] = $_POST['wpmsga_dash_clientid']; 41044108 $this->google_alanytics['wpmsga_dash_clientsecret'] = $_POST['wpmsga_dash_clientsecret']; 41054109 update_option('wpms_google_alanytics', $this->google_alanytics); 41064110 } 41074111 41084112 require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php'; 41094113 if (!empty($this->google_alanytics['wpmsga_dash_clientid']) && !empty($this->google_alanytics['wpmsga_dash_clientsecret'])) { 41104114 $this->client = WpmsGaTools::initClient($this->google_alanytics['wpmsga_dash_clientid'], $this->google_alanytics['wpmsga_dash_clientsecret']); 41114115 $controller = new WpmsGapiController(); 41124116 $this->service = new \WPMSGoogle\Service\Analytics($this->client); 41134117 } 41144118 41154119 $this->setErrorTimeout(); 41164120 41174121 if (!empty($_POST['wpms_gg_access_code'])) { 41184122 $wpms_gg_access_code = $_POST['wpms_gg_access_code']; 41194123 if (!stripos('x' . $wpms_gg_access_code, 'UA-', 1)) { 41204124 WpmsGaTools::deleteCache('gapi_errors'); 41214125 WpmsGaTools::deleteCache('last_error'); 41224126 WpmsGaTools::clearCache(); 41234127 try { 41244128 $this->client->authenticate($wpms_gg_access_code); 41254129 $getAccessToken = $this->client->getAccessToken(); 41264130 if ($getAccessToken) { 41274131 try { 41284132 $this->client->setAccessToken($getAccessToken); 41294133 $this->google_alanytics['googleCredentials'] 41304134 = $this->client->getAccessToken(); 41314135 } catch (WPMSGoogle\Service\Exception $e) { 41324136 WpmsGaTools::setCache( 41334137 'wpmsga_dash_lasterror', 41344138 date('Y-m-d H:i:s') . ': ' . esc_html('(' . $e->getCode() . ') ' . $e->getMessage()), 41354139 $this->error_timeout 41364140 ); 41374141 WpmsGaTools::setCache( 41384142 'wpmsga_dash_gapi_errors', 41394143 $e->getCode(), 41404144 $this->error_timeout 41414145 ); 41424146 } catch (Exception $e) { 41434147 WpmsGaTools::setCache( 41444148 'wpmsga_dash_lasterror', 41454149 date('Y-m-d H:i:s') . ': ' . esc_html($e), 41464150 $this->error_timeout 41474151 ); 41484152 } 41494153 } 41504154 41514155 if (!empty($this->google_alanytics['profile_list'])) { 41524156 $profiles = $this->google_alanytics['profile_list']; 41534157 } else { 41544158 $profiles = WpmsGaTools::refreshProfiles($this->service, $getAccessToken['access_token'], $this->error_timeout); 41554159 } 41564160 41574161 $this->google_alanytics['code'] = $wpms_gg_access_code; 41584162 $this->google_alanytics['googleCredentials'] = $getAccessToken; 41594163 $this->google_alanytics['profile_list'] = $profiles; 41604164 update_option('wpms_google_alanytics', $this->google_alanytics); 41614165 } catch (WPMSGoogle\Service\Exception $e) { 41624166 echo ''; 41634167 } catch (Exception $e) { 41644168 echo ''; 41654169 } 41664170 } else { 41674171 echo '<div class="error"><p>' . esc_html__('The access code is 41684172<strong>NOT</strong> your <strong>Tracking ID</strong> 41694173 (UA-XXXXX-X). Try again, and use the red link to get your access code', 'wp-meta-seo') . '.</p></div>'; 41704174 } 41714175 update_option('wpms_google_alanytics', $this->google_alanytics); 41724176 wp_redirect($_SERVER['HTTP_REFERER']); 41734177 exit; 41744178 } 41754179 $gg_analytcis = get_option('wpms_google_alanytics'); 41764180 if (is_array($gg_analytcis)) { 41774181 $this->google_alanytics = array_merge($gg_analytcis, $this->google_alanytics); 41784182 } 41794183 // If user have google credentials 41804184 if (!empty($this->google_alanytics['googleCredentials'])) { 41814185 // WPMS google analytics setting 41824186 include_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-services/ga-trackcode.php'); 41834187 // Google analytics data 41844188 if (!empty($this->google_alanytics['tableid_jail'])) { 41854189 echo '<h1 class="wpms-top-h1">' . esc_html__('Google Analytics Report', 'wp-meta-seo') . ' 41864190 <i class="material-icons intro-topic-tooltip" data-tippy="' . esc_html__('Create a Google Analytics property then connect WordPress to this Analytics property. You can then follow your traffic and include the data in your Email report (Pro Addon)', 'wp-meta-seo') . '">help_outline</i> 41874191 </h1>'; 41884192 echo '<div id="wpms-window-1"> 41894193 <!-- WPMS Google analytics response using JS --> 41904194 41914195 </div>'; 41924196 } 41934197 } else { 41944198 include_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-services/gg-services-connect.php'); 41954199 } 41964200 } else { 41974201 // WPMS Google Service Tracking - when user don't have Google cloud credentials 41984202 $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings'); 41994203 if (is_array($gaDisconnect)) { 42004204 $this->gaDisconnect = array_merge( 42014205 $this->gaDisconnect, 42024206 $gaDisconnect 42034207 ); 42044208 } 42054209 42064210 // When user submit tracking options 42074211 if (isset($_POST['_metaseo_gg_service_disconnect'])) { 42084212 // Check none field 42094213 if (empty($_POST['wpms_nonce']) 42104214 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 42114215 die(); 42124216 } 42134217 // Sanitizing submit data and save options 42144218 $_metaseo_ga_disconnect = $_POST['_metaseo_gg_service_disconnect']; 42154219 $_metaseo_ga_disconnect['wpms_gg_service_tracking_id'] = sanitize_text_field($_metaseo_ga_disconnect['wpms_gg_service_tracking_id']); 42164220 $_metaseo_ga_disconnect['wpms_gg_service_tracking_type'] = sanitize_text_field($_metaseo_ga_disconnect['wpms_gg_service_tracking_type']); 42174221 $_metaseo_ga_disconnect['wpmsga_code_tracking'] = stripslashes($_metaseo_ga_disconnect['wpmsga_code_tracking']); 42184222 $_metaseo_ga_disconnect['wpmstm_header_code_tracking'] = stripslashes($_metaseo_ga_disconnect['wpmstm_header_code_tracking']); 42194223 $_metaseo_ga_disconnect['wpmstm_body_code_tracking'] = stripslashes($_metaseo_ga_disconnect['wpmstm_body_code_tracking']); 42204224 update_option( 42214225 '_metaseo_ggtracking_disconnect_settings', 42224226 $_metaseo_ga_disconnect 42234227 ); 42244228 $gaDisconnect = get_option('_metaseo_ggtracking_disconnect_settings'); 42254229 if (is_array($gaDisconnect)) { 42264230 $this->gaDisconnect = array_merge( 42274231 $this->gaDisconnect, 42284232 $gaDisconnect 42294233 ); 42304234 } 42314235 } 42324236 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/google-services/google-services.php'); 42334237 } 42344238 42354239 $w = '99%'; 42364240 $text = esc_html__('Bring your WordPress website SEO to the next level with the PRO Addon: Email Report, 42374241 Google Search Console Connect, Automatic Redirect, Advanced Sitemaps and more!', 'wp-meta-seo'); 42384242 $class_btn_close = 'close_gga'; 42394243 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/notification.php'); 42404244 break; 42414245 case 'metaseo_google_sitemap': 42424246 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 42434247 // remove filter by lang 42444248 if (is_plugin_active('sitepress-multilingual-cms/sitepress.php')) { 42454249 global $sitepress; 42464250 remove_filter('terms_clauses', array($sitepress, 'terms_clauses')); 42474251 } elseif (is_plugin_active('polylang/polylang.php')) { 42484252 global $polylang; 42494253 $filters_term = $polylang->filters_term; 42504254 remove_filter('terms_clauses', array($filters_term, 'terms_clauses')); 42514255 } 42524256 } 42534257 42544258 if (!class_exists('MetaSeoSitemap')) { 42554259 require_once(WPMETASEO_PLUGIN_DIR . '/inc/class.metaseo-sitemap.php'); 42564260 } 42574261 42584262 $sitemap = new MetaSeoSitemap(); 42594263 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/sitemaps/metaseo-google-sitemap.php'); 42604264 break; 42614265 case 'metaseo_broken_link': 42624266 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/metaseo-broken-link.php'); 42634267 break; 42644268 case 'metaseo_settings': 42654269 if (isset($_POST['_metaseo_settings'])) { 42664270 if (empty($_POST['wpms_nonce']) 42674271 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 42684272 die(); 42694273 } 42704274 update_option('_metaseo_settings', $_POST['_metaseo_settings']); 42714275 if (isset($_POST['_metaseo_settings']['wpms_save_general'])) { 42724276 $_SESSION['_metaseo_settings_general'] = 1; 42734277 } 42744278 if (isset($_POST['_metaseo_settings']['wpms_save_social'])) { 42754279 $_SESSION['_metaseo_settings_social'] = 1; 42764280 } 42774281 if (isset($_POST['gscapi']['save'])) { 42784282 $_SESSION['_metaseo_settings_search_console'] = 1; 42794283 } 42804284 } 42814285 42824286 $posts = get_posts(array('post_type' => 'page', 'posts_per_page' => -1, 'numberposts' => -1)); 42834287 $types_404 = array( 42844288 'none' => 'None', 42854289 'wp-meta-seo-page' => esc_html__('WP Meta SEO page', 'wp-meta-seo'), 42864290 'custom_page' => esc_html__('Custom page', 'wp-meta-seo') 42874291 ); 42884292 42894293 // get settings 404 42904294 $defaul_settings_404 = array( 42914295 'wpms_redirect_homepage' => 0, 42924296 'wpms_type_404' => 'none', 42934297 'wpms_page_redirected' => 'none' 42944298 ); 42954299 $wpms_settings_404 = get_option('wpms_settings_404'); 42964300 if (is_array($wpms_settings_404)) { 42974301 $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404); 42984302 } 42994303 43004304 // get settings breadcrumb 43014305 $home_title = get_the_title(get_option('page_on_front')); 43024306 if (empty($home_title)) { 43034307 $home_title = get_bloginfo('title'); 43044308 } 43054309 $breadcrumbs = array( 43064310 'separator' => ' > ', 43074311 'include_home' => 1, 43084312 'home_text' => $home_title, 43094313 'home_text_default' => 0, 43104314 'clickable' => 1 43114315 ); 43124316 $breadcrumb_settings = get_option('_metaseo_breadcrumbs'); 43134317 if (is_array($breadcrumb_settings)) { 43144318 $breadcrumbs = array_merge($breadcrumbs, $breadcrumb_settings); 43154319 } 43164320 43174321 // email settings 43184322 $email_settings = array( 43194323 'enable' => 0, 43204324 'host' => 'smtp.gmail.com', 43214325 'type_encryption' => 'ssl', 43224326 'port' => '465', 43234327 'autentication' => 'yes', 43244328 'username' => '', 43254329 'password' => '', 43264330 ); 43274331 43284332 $mailsettings = get_option('wpms_email_settings'); 43294333 if (is_array($mailsettings)) { 43304334 $email_settings = array_merge($email_settings, $mailsettings); 43314335 } 43324336 43334337 $html_tabemail = apply_filters('wpmsaddon_emailsettings', '', $email_settings); 43344338 43354339 // link settings 43364340 $link_settings = array( 43374341 'enable' => 0, 43384342 'numberFrequency' => 1, 43394343 'showlinkFrequency' => 'month' 43404344 ); 43414345 43424346 $linksettings = get_option('wpms_link_settings'); 43434347 if (is_array($linksettings)) { 43444348 $link_settings = array_merge($link_settings, $linksettings); 43454349 } 43464350 43474351 $link_settings_html = apply_filters('wpmsaddon_linksettings', '', $link_settings); 43484352 43494353 // local business settings 43504354 $local_business = array( 43514355 'enable' => 0, 43524356 'logo' => '', 43534357 'type_name' => '', 43544358 'country' => '', 43554359 'address' => '', 43564360 'city' => '', 43574361 'state' => '', 43584362 'phone' => '', 43594363 'pricerange' => '$$' 43604364 ); 43614365 43624366 $business = get_option('wpms_local_business'); 43634367 if (is_array($business)) { 43644368 $local_business = array_merge($local_business, $business); 43654369 } 43664370 $countrys = apply_filters('wpms_get_countryList', array()); 43674371 $local_business_html = apply_filters('wpmsaddon_local_business', '', $local_business, $countrys); 43684372 43694373 $search_console_html = apply_filters('wpmsaddon_search_console', ''); 43704374 43714375 $default_settings = wpmsGetDefaultSettings(); 43724376 $settings = get_option('_metaseo_settings'); 43734377 if (is_array($settings)) { 43744378 $settings = array_merge($default_settings, $settings); 43754379 } else { 43764380 $settings = $default_settings; 43774381 } 43784382 43794383 foreach ($settings as $setting_name => $setting_value) { 43804384 ${$setting_name} = $setting_value; 43814385 } 43824386 43834387 $home_meta_active = wpmsGetOption('home_meta_active'); 43844388 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/settings.php'); 43854389 break; 43864390 43874391 case 'metaseo_content_meta': 43884392 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/content-meta.php'); 43894393 break; 43904394 43914395 case 'metaseo_category_meta': 43924396 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/category-meta.php'); 43934397 break; 43944398 43954399 case 'metaseo_image_meta': 43964400 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/image-meta.php'); 43974401 break; 43984402 43994403 case 'metaseo_link_meta': 44004404 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/link-meta.php'); 44014405 break; 44024406 44034407 case 'metaseo_image_optimize': 44044408 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/image-optimize.php'); 44054409 break; 44064410 44074411 case 'metaseo_better_ranking': 44084412 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/better_seo.php'); 44094413 break; 44104414 case 'metaseo_dashboard': 44114415 default: 44124416 require_once(WPMETASEO_PLUGIN_DIR . 'inc/pages/dashboard.php'); 44134417 break; 44144418 } 44154419 } 44164420 } 44174421 44184422 /** 44194423 * Ajax check attachment have alt empty 44204424 * 44214425 * @return void 44224426 */ 44234427 public function checkExist() 44244428 { 44254429 if (empty($_POST['wpms_nonce']) 44264430 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 44274431 die(); 44284432 } 44294433 44304434 if (isset($_POST['action_name'])) { 44314435 switch ($_POST['action_name']) { 44324436 case 'img-copy-alt': 44334437 $margs = array( 44344438 'posts_per_page' => -1, 44354439 'post_type' => 'attachment', 44364440 'post_status' => 'any', 44374441 'meta_query' => array( 44384442 'relation' => 'OR', 44394443 array( 44404444 'key' => '_wp_attachment_image_alt', 44414445 'value' => '', 44424446 'compare' => '!=' 44434447 ) 44444448 ) 44454449 ); 44464450 44474451 $m_newquery = new WP_Query($margs); 44484452 $mposts_empty_alt = $m_newquery->get_posts(); 44494453 if (!empty($mposts_empty_alt)) { 44504454 wp_send_json(true); 44514455 } else { 44524456 wp_send_json(false); 44534457 } 44544458 break; 44554459 44564460 case 'img-copy-title': 44574461 global $wpdb; 44584462 $check_title = $wpdb->get_var('SELECT COUNT(posts.ID) as total FROM ' . $wpdb->prefix . 'posts as posts 44594463 WHERE posts.post_type = "attachment" AND post_title != ""'); 44604464 if ($check_title > 0) { 44614465 wp_send_json(true); 44624466 } else { 44634467 wp_send_json(false); 44644468 } 44654469 break; 44664470 case 'img-copy-desc': 44674471 global $wpdb; 44684472 $check_title = $wpdb->get_var('SELECT COUNT(posts.ID) as total FROM ' . $wpdb->prefix . 'posts as posts 44694473 WHERE posts.post_type = "attachment" AND post_content != ""'); 44704474 if ($check_title > 0) { 44714475 wp_send_json(true); 44724476 } else { 44734477 wp_send_json(false); 44744478 } 44754479 break; 44764480 } 44774481 } 44784482 } 44794483 44804484 /** 44814485 * Ajax update image alt and image title 44824486 * 44834487 * @return void 44844488 */ 44854489 public function bulkImageCopy() 44864490 { 44874491 if (empty($_POST['wpms_nonce']) 44884492 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 44894493 die(); 44904494 } 44914495 44924496 global $wpdb; 44934497 if (empty($_POST['action_name'])) { 44944498 wp_send_json(false); 44954499 } 44964500 44974501 if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] === 'all') { 44984502 // select all 44994503 $limit = 500; 45004504 // query attachment and update meta 45014505 $total = $wpdb->get_var('SELECT COUNT(posts.ID) as total FROM ' . $wpdb->prefix . 'posts as posts 45024506 WHERE posts.post_type = "attachment"'); 45034507 45044508 $j = ceil((int)$total / $limit); 45054509 for ($i = 0; $i <= $j; $i++) { 45064510 $ofset = $i * $limit; 45074511 $attachments = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'posts as posts 45084512 WHERE posts.post_type = %s LIMIT %d OFFSET %d', array('attachment', $limit, $ofset))); 45094513 45104514 foreach ($attachments as $attachment) { 45114515 $i_info_url = pathinfo($attachment->guid); 45124516 switch ($_POST['action_name']) { 45134517 case 'img-copy-alt': 45144518 $value = $i_info_url['filename']; 45154519 /** 45164520 * Filter before update meta for image 45174521 * 45184522 * @param string Meta value 45194523 * @param integer Image ID 45204524 * @param string Meta key 45214525 * @param array Extra informations 45224526 * 45234527 * @return string 45244528 */ 45254529 $value = apply_filters('wpms_update_image_meta', $value, $attachment->ID, '_wp_attachment_image_alt', array('source' => 'bulk_copy_alt')); 45264530 update_post_meta($attachment->ID, '_wp_attachment_image_alt', $value); 45274531 break; 45284532 45294533 case 'img-copy-title': 45304534 $value = $i_info_url['filename']; 45314535 /** 45324536 * Filter before update meta for image 45334537 * 45344538 * @param string Meta value 45354539 * @param integer Image ID 45364540 * @param string Post title field name 45374541 * @param array Extra informations 45384542 * 45394543 * @return string 45404544 * 45414545 * @ignore Hook already documented 45424546 */ 45434547 $value = apply_filters('wpms_update_image_meta', $value, $attachment->ID, 'post_title', array('source' => 'bulk_copy_title')); 45444548 wp_update_post(array('ID' => $attachment->ID, 'post_title' => $value)); 45454549 break; 45464550 case 'img-copy-desc': 45474551 wp_update_post(array('ID' => $attachment->ID, 'post_content' => $i_info_url['filename'])); 45484552 break; 45494553 } 45504554 } 45514555 } 45524556 45534557 wp_send_json(true); 45544558 } else { 45554559 // selected 45564560 if (isset($_POST['ids'])) { 45574561 $ids = (array)$_POST['ids']; 45584562 $ids = array_map('absint', $ids); 45594563 switch ($_POST['action_name']) { 45604564 case 'img-copy-alt': 45614565 $margs = array( 45624566 'posts_per_page' => -1, 45634567 'post_type' => 'attachment', 45644568 'post_status' => 'any', 45654569 'post__in' => $ids 45664570 ); 45674571 45684572 $m_newquery = new WP_Query($margs); 45694573 $mposts_empty_alt = $m_newquery->get_posts(); 45704574 if (!empty($mposts_empty_alt)) { 45714575 foreach ($mposts_empty_alt as $post) { 45724576 $i_info_url = pathinfo($post->guid); 45734577 $value = $i_info_url['filename']; 45744578 /** 45754579 * Filter before update meta for image 45764580 * 45774581 * @param string Meta value 45784582 * @param integer Image ID 45794583 * @param string Meta key 45804584 * @param array Extra informations 45814585 * 45824586 * @return string 45834587 * 45844588 * @ignore Hook already documented 45854589 */ 45864590 $value = apply_filters('wpms_update_image_meta', $value, $post->ID, '_wp_attachment_image_alt', array('source' => 'bulk_copy_alt')); 45874591 update_post_meta($post->ID, '_wp_attachment_image_alt', $value); 45884592 } 45894593 } else { 45904594 wp_send_json(false); 45914595 } 45924596 break; 45934597 45944598 case 'img-copy-title': 45954599 $posts_result = $wpdb->get_results($wpdb->prepare('SELECT * 45964600 FROM ' . $wpdb->posts . ' WHERE post_type = %s 45974601 AND post_mime_type LIKE %s AND ID IN (' . implode(',', esc_sql($ids)) . ') 45984602 ', array('attachment', '%image%'))); 45994603 46004604 if (!empty($posts_result)) { 46014605 foreach ($posts_result as $post) { 46024606 $i_info_url = pathinfo($post->guid); 46034607 $value = $i_info_url['filename']; 46044608 /** 46054609 * Filter before update meta for image 46064610 * 46074611 * @param string Meta value 46084612 * @param integer Image ID 46094613 * @param string Post title field name 46104614 * @param array Extra informations 46114615 * 46124616 * @return string 46134617 * 46144618 * @ignore Hook already documented 46154619 */ 46164620 $value = apply_filters('wpms_update_image_meta', $value, $post->ID, 'post_title', array('source' => 'bulk_copy_title')); 46174621 wp_update_post(array('ID' => $post->ID, 'post_title' => $value)); 46184622 } 46194623 } else { 46204624 wp_send_json(false); 46214625 } 46224626 break; 46234627 case 'img-copy-desc': 46244628 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Variable has been prepare 46254629 $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_mime_type LIKE %s AND ID IN ('.implode(',', $ids).')', array('attachment', '%image%' )); 46264630 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Variable has been prepare 46274631 $posts_result = $wpdb->get_results($sql); 46284632 if (!empty($posts_result)) { 46294633 foreach ($posts_result as $post) { 46304634 $i_info_url = pathinfo($post->guid); 46314635 wp_update_post(array('ID' => $post->ID, 'post_content' => $i_info_url['filename'])); 46324636 } 46334637 } else { 46344638 wp_send_json(false); 46354639 } 46364640 break; 46374641 } 46384642 wp_send_json(true); 46394643 } else { 46404644 wp_send_json(false); 46414645 } 46424646 } 46434647 } 46444648 46454649 /** 46464650 * Ajax bulk update meta title for a post/page 46474651 * 46484652 * @return void 46494653 */ 46504654 public function bulkPostCopy() 46514655 { 46524656 if (empty($_POST['wpms_nonce']) 46534657 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 46544658 die(); 46554659 } 46564660 46574661 $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false)); 46584662 unset($post_types['attachment']); 46594663 $margs = array(); 46604664 46614665 switch ($_POST['action_name']) { 46624666 case 'post-copy-title': 46634667 $key = '_metaseo_metatitle'; 46644668 break; 46654669 case 'post-copy-desc': 46664670 $key = '_metaseo_metadesc'; 46674671 break; 46684672 } 46694673 46704674 if (isset($_POST['sl_bulk']) && $_POST['sl_bulk'] === 'all') { // for select a;; 46714675 $margs = array( 46724676 'posts_per_page' => -1, 46734677 'post_type' => $post_types, 46744678 'post_status' => 'any' 46754679 ); 46764680 } else { // for select some post 46774681 if (isset($_POST['ids'])) { 46784682 $ids = $_POST['ids']; 46794683 $margs = array( 46804684 'posts_per_page' => -1, 46814685 'post_type' => $post_types, 46824686 'post_status' => 'any', 46834687 'post__in' => $ids 46844688 ); 46854689 } else { 46864690 wp_send_json(false); 46874691 } 46884692 } 46894693 46904694 $m_newquery = new WP_Query($margs); 46914695 $mposts = $m_newquery->get_posts(); 46924696 if (!empty($mposts)) { 46934697 foreach ($mposts as $post) { 46944698 $value = $post->post_title; 46954699 /** 46964700 * Filter before update meta for post/page 46974701 * 46984702 * @param string Meta value 46994703 * @param integer Post ID 47004704 * @param string Meta key 47014705 * @param array Extra informations 47024706 * 47034707 * @return string 47044708 * 47054709 * @ignore Hook already documented 47064710 */ 47074711 $value = apply_filters('wpms_update_content_meta', $value, $post->ID, $key, array('source' => 'copy_meta')); 47084712 update_post_meta($post->ID, $key, $value); 47094713 } 47104714 wp_send_json(true); 47114715 } else { 47124716 wp_send_json(false); 47134717 } 47144718 } 47154719 47164720 /** 47174721 * Set cookie notification 47184722 * 47194723 * @return void 47204724 */ 47214725 public function setcookieNotification() 47224726 { 47234727 if (empty($_POST['wpms_nonce']) 47244728 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 47254729 die(); 47264730 } 47274731 47284732 if (isset($_POST['page'])) { 47294733 setcookie($_POST['page'], time(), time() + (86400 * 30), '/'); 47304734 wp_send_json(true); 47314735 } 47324736 wp_send_json(false); 47334737 } 47344738 47354739 47364740 /** 47374741 * Ajax save ga information 47384742 * 47394743 * @return void 47404744 */ 47414745 public function wpmsGGSaveInformation() 47424746 { 47434747 check_ajax_referer('wpms_nonce', 'wpms_nonce'); 4748 if (!current_user_can('manage_options')) { 4749 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 4750 wp_die(__('There is no permission here', 'wp-meta-seo')); 4751 } 47444752 47454753 $google_alanytics = array( 47464754 'wpmsga_dash_clientid' => isset($_POST['wpmsga_dash_clientid']) ? trim($_POST['wpmsga_dash_clientid']) : '', 47474755 'wpmsga_dash_clientsecret' => isset($_POST['wpmsga_dash_clientsecret']) ? trim($_POST['wpmsga_dash_clientsecret']) : '' 47484756 ); 47494757 47504758 update_option('wpms_google_alanytics', $google_alanytics); 47514759 47524760 require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php'; 47534761 $client = WpmsGaTools::initClient($google_alanytics['wpmsga_dash_clientid'], $google_alanytics['wpmsga_dash_clientsecret']); 47544762 $authUrl = $client->createAuthUrl(); 47554763 47564764 if (!empty($authUrl)) { 47574765 echo json_encode(array('status' => 'true', 'authUrl' => $authUrl)); 47584766 die(); 47594767 } 47604768 47614769 echo json_encode(array('status' => 'false', 'authUrl' => '')); 47624770 die(); 47634771 } 47644772 47654773 /** 47664774 * Run ajax 47674775 * 47684776 * @return void 47694777 */ 47704778 public function startProcess() 47714779 { 47724780 if (empty($_POST['wpms_nonce']) || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 47734781 die(); 47744782 } 47754783 if (!current_user_can('edit_posts')) { 47764784 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 47774785 wp_die(__('There is no edit permission here', 'wp-meta-seo')); 47784786 } 47794787 if (isset($_REQUEST['task'])) { 47804788 switch ($_REQUEST['task']) { 47814789 case 'updateContentMeta': 47824790 $this->updateContentMetaCallback(); 47834791 break; 47844792 case 'scanPosts': 47854793 MetaSeoImageListTable::scanPostsCallback(); 47864794 break; 47874795 case 'load_posts': 47884796 MetaSeoImageListTable::loadPostsCallback(); 47894797 break; 47904798 case 'optimize_imgs': 47914799 MetaSeoImageListTable::optimizeImages(); 47924800 break; 47934801 case 'updateMeta': 47944802 MetaSeoImageListTable::updateMetaCallback(); 47954803 break; 47964804 case 'import_meta_data': 47974805 MetaSeoContentListTable::importMetaData(); 47984806 break; 47994807 case 'dismiss_import_meta': 48004808 MetaSeoContentListTable::dismissImport(); 48014809 break; 48024810 case 'bulk_post_copy': 48034811 $this->bulkPostCopy(); 48044812 break; 48054813 case 'bulk_image_copy': 48064814 $this->bulkImageCopy(); 48074815 break; 48084816 case 'ajax_check_exist': 48094817 $this->checkExist(); 48104818 break; 48114819 case 'reload_analysis': 48124820 $this->reloadAnalysis(); 48134821 break; 48144822 case 'wpmsElementorSavePost': 48154823 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-metabox.php'); 48164824 WPMSEOMetabox::savePostByElementor(); 48174825 break; 48184826 case 'validate_analysis': 48194827 $this->validateAnalysis(); 48204828 break; 48214829 case 'update_link': 48224830 $this->updateLink(); 48234831 break; 48244832 case 'remove_link': 48254833 $this->removeLink(); 48264834 break; 48274835 case 'save_settings404': 48284836 $this->save404Settings(); 48294837 break; 48304838 case 'save_settings_breadcrumb': 48314839 $this->saveBreadcrumbSettings(); 48324840 break; 48334841 case 'update_link_redirect': 48344842 MetaSeoBrokenLinkTable::updateLinkRedirect(); 48354843 break; 48364844 case 'add_custom_redirect': 48374845 MetaSeoBrokenLinkTable::addCustomRedirect(); 48384846 break; 48394847 case 'unlink': 48404848 MetaSeoBrokenLinkTable::unlink(); 48414849 break; 48424850 case 'recheck_link': 48434851 MetaSeoBrokenLinkTable::reCheckLink(); 48444852 break; 48454853 case 'scan_link': 48464854 MetaSeoBrokenLinkTable::scanLink(); 48474855 break; 48484856 case 'flush_link': 48494857 MetaSeoBrokenLinkTable::flushLink(); 48504858 break; 48514859 case 'update_follow': 48524860 $this->updateFollow(); 48534861 break; 48544862 case 'update_multiplefollow': 48554863 $this->updateMultipleFollow(); 48564864 break; 48574865 case 'update_pagefollow': 48584866 $this->updatePageFollow(); 48594867 break; 48604868 case 'update_pageindex': 48614869 $this->updatePageIndex(); 48624870 break; 48634871 case 'backend_item_reports': 48644872 MetaSeoGoogleAnalytics::itemsReport(); 48654873 break; 48664874 case 'analytics_widgets_data': 48674875 MetaSeoGoogleAnalytics::analyticsWidgetsData(); 48684876 break; 48694877 case 'wpms_tagmanager_request_containers': 48704878 $this->tagmanagerContainersReport(); 48714879 break; 48724880 case 'wpms_tagmanager_container_info': 48734881 $this->tagmanagerContainerInfo(); 48744882 break; 48754883 case 'wpms_tagmanager_refresh_connect': 48764884 $this->tagmanagerRefreshConnect(); 48774885 break; 48784886 case 'ga_clearauthor': 48794887 MetaSeoGoogleAnalytics::clearAuthor(); 48804888 break; 48814889 case 'ga_update_option': 48824890 MetaSeoGoogleAnalytics::updateOption(); 48834891 break; 48844892 case 'dash_permalink': 48854893 MetaSeoDashboard::dashboardPermalink(); 48864894 break; 48874895 case 'dash_newcontent': 48884896 MetaSeoDashboard::dashboardNewContent(); 48894897 break; 48904898 case 'dash_linkmeta': 48914899 MetaSeoDashboard::dashboardLinkMeta(); 48924900 break; 48934901 case 'dash_metatitle': 48944902 MetaSeoDashboard::dashboardMetaTitle(); 48954903 break; 48964904 case 'dash_metadesc': 48974905 MetaSeoDashboard::dashboardMetaDesc(); 48984906 break; 48994907 case 'dash_imgsmeta': 49004908 MetaSeoDashboard::dashImgsMeta(); 49014909 break; 49024910 case 'reload-web': 49034911 MetaSeoDashboard::reloadWeb(); 49044912 break; 49054913 case 'setcookie_notification': 49064914 $this->setcookieNotification(); 49074915 break; 49084916 case 'image_scan_meta': 49094917 MetaSeoImageListTable::imageScanMeta(); 49104918 break; 49114919 case 'update_seokeyword_bulk_edit': 49124920 $this->updateSeokeywordBulkEdit(); 49134921 break; 49144922 case 'updateCategoryContent': 49154923 WPMSCategoryMetaTable::updateCategoryContent(); 49164924 break; 49174925 case 'wpmsDeleteCat': 49184926 WPMSCategoryMetaTable::wpmsDeleteCat(); 49194927 break; 49204928 case 'wpmsBulkCatCopy': 49214929 WPMSCategoryMetaTable::wpmsBulkCatCopy(); 49224930 break; 49234931 } 49244932 } 49254933 } 49264934 49274935 49284936 /** 49294937 * Convert canonical url 49304938 * 49314939 * @param string $url Url 49324940 * 49334941 * @return string 49344942 */ 49354943 public static function convertCanonicalUrlToSave($url) 49364944 { 49374945 if (empty($url)) { 49384946 return $url; 49394947 } 49404948 49414949 $url = preg_replace('/\s+/', '', $url); 49424950 49434951 if (substr($url, 0, 2) === '//') { 49444952 $url = (is_ssl() ? 'https:' : 'http:') . $url; 49454953 } 49464954 49474955 // Remove / in first 49484956 $url = ltrim($url, '/'); 49494957 49504958 // Full link 49514959 if (preg_match('#http(s?)://#i', $url)) { 49524960 if (strpos($url, trim(home_url(), '/')) !== false) { 49534961 $url = str_replace(trim(home_url(), '/'), '', $url); 49544962 return (empty($url) ? '/' : $url); 49554963 } else { 49564964 // External link 49574965 return $url; 49584966 } 49594967 } 49604968 49614969 $parseHome = parse_url(home_url()); 49624970 $host = (!empty($parseHome['host']) ? $parseHome['host'] : ''); 49634971 $host .= (!empty($parseHome['path']) ? $parseHome['path'] : ''); 49644972 49654973 if ($host && $url && strpos($url, $host) !== false) { 49664974 $url = str_replace($host, '', $url); 49674975 } 49684976 49694977 return '/' . ltrim($url, '/'); 49704978 } 49714979 49724980 /** 49734981 * Convert canonical url to display 49744982 * 49754983 * @param string $url Url 49764984 * 49774985 * @return string 49784986 */ 49794987 public static function convertCanonicalUrlToDisplay($url) 49804988 { 49814989 if (empty($url)) { 49824990 return $url; 49834991 } 49844992 49854993 if (preg_match('#http(s?)://#i', $url)) { 49864994 // External link 49874995 return $url; 49884996 } 49894997 49904998 return trim(home_url(), '/') . $url; 49914999 } 49925000 49935001 /** 49945002 * Schedules a rewrite flush. 49955003 * 49965004 * @return void 49975005 */ 49985006 public function wpmsScheduleRewriteFlush() 49995007 { 50005008 // Bail if this is a multisite installation and the site has been switched. 50015009 if (is_multisite() && ms_is_switched()) { 50025010 return; 50035011 } 50045012 50055013 add_action('shutdown', 'flush_rewrite_rules'); 50065014 } 50075015} * TABULARUNIFIED WP-META-SEO/TRUNK/INC/CLASS.METASEO-SITEMAP.PHP ¶ r2869205 r2870465 11<?php 22/* Prohibit direct script loading */ 33defined('ABSPATH') || die('No direct script access allowed!'); 44 55/** 66 * Class MetaSeoSitemap 77 * Class that holds most of the sitemap functionality for Meta SEO. 88 */ 99class MetaSeoSitemap 1010{ 1111 1212 /** 1313 * Sitemap html 1414 * 1515 * @var string 1616 */ 1717 public $html = ''; 1818 /** 1919 * WPMS Sitemap xml file 2020 * 2121 * @var string 2222 */ 2323 public $wpms_sitemap_name = 'wpms-sitemap.xml'; 2424 /** 2525 * Sitemap xml file 2626 * 2727 * @var string 2828 */ 2929 public $wpms_sitemap_default_name = 'sitemap.xml'; 3030 /** 3131 * List columns sitemap 3232 * 3333 * @var array 3434 */ 3535 public $columns = array('Zezo', 'One', 'Two', 'Three'); 3636 /** 3737 * Level menu 3838 * 3939 * @var array 4040 */ 4141 public $level = array(); 4242 /** 4343 * Sitemap settings 4444 * 4545 * @var array 4646 */ 4747 public $settings_sitemap; 4848 4949 /** 5050 * MetaSeoSitemap constructor. 5151 */ 5252 public function __construct() 5353 { 5454 $this->getSitemapSettings(); 5555 add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts')); 5656 add_action('wp_enqueue_scripts', array($this, 'enqueueScripts')); 5757 add_filter('the_content', array($this, 'sitemapInContent')); 5858 add_shortcode('wpms_html_sitemap', array($this, 'sitemapShortcode')); 59 add_action('wp_ajax_wpms_regenerate_sitemaps', array($this, 'regenerateSitemaps')); 59 add_action('wp_ajax_wpms_regenerate_sitemaps', array($this, 'regenerateSitemapsAjax')); 6060 add_action('wp_ajax_wpms_save_sitemap_settings', array($this, 'saveSitemapSettings')); 6161 add_action('wp_ajax_wpms_list_posts_category', array($this, 'listPostsCategory')); 6262 add_action('wp_update_nav_menu', array($this, 'wpUpdateNavMenu'), 10, 1); 6363 add_action('wp_update_nav_menu_item', array($this, 'wpAddNavMenuItem'), 10, 3); 6464 add_action('publish_post', array($this, 'wpAutoAddPostInSitemap'), 10, 1); 6565 add_action('wp_ajax_wpms_sitemap_check_all_category', array($this, 'checkAllCategoryInSitemap')); 6666 $this->disableDefaultWPSitemap(); 6767 } 6868 6969 /** 7070 * Fires after a post item has been updated. 7171 * 7272 * @param integer $postId Post ID 7373 * 7474 * @return void 7575 */ 7676 public function wpAutoAddPostInSitemap($postId) 7777 { 7878 if (!(defined('REST_REQUEST') && REST_REQUEST)) { 7979 $settings = get_option('_metaseo_settings_sitemap'); 8080 $category = get_the_category($postId); 8181 $is_create_sitemap = false; 8282 if (!empty($category)) { 8383 foreach ($category as $cat) { 8484 if (isset($settings['wpms_category_select_all']) && isset($settings['wpms_category_link']) 8585 && in_array($cat->cat_ID, $settings['wpms_category_select_all']) 8686 && in_array($cat->cat_ID, $settings['wpms_category_link']) 8787 ) { 8888 $is_create_sitemap = true; 8989 } 9090 } 9191 } 9292 9393 if (!empty($settings['wpms_sitemap_posts'])) { 9494 foreach ($settings['wpms_sitemap_posts'] as $post) { 9595 if ((int)$post['post_id'] === $postId) { 9696 // Exist in sitemap 9797 $is_create_sitemap = false; 9898 } 9999 } 100100 } 101101 102102 if ($is_create_sitemap) { 103103 $settings['wpms_sitemap_posts'][$postId] = array( 104104 'post_id' => $postId, 105105 'priority' => '1', 106106 'frequency' => 'monthly' 107107 ); 108108 109109 update_option('_metaseo_settings_sitemap', $settings); 110110 $this->regenerateSitemaps('submit'); 111111 } 112112 } 113113 } 114114 115115 /** 116116 * Fires after a navigation menu item has been updated. 117117 * 118118 * @param integer $menu_id Menu ID 119119 * @param integer $menu_item_db_id Menu item ID 120120 * @param array $args Params 121121 * 122122 * @return void 123123 */ 124124 public function wpAddNavMenuItem($menu_id, $menu_item_db_id, $args) 125125 { 126126 $this->autoAddMenuItems($menu_id); 127127 } 128128 129129 /** 130130 * This action is documented in wp-includes/nav-menu.php. 131131 * 132132 * @param integer $nav_menu_selected_id Menu ID 133133 * 134134 * @return void 135135 */ 136136 public function wpUpdateNavMenu($nav_menu_selected_id) 137137 { 138138 global $pagenow; 139139 if (isset($pagenow) && $pagenow === 'nav-menus.php') { 140140 $this->autoAddMenuItems($nav_menu_selected_id); 141141 } 142142 } 143143 144144 145145 /** 146146 * Auto add menu items 147147 * 148148 * @param integer $nav_menu_selected_id Menu ID 149149 * 150150 * @return void 151151 */ 152152 public function autoAddMenuItems($nav_menu_selected_id) 153153 { 154154 $settings = get_option('_metaseo_settings_sitemap'); 155155 if (isset($settings['check_all_menu_items']) && in_array($nav_menu_selected_id, $settings['check_all_menu_items'])) { 156156 $list_submenu_id = get_objects_in_term($nav_menu_selected_id, 'nav_menu'); 157157 $args = array( 158158 'orderby' => 'menu_order', 159159 'order' => 'ASC', 160160 'posts_per_page' => - 1, 161161 'post_type' => 'nav_menu_item', 162162 'post_status' => 'any', 163163 'post__in' => $list_submenu_id, 164164 'meta_key' => '_menu_item_menu_item_parent', 165165 'meta_value' => 0 166166 ); 167167 168168 $query = new WP_Query($args); 169169 $submenus = $query->get_posts(); 170170 foreach ($submenus as $menu) { 171171 if (empty($settings['wpms_sitemap_menus'][$menu->ID])) { 172172 $settings['wpms_sitemap_menus'][$menu->ID] = array( 173173 'menu_id' => $menu->ID, 174174 'priority' => '1', 175175 'frequency' => 'monthly' 176176 ); 177177 } 178178 } 179179 180180 update_option('_metaseo_settings_sitemap', $settings); 181181 $this->regenerateSitemaps('submit'); 182182 } 183183 } 184184 185185 /** 186186 * Get sitemap settings 187187 * 188188 * @return void 189189 */ 190190 public function getSitemapSettings() 191191 { 192192 $this->settings_sitemap = array( 193193 'wpms_sitemap_add' => 1, 194194 'wpms_sitemap_root' => 1, 195195 'wpms_sitemap_author' => 0, 196196 'wpms_sitemap_taxonomies' => array(), 197197 'wpms_category_link' => array(), 198198 'check_all_menu_items' => array(), 199199 'wpms_html_sitemap_page' => 0, 200200 'wpms_html_sitemap_column' => 1, 201201 'wpms_html_sitemap_theme' => 'default', 202202 'wpms_html_sitemap_position' => 'after', 203203 'wpms_display_column_menus' => array(0), 204204 'wpms_display_column_posts' => 1, 205205 'wpms_display_column_pages' => 1, 206206 'wpms_display_order_menus' => 1, 207207 'wpms_display_order_posts' => 2, 208208 'wpms_display_order_pages' => 3, 209209 'wpms_display_order_urls' => 4, 210210 'wpms_public_name_pages' => '', 211211 'wpms_public_name_posts' => '', 212212 'wpms_sitemap_posts' => array(), 213213 'wpms_sitemap_pages' => array(), 214214 'wpms_sitemap_include_lang' => array(), 215215 'wpms_category_select_all' => array(), 216216 'wpms_sitemap_enable_core' => 0 217217 ); 218218 219219 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 220220 $this->settings_sitemap['wpms_sitemap_customUrl'] = array(); 221221 $this->settings_sitemap['wpms_display_column_customUrl'] = 1; 222222 $this->settings_sitemap['wpms_public_name_customUrl'] = ''; 223223 $custom_post_types = get_post_types( 224224 array( 225225 'public' => true, 226226 'exclude_from_search' => false, 227227 '_builtin' => false 228228 ) 229229 ); 230230 if (!empty($custom_post_types)) { 231231 foreach ($custom_post_types as $post_type => $label) { 232232 $this->settings_sitemap['wpms_display_column_' . $post_type] = 1; 233233 $this->settings_sitemap['wpms_public_name_' . $post_type] = ''; 234234 $this->settings_sitemap['wpms_sitemap_' . $post_type] = array(); 235235 } 236236 } 237237 } 238238 239239 $settings = get_option('_metaseo_settings_sitemap'); 240240 if ((isset($settings['wpms_sitemap_pages']) && is_object($settings['wpms_sitemap_pages'])) || (isset($settings['wpms_sitemap_posts']) && is_object($settings['wpms_sitemap_posts'])) 241241 || (isset($settings['wpms_sitemap_menus']) && is_object($settings['wpms_sitemap_menus']))) { 242242 $settings_array = json_decode(json_encode($settings), true); 243243 update_option('_metaseo_settings_sitemap', $settings_array); 244244 } 245245 246246 $settings = get_option('_metaseo_settings_sitemap'); 247247 if (is_array($settings)) { 248248 $this->settings_sitemap = array_merge($this->settings_sitemap, $settings); 249249 } 250250 } 251251 252252 /** 253253 * Load metaseo script and style front-end 254254 * 255255 * @return void 256256 */ 257257 public function enqueueScripts() 258258 { 259259 global $post; 260260 if (empty($post)) { 261261 return; 262262 } 263263 264264 if (!empty($this->settings_sitemap) && (int) $this->settings_sitemap['wpms_html_sitemap_page'] !== (int) $post->ID) { 265265 return; 266266 } 267267 268268 wp_enqueue_script( 269269 'site-jPages-js', 270270 plugins_url('assets/js/site-jPages.js', dirname(__FILE__)), 271271 array('jquery'), 272272 WPMSEO_VERSION, 273273 true 274274 ); 275275 wp_localize_script( 276276 'site-jPages-js', 277277 'wpms_avarible', 278278 $this->localizeScript() 279279 ); 280280 wp_enqueue_script( 281281 'jpage-js', 282282 plugins_url('assets/js/jPages.js', dirname(__FILE__)), 283283 array('jquery'), 284284 WPMSEO_VERSION, 285285 true 286286 ); 287287 wp_enqueue_style( 288288 'jpage-css', 289289 plugins_url('assets/css/jPages.css', dirname(__FILE__)), 290290 array(), 291291 WPMSEO_VERSION 292292 ); 293293 } 294294 295295 /** 296296 * Localize a script 297297 * 298298 * @return array 299299 */ 300300 public function localizeScript() 301301 { 302302 $custom_post_types = get_post_types( 303303 array( 304304 'public' => true, 305305 'exclude_from_search' => false, 306306 '_builtin' => false 307307 ) 308308 ); 309309 $arrays = array( 310310 'wpms_display_column_menus' => $this->settings_sitemap['wpms_display_column_menus'], 311311 'post_type' => $custom_post_types 312312 ); 313313 return $arrays; 314314 } 315315 316316 /** 317317 * Load metaseo script and style back-end 318318 * 319319 * @return void 320320 */ 321321 public function adminEnqueueScripts() 322322 { 323323 global $current_screen; 324324 if (!empty($current_screen) && $current_screen->base !== 'wp-meta-seo_page_metaseo_google_sitemap') { 325325 return; 326326 } 327327 328328 $custom_post_types = get_post_types( 329329 array( 330330 'public' => true, 331331 'exclude_from_search' => false, 332332 '_builtin' => false 333333 ) 334334 ); 335335 336336 wp_enqueue_script( 337337 'metaseositemap', 338338 plugins_url('assets/js/metaseo_sitemap.js', dirname(__FILE__)), 339339 array('jquery'), 340340 WPMSEO_VERSION, 341341 true 342342 ); 343343 wp_localize_script( 344344 'metaseositemap', 345345 'wpmseositemap', 346346 array( 347347 'post_type' => $custom_post_types 348348 ) 349349 ); 350350 wp_enqueue_script( 351351 'jpage-js', 352352 plugins_url('assets/js/jPages.js', dirname(__FILE__)), 353353 array('jquery'), 354354 WPMSEO_VERSION, 355355 true 356356 ); 357357 wp_enqueue_style( 358358 'metaseositemapstyle', 359359 plugins_url('assets/css/metaseo_sitemap.css', dirname(__FILE__)), 360360 array(), 361361 WPMSEO_VERSION 362362 ); 363363 wp_enqueue_style( 364364 'jpage-css', 365365 plugins_url('assets/css/jPages.css', dirname(__FILE__)), 366366 array(), 367367 WPMSEO_VERSION 368368 ); 369369 wp_enqueue_style( 370370 'wpms-tippy-style', 371371 plugins_url('assets/tippy/tippy.css', WPMSEO_FILE), 372372 array(), 373373 WPMSEO_VERSION 374374 ); 375375 wp_enqueue_script( 376376 'wpms-tippy-core', 377377 plugins_url('assets/tippy/tippy-core.js', WPMSEO_FILE), 378378 array('jquery'), 379379 '2.2.1', 380380 true 381381 ); 382382 wp_enqueue_script( 383383 'wpms-tippy', 384384 plugins_url('assets/tippy/tippy.js', WPMSEO_FILE), 385385 array('jquery'), 386386 '2.2.1', 387387 true 388388 ); 389389 } 390390 391391 /** 392392 * Display field sitemap link 393393 * 394394 * @return void 395395 */ 396396 public function sitemapLink() 397397 { 398398 echo '<input id="wpms_check_firstsave" name="_metaseo_settings_sitemap[wpms_check_firstsave]" 399399 type="hidden" value="1">'; 400400 if (is_multisite()) { 401401 $home_url = preg_replace( 402402 '/[^a-zA-ZА-Яа-я0-9\s]/', 403403 '_', 404404 str_replace('http://', '', str_replace('https://', '', site_url())) 405405 ); 406406 $value = ABSPATH . '/sitemap_' . $home_url . '.xml'; 407407 $link = network_home_url('', 'relative') . 'sitemap_' . $home_url . '.xml'; 408408 } else { 409409 $value = ABSPATH . '/' . $this->wpms_sitemap_name; 410410 global $sitepress; 411411 if ($sitepress && !empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 412412 $langs = implode('-', $this->settings_sitemap['wpms_sitemap_include_lang']); 413413 $sitemap_xml_name = 'wpms-sitemap-'.$langs .'.xml'; 414414 $link = home_url() . '/' . $sitemap_xml_name; 415415 } else { 416416 $link = home_url() . '/' . $this->wpms_sitemap_name; 417417 } 418418 } 419419 420420 $refresh_install = false; 421421 // Refresh install 422422 if (!file_exists($value)) { 423423 $refresh_install = true; 424424 } 425425 426426 echo '<input readonly id="wpms_sitemap_link" name="_metaseo_settings_sitemap[wpms_sitemap_link]" 427427 type="text" value="' . esc_attr($link) . '" size="50" class="wpms-large-input wpms-no-margin wpms_width_90 '.($refresh_install ? 'wpms-sitemap-xml-link-input' : '').'" />'; 428428 echo '<a class="wpms-open-xml-sitemap ju-button orange-button waves-effect waves-light wpms-small-btn '.(($refresh_install) ? 'wpms-sitemap-xml-link-button' : '').'" href="' . esc_url($link) . '" target="_blank">' . (($refresh_install) ? esc_html__('Generate and Open', 'wp-meta-seo') : esc_html__('Open', 'wp-meta-seo')) . '</a>'; 429429 } 430430 431431 /** 432432 * Display field sitemap lang 433433 * 434434 * @return void 435435 */ 436436 public function sitemapIncludeLanguages() 437437 { 438438 $lang = $this->settings_sitemap['wpms_sitemap_include_lang']; 439439 $sl_lang = apply_filters('wpms_get_languagesList', '', $lang, 'multiple'); 440440 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method MetaSeoAddonAdmin::listLanguageSelect 441441 echo $sl_lang; 442442 } 443443 444444 /** 445445 * Display field sitemap link check 446446 * 447447 * @return void 448448 */ 449449 public function checkLink() 450450 { 451451 ?> 452452 <a href="#links-check-list" title="<?php esc_attr_e('Sitemap links', 'wp-meta-seo') ?>" 453453 class="ju-button orange-button wpms-small-btn wpms_run_linkcheck m-t-5" 454454 ><?php esc_html_e('Run a link check', 'wp-meta-seo') ?></a> 455455 <?php 456456 } 457457 458458 /** 459459 * Display field sitemap author 460460 * 461461 * @return void 462462 */ 463463 public function sitemapAuthor() 464464 { 465465 ?> 466466 <input id="wpms_sitemap_author" type="checkbox" name="_metaseo_settings_sitemap[wpms_sitemap_author]" 467467 value="1" <?php checked(1, $this->settings_sitemap['wpms_sitemap_author']); ?>> 468468 <?php 469469 } 470470 471471 /** 472472 * Display field sitemap taxonomies 473473 * 474474 * @return void 475475 */ 476476 public function sitemapTaxonomies() 477477 { 478478 $wpms_taxonomies = array( 479479 'category' => 'Post category', 480480 'post_tag' => 'Post tag' 481481 ); 482482 foreach ($wpms_taxonomies as $key => $value) { 483483 ?> 484484 <div class="pure-checkbox wpms_left wpms_width_50"> 485485 <?php if (in_array($key, $this->settings_sitemap['wpms_sitemap_taxonomies'])) : ?> 486486 <input title class="wpms_sitemap_taxonomies" 487487 id="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>" 488488 type="checkbox" 489489 name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]" 490490 value="<?php echo esc_attr($key) ?>" checked> 491491 <?php else : ?> 492492 <input title class="wpms_sitemap_taxonomies" 493493 id="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>" 494494 type="checkbox" 495495 name="_metaseo_settings_sitemap[wpms_sitemap_taxonomies][]" 496496 value="<?php echo esc_attr($key) ?>"> 497497 <?php endif; ?> 498498 <label class="wpms-text" 499499 for="<?php echo esc_attr('wpms_sitemap_taxonomies_' . $key); ?>"><?php echo esc_html($value) ?></label> 500500 </div> 501501 <?php 502502 } 503503 } 504504 505505 /** 506506 * Display field sitemap list page 507507 * 508508 * @return void 509509 */ 510510 public function sitemapPage() 511511 { 512512 global $wpdb; 513513 $pages = get_pages(); 514514 $sitemap_page = $wpdb->get_row($wpdb->prepare( 515515 'SELECT * FROM ' . $wpdb->prefix . 'posts WHERE post_title = %s AND post_excerpt = %s AND post_type = %s', 516516 array( 517517 'WPMS HTML Sitemap', 518518 'metaseo_html_sitemap', 519519 'page' 520520 ) 521521 )); 522522 523523 if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) { 524524 $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID; 525525 } 526526 ?> 527527 <select id="wpms_html_sitemap_page" name="_metaseo_settings_sitemap[wpms_html_sitemap_page]" 528528 class="wpms-large-input wpms_width_90"> 529529 <option value="0"><?php esc_html_e('- Choose Your Sitemap Page -', 'wp-meta-seo') ?></option> 530530 <?php 531531 foreach ($pages as $page) { 532532 if ((int) $this->settings_sitemap['wpms_html_sitemap_page'] === (int) $page->ID) { 533533 echo '<option selected value="' . esc_attr($page->ID) . '">' . esc_html($page->post_title) . '</option>'; 534534 } else { 535535 echo '<option value="' . esc_attr($page->ID) . '">' . esc_html($page->post_title) . '</option>'; 536536 } 537537 } 538538 ?> 539539 </select> 540540 <?php 541541 if (!empty($this->settings_sitemap['wpms_html_sitemap_page'])) { 542542 echo '<a class="ju-button orange-button waves-effect waves-light wpms-open-html-sitemap wpms-no-margin wpms-small-btn" href="' . esc_url(get_post_permalink($this->settings_sitemap['wpms_html_sitemap_page'])) . '" 543543 target="_blank">' . esc_html__('Open', 'wp-meta-seo') . '</a>'; 544544 } 545545 ?> 546546 <?php 547547 } 548548 549549 /** 550550 * Display field sitemap column 551551 * 552552 * @return void 553553 */ 554554 public function sitemapColumn() 555555 { 556556 ?> 557557 <label> 558558 <select id="wpms_html_sitemap_column" name="_metaseo_settings_sitemap[wpms_html_sitemap_column]" 559559 class="wpms-large-input wpms_width_100"> 560560 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 1) ?> 561561 value="1"><?php esc_html_e('1 column', 'wp-meta-seo') ?></option> 562562 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 2) ?> 563563 value="2"><?php esc_html_e('2 columns', 'wp-meta-seo') ?></option> 564564 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_column'], 3) ?> 565565 value="3"><?php esc_html_e('3 columns', 'wp-meta-seo') ?></option> 566566 </select> 567567 </label> 568568 <?php 569569 } 570570 571571 /** 572572 * Display field sitemap position 573573 * 574574 * @return void 575575 */ 576576 public function sitemapTheme() 577577 { 578578 ?> 579579 <label> 580580 <select id="wpms_html_sitemap_theme" name="_metaseo_settings_sitemap[wpms_html_sitemap_theme]" 581581 class="wpms-large-input wpms_width_100"> 582582 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'default') ?> 583583 value="default"><?php esc_html_e('Simple list', 'wp-meta-seo') ?></option> 584584 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'accordions') ?> 585585 value="accordions"><?php esc_html_e('List with accordions', 'wp-meta-seo') ?></option> 586586 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_theme'], 'tab') ?> 587587 value="tab"><?php esc_html_e('Tab layout', 'wp-meta-seo') ?></option> 588588 </select> 589589 </label> 590590 <?php 591591 } 592592 593593 /** 594594 * Display field sitemap position 595595 * 596596 * @return void 597597 */ 598598 public function sitemapPosition() 599599 { 600600 ?> 601601 <select id="wpms_html_sitemap_position" name="_metaseo_settings_sitemap[wpms_html_sitemap_position]" 602602 class="wpms-large-input wpms_width_100"> 603603 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'replace') ?> 604604 value="replace"><?php esc_html_e('Replace the Page Content', 'wp-meta-seo') ?></option> 605605 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'before') ?> 606606 value="before"><?php esc_html_e('Before Page Content', 'wp-meta-seo') ?></option> 607607 <option <?php selected($this->settings_sitemap['wpms_html_sitemap_position'], 'after') ?> 608608 value="after"><?php esc_html_e('After Page Content', 'wp-meta-seo') ?></option> 609609 </select> 610610 <?php 611611 } 612612 613613 /** 614614 * Get info of sitemap file xml 615615 * 616616 * @return array 617617 */ 618618 public function getPathSitemapFile() 619619 { 620620 if (is_multisite()) { 621621 $home_url = preg_replace( 622622 '/[^a-zA-ZА-Яа-я0-9\s]/', 623623 '_', 624624 str_replace('http://', '', str_replace('https://', '', site_url())) 625625 ); 626626 $xml_file = 'wpms-sitemap_' . $home_url . '.xml'; 627627 } else { 628628 $xml_file = $this->wpms_sitemap_name; 629629 } 630630 $xml_path = ABSPATH . $xml_file; 631631 return array('path' => $xml_path, 'name' => $xml_file); 632632 } 633633 634634 /** 635635 * Check external link 636636 * 637637 * @param string $link Link to check 638638 * 639639 * @return boolean 640640 */ 641641 public function checkExternalLink($link) 642642 { 643643 if (empty($link)) { 644644 return true; 645645 } 646646 647647 $parseLink = parse_url($link); 648648 649649 if (empty($parseLink['host'])) { 650650 // Maybe is an internal link 651651 return false; 652652 } 653653 global $sitepress; 654654 if ($sitepress || $parseLink['host'] === $_SERVER['HTTP_HOST']) { 655655 // Is an internal link 656656 return false; 657657 } 658658 659659 return true; 660660 } 661661 662662 /** 663663 * Check custom link 664664 * 665665 * @param string $link Link to check 666666 * 667667 * @return string 668668 */ 669669 public function customLink($link) 670670 { 671671 if (empty($link)) { 672672 return $link; 673673 } 674674 675675 if (preg_match('#http(s?)://#i', $link)) { 676676 return $link; 677677 } 678678 679679 $parseHome = parse_url(home_url()); 680680 681681 $http = (is_ssl()) ? 'https:' : 'http:'; 682682 $host = (!empty($parseHome['host']) ? $parseHome['host'] : ''); 683683 $host .= (!empty($parseHome['path']) ? $parseHome['path'] : ''); 684684 685685 if (substr($link, 0, 2) === '//') { 686686 return $http . $link; 687687 } 688688 689689 // Force the path become relative. 690690 if (substr($link, 0, 1) === '/') { 691691 if (!empty($host)) { 692692 return $http . '//' . $host . $link; 693693 } 694694 } 695695 696696 return $link; 697697 } 698698 699699 /** 700700 * Create sitemap 701701 * 702702 * @param string $sitemap_xml_name Sitemap file name 703703 * 704704 * @return void 705705 */ 706706 public function createSitemap($sitemap_xml_name) 707707 { 708708 global $wpdb, $sitepress; 709709 $taxonomies = array(); 710710 $list_links = array(); 711711 foreach ($this->settings_sitemap['wpms_sitemap_taxonomies'] as $val) { 712712 $taxonomies[] = $val; 713713 } 714714 715715 $xml = new DomDocument('1.0', 'utf-8'); 716716 $xml_stylesheet_path = content_url(); 717717 if (defined('WP_PLUGIN_DIR')) { 718718 $xml_stylesheet_path .= '/' . basename(WP_PLUGIN_DIR) . '/wp-meta-seo/wpms-sitemap.xsl'; 719719 } else { 720720 $xml_stylesheet_path .= '/plugins/wp-meta-seo/sitemap.xsl'; 721721 } 722722 723723 $xslt = $xml->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $xml_stylesheet_path . '"'); 724724 $xml->appendChild($xslt); 725725 $gglstmp_urlset = $xml->appendChild( 726726 $xml->createElementNS( 727727 'http://www.sitemaps.org/schemas/sitemap/0.9', 728728 'urlset' 729729 ) 730730 ); 731731 $gglstmp_urlset->setAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); 732732 /* add home page */ 733733 $home_url = home_url('/'); 734734 if ($sitepress && !empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 735735 $domains = $sitepress->get_setting('language_domains'); 736736 $default_language = $sitepress->get_default_language(); 737737 $wpms_lang = $this->settings_sitemap['wpms_sitemap_include_lang'][0]; 738738 if ($wpms_lang !== $default_language) { 739739 $home_schema = wpml_parse_url($home_url, PHP_URL_SCHEME) . '://'; 740740 $home_url = $home_schema . $domains[$wpms_lang]; 741741 } 742742 } 743743 $list_links[] = $home_url; 744744 $url = $gglstmp_urlset->appendChild($xml->createElement('url')); 745745 $loc = $url->appendChild($xml->createElement('loc')); 746746 $loc->appendChild($xml->createTextNode($home_url)); 747747 $lastmod = $url->appendChild($xml->createElement('lastmod')); 748748 $lastmod->appendChild($xml->createTextNode(date('Y-m-d\TH:i:sP', time()))); 749749 $changefreq = $url->appendChild($xml->createElement('changefreq')); 750750 $changefreq->appendChild($xml->createTextNode('monthly')); 751751 $priority = $url->appendChild($xml->createElement('priority')); 752752 $priority->appendChild($xml->createTextNode(1.0)); 753753 754754 // add menus post custom 755755 $menus = $this->getAllMenus(); 756756 $res = $menus['posts_custom']; 757757 if (!empty($res)) { 758758 foreach ($res as $val) { 759759 $menu_object = $wpdb->get_results($wpdb->prepare( 760760 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s AND meta_value=%d', 761761 array('_menu_item_object_id', $val->ID) 762762 )); 763763 if (!empty($menu_object)) { 764764 foreach ($menu_object as $menu) { 765765 $id = $menu->post_id; 766766 $type = get_post_meta($id, '_menu_item_type', true); 767767 $check_type = get_post_meta($id, '_menu_item_object', true); 768768 $permalink = $this->getPermalinkSitemap($check_type, $val->ID); 769769 if ($permalink !== '#') { 770770 if (strpos($permalink, '#') !== false) { 771771 // Check anchor links 772772 $permalink = strstr($permalink, '#', true); 773773 } 774774 775775 // Filter full link with custom link 776776 $permalink = $this->customLink($permalink); 777777 778778 // Check to exclude external link 779779 if ($this->checkExternalLink($permalink)) { 780780 continue; 781781 } 782782 783783 if (!in_array($permalink, $list_links)) { 784784 $list_links[] = $permalink; 785785 if ($type !== 'taxonomy') { 786786 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 787787 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 788788 $loc->appendChild($xml->createTextNode($permalink)); 789789 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 790790 $now = $val->post_modified; 791791 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 792792 $lastmod->appendChild($xml->createTextNode($date)); 793793 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 794794 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 795795 $changefreq->appendChild($xml->createTextNode('monthly')); 796796 } else { 797797 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'])) { 798798 $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'] = 'monthly'; 799799 } 800800 $changefreq->appendChild( 801801 $xml->createTextNode( 802802 $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'] 803803 ) 804804 ); 805805 } 806806 807807 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 808808 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 809809 $priority->appendChild($xml->createTextNode('1.0')); 810810 } else { 811811 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'])) { 812812 $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'] = '1.0'; 813813 } 814814 $priority->appendChild( 815815 $xml->createTextNode( 816816 $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'] 817817 ) 818818 ); 819819 } 820820 821821 $this->createXmlLang( 822822 $xml, 823823 $id, 824824 'post_post', 825825 $loc 826826 ); 827827 } 828828 } 829829 } 830830 } 831831 } 832832 } 833833 } 834834 835835 // add menus category 836836 $res = $menus['categories']; 837837 if (!empty($res)) { 838838 foreach ($res as $k => $val) { 839839 $menu_object = $wpdb->get_results($wpdb->prepare( 840840 'SELECT post_id FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s AND meta_value=%d', 841841 array( 842842 '_menu_item_object_id', 843843 $val 844844 ) 845845 )); 846846 if (!empty($menu_object)) { 847847 foreach ($menu_object as $menu) { 848848 $id = $menu->post_id; 849849 $type = get_post_meta($id, '_menu_item_type', true); 850850 $check_type = get_post_meta($id, '_menu_item_object', true); 851851 $permalink = get_term_link((int) $val, $check_type); 852852 if (empty($permalink)) { 853853 $permalink = get_permalink($id); 854854 } 855855 if (strpos($permalink, '#') !== false) { 856856 // Check anchor links 857857 $permalink = strstr($permalink, '#', true); 858858 } 859859 860860 // Filter full link with custom link 861861 $permalink = $this->customLink($permalink); 862862 863863 // Check to exclude external link 864864 if ($this->checkExternalLink($permalink)) { 865865 continue; 866866 } 867867 868868 if (!in_array($permalink, $list_links)) { 869869 $list_links[] = $permalink; 870870 if ($type === 'taxonomy') { 871871 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 872872 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 873873 $loc->appendChild($xml->createTextNode($permalink)); 874874 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 875875 $ps = get_post($id); 876876 877877 if (!empty($ps)) { 878878 $now = $ps->post_modified; 879879 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 880880 $lastmod->appendChild($xml->createTextNode($date)); 881881 } 882882 883883 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 884884 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 885885 $changefreq->appendChild($xml->createTextNode('monthly')); 886886 } else { 887887 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency'])) { 888888 $menufre = 'monthly'; 889889 } else { 890890 $menufre = $this->settings_sitemap['wpms_sitemap_menus'][$id]['frequency']; 891891 } 892892 $changefreq->appendChild($xml->createTextNode($menufre)); 893893 } 894894 895895 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 896896 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 897897 $priority->appendChild($xml->createTextNode('1.0')); 898898 } else { 899899 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$id]['priority'])) { 900900 $menupriority = '1.0'; 901901 } else { 902902 $menupriority = $this->settings_sitemap['wpms_sitemap_menus'][$id]['priority']; 903903 } 904904 $priority->appendChild($xml->createTextNode($menupriority)); 905905 } 906906 $this->createXmlLang($xml, $id, 'post_post', $loc); 907907 } 908908 } 909909 } 910910 } 911911 } 912912 } 913913 914914 if ($sitepress) { 915915 $sitepress->switch_lang('all', false); 916916 } 917917 // add posts 918918 $res = $this->getPostsSitemap(); 919919 if (!empty($res)) { 920920 foreach ($res as $val) { 921921 /* get translation post id */ 922922 $permalink = get_permalink($val->ID); 923923 if (strpos($permalink, '#') !== false) { 924924 // Check anchor links 925925 $permalink = strstr($permalink, '#', true); 926926 } 927927 928928 // Filter full link with custom link 929929 $permalink = $this->customLink($permalink); 930930 931931 // Check to exclude external link 932932 if ($this->checkExternalLink($permalink)) { 933933 continue; 934934 } 935935 936936 if (!in_array($permalink, $list_links)) { 937937 $list_links[] = $permalink; 938938 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 939939 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 940940 $loc->appendChild($xml->createTextNode($permalink)); 941941 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 942942 $now = $val->post_modified; 943943 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 944944 $lastmod->appendChild($xml->createTextNode($date)); 945945 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 946946 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 947947 $changefreq->appendChild($xml->createTextNode('monthly')); 948948 } else { 949949 if (empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency'])) { 950950 $postfrequency = 'monthly'; 951951 } else { 952952 $postfrequency = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['frequency']; 953953 } 954954 $changefreq->appendChild($xml->createTextNode($postfrequency)); 955955 } 956956 957957 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 958958 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 959959 $priority->appendChild($xml->createTextNode('1.0')); 960960 } else { 961961 if (empty($this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority'])) { 962962 $postpriority = '1.0'; 963963 } else { 964964 $postpriority = $this->settings_sitemap['wpms_sitemap_posts'][$val->ID]['priority']; 965965 } 966966 $priority->appendChild($xml->createTextNode($postpriority)); 967967 } 968968 969969 $this->createXmlLang($xml, $val->ID, 'post_post', $loc); 970970 } 971971 } 972972 } 973973 974974 // run when WP Meta SEO Addon active 975975 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 976976 // add custom post type 977977 $custom_post_types = get_post_types( 978978 array( 979979 'public' => true, 980980 'exclude_from_search' => false, 981981 '_builtin' => false 982982 ) 983983 ); 984984 if (!empty($custom_post_types)) { 985985 foreach ($custom_post_types as $pt => $label) { 986986 $ids = array(0); 987987 $settings_sitemap = get_option('_metaseo_settings_sitemap'); 988988 if (!empty($settings_sitemap['wpms_sitemap_' . $pt])) { 989989 foreach ((array) $settings_sitemap['wpms_sitemap_' . $pt] as $k => $v) { 990990 if (!empty($v['post_id'])) { 991991 $ids[] = (int) $v['post_id']; 992992 } 993993 } 994994 } 995995 996996 $posts = $wpdb->get_results($wpdb->prepare('SELECT ID, post_modified FROM ' . $wpdb->posts . ' WHERE post_status = %s AND post_type = %s AND ID IN (' . implode(',', esc_sql($ids)) . ') ORDER BY post_date DESC', array( 997997 'publish', 998998 $pt 999999 ))); 10001000 if (!empty($posts)) { 10011001 foreach ($posts as $val) { 10021002 $permalink = get_permalink($val->ID); 10031003 if (strpos($permalink, '#') !== false) { 10041004 // Check anchor links 10051005 $permalink = strstr($permalink, '#', true); 10061006 } 10071007 10081008 // Filter full link with custom link 10091009 $permalink = $this->customLink($permalink); 10101010 10111011 // Check to exclude external link 10121012 if ($this->checkExternalLink($permalink)) { 10131013 continue; 10141014 } 10151015 10161016 if (!in_array($permalink, $list_links)) { 10171017 $list_links[] = $permalink; 10181018 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 10191019 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 10201020 $loc->appendChild($xml->createTextNode($permalink)); 10211021 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 10221022 $now = $val->post_modified; 10231023 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 10241024 $lastmod->appendChild($xml->createTextNode($date)); 10251025 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 10261026 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 10271027 $changefreq->appendChild($xml->createTextNode('monthly')); 10281028 } else { 10291029 if (empty($this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['frequency'])) { 10301030 $postfr = 'monthly'; 10311031 } else { 10321032 $postfr = $this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['frequency']; 10331033 } 10341034 $changefreq->appendChild($xml->createTextNode($postfr)); 10351035 } 10361036 10371037 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 10381038 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 10391039 $priority->appendChild($xml->createTextNode('1.0')); 10401040 } else { 10411041 if (empty($this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['priority'])) { 10421042 $postpri = '1.0'; 10431043 } else { 10441044 $postpri = $this->settings_sitemap['wpms_sitemap_' . $pt][$val->ID]['priority']; 10451045 } 10461046 $priority->appendChild($xml->createTextNode($postpri)); 10471047 } 10481048 10491049 $this->createXmlLang( 10501050 $xml, 10511051 $val->ID, 10521052 'post_post', 10531053 $loc 10541054 ); 10551055 } 10561056 } 10571057 } 10581058 } 10591059 } 10601060 10611061 // add custom Url 10621062 $listUrls = get_option('wpms_customUrls_list'); 10631063 $settings = get_option('_metaseo_settings_sitemap'); 10641064 if (!empty($settings['wpms_sitemap_customUrl']) && $settings['wpms_sitemap_customUrl'] !== '{}') { 10651065 foreach ($settings['wpms_sitemap_customUrl'] as $key => $customUrl) { 10661066 if (!empty($listUrls[$key])) { 10671067 if (strpos($listUrls[$key]['link'], '#') !== false) { 10681068 // Check anchor links 10691069 $listUrls[$key]['link'] = strstr($listUrls[$key]['link'], '#', true); 10701070 } 10711071 10721072 // Filter full link with custom link 10731073 $listUrls[$key]['link'] = $this->customLink($listUrls[$key]['link']); 10741074 10751075 // Check to exclude external link 10761076 if ($this->checkExternalLink($listUrls[$key]['link'])) { 10771077 continue; 10781078 } 10791079 10801080 if (!in_array($listUrls[$key]['link'], $list_links)) { 10811081 $list_links[] = $listUrls[$key]['link']; 10821082 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 10831083 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 10841084 10851085 $loc->appendChild($xml->createTextNode($listUrls[$key]['link'])); 10861086 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 10871087 $date = date('Y-m-d\TH:i:sP', $key); 10881088 $lastmod->appendChild($xml->createTextNode($date)); 10891089 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 10901090 10911091 if (empty($customUrl['frequency'])) { 10921092 $pagefrequency = 'monthly'; 10931093 } else { 10941094 $pagefrequency = $customUrl['frequency']; 10951095 } 10961096 $changefreq->appendChild($xml->createTextNode($pagefrequency)); 10971097 10981098 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 10991099 11001100 if (empty($customUrl['priority'])) { 11011101 $pagepriority = '1.0'; 11021102 } else { 11031103 $pagepriority = $customUrl['priority']; 11041104 } 11051105 $priority->appendChild($xml->createTextNode($pagepriority)); 11061106 } 11071107 } 11081108 } 11091109 } 11101110 } 11111111 // ======================================== 11121112 // add pages 11131113 $res = $this->getPagesSitemap(); 11141114 if (!empty($res)) { 11151115 foreach ($res as $val) { 11161116 /* get translation post id */ 11171117 $permalink = get_permalink($val->ID); 11181118 if (strpos($permalink, '#') !== false) { 11191119 // Check anchor links 11201120 $permalink = strstr($permalink, '#', true); 11211121 } 11221122 11231123 // Filter full link with custom link 11241124 $permalink = $this->customLink($permalink); 11251125 11261126 // Check to exclude external link 11271127 if ($this->checkExternalLink($permalink)) { 11281128 continue; 11291129 } 11301130 11311131 if (!in_array($permalink, $list_links)) { 11321132 $list_links[] = $permalink; 11331133 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 11341134 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 11351135 11361136 $loc->appendChild($xml->createTextNode($permalink)); 11371137 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 11381138 $now = $val->post_modified; 11391139 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 11401140 $lastmod->appendChild($xml->createTextNode($date)); 11411141 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 11421142 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 11431143 $changefreq->appendChild($xml->createTextNode('monthly')); 11441144 } else { 11451145 if (empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency'])) { 11461146 $pagefrequency = 'monthly'; 11471147 } else { 11481148 $pagefrequency = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['frequency']; 11491149 } 11501150 $changefreq->appendChild($xml->createTextNode($pagefrequency)); 11511151 } 11521152 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 11531153 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 11541154 $priority->appendChild($xml->createTextNode('1.0')); 11551155 } else { 11561156 if (empty($this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority'])) { 11571157 $pagepriority = '1.0'; 11581158 } else { 11591159 $pagepriority = $this->settings_sitemap['wpms_sitemap_pages'][$val->ID]['priority']; 11601160 } 11611161 $priority->appendChild($xml->createTextNode($pagepriority)); 11621162 } 11631163 11641164 $this->createXmlLang($xml, $val->ID, 'post_page', $loc); 11651165 } 11661166 } 11671167 } 11681168 11691169 // add category 11701170 if (!empty($taxonomies)) { 11711171 foreach ($taxonomies as $value) { 11721172 $terms = get_terms($value, 'hide_empty=1'); 11731173 if (!empty($terms) && !is_wp_error($terms)) { 11741174 foreach ($terms as $term_value) { 11751175 $permalink = get_term_link((int) $term_value->term_id, $value); 11761176 if (strpos($permalink, '#') !== false) { 11771177 // Check anchor links 11781178 $permalink = strstr($permalink, '#', true); 11791179 } 11801180 11811181 // Filter full link with custom link 11821182 $permalink = $this->customLink($permalink); 11831183 11841184 // Check to exclude external link 11851185 if ($this->checkExternalLink($permalink)) { 11861186 continue; 11871187 } 11881188 11891189 if (!in_array($permalink, $list_links)) { 11901190 $list_links[] = $permalink; 11911191 $gglstmp_url = $gglstmp_urlset->appendChild($xml->createElement('url')); 11921192 $loc = $gglstmp_url->appendChild($xml->createElement('loc')); 11931193 11941194 $loc->appendChild($xml->createTextNode($permalink)); 11951195 $lastmod = $gglstmp_url->appendChild($xml->createElement('lastmod')); 11961196 11971197 $now = $wpdb->get_var( 11981198 $wpdb->prepare('SELECT post_modified FROM ' . $wpdb->posts . ' AS posttable, ' . $wpdb->term_relationships . ' AS termrelationship WHERE post_status = %s AND term_taxonomy_id = %d AND posttable.ID = termrelationship.object_id ORDER BY post_modified DESC', array( 11991199 'publish', 12001200 $term_value->term_taxonomy_id 12011201 )) 12021202 ); 12031203 $date = date('Y-m-d\TH:i:sP', strtotime($now)); 12041204 $lastmod->appendChild($xml->createTextNode($date)); 12051205 $changefreq = $gglstmp_url->appendChild($xml->createElement('changefreq')); 12061206 $changefreq->appendChild($xml->createTextNode('monthly')); 12071207 $priority = $gglstmp_url->appendChild($xml->createElement('priority')); 12081208 $priority->appendChild($xml->createTextNode(1.0)); 12091209 } 12101210 } 12111211 } 12121212 } 12131213 } 12141214 12151215 $xml->formatOutput = true; 12161216 12171217 if (!is_writable(ABSPATH)) { 12181218 chmod(ABSPATH, 0755); 12191219 } 12201220 12211221 /** 12221222 * Filter run before save sitemap to xml file 12231223 * 12241224 * @param object The current xml object 12251225 * 12261226 * @return object 12271227 */ 12281228 $xml = apply_filters('wpms_save_sitemap_xml', $xml); 12291229 12301230 if (is_multisite()) { 12311231 $home_url = preg_replace( 12321232 '/[^a-zA-ZА-Яа-я0-9\s]/', 12331233 '_', 12341234 str_replace('http://', '', str_replace('https://', '', site_url())) 12351235 ); 12361236 $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml'); 12371237 } else { 12381238 if ($sitepress && !empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 12391239 $langs = implode('-', $this->settings_sitemap['wpms_sitemap_include_lang']); 12401240 $sitemap_xml_name = 'wpms-sitemap-'.$langs .'.xml'; 12411241 } 12421242 $xml->save(ABSPATH . $sitemap_xml_name); 12431243 } 12441244 $this->sitemapInfos(); 12451245 } 12461246 12471247 /** 12481248 * Create xml language 12491249 * 12501250 * @param object $xml XML 12511251 * @param integer $id Element Id 12521252 * @param string $el_type Element type 12531253 * @param object $loc Node Info 12541254 * 12551255 * @return void 12561256 */ 12571257 public function createXmlLang($xml, $id, $el_type, $loc) 12581258 { 12591259 if (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('sitepress-multilingual-cms/sitepress.php')) { 12601260 if (!empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 12611261 global $sitepress; 12621262 $trid = $sitepress->get_element_trid($id, $el_type); 12631263 if ($trid) { 12641264 // get post $translation 12651265 $translations = $sitepress->get_element_translations($trid, $el_type, true, true, true); 12661266 foreach ($translations as $translation) { 12671267 if (isset($translation->language_code) 12681268 && in_array( 12691269 $translation->language_code, 12701270 $this->settings_sitemap['wpms_sitemap_include_lang'] 12711271 )) { 12721272 $permalink = get_permalink($translation->element_id); 12731273 // can use 12741274 // $xml->appendChild($xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link')); 12751275 $node = $xml->appendChild($xml->createElement('xhtml:link')); 12761276 $node->setAttribute('rel', 'alternate'); 12771277 $node->setAttribute('hreflang', $translation->language_code); 12781278 $node->setAttribute('href', $permalink); 12791279 $loc->parentNode->appendChild($node); 12801280 } 12811281 } 12821282 } 12831283 } 12841284 } elseif (is_plugin_active(WPMSEO_ADDON_FILENAME) && is_plugin_active('polylang/polylang.php')) { 12851285 if (!empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 12861286 global $polylang; 12871287 $model = $polylang->filters->links_model->model; 12881288 $model_post = $polylang->filters->links_model->model->post; 12891289 foreach ($model->get_languages_list() as $language) { 12901290 $value = $model_post->get_translation($id, $language); 12911291 if ($value) { 12921292 $lang = pll_get_post_language($value); 12931293 if (isset($lang) && in_array($lang, $this->settings_sitemap['wpms_sitemap_include_lang'])) { 12941294 $permalink = get_permalink($value); 12951295 $node = $xml->appendChild( 12961296 $xml->createElementNS('http://www.w3.org/1999/xhtml', 'xhtml:link') 12971297 ); 12981298 $node->setAttribute('rel', 'alternate'); 12991299 $node->setAttribute('hreflang', $lang); 13001300 $node->setAttribute('href', $permalink); 13011301 $loc->parentNode->appendChild($node); 13021302 } 13031303 } 13041304 } 13051305 } 13061306 } 13071307 } 13081308 13091309 /** 13101310 * Retrieves the full permalink for the current post or post ID 13111311 * 13121312 * @param string $type Element type 13131313 * @param integer $id Element id 13141314 * 13151315 * @return false|mixed|string 13161316 */ 13171317 public function getPermalinkSitemap($type, $id) 13181318 { 13191319 if (isset($type) && $type === 'custom') { 13201320 $permalink = get_post_meta($id, '_menu_item_url', true); 13211321 } elseif ($type === 'taxonomy') { 13221322 $permalink = get_category_link($id); 13231323 } else { 13241324 $permalink = get_permalink($id); 13251325 } 13261326 return $permalink; 13271327 } 13281328 13291329 /** 13301330 * Update sitemap setting 13311331 * 13321332 * @return void 13331333 */ 13341334 public function sitemapInfos() 13351335 { 13361336 $settings = get_option('_metaseo_settings_sitemap'); 13371337 $info_file = $this->getPathSitemapFile(); 13381338 $xml_url = site_url('/') . $info_file['name']; 13391339 if (file_exists($info_file['path'])) { 13401340 $settings['sitemap'] = array( 13411341 'file' => $info_file['name'], 13421342 'path' => $info_file['path'], 13431343 'loc' => $xml_url, 13441344 'lastmod' => date('Y-m-d\TH:i:sP', filemtime($info_file['path'])) 13451345 ); 13461346 update_option('_metaseo_settings_sitemap', $settings); 13471347 } 13481348 } 13491349 13501350 /** 13511351 * Display sitemap posts by column in front-end 13521352 * 13531353 * @return string 13541354 */ 13551355 public function displayPosts() 13561356 { 13571357 $html = ''; 13581358 $postTitle = get_post_type_object('post'); 13591359 $postTitle = $postTitle->label; 13601360 13611361 if (get_option('show_on_front') === 'page') { 13621362 $postsURL = get_permalink(get_option('page_for_posts')); 13631363 $postTitle = get_the_title(get_option('page_for_posts')); 13641364 } else { 13651365 $postsURL = get_bloginfo('url'); 13661366 } 13671367 13681368 if (!empty($this->settings_sitemap['wpms_public_name_posts'])) { 13691369 $postTitle = $this->settings_sitemap['wpms_public_name_posts']; 13701370 } 13711371 $html .= '<div id="sitemap_posts" class="wpms_sitemap_posts"><h4>'; 13721372 if ($postsURL !== '' && $postsURL !== get_permalink($this->settings_sitemap['wpms_html_sitemap_page'])) { 13731373 $html .= '<a href="' . $postsURL . '">' . $postTitle . '</a>'; 13741374 } else { 13751375 $html .= $postTitle; 13761376 } 13771377 $html .= '</h4><ul>'; 13781378 13791379 //Categories 13801380 $ids = array(0); 13811381 if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) { 13821382 foreach ((array) $this->settings_sitemap['wpms_sitemap_posts'] as $k => $v) { 13831383 if (!empty($v['post_id'])) { 13841384 $ids[] = $k; 13851385 } 13861386 } 13871387 } 13881388 13891389 $cats = get_categories(array('taxonomy' => 'category', 'hide_empty' => true)); 13901390 foreach ($cats as $cat) { 13911391 if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) { 13921392 $cat_link = '<a href="' . esc_url(get_term_link($cat)) . '">' . esc_html($cat->cat_name) . '</a>'; 13931393 } else { 13941394 $cat_link = $cat->cat_name; 13951395 } 13961396 $html .= '<li class="wpms_li_cate"><div class="cat_name">' . $cat_link . '</div></li>'; 13971397 13981398 if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) { 13991399 query_posts(array('post__in' => $ids, 'posts_per_page' => - 1, 'cat' => $cat->cat_ID)); 14001400 while (have_posts()) { 14011401 the_post(); 14021402 if ((get_post_meta(get_the_ID(), '_yoast_wpseo_meta-robots-noindex', true) === '1' 14031403 && get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) !== 'always') 14041404 || (get_post_meta(get_the_ID(), '_yoast_wpseo_sitemap-include', true) === 'never') 14051405 || (get_post_meta(get_the_ID(), '_yoast_wpms_redirect', true) !== '')) { 14061406 continue; 14071407 } 14081408 14091409 $category = get_the_category(); 14101410 // Only display a post link once, even if it's in multiple categories 14111411 if ((int) $category[0]->cat_ID === (int) $cat->cat_ID) { 14121412 $html .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; 14131413 } 14141414 } 14151415 wp_reset_query(); 14161416 } 14171417 } 14181418 $html .= '</ul></div>'; 14191419 $html .= '<div class="holder holder_sitemaps_posts"></div>'; 14201420 14211421 return $html; 14221422 } 14231423 14241424 /** 14251425 * Display sitemap pages by column in front-end 14261426 * 14271427 * @return string 14281428 */ 14291429 public function displayPages() 14301430 { 14311431 $html = ''; 14321432 if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) { 14331433 $pageTitle = get_post_type_object('page'); 14341434 $pageTitle = $pageTitle->label; 14351435 if (!empty($this->settings_sitemap['wpms_public_name_pages'])) { 14361436 $pageTitle = $this->settings_sitemap['wpms_public_name_pages']; 14371437 } 14381438 $html .= '<div id="sitemap_pages" class="wpms_sitemap_pages"><h4>' . $pageTitle . '</h4> 14391439 <ul>'; 14401440 $pageInc = ''; 14411441 $getPages = $this->getPagesSitemap(); 14421442 foreach ($getPages as $page) { 14431443 if (isset($this->settings_sitemap['wpms_html_sitemap_page']) 14441444 && (int) $page->ID !== (int) $this->settings_sitemap['wpms_html_sitemap_page']) { 14451445 if ((get_post_meta($page->ID, '_yoast_wpseo_meta-robots-noindex', true) === '1' 14461446 && get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) !== 'always') 14471447 || (get_post_meta($page->ID, '_yoast_wpseo_sitemap-include', true) === 'never') 14481448 || (get_post_meta($page->ID, '_yoast_wpms_redirect', true) !== '')) { 14491449 continue; 14501450 } 14511451 if ($pageInc === '') { 14521452 $pageInc = $page->ID; 14531453 continue; 14541454 } 14551455 $pageInc .= ', ' . $page->ID; 14561456 } 14571457 } 14581458 14591459 if ($pageInc !== '') { 14601460 $html .= wp_list_pages( 14611461 array( 14621462 'include' => $pageInc, 14631463 'title_li' => '', 14641464 'sort_column' => 'post_title', 14651465 'sort_order' => 'ASC', 14661466 'echo' => false 14671467 ) 14681468 ); 14691469 } 14701470 14711471 $html .= '</ul></div>'; 14721472 $html .= '<div class="holder holder_sitemaps_pages"></div>'; 14731473 } 14741474 return $html; 14751475 } 14761476 14771477 /** 14781478 * Display sitemap customUrl by column in front-end 14791479 * 14801480 * @return string 14811481 */ 14821482 public function displayCustomUrl() 14831483 { 14841484 $html = ''; 14851485 $lists = $this->settings_sitemap['wpms_sitemap_customUrl']; 14861486 $links = get_option('wpms_customUrls_list'); 14871487 if (!empty($lists)) { 14881488 $html .= '<div id="sitemap_customUrl" class="wpms_sitemap_customUrl">'; 14891489 if (!empty($this->settings_sitemap['wpms_public_name_customUrl'])) { 14901490 $publictitle = $this->settings_sitemap['wpms_public_name_customUrl']; 14911491 } else { 14921492 $publictitle = esc_html__('Custom Url', 'wp-meta-seo'); 14931493 } 14941494 14951495 if (!empty($lists) && $lists !== '{}') { 14961496 $html .= '<h4>' . $publictitle . '</h4>'; 14971497 $html .= '<ul>'; 14981498 foreach ($lists as $key => $list) { 14991499 if (!empty($links[$key])) { 15001500 $html .= '<li>'; 15011501 $html .= '<a href="' . esc_url($links[$key]['link']) . '">' . esc_html($links[$key]['title']) . '</a>'; 15021502 $html .= '</li>'; 15031503 } 15041504 } 15051505 15061506 $html .= '</ul>'; 15071507 } 15081508 15091509 $html .= '</div>'; 15101510 $html .= '<div class="holder holder_sitemaps_customUrl"></div>'; 15111511 } 15121512 15131513 return $html; 15141514 } 15151515 15161516 /** 15171517 * Render sitemap theme default 15181518 * 15191519 * @return string 15201520 */ 15211521 public function sitemapThemeDefault() 15221522 { 15231523 $html = ''; 15241524 $html .= '<div id="wpms_sitemap" 15251525 class="' . esc_attr('theme_default columns_' . $this->settings_sitemap['wpms_html_sitemap_column']) . '">'; 15261526 $arrs = array('displayPosts' => 'wpms_display_column_posts', 'displayPages' => 'wpms_display_column_pages'); 15271527 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 15281528 $arrs['displayCustomUrl'] = 'wpms_display_column_customUrl'; 15291529 } 15301530 $checkColumn = array(); 15311531 for ($i = 1; $i <= (int) $this->settings_sitemap['wpms_html_sitemap_column']; $i ++) { 15321532 $html .= '<div class="' . esc_attr('wpms_column wpms_column_' . $i) . '" style="width:33%;float:left;">'; 15331533 if ((int) $i === 1) { 15341534 // Authors 15351535 if ((int) $this->settings_sitemap['wpms_sitemap_author'] === 1) { 15361536 $html .= '<div id="sitemap_authors"><h3>' . esc_html__('Authors', 'wp-meta-seo') . '</h3> 15371537 <ul>'; 15381538 15391539 $authEx = implode( 15401540 ', ', 15411541 get_users('orderby=nicename&meta_key=wpms_excludeauthorsitemap&meta_value=on') 15421542 ); 15431543 $html .= wp_list_authors(array('exclude_admin' => false, 'exclude' => $authEx, 'echo' => false)); 15441544 $html .= '</ul></div>'; 15451545 } 15461546 } 15471547 15481548 foreach ($arrs as $ar => $arr) { 15491549 if (empty($this->settings_sitemap[$arr])) { 15501550 $this->settings_sitemap[$arr] = 1; 15511551 } 15521552 15531553 if (!in_array($ar, $checkColumn)) { 15541554 if ((int) $i === (int) $this->settings_sitemap[$arr]) { 15551555 $checkColumn[] = $ar; 15561556 $output = $this->{$ar}(); 15571557 $html .= $output; 15581558 } 15591559 } 15601560 } 15611561 // custom post type 15621562 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 15631563 $custom_post_types = get_post_types( 15641564 array( 15651565 'public' => true, 15661566 'exclude_from_search' => false, 15671567 '_builtin' => false 15681568 ) 15691569 ); 15701570 if (!empty($custom_post_types)) { 15711571 foreach ($custom_post_types as $post_type => $label) { 15721572 if (!empty($this->settings_sitemap['wpms_display_column_' . $post_type]) 15731573 && (int) $i === (int) $this->settings_sitemap['wpms_display_column_' . $post_type]) { 15741574 //===================================================================================== 15751575 if (isset($this->settings_sitemap['wpms_public_name_' . $post_type]) 15761576 && $this->settings_sitemap['wpms_public_name_' . $post_type] !== '') { 15771577 $postTitle = $this->settings_sitemap['wpms_public_name_' . $post_type]; 15781578 } else { 15791579 $postTitle = get_post_type_object($post_type); 15801580 $postTitle = $postTitle->label; 15811581 } 15821582 15831583 global $wpdb; 15841584 if ($post_type === 'product') { 15851585 $taxonomy_objects = array('product_cat'); 15861586 } else { 15871587 $taxonomy_objects = get_object_taxonomies($post_type, 'names'); 15881588 } 15891589 $ids = array(0); 15901590 if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) { 15911591 $html .= '<div id="sitemap_' . $post_type . '" class="wpms_sitemap_' . $post_type . '"><h4>'; 15921592 $html .= esc_html($postTitle); 15931593 $html .= '</h4><ul>'; 15941594 foreach ((array) $this->settings_sitemap['wpms_sitemap_' . $post_type] as $k => $v) { 15951595 if (!empty($v['post_id'])) { 15961596 $ids[] = (int) $v['post_id']; 15971597 } 15981598 } 15991599 } 16001600 16011601 $list_links = array(); 16021602 if (!empty($taxonomy_objects)) { 16031603 foreach ($taxonomy_objects as $taxo) { 16041604 $categorys = get_categories(array('hide_empty' => true, 'taxonomy' => $taxo)); 16051605 foreach ($categorys as $cat) { 16061606 $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title 16071607FROM ' . $wpdb->posts . ' AS p 16081608INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id) 16091609INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) 16101610INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id) 16111611WHERE p.post_status = %s 16121612 AND p.post_type = %s 16131613 AND tt.taxonomy = %s AND t.slug = %s AND ID IN (' . implode(',', esc_sql($ids)) . ') 16141614ORDER BY p.post_date DESC', array('publish', $post_type, $taxo, $cat->slug))); 16151615 if (!empty($results)) { 16161616 if (in_array($cat->cat_ID, $this->settings_sitemap['wpms_category_link'])) { 16171617 $cat_link = '<a href="' . esc_url(get_term_link($cat)) . '"> 16181618 ' . esc_html($cat->cat_name) . '</a>'; 16191619 $html .= '<li class="wpms_li_cate wpms_li_cate">'; 16201620 $html .= '<div class="cat_name">' . $cat_link . '</div>'; 16211621 $html .= '</li>'; 16221622 } else { 16231623 $cat_link = esc_html($cat->cat_name); 16241624 if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) { 16251625 $html .= '<li class="wpms_li_cate wpms_li_cate">'; 16261626 $html .= '<div class="cat_name">' . $cat_link . '</div>'; 16271627 $html .= '</li>'; 16281628 } 16291629 } 16301630 16311631 if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) { 16321632 foreach ($results as $p) { 16331633 $i = $cat->cat_ID . '-' . $p->ID; 16341634 $link = get_permalink($p->ID); 16351635 if (!in_array($link, $list_links)) { 16361636 $list_links[] = $link; 16371637 $html .= '<li><a href="' . esc_url($link) . '">' . esc_html($p->post_title) . '</a></li>'; 16381638 } 16391639 } 16401640 } 16411641 } 16421642 } 16431643 } 16441644 } else { 16451645 $results = $wpdb->get_results($wpdb->prepare('SELECT ID, post_title FROM ' . $wpdb->posts . ' WHERE post_status = %s AND post_type = %s AND ID IN (' . implode(',', esc_sql($ids)) . ') ORDER BY post_date DESC', array( 16461646 'publish', 16471647 $post_type 16481648 ))); 16491649 if (!empty($results)) { 16501650 if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) { 16511651 $html .= '<ul>'; 16521652 foreach ($results as $p) { 16531653 $link = get_permalink($p->ID); 16541654 if (!in_array($link, $list_links)) { 16551655 $list_links[] = $link; 16561656 $html .= '<li><a href="' . esc_url(get_permalink($p->ID)) . '">' . esc_html($p->post_title) . '</a></li>'; 16571657 } 16581658 } 16591659 $html .= '</ul>'; 16601660 } 16611661 } 16621662 } 16631663 16641664 if (!empty($this->settings_sitemap['wpms_sitemap_' . $post_type])) { 16651665 $html .= '</ul></div>'; 16661666 } 16671667 $html .= '<div class="holder holder_sitemaps_' . $post_type . '"></div>'; 16681668 //====================================================================================== 16691669 } 16701670 } 16711671 } 16721672 } 16731673 // ==================== 16741674 16751675 $ids_menu = array(0); 16761676 $check_menu = array(); 16771677 $terms = get_terms(array( 16781678 'taxonomy' => 'nav_menu', 16791679 'hide_empty' => true, 16801680 'orderby' => 'term_id', 16811681 'order' => 'ASC' 16821682 )); 16831683 foreach ($terms as $term) { 16841684 $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu'); 16851685 $ids_menu = array_merge($ids_menu, $list_submenu_id); 16861686 } 16871687 16881688 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 16891689 $this->settings_sitemap['wpms_sitemap_menus'] = $ids_menu; 16901690 } 16911691 16921692 if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) { 16931693 if (!empty($terms)) { 16941694 foreach ($terms as $term) { 16951695 if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) { 16961696 if (empty($this->settings_sitemap['wpms_display_column_menus'][$term->term_id])) { 16971697 $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] = 1; 16981698 } 16991699 17001700 if ((int) $i === (int) $this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) { 17011701 $check_menu[] = 'sitemap_menus_' . $term->term_id; 17021702 $html .= '<div id="' . esc_attr('sitemap_menus_' . $term->term_id) . '" class="wpms_sitemap_menus">'; 17031703 $viewmenu = $this->viewMenusFrontend($term, $ids_menu); 17041704 $html .= $viewmenu; 17051705 17061706 $html .= '</div>'; 17071707 $html .= '<div class="' . esc_attr('holder holder_sitemaps_menus_' . $term->term_id) . '"></div>'; 17081708 } 17091709 } 17101710 } 17111711 } 17121712 } 17131713 17141714 $html .= '</div>'; 17151715 } 17161716 17171717 // ============================================================================== 17181718 17191719 $html .= '</div>'; 17201720 $html .= '<div class="wpms_clearRow"></div>'; 17211721 return $html; 17221722 } 17231723 17241724 /** 17251725 * Display html sitemap in front-end 17261726 * 17271727 * @return array|string 17281728 */ 17291729 public function sitemapShortcode() 17301730 { 17311731 $html = ''; 17321732 // include style 17331733 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 17341734 $theme = $this->settings_sitemap['wpms_html_sitemap_theme']; 17351735 } else { 17361736 $theme = 'default'; 17371737 } 17381738 17391739 $custom_post_types = get_post_types( 17401740 array( 17411741 'public' => true, 17421742 'exclude_from_search' => false, 17431743 '_builtin' => false 17441744 ) 17451745 ); 17461746 17471747 if ($theme === 'default') { 17481748 wp_enqueue_style( 17491749 'html-sitemap', 17501750 plugins_url('assets/css/html_sitemap.css', dirname(__FILE__)), 17511751 array(), 17521752 WPMSEO_VERSION 17531753 ); 17541754 17551755 $html = $this->sitemapThemeDefault(); 17561756 } elseif ($theme === 'tab') { 17571757 wp_enqueue_script( 17581758 'wpms_tabs_js', 17591759 plugins_url('assets/js/wpms-tabs.js', dirname(__FILE__)), 17601760 array('jquery'), 17611761 WPMSEO_VERSION, 17621762 true 17631763 ); 17641764 wp_enqueue_style( 17651765 'wpms_materialize_style', 17661766 plugins_url('assets/css/materialize/materialize_frontend_tab_theme.css', dirname(__FILE__)), 17671767 array(), 17681768 WPMSEO_VERSION 17691769 ); 17701770 echo '<div id="wpms_sitemap" class="theme_tab">'; 17711771 require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/menu_bar.php'); 17721772 require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_posts.php'); 17731773 require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_pages.php'); 17741774 if (!empty($this->settings_sitemap['wpms_sitemap_customUrl'])) { 17751775 require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/tab/source_urlcustom.php'); 17761776 } 17771777 // source menu 17781778 $ids_menu = array(0); 17791779 $check_menu = array(); 17801780 $terms = get_terms(array('taxonomy' => 'nav_menu', 'hide_empty' => true)); 17811781 foreach ($terms as $term) { 17821782 $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu'); 17831783 $ids_menu = array_merge($ids_menu, $list_submenu_id); 17841784 } 17851785 17861786 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 17871787 $this->settings_sitemap['wpms_sitemap_menus'] = $ids_menu; 17881788 } 17891789 17901790 if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) { 17911791 if (!empty($terms)) { 17921792 echo '<div id="menu_source_menus">'; 17931793 foreach ($terms as $term) { 17941794 if (!in_array('sitemap_menus_' . $term->term_id, $check_menu)) { 17951795 $check_menu[] = 'sitemap_menus_' . $term->term_id; 17961796 echo '<div id="' . esc_attr('sitemap_menus_' . $term->term_id) . '" class="wpms_sitemap_menus">'; 17971797 $viewmenu = $this->viewMenusFrontend($term, $ids_menu); 17981798 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method viewMenusFrontend 17991799 echo $viewmenu; 18001800 18011801 echo '</div>'; 18021802 echo '<div class="' . esc_attr('holder holder_sitemaps_menus_' . $term->term_id) . '"></div>'; 18031803 } 18041804 } 18051805 echo '</div>'; 18061806 } 18071807 } 18081808 echo '</div>'; 18091809 } elseif ($theme === 'accordions') { 18101810 wp_enqueue_style( 18111811 'wpms_materialize_style', 18121812 plugins_url('assets/css/materialize/materialize_frontend_accordions_theme.css', dirname(__FILE__)), 18131813 array(), 18141814 WPMSEO_VERSION 18151815 ); 18161816 echo '<div id="wpms_sitemap" class="theme_accordions">'; 18171817 echo '<ul class="collapsible wpms_collapsible" data-collapsible="accordion">'; 18181818 $arrays = array(); 18191819 if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) { 18201820 $arrays['wpms_display_order_menus'] 18211821 = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_menu.php'; 18221822 } 18231823 if (!empty($this->settings_sitemap['wpms_sitemap_posts'])) { 18241824 $arrays['wpms_display_order_posts'] 18251825 = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_posts.php'; 18261826 } 18271827 if (!empty($this->settings_sitemap['wpms_sitemap_pages'])) { 18281828 $arrays['wpms_display_order_pages'] 18291829 = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_pages.php'; 18301830 } 18311831 if (!empty($this->settings_sitemap['wpms_sitemap_customUrl'])) { 18321832 $arrays['wpms_display_order_urls'] 18331833 = WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/sitemaps/theme/accordions/source_urlcustom.php'; 18341834 } 18351835 18361836 for ($i = 1; $i <= 4; $i ++) { 18371837 foreach ($arrays as $key => $item) { 18381838 if ((int) $this->settings_sitemap[$key] === (int) $i) { 18391839 require_once($item); 18401840 } 18411841 } 18421842 } 18431843 18441844 echo '</ul>'; 18451845 echo '</div>'; 18461846 } 18471847 18481848 return $html; 18491849 } 18501850 18511851 /** 18521852 * Add wpms_html_sitemap shortcode in content 18531853 * 18541854 * @param string $content Sitemap content 18551855 * 18561856 * @return string 18571857 */ 18581858 public function sitemapInContent($content) 18591859 { 18601860 global $wpdb; 18611861 $sitemap_page = $wpdb->get_row($wpdb->prepare( 18621862 'SELECT * FROM ' . $wpdb->prefix . 'posts 18631863 WHERE post_title = %s AND post_excerpt = %s AND post_type = %s', 18641864 array( 18651865 'WPMS HTML Sitemap', 18661866 'metaseo_html_sitemap', 18671867 'page' 18681868 ) 18691869 )); 18701870 18711871 if (empty($this->settings_sitemap['wpms_html_sitemap_page']) && !empty($sitemap_page)) { 18721872 $this->settings_sitemap['wpms_html_sitemap_page'] = $sitemap_page->ID; 18731873 } 18741874 18751875 if (!empty($this->settings_sitemap['wpms_html_sitemap_page']) 18761876 && is_page($this->settings_sitemap['wpms_html_sitemap_page'])) { 18771877 $sitemap = '[wpms_html_sitemap]'; 18781878 switch ($this->settings_sitemap['wpms_html_sitemap_position']) { 18791879 case 'after': 18801880 $content .= $sitemap; 18811881 break; 18821882 case 'before': 18831883 $content = $sitemap . $content; 18841884 break; 18851885 case 'replace': 18861886 $content = $sitemap; 18871887 break; 18881888 default: 18891889 $content .= $sitemap; 18901890 } 18911891 } 18921892 return $content; 18931893 } 18941894 18951895 /** 18961896 * Get all menu 18971897 * 18981898 * @return array 18991899 */ 19001900 public function getAllMenus() 19011901 { 19021902 $settings_sitemap = get_option('_metaseo_settings_sitemap'); 19031903 $post_types = get_post_types('', 'names'); 19041904 unset($post_types['revision']); 19051905 unset($post_types['attachment']); 19061906 $ids_posts_custom = array(0); 19071907 $ids_categories = array(); 19081908 19091909 if (empty($settings_sitemap['wpms_check_firstsave'])) { 19101910 $args = array( 19111911 'posts_per_page' => - 1, 19121912 'post_type' => 'nav_menu_item', 19131913 'post_status' => 'publish' 19141914 ); 19151915 $query = new WP_Query($args); 19161916 $posts_menu = $query->get_posts(); 19171917 foreach ($posts_menu as $k => $v) { 19181918 $type = get_post_meta($v->ID, '_menu_item_type', true); 19191919 $post_meta_object_id = get_post_meta($v->ID, '_menu_item_object_id', true); 19201920 if ($type !== 'taxonomy') { 19211921 $ids_posts_custom[] = $post_meta_object_id; 19221922 } else { 19231923 $ids_categories[] = $post_meta_object_id; 19241924 } 19251925 } 19261926 } else { 19271927 if (!empty($settings_sitemap['wpms_sitemap_menus'])) { 19281928 foreach ($settings_sitemap['wpms_sitemap_menus'] as $k => $v) { 19291929 if (!empty($v['menu_id'])) { 19301930 $type = get_post_meta($k, '_menu_item_type', true); 19311931 $post_meta_object_id = get_post_meta($k, '_menu_item_object_id', true); 19321932 if ($type !== 'taxonomy') { 19331933 $ids_posts_custom[] = $post_meta_object_id; 19341934 } else { 19351935 $ids_categories[] = $post_meta_object_id; 19361936 } 19371937 } 19381938 } 19391939 } 19401940 } 19411941 19421942 $args = array( 19431943 'posts_per_page' => - 1, 19441944 'post_type' => $post_types, 19451945 'post__in' => $ids_posts_custom, 19461946 'post_status' => 'publish' 19471947 ); 19481948 $query = new WP_Query($args); 19491949 $menus_post_custom = $query->get_posts(); 19501950 return array('posts_custom' => $menus_post_custom, 'categories' => $ids_categories); 19511951 } 19521952 19531953 /** 19541954 * Get posts selected in sitemap setting 19551955 * 19561956 * @return array 19571957 */ 19581958 public function getPostsSitemap() 19591959 { 19601960 $post_types = $this->getPostTypes(); 19611961 $ids = array(0); 19621962 $settings_sitemap = get_option('_metaseo_settings_sitemap'); 19631963 if (!empty($settings_sitemap['wpms_sitemap_posts'])) { 19641964 foreach ((array) $settings_sitemap['wpms_sitemap_posts'] as $k => $v) { 19651965 if (!empty($v['post_id'])) { 19661966 $ids[] = $k; 19671967 } 19681968 } 19691969 } 19701970 19711971 $args = array( 19721972 'posts_per_page' => - 1, 19731973 'post_type' => $post_types, 19741974 'post__in' => $ids, 19751975 'post_status' => 'publish' 19761976 ); 19771977 $query = new WP_Query($args); 19781978 $posts = $query->get_posts(); 19791979 return $posts; 19801980 } 19811981 19821982 /** 19831983 * Get a list of all registered post type objects. 19841984 * 19851985 * @return array 19861986 */ 19871987 public function getPostTypes() 19881988 { 19891989 $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false)); 19901990 unset($post_types['attachment']); 19911991 unset($post_types['page']); 19921992 return $post_types; 19931993 } 19941994 19951995 /** 19961996 * Get pages selected in sitemap setting 19971997 * 19981998 * @return array 19991999 */ 20002000 public function getPagesSitemap() 20012001 { 20022002 $ids = array(0); 20032003 $settings_sitemap = get_option('_metaseo_settings_sitemap'); 20042004 if (!empty($settings_sitemap['wpms_sitemap_pages'])) { 20052005 foreach ($settings_sitemap['wpms_sitemap_pages'] as $k => $v) { 20062006 if (!empty($v['post_id'])) { 20072007 $ids[] = $k; 20082008 } 20092009 } 20102010 } 20112011 20122012 $args = array( 20132013 'posts_per_page' => - 1, 20142014 'post_type' => 'page', 20152015 'post__in' => $ids, 20162016 'post_status' => 'publish' 20172017 ); 20182018 $query = new WP_Query($args); 20192019 $pages = $query->get_posts(); 20202020 return $pages; 20212021 } 20222022 20232023 /** 20242024 * Get pages 20252025 * 20262026 * @return array|null|object 20272027 */ 20282028 public function getPages() 20292029 { 20302030 global $wpdb; 20312031 $pages = $wpdb->get_results($wpdb->prepare('SELECT ID,post_title FROM ' . $wpdb->posts . ' WHERE 20322032 post_status = %s AND post_type = %s ORDER BY post_date DESC', array('publish', 'page'))); 20332033 return $pages; 20342034 } 20352035 20362036 /** 20372037 * Get posts by category 20382038 * 20392039 * @return array 20402040 */ 20412041 public function getPosts() 20422042 { 20432043 $posts = array(); 20442044 $taxo = 'category'; 20452045 $categorys = get_categories(array('hide_empty' => true, 'taxonomy' => $taxo)); 20462046 global $wpdb, $sitepress; 20472047 foreach ($categorys as $cat) { 20482048 if ($sitepress && !empty($this->settings_sitemap['wpms_sitemap_include_lang'])) { 20492049 $language_code = apply_filters('wpml_element_language_code', null, array('element_id' => (int)$cat->cat_ID, 'element_type' => 'category')); 20502050 if (!in_array($language_code, $this->settings_sitemap['wpms_sitemap_include_lang'])) { 20512051 continue; 20522052 } 20532053 } 20542054 20552055 $count = $wpdb->get_var($wpdb->prepare('SELECT COUNT(p.ID) 20562056FROM ' . $wpdb->posts . ' AS p 20572057INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id) 20582058INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) 20592059INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id) 20602060WHERE p.post_status = %s 20612061 AND p.post_type = %s 20622062 AND tt.taxonomy = %s AND t.slug=%s 20632063ORDER BY p.post_date DESC', array('publish', 'post', $taxo, $cat->slug))); 20642064 20652065 $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title 20662066FROM ' . $wpdb->posts . ' AS p 20672067INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id) 20682068INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) 20692069INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id) 20702070WHERE p.post_status = %s 20712071 AND p.post_type = %s 20722072 AND tt.taxonomy = %s AND t.slug=%s 20732073ORDER BY p.post_date DESC LIMIT 10', array('publish', 'post', $taxo, $cat->slug))); 20742074 $obj = new StdClass(); 20752075 $obj->cat_name = $cat->cat_name; 20762076 $obj->cat_ID = $cat->cat_ID; 20772077 $obj->taxo = $taxo; 20782078 $obj->slug = $cat->slug; 20792079 $obj->results = array(); 20802080 if (!empty($results)) { 20812081 $obj->results = $results; 20822082 } 20832083 $obj->count_posts = $count; 20842084 $posts[] = $obj; 20852085 } 20862086 20872087 return $posts; 20882088 } 20892089 20902090 /** 20912091 * Get posts by category 20922092 * 20932093 * @param string $post_type Post type 20942094 * 20952095 * @return array 20962096 */ 20972097 public function getPostsCustom($post_type) 20982098 { 20992099 global $wpdb; 21002100 $posts = array(); 21012101 21022102 $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title 21032103FROM ' . $wpdb->posts . ' AS p 21042104WHERE p.post_status = "publish" AND p.post_type = %s 21052105ORDER BY p.post_date DESC', array($post_type))); 21062106 if (!empty($results)) { 21072107 $obj = new StdClass(); 21082108 $obj->cat_name = ''; 21092109 $obj->cat_ID = ''; 21102110 $obj->taxo = ''; 21112111 $obj->slug = ''; 21122112 $obj->results = $results; 21132113 $posts[] = $obj; 21142114 } 21152115 21162116 return $posts; 21172117 } 21182118 21192119 /** 21202120 * Display sitemap menu in front-end 21212121 * 21222122 * @param object $term Term 21232123 * @param array $ids_menu List menu id 21242124 * 21252125 * @return string 21262126 */ 21272127 public function viewMenusFrontend($term, $ids_menu) 21282128 { 21292129 $html = ''; 21302130 $list_menus = array(); 21312131 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 21322132 $list_menus = $ids_menu; 21332133 } else { 21342134 if (!empty($this->settings_sitemap['wpms_sitemap_menus'])) { 21352135 foreach ($this->settings_sitemap['wpms_sitemap_menus'] as $k => $v) { 21362136 $list_menus[] = $k; 21372137 } 21382138 } 21392139 } 21402140 21412141 $args = array( 21422142 'orderby' => 'menu_order', 21432143 'order' => 'ASC', 21442144 'posts_per_page' => - 1, 21452145 'post_type' => 'nav_menu_item', 21462146 'post_status' => 'any', 21472147 'post__in' => $list_menus, 21482148 'tax_query' => array( 21492149 array( 21502150 'taxonomy' => 'nav_menu', 21512151 'field' => 'slug', 21522152 'terms' => $term->slug, 21532153 ), 21542154 ), 21552155 ); 21562156 21572157 $query = new WP_Query($args); 21582158 $submenus = $query->get_posts(); 21592159 if (!empty($submenus)) { 21602160 $html .= '<h4>' . esc_html($term->name) . '</h4>'; 21612161 $html .= '<ul class="wpms_frontend_menus_sitemap">'; 21622162 foreach ($submenus as $menu) { 21632163 $type = get_post_meta($menu->ID, '_menu_item_type', true); 21642164 $type_menu = get_post_meta($menu->ID, '_menu_item_object', true); 21652165 $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true); 21662166 $this->level[$menu->ID] = 0; 21672167 $level = $this->countParent($menu->ID); 21682168 if ($type === 'taxonomy') { 21692169 $post_submenu = get_post($menu->ID); 21702170 $title = $post_submenu->post_title; 21712171 if (empty($title)) { 21722172 $term = get_term($id_menu, $type_menu); 21732173 if (empty($term->name)) { 21742174 continue; 21752175 } 21762176 $title = $term->name; 21772177 } 21782178 } else { 21792179 $post = get_post($menu->ID); 21802180 $title = $post->post_title; 21812181 if (empty($title)) { 21822182 $post_submenu = get_post($id_menu); 21832183 $title = $post_submenu->post_title; 21842184 } 21852185 } 21862186 $type = get_post_meta($menu->ID, '_menu_item_type', true); 21872187 $permalink = $this->getPermalinkSitemap($type, $id_menu); 21882188 $margin = $level * 10; 21892189 $style = ''; 21902190 if ((int) $level !== 0) { 21912191 $style = 'style="' . esc_attr('margin-left:' . $margin . 'px') . '"'; 21922192 } 21932193 $html .= '<li class="' . esc_attr('wpms_menu_level_' . $level) . '" ' . $style . '>'; 21942194 $html .= '<a href="' . esc_url($permalink) . '">' . esc_html($title) . '</a>'; 21952195 $html .= '</li>'; 21962196 } 21972197 21982198 $html .= '</ul>'; 21992199 } 22002200 return $html; 22012201 } 22022202 22032203 /** 22042204 * Get count parent for a menu 22052205 * 22062206 * @param integer $menuID ID of menu 22072207 * 22082208 * @return integer 22092209 */ 22102210 public function countParent($menuID) 22112211 { 22122212 $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true); 22132213 if ((!empty($this->settings_sitemap['wpms_sitemap_menus'][$parent]) || !empty($this->settings_sitemap['wpms_sitemap_menus']->{$parent})) && !empty($parent)) { 22142214 $this->level[$menuID] += 1; 22152215 $this->loopParent($parent, $menuID); 22162216 } else { 22172217 $this->loopParent($parent, $menuID); 22182218 } 22192219 22202220 return (int) $this->level[$menuID]; 22212221 } 22222222 22232223 /** 22242224 * Get level list menu 22252225 * 22262226 * @param integer $menuID Current menu id 22272227 * @param integer $menuIDroot Root menu id 22282228 * 22292229 * @return void 22302230 */ 22312231 public function loopParent($menuID, $menuIDroot) 22322232 { 22332233 $parent = get_post_meta($menuID, '_menu_item_menu_item_parent', true); 22342234 $parent_1 = get_post_meta($parent, '_menu_item_menu_item_parent', true); 22352235 if ((!empty($this->settings_sitemap['wpms_sitemap_menus'][$parent]) && !empty($parent)) 22362236 || (!empty($parent_1) && !empty($parent))) { 22372237 $this->level[$menuIDroot] += 1; 22382238 $this->loopParent($parent, $menuIDroot); 22392239 } 22402240 } 22412241 22422242 /** 22432243 * Display list menu in sitemap settings 22442244 * 22452245 * @param object $term Current menu 22462246 * 22472247 * @return string 22482248 */ 22492249 public function viewMenus($term) 22502250 { 22512251 $list_submenu_id = get_objects_in_term($term->term_id, 'nav_menu'); 22522252 $args = array( 22532253 'orderby' => 'menu_order', 22542254 'order' => 'ASC', 22552255 'posts_per_page' => - 1, 22562256 'post_type' => 'nav_menu_item', 22572257 'post_status' => 'any', 22582258 'post__in' => $list_submenu_id, 22592259 'meta_key' => '_menu_item_menu_item_parent', 22602260 'meta_value' => 0 22612261 ); 22622262 22632263 $query = new WP_Query($args); 22642264 $submenus = $query->get_posts(); 22652265 ?> 22662266 <div class="wpms_row_full"> 22672267 <div class="ju-settings-option wpms_row" style="margin-top: 20px"> 22682268 <div class="wpms_row_full"> 22692269 <label class="ju-setting-label text wpms-uppercase" 22702270 data-tippy="<?php echo esc_attr('Include all elements in the sitemap', 'wp-meta-seo') ?>"> 22712271 <?php echo esc_html($term->name) ?> 22722272 </label> 22732273 <div class="ju-switch-button"> 22742274 <label class="switch"> 22752275 <?php if (isset($this->settings_sitemap['check_all_menu_items']) && in_array($term->term_id, $this->settings_sitemap['check_all_menu_items'])) : ?> 22762276 <input class="xm_cb_all check_all_menu_items" checked 22772277 data-category="<?php echo esc_attr('nav_menu' . $term->slug) ?>" 22782278 value="<?php echo esc_attr($term->term_id) ?>" 22792279 id="<?php echo esc_attr('xm_cb_all_' . $term->slug) ?>" type="checkbox" ?>> 22802280 <?php else : ?> 22812281 <input class="xm_cb_all check_all_menu_items" 22822282 data-category="<?php echo esc_attr('nav_menu' . $term->slug) ?>" 22832283 value="<?php echo esc_attr($term->term_id) ?>" 22842284 id="<?php echo esc_attr('xm_cb_all_' . $term->slug) ?>" type="checkbox" ?>> 22852285 <?php endif; ?> 22862286 <span class="slider round"></span> 22872287 </label> 22882288 </div> 22892289 </div> 22902290 </div> 22912291 22922292 <div class="ju-settings-option wpms_xmp_custom_column wpms_row wpms_right m-r-0" style="margin-top: 20px"> 22932293 <div class="wpms_row_full"> 22942294 <label class="ju-setting-label wpms_left" 22952295 data-tippy="<?php echo esc_attr('Column selection if you’re using the HTML sitemap', 'wp-meta-seo') ?>"> 22962296 <?php esc_html_e('HTML Sitemap column', 'wp-meta-seo') ?> 22972297 </label> 22982298 <div class="ju-switch-button"> 22992299 <label> 23002300 <select class="wpms_display_column wpms_display_column_menus wpms-large-input m-r-10" 23012301 data-menu_id="<?php echo esc_attr($term->term_id) ?>"> 23022302 <?php 23032303 for ($i = 1; $i <= $this->settings_sitemap['wpms_html_sitemap_column']; $i ++) { 23042304 if (isset($this->settings_sitemap['wpms_display_column_menus'][$term->term_id]) 23052305 && (int) $this->settings_sitemap['wpms_display_column_menus'][$term->term_id] === (int) $i) { 23062306 echo '<option selected value="' . esc_attr($i) . '">' . esc_html($this->columns[$i]) . '</option>'; 23072307 } else { 23082308 echo '<option value="' . esc_attr($i) . '">' . esc_html($this->columns[$i]) . '</option>'; 23092309 } 23102310 } 23112311 ?> 23122312 </select> 23132313 </label> 23142314 </div> 23152315 </div> 23162316 </div> 23172317 </div> 23182318 23192319 <?php 23202320 foreach ($submenus as $menu) { 23212321 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'])) { 23222322 $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'] = 'monthly'; 23232323 } 23242324 if (empty($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'])) { 23252325 $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'] = '1.0'; 23262326 } 23272327 $slpr = $this->viewPriority( 23282328 'priority_menu_' . $menu->ID, 23292329 '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][priority]', 23302330 $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['priority'] 23312331 ); 23322332 $slfr = $this->viewFrequency( 23332333 'frequency_menu_' . $menu->ID, 23342334 '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][frequency]', 23352335 $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['frequency'] 23362336 ); 23372337 23382338 $type = get_post_meta($menu->ID, '_menu_item_type', true); 23392339 $type_menu = get_post_meta($menu->ID, '_menu_item_object', true); 23402340 $id_menu = get_post_meta($menu->ID, '_menu_item_object_id', true); 23412341 if ($type === 'taxonomy') { 23422342 $post_submenu = get_post($menu->ID); 23432343 $title = $post_submenu->post_title; 23442344 if (empty($title)) { 23452345 $term_menu = get_term($id_menu, $type_menu); 23462346 $title = $term_menu->name; 23472347 } 23482348 } else { 23492349 $post = get_post($menu->ID); 23502350 $title = $post->post_title; 23512351 if (empty($title)) { 23522352 $post_submenu = get_post($id_menu); 23532353 $title = $post_submenu->post_title; 23542354 } 23552355 } 23562356 $level = 1; 23572357 echo '<div class="wpms_row wpms_row_record">'; 23582358 $check_type = get_post_meta($menu->ID, '_menu_item_object', true); 23592359 $permalink = $this->getPermalinkSitemap($check_type, $id_menu); 23602360 echo '<div style="float:left;line-height:30px">'; 23612361 if (empty($this->settings_sitemap['wpms_check_firstsave'])) { 23622362 echo '<input class="wpms_sitemap_input_link checked" 23632363 type="hidden" data-type="menu" value="' . esc_attr($permalink) . '">'; 23642364 echo '<div class="pure-checkbox">'; 23652365 echo '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" 23662366 id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox" 23672367 name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '" 23682368 value="' . esc_attr($menu->ID) . '" checked>'; 23692369 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It cannot display some special characters on the title 23702370 echo '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" class="wpms-text">' . $title . '</label>'; 23712371 echo '</div>'; 23722372 } else { 23732373 if (isset($this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id']) 23742374 && (int) $this->settings_sitemap['wpms_sitemap_menus'][$menu->ID]['menu_id'] === (int) $menu->ID) { 23752375 echo '<input class="wpms_sitemap_input_link checked" 23762376 type="hidden" data-type="menu" value="' . esc_url($permalink) . '">'; 23772377 echo '<div class="pure-checkbox">'; 23782378 echo '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" 23792379 id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox" 23802380 name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '" 23812381 value="' . esc_attr($menu->ID) . '" checked>'; 23822382 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It cannot display some special characters on the title 23832383 echo '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" class="wpms-text">' . $title . '</label>'; 23842384 echo '</div>'; 23852385 } else { 23862386 echo '<input class="wpms_sitemap_input_link" type="hidden" data-type="menu" 23872387 value="' . esc_url($permalink) . '">'; 23882388 echo '<div class="pure-checkbox">'; 23892389 echo '<input class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" 23902390 id="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" type="checkbox" 23912391 name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $menu->ID . '][menu_id]') . '" 23922392 value="' . esc_attr($menu->ID) . '">'; 23932393 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It cannot display some special characters on the title 23942394 echo '<label for="' . esc_attr('wpms_sitemap_menus_' . $menu->ID) . '" class="wpms-text">' . $title . '</label>'; 23952395 echo '</div>'; 23962396 } 23972397 } 23982398 23992399 echo '</div>'; 24002400 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method MetaSeoSitemap::viewFrequency, MetaSeoSitemap::viewPriority 24012401 echo '<div class="wpms_right">' . $slpr . $slfr . '</div>'; 24022402 echo '</div>'; 24032403 $this->loop($menu->ID, $level + 1, $this->settings_sitemap, $term); 24042404 } 24052405 24062406 return $this->html; 24072407 } 24082408 24092409 /** 24102410 * Display list menu in sitemap settings 24112411 * 24122412 * @param integer $menuID ID of menu 24132413 * @param integer $level Level of menu 24142414 * @param array $settings_sitemap All settings 24152415 * @param object $term Current menu 24162416 * 24172417 * @return void 24182418 */ 24192419 public function loop($menuID, $level, $settings_sitemap, $term) 24202420 { 24212421 $args = array( 24222422 'post_type' => 'nav_menu_item', 24232423 'posts_per_page' => - 1, 24242424 'meta_key' => '_menu_item_menu_item_parent', 24252425 'meta_value' => $menuID, 24262426 'orderby' => 'menu_order', 24272427 'order' => 'ASC' 24282428 ); 24292429 $query = new WP_Query($args); 24302430 $submenus = $query->get_posts(); 24312431 24322432 if (!empty($submenus)) { 24332433 foreach ($submenus as $submenu) { 24342434 $type = get_post_meta($submenu->ID, '_menu_item_type', true); 24352435 $type_menu = get_post_meta($submenu->ID, '_menu_item_object', true); 24362436 $post_subid = get_post_meta($submenu->ID, '_menu_item_object_id', true); 24372437 if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'])) { 24382438 $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'] = 'monthly'; 24392439 } 24402440 if (empty($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'])) { 24412441 $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'] = '1.0'; 24422442 } 24432443 24442444 if ($type === 'taxonomy') { 24452445 $post_submenu = get_post($submenu->ID); 24462446 $title = $post_submenu->post_title; 24472447 if (empty($title)) { 24482448 $term_sub = get_term($post_subid, $type_menu); 24492449 $title = $term_sub->name; 24502450 } 24512451 } else { 24522452 $post_submenu = get_post($submenu->ID); 24532453 $title = $post_submenu->post_title; 24542454 if (empty($title)) { 24552455 $post_submenu = get_post($post_subid); 24562456 $title = $post_submenu->post_title; 24572457 } 24582458 } 24592459 24602460 $space = ''; 24612461 for ($i = 1; $i <= $level * 3; $i ++) { 24622462 $space .= ' '; 24632463 } 24642464 $slpr = $this->viewPriority( 24652465 'priority_menu_' . $submenu->ID, 24662466 '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][priority]', 24672467 $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['priority'] 24682468 ); 24692469 $slfr = $this->viewFrequency( 24702470 'frequency_menu_' . $submenu->ID, 24712471 '_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->post_id . '][frequency]', 24722472 $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['frequency'] 24732473 ); 24742474 24752475 if (empty($settings_sitemap['wpms_check_firstsave'])) { 24762476 $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '" 24772477 class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" 24782478 checked name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '" 24792479 type="checkbox" value="' . $submenu->ID . '">'; 24802480 } else { 24812481 if (isset($settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id']) 24822482 && (int) $settings_sitemap['wpms_sitemap_menus'][$submenu->ID]['menu_id'] === (int) $submenu->ID) { 24832483 $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '" 24842484 class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" checked 24852485 name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '" 24862486 type="checkbox" value="' . esc_attr($submenu->ID) . '">'; 24872487 } else { 24882488 $checkbox = $space . '<input id="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '" 24892489 class="' . esc_attr('cb_sitemaps_menu wpms_xmap_menu nav_menu' . $term->slug) . '" 24902490 name="' . esc_attr('_metaseo_settings_sitemap[wpms_sitemap_menus][' . $submenu->ID . '][menu_id]') . '" 24912491 type="checkbox" value="' . esc_attr($submenu->ID) . '">'; 24922492 } 24932493 } 24942494 24952495 echo '<div class="wpms_row wpms_row_record">'; 24962496 echo '<div style="float:left;line-height:30px">'; 24972497 echo '<div class="pure-checkbox">'; 24982498 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in this method 24992499 echo $checkbox; 25002500 echo '<label for="' . esc_attr('wpms_sitemap_menus_' . $submenu->ID) . '" class="wpms-text">' . esc_html($title) . '</label>'; 25012501 echo '</div>'; 25022502 echo '</div>'; 25032503 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method MetaSeoSitemap::viewFrequency, MetaSeoSitemap::viewPriority 25042504 echo '<div class="wpms_right">' . $slpr . $slfr . '</div>'; 25052505 echo '</div>'; 25062506 $this->loop($submenu->ID, $level + 1, $settings_sitemap, $term); 25072507 } 25082508 } 25092509 } 25102510 25112511 /** 25122512 * Ajax generate sitemap to xml file 25132513 * 2514 * @return void 2515 */ 2516 public function regenerateSitemapsAjax() 2517 { 2518 if (empty($_POST['wpms_nonce']) 2519 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 2520 die(); 2521 } 2522 2523 $this->regenerateSitemaps(); 2524 } 2525 /** 2526 * Ajax generate sitemap to xml file 2527 * 25142528 * @param string $type Type 25152529 * 25162530 * @return void 25172531 */ 25182532 public function regenerateSitemaps($type = 'ajax') 25192533 { 2534 if (!current_user_can('manage_options')) { 2535 if ($type === 'ajax') { 2536 wp_send_json(array('status' => false, 'message' => __('There is no permission here', 'wp-meta-seo'))); 2537 } else { 2538 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 2539 wp_die(__('There is no permission here', 'wp-meta-seo')); 2540 } 2541 } 25202542 if (! function_exists('get_home_path')) { 25212543 include_once ABSPATH . '/wp-admin/includes/file.php'; 25222544 } 25232545 $wpms_url_robot = get_home_path() . 'robots.txt'; 25242546 $wpms_url_home = site_url('/'); 25252547 $this->getSitemapSettings(); 25262548 $this->createSitemap($this->wpms_sitemap_name); 25272549 if ((int) $this->settings_sitemap['wpms_sitemap_root'] === 1) { 25282550 $this->createSitemap($this->wpms_sitemap_default_name); 25292551 } 25302552 25312553 if (isset($this->settings_sitemap['wpms_sitemap_add']) && (int) $this->settings_sitemap['wpms_sitemap_add'] === 1) { 25322554 if (!file_exists($wpms_url_robot) && !is_multisite()) { 25332555 ob_start(); 25342556 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting -- Turn off all error reporting to write file 25352557 error_reporting(0); 25362558 do_robots(); 25372559 $robots_content = ob_get_clean(); 25382560 25392561 $f = fopen($wpms_url_robot, 'x'); 25402562 fwrite($f, $robots_content); 25412563 } 25422564 } 25432565 25442566 if (file_exists($wpms_url_robot) && !is_multisite()) { 25452567 if (!is_writable($wpms_url_robot)) { 25462568 chmod($wpms_url_robot, 0755); 25472569 } 25482570 25492571 if (is_writable($wpms_url_robot)) { 25502572 $file_content = file_get_contents($wpms_url_robot); 25512573 if (isset($this->settings_sitemap['wpms_sitemap_add']) 25522574 && (int) $this->settings_sitemap['wpms_sitemap_add'] === 1 25532575 && !preg_match('|Sitemap: ' . $wpms_url_home . $this->wpms_sitemap_name . '|', $file_content)) { 25542576 file_put_contents( 25552577 $wpms_url_robot, 25562578 $file_content . "\nSitemap: " . $wpms_url_home . $this->wpms_sitemap_name 25572579 ); 25582580 } 25592581 } else { 25602582 $error = esc_html__('Cannot edit "robots.txt". Check your permissions', 'wp-meta-seo'); 25612583 if ($type === 'ajax') { 25622584 wp_send_json(array('status' => false, 'message' => $error)); 25632585 } 25642586 } 25652587 } 25662588 25672589 if ((int)$this->settings_sitemap['wpms_sitemap_root'] === 1) { 25682590 $sitemapUrl = site_url($this->wpms_sitemap_default_name); 25692591 } else { 25702592 $sitemapUrl = site_url($this->wpms_sitemap_name); 25712593 } 25722594 25732595 /** 25742596 * Submit sitemaps, don't ping if blog is not public. 25752597 * 25762598 * @param string Sitemap URL 25772599 */ 25782600 do_action('wpms_submit_sitemap', $sitemapUrl); 25792601 if ($type === 'ajax') { 25802602 wp_send_json(array('status' => true, 'message' => 'success')); 25812603 } 25822604 } 25832605 25842606 /** 25852607 * Display priority for each item 25862608 * 25872609 * @param string $id Selectbox id 25882610 * @param string $name Selectbox name 25892611 * @param string $selected Selected value 25902612 * 25912613 * @return string 25922614 */ 25932615 public function viewPriority($id, $name, $selected) 25942616 { 25952617 $values = array('1' => '100%', '0.9' => '90%', '0.8' => '80%', '0.7' => '70%', '0.6' => '60%', '0.5' => '50%'); 25962618 $select = '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="wpmsleft wpms-large-input">'; 25972619 $select .= '<option value="1">' . esc_html__('Priority', 'wp-meta-seo') . '</option>'; 25982620 foreach ($values as $k => $v) { 25992621 if ($k === $selected) { 26002622 $select .= '<option selected value="' . esc_attr($k) . '">' . esc_html($v) . '</option>'; 26012623 } else { 26022624 $select .= '<option value="' . esc_attr($k) . '">' . esc_html($v) . '</option>'; 26032625 } 26042626 } 26052627 $select .= '</select>'; 26062628 return $select; 26072629 } 26082630 26092631 /** 26102632 * Display frequency for each item 26112633 * 26122634 * @param string $id Selectbox id 26132635 * @param string $name Selectbox name 26142636 * @param string $selected Selected value 26152637 * 26162638 * @return string 26172639 */ 26182640 public function viewFrequency($id, $name, $selected) 26192641 { 26202642 $values = array( 26212643 'always' => 'Always', 26222644 'hourly' => 'Hourly', 26232645 'daily' => 'Daily', 26242646 'weekly' => 'Weekly', 26252647 'monthly' => 'Monthly', 26262648 'yearly' => 'Yearly', 26272649 'never' => 'Never' 26282650 ); 26292651 $select = '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="wpmsleft wpms-large-input">'; 26302652 $select .= '<option value="monthly">' . esc_html__('Frequency', 'wp-meta-seo') . '</option>'; 26312653 foreach ($values as $k => $v) { 26322654 if ($k === $selected) { 26332655 $select .= '<option selected value="' . esc_attr($k) . '">' . esc_html($v) . '</option>'; 26342656 } else { 26352657 $select .= '<option value="' . esc_attr($k) . '">' . esc_html($v) . '</option>'; 26362658 } 26372659 } 26382660 $select .= '</select>'; 26392661 return $select; 26402662 } 26412663 26422664 /** 26432665 * Get all posts in a category 26442666 * 26452667 * @return void 26462668 */ 26472669 public function listPostsCategory() 26482670 { 26492671 if (empty($_POST['wpms_nonce']) 26502672 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 26512673 die(); 2674 } 2675 if (!current_user_can('manage_options')) { 2676 wp_send_json(array('status' => false)); 26522677 } 26532678 set_time_limit(0); 26542679 global $wpdb; 26552680 $results = $wpdb->get_results($wpdb->prepare('SELECT p.ID as ID,p.post_title as post_title 26562681FROM ' . $wpdb->posts . ' AS p 26572682INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON (p.ID = tr.object_id) 26582683INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) 26592684INNER JOIN ' . $wpdb->terms . ' AS t ON (t.term_id = tt.term_id) 26602685WHERE p.post_status = "publish" 26612686 AND p.post_type = "post" 26622687 AND tt.taxonomy = "category" AND t.term_id=%s 26632688ORDER BY p.post_date DESC', array($_POST['category_id']))); 26642689 26652690 $settings = get_option('_metaseo_settings_sitemap'); 26662691 $html = ''; 26672692 foreach ($results as $num => $p) { 26682693 if ((int) $num < 10) { 26692694 continue; 26702695 } 26712696 26722697 if (empty($settings['wpms_sitemap_posts'][$p->ID]['frequency'])) { 26732698 $postfrequency = 'monthly'; 26742699 } else { 26752700 $postfrequency = $settings['wpms_sitemap_posts'][$p->ID]['frequency']; 26762701 } 26772702 if (empty($settings['wpms_sitemap_posts'][$p->ID]['priority'])) { 26782703 $postpriority = '1.0'; 26792704 } else { 26802705 $postpriority = $settings['wpms_sitemap_posts'][$p->ID]['priority']; 26812706 } 26822707 $slpr = $this->viewPriority( 26832708 'priority_posts_' . $p->ID, 26842709 '_metaseo_settings_sitemap[wpms_sitemap_posts][' . $p->ID . '][priority]', 26852710 $postpriority 26862711 ); 26872712 $slfr = $this->viewFrequency( 26882713 'frequency_posts_' . $p->ID, 26892714 '_metaseo_settings_sitemap[wpms_sitemap_posts][' . $p->ID . '][frequency]', 26902715 $postfrequency 26912716 ); 26922717 $permalink = get_permalink($p->ID); 26932718 $html .= '<div class="wpms_row wpms_row_record">'; 26942719 $html .= '<div style="float:left;line-height:30px;">'; 26952720 if (strlen($p->post_title) > 30) { 26962721 $title = substr($p->post_title, 0, 30); 26972722 } else { 26982723 $title = $p->post_title; 26992724 } 27002725 if (isset($settings['wpms_sitemap_posts'][$p->ID]['post_id']) 27012726 && (int) $settings['wpms_sitemap_posts'][$p->ID]['post_id'] === (int) $p->ID) { 27022727 $html .= '<input class="wpms_sitemap_input_link checked" 27032728 type="hidden" data-type="post" value="' . esc_attr($permalink) . '">'; 27042729 $html .= '<div class="pure-checkbox">'; 27052730 $html .= '<input class="' . esc_attr('cb_sitemaps_posts wpms_xmap_posts category' . $_POST['slug']) . '" 27062731 id="' . esc_attr('wpms_sitemap_posts_' . $p->ID) . '" type="checkbox" 27072732 name="_metaseo_settings_sitemap[wpms_sitemap_posts]" value="' . esc_attr($p->ID) . '" checked>'; 27082733 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It cannot display some special characters on the title 27092734 $html .= '<label for="' . esc_attr('wpms_sitemap_posts_' . $p->ID) . '" class="wpms-text">' . $title . '</label>'; 27102735 $html .= '</div>'; 27112736 } else { 27122737 $html .= '<input class="wpms_sitemap_input_link" type="hidden" 27132738 data-type="post" value="' . esc_attr($permalink) . '">'; 27142739 $html .= '<div class="pure-checkbox">'; 27152740 $html .= '<input class="' . esc_attr('cb_sitemaps_posts wpms_xmap_posts category' . $_POST['slug']) . '" 27162741 id="' . esc_attr('wpms_sitemap_posts_' . $p->ID) . '" type="checkbox" 27172742 name="_metaseo_settings_sitemap[wpms_sitemap_posts]" value="' . esc_attr($p->ID) . '">'; 27182743 //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It cannot display some special characters on the title 27192744 $html .= '<label for="' . esc_attr('wpms_sitemap_posts_' . $p->ID) . '" class="wpms-text">' . $title . '</label>'; 27202745 $html .= '</div>'; 27212746 } 27222747 27232748 $html .= '</div>'; 27242749 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in the method MetaSeoSitemap::viewPriority and MetaSeoSitemap::viewFrequency 27252750 $html .= '<div class="wpms_right">' . $slpr . $slfr . '</div>'; 27262751 $html .= '</div>'; 27272752 } 27282753 27292754 wp_send_json($html); 27302755 } 27312756 27322757 /** 27332758 * Ajax update sitemap settings 27342759 * 27352760 * @return void 27362761 */ 27372762 public function saveSitemapSettings() 27382763 { 27392764 if (empty($_POST['wpms_nonce']) 27402765 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 27412766 die(); 2767 } 2768 if (!current_user_can('manage_options')) { 2769 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 2770 wp_die(__('There is no permission here', 'wp-meta-seo')); 27422771 } 27432772 27442773 $settings_sitemap = get_option('_metaseo_settings_sitemap'); 27452774 $lists = array( 27462775 'wpms_sitemap_add' => 1, 27472776 'wpms_sitemap_root' => 1, 27482777 'wpms_sitemap_author' => 0, 27492778 'wpms_html_sitemap_page' => 0, 27502779 'wpms_html_sitemap_column' => 1, 27512780 'wpms_html_sitemap_theme' => 'default', 27522781 'wpms_html_sitemap_position' => 'after', 27532782 'wpms_sitemap_taxonomies' => array(), 27542783 'wpms_check_firstsave' => 0, 27552784 'wpms_display_column_posts' => 1, 27562785 'wpms_display_column_pages' => 1, 27572786 'wpms_category_link' => array(), 27582787 'check_all_menu_items' => array(), 27592788 'wpms_display_order_menus' => 1, 27602789 'wpms_display_order_posts' => 2, 27612790 'wpms_display_order_pages' => 3, 27622791 'wpms_display_order_urls' => 4, 27632792 'wpms_category_select_all' => array(), 27642793 'wpms_sitemap_enable_core' => 0 27652794 ); 27662795 27672796 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 27682797 $custom_post_types = get_post_types( 27692798 array( 27702799 'public' => true, 27712800 'exclude_from_search' => false, 27722801 '_builtin' => false 27732802 ) 27742803 ); 27752804 if (!empty($custom_post_types)) { 27762805 foreach ($custom_post_types as $post_type => $label) { 27772806 $lists['wpms_display_column_' . $post_type] = 1; 27782807 $lists['wpms_public_name_' . $post_type] = ''; 27792808 $lists['wpms_sitemap_' . $post_type] = array(); 27802809 } 27812810 } 27822811 27832812 $lists['wpms_display_column_customUrl'] = 1; 27842813 $lists['wpms_public_name_customUrl'] = ''; 27852814 $lists['wpms_sitemap_customUrl'] = array(); 27862815 } 27872816 27882817 $wpms_display_column_menus = json_decode(stripslashes($_POST['wpms_display_column_menus']), true); 27892818 if (!empty($wpms_display_column_menus)) { 27902819 $settings_sitemap['wpms_display_column_menus'] = $wpms_display_column_menus; 27912820 } 27922821 27932822 foreach ($lists as $k => $v) { 27942823 if (isset($_POST[$k])) { 27952824 $settings_sitemap[$k] = $_POST[$k]; 27962825 } else { 27972826 $settings_sitemap[$k] = $lists[$k]; 27982827 } 27992828 } 28002829 28012830 $lists_selected = array( 28022831 'wpms_sitemap_posts' => array(), 28032832 'wpms_sitemap_pages' => array(), 28042833 'wpms_sitemap_menus' => array() 28052834 ); 28062835 28072836 if (is_plugin_active(WPMSEO_ADDON_FILENAME)) { 28082837 $custom_post_types = get_post_types( 28092838 array( 28102839 'public' => true, 28112840 'exclude_from_search' => false, 28122841 '_builtin' => false 28132842 ) 28142843 ); 28152844 if (!empty($custom_post_types)) { 28162845 foreach ($custom_post_types as $post_type => $label) { 28172846 $lists_selected['wpms_sitemap_' . $post_type] = array(); 28182847 } 28192848 } 28202849 28212850 $lists_selected['wpms_sitemap_customUrl'] = array(); 28222851 28232852 // save setting include lang 28242853 if (isset($_POST['wpms_lang_list']) && is_array($_POST['wpms_lang_list'])) { 28252854 $settings_sitemap['wpms_sitemap_include_lang'] = $_POST['wpms_lang_list']; 28262855 } 28272856 } 28282857 28292858 foreach ($lists_selected as $k => $v) { 28302859 if (isset($_POST[$k]) && $_POST[$k] !== '{}') { 28312860 $values = json_decode(stripslashes($_POST[$k]), true); 28322861 $settings_sitemap[$k] = $values; 28332862 } else { 28342863 $settings_sitemap[$k] = array(); 28352864 } 28362865 } 28372866 28382867 if (isset($_POST['wpms_public_name_posts'])) { 28392868 $settings_sitemap['wpms_public_name_posts'] = $_POST['wpms_public_name_posts']; 28402869 } 28412870 28422871 if (isset($_POST['wpms_public_name_pages'])) { 28432872 $settings_sitemap['wpms_public_name_pages'] = $_POST['wpms_public_name_pages']; 28442873 } 28452874 28462875 update_option('_metaseo_settings_sitemap', $settings_sitemap); 28472876 28482877 $this->updatePostInSitemapWithSelectAll(); 28492878 /** 28502879 * Save sitemap settings 28512880 * 28522881 * @param array Sitemap settings 28532882 */ 28542883 do_action('wpms_save_sitemap_settings', $settings_sitemap); 28552884 wp_send_json(true); 28562885 } 28572886 28582887 /** 28592888 * Update all post into sitemap with select all 28602889 * 28612890 * @return void 28622891 */ 28632892 public function updatePostInSitemapWithSelectAll() 28642893 { 28652894 global $sitepress; 28662895 $settings = get_option('_metaseo_settings_sitemap'); 28672896 $post_in_category = array(); 28682897 $post_in_sitemap = array(); 28692898 28702899 if (!empty($settings['wpms_category_select_all'])) { 28712900 if ($sitepress) { 28722901 $sitepress->switch_lang('all', false); 28732902 } 28742903 28752904 foreach ($settings['wpms_category_select_all'] as $cat_id) { 28762905 $args = array( 28772906 'numberposts' => -1, 28782907 'category' => $cat_id, 28792908 'post_type' => 'post' 28802909 ); 28812910 28822911 $posts = get_posts($args); 28832912 if (!empty($posts)) { 28842913 foreach ($posts as $post) { 28852914 $post_in_category[] = $post->ID; 28862915 } 28872916 } 28882917 } 28892918 } 28902919 28912920 if (!empty($settings['wpms_sitemap_posts'])) { 28922921 foreach ($settings['wpms_sitemap_posts'] as $value) { 28932922 $post_in_sitemap[] = (int)$value['post_id']; 28942923 } 28952924 } 28962925 28972926 28982927 if (!empty($post_in_category)) { 28992928 foreach ($post_in_category as $post) { 29002929 if (in_array($post, $post_in_sitemap)) { 29012930 continue; 29022931 } 29032932 29042933 $settings['wpms_sitemap_posts'][$post] = array( 29052934 'post_id' => $post, 29062935 'priority' => '1', 29072936 'frequency' => 'monthly' 29082937 ); 29092938 } 29102939 } 29112940 29122941 update_option('_metaseo_settings_sitemap', $settings); 29132942 } 29142943 29152944 /** 29162945 * Ajax generate sitemap 29172946 * 29182947 * @return void 29192948 */ 29202949 public function checkAllCategoryInSitemap() 29212950 { 29222951 if (empty($_POST['wpms_nonce']) 29232952 || !wp_verify_nonce($_POST['wpms_nonce'], 'wpms_nonce')) { 29242953 die(); 29252954 } 2955 if (!current_user_can('manage_options')) { 2956 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 2957 wp_die(__('There is no permission here', 'wp-meta-seo')); 2958 } 29262959 $post_in_category = array(); 29272960 $post_in_sitemap = array(); 29282961 $settings = get_option('_metaseo_settings_sitemap'); 29292962 $is_all = $_POST['wpms_sitemap_cateogry_is_all']; 29302963 $cat_id = $_POST['wpms_sitemap_category_id']; 29312964 29322965 if (isset($_POST['wpms_sitemap_category_id'])) { 29332966 $args = array( 29342967 'numberposts' => -1, 29352968 'category' => $cat_id, 29362969 'post_type' => 'post' 29372970 ); 29382971 29392972 $posts = get_posts($args); 29402973 if (!empty($posts)) { 29412974 foreach ($posts as $post) { 29422975 $post_in_category[] = $post->ID; 29432976 } 29442977 } 29452978 } 29462979 29472980 if (!empty($settings['wpms_sitemap_posts'])) { 29482981 foreach ($settings['wpms_sitemap_posts'] as $value) { 29492982 $post_in_sitemap[] = (int)$value['post_id']; 29502983 } 29512984 } 29522985 29532986 if ($is_all) { 29542987 if ($post_in_category) { 29552988 foreach ($post_in_category as $post) { 29562989 if (in_array($post, $post_in_sitemap)) { 29572990 continue; 29582991 } 29592992 29602993 $settings['wpms_sitemap_posts'][$post] = array( 29612994 'post_id' => $post, 29622995 'priority' => '1', 29632996 'frequency' => 'monthly' 29642997 ); 29652998 } 29662999 } 29673000 29683001 array_push($settings['wpms_category_select_all'], $cat_id); 29693002 } else { 29703003 if (!empty($post_in_sitemap)) { 29713004 foreach ($post_in_sitemap as $v) { 29723005 if (in_array($v, $post_in_category)) { 29733006 unset($settings['wpms_sitemap_posts'][$v]); 29743007 } 29753008 } 29763009 } 29773010 29783011 foreach ($settings['wpms_category_select_all'] as $k => $val) { 29793012 if ((int)$val === (int)$cat_id) { 29803013 unset($settings['wpms_category_select_all'][$k]); 29813014 } 29823015 } 29833016 } 29843017 $settings['wpms_category_select_all'] = array_unique($settings['wpms_category_select_all']); 29853018 update_option('_metaseo_settings_sitemap', $settings); 29863019 $this->regenerateSitemaps(); 29873020 } 29883021 29893022 /** 29903023 * Disable default sitemap of wordpress 29913024 * 29923025 * @return void 29933026 */ 29943027 public function disableDefaultWPSitemap() 29953028 { 29963029 $settings = get_option('_metaseo_settings_sitemap'); 29973030 29983031 if (!empty($settings['wpms_sitemap_enable_core'])) { 29993032 return; 30003033 } 30013034 30023035 add_filter('wp_sitemaps_enabled', '__return_false'); 30033036 30043037 if (isset($settings['sitemap'])) { 30053038 add_action('template_redirect', array($this, 'redirectDefaultWPSitemap')); 30063039 } 30073040 } 30083041 30093042 /** 30103043 * Redirects requests to the WordPress sitemap to wpmetaseo sitemap. 30113044 * 30123045 * @return void 30133046 */ 30143047 public function redirectDefaultWPSitemap() 30153048 { 30163049 $settings = get_option('_metaseo_settings_sitemap'); 30173050 // If there is no path, return 30183051 if (empty($_SERVER['REQUEST_URI'])) { 30193052 return; 30203053 } 30213054 30223055 $path = sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])); 30233056 30243057 if (strpos($path, '/wp-sitemap') === false) { 30253058 return; 30263059 } 30273060 30283061 if (is_multisite()) { 30293062 $home_url = preg_replace( 30303063 '/[^a-zA-ZА-Яа-я0-9\s]/', 30313064 '_', 30323065 str_replace('http://', '', str_replace('https://', '', site_url())) 30333066 ); 30343067 30353068 $location = network_home_url('', 'relative') . 'sitemap_' . $home_url . '.xml'; 30363069 } else { 30373070 $location = home_url() . '/' . $this->wpms_sitemap_name; 30383071 } 30393072 30403073 wp_safe_redirect($location, 302, 'WP Meta SEO'); 30413074 exit; 30423075 } 30433076} * TABULARUNIFIED WP-META-SEO/TRUNK/README.TXT ¶ r2869205 r2870465 11=== WP Meta SEO === 22Contributors: JoomUnited 33Tags: google, webmaster tools, keywords, meta, meta description, meta keywords, meta title, robots meta, search engine optimization, seo, wordpress seo, yahoo, image optimization, image resize, custom post seo, redirect, redirection, 301, broken link 44Requires at least: 4.7 55Tested up to: 6.1 6 Stable tag: 4.5.3 6Stable tag: 4.5.4 77Requires PHP: 5.6 88License: GPLv2 or later 99License URI: http://www.gnu.org/licenses/gpl-2.0.html 1010 1111WP Meta SEO gives you the control over all your SEO optimization. Bulk SEO content and image SEO, on page content check, 404 and redirect 1212 1313== Description == 1414 1515## WP Meta SEO plugin, main search engine optimization features 1616 1717* Bulk edit all website meta on a single view 1818* Edit meta in content with live SEO analysis 1919* Fix HTML image resizing in content 2020* Bulk edit image file name and meta 2121* Bulk edit SEO link title 2222* 404 errors redirect and internal broken link checker 2323* Add Google Analytics tracking information and display statistics on WordPress 2424* Generate XML and HTML sitemaps 2525* Facebook and Twitter social sharing custom elements per content 2626* Breadcrumb generator 2727* Gutenberg SEO content checker 2828* Canonical URL management for post, pages 2929 and categories 3030* Elementor full integration with live onPage SEO in the Elementor page editor 3131 3232 3333## WP Meta SEO Addon plugin (optional), additional search engine optimization 3434 3535> * Google Search Console keyword suggestion in content 3636> * Add local business information 3737> * Email SEO report: SEO data 3838> * Email SEO report: Google Analytics data 3939> * Duplicate meta check 4040> * Automatic schedule crawl content for broken links 4141> * Redirect URL based on rules 4242> * Add custom redirect, not only 404 errors 4343> * Custom post type in sitemaps 4444> * Sitemap crawl for errors 4545> * Automatic Google Search Console sitemap submission 4646> * Google Search Console error import and fix 4747> * And more! 4848 4949<a href="https://www.joomunited.com/wordpress-products/wp-meta-seo" rel="friend">More information and feature details here!</a> 5050 5151 5252## Meta information bulk edition and image SEO = 5353 5454Editing meta information on an existing website can be very long, open each post, edit, close it, open again and almost nobody was doing it. Especially if you need to edit content + image meta. 5555WP Meta SEO is going to list all posts, pages, custom post types and all images. Type your meta content and fix image size and everything is AJAX saved. 5656Plus, a bulk copy feature is available to save tons of time in your SEO optimization process: 5757 5858* Content title to All meta titles (optional meta keywords) 5959* Image name to Image title 6060* Image name to Image alt 6161* Optional keyword edition 6262 6363A bunch of people reduce the size of the pictures in content using handles that results to a HTML resizing. And that's something wrong for SEO, for page loading time and for image quality. 6464WP Meta SEO also include this feature in the bulk edition view, you are notified, and you can now optimize the size of your images in articles, click fix, and it's replaced in your content (no broken links). 6565 6666## On-page SEO optimization and content analysis 6767 6868* Content SEO smart analysis below content 6969* Google Search Console keyword suggestion in content 7070* Search engine snippet preview 7171* AJAX SEO analysis refresh 7272* 7 criteria of SEO analysis 7373* Force SEO criteria validation 7474* Check: Page title word in content heading 7575* Check: Page title word in content 7676* Check: Page URL matches with page title 7777* Check: Meta title filled 7878* Check: Meta description filled 7979* Check: Wrong image resizing 8080* Check: Image meta title or alt 8181* Check the Page builders content (Text, HTML, Heading content): 8282Gutenberg, Visual composer, DIVI Builder, Beaver Builder, ACF, Site Origine, Themify builder, Live composer, Elementor 8383 8484## 404 and redirect manager 8585 8686404 errors are bad for user experience and for your backlinks, Google hates it too: this is something that has to be fixed to improve your SEO. 8787The redirect manager will help you to fix all types of 404 errors you can encounter on your website. 8888 8989* Index all 404 errors from external source (external websites) 9090* Internal broken links check: index all broken links you got in your posts, pages, custom posts, comments 9191* Possibility to redirect URL, remove link, recheck link 9292* Redirect all 404 errors to home page 9393* Index all 404 types: URL and images 9494* Monitor the 404 hits number 9595* Flush existing indexed URLs and hits number 9696* Setup and redirect to a 404-custom page 9797 9898## Google Analytics connection 9999 100100* Enable analytics statistics in 2 clicks with token access 101101* Tracking options to exclude WordPress user groups 102102* File download statistics 103103* Display Analytics statistics: session, users, organic, page views, bounce, location, pages, referrer, searches, traffic, technology 104104 105105 106106## XML sitemap & HTML sitemap 107107 108108* Generate automatically xml sitemap 109109* Generate automatically HTML sitemap 110110* Sitemap source: menu selection (can be any content type), post, category of post, pages, author content 111111* Setup update frequency and priority for each sitemap link 112112* Crawl all sitemap URL for errors 113113 114114## Breadcrumb generator = 115115 116116* Rich snippet breadcrumb 117117* Control breadcrumb separator, links and display 118118* Generate breadcrumb shortcode 119119* Generate breadcrumb PHP shortcode 120120 121121**More details here:** <a href="https://www.joomunited.com/wordpress-products/wp-meta-seo" rel="friend">http://www.joomunited.com/wordpress-products/wp-meta-seo</a> 122122 123123= Video demo: = 124124[vimeo https://vimeo.com/113695156] 125125 126126 127127## Other search engine optimization features 128128 129129* Reduce page weight by fixing HTML image resizing 130130* See all your snippet in one view 131131* Image name, title, description, and legend 132132* Dashboard SEO check 133133* Automatic AJAX saving SEO content on bulk edition 134134* On page analysis: fix SEO criteria 135135* Custom post type meta edition 136136* All custom post type and WooCommerce SEO optimization 137137* Yoast SEO meta information importer 138138* All in one SEO meta information importer 139139* ImageRecycle image compression integration 140140* Live Google snippet preview 141141* Content meta length limit (Google + Yahoo + Bing) 142142* SEO problem warning 143143* One click image title copy 144144* SEO bulk copy: Copy image name to image alt and/or image title 145145* SEO bulk copy: Copy content title to content meta title 146146* SEO 404 and redirect: all 404 errors monitoring 147147* SEO 404 and redirect: Redirect all 404 errors 148148* SEO 404 and redirect: Internal broken link checker 149149* SEO 404 and redirect: Custom 404 error page 150150* SEO 404 and redirect: Redirect all 404 in one click 151151* Check for SEO error: is robot.txt blocking search engine 152152* Bulk edit SEO link title in your content 153153* Follow/No follow on WordPress content 154154* Generate automatically XML sitemap 155155* Generate automatically HTML sitemap 156156* Sitemap source: menu, post, pages, category, and custom posts 157157* HTML sitemap display with 3 frontend layouts 158158 159159 160160= Main plugins from JoomUnited: = 161161 162162* <a href="https://www.joomunited.com/wordpress-products/wp-media-folder" rel="friend">WP Media Folder:</a> Supercharge your media library with folders 163163* <a href="https://www.joomunited.com/wordpress-products/wp-file-download" rel="friend">WP File Download: </a> Best in class file and document manager 164164* <a href="https://www.joomunited.com/wordpress-products/wp-speed-of-light" rel="friend">WP Speed of Light: </a> Speedup your website easily 165165* <a href="https://www.joomunited.com/wordpress-products/wp-latest-posts" rel="friend">WP Latest Posts: </a> Super flexible latest posts and content 166166* <a href="https://www.joomunited.com/wordpress-products/wp-table-manager" rel="friend"> WP Table Manager: </a> Create and manage tables with style 167167 168168 169169= Support = 170170 171171A HTML support document is provided with WP Meta SEO on JoomUnited website 172172You are welcome to ask SEO questions on our forum or here in the support section 173173**Documentation here:** <a href="https://www.joomunited.com/support/wordpress-plugins-documentation?extension=wp-meta-seo#document" rel="friend">https://www.joomunited.com/support/wordpress-plugins-documentation?extension=wp-meta-seo#document</a> 174174 175175== Installation == 176176 177177= To install the automatically: = 178178* Through WordPress admin, use the menu: Plugin > Add new 179179* Search for WP Meta SEO 180180* Click on install then click activate link 181181 182182= To install the plugin manually: = 183183* Download and unzip the plugin wp-meta-seo.zip 184184* Upload the /wp-meta-seo directory to /wp-content/plugins/ 185185* Activate the plugin through the 'Plugins' menu on WordPress 186186* Use the WP Meta SEO WordPress left menu 187187 188188Once the plugin is installed, open the bulk edition through the admin menu or open a content to load SEO on page analysis. 189189The plugin will check on install if there's Yoast SEO or All in one SEO and ask for a meta import. Global parameter "Search engine visibility" is also checked to avoid SEO error. 190190 191191== Frequently Asked Questions == 192192 193193= Will the image rename bulk feature generate broken links? = 194194Not at all, it would have been bad for SEO :) the image name is dynamically replaced in all your content. 195195 196196= If I edit image title and alt text, will that information be loaded each time my image is in a content? = 197197There's an SEO option for that :) WP Meta SEO will detect that the image has missing information and once edit it, you will have a list of all the image instance and where it's loaded. 198198So you'll be able to define SEO info for each instance. 199199 200200= Is WP Meta SEO slowing down my website? = 201201Nope :) All your SEO content is properly stored in the database and automatic SEO checks are also cached or run every 72 hours (unless you force the process) 202202 203203= Is WP Meta SEO compatible with 3rd party plugins? = 204204YES it is :) All plugins and themes that are using custom post type are compatible, and you'll be able to set up SEO for those content. Plus, Yoast SEO and All in one SEO content can also be imported. 205205 206206= Is WP Meta SEO fixing 404 errors? = 207207Yes, using a redirect manager tool. WP Meta SEO will index all the 404 you have in your content (internal broken links). 208208 209209= Can I translate WP Meta SEO? = 210210You're welcome! In the WP Meta SEO package, you got English and French included as standard .po/.mo files. Use the .pot file also available in the /language folder to create your own. 211211You can contact us if you want it to be included in the WP Meta SEO package. 212212 213213= How can I set up the Google Analytics to get statistics? = 214214First create an account on Google Analytics associated to your domain. Then from the plugin connect your website with your analytics account by copy/pasting a token code. 215215 216216 217217= Compatibility = 218218What's the minimum version of WordPress required to run WP Meta SEO? WordPress 4.0 is required. WP Meta SEO may generate PHP errors if you tried to run it on an earlier version, and so it will simply refuse to activate on any version of WordPress that's older than 4.0 219219 220220= Where on WordPress does WP Meta SEO plugin should be displayed? = 221221In the admin of WordPress, on the left menu named WP Meta SEO and its sub menu for SEO tools 222222 223223= How do I uninstall WP Meta SEO? = 224224Go to the Plugins > WP Meta SEO > Deactivate > Delete 225225If you choose to install it later all your SEO data will remain in place (database stored) 226226 227227= Which browsers work best with the WP Meta SEO administration interface? = 228228WP Meta SEO is using HTML5 features so to be certain run the latest version of Chrome / Firefox / Safari or IE9+ 229229 230230= Can I help with WP Meta SEO translation? = 231231Yes! you can contact us on our forum. SEO as its language and expression, we would be happy to add yours. 232232 233233= Why including meta keywords' edition as it's not a SEO rank criteria? = 234234Because it may help in some case for SEO, mainly for multilingual website, it helps search engines to validate the page language. Some automatic SEO tool may use it too. 235235 236236= Some criteria of the SEO on page analysis does not fit my content = 237237Yes, it may be the case when, for example, you are calling 3rd party plugins in content or using specific page layouts. You have a global option to force validation of SEO criteria. 238238This manual SEO validation on click on the reload analysis button. 239239 240240= How do I submit my sitemap to the Google Search Console? = 241241From the Sitemap section of the plugin, you got a link to the XML sitemap page. Just copy/paste the link in the Google Search Console. 242242You can also use the link: www.your-website.com/sitemap.xml after checking the option to copy the sitemap to the WordPress install root. 243243 244244= Is there a real interest for SEO to display a HTML sitemap? = 245245It could be! If you have many pages that need to be indexed with no specific priority. Our advice is to keep only the main menus of your website in the HTML sitemap. 246246 247247= Is it compatible with Gutenberg Editor? = 248248Yes WP Meta SEO is compatible with Gutenberg editor since 3.7 version. 249249 250250== Screenshots == 251251 2522521. Main dashboard of the plugin with SEO optimization check 2532531. On page dynamic SEO analysis for posts, pages, page builders and custom post type 2542541. Bulk content meta edition with AJAX saving 2552551. Bulk image SEO content edition: title, description, alt, legend text 2562561. Image resized in HTML (with handles) is automatically detected and can be resized 2572571. 404 and redirect tool + broken link checker 2582581. Google Search Console integration: Google keyword suggestions 2592591. Google Analytics integration with all main information and view selection 260260 261261== Changelog == 262262 263= 4.5.4 = 264 * Fix : Security: Added current_user_can() and nonce checks to some functions 265 263266= 4.5.3 = 264267 * Fix : Security: SQL injection by subscriber users 265268 * Fix : Security: arbitrary redirect by subscriber users 266269 267270= 4.5.2 = 268271 * Fix : A fatal error with PHP 8 269272 * Fix : Analysis meta title error on WP Meta Seo dashboard when having many posts 270273 271274= 4.5.1 = 272275 * Add : Update JU translation tool with autosaving 273276 * Add : Instant installation of translation and help texts 274277 * Fix : Cleanup text for meta description 275278 276279= 4.5.0 = 277280 * Add : SEO optimization meta block for DIVI 278281 * Add : New variables: %page%, %pagetotla%, %pagenumber% for blog pagination 279282 280283= 4.4.9 = 281284 * Fix : Security issue 282285 283286= 4.4.8 = 284287 * Fix : Google Analytics connection: update OAuth2 authorization 285288 286289= 4.4.7 = 287290 * Fix : Escape the breadcrumb separator before outputting it to the page 288291 289292= 4.4.6 = 290293 * Add : WP Meta Seo widget: Quick SEO Preview 291294 292295= 4.4.5 = 293296 * Add : Update Google API 294297 * Fix : SEO checker on WP Meta SEO meta box 295298 296299= 4.4.4 = 297300 * Fix : Google search console on Elementor 298301 299302= 4.4.3 = 300303 * Add : Default post image setting for social meta 301304 * Fix : SEO checker on Elementor Meta SEO meta box 302305 303306= 4.4.2 = 304307 * Fix : Remove social meta tags on front-end when they are not filled 305308 306309= 4.4.1 = 307310 * Fix : Removed unused assets 308311 309312= 4.4.0 = 310313 * Add : Meta SEO meta box on Elementor 311314 * Add : Bulk editor for post/product categories 312315 313316= 4.3.7 = 314317 * Fix : The header title issue on some themes 315318 316319= 4.3.6 = 317320 * Fix : Update settings from old version to Google Analytics 318321 319322= 4.3.5 = 320323 * Add : New Google Analytics tracking UX 321324 * Add : Support Google Analytics v4 property 322325 * Add : Support Google Tag manager 323326 * Fix : Update Meta SEO meta description length 324327 * Fix : Remove HTML tags from WP Meta SEO meta tags 325328 326329= 4.3.4 = 327330 * Fix : Remove some jQuery deprecated functions 328331 * Fix : Update Google Analytics library 329332 330333= 4.3.3 = 331334 * Fix : Update page SEO checker text 332335 333336= 4.3.2 = 334337 * Fix : Tooltips are going out of the screen on bulk lists 335338 336339= 4.3.1 = 337340 * Fix : Tooltip display incorrectly 338341 * Fix : Use default WordPress canonical url for all pages when Canonical URL setting disabled 339342 * Fix : Checkbox CSS color on admin panel 340343 341344= 4.3.0 = 342345 * Add : New content meta editor with direct edition 343346 * Add : New content meta editor on bulk meta editor 344347 * Add : SEO keywords field on post/page edition 345348 * Add : SEO score and keywords in posts list 346349 347350= 4.2.10 = 348351 * Fix : Adding image alt not always working 349352 350353= 4.2.9 = 351354 * Fix : Conflict with the Enable jQuery Migrate Helper plugin 352355 353356= 4.2.8 = 354357 * Add : Disable WordPress core XML sitemap by default 355358 * Fix : Tooltip is not shown on WordPress 5.5 356359 357360= 4.2.7 = 358361 * Fix : Google Analytics chart display 359362 * Fix : Some PHP warnings in debug.log 360363 361364= 4.2.6 = 362365 * Fix : Google Client libraries conflict with BackupBuddy plugin 363366 364367= 4.2.5 = 365368 * Add : Possibility to automatically add articles to sitemaps 366369 * Fix : Select all posts in the sitemap 367370 368371= 4.2.4 = 369372 * Add : Possibility to remove category prefix 370373 * Fix : The loader image to display incorrectly in the metabox 371374 372375= 4.2.3 = 373376 * Fix : Update successfully message after save settings 374377 * Fix : See more posts in category in the sitemap 375378 * Fix : Display XML sitemap link in multisite 376379 377380= 4.2.2 = 378381 * Fix : JS error in Gutenberg editor that prevent the metabox to be 100% loaded 379382 380383= 4.2.1 = 381384 * Fix : Translation sharing issue in some browsers 382385 383386= 4.2.0 = 384387 * Add : Description on admin on each WPMS topic 385388 * Add : Generate automatically a sitemap before the first configuration 386389 * Fix : Edit some styles and tooltips 387390 * Fix : Conflict with other tabs in metabox 388391 * Fix : Some minor errors in the sitemap page 389392 390393= 4.1.0 = 391394 * Add : Force a Canonical URL per content (post, page...) or category 392395 * Add : Google Analytics update: update app and connexion method 393396 * Add : Better admin responsive display 394397 * Add : Consider publish state in meta bulk editor 395398 396399= 4.0.13 = 397400 * Fix : JS error when edit a post 398401 * Fix : Exclude external link and replicate the custom link in sitemap 399402 400403= 4.0.12 = 401404 * Add : Compatibility with Google Search Console integration 402405 403406= 4.0.11 = 404407 * Fix : Material fonts missing 405408 406409= 4.0.10 = 407410 * Fix : Blank page when edit post tag & attribute 408411 * Fix : Snippet for homepage is not properly checked 409412 * Add : Opt In feedback on plugin first disabling & review message 410413 411414= 4.0.9 = 412415 * Fix : JuTranslation duplicate slash in language url 413416 414417= 4.0.8 = 415418 * Fix : Check version requirements 416419 417420= 4.0.7 = 418421 * Add : Link editor & Image editor compatible with Gutenberg blocks 419422 * Fix : The sitemap generated ignore anchor links 420423 421424= 4.0.6 = 422425 * Add : Quick SEO content preview style for WordPress 5.2 423426 * Fix : Bulk action and meta bulk apply to all images 424427 * Fix : Resize and edit meta information in image editor 425428 * Fix : Put back the sitemap URL instead of the server path 426429 * Fix : Add short description for WooCommerce in SEO analysis 427430 428431= 4.0.5 = 429432 * Fix : Add index to improve the query performance 430433 * Fix : Rredirect link with xlink 431434 * Fix : Display of HTML Sitemap theme with DIVI theme 432435 * Fix : Redirect link in custom redirect 433436 434437= 4.0.4 = 435438 * Add : Compatible of the SEO checker and ACF fields 436439 * Add : Change meta title and meta description length 437440 * Fix : Conflict image alt info and Elementor builder 438441 * Fix : Default image and priority of meta 439442 * Fix : Conflict with other SEO plugin (WooCommerce Multivendor plugin) 440443 * Fix : Save new term in product category 441444 442445= 4.0.3 = 443446 * Fix : XML Sitemap cannot be parsed in google console 444447 * Fix : Resize images and check on dashboard 445448 * Fix : Fix list image in image editor 446449 * Fix : Fix an HTTP error when delete posts 447450 448451= 4.0.2 = 449452 * Fix : Title undefined in gutenberg editor 450453 * Fix : Compatible with Oxygen Builder 451454 * Fix : Error when save post 452455 453456= 4.0.1 = 454457 * Fix : Email report doesn't work 455458 * Fix : Css conflict in meta box 456459 457460= 4.0.0 = 458461 * Add : New admin UX and design 459462 * Add : Settings UX with AJAX search engine 460463 * Add : Implement new plugin dashboard with new criteria checks 461464 * Add : Implement bulk actions on meta bulk editor 462465 * Add : Implement bulk actions on image information bulk editor 463466 * Add : Implement bulk actions on the link title manager 464467 * Add : Check color for meta lenght: check is meta is too short or too long 465468 * Add : Plugin installer with quick configuration 466469 * Add : Environment checker on install (PHP Version, PHP Extensions, Apache Modules) 467470 * Add : System Check menu to notify of server configuration problems after install 468471 * Fix : Sitemap display on frontend 469472 470473= 3.7.7 = 471474 * Add : Add actions and filters for developers 472475 473476= 3.7.6 = 474477 * Fix : Redirect to home page when WPMS Addon is not activated 475478 476479= 3.7.5 = 477480 * Fix : Warning returned on frontend 478481 * Fix : Load Dashboard widget content using ajax method (large amount of data) 479482 * Fix : PHP warning in redirect URL interface 480483 481484= 3.7.4 = 482485 * Fix : Update alt meta for Elementor image in content 483486 * Fix : Redirect URL 484487 485488= 3.7.3 = 486489 * Fix : Enhance code readability and performance 487490 488491= 3.7.2 = 489492 * Fix : JUtranslation share with JoomUnited 490493 491494= 3.7.1 = 492495 * Fix : Sitemap categories not properly added 493496 * Fix : Broken link display column header 494497 * Fix : Render meta description on frontend 495498 496499= 3.7.0 = 497500 * Add : Compatible with Gutemberg editor 498501 * Fix : Reload analysis in metabox 499502 * Fix : Render title tag 500503 501504= 3.6.8 = 502505 * Fix : Conflict with Origin PageBuilder plugin 503506 * Fix : Save post and page slow request 504507 505508= 3.6.7 = 506509 * Fix : Meta box not loaded on WordPress multisite 507510 508511= 3.6.6 = 509512 * Fix : Sitemap column display 510513 * Fix : Reload Google Analytics data 511514 512515= 3.6.5 = 513516 * Fix : Compatibility with php 5.3 and 5.4 514517 515518= 3.6.4 = 516519 * Fix : Google analytics tracking code removed some characters 517520 * Fix : Send email (SEO report) 518521 * Fix : Query duplicate meta 519522 520523= 3.6.3 = 521524 * Add : Change meta description max length (320 characters) 522525 * Fix : Conflict with Antispam Bee plugin 523526 * Fix : Page title word in content heading 524527 525528= 3.6.2 = 526529 * Fix : Saving translation does not apply 527530 * Fix : JS error when edit a post (public false) 528531 529532= 3.6.1 = 530533 * Fix : Fatal error on frontend on certain configuration 531534 532535= 3.6.0 = 533536 * Add : Full code reformating for better performance and code comments 534537 * Add : Using PHPCS to make standard definitions 535538 536539= 3.5.3 = 537540 * Fix : Display WordPress page with sitemap 538541 * Fix : Set default image for facebook and Twitter 539542 * Fix : Return error when using undefined get_term_meta function 540543 541544= 3.5.2 = 542545 * Fix : Create robots.txt file for multisite 543546 * Fix : Add meta tags og:type and fb:app_id (Facebook page share) 544547 545548= 3.5.1 = 546549 * Language filter for meta, images and sitemap XML 547550 * Fix : Encoding issue on dashboard page 548551 * Fix : JS error when empty post content 549552 550553= 3.5.0 = 551554 * Fix : Check content of page builders: Visual composer, DIVI Builder, Beaver Builder, ACF, Site Origine, Themify builder, Live composer, Elementor plugins 552555 * Add : Generate rich snippet breadcrumb shortcode and PHP code 553556 * Fix : Redesign the image edition window 554557 555558= 3.4.1 = 556559 * Add : Meta keywords field in category meta edition 557560 * Add : Update dashboard description and image compression layout 558561 * Fix : Warning when 'wpio_images' table does not exist 559562 560563= 3.4.0 = 561564 * Add : Simple Analytics tracking only based on UA or JS snippet 562565 * Add : Add image indexation system for large websites (image bulk editor) 563566 * Add : Apply material design over all plugin views 564567 * Add : Image information: Filter only images that require optimization 565568 * Fix : Conflict with WP Latest Posts plugin 566569 567570= 3.3.2 = 568571 * Fix : Remove custom redirect rule not applied 569572 * Fix : Wrong value in meta description for category 570573 * Fix : Custom post types alway displayed in HTML sitemaps 571574 572575= 3.3.1 = 573576 * Fix : Remove upgrade notification when the ADDON is installed 574577 * Fix : Change style for dashboard widgets 575578 * Fix : Change layout and fix criteria in SEO page optimization 576579 577580= 3.3.0 = 578581 * Add : If an image information are filled, add it by default if empty if image is re-used 579582 * Add : Compatibility with WPML, Polylang for meta edition and Media SEO content 580583 * Add : Possibility to edit meta information on categories 581584 * Add : Pro version notifications of features in some views 582585 * Add : Dashboard widget with 6 SEO criteria 583586 * Fix : Change the 404 error page title to remove the plugin name by default 584587 585588= 3.2.6 = 586589 * Add : Add builtin translation tool 587590 * Fix : Wrong function used to get description length 588591 589592= 3.2.5 = 590593 * Add : Check DOM PHP activation install to avoid fatal error 591594 * Fix : Image information edition with greek characters 592595 593596= 3.2.4 = 594597 * Add : WP Meta SEO Addon compatibility 595598 * Fix : Conflict with DIVI layout injector plugin 596599 597600= 3.2.3 = 598601 * Fix : Image resize list does not refresh 599602 * Fix : Meta image text replaced by image information 600603 * Fix : Dashboard Alexa rank display 601604 * Fix : Sharp URL suffix are detected as 404 by the redirect manager 602605 * Fix : Phone numbers with '+' are detected as 404 by the redirect manager 603606 * Fix : German characters are broken in the link manager 604607 605608= 3.2.2 = 606609 * Fix : Image information edition with a quote becomes empty 607610 * Fix : Meta edition character count does not refresh using AJAX 608611 609612= 3.2.1 = 610613 * Add : Compatibility with WP Speed of Light plugin: https://www.joomunited.com/wordpress-products/wp-speed-of-light 611614 612615= 3.2.0 = 613616 * Add : Enable Google Analytics tracking with token access 614617 * Add : Tracking options to exclude WordPress user groups from analytics 615618 * Add : File download statistics activation 616619 * Add : Display Analytics statistics: session, users, organic... 617620 618621= 3.0.2 = 619622 * Add : Add Import meta from Yoast premium plugin 620623 * Fix : Font called from http instead of https from dashboard 621624 622625= 3.0.1 = 623626 * Fix : XML menu generation don't handle menu levels 624627 * Fix : Mailto links are indexed as 404 error in the redirect manager 625628 * Fix : PHP warning when link editor is activated in editor 626629 * Fix : Secure code 627630 628631= 3.0.0 = 629632 * Add : Add XML sitemap feature 630633 * Add : Add HTML sitemap feature 631634 * Add : Add sitemap source: menus (any content), post, page, category, author 632635 * Add : Add HTML sitemap content position in page 633636 * Add : Add XML sitemap copy option on root option 634637 * Add : Add XML sitemap link in robot.txt option 635638 * Add : Add help text for all the sitemap parameters 636639 * Add : Add help text for all the global parameters 637640 * Add : Add AJAX sitemap regeneration 638641 639642= 2.2.1 = 640643 * Add : Update sql sentences to improve query speed 641644 642645= 2.2.0 = 643646 * Add : Follow/Nofollow bulk link edition 644647 * Add : Link re-index tool from the bulk link editor 645648 * Add : Follow/Nofollow on Wordpress content (onpage SEO) 646649 * Add : Index/Noindex on Wordpress content (onpage SEO) 647650 648651= 2.1.0 = 649652 * Add : Add ImageRecycle images and PDF compression integration (https://www.imagerecycle.com) 650653 651654= 2.0.3 = 652655 * Fix : On page analysis return wrong result on header title in content 653656 * Fix : Update language on image bulk edit view 654657 655658= 2.0.2 = 656659 * Fix : Detect new type of 404 and add tooltip 657660 * Fix : Comment content not detected 658661 * Fix : Autosaving too fast in safari or firefox 659662 660663= 2.0.1 = 661664 * Fix : Google font style on Safari browser 662665 663666= 2.0.0 = 664667 * Add : Add 404 and redirect manager 665668 * Add : Add Options to redirect all 404 to home page 666669 * Add : Add Setup 404 page as: WP Meta SEO page, custom page, default page 667670 668671= 1.7.3 = 669672 * Fix : og: link broken (facebook) 670673 671674= 1.7.2 = 672675 * Add : Page title as content title or as SEO meta title (option) 673676 674677= 1.7.1 = 675678 * Add : Edit separately the content title from the meta title (for search engine) 676679 * Fix : Fix RSS feed is broken with WP Meta SEO 1.7.0 677680 678681= 1.7.0 = 679682 * Add : Add link SEO title field in link editor tool 680683 * Add : Add a SEO bulk edition view on your links titles (of all your content) 681684 * Add : Automatic meta SEO addition for category view: add category title as meta title and category description as meta description 682685 * Add : Add SEO dashboard check for link titles 683686 * Fix : WooCommerce meta description and title in category view (automatic) 684687 * Fix : WP Meta SEO language to be conform to plugin directory translation tool 685688 686689= 1.6.0 = 687690 * Add : Add meta keywords edition in bulk editor 688691 * Add : Add option to for SEO criteria validation 689692 690693= 1.5.1 = 691694 * Fix : Home page meta not working on some themes 692695 * Fix : Break foreach when search title in SEO content (title in heading) 693696 694697= 1.5.0 = 695698 * Add : Add help tooltip to explain on page validation SEO criteria 696699 * Add : Add help tooltip to explain dashboard SEO parameters 697700 * Add : Put snippet preview title in a column on SEO bulk view edition 698701 * Add : Add SEO and check notification for robot.txt that lock search engine 699702 * Add : Update EN and FR language files 700703 701704= 1.4.0 = 702705 * Add : Bulk copy new option: content title to meta title 703706 * Add : Bulk copy new option: image name to alt text 704707 * Add : Bulk copy new option: image name to image title 705708 * Fix : Twitter card on SEO on page optimization 706709 * Fix : SEO meta empty in some themes 707710 708711= 1.3.0 = 709712 * Add : New SEO check dashboard 710713 * Add : Check for SEO permalinks 711714 * Add : Check for meta description 712715 * Add : Check for image HTML resizing 713716 * Add : Check for image SEO: title, alt and description 714717 * Add : Check for new content 715718 716719= 1.2.0 = 717720 * Add : Change language to po/mo files 718721 * Add : Include .pot file and French language 719722 * Add : Setting for home page meta 720723 * Add : Bigger edit meta boxes 721724 * Add : Update icon of notification in meta view 722725 723726= 1.1.0 = 724727 * Add : On page SEO analysis 725728 * Add : Social sharing custom content 726729 727730= 1.0.4 = 728731 * Fix : Check empty array 729732 730733= 1.0.3 = 731734 * Fix : Escape meta title and meta description 732735 733736= 1.0.2 = 734737 * Fix : Filter broken and icons broken 735738 736739= 1.0.1 = 737740 * Fix : display (no title) in column title if post is no titled 738741 739742= 1.0.0 = 740743 * Add : Initial release 741744 742745 743746 744747== Upgrade Notice == 745748 746749Update through the automatic WordPress updater, all WP Meta SEO content will remain in place. 747750You WON'T lose any SEO content: meta, alt, titles 748751 749752 750753 751754== Requirements == 752755 753756= !!NEW in latest & fresh 3.0 version!! = 754757Sitemap feature with XML for the Google Search Console and HTML with display option. 755758 756759= SEO vision = 757760 758761Search engines are a major source of traffic for most websites. That's why our users often ask us for SEO tips and plugins that can help improve SEO of their WordPress sites. 759762WP Meta SEO has been created to give to professionals and final users some real SEO tools to get better SEO rank. We think that SEO has to be something logic and durable. Overall SEO optimization requires a lot of time for each website, each client. 760763 761764WP Meta SEO provides some automatic tools to analyze your content and give to search engine a better content to analyze. 762765 763766WP Meta SEO on each new version, will focus on both "On-page SEO" and "Global website SEO" factors: 764767On-page SEO: Features that help you optimize a single page, e.g. the article you are working on (with a live analysis). Common functionality includes giving SEO scores to each article, content/meta comparison, page analysis tools and making recommendations how to improve the SEO of a post. 765768Site-wide SEO: it's more about your whole site and structure between multiple articles. Common functionality includes title formatting, meta tag optimization as well as internal linking and redirects management. 766769 767770And... don't forget to check each month your SEO dashboard :) 768771 769772PHP 5.6+, WordPress 5.x * TABULARUNIFIED WP-META-SEO/TRUNK/WP-META-SEO.PHP ¶ r2869205 r2870465 11<?php 22 33/** 44 * Plugin Name: WP Meta SEO 55 * Plugin URI: http://www.joomunited.com/wordpress-products/wp-meta-seo 66 * Description: WP Meta SEO is a plugin for WordPress to fill meta for content, images and main SEO info in a single view. 7 * Version: 4.5.3 7 * Version: 4.5.4 88 * Text Domain: wp-meta-seo 99 * Domain Path: /languages 1010 * Author: JoomUnited 1111 * Author URI: http://www.joomunited.com 1212 * License: GPL2 1313 */ 1414// Make sure we don't expose any info if called directly 1515if (!function_exists('add_action')) { 1616 echo 'Hi there! I\'m just a plugin, not much I can do when called directly.'; 1717 exit; 1818} 1919 2020if (version_compare(PHP_VERSION, '5.6', '<')) { 2121 if (!function_exists('wpmsDisablePlugin')) { 2222 /** 2323 * Deactivate plugin 2424 * 2525 * @return void 2626 */ 2727 function wpmsDisablePlugin() 2828 { 2929 if (current_user_can('activate_plugins') && is_plugin_active(plugin_basename(__FILE__))) { 3030 deactivate_plugins(__FILE__); 3131 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Do not load anything more 3232 unset($_GET['activate']); 3333 } 3434 } 3535 } 3636 3737 if (!function_exists('wpmsShowError')) { 3838 /** 3939 * Show notice 4040 * 4141 * @return void 4242 */ 4343 function wpmsShowError() 4444 { 4545 echo '<div class="error"><p><strong>WP Meta SEO</strong> 4646 need at least PHP 5.6 version, please update php before installing the plugin.</p></div>'; 4747 } 4848 } 4949 5050 //Add actions 5151 add_action('admin_init', 'wpmsDisablePlugin'); 5252 add_action('admin_notices', 'wpmsShowError'); 5353 5454 //Do not load anything more 5555 return; 5656} 5757 5858//Include the jutranslation helpers 5959include_once('jutranslation' . DIRECTORY_SEPARATOR . 'jutranslation.php'); 6060call_user_func( 6161 '\Joomunited\WPMetaSEO\Jutranslation\Jutranslation::init', 6262 __FILE__, 6363 'wp-meta-seo', 6464 'WP Meta SEO', 6565 'wp-meta-seo', 6666 'languages' . DIRECTORY_SEPARATOR . 'wp-meta-seo-en_US.mo' 6767); 6868 6969// Include jufeedback helpers 7070require_once('jufeedback'. DIRECTORY_SEPARATOR . 'jufeedback.php'); 7171call_user_func( 7272 '\Joomunited\WPMetaSEO\Jufeedback\Jufeedback::init', 7373 __FILE__, 7474 'wpms', 7575 'wp-meta-seo', 7676 'WP Meta Seo', 7777 'wp-meta-seo' 7878); 7979 8080if (!class_exists('\Joomunited\WPMS\JUCheckRequirements')) { 8181 require_once(trailingslashit(dirname(__FILE__)) . 'requirements.php'); 8282} 8383 8484if (class_exists('\Joomunited\WPMS\JUCheckRequirements')) { 8585 // Plugins name for translate 8686 $args = array( 8787 'plugin_name' => esc_html__('WP Meta SEO', 'wp-meta-seo'), 8888 'plugin_path' => 'wp-meta-seo/wp-meta-seo.php', 8989 'plugin_textdomain' => 'wp-meta-seo', 9090 'requirements' => array( 9191 'php_version' => '5.6', 9292 'php_modules' => array( 9393 'curl' => 'warning', 9494 'libxml' => 'warning' 9595 ), 9696 // Minimum addons version 9797 'addons_version' => array( 9898 'wpmsAddons' => '1.3.7' 9999 ) 100100 ), 101101 ); 102102 $wpmsCheck = call_user_func('\Joomunited\WPMS\JUCheckRequirements::init', $args); 103103 104104 if (!$wpmsCheck['success']) { 105105 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Do not load anything more 106106 unset($_GET['activate']); 107107 return; 108108 } 109109} 110110 111111if (!defined('WPMETASEO_PLUGIN_URL')) { 112112 /** 113113 * Url to WP Meta SEO plugin 114114 */ 115115 define('WPMETASEO_PLUGIN_URL', plugin_dir_url(__FILE__)); 116116} 117117 118118if (!defined('WPMETASEO_PLUGIN_DIR')) { 119119 /** 120120 * Path to WP Meta SEO plugin 121121 */ 122122 define('WPMETASEO_PLUGIN_DIR', plugin_dir_path(__FILE__)); 123123} 124124 125125if (!defined('URL')) { 126126 /** 127127 * Site url 128128 */ 129129 define('URL', get_site_url()); 130130} 131131 132132if (!defined('WPMSEO_VERSION')) { 133133 /** 134134 * Plugin version 135135 */ 136 define('WPMSEO_VERSION', '4.5.3'); 136 define('WPMSEO_VERSION', '4.5.4'); 137137} 138138 139139if (!defined('WPMS_CLIENTID')) { 140140 /** 141141 * Default client id to connect to google application 142142 */ 143143 define('WPMS_CLIENTID', '992432963228-t8pc9ph1i7afaqocnhjl9cvoovc9oc7q.apps.googleusercontent.com'); 144144} 145145 146146if (!defined('WPMS_CLIENTSECRET')) { 147147 /** 148148 * Default client secret to connect to google application 149149 */ 150150 define('WPMS_CLIENTSECRET', 'tyF4XICemXdORWX2qjyazfqP'); 151151} 152152 153153if (!defined('MPMSCAT_TITLE_LENGTH')) { 154154 /** 155155 * Default meta title length 156156 */ 157157 define('MPMSCAT_TITLE_LENGTH', 60); 158158} 159159 160160if (!defined('MPMSCAT_DESC_LENGTH')) { 161161 /** 162162 * Default meta description length 163163 */ 164164 define('MPMSCAT_DESC_LENGTH', 158); 165165} 166166 167167if (!defined('MPMSCAT_KEYWORDS_LENGTH')) { 168168 /** 169169 * Default meta keywords length 170170 */ 171171 define('MPMSCAT_KEYWORDS_LENGTH', 256); 172172} 173173 174174if (!defined('WPMSEO_FILE')) { 175175 /** 176176 * Path to this file 177177 */ 178178 define('WPMSEO_FILE', __FILE__); 179179} 180180 181181 182182if (!defined('WPMSEO_ADDON_FILENAME')) { 183183 /** 184184 * WP Meta SEO addon file 185185 */ 186186 define('WPMSEO_ADDON_FILENAME', 'wp-meta-seo-addon/wp-meta-seo-addon.php'); 187187} 188188 189189if (!defined('WPMSEO_TEMPLATE_BREADCRUMB')) { 190190 /** 191191 * Default template for breadcrumb 192192 */ 193193 define( 194194 'WPMSEO_TEMPLATE_BREADCRUMB', 195195 '<span property="itemListElement" typeof="ListItem"> 196196<span property="name">%htitle%</span><meta property="position" content="%position%"></span>' 197197 ); 198198} 199199include_once(ABSPATH . 'wp-admin/includes/plugin.php'); 200200register_activation_hook(__FILE__, array('WpMetaSeo', 'pluginActivation')); 201201register_deactivation_hook(__FILE__, array('WpMetaSeo', 'pluginDeactivation')); 202202 203203require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.wp-metaseo.php'); 204204add_action('init', array('WpMetaSeo', 'init')); 205205require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-sitemap.php'); 206206$GLOBALS['metaseo_sitemap'] = new MetaSeoSitemap; 207207/** 208208 * Get default settings 209209 * 210210 * @return array 211211 */ 212212function wpmsGetDefaultSettings() 213213{ 214214 return array( 215215 'home_meta_active' => 1, 216216 'metaseo_title_home' => '', 217217 'metaseo_desc_home' => '', 218218 'metaseo_showfacebook' => '', 219219 'metaseo_showfbappid' => '', 220220 'metaseo_showtwitter' => '', 221221 'metaseo_twitter_card' => 'summary', 222222 'metaseo_showkeywords' => 0, 223223 'metaseo_showtmetablock' => 1, 224224 'metaseo_showsocial' => 1, 225225 'metaseo_seovalidate' => 0, 226226 'metaseo_linkfield' => 1, 227227 'metaseo_metatitle_tab' => 1, 228228 'metaseo_follow' => 0, 229229 'metaseo_index' => 0, 230230 'metaseo_overridemeta' => 1, 231231 'metaseo_canonical' => 0, 232232 'metaseo_removecatprefix' => 0, 233233 'metaseo_specific_keywords' => '', 234234 'metaseo_enable_default_fb_image' => array( 235235 'active' => 0, 236236 'source' => 'featured', 237237 'default_set' => '' 238238 ), 239239 'metaseo_enable_default_twitter_image' => array( 240240 'active' => 0, 241241 'source' => 'featured', 242242 'default_set' => '' 243243 ), 244244 ); 245245} 246246 247247/** 248248 * Retrieve the date of the post/page/cpt for use as replacement string 249249 * 250250 * @param object $current_post Current post info 251251 * 252252 * @return string|null 253253 */ 254254function wpmsRetrieveDate($current_post) 255255{ 256256 $replacement = null; 257257 if (isset($current_post->post_date) && $current_post->post_date !== '') { 258258 $replacement = mysql2date(get_option('date_format'), $current_post->post_date, true); 259259 } else { 260260 if (get_query_var('day') && get_query_var('day') !== '') { 261261 $replacement = get_the_date(); 262262 } else { 263263 if (single_month_title(' ', false) && single_month_title(' ', false) !== '') { 264264 $replacement = single_month_title(' ', false); 265265 } elseif (get_query_var('year') !== '') { 266266 $replacement = get_query_var('year'); 267267 } 268268 } 269269 } 270270 271271 return $replacement; 272272} 273273 274274/** 275275 * Extract specific HTML tags and their attributes from a string. 276276 * 277277 * You can either specify one tag, an array of tag names, or a regular expression that matches the tag name(s). 278278 * If multiple tags are specified you must also set the $selfclosing parameter and it must be the same for 279279 * all specified tags (so you can't extract both normal and self-closing tags in one go). 280280 * 281281 * The function returns a numerically indexed array of extracted tags. Each entry is an associative array 282282 * with these keys : 283283 * tag_name - the name of the extracted tag, e.g. "a" or "img". 284284 * offset - the numberic offset of the first character of the tag within the HTML source. 285285 * contents - the inner HTML of the tag. This is always empty for self-closing tags. 286286 * attributes - a name -> value array of the tag's attributes, or an empty array if the tag has none. 287287 * full_tag - the entire matched tag, e.g. '<a href="http://example.com">example.com</a>'. This key 288288 * will only be present if you set $return_the_entire_tag to true. 289289 * 290290 * @param string $html The HTML code to search for tags. 291291 * @param string|array $tag The tag(s) to extract. 292292 * @param boolean $selfclosing Whether the tag is self-closing or not. 293293 * Setting it to null will force the script to try and make an educated guess. 294294 * @param boolean $return_the_entire_tag Return the entire matched tag in 'full_tag' key of the results array. 295295 * @param string $charset The character set of the HTML code. Defaults to ISO-8859-1. 296296 * 297297 * @return array An array of extracted tags, or an empty array if no matching tags were found. 298298 */ 299299function wpmsExtractTags( 300300 $html, 301301 $tag, 302302 $selfclosing = null, 303303 $return_the_entire_tag = false, 304304 $charset = 'ISO-8859-1' 305305) { 306306 307307 if (is_array($tag)) { 308308 $tag = implode('|', $tag); 309309 } 310310 311311 $selfclosing_tags = array( 312312 'area', 313313 'base', 314314 'basefont', 315315 'br', 316316 'hr', 317317 'input', 318318 'img', 319319 'link', 320320 'meta', 321321 'col', 322322 'param' 323323 ); 324324 if (is_null($selfclosing)) { 325325 $selfclosing = in_array($tag, $selfclosing_tags); 326326 } 327327 328328 if ($selfclosing) { 329329 $tag_pattern = '@<(?P<tag>' . $tag . ') # <tag 330330 (?P<attributes>\s[^>]+)? # attributes, if any 331331 \s*/?> # /> or just >, being lenient here 332332 @xsi'; 333333 } else { 334334 $tag_pattern = '@<(?P<tag>' . $tag . ') # <tag 335335 (?P<attributes>\s[^>]+)? # attributes, if any 336336 \s*> # > 337337 (?P<contents>.*?) # tag contents 338338 </(?P=tag)> # the closing </tag> 339339 @xsi'; 340340 } 341341 342342 $attribute_pattern = '@ 343343 (?P<name>\w+) # attribute name 344344 \s*=\s* 345345 ( 346346 (?P<quote>[\"\'])(?P<value_quoted>.*?)(?P=quote) # a quoted value 347347 | # or 348348 (?P<value_unquoted>[^\s"\']+?)(?:\s+|$) # an unquoted value (terminated by whitespace or EOF) 349349 ) 350350 @xsi'; 351351 352352 //Find all tags 353353 if (!preg_match_all($tag_pattern, $html, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { 354354 //Return an empty array if we didn't find anything 355355 return array(); 356356 } 357357 358358 $tags = array(); 359359 foreach ($matches as $match) { 360360 //Parse tag attributes, if any 361361 $attributes = array(); 362362 if (!empty($match['attributes'][0])) { 363363 if (preg_match_all($attribute_pattern, $match['attributes'][0], $attribute_data, PREG_SET_ORDER)) { 364364 //Turn the attribute data into a name->value array 365365 foreach ($attribute_data as $attr) { 366366 if (!empty($attr['value_quoted'])) { 367367 $value = $attr['value_quoted']; 368368 } elseif (!empty($attr['value_unquoted'])) { 369369 $value = $attr['value_unquoted']; 370370 } else { 371371 $value = ''; 372372 } 373373 374374 //Passing the value through html_entity_decode is handy when you want 375375 //to extract link URLs or something like that. You might want to remove 376376 //or modify this call if it doesn't fit your situation. 377377 $value = html_entity_decode($value, ENT_QUOTES, $charset); 378378 379379 $attributes[$attr['name']] = $value; 380380 } 381381 } 382382 } 383383 384384 $tag = array( 385385 'tag_name' => $match['tag'][0], 386386 'offset' => $match[0][1], 387387 'contents' => !empty($match['contents']) ? $match['contents'][0] : '', //empty for self-closing tags 388388 'attributes' => $attributes, 389389 ); 390390 if ($return_the_entire_tag) { 391391 $tag['full_tag'] = $match[0][0]; 392392 } 393393 394394 $tags[] = $tag; 395395 } 396396 397397 return $tags; 398398} 399399 400400require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-rewrite.php'); 401401$settings = get_option('_metaseo_settings'); 402402if (isset($settings['metaseo_removecatprefix']) && $settings['metaseo_removecatprefix'] === '1') { 403403 $GLOBALS['metaseo_rewrite'] = new MetaSeoRewrite; 404404} 405405 406406if (is_admin()) { 407407 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-content-list-table.php'); 408408 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-category-meta-table.php'); 409409 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-image-list-table.php'); 410410 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-dashboard.php'); 411411 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-broken-link-table.php'); 412412 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-google-analytics.php'); 413413 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-admin.php'); 414414 add_action('plugins_loaded', 'wpmsAdminInit', 15); 415415 416416 /** 417417 * Admin init 418418 * 419419 * @return void 420420 */ 421421 function wpmsAdminInit() 422422 { 423423 $GLOBALS['metaseo_admin'] = new MetaSeoAdmin; 424424 } 425425 426426 /*add_filter('wp_prepare_attachment_for_js', array('MetaSeoImageListTable', 'addMoreAttachmentSizes'), 10, 2); 427427 add_filter('image_size_names_choose', array('MetaSeoImageListTable', 'addMoreAttachmentSizesChoose'), 10, 1);*/ 428428 add_filter('user_contactmethods', 'metaseoContactuser', 10, 1); 429429 430430 /** 431431 * Custom field for user profile 432432 * 433433 * @param array $contactusers List contact users 434434 * 435435 * @return mixed 436436 */ 437437 function metaseoContactuser($contactusers) 438438 { 439439 $contactusers['mtwitter'] = esc_html__('Twitter username (without @)', 'wp-meta-seo'); 440440 $contactusers['mfacebook'] = esc_html__('Facebook profile URL', 'wp-meta-seo'); 441441 return $contactusers; 442442 } 443443 444444 include_once(WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmsga.php'); 445445 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Not a form, nonce is not required 446446 if (isset($_GET['task']) && $_GET['task'] === 'wpms_ga') { 447447 if (!empty($_GET['code'])) { 448448 $google_analytics = get_option('wpms_google_alanytics'); 449449 450450 if (is_array($google_analytics)) { 451451 $google_analytics['code'] = $_GET['code']; 452452 453453 require_once WPMETASEO_PLUGIN_DIR . 'inc/google_analytics/wpmstools.php'; 454454 $ggClient = WpmsGaTools::initClient($google_analytics['wpmsga_dash_clientid'], $google_analytics['wpmsga_dash_clientsecret']); 455455 456456 try { 457457 $ggClient->authenticate($google_analytics['code']); 458458 $getAccessToken = $ggClient->getAccessToken(); 459459 460460 if ($getAccessToken) { 461461 $ggClient->setAccessToken($getAccessToken); 462462 $google_analytics['googleCredentials'] = $getAccessToken; 463463 464464 if (empty($google_alanytics['profile_list'])) { 465465 $service = new WPMSGoogle_Service_Analytics($ggClient); 466466 $midnight = strtotime('tomorrow 00:00:00'); // UTC midnight 467467 $midnight = $midnight + 8 * 3600; // UTC 8 AM 468468 $error_timeout = $midnight - time(); 469469 470470 $profiles = WpmsGaTools::refreshProfiles($service, $getAccessToken['access_token'], $error_timeout); 471471 $google_analytics['profile_list'] = $profiles; 472472 } 473473 474474 update_option('wpms_google_alanytics', $google_analytics); 475475 // Do redirect 476476 $redirectUrl = admin_url('admin.php?page=metaseo_google_analytics&view=wpms_gg_service_data'); 477477 header('Location: '.$redirectUrl, true, 302); 478478 exit; 479479 } 480480 } catch (WPMSGoogle\Service\Exception $e) { 481481 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Log error for debug 482482 error_log($e->getMessage()); 483483 } catch (Exception $e) { 484484 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Log error for debug 485485 error_log($e->getMessage()); 486486 } 487487 } 488488 } 489489 // phpcs:enable 490490 } 491491} else { 492492 /** 493493 * Outputs the breadcrumb 494494 * 495495 * @param boolean $return Whether to return or echo the trail. (optional) 496496 * @param boolean $reverse Whether to reverse the output or not. (optional) 497497 * 498498 * @return string 499499 */ 500500 function wpmsBreadcrumb($return = false, $reverse = false) 501501 { 502502 require_once(WPMETASEO_PLUGIN_DIR . 'inc/breadcrumb/class.metaseo-breadcrumb.php'); 503503 $breadcrumb = new MetaSeoBreadcrumb; 504504 if ($breadcrumb !== null) { 505505 $breadcrumb->checkPosts(); 506506 return $breadcrumb->breadcrumbDisplay($return, $reverse); 507507 } 508508 return ''; 509509 } 510510 511511 /* 512512 * shortcode for breadcrumb 513513 */ 514514 add_shortcode('wpms_breadcrumb', 'wpmsBreadcrumbShortcode'); 515515 516516 if (!function_exists('wpmsBreadcrumbShortcode')) { 517517 /** 518518 * Create shortcode for breadcrumb 519519 * 520520 * @param array $params Shortcode attribute 521521 * 522522 * @return string 523523 */ 524524 function wpmsBreadcrumbShortcode($params) 525525 { 526526 $html = '<div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">'; 527527 if (isset($params['reverse']) && (int)$params['reverse'] === 1) { 528528 $html .= wpmsBreadcrumb(true, true); 529529 } else { 530530 $html .= wpmsBreadcrumb(true, false); 531531 } 532532 $html .= '</div>'; 533533 534534 return $html; 535535 } 536536 } 537537 538538 // Check again and modify title, meta title, meta description before output 539539 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-opengraph.php'); 540540 541541 add_action('wpmsseo_head', 'wpmsopengraph', 30); 542542 // Remove actions that we will handle through our wpseo_head call, and probably change the output of. 543543 remove_action('wp_head', 'rel_canonical'); 544544 /** 545545 * Render graph meta tag 546546 * 547547 * @return void 548548 */ 549549 function wpmsopengraph() 550550 { 551551 global $wp_query; 552552 $is_shop = false; 553553 if (function_exists('is_shop')) { 554554 if (is_shop()) { 555555 $is_shop = true; 556556 $id = wc_get_page_id('shop'); 557557 $post = get_post($id); 558558 $content = $post->post_content; 559559 } else { 560560 if (empty($wp_query->post)) { 561561 return; 562562 } 563563 $id = $wp_query->post->ID; 564564 $content = $wp_query->post->post_content; 565565 } 566566 } else { 567567 if (empty($wp_query->post)) { 568568 return; 569569 } 570570 $id = $wp_query->post->ID; 571571 $content = $wp_query->post->post_content; 572572 } 573573 wp_reset_query(); 574574 575575 $default_settings = wpmsGetDefaultSettings(); 576576 $settings = get_option('_metaseo_settings'); 577577 if (is_array($settings)) { 578578 $settings = array_merge($default_settings, $settings); 579579 } else { 580580 $settings = $default_settings; 581581 } 582582 583583 // get meta title 584584 $opengraph = new MetaSeoOpenGraph(); 585585 $meta_title = $opengraph->getTitle($is_shop, $id); 586586 $meta_title_esc = $opengraph->getMetaTitle($settings, $meta_title); 587587 // get meta description 588588 $meta_desc_esc = $opengraph->getDesc($settings, $id, $content); 589589 // get meta keyword 590590 $meta_keywords_esc = $opengraph->getKeyword($settings, $id); 591591 592592 $page_follow = get_post_meta($id, '_metaseo_metafollow', true); 593593 $page_index = get_post_meta($id, '_metaseo_metaindex', true); 594594 // get meta title for twitter 595595 $meta_twtitle = $opengraph->getTwtitle($id); 596596 // get meta description for twitter 597597 $meta_twdesc = $opengraph->getTwdesc($id); 598598 // get twiter card 599599 $meta_twcard = $opengraph->getTwCard($settings); 600600 601601 // get facebook admin and twiter site meta 602602 $usermeta = $opengraph->getUserMeta($settings, $id); 603603 $meta_twitter_site = $usermeta['meta_twitter_site']; 604604 $facebook_admin = $usermeta['facebook_admin']; 605605 $sitename = get_bloginfo('name'); 606606 607607 // get meta title for facebook 608608 $meta_fbtitle = $opengraph->getFbtitle($id); 609609 // get meta description for facebook 610610 $meta_fbdesc = $opengraph->getFbdesc($id); 611611 // get facebook app id 612612 if (isset($settings['metaseo_showfbappid'])) { 613613 $fbapp_id = esc_attr($settings['metaseo_showfbappid']); 614614 } else { 615615 $fbapp_id = ''; 616616 } 617617 // get meta image for facebook & twiter 618618 $images = $opengraph->getImage($id, $settings); 619619 $meta_fbimage = $images[0]; 620620 $meta_twimage = $images[1]; 621621 622622 $current_url = $opengraph->getCurentUrl($settings, $id); 623623 $type = $opengraph->getType(); 624624 $home_meta_active = wpmsGetOption('home_meta_active'); 625625 // check homepage is latest post 626626 if (is_home() && !empty($home_meta_active)) { 627627 $metas = $opengraph->getHome($settings); 628628 $meta_title_esc = $metas['title']; 629629 $meta_twtitle = $metas['title']; 630630 $meta_fbtitle = $metas['title']; 631631 if ($metas['desc']) { 632632 $meta_desc_esc = $metas['desc']; 633633 $meta_twdesc = $metas['desc']; 634634 $meta_fbdesc = $metas['desc']; 635635 } 636636 $page_follow = $metas['page_follow']; 637637 $page_index = $metas['page_index']; 638638 } 639639 640640 // is front page 641641 if (is_front_page() && 'page' === get_option('show_on_front') && is_page(get_option('page_on_front'))) { 642642 $metas = $opengraph->getFrontPageMeta($settings, $id); 643643 $meta_title_esc = $metas['title']; 644644 $meta_twtitle = $metas['title']; 645645 $meta_fbtitle = $metas['title']; 646646 if ($metas['desc']) { 647647 $meta_desc_esc = $metas['desc']; 648648 $meta_twdesc = $metas['desc']; 649649 $meta_fbdesc = $metas['desc']; 650650 } 651651 652652 $page_follow = $metas['page_follow']; 653653 $page_index = $metas['page_index']; 654654 } 655655 656656 if (is_category() || is_tag() || is_tax()) { 657657 $metas = $opengraph->getTagMeta($wp_query, $settings); 658658 $meta_keywords_esc = $metas['keyword']; 659659 $meta_title_esc = $metas['title']; 660660 $meta_fbtitle = $metas['title']; 661661 $meta_twtitle = $metas['title']; 662662 $meta_desc_esc = $metas['desc']; 663663 $meta_fbdesc = $metas['desc']; 664664 $meta_twdesc = $metas['desc']; 665665 if (!empty($metas['canonical'])) { 666666 $current_url = $metas['canonical']; 667667 } 668668 $page_follow = 'follow'; 669669 } 670670 671671 if (empty($page_index)) { 672672 $page_index = 'index'; 673673 } 674674 675675 if (empty($page_follow)) { 676676 $page_follow = 'follow'; 677677 } 678678 679679 // Create canonical meta link 680680 $canonical_meta = $opengraph->getCanonical($id, $settings, $current_url, $page_index); 681681 if (!empty($canonical_meta)) { 682682 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in some method in class MetaSeoOpenGraph 683683 echo $canonical_meta; 684684 } 685685 686686 $patterns = $opengraph->getPatterns( 687687 $id, 688688 $settings, 689689 $meta_twimage, 690690 $meta_twcard, 691691 $meta_twitter_site, 692692 $sitename, 693693 strip_tags(html_entity_decode($meta_twdesc, ENT_COMPAT, 'UTF-8')), 694694 strip_tags(html_entity_decode($meta_twtitle, ENT_COMPAT, 'UTF-8')), 695695 $facebook_admin, 696696 $meta_fbimage, 697697 strip_tags(html_entity_decode($meta_fbdesc, ENT_COMPAT, 'UTF-8')), 698698 $current_url, 699699 $type, 700700 $fbapp_id, 701701 strip_tags(html_entity_decode($meta_fbtitle, ENT_COMPAT, 'UTF-8')), 702702 esc_html($meta_desc_esc, 'wp-meta-seo'), 703703 esc_html($meta_keywords_esc, 'wp-meta-seo'), 704704 strip_tags(html_entity_decode($meta_title_esc, ENT_COMPAT, 'UTF-8')), 705705 $page_index, 706706 $page_follow 707707 ); 708708 709709 foreach ($patterns as $k => $pattern) { 710710 // phpcs:ignore WordPress.Security.EscapeOutput -- Content escaped in some method in class MetaSeoOpenGraph 711711 echo $pattern[1]; 712712 } 713713 } 714714 715715 add_action('wp_head', 'wpmshead', 30); 716716 /** 717717 * WPMS frontend head 718718 * 719719 * @return void 720720 */ 721721 function wpmshead() 722722 { 723723 global $wp_query; 724724 725725 $old_wp_query = null; 726726 727727 if (!$wp_query->is_main_query()) { 728728 $old_wp_query = $wp_query; 729729 wp_reset_query(); 730730 } 731731 732732 do_action('wpmsseo_head'); 733733 734734 if (!empty($old_wp_query)) { 735735 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- This combines all the output on the frontend 736736 $GLOBALS['wp_query'] = $old_wp_query; 737737 unset($old_wp_query); 738738 } 739739 } 740740 741741 add_filter('pre_get_document_title', 'wpmstitle', 15); 742742 add_filter('wp_title', 'wpmstitle', 15, 3); 743743 add_filter('thematic_doctitle', 'wpmstitle', 15); 744744 add_filter('woo_title', 'wpmstitle', 99); 745745 /** 746746 * Render meta title tag 747747 * 748748 * @param string $title Title 749749 * 750750 * @return mixed|string 751751 */ 752752 function wpmstitle($title) 753753 { 754754 global $wp_query; 755755 $default_settings = wpmsGetDefaultSettings(); 756756 $settings = get_option('_metaseo_settings'); 757757 if (is_array($settings)) { 758758 $settings = array_merge($default_settings, $settings); 759759 } else { 760760 $settings = $default_settings; 761761 } 762762 if (empty($settings)) { 763763 return esc_html($title); 764764 } 765765 766766 if (empty($settings['metaseo_metatitle_tab'])) { 767767 return esc_html($title); 768768 } 769769 if (empty($wp_query->post)) { 770770 return esc_html($title); 771771 } 772772 773773 $is_shop = false; 774774 if (function_exists('is_shop')) { 775775 if (is_shop()) { 776776 $is_shop = true; 777777 $id = wc_get_page_id('shop'); 778778 } else { 779779 $id = $wp_query->post->ID; 780780 } 781781 } else { 782782 $id = $wp_query->post->ID; 783783 } 784784 785785 $opengraph = new MetaSeoOpenGraph(); 786786 $meta_title = $opengraph->getTitle($is_shop, $id); 787787 788788 if (is_home()) { 789789 $metas = $opengraph->getHome($settings); 790790 $meta_title = $metas['title']; 791791 } 792792 793793 // is front page 794794 if (is_front_page() && 'page' === get_option('show_on_front') && is_page(get_option('page_on_front'))) { 795795 $metas = $opengraph->getFrontPageMeta($settings, $id); 796796 $meta_title = $metas['title']; 797797 } 798798 799799 $term = $wp_query->get_queried_object(); 800800 if (is_category() || is_tag() || is_tax()) { 801801 if (function_exists('get_term_meta')) { 802802 $meta_title = get_term_meta($term->term_id, 'wpms_category_metatitle', true); 803803 } else { 804804 $meta_title = get_metadata('term', $term->term_id, 'wpms_category_metatitle', true); 805805 } 806806 807807 $meta_title = $opengraph->replaceSnippet($meta_title, null, $term); 808808 } 809809 810810 if (empty($meta_title)) { 811811 $meta_title = $title; 812812 } 813813 814814 return esc_html($meta_title); 815815 } 816816 817817 require_once(WPMETASEO_PLUGIN_DIR . 'inc/class.metaseo-front_end.php'); 818818 $GLOBALS['metaseo_front'] = new MetaSeoFront; 819819 820820 /* * ******************************************** */ 821821} 822822 823823/** 824824 * Set a option 825825 * 826826 * @param string $option_name Option name 827827 * @param string|array|object $value Value of option 828828 * 829829 * @return void 830830 */ 831831function wpmsSetOption($option_name, $value) 832832{ 833833 $settings = get_option('_metaseo_settings'); 834834 if (empty($settings)) { 835835 $settings = array(); 836836 $settings[$option_name] = $value; 837837 } else { 838838 $settings[$option_name] = $value; 839839 } 840840 841841 update_option('_metaseo_settings', $settings); 842842} 843843 844844/** 845845 * Get a option 846846 * 847847 * @param string $option_name Option name 848848 * 849849 * @return mixed 850850 */ 851851function wpmsGetOption($option_name) 852852{ 853853 $default_settings = wpmsGetDefaultSettings(); 854854 $settings = get_option('_metaseo_settings'); 855855 if (isset($settings) && isset($settings[$option_name])) { 856856 return $settings[$option_name]; 857857 } 858858 859859 return $default_settings[$option_name]; 860860} 861861 862862/* * ****** Check and import meta data from other installed plugins for SEO ******* */ 863863 864864/** 865865 * Handle import of meta data from other installed plugins for SEO 866866 * 867867 * @return void 868868 */ 869869function wpmsYoastMessage() 870870{ 871871 $activated = 0; 872872 // Check if All In One Pack is active 873873 if (!get_option('_aio_import_notice_flag')) { 874874 if (is_plugin_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) { 875875 add_action('admin_notices', 'wpmsImportMetaNotice', 2); 876876 $activated ++; 877877 } 878878 879879 if (get_option('_aio_import_notice_flag') === false) { 880880 update_option('_aio_import_notice_flag', 0); 881881 } 882882 } 883883 // Check if Yoast is active 884884 if (!get_option('_yoast_import_notice_flag', false)) { 885885 if (is_plugin_active('wordpress-seo/wp-seo.php') 886886 || is_plugin_active('Yoast-SEO-Premium/wp-seo-premium.php') || class_exists('WPSEO_Premium')) { 887887 add_action('admin_notices', 'wpmsImportYoastMetaNotice', 3); 888888 $activated ++; 889889 } 890890 891891 if (get_option('_yoast_import_notice_flag') === false) { 892892 update_option('_yoast_import_notice_flag', 0); 893893 } 894894 } 895895 896896 if ($activated === 2 && !get_option('plugin_to_sync_with', false)) { 897897 add_action('admin_notices', 'wpmsNoticeSameFeature', 1); 898898 } 899899} 900900 901901/** 902902 * Show notice 903903 * 904904 * @return void 905905 */ 906906function wpmsNoticeSameFeature() 907907{ 908908 echo '<div class="error metaseo-import-wrn"><p>' . esc_html__('Be careful you installed 2 extensions doing almost the same thing, please deactivate AIOSEO or Yoast in order to work more clearly!', 'wp-meta-seo') . '</p></div>'; 909909} 910910 911911add_action('admin_init', 'wpmsYoastMessage'); 912912 913913/** 914914 * Notice import meta 915915 * 916916 * @return void 917917 */ 918918function wpmsImportMetaNotice() 919919{ 920920 echo '<div class="error metaseo-import-wrn"><p>' . sprintf(esc_html__('We have found that you're using 921921 All In One Pack Plugin, WP Meta SEO can import the meta 922922 from this plugin, %s', 'wp-meta-seo'), '<a href="#" class="button mseo-import-action" 923923 style="position:relative" onclick="importMetaData(this, event)" id="_aio_"> 924924 <span class="spinner-light"></span>Import now</a> or 925925 <a href="#" class="dissmiss-import">dismiss this</a>') . '</p></div>'; 926926} 927927 928928/** 929929 * Notice import Yoast meta 930930 * 931931 * @return void 932932 */ 933933function wpmsImportYoastMetaNotice() 934934{ 935935 echo '<div class="error metaseo-import-wrn"><p>' . sprintf(esc_html__('We have found that you're using Yoast SEO Plugin, 936936 WP Meta SEO can import the meta from this plugin, %s', 'wp-meta-seo'), '<a href="#" 937937 class="button mseo-import-action" style="position:relative" 938938 onclick="importMetaData(this, event)" id="_yoast_">Import now<span class="spinner-light"></span></a> 939939 or <a href="#" class="dissmiss-import">dismiss this</a>') . '</p></div>'; 940940} 941941 942942/** 943943 * Encode or decode all values in string format of an array 944944 * 945945 * @param array $obj List string 946946 * @param string $action Action 947947 * 948948 * @return mixed 949949 */ 950950function wpmsUtf8($obj, $action = 'encode') 951951{ 952952 $action = strtolower(trim($action)); 953953 $fn = 'utf8_' . $action; 954954 if (is_array($obj)) { 955955 foreach ($obj as &$el) { 956956 if (is_array($el)) { 957957 if (is_callable($fn)) { 958958 $el = wpmsUtf8($el, $action); 959959 } 960960 } elseif (is_string($el)) { 961961 $isASCII = mb_detect_encoding($el, 'ASCII'); 962962 if ($action === 'encode' && !$isASCII) { 963963 $el = mb_convert_encoding($el, 'UTF-8', 'auto'); 964964 } 965965 966966 $el = $fn($el); 967967 } 968968 } 969969 } elseif (is_object($obj)) { 970970 $vars = array_keys(get_object_vars($obj)); 971971 foreach ($vars as $var) { 972972 wpmsUtf8($obj->$var, $action); 973973 } 974974 } 975975 976976 return $obj; 977977} 978978 979979/** 980980 * Cmb render text link 981981 * 982982 * @param array $field Field 983983 * @param string $meta Meta value 984984 * 985985 * @return void 986986 */ 987987function textLink($field, $meta) 988988{ 989989 echo '<input class="cmb_text_link" type="text" size="45" id="', esc_html($field['id']), '" 990990 name="', esc_html($field['id']), '" value="', esc_html($meta), '" />'; 991991 echo '<input class="cmb_link_button button" type="button" 992992 value="Voeg link toe" />', '<p class="cmb_metabox_description">', esc_html($field['desc']), '</p>'; 993993} 994994 995995add_action('cmb_render_text_link', 'textLink', 10, 2); 996996add_action('template_redirect', 'wpmsTemplateRedirect'); 997997 998998/** 999999 * Redirect 404 url and insert url to database 10001000 * 10011001 * @return void 10021002 */ 10031003function wpmsTemplateRedirect() 10041004{ 10051005 global $wpdb; 10061006 // redirect by rule 10071007 $url = ''; 10081008 if (isset($_SERVER['REQUEST_URI'])) { 10091009 $url = $_SERVER['REQUEST_URI']; 10101010 } 10111011 10121012 if (!is_home() && !is_front_page()) { 10131013 $redirects = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE (link_url = %s AND link_url != "/") OR type = "add_rule" OR type = "add_custom"', array( 10141014 $url 10151015 ))); 10161016 $target = ''; 10171017 $status_redirect = 302; 10181018 foreach ($redirects as $link) { 10191019 // If redirect success, not redirect again 10201020 $parse_url = parse_url($link->link_url_redirect); 10211021 if (isset($parse_url['path'])) { 10221022 if (rtrim($parse_url['path'], '/') === rtrim($url, '/')) { 10231023 break; 10241024 } 10251025 } 10261026 // Fix with xlink 10271027 $query_str = parse_url($url, PHP_URL_QUERY); 10281028 if (!empty($query_str) && strpos($query_str, 'xlink') !== false) { 10291029 break; 10301030 } 10311031 10321032 $link->link_url = str_replace(' ', '%20', $link->link_url); 10331033 $matches = false; 10341034 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- remove warning if match the URL 10351035 if ((($link->link_url === $url || $link->link_url === rtrim($url, '/') || $link->link_url === urldecode($url))) || (@preg_match('@' . str_replace('@', '\\@', $link->link_url) . '@', $url, $matches) > 0) || (@preg_match('@' . str_replace('@', '\\@', $link->link_url) . '@', urldecode($url), $matches) > 0)) { 10361036 $target = $link->link_url_redirect; 10371037 if ($link->type === 'add_custom') { 10381038 if (!is_plugin_active(WPMSEO_ADDON_FILENAME)) { 10391039 return; 10401040 } 10411041 $status_redirect = $link->meta_title; 10421042 } 10431043 10441044 break; 10451045 } 10461046 } 10471047 10481048 if ($target) { 10491049 if (empty($status_redirect) && !in_array($status_redirect, array(301, 302, 307))) { 10501050 $status_redirect = 302; 10511051 } 10521052 wp_redirect($target, $status_redirect); 10531053 exit(); 10541054 } else { 10551055 if (is_404()) { 10561056 if (isset($_SERVER['REQUEST_URI'])) { 10571057 $path_infos = pathinfo($_SERVER['REQUEST_URI']); 10581058 if (isset($path_infos['extension'])) { 10591059 return; 10601060 } 10611061 10621062 $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 10631063 if (isset($_SERVER['HTTPS']) && 10641064 ($_SERVER['HTTPS'] === 'on' || (int) $_SERVER['HTTPS'] === 1) || 10651065 isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 10661066 $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { 10671067 $protocol = 'https://'; 10681068 } else { 10691069 $protocol = 'http://'; 10701070 } 10711071 $esc_url = str_replace(array('http://', 'https://'), $protocol, esc_url($url)); 10721072 $check = $wpdb->get_results($wpdb->prepare( 10731073 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE (link_url=%s OR link_url=%s OR link_url=%s)', 10741074 array( 10751075 $url, 10761076 $esc_url, 10771077 $_SERVER['REQUEST_URI'] 10781078 ) 10791079 )); 10801080 10811081 // get referer url 10821082 if (wp_get_raw_referer()) { 10831083 $referer_url = wp_get_raw_referer(); 10841084 } else { 10851085 $referer_url = get_home_url(); 10861086 } 10871087 10881088 if ($referer_url === '') { 10891089 $referer_url = get_home_url(); 10901090 } 10911091 if (count($check) === 0) { 10921092 if (!function_exists('wp_validate_redirect')) { 10931093 require_once(ABSPATH . 'wp-includes/pluggable.php'); 10941094 } 10951095 10961096 // insert url 10971097 $insert = array( 10981098 'link_url' => ($url), 10991099 'status_code' => '404 Not Found', 11001100 'status_text' => '404 Not Found', 11011101 'type' => '404_automaticaly', 11021102 'broken_indexed' => 1, 11031103 'broken_internal' => 0, 11041104 'warning' => 0, 11051105 'dismissed' => 0, 11061106 'referrer' => $referer_url 11071107 ); 11081108 11091109 $wpdb->insert($wpdb->prefix . 'wpms_links', $insert); 11101110 } else { 11111111 // update url 11121112 $links_broken = $wpdb->get_row($wpdb->prepare( 11131113 'SELECT * FROM ' . $wpdb->prefix . 'wpms_links WHERE (link_url=%s OR link_url=%s OR link_url=%s) ', 11141114 array( 11151115 $url, 11161116 $esc_url, 11171117 $_SERVER['REQUEST_URI'] 11181118 ) 11191119 )); 11201120 11211121 if (!empty($links_broken)) { 11221122 $list_referrers = explode('||', $links_broken->referrer); 11231123 if (!in_array($referer_url, $list_referrers)) { 11241124 $list_referrers[] = $referer_url; 11251125 } 11261126 11271127 $referrers = implode('||', $list_referrers); 11281128 $referrers = trim($referrers, '||'); 11291129 $value = array( 11301130 'hit' => (int) $links_broken->hit + 1, 11311131 'referrer' => $referrers 11321132 ); 11331133 11341134 $wpdb->update( 11351135 $wpdb->prefix . 'wpms_links', 11361136 $value, 11371137 array('id' => $links_broken->id), 11381138 array('%d', '%s'), 11391139 array('%d') 11401140 ); 11411141 11421142 if (($url === $links_broken->link_url || esc_url($url) === $links_broken->link_url) 11431143 && $links_broken->link_url_redirect !== '') { 11441144 if (!empty($links_broken->meta_title)) { 11451145 $status_redirect = $links_broken->meta_title; 11461146 } else { 11471147 $status_redirect = 302; 11481148 } 11491149 11501150 if (empty($status_redirect) && !in_array($status_redirect, array(301, 302, 307))) { 11511151 $status_redirect = 302; 11521152 } 11531153 11541154 wp_redirect($links_broken->link_url_redirect, $status_redirect); 11551155 exit(); 11561156 } 11571157 } 11581158 } 11591159 } 11601160 11611161 $defaul_settings_404 = array( 11621162 'wpms_redirect_homepage' => 0, 11631163 'wpms_type_404' => 'none', 11641164 'wpms_page_redirected' => 'none' 11651165 ); 11661166 $wpms_settings_404 = get_option('wpms_settings_404'); 11671167 11681168 if (is_array($wpms_settings_404)) { 11691169 $defaul_settings_404 = array_merge($defaul_settings_404, $wpms_settings_404); 11701170 } 11711171 11721172 // redirect url by settings 11731173 if (isset($defaul_settings_404['wpms_redirect_homepage']) 11741174 && (int) $defaul_settings_404['wpms_redirect_homepage'] === 1) { 11751175 wp_redirect(get_home_url()); 11761176 exit(); 11771177 } else { 11781178 if (isset($defaul_settings_404['wpms_type_404'])) { 11791179 switch ($defaul_settings_404['wpms_type_404']) { 11801180 case 'wp-meta-seo-page': 11811181 global $wpdb; 11821182 $wpms_page = $wpdb->get_row($wpdb->prepare( 11831183 'SELECT * FROM ' . $wpdb->prefix . 'posts WHERE post_title = %s AND post_excerpt = %s', 11841184 array( 11851185 '404 Error, content does not exist anymore', 11861186 'metaseo_404_page' 11871187 ) 11881188 )); 11891189 if (!empty($wpms_page)) { 11901190 $link_redirect = get_permalink($wpms_page->ID); 11911191 if ($link_redirect) { 11921192 wp_redirect($link_redirect); 11931193 exit(); 11941194 } 11951195 } 11961196 break; 11971197 11981198 case 'custom_page': 11991199 if (isset($defaul_settings_404['wpms_page_redirected']) 12001200 && $defaul_settings_404['wpms_page_redirected'] !== 'none') { 12011201 $link_redirect = get_permalink($defaul_settings_404['wpms_page_redirected']); 12021202 if ($link_redirect) { 12031203 wp_redirect($link_redirect); 12041204 exit(); 12051205 } 12061206 } 12071207 break; 12081208 } 12091209 } 12101210 } 12111211 } 12121212 } 12131213 } 12141214} 12151215 12161216add_action( 12171217 'after_setup_theme', 12181218 function () { 12191219 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No action, no need verification 12201220 if (defined('ET_CORE') && !empty($_GET['et_fb'])) { 12211221 require_once(WPMETASEO_PLUGIN_DIR . 'inc/divi-seo/divi.php'); 12221222 new Divi; 12231223 } 12241224 }, 12251225 11 12261226); Note: See TracChangeset for help on using the changeset viewer. Trac UI Preferences DOWNLOAD IN OTHER FORMATS: * Unified Diff * Zip Archive * About * Blog * Hosting * Donate * Support * Developers * Get Involved * Learn * Showcase * Plugins * Themes * Ideas * WordCamp * WordPress.TV * BuddyPress * bbPress * WordPress.com * Matt * Privacy * License / GPLv2 Code is Poetry