1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @since 2.02.12 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
class FrmShortcodeHelper { |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Get the shortcode attributes in key/value pairs from a string |
10
|
|
|
* |
11
|
|
|
* @since 2.02.12 |
12
|
|
|
* @param string $text |
13
|
|
|
* |
14
|
|
|
* @return array |
15
|
|
|
*/ |
16
|
|
|
public static function get_shortcode_attribute_array( $text ) { |
17
|
|
|
$atts = array(); |
18
|
|
|
if ( $text !== '' ) { |
19
|
|
|
$atts = shortcode_parse_atts( $text ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if ( ! is_array( $atts ) ) { |
23
|
|
|
$atts = array(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return $atts; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the name of the shortcode from the regEx |
31
|
|
|
* |
32
|
|
|
* @since 3.0 |
33
|
|
|
* @param array $shortcodes |
34
|
|
|
* @param int $short_key The position in the shortcodes array |
35
|
|
|
* @param array $args |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
40
|
|
|
$args = wp_parse_args( $args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false ) ); |
41
|
|
|
if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
42
|
|
|
$args['conditional_check'] = true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$prefix = ''; |
46
|
|
|
if ( $args['conditional_check'] ) { |
47
|
|
|
if ( $args['conditional'] ) { |
48
|
|
|
$prefix = 'if '; |
49
|
|
|
} else if ( $args['foreach'] ) { |
50
|
|
|
$prefix = 'foreach '; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$with_tags = $args['conditional_check'] ? 3 : 2; |
55
|
|
|
if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { |
56
|
|
|
$tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); |
57
|
|
|
$tag = str_replace(']', '', $tag); |
58
|
|
|
$tags = explode(' ', $tag); |
59
|
|
|
if ( is_array($tags) ) { |
60
|
|
|
$tag = $tags[0]; |
61
|
|
|
} |
62
|
|
|
} else { |
63
|
|
|
$tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $tag; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
70
|
|
|
if ( $no_vars ) { |
71
|
|
|
$html = str_replace( '[if ' . $code . ']', '', $html ); |
72
|
|
|
$html = str_replace( '[/if ' . $code . ']', '', $html ); |
73
|
|
|
} else { |
74
|
|
|
$html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$html = str_replace( '[' . $code . ']', $replace_with, $html ); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|