PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmShortcodeHelper.php

FrmShortcodeHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.12, at classes/helpers/FrmShortcodeHelper.php

93 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.02.12
8 */
9 class FrmShortcodeHelper {
10
11 /**
12 * Get the shortcode attributes in key/value pairs from a string
13 *
14 * @since 2.02.12
15 *
16 * @param string $text
17 *
18 * @return array
19 */
20 public static function get_shortcode_attribute_array( $text ) {
21 $atts = array();
22 if ( $text !== '' ) {
23 $atts = shortcode_parse_atts( $text );
24 }
25
26 if ( ! is_array( $atts ) ) {
27 $atts = array();
28 }
29
30 return $atts;
31 }
32
33 /**
34 * Get the name of the shortcode from the regEx
35 *
36 * @since 3.0
37 *
38 * @param array $shortcodes
39 * @param int $short_key The position in the shortcodes array.
40 * @param array $args
41 *
42 * @return string
43 */
44 public static function get_shortcode_tag( $shortcodes, $short_key, $args = array() ) {
45 $args = wp_parse_args(
46 $args,
47 array(
48 'conditional' => false,
49 'conditional_check' => false,
50 'foreach' => false,
51 )
52 );
53 if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
54 $args['conditional_check'] = true;
55 }
56
57 $prefix = '';
58 if ( $args['conditional_check'] ) {
59 if ( $args['conditional'] ) {
60 $prefix = 'if ';
61 } elseif ( $args['foreach'] ) {
62 $prefix = 'foreach ';
63 }
64 }
65
66 $with_tags = $args['conditional_check'] ? 3 : 2;
67 if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
68 $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
69 $tag = str_replace( ']', '', $tag );
70 $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag );
71 $tags = preg_split( '/\s+/', $tag, 2 );
72 if ( is_array( $tags ) ) {
73 $tag = $tags[0];
74 }
75 } else {
76 $tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
77 }
78
79 return $tag;
80 }
81
82 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
83 if ( $no_vars ) {
84 $html = str_replace( '[if ' . $code . ']', '', $html );
85 $html = str_replace( '[/if ' . $code . ']', '', $html );
86 } else {
87 $html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html );
88 }
89
90 $html = str_replace( '[' . $code . ']', $replace_with, $html );
91 }
92 }
93