css
11 years ago
js
11 years ago
capabilities.php
13 years ago
contact-form-template.php
11 years ago
contact-form.php
11 years ago
controller.php
11 years ago
formatting.php
11 years ago
functions.php
11 years ago
mail.php
11 years ago
pipe.php
12 years ago
shortcodes.php
11 years ago
submission.php
11 years ago
upgrade.php
11 years ago
validation.php
11 years ago
functions.php
478 lines
| 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 | $url = plugins_url( $path, WPCF7_PLUGIN ); |
| 9 | |
| 10 | if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) { |
| 11 | $url = 'https:' . substr( $url, 5 ); |
| 12 | } |
| 13 | |
| 14 | return $url; |
| 15 | } |
| 16 | |
| 17 | function wpcf7_upload_dir( $type = false ) { |
| 18 | $uploads = wp_upload_dir(); |
| 19 | |
| 20 | $uploads = apply_filters( 'wpcf7_upload_dir', array( |
| 21 | 'dir' => $uploads['basedir'], |
| 22 | 'url' => $uploads['baseurl'] ) ); |
| 23 | |
| 24 | if ( 'dir' == $type ) |
| 25 | return $uploads['dir']; |
| 26 | if ( 'url' == $type ) |
| 27 | return $uploads['url']; |
| 28 | |
| 29 | return $uploads; |
| 30 | } |
| 31 | |
| 32 | function wpcf7_l10n() { |
| 33 | static $l10n = array(); |
| 34 | |
| 35 | if ( ! empty( $l10n ) ) { |
| 36 | return $l10n; |
| 37 | } |
| 38 | |
| 39 | $l10n = array( |
| 40 | 'af' => __( 'Afrikaans', 'contact-form-7' ), |
| 41 | 'sq' => __( 'Albanian', 'contact-form-7' ), |
| 42 | 'ar' => __( 'Arabic', 'contact-form-7' ), |
| 43 | 'hy_AM' => __( 'Armenian', 'contact-form-7' ), |
| 44 | 'az' => __( 'Azerbaijani', 'contact-form-7' ), |
| 45 | 'bn_BD' => __( 'Bangla', 'contact-form-7' ), |
| 46 | 'eu' => __( 'Basque', 'contact-form-7' ), |
| 47 | 'be_BY' => __( 'Belarusian', 'contact-form-7' ), |
| 48 | 'bs_BA' => __( 'Bosnian', 'contact-form-7' ), |
| 49 | 'bg_BG' => __( 'Bulgarian', 'contact-form-7' ), |
| 50 | 'ca' => __( 'Catalan', 'contact-form-7' ), |
| 51 | 'ckb' => __( 'Central Kurdish', 'contact-form-7' ), |
| 52 | 'zh_CN' => __( 'Chinese (China)', 'contact-form-7' ), |
| 53 | 'zh_TW' => __( 'Chinese (Taiwan)', 'contact-form-7' ), |
| 54 | 'hr' => __( 'Croatian', 'contact-form-7' ), |
| 55 | 'cs_CZ' => __( 'Czech', 'contact-form-7' ), |
| 56 | 'da_DK' => __( 'Danish', 'contact-form-7' ), |
| 57 | 'nl_NL' => __( 'Dutch', 'contact-form-7' ), |
| 58 | 'en_US' => __( 'English (United States)', 'contact-form-7' ), |
| 59 | 'eo_EO' => __( 'Esperanto', 'contact-form-7' ), |
| 60 | 'et' => __( 'Estonian', 'contact-form-7' ), |
| 61 | 'fi' => __( 'Finnish', 'contact-form-7' ), |
| 62 | 'fr_FR' => __( 'French (France)', 'contact-form-7' ), |
| 63 | 'gl_ES' => __( 'Galician', 'contact-form-7' ), |
| 64 | 'gu_IN' => __( 'Gujarati', 'contact-form-7' ), |
| 65 | 'ka_GE' => __( 'Georgian', 'contact-form-7' ), |
| 66 | 'de_DE' => __( 'German', 'contact-form-7' ), |
| 67 | 'el' => __( 'Greek', 'contact-form-7' ), |
| 68 | 'ht' => __( 'Haitian', 'contact-form-7' ), |
| 69 | 'he_IL' => __( 'Hebrew', 'contact-form-7' ), |
| 70 | 'hi_IN' => __( 'Hindi', 'contact-form-7' ), |
| 71 | 'hu_HU' => __( 'Hungarian', 'contact-form-7' ), |
| 72 | 'bn_IN' => __( 'Indian Bengali', 'contact-form-7' ), |
| 73 | 'id_ID' => __( 'Indonesian', 'contact-form-7' ), |
| 74 | 'ga_IE' => __( 'Irish', 'contact-form-7' ), |
| 75 | 'it_IT' => __( 'Italian', 'contact-form-7' ), |
| 76 | 'ja' => __( 'Japanese', 'contact-form-7' ), |
| 77 | 'ko_KR' => __( 'Korean', 'contact-form-7' ), |
| 78 | 'lv' => __( 'Latvian', 'contact-form-7' ), |
| 79 | 'lt_LT' => __( 'Lithuanian', 'contact-form-7' ), |
| 80 | 'mk_MK' => __( 'Macedonian', 'contact-form-7' ), |
| 81 | 'ms_MY' => __( 'Malay', 'contact-form-7' ), |
| 82 | 'ml_IN' => __( 'Malayalam', 'contact-form-7' ), |
| 83 | 'mt_MT' => __( 'Maltese', 'contact-form-7' ), |
| 84 | 'nb_NO' => __( 'Norwegian (Bokmål)', 'contact-form-7' ), |
| 85 | 'fa_IR' => __( 'Persian', 'contact-form-7' ), |
| 86 | 'pl_PL' => __( 'Polish', 'contact-form-7' ), |
| 87 | 'pt_BR' => __( 'Portuguese (Brazil)', 'contact-form-7' ), |
| 88 | 'pt_PT' => __( 'Portuguese (Portugal)', 'contact-form-7' ), |
| 89 | 'pa_IN' => __( 'Punjabi', 'contact-form-7' ), |
| 90 | 'ru_RU' => __( 'Russian', 'contact-form-7' ), |
| 91 | 'ro_RO' => __( 'Romanian', 'contact-form-7' ), |
| 92 | 'sr_RS' => __( 'Serbian', 'contact-form-7' ), |
| 93 | 'si_LK' => __( 'Sinhala', 'contact-form-7' ), |
| 94 | 'sk_SK' => __( 'Slovak', 'contact-form-7' ), |
| 95 | 'sl_SI' => __( 'Slovene', 'contact-form-7' ), |
| 96 | 'es_ES' => __( 'Spanish (Spain)', 'contact-form-7' ), |
| 97 | 'sv_SE' => __( 'Swedish', 'contact-form-7' ), |
| 98 | 'ta' => __( 'Tamil', 'contact-form-7' ), |
| 99 | 'th' => __( 'Thai', 'contact-form-7' ), |
| 100 | 'tl' => __( 'Tagalog', 'contact-form-7' ), |
| 101 | 'tr_TR' => __( 'Turkish', 'contact-form-7' ), |
| 102 | 'uk' => __( 'Ukrainian', 'contact-form-7' ), |
| 103 | 'vi' => __( 'Vietnamese', 'contact-form-7' ) |
| 104 | ); |
| 105 | |
| 106 | return $l10n; |
| 107 | } |
| 108 | |
| 109 | function wpcf7_is_valid_locale( $locale ) { |
| 110 | $l10n = wpcf7_l10n(); |
| 111 | return isset( $l10n[$locale] ); |
| 112 | } |
| 113 | |
| 114 | function wpcf7_is_rtl( $locale = '' ) { |
| 115 | if ( empty( $locale ) ) { |
| 116 | return function_exists( 'is_rtl' ) ? is_rtl() : false; |
| 117 | } |
| 118 | |
| 119 | $rtl_locales = array( |
| 120 | 'ar' => 'Arabic', |
| 121 | 'he_IL' => 'Hebrew', |
| 122 | 'fa_IR' => 'Persian' ); |
| 123 | |
| 124 | return isset( $rtl_locales[$locale] ); |
| 125 | } |
| 126 | |
| 127 | function wpcf7_ajax_loader() { |
| 128 | $url = wpcf7_plugin_url( 'images/ajax-loader.gif' ); |
| 129 | |
| 130 | return apply_filters( 'wpcf7_ajax_loader', $url ); |
| 131 | } |
| 132 | |
| 133 | function wpcf7_verify_nonce( $nonce, $action = -1 ) { |
| 134 | if ( substr( wp_hash( $action, 'nonce' ), -12, 10 ) == $nonce ) |
| 135 | return true; |
| 136 | |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | function wpcf7_create_nonce( $action = -1 ) { |
| 141 | return substr( wp_hash( $action, 'nonce' ), -12, 10 ); |
| 142 | } |
| 143 | |
| 144 | function wpcf7_blacklist_check( $target ) { |
| 145 | $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
| 146 | |
| 147 | if ( empty( $mod_keys ) ) { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | $words = explode( "\n", $mod_keys ); |
| 152 | |
| 153 | foreach ( (array) $words as $word ) { |
| 154 | $word = trim( $word ); |
| 155 | |
| 156 | if ( empty( $word ) || 256 < strlen( $word ) ) { |
| 157 | continue; |
| 158 | } |
| 159 | |
| 160 | $pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) ); |
| 161 | |
| 162 | if ( preg_match( $pattern, $target ) ) { |
| 163 | return true; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | function wpcf7_array_flatten( $input ) { |
| 171 | if ( ! is_array( $input ) ) |
| 172 | return array( $input ); |
| 173 | |
| 174 | $output = array(); |
| 175 | |
| 176 | foreach ( $input as $value ) |
| 177 | $output = array_merge( $output, wpcf7_array_flatten( $value ) ); |
| 178 | |
| 179 | return $output; |
| 180 | } |
| 181 | |
| 182 | function wpcf7_flat_join( $input ) { |
| 183 | $input = wpcf7_array_flatten( $input ); |
| 184 | $output = array(); |
| 185 | |
| 186 | foreach ( (array) $input as $value ) |
| 187 | $output[] = trim( (string) $value ); |
| 188 | |
| 189 | return implode( ', ', $output ); |
| 190 | } |
| 191 | |
| 192 | function wpcf7_support_html5() { |
| 193 | return (bool) apply_filters( 'wpcf7_support_html5', true ); |
| 194 | } |
| 195 | |
| 196 | function wpcf7_support_html5_fallback() { |
| 197 | return (bool) apply_filters( 'wpcf7_support_html5_fallback', false ); |
| 198 | } |
| 199 | |
| 200 | function wpcf7_load_js() { |
| 201 | return apply_filters( 'wpcf7_load_js', WPCF7_LOAD_JS ); |
| 202 | } |
| 203 | |
| 204 | function wpcf7_load_css() { |
| 205 | return apply_filters( 'wpcf7_load_css', WPCF7_LOAD_CSS ); |
| 206 | } |
| 207 | |
| 208 | function wpcf7_format_atts( $atts ) { |
| 209 | $html = ''; |
| 210 | |
| 211 | $prioritized_atts = array( 'type', 'name', 'value' ); |
| 212 | |
| 213 | foreach ( $prioritized_atts as $att ) { |
| 214 | if ( isset( $atts[$att] ) ) { |
| 215 | $value = trim( $atts[$att] ); |
| 216 | $html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) ); |
| 217 | unset( $atts[$att] ); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | foreach ( $atts as $key => $value ) { |
| 222 | $key = strtolower( trim( $key ) ); |
| 223 | |
| 224 | if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) { |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | $value = trim( $value ); |
| 229 | |
| 230 | if ( '' !== $value ) { |
| 231 | $html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) ); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | $html = trim( $html ); |
| 236 | |
| 237 | return $html; |
| 238 | } |
| 239 | |
| 240 | function wpcf7_link( $url, $anchor_text, $args = '' ) { |
| 241 | $defaults = array( |
| 242 | 'id' => '', |
| 243 | 'class' => '' ); |
| 244 | |
| 245 | $args = wp_parse_args( $args, $defaults ); |
| 246 | $args = array_intersect_key( $args, $defaults ); |
| 247 | $atts = wpcf7_format_atts( $args ); |
| 248 | |
| 249 | $link = sprintf( '<a href="%1$s"%3$s>%2$s</a>', |
| 250 | esc_url( $url ), |
| 251 | esc_html( $anchor_text ), |
| 252 | $atts ? ( ' ' . $atts ) : '' ); |
| 253 | |
| 254 | return $link; |
| 255 | } |
| 256 | |
| 257 | function wpcf7_load_textdomain( $locale = null ) { |
| 258 | global $l10n; |
| 259 | |
| 260 | $domain = 'contact-form-7'; |
| 261 | |
| 262 | if ( get_locale() == $locale ) { |
| 263 | $locale = null; |
| 264 | } |
| 265 | |
| 266 | if ( empty( $locale ) ) { |
| 267 | if ( is_textdomain_loaded( $domain ) ) { |
| 268 | return true; |
| 269 | } else { |
| 270 | return load_plugin_textdomain( $domain, false, $domain . '/languages' ); |
| 271 | } |
| 272 | } else { |
| 273 | $mo_orig = $l10n[$domain]; |
| 274 | unload_textdomain( $domain ); |
| 275 | |
| 276 | $mofile = $domain . '-' . $locale . '.mo'; |
| 277 | $path = WP_PLUGIN_DIR . '/' . $domain . '/languages'; |
| 278 | |
| 279 | if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) ) { |
| 280 | return $loaded; |
| 281 | } else { |
| 282 | $mofile = WP_LANG_DIR . '/plugins/' . $mofile; |
| 283 | return load_textdomain( $domain, $mofile ); |
| 284 | } |
| 285 | |
| 286 | $l10n[$domain] = $mo_orig; |
| 287 | } |
| 288 | |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | function wpcf7_load_modules() { |
| 293 | $dir = WPCF7_PLUGIN_MODULES_DIR; |
| 294 | |
| 295 | if ( empty( $dir ) || ! is_dir( $dir ) ) { |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | $mods = array( |
| 300 | 'acceptance', 'flamingo', |
| 301 | 'akismet', 'jetpack', 'submit', 'captcha', 'number', |
| 302 | 'text', 'checkbox', 'quiz', 'textarea', 'date', |
| 303 | 'response', 'file', 'select', 'listo', 'count' ); |
| 304 | |
| 305 | foreach ( $mods as $mod ) { |
| 306 | $file = trailingslashit( $dir ) . $mod . '.php'; |
| 307 | |
| 308 | if ( file_exists( $file ) ) { |
| 309 | include_once $file; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | function wpcf7_get_request_uri() { |
| 315 | static $request_uri = ''; |
| 316 | |
| 317 | if ( empty( $request_uri ) ) { |
| 318 | $request_uri = add_query_arg( array() ); |
| 319 | } |
| 320 | |
| 321 | return esc_url_raw( $request_uri ); |
| 322 | } |
| 323 | |
| 324 | function wpcf7_register_post_types() { |
| 325 | if ( class_exists( 'WPCF7_ContactForm' ) ) { |
| 326 | WPCF7_ContactForm::register_post_type(); |
| 327 | return true; |
| 328 | } else { |
| 329 | return false; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | function wpcf7_version( $args = '' ) { |
| 334 | $defaults = array( |
| 335 | 'limit' => -1, |
| 336 | 'only_major' => false ); |
| 337 | |
| 338 | $args = wp_parse_args( $args, $defaults ); |
| 339 | |
| 340 | if ( $args['only_major'] ) { |
| 341 | $args['limit'] = 2; |
| 342 | } |
| 343 | |
| 344 | $args['limit'] = (int) $args['limit']; |
| 345 | |
| 346 | $ver = WPCF7_VERSION; |
| 347 | $ver = strtr( $ver, '_-+', '...' ); |
| 348 | $ver = preg_replace( '/[^0-9.]+/', ".$0.", $ver ); |
| 349 | $ver = preg_replace( '/[.]+/', ".", $ver ); |
| 350 | $ver = trim( $ver, '.' ); |
| 351 | $ver = explode( '.', $ver ); |
| 352 | |
| 353 | if ( -1 < $args['limit'] ) { |
| 354 | $ver = array_slice( $ver, 0, $args['limit'] ); |
| 355 | } |
| 356 | |
| 357 | $ver = implode( '.', $ver ); |
| 358 | |
| 359 | return $ver; |
| 360 | } |
| 361 | |
| 362 | function wpcf7_version_grep( $version, array $input ) { |
| 363 | $pattern = '/^' . preg_quote( (string) $version, '/' ) . '(?:\.|$)/'; |
| 364 | |
| 365 | return preg_grep( $pattern, $input ); |
| 366 | } |
| 367 | |
| 368 | function wpcf7_enctype_value( $enctype ) { |
| 369 | $enctype = trim( $enctype ); |
| 370 | |
| 371 | if ( empty( $enctype ) ) { |
| 372 | return ''; |
| 373 | } |
| 374 | |
| 375 | $valid_enctypes = array( |
| 376 | 'application/x-www-form-urlencoded', |
| 377 | 'multipart/form-data', |
| 378 | 'text/plain' ); |
| 379 | |
| 380 | if ( in_array( $enctype, $valid_enctypes ) ) { |
| 381 | return $enctype; |
| 382 | } |
| 383 | |
| 384 | $pattern = '%^enctype="(' . implode( '|', $valid_enctypes ) . ')"$%'; |
| 385 | |
| 386 | if ( preg_match( $pattern, $enctype, $matches ) ) { |
| 387 | return $matches[1]; // for back-compat |
| 388 | } |
| 389 | |
| 390 | return ''; |
| 391 | } |
| 392 | |
| 393 | function wpcf7_rmdir_p( $dir ) { |
| 394 | if ( is_file( $dir ) ) { |
| 395 | @unlink( $dir ); |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | if ( ! is_dir( $dir ) ) { |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | if ( $handle = @opendir( $dir ) ) { |
| 404 | while ( false !== ( $file = readdir( $handle ) ) ) { |
| 405 | if ( $file == "." || $file == ".." ) { |
| 406 | continue; |
| 407 | } |
| 408 | |
| 409 | wpcf7_rmdir_p( path_join( $dir, $file ) ); |
| 410 | } |
| 411 | |
| 412 | closedir( $handle ); |
| 413 | } |
| 414 | |
| 415 | return @rmdir( $dir ); |
| 416 | } |
| 417 | |
| 418 | /* From _http_build_query in wp-includes/functions.php */ |
| 419 | function wpcf7_build_query( $args, $key = '' ) { |
| 420 | $sep = '&'; |
| 421 | $ret = array(); |
| 422 | |
| 423 | foreach ( (array) $args as $k => $v ) { |
| 424 | $k = urlencode( $k ); |
| 425 | |
| 426 | if ( ! empty( $key ) ) { |
| 427 | $k = $key . '%5B' . $k . '%5D'; |
| 428 | } |
| 429 | |
| 430 | if ( null === $v ) { |
| 431 | continue; |
| 432 | } elseif ( false === $v ) { |
| 433 | $v = '0'; |
| 434 | } |
| 435 | |
| 436 | if ( is_array( $v ) || is_object( $v ) ) { |
| 437 | array_push( $ret, wpcf7_build_query( $v, $k ) ); |
| 438 | } else { |
| 439 | array_push( $ret, $k . '=' . urlencode( $v ) ); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | return implode( $sep, $ret ); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Returns the number of code units in a string. |
| 448 | * |
| 449 | * @see http://www.w3.org/TR/html5/infrastructure.html#code-unit-length |
| 450 | * |
| 451 | * @return int|bool The number of code units, or false if mb_convert_encoding is not available. |
| 452 | */ |
| 453 | function wpcf7_count_code_units( $string ) { |
| 454 | static $use_mb = null; |
| 455 | |
| 456 | if ( is_null( $use_mb ) ) { |
| 457 | $use_mb = function_exists( 'mb_convert_encoding' ); |
| 458 | } |
| 459 | |
| 460 | if ( ! $use_mb ) { |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | $string = (string) $string; |
| 465 | |
| 466 | $encoding = mb_detect_encoding( $string, mb_detect_order(), true ); |
| 467 | |
| 468 | if ( $encoding ) { |
| 469 | $string = mb_convert_encoding( $string, 'UTF-16', $encoding ); |
| 470 | } else { |
| 471 | $string = mb_convert_encoding( $string, 'UTF-16', 'UTF-8' ); |
| 472 | } |
| 473 | |
| 474 | $byte_count = mb_strlen( $string, '8bit' ); |
| 475 | |
| 476 | return floor( $byte_count / 2 ); |
| 477 | } |
| 478 |