| @@ -15,52 +15,50 @@ | ||
| 15 | 15 | public static function get_direct_link( $key, $form = false ) { |
| 16 | 16 | $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) ); |
| 17 | 17 | $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form ); |
| 18 | 18 | |
| 19 | - return $target_url; | |
| 20 | - } | |
| 19 | + return $target_url; | |
| 20 | + } | |
| 21 | 21 | |
| 22 | - public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) { | |
| 23 | - $defaults = array( | |
| 24 | - 'blank' => true, | |
| 25 | - 'field_id' => false, | |
| 26 | - 'onchange' => false, | |
| 27 | - 'exclude' => false, | |
| 28 | - 'class' => '', | |
| 22 | + public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) { | |
| 23 | + $defaults = array( | |
| 24 | + 'blank' => true, | |
| 25 | + 'field_id' => false, | |
| 26 | + 'onchange' => false, | |
| 27 | + 'exclude' => false, | |
| 28 | + 'class' => '', | |
| 29 | 29 | 'inc_children' => 'exclude', |
| 30 | - ); | |
| 31 | - $args = wp_parse_args( $args, $defaults ); | |
| 30 | + ); | |
| 31 | + $args = wp_parse_args( $args, $defaults ); | |
| 32 | 32 | |
| 33 | - if ( ! $args['field_id'] ) { | |
| 34 | - $args['field_id'] = $field_name; | |
| 35 | - } | |
| 33 | + if ( ! $args['field_id'] ) { | |
| 34 | + $args['field_id'] = $field_name; | |
| 35 | + } | |
| 36 | 36 | |
| 37 | 37 | $query = array(); |
| 38 | - if ( $args['exclude'] ) { | |
| 38 | + if ( $args['exclude'] ) { | |
| 39 | 39 | $query['id !'] = $args['exclude']; |
| 40 | - } | |
| 40 | + } | |
| 41 | 41 | |
| 42 | - $where = apply_filters( 'frm_forms_dropdown', $query, $field_name ); | |
| 43 | - $forms = FrmForm::get_published_forms( $where, 999, $args['inc_children'] ); | |
| 42 | + $where = apply_filters( 'frm_forms_dropdown', $query, $field_name ); | |
| 43 | + $forms = FrmForm::get_published_forms( $where, 999, $args['inc_children'] ); | |
| 44 | 44 | $add_html = array(); |
| 45 | 45 | self::add_html_attr( $args['onchange'], 'onchange', $add_html ); |
| 46 | 46 | self::add_html_attr( $args['class'], 'class', $add_html ); |
| 47 | 47 | |
| 48 | - ?> | |
| 49 | - <select name="<?php echo esc_attr( $field_name ); ?>" | |
| 50 | - id="<?php echo esc_attr( $args['field_id'] ); ?>" | |
| 51 | - <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 52 | - <?php if ( $args['blank'] ) { ?> | |
| 53 | - <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 54 | - <?php } ?> | |
| 55 | - <?php foreach ( $forms as $form ) { ?> | |
| 56 | - <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> | |
| 57 | - <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> | |
| 58 | - </option> | |
| 59 | - <?php } ?> | |
| 60 | - </select> | |
| 61 | - <?php | |
| 62 | - } | |
| 48 | + ?> | |
| 49 | + <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $args['field_id'] ) ?>" <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // WPCS: XSS ok. ?>> | |
| 50 | + <?php if ( $args['blank'] ) { ?> | |
| 51 | + <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 52 | + <?php } ?> | |
| 53 | + <?php foreach ( $forms as $form ) { ?> | |
| 54 | + <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> | |
| 55 | + <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> | |
| 56 | + </option> | |
| 57 | + <?php } ?> | |
| 58 | + </select> | |
| 59 | + <?php | |
| 60 | + } | |
| 63 | 61 | |
| 64 | 62 | /** |
| 65 | 63 | * @param string $class |
| 66 | 64 | * @param string $param |
| @@ -73,12 +71,9 @@ | ||
| 73 | 71 | $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"'; |
| 74 | 72 | } |
| 75 | 73 | } |
| 76 | 74 | |
| 77 | - /** | |
| 78 | - * @param string|object|false $selected - The label for the placeholder, or the form object. | |
| 79 | - */ | |
| 80 | - public static function form_switcher( $selected = false ) { | |
| 75 | + public static function form_switcher() { | |
| 81 | 76 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 82 | 77 | $forms = FrmForm::get_published_forms( $where ); |
| 83 | 78 | |
| 84 | 79 | $args = array( |
| @@ -88,130 +83,66 @@ | ||
| 88 | 83 | if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) { |
| 89 | 84 | unset( $args['form'] ); |
| 90 | 85 | } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) { |
| 91 | 86 | unset( $args['id'] ); |
| 92 | - } | |
| 87 | + } | |
| 93 | 88 | |
| 94 | 89 | $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 95 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ) ) ) { | |
| 96 | - $args['frm_action'] = 'list'; | |
| 97 | - $args['form'] = 0; | |
| 90 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy_all' ) ) ) { | |
| 91 | + $args['frm_action'] = 'list'; | |
| 92 | + $args['form'] = 0; | |
| 98 | 93 | } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) { |
| 99 | - $args['frm_action'] = 'edit'; | |
| 100 | - } elseif ( FrmAppHelper::is_style_editor_page() ) { | |
| 101 | - unset( $args['id'] ); // Avoid passing style into form switcher on style page. | |
| 102 | - $query_args = array( | |
| 103 | - 'page' => 'formidable-styles', | |
| 104 | - ); | |
| 105 | - if ( $frm_action ) { | |
| 106 | - $query_args['frm_action'] = $frm_action; | |
| 107 | - } | |
| 108 | - $base = add_query_arg( $query_args, admin_url( 'admin.php' ) ); | |
| 109 | - } elseif ( isset( $_GET['post'] ) ) { | |
| 110 | - $args['form'] = 0; | |
| 111 | - $base = admin_url( 'edit.php?post_type=frm_display' ); | |
| 112 | - } | |
| 94 | + $args['frm_action'] = 'edit'; | |
| 95 | + } else if ( isset( $_GET['post'] ) ) { | |
| 96 | + $args['form'] = 0; | |
| 97 | + $base = admin_url( 'edit.php?post_type=frm_display' ); | |
| 98 | + } | |
| 113 | 99 | |
| 114 | - $form_id = 0; | |
| 115 | - if ( is_object( $selected ) ) { | |
| 116 | - $form_id = $selected->id; | |
| 117 | - $selected = $selected->name; | |
| 118 | - } | |
| 119 | - | |
| 120 | - $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected; | |
| 121 | - $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name ); | |
| 122 | - $truncated_name = FrmAppHelper::truncate( $name, 25 ); | |
| 123 | - | |
| 124 | - if ( count( $forms ) < 2 ) { | |
| 125 | - ?> | |
| 126 | - <div id="frm_bs_dropdown"> | |
| 127 | - <h1> | |
| 128 | - <span class="frm_bstooltip" title="<?php echo esc_attr( $truncated_name === $name ? '' : $name ); ?>" data-placement="right"> | |
| 129 | - <?php echo esc_html( $name ); ?> | |
| 130 | - </span> | |
| 131 | - </h1> | |
| 132 | - </div> | |
| 100 | + ?> | |
| 101 | + <li id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ) ?>"> | |
| 102 | + <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php esc_html_e( 'Switch Form', 'formidable' ) ?> <b class="caret"></b></a> | |
| 103 | + <ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-navbarDrop"> | |
| 133 | 104 | <?php |
| 134 | - return; | |
| 135 | - } | |
| 136 | - ?> | |
| 137 | - <div id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'dropdown-menu-right' : 'dropdown-menu-left' ); ?>"> | |
| 138 | - <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"> | |
| 139 | - <h1> | |
| 140 | - <span class="frm_bstooltip" title="<?php echo esc_attr( $truncated_name === $name ? '' : $name ); ?>" data-placement="right"> | |
| 141 | - <?php echo esc_html( $name ); ?> | |
| 142 | - </span> | |
| 143 | - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) ); ?> | |
| 144 | - </h1> | |
| 145 | - </a> | |
| 146 | - <ul class="frm-dropdown-menu frm-on-top frm-inline-modal frm_code_list frm-full-hover" role="menu" aria-labelledby="frm-navbarDrop"> | |
| 147 | - <?php if ( count( $forms ) > 8 ) { ?> | |
| 148 | - <li class="frm-with-search"> | |
| 149 | - <?php | |
| 150 | - FrmAppHelper::show_search_box( | |
| 151 | - array( | |
| 152 | - 'input_id' => 'dropform', | |
| 153 | - 'placeholder' => __( 'Search Forms', 'formidable' ), | |
| 154 | - 'tosearch' => 'frm-dropdown-form', | |
| 155 | - ) | |
| 156 | - ); | |
| 157 | - ?> | |
| 158 | - </li> | |
| 159 | - <?php } ?> | |
| 160 | - <?php | |
| 161 | - foreach ( $forms as $form ) { | |
| 162 | - if ( $form->id === $form_id ) { | |
| 163 | - // Don't include the selected form in the switcher since it does nothing. | |
| 164 | - continue; | |
| 165 | - } | |
| 166 | - | |
| 167 | - if ( isset( $args['id'] ) ) { | |
| 168 | - $args['id'] = $form->id; | |
| 169 | - } | |
| 170 | - if ( isset( $args['form'] ) ) { | |
| 171 | - $args['form'] = $form->id; | |
| 172 | - } | |
| 173 | - | |
| 174 | - $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ); | |
| 175 | - $form_name = empty( $form->name ) ? __( '(no title)', 'formidable' ) : $form->name; | |
| 176 | - ?> | |
| 177 | - <li class="frm-dropdown-form"> | |
| 178 | - <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between"> | |
| 179 | - <?php echo esc_html( $form_name ); ?> | |
| 180 | - <span> | |
| 181 | - <?php | |
| 182 | - printf( | |
| 183 | - /* translators: %d: Form ID */ | |
| 184 | - esc_html__( '(ID %d)', 'formidable' ), | |
| 185 | - esc_attr( $form->id ) | |
| 186 | - ); | |
| 187 | - ?> | |
| 188 | - </span> | |
| 189 | - <span class="frm_hidden"><?php echo esc_html( $form->form_key ); ?></span> | |
| 190 | - </a> | |
| 191 | - </li> | |
| 192 | - <?php | |
| 193 | - unset( $form ); | |
| 105 | + foreach ( $forms as $form ) { | |
| 106 | + if ( isset( $args['id'] ) ) { | |
| 107 | + $args['id'] = $form->id; | |
| 194 | 108 | } |
| 195 | - ?> | |
| 109 | + if ( isset( $args['form'] ) ) { | |
| 110 | + $args['form'] = $form->id; | |
| 111 | + } | |
| 112 | + ?> | |
| 113 | + <li><a href="<?php echo esc_url( isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 60 ) ); ?></a></li> | |
| 114 | + <?php | |
| 115 | + unset( $form ); | |
| 116 | + } | |
| 117 | + ?> | |
| 196 | 118 | </ul> |
| 197 | - </div> | |
| 198 | - <?php | |
| 199 | - } | |
| 119 | + </li> | |
| 120 | + <?php | |
| 121 | + } | |
| 200 | 122 | |
| 201 | 123 | /** |
| 202 | 124 | * @since 3.05 |
| 203 | - * @deprecated 4.0 | |
| 204 | - * | |
| 205 | 125 | * @param array $values - The form array |
| 206 | 126 | */ |
| 207 | 127 | public static function builder_submit_button( $values ) { |
| 208 | - FrmDeprecated::builder_submit_button( $values ); | |
| 128 | + $page_action = FrmAppHelper::get_param( 'frm_action' ); | |
| 129 | + $label = ( $page_action == 'edit' || $page_action == 'update' ) ? __( 'Update', 'formidable' ) : __( 'Create', 'formidable' ); | |
| 130 | + | |
| 131 | + ?> | |
| 132 | + <div class="postbox"> | |
| 133 | + <p class="inside"> | |
| 134 | + <button class="frm_submit_<?php echo esc_attr( ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_' ); ?>ajax button-primary frm_button_submit" type="button"> | |
| 135 | + <?php echo esc_html( $label ); ?> | |
| 136 | + </button> | |
| 137 | + </p> | |
| 138 | + </div> | |
| 139 | + <?php | |
| 209 | 140 | } |
| 210 | 141 | |
| 211 | 142 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 212 | 143 | echo ( $sort_col == $col ) ? 'sorted' : 'sortable'; |
| 213 | - echo ( $sort_col == $col && $sort_dir === 'desc' ) ? ' asc' : ' desc'; | |
| 144 | + echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc'; | |
| 214 | 145 | } |
| 215 | 146 | |
| 216 | 147 | /** |
| 217 | 148 | * @since 3.0 |
| @@ -221,9 +152,8 @@ | ||
| 221 | 152 | $field_label = $field_type['name']; |
| 222 | 153 | } else { |
| 223 | 154 | $field_label = $field_type; |
| 224 | 155 | } |
| 225 | - | |
| 226 | 156 | return $field_label; |
| 227 | 157 | } |
| 228 | 158 | |
| 229 | 159 | /** |
| @@ -234,9 +164,8 @@ | ||
| 234 | 164 | $icon = $field_type['icon']; |
| 235 | 165 | } else { |
| 236 | 166 | $icon = 'frm_icon_font frm_pencil_icon'; |
| 237 | 167 | } |
| 238 | - | |
| 239 | 168 | return $icon; |
| 240 | 169 | } |
| 241 | 170 | |
| 242 | 171 | /** |
| @@ -242,11 +171,9 @@ | ||
| 242 | 171 | /** |
| 243 | 172 | * Get the invalid form error message |
| 244 | 173 | * |
| 245 | 174 | * @since 2.02.07 |
| 246 | - * | |
| 247 | 175 | * @param array $args |
| 248 | - * | |
| 249 | 176 | * @return string |
| 250 | 177 | */ |
| 251 | 178 | public static function get_invalid_error_message( $args ) { |
| 252 | 179 | $settings_args = $args; |
| @@ -258,46 +185,37 @@ | ||
| 258 | 185 | $invalid_msg = do_shortcode( $frm_settings->invalid_msg ); |
| 259 | 186 | return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args ); |
| 260 | 187 | } |
| 261 | 188 | |
| 262 | - /** | |
| 263 | - * @param array $atts { | |
| 264 | - * @type string $message | |
| 265 | - * @type stdClass $form | |
| 266 | - * @type int $entry_id | |
| 267 | - * @type string $class | |
| 268 | - * } | |
| 269 | - * @return string | |
| 270 | - */ | |
| 271 | 189 | public static function get_success_message( $atts ) { |
| 272 | 190 | $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] ); |
| 273 | - $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) ); | |
| 274 | - $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 191 | + $message = FrmAppHelper::use_wpautop( do_shortcode( $message ) ); | |
| 192 | + $message = '<div class="' . esc_attr( $atts['class'] ) . '">' . $message . '</div>'; | |
| 275 | 193 | return $message; |
| 276 | 194 | } |
| 277 | 195 | |
| 278 | - /** | |
| 279 | - * Used when a form is created | |
| 280 | - */ | |
| 281 | - public static function setup_new_vars( $values = array() ) { | |
| 282 | - global $wpdb; | |
| 196 | + /** | |
| 197 | + * Used when a form is created | |
| 198 | + */ | |
| 199 | + public static function setup_new_vars( $values = array() ) { | |
| 200 | + global $wpdb; | |
| 283 | 201 | |
| 284 | - if ( ! empty( $values ) ) { | |
| 285 | - $post_values = $values; | |
| 286 | - } else { | |
| 287 | - $values = array(); | |
| 288 | - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 289 | - } | |
| 202 | + if ( ! empty( $values ) ) { | |
| 203 | + $post_values = $values; | |
| 204 | + } else { | |
| 205 | + $values = array(); | |
| 206 | + $post_values = isset( $_POST ) ? $_POST : array(); | |
| 207 | + } | |
| 290 | 208 | |
| 291 | 209 | $defaults = array( |
| 292 | - 'name' => '', | |
| 210 | + 'name' => '', | |
| 293 | 211 | 'description' => '', |
| 294 | 212 | ); |
| 295 | 213 | foreach ( $defaults as $var => $default ) { |
| 296 | 214 | if ( ! isset( $values[ $var ] ) ) { |
| 297 | 215 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 298 | - } | |
| 299 | - } | |
| 216 | + } | |
| 217 | + } | |
| 300 | 218 | |
| 301 | 219 | $values['description'] = FrmAppHelper::use_wpautop( $values['description'] ); |
| 302 | 220 | |
| 303 | 221 | $defaults = array( |
| @@ -304,9 +222,9 @@ | ||
| 304 | 222 | 'form_id' => '', |
| 305 | 223 | 'logged_in' => '', |
| 306 | 224 | 'editable' => '', |
| 307 | 225 | 'is_template' => 0, |
| 308 | - 'status' => 'published', | |
| 226 | + 'status' => 'draft', | |
| 309 | 227 | 'parent_form_id' => 0, |
| 310 | 228 | ); |
| 311 | 229 | foreach ( $defaults as $var => $default ) { |
| 312 | 230 | if ( ! isset( $values[ $var ] ) ) { |
| @@ -314,91 +232,83 @@ | ||
| 314 | 232 | } |
| 315 | 233 | } |
| 316 | 234 | unset( $defaults ); |
| 317 | 235 | |
| 318 | - if ( ! isset( $values['form_key'] ) ) { | |
| 236 | + if ( ! isset( $values['form_key'] ) ) { | |
| 319 | 237 | $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); |
| 320 | - } | |
| 238 | + } | |
| 321 | 239 | |
| 322 | - $values = self::fill_default_opts( $values, false, $post_values ); | |
| 240 | + $values = self::fill_default_opts( $values, false, $post_values ); | |
| 323 | 241 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| 324 | 242 | |
| 325 | 243 | return apply_filters( 'frm_setup_new_form_vars', $values ); |
| 326 | - } | |
| 244 | + } | |
| 327 | 245 | |
| 328 | - /** | |
| 329 | - * Used when editing a form | |
| 330 | - */ | |
| 331 | - public static function setup_edit_vars( $values, $record, $post_values = array() ) { | |
| 246 | + /** | |
| 247 | + * Used when editing a form | |
| 248 | + */ | |
| 249 | + public static function setup_edit_vars( $values, $record, $post_values = array() ) { | |
| 332 | 250 | if ( empty( $post_values ) ) { |
| 333 | - $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 251 | + $post_values = stripslashes_deep( $_POST ); | |
| 334 | 252 | } |
| 335 | 253 | |
| 336 | - $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key; | |
| 254 | + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key; | |
| 337 | 255 | $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template; |
| 338 | - $values['status'] = $record->status; | |
| 256 | + $values['status'] = $record->status; | |
| 339 | 257 | |
| 340 | 258 | $values = self::fill_default_opts( $values, $record, $post_values ); |
| 341 | 259 | |
| 342 | 260 | return apply_filters( 'frm_setup_edit_form_vars', $values ); |
| 343 | - } | |
| 261 | + } | |
| 344 | 262 | |
| 345 | 263 | public static function fill_default_opts( $values, $record, $post_values ) { |
| 346 | 264 | |
| 347 | - $defaults = self::get_default_opts(); | |
| 265 | + $defaults = self::get_default_opts(); | |
| 348 | 266 | foreach ( $defaults as $var => $default ) { |
| 349 | 267 | if ( is_array( $default ) ) { |
| 350 | - if ( ! isset( $values[ $var ] ) ) { | |
| 268 | + if ( ! isset( $values[ $var ] ) ) { | |
| 351 | 269 | $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array(); |
| 352 | - } | |
| 270 | + } | |
| 353 | 271 | |
| 354 | - foreach ( $default as $k => $v ) { | |
| 272 | + foreach ( $default as $k => $v ) { | |
| 355 | 273 | $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 ); |
| 356 | 274 | |
| 357 | - if ( is_array( $v ) ) { | |
| 358 | - foreach ( $v as $k1 => $v1 ) { | |
| 275 | + if ( is_array( $v ) ) { | |
| 276 | + foreach ( $v as $k1 => $v1 ) { | |
| 359 | 277 | $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 ); |
| 360 | - unset( $k1, $v1 ); | |
| 361 | - } | |
| 362 | - } | |
| 278 | + unset( $k1, $v1 ); | |
| 279 | + } | |
| 280 | + } | |
| 363 | 281 | |
| 364 | 282 | unset( $k, $v ); |
| 365 | - } | |
| 366 | - } else { | |
| 283 | + } | |
| 284 | + } else { | |
| 367 | 285 | $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default ); |
| 368 | - } | |
| 286 | + } | |
| 369 | 287 | |
| 370 | 288 | unset( $var, $default ); |
| 371 | - } | |
| 289 | + } | |
| 372 | 290 | |
| 373 | - return $values; | |
| 374 | - } | |
| 291 | + return $values; | |
| 292 | + } | |
| 375 | 293 | |
| 376 | - /** | |
| 377 | - * @return array | |
| 378 | - */ | |
| 379 | 294 | public static function get_default_opts() { |
| 380 | 295 | $frm_settings = FrmAppHelper::get_settings(); |
| 381 | 296 | |
| 382 | 297 | return array( |
| 383 | - 'submit_value' => $frm_settings->submit_value, | |
| 384 | - 'success_action' => 'message', | |
| 385 | - 'success_msg' => $frm_settings->success_msg, | |
| 386 | - 'show_form' => 0, | |
| 387 | - 'akismet' => '', | |
| 388 | - 'honeypot' => 'basic', | |
| 389 | - 'antispam' => 0, | |
| 390 | - 'no_save' => 0, | |
| 391 | - 'ajax_load' => 0, | |
| 392 | - 'js_validate' => 0, | |
| 393 | - 'form_class' => '', | |
| 394 | - 'custom_style' => 1, | |
| 395 | - 'before_html' => self::get_default_html( 'before' ), | |
| 396 | - 'after_html' => '', | |
| 397 | - 'submit_html' => self::get_default_html( 'submit' ), | |
| 398 | - 'show_title' => 0, | |
| 399 | - 'show_description' => 0, | |
| 400 | - 'ajax_submit' => 0, | |
| 298 | + 'submit_value' => $frm_settings->submit_value, | |
| 299 | + 'success_action' => 'message', | |
| 300 | + 'success_msg' => $frm_settings->success_msg, | |
| 301 | + 'show_form' => 0, | |
| 302 | + 'akismet' => '', | |
| 303 | + 'no_save' => 0, | |
| 304 | + 'ajax_load' => 0, | |
| 305 | + 'js_validate' => 0, | |
| 306 | + 'form_class' => '', | |
| 307 | + 'custom_style' => 1, | |
| 308 | + 'before_html' => self::get_default_html( 'before' ), | |
| 309 | + 'after_html' => '', | |
| 310 | + 'submit_html' => self::get_default_html( 'submit' ), | |
| 401 | 311 | ); |
| 402 | 312 | } |
| 403 | 313 | |
| 404 | 314 | /** |
| @@ -403,9 +313,8 @@ | ||
| 403 | 313 | |
| 404 | 314 | /** |
| 405 | 315 | * @param array $options |
| 406 | 316 | * @param array $values |
| 407 | - * | |
| 408 | 317 | * @since 2.0.6 |
| 409 | 318 | */ |
| 410 | 319 | public static function fill_form_options( &$options, $values ) { |
| 411 | 320 | $defaults = self::get_default_opts(); |
| @@ -414,72 +323,51 @@ | ||
| 414 | 323 | unset( $var, $default ); |
| 415 | 324 | } |
| 416 | 325 | } |
| 417 | 326 | |
| 418 | - /** | |
| 419 | - * @param string $loc | |
| 420 | - */ | |
| 327 | + /** | |
| 328 | + * @param string $loc | |
| 329 | + */ | |
| 421 | 330 | public static function get_default_html( $loc ) { |
| 422 | 331 | if ( $loc == 'submit' ) { |
| 423 | - $draft_link = self::get_draft_link(); | |
| 424 | - $start_over = self::get_start_over_shortcode(); | |
| 425 | - $default_html = <<<SUBMIT_HTML | |
| 332 | + $draft_link = self::get_draft_link(); | |
| 333 | + $default_html = <<<SUBMIT_HTML | |
| 426 | 334 | <div class="frm_submit"> |
| 427 | 335 | [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] |
| 428 | 336 | <button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> |
| 429 | 337 | $draft_link |
| 430 | -$start_over | |
| 431 | 338 | </div> |
| 432 | 339 | SUBMIT_HTML; |
| 433 | - } elseif ( $loc == 'before' ) { | |
| 434 | - $default_html = <<<BEFORE_HTML | |
| 340 | + } else if ( $loc == 'before' ) { | |
| 341 | + $default_html = <<<BEFORE_HTML | |
| 435 | 342 | <legend class="frm_screen_reader">[form_name]</legend> |
| 436 | 343 | [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name] |
| 437 | 344 | [if form_description]<div class="frm_description">[form_description]</div>[/if form_description] |
| 438 | 345 | BEFORE_HTML; |
| 439 | 346 | } else { |
| 440 | - $default_html = ''; | |
| 441 | - } | |
| 347 | + $default_html = ''; | |
| 348 | + } | |
| 442 | 349 | |
| 443 | - return $default_html; | |
| 444 | - } | |
| 350 | + return $default_html; | |
| 351 | + } | |
| 445 | 352 | |
| 446 | - public static function get_draft_link() { | |
| 447 | - $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]'; | |
| 353 | + public static function get_draft_link() { | |
| 354 | + $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]'; | |
| 355 | + return $link; | |
| 356 | + } | |
| 448 | 357 | |
| 449 | - return $link; | |
| 450 | - } | |
| 451 | - | |
| 452 | - /** | |
| 453 | - * Gets start over button shortcode. | |
| 454 | - * | |
| 455 | - * @since 5.4 | |
| 456 | - * | |
| 457 | - * @return string | |
| 458 | - */ | |
| 459 | - public static function get_start_over_shortcode() { | |
| 460 | - return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]'; | |
| 461 | - } | |
| 462 | - | |
| 463 | 358 | public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) { |
| 464 | 359 | $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values ); |
| 465 | 360 | if ( ! strpos( $button, '[button_action]' ) ) { |
| 466 | - echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 361 | + echo $button; // WPCS: XSS ok. | |
| 467 | 362 | return; |
| 468 | 363 | } |
| 469 | 364 | |
| 470 | - /** | |
| 471 | - * @since 5.0.06 | |
| 472 | - */ | |
| 473 | - $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) ); | |
| 474 | - if ( FrmAppHelper::should_never_allow_unfiltered_html() ) { | |
| 475 | - $button = FrmAppHelper::kses_submit_button( $button ); | |
| 476 | - } | |
| 477 | 365 | $button_parts = explode( '[button_action]', $button ); |
| 478 | 366 | |
| 479 | 367 | $classes = apply_filters( 'frm_submit_button_class', array(), $form ); |
| 480 | 368 | if ( ! empty( $classes ) ) { |
| 481 | - $classes = implode( ' ', $classes ); | |
| 369 | + $classes = implode( ' ', $classes ); | |
| 482 | 370 | $button_class = ' class="frm_button_submit'; |
| 483 | 371 | if ( strpos( $button_parts[0], $button_class ) !== false ) { |
| 484 | 372 | $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] ); |
| 485 | 373 | } else { |
| @@ -486,243 +374,70 @@ | ||
| 486 | 374 | $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"'; |
| 487 | 375 | } |
| 488 | 376 | } |
| 489 | 377 | |
| 490 | - echo $button_parts[0]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 378 | + echo $button_parts[0]; // WPCS: XSS ok. | |
| 491 | 379 | do_action( 'frm_submit_button_action', $form, $form_action ); |
| 492 | - echo $button_parts[1]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 380 | + echo $button_parts[1]; // WPCS: XSS ok. | |
| 493 | 381 | } |
| 494 | 382 | |
| 495 | - /** | |
| 496 | - * @since 4.0 | |
| 497 | - */ | |
| 498 | - public static function html_shortcodes() { | |
| 499 | - $codes = array( | |
| 500 | - 'id' => array( | |
| 501 | - 'label' => __( 'Field ID', 'formidable' ), | |
| 502 | - 'class' => 'show_field_custom_html', | |
| 503 | - ), | |
| 504 | - 'key' => array( | |
| 505 | - 'label' => __( 'Field Key', 'formidable' ), | |
| 506 | - 'class' => 'show_field_custom_html', | |
| 507 | - ), | |
| 508 | - 'field_name' => array( | |
| 509 | - 'label' => __( 'Field Name', 'formidable' ), | |
| 510 | - 'class' => 'show_field_custom_html', | |
| 511 | - ), | |
| 512 | - 'description' => array( | |
| 513 | - 'label' => __( 'Field Description', 'formidable' ), | |
| 514 | - 'class' => 'show_field_custom_html', | |
| 515 | - ), | |
| 516 | - 'label_position' => array( | |
| 517 | - 'label' => __( 'Label Position', 'formidable' ), | |
| 518 | - 'class' => 'show_field_custom_html', | |
| 519 | - ), | |
| 520 | - 'required_label' => array( | |
| 521 | - 'label' => __( 'Required Label', 'formidable' ), | |
| 522 | - 'class' => 'show_field_custom_html', | |
| 523 | - ), | |
| 524 | - 'input' => array( | |
| 525 | - 'label' => __( 'Input Field', 'formidable' ), | |
| 526 | - 'class' => 'show_field_custom_html', | |
| 527 | - ), | |
| 528 | - 'input opt=1' => array( | |
| 529 | - 'label' => __( 'Single Option', 'formidable' ), | |
| 530 | - 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ), | |
| 531 | - 'class' => 'show_field_custom_html', | |
| 532 | - ), | |
| 533 | - 'input label=0' => array( | |
| 534 | - 'label' => __( 'Hide Option Label', 'formidable' ), | |
| 535 | - 'class' => 'show_field_custom_html', | |
| 536 | - ), | |
| 537 | - 'required_class' => array( | |
| 538 | - 'label' => __( 'Required Class', 'formidable' ), | |
| 539 | - 'title' => __( 'Add class name if field is required', 'formidable' ), | |
| 540 | - 'class' => 'show_field_custom_html', | |
| 541 | - ), | |
| 542 | - 'error_class' => array( | |
| 543 | - 'label' => __( 'Error Class', 'formidable' ), | |
| 544 | - 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ), | |
| 545 | - 'class' => 'show_field_custom_html', | |
| 546 | - ), | |
| 547 | - | |
| 548 | - 'form_name' => array( | |
| 549 | - 'label' => __( 'Form Name', 'formidable' ), | |
| 550 | - 'class' => 'show_before_html show_after_html', | |
| 551 | - ), | |
| 552 | - 'form_description' => array( | |
| 553 | - 'label' => __( 'Form Description', 'formidable' ), | |
| 554 | - 'class' => 'show_before_html show_after_html', | |
| 555 | - ), | |
| 556 | - 'form_key' => array( | |
| 557 | - 'label' => __( 'Form Key', 'formidable' ), | |
| 558 | - 'class' => 'show_before_html show_after_html', | |
| 559 | - ), | |
| 560 | - 'deletelink' => array( | |
| 561 | - 'label' => __( 'Delete Entry Link', 'formidable' ), | |
| 562 | - 'class' => 'show_before_html show_after_html', | |
| 563 | - ), | |
| 564 | - | |
| 565 | - 'button_label' => array( | |
| 566 | - 'label' => __( 'Button Label', 'formidable' ), | |
| 567 | - 'class' => 'show_submit_html', | |
| 568 | - ), | |
| 569 | - 'button_action' => array( | |
| 570 | - 'label' => __( 'Button Hook', 'formidable' ), | |
| 571 | - 'class' => 'show_submit_html', | |
| 572 | - ), | |
| 573 | - ); | |
| 574 | - | |
| 575 | - /** | |
| 576 | - * @since 4.0 | |
| 577 | - */ | |
| 578 | - return apply_filters( 'frm_html_codes', $codes ); | |
| 579 | - } | |
| 580 | - | |
| 581 | - /** | |
| 582 | - * @since 4.0 | |
| 583 | - * @param array $args | |
| 584 | - */ | |
| 585 | - public static function insert_opt_html( $args ) { | |
| 586 | - $class = isset( $args['class'] ) ? $args['class'] : ''; | |
| 587 | - $fields = FrmField::all_field_selection(); | |
| 588 | - $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array(); | |
| 589 | - | |
| 590 | - self::prepare_field_type( $field ); | |
| 591 | - | |
| 592 | - if ( ! isset( $field['icon'] ) ) { | |
| 593 | - $field['icon'] = 'frmfont frm_pencil_icon'; | |
| 594 | - } | |
| 595 | - | |
| 596 | - $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' ); | |
| 597 | - if ( $possible_email_field ) { | |
| 598 | - $class .= ' show_frm_not_email_to'; | |
| 599 | - } | |
| 600 | - | |
| 601 | - if ( 'url' === $args['type'] ) { | |
| 602 | - $class .= ' frm_insert_url'; | |
| 603 | - } | |
| 604 | - ?> | |
| 605 | - <li class="<?php echo esc_attr( $class ); ?>"> | |
| 606 | - <a href="javascript:void(0)" class="frmids frm_insert_code" | |
| 607 | - data-code="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 608 | - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 609 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 610 | - <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span> | |
| 611 | - </a> | |
| 612 | - <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" | |
| 613 | - data-code="<?php echo esc_attr( $args['key'] ); ?>"> | |
| 614 | - <?php if ( isset( $field['icon'] ) ) { ?> | |
| 615 | - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 616 | - <?php } ?> | |
| 617 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 618 | - <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span> | |
| 619 | - </a> | |
| 620 | - </li> | |
| 621 | - <?php | |
| 622 | - } | |
| 623 | - | |
| 624 | - /** | |
| 625 | - * @since 4.0 | |
| 626 | - * @param array $args | |
| 627 | - */ | |
| 628 | - public static function insert_code_html( $args ) { | |
| 629 | - $defaults = array( | |
| 630 | - 'class' => '', | |
| 631 | - 'code' => '', | |
| 632 | - 'label' => '', | |
| 633 | - 'title' => '', | |
| 634 | - ); | |
| 635 | - | |
| 636 | - $args = array_merge( $defaults, $args ); | |
| 637 | - $has_tooltip = ! empty( $args['title'] ); | |
| 638 | - | |
| 639 | - ?> | |
| 640 | - <li class="<?php echo esc_attr( $args['class'] ); ?>"> | |
| 641 | - <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>" | |
| 642 | - <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?> | |
| 643 | - data-code="<?php echo esc_attr( $args['code'] ); ?>"> | |
| 644 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 645 | - <span> | |
| 646 | - [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 647 | - </span> | |
| 648 | - </a> | |
| 649 | - </li> | |
| 650 | - <?php | |
| 651 | - } | |
| 652 | - | |
| 653 | - /** | |
| 654 | - * Some field types in add-ons may have been added with only | |
| 655 | - * a field type and name. | |
| 383 | + /** | |
| 384 | + * Automatically add end section fields if they don't exist (2.0 migration) | |
| 656 | 385 | * |
| 657 | - * @since 4.0 | |
| 658 | - */ | |
| 659 | - public static function prepare_field_type( &$field ) { | |
| 660 | - if ( ! is_array( $field ) ) { | |
| 661 | - $field = array( | |
| 662 | - 'name' => $field, | |
| 663 | - 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 664 | - ); | |
| 665 | - } | |
| 666 | - } | |
| 667 | - | |
| 668 | - /** | |
| 669 | - * Automatically add end section fields if they don't exist (2.0 migration) | |
| 670 | - * | |
| 671 | - * @since 2.0 | |
| 672 | - * | |
| 673 | - * @param boolean $reset_fields | |
| 674 | - */ | |
| 675 | - public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { | |
| 386 | + * @since 2.0 | |
| 387 | + * | |
| 388 | + * @param boolean $reset_fields | |
| 389 | + */ | |
| 390 | + public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { | |
| 676 | 391 | if ( empty( $fields ) ) { |
| 677 | 392 | return; |
| 678 | 393 | } |
| 679 | 394 | |
| 680 | 395 | $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) ); |
| 681 | - $open = false; | |
| 682 | - $prev_order = false; | |
| 683 | - $add_order = 0; | |
| 684 | - $last_field = false; | |
| 685 | - foreach ( $fields as $field ) { | |
| 396 | + $open = false; | |
| 397 | + $prev_order = false; | |
| 398 | + $add_order = 0; | |
| 399 | + $last_field = false; | |
| 400 | + foreach ( $fields as $field ) { | |
| 686 | 401 | if ( $prev_order === $field->field_order ) { |
| 687 | - $add_order ++; | |
| 402 | + $add_order++; | |
| 688 | 403 | } |
| 689 | 404 | |
| 690 | 405 | if ( $add_order ) { |
| 691 | - $reset_fields = true; | |
| 406 | + $reset_fields = true; | |
| 692 | 407 | $field->field_order = $field->field_order + $add_order; |
| 693 | 408 | FrmField::update( $field->id, array( 'field_order' => $field->field_order ) ); |
| 694 | 409 | } |
| 695 | 410 | |
| 696 | - switch ( $field->type ) { | |
| 697 | - case 'divider': | |
| 698 | - // Create an end section if open. | |
| 411 | + switch ( $field->type ) { | |
| 412 | + case 'divider': | |
| 413 | + // create an end section if open | |
| 699 | 414 | self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' ); |
| 700 | 415 | |
| 701 | - // Mark it open for the next end section. | |
| 702 | - $open = true; | |
| 416 | + // mark it open for the next end section | |
| 417 | + $open = true; | |
| 703 | 418 | break; |
| 704 | - case 'break': | |
| 419 | + case 'break': | |
| 705 | 420 | self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' ); |
| 706 | 421 | break; |
| 707 | - case 'end_divider': | |
| 708 | - if ( ! $open ) { | |
| 709 | - // The section isn't open, so this is an extra field that needs to be removed. | |
| 710 | - FrmField::destroy( $field->id ); | |
| 711 | - $reset_fields = true; | |
| 712 | - } | |
| 422 | + case 'end_divider': | |
| 423 | + if ( ! $open ) { | |
| 424 | + // the section isn't open, so this is an extra field that needs to be removed | |
| 425 | + FrmField::destroy( $field->id ); | |
| 426 | + $reset_fields = true; | |
| 427 | + } | |
| 713 | 428 | |
| 714 | - // There is already an end section here, so there is no need to create one. | |
| 715 | - $open = false; | |
| 716 | - } | |
| 429 | + // There is already an end section here, so there is no need to create one | |
| 430 | + $open = false; | |
| 431 | + } | |
| 717 | 432 | $prev_order = $field->field_order; |
| 718 | 433 | |
| 719 | 434 | $last_field = $field; |
| 720 | 435 | unset( $field ); |
| 721 | - } | |
| 436 | + } | |
| 722 | 437 | |
| 723 | 438 | self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field ); |
| 724 | - } | |
| 439 | + } | |
| 725 | 440 | |
| 726 | 441 | /** |
| 727 | 442 | * Create end section field if it doesn't exist. This is for migration from < 2.0 |
| 728 | 443 | * Fix any ordering that may be messed up |
| @@ -727,15 +442,15 @@ | ||
| 727 | 442 | * Create end section field if it doesn't exist. This is for migration from < 2.0 |
| 728 | 443 | * Fix any ordering that may be messed up |
| 729 | 444 | */ |
| 730 | 445 | public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) { |
| 731 | - if ( ! $open ) { | |
| 732 | - return; | |
| 733 | - } | |
| 446 | + if ( ! $open ) { | |
| 447 | + return; | |
| 448 | + } | |
| 734 | 449 | |
| 735 | 450 | $end_section_values['field_order'] = $field->field_order + 1; |
| 736 | 451 | |
| 737 | - FrmField::create( $end_section_values ); | |
| 452 | + FrmField::create( $end_section_values ); | |
| 738 | 453 | |
| 739 | 454 | if ( $move == 'move' ) { |
| 740 | 455 | // bump the order of current field unless we're at the end of the form |
| 741 | 456 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| @@ -740,25 +455,25 @@ | ||
| 740 | 455 | // bump the order of current field unless we're at the end of the form |
| 741 | 456 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 742 | 457 | } |
| 743 | 458 | |
| 744 | - $add_order += 2; | |
| 745 | - $open = false; | |
| 746 | - $reset_fields = true; | |
| 747 | - } | |
| 459 | + $add_order += 2; | |
| 460 | + $open = false; | |
| 461 | + $reset_fields = true; | |
| 462 | + } | |
| 748 | 463 | |
| 749 | 464 | public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) { |
| 750 | 465 | $codes = array( |
| 751 | - 'form_name' => $title, | |
| 466 | + 'form_name' => $title, | |
| 752 | 467 | 'form_description' => $description, |
| 753 | - 'entry_key' => true, | |
| 468 | + 'entry_key' => true, | |
| 754 | 469 | ); |
| 755 | 470 | foreach ( $codes as $code => $show ) { |
| 756 | - if ( $code === 'form_name' ) { | |
| 471 | + if ( $code == 'form_name' ) { | |
| 757 | 472 | $replace_with = $form->name; |
| 758 | - } elseif ( $code === 'form_description' ) { | |
| 473 | + } elseif ( $code == 'form_description' ) { | |
| 759 | 474 | $replace_with = FrmAppHelper::use_wpautop( $form->description ); |
| 760 | - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 475 | + } elseif ( $code == 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 761 | 476 | $replace_with = FrmAppHelper::simple_get( 'entry' ); |
| 762 | 477 | } else { |
| 763 | 478 | $replace_with = ''; |
| 764 | 479 | } |
| @@ -763,9 +478,9 @@ | ||
| 763 | 478 | $replace_with = ''; |
| 764 | 479 | } |
| 765 | 480 | |
| 766 | 481 | FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); |
| 767 | - } | |
| 482 | + } | |
| 768 | 483 | |
| 769 | 484 | //replace [form_key] |
| 770 | 485 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| 771 | 486 | |
| @@ -775,10 +490,10 @@ | ||
| 775 | 490 | if ( strpos( $html, '[button_label]' ) ) { |
| 776 | 491 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| 777 | 492 | $submit_label = apply_filters( 'frm_submit_button', $title, $form ); |
| 778 | 493 | $submit_label = esc_attr( do_shortcode( $submit_label ) ); |
| 779 | - $html = str_replace( '[button_label]', $submit_label, $html ); | |
| 780 | - } | |
| 494 | + $html = str_replace( '[button_label]', $submit_label, $html ); | |
| 495 | + } | |
| 781 | 496 | |
| 782 | 497 | $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values ); |
| 783 | 498 | |
| 784 | 499 | if ( strpos( $html, '[if back_button]' ) ) { |
| @@ -788,27 +503,23 @@ | ||
| 788 | 503 | if ( strpos( $html, '[if save_draft]' ) ) { |
| 789 | 504 | $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html ); |
| 790 | 505 | } |
| 791 | 506 | |
| 792 | - if ( strpos( $html, '[if start_over]' ) ) { | |
| 793 | - $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html ); | |
| 794 | - } | |
| 795 | - | |
| 796 | 507 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 797 | 508 | $html = do_shortcode( $html ); |
| 798 | 509 | } |
| 799 | 510 | |
| 800 | - return $html; | |
| 801 | - } | |
| 511 | + return $html; | |
| 512 | + } | |
| 802 | 513 | |
| 803 | 514 | public static function submit_button_label( $submit ) { |
| 804 | - if ( ! $submit ) { | |
| 805 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 806 | - $submit = $frm_settings->submit_value; | |
| 807 | - } | |
| 515 | + if ( ! $submit || empty( $submit ) ) { | |
| 516 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 517 | + $submit = $frm_settings->submit_value; | |
| 518 | + } | |
| 808 | 519 | |
| 809 | - return $submit; | |
| 810 | - } | |
| 520 | + return $submit; | |
| 521 | + } | |
| 811 | 522 | |
| 812 | 523 | /** |
| 813 | 524 | * If the Formidable styling isn't being loaded, |
| 814 | 525 | * use inline styling to hide the element |
| @@ -835,20 +546,14 @@ | ||
| 835 | 546 | return; |
| 836 | 547 | } |
| 837 | 548 | } |
| 838 | 549 | |
| 839 | - // If submit button needs to be inline or centered. | |
| 550 | + //If submit button needs to be inline or centered | |
| 840 | 551 | if ( is_object( $form ) ) { |
| 841 | 552 | $form = $form->options; |
| 842 | 553 | } |
| 843 | 554 | |
| 844 | - if ( ! empty( $form['submit_align'] ) ) { | |
| 845 | - $submit_align = $form['submit_align']; | |
| 846 | - } elseif ( self::form_should_be_inline_and_missing_class( $form ) ) { | |
| 847 | - $submit_align = 'inline'; | |
| 848 | - } else { | |
| 849 | - $submit_align = ''; | |
| 850 | - } | |
| 555 | + $submit_align = isset( $form['submit_align'] ) ? $form['submit_align'] : ''; | |
| 851 | 556 | |
| 852 | 557 | if ( 'inline' === $submit_align ) { |
| 853 | 558 | $class .= ' frm_inline_form'; |
| 854 | 559 | $class .= self::maybe_align_fields_top( $form ); |
| @@ -855,30 +560,14 @@ | ||
| 855 | 560 | } elseif ( 'center' === $submit_align ) { |
| 856 | 561 | $class .= ' frm_center_submit'; |
| 857 | 562 | } |
| 858 | 563 | |
| 859 | - $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 564 | + $class = apply_filters( 'frm_add_form_style_class', $class, $style ); | |
| 860 | 565 | |
| 861 | - return $class; | |
| 862 | - } | |
| 566 | + return $class; | |
| 567 | + } | |
| 863 | 568 | |
| 864 | 569 | /** |
| 865 | - * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work. | |
| 866 | - * | |
| 867 | - * @since 5.0.12 | |
| 868 | - * | |
| 869 | - * @param array $form | |
| 870 | - * @return bool | |
| 871 | - */ | |
| 872 | - private static function form_should_be_inline_and_missing_class( $form ) { | |
| 873 | - if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 874 | - // not missing class, avoid adding it twice. | |
| 875 | - return false; | |
| 876 | - } | |
| 877 | - return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' ); | |
| 878 | - } | |
| 879 | - | |
| 880 | - /** | |
| 881 | 570 | * Returns appropriate class if form has top labels |
| 882 | 571 | * |
| 883 | 572 | * @param $form |
| 884 | 573 | * |
| @@ -906,9 +595,9 @@ | ||
| 906 | 595 | } |
| 907 | 596 | |
| 908 | 597 | $fields = array_reverse( $fields ); // start from the fields closest to the submit button |
| 909 | 598 | foreach ( $fields as $field ) { |
| 910 | - $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; | |
| 599 | + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; | |
| 911 | 600 | $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' ); |
| 912 | 601 | if ( $has_input ) { |
| 913 | 602 | return self::field_has_top_label( $field, $form ); |
| 914 | 603 | } |
| @@ -926,27 +615,26 @@ | ||
| 926 | 615 | * @return bool |
| 927 | 616 | */ |
| 928 | 617 | private static function field_has_top_label( $field, $form ) { |
| 929 | 618 | $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form ); |
| 930 | - | |
| 931 | 619 | return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); |
| 932 | 620 | } |
| 933 | 621 | |
| 934 | - /** | |
| 935 | - * @param object|string|boolean $form | |
| 936 | - * | |
| 937 | - * @return string | |
| 938 | - */ | |
| 939 | - public static function get_form_style( $form ) { | |
| 622 | + /** | |
| 623 | + * @param string|boolean $form | |
| 624 | + * | |
| 625 | + * @return string | |
| 626 | + */ | |
| 627 | + public static function get_form_style( $form ) { | |
| 940 | 628 | $style = 1; |
| 941 | - if ( empty( $form ) || 'default' === $form ) { | |
| 629 | + if ( empty( $form ) || 'default' == 'form' ) { | |
| 942 | 630 | return $style; |
| 943 | - } elseif ( is_object( $form ) && $form->parent_form_id ) { | |
| 631 | + } else if ( is_object( $form ) && $form->parent_form_id ) { | |
| 944 | 632 | // get the parent form if this is a child |
| 945 | 633 | $form = $form->parent_form_id; |
| 946 | - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) { | |
| 634 | + } else if ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) { | |
| 947 | 635 | $form = $form['parent_form_id']; |
| 948 | - } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { | |
| 636 | + } else if ( is_array( $form ) && isset( $form['custom_style'] ) ) { | |
| 949 | 637 | $style = $form['custom_style']; |
| 950 | 638 | } |
| 951 | 639 | |
| 952 | 640 | if ( $form && is_string( $form ) ) { |
| @@ -955,15 +643,14 @@ | ||
| 955 | 643 | |
| 956 | 644 | $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style; |
| 957 | 645 | |
| 958 | 646 | return $style; |
| 959 | - } | |
| 647 | + } | |
| 960 | 648 | |
| 961 | 649 | /** |
| 962 | 650 | * Display the validation error messages when an entry is submitted |
| 963 | 651 | * |
| 964 | 652 | * @param array $args - includes img, errors |
| 965 | - * | |
| 966 | 653 | * @since 2.0.6 |
| 967 | 654 | */ |
| 968 | 655 | public static function show_errors( $args ) { |
| 969 | 656 | $invalid_msg = self::get_invalid_error_message( $args ); |
| @@ -989,9 +676,8 @@ | ||
| 989 | 676 | * The image was removed from the styling settings, but it may still be set with a hook |
| 990 | 677 | * If the message in the global settings is empty, show every validation message in the error box |
| 991 | 678 | * |
| 992 | 679 | * @param array $args - includes img, errors, and show_img |
| 993 | - * | |
| 994 | 680 | * @since 2.0.6 |
| 995 | 681 | */ |
| 996 | 682 | public static function show_error( $args ) { |
| 997 | 683 | // remove any blank messages |
| @@ -1019,16 +705,16 @@ | ||
| 1019 | 705 | } |
| 1020 | 706 | |
| 1021 | 707 | public static function maybe_get_scroll_js( $id ) { |
| 1022 | 708 | $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) ); |
| 1023 | - if ( $offset != - 1 ) { | |
| 709 | + if ( $offset != -1 ) { | |
| 1024 | 710 | self::get_scroll_js( $id ); |
| 1025 | 711 | } |
| 1026 | 712 | } |
| 1027 | 713 | |
| 1028 | 714 | public static function get_scroll_js( $form_id ) { |
| 1029 | - echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; | |
| 1030 | - } | |
| 715 | + echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; | |
| 716 | + } | |
| 1031 | 717 | |
| 1032 | 718 | /** |
| 1033 | 719 | * @since 3.0 |
| 1034 | 720 | */ |
| @@ -1033,12 +719,12 @@ | ||
| 1033 | 719 | * @since 3.0 |
| 1034 | 720 | */ |
| 1035 | 721 | public static function actions_dropdown( $atts ) { |
| 1036 | 722 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| 1037 | - $status = $atts['status']; | |
| 1038 | - $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 723 | + $status = $atts['status']; | |
| 724 | + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1039 | 725 | $trash_link = self::delete_trash_info( $form_id, $status ); |
| 1040 | - $links = self::get_action_links( $form_id, $status ); | |
| 726 | + $links = self::get_action_links( $form_id, $status ); | |
| 1041 | 727 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' ); |
| 1042 | 728 | } |
| 1043 | 729 | } |
| 1044 | 730 | |
| @@ -1049,9 +735,9 @@ | ||
| 1049 | 735 | if ( ! is_object( $form ) ) { |
| 1050 | 736 | $form = FrmForm::getOne( $form_id ); |
| 1051 | 737 | } |
| 1052 | 738 | |
| 1053 | - $actions = array(); | |
| 739 | + $actions = array(); | |
| 1054 | 740 | $trash_links = self::delete_trash_links( $form_id ); |
| 1055 | 741 | if ( 'trash' == $form->status ) { |
| 1056 | 742 | $actions['restore'] = $trash_links['restore']; |
| 1057 | 743 | |
| @@ -1063,15 +749,15 @@ | ||
| 1063 | 749 | if ( $form->is_template ) { |
| 1064 | 750 | $actions['frm_duplicate'] = array( |
| 1065 | 751 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1066 | 752 | 'label' => __( 'Create Form from Template', 'formidable' ), |
| 1067 | - 'icon' => 'frm_icon_font frm_clone_icon', | |
| 753 | + 'icon' => 'frm_icon_font frm_duplicate_icon', | |
| 1068 | 754 | ); |
| 1069 | 755 | } else { |
| 1070 | 756 | $actions['duplicate'] = array( |
| 1071 | 757 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1072 | 758 | 'label' => __( 'Duplicate Form', 'formidable' ), |
| 1073 | - 'icon' => 'frm_icon_font frm_clone_icon', | |
| 759 | + 'icon' => 'frm_icon_font frm_duplicate_icon', | |
| 1074 | 760 | ); |
| 1075 | 761 | } |
| 1076 | 762 | |
| 1077 | 763 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| @@ -1079,55 +765,26 @@ | ||
| 1079 | 765 | |
| 1080 | 766 | return $actions; |
| 1081 | 767 | } |
| 1082 | 768 | |
| 1083 | - public static function edit_form_link( $data ) { | |
| 1084 | - $form_id = self::get_form_id_from_data( $data ); | |
| 769 | + public static function edit_form_link( $form_id ) { | |
| 770 | + if ( is_object( $form_id ) ) { | |
| 771 | + $form = $form_id; | |
| 772 | + $name = $form->name; | |
| 773 | + $form_id = $form->id; | |
| 774 | + } else { | |
| 775 | + $name = FrmForm::getName( $form_id ); | |
| 776 | + } | |
| 1085 | 777 | |
| 1086 | - if ( ! $form_id ) { | |
| 1087 | - return ''; | |
| 1088 | - } | |
| 778 | + if ( $form_id ) { | |
| 779 | + $val = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ) ) . '">' . ( '' == $name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $name, 40 ) ) . '</a>'; | |
| 780 | + } else { | |
| 781 | + $val = ''; | |
| 782 | + } | |
| 1089 | 783 | |
| 1090 | - $label = self::edit_form_link_label( $data ); | |
| 1091 | - $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1092 | - return $link; | |
| 784 | + return $val; | |
| 1093 | 785 | } |
| 1094 | 786 | |
| 1095 | - public static function edit_form_link_label( $data ) { | |
| 1096 | - $name = self::get_form_name_from_data( $data ); | |
| 1097 | - if ( ! $name ) { | |
| 1098 | - return __( '(no title)', 'formidable' ); | |
| 1099 | - } | |
| 1100 | - return FrmAppHelper::truncate( $name, 40 ); | |
| 1101 | - } | |
| 1102 | - | |
| 1103 | - /** | |
| 1104 | - * @param mixed data | |
| 1105 | - * @return int | |
| 1106 | - */ | |
| 1107 | - private static function get_form_id_from_data( $data ) { | |
| 1108 | - if ( is_object( $data ) ) { | |
| 1109 | - $form_id = $data->id; | |
| 1110 | - } else { | |
| 1111 | - $form_id = $data; | |
| 1112 | - } | |
| 1113 | - return $form_id; | |
| 1114 | - } | |
| 1115 | - | |
| 1116 | - /** | |
| 1117 | - * @param mixed $data | |
| 1118 | - * @return string | |
| 1119 | - */ | |
| 1120 | - private static function get_form_name_from_data( $data ) { | |
| 1121 | - if ( is_object( $data ) ) { | |
| 1122 | - $form_name = $data->name; | |
| 1123 | - } else { | |
| 1124 | - $form_id = $data; | |
| 1125 | - $form_name = FrmForm::getName( $form_id ); | |
| 1126 | - } | |
| 1127 | - return $form_name; | |
| 1128 | - } | |
| 1129 | - | |
| 1130 | 787 | public static function delete_trash_link( $id, $status, $length = 'label' ) { |
| 1131 | 788 | $link_details = self::delete_trash_info( $id, $status ); |
| 1132 | 789 | |
| 1133 | 790 | return self::format_link_html( $link_details, $length ); |
| @@ -1138,9 +795,9 @@ | ||
| 1138 | 795 | */ |
| 1139 | 796 | public static function format_link_html( $link_details, $length = 'label' ) { |
| 1140 | 797 | $link = ''; |
| 1141 | 798 | if ( ! empty( $link_details ) ) { |
| 1142 | - $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 799 | + $link = '<a href="' . esc_url( $link_details['url'] ) . '"'; | |
| 1143 | 800 | if ( isset( $link_details['data'] ) ) { |
| 1144 | 801 | foreach ( $link_details['data'] as $data => $value ) { |
| 1145 | 802 | $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; |
| 1146 | 803 | } |
| @@ -1146,18 +803,11 @@ | ||
| 1146 | 803 | } |
| 1147 | 804 | } elseif ( isset( $link_details['confirm'] ) ) { |
| 1148 | 805 | $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; |
| 1149 | 806 | } |
| 1150 | - | |
| 1151 | 807 | $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] ); |
| 1152 | - if ( $length == 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1153 | - $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1154 | - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1155 | - } | |
| 1156 | - | |
| 1157 | 808 | $link .= '>' . $label . '</a>'; |
| 1158 | 809 | } |
| 1159 | - | |
| 1160 | 810 | return $link; |
| 1161 | 811 | } |
| 1162 | 812 | |
| 1163 | 813 | /** |
| @@ -1185,9 +835,9 @@ | ||
| 1185 | 835 | * @since 3.0 |
| 1186 | 836 | */ |
| 1187 | 837 | private static function delete_trash_links( $id ) { |
| 1188 | 838 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1189 | - $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; | |
| 839 | + $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; | |
| 1190 | 840 | |
| 1191 | 841 | return array( |
| 1192 | 842 | 'restore' => array( |
| 1193 | 843 | 'label' => __( 'Restore from Trash', 'formidable' ), |
| @@ -1193,28 +843,22 @@ | ||
| 1193 | 843 | 'label' => __( 'Restore from Trash', 'formidable' ), |
| 1194 | 844 | 'short' => __( 'Restore', 'formidable' ), |
| 1195 | 845 | 'url' => wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . absint( $id ) ), |
| 1196 | 846 | ), |
| 1197 | - 'trash' => array( | |
| 847 | + 'trash' => array( | |
| 1198 | 848 | 'label' => __( 'Move Form to Trash', 'formidable' ), |
| 1199 | 849 | 'short' => __( 'Trash', 'formidable' ), |
| 1200 | 850 | 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ), |
| 1201 | 851 | 'icon' => 'frm_icon_font frm_delete_icon', |
| 1202 | - 'data' => array( | |
| 1203 | - 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ), | |
| 1204 | - 'frmverify-btn' => 'frm-button-red', | |
| 1205 | - ), | |
| 852 | + 'data' => array( 'frmverify' => __( 'Are you sure?', 'formidable' ) ), | |
| 1206 | 853 | ), |
| 1207 | - 'delete' => array( | |
| 1208 | - 'label' => __( 'Delete Permanently', 'formidable' ), | |
| 1209 | - 'short' => __( 'Delete', 'formidable' ), | |
| 1210 | - 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), | |
| 854 | + 'delete' => array( | |
| 855 | + 'label' => __( 'Delete Permanently', 'formidable' ), | |
| 856 | + 'short' => __( 'Delete', 'formidable' ), | |
| 857 | + 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), | |
| 1211 | 858 | 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ), |
| 1212 | - 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1213 | - 'data' => array( | |
| 1214 | - 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ), | |
| 1215 | - 'frmverify-btn' => 'frm-button-red', | |
| 1216 | - ), | |
| 859 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 860 | + 'data' => array( 'frmverify' => __( 'Delete form & entries?', 'formidable' ) ), | |
| 1217 | 861 | ), |
| 1218 | 862 | ); |
| 1219 | 863 | } |
| 1220 | 864 | |
| @@ -1222,35 +866,39 @@ | ||
| 1222 | 866 | * @since 3.0 |
| 1223 | 867 | */ |
| 1224 | 868 | public static function css_classes() { |
| 1225 | 869 | $classes = array( |
| 1226 | - 'frm_total' => array( | |
| 1227 | - 'label' => __( 'Total', 'formidable' ), | |
| 1228 | - 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ), | |
| 1229 | - ), | |
| 1230 | - 'frm_total_big' => array( | |
| 1231 | - 'label' => __( 'Big Total', 'formidable' ), | |
| 1232 | - 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), | |
| 1233 | - ), | |
| 1234 | - 'frm_scroll_box' => array( | |
| 1235 | - 'label' => __( 'Scroll Box', 'formidable' ), | |
| 1236 | - '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' ), | |
| 1237 | - ), | |
| 1238 | 870 | 'frm_first' => array( |
| 1239 | - 'label' => __( 'First', 'formidable' ), | |
| 1240 | - 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), | |
| 871 | + 'label' => __( 'First', 'formidable' ), | |
| 872 | + 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), | |
| 1241 | 873 | ), |
| 1242 | 874 | 'frm_alignright' => __( 'Right', 'formidable' ), |
| 875 | + 'frm_total' => array( | |
| 876 | + 'label' => __( 'Total', 'formidable' ), | |
| 877 | + 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ), | |
| 878 | + ), | |
| 1243 | 879 | 'frm_grid_first' => __( 'First Grid Row', 'formidable' ), |
| 1244 | 880 | 'frm_grid' => __( 'Even Grid Row', 'formidable' ), |
| 1245 | 881 | 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ), |
| 1246 | - 'frm_color_block' => array( | |
| 1247 | - 'label' => __( 'Color Block', 'formidable' ), | |
| 1248 | - 'title' => __( 'Add a background color to the field or section.', 'formidable' ), | |
| 882 | + 'frm_two_col' => array( | |
| 883 | + 'label' => __( '2 Col Options', 'formidable' ), | |
| 884 | + 'title' => __( 'Put your radio button or checkbox options into two columns.', 'formidable' ), | |
| 1249 | 885 | ), |
| 886 | + 'frm_three_col' => array( | |
| 887 | + 'label' => __( '3 Col Options', 'formidable' ), | |
| 888 | + 'title' => __( 'Put your radio button or checkbox options into three columns.', 'formidable' ), | |
| 889 | + ), | |
| 890 | + 'frm_four_col' => array( | |
| 891 | + 'label' => __( '4 Col Options', 'formidable' ), | |
| 892 | + 'title' => __( 'Put your radio button or checkbox options into four columns.', 'formidable' ), | |
| 893 | + ), | |
| 894 | + 'frm_scroll_box' => array( | |
| 895 | + 'label' => __( 'Scroll Box', 'formidable' ), | |
| 896 | + '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' ), | |
| 897 | + ), | |
| 1250 | 898 | 'frm_capitalize' => array( |
| 1251 | - 'label' => __( 'Capitalize', 'formidable' ), | |
| 1252 | - 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ), | |
| 899 | + 'label' => __( 'Capitalize', 'formidable' ), | |
| 900 | + 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ), | |
| 1253 | 901 | ), |
| 1254 | 902 | ); |
| 1255 | 903 | |
| 1256 | 904 | return apply_filters( 'frm_layout_classes', $classes ); |
| @@ -1256,18 +904,47 @@ | ||
| 1256 | 904 | return apply_filters( 'frm_layout_classes', $classes ); |
| 1257 | 905 | } |
| 1258 | 906 | |
| 1259 | 907 | public static function grid_classes() { |
| 1260 | - return array( | |
| 908 | + $base = array( | |
| 1261 | 909 | 'frm_half' => '1/2', |
| 910 | + | |
| 1262 | 911 | 'frm_third' => '1/3', |
| 1263 | 912 | 'frm_two_thirds' => '2/3', |
| 913 | + | |
| 1264 | 914 | 'frm_fourth' => '1/4', |
| 1265 | 915 | 'frm_three_fourths' => '3/4', |
| 1266 | - 'frm_sixth' => '1/6', | |
| 1267 | - 'frm10' => '5/6', | |
| 1268 | - 'frm12' => '100%', | |
| 1269 | 916 | ); |
| 917 | + | |
| 918 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 919 | + if ( $frm_settings->old_css ) { | |
| 920 | + $classes = array( | |
| 921 | + 'frm_fifth' => '1/5', | |
| 922 | + 'frm_four_fifths' => '4/5', | |
| 923 | + | |
| 924 | + 'frm_two_fifths' => '2/5', | |
| 925 | + 'frm_three_fifths' => '3/5', | |
| 926 | + | |
| 927 | + 'frm_sixth' => '1/6', | |
| 928 | + | |
| 929 | + 'frm_full' => '100%', | |
| 930 | + ); | |
| 931 | + } else { | |
| 932 | + $classes = array( | |
| 933 | + 'frm_sixth' => '1/6', | |
| 934 | + 'frm10' => '5/6', | |
| 935 | + | |
| 936 | + 'frm11' => '11/12', | |
| 937 | + 'frm1' => '1/12', | |
| 938 | + | |
| 939 | + 'frm5' => '5/12', | |
| 940 | + 'frm7' => '7/12', | |
| 941 | + | |
| 942 | + 'frm12' => '100%', | |
| 943 | + ); | |
| 944 | + } | |
| 945 | + | |
| 946 | + return array_merge( $base, $classes ); | |
| 1270 | 947 | } |
| 1271 | 948 | |
| 1272 | 949 | /** |
| 1273 | 950 | * @since 3.0 |
| @@ -1277,495 +954,26 @@ | ||
| 1277 | 954 | if ( empty( $style ) ) { |
| 1278 | 955 | $label = $class; |
| 1279 | 956 | } elseif ( ! is_array( $style ) ) { |
| 1280 | 957 | $label = $style; |
| 1281 | - } elseif ( isset( $style['label'] ) ) { | |
| 958 | + } else if ( isset( $style['label'] ) ) { | |
| 1282 | 959 | $label = $style['label']; |
| 1283 | 960 | } |
| 1284 | - | |
| 1285 | 961 | return $label; |
| 1286 | 962 | } |
| 1287 | 963 | |
| 1288 | 964 | public static function status_nice_name( $status ) { |
| 1289 | - $nice_names = array( | |
| 1290 | - 'draft' => __( 'Draft', 'formidable' ), | |
| 1291 | - 'trash' => __( 'Trash', 'formidable' ), | |
| 1292 | - 'publish' => __( 'Published', 'formidable' ), | |
| 1293 | - ); | |
| 965 | + $nice_names = array( | |
| 966 | + 'draft' => __( 'Draft', 'formidable' ), | |
| 967 | + 'trash' => __( 'Trash', 'formidable' ), | |
| 968 | + 'publish' => __( 'Published', 'formidable' ), | |
| 969 | + ); | |
| 1294 | 970 | |
| 1295 | 971 | if ( ! in_array( $status, array_keys( $nice_names ) ) ) { |
| 1296 | - $status = 'publish'; | |
| 1297 | - } | |
| 972 | + $status = 'publish'; | |
| 973 | + } | |
| 1298 | 974 | |
| 1299 | 975 | $name = $nice_names[ $status ]; |
| 1300 | 976 | |
| 1301 | - return $name; | |
| 1302 | - } | |
| 1303 | - | |
| 1304 | - /** | |
| 1305 | - * @param array $categories | |
| 1306 | - * @param array $atts { | |
| 1307 | - * @type string $html 'span' or 'div'. | |
| 1308 | - * @type boolean $bg Whether to add a bg color or not. | |
| 1309 | - * } | |
| 1310 | - * | |
| 1311 | - * @return void | |
| 1312 | - */ | |
| 1313 | - public static function template_icon( $categories, $atts = array() ) { | |
| 1314 | - $defaults = array( | |
| 1315 | - 'html' => 'span', | |
| 1316 | - 'bg' => false, | |
| 1317 | - ); | |
| 1318 | - $atts = array_merge( $defaults, $atts ); | |
| 1319 | - | |
| 1320 | - $ignore = self::ignore_template_categories(); | |
| 1321 | - $categories = array_diff( $categories, $ignore ); | |
| 1322 | - | |
| 1323 | - $icons = array( | |
| 1324 | - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), | |
| 1325 | - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), | |
| 1326 | - 'User Registration' => array( 'register', 'var(--pink)' ), | |
| 1327 | - 'Registration and Signup' => array( 'register', 'var(--pink)' ), | |
| 1328 | - 'PayPal' => array( 'paypal' ), | |
| 1329 | - 'Stripe' => array( 'credit_card', 'var(--green)' ), | |
| 1330 | - 'Twilio' => array( 'sms' ), | |
| 1331 | - 'Payment' => array( 'credit_card' ), | |
| 1332 | - 'Order Form' => array( 'product' ), | |
| 1333 | - 'Finance' => array( 'total' ), | |
| 1334 | - 'Health and Wellness' => array( 'heart', 'var(--pink)' ), | |
| 1335 | - 'Event Planning' => array( 'calendar', 'var(--orange)' ), | |
| 1336 | - 'Real Estate' => array( 'house' ), | |
| 1337 | - 'Nonprofit' => array( 'heart_solid' ), | |
| 1338 | - 'Calculator' => array( 'calculator', 'var(--purple)' ), | |
| 1339 | - 'Quiz' => array( 'percent' ), | |
| 1340 | - 'Registrations' => array( 'address_card' ), | |
| 1341 | - 'Customer Service' => array( 'users_solid' ), | |
| 1342 | - 'Education' => array( 'pencil' ), | |
| 1343 | - 'Marketing' => array( 'eye' ), | |
| 1344 | - 'Feedback' => array( 'smile' ), | |
| 1345 | - 'Business Operations' => array( 'case' ), | |
| 1346 | - 'Contact Form' => array( 'email' ), | |
| 1347 | - 'Conversational Forms' => array( 'chat_forms' ), | |
| 1348 | - 'Survey' => array( 'chat_forms', 'var(--orange)' ), | |
| 1349 | - 'Application' => array( 'align_right' ), | |
| 1350 | - 'Signature' => array( 'signature' ), | |
| 1351 | - '' => array( 'align_right' ), | |
| 1352 | - ); | |
| 1353 | - | |
| 1354 | - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' ); | |
| 1355 | - | |
| 1356 | - $icon = $icons['']; | |
| 1357 | - | |
| 1358 | - if ( count( $categories ) === 1 ) { | |
| 1359 | - $category = reset( $categories ); | |
| 1360 | - $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; | |
| 1361 | - } elseif ( ! empty( $categories ) ) { | |
| 1362 | - foreach ( $icons as $cat => $icon ) { | |
| 1363 | - if ( ! in_array( $cat, $categories ) ) { | |
| 1364 | - unset( $icons[ $cat ] ); | |
| 1365 | - } | |
| 1366 | - } | |
| 1367 | - $icon = reset( $icons ); | |
| 1368 | - } | |
| 1369 | - | |
| 1370 | - $bg = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1371 | - | |
| 1372 | - if ( $atts['html'] === 'div' ) { | |
| 1373 | - echo '<div class="frm-category-icon frm-icon-wrapper" role="button"'; | |
| 1374 | - } else { | |
| 1375 | - echo '<span class="frm-inner-circle"'; | |
| 1376 | - } | |
| 1377 | - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"'; | |
| 1378 | - echo '>'; | |
| 1379 | - | |
| 1380 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' ); | |
| 1381 | - echo '<span class="frm_hidden">'; | |
| 1382 | - FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' ); | |
| 1383 | - echo '</span>'; | |
| 1384 | - echo '</' . esc_attr( $atts['html'] ) . '>'; | |
| 1385 | - } | |
| 1386 | - | |
| 1387 | - /** | |
| 1388 | - * @since 4.03.01 | |
| 1389 | - * | |
| 1390 | - * @return array<string> | |
| 1391 | - */ | |
| 1392 | - public static function ignore_template_categories() { | |
| 1393 | - return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); | |
| 1394 | - } | |
| 1395 | - | |
| 1396 | - /** | |
| 1397 | - * @since 4.02 | |
| 1398 | - */ | |
| 1399 | - public static function get_template_install_link( $template, $args ) { | |
| 1400 | - $defaults = array( | |
| 1401 | - 'class' => 'install-now', | |
| 1402 | - 'href' => 'href', | |
| 1403 | - 'atts' => true, | |
| 1404 | - ); | |
| 1405 | - | |
| 1406 | - if ( ! empty( $template['url'] ) ) { | |
| 1407 | - $link = array( | |
| 1408 | - 'url' => $template['url'], | |
| 1409 | - 'label' => __( 'Create Form', 'formidable' ), | |
| 1410 | - 'class' => 'frm-install-template', | |
| 1411 | - 'href' => 'rel', | |
| 1412 | - 'atts' => '', | |
| 1413 | - ); | |
| 1414 | - } elseif ( self::plan_is_allowed( $args ) ) { | |
| 1415 | - $link = array( | |
| 1416 | - 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'], | |
| 1417 | - 'label' => __( 'Renew', 'formidable' ), | |
| 1418 | - ); | |
| 1419 | - } else { | |
| 1420 | - $link = array( | |
| 1421 | - 'url' => $args['pricing'], | |
| 1422 | - 'label' => __( 'Upgrade', 'formidable' ), | |
| 1423 | - ); | |
| 1424 | - } | |
| 1425 | - | |
| 1426 | - return array_merge( $defaults, $link ); | |
| 1427 | - } | |
| 1428 | - | |
| 1429 | - /** | |
| 1430 | - * Is the template included with the license type? | |
| 1431 | - * | |
| 1432 | - * @since 4.02.02 | |
| 1433 | - * | |
| 1434 | - * @param array $args | |
| 1435 | - * | |
| 1436 | - * @return bool | |
| 1437 | - */ | |
| 1438 | - public static function plan_is_allowed( $args ) { | |
| 1439 | - if ( empty( $args['license_type'] ) ) { | |
| 1440 | - return false; | |
| 1441 | - } | |
| 1442 | - | |
| 1443 | - $included = $args['license_type'] === strtolower( $args['plan_required'] ); | |
| 1444 | - | |
| 1445 | - $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1446 | - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) { | |
| 1447 | - return $included; | |
| 1448 | - } | |
| 1449 | - | |
| 1450 | - foreach ( $plans as $plan ) { | |
| 1451 | - if ( $included || $plan === $args['license_type'] ) { | |
| 1452 | - break; | |
| 1453 | - } | |
| 1454 | - $included = $plan === strtolower( $args['plan_required'] ); | |
| 1455 | - } | |
| 1456 | - | |
| 1457 | - return $included; | |
| 1458 | - } | |
| 1459 | - | |
| 1460 | - /** | |
| 1461 | - * @since 4.02 | |
| 1462 | - */ | |
| 1463 | - public static function template_install_html( $link, $class = '' ) { | |
| 1464 | - $link['class'] .= ' ' . $class; | |
| 1465 | - 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"' : '' ) . '>'; | |
| 1466 | - } | |
| 1467 | - | |
| 1468 | - /** | |
| 1469 | - * If a template or add-on cannot be installed, show a message | |
| 1470 | - * about which plan is required. | |
| 1471 | - * | |
| 1472 | - * @since 4.0 | |
| 1473 | - */ | |
| 1474 | - public static function show_plan_required( $requires, $link ) { | |
| 1475 | - if ( empty( $requires ) ) { | |
| 1476 | - return; | |
| 1477 | - } | |
| 1478 | - | |
| 1479 | - ?> | |
| 1480 | - <p class="frm_plan_required"> | |
| 1481 | - <?php esc_html_e( 'License plan required:', 'formidable' ); ?> | |
| 1482 | - <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener"> | |
| 1483 | - <?php echo esc_html( $requires ); ?> | |
| 1484 | - </a> | |
| 1485 | - </p> | |
| 1486 | - <?php | |
| 1487 | - } | |
| 1488 | - | |
| 1489 | - /** | |
| 1490 | - * @since 4.0 | |
| 1491 | - * | |
| 1492 | - * @param array $item | |
| 1493 | - * @return string|false | |
| 1494 | - */ | |
| 1495 | - public static function get_plan_required( &$item ) { | |
| 1496 | - if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { | |
| 1497 | - return false; | |
| 1498 | - } | |
| 1499 | - | |
| 1500 | - $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' ); | |
| 1501 | - | |
| 1502 | - foreach ( $item['categories'] as $k => $category ) { | |
| 1503 | - if ( in_array( $category, $plans, true ) ) { | |
| 1504 | - unset( $item['categories'][ $k ] ); | |
| 1505 | - | |
| 1506 | - if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) { | |
| 1507 | - // Show the current package name. | |
| 1508 | - $category = 'Plus'; | |
| 1509 | - } | |
| 1510 | - | |
| 1511 | - return $category; | |
| 1512 | - } | |
| 1513 | - } | |
| 1514 | - | |
| 1515 | - return false; | |
| 1516 | - } | |
| 1517 | - | |
| 1518 | - /** | |
| 1519 | - * Checks for warnings to be displayed after form settings are saved. | |
| 1520 | - * | |
| 1521 | - * @since 4.04 | |
| 1522 | - * | |
| 1523 | - * @param array $values The $_POST array, which contains values submitted in a form. | |
| 1524 | - * | |
| 1525 | - * @return array An array of warnings or an empty array. | |
| 1526 | - */ | |
| 1527 | - public static function check_for_warnings( $values ) { | |
| 1528 | - $warnings = array(); | |
| 1529 | - | |
| 1530 | - $redirect_warning = self::check_redirect_url_for_unsafe_params( $values ); | |
| 1531 | - | |
| 1532 | - if ( $redirect_warning ) { | |
| 1533 | - $warnings[] = $redirect_warning; | |
| 1534 | - } | |
| 1535 | - | |
| 1536 | - return apply_filters( 'frm_check_for_warnings', $warnings, $values ); | |
| 1537 | - } | |
| 1538 | - | |
| 1539 | - /** | |
| 1540 | - * Checks the redirect URL for params whose names are reserved words. | |
| 1541 | - * | |
| 1542 | - * @since 4.04 | |
| 1543 | - * | |
| 1544 | - * @param array $values The $_POST array, which contains the values submitted in a form. | |
| 1545 | - * | |
| 1546 | - * @return bool|string A warning message about unsafe params or false. | |
| 1547 | - */ | |
| 1548 | - private static function check_redirect_url_for_unsafe_params( $values ) { | |
| 1549 | - if ( ! isset( $values['options'] ) ) { | |
| 1550 | - return false; | |
| 1551 | - } | |
| 1552 | - | |
| 1553 | - $options = $values['options']; | |
| 1554 | - FrmAppHelper::sanitize_with_html( $options ); | |
| 1555 | - | |
| 1556 | - if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) { | |
| 1557 | - return false; | |
| 1558 | - } | |
| 1559 | - | |
| 1560 | - $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] ); | |
| 1561 | - | |
| 1562 | - return self::create_unsafe_param_warning( $unsafe_params_in_redirect ); | |
| 1563 | - } | |
| 1564 | - | |
| 1565 | - /** | |
| 1566 | - * Returns an array of params whose names are reserved words in the specified URL. | |
| 1567 | - * | |
| 1568 | - * @since 4.04 | |
| 1569 | - * | |
| 1570 | - * @param string $url The URL whose params are being checked. | |
| 1571 | - * | |
| 1572 | - * @return array An array of params whose names are reserved words or an empty array. | |
| 1573 | - */ | |
| 1574 | - private static function get_unsafe_params( $url ) { | |
| 1575 | - $redirect_components = parse_url( $url ); | |
| 1576 | - if ( empty( $redirect_components['query'] ) ) { | |
| 1577 | - return array(); | |
| 1578 | - } | |
| 1579 | - parse_str( $redirect_components['query'], $redirect_params ); | |
| 1580 | - $redirect_param_names = array_keys( $redirect_params ); | |
| 1581 | - $reserved_words = self::reserved_words(); | |
| 1582 | - $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words ); | |
| 1583 | - | |
| 1584 | - return array_values( $unsafe_params_in_redirect ); | |
| 1585 | - } | |
| 1586 | - | |
| 1587 | - /** | |
| 1588 | - * Returns a warning if reserved words have been used as param names in the redirect URL. | |
| 1589 | - * | |
| 1590 | - * @since 4.04 | |
| 1591 | - * | |
| 1592 | - * @param array $unsafe_params_in_redirect Array of params from the redirect URL whose names are reserved words. | |
| 1593 | - * | |
| 1594 | - * @return bool|string A string with an unsafe param message or false. | |
| 1595 | - */ | |
| 1596 | - private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) { | |
| 1597 | - $count = count( $unsafe_params_in_redirect ); | |
| 1598 | - $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1599 | - $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1600 | - $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1601 | - | |
| 1602 | - if ( $count === 0 ) { | |
| 1603 | - return false; | |
| 1604 | - } | |
| 1605 | - | |
| 1606 | - if ( $count == 1 ) { | |
| 1607 | - /* translators: %s: the name of a single parameter in the redirect URL */ | |
| 1608 | - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; | |
| 1609 | - } | |
| 1610 | - | |
| 1611 | - $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect ); | |
| 1612 | - | |
| 1613 | - /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */ | |
| 1614 | - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; | |
| 1615 | - } | |
| 1616 | - | |
| 1617 | - /** | |
| 1618 | - * Returns an array of common reserved words in WordPress. | |
| 1619 | - * | |
| 1620 | - * An edited list of reserved terms from the Codex. | |
| 1621 | - * https://codex.wordpress.org/Reserved_Terms | |
| 1622 | - * | |
| 1623 | - * @since 4.04 | |
| 1624 | - * | |
| 1625 | - * @return array Array of WordPress reserved words. | |
| 1626 | - */ | |
| 1627 | - public static function reserved_words() { | |
| 1628 | - return array( | |
| 1629 | - 'id', | |
| 1630 | - 'attachment', | |
| 1631 | - 'author', | |
| 1632 | - 'author_name', | |
| 1633 | - 'calendar', | |
| 1634 | - 'cat', | |
| 1635 | - 'category', | |
| 1636 | - 'category_name', | |
| 1637 | - 'cpage', | |
| 1638 | - 'custom', | |
| 1639 | - 'day', | |
| 1640 | - 'date', | |
| 1641 | - 'error', | |
| 1642 | - 'feed', | |
| 1643 | - 'hour', | |
| 1644 | - 'm', | |
| 1645 | - 'minute', | |
| 1646 | - 'more', | |
| 1647 | - 'name', | |
| 1648 | - 'order', | |
| 1649 | - 'p', | |
| 1650 | - 'page', | |
| 1651 | - 'page_id', | |
| 1652 | - 'paged', | |
| 1653 | - 'pb', | |
| 1654 | - 'post', | |
| 1655 | - 'posts', | |
| 1656 | - 'preview', | |
| 1657 | - 's', | |
| 1658 | - 'search', | |
| 1659 | - 'second', | |
| 1660 | - 'sentence', | |
| 1661 | - 'tag', | |
| 1662 | - 'taxonomy', | |
| 1663 | - 'tb', | |
| 1664 | - 'term', | |
| 1665 | - 'terms', | |
| 1666 | - 'theme', | |
| 1667 | - 'title', | |
| 1668 | - 'type', | |
| 1669 | - 'w', | |
| 1670 | - 'year', | |
| 1671 | - ); | |
| 1672 | - } | |
| 1673 | - | |
| 1674 | - /** | |
| 1675 | - * Check an array of templates, determine how many the logged in user can use | |
| 1676 | - * | |
| 1677 | - * @param array $templates | |
| 1678 | - * @param array $args | |
| 1679 | - * @return int | |
| 1680 | - */ | |
| 1681 | - public static function available_count( $templates, $args ) { | |
| 1682 | - return array_reduce( | |
| 1683 | - $templates, | |
| 1684 | - function( $total, $template ) use ( $args ) { | |
| 1685 | - if ( ! empty( $template['url'] ) ) { | |
| 1686 | - return $total + 1; | |
| 1687 | - } | |
| 1688 | - | |
| 1689 | - $args['plan_required'] = self::get_plan_required( $template ); | |
| 1690 | - if ( self::plan_is_allowed( $args ) ) { | |
| 1691 | - return $total + 1; | |
| 1692 | - } | |
| 1693 | - | |
| 1694 | - return $total; | |
| 1695 | - }, | |
| 1696 | - 0 | |
| 1697 | - ); | |
| 1698 | - } | |
| 1699 | - | |
| 1700 | - /** | |
| 1701 | - * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined. | |
| 1702 | - * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL. | |
| 1703 | - * | |
| 1704 | - * @since 5.0.16 | |
| 1705 | - * | |
| 1706 | - * @param string $url | |
| 1707 | - * @param int $form_id | |
| 1708 | - * @return string | |
| 1709 | - */ | |
| 1710 | - public static function maybe_add_sanitize_url_attr( $url, $form_id ) { | |
| 1711 | - if ( false === strpos( $url, '[' ) ) { | |
| 1712 | - // Do nothing if no shortcodes are detected. | |
| 1713 | - return $url; | |
| 1714 | - } | |
| 1715 | - | |
| 1716 | - $parsed = wp_parse_url( $url ); | |
| 1717 | - if ( empty( $parsed['query'] ) ) { | |
| 1718 | - // Do nothing if no query can be detected in the url string. | |
| 1719 | - return $url; | |
| 1720 | - } | |
| 1721 | - | |
| 1722 | - $original_query = $parsed['query']; | |
| 1723 | - $query = $parsed['query']; | |
| 1724 | - | |
| 1725 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1726 | - if ( empty( $shortcodes[0] ) ) { | |
| 1727 | - // No shortcodes found, do nothing. | |
| 1728 | - return $url; | |
| 1729 | - } | |
| 1730 | - | |
| 1731 | - foreach ( $shortcodes[0] as $key => $shortcode ) { | |
| 1732 | - $options = trim( $shortcodes[3][ $key ] ); | |
| 1733 | - | |
| 1734 | - if ( in_array( $shortcodes[1][ $key ], array( 'if ' ), true ) ) { | |
| 1735 | - // Skip if shortcodes. | |
| 1736 | - continue; | |
| 1737 | - } | |
| 1738 | - | |
| 1739 | - if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) { | |
| 1740 | - // A sanitize option is already set so leave it alone. | |
| 1741 | - continue; | |
| 1742 | - } | |
| 1743 | - | |
| 1744 | - $new_shortcode = '[' . $shortcodes[2][ $key ]; | |
| 1745 | - if ( $options ) { | |
| 1746 | - $new_shortcode .= ' ' . $options; | |
| 1747 | - } | |
| 1748 | - $new_shortcode .= ' sanitize_url=1]'; | |
| 1749 | - | |
| 1750 | - $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1751 | - } | |
| 1752 | - | |
| 1753 | - if ( $query === $original_query ) { | |
| 1754 | - return $url; | |
| 1755 | - } | |
| 1756 | - | |
| 1757 | - return str_replace( $original_query, $query, $url ); | |
| 1758 | - } | |
| 1759 | - | |
| 1760 | - /** | |
| 1761 | - * Check if Pro isn't up to date yet. | |
| 1762 | - * 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). | |
| 1763 | - * | |
| 1764 | - * @since 6.2 | |
| 1765 | - * | |
| 1766 | - * @return bool | |
| 1767 | - */ | |
| 1768 | - public static function should_use_pro_for_ajax_submit() { | |
| 1769 | - return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' ); | |
| 1770 | - } | |
| 977 | + return $name; | |
| 978 | + } | |
| 1771 | 979 | } |