| @@ -1,12 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | - | |
| 6 | 2 | /** |
| 7 | 3 | * @since 2.02.12 |
| 8 | 4 | */ |
| 5 | + | |
| 9 | 6 | class FrmShortcodeHelper { |
| 10 | 7 | |
| 11 | 8 | /** |
| 12 | 9 | * Get the shortcode attributes in key/value pairs from a string |
| @@ -11,9 +8,8 @@ | ||
| 11 | 8 | /** |
| 12 | 9 | * Get the shortcode attributes in key/value pairs from a string |
| 13 | 10 | * |
| 14 | 11 | * @since 2.02.12 |
| 15 | - * | |
| 16 | 12 | * @param string $text |
| 17 | 13 | * |
| 18 | 14 | * @return array |
| 19 | 15 | */ |
| @@ -18,65 +14,17 @@ | ||
| 18 | 14 | * @return array |
| 19 | 15 | */ |
| 20 | 16 | public static function get_shortcode_attribute_array( $text ) { |
| 21 | 17 | $atts = array(); |
| 22 | - | |
| 23 | 18 | if ( $text !== '' ) { |
| 24 | 19 | $atts = shortcode_parse_atts( $text ); |
| 25 | 20 | } |
| 26 | 21 | |
| 27 | - return is_array( $atts ) ? $atts : array(); | |
| 28 | - } | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * Returns shortcodes that are shown/hidden based on the context. | |
| 32 | - * | |
| 33 | - * @since 6.16.3 | |
| 34 | - * | |
| 35 | - * @return array | |
| 36 | - */ | |
| 37 | - public static function get_contextual_shortcodes() { | |
| 38 | - return array( | |
| 39 | - 'address' => array( | |
| 40 | - 'admin_email' => __( 'Admin email', 'formidable' ), | |
| 41 | - 'default-from-email' => __( 'Default from email', 'formidable' ), | |
| 42 | - 'default-email' => __( 'Default email', 'formidable' ), | |
| 43 | - ), | |
| 44 | - 'body' => array( | |
| 45 | - 'default-message' => __( 'Default Msg', 'formidable' ), | |
| 46 | - 'default-html' => __( 'Default HTML', 'formidable' ), | |
| 47 | - 'default-plain' => __( 'Default Plain', 'formidable' ), | |
| 48 | - ), | |
| 49 | - ); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Get contextual shortcodes. | |
| 54 | - * | |
| 55 | - * @since 6.16.3 | |
| 56 | - * | |
| 57 | - * @return array | |
| 58 | - */ | |
| 59 | - public static function get_contextual_shortcode_values() { | |
| 60 | - $contextual_shortcodes = self::get_contextual_shortcodes(); | |
| 61 | - return array_merge( $contextual_shortcodes['address'], $contextual_shortcodes['body'] ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * Get flattened format of contextual shortcodes. | |
| 66 | - * | |
| 67 | - * @since 6.16.3 | |
| 68 | - * | |
| 69 | - * @return array | |
| 70 | - */ | |
| 71 | - public static function get_contextual_codes() { | |
| 72 | - $result = array(); | |
| 73 | - | |
| 74 | - foreach ( self::get_contextual_shortcodes() as $type => $shortcodes ) { | |
| 75 | - $result[ $type ] = array_keys( $shortcodes ); | |
| 22 | + if ( ! is_array( $atts ) ) { | |
| 23 | + $atts = array(); | |
| 76 | 24 | } |
| 77 | 25 | |
| 78 | - return $result; | |
| 26 | + return $atts; | |
| 79 | 27 | } |
| 80 | 28 | |
| 81 | 29 | /** |
| 82 | 30 | * Get the name of the shortcode from the regEx |
| @@ -81,11 +29,10 @@ | ||
| 81 | 29 | /** |
| 82 | 30 | * Get the name of the shortcode from the regEx |
| 83 | 31 | * |
| 84 | 32 | * @since 3.0 |
| 85 | - * | |
| 86 | 33 | * @param array $shortcodes |
| 87 | - * @param int $short_key The position in the shortcodes array. | |
| 34 | + * @param int $short_key The position in the shortcodes array | |
| 88 | 35 | * @param array $args |
| 89 | 36 | * |
| 90 | 37 | * @return string |
| 91 | 38 | */ |
| @@ -97,45 +44,37 @@ | ||
| 97 | 44 | 'conditional_check' => false, |
| 98 | 45 | 'foreach' => false, |
| 99 | 46 | ) |
| 100 | 47 | ); |
| 101 | - | |
| 102 | 48 | if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
| 103 | 49 | $args['conditional_check'] = true; |
| 104 | 50 | } |
| 105 | 51 | |
| 106 | 52 | $prefix = ''; |
| 107 | - | |
| 108 | 53 | if ( $args['conditional_check'] ) { |
| 109 | 54 | if ( $args['conditional'] ) { |
| 110 | 55 | $prefix = 'if '; |
| 111 | - } elseif ( $args['foreach'] ) { | |
| 56 | + } else if ( $args['foreach'] ) { | |
| 112 | 57 | $prefix = 'foreach '; |
| 113 | 58 | } |
| 114 | 59 | } |
| 115 | 60 | |
| 116 | 61 | $with_tags = $args['conditional_check'] ? 3 : 2; |
| 117 | - | |
| 118 | - if ( empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { | |
| 119 | - return $shortcodes[ $with_tags - 1 ][ $short_key ]; | |
| 62 | + if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { | |
| 63 | + $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); | |
| 64 | + $tag = str_replace( ']', '', $tag ); | |
| 65 | + $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag ); | |
| 66 | + $tags = preg_split( '/\s+/', $tag, 2 ); | |
| 67 | + if ( is_array( $tags ) ) { | |
| 68 | + $tag = $tags[0]; | |
| 69 | + } | |
| 70 | + } else { | |
| 71 | + $tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; | |
| 120 | 72 | } |
| 121 | 73 | |
| 122 | - $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); | |
| 123 | - $tag = str_replace( ']', '', $tag ); | |
| 124 | - $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag ); | |
| 125 | - $tags = preg_split( '/\s+/', $tag, 2 ); | |
| 126 | - | |
| 127 | - return is_array( $tags ) ? $tags[0] : $tag; | |
| 74 | + return $tag; | |
| 128 | 75 | } |
| 129 | 76 | |
| 130 | - /** | |
| 131 | - * @param bool $no_vars | |
| 132 | - * @param string $code | |
| 133 | - * @param string $replace_with | |
| 134 | - * @param string $html | |
| 135 | - * | |
| 136 | - * @return void | |
| 137 | - */ | |
| 138 | 77 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
| 139 | 78 | if ( $no_vars ) { |
| 140 | 79 | $html = str_replace( '[if ' . $code . ']', '', $html ); |
| 141 | 80 | $html = str_replace( '[/if ' . $code . ']', '', $html ); |