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