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.1 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 / modules / icl.php
contact-form-7 / modules Last commit date
acceptance.php 16 years ago captcha.php 16 years ago checkbox.php 16 years ago file.php 16 years ago icl.php 16 years ago quiz.php 16 years ago select.php 16 years ago submit.php 16 years ago text.php 16 years ago textarea.php 16 years ago
icl.php
217 lines
1 <?php
2 /**
3 ** ICL module for ICanLocalize translation service
4 **/
5
6 /* Shortcode handler */
7
8 function icl_wpcf7_shortcode_handler( $tag ) {
9
10 if ( ! is_array( $tag ) )
11 return '';
12
13 $name = $tag['name'];
14 $values = (array) $tag['values'];
15 $content = $tag['content'];
16
17 $content = trim( $content );
18 if ( ! empty( $content ) ) {
19 $string_name = icl_wpcf7_string_name( $content, $name );
20 return icl_wpcf7_translate( $string_name, $content );
21 }
22
23 $value = trim( $values[0] );
24 if ( ! empty( $value ) ) {
25 $string_name = icl_wpcf7_string_name( $value, $name, 0 );
26 return icl_wpcf7_translate( $string_name, $value );
27 }
28
29 return '';
30 }
31
32 wpcf7_add_shortcode( 'icl', 'icl_wpcf7_shortcode_handler', true );
33
34
35 /* Form tag filter */
36
37 function icl_wpcf7_form_tag_filter( $tag ) {
38 if ( ! is_array( $tag ) )
39 return $tag;
40
41 $type = $tag['type'];
42 $name = $tag['name'];
43 $options = (array) $tag['options'];
44 $values = (array) $tag['values'];
45 $content = $tag['content'];
46
47 $icl_option = array();
48 foreach ( $options as $option ) {
49 if ( 'icl' == $option ) {
50 $icl_option = array( 'icl', null );
51 break;
52 } elseif ( preg_match( '/^icl:(.+)$/', $option, $matches ) ) {
53 $icl_option = array( 'icl', $matches[1] );
54 break;
55 }
56 }
57
58 if ( ! ('icl' == $type || $icl_option ) )
59 return $tag;
60
61 $str_id = $icl_option[1] ? $icl_option[1] : $name;
62
63 if ( ! empty( $values ) ) {
64 $new_values = array();
65 foreach ( $values as $key => $value ) {
66 $string_name = icl_wpcf7_string_name( $value, $str_id, $key );
67 $new_values[$key] = icl_wpcf7_translate( $string_name, $value );
68 }
69
70 if ( preg_match( '/^(?:text|email|textarea|captchar|submit)[*]?$/', $type ) )
71 $tag['values'] = $new_values;
72 else
73 $tag['labels'] = $new_values;
74 }
75
76 $content = trim( $content );
77
78 if ( ! empty( $content ) ) {
79 $string_name = icl_wpcf7_string_name( $content, $str_id );
80 $content = icl_wpcf7_translate( $string_name, $content );
81 $tag['content'] = $content;
82 }
83
84 return $tag;
85 }
86
87 add_filter( 'wpcf7_form_tag', 'icl_wpcf7_form_tag_filter' );
88
89
90 /* Message dispaly filter */
91
92 function icl_wpcf7_display_message_filter( $message ) {
93 $shortcode_manager = new WPCF7_ShortcodeManager();
94 $shortcode_manager->add_shortcode( 'icl', 'icl_wpcf7_shortcode_handler', true );
95
96 return $shortcode_manager->do_shortcode( $message );
97 }
98
99 add_filter( 'wpcf7_display_message', 'icl_wpcf7_display_message_filter' );
100
101
102 /* Collecting strings hook after saving */
103
104 function icl_wpcf7_collect_strings( &$contact_form ) {
105 $scanned = $contact_form->form_scan_shortcode();
106
107 foreach ( $scanned as $tag ) {
108 if ( ! is_array( $tag ) )
109 continue;
110
111 $type = $tag['type'];
112 $name = $tag['name'];
113 $options = (array) $tag['options'];
114 $values = (array) $tag['values'];
115 $content = $tag['content'];
116
117 $icl_option = array();
118 foreach ( $options as $option ) {
119 if ( 'icl' == $option ) {
120 $icl_option = array( 'icl', null );
121 break;
122 } elseif ( preg_match( '/^icl:(.+)$/', $option, $matches ) ) {
123 $icl_option = array( 'icl', $matches[1] );
124 break;
125 }
126 }
127
128 if ( ! ('icl' == $type || $icl_option ) )
129 continue;
130
131 $str_id = $icl_option[1] ? $icl_option[1] : $name;
132
133 if ( ! empty( $content ) ) {
134 $string_name = icl_wpcf7_string_name( $content, $str_id );
135 icl_wpcf7_register_string( $string_name, $content );
136
137 } elseif ( ! empty( $values ) ) {
138 foreach ( $values as $key => $value ) {
139 $value = trim( $value );
140 $string_name = icl_wpcf7_string_name( $value, $str_id, $key );
141 icl_wpcf7_register_string( $string_name, $value );
142 }
143 }
144 }
145
146 /* From messages */
147
148 $messages = (array) $contact_form->messages;
149
150 $shortcode_manager = new WPCF7_ShortcodeManager();
151 $shortcode_manager->add_shortcode( 'icl', create_function( '$tag', 'return null;' ), true );
152
153 foreach ( $messages as $message ) {
154 $tags = $shortcode_manager->scan_shortcode( $message );
155 foreach ( $tags as $tag ) {
156 $name = $tag['name'];
157 $values = (array) $tag['values'];
158 $content = trim( $tag['content'] );
159
160 if ( ! empty( $content ) ) {
161 $string_name = icl_wpcf7_string_name( $content, $name );
162 icl_wpcf7_register_string( $string_name, $content );
163
164 } else {
165 foreach ( $values as $key => $value ) {
166 $value = trim( $value );
167 $string_name = icl_wpcf7_string_name( $value, $name, $key );
168 icl_wpcf7_register_string( $string_name, $value );
169 }
170 }
171 }
172 }
173 }
174
175 add_action( 'wpcf7_after_save', 'icl_wpcf7_collect_strings' );
176
177
178 /* Functions */
179
180 function icl_wpcf7_string_name( $value, $name = '', $key = '' ) {
181 if ( ! empty( $name ) ) {
182 $string_name = '@' . $name;
183 if ( '' !== $key )
184 $string_name .= ' ' . $key;
185 } else {
186 $string_name = '#' . md5( $value );
187 }
188
189 return $string_name;
190 }
191
192 function icl_wpcf7_register_string( $name, $value ) {
193 if ( ! function_exists( 'icl_register_string' ) )
194 return false;
195
196 $context = 'Contact Form 7';
197
198 $value = trim( $value );
199 if ( empty( $value ) )
200 return false;
201
202 icl_register_string( $context, $name, $value );
203 }
204
205 function icl_wpcf7_translate( $name, $value = '' ) {
206 if ( ! function_exists( 'icl_t' ) )
207 return $value;
208
209 if ( empty( $name ) )
210 return $value;
211
212 $context = 'Contact Form 7';
213
214 return icl_t( $context, $name, $value );
215 }
216
217 ?>