| @@ -5,43 +5,21 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmFormsHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Store and re-use field type data for the insert_opt_html function (to avoid multiple calls to FrmField::all_field_selection). | |
| 10 | - * | |
| 11 | - * @since 6.10 | |
| 12 | - * | |
| 13 | - * @var array|null | |
| 14 | - */ | |
| 15 | - private static $field_type_data_for_insert_opt_html; | |
| 16 | - | |
| 17 | - /** | |
| 18 | 9 | * @since 2.2.10 |
| 19 | - * | |
| 20 | - * @return string | |
| 21 | 10 | */ |
| 22 | 11 | public static function form_error_class() { |
| 23 | 12 | return apply_filters( 'frm_form_error_class', 'frm_error_style' ); |
| 24 | 13 | } |
| 25 | 14 | |
| 26 | - /** | |
| 27 | - * @param string $key | |
| 28 | - * @param false|object $form | |
| 29 | - * | |
| 30 | - * @return string | |
| 31 | - */ | |
| 32 | 15 | public static function get_direct_link( $key, $form = false ) { |
| 33 | 16 | $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) ); |
| 34 | - return apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 17 | + $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 18 | + | |
| 19 | + return $target_url; | |
| 35 | 20 | } |
| 36 | 21 | |
| 37 | - /** | |
| 38 | - * @param string $field_name | |
| 39 | - * @param int|string $field_value | |
| 40 | - * @param array $args | |
| 41 | - * | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | 22 | public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) { |
| 45 | 23 | $defaults = array( |
| 46 | 24 | 'blank' => true, |
| 47 | 25 | 'field_id' => false, |
| @@ -56,9 +34,8 @@ | ||
| 56 | 34 | $args['field_id'] = $field_name; |
| 57 | 35 | } |
| 58 | 36 | |
| 59 | 37 | $query = array(); |
| 60 | - | |
| 61 | 38 | if ( $args['exclude'] ) { |
| 62 | 39 | $query['id !'] = $args['exclude']; |
| 63 | 40 | } |
| 64 | 41 | |
| @@ -67,47 +44,41 @@ | ||
| 67 | 44 | $add_html = array(); |
| 68 | 45 | self::add_html_attr( $args['onchange'], 'onchange', $add_html ); |
| 69 | 46 | self::add_html_attr( $args['class'], 'class', $add_html ); |
| 70 | 47 | |
| 71 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 72 | 48 | ?> |
| 73 | 49 | <select name="<?php echo esc_attr( $field_name ); ?>" |
| 74 | 50 | id="<?php echo esc_attr( $args['field_id'] ); ?>" |
| 75 | 51 | <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 76 | 52 | <?php if ( $args['blank'] ) { ?> |
| 77 | - <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; // phpcs:ignore Universal.Operators.StrictComparisons ?></option> | |
| 53 | + <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 78 | 54 | <?php } ?> |
| 79 | 55 | <?php foreach ( $forms as $form ) { ?> |
| 80 | 56 | <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> |
| 81 | - <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 57 | + <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> | |
| 82 | 58 | </option> |
| 83 | 59 | <?php } ?> |
| 84 | 60 | </select> |
| 85 | 61 | <?php |
| 86 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 87 | 62 | } |
| 88 | 63 | |
| 89 | 64 | /** |
| 90 | - * @since 2.0.6 | |
| 91 | - * | |
| 92 | 65 | * @param string $class |
| 93 | 66 | * @param string $param |
| 94 | - * @param array $add_html | |
| 67 | + * @param array $add_html | |
| 95 | 68 | * |
| 96 | - * @return void | |
| 69 | + * @since 2.0.6 | |
| 97 | 70 | */ |
| 98 | 71 | public static function add_html_attr( $class, $param, &$add_html ) { |
| 99 | - if ( $class ) { | |
| 100 | - $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( sanitize_text_field( $class ) ) . '"'; | |
| 72 | + if ( ! empty( $class ) ) { | |
| 73 | + $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"'; | |
| 101 | 74 | } |
| 102 | 75 | } |
| 103 | 76 | |
| 104 | 77 | /** |
| 105 | - * @param false|object|string $selected - The label for the placeholder, or the form object. | |
| 106 | - * | |
| 107 | - * @return void | |
| 78 | + * @param string|object|false $selected - The label for the placeholder, or the form object. | |
| 108 | 79 | */ |
| 109 | - public static function form_switcher( $selected = false ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 80 | + public static function form_switcher( $selected = false ) { | |
| 110 | 81 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 111 | 82 | $forms = FrmForm::get_published_forms( $where ); |
| 112 | 83 | |
| 113 | 84 | $args = array( |
| @@ -113,9 +84,8 @@ | ||
| 113 | 84 | $args = array( |
| 114 | 85 | 'id' => 0, |
| 115 | 86 | 'form' => 0, |
| 116 | 87 | ); |
| 117 | - | |
| 118 | 88 | if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) { |
| 119 | 89 | unset( $args['form'] ); |
| 120 | 90 | } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) { |
| 121 | 91 | unset( $args['id'] ); |
| @@ -121,43 +91,28 @@ | ||
| 121 | 91 | unset( $args['id'] ); |
| 122 | 92 | } |
| 123 | 93 | |
| 124 | 94 | $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 125 | - | |
| 126 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) { | |
| 95 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ) ) ) { | |
| 127 | 96 | $args['frm_action'] = 'list'; |
| 128 | 97 | $args['form'] = 0; |
| 129 | - } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) { | |
| 98 | + } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) { | |
| 130 | 99 | $args['frm_action'] = 'edit'; |
| 131 | - } elseif ( FrmAppHelper::is_style_editor_page() ) { | |
| 132 | - // Avoid passing style into form switcher on style page. | |
| 133 | - unset( $args['id'] ); | |
| 134 | - $query_args = array( | |
| 135 | - 'page' => 'formidable-styles', | |
| 136 | - ); | |
| 137 | - | |
| 138 | - if ( $frm_action ) { | |
| 139 | - $query_args['frm_action'] = $frm_action; | |
| 140 | - } | |
| 141 | - | |
| 142 | - $base = add_query_arg( $query_args, admin_url( 'admin.php' ) ); | |
| 143 | 100 | } elseif ( isset( $_GET['post'] ) ) { |
| 144 | 101 | $args['form'] = 0; |
| 145 | 102 | $base = admin_url( 'edit.php?post_type=frm_display' ); |
| 146 | - }//end if | |
| 103 | + } | |
| 147 | 104 | |
| 148 | 105 | $form_id = 0; |
| 149 | - | |
| 150 | 106 | if ( is_object( $selected ) ) { |
| 151 | 107 | $form_id = $selected->id; |
| 152 | 108 | $selected = $selected->name; |
| 153 | 109 | } |
| 154 | 110 | |
| 155 | - $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected; | |
| 156 | - $name = '' === $name || is_null( $name ) ? self::get_no_title_text() : strip_tags( $name ); | |
| 111 | + $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected; | |
| 112 | + $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name ); | |
| 157 | 113 | $truncated_name = FrmAppHelper::truncate( $name, 25 ); |
| 158 | 114 | |
| 159 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 160 | 115 | if ( count( $forms ) < 2 ) { |
| 161 | 116 | ?> |
| 162 | 117 | <div id="frm_bs_dropdown"> |
| 163 | 118 | <h1> |
| @@ -169,15 +124,15 @@ | ||
| 169 | 124 | <?php |
| 170 | 125 | return; |
| 171 | 126 | } |
| 172 | 127 | ?> |
| 173 | - <div id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'dropdown-menu-right' : 'dropdown-menu-left' ); ?>"> | |
| 128 | + <div id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ); ?>"> | |
| 174 | 129 | <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"> |
| 175 | 130 | <h1> |
| 176 | 131 | <span class="frm_bstooltip" title="<?php echo esc_attr( $truncated_name === $name ? '' : $name ); ?>" data-placement="right"> |
| 177 | 132 | <?php echo esc_html( $name ); ?> |
| 178 | 133 | </span> |
| 179 | - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) ); ?> | |
| 134 | + <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown4_icon', array( 'aria-hidden' => 'true' ) ); ?> | |
| 180 | 135 | </h1> |
| 181 | 136 | </a> |
| 182 | 137 | <ul class="frm-dropdown-menu frm-on-top frm-inline-modal frm_code_list frm-full-hover" role="menu" aria-labelledby="frm-navbarDrop"> |
| 183 | 138 | <?php if ( count( $forms ) > 8 ) { ?> |
| @@ -187,10 +142,8 @@ | ||
| 187 | 142 | array( |
| 188 | 143 | 'input_id' => 'dropform', |
| 189 | 144 | 'placeholder' => __( 'Search Forms', 'formidable' ), |
| 190 | 145 | 'tosearch' => 'frm-dropdown-form', |
| 191 | - // Specify a value to avoid the $_REQUEST['s'] default value. | |
| 192 | - 'value' => '', | |
| 193 | 146 | ) |
| 194 | 147 | ); |
| 195 | 148 | ?> |
| 196 | 149 | </li> |
| @@ -204,20 +157,18 @@ | ||
| 204 | 157 | |
| 205 | 158 | if ( isset( $args['id'] ) ) { |
| 206 | 159 | $args['id'] = $form->id; |
| 207 | 160 | } |
| 208 | - | |
| 209 | 161 | if ( isset( $args['form'] ) ) { |
| 210 | 162 | $args['form'] = $form->id; |
| 211 | 163 | } |
| 212 | 164 | |
| 213 | 165 | $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ); |
| 214 | - $form_name = ! empty( $form->name ) ? $form->name : self::get_no_title_text(); | |
| 166 | + $form_name = empty( $form->name ) ? __( '(no title)', 'formidable' ) : $form->name; | |
| 215 | 167 | ?> |
| 216 | 168 | <li class="frm-dropdown-form"> |
| 217 | - <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between"> | |
| 218 | - <?php echo esc_html( $form_name ); ?> | |
| 219 | - <span> | |
| 169 | + <a href="<?php echo esc_url( $url ); ?>" tabindex="-1"> | |
| 170 | + <span class="frm-sub-label"> | |
| 220 | 171 | <?php |
| 221 | 172 | printf( |
| 222 | 173 | /* translators: %d: Form ID */ |
| 223 | 174 | esc_html__( '(ID %d)', 'formidable' ), |
| @@ -224,53 +175,60 @@ | ||
| 224 | 175 | esc_attr( $form->id ) |
| 225 | 176 | ); |
| 226 | 177 | ?> |
| 227 | 178 | </span> |
| 179 | + <?php echo esc_html( $form_name ); ?> | |
| 228 | 180 | <span class="frm_hidden"><?php echo esc_html( $form->form_key ); ?></span> |
| 229 | 181 | </a> |
| 230 | 182 | </li> |
| 231 | 183 | <?php |
| 232 | 184 | unset( $form ); |
| 233 | - }//end foreach | |
| 185 | + } | |
| 234 | 186 | ?> |
| 235 | 187 | </ul> |
| 236 | 188 | </div> |
| 237 | 189 | <?php |
| 238 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 239 | 190 | } |
| 240 | 191 | |
| 241 | 192 | /** |
| 242 | - * @param string $col | |
| 243 | - * @param string $sort_col | |
| 244 | - * @param string $sort_dir | |
| 193 | + * @since 3.05 | |
| 194 | + * @deprecated 4.0 | |
| 245 | 195 | * |
| 246 | - * @return void | |
| 196 | + * @param array $values - The form array | |
| 247 | 197 | */ |
| 198 | + public static function builder_submit_button( $values ) { | |
| 199 | + FrmDeprecated::builder_submit_button( $values ); | |
| 200 | + } | |
| 201 | + | |
| 248 | 202 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 249 | - echo $sort_col == $col ? 'sorted' : 'sortable'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 250 | - echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 203 | + echo ( $sort_col == $col ) ? 'sorted' : 'sortable'; | |
| 204 | + echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc'; | |
| 251 | 205 | } |
| 252 | 206 | |
| 253 | 207 | /** |
| 254 | 208 | * @since 3.0 |
| 255 | - * | |
| 256 | - * @param array|string $field_type | |
| 257 | - * | |
| 258 | - * @return string | |
| 259 | 209 | */ |
| 260 | 210 | public static function get_field_link_name( $field_type ) { |
| 261 | - return is_array( $field_type ) ? $field_type['name'] : $field_type; | |
| 211 | + if ( is_array( $field_type ) ) { | |
| 212 | + $field_label = $field_type['name']; | |
| 213 | + } else { | |
| 214 | + $field_label = $field_type; | |
| 215 | + } | |
| 216 | + | |
| 217 | + return $field_label; | |
| 262 | 218 | } |
| 263 | 219 | |
| 264 | 220 | /** |
| 265 | 221 | * @since 3.0 |
| 266 | - * | |
| 267 | - * @param array|string $field_type | |
| 268 | - * | |
| 269 | - * @return string | |
| 270 | 222 | */ |
| 271 | 223 | public static function get_field_link_icon( $field_type ) { |
| 272 | - return is_array( $field_type ) && isset( $field_type['icon'] ) ? $field_type['icon'] : 'frmfont frm_pencil_icon'; | |
| 224 | + if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) { | |
| 225 | + $icon = $field_type['icon']; | |
| 226 | + } else { | |
| 227 | + $icon = 'frm_icon_font frm_pencil_icon'; | |
| 228 | + } | |
| 229 | + | |
| 230 | + return $icon; | |
| 273 | 231 | } |
| 274 | 232 | |
| 275 | 233 | /** |
| 276 | 234 | * Get the invalid form error message |
| @@ -282,71 +240,36 @@ | ||
| 282 | 240 | * @return string |
| 283 | 241 | */ |
| 284 | 242 | public static function get_invalid_error_message( $args ) { |
| 285 | 243 | $settings_args = $args; |
| 286 | - | |
| 287 | 244 | if ( isset( $args['form'] ) ) { |
| 288 | 245 | $settings_args['current_form'] = $args['form']->id; |
| 289 | 246 | } |
| 290 | 247 | |
| 291 | 248 | $frm_settings = FrmAppHelper::get_settings( $settings_args ); |
| 292 | - $invalid_msg = do_shortcode( $frm_settings->invalid_msg ); | |
| 249 | + $invalid_msg = do_shortcode( $frm_settings->invalid_msg ); | |
| 293 | 250 | return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args ); |
| 294 | 251 | } |
| 295 | 252 | |
| 296 | - /** | |
| 297 | - * @param array $atts { | |
| 298 | - * The success message details. | |
| 299 | - * | |
| 300 | - * @type string $message | |
| 301 | - * @type stdClass $form | |
| 302 | - * @type int $entry_id | |
| 303 | - * @type string $class | |
| 304 | - * } | |
| 305 | - * | |
| 306 | - * @return string | |
| 307 | - */ | |
| 308 | 253 | public static function get_success_message( $atts ) { |
| 309 | 254 | $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] ); |
| 255 | + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) ); | |
| 256 | + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 310 | 257 | |
| 311 | - // Only autop if the message includes line breaks. | |
| 312 | - $autop = str_contains( $message, "\n" ); | |
| 313 | - | |
| 314 | - /** | |
| 315 | - * Filters whether to autop the success message. | |
| 316 | - * This is false by default if the message does not include line breaks. | |
| 317 | - * | |
| 318 | - * @since 6.23 | |
| 319 | - * | |
| 320 | - * @param bool $autop | |
| 321 | - * @param string $message | |
| 322 | - * @param object $form | |
| 323 | - */ | |
| 324 | - $autop = (bool) apply_filters( 'frm_wpautop_success_message', $autop, $message, $atts['form'] ); | |
| 325 | - | |
| 326 | - if ( $autop ) { | |
| 327 | - $message = FrmAppHelper::use_wpautop( $message ); | |
| 328 | - } | |
| 329 | - | |
| 330 | - $message = do_shortcode( $message ); | |
| 331 | - return '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 258 | + return $message; | |
| 332 | 259 | } |
| 333 | 260 | |
| 334 | 261 | /** |
| 335 | 262 | * Used when a form is created |
| 336 | - * | |
| 337 | - * @param array $values | |
| 338 | - * | |
| 339 | - * @return array | |
| 340 | 263 | */ |
| 341 | 264 | public static function setup_new_vars( $values = array() ) { |
| 342 | 265 | global $wpdb; |
| 343 | 266 | |
| 344 | - if ( $values ) { | |
| 267 | + if ( ! empty( $values ) ) { | |
| 345 | 268 | $post_values = $values; |
| 346 | 269 | } else { |
| 347 | 270 | $values = array(); |
| 348 | - $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 271 | + $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 349 | 272 | } |
| 350 | 273 | |
| 351 | 274 | $defaults = array( |
| 352 | 275 | 'name' => '', |
| @@ -351,9 +274,8 @@ | ||
| 351 | 274 | $defaults = array( |
| 352 | 275 | 'name' => '', |
| 353 | 276 | 'description' => '', |
| 354 | 277 | ); |
| 355 | - | |
| 356 | 278 | foreach ( $defaults as $var => $default ) { |
| 357 | 279 | if ( ! isset( $values[ $var ] ) ) { |
| 358 | 280 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 359 | 281 | } |
| @@ -368,9 +290,8 @@ | ||
| 368 | 290 | 'is_template' => 0, |
| 369 | 291 | 'status' => 'published', |
| 370 | 292 | 'parent_form_id' => 0, |
| 371 | 293 | ); |
| 372 | - | |
| 373 | 294 | foreach ( $defaults as $var => $default ) { |
| 374 | 295 | if ( ! isset( $values[ $var ] ) ) { |
| 375 | 296 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 376 | 297 | } |
| @@ -377,9 +298,9 @@ | ||
| 377 | 298 | } |
| 378 | 299 | unset( $defaults ); |
| 379 | 300 | |
| 380 | 301 | if ( ! isset( $values['form_key'] ) ) { |
| 381 | - $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 302 | + $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); | |
| 382 | 303 | } |
| 383 | 304 | |
| 384 | 305 | $values = self::fill_default_opts( $values, false, $post_values ); |
| 385 | 306 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| @@ -388,22 +309,16 @@ | ||
| 388 | 309 | } |
| 389 | 310 | |
| 390 | 311 | /** |
| 391 | 312 | * Used when editing a form |
| 392 | - * | |
| 393 | - * @param array $values | |
| 394 | - * @param object $record | |
| 395 | - * @param array $post_values | |
| 396 | - * | |
| 397 | - * @return array | |
| 398 | 313 | */ |
| 399 | 314 | public static function setup_edit_vars( $values, $record, $post_values = array() ) { |
| 400 | - if ( ! $post_values ) { | |
| 315 | + if ( empty( $post_values ) ) { | |
| 401 | 316 | $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 402 | 317 | } |
| 403 | 318 | |
| 404 | - $values['form_key'] = $post_values['form_key'] ?? $record->form_key; | |
| 405 | - $values['is_template'] = $post_values['is_template'] ?? $record->is_template; | |
| 319 | + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key; | |
| 320 | + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template; | |
| 406 | 321 | $values['status'] = $record->status; |
| 407 | 322 | |
| 408 | 323 | $values = self::fill_default_opts( $values, $record, $post_values ); |
| 409 | 324 | |
| @@ -409,31 +324,23 @@ | ||
| 409 | 324 | |
| 410 | 325 | return apply_filters( 'frm_setup_edit_form_vars', $values ); |
| 411 | 326 | } |
| 412 | 327 | |
| 413 | - /** | |
| 414 | - * @param array $values | |
| 415 | - * @param false|object $record | |
| 416 | - * @param array|false $post_values | |
| 417 | - * | |
| 418 | - * @return array | |
| 419 | - */ | |
| 420 | - public static function fill_default_opts( $values, $record, $post_values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 328 | + public static function fill_default_opts( $values, $record, $post_values ) { | |
| 421 | 329 | |
| 422 | 330 | $defaults = self::get_default_opts(); |
| 423 | - | |
| 424 | 331 | foreach ( $defaults as $var => $default ) { |
| 425 | 332 | if ( is_array( $default ) ) { |
| 426 | 333 | if ( ! isset( $values[ $var ] ) ) { |
| 427 | - $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); | |
| 334 | + $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array(); | |
| 428 | 335 | } |
| 429 | 336 | |
| 430 | 337 | foreach ( $default as $k => $v ) { |
| 431 | - $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 338 | + $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v ); | |
| 432 | 339 | |
| 433 | 340 | if ( is_array( $v ) ) { |
| 434 | 341 | foreach ( $v as $k1 => $v1 ) { |
| 435 | - $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 342 | + $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); | |
| 436 | 343 | unset( $k1, $v1 ); |
| 437 | 344 | } |
| 438 | 345 | } |
| 439 | 346 | |
| @@ -439,13 +346,13 @@ | ||
| 439 | 346 | |
| 440 | 347 | unset( $k, $v ); |
| 441 | 348 | } |
| 442 | 349 | } else { |
| 443 | - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 350 | + $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default ); | |
| 444 | 351 | } |
| 445 | 352 | |
| 446 | 353 | unset( $var, $default ); |
| 447 | - }//end foreach | |
| 354 | + } | |
| 448 | 355 | |
| 449 | 356 | return $values; |
| 450 | 357 | } |
| 451 | 358 | |
| @@ -460,9 +367,9 @@ | ||
| 460 | 367 | 'success_action' => 'message', |
| 461 | 368 | 'success_msg' => $frm_settings->success_msg, |
| 462 | 369 | 'show_form' => 0, |
| 463 | 370 | 'akismet' => '', |
| 464 | - 'stopforumspam' => 0, | |
| 371 | + 'honeypot' => 'basic', | |
| 465 | 372 | 'antispam' => 0, |
| 466 | 373 | 'no_save' => 0, |
| 467 | 374 | 'ajax_load' => 0, |
| 468 | 375 | 'js_validate' => 0, |
| @@ -472,25 +379,21 @@ | ||
| 472 | 379 | 'after_html' => '', |
| 473 | 380 | 'submit_html' => self::get_default_html( 'submit' ), |
| 474 | 381 | 'show_title' => 0, |
| 475 | 382 | 'show_description' => 0, |
| 476 | - 'ajax_submit' => 0, | |
| 477 | 383 | ); |
| 478 | 384 | } |
| 479 | 385 | |
| 480 | 386 | /** |
| 481 | - * @since 2.0.6 | |
| 482 | - * | |
| 483 | 387 | * @param array $options |
| 484 | 388 | * @param array $values |
| 485 | 389 | * |
| 486 | - * @return void | |
| 390 | + * @since 2.0.6 | |
| 487 | 391 | */ |
| 488 | 392 | public static function fill_form_options( &$options, $values ) { |
| 489 | 393 | $defaults = self::get_default_opts(); |
| 490 | - | |
| 491 | 394 | foreach ( $defaults as $var => $default ) { |
| 492 | - $options[ $var ] = $values['options'][ $var ] ?? $default; | |
| 395 | + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default; | |
| 493 | 396 | unset( $var, $default ); |
| 494 | 397 | } |
| 495 | 398 | } |
| 496 | 399 | |
| @@ -495,24 +398,22 @@ | ||
| 495 | 398 | } |
| 496 | 399 | |
| 497 | 400 | /** |
| 498 | 401 | * @param string $loc |
| 499 | - * | |
| 500 | - * @return string | |
| 501 | 402 | */ |
| 502 | 403 | public static function get_default_html( $loc ) { |
| 503 | - if ( $loc === 'submit' ) { | |
| 404 | + if ( $loc == 'submit' ) { | |
| 504 | 405 | $draft_link = self::get_draft_link(); |
| 505 | 406 | $start_over = self::get_start_over_shortcode(); |
| 506 | 407 | $default_html = <<<SUBMIT_HTML |
| 507 | -<div class="frm_submit frm_flex"> | |
| 408 | +<div class="frm_submit"> | |
| 409 | +[if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] | |
| 508 | 410 | <button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> |
| 509 | -[if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] | |
| 510 | 411 | $draft_link |
| 511 | 412 | $start_over |
| 512 | 413 | </div> |
| 513 | 414 | SUBMIT_HTML; |
| 514 | - } elseif ( $loc === 'before' ) { | |
| 415 | + } elseif ( $loc == 'before' ) { | |
| 515 | 416 | $default_html = <<<BEFORE_HTML |
| 516 | 417 | <legend class="frm_screen_reader">[form_name]</legend> |
| 517 | 418 | [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name] |
| 518 | 419 | [if form_description]<div class="frm_description">[form_description]</div>[/if form_description] |
| @@ -523,13 +424,12 @@ | ||
| 523 | 424 | |
| 524 | 425 | return $default_html; |
| 525 | 426 | } |
| 526 | 427 | |
| 527 | - /** | |
| 528 | - * @return string | |
| 529 | - */ | |
| 530 | 428 | public static function get_draft_link() { |
| 531 | - return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 429 | + $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]'; | |
| 430 | + | |
| 431 | + return $link; | |
| 532 | 432 | } |
| 533 | 433 | |
| 534 | 434 | /** |
| 535 | 435 | * Gets start over button shortcode. |
| @@ -541,21 +441,11 @@ | ||
| 541 | 441 | public static function get_start_over_shortcode() { |
| 542 | 442 | return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]'; |
| 543 | 443 | } |
| 544 | 444 | |
| 545 | - /** | |
| 546 | - * @param string $html | |
| 547 | - * @param object $form | |
| 548 | - * @param string $submit | |
| 549 | - * @param object|null $form_action | |
| 550 | - * @param array $values | |
| 551 | - * | |
| 552 | - * @return void | |
| 553 | - */ | |
| 554 | 445 | public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) { |
| 555 | 446 | $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values ); |
| 556 | - | |
| 557 | - if ( ! str_contains( $button, '[button_action]' ) ) { | |
| 447 | + if ( ! strpos( $button, '[button_action]' ) ) { | |
| 558 | 448 | echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 559 | 449 | return; |
| 560 | 450 | } |
| 561 | 451 | |
| @@ -562,21 +452,18 @@ | ||
| 562 | 452 | /** |
| 563 | 453 | * @since 5.0.06 |
| 564 | 454 | */ |
| 565 | 455 | $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) ); |
| 566 | - | |
| 567 | 456 | if ( FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| 568 | 457 | $button = FrmAppHelper::kses_submit_button( $button ); |
| 569 | 458 | } |
| 570 | - | |
| 571 | 459 | $button_parts = explode( '[button_action]', $button ); |
| 572 | - $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 573 | 460 | |
| 574 | - if ( $classes ) { | |
| 461 | + $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 462 | + if ( ! empty( $classes ) ) { | |
| 575 | 463 | $classes = implode( ' ', $classes ); |
| 576 | - $button_class = 'frm_button_submit'; | |
| 577 | - | |
| 578 | - if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) { | |
| 464 | + $button_class = ' class="frm_button_submit'; | |
| 465 | + if ( strpos( $button_parts[0], $button_class ) !== false ) { | |
| 579 | 466 | $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] ); |
| 580 | 467 | } else { |
| 581 | 468 | $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"'; |
| 582 | 469 | } |
| @@ -588,56 +475,54 @@ | ||
| 588 | 475 | } |
| 589 | 476 | |
| 590 | 477 | /** |
| 591 | 478 | * @since 4.0 |
| 592 | - * | |
| 593 | - * @return array | |
| 594 | 479 | */ |
| 595 | 480 | public static function html_shortcodes() { |
| 596 | 481 | $codes = array( |
| 597 | - 'id' => array( | |
| 482 | + 'id' => array( | |
| 598 | 483 | 'label' => __( 'Field ID', 'formidable' ), |
| 599 | 484 | 'class' => 'show_field_custom_html', |
| 600 | 485 | ), |
| 601 | - 'key' => array( | |
| 486 | + 'key' => array( | |
| 602 | 487 | 'label' => __( 'Field Key', 'formidable' ), |
| 603 | 488 | 'class' => 'show_field_custom_html', |
| 604 | 489 | ), |
| 605 | - 'field_name' => array( | |
| 490 | + 'field_name' => array( | |
| 606 | 491 | 'label' => __( 'Field Name', 'formidable' ), |
| 607 | 492 | 'class' => 'show_field_custom_html', |
| 608 | 493 | ), |
| 609 | - 'description' => array( | |
| 494 | + 'description' => array( | |
| 610 | 495 | 'label' => __( 'Field Description', 'formidable' ), |
| 611 | 496 | 'class' => 'show_field_custom_html', |
| 612 | 497 | ), |
| 613 | - 'label_position' => array( | |
| 498 | + 'label_position' => array( | |
| 614 | 499 | 'label' => __( 'Label Position', 'formidable' ), |
| 615 | 500 | 'class' => 'show_field_custom_html', |
| 616 | 501 | ), |
| 617 | - 'required_label' => array( | |
| 502 | + 'required_label' => array( | |
| 618 | 503 | 'label' => __( 'Required Label', 'formidable' ), |
| 619 | 504 | 'class' => 'show_field_custom_html', |
| 620 | 505 | ), |
| 621 | - 'input' => array( | |
| 506 | + 'input' => array( | |
| 622 | 507 | 'label' => __( 'Input Field', 'formidable' ), |
| 623 | 508 | 'class' => 'show_field_custom_html', |
| 624 | 509 | ), |
| 625 | - 'input opt=1' => array( | |
| 510 | + 'input opt=1' => array( | |
| 626 | 511 | 'label' => __( 'Single Option', 'formidable' ), |
| 627 | 512 | 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ), |
| 628 | 513 | 'class' => 'show_field_custom_html', |
| 629 | 514 | ), |
| 630 | - 'input label=0' => array( | |
| 515 | + 'input label=0' => array( | |
| 631 | 516 | 'label' => __( 'Hide Option Label', 'formidable' ), |
| 632 | 517 | 'class' => 'show_field_custom_html', |
| 633 | 518 | ), |
| 634 | - 'required_class' => array( | |
| 519 | + 'required_class' => array( | |
| 635 | 520 | 'label' => __( 'Required Class', 'formidable' ), |
| 636 | 521 | 'title' => __( 'Add class name if field is required', 'formidable' ), |
| 637 | 522 | 'class' => 'show_field_custom_html', |
| 638 | 523 | ), |
| 639 | - 'error_class' => array( | |
| 524 | + 'error_class' => array( | |
| 640 | 525 | 'label' => __( 'Error Class', 'formidable' ), |
| 641 | 526 | 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ), |
| 642 | 527 | 'class' => 'show_field_custom_html', |
| 643 | 528 | ), |
| @@ -658,13 +543,13 @@ | ||
| 658 | 543 | 'label' => __( 'Delete Entry Link', 'formidable' ), |
| 659 | 544 | 'class' => 'show_before_html show_after_html', |
| 660 | 545 | ), |
| 661 | 546 | |
| 662 | - 'button_label' => array( | |
| 547 | + 'button_label' => array( | |
| 663 | 548 | 'label' => __( 'Button Label', 'formidable' ), |
| 664 | 549 | 'class' => 'show_submit_html', |
| 665 | 550 | ), |
| 666 | - 'button_action' => array( | |
| 551 | + 'button_action' => array( | |
| 667 | 552 | 'label' => __( 'Button Hook', 'formidable' ), |
| 668 | 553 | 'class' => 'show_submit_html', |
| 669 | 554 | ), |
| 670 | 555 | ); |
| @@ -676,17 +561,14 @@ | ||
| 676 | 561 | } |
| 677 | 562 | |
| 678 | 563 | /** |
| 679 | 564 | * @since 4.0 |
| 680 | - * | |
| 681 | 565 | * @param array $args |
| 682 | - * | |
| 683 | - * @return void | |
| 684 | 566 | */ |
| 685 | 567 | public static function insert_opt_html( $args ) { |
| 686 | - $class = $args['class'] ?? ''; | |
| 687 | - $fields = self::get_field_type_data_for_insert_opt_html(); | |
| 688 | - $field = $fields[ $args['type'] ] ?? array(); | |
| 568 | + $class = isset( $args['class'] ) ? $args['class'] : ''; | |
| 569 | + $fields = FrmField::all_field_selection(); | |
| 570 | + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array(); | |
| 689 | 571 | |
| 690 | 572 | self::prepare_field_type( $field ); |
| 691 | 573 | |
| 692 | 574 | if ( ! isset( $field['icon'] ) ) { |
| @@ -693,9 +575,8 @@ | ||
| 693 | 575 | $field['icon'] = 'frmfont frm_pencil_icon'; |
| 694 | 576 | } |
| 695 | 577 | |
| 696 | 578 | $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' ); |
| 697 | - | |
| 698 | 579 | if ( $possible_email_field ) { |
| 699 | 580 | $class .= ' show_frm_not_email_to'; |
| 700 | 581 | } |
| 701 | 582 | |
| @@ -701,60 +582,31 @@ | ||
| 701 | 582 | |
| 702 | 583 | if ( 'url' === $args['type'] ) { |
| 703 | 584 | $class .= ' frm_insert_url'; |
| 704 | 585 | } |
| 705 | - | |
| 706 | - $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ); | |
| 707 | - | |
| 708 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 709 | 586 | ?> |
| 710 | 587 | <li class="<?php echo esc_attr( $class ); ?>"> |
| 711 | - <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 712 | - <?php | |
| 713 | - if ( isset( $field['icon'] ) ) { | |
| 714 | - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 715 | - } | |
| 716 | - | |
| 717 | - echo esc_html( $truncated_name ); | |
| 718 | - ?> | |
| 719 | - <span>[<?php echo esc_html( $args['id_label'] ?? $args['id'] ); ?>]</span> | |
| 588 | + <a href="javascript:void(0)" class="frmids frm_insert_code" | |
| 589 | + data-code="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 590 | + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span> | |
| 591 | + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 592 | + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 720 | 593 | </a> |
| 721 | - <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>"> | |
| 722 | - <?php | |
| 723 | - if ( isset( $field['icon'] ) ) { | |
| 724 | - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 725 | - } | |
| 726 | - | |
| 727 | - echo esc_html( $truncated_name ); | |
| 728 | - ?> | |
| 729 | - <span>[<?php echo esc_html( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) ); ?>]</span> | |
| 594 | + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" | |
| 595 | + data-code="<?php echo esc_attr( $args['key'] ); ?>"> | |
| 596 | + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span> | |
| 597 | + <?php if ( isset( $field['icon'] ) ) { ?> | |
| 598 | + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 599 | + <?php } ?> | |
| 600 | + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 730 | 601 | </a> |
| 731 | 602 | </li> |
| 732 | 603 | <?php |
| 733 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 734 | 604 | } |
| 735 | 605 | |
| 736 | 606 | /** |
| 737 | - * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up. | |
| 738 | - * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection. | |
| 739 | - * | |
| 740 | - * @since 6.10 | |
| 741 | - * | |
| 742 | - * @return array | |
| 743 | - */ | |
| 744 | - private static function get_field_type_data_for_insert_opt_html() { | |
| 745 | - if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) { | |
| 746 | - self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection(); | |
| 747 | - } | |
| 748 | - return self::$field_type_data_for_insert_opt_html; | |
| 749 | - } | |
| 750 | - | |
| 751 | - /** | |
| 752 | 607 | * @since 4.0 |
| 753 | - * | |
| 754 | 608 | * @param array $args |
| 755 | - * | |
| 756 | - * @return void | |
| 757 | 609 | */ |
| 758 | 610 | public static function insert_code_html( $args ) { |
| 759 | 611 | $defaults = array( |
| 760 | 612 | 'class' => '', |
| @@ -765,22 +617,20 @@ | ||
| 765 | 617 | |
| 766 | 618 | $args = array_merge( $defaults, $args ); |
| 767 | 619 | $has_tooltip = ! empty( $args['title'] ); |
| 768 | 620 | |
| 769 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 770 | 621 | ?> |
| 771 | 622 | <li class="<?php echo esc_attr( $args['class'] ); ?>"> |
| 772 | 623 | <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>" |
| 773 | 624 | <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?> |
| 774 | 625 | data-code="<?php echo esc_attr( $args['code'] ); ?>"> |
| 775 | - <?php echo esc_html( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 776 | 626 | <span> |
| 777 | - [<?php echo esc_html( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 627 | + [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 778 | 628 | </span> |
| 629 | + <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 779 | 630 | </a> |
| 780 | 631 | </li> |
| 781 | 632 | <?php |
| 782 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 783 | 633 | } |
| 784 | 634 | |
| 785 | 635 | /** |
| 786 | 636 | * Some field types in add-ons may have been added with only |
| @@ -786,18 +636,14 @@ | ||
| 786 | 636 | * Some field types in add-ons may have been added with only |
| 787 | 637 | * a field type and name. |
| 788 | 638 | * |
| 789 | 639 | * @since 4.0 |
| 790 | - * | |
| 791 | - * @param array|string $field | |
| 792 | - * | |
| 793 | - * @return void | |
| 794 | 640 | */ |
| 795 | 641 | public static function prepare_field_type( &$field ) { |
| 796 | 642 | if ( ! is_array( $field ) ) { |
| 797 | 643 | $field = array( |
| 798 | 644 | 'name' => $field, |
| 799 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 645 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 800 | 646 | ); |
| 801 | 647 | } |
| 802 | 648 | } |
| 803 | 649 | |
| @@ -805,16 +651,12 @@ | ||
| 805 | 651 | * Automatically add end section fields if they don't exist (2.0 migration) |
| 806 | 652 | * |
| 807 | 653 | * @since 2.0 |
| 808 | 654 | * |
| 809 | - * @param object $form | |
| 810 | - * @param array $fields | |
| 811 | - * @param bool $reset_fields | |
| 812 | - * | |
| 813 | - * @return void | |
| 655 | + * @param boolean $reset_fields | |
| 814 | 656 | */ |
| 815 | 657 | public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { |
| 816 | - if ( ! $fields ) { | |
| 658 | + if ( empty( $fields ) ) { | |
| 817 | 659 | return; |
| 818 | 660 | } |
| 819 | 661 | |
| 820 | 662 | $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) ); |
| @@ -821,12 +663,11 @@ | ||
| 821 | 663 | $open = false; |
| 822 | 664 | $prev_order = false; |
| 823 | 665 | $add_order = 0; |
| 824 | 666 | $last_field = false; |
| 825 | - | |
| 826 | 667 | foreach ( $fields as $field ) { |
| 827 | 668 | if ( $prev_order === $field->field_order ) { |
| 828 | - ++$add_order; | |
| 669 | + $add_order ++; | |
| 829 | 670 | } |
| 830 | 671 | |
| 831 | 672 | if ( $add_order ) { |
| 832 | 673 | $reset_fields = true; |
| @@ -853,14 +694,14 @@ | ||
| 853 | 694 | } |
| 854 | 695 | |
| 855 | 696 | // There is already an end section here, so there is no need to create one. |
| 856 | 697 | $open = false; |
| 857 | - }//end switch | |
| 698 | + } | |
| 858 | 699 | $prev_order = $field->field_order; |
| 859 | 700 | |
| 860 | 701 | $last_field = $field; |
| 861 | 702 | unset( $field ); |
| 862 | - }//end foreach | |
| 703 | + } | |
| 863 | 704 | |
| 864 | 705 | self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field ); |
| 865 | 706 | } |
| 866 | 707 | |
| @@ -866,17 +707,8 @@ | ||
| 866 | 707 | |
| 867 | 708 | /** |
| 868 | 709 | * Create end section field if it doesn't exist. This is for migration from < 2.0 |
| 869 | 710 | * Fix any ordering that may be messed up |
| 870 | - * | |
| 871 | - * @param bool $open | |
| 872 | - * @param bool $reset_fields | |
| 873 | - * @param int $add_order | |
| 874 | - * @param array $end_section_values | |
| 875 | - * @param object $field | |
| 876 | - * @param string $move | |
| 877 | - * | |
| 878 | - * @return void | |
| 879 | 711 | */ |
| 880 | 712 | public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) { |
| 881 | 713 | if ( ! $open ) { |
| 882 | 714 | return; |
| @@ -885,27 +717,18 @@ | ||
| 885 | 717 | $end_section_values['field_order'] = $field->field_order + 1; |
| 886 | 718 | |
| 887 | 719 | FrmField::create( $end_section_values ); |
| 888 | 720 | |
| 889 | - if ( $move === 'move' ) { | |
| 890 | - // Bump the order of current field unless we're at the end of the form | |
| 721 | + if ( $move == 'move' ) { | |
| 722 | + // bump the order of current field unless we're at the end of the form | |
| 891 | 723 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 892 | 724 | } |
| 893 | 725 | |
| 894 | - $add_order += 2; | |
| 726 | + $add_order += 2; | |
| 895 | 727 | $open = false; |
| 896 | 728 | $reset_fields = true; |
| 897 | 729 | } |
| 898 | 730 | |
| 899 | - /** | |
| 900 | - * @param string $html | |
| 901 | - * @param object $form | |
| 902 | - * @param bool $title | |
| 903 | - * @param bool $description | |
| 904 | - * @param array $values | |
| 905 | - * | |
| 906 | - * @return string | |
| 907 | - */ | |
| 908 | 731 | public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) { |
| 909 | 732 | $codes = array( |
| 910 | 733 | 'form_name' => $title, |
| 911 | 734 | 'form_description' => $description, |
| @@ -910,30 +733,29 @@ | ||
| 910 | 733 | 'form_name' => $title, |
| 911 | 734 | 'form_description' => $description, |
| 912 | 735 | 'entry_key' => true, |
| 913 | 736 | ); |
| 914 | - | |
| 915 | 737 | foreach ( $codes as $code => $show ) { |
| 916 | 738 | if ( $code === 'form_name' ) { |
| 917 | 739 | $replace_with = $form->name; |
| 918 | 740 | } elseif ( $code === 'form_description' ) { |
| 919 | 741 | $replace_with = FrmAppHelper::use_wpautop( $form->description ); |
| 920 | - } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 742 | + } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 921 | 743 | $replace_with = FrmAppHelper::simple_get( 'entry' ); |
| 922 | 744 | } else { |
| 923 | 745 | $replace_with = ''; |
| 924 | 746 | } |
| 925 | 747 | |
| 926 | - FrmShortcodeHelper::remove_inline_conditions( FrmAppHelper::is_true( $show ) && $replace_with != '', $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 748 | + FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); | |
| 927 | 749 | } |
| 928 | 750 | |
| 929 | - // Replace [form_key]. | |
| 751 | + //replace [form_key] | |
| 930 | 752 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| 931 | 753 | |
| 932 | - // Replace [frmurl]. | |
| 754 | + //replace [frmurl] | |
| 933 | 755 | $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html ); |
| 934 | 756 | |
| 935 | - if ( str_contains( $html, '[button_label]' ) ) { | |
| 757 | + if ( strpos( $html, '[button_label]' ) ) { | |
| 936 | 758 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| 937 | 759 | $submit_label = apply_filters( 'frm_submit_button', $title, $form ); |
| 938 | 760 | $submit_label = esc_attr( do_shortcode( $submit_label ) ); |
| 939 | 761 | $html = str_replace( '[button_label]', $submit_label, $html ); |
| @@ -940,32 +762,27 @@ | ||
| 940 | 762 | } |
| 941 | 763 | |
| 942 | 764 | $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values ); |
| 943 | 765 | |
| 944 | - if ( str_contains( $html, '[if back_button]' ) ) { | |
| 766 | + if ( strpos( $html, '[if back_button]' ) ) { | |
| 945 | 767 | $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html ); |
| 946 | 768 | } |
| 947 | 769 | |
| 948 | - if ( str_contains( $html, '[if save_draft]' ) ) { | |
| 770 | + if ( strpos( $html, '[if save_draft]' ) ) { | |
| 949 | 771 | $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html ); |
| 950 | 772 | } |
| 951 | 773 | |
| 952 | - if ( str_contains( $html, '[if start_over]' ) ) { | |
| 774 | + if ( strpos( $html, '[if start_over]' ) ) { | |
| 953 | 775 | $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html ); |
| 954 | 776 | } |
| 955 | 777 | |
| 956 | 778 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 957 | - return do_shortcode( $html ); | |
| 779 | + $html = do_shortcode( $html ); | |
| 958 | 780 | } |
| 959 | 781 | |
| 960 | 782 | return $html; |
| 961 | 783 | } |
| 962 | 784 | |
| 963 | - /** | |
| 964 | - * @param string $submit | |
| 965 | - * | |
| 966 | - * @return string | |
| 967 | - */ | |
| 968 | 785 | public static function submit_button_label( $submit ) { |
| 969 | 786 | if ( ! $submit ) { |
| 970 | 787 | $frm_settings = FrmAppHelper::get_settings(); |
| 971 | 788 | $submit = $frm_settings->submit_value; |
| @@ -978,32 +795,28 @@ | ||
| 978 | 795 | * If the Formidable styling isn't being loaded, |
| 979 | 796 | * use inline styling to hide the element |
| 980 | 797 | * |
| 981 | 798 | * @since 2.03.05 |
| 982 | - * | |
| 983 | - * @return void | |
| 984 | 799 | */ |
| 985 | 800 | public static function maybe_hide_inline() { |
| 986 | 801 | $frm_settings = FrmAppHelper::get_settings(); |
| 987 | - | |
| 988 | - if ( $frm_settings->load_style === 'none' ) { | |
| 802 | + if ( $frm_settings->load_style == 'none' ) { | |
| 989 | 803 | echo ' style="display:none;"'; |
| 990 | - } elseif ( $frm_settings->load_style === 'dynamic' ) { | |
| 804 | + } elseif ( $frm_settings->load_style == 'dynamic' ) { | |
| 991 | 805 | FrmStylesController::enqueue_style(); |
| 992 | 806 | } |
| 993 | 807 | } |
| 994 | 808 | |
| 995 | - /** | |
| 996 | - * @param array|bool|int|object|string $form | |
| 997 | - * | |
| 998 | - * @return string|null | |
| 999 | - */ | |
| 1000 | 809 | public static function get_form_style_class( $form = false ) { |
| 1001 | 810 | $style = self::get_form_style( $form ); |
| 1002 | 811 | $class = ' with_frm_style'; |
| 1003 | 812 | |
| 1004 | - if ( ! $style ) { | |
| 1005 | - return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null; | |
| 813 | + if ( empty( $style ) ) { | |
| 814 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { | |
| 815 | + return $class; | |
| 816 | + } else { | |
| 817 | + return; | |
| 818 | + } | |
| 1006 | 819 | } |
| 1007 | 820 | |
| 1008 | 821 | // If submit button needs to be inline or centered. |
| 1009 | 822 | if ( is_object( $form ) ) { |
| @@ -1024,9 +837,11 @@ | ||
| 1024 | 837 | } elseif ( 'center' === $submit_align ) { |
| 1025 | 838 | $class .= ' frm_center_submit'; |
| 1026 | 839 | } |
| 1027 | 840 | |
| 1028 | - return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 841 | + $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 842 | + | |
| 843 | + return $class; | |
| 1029 | 844 | } |
| 1030 | 845 | |
| 1031 | 846 | /** |
| 1032 | 847 | * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work. |
| @@ -1033,23 +848,22 @@ | ||
| 1033 | 848 | * |
| 1034 | 849 | * @since 5.0.12 |
| 1035 | 850 | * |
| 1036 | 851 | * @param array $form |
| 1037 | - * | |
| 1038 | 852 | * @return bool |
| 1039 | 853 | */ |
| 1040 | 854 | private static function form_should_be_inline_and_missing_class( $form ) { |
| 1041 | - if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 1042 | - // Not missing class, avoid adding it twice. | |
| 855 | + if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 856 | + // not missing class, avoid adding it twice. | |
| 1043 | 857 | return false; |
| 1044 | 858 | } |
| 1045 | - return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' ); | |
| 859 | + return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' ); | |
| 1046 | 860 | } |
| 1047 | 861 | |
| 1048 | 862 | /** |
| 1049 | 863 | * Returns appropriate class if form has top labels |
| 1050 | 864 | * |
| 1051 | - * @param array $form | |
| 865 | + * @param $form | |
| 1052 | 866 | * |
| 1053 | 867 | * @return string |
| 1054 | 868 | */ |
| 1055 | 869 | private static function maybe_align_fields_top( $form ) { |
| @@ -1058,9 +872,9 @@ | ||
| 1058 | 872 | |
| 1059 | 873 | /** |
| 1060 | 874 | * Determine if a form has fields with top labels so submit button can be aligned properly |
| 1061 | 875 | * |
| 1062 | - * @param array $form | |
| 876 | + * @param $form | |
| 1063 | 877 | * |
| 1064 | 878 | * @return bool |
| 1065 | 879 | */ |
| 1066 | 880 | private static function form_has_top_labels( $form ) { |
| @@ -1068,20 +882,16 @@ | ||
| 1068 | 882 | return false; |
| 1069 | 883 | } |
| 1070 | 884 | |
| 1071 | 885 | $fields = $form['fields']; |
| 1072 | - | |
| 1073 | 886 | if ( count( $fields ) <= 0 ) { |
| 1074 | 887 | return false; |
| 1075 | 888 | } |
| 1076 | 889 | |
| 1077 | - // Start from the fields closest to the submit button. | |
| 1078 | - $fields = array_reverse( $fields ); | |
| 1079 | - | |
| 890 | + $fields = array_reverse( $fields ); // start from the fields closest to the submit button | |
| 1080 | 891 | foreach ( $fields as $field ) { |
| 1081 | - $type = $field['original_type'] ?? $field['type']; | |
| 892 | + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; | |
| 1082 | 893 | $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' ); |
| 1083 | - | |
| 1084 | 894 | if ( $has_input ) { |
| 1085 | 895 | return self::field_has_top_label( $field, $form ); |
| 1086 | 896 | } |
| 1087 | 897 | } |
| @@ -1091,63 +901,61 @@ | ||
| 1091 | 901 | |
| 1092 | 902 | /** |
| 1093 | 903 | * Check if a field's label position is set to "top" |
| 1094 | 904 | * |
| 1095 | - * @param array $field | |
| 1096 | - * @param bool|object|string $form | |
| 905 | + * @param $field | |
| 906 | + * @param $form | |
| 1097 | 907 | * |
| 1098 | 908 | * @return bool |
| 1099 | 909 | */ |
| 1100 | 910 | private static function field_has_top_label( $field, $form ) { |
| 1101 | 911 | $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form ); |
| 1102 | - return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true ); | |
| 912 | + | |
| 913 | + return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); | |
| 1103 | 914 | } |
| 1104 | 915 | |
| 1105 | 916 | /** |
| 1106 | - * @param array|bool|int|object|string $form | |
| 917 | + * @param object|string|boolean $form | |
| 1107 | 918 | * |
| 1108 | - * @return int|string | |
| 919 | + * @return string | |
| 1109 | 920 | */ |
| 1110 | 921 | public static function get_form_style( $form ) { |
| 1111 | 922 | $style = 1; |
| 1112 | - | |
| 1113 | - if ( ! $form || 'default' === $form ) { | |
| 923 | + if ( empty( $form ) || 'default' === $form ) { | |
| 1114 | 924 | return $style; |
| 1115 | - } | |
| 1116 | - | |
| 1117 | - if ( is_object( $form ) && $form->parent_form_id ) { | |
| 1118 | - // Get the parent form if this is a child | |
| 925 | + } elseif ( is_object( $form ) && $form->parent_form_id ) { | |
| 926 | + // get the parent form if this is a child | |
| 1119 | 927 | $form = $form->parent_form_id; |
| 1120 | - } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) { | |
| 928 | + } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) { | |
| 1121 | 929 | $form = $form['parent_form_id']; |
| 1122 | 930 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| 1123 | 931 | $style = $form['custom_style']; |
| 1124 | 932 | } |
| 1125 | 933 | |
| 1126 | - if ( $form && ( is_string( $form ) || is_int( $form ) ) ) { | |
| 934 | + if ( $form && is_string( $form ) ) { | |
| 1127 | 935 | $form = FrmForm::getOne( $form ); |
| 1128 | 936 | } |
| 1129 | 937 | |
| 1130 | - return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 938 | + $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style; | |
| 939 | + | |
| 940 | + return $style; | |
| 1131 | 941 | } |
| 1132 | 942 | |
| 1133 | 943 | /** |
| 1134 | 944 | * Display the validation error messages when an entry is submitted |
| 1135 | 945 | * |
| 946 | + * @param array $args - includes img, errors | |
| 947 | + * | |
| 1136 | 948 | * @since 2.0.6 |
| 1137 | - * | |
| 1138 | - * @param array $args Includes img, errors. | |
| 1139 | - * | |
| 1140 | - * @return void | |
| 1141 | 949 | */ |
| 1142 | 950 | public static function show_errors( $args ) { |
| 1143 | 951 | $invalid_msg = self::get_invalid_error_message( $args ); |
| 1144 | 952 | |
| 1145 | - if ( $invalid_msg ) { | |
| 953 | + if ( empty( $invalid_msg ) ) { | |
| 954 | + $show_img = false; | |
| 955 | + } else { | |
| 1146 | 956 | echo wp_kses_post( $invalid_msg ); |
| 1147 | 957 | $show_img = true; |
| 1148 | - } else { | |
| 1149 | - $show_img = false; | |
| 1150 | 958 | } |
| 1151 | 959 | |
| 1152 | 960 | self::show_error( |
| 1153 | 961 | array( |
| @@ -1162,22 +970,19 @@ | ||
| 1162 | 970 | * Display the error message in the front-end along with the image if set |
| 1163 | 971 | * The image was removed from the styling settings, but it may still be set with a hook |
| 1164 | 972 | * If the message in the global settings is empty, show every validation message in the error box |
| 1165 | 973 | * |
| 974 | + * @param array $args - includes img, errors, and show_img | |
| 975 | + * | |
| 1166 | 976 | * @since 2.0.6 |
| 1167 | - * | |
| 1168 | - * @param array $args Includes img, errors, and show_img. | |
| 1169 | - * | |
| 1170 | - * @return void | |
| 1171 | 977 | */ |
| 1172 | 978 | public static function show_error( $args ) { |
| 1173 | - // Remove any blank messages | |
| 979 | + // remove any blank messages | |
| 1174 | 980 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| 1175 | 981 | |
| 1176 | 982 | $line_break_first = $args['show_img']; |
| 1177 | - | |
| 1178 | 983 | foreach ( $args['errors'] as $error_key => $error ) { |
| 1179 | - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) { | |
| 984 | + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key == 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1180 | 985 | continue; |
| 1181 | 986 | } |
| 1182 | 987 | |
| 1183 | 988 | $id = str_replace( 'field', 'field_', $error_key ); |
| @@ -1183,9 +988,9 @@ | ||
| 1183 | 988 | $id = str_replace( 'field', 'field_', $error_key ); |
| 1184 | 989 | echo '<div id="' . esc_attr( $id ) . '_error">'; |
| 1185 | 990 | |
| 1186 | 991 | if ( $args['show_img'] && ! empty( $args['img'] ) ) { |
| 1187 | - echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />'; | |
| 992 | + echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />'; | |
| 1188 | 993 | } else { |
| 1189 | 994 | $args['show_img'] = true; |
| 1190 | 995 | } |
| 1191 | 996 | |
| @@ -1194,38 +999,34 @@ | ||
| 1194 | 999 | echo '</div>'; |
| 1195 | 1000 | } |
| 1196 | 1001 | } |
| 1197 | 1002 | |
| 1198 | - /** | |
| 1199 | - * @param int|string $id | |
| 1200 | - * | |
| 1201 | - * @return void | |
| 1202 | - */ | |
| 1203 | 1003 | public static function maybe_get_scroll_js( $id ) { |
| 1204 | 1004 | $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) ); |
| 1205 | - | |
| 1206 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1207 | 1005 | if ( $offset != - 1 ) { |
| 1208 | 1006 | self::get_scroll_js( $id ); |
| 1209 | 1007 | } |
| 1210 | 1008 | } |
| 1211 | 1009 | |
| 1010 | + public static function get_scroll_js( $form_id ) { | |
| 1011 | + echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; | |
| 1012 | + } | |
| 1013 | + | |
| 1212 | 1014 | /** |
| 1213 | - * @param int|string $form_id | |
| 1214 | - * | |
| 1215 | - * @return void | |
| 1015 | + * @since 3.0 | |
| 1216 | 1016 | */ |
| 1217 | - public static function get_scroll_js( $form_id ) { | |
| 1218 | - echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; | |
| 1017 | + public static function actions_dropdown( $atts ) { | |
| 1018 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 1019 | + $status = $atts['status']; | |
| 1020 | + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1021 | + $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 1022 | + $links = self::get_action_links( $form_id, $status ); | |
| 1023 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' ); | |
| 1024 | + } | |
| 1219 | 1025 | } |
| 1220 | 1026 | |
| 1221 | 1027 | /** |
| 1222 | 1028 | * @since 3.0 |
| 1223 | - * | |
| 1224 | - * @param int|object|string $form_id | |
| 1225 | - * @param mixed $form | |
| 1226 | - * | |
| 1227 | - * @return array | |
| 1228 | 1029 | */ |
| 1229 | 1030 | public static function get_action_links( $form_id, $form ) { |
| 1230 | 1031 | if ( ! is_object( $form ) ) { |
| 1231 | 1032 | $form = FrmForm::getOne( $form_id ); |
| @@ -1232,10 +1033,9 @@ | ||
| 1232 | 1033 | } |
| 1233 | 1034 | |
| 1234 | 1035 | $actions = array(); |
| 1235 | 1036 | $trash_links = self::delete_trash_links( $form_id ); |
| 1236 | - | |
| 1237 | - if ( 'trash' === $form->status ) { | |
| 1037 | + if ( 'trash' == $form->status ) { | |
| 1238 | 1038 | $actions['restore'] = $trash_links['restore']; |
| 1239 | 1039 | |
| 1240 | 1040 | if ( current_user_can( 'frm_delete_forms' ) ) { |
| 1241 | 1041 | $actions['trash'] = $trash_links['delete']; |
| @@ -1241,34 +1041,28 @@ | ||
| 1241 | 1041 | $actions['trash'] = $trash_links['delete']; |
| 1242 | 1042 | } |
| 1243 | 1043 | } elseif ( current_user_can( 'frm_edit_forms' ) ) { |
| 1244 | 1044 | $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id; |
| 1245 | - | |
| 1246 | 1045 | if ( $form->is_template ) { |
| 1247 | 1046 | $actions['frm_duplicate'] = array( |
| 1248 | 1047 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1249 | 1048 | 'label' => __( 'Create Form from Template', 'formidable' ), |
| 1250 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1049 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1251 | 1050 | ); |
| 1252 | 1051 | } else { |
| 1253 | 1052 | $actions['duplicate'] = array( |
| 1254 | 1053 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1255 | 1054 | 'label' => __( 'Duplicate Form', 'formidable' ), |
| 1256 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1055 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1257 | 1056 | ); |
| 1258 | 1057 | } |
| 1259 | 1058 | |
| 1260 | 1059 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| 1261 | - }//end if | |
| 1060 | + } | |
| 1262 | 1061 | |
| 1263 | 1062 | return $actions; |
| 1264 | 1063 | } |
| 1265 | 1064 | |
| 1266 | - /** | |
| 1267 | - * @param int|object|string $data | |
| 1268 | - * | |
| 1269 | - * @return string | |
| 1270 | - */ | |
| 1271 | 1065 | public static function edit_form_link( $data ) { |
| 1272 | 1066 | $form_id = self::get_form_id_from_data( $data ); |
| 1273 | 1067 | |
| 1274 | 1068 | if ( ! $form_id ) { |
| @@ -1275,122 +1069,94 @@ | ||
| 1275 | 1069 | return ''; |
| 1276 | 1070 | } |
| 1277 | 1071 | |
| 1278 | 1072 | $label = self::edit_form_link_label( $data ); |
| 1279 | - return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1073 | + $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1074 | + return $link; | |
| 1280 | 1075 | } |
| 1281 | 1076 | |
| 1282 | - /** | |
| 1283 | - * Returns a text used when no title is set. | |
| 1284 | - * | |
| 1285 | - * @since 6.16.1 | |
| 1286 | - * | |
| 1287 | - * @return string | |
| 1288 | - */ | |
| 1289 | - public static function get_no_title_text() { | |
| 1290 | - return __( '(no title)', 'formidable' ); | |
| 1291 | - } | |
| 1292 | - | |
| 1293 | - /** | |
| 1294 | - * @param int|object|string $data | |
| 1295 | - * | |
| 1296 | - * @return string | |
| 1297 | - */ | |
| 1298 | 1077 | public static function edit_form_link_label( $data ) { |
| 1299 | 1078 | $name = self::get_form_name_from_data( $data ); |
| 1300 | - | |
| 1301 | 1079 | if ( ! $name ) { |
| 1302 | - return self::get_no_title_text(); | |
| 1080 | + return __( '(no title)', 'formidable' ); | |
| 1303 | 1081 | } |
| 1304 | - | |
| 1305 | 1082 | return FrmAppHelper::truncate( $name, 40 ); |
| 1306 | 1083 | } |
| 1307 | 1084 | |
| 1308 | 1085 | /** |
| 1309 | - * @param int|object|string $data | |
| 1310 | - * | |
| 1311 | - * @return int|string | |
| 1086 | + * @param mixed data | |
| 1087 | + * @return int | |
| 1312 | 1088 | */ |
| 1313 | 1089 | private static function get_form_id_from_data( $data ) { |
| 1314 | - return is_object( $data ) ? $data->id : $data; | |
| 1090 | + if ( is_object( $data ) ) { | |
| 1091 | + $form_id = $data->id; | |
| 1092 | + } else { | |
| 1093 | + $form_id = $data; | |
| 1094 | + } | |
| 1095 | + return $form_id; | |
| 1315 | 1096 | } |
| 1316 | 1097 | |
| 1317 | 1098 | /** |
| 1318 | 1099 | * @param mixed $data |
| 1319 | - * | |
| 1320 | 1100 | * @return string |
| 1321 | 1101 | */ |
| 1322 | 1102 | private static function get_form_name_from_data( $data ) { |
| 1323 | 1103 | if ( is_object( $data ) ) { |
| 1324 | - return $data->name; | |
| 1104 | + $form_name = $data->name; | |
| 1105 | + } else { | |
| 1106 | + $form_id = $data; | |
| 1107 | + $form_name = FrmForm::getName( $form_id ); | |
| 1325 | 1108 | } |
| 1326 | - | |
| 1327 | - $form_id = $data; | |
| 1328 | - return FrmForm::getName( $form_id ); | |
| 1109 | + return $form_name; | |
| 1329 | 1110 | } |
| 1330 | 1111 | |
| 1331 | - /** | |
| 1332 | - * @param int $id | |
| 1333 | - * @param string $status | |
| 1334 | - * @param string $length | |
| 1335 | - * | |
| 1336 | - * @return string | |
| 1337 | - */ | |
| 1338 | 1112 | public static function delete_trash_link( $id, $status, $length = 'label' ) { |
| 1339 | 1113 | $link_details = self::delete_trash_info( $id, $status ); |
| 1114 | + | |
| 1340 | 1115 | return self::format_link_html( $link_details, $length ); |
| 1341 | 1116 | } |
| 1342 | 1117 | |
| 1343 | 1118 | /** |
| 1344 | 1119 | * @since 3.0 |
| 1345 | - * | |
| 1346 | - * @param array $link_details | |
| 1347 | - * @param string $length | |
| 1348 | - * | |
| 1349 | - * @return string | |
| 1350 | 1120 | */ |
| 1351 | 1121 | public static function format_link_html( $link_details, $length = 'label' ) { |
| 1352 | 1122 | $link = ''; |
| 1123 | + if ( ! empty( $link_details ) ) { | |
| 1124 | + $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1125 | + if ( isset( $link_details['data'] ) ) { | |
| 1126 | + foreach ( $link_details['data'] as $data => $value ) { | |
| 1127 | + $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1128 | + } | |
| 1129 | + } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1130 | + $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1131 | + } | |
| 1353 | 1132 | |
| 1354 | - if ( ! $link_details ) { | |
| 1355 | - return $link; | |
| 1356 | - } | |
| 1357 | - | |
| 1358 | - $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1359 | - | |
| 1360 | - if ( isset( $link_details['data'] ) ) { | |
| 1361 | - foreach ( $link_details['data'] as $data => $value ) { | |
| 1362 | - $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1133 | + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] ); | |
| 1134 | + if ( $length == 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1135 | + $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1136 | + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1363 | 1137 | } |
| 1364 | - } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1365 | - $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1366 | - } | |
| 1367 | 1138 | |
| 1368 | - $label = $link_details[ $length ] ?? $link_details['label']; | |
| 1369 | - | |
| 1370 | - if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1371 | - $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1372 | - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1139 | + $link .= '>' . $label . '</a>'; | |
| 1373 | 1140 | } |
| 1374 | 1141 | |
| 1375 | - return $link . ( '>' . $label . '</a>' ); | |
| 1142 | + return $link; | |
| 1376 | 1143 | } |
| 1377 | 1144 | |
| 1378 | 1145 | /** |
| 1379 | 1146 | * @since 3.0 |
| 1380 | - * | |
| 1381 | - * @param int $id | |
| 1382 | - * @param string $status | |
| 1383 | - * | |
| 1384 | - * @return array | |
| 1385 | 1147 | */ |
| 1386 | 1148 | public static function delete_trash_info( $id, $status ) { |
| 1387 | 1149 | $labels = self::delete_trash_links( $id ); |
| 1388 | 1150 | |
| 1389 | - if ( 'trash' === $status ) { | |
| 1151 | + if ( 'trash' == $status ) { | |
| 1390 | 1152 | $info = $labels['restore']; |
| 1391 | 1153 | } elseif ( current_user_can( 'frm_delete_forms' ) ) { |
| 1392 | - $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete']; | |
| 1154 | + if ( EMPTY_TRASH_DAYS ) { | |
| 1155 | + $info = $labels['trash']; | |
| 1156 | + } else { | |
| 1157 | + $info = $labels['delete']; | |
| 1158 | + } | |
| 1393 | 1159 | } else { |
| 1394 | 1160 | $info = array(); |
| 1395 | 1161 | } |
| 1396 | 1162 | |
| @@ -1398,14 +1164,10 @@ | ||
| 1398 | 1164 | } |
| 1399 | 1165 | |
| 1400 | 1166 | /** |
| 1401 | 1167 | * @since 3.0 |
| 1402 | - * | |
| 1403 | - * @param int $id | |
| 1404 | - * | |
| 1405 | - * @return array | |
| 1406 | 1168 | */ |
| 1407 | - public static function delete_trash_links( $id ) { | |
| 1169 | + private static function delete_trash_links( $id ) { | |
| 1408 | 1170 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1409 | 1171 | $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; |
| 1410 | 1172 | |
| 1411 | 1173 | return array( |
| @@ -1417,13 +1179,10 @@ | ||
| 1417 | 1179 | 'trash' => array( |
| 1418 | 1180 | 'label' => __( 'Move Form to Trash', 'formidable' ), |
| 1419 | 1181 | 'short' => __( 'Trash', 'formidable' ), |
| 1420 | 1182 | 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ), |
| 1421 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1422 | - 'data' => array( | |
| 1423 | - 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ), | |
| 1424 | - 'frmverify-btn' => 'frm-button-red', | |
| 1425 | - ), | |
| 1183 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1184 | + 'data' => array( 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ) ), | |
| 1426 | 1185 | ), |
| 1427 | 1186 | 'delete' => array( |
| 1428 | 1187 | 'label' => __( 'Delete Permanently', 'formidable' ), |
| 1429 | 1188 | 'short' => __( 'Delete', 'formidable' ), |
| @@ -1428,13 +1187,10 @@ | ||
| 1428 | 1187 | 'label' => __( 'Delete Permanently', 'formidable' ), |
| 1429 | 1188 | 'short' => __( 'Delete', 'formidable' ), |
| 1430 | 1189 | 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), |
| 1431 | 1190 | 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ), |
| 1432 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1433 | - 'data' => array( | |
| 1434 | - 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ), | |
| 1435 | - 'frmverify-btn' => 'frm-button-red', | |
| 1436 | - ), | |
| 1191 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1192 | + 'data' => array( 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ) ), | |
| 1437 | 1193 | ), |
| 1438 | 1194 | ); |
| 1439 | 1195 | } |
| 1440 | 1196 | |
| @@ -1439,38 +1195,36 @@ | ||
| 1439 | 1195 | } |
| 1440 | 1196 | |
| 1441 | 1197 | /** |
| 1442 | 1198 | * @since 3.0 |
| 1443 | - * | |
| 1444 | - * @return array | |
| 1445 | 1199 | */ |
| 1446 | 1200 | public static function css_classes() { |
| 1447 | 1201 | $classes = array( |
| 1448 | - 'frm_total' => array( | |
| 1202 | + 'frm_total' => array( | |
| 1449 | 1203 | 'label' => __( 'Total', 'formidable' ), |
| 1450 | 1204 | 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ), |
| 1451 | 1205 | ), |
| 1452 | - 'frm_total_big' => array( | |
| 1206 | + 'frm_total_big' => array( | |
| 1453 | 1207 | 'label' => __( 'Big Total', 'formidable' ), |
| 1454 | 1208 | 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), |
| 1455 | 1209 | ), |
| 1456 | - 'frm_scroll_box' => array( | |
| 1210 | + 'frm_scroll_box' => array( | |
| 1457 | 1211 | 'label' => __( 'Scroll Box', 'formidable' ), |
| 1458 | - 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1212 | + 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), | |
| 1459 | 1213 | ), |
| 1460 | - 'frm_first' => array( | |
| 1214 | + 'frm_first' => array( | |
| 1461 | 1215 | 'label' => __( 'First', 'formidable' ), |
| 1462 | 1216 | 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), |
| 1463 | 1217 | ), |
| 1464 | - 'frm_alignright' => __( 'Right', 'formidable' ), | |
| 1465 | - 'frm_grid_first' => __( 'First Grid Row', 'formidable' ), | |
| 1466 | - 'frm_grid' => __( 'Even Grid Row', 'formidable' ), | |
| 1467 | - 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ), | |
| 1218 | + 'frm_alignright' => __( 'Right', 'formidable' ), | |
| 1219 | + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ), | |
| 1220 | + 'frm_grid' => __( 'Even Grid Row', 'formidable' ), | |
| 1221 | + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ), | |
| 1468 | 1222 | 'frm_color_block' => array( |
| 1469 | 1223 | 'label' => __( 'Color Block', 'formidable' ), |
| 1470 | 1224 | 'title' => __( 'Add a background color to the field or section.', 'formidable' ), |
| 1471 | 1225 | ), |
| 1472 | - 'frm_capitalize' => array( | |
| 1226 | + 'frm_capitalize' => array( | |
| 1473 | 1227 | 'label' => __( 'Capitalize', 'formidable' ), |
| 1474 | 1228 | 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ), |
| 1475 | 1229 | ), |
| 1476 | 1230 | ); |
| @@ -1477,11 +1231,8 @@ | ||
| 1477 | 1231 | |
| 1478 | 1232 | return apply_filters( 'frm_layout_classes', $classes ); |
| 1479 | 1233 | } |
| 1480 | 1234 | |
| 1481 | - /** | |
| 1482 | - * @return array | |
| 1483 | - */ | |
| 1484 | 1235 | public static function grid_classes() { |
| 1485 | 1236 | return array( |
| 1486 | 1237 | 'frm_half' => '1/2', |
| 1487 | 1238 | 'frm_third' => '1/3', |
| @@ -1495,18 +1246,12 @@ | ||
| 1495 | 1246 | } |
| 1496 | 1247 | |
| 1497 | 1248 | /** |
| 1498 | 1249 | * @since 3.0 |
| 1499 | - * | |
| 1500 | - * @param mixed $style | |
| 1501 | - * @param string $class | |
| 1502 | - * | |
| 1503 | - * @return string | |
| 1504 | 1250 | */ |
| 1505 | 1251 | public static function style_class_label( $style, $class ) { |
| 1506 | 1252 | $label = ''; |
| 1507 | - | |
| 1508 | - if ( ! $style ) { | |
| 1253 | + if ( empty( $style ) ) { | |
| 1509 | 1254 | $label = $class; |
| 1510 | 1255 | } elseif ( ! is_array( $style ) ) { |
| 1511 | 1256 | $label = $style; |
| 1512 | 1257 | } elseif ( isset( $style['label'] ) ) { |
| @@ -1515,13 +1260,8 @@ | ||
| 1515 | 1260 | |
| 1516 | 1261 | return $label; |
| 1517 | 1262 | } |
| 1518 | 1263 | |
| 1519 | - /** | |
| 1520 | - * @param string $status | |
| 1521 | - * | |
| 1522 | - * @return string | |
| 1523 | - */ | |
| 1524 | 1264 | public static function status_nice_name( $status ) { |
| 1525 | 1265 | $nice_names = array( |
| 1526 | 1266 | 'draft' => __( 'Draft', 'formidable' ), |
| 1527 | 1267 | 'trash' => __( 'Trash', 'formidable' ), |
| @@ -1527,107 +1267,79 @@ | ||
| 1527 | 1267 | 'trash' => __( 'Trash', 'formidable' ), |
| 1528 | 1268 | 'publish' => __( 'Published', 'formidable' ), |
| 1529 | 1269 | ); |
| 1530 | 1270 | |
| 1531 | - if ( ! array_key_exists( $status, $nice_names ) ) { | |
| 1271 | + if ( ! in_array( $status, array_keys( $nice_names ) ) ) { | |
| 1532 | 1272 | $status = 'publish'; |
| 1533 | 1273 | } |
| 1534 | 1274 | |
| 1535 | - return $nice_names[ $status ]; | |
| 1275 | + $name = $nice_names[ $status ]; | |
| 1276 | + | |
| 1277 | + return $name; | |
| 1536 | 1278 | } |
| 1537 | 1279 | |
| 1538 | - /** | |
| 1539 | - * Renders a template icon based on the given categories. | |
| 1540 | - * | |
| 1541 | - * @param array $categories The categories to render the icon for. | |
| 1542 | - * @param array $atts { | |
| 1543 | - * Optional. An array of attributes for rendering. | |
| 1544 | - * | |
| 1545 | - * @type string $html 'span' or 'div'. Default 'span'. | |
| 1546 | - * @type bool $bg Whether to add a background color or not. Default false. | |
| 1547 | - * } | |
| 1548 | - * | |
| 1549 | - * @return void | |
| 1550 | - */ | |
| 1551 | - public static function template_icon( $categories, $atts = array() ) { | |
| 1552 | - // Define defaults. | |
| 1553 | - $defaults = array( | |
| 1554 | - 'bg' => true, | |
| 1555 | - ); | |
| 1556 | - $atts = array_merge( $defaults, $atts ); | |
| 1557 | - | |
| 1558 | - // Filter out ignored categories. | |
| 1559 | - $ignore = self::get_license_types(); | |
| 1280 | + public static function template_icon( $categories ) { | |
| 1281 | + $ignore = self::ignore_template_categories(); | |
| 1560 | 1282 | $categories = array_diff( $categories, $ignore ); |
| 1561 | 1283 | |
| 1562 | - // Define icons mapping. | |
| 1563 | 1284 | $icons = array( |
| 1564 | - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), | |
| 1565 | - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), | |
| 1566 | - 'User Registration' => array( 'register', 'var(--pink)' ), | |
| 1567 | - 'Registration and Signup' => array( 'register', 'var(--pink)' ), | |
| 1568 | - 'PayPal' => array( 'paypal' ), | |
| 1569 | - 'Stripe' => array( 'credit_card', 'var(--green)' ), | |
| 1570 | - 'Twilio' => array( 'sms' ), | |
| 1571 | - 'Payment' => array( 'credit_card' ), | |
| 1572 | - 'Order Form' => array( 'product' ), | |
| 1573 | - 'Finance' => array( 'total' ), | |
| 1574 | - 'Health and Wellness' => array( 'heart', 'var(--pink)' ), | |
| 1575 | - 'Event Planning' => array( 'calendar', 'var(--orange)' ), | |
| 1576 | - 'Real Estate' => array( 'house' ), | |
| 1577 | - 'Nonprofit' => array( 'heart_solid' ), | |
| 1578 | - 'Calculator' => array( 'calculator', 'var(--purple)' ), | |
| 1579 | - 'Quiz' => array( 'percent' ), | |
| 1580 | - 'Registrations' => array( 'address_card' ), | |
| 1581 | - 'Customer Service' => array( 'users_solid' ), | |
| 1582 | - 'Education' => array( 'pencil' ), | |
| 1583 | - 'Marketing' => array( 'eye' ), | |
| 1584 | - 'Feedback' => array( 'smile' ), | |
| 1585 | - 'Business Operations' => array( 'case' ), | |
| 1586 | - 'Contact Form' => array( 'email' ), | |
| 1587 | - 'Conversational Forms' => array( 'chat_forms' ), | |
| 1588 | - 'Survey' => array( 'chat_forms', 'var(--orange)' ), | |
| 1589 | - 'Application' => array( 'align_right' ), | |
| 1590 | - 'Signature' => array( 'signature' ), | |
| 1591 | - '' => array( 'align_right' ), | |
| 1285 | + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), | |
| 1286 | + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), | |
| 1287 | + 'User Registration' => array( 'register', 'var(--pink)' ), | |
| 1288 | + 'PayPal' => array( 'paypal' ), | |
| 1289 | + 'Stripe' => array( 'credit_card', 'var(--green)' ), | |
| 1290 | + 'Twilio' => array( 'sms', 'rgb(0,160,210)' ), | |
| 1291 | + 'Payment' => array( 'credit_card', 'var(--green)' ), | |
| 1292 | + 'Health and Wellness' => array( 'heart', 'var(--pink)' ), | |
| 1293 | + 'Event Planning' => array( 'calendar', 'var(--orange)' ), | |
| 1294 | + 'Real Estate' => array( 'house', 'var(--purple)' ), | |
| 1295 | + 'Calculator' => array( 'calculator', 'var(--purple)' ), | |
| 1296 | + 'Registrations' => array( 'address_card' ), | |
| 1297 | + 'Customer Service' => array( 'users_solid', 'var(--pink)' ), | |
| 1298 | + 'Education' => array( 'pencil', 'var(--primary-color)' ), | |
| 1299 | + 'Marketing' => array( 'eye', 'rgb(0,160,210)' ), | |
| 1300 | + 'Feedback' => array( 'smile', 'var(--green)' ), | |
| 1301 | + 'Business Operations' => array( 'case' ), | |
| 1302 | + 'Contact Form' => array( 'email' ), | |
| 1303 | + 'Survey' => array( 'comment', 'var(--primary-color)' ), | |
| 1304 | + 'Application Form' => array( 'align_right', 'rgb(0,160,210)' ), | |
| 1305 | + 'Quiz' => array( 'percent' ), | |
| 1306 | + '' => array( 'align_right' ), | |
| 1592 | 1307 | ); |
| 1593 | 1308 | |
| 1594 | - // Determine the icon to be used. | |
| 1309 | + $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' ); | |
| 1310 | + | |
| 1595 | 1311 | $icon = $icons['']; |
| 1596 | 1312 | |
| 1597 | 1313 | if ( count( $categories ) === 1 ) { |
| 1598 | 1314 | $category = reset( $categories ); |
| 1599 | - $icon = $icons[ $category ] ?? $icon; | |
| 1600 | - } elseif ( $categories ) { | |
| 1601 | - $icons = array_intersect_key( $icons, array_flip( $categories ) ); | |
| 1602 | - $icon = reset( $icons ); | |
| 1315 | + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; | |
| 1316 | + } elseif ( ! empty( $categories ) ) { | |
| 1317 | + foreach ( $icons as $cat => $icon ) { | |
| 1318 | + if ( ! in_array( $cat, $categories ) ) { | |
| 1319 | + unset( $icons[ $cat ] ); | |
| 1320 | + } | |
| 1321 | + } | |
| 1322 | + $icon = reset( $icons ); | |
| 1603 | 1323 | } |
| 1604 | 1324 | |
| 1605 | - // Prepare variables for output. | |
| 1606 | - $icon_name = $icon[0]; | |
| 1607 | - $bg_color = $icon[1] ?? ''; | |
| 1325 | + echo '<span class="frm-inner-circle" ' . ( isset( $icon[1] ) ? 'style="background-color:' . esc_attr( $icon[1] ) : '' ) . '">'; | |
| 1326 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' ); | |
| 1327 | + echo '<span class="frm_hidden">'; | |
| 1328 | + FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' ); | |
| 1329 | + echo '</span>'; | |
| 1330 | + echo '</span>'; | |
| 1331 | + } | |
| 1608 | 1332 | |
| 1609 | - // Render the icon. | |
| 1610 | - echo '<span class="frm-category-icon frm-icon-wrapper"'; | |
| 1611 | - | |
| 1612 | - if ( $bg_color && $atts['bg'] ) { | |
| 1613 | - echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; | |
| 1614 | - } | |
| 1615 | - | |
| 1616 | - echo '>'; | |
| 1617 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1618 | - echo '</span>'; | |
| 1333 | + /** | |
| 1334 | + * @since 4.03.01 | |
| 1335 | + */ | |
| 1336 | + public static function ignore_template_categories() { | |
| 1337 | + return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); | |
| 1619 | 1338 | } |
| 1620 | 1339 | |
| 1621 | 1340 | /** |
| 1622 | - * Get template install link. | |
| 1623 | - * | |
| 1624 | 1341 | * @since 4.02 |
| 1625 | - * | |
| 1626 | - * @param array $template Template details. | |
| 1627 | - * @param array $args Additional arguments. | |
| 1628 | - * | |
| 1629 | - * @return array The link attributes. | |
| 1630 | 1342 | */ |
| 1631 | 1343 | public static function get_template_install_link( $template, $args ) { |
| 1632 | 1344 | $defaults = array( |
| 1633 | 1345 | 'class' => 'install-now', |
| @@ -1642,8 +1354,13 @@ | ||
| 1642 | 1354 | 'class' => 'frm-install-template', |
| 1643 | 1355 | 'href' => 'rel', |
| 1644 | 1356 | 'atts' => '', |
| 1645 | 1357 | ); |
| 1358 | + } elseif ( self::plan_is_allowed( $args ) ) { | |
| 1359 | + $link = array( | |
| 1360 | + 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'], | |
| 1361 | + 'label' => __( 'Renew', 'formidable' ), | |
| 1362 | + ); | |
| 1646 | 1363 | } else { |
| 1647 | 1364 | $link = array( |
| 1648 | 1365 | 'url' => $args['pricing'], |
| 1649 | 1366 | 'label' => __( 'Upgrade', 'formidable' ), |
| @@ -1666,23 +1383,20 @@ | ||
| 1666 | 1383 | if ( empty( $args['license_type'] ) ) { |
| 1667 | 1384 | return false; |
| 1668 | 1385 | } |
| 1669 | 1386 | |
| 1670 | - $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1671 | - $license_type = strtolower( $args['license_type'] ); | |
| 1672 | - $plan_required = strtolower( $args['plan_required'] ); | |
| 1673 | - $included = $license_type === $plan_required; | |
| 1387 | + $included = $args['license_type'] === strtolower( $args['plan_required'] ); | |
| 1674 | 1388 | |
| 1675 | - if ( $included || ! in_array( $plan_required, $plans, true ) ) { | |
| 1389 | + $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1390 | + if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) { | |
| 1676 | 1391 | return $included; |
| 1677 | 1392 | } |
| 1678 | 1393 | |
| 1679 | 1394 | foreach ( $plans as $plan ) { |
| 1680 | - if ( $included || $plan === $license_type ) { | |
| 1395 | + if ( $included || $plan === $args['license_type'] ) { | |
| 1681 | 1396 | break; |
| 1682 | 1397 | } |
| 1683 | - | |
| 1684 | - $included = $plan === $plan_required; | |
| 1398 | + $included = $plan === strtolower( $args['plan_required'] ); | |
| 1685 | 1399 | } |
| 1686 | 1400 | |
| 1687 | 1401 | return $included; |
| 1688 | 1402 | } |
| @@ -1687,33 +1401,34 @@ | ||
| 1687 | 1401 | return $included; |
| 1688 | 1402 | } |
| 1689 | 1403 | |
| 1690 | 1404 | /** |
| 1405 | + * @since 4.02 | |
| 1406 | + */ | |
| 1407 | + public static function template_install_html( $link, $class = '' ) { | |
| 1408 | + $link['class'] .= ' ' . $class; | |
| 1409 | + echo '<a ' . esc_attr( $link['href'] ) . '="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link['class'] ) . ' " aria-label="' . esc_attr( $link['label'] ) . '"' . ( $link['atts'] ? ' target="_blank" rel="noopener"' : '' ) . '>'; | |
| 1410 | + } | |
| 1411 | + | |
| 1412 | + /** | |
| 1691 | 1413 | * If a template or add-on cannot be installed, show a message |
| 1692 | 1414 | * about which plan is required. |
| 1693 | 1415 | * |
| 1694 | 1416 | * @since 4.0 |
| 1695 | - * | |
| 1696 | - * @param string $requires | |
| 1697 | - * @param string $link | |
| 1698 | - * | |
| 1699 | - * @return void | |
| 1700 | 1417 | */ |
| 1701 | 1418 | public static function show_plan_required( $requires, $link ) { |
| 1702 | - if ( ! $requires ) { | |
| 1419 | + if ( empty( $requires ) ) { | |
| 1703 | 1420 | return; |
| 1704 | 1421 | } |
| 1705 | 1422 | |
| 1706 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1707 | 1423 | ?> |
| 1708 | 1424 | <p class="frm_plan_required"> |
| 1709 | - <?php esc_html_e( 'Plan required:', 'formidable' ); ?> | |
| 1425 | + <?php esc_html_e( 'License plan required:', 'formidable' ); ?> | |
| 1710 | 1426 | <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener"> |
| 1711 | 1427 | <?php echo esc_html( $requires ); ?> |
| 1712 | 1428 | </a> |
| 1713 | 1429 | </p> |
| 1714 | 1430 | <?php |
| 1715 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1716 | 1431 | } |
| 1717 | 1432 | |
| 1718 | 1433 | /** |
| 1719 | 1434 | * @since 4.0 |
| @@ -1718,10 +1433,9 @@ | ||
| 1718 | 1433 | /** |
| 1719 | 1434 | * @since 4.0 |
| 1720 | 1435 | * |
| 1721 | 1436 | * @param array $item |
| 1722 | - * | |
| 1723 | - * @return false|string | |
| 1437 | + * @return string|false | |
| 1724 | 1438 | */ |
| 1725 | 1439 | public static function get_plan_required( &$item ) { |
| 1726 | 1440 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| 1727 | 1441 | return false; |
| @@ -1726,14 +1440,20 @@ | ||
| 1726 | 1440 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| 1727 | 1441 | return false; |
| 1728 | 1442 | } |
| 1729 | 1443 | |
| 1730 | - $plans = self::get_license_types(); | |
| 1444 | + $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' ); | |
| 1731 | 1445 | |
| 1732 | 1446 | foreach ( $item['categories'] as $k => $category ) { |
| 1733 | 1447 | if ( in_array( $category, $plans, true ) ) { |
| 1734 | 1448 | unset( $item['categories'][ $k ] ); |
| 1735 | - return self::convert_legacy_package_names( $category ); | |
| 1449 | + | |
| 1450 | + if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) { | |
| 1451 | + // Show the current package name. | |
| 1452 | + $category = 'Plus'; | |
| 1453 | + } | |
| 1454 | + | |
| 1455 | + return $category; | |
| 1736 | 1456 | } |
| 1737 | 1457 | } |
| 1738 | 1458 | |
| 1739 | 1459 | return false; |
| @@ -1739,53 +1459,8 @@ | ||
| 1739 | 1459 | return false; |
| 1740 | 1460 | } |
| 1741 | 1461 | |
| 1742 | 1462 | /** |
| 1743 | - * Converts legacy package names to the current standard package name. | |
| 1744 | - * | |
| 1745 | - * @since 6.15 | |
| 1746 | - * | |
| 1747 | - * @param string $package_name | |
| 1748 | - * | |
| 1749 | - * @return string The updated package name. | |
| 1750 | - */ | |
| 1751 | - public static function convert_legacy_package_names( $package_name ) { | |
| 1752 | - if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) { | |
| 1753 | - return 'Plus'; | |
| 1754 | - } | |
| 1755 | - | |
| 1756 | - return $package_name; | |
| 1757 | - } | |
| 1758 | - | |
| 1759 | - /** | |
| 1760 | - * Get the license types. | |
| 1761 | - * | |
| 1762 | - * @since 6.15 | |
| 1763 | - * | |
| 1764 | - * @param array $args | |
| 1765 | - * | |
| 1766 | - * @return array | |
| 1767 | - */ | |
| 1768 | - public static function get_license_types( $args = array() ) { | |
| 1769 | - $defaults = array( | |
| 1770 | - 'include_all' => true, | |
| 1771 | - 'case_lower' => false, | |
| 1772 | - ); | |
| 1773 | - $args = wp_parse_args( $args, $defaults ); | |
| 1774 | - $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' ); | |
| 1775 | - | |
| 1776 | - if ( $args['include_all'] ) { | |
| 1777 | - $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); | |
| 1778 | - } | |
| 1779 | - | |
| 1780 | - if ( $args['case_lower'] ) { | |
| 1781 | - return array_map( 'strtolower', $license_types ); | |
| 1782 | - } | |
| 1783 | - | |
| 1784 | - return $license_types; | |
| 1785 | - } | |
| 1786 | - | |
| 1787 | - /** | |
| 1788 | 1463 | * Checks for warnings to be displayed after form settings are saved. |
| 1789 | 1464 | * |
| 1790 | 1465 | * @since 4.04 |
| 1791 | 1466 | * |
| @@ -1793,9 +1468,10 @@ | ||
| 1793 | 1468 | * |
| 1794 | 1469 | * @return array An array of warnings or an empty array. |
| 1795 | 1470 | */ |
| 1796 | 1471 | public static function check_for_warnings( $values ) { |
| 1797 | - $warnings = array(); | |
| 1472 | + $warnings = array(); | |
| 1473 | + | |
| 1798 | 1474 | $redirect_warning = self::check_redirect_url_for_unsafe_params( $values ); |
| 1799 | 1475 | |
| 1800 | 1476 | if ( $redirect_warning ) { |
| 1801 | 1477 | $warnings[] = $redirect_warning; |
| @@ -1820,9 +1496,9 @@ | ||
| 1820 | 1496 | |
| 1821 | 1497 | $options = $values['options']; |
| 1822 | 1498 | FrmAppHelper::sanitize_with_html( $options ); |
| 1823 | 1499 | |
| 1824 | - if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) { | |
| 1500 | + if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) { | |
| 1825 | 1501 | return false; |
| 1826 | 1502 | } |
| 1827 | 1503 | |
| 1828 | 1504 | $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] ); |
| @@ -1840,13 +1516,11 @@ | ||
| 1840 | 1516 | * @return array An array of params whose names are reserved words or an empty array. |
| 1841 | 1517 | */ |
| 1842 | 1518 | private static function get_unsafe_params( $url ) { |
| 1843 | 1519 | $redirect_components = parse_url( $url ); |
| 1844 | - | |
| 1845 | 1520 | if ( empty( $redirect_components['query'] ) ) { |
| 1846 | 1521 | return array(); |
| 1847 | 1522 | } |
| 1848 | - | |
| 1849 | 1523 | parse_str( $redirect_components['query'], $redirect_params ); |
| 1850 | 1524 | $redirect_param_names = array_keys( $redirect_params ); |
| 1851 | 1525 | $reserved_words = self::reserved_words(); |
| 1852 | 1526 | $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words ); |
| @@ -1863,27 +1537,26 @@ | ||
| 1863 | 1537 | * |
| 1864 | 1538 | * @return bool|string A string with an unsafe param message or false. |
| 1865 | 1539 | */ |
| 1866 | 1540 | private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) { |
| 1867 | - $count = count( $unsafe_params_in_redirect ); | |
| 1541 | + $count = count( $unsafe_params_in_redirect ); | |
| 1542 | + $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1543 | + $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1544 | + $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1868 | 1545 | |
| 1869 | 1546 | if ( $count === 0 ) { |
| 1870 | 1547 | return false; |
| 1871 | 1548 | } |
| 1872 | 1549 | |
| 1873 | - $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1874 | - $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1875 | - $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1876 | - | |
| 1877 | - if ( $count === 1 ) { | |
| 1550 | + if ( $count == 1 ) { | |
| 1878 | 1551 | /* translators: %s: the name of a single parameter in the redirect URL */ |
| 1879 | - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1552 | + return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; | |
| 1880 | 1553 | } |
| 1881 | 1554 | |
| 1882 | 1555 | $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect ); |
| 1883 | 1556 | |
| 1884 | 1557 | /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */ |
| 1885 | - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1558 | + return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; | |
| 1886 | 1559 | } |
| 1887 | 1560 | |
| 1888 | 1561 | /** |
| 1889 | 1562 | * Returns an array of common reserved words in WordPress. |
| @@ -1942,8 +1615,34 @@ | ||
| 1942 | 1615 | ); |
| 1943 | 1616 | } |
| 1944 | 1617 | |
| 1945 | 1618 | /** |
| 1619 | + * Check an array of templates, determine how many the logged in user can use | |
| 1620 | + * | |
| 1621 | + * @param array $templates | |
| 1622 | + * @param array $args | |
| 1623 | + * @return int | |
| 1624 | + */ | |
| 1625 | + public static function available_count( $templates, $args ) { | |
| 1626 | + return array_reduce( | |
| 1627 | + $templates, | |
| 1628 | + function( $total, $template ) use ( $args ) { | |
| 1629 | + if ( ! empty( $template['url'] ) ) { | |
| 1630 | + return $total + 1; | |
| 1631 | + } | |
| 1632 | + | |
| 1633 | + $args['plan_required'] = self::get_plan_required( $template ); | |
| 1634 | + if ( self::plan_is_allowed( $args ) ) { | |
| 1635 | + return $total + 1; | |
| 1636 | + } | |
| 1637 | + | |
| 1638 | + return $total; | |
| 1639 | + }, | |
| 1640 | + 0 | |
| 1641 | + ); | |
| 1642 | + } | |
| 1643 | + | |
| 1644 | + /** | |
| 1946 | 1645 | * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined. |
| 1947 | 1646 | * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL. |
| 1948 | 1647 | * |
| 1949 | 1648 | * @since 5.0.16 |
| @@ -1949,19 +1648,17 @@ | ||
| 1949 | 1648 | * @since 5.0.16 |
| 1950 | 1649 | * |
| 1951 | 1650 | * @param string $url |
| 1952 | 1651 | * @param int $form_id |
| 1953 | - * | |
| 1954 | 1652 | * @return string |
| 1955 | 1653 | */ |
| 1956 | 1654 | public static function maybe_add_sanitize_url_attr( $url, $form_id ) { |
| 1957 | - if ( ! str_contains( $url, '[' ) ) { | |
| 1655 | + if ( false === strpos( $url, '[' ) ) { | |
| 1958 | 1656 | // Do nothing if no shortcodes are detected. |
| 1959 | 1657 | return $url; |
| 1960 | 1658 | } |
| 1961 | 1659 | |
| 1962 | 1660 | $parsed = wp_parse_url( $url ); |
| 1963 | - | |
| 1964 | 1661 | if ( empty( $parsed['query'] ) ) { |
| 1965 | 1662 | // Do nothing if no query can be detected in the url string. |
| 1966 | 1663 | return $url; |
| 1967 | 1664 | } |
| @@ -1967,10 +1664,10 @@ | ||
| 1967 | 1664 | } |
| 1968 | 1665 | |
| 1969 | 1666 | $original_query = $parsed['query']; |
| 1970 | 1667 | $query = $parsed['query']; |
| 1971 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1972 | 1668 | |
| 1669 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1973 | 1670 | if ( empty( $shortcodes[0] ) ) { |
| 1974 | 1671 | // No shortcodes found, do nothing. |
| 1975 | 1672 | return $url; |
| 1976 | 1673 | } |
| @@ -1982,22 +1679,21 @@ | ||
| 1982 | 1679 | // Skip if shortcodes. |
| 1983 | 1680 | continue; |
| 1984 | 1681 | } |
| 1985 | 1682 | |
| 1986 | - if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) { | |
| 1683 | + if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) { | |
| 1987 | 1684 | // A sanitize option is already set so leave it alone. |
| 1988 | 1685 | continue; |
| 1989 | 1686 | } |
| 1990 | 1687 | |
| 1991 | 1688 | $new_shortcode = '[' . $shortcodes[2][ $key ]; |
| 1992 | - | |
| 1993 | 1689 | if ( $options ) { |
| 1994 | 1690 | $new_shortcode .= ' ' . $options; |
| 1995 | 1691 | } |
| 1692 | + $new_shortcode .= ' sanitize_url=1]'; | |
| 1996 | 1693 | |
| 1997 | - $new_shortcode .= ' sanitize_url=1]'; | |
| 1998 | - $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1999 | - }//end foreach | |
| 1694 | + $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1695 | + } | |
| 2000 | 1696 | |
| 2001 | 1697 | if ( $query === $original_query ) { |
| 2002 | 1698 | return $url; |
| 2003 | 1699 | } |
| @@ -2002,157 +1698,6 @@ | ||
| 2002 | 1698 | return $url; |
| 2003 | 1699 | } |
| 2004 | 1700 | |
| 2005 | 1701 | return str_replace( $original_query, $query, $url ); |
| 2006 | - } | |
| 2007 | - | |
| 2008 | - /** | |
| 2009 | - * Outputs the appropriate button text in the publish box. | |
| 2010 | - * | |
| 2011 | - * @return void | |
| 2012 | - */ | |
| 2013 | - public static function publish_box_button_text() { | |
| 2014 | - $is_new_template = FrmAppHelper::simple_get( 'new_template' ); | |
| 2015 | - $action = FrmAppHelper::simple_get( 'frm_action' ); | |
| 2016 | - | |
| 2017 | - if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) { | |
| 2018 | - esc_html_e( 'Save', 'formidable' ); | |
| 2019 | - } else { | |
| 2020 | - esc_html_e( 'Update', 'formidable' ); | |
| 2021 | - } | |
| 2022 | - } | |
| 2023 | - | |
| 2024 | - /** | |
| 2025 | - * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ]. | |
| 2026 | - * This allows shortcodes inside of the layout classes setting. | |
| 2027 | - * | |
| 2028 | - * @since 6.16 | |
| 2029 | - * | |
| 2030 | - * @param string $classname | |
| 2031 | - * | |
| 2032 | - * @return string | |
| 2033 | - */ | |
| 2034 | - public static function sanitize_layout_class( $classname ) { | |
| 2035 | - // Strip out any percent-encoded characters. | |
| 2036 | - $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname ); | |
| 2037 | - | |
| 2038 | - // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'. | |
| 2039 | - return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 2040 | - } | |
| 2041 | - | |
| 2042 | - /** | |
| 2043 | - * Returns true if the preview should be blocked. | |
| 2044 | - * | |
| 2045 | - * @since 6.20 | |
| 2046 | - * | |
| 2047 | - * @param string $form_key | |
| 2048 | - * | |
| 2049 | - * @return bool | |
| 2050 | - */ | |
| 2051 | - public static function should_block_preview( $form_key ) { | |
| 2052 | - $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' ); | |
| 2053 | - /** | |
| 2054 | - * Filters whether the form preview should be blocked. | |
| 2055 | - * | |
| 2056 | - * @since 6.20 | |
| 2057 | - * | |
| 2058 | - * @param bool $should_block | |
| 2059 | - * @param string $form_key | |
| 2060 | - */ | |
| 2061 | - return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 2062 | - } | |
| 2063 | - | |
| 2064 | - /** | |
| 2065 | - * Checks if the form is loaded by API. | |
| 2066 | - * | |
| 2067 | - * @since 6.21 | |
| 2068 | - * | |
| 2069 | - * @return bool | |
| 2070 | - */ | |
| 2071 | - public static function form_is_loaded_by_api() { | |
| 2072 | - global $frm_vars; | |
| 2073 | - | |
| 2074 | - if ( ! empty( $frm_vars['inplace_edit'] ) ) { | |
| 2075 | - return true; | |
| 2076 | - } | |
| 2077 | - | |
| 2078 | - return self::is_formidable_api_form() || self::is_block_or_page_builder_preview(); | |
| 2079 | - } | |
| 2080 | - | |
| 2081 | - /** | |
| 2082 | - * Checks if the form is rendered inside a block editor or page builder preview. | |
| 2083 | - * | |
| 2084 | - * @since 6.29 | |
| 2085 | - * | |
| 2086 | - * @return bool | |
| 2087 | - */ | |
| 2088 | - public static function is_block_or_page_builder_preview() { | |
| 2089 | - return self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview(); | |
| 2090 | - } | |
| 2091 | - | |
| 2092 | - /** | |
| 2093 | - * @since 6.21 | |
| 2094 | - * | |
| 2095 | - * @return bool | |
| 2096 | - */ | |
| 2097 | - private static function is_visual_views_preview() { | |
| 2098 | - return 'frm_views_process_box_preview' === FrmAppHelper::get_post_param( 'action' ); | |
| 2099 | - } | |
| 2100 | - | |
| 2101 | - /** | |
| 2102 | - * @since 6.21 | |
| 2103 | - * | |
| 2104 | - * @return bool | |
| 2105 | - */ | |
| 2106 | - private static function is_elementor_ajax() { | |
| 2107 | - return 'elementor_ajax' === FrmAppHelper::get_post_param( 'action' ); | |
| 2108 | - } | |
| 2109 | - | |
| 2110 | - /** | |
| 2111 | - * @since 6.21 | |
| 2112 | - * | |
| 2113 | - * @return bool | |
| 2114 | - */ | |
| 2115 | - private static function is_gutenberg_editor() { | |
| 2116 | - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); | |
| 2117 | - | |
| 2118 | - if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 2119 | - return true; | |
| 2120 | - } | |
| 2121 | - | |
| 2122 | - if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) { | |
| 2123 | - return true; | |
| 2124 | - } | |
| 2125 | - | |
| 2126 | - global $pagenow; | |
| 2127 | - return 'post.php' === $pagenow; | |
| 2128 | - } | |
| 2129 | - | |
| 2130 | - /** | |
| 2131 | - * @since 6.21 | |
| 2132 | - * | |
| 2133 | - * @return bool | |
| 2134 | - */ | |
| 2135 | - private static function is_formidable_api_form() { | |
| 2136 | - if ( ! class_exists( 'FrmAPIAppController' ) ) { | |
| 2137 | - return false; | |
| 2138 | - } | |
| 2139 | - | |
| 2140 | - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); | |
| 2141 | - | |
| 2142 | - if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 2143 | - // Prevent the honeypot from appearing for an API loaded form. | |
| 2144 | - // This is to prevent conflicts where the script is not working. | |
| 2145 | - return true; | |
| 2146 | - } | |
| 2147 | - | |
| 2148 | - if ( is_callable( 'FrmProFormState::get_from_request' ) ) { | |
| 2149 | - $api = FrmProFormState::get_from_request( 'a', 0 ); | |
| 2150 | - | |
| 2151 | - if ( $api ) { | |
| 2152 | - return true; | |
| 2153 | - } | |
| 2154 | - } | |
| 2155 | - | |
| 2156 | - return false; | |
| 2157 | 1702 | } |
| 2158 | 1703 | } |