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
captcha.php
491 lines
| 1 | <?php |
| 2 | /** |
| 3 | ** A base module for [captchac] and [captchar] |
| 4 | **/ |
| 5 | |
| 6 | /* Shortcode handler */ |
| 7 | |
| 8 | wpcf7_add_shortcode( 'captchac', 'wpcf7_captcha_shortcode_handler', true ); |
| 9 | wpcf7_add_shortcode( 'captchar', 'wpcf7_captcha_shortcode_handler', true ); |
| 10 | |
| 11 | function wpcf7_captcha_shortcode_handler( $tag ) { |
| 12 | global $wpcf7_contact_form; |
| 13 | |
| 14 | if ( ! is_array( $tag ) ) |
| 15 | return ''; |
| 16 | |
| 17 | $type = $tag['type']; |
| 18 | $name = $tag['name']; |
| 19 | $options = (array) $tag['options']; |
| 20 | $values = (array) $tag['values']; |
| 21 | |
| 22 | if ( empty( $name ) ) |
| 23 | return ''; |
| 24 | |
| 25 | $validation_error = ''; |
| 26 | if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) ) |
| 27 | $validation_error = $wpcf7_contact_form->validation_error( $name ); |
| 28 | |
| 29 | $atts = ''; |
| 30 | $id_att = ''; |
| 31 | $class_att = ''; |
| 32 | $size_att = ''; |
| 33 | $maxlength_att = ''; |
| 34 | |
| 35 | if ( 'captchac' == $type ) |
| 36 | $class_att .= ' wpcf7-captcha-' . $name; |
| 37 | |
| 38 | foreach ( $options as $option ) { |
| 39 | if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) { |
| 40 | $id_att = $matches[1]; |
| 41 | |
| 42 | } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) { |
| 43 | $class_att .= ' ' . $matches[1]; |
| 44 | |
| 45 | } elseif ( preg_match( '%^([0-9]*)[/x]([0-9]*)$%', $option, $matches ) ) { |
| 46 | $size_att = (int) $matches[1]; |
| 47 | $maxlength_att = (int) $matches[2]; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if ( $id_att ) |
| 52 | $atts .= ' id="' . trim( $id_att ) . '"'; |
| 53 | |
| 54 | if ( $class_att ) |
| 55 | $atts .= ' class="' . trim( $class_att ) . '"'; |
| 56 | |
| 57 | // Value. |
| 58 | if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) |
| 59 | $value = ''; |
| 60 | else |
| 61 | $value = $values[0]; |
| 62 | |
| 63 | if ( 'captchac' == $type ) { |
| 64 | if ( ! class_exists( 'ReallySimpleCaptcha' ) ) { |
| 65 | return '<em>' . __( 'To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'wpcf7' ) . '</em>'; |
| 66 | } |
| 67 | |
| 68 | $op = array(); |
| 69 | // Default |
| 70 | $op['img_size'] = array( 72, 24 ); |
| 71 | $op['base'] = array( 6, 18 ); |
| 72 | $op['font_size'] = 14; |
| 73 | $op['font_char_width'] = 15; |
| 74 | |
| 75 | $op = array_merge( $op, wpcf7_captchac_options( $options ) ); |
| 76 | |
| 77 | if ( ! $filename = wpcf7_generate_captcha( $op ) ) |
| 78 | return ''; |
| 79 | |
| 80 | if ( is_array( $op['img_size'] ) ) |
| 81 | $atts .= ' width="' . $op['img_size'][0] . '" height="' . $op['img_size'][1] . '"'; |
| 82 | |
| 83 | $captcha_url = trailingslashit( wpcf7_captcha_tmp_url() ) . $filename; |
| 84 | $html = '<img alt="captcha" src="' . $captcha_url . '"' . $atts . ' />'; |
| 85 | $ref = substr( $filename, 0, strrpos( $filename, '.' ) ); |
| 86 | $html = '<input type="hidden" name="_wpcf7_captcha_challenge_' . $name . '" value="' . $ref . '" />' . $html; |
| 87 | |
| 88 | return $html; |
| 89 | |
| 90 | } elseif ( 'captchar' == $type ) { |
| 91 | if ( $size_att ) |
| 92 | $atts .= ' size="' . $size_att . '"'; |
| 93 | else |
| 94 | $atts .= ' size="40"'; // default size |
| 95 | |
| 96 | if ( $maxlength_att ) |
| 97 | $atts .= ' maxlength="' . $maxlength_att . '"'; |
| 98 | |
| 99 | $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />'; |
| 100 | $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>'; |
| 101 | |
| 102 | return $html; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /* Validation filter */ |
| 108 | |
| 109 | add_filter( 'wpcf7_validate_captchar', 'wpcf7_captcha_validation_filter', 10, 2 ); |
| 110 | |
| 111 | function wpcf7_captcha_validation_filter( $result, $tag ) { |
| 112 | global $wpcf7_contact_form; |
| 113 | |
| 114 | $type = $tag['type']; |
| 115 | $name = $tag['name']; |
| 116 | |
| 117 | $_POST[$name] = (string) $_POST[$name]; |
| 118 | |
| 119 | $captchac = '_wpcf7_captcha_challenge_' . $name; |
| 120 | |
| 121 | if ( ! wpcf7_check_captcha( $_POST[$captchac], $_POST[$name] ) ) { |
| 122 | $result['valid'] = false; |
| 123 | $result['reason'][$name] = $wpcf7_contact_form->message( 'captcha_not_match' ); |
| 124 | } |
| 125 | |
| 126 | wpcf7_remove_captcha( $_POST[$captchac] ); |
| 127 | |
| 128 | return $result; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /* Ajax echo filter */ |
| 133 | |
| 134 | add_filter( 'wpcf7_ajax_onload', 'wpcf7_captcha_ajax_refill' ); |
| 135 | add_filter( 'wpcf7_ajax_json_echo', 'wpcf7_captcha_ajax_refill' ); |
| 136 | |
| 137 | function wpcf7_captcha_ajax_refill( $items ) { |
| 138 | global $wpcf7_contact_form; |
| 139 | |
| 140 | if ( ! is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) ) |
| 141 | return $items; |
| 142 | |
| 143 | if ( ! is_array( $items ) ) |
| 144 | return $items; |
| 145 | |
| 146 | $fes = $wpcf7_contact_form->form_scan_shortcode( |
| 147 | array( 'type' => 'captchac' ) ); |
| 148 | |
| 149 | if ( empty( $fes ) ) |
| 150 | return $items; |
| 151 | |
| 152 | $refill = array(); |
| 153 | |
| 154 | foreach ( $fes as $fe ) { |
| 155 | $name = $fe['name']; |
| 156 | $options = $fe['options']; |
| 157 | |
| 158 | if ( empty( $name ) ) |
| 159 | continue; |
| 160 | |
| 161 | $op = wpcf7_captchac_options( $options ); |
| 162 | if ( $filename = wpcf7_generate_captcha( $op ) ) { |
| 163 | $captcha_url = trailingslashit( wpcf7_captcha_tmp_url() ) . $filename; |
| 164 | $refill[$name] = $captcha_url; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if ( ! empty( $refill ) ) |
| 169 | $items['captcha'] = $refill; |
| 170 | |
| 171 | return $items; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* Messages */ |
| 176 | |
| 177 | add_filter( 'wpcf7_messages', 'wpcf7_captcha_messages' ); |
| 178 | |
| 179 | function wpcf7_captcha_messages( $messages ) { |
| 180 | return array_merge( $messages, array( 'captcha_not_match' => array( |
| 181 | 'description' => __( "The code that sender entered does not match the CAPTCHA", 'wpcf7' ), |
| 182 | 'default' => __( 'Your entered code is incorrect.', 'wpcf7' ) |
| 183 | ) ) ); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /* Tag generator */ |
| 188 | |
| 189 | add_action( 'admin_init', 'wpcf7_add_tag_generator_captcha', 45 ); |
| 190 | |
| 191 | function wpcf7_add_tag_generator_captcha() { |
| 192 | wpcf7_add_tag_generator( 'captcha', __( 'CAPTCHA', 'wpcf7' ), |
| 193 | 'wpcf7-tg-pane-captcha', 'wpcf7_tg_pane_captcha' ); |
| 194 | } |
| 195 | |
| 196 | function wpcf7_tg_pane_captcha( &$contact_form ) { |
| 197 | ?> |
| 198 | <div id="wpcf7-tg-pane-captcha" class="hidden"> |
| 199 | <form action=""> |
| 200 | <table> |
| 201 | |
| 202 | <?php if ( ! class_exists( 'ReallySimpleCaptcha' ) ) : ?> |
| 203 | <tr><td colspan="2"><strong style="color: #e6255b"><?php echo esc_html( __( "Note: To use CAPTCHA, you need Really Simple CAPTCHA plugin installed.", 'wpcf7' ) ); ?></strong><br /><a href="http://wordpress.org/extend/plugins/really-simple-captcha/">http://wordpress.org/extend/plugins/really-simple-captcha/</a></td></tr> |
| 204 | <?php endif; ?> |
| 205 | |
| 206 | <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr> |
| 207 | </table> |
| 208 | |
| 209 | <table class="scope captchac"> |
| 210 | <caption><?php echo esc_html( __( "Image settings", 'wpcf7' ) ); ?></caption> |
| 211 | |
| 212 | <tr> |
| 213 | <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 214 | <input type="text" name="id" class="idvalue oneline option" /></td> |
| 215 | |
| 216 | <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 217 | <input type="text" name="class" class="classvalue oneline option" /></td> |
| 218 | </tr> |
| 219 | |
| 220 | <tr> |
| 221 | <td><?php echo esc_html( __( "Foreground color", 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 222 | <input type="text" name="fg" class="color oneline option" /></td> |
| 223 | |
| 224 | <td><?php echo esc_html( __( "Background color", 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 225 | <input type="text" name="bg" class="color oneline option" /></td> |
| 226 | </tr> |
| 227 | |
| 228 | <tr><td colspan="2"><?php echo esc_html( __( "Image size", 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 229 | <input type="checkbox" name="size:s" class="exclusive option" /> <?php echo esc_html( __( "Small", 'wpcf7' ) ); ?>  |
| 230 | <input type="checkbox" name="size:m" class="exclusive option" /> <?php echo esc_html( __( "Medium", 'wpcf7' ) ); ?>  |
| 231 | <input type="checkbox" name="size:l" class="exclusive option" /> <?php echo esc_html( __( "Large", 'wpcf7' ) ); ?> |
| 232 | </td></tr> |
| 233 | </table> |
| 234 | |
| 235 | <table class="scope captchar"> |
| 236 | <caption><?php echo esc_html( __( "Input field settings", 'wpcf7' ) ); ?></caption> |
| 237 | |
| 238 | <tr> |
| 239 | <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 240 | <input type="text" name="id" class="idvalue oneline option" /></td> |
| 241 | |
| 242 | <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 243 | <input type="text" name="class" class="classvalue oneline option" /></td> |
| 244 | </tr> |
| 245 | |
| 246 | <tr> |
| 247 | <td><code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 248 | <input type="text" name="size" class="numeric oneline option" /></td> |
| 249 | |
| 250 | <td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /> |
| 251 | <input type="text" name="maxlength" class="numeric oneline option" /></td> |
| 252 | </tr> |
| 253 | </table> |
| 254 | |
| 255 | <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?> |
| 256 | <br />1) <?php echo esc_html( __( "For image", 'wpcf7' ) ); ?> |
| 257 | <input type="text" name="captchac" class="tag" readonly="readonly" onfocus="this.select()" /> |
| 258 | <br />2) <?php echo esc_html( __( "For input field", 'wpcf7' ) ); ?> |
| 259 | <input type="text" name="captchar" class="tag" readonly="readonly" onfocus="this.select()" /> |
| 260 | </div> |
| 261 | </form> |
| 262 | </div> |
| 263 | <?php |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /* Warning message */ |
| 268 | |
| 269 | add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_captcha_display_warning_message' ); |
| 270 | |
| 271 | function wpcf7_captcha_display_warning_message( &$contact_form ) { |
| 272 | if ( ! $contact_form ) |
| 273 | return; |
| 274 | |
| 275 | $has_tags = (bool) $contact_form->form_scan_shortcode( |
| 276 | array( 'type' => array( 'captchac' ) ) ); |
| 277 | |
| 278 | if ( ! $has_tags ) |
| 279 | return; |
| 280 | |
| 281 | if ( ! class_exists( 'ReallySimpleCaptcha' ) ) |
| 282 | return; |
| 283 | |
| 284 | $uploads_dir = wpcf7_captcha_tmp_dir(); |
| 285 | wpcf7_init_captcha(); |
| 286 | |
| 287 | if ( ! is_dir( $uploads_dir ) || ! is_writable( $uploads_dir ) ) { |
| 288 | $message = sprintf( __( 'This contact form contains CAPTCHA fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'wpcf7' ), $uploads_dir ); |
| 289 | |
| 290 | echo '<div class="error"><p><strong>' . esc_html( $message ) . '</strong></p></div>'; |
| 291 | } |
| 292 | |
| 293 | if ( ! function_exists( 'imagecreatetruecolor' ) || ! function_exists( 'imagettftext' ) ) { |
| 294 | $message = __( 'This contact form contains CAPTCHA fields, but the necessary libraries (GD and FreeType) are not available on your server.', 'wpcf7' ); |
| 295 | |
| 296 | echo '<div class="error"><p><strong>' . esc_html( $message ) . '</strong></p></div>'; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | /* CAPTCHA functions */ |
| 302 | |
| 303 | function wpcf7_init_captcha() { |
| 304 | global $wpcf7_captcha; |
| 305 | |
| 306 | if ( ! class_exists( 'ReallySimpleCaptcha' ) ) |
| 307 | return false; |
| 308 | |
| 309 | if ( ! is_object( $wpcf7_captcha ) ) |
| 310 | $wpcf7_captcha = new ReallySimpleCaptcha(); |
| 311 | $captcha =& $wpcf7_captcha; |
| 312 | |
| 313 | $captcha->tmp_dir = trailingslashit( wpcf7_captcha_tmp_dir() ); |
| 314 | wp_mkdir_p( $captcha->tmp_dir ); |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | function wpcf7_captcha_tmp_dir() { |
| 319 | if ( defined( 'WPCF7_CAPTCHA_TMP_DIR' ) ) |
| 320 | return WPCF7_CAPTCHA_TMP_DIR; |
| 321 | else |
| 322 | return wpcf7_upload_dir( 'dir' ) . '/wpcf7_captcha'; |
| 323 | } |
| 324 | |
| 325 | function wpcf7_captcha_tmp_url() { |
| 326 | if ( defined( 'WPCF7_CAPTCHA_TMP_URL' ) ) |
| 327 | return WPCF7_CAPTCHA_TMP_URL; |
| 328 | else |
| 329 | return wpcf7_upload_dir( 'url' ) . '/wpcf7_captcha'; |
| 330 | } |
| 331 | |
| 332 | function wpcf7_generate_captcha( $options = null ) { |
| 333 | global $wpcf7_captcha; |
| 334 | |
| 335 | if ( ! wpcf7_init_captcha() ) |
| 336 | return false; |
| 337 | $captcha =& $wpcf7_captcha; |
| 338 | |
| 339 | if ( ! is_dir( $captcha->tmp_dir ) || ! is_writable( $captcha->tmp_dir ) ) |
| 340 | return false; |
| 341 | |
| 342 | $img_type = imagetypes(); |
| 343 | if ( $img_type & IMG_PNG ) |
| 344 | $captcha->img_type = 'png'; |
| 345 | elseif ( $img_type & IMG_GIF ) |
| 346 | $captcha->img_type = 'gif'; |
| 347 | elseif ( $img_type & IMG_JPG ) |
| 348 | $captcha->img_type = 'jpeg'; |
| 349 | else |
| 350 | return false; |
| 351 | |
| 352 | if ( is_array( $options ) ) { |
| 353 | if ( isset( $options['img_size'] ) ) |
| 354 | $captcha->img_size = $options['img_size']; |
| 355 | if ( isset( $options['base'] ) ) |
| 356 | $captcha->base = $options['base']; |
| 357 | if ( isset( $options['font_size'] ) ) |
| 358 | $captcha->font_size = $options['font_size']; |
| 359 | if ( isset( $options['font_char_width'] ) ) |
| 360 | $captcha->font_char_width = $options['font_char_width']; |
| 361 | if ( isset( $options['fg'] ) ) |
| 362 | $captcha->fg = $options['fg']; |
| 363 | if ( isset( $options['bg'] ) ) |
| 364 | $captcha->bg = $options['bg']; |
| 365 | } |
| 366 | |
| 367 | $prefix = mt_rand(); |
| 368 | $captcha_word = $captcha->generate_random_word(); |
| 369 | return $captcha->generate_image( $prefix, $captcha_word ); |
| 370 | } |
| 371 | |
| 372 | function wpcf7_check_captcha( $prefix, $response ) { |
| 373 | global $wpcf7_captcha; |
| 374 | |
| 375 | if ( ! wpcf7_init_captcha() ) |
| 376 | return false; |
| 377 | $captcha =& $wpcf7_captcha; |
| 378 | |
| 379 | return $captcha->check( $prefix, $response ); |
| 380 | } |
| 381 | |
| 382 | function wpcf7_remove_captcha( $prefix ) { |
| 383 | global $wpcf7_captcha; |
| 384 | |
| 385 | if ( ! wpcf7_init_captcha() ) |
| 386 | return false; |
| 387 | $captcha =& $wpcf7_captcha; |
| 388 | |
| 389 | $captcha->remove( $prefix ); |
| 390 | } |
| 391 | |
| 392 | function wpcf7_cleanup_captcha_files() { |
| 393 | global $wpcf7_captcha; |
| 394 | |
| 395 | if ( ! wpcf7_init_captcha() ) |
| 396 | return false; |
| 397 | $captcha =& $wpcf7_captcha; |
| 398 | |
| 399 | if ( is_callable( array( $captcha, 'cleanup' ) ) ) |
| 400 | return $captcha->cleanup(); |
| 401 | |
| 402 | $dir = trailingslashit( wpcf7_captcha_tmp_dir() ); |
| 403 | |
| 404 | if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! is_writable( $dir ) ) |
| 405 | return false; |
| 406 | |
| 407 | if ( $handle = @opendir( $dir ) ) { |
| 408 | while ( false !== ( $file = readdir( $handle ) ) ) { |
| 409 | if ( ! preg_match( '/^[0-9]+\.(php|png|gif|jpeg)$/', $file ) ) |
| 410 | continue; |
| 411 | |
| 412 | $stat = @stat( $dir . $file ); |
| 413 | if ( $stat['mtime'] + 3600 < time() ) // 3600 secs == 1 hour |
| 414 | @unlink( $dir . $file ); |
| 415 | } |
| 416 | closedir( $handle ); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if ( ! is_admin() && 'GET' == $_SERVER['REQUEST_METHOD'] ) |
| 421 | wpcf7_cleanup_captcha_files(); |
| 422 | |
| 423 | function wpcf7_captchac_options( $options ) { |
| 424 | if ( ! is_array( $options ) ) |
| 425 | return array(); |
| 426 | |
| 427 | $op = array(); |
| 428 | $image_size_array = preg_grep( '%^size:[smlSML]$%', $options ); |
| 429 | |
| 430 | if ( $image_size = array_shift( $image_size_array ) ) { |
| 431 | preg_match( '%^size:([smlSML])$%', $image_size, $is_matches ); |
| 432 | switch ( strtolower( $is_matches[1] ) ) { |
| 433 | case 's': |
| 434 | $op['img_size'] = array( 60, 20 ); |
| 435 | $op['base'] = array( 6, 15 ); |
| 436 | $op['font_size'] = 11; |
| 437 | $op['font_char_width'] = 13; |
| 438 | break; |
| 439 | case 'l': |
| 440 | $op['img_size'] = array( 84, 28 ); |
| 441 | $op['base'] = array( 6, 20 ); |
| 442 | $op['font_size'] = 17; |
| 443 | $op['font_char_width'] = 19; |
| 444 | break; |
| 445 | case 'm': |
| 446 | default: |
| 447 | $op['img_size'] = array( 72, 24 ); |
| 448 | $op['base'] = array( 6, 18 ); |
| 449 | $op['font_size'] = 14; |
| 450 | $op['font_char_width'] = 15; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | $fg_color_array = preg_grep( '%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options ); |
| 455 | if ( $fg_color = array_shift( $fg_color_array ) ) { |
| 456 | preg_match( '%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $fg_color, $fc_matches ); |
| 457 | if ( 3 == strlen( $fc_matches[1] ) ) { |
| 458 | $r = substr( $fc_matches[1], 0, 1 ); |
| 459 | $g = substr( $fc_matches[1], 1, 1 ); |
| 460 | $b = substr( $fc_matches[1], 2, 1 ); |
| 461 | $op['fg'] = array( hexdec( $r . $r ), hexdec( $g . $g ), hexdec( $b . $b ) ); |
| 462 | } elseif ( 6 == strlen( $fc_matches[1] ) ) { |
| 463 | $r = substr( $fc_matches[1], 0, 2 ); |
| 464 | $g = substr( $fc_matches[1], 2, 2 ); |
| 465 | $b = substr( $fc_matches[1], 4, 2 ); |
| 466 | $op['fg'] = array( hexdec( $r ), hexdec( $g ), hexdec( $b ) ); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | $bg_color_array = preg_grep( '%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options ); |
| 471 | if ( $bg_color = array_shift( $bg_color_array ) ) { |
| 472 | preg_match( '%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $bg_color, $bc_matches ); |
| 473 | if ( 3 == strlen( $bc_matches[1] ) ) { |
| 474 | $r = substr( $bc_matches[1], 0, 1 ); |
| 475 | $g = substr( $bc_matches[1], 1, 1 ); |
| 476 | $b = substr( $bc_matches[1], 2, 1 ); |
| 477 | $op['bg'] = array( hexdec( $r . $r ), hexdec( $g . $g ), hexdec( $b . $b ) ); |
| 478 | } elseif ( 6 == strlen( $bc_matches[1] ) ) { |
| 479 | $r = substr( $bc_matches[1], 0, 2 ); |
| 480 | $g = substr( $bc_matches[1], 2, 2 ); |
| 481 | $b = substr( $bc_matches[1], 4, 2 ); |
| 482 | $op['bg'] = array( hexdec( $r ), hexdec( $g ), hexdec( $b ) ); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return $op; |
| 487 | } |
| 488 | |
| 489 | $wpcf7_captcha = null; |
| 490 | |
| 491 | ?> |