1 | <?php
|
---|
2 |
|
---|
3 | function wpcf7_plugin_path( $path = '' ) {
|
---|
4 | return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
|
---|
5 | }
|
---|
6 |
|
---|
7 | function wpcf7_plugin_url( $path = '' ) {
|
---|
8 | global $wp_version;
|
---|
9 |
|
---|
10 | if ( version_compare( $wp_version, '2.8', '<' ) ) { // Using WordPress 2.7
|
---|
11 | $path = path_join( WPCF7_PLUGIN_NAME, $path );
|
---|
12 | return plugins_url( $path );
|
---|
13 | }
|
---|
14 |
|
---|
15 | return plugins_url( $path, WPCF7_PLUGIN_BASENAME );
|
---|
16 | }
|
---|
17 |
|
---|
18 | function wpcf7_table_name() {
|
---|
19 | global $wpdb;
|
---|
20 |
|
---|
21 | return $wpdb->prefix . "contact_form_7";
|
---|
22 | }
|
---|
23 |
|
---|
24 | function wpcf7_table_exists() {
|
---|
25 | global $wpdb;
|
---|
26 |
|
---|
27 | $table_name = wpcf7_table_name();
|
---|
28 |
|
---|
29 | return $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) == $table_name;
|
---|
30 | }
|
---|
31 |
|
---|
32 | // Pre-2.8 compatibility
|
---|
33 | if ( ! function_exists( 'esc_js' ) ) {
|
---|
34 | function esc_js( $text ) {
|
---|
35 | return js_escape( $text );
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | if ( ! function_exists( 'esc_html' ) ) {
|
---|
40 | function esc_html( $text ) {
|
---|
41 | return wp_specialchars( $text );
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | if ( ! function_exists( 'esc_attr' ) ) {
|
---|
46 | function esc_attr( $text ) {
|
---|
47 | return attribute_escape( $text );
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | if ( ! function_exists( 'esc_sql' ) ) {
|
---|
52 | function esc_sql( $text ) {
|
---|
53 | global $wpdb;
|
---|
54 | return $wpdb->escape( $text );
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | require_once WPCF7_PLUGIN_DIR . '/includes/functions.php';
|
---|
59 | require_once WPCF7_PLUGIN_DIR . '/includes/formatting.php';
|
---|
60 | require_once WPCF7_PLUGIN_DIR . '/includes/pipe.php';
|
---|
61 | require_once WPCF7_PLUGIN_DIR . '/includes/shortcodes.php';
|
---|
62 | require_once WPCF7_PLUGIN_DIR . '/includes/classes.php';
|
---|
63 |
|
---|
64 | if ( is_admin() )
|
---|
65 | require_once WPCF7_PLUGIN_DIR . '/admin/admin.php';
|
---|
66 |
|
---|
67 | function wpcf7_contact_forms() {
|
---|
68 | global $wpdb;
|
---|
69 |
|
---|
70 | $table_name = wpcf7_table_name();
|
---|
71 |
|
---|
72 | return $wpdb->get_results( "SELECT cf7_unit_id as id, title FROM $table_name" );
|
---|
73 | }
|
---|
74 |
|
---|
75 | $wpcf7_contact_form = null;
|
---|
76 |
|
---|
77 | $wpcf7_processing_within = null;
|
---|
78 | $wpcf7_unit_count = null;
|
---|
79 | $wpcf7_widget_count = null;
|
---|
80 |
|
---|
81 | function wpcf7_ajax_json_echo() {
|
---|
82 | global $wpcf7_contact_form;
|
---|
83 |
|
---|
84 | $echo = '';
|
---|
85 |
|
---|
86 | if ( isset( $_POST['_wpcf7'] ) ) {
|
---|
87 | $id = (int) $_POST['_wpcf7'];
|
---|
88 | $unit_tag = $_POST['_wpcf7_unit_tag'];
|
---|
89 |
|
---|
90 | if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) {
|
---|
91 | $validation = $wpcf7_contact_form->validate();
|
---|
92 |
|
---|
93 | $items = array(
|
---|
94 | 'mailSent' => false,
|
---|
95 | 'into' => '#' . $unit_tag,
|
---|
96 | 'captcha' => null );
|
---|
97 |
|
---|
98 | $items = apply_filters( 'wpcf7_ajax_json_echo', $items );
|
---|
99 |
|
---|
100 | if ( ! $validation['valid'] ) { // Validation error occured
|
---|
101 | $invalids = array();
|
---|
102 | foreach ( $validation['reason'] as $name => $reason ) {
|
---|
103 | $invalids[] = array(
|
---|
104 | 'into' => 'span.wpcf7-form-control-wrap.' . $name,
|
---|
105 | 'message' => $reason );
|
---|
106 | }
|
---|
107 |
|
---|
108 | $items['message'] = $wpcf7_contact_form->message( 'validation_error' );
|
---|
109 | $items['invalids'] = $invalids;
|
---|
110 |
|
---|
111 | } elseif ( ! $wpcf7_contact_form->accepted() ) { // Not accepted terms
|
---|
112 | $items['message'] = $wpcf7_contact_form->message( 'accept_terms' );
|
---|
113 |
|
---|
114 | } elseif ( $wpcf7_contact_form->akismet() ) { // Spam!
|
---|
115 | $items['message'] = $wpcf7_contact_form->message( 'akismet_says_spam' );
|
---|
116 | $items['spam'] = true;
|
---|
117 |
|
---|
118 | } elseif ( $wpcf7_contact_form->mail() ) {
|
---|
119 | $items['mailSent'] = true;
|
---|
120 | $items['message'] = $wpcf7_contact_form->message( 'mail_sent_ok' );
|
---|
121 |
|
---|
122 | $on_sent_ok = $wpcf7_contact_form->additional_setting( 'on_sent_ok', false );
|
---|
123 | if ( ! empty( $on_sent_ok ) ) {
|
---|
124 | $on_sent_ok = array_map( 'wpcf7_strip_quote', $on_sent_ok );
|
---|
125 | } else {
|
---|
126 | $on_sent_ok = null;
|
---|
127 | }
|
---|
128 | $items['onSentOk'] = $on_sent_ok;
|
---|
129 |
|
---|
130 | do_action_ref_array( 'wpcf7_mail_sent', array( &$wpcf7_contact_form ) );
|
---|
131 |
|
---|
132 | } else {
|
---|
133 | $items['message'] = $wpcf7_contact_form->message( 'mail_sent_ng' );
|
---|
134 | }
|
---|
135 |
|
---|
136 | // remove upload files
|
---|
137 | foreach ( (array) $wpcf7_contact_form->uploaded_files as $name => $path ) {
|
---|
138 | @unlink( $path );
|
---|
139 | }
|
---|
140 |
|
---|
141 | $wpcf7_contact_form = null;
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | $echo = wpcf7_json( $items );
|
---|
146 |
|
---|
147 | if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) {
|
---|
148 | @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
|
---|
149 | echo $echo;
|
---|
150 | } else {
|
---|
151 | @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
|
---|
152 | echo '<textarea>' . $echo . '</textarea>';
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | function wpcf7_process_nonajax_submitting() {
|
---|
157 | global $wpcf7_contact_form;
|
---|
158 |
|
---|
159 | if ( ! isset($_POST['_wpcf7'] ) )
|
---|
160 | return;
|
---|
161 |
|
---|
162 | $id = (int) $_POST['_wpcf7'];
|
---|
163 |
|
---|
164 | if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) {
|
---|
165 | $validation = $wpcf7_contact_form->validate();
|
---|
166 |
|
---|
167 | if ( ! $validation['valid'] ) {
|
---|
168 | $_POST['_wpcf7_validation_errors'] = array( 'id' => $id, 'messages' => $validation['reason'] );
|
---|
169 | } elseif ( ! $wpcf7_contact_form->accepted() ) { // Not accepted terms
|
---|
170 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'accept_terms' ) );
|
---|
171 | } elseif ( $wpcf7_contact_form->akismet() ) { // Spam!
|
---|
172 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'akismet_says_spam' ), 'spam' => true );
|
---|
173 | } elseif ( $wpcf7_contact_form->mail() ) {
|
---|
174 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => true, 'message' => $wpcf7_contact_form->message( 'mail_sent_ok' ) );
|
---|
175 |
|
---|
176 | do_action_ref_array( 'wpcf7_mail_sent', array( &$wpcf7_contact_form ) );
|
---|
177 | } else {
|
---|
178 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'mail_sent_ng' ) );
|
---|
179 | }
|
---|
180 |
|
---|
181 | // remove upload files
|
---|
182 | foreach ( (array) $wpcf7_contact_form->uploaded_files as $name => $path ) {
|
---|
183 | @unlink( $path );
|
---|
184 | }
|
---|
185 |
|
---|
186 | $wpcf7_contact_form = null;
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | function wpcf7_the_content_filter( $content ) {
|
---|
191 | global $wpcf7_processing_within, $wpcf7_unit_count;
|
---|
192 |
|
---|
193 | $wpcf7_processing_within = 'p' . get_the_ID();
|
---|
194 | $wpcf7_unit_count = 0;
|
---|
195 |
|
---|
196 | return $content;
|
---|
197 | }
|
---|
198 |
|
---|
199 | add_filter( 'the_content', 'wpcf7_the_content_filter', 9 );
|
---|
200 |
|
---|
201 | function wpcf7_widget_text_filter( $content ) {
|
---|
202 | global $wpcf7_widget_count, $wpcf7_processing_within, $wpcf7_unit_count;
|
---|
203 |
|
---|
204 | $wpcf7_widget_count += 1;
|
---|
205 | $wpcf7_processing_within = 'w' . $wpcf7_widget_count;
|
---|
206 | $wpcf7_unit_count = 0;
|
---|
207 |
|
---|
208 | $regex = '/\[\s*contact-form\s+(\d+(?:\s+.*)?)\]/';
|
---|
209 | return preg_replace_callback( $regex, 'wpcf7_widget_text_filter_callback', $content );
|
---|
210 | }
|
---|
211 |
|
---|
212 | add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 );
|
---|
213 |
|
---|
214 | function wpcf7_widget_text_filter_callback( $matches ) {
|
---|
215 | return do_shortcode( $matches[0] );
|
---|
216 | }
|
---|
217 |
|
---|
218 | function wpcf7_contact_form_tag_func( $atts ) {
|
---|
219 | global $wpcf7_contact_form, $wpcf7_unit_count, $wpcf7_processing_within;
|
---|
220 |
|
---|
221 | if ( is_string( $atts ) )
|
---|
222 | $atts = explode( ' ', $atts, 2 );
|
---|
223 |
|
---|
224 | $atts = (array) $atts;
|
---|
225 |
|
---|
226 | $id = (int) array_shift( $atts );
|
---|
227 |
|
---|
228 | if ( ! ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) )
|
---|
229 | return '[contact-form 404 "Not Found"]';
|
---|
230 |
|
---|
231 | $wpcf7_unit_count += 1;
|
---|
232 |
|
---|
233 | $unit_tag = 'wpcf7-f' . $id . '-' . $wpcf7_processing_within . '-o' . $wpcf7_unit_count;
|
---|
234 | $wpcf7_contact_form->unit_tag = $unit_tag;
|
---|
235 |
|
---|
236 | $form = $wpcf7_contact_form->form_html();
|
---|
237 |
|
---|
238 | $wpcf7_contact_form = null;
|
---|
239 |
|
---|
240 | return $form;
|
---|
241 | }
|
---|
242 |
|
---|
243 | add_shortcode( 'contact-form', 'wpcf7_contact_form_tag_func' );
|
---|
244 |
|
---|
245 | function wpcf7_wp_head() {
|
---|
246 | $stylesheet_url = wpcf7_plugin_url( 'stylesheet.css' );
|
---|
247 | echo '<link rel="stylesheet" href="' . $stylesheet_url . '" type="text/css" />';
|
---|
248 |
|
---|
249 | if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
|
---|
250 | $stylesheet_rtl_url = wpcf7_plugin_url( 'stylesheet-rtl.css' );
|
---|
251 | echo '<link rel="stylesheet" href="' . $stylesheet_rtl_url . '" type="text/css" />';
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | if ( WPCF7_LOAD_CSS )
|
---|
256 | add_action( 'wp_head', 'wpcf7_wp_head' );
|
---|
257 |
|
---|
258 | /* Loading modules */
|
---|
259 |
|
---|
260 | function wpcf7_load_modules() {
|
---|
261 | $dir = WPCF7_PLUGIN_MODULES_DIR;
|
---|
262 |
|
---|
263 | if ( ! ( is_dir( $dir ) && $dh = opendir( $dir ) ) )
|
---|
264 | return false;
|
---|
265 |
|
---|
266 | while ( ( $module = readdir( $dh ) ) !== false ) {
|
---|
267 | if ( substr( $module, -4 ) == '.php' )
|
---|
268 | include_once $dir . '/' . $module;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | add_action( 'init', 'wpcf7_load_modules' );
|
---|
273 |
|
---|
274 | function wpcf7_enqueue_scripts() {
|
---|
275 | $in_footer = true;
|
---|
276 | if ( 'header' === WPCF7_LOAD_JS )
|
---|
277 | $in_footer = false;
|
---|
278 |
|
---|
279 | wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'contact-form-7.js' ),
|
---|
280 | array('jquery', 'jquery-form'), WPCF7_VERSION, $in_footer );
|
---|
281 | }
|
---|
282 |
|
---|
283 | if ( ! is_admin() && WPCF7_LOAD_JS )
|
---|
284 | add_action( 'init', 'wpcf7_enqueue_scripts' );
|
---|
285 |
|
---|
286 | function wpcf7_load_plugin_textdomain() { // l10n
|
---|
287 | load_plugin_textdomain( 'wpcf7',
|
---|
288 | 'wp-content/plugins/contact-form-7/languages', 'contact-form-7/languages' );
|
---|
289 | }
|
---|
290 |
|
---|
291 | add_action( 'init', 'wpcf7_load_plugin_textdomain' );
|
---|
292 |
|
---|
293 | function wpcf7_init_switch() {
|
---|
294 | if ( 'POST' == $_SERVER['REQUEST_METHOD'] && 1 == (int) $_POST['_wpcf7_is_ajax_call'] ) {
|
---|
295 | wpcf7_ajax_json_echo();
|
---|
296 | exit();
|
---|
297 | } elseif ( ! is_admin() ) {
|
---|
298 | wpcf7_process_nonajax_submitting();
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | add_action( 'init', 'wpcf7_init_switch', 11 );
|
---|
303 |
|
---|
304 | ?> |
---|