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