diff --git a/build/dev/web-default-conf-cm.yaml b/build/dev/web-default-conf-cm.yaml index ea7ee92a..4beead79 100644 --- a/build/dev/web-default-conf-cm.yaml +++ b/build/dev/web-default-conf-cm.yaml @@ -147,6 +147,7 @@ data: } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 7d; proxy_set_header X-Forwarded-Proto $scheme; fastcgi_cache MYAPP; fastcgi_cache_valid 200 302 60m; diff --git a/build/prod/web-default-conf-cm.yaml b/build/prod/web-default-conf-cm.yaml index 67dd52d3..24d9736f 100644 --- a/build/prod/web-default-conf-cm.yaml +++ b/build/prod/web-default-conf-cm.yaml @@ -266,6 +266,7 @@ data: } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 7d; proxy_set_header X-Forwarded-Proto $scheme; fastcgi_cache MYAPP; fastcgi_cache_valid 200 302 60m; diff --git a/build/qa/web-default-conf-cm.yaml b/build/qa/web-default-conf-cm.yaml index 95958c6e..65610d16 100644 --- a/build/qa/web-default-conf-cm.yaml +++ b/build/qa/web-default-conf-cm.yaml @@ -266,6 +266,7 @@ data: } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 7d; proxy_set_header X-Forwarded-Proto $scheme; fastcgi_cache MYAPP; fastcgi_cache_valid 200 302 60m; diff --git a/build/stage/web-default-conf-cm.yaml b/build/stage/web-default-conf-cm.yaml index 18aa7519..ce87a944 100644 --- a/build/stage/web-default-conf-cm.yaml +++ b/build/stage/web-default-conf-cm.yaml @@ -266,6 +266,7 @@ data: } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 7d; proxy_set_header X-Forwarded-Proto $scheme; fastcgi_cache MYAPP; fastcgi_cache_valid 200 302 60m; diff --git a/wp/pantheon.upstream.yml b/wp/pantheon.upstream.yml index ec2d615f..fe69d377 100644 --- a/wp/pantheon.upstream.yml +++ b/wp/pantheon.upstream.yml @@ -3,7 +3,7 @@ # Override the defaults specified here in a site-specific `pantheon.yml` file. # For more information see: https://pantheon.io/docs/pantheon-upstream-yml api_version: 1 -php_version: 8.1 +php_version: 7.4 # See https://pantheon.io/docs/pantheon-yml#specify-a-version-of-mariadb database: diff --git a/wp/pantheon.yml b/wp/pantheon.yml index ca64f39e..d7a87d68 100644 --- a/wp/pantheon.yml +++ b/wp/pantheon.yml @@ -1,6 +1,5 @@ api_version: 1 enforce_https: full+subdomains -php_version: 7.4 protected_web_paths: - /.user.ini diff --git a/wp/wp-admin/about.php b/wp/wp-admin/about.php index e0c24c99..4e2779d3 100644 --- a/wp/wp-admin/about.php +++ b/wp/wp-admin/about.php @@ -42,37 +42,6 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; - -
-
-

-

- Version %1$s addressed %2$s bug.', - 'Version %1$s addressed %2$s bugs.', - 10 - ), - '6.3.1', - '10' - ); - ?> - the release notes.' ), - sprintf( - /* translators: %s: WordPress version. */ - esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ), - sanitize_title( '6.3.1' ) - ) - ); - ?> -

-
-
diff --git a/wp/wp-admin/includes/class-wp-site-health.php b/wp/wp-admin/includes/class-wp-site-health.php index a0e1de58..eda8bfaa 100644 --- a/wp/wp-admin/includes/class-wp-site-health.php +++ b/wp/wp-admin/includes/class-wp-site-health.php @@ -1943,6 +1943,10 @@ class WP_Site_Health { public function get_test_available_updates_disk_space() { $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false; + $available_space = false !== $available_space + ? (int) $available_space + : 0; + $result = array( 'label' => __( 'Disk space available to safely perform updates' ), 'status' => 'good', @@ -1959,14 +1963,18 @@ class WP_Site_Health { 'test' => 'available_updates_disk_space', ); - if ( false === $available_space ) { - $result['description'] = __( 'Could not determine available disk space for updates.' ); + if ( $available_space < 100 * MB_IN_BYTES ) { + $result['description'] = __( 'Available disk space is low, less than 100 MB available.' ); $result['status'] = 'recommended'; - } elseif ( $available_space < 20 * MB_IN_BYTES ) { + } + + if ( $available_space < 20 * MB_IN_BYTES ) { $result['description'] = __( 'Available disk space is critically low, less than 20 MB available. Proceed with caution, updates may fail.' ); $result['status'] = 'critical'; - } elseif ( $available_space < 100 * MB_IN_BYTES ) { - $result['description'] = __( 'Available disk space is low, less than 100 MB available.' ); + } + + if ( ! $available_space ) { + $result['description'] = __( 'Could not determine available disk space for updates.' ); $result['status'] = 'recommended'; } diff --git a/wp/wp-admin/includes/update-core.php b/wp/wp-admin/includes/update-core.php index 6085b02c..8d672199 100644 --- a/wp/wp-admin/includes/update-core.php +++ b/wp/wp-admin/includes/update-core.php @@ -1431,13 +1431,9 @@ function update_core( $from, $to ) { } else { $lang_dir = WP_CONTENT_DIR . '/languages'; } - /* - * Note: str_starts_with() is not used here, as this file is included - * when updating from older WordPress versions, in which case - * the polyfills from wp-includes/compat.php may not be available. - */ + // Check if the language directory exists first. - if ( ! @is_dir( $lang_dir ) && 0 === strpos( $lang_dir, ABSPATH ) ) { + if ( ! @is_dir( $lang_dir ) && str_starts_with( $lang_dir, ABSPATH ) ) { // If it's within the ABSPATH we can handle it here, otherwise they're out of luck. $wp_filesystem->mkdir( $to . str_replace( ABSPATH, '', $lang_dir ), FS_CHMOD_DIR ); clearstatcache(); // For FTP, need to clear the stat cache. diff --git a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.js b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.js index f2323d38..64c5b914 100644 --- a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.js +++ b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.js @@ -55,7 +55,7 @@ var $ = jQuery.noConflict(), default: if (tag) { // Queue the requests for an AJAX call at the end of init - dtx.queue.push({ 'value': raw_value, 'multiline': $input.is('textarea') }); + dtx.queue.push(raw_value); } return; // Don't continue after queuing it for AJAX } diff --git a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js index 175a7328..8cbdb4ba 100644 --- a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js +++ b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js @@ -1,2 +1,2 @@ -/*! Do not edit, this file is generated automatically - 2023-09-18 14:09:50 EDT */ -var $=jQuery.noConflict(),dtx={queue:[],init:function(){var e=$("input.dtx-pageload[data-dtx-value]");e.length&&(e.each(function(e,t){var r=$(t),a=r.attr("data-dtx-value"),o=decodeURIComponent(a).split(" ");if(o.length){var n=o[0],c={};if(1(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)):(r=(new Date).getTime(),a="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random();return 0(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16)).toUpperCase();console.warn("[CF7 DTX] Cryptographically secure PRNG is not available for generating GUID value");var d=(new Date).getTime(),d2="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=16*Math.random();return 0 array( - 'title' => __('dynamic text', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'dtx_pageload'), - 'description' => __('a single-line plain text', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_hidden' => array( - 'title' => __('dynamic hidden', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('dtx_pageload'), - 'description' => __('a single-line plain text hidden input field', 'contact-form-7-dynamic-text-extension'), - 'features' => array( - 'display-hidden' => true // Generates an HTML element that is not visible - ) - ), - 'dynamic_email' => array( - 'title' => __('dynamic email', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'dtx_pageload'), - 'description' => __('a single-line email address input field', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_url' => array( - 'title' => __('dynamic URL', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'dtx_pageload'), - 'description' => __('a single-line URL input field', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_tel' => array( - 'title' => __('dynamic tel', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'pattern'), - 'description' => __('a single-line telephone number input field', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_number' => array( - 'title' => __('dynamic number', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'min', 'max', 'step', 'pattern'), - 'description' => __('a numeric input field displayed as a number spinbox', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_range' => array( - 'title' => __('dynamic range', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'min', 'max', 'step', 'pattern'), - 'description' => __('a numeric input field displayed as a slider between a minimum and maximum range', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_textarea' => array( - 'title' => __('dynamic textarea', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'dtx_pageload'), - 'description' => __('a multi-line plain text input field', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_select' => array( - 'title' => __('dynamic drop-down menu', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'multiple', 'include_blank'), - 'description' => __('a drop-down menu (i.e select input field)', 'contact-form-7-dynamic-text-extension'), - 'features' => array( - 'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options - ) - ), - 'dynamic_checkbox' => array( - 'title' => __('dynamic checkboxes', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('readonly', 'label_first', 'use_label_element', 'exclusive'), - 'description' => __('a group of checkboxes', 'contact-form-7-dynamic-text-extension'), - 'features' => array( - 'multiple-controls-container' => true, // Generates an HTML element that can contain multiple form controls - 'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options - ) - ), - 'dynamic_radio' => array( - 'title' => __('dynamic radio buttons', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('readonly', 'label_first', 'use_label_element'), - 'description' => __('a group of radio buttons', 'contact-form-7-dynamic-text-extension'), - 'features' => array( - 'multiple-controls-container' => true, // Generates an HTML element that can contain multiple form controls - 'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options - ) - ), - 'dynamic_date' => array( - 'title' => __('dynamic date', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('placeholder', 'readonly', 'min', 'max'), - 'description' => __('a date input field', 'contact-form-7-dynamic-text-extension') - ), - 'dynamic_submit' => array( - 'title' => __('dynamic submit', 'contact-form-7-dynamic-text-extension'), //title - 'options' => array('dtx_pageload'), - 'description' => __('a submit button', 'contact-form-7-dynamic-text-extension') - ) - ); - } - return $wpcf7_dynamic_fields_config; -} /** * Add Custom Shortcodes to Contact Form 7 * * @return void */ -function wpcf7dtx_add_shortcodes() +function wpcf7dtx_add_shortcode_dynamictext() { - //Add the dynamic form fields - foreach (wpcf7dtx_config() as $form_tag => $field) { - $input_type = str_replace('dynamic_', '', $form_tag); - $tag_types = array($form_tag, "$form_tag*"); - $callback = 'wpcf7dtx_shortcode_handler'; - $features = array_merge(array('name-attr' => true), wpcf7dtx_array_has_key('features', $field, array())); - switch ($input_type) { - case 'text': - case 'hidden': - // Add deprecated tags - $dep_tag = str_replace('_', '', $form_tag); - $tag_types[] = $dep_tag; - $tag_types[] = "$dep_tag*"; - add_filter("wpcf7_validate_$dep_tag*", 'wpcf7dtx_validation_filter', 20, 2); // Validate required deprecated form tags - break; - case 'submit': - case 'reset': - $callback = 'wpcf7dtx_button_shortcode_handler'; - $features['name-attr'] = false; - break; - default: - break; - } - add_filter("wpcf7_validate_$form_tag*", 'wpcf7dtx_validation_filter', 20, 2); // Validate required custom form tags - wpcf7_add_form_tag($tag_types, $callback, $features); - } + //Add the dynamic text and hidden form fields + wpcf7_add_form_tag( + array( + 'dynamictext', 'dynamictext*', + 'dynamichidden', 'dynamichidden*' //Required hidden fields do nothing + ), + 'wpcf7dtx_dynamictext_shortcode_handler', //Callback + array( //Features + 'name-attr' => true, + 'dtx_pageload' => true + ) + ); } /** @@ -220,9 +112,35 @@ add_action('wp_enqueue_scripts', 'wpcf7dtx_enqueue_frontend_assets'); include_once(WPCF7DTX_DIR . '/includes/utilities.php'); /** - * Include Validation Functions + * Get Dynamic Value + * + * @since 3.2.2 + * + * @param string $value The form tag value. + * @param WPCF7_FormTag|false $tag Optional. Use to look up default value. + * + * @return string The dynamic output or the original value, not escaped or sanitized. */ -include_once(WPCF7DTX_DIR . '/includes/validation.php'); +function wpcf7dtx_get_dynamic($value, $tag = false) +{ + if ($tag !== false) { + $default = $tag->get_option('defaultvalue', '', true); + if (!$default) { + $default = $tag->get_default_option(strval(reset($tag->values))); + } + $value = wpcf7_get_hangover($tag->name, $default); + } + $value = apply_filters('wpcf7dtx_sanitize', $value); + if (is_string($value) && !empty($value)) { + // If a shortcode was passed as the options, evaluate it and use the result + $shortcode_tag = '[' . $value . ']'; + $shortcode_output = do_shortcode($shortcode_tag); //Shortcode value + if (is_string($shortcode_output) && $shortcode_output != $shortcode_tag) { + return apply_filters('wpcf7dtx_sanitize', $shortcode_output); + } + } + return $value; +} /** * Form Tag Handler @@ -231,54 +149,59 @@ include_once(WPCF7DTX_DIR . '/includes/validation.php'); * * @return string HTML output of the shortcode */ -function wpcf7dtx_shortcode_handler($tag) +function wpcf7dtx_dynamictext_shortcode_handler($tag) { - // Name attribute is required for these form tags if (empty($tag->name)) { return ''; } - // Validate + //Validate $validation_error = wpcf7_get_validation_error($tag->name); + //Configure classes + $class = wpcf7_form_controls_class($tag->type, 'wpcf7dtx-dynamictext'); + if ($validation_error) { + $class .= ' wpcf7-not-valid'; + } + //Configure input attributes $atts = array(); - $atts['type'] = sanitize_key(str_replace(array('dynamic_', 'dynamic'), '', $tag->basetype)); $atts['name'] = $tag->name; - $atts['id'] = strval($tag->get_id_option()); + $atts['id'] = $tag->get_id_option(); $atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true); $atts['size'] = $tag->get_size_option('40'); - $atts['class'] = explode(' ', wpcf7_form_controls_class($atts['type'])); - $atts['class'][] = 'wpcf7dtx'; - $atts['class'][] = sanitize_html_class('wpcf7dtx-' . $atts['type']); - if ($validation_error) { - $atts['class'][] = 'wpcf7-not-valid'; - $atts['aria-invalid'] = 'true'; - $atts['aria-describedby'] = wpcf7_get_validation_error_reference($tag->name); - } else { - $atts['aria-invalid'] = 'false'; + $atts['maxlength'] = $tag->get_maxlength_option(); + $atts['minlength'] = $tag->get_minlength_option(); + $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; + switch ($tag->basetype) { + case 'dynamichidden': + $atts['type'] = 'hidden'; //Override type as hidden + break; + default: // Includes `dynamictext` + $atts['type'] = 'text'; //Override type as text + break; + } + if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) { + unset($atts['maxlength'], $atts['minlength']); } - if ($tag->has_option('readonly')) { $atts['readonly'] = 'readonly'; } - // Add required attribute to applicable input types - if ($tag->is_required() && !in_array($atts['type'], array('hidden', 'quiz'))) { + if ($tag->is_required() && $atts['type'] !== 'hidden') { $atts['aria-required'] = 'true'; $atts['required'] = 'required'; } // Evaluate the dynamic value - $sanitize_type = $atts['type'] == 'textarea' ? $atts['type'] : 'auto'; - $value = wpcf7dtx_get_dynamic(false, $tag, $sanitize_type); + $value = wpcf7dtx_get_dynamic(false, $tag); // Identify placeholder if ($tag->has_option('placeholder') || $tag->has_option('watermark')) { //Reverse engineer what JS did (converted quotes to HTML entities --> URL encode) then sanitize - $placeholder = html_entity_decode(urldecode($tag->get_option('placeholder', '', true)), ENT_QUOTES); + $placeholder = html_entity_decode(urldecode(implode('', (array)$tag->get_option('placeholder'))), ENT_QUOTES); if ($placeholder) { //If a different placeholder text has been specified, set both attributes - $placeholder = wpcf7dtx_get_dynamic($placeholder, false, $sanitize_type); + $placeholder = wpcf7dtx_get_dynamic($placeholder); $atts['placeholder'] = $placeholder; $atts['value'] = $value; } else { @@ -289,10 +212,18 @@ function wpcf7dtx_shortcode_handler($tag) $atts['value'] = $value; } + if ($atts['type'] == 'hidden') { + // Always disable for hidden fields + $atts['autocomplete'] = 'off'; + } else { + // Disable autocomplete for this field if a value has been specified + $atts['autocomplete'] = $atts['value'] ? 'off' : $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true); + } + // Page load attribute - if ($tag->has_option('dtx_pageload') && is_array($tag->raw_values) && count($tag->raw_values)) { - $atts['data-dtx-value'] = rawurlencode(sanitize_text_field($tag->raw_values[0])); - $atts['class'][] = 'dtx-pageload'; + if ($tag->has_option('dtx_pageload')) { + $atts['data-dtx-value'] = rawurlencode(sanitize_text_field(implode('', (array)$tag->raw_values))); + $class .= ' dtx-pageload'; if (wp_style_is('wpcf7dtx', 'registered') && !wp_script_is('wpcf7dtx', 'queue')) { // If already registered, just enqueue it wp_enqueue_script('wpcf7dtx'); @@ -303,190 +234,54 @@ function wpcf7dtx_shortcode_handler($tag) } } - // Additional configuration based on form field type - if (in_array($atts['type'], array('select', 'checkbox', 'radio'))) { - /** - * Configuration for selection-based fields - */ - if ($tag->has_option('default')) { - $atts['dtx-default'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('default', '', true)), ENT_QUOTES)); - } - - // Get options for selection-based fields - $options = array(); - $pipes = $tag->pipes->to_array(); - if (count($pipes)) { - foreach ($pipes as $pipe) { - $key = trim(strval($pipe[0])); - $value = trim(strval($pipe[1])); - if ($key && $value) { - $options[$key] = $value; - } - } - } - if ($atts['type'] == 'select' && $tag->has_option('include_blank')) { - $atts['placeholder'] = wpcf7dtx_array_has_key('placeholder', $atts, __('—Please choose an option—', 'contact-form-7-dynamic-text-extension')); - } - } else { - /** - * Configuration for text-based fields - */ - - // Attributes - $atts['maxlength'] = $tag->get_maxlength_option(); - $atts['minlength'] = $tag->get_minlength_option(); - if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) { - unset($atts['maxlength'], $atts['minlength']); - } - - // Autocomplete attribute - if ($atts['type'] == 'hidden') { - $atts['autocomplete'] = 'off'; // Always disable for hidden fields - } else { - // Disable autocomplete for this field if a dynamic value has been specified - $atts['autocomplete'] = $atts['value'] ? 'off' : $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true); - } - - switch ($atts['type']) { - case 'email': - case 'url': - case 'tel': - case 'number': - case 'date': - // Client-side validation by type - $atts['class'][] = sanitize_html_class('wpcf7-validates-as-' . $atts['type']); - break; - case 'range': - // Client-side validation by type - $atts['class'][] = 'wpcf7-validates-as-number'; - break; - case 'textarea': - // Attributes unique to textareas - $atts['cols'] = $tag->get_cols_option('40'); - $atts['rows'] = $tag->get_rows_option('10'); - break; - } - } - // Wrap up class attribute - $atts['class'] = $tag->get_class_option($atts['class']); + $atts['class'] = $tag->get_class_option($class); - // Output the form field HTML - $wrapper = '%2$s%3$s'; - $allowed_html = array('br' => array(), 'span' => array('id' => array(), 'class' => array(), 'data-name' => array(), 'aria-hidden' => array())); - switch ($atts['type']) { - case 'checkbox': - case 'radio': - return wp_kses(sprintf( - str_replace('options), - in_array('label_first', $tag->options), - in_array('exclusive', $tag->options) - ), - $validation_error, - $atts['id'] ? sprintf(' id="%s"', esc_attr($atts['id'])) : '' - ), array_merge($allowed_html, array( - 'label' => array('for' => array()), - 'input' => wpcf7dtx_get_allowed_field_properties($atts['type']) - ))); - case 'select': - $allowed_html = array_merge($allowed_html, wpcf7dtx_get_allowed_field_properties('option'), array( - 'select' => wpcf7dtx_get_allowed_field_properties($atts['type']) - )); - return wp_kses(sprintf( - $wrapper, - esc_attr($tag->name), - wpcf7dtx_select_html( - $atts, - $options, - $tag->has_option('dtx_hide_blank'), - $tag->has_option('dtx_disable_blank') - ), - $validation_error - ), array_merge($allowed_html, wpcf7dtx_get_allowed_field_properties('option'), array( - 'select' => wpcf7dtx_get_allowed_field_properties($atts['type']), - ))); - case 'textarea': - return wp_kses(sprintf( - $wrapper, - esc_attr($tag->name), - wpcf7dtx_textarea_html($atts), - $validation_error - ), array_merge($allowed_html, array( - 'textarea' => wpcf7dtx_get_allowed_field_properties($atts['type']) - ))); - default: - return wp_kses(sprintf( - $wrapper, - esc_attr($tag->name), - wpcf7dtx_input_html($atts), - $validation_error - ), array_merge($allowed_html, array( - 'input' => wpcf7dtx_get_allowed_field_properties($atts['type']) - ))); - } + //Output the HTML + return sprintf( + '%s', + sanitize_html_class($tag->name), + esc_attr($tag->name), + wpcf7_format_atts($atts), //This function already escapes attribute values + $validation_error + ); } /** - * Form Tag Handler for Dynamic Submit + * Validate Required Dynamic Text Field * - * @param WPCF7_FormTag $tag Current Contact Form 7 tag object + * @param WPCF7_Validation $result the current validation result object + * @param WPCF7_FormTag $tag the current form tag being filtered for validation * - * @return string HTML output of the shortcode + * @return WPCF7_Validation a possibly modified validation result object */ -function wpcf7dtx_button_shortcode_handler($tag) +function wpcf7dtx_dynamictext_validation_filter($result, $tag) { - //Configure input attributes - $atts = array(); - $atts['type'] = sanitize_key(str_replace('dynamic_', '', $tag->basetype)); - $atts['id'] = strval($tag->get_id_option()); - $atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true); - $atts['value'] = wpcf7dtx_get_dynamic(false, $tag); // Evaluate the dynamic value - $atts['class'] = explode(' ', wpcf7_form_controls_class($atts['type'])); - $atts['class'][] = 'wpcf7dtx'; - $atts['class'][] = sanitize_html_class('wpcf7dtx-' . $atts['type']); - if ($atts['type'] == 'submit') { - $atts['class'][] = 'has-spinner'; - } + //Sanitize value + $value = empty($_POST[$tag->name]) ? '' : sanitize_text_field(strval($_POST[$tag->name])); - // Default value if empty - if (empty($atts['value'])) { - switch ($atts['type']) { - case 'reset': - $atts['value'] = __('Clear', 'contact-form-7-dynamic-text-extension'); - break; - default: - $atts['value'] = __('Send', 'contact-form-7-dynamic-text-extension'); - break; + //Validate + if ('dynamictext' == $tag->basetype) { + if ($tag->is_required() && '' == $value) { + $result->invalidate($tag, wpcf7_get_message('invalid_required')); } } - - // Page load attribute - if ($tag->has_option('dtx_pageload') && is_array($tag->raw_values) && count($tag->raw_values)) { - $atts['data-dtx-value'] = rawurlencode(sanitize_text_field($tag->raw_values[0])); - $atts['class'][] = 'dtx-pageload'; - if (wp_style_is('wpcf7dtx', 'registered') && !wp_script_is('wpcf7dtx', 'queue')) { - // If already registered, just enqueue it - wp_enqueue_script('wpcf7dtx'); - } elseif (!wp_style_is('wpcf7dtx', 'registered')) { - // If not registered, do that first, then enqueue it - wpcf7dtx_enqueue_frontend_assets(); - wp_enqueue_script('wpcf7dtx'); + if (!empty($value)) { + $maxlength = $tag->get_maxlength_option(); + $minlength = $tag->get_minlength_option(); + if ($maxlength && $minlength && $maxlength < $minlength) { + $maxlength = $minlength = null; + } + $code_units = wpcf7_count_code_units($value); + if (false !== $code_units) { + if ($maxlength && $maxlength < $code_units) { + $result->invalidate($tag, wpcf7_get_message('invalid_too_long')); + } elseif ($minlength && $code_units < $minlength) { + $result->invalidate($tag, wpcf7_get_message('invalid_too_short')); + } } } - - // Wrap up class attribute - $atts['class'] = $tag->get_class_option($atts['class']); - - // Output the form field HTML - return wp_kses( - wpcf7dtx_input_html($atts), - array('input' => wpcf7dtx_get_allowed_field_properties($atts['type'])) - ); + return $result; } /** @@ -501,14 +296,16 @@ function wpcf7dtx_button_shortcode_handler($tag) function wpcf7dtx_js_handler() { $return = array(); - $queue = wpcf7dtx_array_has_key('shortcodes', $_POST); - if (is_array($queue) && count($queue)) { - foreach ($queue as $field) { - $multiline = wpcf7dtx_array_has_key('multiline', $field, false); - $raw_value = sanitize_text_field(rawurldecode(wpcf7dtx_array_has_key('value', $field))); + $shortcodes = wpcf7dtx_array_has_key('shortcodes', $_POST); + if (is_array($shortcodes) && count($shortcodes)) { + foreach ($shortcodes as $raw_value) { + $value = sanitize_text_field(rawurldecode($raw_value)); + if (!empty($value)) { + $value = wpcf7dtx_get_dynamic($value); + } $return[] = array( 'raw_value' => esc_attr($raw_value), - 'value' => esc_attr(wpcf7dtx_get_dynamic($raw_value, false, $multiline ? 'textarea' : 'auto')) + 'value' => esc_attr($value) ); } } @@ -525,20 +322,6 @@ if (is_admin()) { } /** - * Built-in Shortcodes + * Included Shortcodes */ include_once(WPCF7DTX_DIR . '/includes/shortcodes.php'); - -/** - * Website's custom shortcodes, if they exist - */ -$user_files = array( - constant('WP_CONTENT_DIR') . '/dtx.php', // e.g. C:\path\to\website\wp-content\dtx.php - get_template_directory() . '/dtx.php', // e.g. C:\path\to\website\wp-content/themes/parent-theme/dtx.php - get_stylesheet_directory() . '/dtx.php' // e.g. C:\path\to\website\wp-content/themes/child-theme/dtx.php -); -foreach ($user_files as $user_file) { - if (file_exists($user_file)) { - include_once($user_file); - } -} diff --git a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/admin.php b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/admin.php index 6256b710..b62f4f65 100644 --- a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/admin.php +++ b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/admin.php @@ -16,13 +16,13 @@ function wpcf7dtx_enqueue_admin_assets($hook) // Only load on CF7 Form pages (both editing forms and creating new forms) if ($hook === 'toplevel_page_wpcf7' || $hook === 'contact_page_wpcf7-new') { $prefix = 'wpcf7dtx-'; - $debug = defined('WP_DEBUG_SCRIPTS') && constant('WP_DEBUG_SCRIPTS'); + $debug = defined('WP_DEBUG') && constant('WP_DEBUG'); $url = plugin_dir_url(WPCF7DTX_FILE); $path = plugin_dir_path(WPCF7DTX_FILE); wp_enqueue_style( $prefix . 'admin', //Handle - $url . 'assets/styles/tag-generator' . ($debug ? '' : '.min') . '.css', //Source + $url . 'assets/styles/tag-generator.css', //Source array('contact-form-7-admin'), //Dependencies $debug ? @filemtime($path . 'assets/styles/tag-generator.css') : WPCF7DTX_VERSION //Version ); @@ -44,22 +44,30 @@ add_action('admin_enqueue_scripts', 'wpcf7dtx_enqueue_admin_assets'); //Enqueue * * @return void */ -function wpcf7dtx_add_tag_generators() +function wpcf7dtx_add_tag_generator_dynamictext() { if (!class_exists('WPCF7_TagGenerator')) { return; } - - // Custom dynamic fields to add - global $wpcf7_dynamic_fields_config; - - // Loop fields to add them $tag_generator = WPCF7_TagGenerator::get_instance(); - foreach ($wpcf7_dynamic_fields_config as $id => $field) { - $tag_generator->add($id, $field['title'], 'wpcf7dtx_tag_generator', array_merge(array('name-attr', 'dtx_pageload'), $field['options'])); - } + + //Dynamic Text Field + $tag_generator->add( + 'dynamictext', //id + __('dynamic text', 'contact-form-7-dynamic-text-extension'), //title + 'wpcf7dtx_tag_generator_dynamictext', //callback + array('placeholder', 'readonly', 'dtx_pageload') //options + ); + + //Dynamic Hidden Field + $tag_generator->add( + 'dynamichidden', //id + __('dynamic hidden', 'contact-form-7-dynamic-text-extension'), //title + 'wpcf7dtx_tag_generator_dynamictext', //callback + array('dtx_pageload') // options + ); } -add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generators', 100); +add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generator_dynamictext', 100); /** * Echo HTML for Dynamic Tag Generator @@ -69,43 +77,36 @@ add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generators', 100); * * @return void */ -function wpcf7dtx_tag_generator($contact_form, $options = '') +function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '') { $options = wp_parse_args($options); - global $wpcf7_dynamic_fields_config; $type = $options['id']; - $input_type = str_replace('dynamic_', '', $type); + switch ($type) { + case 'dynamichidden': //hiden + $description = __('Generate a form-tag for a hidden input field, with a dynamically generated default value.', 'contact-form-7-dynamic-text-extension'); + break; + default: + $description = __('Generate a form-tag for a single-line plain text input field, with a dynamically generated default value.', 'contact-form-7-dynamic-text-extension'); + break; + } $utm_source = urlencode(home_url()); - $description = sprintf( - __('Generate a form-tag for %s with a dynamic default value. For more details, see %s fields in the %s.', 'contact-form-7-dynamic-text-extension'), - esc_html($wpcf7_dynamic_fields_config[$type]['description']), // dynamic description - // Link to specific form-tag documentation - sprintf( - '%s', - esc_attr(str_replace('_', '-', $type)), // URL component - esc_attr($utm_source), //UTM source - esc_attr($type), //UTM content - esc_attr__('View this form-tag on the DTX Documentation website', 'contact-form-7-dynamic-text-extension'), // Link title - esc_html(ucwords(str_replace('_', ' ', $type))) // Link label - ), - // Link to general DTX documentation - sprintf( - '%s', - esc_attr($utm_source), //UTM source - esc_attr($type), //UTM content - esc_attr__('Go to DTX Documentation website', 'contact-form-7-dynamic-text-extension'), - esc_html__('DTX knowledge base', 'contact-form-7-dynamic-text-extension') - ) + $description .= sprintf( + ' %s %s.', + esc_html__('For more details, see', 'contact-form-7-dynamic-text-extension'), + esc_attr($utm_source), //UTM source + esc_attr($type), //UTM content + esc_attr__('Go to DTX Documentation website', 'contact-form-7-dynamic-text-extension'), + esc_html__('DTX knowledge base', 'contact-form-7-dynamic-text-extension') ); - // Open Form-Tag Generator + //Open Form-Tag Generator printf( - '
%s', + '
%s
', wp_kses($description, array('a' => array('href' => array(), 'target' => array(), 'rel' => array(), 'title' => array()))) //Tag generator description ); - // Input field - Required checkbox (not available for some fields) - if (!in_array($input_type, array('hidden', 'quiz', 'submit', 'reset'))) { + //Input field - Required checkbox (not available for hidden fields) + if ($type != 'dynamichidden') { printf( '', esc_attr($options['content'] . '-required'), // field id @@ -119,253 +120,62 @@ function wpcf7dtx_tag_generator($contact_form, $options = '') ); } - // Input field - Field Name (not available for some fields) - if (!in_array($input_type, array('submit', 'reset'))) { - printf( - '', - esc_attr($options['content'] . '-name'), // field id - esc_html__('Name', 'contact-form-7-dynamic-text-extension'), // field label - wpcf7_format_atts(array( - 'type' => 'text', - 'name' => 'name', - 'id' => $options['content'] . '-name', - 'class' => 'tg-name oneline', - 'autocomplete' => 'off' - )) - ); - } - - // Input field - Dynamic value/options - $value_name = __('Dynamic value', 'contact-form-7-dynamic-text-extension'); - $value_description = __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'); - $value_placeholder = "CF7_GET key='foo'"; - $value_input_type = ''; - switch ($input_type) { - case 'textarea': - $value_placeholder = "CF7_get_post_var key='post_excerpt'"; - $value_input_type = ''; - break; - case 'select': - $value_name = __('Dynamic options', 'contact-form-7-dynamic-text-extension'); - $value_description .= ' ' . __('If static text, use one option per line. Can define static key/value pairs using pipes.', 'contact-form-7-dynamic-text-extension'); - $value_description .= ' ' . __('If shortcode, it must return only option or optgroup HTML and can override the first option and select default settings here.', 'contact-form-7-dynamic-text-extension'); - $value_placeholder = "hello-world | Hello World" . PHP_EOL . "Foo"; - $value_input_type = ''; - break; - case 'checkbox': - case 'radio': - $value_name = __('Dynamic options', 'contact-form-7-dynamic-text-extension'); - $value_description .= ' ' . __('If static text, use one option per line. Can define static key/value pairs using pipes.', 'contact-form-7-dynamic-text-extension'); - $value_description .= ' ' . __('If shortcode, it must return only option or optgroup HTML.', 'contact-form-7-dynamic-text-extension'); - $value_placeholder = "hello-world | Hello World" . PHP_EOL . "Foo"; - $value_input_type = ''; - break; - default: // All other text fields - break; - } + //Input field - Field Name printf( - '', - esc_attr($options['content'] . '-values'), // field id - esc_html($value_name), // field label + '', + esc_attr($options['content'] . '-name'), // field id + esc_html__('Name', 'contact-form-7-dynamic-text-extension'), // field label wpcf7_format_atts(array( - 'name' => 'values', - 'id' => $options['content'] . '-values', - 'class' => 'multiline', - 'placeholder' => $value_placeholder, - 'list' => 'dtx-shortcodes' - )), - esc_html($value_description), - esc_attr($utm_source), // UTM source - esc_attr($type), // UTM content - esc_html__('View DTX shortcode syntax documentation', 'contact-form-7-dynamic-text-extension') // Link label + 'type' => 'text', + 'name' => 'name', + 'id' => $options['content'] . '-name', + 'class' => 'tg-name oneline' + )) ); - if ($input_type == 'select') { - // Input field - Multiple selections checkbox - printf( - '', - esc_attr($options['content'] . '-multiple'), // field id - esc_html__('Multiple Options', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'multiple', - 'id' => $options['content'] . '-multiple', - 'class' => 'option' - )), - esc_html__('Allow user to select multiple options', 'contact-form-7-dynamic-text-extension') // checkbox label - ); + //Input field - Dynamic value + printf( + '', + esc_attr($options['content'] . '-values'), // field id + esc_html__('Dynamic value', 'contact-form-7-dynamic-text-extension'), // field label + wpcf7_format_atts(array( + 'type' => 'text', + 'name' => 'values', + 'id' => $options['content'] . '-values', + 'class' => 'oneline', + 'placeholder' => "CF7_GET key='foo'" + )), + esc_html__('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'), + esc_attr($utm_source), //UTM source + esc_attr($type), //UTM content + esc_html__('View DTX shortcode syntax documentation', 'contact-form-7-dynamic-text-extension') //Link label + ); - // Input field - Include blank checkbox + //Input field - Dynamic placeholder (not available for hidden fields) + if ($type != 'dynamichidden') { printf( - '', - esc_attr($options['content'] . '-include_blank'), // field id - esc_html__('First Option', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'include_blank', - 'id' => $options['content'] . '-include_blank', - 'class' => 'include_blankvalue option' - )), - esc_html__('Insert a blank item as the first option', 'contact-form-7-dynamic-text-extension') // checkbox label - ); - } - - // Input field - Dynamic placeholder (not available for some fields) - if (!in_array($input_type, array('hidden', 'radio', 'checkbox', 'quiz', 'submit', 'reset'))) { - $placeholder_description = ''; - if (in_array($input_type, array('select', 'checkbox', 'radio'))) { - $placeholder_label = __('First Option Label', 'contact-form-7-dynamic-text-extension'); - $placeholder_description .= __('Optionally define a label for the first option.', 'contact-form-7-dynamic-text-extension') . ' '; - } else { - $placeholder_label = __('Dynamic placeholder', 'contact-form-7-dynamic-text-extension'); - } - $placeholder_description .= __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'); - $placeholder_input_type = $input_type == 'textarea' ? $value_input_type : ''; - printf( - '', + '', esc_attr($options['content'] . '-placeholder'), // field id - esc_html($placeholder_label), // field label + esc_html__('Dynamic placeholder', 'contact-form-7-dynamic-text-extension'), // field label wpcf7_format_atts(array( 'type' => 'hidden', 'name' => 'placeholder', 'class' => 'option' )), wpcf7_format_atts(array( + 'type' => 'text', 'name' => 'dtx-placeholder', 'id' => $options['content'] . '-placeholder', // field id - 'class' => 'multiline dtx-option', - 'placeholder' => "CF7_get_post_var key='post_title'", - 'list' => 'dtx-shortcodes' + 'class' => 'oneline dtx-option', + 'placeholder' => 'CF7_get_post_var key=\'post_title\'' )), - esc_html($placeholder_description), // Small note below input + esc_html__('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'), // Small note below input esc_attr($utm_source), //UTM source esc_attr($type), //UTM content esc_html__('View DTX placeholder documentation', 'contact-form-7-dynamic-text-extension') //Link label ); } - // Additional fields for select regarding placeholder options - if ($input_type == 'select') { - - // Input field - Hide Blank Option - printf( - '', - esc_attr($options['content'] . '-dtx_hide_blank'), // field id - esc_html__('Hide First Option', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'dtx_hide_blank', - 'id' => $options['content'] . '-dtx_hide_blank', - 'class' => 'option' - )), - esc_html__('Hide the first blank option from being visible in the drop-down', 'contact-form-7-dynamic-text-extension'), // checkbox label - esc_html__('Optional. Only works if "First Option" is checked.', 'contact-form-7-dynamic-text-extension'), // Small note below input - esc_attr($utm_source), //UTM source - esc_attr($type), //UTM content - esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label - ); - - // Input field - Disable Blank Option - printf( - '', - esc_attr($options['content'] . '-dtx_disable_blank'), // field id - esc_html__('Disable First Option', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'dtx_disable_blank', - 'id' => $options['content'] . '-dtx_disable_blank', - 'class' => 'option' - )), - esc_html__('Disable the first blank option from being selectable in the drop-down', 'contact-form-7-dynamic-text-extension'), // checkbox label - esc_html__('Optional. Only works if "First Option" is checked.', 'contact-form-7-dynamic-text-extension'), // Small note below input - esc_attr($utm_source), //UTM source - esc_attr($type), //UTM content - esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label - - ); - } elseif (in_array($input_type, array('checkbox', 'radio'))) { - // Additional fields for checkboxes and radio buttons - - // Input field - Checkbox Layout Reverse Option - printf( - '', - esc_attr($options['content'] . '-label_first'), // field id - esc_html__('Reverse', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'label_first', - 'id' => $options['content'] . '-label_first', - 'class' => 'option' - )), - esc_html__('Put a label first, an input last', 'contact-form-7-dynamic-text-extension') // checkbox label - ); - - // Input field - Label UI - printf( - '', - esc_attr($options['content'] . '-use_label_element'), // field id - esc_html__('Label', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'use_label_element', - 'id' => $options['content'] . '-use_label_element', - 'class' => 'option' - )), - esc_html__('Wrap each item with label element', 'contact-form-7-dynamic-text-extension') // checkbox label - ); - - // Input field - Exclusive Checkbox - if ($input_type == 'checkbox') { - printf( - '', - esc_attr($options['content'] . '-exclusive'), // field id - esc_html__('Exclusive', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'exclusive', - 'id' => $options['content'] . '-exclusive', - 'class' => 'option' - )), - esc_html__('Make checkboxes exclusive', 'contact-form-7-dynamic-text-extension') // checkbox label - ); - } - } - - // Input field - Dynamic default value (not available for some fields) - if (in_array($input_type, array('select'))) { - $default_input_type = ''; - $default_placeholder = ''; - if ($input_type == 'checkbox') { - $default_input_type = ''; - $default_description = __('Optionally define the default on/off status of the checkboxes by putting a 1 (checked) or 0 (not checked) on each line that corresponds with the options.', 'contact-form-7-dynamic-text-extension') . ' '; - $default_placeholder = '0' . PHP_EOL . '1'; - } else { - $default_description = __('Optionally define the option that is selected by default. This can be different than the first [blank] option. If options use key/value pairs, only define the key here.', 'contact-form-7-dynamic-text-extension') . ' '; - } - $default_description .= __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'); - printf( - '', - esc_attr($options['content'] . '-default'), // field id - esc_html__('Selected Default'), // field label - wpcf7_format_atts(array( - 'type' => 'hidden', - 'name' => 'default', - 'class' => 'option' - )), - wpcf7_format_atts(array( - 'name' => 'dtx-default', - 'id' => $options['content'] . '-default', // field id - 'class' => 'oneline dtx-option', - 'placeholder' => $default_placeholder, - 'list' => 'dtx-shortcodes' - )), - esc_html($default_description), // Small note below input - esc_attr($utm_source), //UTM source - esc_attr($type), //UTM content - esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label - ); - } - //Input field - ID attribute printf( '', @@ -392,8 +202,8 @@ function wpcf7dtx_tag_generator($contact_form, $options = '') )) ); - //Input field - Readonly attribute (not available for hidden, submit, or quiz fields) - if (!in_array($input_type, array('hidden', 'submit', 'quiz'))) { + //Input field - Readonly attribute (not available for hidden fields) + if ($type != 'dynamichidden') { printf( '', esc_attr($options['content'] . '-readonly'), // field id @@ -408,55 +218,25 @@ function wpcf7dtx_tag_generator($contact_form, $options = '') ); } - // Input field - Page load data attribute (triggers the loading of a frontend script) + // Page load data attribute (triggers the loading of a frontend script) printf( '', - esc_attr($options['content'] . '-dtx_pageload'), // field id + esc_attr($options['content'] . '-frontend'), // field id esc_html__('Cache Compatible', 'contact-form-7-dynamic-text-extension'), // field Label wpcf7_format_atts(array( 'type' => 'checkbox', 'name' => 'dtx_pageload', 'id' => $options['content'] . '-dtx_pageload', - 'class' => 'option' + 'class' => 'dtx_pageloadvalue option' )), esc_html__('Get the dynamic value after the page has loaded', 'contact-form-7-dynamic-text-extension'), // checkbox label - esc_html__('May impact page performance.', 'contact-form-7-dynamic-text-extension'), // Small note below input + esc_html('May impact page performance.', 'contact-form-7-dynamic-text-extension'), // Small note below input esc_attr($utm_source), //UTM source esc_attr($type), //UTM content esc_html__('View DTX page load documentation', 'contact-form-7-dynamic-text-extension') //Link label ); - // Input field - Akismet module (only available for text, email, and url fields) - if (in_array($input_type, array('text', 'email', 'url'))) { - switch ($input_type) { - case 'email': - $akismet_name = 'author_email'; - $akismet_desc = __("This field requires author's email address", 'contact-form-7-dynamic-text-extension'); - break; - case 'url': - $akismet_name = 'author_url'; - $akismet_desc = __("This field requires author's URL", 'contact-form-7-dynamic-text-extension'); - break; - default: - $akismet_name = 'author'; - $akismet_desc = __("This field requires author's name", 'contact-form-7-dynamic-text-extension'); - break; - } - printf( - '', - esc_attr($options['content'] . '-readonly'), // field id - esc_html__('Akismet', 'contact-form-7-dynamic-text-extension'), // field Label - wpcf7_format_atts(array( - 'type' => 'checkbox', - 'name' => 'akismet:' . $akismet_name, - 'id' => $options['content'] . '-akismet-' . $akismet_name, - 'class' => 'akismetvalue option' - )), - esc_html($akismet_desc) // checkbox label - ); - } - //Close Form-Tag Generator printf( '
' . $value_input_type . '
%s %s

%s %s
' . $placeholder_input_type . '
%s %s

%s %s

%s %s

%s %s
' . $default_input_type . '
%s %s

%s %s

', diff --git a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/utilities.php b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/utilities.php index c0a6fc4d..725a5442 100644 --- a/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/utilities.php +++ b/wp/wp-content/plugins/contact-form-7-dynamic-text-extension/includes/utilities.php @@ -50,9 +50,6 @@ add_filter('wpcf7dtx_allow_protocols', 'wpcf7dtx_allow_protocols', 10, 2); */ function wpcf7dtx_sanitize($value = '', $type = 'auto', $protocols = false) { - if ($type == 'none') { - return $value; - } $value = is_string($value) ? $value : strval($value); // Force string value if (!empty($value)) { $type = $type == 'auto' ? wpcf7dtx_detect_value_type($value) : sanitize_text_field($type); @@ -65,8 +62,6 @@ function wpcf7dtx_sanitize($value = '', $type = 'auto', $protocols = false) return sanitize_key($value); case 'slug': return sanitize_title($value); - case 'textarea': - return sanitize_textarea_field($value); } } return sanitize_text_field($value); @@ -87,9 +82,6 @@ add_filter('wpcf7dtx_sanitize', 'wpcf7dtx_sanitize', 10, 3); */ function wpcf7dtx_escape($value = '', $obfuscate = false, $type = 'auto', $protocols = false) { - if ($type == 'none') { - return $value; - } $value = apply_filters('wpcf7dtx_sanitize', $value, $type); // Sanitize value if (!empty($value)) { if ($obfuscate) { @@ -99,8 +91,6 @@ function wpcf7dtx_escape($value = '', $obfuscate = false, $type = 'auto', $proto switch ($type) { case 'url': return esc_url($value, apply_filters('wpcf7dtx_allow_protocols', $protocols)); - case 'textarea': - return esc_textarea($value); } } return esc_attr($value); // Return attribute value @@ -192,449 +182,51 @@ function wpcf7dtx_get_post_id($post_id, $context = 'dtx') } /** - * Get Dynamic Value + * Parse Content for Specified Shortcodes * - * @since 3.2.2 + * Parse a string of content for a specific shortcode to retrieve its attributes and content * - * @param string $value The form tag value. - * @param WPCF7_FormTag|false $tag Optional. Use to look up default value. - * @param string $sanitize Optional. Specify type of sanitization. Default is `auto`. + * @since 3.1.0 * - * @return string The dynamic output or the original value, not escaped or sanitized. + * @param string $content The content to parse + * @param string $tag The shortcode tag + * + * @return array An associative array with `tag` (string) and `shortcodes` (sequential array). If shortcodes were discovered, each one has keys for `atts` (associative array) and `content` (string) */ -function wpcf7dtx_get_dynamic($value, $tag = false, $sanitize = 'auto') +function wpcf7dtx_get_shortcode_atts($content) { - if ($tag !== false) { - $default = $tag->get_option('defaultvalue', '', true); - if (!$default) { - $default = $tag->get_default_option(strval(reset($tag->values))); - } - $value = wpcf7_get_hangover($tag->name, $default); - } - $value = apply_filters('wpcf7dtx_sanitize', $value, $sanitize); - if (is_string($value) && !empty($value)) { - // If a shortcode was passed as the value, evaluate it and use the result - $shortcode_tag = '[' . $value . ']'; - $shortcode_output = do_shortcode($shortcode_tag); //Shortcode value - if (is_string($shortcode_output) && $shortcode_output != $shortcode_tag) { - return apply_filters('wpcf7dtx_sanitize', $shortcode_output, $sanitize); - } - } - return $value; -} - -/** - * Get Allowed HTML for Form Field Properties - * - * @since 4.0.0 - * - * @param string $type Optional. The type of input for unique properties. Default is `text`. - * @param array $extra Optional. A sequential array of properties to additionally include. - * - * @return array An associative array of allowed properties appropriate for use in `wp_kses()` - */ -function wpcf7dtx_get_allowed_field_properties($type = 'text', $extra = array()) -{ - if (in_array($type, array('option', 'optgroup'))) { - return array( - 'optgroup' => array( - 'label' => array(), - 'disabled' => array(), - 'hidden' => array() - ), - 'option' => array( - 'value' => array(), - 'selected' => array(), - 'disabled' => array(), - 'hidden' => array() - ) - ); - } - $allowed_properties = array( - // Global properties - 'type' => array(), - 'id' => array(), - 'name' => array(), - 'value' => array(), - 'required' => array(), - 'class' => array(), - 'disabled' => array(), - 'readonly' => array(), - 'tabindex' => array(), - 'size' => array(), - 'title' => array(), - 'autofocus' => array(), - // ARIA properties - 'aria-invalid' => array(), - 'aria-describedby' => array(), - // DTX properties - 'data-dtx-value' => array(), + $return = array( + 'tag' => '', + 'atts' => array() ); - if (in_array($type, array('checkbox', 'radio', 'acceptance'))) { - // Properties exclusive to checkboxes and radio buttons - $allowed_properties['checked'] = array(); - $allowed_properties['dtx-default'] = array(); - } elseif (in_array($type, array('number', 'range'))) { - // Properties exclusive to number inputs - $allowed_properties['step'] = array(); - } elseif ($type == 'select') { - // Properties exclusive to select fields - $allowed_properties['multiple'] = array(); - $allowed_properties['dtx-default'] = array(); - unset($allowed_properties['type'], $allowed_properties['value'], $allowed_properties['placeholder'], $allowed_properties['size']); // Remove invalid select attributes - } - if (!in_array($type, array('checkbox', 'radio', 'select', 'acceptance'))) { - // Allowed properties for all text-based inputs - $allowed_properties['placeholder'] = array(); - $allowed_properties['autocomplete'] = array(); - $allowed_properties['minlength'] = array(); - $allowed_properties['maxlength'] = array(); - if (in_array($type, array('number', 'range', 'date', 'datetime-local', 'time'))) { - // Additional properties for number and date inputs - $allowed_properties['min'] = array(); - $allowed_properties['max'] = array(); - } - if ($type == 'textarea') { - // Additional properties exclusive to textarea fields - $allowed_properties['cols'] = array(); - $allowed_properties['rows'] = array(); - unset($allowed_properties['type'], $allowed_properties['value']); // Remove invalid textarea attributes - } elseif (in_array($type, array('text', 'date', 'url', 'tel', 'email', 'password'))) { - // Additional properties exclusive to specific text fields - $allowed_properties['pattern'] = array(); - } - } - if (is_array($extra) && count($extra)) { - foreach ($extra as $property) { - $allowed_properties[sanitize_title($property)] = array(); - } - } - return $allowed_properties; -} + //Search for shortcodes with attributes + if (false !== ($start = strpos($content, ' '))) { + $return['tag'] = substr($content, 0, $start); //Opens the start tag, assumes there are attributes because of the space -/** - * Returns a formatted string of HTML attributes - * - * @since 4.0.0 - * - * @param array $atts Associative array of attribute name and value pairs - * - * @return string Formatted HTML attributes with keys and values both escaped - */ -function wpcf7dtx_format_atts($atts) -{ - if (is_array($atts) && count($atts)) { - $sanitized_atts = array(); - static $boolean_attributes = array( - 'checked', 'disabled', 'multiple', 'readonly', 'required', 'selected' - ); - foreach ($atts as $key => $value) { - $key = sanitize_key(strval($key)); - if ($key) { - if (in_array($key, $boolean_attributes) || is_bool($value)) { - if ($value) { - $sanitized_atts[$key] = $key; - } - } elseif ($value && (is_string($value) || is_numeric($value))) { - $sanitized_atts[$key] = $value; - } - } - } - if (count($sanitized_atts)) { - $output = array(); - foreach ($sanitized_atts as $key => $value) { - $output[] = sprintf('%s="%s"', esc_attr($key), esc_attr($value)); - } - return implode(' ', $output); - } - } - return ''; -} + //Parse for shortcode attributes: `shortcode att1='foo' att2='bar'` -/** - * Create Input Field HTML - * - * @since 4.0.0 - * - * @param array $atts An associative array of input attributes. - * - * @return string HTML output of input field - */ -function wpcf7dtx_input_html($atts) -{ - return sprintf('', wpcf7dtx_format_atts($atts)); -} - -/** - * Create Checkbox Field HTML - * - * @since 4.0.0 - * - * @param array $atts An associative array of select input attributes. - * @param string $label_text Optional. The text to display next to the checkbox or radio button. - * @param bool $label_ui Optional. If true, will place input and label text inside a `