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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / includes / shortcodes.php
contact-form-7 / includes Last commit date
classes.php 16 years ago controller.php 16 years ago formatting.php 16 years ago functions.php 16 years ago pipe.php 16 years ago shortcodes.php 16 years ago taggenerator.php 16 years ago
shortcodes.php
149 lines
1 <?php
2
3 class WPCF7_ShortcodeManager {
4
5 var $shortcode_tags = array();
6
7 // Taggs scanned at the last time of do_shortcode()
8 var $scanned_tags = null;
9
10 // Executing shortcodes (true) or just scanning (false)
11 var $exec = true;
12
13 function add_shortcode( $tag, $func, $has_name = false ) {
14 if ( is_callable( $func ) )
15 $this->shortcode_tags[$tag] = array(
16 'function' => $func,
17 'has_name' => (boolean) $has_name );
18 }
19
20 function remove_shortcode( $tag ) {
21 unset( $this->shortcode_tags[$tag] );
22 }
23
24 function do_shortcode( $content, $exec = true ) {
25 $this->exec = (bool) $exec;
26 $this->scanned_tags = array();
27
28 if ( empty( $this->shortcode_tags ) || ! is_array( $this->shortcode_tags) )
29 return $content;
30
31 $pattern = $this->get_shortcode_regex();
32 return preg_replace_callback( '/' . $pattern . '/s',
33 array(&$this, 'do_shortcode_tag'), $content );
34 }
35
36 function scan_shortcode( $content ) {
37 $this->do_shortcode( $content, false );
38 return $this->scanned_tags;
39 }
40
41 function get_shortcode_regex() {
42 $tagnames = array_keys( $this->shortcode_tags );
43 $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
44
45 return '(\[?)\[(' . $tagregexp . ')(?:\s(.*?))?(?:\s(\/))?\](?:(.+?)\[\/\2\])?(\]?)';
46 }
47
48 function do_shortcode_tag( $m ) {
49 // allow [[foo]] syntax for escaping a tag
50 if ( $m[1] == '[' && $m[6] == ']' ) {
51 return substr( $m[0], 1, -1 );
52 }
53
54 $tag = $m[2];
55 $attr = $this->shortcode_parse_atts( $m[3] );
56
57 $scanned_tag = array();
58 $scanned_tag['type'] = $tag;
59
60 if ( is_array( $attr ) ) {
61 if ( is_array( $attr['options'] ) ) {
62 if ( $this->shortcode_tags[$tag]['has_name'] && ! empty( $attr['options'] ) )
63 $scanned_tag['name'] = array_shift( $attr['options'] );
64
65 $scanned_tag['options'] = (array) $attr['options'];
66 }
67 $scanned_tag['raw_values'] = (array) $attr['values'];
68
69 if ( WPCF7_USE_PIPE ) {
70 $pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
71 $scanned_tag['values'] = $pipes->collect_befores();
72 $scanned_tag['pipes'] = $pipes;
73 } else {
74 $scanned_tag['values'] = $scanned_tag['raw_values'];
75 }
76
77 $scanned_tag['labels'] = $scanned_tag['values'];
78
79 } else {
80 $scanned_tag['attr'] = $attr;
81 }
82
83 $content = trim( $m[5] );
84 $content = preg_replace( "/<br\s*\/?>$/m", '', $content );
85 $scanned_tag['content'] = $content;
86
87 $this->scanned_tags[] = $scanned_tag;
88
89 $func = $this->shortcode_tags[$tag]['function'];
90
91 if ( $this->exec ) {
92 $scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag );
93 return $m[1] . call_user_func( $func, $scanned_tag ) . $m[6];
94 } else {
95 return $m[0];
96 }
97 }
98
99 function shortcode_parse_atts( $text ) {
100 $atts = array( 'options' => array(), 'values' => array() );
101 $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
102 $text = stripcslashes( trim( $text ) );
103
104 $pattern = '%^([-0-9a-zA-Z:.#_/|\s]*?)((?:\s*"[^"]*"|\s*\'[^\']*\')*)$%';
105
106 if ( preg_match( $pattern, $text, $match ) ) {
107 if ( ! empty( $match[1] ) ) {
108 $atts['options'] = preg_split( '/[\s]+/', trim( $match[1] ) );
109 }
110 if ( ! empty( $match[2] ) ) {
111 preg_match_all( '/"[^"]*"|\'[^\']*\'/', $match[2], $matched_values );
112 $atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
113 }
114 } else {
115 $atts = $text;
116 }
117
118 return $atts;
119 }
120
121 }
122
123 $wpcf7_shortcode_manager = new WPCF7_ShortcodeManager();
124
125 function wpcf7_add_shortcode( $tag, $func, $has_name = false ) {
126 global $wpcf7_shortcode_manager;
127
128 return $wpcf7_shortcode_manager->add_shortcode( $tag, $func, $has_name );
129 }
130
131 function wpcf7_remove_shortcode( $tag ) {
132 global $wpcf7_shortcode_manager;
133
134 return $wpcf7_shortcode_manager->remove_shortcode( $tag );
135 }
136
137 function wpcf7_do_shortcode( $content ) {
138 global $wpcf7_shortcode_manager;
139
140 return $wpcf7_shortcode_manager->do_shortcode( $content );
141 }
142
143 function wpcf7_get_shortcode_regex() {
144 global $wpcf7_shortcode_manager;
145
146 return $wpcf7_shortcode_manager->get_shortcode_regex();
147 }
148
149 ?>