contact-form-7
Last commit date
admin
16 years ago
images
18 years ago
includes
16 years ago
languages
16 years ago
modules
16 years ago
README.txt
16 years ago
contact-form-7.js
17 years ago
screenshot-1.png
17 years ago
stylesheet-rtl.css
17 years ago
stylesheet.css
17 years ago
wp-contact-form-7.php
16 years ago
wp-contact-form-7.php
356 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Contact Form 7 |
| 4 | Plugin URI: http://ideasilo.wordpress.com/2007/04/30/contact-form-7/ |
| 5 | Description: Just another contact form plugin. Simple but flexible. |
| 6 | Author: Takayuki Miyoshi |
| 7 | Version: 2.0-beta |
| 8 | Author URI: http://ideasilo.wordpress.com/ |
| 9 | */ |
| 10 | |
| 11 | /* Copyright 2007-2009 Takayuki Miyoshi (email: takayukister at gmail.com) |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or modify |
| 14 | it under the terms of the GNU General Public License as published by |
| 15 | the Free Software Foundation; either version 2 of the License, or |
| 16 | (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, |
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | GNU General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | define( 'WPCF7_VERSION', '2.0-beta' ); |
| 29 | |
| 30 | if ( ! defined( 'WPCF7_PLUGIN_DIR' ) ) |
| 31 | define( 'WPCF7_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . plugin_basename( dirname( __FILE__ ) ) ); |
| 32 | |
| 33 | if ( ! defined( 'WPCF7_PLUGIN_URL' ) ) |
| 34 | define( 'WPCF7_PLUGIN_URL', WP_PLUGIN_URL . '/' . plugin_basename( dirname( __FILE__ ) ) ); |
| 35 | |
| 36 | if ( ! defined( 'WPCF7_PLUGIN_MODULES_DIR' ) ) |
| 37 | define( 'WPCF7_PLUGIN_MODULES_DIR', WPCF7_PLUGIN_DIR . '/modules' ); |
| 38 | |
| 39 | if ( ! defined( 'WPCF7_PLUGIN_BASENAME' ) ) |
| 40 | define( 'WPCF7_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 41 | |
| 42 | if ( ! defined( 'WPCF7_LOAD_JS' ) ) |
| 43 | define( 'WPCF7_LOAD_JS', true ); |
| 44 | |
| 45 | if ( ! defined( 'WPCF7_LOAD_CSS' ) ) |
| 46 | define( 'WPCF7_LOAD_CSS', true ); |
| 47 | |
| 48 | if ( ! defined( 'WPCF7_AUTOP' ) ) |
| 49 | define( 'WPCF7_AUTOP', true ); |
| 50 | |
| 51 | if ( ! defined( 'WPCF7_USE_PIPE' ) ) |
| 52 | define( 'WPCF7_USE_PIPE', true ); |
| 53 | |
| 54 | /* If you or your client hate to see about donation, set this value false. */ |
| 55 | if ( ! defined( 'WPCF7_SHOW_DONATION_LINK' ) ) |
| 56 | define( 'WPCF7_SHOW_DONATION_LINK', true ); |
| 57 | |
| 58 | if ( ! defined( 'WPCF7_ADMIN_READ_CAPABILITY' ) ) |
| 59 | define( 'WPCF7_ADMIN_READ_CAPABILITY', 'edit_posts' ); |
| 60 | |
| 61 | if ( ! defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ) |
| 62 | define( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY', 'publish_pages' ); |
| 63 | |
| 64 | function wpcf7_plugin_url( $path = '' ) { |
| 65 | global $wp_version; |
| 66 | |
| 67 | if ( version_compare( $wp_version, '2.8', '<' ) ) { // Using WordPress 2.7 |
| 68 | $folder = dirname( plugin_basename( __FILE__ ) ); |
| 69 | if ( '.' != $folder ) |
| 70 | $path = path_join( ltrim( $folder, '/' ), $path ); |
| 71 | |
| 72 | return plugins_url( $path ); |
| 73 | } |
| 74 | |
| 75 | return plugins_url( $path, __FILE__ ); |
| 76 | } |
| 77 | |
| 78 | function wpcf7_table_name() { |
| 79 | global $wpdb; |
| 80 | |
| 81 | return $wpdb->prefix . "contact_form_7"; |
| 82 | } |
| 83 | |
| 84 | // Pre-2.8 compatibility |
| 85 | if ( ! function_exists( 'esc_js' ) ) { |
| 86 | function esc_js( $text ) { |
| 87 | return js_escape( $text ); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if ( ! function_exists( 'esc_html' ) ) { |
| 92 | function esc_html( $text ) { |
| 93 | return wp_specialchars( $text ); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if ( ! function_exists( 'esc_attr' ) ) { |
| 98 | function esc_attr( $text ) { |
| 99 | return attribute_escape( $text ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if ( ! function_exists( 'esc_sql' ) ) { |
| 104 | function esc_sql( $text ) { |
| 105 | global $wpdb; |
| 106 | return $wpdb->escape( $text ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | require_once WPCF7_PLUGIN_DIR . '/includes/functions.php'; |
| 111 | require_once WPCF7_PLUGIN_DIR . '/includes/formatting.php'; |
| 112 | require_once WPCF7_PLUGIN_DIR . '/includes/pipe.php'; |
| 113 | require_once WPCF7_PLUGIN_DIR . '/includes/shortcodes.php'; |
| 114 | require_once WPCF7_PLUGIN_DIR . '/includes/classes.php'; |
| 115 | |
| 116 | if ( is_admin() ) |
| 117 | require_once WPCF7_PLUGIN_DIR . '/admin/admin.php'; |
| 118 | |
| 119 | function wpcf7_contact_forms() { |
| 120 | global $wpdb; |
| 121 | |
| 122 | $table_name = wpcf7_table_name(); |
| 123 | |
| 124 | return $wpdb->get_results( "SELECT cf7_unit_id as id, title FROM $table_name" ); |
| 125 | } |
| 126 | |
| 127 | $wpcf7_contact_form = null; |
| 128 | |
| 129 | $wpcf7_processing_within = null; |
| 130 | $wpcf7_unit_count = null; |
| 131 | $wpcf7_widget_count = null; |
| 132 | |
| 133 | function wpcf7_ajax_json_echo() { |
| 134 | global $wpcf7_contact_form; |
| 135 | |
| 136 | $echo = ''; |
| 137 | |
| 138 | if ( isset( $_POST['_wpcf7'] ) ) { |
| 139 | $id = (int) $_POST['_wpcf7']; |
| 140 | $unit_tag = $_POST['_wpcf7_unit_tag']; |
| 141 | |
| 142 | if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) { |
| 143 | $validation = $wpcf7_contact_form->validate(); |
| 144 | |
| 145 | $items = array( |
| 146 | 'mailSent' => false, |
| 147 | 'into' => '#' . $unit_tag, |
| 148 | 'captcha' => $captcha ); |
| 149 | |
| 150 | $items = apply_filters( 'wpcf7_ajax_json_echo', $items ); |
| 151 | |
| 152 | if ( ! $validation['valid'] ) { // Validation error occured |
| 153 | $invalids = array(); |
| 154 | foreach ( $validation['reason'] as $name => $reason ) { |
| 155 | $invalids[] = array( |
| 156 | 'into' => 'span.wpcf7-form-control-wrap.' . $name, |
| 157 | 'message' => $reason ); |
| 158 | } |
| 159 | |
| 160 | $items['message'] = $wpcf7_contact_form->message( 'validation_error' ); |
| 161 | $items['invalids'] = $invalids; |
| 162 | |
| 163 | } elseif ( ! $wpcf7_contact_form->accepted() ) { // Not accepted terms |
| 164 | $items['message'] = $wpcf7_contact_form->message( 'accept_terms' ); |
| 165 | |
| 166 | } elseif ( $wpcf7_contact_form->akismet() ) { // Spam! |
| 167 | $items['message'] = $wpcf7_contact_form->message( 'akismet_says_spam' ); |
| 168 | $items['spam'] = true; |
| 169 | |
| 170 | } elseif ( $wpcf7_contact_form->mail() ) { |
| 171 | $items['mailSent'] = true; |
| 172 | $items['message'] = $wpcf7_contact_form->message( 'mail_sent_ok' ); |
| 173 | |
| 174 | $on_sent_ok = $wpcf7_contact_form->additional_setting( 'on_sent_ok', false ); |
| 175 | if ( ! empty( $on_sent_ok ) ) { |
| 176 | $on_sent_ok = array_map( 'wpcf7_strip_quote', $on_sent_ok ); |
| 177 | } else { |
| 178 | $on_sent_ok = null; |
| 179 | } |
| 180 | $items['onSentOk'] = $on_sent_ok; |
| 181 | |
| 182 | do_action_ref_array( 'wpcf7_mail_sent', array( &$wpcf7_contact_form ) ); |
| 183 | |
| 184 | } else { |
| 185 | $items['message'] = $wpcf7_contact_form->message( 'mail_sent_ng' ); |
| 186 | } |
| 187 | |
| 188 | // remove upload files |
| 189 | foreach ( (array) $wpcf7_contact_form->uploaded_files as $name => $path ) { |
| 190 | @unlink( $path ); |
| 191 | } |
| 192 | |
| 193 | $wpcf7_contact_form = null; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | $echo = wpcf7_json( $items ); |
| 198 | |
| 199 | if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) { |
| 200 | @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
| 201 | echo $echo; |
| 202 | } else { |
| 203 | @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
| 204 | echo '<textarea>' . $echo . '</textarea>'; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | function wpcf7_process_nonajax_submitting() { |
| 209 | global $wpcf7_contact_form; |
| 210 | |
| 211 | if ( ! isset($_POST['_wpcf7'] ) ) |
| 212 | return; |
| 213 | |
| 214 | $id = (int) $_POST['_wpcf7']; |
| 215 | |
| 216 | if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) { |
| 217 | $validation = $wpcf7_contact_form->validate(); |
| 218 | |
| 219 | if ( ! $validation['valid'] ) { |
| 220 | $_POST['_wpcf7_validation_errors'] = array( 'id' => $id, 'messages' => $validation['reason'] ); |
| 221 | } elseif ( ! $wpcf7_contact_form->accepted() ) { // Not accepted terms |
| 222 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'accept_terms' ) ); |
| 223 | } elseif ( $wpcf7_contact_form->akismet() ) { // Spam! |
| 224 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'akismet_says_spam' ), 'spam' => true ); |
| 225 | } elseif ( $wpcf7_contact_form->mail() ) { |
| 226 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => true, 'message' => $wpcf7_contact_form->message( 'mail_sent_ok' ) ); |
| 227 | |
| 228 | do_action_ref_array( 'wpcf7_mail_sent', array( &$wpcf7_contact_form ) ); |
| 229 | } else { |
| 230 | $_POST['_wpcf7_mail_sent'] = array( 'id' => $id, 'ok' => false, 'message' => $wpcf7_contact_form->message( 'mail_sent_ng' ) ); |
| 231 | } |
| 232 | |
| 233 | // remove upload files |
| 234 | foreach ( (array) $wpcf7_contact_form->uploaded_files as $name => $path ) { |
| 235 | @unlink( $path ); |
| 236 | } |
| 237 | |
| 238 | $wpcf7_contact_form = null; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | function wpcf7_the_content_filter( $content ) { |
| 243 | global $wpcf7_processing_within, $wpcf7_unit_count; |
| 244 | |
| 245 | $wpcf7_processing_within = 'p' . get_the_ID(); |
| 246 | $wpcf7_unit_count = 0; |
| 247 | |
| 248 | return $content; |
| 249 | } |
| 250 | |
| 251 | add_filter( 'the_content', 'wpcf7_the_content_filter', 9 ); |
| 252 | |
| 253 | function wpcf7_widget_text_filter( $content ) { |
| 254 | global $wpcf7_widget_count, $wpcf7_processing_within, $wpcf7_unit_count; |
| 255 | |
| 256 | $wpcf7_widget_count += 1; |
| 257 | $wpcf7_processing_within = 'w' . $wpcf7_widget_count; |
| 258 | $wpcf7_unit_count = 0; |
| 259 | |
| 260 | $regex = '/\[\s*contact-form\s+(\d+(?:\s+.*)?)\]/'; |
| 261 | return preg_replace_callback( $regex, 'wpcf7_widget_text_filter_callback', $content ); |
| 262 | } |
| 263 | |
| 264 | add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 ); |
| 265 | |
| 266 | function wpcf7_widget_text_filter_callback( $matches ) { |
| 267 | return do_shortcode( $matches[0] ); |
| 268 | } |
| 269 | |
| 270 | function wpcf7_contact_form_tag_func( $atts ) { |
| 271 | global $wpcf7_contact_form, $wpcf7_unit_count, $wpcf7_processing_within; |
| 272 | |
| 273 | if ( is_string( $atts ) ) |
| 274 | $atts = explode( ' ', $atts, 2 ); |
| 275 | |
| 276 | $atts = (array) $atts; |
| 277 | |
| 278 | $id = (int) array_shift( $atts ); |
| 279 | |
| 280 | if ( ! ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) ) |
| 281 | return '[contact-form 404 "Not Found"]'; |
| 282 | |
| 283 | $wpcf7_unit_count += 1; |
| 284 | |
| 285 | $unit_tag = 'wpcf7-f' . $id . '-' . $wpcf7_processing_within . '-o' . $wpcf7_unit_count; |
| 286 | $wpcf7_contact_form->unit_tag = $unit_tag; |
| 287 | |
| 288 | $form = $wpcf7_contact_form->form_html(); |
| 289 | |
| 290 | $wpcf7_contact_form = null; |
| 291 | |
| 292 | return $form; |
| 293 | } |
| 294 | |
| 295 | add_shortcode( 'contact-form', 'wpcf7_contact_form_tag_func' ); |
| 296 | |
| 297 | function wpcf7_wp_head() { |
| 298 | $stylesheet_url = wpcf7_plugin_url( 'stylesheet.css' ); |
| 299 | echo '<link rel="stylesheet" href="' . $stylesheet_url . '" type="text/css" />'; |
| 300 | |
| 301 | if ( 'rtl' == get_bloginfo( 'text_direction' ) ) { |
| 302 | $stylesheet_rtl_url = wpcf7_plugin_url( 'stylesheet-rtl.css' ); |
| 303 | echo '<link rel="stylesheet" href="' . $stylesheet_rtl_url . '" type="text/css" />'; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if ( WPCF7_LOAD_CSS ) |
| 308 | add_action( 'wp_head', 'wpcf7_wp_head' ); |
| 309 | |
| 310 | /* Loading modules */ |
| 311 | |
| 312 | function wpcf7_load_modules() { |
| 313 | $dir = WPCF7_PLUGIN_MODULES_DIR; |
| 314 | |
| 315 | if ( ! ( is_dir( $dir ) && $dh = opendir( $dir ) ) ) |
| 316 | return false; |
| 317 | |
| 318 | while ( ( $module = readdir( $dh ) ) !== false ) { |
| 319 | if ( substr( $module, -4 ) == '.php' ) |
| 320 | include_once $dir . '/' . $module; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | add_action( 'init', 'wpcf7_load_modules' ); |
| 325 | |
| 326 | function wpcf7_enqueue_scripts() { |
| 327 | $in_footer = true; |
| 328 | if ( 'header' === WPCF7_LOAD_JS ) |
| 329 | $in_footer = false; |
| 330 | |
| 331 | wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'contact-form-7.js' ), |
| 332 | array('jquery', 'jquery-form'), WPCF7_VERSION, $in_footer ); |
| 333 | } |
| 334 | |
| 335 | if ( ! is_admin() && WPCF7_LOAD_JS ) |
| 336 | add_action( 'init', 'wpcf7_enqueue_scripts' ); |
| 337 | |
| 338 | function wpcf7_load_plugin_textdomain() { // l10n |
| 339 | load_plugin_textdomain( 'wpcf7', |
| 340 | 'wp-content/plugins/contact-form-7/languages', 'contact-form-7/languages' ); |
| 341 | } |
| 342 | |
| 343 | add_action( 'init', 'wpcf7_load_plugin_textdomain' ); |
| 344 | |
| 345 | function wpcf7_init_switch() { |
| 346 | if ( 'POST' == $_SERVER['REQUEST_METHOD'] && 1 == (int) $_POST['_wpcf7_is_ajax_call'] ) { |
| 347 | wpcf7_ajax_json_echo(); |
| 348 | exit(); |
| 349 | } elseif ( ! is_admin() ) { |
| 350 | wpcf7_process_nonajax_submitting(); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | add_action( 'init', 'wpcf7_init_switch', 11 ); |
| 355 | |
| 356 | ?> |