Changeset 3820184
- Timestamp:
- 11/24/2026 10:18:16 AM (2 days ago)
- Location:
- wp-product-feed-manager/trunk
- Files:
-
- 6 added
- 22 edited
-
includes/application/class-feed-master.php (modified) (2 diffs)
-
includes/application/class-wppfm-feed-processor.php (modified) (1 diff)
-
includes/application/google/class-feed.php (modified) (1 diff)
-
includes/application/js/wppfm_logic.js (modified) (3 diffs)
-
includes/application/js/wppfm_logic.min.js (modified) (1 diff)
-
includes/application/wppfm-feed-processing-support.php (modified) (4 diffs)
-
includes/application/wppfm-xml-text-functions.php (added)
-
includes/class-wppfm-register-scripts.php (modified) (1 diff)
-
includes/data/class-wppfm-ajax-data.php (modified) (1 diff)
-
includes/data/class-wppfm-db-management.php (modified) (1 diff)
-
includes/data/js/wppfm_ajaxdatahandling.js (modified) (1 diff)
-
includes/data/js/wppfm_ajaxdatahandling.min.js (modified) (1 diff)
-
includes/setup/class-wppfm-folders.php (modified) (1 diff)
-
includes/user-interface/class-wppfm-list-table.php (modified) (4 diffs)
-
includes/user-interface/class-wppfm-settings-page.php (modified) (1 diff)
-
includes/user-interface/css (added)
-
includes/user-interface/css/wppfm-product-exclude-from-feed-admin.css (added)
-
includes/user-interface/js/wppfm-product-exclude-from-feed.js (added)
-
includes/user-interface/js/wppfm-product-exclude-from-feed.min.js (added)
-
includes/user-interface/js/wppfm_feed-list.js (modified) (5 diffs)
-
includes/user-interface/js/wppfm_feed-list.min.js (modified) (1 diff)
-
includes/user-interface/js/wppfm_setting-form.js (modified) (1 diff)
-
includes/user-interface/js/wppfm_setting-form.min.js (modified) (1 diff)
-
includes/user-interface/wppfm-backup-export-actions.php (added)
-
includes/user-interface/wppfm-product-identifiers.php (modified) (2 diffs)
-
includes/user-interface/wppfm-woocommerce-actions.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
-
wp-product-feed-manager.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-product-feed-manager/trunk/includes/application/class-feed-master.php
r3745889 r3820184 566 566 private function get_feed_start_line() { 567 567 $header_string = ''; 568 $feed_id = property_exists( $this->_feed, 'feedId' ) ? $this->_feed->feedId : null; 569 570 if ( null !== $feed_id && '' !== $feed_id ) { 571 $this->wppfm_set_xml_sanitize_context( $feed_id, null ); 572 } 568 573 569 574 if ( $this->_feed->channel ) { … … 585 590 $header_string = $this->_channel_class->header( $string ); 586 591 } 592 } 593 594 if ( null !== $feed_id && '' !== $feed_id ) { 595 $this->wppfm_clear_xml_sanitize_context(); 587 596 } 588 597 -
wp-product-feed-manager/trunk/includes/application/class-wppfm-feed-processor.php
r3745889 r3820184 494 494 */ 495 495 private function write_product_object( $product_placeholder, $feed_id, $product_id ) { 496 496 $this->wppfm_set_xml_sanitize_context( $feed_id, $product_id ); 497 497 $product_text = $this->generate_feed_text( $product_placeholder ); 498 $this->wppfm_clear_xml_sanitize_context(); 498 499 499 500 // Buffer the output instead of writing immediately -
wp-product-feed-manager/trunk/includes/application/google/class-feed.php
r3745889 r3820184 267 267 protected function header( $title, $description = '' ) { 268 268 // the check for convert_to_data_string function can be removed when all users have switched to plugin version 1.6 or higher 269 $title_string = $this->convert_to_character_data_string( $title );270 $home_link = $this->convert_to_character_data_string( get_option( 'home' ) );269 $title_string = $this->convert_to_character_data_string( $title, 'channel title' ); 270 $home_link = $this->convert_to_character_data_string( get_option( 'home' ), 'link' ); 271 271 $header_description = '' !== $description ? $description : "This product feed is created with the WP Product Feed Manager plugin. For more information visit https://www.wpmarketingrobot.com"; 272 $description_string = $this->convert_to_character_data_string( $header_description );272 $description_string = $this->convert_to_character_data_string( $header_description, 'channel description' ); 273 273 $title_tag = '<wf-connection-string>'; 274 274 -
wp-product-feed-manager/trunk/includes/application/js/wppfm_logic.js
r3484732 r3820184 237 237 function( result ) { 238 238 if ( result ) { 239 wppfm_showSuccessMessage( wppfm_feed_list_form_vars.added_feed_copy.replace( '%feedname%', feedName ) ); 239 // The message is inserted as html, so the stored feed name must be escaped. 240 wppfm_showSuccessMessage( wppfm_feed_list_form_vars.added_feed_copy.replace( '%feedname%', wppfm_escapeHtml( feedName ) ) ); 240 241 wppfm_hideWorkingSpinner(); 241 242 } … … 294 295 * @since 2.39.0 Fixed an issue where the "View feed" functions would not work if the user has the "Relative URL" plugin active. 295 296 * @since 3.16.0 Improved URL validation to be more robust and language-independent 297 * @since 3.25.0 Only opens http(s) URLs, so a javascript: or data: URL ending in a feed file name is rejected. 296 298 */ 297 299 function wppfm_viewFeed(url) { 298 300 // Check if URL is provided and appears to be a valid feed URL (xml, csv, txt, or tsv) 299 if (url && /\/wppfm-feeds\/.*\.(xml|csv|txt|tsv)$/.test(url) ) {301 if (url && /\/wppfm-feeds\/.*\.(xml|csv|txt|tsv)$/.test(url) && wppfm_isHttpUrl(url)) { 300 302 window.open(url); 301 303 } else { … … 306 308 // Deselect the view feed button 307 309 wppfm_enableViewFeedButtons(); 310 } 311 312 /** 313 * Checks if a URL uses the http or https protocol. 314 * 315 * Relative URLs are resolved against the current page, so they stay valid when the "Relative URL" plugin is active. 316 * 317 * @param {string} url The URL to check. 318 * @returns {boolean} True if the resolved URL is an http(s) URL. 319 */ 320 function wppfm_isHttpUrl(url) { 321 try { 322 var protocol = new URL(url, window.location.href).protocol; 323 return 'http:' === protocol || 'https:' === protocol; 324 } catch (e) { 325 return false; 326 } 308 327 } 309 328 -
wp-product-feed-manager/trunk/includes/application/js/wppfm_logic.min.js
r3484732 r3820184 1 var _feedHolder;function wppfm_editCategories(){var e=jQuery("#category-selector-lvl");if(wppfm_isCustomChannel(_feedHolder.channel))e.html(wppfm_freeCategoryInputCntrl("default",_feedHolder.feedId,_feedHolder.mainCategory)),e.prop("disabled",!1);else{var t=_feedHolder.mainCategory.split(" > "),r=t.length,n=""!==jQuery("#lvl_"+r).html()?r+1:r;jQuery("#selected-categories").hide(),jQuery("#lvl_0").prop("disabled",!1);for(var a=0;a<n;a++){var p=jQuery("#lvl_"+a);t[a]||p.val("0"),p.show()}}}function wppfm_generateFeed(){""!==jQuery("#wppfm-feed-file-name").val()?(_feedHolder.categoryMapping&&_feedHolder.categoryMapping.length>0||!0===confirm(wppfm_feed_settings_form_vars.no_category_selected))&&(wppfm_disableFeedActionButtons(),wppfm_generateAndSaveFeed()):(jQuery("#alert-message").html("<p>"+wppfm_feed_settings_form_vars.file_name_required+"</p>"),jQuery("#wppfm-success-message").show())}function wppfm_saveFeedData(){""!==jQuery("#wppfm-feed-file-name").val()?wppfm_saveFeed():(jQuery("#alert-message").html("<p>"+wppfm_feed_settings_form_vars.file_name_required+"</p>"),jQuery("#wppfm-success-message").show())}function getCombinedValue(e,t){for(var r=1,n="",a=_feedHolder.getCombinedOutputValue(e,t);jQuery("#combined-input-field-cntrl-"+e+"-"+t+"-"+r).val();){var p=e+"-"+t+"-"+r,i=jQuery("#combined-input-field-cntrl-"+p).val();if(n+=r>1?jQuery("#combined-separator-cntrl-"+p).val()+"#":"","static"!==i)n+="select"!==i?i+"|":"";else{if(!jQuery("#static-input-field-"+p).val()){n=a+"|";break}n+=i+"#"+jQuery("#static-input-field-"+p).val()+"|"}r++}return n=n.substring(0,n.length-1),r>1&&n}function wppfm_staticValueChanged(e,t,r){r>0?wppfm_changedCombinedOutput(e,t,r):(wppfm_setStaticValue(e,t,r),34===e&&wppfm_setIdentifierExistsDependencies())}function wppfm_changedOutputSelection(e){var t=jQuery("#output-field-cntrl-"+e);"no-value"!==t.val()&&wppfm_activateOptionalFieldRow(e,t.val())}function wppfm_hasExtraSourceRow(e,t){return!(!t||!t[e-1])&&t[e-1].hasOwnProperty("c")}function wppfm_changedCustomOutputTitle(){var e=jQuery("#custom-output-title-input").val();e&&wppfm_activateCustomFieldRow(e)}function wppfm_deleteSpecificFeed(e,t){!0===confirm(wppfm_feed_list_form_vars.confirm_delete_feed.replace("%feedname%",t))&&wppfm_deleteFeed(e,t)}function wppfm_valueOptionChanged(e,t,r){var n=wppfm_getCorrectValueSelector(e,t,0,jQuery("#value-options-"+e+"-"+t+"-"+r).val(),"","");jQuery("#value-editor-input-span-"+e+"-"+t+"-"+r).html(n)}function wppfm_getCorrectValueSelector(e,t,r,n,a,p){var i;switch(n){case"0":case"change nothing":case"8":case"strip tags":case"9":case"html entity decode":case"11":case"html entity encode":wppfm_valueInputOptionsChanged(e,t,r),i="";break;case"1":case"overwrite":case"10":case"limit characters":default:i=wppfm_valueOptionsSingleInput(e,t,r,a);break;case"2":case"replace":i=wppfm_valueOptionsReplaceInput(e,t,r,a,p);break;case"3":case"remove":case"4":case"add prefix":case"5":case"add suffix":i=wppfm_valueOptionsSingleInputValue(e,t,r,a);break;case"6":case"recalculate":i=wppfm_valueOptionsRecalculate(e,t,r,a,p);break;case"7":case"convert to child-element":i=wppfm_valueOptionsElementInput(e,t,r,a)}return i}function wppfm_deactivateFeed(e){wppfm_switchFeedStatus(e,function(t){wppfm_updateFeedRowStatus(e,parseInt(t))})}function wppfm_duplicateFeed(e,t){wppfm_showWorkingSpinner(),wppfm_duplicateExistingFeed(e,function(e){e&&(wppfm_showSuccessMessage(wppfm_feed_list_form_vars.added_feed_copy.replace("%feedname%",t)),wppfm_hideWorkingSpinner())})}function wppfm_regenerateFeed(e){var t=wppfmQueueStringIsEmpty()?3:4;wppfmAddToQueueString(e),wppfm_showWorkingSpinner(),wppfm_updateFeedRowStatus(e,t),wppfm_updateFeedFile(e,function(t){if(wppfm_hideWorkingSpinner(),t.includes("channel_not_installed")){var r=t.split(":")[1];return alert(wppfm_feed_list_form_vars.missing_channel.replaceAll("%channelname%",r)),wppfm_updateFeedRowStatus(e,7),void wppfmRemoveFromQueueString(e)}var n=setInterval(function(){wppfm_getCurrentFeedStatus(e,function(t){var r=JSON.parse(t);"3"!==r.status_id&&"4"!==r.status_id&&(wppfm_resetFeedStatus(r),wppfm_resetFeedList(),clearInterval(n),wppfmRemoveFromQueueString(e))})},1e4)})}function wppfm_viewFeed(e){e&&/\/wppfm-feeds\/.*\.(xml|csv|txt|tsv)$/.test(e)?window.open(e):alert(wppfm_feed_list_form_vars.feed_not_generated),wppfm_enableViewFeedButtons()}function wppfm_addRowValueEditor(e,t,r,n){jQuery("#row-"+e).append(wppfm_valueEditor(e,t,r,n)),jQuery("#value-editor-input-query-add-span-"+e+"-"+t+"-"+r).remove()}function wppfm_convertToCamelCase(e){for(var t=e[0].toLowerCase(),r=1;r<e.length;r++)t+=e[r].charAt(0).toUpperCase()+e[r].slice(1);return t}function wppfm_addValueEditorQuery(e,t,r){wppfm_changeValueIsFilled(e,t,r)?wppfm_queryIsFilled(e,t-1,1)?wppfm_showEditValueQuery(e,t,r,!0):alert(wppfm_feed_settings_form_vars.query_requirements):alert(wppfm_feed_settings_form_vars.first_fill_in_change_value)}function wppfm_queryStringToQueryObject(e){var t={};if(e)for(var r in e)t=wppfm_convertQueryStringToQueryObject(e[r]);return t}function wppfm_valueStringToValueObject(e){var t={};if(e)for(var r in e)"q"!==r&&(t=wppfm_convertValueStringToValueObject(e[r]));return t}function wppfm_convertQueryStringToQueryObject(e){var t={},r=e.split("#");return"1"===r[0]||"2"===r[0]?t.preCondition=r[0]:t.preCondition="0",t.source=r[1],t.condition=r[2],t.value=r[3]?r[3]:"",t.endValue=r[5]?r[5]:"",t}function wppfm_resortObject(e){var t=[],r=1;for(var n in e){var a={};for(var p in e[n])"q"!==p?(a[r]=e[n][p],t.push(a)):t[r-1].q=e[n][p];r++}return r>1?t:""}function wppfm_convertValueStringToValueObject(e){var t={},r=e.split("#");return t.preCondition=r[0],t.condition=r[1],t.value=r[2],t.endValue=r[3]?r[3]:"",t}function wppfm_makeCleanQueryObject(){return{preCondition:"if",source:"select",condition:"",value:"",endValue:""}}function wppfm_makeCleanValueObject(){return{preCondition:"change",condition:"overwrite",value:"",endValue:""}}function wppfm_addNewItemToCategoryString(e,t,r,n){var a=t.split(n).length;if(t===wppfm_feed_settings_form_vars.map_to_default_category||"0"===e)return r;if(a<=e)return t+n+r;for(var p=0,i=0;i<e;i++){p=t.indexOf(n,p+1);var o=t.substring(0,p)}return o+n+r}function wppfm_snakeToCamel(e){return e.split("_").map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("")}1 var _feedHolder;function wppfm_editCategories(){var e=jQuery("#category-selector-lvl");if(wppfm_isCustomChannel(_feedHolder.channel))e.html(wppfm_freeCategoryInputCntrl("default",_feedHolder.feedId,_feedHolder.mainCategory)),e.prop("disabled",!1);else{var t=_feedHolder.mainCategory.split(" > "),r=t.length,n=""!==jQuery("#lvl_"+r).html()?r+1:r;jQuery("#selected-categories").hide(),jQuery("#lvl_0").prop("disabled",!1);for(var p=0;p<n;p++){var a=jQuery("#lvl_"+p);t[p]||a.val("0"),a.show()}}}function wppfm_generateFeed(){""!==jQuery("#wppfm-feed-file-name").val()?(_feedHolder.categoryMapping&&_feedHolder.categoryMapping.length>0||!0===confirm(wppfm_feed_settings_form_vars.no_category_selected))&&(wppfm_disableFeedActionButtons(),wppfm_generateAndSaveFeed()):(jQuery("#alert-message").html("<p>"+wppfm_feed_settings_form_vars.file_name_required+"</p>"),jQuery("#wppfm-success-message").show())}function wppfm_saveFeedData(){""!==jQuery("#wppfm-feed-file-name").val()?wppfm_saveFeed():(jQuery("#alert-message").html("<p>"+wppfm_feed_settings_form_vars.file_name_required+"</p>"),jQuery("#wppfm-success-message").show())}function getCombinedValue(e,t){for(var r=1,n="",p=_feedHolder.getCombinedOutputValue(e,t);jQuery("#combined-input-field-cntrl-"+e+"-"+t+"-"+r).val();){var a=e+"-"+t+"-"+r,i=jQuery("#combined-input-field-cntrl-"+a).val();if(n+=r>1?jQuery("#combined-separator-cntrl-"+a).val()+"#":"","static"!==i)n+="select"!==i?i+"|":"";else{if(!jQuery("#static-input-field-"+a).val()){n=p+"|";break}n+=i+"#"+jQuery("#static-input-field-"+a).val()+"|"}r++}return n=n.substring(0,n.length-1),r>1&&n}function wppfm_staticValueChanged(e,t,r){r>0?wppfm_changedCombinedOutput(e,t,r):(wppfm_setStaticValue(e,t,r),34===e&&wppfm_setIdentifierExistsDependencies())}function wppfm_changedOutputSelection(e){var t=jQuery("#output-field-cntrl-"+e);"no-value"!==t.val()&&wppfm_activateOptionalFieldRow(e,t.val())}function wppfm_hasExtraSourceRow(e,t){return!(!t||!t[e-1])&&t[e-1].hasOwnProperty("c")}function wppfm_changedCustomOutputTitle(){var e=jQuery("#custom-output-title-input").val();e&&wppfm_activateCustomFieldRow(e)}function wppfm_deleteSpecificFeed(e,t){!0===confirm(wppfm_feed_list_form_vars.confirm_delete_feed.replace("%feedname%",t))&&wppfm_deleteFeed(e,t)}function wppfm_valueOptionChanged(e,t,r){var n=wppfm_getCorrectValueSelector(e,t,0,jQuery("#value-options-"+e+"-"+t+"-"+r).val(),"","");jQuery("#value-editor-input-span-"+e+"-"+t+"-"+r).html(n)}function wppfm_getCorrectValueSelector(e,t,r,n,p,a){var i;switch(n){case"0":case"change nothing":case"8":case"strip tags":case"9":case"html entity decode":case"11":case"html entity encode":wppfm_valueInputOptionsChanged(e,t,r),i="";break;case"1":case"overwrite":case"10":case"limit characters":default:i=wppfm_valueOptionsSingleInput(e,t,r,p);break;case"2":case"replace":i=wppfm_valueOptionsReplaceInput(e,t,r,p,a);break;case"3":case"remove":case"4":case"add prefix":case"5":case"add suffix":i=wppfm_valueOptionsSingleInputValue(e,t,r,p);break;case"6":case"recalculate":i=wppfm_valueOptionsRecalculate(e,t,r,p,a);break;case"7":case"convert to child-element":i=wppfm_valueOptionsElementInput(e,t,r,p)}return i}function wppfm_deactivateFeed(e){wppfm_switchFeedStatus(e,function(t){wppfm_updateFeedRowStatus(e,parseInt(t))})}function wppfm_duplicateFeed(e,t){wppfm_showWorkingSpinner(),wppfm_duplicateExistingFeed(e,function(e){e&&(wppfm_showSuccessMessage(wppfm_feed_list_form_vars.added_feed_copy.replace("%feedname%",wppfm_escapeHtml(t))),wppfm_hideWorkingSpinner())})}function wppfm_regenerateFeed(e){var t=wppfmQueueStringIsEmpty()?3:4;wppfmAddToQueueString(e),wppfm_showWorkingSpinner(),wppfm_updateFeedRowStatus(e,t),wppfm_updateFeedFile(e,function(t){if(wppfm_hideWorkingSpinner(),t.includes("channel_not_installed")){var r=t.split(":")[1];return alert(wppfm_feed_list_form_vars.missing_channel.replaceAll("%channelname%",r)),wppfm_updateFeedRowStatus(e,7),void wppfmRemoveFromQueueString(e)}var n=setInterval(function(){wppfm_getCurrentFeedStatus(e,function(t){var r=JSON.parse(t);"3"!==r.status_id&&"4"!==r.status_id&&(wppfm_resetFeedStatus(r),wppfm_resetFeedList(),clearInterval(n),wppfmRemoveFromQueueString(e))})},1e4)})}function wppfm_viewFeed(e){e&&/\/wppfm-feeds\/.*\.(xml|csv|txt|tsv)$/.test(e)&&wppfm_isHttpUrl(e)?window.open(e):alert(wppfm_feed_list_form_vars.feed_not_generated),wppfm_enableViewFeedButtons()}function wppfm_isHttpUrl(e){try{var t=new URL(e,window.location.href).protocol;return"http:"===t||"https:"===t}catch(e){return!1}}function wppfm_addRowValueEditor(e,t,r,n){jQuery("#row-"+e).append(wppfm_valueEditor(e,t,r,n)),jQuery("#value-editor-input-query-add-span-"+e+"-"+t+"-"+r).remove()}function wppfm_convertToCamelCase(e){for(var t=e[0].toLowerCase(),r=1;r<e.length;r++)t+=e[r].charAt(0).toUpperCase()+e[r].slice(1);return t}function wppfm_addValueEditorQuery(e,t,r){wppfm_changeValueIsFilled(e,t,r)?wppfm_queryIsFilled(e,t-1,1)?wppfm_showEditValueQuery(e,t,r,!0):alert(wppfm_feed_settings_form_vars.query_requirements):alert(wppfm_feed_settings_form_vars.first_fill_in_change_value)}function wppfm_queryStringToQueryObject(e){var t={};if(e)for(var r in e)t=wppfm_convertQueryStringToQueryObject(e[r]);return t}function wppfm_valueStringToValueObject(e){var t={};if(e)for(var r in e)"q"!==r&&(t=wppfm_convertValueStringToValueObject(e[r]));return t}function wppfm_convertQueryStringToQueryObject(e){var t={},r=e.split("#");return"1"===r[0]||"2"===r[0]?t.preCondition=r[0]:t.preCondition="0",t.source=r[1],t.condition=r[2],t.value=r[3]?r[3]:"",t.endValue=r[5]?r[5]:"",t}function wppfm_resortObject(e){var t=[],r=1;for(var n in e){var p={};for(var a in e[n])"q"!==a?(p[r]=e[n][a],t.push(p)):t[r-1].q=e[n][a];r++}return r>1?t:""}function wppfm_convertValueStringToValueObject(e){var t={},r=e.split("#");return t.preCondition=r[0],t.condition=r[1],t.value=r[2],t.endValue=r[3]?r[3]:"",t}function wppfm_makeCleanQueryObject(){return{preCondition:"if",source:"select",condition:"",value:"",endValue:""}}function wppfm_makeCleanValueObject(){return{preCondition:"change",condition:"overwrite",value:"",endValue:""}}function wppfm_addNewItemToCategoryString(e,t,r,n){var p=t.split(n).length;if(t===wppfm_feed_settings_form_vars.map_to_default_category||"0"===e)return r;if(p<=e)return t+n+r;for(var a=0,i=0;i<e;i++){a=t.indexOf(n,a+1);var o=t.substring(0,a)}return o+n+r}function wppfm_snakeToCamel(e){return e.split("_").map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("")} -
wp-product-feed-manager/trunk/includes/application/wppfm-feed-processing-support.php
r3745889 r3820184 35 35 private $_wppfm_performance_enabled_cache_feed_id = null; 36 36 37 37 /** 38 * Context for XML text sanitization warnings (feed, product, field). 39 * 40 * @since 3.25.0 41 * @var array{feed_id: string|int|null, product_id: string|int|null} 42 */ 43 private $_wppfm_xml_sanitize_context = array( 44 'feed_id' => null, 45 'product_id' => null, 46 ); 38 47 39 48 /** … … 1158 1167 if ( ! is_array( $xml_value ) && ! in_array( $key, $tags_with_sub_tags, true ) ) { 1159 1168 if ( in_array( $key, $cdata_keys, true ) ) { 1160 $xml_value = $this->convert_to_character_data_string( $xml_value ); // Put in a ![CDATA[...]] bracket.1169 $xml_value = $this->convert_to_character_data_string( $xml_value, $key ); // Put in a ![CDATA[...]] bracket. 1161 1170 } else { 1162 $xml_value = $this->convert_to_xml_value( $xml_value );1171 $xml_value = $this->convert_to_xml_value( $xml_value, $key ); 1163 1172 } 1164 1173 } … … 1207 1216 1208 1217 /** 1218 * Sets context used when logging XML-invalid character removals. 1219 * 1220 * @param string|int|null $feed_id Active feed ID. 1221 * @param string|int|null $product_id Active product ID, or null for channel/header fields. 1222 * 1223 * @return void 1224 */ 1225 protected function wppfm_set_xml_sanitize_context( $feed_id, $product_id = null ) { 1226 $this->_wppfm_xml_sanitize_context = array( 1227 'feed_id' => $feed_id, 1228 'product_id' => $product_id, 1229 ); 1230 } 1231 1232 /** 1233 * Clears the XML sanitization logging context. 1234 * 1235 * @return void 1236 */ 1237 protected function wppfm_clear_xml_sanitize_context() { 1238 $this->_wppfm_xml_sanitize_context = array( 1239 'feed_id' => null, 1240 'product_id' => null, 1241 ); 1242 } 1243 1244 /** 1245 * Logs a feed-process WARNING when XML 1.0–illegal characters were stripped from field text. 1246 * 1247 * @param array $report Output from wppfm_sanitize_xml_10_text_with_report(). 1248 * @param string $field_key Feed attribute / XML field name. 1249 * 1250 * @return void 1251 */ 1252 private function wppfm_maybe_log_xml_text_sanitization( $report, $field_key = '' ) { 1253 if ( empty( $report['changed'] ) || empty( $report['removed_count'] ) ) { 1254 return; 1255 } 1256 1257 if ( ! function_exists( 'wppfm_process_logger_is_active' ) || ! wppfm_process_logger_is_active() ) { 1258 return; 1259 } 1260 1261 $feed_id = $this->_wppfm_xml_sanitize_context['feed_id'] ?? null; 1262 if ( null === $feed_id || '' === $feed_id ) { 1263 if ( class_exists( 'WPPFM_Feed_Process_Logging' ) ) { 1264 $feed_id = WPPFM_Feed_Process_Logging::resolve_log_feed_id( '' ); 1265 } 1266 } 1267 1268 if ( null === $feed_id || '' === $feed_id ) { 1269 return; 1270 } 1271 1272 $codepoints = ! empty( $report['removed_codepoints'] ) ? implode( ', ', $report['removed_codepoints'] ) : 'unknown'; 1273 $count = (int) $report['removed_count']; 1274 $field = '' !== $field_key ? $field_key : 'feed field'; 1275 1276 $product_id = $this->_wppfm_xml_sanitize_context['product_id'] ?? null; 1277 if ( null !== $product_id && '' !== $product_id ) { 1278 $message = sprintf( 1279 'Removed %1$d XML-invalid character%2$s (%3$s) from feed field "%4$s" while processing product %5$s.', 1280 $count, 1281 1 === $count ? '' : 's', 1282 $codepoints, 1283 $field, 1284 $product_id 1285 ); 1286 } else { 1287 $message = sprintf( 1288 'Removed %1$d XML-invalid character%2$s (%3$s) from feed field "%4$s" while building the feed.', 1289 $count, 1290 1 === $count ? '' : 's', 1291 $codepoints, 1292 $field 1293 ); 1294 } 1295 1296 do_action( 'wppfm_feed_generation_message', $feed_id, $message, 'WARNING' ); 1297 } 1298 1299 /** 1209 1300 * Converts an ordinary XML string into a CDATA string as long as it's not only a numeric value. 1210 1301 * 1211 * @param string $string XML string to convert. 1302 * @param string $string XML string to convert. 1303 * @param string $field_key Optional feed field name for sanitization logging. 1212 1304 * 1213 1305 * @since 2.34.0. Added an utf8 check and rewritten the CDATA string rule. 1214 1306 * @since 3.5.0. Replaced the deprecated utf8_encode with mb_convert_encoding. 1307 * @since 3.25.0. Strips XML 1.0–illegal characters and logs removals when process logging is enabled. 1215 1308 * @return string the CDATA string. 1216 1309 */ 1217 protected function convert_to_character_data_string( $string ) {1310 protected function convert_to_character_data_string( $string, $field_key = '' ) { 1218 1311 if ( is_numeric( $string ) ) { 1219 1312 return $string; 1220 1313 } 1221 1314 1222 if ( mb_detect_encoding( $string, 'UTF-8' ) ) { // string contains non-UTF-8 characters so they should be removed 1223 $string = mb_convert_encoding( $string, 'UTF-8', mb_detect_encoding( $string )); 1315 if ( ! mb_check_encoding( $string, 'UTF-8' ) ) { 1316 $from_encoding = mb_detect_encoding( $string, mb_detect_order(), true ); 1317 $string = mb_convert_encoding( $string, 'UTF-8', $from_encoding ? $from_encoding : 'UTF-8' ); 1318 } 1319 1320 if ( function_exists( 'wppfm_sanitize_xml_10_text_with_report' ) ) { 1321 list( $string, $report ) = wppfm_sanitize_xml_10_text_with_report( $string ); 1322 $this->wppfm_maybe_log_xml_text_sanitization( $report, $field_key ); 1224 1323 } 1225 1324 … … 1321 1420 * 1322 1421 * @param string $value_string the original value. 1323 * 1422 * @param string $field_key Optional feed field name for sanitization logging. 1423 * 1424 * @since 3.25.0. Strips XML 1.0–illegal characters before XML entity escaping. 1324 1425 * @return string converted string. 1325 1426 */ 1326 public function convert_to_xml_value( $value_string ) { 1427 public function convert_to_xml_value( $value_string, $field_key = '' ) { 1428 if ( function_exists( 'wppfm_sanitize_xml_10_text_with_report' ) ) { 1429 list( $value_string, $report ) = wppfm_sanitize_xml_10_text_with_report( $value_string ); 1430 $this->wppfm_maybe_log_xml_text_sanitization( $report, $field_key ); 1431 } 1432 1327 1433 $string_without_tags = wp_strip_all_tags( $value_string ); 1328 1434 $prep_string = str_replace( -
wp-product-feed-manager/trunk/includes/class-wppfm-register-scripts.php
r3745889 r3820184 305 305 $source_url = $this->wppfm_normalize_uploads_url_host( $source_url ); 306 306 307 // Align script URLs with the request scheme (e.g. DDEV/HSTS serves HTTPS while siteurl stays HTTP). 308 $source_url = set_url_scheme( $source_url, is_ssl() ? 'https' : 'http' ); 309 307 310 /** 308 311 * Filters the resolved channel source URL. -
wp-product-feed-manager/trunk/includes/data/class-wppfm-ajax-data.php
r3745889 r3820184 77 77 public function wppfm_get_list_of_backups() { 78 78 if ( wp_verify_nonce( filter_input( INPUT_POST, 'postBackupListNonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 'wppfm-ajax-backups-list-nonce' ) && current_user_can( 'manage_options' ) && is_admin() ) { 79 // Also protects backup folders that were created before the folder protection was introduced (@since 3.25.0). 80 WPPFM_Folders::protect_backup_folder(); 81 79 82 echo wp_json_encode( $this->_files_class->make_list_of_active_backups() ); 80 83 } else { -
wp-product-feed-manager/trunk/includes/data/class-wppfm-db-management.php
r3642912 r3820184 148 148 $backup_path = str_replace( '\\', '/', $backup_file ); 149 149 150 // Prepare the folder structure to support saving backup files. 151 if ( ! file_exists( WPPFM_BACKUP_DIR ) ) { 152 WPPFM_Folders::make_backup_folder(); 153 } 150 // Prepare the folder structure to support saving backup files and make sure the folder is protected. 151 WPPFM_Folders::make_backup_folder(); 154 152 155 153 if ( ! file_exists( $backup_path ) ) { -
wp-product-feed-manager/trunk/includes/data/js/wppfm_ajaxdatahandling.js
r3525603 r3820184 586 586 // reset the feed list 587 587 wppfm_resetFeedList(); 588 wppfm_showSuccessMessage( wppfm_feed_list_form_vars.feed_removed.replace( '%feedname%', feedTitle ) ); 588 // The message is inserted as html, so the stored feed name must be escaped. 589 wppfm_showSuccessMessage( wppfm_feed_list_form_vars.feed_removed.replace( '%feedname%', wppfm_escapeHtml( feedTitle ) ) ); 589 590 wppfm_hideWorkingSpinner(); 590 591 } else { -
wp-product-feed-manager/trunk/includes/data/js/wppfm_ajaxdatahandling.min.js
r3525603 r3820184 1 var wppfmAjaxNonces=window.wppfmAjaxNonces||window.myAjaxNonces||{},myAjaxNonces=wppfmAjaxNonces;function wppfm_getFeedList(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-list-of-feeds",postFeedsListNonce:myAjaxNonces.postFeedsListNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getBackupsList(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-list-of-backups",postBackupListNonce:myAjaxNonces.postBackupListNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getSettingsOptions(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-settings-options",postSetupOptionsNonce:myAjaxNonces.postSetupOptionsNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getOutputFields(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-output-fields",feedId:e,channelId:n,feedType:t,outputFieldsNonce:myAjaxNonces.outputFieldsNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_getSourceFields(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-input-fields",sourceId:e,inputFieldsNonce:myAjaxNonces.inputFieldsNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_getMainFeedFilters(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-main-feed-filters",feedId:e,inputFeedFiltersNonce:myAjaxNonces.inputFeedFiltersNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_getNextCategories(e,n,t,a,o){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-next-categories",channelId:e,requestedLevel:n,parentCategory:t,fileLanguage:a,nextCategoryNonce:myAjaxNonces.nextCategoryNonce},function(e){"0"===(e=e.trim()).substring(e.length-1)&&(e=e.substring(0,e.length-1)),o(wppfm_validateResponse(e))})}function wppfm_getCategoryListsFromString(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-category-lists",channelId:e,mainCategories:n,fileLanguage:t,categoryListsNonce:myAjaxNonces.categoryListsNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_updateFeedToDb(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-update-feed-data",feed:JSON.stringify(e),feedFilter:t&&t.length>0?t[0].meta_value:"",metaData:JSON.stringify(n),updateFeedDataNonce:myAjaxNonces.updateFeedDataNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_updateFeedFile(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-update-feed-file",dataType:"text",feedId:e,updateFeedFileNonce:myAjaxNonces.updateFeedFileNonce,client_request_id:t?String(t):""},function(e){n(wppfm_validateResponse(e))})}function wppfm_getCurrentFeedStatus(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-feed-status",sourceId:e,feedStatusNonce:myAjaxNonces.feedStatusNonce,client_request_id:t?String(t):""},function(e){n(wppfm_validateResponse(e))})}function wppfm_switchFeedStatus(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-switch-feed-status",feedId:e,switchFeedStatusNonce:myAjaxNonces.switchFeedStatusNonce},function(t){wppfm_switchStatusAction(e,t),n(wppfm_validateResponse(t))})}function wppfm_duplicateExistingFeed(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-duplicate-existing-feed",feedId:e,duplicateFeedNonce:myAjaxNonces.duplicateFeedNonce},function(e){e.trim()&&wppfm_resetFeedList(),n(wppfm_validateResponse(e))})}function wppfm_logMessageOnServer(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-log-message",messageList:e,fileName:n,logMessageNonce:myAjaxNonces.logMessageNonce},function(e){t(e.trim())})}function wppfm_normalizeBooleanSelection(e){return!0===e||"true"===e||1===e||"1"===e||"on"===e?"true":"false"}function wppfm_auto_feed_fix_mode(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-auto-feed-fix-mode-selection",fix_selection:wppfm_normalizeBooleanSelection(e),updateAutoFeedFixNonce:myAjaxNonces.setAutoFeedFixNonce},function(e){n(e.trim())})}function wppfm_background_processing_mode(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-background-processing-mode-selection",mode_selection:wppfm_normalizeBooleanSelection(e),backgroundModeNonce:myAjaxNonces.setBackgroundModeNonce},function(e){n(e.trim())})}function wppfm_feed_logger_status(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-feed-logger-status-selection",statusSelection:wppfm_normalizeBooleanSelection(e),feedLoggerStatusNonce:myAjaxNonces.setFeedLoggerStatusNonce},function(e){n(e.trim())})}function wppfm_show_pi_status(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-show-product-identifiers-selection",showPiSelection:wppfm_normalizeBooleanSelection(e),showPINonce:myAjaxNonces.setShowPINonce},function(e){n(e.trim())})}function wppfm_switch_to_manual_channel_update(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-switch-to-manual-channel-update-selection",manualChannelUpdateSelection:wppfm_normalizeBooleanSelection(e),manualChannelUpdateNonce:myAjaxNonces.setManualChannelUpdateNonce},function(e){n(e.trim())})}function wppfm_wpml_use_full_url_resolution(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-wpml-use-full-url-resolution-selection",urlResolutionSelection:wppfm_normalizeBooleanSelection(e),urlResolutionNonce:myAjaxNonces.setUseFullResolutionNonce},function(e){n(e.trim())})}function wppfm_omit_price_filters(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-omit-price-filters-selection",omitPriceFiltersSelection:wppfm_normalizeBooleanSelection(e),omitPriceFiltersNonce:myAjaxNonces.setOmitPriceFiltersNonce},function(e){n(e.trim())})}function wppfm_change_third_party_attribute_keywords(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-third-party-attribute-keywords",keywords:e,thirdPartyKeywordsNonce:myAjaxNonces.setThirdPartyKeywordsNonce},function(e){n(e.trim())})}function wppfm_change_notice_mailaddress(e,n){jQuery.ajax({url:myAjaxNonces.ajaxurl,type:"POST",data:{action:"wppfm-ajax-set-notice-mailaddress",mailaddress:e,noticeMailaddressNonce:myAjaxNonces.setNoticeMailaddressNonce},dataType:"json",success:function(t){t&&t.success&&t.data?n(t.data):n({email:e,test_sent:!1})},error:function(){n(null)}})}function wppfm_change_background_processing_time_limit(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-background-processing-time-limit",limit:e,batchProcessingLimitNonce:myAjaxNonces.setBatchProcessingLimitNonce},function(e){n(e.trim())})}function wppfm_clear_feed_process_data(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-clear-feed-process-data",clearFeedNonce:myAjaxNonces.setClearFeedProcessNonce},function(n){e(n)})}function wppfm_reinitiate_plugin(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-reinitiate-plugin",reInitiateNonce:myAjaxNonces.setReInitiateNonce},function(n){e(n)})}function wppfm_validateResponse(e){return(e=e.trim()).indexOf('id="error"')<0?e:(wppfm_showErrorMessage(e),"error")}function wppfm_deleteFeed(e,n){var t=jQuery("#feed-list-message");t.empty(),wppfm_showWorkingSpinner(),wppfm_removeFeedFile(function(){wppfm_deleteFeedFromDb(e,function(e){wppfm_showWorkingSpinner(),"1"===(e=e.trim())?(wppfm_resetFeedList(),wppfm_showSuccessMessage(wppfm_feed_list_form_vars.feed_removed.replace("%feedname%", n)),wppfm_hideWorkingSpinner()):(t.append(e),wppfm_hideWorkingSpinner())},e)},n)}function wppfm_removeFeedFile(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-feed-file",fileTitle:n,deleteFeedNonce:myAjaxNonces.deleteFeedNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_deleteFeedFromDb(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-feed",feedId:e,deleteFeedNonce:myAjaxNonces.deleteFeedNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_checkNextFeedInQueue(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-next-feed-in-queue",nextFeedInQueueNonce:myAjaxNonces.nextFeedInQueueNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_initiateBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-backup-current-data",fileName:e,backupNonce:myAjaxNonces.backupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_deleteBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-backup-file",fileName:e,deleteBackupNonce:myAjaxNonces.deleteBackupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_restoreBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-restore-backup-file",fileName:e,restoreBackupNonce:myAjaxNonces.restoreBackupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_duplicateBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-duplicate-backup-file",fileName:e,duplicateBackupNonce:myAjaxNonces.duplicateBackupNonce},function(e){n(wppfm_validateResponse(e))})}1 var wppfmAjaxNonces=window.wppfmAjaxNonces||window.myAjaxNonces||{},myAjaxNonces=wppfmAjaxNonces;function wppfm_getFeedList(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-list-of-feeds",postFeedsListNonce:myAjaxNonces.postFeedsListNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getBackupsList(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-list-of-backups",postBackupListNonce:myAjaxNonces.postBackupListNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getSettingsOptions(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-settings-options",postSetupOptionsNonce:myAjaxNonces.postSetupOptionsNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_getOutputFields(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-output-fields",feedId:e,channelId:n,feedType:t,outputFieldsNonce:myAjaxNonces.outputFieldsNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_getSourceFields(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-input-fields",sourceId:e,inputFieldsNonce:myAjaxNonces.inputFieldsNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_getMainFeedFilters(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-main-feed-filters",feedId:e,inputFeedFiltersNonce:myAjaxNonces.inputFeedFiltersNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_getNextCategories(e,n,t,a,o){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-next-categories",channelId:e,requestedLevel:n,parentCategory:t,fileLanguage:a,nextCategoryNonce:myAjaxNonces.nextCategoryNonce},function(e){"0"===(e=e.trim()).substring(e.length-1)&&(e=e.substring(0,e.length-1)),o(wppfm_validateResponse(e))})}function wppfm_getCategoryListsFromString(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-category-lists",channelId:e,mainCategories:n,fileLanguage:t,categoryListsNonce:myAjaxNonces.categoryListsNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_updateFeedToDb(e,n,t,a){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-update-feed-data",feed:JSON.stringify(e),feedFilter:t&&t.length>0?t[0].meta_value:"",metaData:JSON.stringify(n),updateFeedDataNonce:myAjaxNonces.updateFeedDataNonce},function(e){a(wppfm_validateResponse(e))})}function wppfm_updateFeedFile(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-update-feed-file",dataType:"text",feedId:e,updateFeedFileNonce:myAjaxNonces.updateFeedFileNonce,client_request_id:t?String(t):""},function(e){n(wppfm_validateResponse(e))})}function wppfm_getCurrentFeedStatus(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-feed-status",sourceId:e,feedStatusNonce:myAjaxNonces.feedStatusNonce,client_request_id:t?String(t):""},function(e){n(wppfm_validateResponse(e))})}function wppfm_switchFeedStatus(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-switch-feed-status",feedId:e,switchFeedStatusNonce:myAjaxNonces.switchFeedStatusNonce},function(t){wppfm_switchStatusAction(e,t),n(wppfm_validateResponse(t))})}function wppfm_duplicateExistingFeed(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-duplicate-existing-feed",feedId:e,duplicateFeedNonce:myAjaxNonces.duplicateFeedNonce},function(e){e.trim()&&wppfm_resetFeedList(),n(wppfm_validateResponse(e))})}function wppfm_logMessageOnServer(e,n,t){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-log-message",messageList:e,fileName:n,logMessageNonce:myAjaxNonces.logMessageNonce},function(e){t(e.trim())})}function wppfm_normalizeBooleanSelection(e){return!0===e||"true"===e||1===e||"1"===e||"on"===e?"true":"false"}function wppfm_auto_feed_fix_mode(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-auto-feed-fix-mode-selection",fix_selection:wppfm_normalizeBooleanSelection(e),updateAutoFeedFixNonce:myAjaxNonces.setAutoFeedFixNonce},function(e){n(e.trim())})}function wppfm_background_processing_mode(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-background-processing-mode-selection",mode_selection:wppfm_normalizeBooleanSelection(e),backgroundModeNonce:myAjaxNonces.setBackgroundModeNonce},function(e){n(e.trim())})}function wppfm_feed_logger_status(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-feed-logger-status-selection",statusSelection:wppfm_normalizeBooleanSelection(e),feedLoggerStatusNonce:myAjaxNonces.setFeedLoggerStatusNonce},function(e){n(e.trim())})}function wppfm_show_pi_status(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-show-product-identifiers-selection",showPiSelection:wppfm_normalizeBooleanSelection(e),showPINonce:myAjaxNonces.setShowPINonce},function(e){n(e.trim())})}function wppfm_switch_to_manual_channel_update(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-switch-to-manual-channel-update-selection",manualChannelUpdateSelection:wppfm_normalizeBooleanSelection(e),manualChannelUpdateNonce:myAjaxNonces.setManualChannelUpdateNonce},function(e){n(e.trim())})}function wppfm_wpml_use_full_url_resolution(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-wpml-use-full-url-resolution-selection",urlResolutionSelection:wppfm_normalizeBooleanSelection(e),urlResolutionNonce:myAjaxNonces.setUseFullResolutionNonce},function(e){n(e.trim())})}function wppfm_omit_price_filters(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-omit-price-filters-selection",omitPriceFiltersSelection:wppfm_normalizeBooleanSelection(e),omitPriceFiltersNonce:myAjaxNonces.setOmitPriceFiltersNonce},function(e){n(e.trim())})}function wppfm_change_third_party_attribute_keywords(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-third-party-attribute-keywords",keywords:e,thirdPartyKeywordsNonce:myAjaxNonces.setThirdPartyKeywordsNonce},function(e){n(e.trim())})}function wppfm_change_notice_mailaddress(e,n){jQuery.ajax({url:myAjaxNonces.ajaxurl,type:"POST",data:{action:"wppfm-ajax-set-notice-mailaddress",mailaddress:e,noticeMailaddressNonce:myAjaxNonces.setNoticeMailaddressNonce},dataType:"json",success:function(t){t&&t.success&&t.data?n(t.data):n({email:e,test_sent:!1})},error:function(){n(null)}})}function wppfm_change_background_processing_time_limit(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-background-processing-time-limit",limit:e,batchProcessingLimitNonce:myAjaxNonces.setBatchProcessingLimitNonce},function(e){n(e.trim())})}function wppfm_clear_feed_process_data(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-clear-feed-process-data",clearFeedNonce:myAjaxNonces.setClearFeedProcessNonce},function(n){e(n)})}function wppfm_reinitiate_plugin(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-reinitiate-plugin",reInitiateNonce:myAjaxNonces.setReInitiateNonce},function(n){e(n)})}function wppfm_validateResponse(e){return(e=e.trim()).indexOf('id="error"')<0?e:(wppfm_showErrorMessage(e),"error")}function wppfm_deleteFeed(e,n){var t=jQuery("#feed-list-message");t.empty(),wppfm_showWorkingSpinner(),wppfm_removeFeedFile(function(){wppfm_deleteFeedFromDb(e,function(e){wppfm_showWorkingSpinner(),"1"===(e=e.trim())?(wppfm_resetFeedList(),wppfm_showSuccessMessage(wppfm_feed_list_form_vars.feed_removed.replace("%feedname%",wppfm_escapeHtml(n))),wppfm_hideWorkingSpinner()):(t.append(e),wppfm_hideWorkingSpinner())},e)},n)}function wppfm_removeFeedFile(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-feed-file",fileTitle:n,deleteFeedNonce:myAjaxNonces.deleteFeedNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_deleteFeedFromDb(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-feed",feedId:e,deleteFeedNonce:myAjaxNonces.deleteFeedNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_checkNextFeedInQueue(e){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-get-next-feed-in-queue",nextFeedInQueueNonce:myAjaxNonces.nextFeedInQueueNonce},function(n){e(wppfm_validateResponse(n))})}function wppfm_initiateBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-backup-current-data",fileName:e,backupNonce:myAjaxNonces.backupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_deleteBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-delete-backup-file",fileName:e,deleteBackupNonce:myAjaxNonces.deleteBackupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_restoreBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-restore-backup-file",fileName:e,restoreBackupNonce:myAjaxNonces.restoreBackupNonce},function(e){n(wppfm_validateResponse(e))})}function wppfm_duplicateBackup(e,n){jQuery.post(myAjaxNonces.ajaxurl,{action:"wppfm-ajax-duplicate-backup-file",fileName:e,duplicateBackupNonce:myAjaxNonces.duplicateBackupNonce},function(e){n(wppfm_validateResponse(e))})} -
wp-product-feed-manager/trunk/includes/setup/class-wppfm-folders.php
r3677452 r3820184 35 35 if ( ! file_exists( WPPFM_BACKUP_DIR ) ) { 36 36 self::make_wppfm_dir( WPPFM_BACKUP_DIR ); 37 } 38 39 self::protect_backup_folder(); 40 } 41 42 /** 43 * Blocks direct web access to the backup files by adding an .htaccess deny rule and an empty index.php file. 44 * 45 * Backups are exported through an authenticated admin request, so the files never need to be publicly reachable. 46 * Existing protection files are left untouched. 47 * 48 * @since 3.25.0 49 */ 50 public static function protect_backup_folder() { 51 if ( ! is_dir( WPPFM_BACKUP_DIR ) ) { 52 return; 53 } 54 55 $htaccess_file = WPPFM_BACKUP_DIR . '/.htaccess'; 56 $index_file = WPPFM_BACKUP_DIR . '/index.php'; 57 58 if ( file_exists( $htaccess_file ) && file_exists( $index_file ) ) { 59 return; 60 } 61 62 $wp_filesystem = wppfm_get_wp_filesystem(); 63 64 // Supports both the Apache 2.4+ and the legacy Apache 2.2 access control syntax. 65 $htaccess_rules = "# Prevent direct web access to the Feed Manager backup files.\n" 66 . "<IfModule mod_authz_core.c>\n" 67 . "\tRequire all denied\n" 68 . "</IfModule>\n" 69 . "<IfModule !mod_authz_core.c>\n" 70 . "\tOrder deny,allow\n" 71 . "\tDeny from all\n" 72 . "</IfModule>\n"; 73 74 if ( ! $wp_filesystem->exists( $htaccess_file ) ) { 75 $wp_filesystem->put_contents( $htaccess_file, $htaccess_rules, FS_CHMOD_FILE ); 76 } 77 78 if ( ! $wp_filesystem->exists( $index_file ) ) { 79 $wp_filesystem->put_contents( $index_file, "<?php\n// Silence is golden.\n", FS_CHMOD_FILE ); 37 80 } 38 81 } -
wp-product-feed-manager/trunk/includes/user-interface/class-wppfm-list-table.php
r3642912 r3820184 232 232 * @param string $title 233 233 * @param string $feed_type 234 *235 * @noinspection BadExpressionStatementJS236 * @noinspection JSVoidFunctionReturnValueUsed237 * @noinspection CommaExpressionJS238 234 */ 239 235 private function feed_ready_action_links( $feed_id, $feed_url, $status, $title, $feed_type ) { … … 245 241 $action_id = wppfm_convert_string_with_spaces_to_lower_case_string_with_dashes( $title ); 246 242 247 echo '<strong><a href="javascript:void(0);" id="wppfm-edit-' . esc_attr( $action_id ) . '-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type=' . esc_attr( $feed_type_link ) . '&id=' . esc_attr( $feed_id ) . '\'">' . esc_html__( 'Edit', 'wp-product-feed-manager' ) . '</a>'; 248 echo $file_exists ? ' | <a href="javascript:void(0);" id="wppfm-view-' . esc_html( $action_id ) . '-action" onclick="wppfm_viewFeed(\'' . esc_url( $feed_url ) . '\')">' . esc_html__( 'View', 'wp-product-feed-manager' ) . '</a>' : ''; 249 echo ' | <a href="javascript:void(0);" id="wppfm-delete-' . esc_attr( $action_id ) . '-action" onclick="wppfm_deleteSpecificFeed(' . esc_html( $feed_id ) . ', \'' . esc_html( $file_name ) . '\')">' . esc_html__( 'Delete', 'wp-product-feed-manager' ) . '</a>'; 250 echo $file_exists && 'Google Merchant Promotions Feed' !== $feed_type ? '<a href="javascript:void(0);" id="wppfm-deactivate-' . esc_attr( $action_id ) . '-action" onclick="wppfm_deactivateFeed(' . esc_attr( $feed_id ) . ')" id="feed-status-switch-' . esc_attr( $feed_id ) . '"> | ' . esc_html( $change_status ) . '</a>' : ''; 251 echo ' | <a href="javascript:void(0);" id="wppfm-duplicate-' . esc_attr( $action_id ) . '-action" onclick="wppfm_duplicateFeed(' . esc_attr( $feed_id ) . ', \'' . esc_html( $title ) . '\')">' . esc_html__( 'Duplicate', 'wp-product-feed-manager' ) . '</a>'; 252 echo 'Product Feed' === $feed_type ? ' | <a href="javascript:void(0);" id="wppfm-regenerate-' . esc_attr( $action_id ) . '-action" onclick="wppfm_regenerateFeed(' . esc_attr( $feed_id ) . ')">' . esc_html__( 'Regenerate', 'wp-product-feed-manager' ) . '</a></strong>' : ''; 243 // All feed action links are handled by delegated listeners in wppfm_feed-list.js. Feed data must 244 // never be placed in an inline onclick handler, because the browser decodes HTML entities before running the handler code. 245 echo '<strong><a href="javascript:void(0);" id="wppfm-edit-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-edit-action" data-feed-id="' . esc_attr( $feed_id ) . '" data-feed-type="' . esc_attr( $feed_type_link ) . '">' . esc_html__( 'Edit', 'wp-product-feed-manager' ) . '</a>'; 246 echo $file_exists ? ' | <a href="javascript:void(0);" id="wppfm-view-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-view-action" data-feed-url="' . esc_url( $feed_url ) . '">' . esc_html__( 'View', 'wp-product-feed-manager' ) . '</a>' : ''; 247 echo ' | <a href="javascript:void(0);" id="wppfm-delete-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-delete-action" data-feed-id="' . esc_attr( $feed_id ) . '" data-feed-name="' . esc_attr( $file_name ) . '">' . esc_html__( 'Delete', 'wp-product-feed-manager' ) . '</a>'; 248 echo $file_exists && 'Google Merchant Promotions Feed' !== $feed_type ? '<a href="javascript:void(0);" id="wppfm-deactivate-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-deactivate-action" data-feed-id="' . esc_attr( $feed_id ) . '" id="feed-status-switch-' . esc_attr( $feed_id ) . '"> | ' . esc_html( $change_status ) . '</a>' : ''; 249 echo ' | <a href="javascript:void(0);" id="wppfm-duplicate-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-duplicate-action" data-feed-id="' . esc_attr( $feed_id ) . '" data-feed-name="' . esc_attr( $title ) . '">' . esc_html__( 'Duplicate', 'wp-product-feed-manager' ) . '</a>'; 250 echo 'Product Feed' === $feed_type ? ' | <a href="javascript:void(0);" id="wppfm-regenerate-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-regenerate-action" data-feed-id="' . esc_attr( $feed_id ) . '">' . esc_html__( 'Regenerate', 'wp-product-feed-manager' ) . '</a></strong>' : ''; 253 251 } 254 252 … … 261 259 * @param string $title 262 260 * @param string $feed_type 263 *264 * @noinspection BadExpressionStatementJS265 * @noinspection JSVoidFunctionReturnValueUsed266 * @noinspection CommaExpressionJS267 261 */ 268 262 private function feed_not_ready_action_links( $feed_id, $feed_url, $title, $feed_type ) { … … 277 271 $action_id = wppfm_convert_string_with_spaces_to_lower_case_string_with_dashes( $title ); 278 272 279 echo '<strong><a href="javascript:void(0);" id="wppfm-edit-' . esc_attr( $action_id ) . '-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type=' . esc_attr( $feed_type_link ) . '&id=' . esc_attr( $feed_id ) . '\'">' . esc_html__( 'Edit', 'wp-product-feed-manager' ) . '</a>';280 echo ' | <a href="javascript:void(0);" id="wppfm-delete-' . esc_attr( $action_id ) . '-action" onclick="wppfm_deleteSpecificFeed(' . esc_attr( $feed_id ) . ', \'' . esc_attr( $file_name ) . '\')">' . esc_html__( 'Delete', 'wp-product-feed-manager' ) . '</a>';281 echo 'Product Feed' === $feed_type ? ' | <a href="javascript:void(0);" id="wppfm-regenerate-' . esc_attr( $action_id ) . '-action" onclick="wppfm_regenerateFeed(' . esc_attr( $feed_id ) . ')">' . esc_html__( 'Regenerate', 'wp-product-feed-manager' ) . '</a></strong>' : '';273 echo '<strong><a href="javascript:void(0);" id="wppfm-edit-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-edit-action" data-feed-id="' . esc_attr( $feed_id ) . '" data-feed-type="' . esc_attr( $feed_type_link ) . '">' . esc_html__( 'Edit', 'wp-product-feed-manager' ) . '</a>'; 274 echo ' | <a href="javascript:void(0);" id="wppfm-delete-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-delete-action" data-feed-id="' . esc_attr( $feed_id ) . '" data-feed-name="' . esc_attr( $file_name ) . '">' . esc_html__( 'Delete', 'wp-product-feed-manager' ) . '</a>'; 275 echo 'Product Feed' === $feed_type ? ' | <a href="javascript:void(0);" id="wppfm-regenerate-' . esc_attr( $action_id ) . '-action" class="wppfm-feed-regenerate-action" data-feed-id="' . esc_attr( $feed_id ) . '">' . esc_html__( 'Regenerate', 'wp-product-feed-manager' ) . '</a></strong>' : ''; 282 276 $this->feed_status_checker_script( $feed_id ); 283 277 } -
wp-product-feed-manager/trunk/includes/user-interface/class-wppfm-settings-page.php
r3517383 r3820184 233 233 echo 234 234 '<div id="wppfm-settings-page-data-storage" class="wppfm-data-storage-element" 235 data-wppfm- wp-uploads-url="' . esc_url( WPPFM_UPLOADS_URL) . '"235 data-wppfm-backup-export-url="' . esc_url( wppfm_get_backup_export_url() ) . '" 236 236 data-wppfm-plugin-version-id="' . esc_attr( WPPFM_PLUGIN_VERSION_ID ) . '" 237 237 data-wppfm-plugin-version-nr="' . esc_attr( WPPFM_VERSION_NUM ) . '" -
wp-product-feed-manager/trunk/includes/user-interface/js/wppfm_feed-list.js
r3517383 r3820184 90 90 } 91 91 92 // Stored feed data is escaped like the esc_html() output of the server-rendered list in WPPFM_List_Table. 92 93 htmlCode += '<tr id="feed-row">'; 93 htmlCode += '<td id="title-' + feedId + '">' + list [ i ] [ 'title' ]+ '</td>';94 htmlCode += '<td id="url">' + feedUrl+ '</td>';95 htmlCode += '<td id="updated-' + feedId + '">' + list [ i ] [ 'updated' ]+ '</td>';96 htmlCode += '<td id="products-' + feedId + '">' + nrProducts+ '</td>';97 htmlCode += '<td id="type-' + feedId + '">' + list [ i ] [ 'feed_type_name' ]+ '</td>';94 htmlCode += '<td id="title-' + feedId + '">' + wppfm_escapeFeedListValue( list [ i ] [ 'title' ] ) + '</td>'; 95 htmlCode += '<td id="url">' + wppfm_escapeFeedListValue( feedUrl ) + '</td>'; 96 htmlCode += '<td id="updated-' + feedId + '">' + wppfm_escapeFeedListValue( list [ i ] [ 'updated' ] ) + '</td>'; 97 htmlCode += '<td id="products-' + feedId + '">' + wppfm_escapeFeedListValue( nrProducts ) + '</td>'; 98 htmlCode += '<td id="type-' + feedId + '">' + wppfm_escapeFeedListValue( list [ i ] [ 'feed_type_name' ] ) + '</td>'; 98 99 htmlCode += '<td id="feed-status-' + feedId + '" style="color: ' + list [ i ] [ 'color' ] + '"><strong>'; 99 100 htmlCode += statusString; … … 124 125 } 125 126 127 /** 128 * Escapes a feed list value for use as html text or inside a double-quoted attribute. 129 * 130 * Non-string values such as numbers are converted first, because wppfm_escapeHtml() only handles strings. 131 * 132 * @param {*} value Value to escape. 133 * @returns {string} The escaped value, or an empty string for null and undefined. 134 */ 135 function wppfm_escapeFeedListValue( value ) { 136 return null === value || undefined === value ? '' : wppfm_escapeHtml( String( value ) ); 137 } 138 139 /** 140 * Converts a feed title to the html-escaped part used in the ids of the action links of that feed. 141 * 142 * @param {string} title Title of the feed. 143 * @returns {string} Lowercase, dash-separated and html-escaped title. 144 */ 145 function wppfm_feedActionId( title ) { 146 return wppfm_escapeFeedListValue( ( title || '' ).toString().replace( / /g, '-' ).toLowerCase() ); 147 } 148 126 149 function feedReadyActions( feedId, feedUrl, status, title, feedTypeName, feedType ) { 127 150 var fileExists = 'No feed generated' !== feedUrl; 128 151 var fileName = feedUrl.lastIndexOf( '/' ) > 0 ? feedUrl.slice( feedUrl.lastIndexOf( '/' ) - feedUrl.length + 1 ) : title; 129 152 var tabTitle = wppfm_getFeedTypeSlug( feedType ); 130 var actionId = title.replace( / /g, '-' ).toLowerCase();153 var actionId = wppfm_feedActionId( title ); 131 154 var changeStatus = 'ok' === status ? wppfm_feed_list_form_vars.list_deactivate : wppfm_feed_list_form_vars.list_activate; 132 155 133 var htmlCode = '<strong> <a href="javascript:void(0);" id="wppfm-edit-' + actionId + '-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type=' + tabTitle + '&id=' + feedId + '\'">' + wppfm_feed_list_form_vars.list_edit + ' </a>';134 htmlCode += fileExists ? ' | <a href="javascript:void(0);" id="wppfm-view-' + actionId + '-action" onclick="wppfm_viewFeed(\'' + feedUrl + '\')">' + wppfm_feed_list_form_vars.list_view + '</a>': '';135 htmlCode += ' | <a href="javascript:void(0);" id="wppfm-delete-' + actionId + '-action" onclick="wppfm_deleteSpecificFeed(' + feedId + ', \'' + fileName + '\')">' + wppfm_feed_list_form_vars.list_delete + '</a>';136 htmlCode += fileExists ? '<a href="javascript:void(0);" id="wppfm-deactivate-' + actionId + '-action" onclick="wppfm_deactivateFeed(' + feedId + ')" id="feed-status-switch-' + feedId + '"> | ' + changeStatus + '</a>': '';156 var htmlCode = '<strong>' + wppfm_feedEditActionLink( feedId, actionId, tabTitle, wppfm_feed_list_form_vars.list_edit + ' ' ); 157 htmlCode += fileExists ? ' | ' + wppfm_feedViewActionLink( actionId, feedUrl ) : ''; 158 htmlCode += ' | ' + wppfm_feedDeleteActionLink( feedId, actionId, fileName, wppfm_feed_list_form_vars.list_delete ); 159 htmlCode += fileExists ? wppfm_feedDeactivateActionLink( feedId, actionId, ' | ' + changeStatus ) : ''; 137 160 htmlCode += wppfmEndOfActionsCode( feedId, actionId, title, feedType ); 138 161 return htmlCode; … … 142 165 var fileName = feedUrl.lastIndexOf( '/' ) > 0 ? feedUrl.slice( feedUrl.lastIndexOf( '/' ) - feedUrl.length + 1 ) : title; 143 166 var tabTitle = wppfm_getFeedTypeSlug( feedType ); 144 var actionId = title.replace( / /g, '-' ).toLowerCase();167 var actionId = wppfm_feedActionId( title ); 145 168 146 169 var htmlCode = '<strong>'; 147 htmlCode += '<a href="javascript:void(0);" id="wppfm-edit-' + actionId + '-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type=' + tabTitle + '&id=' + feedId + '\'">' + wppfm_feed_list_form_vars.list_edit + '</a>';148 htmlCode += ' | <a href="javascript:void(0);" id="wppfm-delete-' + actionId + '-action" onclick="wppfm_deleteSpecificFeed(' + feedId + ', \'' + fileName + '\')"> ' + wppfm_feed_list_form_vars.list_delete + '</a>';170 htmlCode += wppfm_feedEditActionLink( feedId, actionId, tabTitle, wppfm_feed_list_form_vars.list_edit ); 171 htmlCode += ' | ' + wppfm_feedDeleteActionLink( feedId, actionId, fileName, ' ' + wppfm_feed_list_form_vars.list_delete ); 149 172 htmlCode += wppfmEndOfActionsCode( feedId, actionId, title, feedType ); 150 173 htmlCode += wppfm_addFeedStatusChecker( feedId ); … … 152 175 } 153 176 177 /** 178 * Builds the Edit action link of a feed list row. 179 * 180 * Uses data attributes and a delegated click listener for the same reason as wppfm_feedDeleteActionLink(). 181 * 182 * @param {string|number} feedId Id of the feed. 183 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 184 * @param {string} feedTypeSlug Feed type slug used for the feed-type parameter of the feed editor url. 185 * @param {string} label Link text. 186 * @returns {string} Html code of the link. 187 */ 188 function wppfm_feedEditActionLink( feedId, actionId, feedTypeSlug, label ) { 189 return '<a href="javascript:void(0);" id="wppfm-edit-' + actionId + '-action" class="wppfm-feed-edit-action" data-feed-id="' + wppfm_escapeFeedListValue( feedId ) + '" data-feed-type="' + wppfm_escapeFeedListValue( feedTypeSlug ) + '">' + label + '</a>'; 190 } 191 192 /** 193 * Builds the View action link of a feed list row. 194 * 195 * Uses data attributes and a delegated click listener for the same reason as wppfm_feedDeleteActionLink(). 196 * 197 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 198 * @param {string} feedUrl Url of the feed file. 199 * @returns {string} Html code of the link. 200 */ 201 function wppfm_feedViewActionLink( actionId, feedUrl ) { 202 return '<a href="javascript:void(0);" id="wppfm-view-' + actionId + '-action" class="wppfm-feed-view-action" data-feed-url="' + wppfm_escapeFeedListValue( feedUrl ) + '">' + wppfm_feed_list_form_vars.list_view + '</a>'; 203 } 204 205 /** 206 * Builds the Delete action link of a feed list row. 207 * 208 * The feed id and name are stored in data attributes and handled by a delegated click listener, because 209 * concatenating stored feed data into an inline onclick handler allows a quote in the name to inject script. 210 * 211 * @param {string|number} feedId Id of the feed. 212 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 213 * @param {string} feedName File name or title of the feed, used in the confirmation and removal. 214 * @param {string} label Link text. 215 * @returns {string} Html code of the link. 216 */ 217 function wppfm_feedDeleteActionLink( feedId, actionId, feedName, label ) { 218 return '<a href="javascript:void(0);" id="wppfm-delete-' + actionId + '-action" class="wppfm-feed-delete-action" data-feed-id="' + wppfm_escapeFeedListValue( feedId ) + '" data-feed-name="' + wppfm_escapeFeedListValue( feedName ) + '">' + label + '</a>'; 219 } 220 221 /** 222 * Builds the Duplicate action link of a feed list row. 223 * 224 * Uses data attributes and a delegated click listener for the same reason as wppfm_feedDeleteActionLink(). 225 * 226 * @param {string|number} feedId Id of the feed. 227 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 228 * @param {string} title Title of the feed, used in the success message. 229 * @returns {string} Html code of the link. 230 */ 231 function wppfm_feedDuplicateActionLink( feedId, actionId, title ) { 232 return '<a href="javascript:void(0);" id="wppfm-duplicate-' + actionId + '-action" class="wppfm-feed-duplicate-action" data-feed-id="' + wppfm_escapeFeedListValue( feedId ) + '" data-feed-name="' + wppfm_escapeFeedListValue( title ) + '">' + wppfm_feed_list_form_vars.list_duplicate + '</a>'; 233 } 234 235 /** 236 * Builds the Auto-on/Auto-off action link of a feed list row. 237 * 238 * Uses data attributes and a delegated click listener for the same reason as wppfm_feedDeleteActionLink(). 239 * 240 * @param {string|number} feedId Id of the feed. 241 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 242 * @param {string} label Link text, including the leading separator. 243 * @returns {string} Html code of the link. 244 */ 245 function wppfm_feedDeactivateActionLink( feedId, actionId, label ) { 246 var escapedFeedId = wppfm_escapeFeedListValue( feedId ); 247 return '<a href="javascript:void(0);" id="wppfm-deactivate-' + actionId + '-action" class="wppfm-feed-deactivate-action" data-feed-id="' + escapedFeedId + '" id="feed-status-switch-' + escapedFeedId + '">' + label + '</a>'; 248 } 249 250 /** 251 * Builds the Regenerate action link of a feed list row. 252 * 253 * Uses data attributes and a delegated click listener for the same reason as wppfm_feedDeleteActionLink(). 254 * 255 * @param {string|number} feedId Id of the feed. 256 * @param {string} actionId Html-escaped, feed-name based part of the link id (see wppfm_feedActionId()). 257 * @returns {string} Html code of the link. 258 */ 259 function wppfm_feedRegenerateActionLink( feedId, actionId ) { 260 return '<a href="javascript:void(0);" id="wppfm-regenerate-' + actionId + '-action" class="wppfm-feed-regenerate-action" data-feed-id="' + wppfm_escapeFeedListValue( feedId ) + '">' + wppfm_feed_list_form_vars.list_regenerate + '</a>'; 261 } 262 154 263 function wppfmEndOfActionsCode( feedId, actionId, title, feedType ) { 155 var htmlCode = ' | <a href="javascript:void(0);" id="wppfm-duplicate-' + actionId + '-action" onclick="wppfm_duplicateFeed(' + feedId + ', \'' + title + '\')">' + wppfm_feed_list_form_vars.list_duplicate + '</a>';156 htmlCode += 'product-feed' === wppfm_getFeedTypeSlug( feedType ) ? ' | <a href="javascript:void(0);" id="wppfm-regenerate-' + actionId + '-action" onclick="wppfm_regenerateFeed(' + feedId + ')">' + wppfm_feed_list_form_vars.list_regenerate + '</a>': '';264 var htmlCode = ' | ' + wppfm_feedDuplicateActionLink( feedId, actionId, title ); 265 htmlCode += 'product-feed' === wppfm_getFeedTypeSlug( feedType ) ? ' | ' + wppfm_feedRegenerateActionLink( feedId, actionId ) : ''; 157 266 htmlCode += '</strong>'; 158 267 … … 369 478 */ 370 479 jQuery( function() { 371 // No actions required at the moment. 480 /** 481 * Handles the action links (Edit, View, Delete, Auto-on/off, Duplicate and Regenerate) of the feed list. 482 * 483 * Delegated to the document so it covers both the server-rendered rows and the rows rebuilt by wppfm_feedListTable(). 484 * attr() is used instead of data() so jQuery does not convert the values to numbers or JSON. 485 */ 486 jQuery( document ).on( 487 'click', 488 'a.wppfm-feed-edit-action', 489 function( event ) { 490 event.preventDefault(); 491 var link = jQuery( this ); 492 // Encoded so the attribute values cannot add or change query parameters of the feed editor url. 493 parent.location = 'admin.php?page=wppfm-feed-editor-page&feed-type=' + encodeURIComponent( link.attr( 'data-feed-type' ) || '' ) + '&id=' + encodeURIComponent( link.attr( 'data-feed-id' ) || '' ); 494 } 495 ); 496 497 jQuery( document ).on( 498 'click', 499 'a.wppfm-feed-view-action', 500 function( event ) { 501 event.preventDefault(); 502 wppfm_viewFeed( jQuery( this ).attr( 'data-feed-url' ) ); 503 } 504 ); 505 506 jQuery( document ).on( 507 'click', 508 'a.wppfm-feed-delete-action', 509 function( event ) { 510 event.preventDefault(); 511 var link = jQuery( this ); 512 wppfm_deleteSpecificFeed( link.attr( 'data-feed-id' ), link.attr( 'data-feed-name' ) ); 513 } 514 ); 515 516 jQuery( document ).on( 517 'click', 518 'a.wppfm-feed-deactivate-action', 519 function( event ) { 520 event.preventDefault(); 521 wppfm_deactivateFeed( jQuery( this ).attr( 'data-feed-id' ) ); 522 } 523 ); 524 525 jQuery( document ).on( 526 'click', 527 'a.wppfm-feed-regenerate-action', 528 function( event ) { 529 event.preventDefault(); 530 wppfm_regenerateFeed( jQuery( this ).attr( 'data-feed-id' ) ); 531 } 532 ); 533 534 jQuery( document ).on( 535 'click', 536 'a.wppfm-feed-duplicate-action', 537 function( event ) { 538 event.preventDefault(); 539 var link = jQuery( this ); 540 wppfm_duplicateFeed( link.attr( 'data-feed-id' ), link.attr( 'data-feed-name' ) ); 541 } 542 ); 372 543 } ); -
wp-product-feed-manager/trunk/includes/user-interface/js/wppfm_feed-list.min.js
r3517383 r3820184 1 function wppfm_fillFeedList(){var e="",t=jQuery("#wppfm-feed-list");wppfm_getFeedList(function( r){var s=JSON.parse(r).list;e="0"!==s?wppfm_feedListTable(s):wppfm_emptyListTable(),t.empty(),t.append(e)})}function appendCategoryLists(e,t,r){var s=jQuery("#lvl_0"),a=jQuery("#category-selector-lvl");r&&wppfm_getCategoryListsFromString(e,"",t,function(e){var t=JSON.parse(e)[0];t&&t.length>0?(s.html(wppfm_categorySelectCntrl(t)),s.prop("disabled",!1)):(a.html(wppfm_freeCategoryInputCntrl("default","0",!1)),a.prop("disabled",!1))})}function wppfm_resetFeedList(){wppfm_fillFeedList()}function wppfm_resetFeedStatus(e){wppfm_checkNextFeedInQueue(function(){e.validation_failure_message&&wppfm_showErrorMessage(e.validation_failure_message),wppfm_updateFeedRowStatus(e.product_feed_id,parseInt(e.status_id)),wppfm_updateFeedRowData(e)})}function wppfm_feedListTable(e){var t="";if(!e)return t;for(var r=0;r<e.length;r++){var s=e[r].status,a=e[r].product_feed_id,p=e[r].url,o="on_hold"===s||"ok"===s,f="",d=wppfm_list_status_text(s);o?f=e[r].products:"processing"===s?f=wppfm_feed_list_form_vars.processing_the_feed:"failed_processing"!==s&&"in_processing_queue"!==s||(f=wppfm_feed_list_form_vars.unknown_text),t+='<tr id="feed-row">',t+='<td id="title-'+a+'">'+e[r].title+"</td>",t+='<td id="url">'+p+"</td>",t+='<td id="updated-'+a+'">'+e[r].updated+"</td>",t+='<td id="products-'+a+'">'+f+"</td>",t+='<td id="type-'+a+'">'+e[r].feed_type_name+"</td>",t+='<td id="feed-status-'+a+'" style="color: '+e[r].color+'"><strong>',t+=d,t+="</strong></td>",t+='<td id="wppfm-feed-list-actions-for-feed-'+a+'">',t+=o?feedReadyActions(a,p,s,e[r].title,e[r].feed_type_name,e[r].feed_type):feedNotReadyActions(a,p,e[r].title,e[r].feed_type),t+="</td>"}return t}function wppfm_getFeedTypeSlug(e){return(e||"").toString().trim().replace(/\s+/g,"-").toLowerCase()}function feedReadyActions(e,t,r,s,a,p){var o="No feed generated"!==t,f=t.lastIndexOf("/")>0?t.slice(t.lastIndexOf("/")-t.length+1):s,d=wppfm_getFeedTypeSlug(p),i=s.replace(/ /g,"-").toLowerCase(),_="ok"===r?wppfm_feed_list_form_vars.list_deactivate:wppfm_feed_list_form_vars.list_activate,n='<strong><a href="javascript:void(0);" id="wppfm-edit-'+i+'-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type='+d+"&id="+e+"'\">"+wppfm_feed_list_form_vars.list_edit+" </a>";return n+=o?' | <a href="javascript:void(0);" id="wppfm-view-'+i+'-action" onclick="wppfm_viewFeed(\''+t+"')\">"+wppfm_feed_list_form_vars.list_view+"</a>":"",n+=' | <a href="javascript:void(0);" id="wppfm-delete-'+i+'-action" onclick="wppfm_deleteSpecificFeed('+e+", '"+f+"')\">"+wppfm_feed_list_form_vars.list_delete+"</a>",(n+=o?'<a href="javascript:void(0);" id="wppfm-deactivate-'+i+'-action" onclick="wppfm_deactivateFeed('+e+')" id="feed-status-switch-'+e+'"> | '+_+"</a>":"")+wppfmEndOfActionsCode(e,i,s,p)}function feedNotReadyActions(e,t,r,s){var a=t.lastIndexOf("/")>0?t.slice(t.lastIndexOf("/")-t.length+1):r,p=wppfm_getFeedTypeSlug(s),o=r.replace(/ /g,"-").toLowerCase(),f="<strong>";return f+='<a href="javascript:void(0);" id="wppfm-edit-'+o+'-action" onclick="parent.location=\'admin.php?page=wppfm-feed-editor-page&feed-type='+p+"&id="+e+"'\">"+wppfm_feed_list_form_vars.list_edit+"</a>",f+=' | <a href="javascript:void(0);" id="wppfm-delete-'+o+'-action" onclick="wppfm_deleteSpecificFeed('+e+", '"+a+"')\"> "+wppfm_feed_list_form_vars.list_delete+"</a>",(f+=wppfmEndOfActionsCode(e,o,r,s))+wppfm_addFeedStatusChecker(e)}function wppfmEndOfActionsCode(e,t,r,s){var a=' | <a href="javascript:void(0);" id="wppfm-duplicate-'+t+'-action" onclick="wppfm_duplicateFeed('+e+", '"+r+"')\">"+wppfm_feed_list_form_vars.list_duplicate+"</a>";return(a+="product-feed"===wppfm_getFeedTypeSlug(s)?' | <a href="javascript:void(0);" id="wppfm-regenerate-'+t+'-action" onclick="wppfm_regenerateFeed('+e+')">'+wppfm_feed_list_form_vars.list_regenerate+"</a>":"")+"</strong>"}function wppfm_emptyListTable(){var e="";return e+="<tr>",(e+="<td colspan = 4>"+wppfm_feed_list_form_vars.no_data_found+"</td>")+"</tr>"}function wppfm_updateFeedRowData(e){if("1"===e.status_id||"2"===e.status_id){var t=e.product_feed_id,r="1"===e.status_id?wppfm_feed_list_form_vars.ok:wppfm_feed_list_form_vars.other;jQuery("#updated-"+t).html(e.updated),jQuery("#products-"+t).html(e.products),jQuery("#wppfm-feed-list-actions-for-feed-"+t).html(feedReadyActions(t,e.url,r,e.title,e.feed_type_name,e.feed_type))}}function wppfm_sortOnColumn(e){for(var t=jQuery("tbody#wppfm-feed-list"),r=jQuery("#wppfm-feed-list-page-data-storage"),s=r.data("wppfmSortColumn"),a=r.data("wppfmSortDirection"),p=r.data("wppfmSortableColumns").split("-"),o=0;o<p.length;o++)e.toString()!==p[o]&&wppfm_resetSortableColumns(p[o]);t.find("tr").sort(function(t,p){var o=jQuery("td:nth-child("+e+")",t),f=jQuery("td:nth-child("+e+")",p);return r.data("wppfmSortColumn",e),s!==e||"asc"!==a&&"none"!==a?(r.data("wppfmSortDirection","asc"),o.text().localeCompare(f.text(),!1,{numeric:!0})):(r.data("wppfmSortDirection","desc"),f.text().localeCompare(o.text(),!1,{numeric:!0}))}).appendTo(t),wppfm_setSortedColumn(e),wppfm_redrawAlternateRowBackground()}function wppfm_redrawAlternateRowBackground(){jQuery("tbody#wppfm-feed-list tr:odd").removeClass("alternate"),jQuery("tbody#wppfm-feed-list tr:even").addClass("alternate")}function wppfm_setSortedColumn(e){var t=jQuery("table thead tr th:nth-child("+e+")");t.hasClass("asc")?t.removeClass("asc").addClass("desc"):t.removeClass("desc").addClass("asc"),t.removeClass("sortable").addClass("sorted")}function wppfm_resetSortableColumns(e){var t=jQuery("table thead tr th:nth-child("+e+")");t.removeClass("sorted").addClass("sortable"),t.removeClass("asc").addClass("desc")}function wppfm_switchStatusAction(e,t){var r=jQuery("#title-"+e).html(),s="";switch(r=r.replace(/\s+/g,"-").toLowerCase(),t=null!=t?t.toString().trim():""){case"1":s=" | Auto-off ";break;case"2":s=" | Auto-on "}jQuery("#wppfm-deactivate-"+r+"-action").html(s)}function wppfm_list_status_text(e){switch(e){case"unknown":return wppfm_feed_list_form_vars.unknown;case"ok":return wppfm_feed_list_form_vars.status_ok;case"on_hold":return wppfm_feed_list_form_vars.on_hold;case"processing":return wppfm_feed_list_form_vars.processing;case"in_processing_queue":return wppfm_feed_list_form_vars.processing_queue;case"has_errors":return wppfm_feed_list_form_vars.has_errors;case"failed_processing":return wppfm_feed_list_form_vars.failed_processing}}function wppfm_updateFeedRowStatus(e,t){var r=jQuery("#feed-status-"+e),s=jQuery("#feed-status-switch-"+e),a=jQuery("#products-"+e);switch(t){case 0:r.html("<strong>"+wppfm_feed_list_form_vars.unknown+"</strong>"),r.css("color","#6549F7"),s.html("");break;case 1:r.html("<strong>"+wppfm_feed_list_form_vars.ok+"</strong>"),r.css("color","#0073AA"),s.html(" | "+wppfm_feed_list_form_vars.list_deactivate+" ");break;case 2:r.html("<strong>"+wppfm_feed_list_form_vars.on_hold+"</strong>"),r.css("color","#0173AA"),s.html(" | "+wppfm_feed_list_form_vars.list_activate+" ");break;case 3:r.html("<strong>"+wppfm_feed_list_form_vars.processing+"</strong>"),r.css("color","#0000FF"),s.html(""),a.html(wppfm_feed_list_form_vars.processing_the_feed);break;case 4:r.html("<strong>"+wppfm_feed_list_form_vars.processing_queue+"</strong>"),r.css("color","#00CCFF"),s.html(wppfm_feed_list_form_vars.list_activate+" ");break;case 5:r.html("<strong>"+wppfm_feed_list_form_vars.has_errors+"</strong>"),r.css("color","#FF0000"),a.html(wppfm_feed_list_form_vars.unknown_text),s.html(wppfm_feed_list_form_vars.list_activate+" ");break;case 6:r.html("<strong>"+wppfm_feed_list_form_vars.processing_failed+"</strong>"),r.css("color","#FF3300"),a.html(wppfm_feed_list_form_vars.unknown_text),s.html("");break;case 7:r.html("<strong>"+wppfm_feed_list_form_vars.no_channel+"</strong>"),r.css("color","#FF3300"),a.html(wppfm_feed_list_form_vars.unknown_text),s.html("")}}jQuery(function(){});1 function wppfm_fillFeedList(){var e="",t=jQuery("#wppfm-feed-list");wppfm_getFeedList(function(a){var p=JSON.parse(a).list;e="0"!==p?wppfm_feedListTable(p):wppfm_emptyListTable(),t.empty(),t.append(e)})}function appendCategoryLists(e,t,a){var p=jQuery("#lvl_0"),r=jQuery("#category-selector-lvl");a&&wppfm_getCategoryListsFromString(e,"",t,function(e){var t=JSON.parse(e)[0];t&&t.length>0?(p.html(wppfm_categorySelectCntrl(t)),p.prop("disabled",!1)):(r.html(wppfm_freeCategoryInputCntrl("default","0",!1)),r.prop("disabled",!1))})}function wppfm_resetFeedList(){wppfm_fillFeedList()}function wppfm_resetFeedStatus(e){wppfm_checkNextFeedInQueue(function(){e.validation_failure_message&&wppfm_showErrorMessage(e.validation_failure_message),wppfm_updateFeedRowStatus(e.product_feed_id,parseInt(e.status_id)),wppfm_updateFeedRowData(e)})}function wppfm_feedListTable(e){var t="";if(!e)return t;for(var a=0;a<e.length;a++){var p=e[a].status,r=e[a].product_feed_id,s=e[a].url,f="on_hold"===p||"ok"===p,d="",i=wppfm_list_status_text(p);f?d=e[a].products:"processing"===p?d=wppfm_feed_list_form_vars.processing_the_feed:"failed_processing"!==p&&"in_processing_queue"!==p||(d=wppfm_feed_list_form_vars.unknown_text),t+='<tr id="feed-row">',t+='<td id="title-'+r+'">'+wppfm_escapeFeedListValue(e[a].title)+"</td>",t+='<td id="url">'+wppfm_escapeFeedListValue(s)+"</td>",t+='<td id="updated-'+r+'">'+wppfm_escapeFeedListValue(e[a].updated)+"</td>",t+='<td id="products-'+r+'">'+wppfm_escapeFeedListValue(d)+"</td>",t+='<td id="type-'+r+'">'+wppfm_escapeFeedListValue(e[a].feed_type_name)+"</td>",t+='<td id="feed-status-'+r+'" style="color: '+e[a].color+'"><strong>',t+=i,t+="</strong></td>",t+='<td id="wppfm-feed-list-actions-for-feed-'+r+'">',t+=f?feedReadyActions(r,s,p,e[a].title,e[a].feed_type_name,e[a].feed_type):feedNotReadyActions(r,s,e[a].title,e[a].feed_type),t+="</td>"}return t}function wppfm_getFeedTypeSlug(e){return(e||"").toString().trim().replace(/\s+/g,"-").toLowerCase()}function wppfm_escapeFeedListValue(e){return null==e?"":wppfm_escapeHtml(String(e))}function wppfm_feedActionId(e){return wppfm_escapeFeedListValue((e||"").toString().replace(/ /g,"-").toLowerCase())}function feedReadyActions(e,t,a,p,r,s){var f="No feed generated"!==t,d=t.lastIndexOf("/")>0?t.slice(t.lastIndexOf("/")-t.length+1):p,i=wppfm_getFeedTypeSlug(s),o=wppfm_feedActionId(p),n="ok"===a?wppfm_feed_list_form_vars.list_deactivate:wppfm_feed_list_form_vars.list_activate,_="<strong>"+wppfm_feedEditActionLink(e,o,i,wppfm_feed_list_form_vars.list_edit+" ");return _+=f?" | "+wppfm_feedViewActionLink(o,t):"",_+=" | "+wppfm_feedDeleteActionLink(e,o,d,wppfm_feed_list_form_vars.list_delete),(_+=f?wppfm_feedDeactivateActionLink(e,o," | "+n):"")+wppfmEndOfActionsCode(e,o,p,s)}function feedNotReadyActions(e,t,a,p){var r=t.lastIndexOf("/")>0?t.slice(t.lastIndexOf("/")-t.length+1):a,s=wppfm_getFeedTypeSlug(p),f=wppfm_feedActionId(a),d="<strong>";return d+=wppfm_feedEditActionLink(e,f,s,wppfm_feed_list_form_vars.list_edit),d+=" | "+wppfm_feedDeleteActionLink(e,f,r," "+wppfm_feed_list_form_vars.list_delete),(d+=wppfmEndOfActionsCode(e,f,a,p))+wppfm_addFeedStatusChecker(e)}function wppfm_feedEditActionLink(e,t,a,p){return'<a href="javascript:void(0);" id="wppfm-edit-'+t+'-action" class="wppfm-feed-edit-action" data-feed-id="'+wppfm_escapeFeedListValue(e)+'" data-feed-type="'+wppfm_escapeFeedListValue(a)+'">'+p+"</a>"}function wppfm_feedViewActionLink(e,t){return'<a href="javascript:void(0);" id="wppfm-view-'+e+'-action" class="wppfm-feed-view-action" data-feed-url="'+wppfm_escapeFeedListValue(t)+'">'+wppfm_feed_list_form_vars.list_view+"</a>"}function wppfm_feedDeleteActionLink(e,t,a,p){return'<a href="javascript:void(0);" id="wppfm-delete-'+t+'-action" class="wppfm-feed-delete-action" data-feed-id="'+wppfm_escapeFeedListValue(e)+'" data-feed-name="'+wppfm_escapeFeedListValue(a)+'">'+p+"</a>"}function wppfm_feedDuplicateActionLink(e,t,a){return'<a href="javascript:void(0);" id="wppfm-duplicate-'+t+'-action" class="wppfm-feed-duplicate-action" data-feed-id="'+wppfm_escapeFeedListValue(e)+'" data-feed-name="'+wppfm_escapeFeedListValue(a)+'">'+wppfm_feed_list_form_vars.list_duplicate+"</a>"}function wppfm_feedDeactivateActionLink(e,t,a){var p=wppfm_escapeFeedListValue(e);return'<a href="javascript:void(0);" id="wppfm-deactivate-'+t+'-action" class="wppfm-feed-deactivate-action" data-feed-id="'+p+'" id="feed-status-switch-'+p+'">'+a+"</a>"}function wppfm_feedRegenerateActionLink(e,t){return'<a href="javascript:void(0);" id="wppfm-regenerate-'+t+'-action" class="wppfm-feed-regenerate-action" data-feed-id="'+wppfm_escapeFeedListValue(e)+'">'+wppfm_feed_list_form_vars.list_regenerate+"</a>"}function wppfmEndOfActionsCode(e,t,a,p){var r=" | "+wppfm_feedDuplicateActionLink(e,t,a);return(r+="product-feed"===wppfm_getFeedTypeSlug(p)?" | "+wppfm_feedRegenerateActionLink(e,t):"")+"</strong>"}function wppfm_emptyListTable(){var e="";return e+="<tr>",(e+="<td colspan = 4>"+wppfm_feed_list_form_vars.no_data_found+"</td>")+"</tr>"}function wppfm_updateFeedRowData(e){if("1"===e.status_id||"2"===e.status_id){var t=e.product_feed_id,a="1"===e.status_id?wppfm_feed_list_form_vars.ok:wppfm_feed_list_form_vars.other;jQuery("#updated-"+t).html(e.updated),jQuery("#products-"+t).html(e.products),jQuery("#wppfm-feed-list-actions-for-feed-"+t).html(feedReadyActions(t,e.url,a,e.title,e.feed_type_name,e.feed_type))}}function wppfm_sortOnColumn(e){for(var t=jQuery("tbody#wppfm-feed-list"),a=jQuery("#wppfm-feed-list-page-data-storage"),p=a.data("wppfmSortColumn"),r=a.data("wppfmSortDirection"),s=a.data("wppfmSortableColumns").split("-"),f=0;f<s.length;f++)e.toString()!==s[f]&&wppfm_resetSortableColumns(s[f]);t.find("tr").sort(function(t,s){var f=jQuery("td:nth-child("+e+")",t),d=jQuery("td:nth-child("+e+")",s);return a.data("wppfmSortColumn",e),p!==e||"asc"!==r&&"none"!==r?(a.data("wppfmSortDirection","asc"),f.text().localeCompare(d.text(),!1,{numeric:!0})):(a.data("wppfmSortDirection","desc"),d.text().localeCompare(f.text(),!1,{numeric:!0}))}).appendTo(t),wppfm_setSortedColumn(e),wppfm_redrawAlternateRowBackground()}function wppfm_redrawAlternateRowBackground(){jQuery("tbody#wppfm-feed-list tr:odd").removeClass("alternate"),jQuery("tbody#wppfm-feed-list tr:even").addClass("alternate")}function wppfm_setSortedColumn(e){var t=jQuery("table thead tr th:nth-child("+e+")");t.hasClass("asc")?t.removeClass("asc").addClass("desc"):t.removeClass("desc").addClass("asc"),t.removeClass("sortable").addClass("sorted")}function wppfm_resetSortableColumns(e){var t=jQuery("table thead tr th:nth-child("+e+")");t.removeClass("sorted").addClass("sortable"),t.removeClass("asc").addClass("desc")}function wppfm_switchStatusAction(e,t){var a=jQuery("#title-"+e).html(),p="";switch(a=a.replace(/\s+/g,"-").toLowerCase(),t=null!=t?t.toString().trim():""){case"1":p=" | Auto-off ";break;case"2":p=" | Auto-on "}jQuery("#wppfm-deactivate-"+a+"-action").html(p)}function wppfm_list_status_text(e){switch(e){case"unknown":return wppfm_feed_list_form_vars.unknown;case"ok":return wppfm_feed_list_form_vars.status_ok;case"on_hold":return wppfm_feed_list_form_vars.on_hold;case"processing":return wppfm_feed_list_form_vars.processing;case"in_processing_queue":return wppfm_feed_list_form_vars.processing_queue;case"has_errors":return wppfm_feed_list_form_vars.has_errors;case"failed_processing":return wppfm_feed_list_form_vars.failed_processing}}function wppfm_updateFeedRowStatus(e,t){var a=jQuery("#feed-status-"+e),p=jQuery("#feed-status-switch-"+e),r=jQuery("#products-"+e);switch(t){case 0:a.html("<strong>"+wppfm_feed_list_form_vars.unknown+"</strong>"),a.css("color","#6549F7"),p.html("");break;case 1:a.html("<strong>"+wppfm_feed_list_form_vars.ok+"</strong>"),a.css("color","#0073AA"),p.html(" | "+wppfm_feed_list_form_vars.list_deactivate+" ");break;case 2:a.html("<strong>"+wppfm_feed_list_form_vars.on_hold+"</strong>"),a.css("color","#0173AA"),p.html(" | "+wppfm_feed_list_form_vars.list_activate+" ");break;case 3:a.html("<strong>"+wppfm_feed_list_form_vars.processing+"</strong>"),a.css("color","#0000FF"),p.html(""),r.html(wppfm_feed_list_form_vars.processing_the_feed);break;case 4:a.html("<strong>"+wppfm_feed_list_form_vars.processing_queue+"</strong>"),a.css("color","#00CCFF"),p.html(wppfm_feed_list_form_vars.list_activate+" ");break;case 5:a.html("<strong>"+wppfm_feed_list_form_vars.has_errors+"</strong>"),a.css("color","#FF0000"),r.html(wppfm_feed_list_form_vars.unknown_text),p.html(wppfm_feed_list_form_vars.list_activate+" ");break;case 6:a.html("<strong>"+wppfm_feed_list_form_vars.processing_failed+"</strong>"),a.css("color","#FF3300"),r.html(wppfm_feed_list_form_vars.unknown_text),p.html("");break;case 7:a.html("<strong>"+wppfm_feed_list_form_vars.no_channel+"</strong>"),a.css("color","#FF3300"),r.html(wppfm_feed_list_form_vars.unknown_text),p.html("")}}jQuery(function(){jQuery(document).on("click","a.wppfm-feed-edit-action",function(e){e.preventDefault();var t=jQuery(this);parent.location="admin.php?page=wppfm-feed-editor-page&feed-type="+encodeURIComponent(t.attr("data-feed-type")||"")+"&id="+encodeURIComponent(t.attr("data-feed-id")||"")}),jQuery(document).on("click","a.wppfm-feed-view-action",function(e){e.preventDefault(),wppfm_viewFeed(jQuery(this).attr("data-feed-url"))}),jQuery(document).on("click","a.wppfm-feed-delete-action",function(e){e.preventDefault();var t=jQuery(this);wppfm_deleteSpecificFeed(t.attr("data-feed-id"),t.attr("data-feed-name"))}),jQuery(document).on("click","a.wppfm-feed-deactivate-action",function(e){e.preventDefault(),wppfm_deactivateFeed(jQuery(this).attr("data-feed-id"))}),jQuery(document).on("click","a.wppfm-feed-regenerate-action",function(e){e.preventDefault(),wppfm_regenerateFeed(jQuery(this).attr("data-feed-id"))}),jQuery(document).on("click","a.wppfm-feed-duplicate-action",function(e){e.preventDefault();var t=jQuery(this);wppfm_duplicateFeed(t.attr("data-feed-id"),t.attr("data-feed-name"))})}); -
wp-product-feed-manager/trunk/includes/user-interface/js/wppfm_setting-form.js
r3517383 r3820184 246 246 * Exports the backup file to the user's download folder. 247 247 * 248 * The file is streamed by an authenticated admin-post.php request instead of a direct link to the .sql file, 249 * because many servers and firewalls block public requests to .sql files. No download attribute is set, so a 250 * server error is shown to the user instead of being saved as the backup file. 251 * 248 252 * @param {string} fileName the file name. 249 253 */ 250 254 function wppfm_exportBackupFile( fileName ) { 251 255 const dataStorageElement = jQuery( '#wppfm-settings-page-data-storage' ); 252 const uploadDir = dataStorageElement.data( 'wppfmWpUploadsUrl' );256 const exportUrl = dataStorageElement.data( 'wppfmBackupExportUrl' ); 253 257 const link = document.createElement('a'); 254 258 255 link.href = uploadDir + '/wppfm-backups/' + fileName; 256 link.download = fileName; // Suggested file name for download. 259 link.href = exportUrl + '&file=' + encodeURIComponent( fileName ); 257 260 document.body.appendChild(link); 258 261 link.click(); -
wp-product-feed-manager/trunk/includes/user-interface/js/wppfm_setting-form.min.js
r3745889 r3820184 21 21 function wppfm_duplicateBackupFile(fileName){wppfm_showWorkingSpinner();wppfm_duplicateBackup(fileName,function(response){if('1'===response){wppfm_showSuccessMessage(wppfm_setting_form_vars.file_duplicated.replace('%backup_file_name%',fileName));console.log('Backup file duplicated'+response);wppfm_resetBackupsList();} 22 22 wppfm_hideWorkingSpinner();});} 23 function wppfm_exportBackupFile(fileName){const dataStorageElement=jQuery('#wppfm-settings-page-data-storage');const uploadDir=dataStorageElement.data('wppfmWpUploadsUrl');const link=document.createElement('a');link.href=uploadDir+'/wppfm-backups/'+fileName;link.download=fileName;document.body.appendChild(link);link.click();document.body.removeChild(link);alert(wppfm_setting_form_vars.how_to_import_backup_file);console.log('Exported the backup file'+fileName);}23 function wppfm_exportBackupFile(fileName){const dataStorageElement=jQuery('#wppfm-settings-page-data-storage');const exportUrl=dataStorageElement.data('wppfmBackupExportUrl');const link=document.createElement('a');link.href=exportUrl+'&file='+encodeURIComponent(fileName);document.body.appendChild(link);link.click();document.body.removeChild(link);alert(wppfm_setting_form_vars.how_to_import_backup_file);console.log('Exported the backup file'+fileName);} -
wp-product-feed-manager/trunk/includes/user-interface/wppfm-product-identifiers.php
r3642912 r3820184 58 58 */ 59 59 function wppfm_save_custom_fields( $post_id ) { 60 if ( ! wp_verify_nonce( filter_input( INPUT_POST, 'wppfm_exclude_from_feed_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 'wppfm_exclude_from_feed_nonce_action') || ! current_user_can( 'edit_post', $post_id ) ) {60 if ( ! wp_verify_nonce( filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME, FILTER_SANITIZE_FULL_SPECIAL_CHARS ), WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION ) || ! current_user_can( 'edit_post', $post_id ) ) { 61 61 return; 62 62 } … … 127 127 */ 128 128 function wppfm_save_variation_custom_fields( $variation_id, $id ) { 129 if ( ! wp_verify_nonce( filter_input( INPUT_POST, 'wppfm_exclude_from_feed_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 'wppfm_exclude_from_feed_nonce_action') || ! current_user_can( 'edit_post', $variation_id ) ) {129 if ( ! wp_verify_nonce( filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME, FILTER_SANITIZE_FULL_SPECIAL_CHARS ), WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION ) || ! current_user_can( 'edit_post', $variation_id ) ) { 130 130 return; 131 131 } -
wp-product-feed-manager/trunk/includes/user-interface/wppfm-woocommerce-actions.php
r3525603 r3820184 8 8 if ( ! defined( 'ABSPATH' ) ) { 9 9 exit; 10 } 11 12 /** Post meta key: product or variation excluded from feeds when set to "yes". */ 13 const WPPFM_EXCLUDE_FROM_FEED_META_KEY = 'wppfm_exclude_from_feed'; 14 15 /** POST field: simple product exclude checkbox. */ 16 const WPPFM_EXCLUDE_FROM_FEED_SIMPLE_FIELD = 'wppfm_exclude_from_feed'; 17 18 /** POST field: variable product parent exclude checkbox. */ 19 const WPPFM_EXCLUDE_FROM_FEED_PARENT_FIELD = 'wppfm_exclude_from_feed_parent'; 20 21 /** POST field: per-variation exclude checkboxes (variation ID keys). */ 22 const WPPFM_EXCLUDE_FROM_FEED_VARIATION_FIELD = 'wppfm_exclude_from_feed_variation'; 23 24 /** POST field: signals a bulk parent toggle that should sync all variations. */ 25 const WPPFM_EXCLUDE_FROM_FEED_BULK_SYNC_FIELD = 'wppfm_exclude_from_feed_parent_bulk_sync'; 26 27 /** POST field: baseline exclude state for all variations after a parent bulk toggle (before per-row overrides). */ 28 const WPPFM_EXCLUDE_FROM_FEED_BULK_INTENT_FIELD = 'wppfm_exclude_from_feed_parent_bulk_intent'; 29 30 /** Nonce action/name for Product Feed tab and related product meta saves. */ 31 const WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION = 'wppfm_exclude_from_feed_nonce_action'; 32 const WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME = 'wppfm_exclude_from_feed_nonce'; 33 34 /** Stored meta values for the exclude flag. */ 35 const WPPFM_EXCLUDE_FROM_FEED_VALUE_YES = 'yes'; 36 const WPPFM_EXCLUDE_FROM_FEED_VALUE_NO = 'no'; 37 38 /** 39 * Request-scoped cache for variation exclusion stats. 40 * 41 * @return array<int, array{total: int, excluded: int}> 42 */ 43 function &wppfm_excluded_variation_stats_cache() { 44 static $cache = array(); 45 46 return $cache; 47 } 48 49 /** 50 * Clears cached variation exclusion stats for one or all products. 51 * 52 * @param int|null $product_id Variable product ID, or null to clear all. 53 */ 54 function wppfm_clear_excluded_variation_stats_cache( $product_id = null ) { 55 $cache = &wppfm_excluded_variation_stats_cache(); 56 57 if ( null === $product_id ) { 58 $cache = array(); 59 return; 60 } 61 62 unset( $cache[ (int) $product_id ] ); 10 63 } 11 64 … … 26 79 27 80 /** 81 * Returns how many variations of a variable product are excluded from feeds. 82 * 83 * @param int $product_id Variable product ID. 84 * 85 * @return array{total: int, excluded: int} 86 */ 87 function wppfm_get_excluded_variation_stats( $product_id ) { 88 $product_id = (int) $product_id; 89 $cache = &wppfm_excluded_variation_stats_cache(); 90 91 if ( isset( $cache[ $product_id ] ) ) { 92 return $cache[ $product_id ]; 93 } 94 95 $product = wc_get_product( $product_id ); 96 97 if ( ! $product || ! $product->is_type( 'variable' ) ) { 98 $cache[ $product_id ] = array( 99 'total' => 0, 100 'excluded' => 0, 101 ); 102 103 return $cache[ $product_id ]; 104 } 105 106 $children = $product->get_children(); 107 108 if ( ! empty( $children ) ) { 109 update_meta_cache( 'post', $children ); 110 } 111 112 $excluded = 0; 113 114 foreach ( $children as $child_id ) { 115 if ( WPPFM_EXCLUDE_FROM_FEED_VALUE_YES === get_post_meta( (int) $child_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, true ) ) { 116 ++$excluded; 117 } 118 } 119 120 $cache[ $product_id ] = array( 121 'total' => count( $children ), 122 'excluded' => $excluded, 123 ); 124 125 return $cache[ $product_id ]; 126 } 127 128 /** 129 * Updates the parent product exclude meta to reflect variation exclusion counts. 130 * 131 * @param int $product_id Variable product ID. 132 */ 133 function wppfm_sync_parent_exclude_meta_from_variations( $product_id ) { 134 wppfm_clear_excluded_variation_stats_cache( $product_id ); 135 136 $stats = wppfm_get_excluded_variation_stats( $product_id ); 137 $value = $stats['excluded'] > 0 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 138 139 update_post_meta( $product_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $value ); 140 } 141 142 /** 143 * Queues a single parent meta sync at shutdown (avoids N full rescans during variation batch saves). 144 * 145 * @param int $product_id Variable product ID. 146 */ 147 function wppfm_queue_parent_exclude_meta_sync( $product_id ) { 148 $product_id = (int) $product_id; 149 150 if ( $product_id <= 0 ) { 151 return; 152 } 153 154 $queue = &wppfm_parent_exclude_meta_sync_queue(); 155 $queue[ $product_id ] = true; 156 157 if ( ! has_action( 'shutdown', 'wppfm_process_queued_parent_exclude_meta_sync' ) ) { 158 add_action( 'shutdown', 'wppfm_process_queued_parent_exclude_meta_sync', 5 ); 159 } 160 } 161 162 /** 163 * Product IDs queued for parent exclude meta sync on shutdown. 164 * 165 * @return array<int, bool> 166 */ 167 function &wppfm_parent_exclude_meta_sync_queue() { 168 static $queue = array(); 169 170 return $queue; 171 } 172 173 /** 174 * Runs queued parent exclude meta syncs once per request. 175 */ 176 function wppfm_process_queued_parent_exclude_meta_sync() { 177 $queue = &wppfm_parent_exclude_meta_sync_queue(); 178 179 foreach ( array_keys( $queue ) as $product_id ) { 180 wppfm_sync_parent_exclude_meta_from_variations( (int) $product_id ); 181 } 182 183 $queue = array(); 184 } 185 186 /** 187 * Checks whether a variation exclude checkbox was posted for a given variation. 188 * 189 * WooCommerce may submit variation data through AJAX (only changed rows) or through a full 190 * product save. Keys may be numeric strings depending on the serializer. 191 * 192 * @param int $variation_id Variation post ID. 193 * 194 * @return bool 195 */ 196 function wppfm_is_variation_marked_excluded_in_post( $variation_id ) { 197 $variation_id = (int) $variation_id; 198 199 if ( ! wppfm_verify_wc_product_exclude_post_context( $variation_id ) ) { 200 return false; 201 } 202 203 $variation_input = filter_input_array( 204 INPUT_POST, 205 array( 206 WPPFM_EXCLUDE_FROM_FEED_VARIATION_FIELD => array( 207 'filter' => FILTER_DEFAULT, 208 'flags' => FILTER_REQUIRE_ARRAY, 209 ), 210 ) 211 ); 212 213 $posted = $variation_input[ WPPFM_EXCLUDE_FROM_FEED_VARIATION_FIELD ] ?? null; 214 215 if ( ! is_array( $posted ) ) { 216 return false; 217 } 218 219 return array_key_exists( $variation_id, $posted ) || array_key_exists( (string) $variation_id, $posted ); 220 } 221 222 /** 223 * Verifies the exclude-from-feed nonce and edit capability for a post. 224 * 225 * @param int $post_id Post ID. 226 * 227 * @return bool 228 */ 229 function wppfm_verify_exclude_from_feed_save_request( $post_id ) { 230 return wp_verify_nonce( 231 filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME, FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 232 WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION 233 ) && current_user_can( 'edit_post', $post_id ); 234 } 235 236 /** 237 * Whether the current request is an authenticated WooCommerce product save that may carry exclude fields. 238 * 239 * Accepts the Product Feed nonce, WooCommerce product meta nonce, or the AJAX save-variations nonce. 240 * 241 * @param int $post_id Optional post ID to require edit capability (0 to skip). 242 * 243 * @return bool 244 */ 245 function wppfm_verify_wc_product_exclude_post_context( $post_id = 0 ) { 246 $post_id = (int) $post_id; 247 248 if ( wp_verify_nonce( 249 filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME, FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 250 WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION 251 ) ) { 252 return 0 === $post_id || current_user_can( 'edit_post', $post_id ); 253 } 254 255 $woocommerce_meta_nonce = filter_input( INPUT_POST, 'woocommerce_meta_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 256 257 if ( is_string( $woocommerce_meta_nonce ) && wp_verify_nonce( $woocommerce_meta_nonce, 'woocommerce_save_data' ) ) { 258 return 0 === $post_id || current_user_can( 'edit_post', $post_id ); 259 } 260 261 $ajax_security = filter_input( INPUT_POST, 'security', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 262 263 if ( is_string( $ajax_security ) && wp_verify_nonce( $ajax_security, 'save-variations' ) ) { 264 return 0 === $post_id || current_user_can( 'edit_post', $post_id ); 265 } 266 267 return false; 268 } 269 270 /** 271 * Whether the current request is a variable-product bulk exclude sync from the Product Feed tab. 272 * 273 * @return bool 274 */ 275 function wppfm_is_exclude_from_feed_bulk_sync_request() { 276 $bulk_sync_input = filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_BULK_SYNC_FIELD, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 277 278 return '1' === $bulk_sync_input; 279 } 280 281 /** 282 * Reads the persisted bulk exclude baseline from POST (set when the parent checkbox is toggled). 283 * 284 * @return string WPPFM_EXCLUDE_FROM_FEED_VALUE_YES, VALUE_NO, or empty string when unset. 285 */ 286 function wppfm_get_exclude_from_feed_bulk_intent_post_value() { 287 $intent = filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_BULK_INTENT_FIELD, FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 288 289 if ( WPPFM_EXCLUDE_FROM_FEED_VALUE_YES === $intent || WPPFM_EXCLUDE_FROM_FEED_VALUE_NO === $intent ) { 290 return $intent; 291 } 292 293 return ''; 294 } 295 296 /** 297 * Variation IDs included in the current product or variation save request. 298 * 299 * @return int[] 300 */ 301 function wppfm_get_variation_ids_from_product_save_post() { 302 if ( ! wppfm_verify_wc_product_exclude_post_context() ) { 303 return array(); 304 } 305 306 $variable_ids_input = filter_input_array( 307 INPUT_POST, 308 array( 309 'variable_post_id' => array( 310 'filter' => FILTER_VALIDATE_INT, 311 'flags' => FILTER_REQUIRE_ARRAY, 312 ), 313 ) 314 ); 315 316 $raw_ids = $variable_ids_input['variable_post_id'] ?? null; 317 318 if ( ! is_array( $raw_ids ) || empty( $raw_ids ) ) { 319 return array(); 320 } 321 322 return array_values( array_filter( array_map( 'absint', $raw_ids ) ) ); 323 } 324 325 /** 326 * Applies posted per-variation exclude checkbox values for the given variation IDs. 327 * 328 * @param int[] $variation_ids Variation post IDs to update from POST. 329 */ 330 function wppfm_apply_posted_variation_exclude_meta_for_ids( array $variation_ids ) { 331 foreach ( $variation_ids as $variation_id ) { 332 $variation_id = (int) $variation_id; 333 334 if ( $variation_id <= 0 ) { 335 continue; 336 } 337 338 $exclude_variation = wppfm_is_variation_marked_excluded_in_post( $variation_id ) 339 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES 340 : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 341 342 update_post_meta( $variation_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $exclude_variation ); 343 } 344 } 345 346 /** 347 * Applies a bulk exclude baseline to every child variation, then POST overrides for rows in the request. 348 * 349 * @param WC_Product $product Variable product. 350 * @param string $baseline WPPFM_EXCLUDE_FROM_FEED_VALUE_YES or VALUE_NO. 351 */ 352 function wppfm_apply_variable_exclude_bulk_intent_with_post_overrides( $product, $baseline ) { 353 foreach ( $product->get_children() as $child_id ) { 354 update_post_meta( (int) $child_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $baseline ); 355 } 356 357 $posted_variation_ids = wppfm_get_variation_ids_from_product_save_post(); 358 359 if ( ! empty( $posted_variation_ids ) ) { 360 wppfm_apply_posted_variation_exclude_meta_for_ids( $posted_variation_ids ); 361 } 362 363 wppfm_sync_parent_exclude_meta_from_variations( $product->get_id() ); 364 wppfm_clear_excluded_variation_stats_cache( $product->get_id() ); 365 } 366 367 /** 368 * Reads the variable-product parent exclude checkbox from POST (hidden "no" + optional checked "yes"). 369 * 370 * @return string WPPFM_EXCLUDE_FROM_FEED_VALUE_YES or WPPFM_EXCLUDE_FROM_FEED_VALUE_NO. 371 */ 372 function wppfm_get_parent_exclude_from_feed_post_value() { 373 if ( ! wppfm_verify_wc_product_exclude_post_context() ) { 374 return WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 375 } 376 377 $posted = filter_input( 378 INPUT_POST, 379 WPPFM_EXCLUDE_FROM_FEED_PARENT_FIELD, 380 FILTER_DEFAULT, 381 FILTER_REQUIRE_ARRAY 382 ); 383 384 if ( false === $posted || null === $posted ) { 385 $posted = filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_PARENT_FIELD, FILTER_DEFAULT ); 386 } 387 388 if ( null === $posted || false === $posted ) { 389 return WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 390 } 391 392 if ( is_array( $posted ) ) { 393 return in_array( WPPFM_EXCLUDE_FROM_FEED_VALUE_YES, $posted, true ) 394 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES 395 : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 396 } 397 398 return WPPFM_EXCLUDE_FROM_FEED_VALUE_YES === $posted 399 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES 400 : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 401 } 402 403 /** 404 * Enqueues the product edit script that syncs parent and variation exclude controls. 405 * 406 * @param string $hook_suffix Current admin page hook suffix. 407 */ 408 function wppfm_enqueue_product_exclude_from_feed_script( $hook_suffix ) { 409 if ( 'post.php' !== $hook_suffix && 'post-new.php' !== $hook_suffix ) { 410 return; 411 } 412 413 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; 414 415 if ( ! $screen || 'product' !== $screen->post_type ) { 416 return; 417 } 418 419 $script_suffix = defined( 'WP_DEBUG' ) && WP_DEBUG ? '' : '.min'; 420 421 wp_enqueue_script( 422 'wppfm-product-exclude-from-feed', 423 WPPFM_PLUGIN_URL . '/includes/user-interface/js/wppfm-product-exclude-from-feed' . $script_suffix . '.js', 424 array( 'jquery' ), 425 WPPFM_VERSION_NUM, 426 true 427 ); 428 429 $variation_stats = array( 430 'excluded' => 0, 431 'total' => 0, 432 ); 433 434 if ( 'post.php' === $hook_suffix ) { 435 global $post; 436 437 if ( $post && 'product' === $post->post_type ) { 438 $product = wc_get_product( $post->ID ); 439 440 if ( $product && $product->is_type( 'variable' ) ) { 441 $variation_stats = wppfm_get_excluded_variation_stats( $post->ID ); 442 } 443 } 444 } 445 446 wp_localize_script( 447 'wppfm-product-exclude-from-feed', 448 'wppfmExcludeFromFeed', 449 array( 450 /* translators: 1: Number of excluded variations, 2: Total number of variations. */ 451 'partialSummaryTemplate' => __( '%1$d of %2$d variations are excluded from the feed.', 'wp-product-feed-manager' ), 452 'variationStats' => $variation_stats, 453 ) 454 ); 455 456 wp_enqueue_style( 457 'wppfm-product-exclude-from-feed-admin', 458 WPPFM_PLUGIN_URL . '/includes/user-interface/css/wppfm-product-exclude-from-feed-admin.css', 459 array(), 460 WPPFM_VERSION_NUM 461 ); 462 } 463 464 add_action( 'admin_enqueue_scripts', 'wppfm_enqueue_product_exclude_from_feed_script' ); 465 466 /** 467 * Outputs hidden Product Feed save fields on the admin product edit screen (General tab). 468 * 469 * The storefront `woocommerce_product_meta_start` hook does not run in admin, so these fields 470 * must live on a product-data panel that is always part of the post form. 471 */ 472 function wppfm_product_edit_exclude_from_feed_hidden_fields() { 473 echo '<input type="hidden" name="' . esc_attr( WPPFM_EXCLUDE_FROM_FEED_NONCE_NAME ) . '" value="' . esc_attr( wp_create_nonce( WPPFM_EXCLUDE_FROM_FEED_NONCE_ACTION ) ) . '" />'; 474 echo '<input type="hidden" id="wppfm-exclude-from-feed-parent-bulk-sync" name="' . esc_attr( WPPFM_EXCLUDE_FROM_FEED_BULK_SYNC_FIELD ) . '" value="0" />'; 475 echo '<input type="hidden" id="wppfm-exclude-from-feed-parent-bulk-intent" name="' . esc_attr( WPPFM_EXCLUDE_FROM_FEED_BULK_INTENT_FIELD ) . '" value="" />'; 476 } 477 478 add_action( 'woocommerce_product_options_general_product_data', 'wppfm_product_edit_exclude_from_feed_hidden_fields', 5 ); 479 480 /** 481 * Renders the variable-product exclude checkbox with a two-line clickable label next to the input. 482 * 483 * @param string $checked_value Stored checkbox value. 484 * @param string $description Primary label description line. 485 */ 486 function wppfm_render_variable_exclude_from_feed_checkbox( $checked_value, $description ) { 487 $checkbox_id = 'wppfm-exclude-from-feed-checkbox-variable'; 488 ?> 489 <p class="form-field <?php echo esc_attr( $checkbox_id ); ?>_field show_if_variable"> 490 <label for="<?php echo esc_attr( $checkbox_id ); ?>"> 491 <?php esc_html_e( 'Exclude from Feed', 'wp-product-feed-manager' ); ?> 492 </label> 493 <input type="hidden" name="<?php echo esc_attr( WPPFM_EXCLUDE_FROM_FEED_PARENT_FIELD ); ?>" value="<?php echo esc_attr( WPPFM_EXCLUDE_FROM_FEED_VALUE_NO ); ?>" /> 494 <input 495 type="checkbox" 496 class="checkbox" 497 name="<?php echo esc_attr( WPPFM_EXCLUDE_FROM_FEED_PARENT_FIELD ); ?>" 498 id="<?php echo esc_attr( $checkbox_id ); ?>" 499 value="<?php echo esc_attr( WPPFM_EXCLUDE_FROM_FEED_VALUE_YES ); ?>" 500 <?php checked( $checked_value, WPPFM_EXCLUDE_FROM_FEED_VALUE_YES ); ?> 501 /> 502 <label class="description wppfm-exclude-from-feed-description-label" for="<?php echo esc_attr( $checkbox_id ); ?>"> 503 <?php echo esc_html( $description ); ?> 504 <br /> 505 <span id="wppfm-exclude-from-feed-variation-summary" class="wppfm-exclude-from-feed-variation-summary" aria-live="polite"></span> 506 </label> 507 </p> 508 <?php 509 } 510 511 /** 28 512 * Renders the Product Feed tab content. Triggered by the 'woocommerce_product_data_panels' action. 29 513 * … … 31 515 */ 32 516 function wppfm_render_product_feed_tab() { 33 // The Product Feed tab content 517 $product_id = get_the_ID(); 518 $stats = wppfm_get_excluded_variation_stats( $product_id ); 519 520 $variable_parent_checked = $stats['excluded'] > 0 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 521 $variable_description = esc_html__( 'Activate this option to exclude all variations from the feed. Use the Feed Manager Product Filter to remove marked products from feeds.', 'wp-product-feed-manager' ); 522 34 523 ?> 35 524 <div id="wppfm_product_feed_tab" class="panel woocommerce_options_panel"> 36 525 <?php 37 woocommerce_wp_checkbox( array( 38 'id' => 'wppfm-exclude-from-feed-checkbox', 39 'name' => 'wppfm_exclude_from_feed', 40 'wrapper_class' => 'show_if_simple show_if_variable', 41 'value' => get_post_meta( get_the_ID(), 'wppfm_exclude_from_feed', true ), 42 'label' => esc_html__( 'Exclude from Feed', 'wp-product-feed-manager' ), 43 'description' => esc_html__( 'Activate this option to mark this product for exclusion. Use the Feed Manager Product Filter to remove marked products from feeds', 'wp-product-feed-manager' ), 44 'default' => '0', 45 'desc_tip' => false, 46 ) ); 47 48 // Adding a nonce field to the form 49 wp_nonce_field( 'wppfm_exclude_from_feed_nonce_action', 'wppfm_exclude_from_feed_nonce' ); 526 woocommerce_wp_checkbox( 527 array( 528 'id' => 'wppfm-exclude-from-feed-checkbox', 529 'name' => WPPFM_EXCLUDE_FROM_FEED_SIMPLE_FIELD, 530 'wrapper_class' => 'show_if_simple', 531 'value' => get_post_meta( $product_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, true ), 532 'label' => esc_html__( 'Exclude from Feed', 'wp-product-feed-manager' ), 533 'description' => esc_html__( 'Activate this option to mark this product for exclusion. Use the Feed Manager Product Filter to remove marked products from feeds', 'wp-product-feed-manager' ), 534 'default' => '0', 535 'desc_tip' => false, 536 ) 537 ); 538 539 wppfm_render_variable_exclude_from_feed_checkbox( $variable_parent_checked, $variable_description ); 50 540 51 541 do_action( 'wppfm_woocommerce_product_feed_panel' ); … … 65 555 */ 66 556 function wppfm_save_custom_product_feed_exclusion_checkbox( $post_id ) { 67 if ( wp_verify_nonce( filter_input( INPUT_POST, 'wppfm_exclude_from_feed_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 'wppfm_exclude_from_feed_nonce_action' ) && current_user_can( 'edit_post', $post_id ) ) { 68 $exclude_product = isset( $_POST['wppfm_exclude_from_feed'] ) ? 'yes' : 'no'; 69 update_post_meta( $post_id, 'wppfm_exclude_from_feed', $exclude_product ); 70 } 557 if ( ! wppfm_verify_exclude_from_feed_save_request( $post_id ) ) { 558 return; 559 } 560 561 $product = wc_get_product( $post_id ); 562 563 if ( ! $product ) { 564 return; 565 } 566 567 if ( $product->is_type( 'variable' ) ) { 568 if ( wppfm_is_exclude_from_feed_bulk_sync_request() ) { 569 $exclude_all = wppfm_get_parent_exclude_from_feed_post_value(); 570 571 foreach ( $product->get_children() as $child_id ) { 572 update_post_meta( (int) $child_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $exclude_all ); 573 } 574 575 update_post_meta( $post_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $exclude_all ); 576 wppfm_clear_excluded_variation_stats_cache( $post_id ); 577 578 return; 579 } 580 581 $bulk_intent = wppfm_get_exclude_from_feed_bulk_intent_post_value(); 582 583 if ( '' !== $bulk_intent ) { 584 wppfm_apply_variable_exclude_bulk_intent_with_post_overrides( $product, $bulk_intent ); 585 586 return; 587 } 588 589 // Per-variation values are saved in wppfm_process_variation_exclude_from_feed_object(). 590 return; 591 } 592 593 $exclude_product = null !== filter_input( INPUT_POST, WPPFM_EXCLUDE_FROM_FEED_SIMPLE_FIELD, FILTER_DEFAULT ) 594 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES 595 : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 596 597 update_post_meta( $post_id, WPPFM_EXCLUDE_FROM_FEED_META_KEY, $exclude_product ); 71 598 } 72 599 … … 78 605 * @param int $loop iteration count of the variations. 79 606 * @param array $variation_data the variation data. 80 * @param WP_P OST$variation the variation object.607 * @param WP_Post $variation the variation object. 81 608 * 82 609 * @since 3.12.0. - Added a nonce field to the checkbox form. 83 * @noinspection PhpUnusedParameterInspection*/ 610 * @noinspection PhpUnusedParameterInspection 611 */ 84 612 function wppfm_add_custom_select_to_variations( $loop, $variation_data, $variation ) { 85 $exclude_variation_checked = get_post_meta( $variation->ID, 'wppfm_exclude_from_feed', true ); 86 87 ?><label class="tips" data-tip="<?php esc_attr_e( 'Activate this option to mark this product variation for exclusion. Use the Feed Manager Product Filter to remove marked products from feeds', 'wp-product-feed-manager' ); ?>"> 613 unset( $loop, $variation_data ); 614 615 if ( empty( $variation->ID ) ) { 616 return; 617 } 618 619 $exclude_variation_checked = get_post_meta( $variation->ID, WPPFM_EXCLUDE_FROM_FEED_META_KEY, true ); 620 621 ?> 622 <label class="tips" data-tip="<?php esc_attr_e( 'Activate this option to mark this product variation for exclusion. Use the Feed Manager Product Filter to remove marked products from feeds', 'wp-product-feed-manager' ); ?>"> 88 623 <?php esc_html_e( 'Exclude from Feed', 'wp-product-feed-manager' ); ?> 89 <input type="checkbox" class="checkbox variable_exclude_from_feed" name="wppfm_exclude_from_feed[<?php esc_attr( $loop ) ?>]" <?php checked( $exclude_variation_checked, 'yes' ); ?> /> 90 <?php wp_nonce_field( 'wppfm_exclude_from_feed_nonce_action', 'wppfm_exclude_from_feed_nonce' ); ?> 91 </label><?php 624 <input 625 type="checkbox" 626 class="checkbox variable_exclude_from_feed" 627 name="<?php echo esc_attr( WPPFM_EXCLUDE_FROM_FEED_VARIATION_FIELD . '[' . (string) $variation->ID . ']' ); ?>" 628 value="1" 629 <?php checked( $exclude_variation_checked, WPPFM_EXCLUDE_FROM_FEED_VALUE_YES ); ?> 630 /> 631 </label> 632 <?php 92 633 } 93 634 … … 95 636 96 637 /** 97 * Saves the checkbox value for variations. Triggered by the 'woocommerce_save_product_variation' action. 98 * 99 * @param string $variation_id the ID of the variation. 100 * @param int $loop iteration count of the variations. 101 * 102 * @since 3.12.0. - Added a nonce check. 103 */ 104 function wppfm_save_custom_variation_feed_exclusion_checkbox( $variation_id, $loop ) { 105 if ( wp_verify_nonce( filter_input( INPUT_POST, 'wppfm_exclude_from_feed_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), 'wppfm_exclude_from_feed_nonce_action' ) && current_user_can( 'edit_post', $variation_id ) ) { 106 $exclude_variation = isset( $_POST['wppfm_exclude_from_feed'][0] ) ? 'yes' : 'no'; 107 update_post_meta( $variation_id, 'wppfm_exclude_from_feed', $exclude_variation ); 108 } 109 } 110 111 add_action( 'woocommerce_save_product_variation', 'wppfm_save_custom_variation_feed_exclusion_checkbox', 10, 2 ); 638 * Saves variation exclude meta during WooCommerce's variation save routine. 639 * 640 * Uses woocommerce_admin_process_variation_object so saves work for AJAX variation updates 641 * (which do not include the Product Feed tab nonce in the request payload). 642 * 643 * @param WC_Product_Variation $variation Variation product object. 644 * @param int $loop Variation loop index in the current save request. 645 * 646 * @since 3.16.0 647 */ 648 function wppfm_process_variation_exclude_from_feed_object( $variation, $loop ) { 649 unset( $loop ); 650 651 if ( ! $variation instanceof WC_Product_Variation ) { 652 return; 653 } 654 655 // Bulk parent sync updates every variation in wppfm_save_custom_product_feed_exclusion_checkbox(). 656 if ( wppfm_is_exclude_from_feed_bulk_sync_request() ) { 657 return; 658 } 659 660 // Main product save applies bulk intent (all children + POST overrides) in one pass. 661 if ( '' !== wppfm_get_exclude_from_feed_bulk_intent_post_value() ) { 662 return; 663 } 664 665 $variation_id = $variation->get_id(); 666 667 if ( ! $variation_id || ! current_user_can( 'edit_post', $variation_id ) ) { 668 return; 669 } 670 671 $exclude_variation = wppfm_is_variation_marked_excluded_in_post( $variation_id ) 672 ? WPPFM_EXCLUDE_FROM_FEED_VALUE_YES 673 : WPPFM_EXCLUDE_FROM_FEED_VALUE_NO; 674 675 $variation->update_meta_data( WPPFM_EXCLUDE_FROM_FEED_META_KEY, $exclude_variation ); 676 } 677 678 add_action( 'woocommerce_admin_process_variation_object', 'wppfm_process_variation_exclude_from_feed_object', 10, 2 ); 679 680 /** 681 * Schedules a deferred parent meta sync after a variation save completes. 682 * 683 * @param int $variation_id Variation post ID. 684 * @param int $loop Variation loop index. 685 */ 686 function wppfm_schedule_parent_exclude_meta_sync( $variation_id, $loop ) { 687 unset( $loop ); 688 689 $parent_id = wp_get_post_parent_id( $variation_id ); 690 691 if ( $parent_id ) { 692 wppfm_queue_parent_exclude_meta_sync( (int) $parent_id ); 693 } 694 } 695 696 add_action( 'woocommerce_save_product_variation', 'wppfm_schedule_parent_exclude_meta_sync', 99, 2 ); -
wp-product-feed-manager/trunk/readme.txt
r3792175 r3820184 6 6 Tested up to: 7.1 7 7 Requires PHP: 7.4 8 Stable tag: 2.2 4.28 Stable tag: 2.25.0 9 9 License: GPL-3.0-or-later 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 226 226 227 227 == Changelog == 228 = 2.25.0 2026-11-24 = 229 Fix - Fixed a vulnerability issue with the Feed Title 230 Fix - Fixed several issues with the "exclude from feed" functionality 231 Tweak - Changed the way the export of a backup file was send to the user 232 Tweak - Added additional xml filtering to the feed generation process 233 Tested - Tested up to WooCommerce 11.3.1. 234 228 235 = 2.24.2 2026-11-03 = 229 236 Fix - Fixed a vulnerability issue in the Review Feed generation process … … 503 510 504 511 === Upgrade Notice === 505 = 2.2 4.2 2026-11-03=512 = 2.25.0 2026-11-24 = 506 513 * Important: This update introduces additional tweaks and some bug fixes. We strongly recommend backing up your existing feeds before upgrading. -
wp-product-feed-manager/trunk/wp-product-feed-manager.php
r3792175 r3820184 8 8 * Developer: Michel Jongbloed 9 9 * Developer URI: https://www.wpmarketingrobot.com 10 * Version: 2.2 4.211 * Modified: 2 3-10-202610 * Version: 2.25.0 11 * Modified: 24-11-2026 12 12 * WC requires at least: 8.4 13 * WC tested up to: 11. 2.113 * WC tested up to: 11.3.1 14 14 * License: GPL-3.0-or-later 15 15 * License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 29 29 * Requires at least: 6.5 30 30 * Requires Plugins: woocommerce 31 * Tested up to: 7.132 31 * 33 32 * @package WordPress … … 40 39 exit; 41 40 } 41 42 /** 43 * Declares compatibility with WooCommerce HPOS (custom order tables). 44 * 45 * Registered at bootstrap so WooCommerce always receives the main plugin file path. 46 * 47 * @since 2.36.0 48 */ 49 function wppfm_declare_woocommerce_hpos_compatibility() { 50 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 51 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__ ); 52 } 53 } 54 55 add_action( 'before_woocommerce_init', 'wppfm_declare_woocommerce_hpos_compatibility' ); 42 56 43 57 if ( ! class_exists( 'WP_Product_Feed_Manager' ) ) : … … 55 69 * @var string Containing the version number of the plugin. 56 70 */ 57 public $version = '2.2 4.2';71 public $version = '2.25.0'; 58 72 59 73 /** … … 134 148 add_filter( 'load_textdomain_mofile', array( $this, 'prefer_bundled_translations' ), 10, 2 ); 135 149 136 // Declare compatibility with custom order tables.137 add_action( 'before_woocommerce_init', array( $this, 'declare_compatibility_for_custom_order_tables' ) );138 139 150 // Invalidate custom product fields cache when third-party keywords option changes. 140 151 add_action( 'update_option_wppfm_third_party_attribute_keywords', array( $this, 'invalidate_custom_product_fields_cache' ), 10, 3 ); … … 298 309 299 310 // Include the admin menu and the includes file. 311 require_once __DIR__ . '/includes/application/wppfm-xml-text-functions.php'; 300 312 require_once __DIR__ . '/includes/application/wppfm-feed-processing-support.php'; 301 313 require_once __DIR__ . '/includes/application/wppfm-feed-product-counter.php'; … … 304 316 require_once __DIR__ . '/includes/user-interface/wppfm-admin-menu-functions.php'; 305 317 require_once __DIR__ . '/includes/user-interface/wppfm-admin-actions.php'; 318 require_once __DIR__ . '/includes/user-interface/wppfm-backup-export-actions.php'; // @since 3.25.0 306 319 require_once __DIR__ . '/includes/user-interface/wppfm-edit-feed-form-functions.php'; 307 320 require_once __DIR__ . '/includes/user-interface/wppfm-admin-filters.php'; … … 370 383 delete_transient( 'wppfm_custom_product_fields_' . md5( (string) $old_value ) ); 371 384 delete_transient( 'wppfm_custom_product_fields_' . md5( (string) $value ) ); 372 }373 374 /**375 * Registers a dismiss notice action, declaring compatibility with the WooCommerce custom order tables feature.376 *377 * @since 2.36.0378 * @noinspection PhpFullyQualifiedNameUsageInspection379 */380 public function declare_compatibility_for_custom_order_tables() {381 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {382 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__ );383 }384 385 } 385 386
Note:
See TracChangeset
for help on using the changeset viewer.