Guest User

Mod of wp-recaptcha with BuddyPress support -- quick hack

a guest
May 7th, 2010
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 44.65 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  Plugin name: BP-ReCaptcha
  5.  Plugin URI: http://createdigitalmedia.net
  6.  Description: Adds ReCaptcha support to the registration process for BuddyPress
  7.  Version: 0.1
  8.  Author: Peter Kirn, modification to wp-recaptcha by http://www.blaenkdenum.com/
  9.  Author URI: http://peter.noisepages.com
  10.  */
  11.  
  12. /*  Copyright 2010  CREATE DIGITAL MEDIA, LTD.  (email : peter@createdigitalmedia.net)
  13.  
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License, version 2, as
  16. published by the Free Software Foundation.
  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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  26. */
  27.  
  28. $wpmu = 0;
  29.  
  30. if (basename(dirname(__FILE__)) == "mu-plugins") // forced activated
  31. $wpmu = 1;
  32. else if (basename(dirname(__FILE__)) == "plugins" && function_exists('is_site_admin')) // optionally activated
  33. $wpmu = 2;
  34.  
  35. if ($wpmu == 1)
  36. $recaptcha_opt = get_site_option('recaptcha'); // get the options from the database
  37. else
  38. $recaptcha_opt = get_option('recaptcha'); // get the options from the database
  39.  
  40. // END WORDPRESS MU DETECTION
  41.  
  42. if ($wpmu == 1)
  43. require_once(dirname(__FILE__) . '/wp-recaptcha/recaptchalib.php');
  44. else
  45. require_once(dirname(__FILE__) . '/recaptchalib.php');
  46.  
  47. // doesn't need to be secret, just shouldn't be used by any other code.
  48. define ("RECAPTCHA_WP_HASH_SALT", "b7e0638d85f5d7f3694f68e944136d62");
  49.  
  50. /* =============================================================================
  51.  CSS - This links the pages to the stylesheet to be properly styled
  52.  ============================================================================= */
  53.  
  54. function re_css() {
  55.     global $recaptcha_opt, $wpmu;
  56.  
  57.     if (!defined('WP_CONTENT_URL'))
  58.     define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  59.  
  60.     $path = WP_CONTENT_URL . '/plugins/wp-recaptcha/recaptcha.css';
  61.  
  62.     if ($wpmu == 1)
  63.     $path = WP_CONTENT_URL . '/mu-plugins/wp-recaptcha/recaptcha.css';
  64.  
  65.     echo '<link rel="stylesheet" type="text/css" href="' . $path . '" />';
  66. }
  67.  
  68. function registration_css() {
  69.     global $recaptcha_opt;
  70.  
  71.     if ($recaptcha_opt['re_registration']) {
  72.         $width = 0;
  73.  
  74.         if ($recaptcha_opt['re_theme_reg'] == 'red' ||
  75.         $recaptcha_opt['re_theme_reg'] == 'white' ||
  76.         $recaptcha_opt['re_theme_reg'] == 'blackglass')
  77.         $width = 358;
  78.         else if ($recaptcha_opt['re_theme_reg'] == 'clean')
  79.         $width = 485;
  80.  
  81.         echo <<<REGISTRATION
  82.         <style type="text/css">
  83.         #login {
  84.                 width: {$width}px !important;
  85.         }
  86.        
  87.         #login a {
  88.                 text-align: center;
  89.         }
  90.        
  91.         #nav {
  92.                 text-align: center;
  93.         }
  94.         form .submit {
  95.             margin-top: 10px;
  96.       }
  97.         </style>
  98. REGISTRATION;
  99.     }
  100. }
  101.  
  102. add_action('wp_head', 're_css'); // include the stylesheet in typical pages to style hidden emails
  103. add_action('admin_head', 're_css'); // include stylesheet to style options page
  104. add_action('login_head', 'registration_css'); // include the login div styling, embedded
  105.  
  106. /* =============================================================================
  107.  End CSS
  108.  ============================================================================= */
  109.  
  110. // If the plugin is deactivated, delete the preferences
  111. function delete_preferences() {
  112.     global $wpmu;
  113.  
  114.     if ($wpmu != 1)
  115.     delete_option('recaptcha');
  116. }
  117.  
  118. register_deactivation_hook(__FILE__, 'delete_preferences');
  119.  
  120. /* =============================================================================
  121.  reCAPTCHA on Registration Form - Thanks to Ben C.'s recapture plugin
  122.  ============================================================================= */
  123.  
  124. // Display the reCAPTCHA on the registration form
  125. function display_recaptcha($errors) {
  126.     global $recaptcha_opt, $wpmu;
  127.  
  128.     if ($recaptcha_opt['re_registration']) {
  129.         $format = <<<END
  130.         <script type='text/javascript'>
  131.         var RecaptchaOptions = { theme : '{$recaptcha_opt['re_theme_reg']}', lang : '{$recaptcha_opt['re_lang']}' , tabindex : 30 };
  132.         </script>
  133. END;
  134.  
  135.         $comment_string = <<<COMMENT_FORM
  136.         <script type='text/javascript'>  
  137.         document.getElementById('recaptcha_table').style.direction = 'ltr';
  138.         </script>
  139. COMMENT_FORM;
  140.  
  141.         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
  142.         $use_ssl = true;
  143.         else
  144.         $use_ssl = false;
  145.  
  146.         if ($wpmu == 1) {
  147.             $error = $errors->get_error_message('captcha'); ?>
  148. <label for="verification">Verification:</label>
  149.             <?php echo($error ? '<p class="error">'.$error.'</p>' : '') ?>
  150.             <?php echo $format . recaptcha_wp_get_html($_GET['rerror'], $use_ssl); ?>
  151.             <?php }
  152.  
  153.             else {
  154.                 echo '<hr style="clear: both; margin-bottom: 1.5em; border: 0; border-top: 1px solid #999; height: 1px;" />';
  155.                 echo $format . recaptcha_wp_get_html($_GET['rerror'], $use_ssl);
  156.             }
  157.     }
  158. }
  159.  
  160. function display_recaptcha_bp($errors) {
  161.     global $recaptcha_opt, $wpmu, $bp;
  162.  
  163.     if ($recaptcha_opt['re_registration']) {
  164.  
  165.         $format = <<<END
  166.         <script type='text/javascript'>
  167.         var RecaptchaOptions = { theme : '{$recaptcha_opt['re_theme_reg']}', lang : '{$recaptcha_opt['re_lang']}' , tabindex : 30 };
  168.         </script>
  169. END;
  170.  
  171.         $comment_string = <<<COMMENT_FORM
  172.         <script type='text/javascript'>  
  173.         document.getElementById('recaptcha_table').style.direction = 'ltr';
  174.         </script>
  175. COMMENT_FORM;
  176.  
  177.         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
  178.         $use_ssl = true;
  179.         else
  180.         $use_ssl = false;
  181.  
  182.         ?>
  183. <label for="verification">Verification:</label>
  184.         <?php do_action( 'bp_captcha_errors' ); ?>
  185.         <?php echo $format . recaptcha_wp_get_html($_GET['rerror'], $use_ssl); ?>
  186.         <?php
  187.     }
  188. }
  189.  
  190.  
  191. function bp_captcha_errors() {
  192.     if ( !empty( $bp->signup->errors['captcha'])) {
  193.         $error_message = $bp->signup->errors['captcha'];
  194.         echo "<div class=\"error\">' . $error_message . '</div>";
  195.     }
  196. }
  197.  
  198. // PK custom function for validating recaptcha for BuddyPress
  199. function check_recaptcha_bp() {
  200.     global $_POST, $recaptcha_opt, $bp;
  201.  
  202.     // must make a check here, otherwise the wp-admin/user-new.php script will keep trying to call
  203.     // this function despite not having called do_action('signup_extra_fields'), so the recaptcha
  204.     // field was never shown. this way it won't validate if it's called in the admin interface
  205.     if (!is_admin()) {
  206.         // It's blogname in 2.6, blog_id prior to that
  207.         if (isset($_POST['blog_id']) || isset($_POST['blogname']))
  208.  
  209.         // no text entered
  210.         if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') {
  211.             $bp->signup->errors['captcha'] = __( 'Please fill in the reCAPTCHA form.', 'buddypress');
  212.         }
  213.  
  214.         $response = recaptcha_check_answer($recaptcha_opt['privkey'],
  215.         $_SERVER['REMOTE_ADDR'],
  216.         $_POST['recaptcha_challenge_field'],
  217.         $_POST['recaptcha_response_field'] );
  218.  
  219.         // incorrect CAPTCHA
  220.         if (!$response->is_valid)
  221.         if ($response->error == 'incorrect-captcha-sol') {
  222.             $bp->signup->errors['captcha'] = __( 'That reCAPTCHA response was incorrect.', 'buddypress');
  223.         }
  224.     }
  225.  
  226.     //return $result;
  227. }
  228.  
  229. //PK added to hook into BP registration form
  230. add_action('bp_before_registration_submit_buttons', 'display_recaptcha_bp', 9999);
  231.  
  232. //PK added to validate recaptcha response before allowing BP user to proceed
  233. add_action('bp_signup_validate', 'check_recaptcha_bp');
  234.  
  235. // Hook the display_recaptcha function into WordPress
  236. if ($wpmu != 1)
  237. add_action('register_form', 'display_recaptcha');
  238. else
  239. add_action('signup_extra_fields', 'display_recaptcha');
  240.  
  241. // Check the captcha
  242. function check_recaptcha() {
  243.     global $recaptcha_opt, $errors;
  244.  
  245.     if (empty($_POST['recaptcha_response_field']))
  246.     $errors['blank_captcha'] = $recaptcha_opt['error_blank'];
  247.  
  248.     else {
  249.         $response = recaptcha_check_answer($recaptcha_opt['privkey'],
  250.         $_SERVER['REMOTE_ADDR'],
  251.         $_POST['recaptcha_challenge_field'],
  252.         $_POST['recaptcha_response_field']);
  253.  
  254.         if (!$response->is_valid)
  255.         if ($response->error == 'incorrect-captcha-sol')
  256.         $errors['captcha_wrong'] = $recaptcha_opt['error_incorrect'];
  257.     }
  258. }
  259.  
  260. // Check the captcha
  261. function check_recaptcha_new($errors) {
  262.     global $recaptcha_opt;
  263.  
  264.     if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') {
  265.         $errors->add('blank_captcha', $recaptcha_opt['error_blank']);
  266.         return $errors;
  267.     }
  268.  
  269.     $response = recaptcha_check_answer($recaptcha_opt['privkey'],
  270.     $_SERVER['REMOTE_ADDR'],
  271.     $_POST['recaptcha_challenge_field'],
  272.     $_POST['recaptcha_response_field'] );
  273.  
  274.     if (!$response->is_valid)
  275.     if ($response->error == 'incorrect-captcha-sol')
  276.     $errors->add('captcha_wrong', $recaptcha_opt['error_incorrect']);
  277.  
  278.     return $errors;
  279. }
  280.  
  281. // Check the recaptcha on WordPress MU
  282. function check_recaptcha_wpmu($result) {
  283.     global $_POST, $recaptcha_opt;
  284.  
  285.     // must make a check here, otherwise the wp-admin/user-new.php script will keep trying to call
  286.     // this function despite not having called do_action('signup_extra_fields'), so the recaptcha
  287.     // field was never shown. this way it won't validate if it's called in the admin interface
  288.     if (!is_admin()) {
  289.         // It's blogname in 2.6, blog_id prior to that
  290.         if (isset($_POST['blog_id']) || isset($_POST['blogname']))
  291.         return $result;
  292.  
  293.         // no text entered
  294.         if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') {
  295.             $result['errors']->add('blank_captcha', $recaptcha_opt['error_blank']);
  296.             return $result;
  297.         }
  298.  
  299.         $response = recaptcha_check_answer($recaptcha_opt['privkey'],
  300.         $_SERVER['REMOTE_ADDR'],
  301.         $_POST['recaptcha_challenge_field'],
  302.         $_POST['recaptcha_response_field'] );
  303.  
  304.         // incorrect CAPTCHA
  305.         if (!$response->is_valid)
  306.         if ($response->error == 'incorrect-captcha-sol') {
  307.             $result['errors']->add('captcha_wrong', $recaptcha_opt['error_incorrect']);
  308.             echo "<div class=\"error\">". $recaptcha_opt['error_incorrect'] . "</div>";
  309.         }
  310.     }
  311.  
  312.     return $result;
  313. }
  314.  
  315. if ($recaptcha_opt['re_registration']) {
  316.     if ($wpmu == 1)
  317.     add_filter('wpmu_validate_user_signup', 'check_recaptcha_wpmu');
  318.  
  319.     else if ($wpmu == 0) {
  320.         // Hook the check_recaptcha function into WordPress
  321.         if (version_compare(get_bloginfo('version'), '2.5' ) >= 0)
  322.         add_filter('registration_errors', 'check_recaptcha_new');
  323.         else
  324.         add_filter('registration_errors', 'check_recaptcha');
  325.     }
  326. }
  327. /* =============================================================================
  328.  End reCAPTCHA on Registration Form
  329.  ============================================================================= */
  330.  
  331. /* =============================================================================
  332.  reCAPTCHA Plugin Default Options
  333.  ============================================================================= */
  334.  
  335. $option_defaults = array (
  336.    'pubkey' => '', // the public key for reCAPTCHA
  337.    'privkey'    => '', // the private key for reCAPTCHA
  338.    'use_mailhide_posts' => '0', // mailhide for posts/pages
  339.    'use_mailhide_comments' => '0', // use mailhide for comments
  340.    'use_mailhide_rss' => '0', // use mailhide for the rss feed of the posts/pages
  341.    'use_mailhide_rss_comments' => '0', // use mailhide for the rss comments
  342.    're_bypass' => '', // whether to sometimes skip reCAPTCHAs for registered users
  343.    're_bypasslevel' => '', // who doesn't have to do the reCAPTCHA (should be a valid WordPress capability slug)
  344.    'mh_bypass' => '', // whether to sometimes skip the MailHide filter for registered users
  345.    'mh_bypasslevel' => '', // who can see full emails normally (should be a valid WordPress capability slug)
  346.    'mailhide_pub' => '', // mailhide public key
  347.    'mailhide_priv' => '', // mailhide private key
  348.    're_theme' => 'red', // the default theme for reCAPTCHA on the comment post
  349.    're_theme_reg' => 'red', // the default theme for reCAPTCHA on the registration form
  350.    're_lang' => 'en', // the default language for reCAPTCHA
  351.    're_tabindex' => '5', // the default tabindex for reCAPTCHA
  352.    're_comments' => '1', // whether or not to show reCAPTCHA on the comment post
  353.    're_registration' => '1', // whether or not to show reCAPTCHA on the registratoin page
  354.    're_xhtml' => '0', // whether or not to be XHTML 1.0 Strict compliant
  355.    'mh_replace_link' => '', // name the link something else
  356.    'mh_replace_title' => '', // title of the link
  357.    'error_blank' => '<strong>ERROR</strong>: Please fill in the reCAPTCHA form.', // the message to display when the user enters no CAPTCHA response
  358.    'error_incorrect' => '<strong>ERROR</strong>: That reCAPTCHA response was incorrect.', // the message to display when the user enters the incorrect CAPTCHA response
  359. );
  360.  
  361. // install the defaults
  362. if ($wpmu != 1)
  363. add_option('recaptcha', $option_defaults, 'reCAPTCHA Default Options', 'yes');
  364.  
  365. /* =============================================================================
  366.  End reCAPTCHA Plugin Default Options
  367.  ============================================================================= */
  368.  
  369. /* =============================================================================
  370.  MailHide - This scans for addresses and hides them using the MailHide API
  371.  ============================================================================= */
  372.  
  373. // The main mailhide filter
  374. function mh_insert_email($content = '') {
  375.     global $recaptcha_opt;
  376.  
  377.     // set the minimum capability needed to skip the MailHide if there is one
  378.     if ($recaptcha_opt['mh_bypass'] && $recaptcha_opt['mh_bypasslevel'])
  379.     $needed_capability = $recaptcha_opt['mh_bypasslevel'];
  380.  
  381.     // skip the MailHide display if the minimum capability is met
  382.     if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) {
  383.         // remove the nohides
  384.         $content = preg_replace('/\[\/?nohide\]/i','',$content);
  385.         return $content;
  386.     }
  387.  
  388.     // Regular Expressions thanks to diabolic from EFNet #regex
  389.  
  390.     // match hyperlinks with emails
  391.     $regex = '%(?<!\[nohide\])<a[^>]*href="((?:mailto:)?([^@"]+@[^@"]+))"[^>]*>(.+?)<\/a>(?!\[/nohide\])%i';
  392.     $content = preg_replace_callback($regex, "mh_replace_hyperlink", $content);
  393.  
  394.     // match emails
  395.     $regex = '%\b([\w.+-]+@[a-z\d.-]+\.[a-z]{2,6})\b(?!\s*\[\/nohide\]|(?:(?!<a[^>]*>).)*<\/a>)%i';
  396.     $content = preg_replace_callback($regex, "mh_replace", $content);
  397.  
  398.     // remove the nohides
  399.     $content = preg_replace('/\[\/?nohide\]/i','',$content);
  400.     return $content;
  401. }
  402.  
  403. // replace the hyperlinked emails i.e. <a href="haha@lol.com">this</a> or <a href="mailto:haha@lol.com">that</a>
  404. function mh_replace_hyperlink($matches) {
  405.     global $recaptcha_opt;
  406.  
  407.     // set the minimum capability needed to skip the MailHide if there is one
  408.     if ($recaptcha_opt['mh_bypass'] && $recaptcha_opt['mh_bypasslevel'])
  409.     $needed_capability = $recaptcha_opt['mh_bypasslevel'];
  410.  
  411.     // skip the MailHide display if the minimum capability is met
  412.     if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) {
  413.         // remove the nohides
  414.         $content = preg_replace('/\[\/?nohide\]/i','',$content);
  415.         return $content;
  416.     }
  417.  
  418.     // get the url, the part inside the href. this is the email of course
  419.     $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[2]);
  420.  
  421.     // construct a new hyperlink with the url hidden but the link text the same
  422.     $html = "<a href='" . $url . "' onclick=\"window.open('" . htmlentities ($url, ENT_QUOTES) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\">" . $matches[3] . "</a>";
  423.  
  424.     // style it
  425.     $html = '<span class="mh-hyperlinked">' . $html . "</span>";
  426.  
  427.     return $html;
  428. }
  429.  
  430. // replace the plain text emails i.e. haha@lol.com
  431. function mh_replace($matches) {
  432.     global $recaptcha_opt;
  433.  
  434.     # var_dump($matches);
  435.  
  436.     if ($recaptcha_opt['mh_replace_link'] == "" && $recaptcha_opt['mh_replace_title'] == "") {
  437.         // find plain text emails and hide them
  438.         $html = recaptcha_mailhide_html($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[0]);
  439.     }
  440.  
  441.     else {
  442.         // replace both things
  443.         if ($recaptcha_opt['mh_replace_link'] != "" && $recaptcha_opt['mh_replace_title'] != "") {
  444.             $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[0]);
  445.             $html = "<a href='" . htmlentities($url, ENT_QUOTES) .
  446.             "' onclick=\"window.open('" . htmlentities($url, ENT_QUOTES) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"" . $recaptcha_opt['mh_replace_title'] . "\">" . $recaptcha_opt['mh_replace_link'] . "</a>";
  447.         }
  448.  
  449.         // only replace the link
  450.         else if ($recaptcha_opt['mh_replace_link'] != "" && $recaptcha_opt['mh_replace_title'] == "") {
  451.             $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[0]);
  452.             $html = "<a href='" . htmlentities($url, ENT_QUOTES) .
  453.             "' onclick=\"window.open('" . htmlentities($url, ENT_QUOTES) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">" . $recaptcha_opt['mh_replace_link'] . "</a>";
  454.         }
  455.  
  456.         // only replace the title
  457.         else if ($recaptcha_opt['mh_replace_link'] == "" && $recaptcha_opt['mh_replace_title'] != "") {
  458.             $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[0]);
  459.             $emailparts = _recaptcha_mailhide_email_parts ($matches[0]);
  460.  
  461.             $html = htmlentities($emailparts[0], ENT_QUOTES) . "<a href='" . htmlentities($url, ENT_QUOTES) .
  462.             "' onclick=\"window.open('" . htmlentities($url, ENT_QUOTES) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"" . $recaptcha_opt['mh_replace_title'] . "\">...</a>@" . htmlentities($emailparts[0], ENT_QUOTES);
  463.         }
  464.     }
  465.  
  466.     // style it
  467.     $html = '<span class="mh-plaintext">' . $html . "</span>";
  468.  
  469.     return $html;
  470. }
  471.  
  472. // add the filters only if mcrypt is loaded
  473. if (extension_loaded('mcrypt')) {
  474.     if ($recaptcha_opt['use_mailhide_posts'])
  475.     add_filter('the_content', 'mh_insert_email');
  476.     if ($recaptcha_opt['use_mailhide_comments'])
  477.     add_filter('get_comment_text', 'mh_insert_email');
  478.     if ($recaptcha_opt['use_mailhide_rss'])
  479.     add_filter('the_content_rss', 'mh_insert_email');
  480.     if ($recaptcha_opt['use_mailhide_rss_comments'])
  481.     add_filter('comment_text_rss', 'mh_insert_email');
  482. }
  483.  
  484. /* =============================================================================
  485.  End MailHide
  486.  ============================================================================= */
  487.  
  488. /* =============================================================================
  489.  reCAPTCHA - The reCAPTCHA comment spam protection section
  490.  ============================================================================= */
  491. function recaptcha_wp_hash_comment($id)
  492. {
  493.     global $recaptcha_opt;
  494.  
  495.     if (function_exists('wp_hash'))
  496.     return wp_hash(RECAPTCHA_WP_HASH_COMMENT . $id);
  497.     else
  498.     return md5(RECAPTCHA_WP_HASH_COMMENT . $recaptcha_opt['privkey'] . $id);
  499. }
  500.  
  501. function recaptcha_wp_get_html ($recaptcha_error, $use_ssl=false) {
  502.     global $recaptcha_opt;
  503.  
  504.     return recaptcha_get_html($recaptcha_opt['pubkey'], $recaptcha_error, $use_ssl, $recaptcha_opt['re_xhtml']);
  505. }
  506.  
  507. /**
  508.  *  Embeds the reCAPTCHA widget into the comment form.
  509.  *
  510.  */
  511. function recaptcha_comment_form() {
  512.     global $user_ID, $recaptcha_opt;
  513.  
  514.     // set the minimum capability needed to skip the captcha if there is one
  515.     if ($recaptcha_opt['re_bypass'] && $recaptcha_opt['re_bypasslevel'])
  516.     $needed_capability = $recaptcha_opt['re_bypasslevel'];
  517.  
  518.     // skip the reCAPTCHA display if the minimum capability is met
  519.     if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments'])
  520.     return;
  521.  
  522.     else {
  523.         // Did the user fail to match the CAPTCHA? If so, let them know
  524.         if ($_GET['rerror'] == 'incorrect-captcha-sol')
  525.         echo "<p class=\"recaptcha-error\">" . $recaptcha_opt['error_incorrect'] . "</p>";
  526.            
  527.         //modify the comment form for the reCAPTCHA widget
  528.         $recaptcha_js_opts = <<<OPTS
  529.         <script type='text/javascript'>
  530.                 var RecaptchaOptions = { theme : '{$recaptcha_opt['re_theme']}', lang : '{$recaptcha_opt['re_lang']}' , tabindex : {$recaptcha_opt['re_tabindex']} };
  531.         </script>
  532. OPTS;
  533.  
  534.         if ($recaptcha_opt['re_xhtml']) {
  535.             $comment_string = <<<COMMENT_FORM
  536.                 <div id="recaptcha-submit-btn-area"><br /></div>
  537.                 <script type='text/javascript'>
  538.                 var sub = document.getElementById('submit');
  539.                 sub.parentNode.removeChild(sub);
  540.                 document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
  541.                 document.getElementById('submit').tabIndex = 6;
  542.                 if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
  543.                         document.getElementById('comment').value = _recaptcha_wordpress_savedcomment;
  544.                 }
  545.                 document.getElementById('recaptcha_table').style.direction = 'ltr';
  546.                 </script>
  547. COMMENT_FORM;
  548.         }
  549.  
  550.         else {
  551.             $comment_string = <<<COMMENT_FORM
  552.                 <div id="recaptcha-submit-btn-area"></div>
  553.                 <script type='text/javascript'>
  554.                 var sub = document.getElementById('submit');
  555.                 sub.parentNode.removeChild(sub);
  556.                 document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
  557.                 document.getElementById('submit').tabIndex = 6;
  558.                 if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
  559.                         document.getElementById('comment').value = _recaptcha_wordpress_savedcomment;
  560.                 }
  561.                 document.getElementById('recaptcha_table').style.direction = 'ltr';
  562.                 </script>
  563.                 <noscript>
  564.                  <style type='text/css'>#submit {display:none;}</style>
  565.                  <input name="submit" type="submit" id="submit-alt" tabindex="6" value="Submit Comment"/>
  566.                 </noscript>
  567. COMMENT_FORM;
  568.         }
  569.  
  570.         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
  571.         $use_ssl = true;
  572.         else
  573.         $use_ssl = false;
  574.  
  575.         echo $recaptcha_js_opts .  recaptcha_wp_get_html($_GET['rerror'], $use_ssl) . $comment_string;
  576.     }
  577. }
  578.  
  579. add_action('comment_form', 'recaptcha_comment_form');
  580.  
  581. function recaptcha_wp_show_captcha_for_comment() {
  582.     global $user_ID;
  583.     return true;
  584. }
  585.  
  586. $recaptcha_saved_error = '';
  587.  
  588. /**
  589.  * Checks if the reCAPTCHA guess was correct and sets an error session variable if not
  590.  * @param array $comment_data
  591.  * @return array $comment_data
  592.  */
  593. function recaptcha_wp_check_comment($comment_data) {
  594.     global $user_ID, $recaptcha_opt;
  595.     global $recaptcha_saved_error;
  596.  
  597.     // set the minimum capability needed to skip the captcha if there is one
  598.     if ($recaptcha_opt['re_bypass'] && $recaptcha_opt['re_bypasslevel'])
  599.     $needed_capability = $recaptcha_opt['re_bypasslevel'];
  600.  
  601.     // skip the filtering if the minimum capability is met
  602.     if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments'])
  603.     return $comment_data;
  604.  
  605.     if (recaptcha_wp_show_captcha_for_comment()) {
  606.         if ( $comment_data['comment_type'] == '' ) { // Do not check trackbacks/pingbacks
  607.             $challenge = $_POST['recaptcha_challenge_field'];
  608.             $response = $_POST['recaptcha_response_field'];
  609.  
  610.             $recaptcha_response = recaptcha_check_answer ($recaptcha_opt ['privkey'], $_SERVER['REMOTE_ADDR'], $challenge, $response);
  611.             if ($recaptcha_response->is_valid)
  612.             return $comment_data;
  613.             else {
  614.                 $recaptcha_saved_error = $recaptcha_response->error;
  615.                 add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';'));
  616.                 return $comment_data;
  617.             }
  618.         }
  619.     }
  620.     return $comment_data;
  621. }
  622.  
  623. /*
  624.  * If the reCAPTCHA guess was incorrect from recaptcha_wp_check_comment, then redirect back to the comment form
  625.  * @param string $location
  626.  * @param OBJECT $comment
  627.  * @return string $location
  628.  */
  629. function recaptcha_wp_relative_redirect($location, $comment) {
  630.     global $recaptcha_saved_error;
  631.     if($recaptcha_saved_error != '') {
  632.         //replace the '#comment-' chars on the end of $location with '#commentform'.
  633.  
  634.         $location = substr($location, 0,strrpos($location, '#')) .
  635.         ((strrpos($location, "?") === false) ? "?" : "&") .
  636.             'rcommentid=' . $comment->comment_ID .
  637.             '&rerror=' . $recaptcha_saved_error .
  638.             '&rchash=' . recaptcha_wp_hash_comment ($comment->comment_ID) .
  639.             '#commentform';
  640.     }
  641.     return $location;
  642. }
  643.  
  644. /*
  645.  * If the reCAPTCHA guess was incorrect from recaptcha_wp_check_comment, then insert their saved comment text
  646.  * back in the comment form.
  647.  * @param boolean $approved
  648.  * @return boolean $approved
  649.  */
  650. function recaptcha_wp_saved_comment() {
  651.     if (!is_single() && !is_page())
  652.     return;
  653.  
  654.     if ($_GET['rcommentid'] && $_GET['rchash'] == recaptcha_wp_hash_comment ($_GET['rcommentid'])) {
  655.         $comment = get_comment($_GET['rcommentid']);
  656.  
  657.         $com = preg_replace('/([\\/\(\)\+\;\'\"])/e','\'%\'.dechex(ord(\'$1\'))', $comment->comment_content);
  658.         $com = preg_replace('/\\r\\n/m', '\\\n', $com);
  659.  
  660.         echo "
  661.      <script type='text/javascript'>
  662.      var _recaptcha_wordpress_savedcomment =  '" . $com  ."';
  663.  
  664.      _recaptcha_wordpress_savedcomment = unescape(_recaptcha_wordpress_savedcomment);
  665.      </script>
  666.      ";
  667.  
  668.         wp_delete_comment($comment->comment_ID);
  669.     }
  670. }
  671.  
  672. function recaptcha_wp_blog_domain () {
  673.     $uri = parse_url(get_settings('siteurl'));
  674.     return $uri['host'];
  675. }
  676.  
  677. add_filter('wp_head', 'recaptcha_wp_saved_comment',0);
  678. add_filter('preprocess_comment', 'recaptcha_wp_check_comment',0);
  679. add_filter('comment_post_redirect', 'recaptcha_wp_relative_redirect',0,2);
  680.  
  681. function recaptcha_wp_add_options_to_admin() {
  682.     global $wpmu;
  683.  
  684.     if ($wpmu == 1 && is_site_admin()) {
  685.         add_submenu_page('wpmu-admin.php', 'reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel');
  686.         add_options_page('reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel');
  687.     }
  688.     else if ($wpmu != 1) {
  689.         add_options_page('reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel');
  690.     }
  691. }
  692.  
  693. function recaptcha_wp_options_subpanel() {
  694.     global $wpmu;
  695.     // Default values for the options array
  696.     $optionarray_def = array(
  697.         'pubkey'    => '',
  698.         'privkey'   => '',
  699.         'use_mailhide_posts' => '',
  700.         'use_mailhide_comments' => '',
  701.         'use_mailhide_rss' => '',
  702.         'use_mailhide_rss_comments' => '',
  703.         're_bypasslevel' => '3',
  704.         'mh_bypasslevel' => '3',
  705.         'mailhide_pub' => '',
  706.         'mailhide_priv' => '',
  707.         're_theme' => 'red',
  708.         're_theme_reg' => 'red',
  709.         're_lang' => 'en',
  710.         're_tabindex' => '5',
  711.         're_comments' => '1',
  712.         're_registration' => '1',
  713.         're_xhtml' => '0',
  714.       'mh_replace_link' => '',
  715.       'mh_replace_title' => '',
  716.       'error_blank' => '<strong>ERROR</strong>: Please fill in the reCAPTCHA form.',
  717.       'error_incorrect' => '<strong>ERROR</strong>: That reCAPTCHA response was incorrect.',
  718.     );
  719.  
  720.     if ($wpmu != 1)
  721.     add_option('recaptcha', $optionarray_def, 'reCAPTCHA Options');
  722.  
  723.     /* Check form submission and update options if no error occurred */
  724.     if (isset($_POST['submit'])) {
  725.         $optionarray_update = array (
  726.         'pubkey'    => trim($_POST['recaptcha_opt_pubkey']),
  727.         'privkey'   => trim($_POST['recaptcha_opt_privkey']),
  728.         'use_mailhide_posts' => $_POST['use_mailhide_posts'],
  729.         'use_mailhide_comments' => $_POST['use_mailhide_comments'],
  730.         'use_mailhide_rss' => $_POST['use_mailhide_rss'],
  731.         'use_mailhide_rss_comments' => $_POST['use_mailhide_rss_comments'],
  732.         're_bypass' => $_POST['re_bypass'],
  733.         're_bypasslevel' => $_POST['re_bypasslevel'],
  734.         'mailhide_pub' => trim($_POST['mailhide_pub']),
  735.         'mailhide_priv' => trim($_POST['mailhide_priv']),
  736.         'mh_bypass' => $_POST['mh_bypass'],
  737.         'mh_bypasslevel' => $_POST['mh_bypasslevel'],
  738.         're_theme' => $_POST['re_theme'],
  739.         're_theme_reg' => $_POST['re_theme_reg'],
  740.         're_lang' => $_POST['re_lang'],
  741.         're_tabindex' => $_POST['re_tabindex'],
  742.         're_comments' => $_POST['re_comments'],
  743.         're_registration' => $_POST['re_registration'],
  744.         're_xhtml' => $_POST['re_xhtml'],
  745.       'mh_replace_link' => $_POST['mh_replace_link'],
  746.       'mh_replace_title' => $_POST['mh_replace_title'],
  747.       'error_blank' => $_POST['error_blank'],
  748.       'error_incorrect' => $_POST['error_incorrect'],
  749.         );
  750.         // save updated options
  751.         if ($wpmu == 1)
  752.         update_site_option('recaptcha', $optionarray_update);
  753.         else
  754.         update_option('recaptcha', $optionarray_update);
  755.     }
  756.  
  757.     /* Get options */
  758.     if ($wpmu == 1)
  759.     $optionarray_def = get_site_option('recaptcha');
  760.     else
  761.     $optionarray_def = get_option('recaptcha');
  762.  
  763.     /* =============================================================================
  764.      reCAPTCHA Admin Page and Functions
  765.      ============================================================================= */
  766.  
  767.     /*
  768.      * Display an HTML <select> listing the capability options for disabling security
  769.      * for registered users.
  770.      * @param string $select_name slug to use in <select> id and name
  771.      * @param string $checked_value selected value for dropdown, slug form.
  772.      * @return NULL
  773.      */
  774.  
  775.     function recaptcha_dropdown_capabilities($select_name, $checked_value="") {
  776.         // define choices: Display text => permission slug
  777.         $capability_choices = array (
  778.         'All registered users' => 'read',
  779.         'Edit posts' => 'edit_posts',
  780.         'Publish Posts' => 'publish_posts',
  781.         'Moderate Comments' => 'moderate_comments',
  782.         'Administer site' => 'level_10'
  783.         );
  784.         // print the <select> and loop through <options>
  785.         echo '<select name="' . $select_name . '" id="' . $select_name . '">' . "\n";
  786.         foreach ($capability_choices as $text => $capability) :
  787.         if ($capability == $checked_value) $checked = ' selected="selected" ';
  788.         echo '\t <option value="' . $capability . '"' . $checked . ">$text</option> \n";
  789.         $checked = NULL;
  790.         endforeach;
  791.         echo "</select> \n";
  792.     } // end recaptcha_dropdown_capabilities()
  793.  
  794.     ?>
  795.  
  796. <!-- ############################## BEGIN: ADMIN OPTIONS ################### -->
  797. <div class="wrap">
  798. <h2>reCAPTCHA Options</h2>
  799. <h3>About reCAPTCHA</h3>
  800. <p>reCAPTCHA is a free, accessible CAPTCHA service that helps to
  801. digitize books while blocking spam on your blog.</p>
  802.  
  803. <p>reCAPTCHA asks commenters to retype two words scanned from a book to
  804. prove that they are a human. This verifies that they are not a spambot
  805. while also correcting the automatic scans of old books. So you get less
  806. spam, and the world gets accurately digitized books. Everybody wins! For
  807. details, visit the <a href="http://recaptcha.net/">reCAPTCHA website</a>.</p>
  808. <p><strong>NOTE</strong>: If you are using some form of Cache plugin you
  809. will probably need to flush/clear your cache for changes to take effect.</p>
  810.  
  811. <form name="form1" method="post"
  812.     action="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>&updated=true">
  813. <div class="submit"><input type="submit" name="submit"
  814.     value="<?php _e('Update Options') ?> &raquo;" /></div>
  815.  
  816. <!-- ****************** Operands ****************** -->
  817. <table class="form-table">
  818.     <tr valign="top">
  819.         <th scope="row">reCAPTCHA Keys</th>
  820.         <td>reCAPTCHA requires an API key, consisting of a "public" and a
  821.         "private" key. You can sign up for a <a
  822.             href="<?php echo recaptcha_get_signup_url (recaptcha_wp_blog_domain (), 'wordpress');?>"
  823.             target="0">free reCAPTCHA key</a>. <br />
  824.         <p class="re-keys"><!-- reCAPTCHA public key --> <label
  825.             class="which-key" for="recaptcha_opt_pubkey">Public Key:</label> <input
  826.             name="recaptcha_opt_pubkey" id="recaptcha_opt_pubkey" size="40"
  827.             value="<?php  echo $optionarray_def['pubkey']; ?>" /> <br />
  828.         <!-- reCAPTCHA private key --> <label class="which-key"
  829.             for="recaptcha_opt_privkey">Private Key:</label> <input
  830.             name="recaptcha_opt_privkey" id="recaptcha_opt_privkey" size="40"
  831.             value="<?php  echo $optionarray_def['privkey']; ?>" /></p>
  832.         </td>
  833.     </tr>
  834.     <tr valign="top">
  835.         <th scope="row">Comment Options</th>
  836.         <td><!-- Show reCAPTCHA on the comment post --> <big><input
  837.             type="checkbox" name="re_comments" id="re_comments" value="1"
  838.             <?php if($optionarray_def['re_comments'] == true){echo 'checked="checked"';} ?> />
  839.         <label for="re_comments">Enable reCAPTCHA for comments.</label></big>
  840.         <br />
  841.         <!-- Don't show reCAPTCHA to admins -->
  842.         <div class="theme-select"><input type="checkbox" id="re_bypass"
  843.             name="re_bypass"
  844.             <?php if($optionarray_def['re_bypass'] == true){echo 'checked="checked"';} ?> />
  845.         <label name="re_bypass" for="re_bypass">Hide reCAPTCHA for <strong>registered</strong>
  846.         users who can:</label> <?php recaptcha_dropdown_capabilities('re_bypasslevel', $optionarray_def['re_bypasslevel']); // <select> of capabilities ?>
  847.         </div>
  848.  
  849.         <!-- The theme selection -->
  850.         <div class="theme-select"><label for="re_theme">Theme:</label> <select
  851.             name="re_theme" id="re_theme">
  852.             <option value="red"
  853.             <?php if($optionarray_def['re_theme'] == 'red'){echo 'selected="selected"';} ?>>Red</option>
  854.             <option value="white"
  855.             <?php if($optionarray_def['re_theme'] == 'white'){echo 'selected="selected"';} ?>>White</option>
  856.             <option value="blackglass"
  857.             <?php if($optionarray_def['re_theme'] == 'blackglass'){echo 'selected="selected"';} ?>>Black
  858.             Glass</option>
  859.             <option value="clean"
  860.             <?php if($optionarray_def['re_theme'] == 'clean'){echo 'selected="selected"';} ?>>Clean</option>
  861.         </select></div>
  862.         <!-- Tab Index --> <label for="re_tabindex">Tab Index (<em>e.g. WP: <strong>5</strong>,
  863.         WPMU: <strong>3</strong></em>):</label> <input name="re_tabindex"
  864.             id="re_tabindex" size="5"
  865.             value="<?php  echo $optionarray_def['re_tabindex']; ?>" /> <br />
  866.             <?php global $wpmu; if ($wpmu == 1 || $wpmu == 0) { ?></td>
  867.     </tr>
  868.     <tr valign="top">
  869.         <th scope="row">Registration Options</th>
  870.         <td><!-- Show reCAPTCHA on the registration page --> <big><input
  871.             type="checkbox" name="re_registration" id="re_registration" value="1"
  872.             <?php if($optionarray_def['re_registration'] == true){echo 'checked="checked"';} ?> />
  873.         <label for="re_registration">Enable reCAPTCHA on registration form.</label></big>
  874.         <br />
  875.         <!-- The theme selection -->
  876.         <div class="theme-select"><label for="re_theme_reg">Theme:</label> <select
  877.             name="re_theme_reg" id="re_theme_reg">
  878.             <option value="red"
  879.             <?php if($optionarray_def['re_theme_reg'] == 'red'){echo 'selected="selected"';} ?>>Red</option>
  880.             <option value="white"
  881.             <?php if($optionarray_def['re_theme_reg'] == 'white'){echo 'selected="selected"';} ?>>White</option>
  882.             <option value="blackglass"
  883.             <?php if($optionarray_def['re_theme_reg'] == 'blackglass'){echo 'selected="selected"';} ?>>Black
  884.             Glass</option>
  885.             <option value="clean"
  886.             <?php if($optionarray_def['re_theme_reg'] == 'clean'){echo 'selected="selected"';} ?>>Clean</option>
  887.         </select></div>
  888.         <?php } ?></td>
  889.     </tr>
  890.     <tr valign="top">
  891.         <th scope="row">Error Messages</th>
  892.         <td>
  893.         <p>The following are the messages to display when the user does not
  894.         enter a CAPTCHA response or enters the incorrect CAPTCHA response.</p>
  895.         <!-- Error Messages -->
  896.         <p class="re-keys"><!-- Blank --> <label class="which-key"
  897.             for="error_blank">No response entered:</label> <input
  898.             name="error_blank" id="error_blank" size="80"
  899.             value="<?php echo $optionarray_def['error_blank']; ?>" /> <br />
  900.         <!-- Incorrect --> <label class="which-key" for="error_incorrect">Incorrect
  901.         response entered:</label> <input name="error_incorrect"
  902.             id="error_incorrect" size="80"
  903.             value="<?php echo $optionarray_def['error_incorrect']; ?>" /></p>
  904.         </td>
  905.         </th>
  906.     </tr>
  907.     <tr valign="top">
  908.         <th scope="row">General Settings</th>
  909.         <td><!-- The language selection -->
  910.         <div class="lang-select"><label for="re_lang">Language:</label> <select
  911.             name="re_lang" id="re_lang">
  912.             <option value="en"
  913.             <?php if($optionarray_def['re_lang'] == 'en'){echo 'selected="selected"';} ?>>English</option>
  914.             <option value="nl"
  915.             <?php if($optionarray_def['re_lang'] == 'nl'){echo 'selected="selected"';} ?>>Dutch</option>
  916.             <option value="fr"
  917.             <?php if($optionarray_def['re_lang'] == 'fr'){echo 'selected="selected"';} ?>>French</option>
  918.             <option value="de"
  919.             <?php if($optionarray_def['re_lang'] == 'de'){echo 'selected="selected"';} ?>>German</option>
  920.             <option value="pt"
  921.             <?php if($optionarray_def['re_lang'] == 'pt'){echo 'selected="selected"';} ?>>Portuguese</option>
  922.             <option value="ru"
  923.             <?php if($optionarray_def['re_lang'] == 'ru'){echo 'selected="selected"';} ?>>Russian</option>
  924.             <option value="es"
  925.             <?php if($optionarray_def['re_lang'] == 'es'){echo 'selected="selected"';} ?>>Spanish</option>
  926.             <option value="tr"
  927.             <?php if($optionarray_def['re_lang'] == 'tr'){echo 'selected="selected"';} ?>>Turkish</option>
  928.         </select> </label></div>
  929.         <!-- Whether or not to be XHTML 1.0 Strict compliant --> <input
  930.             type="checkbox" name="re_xhtml" id="re_xhtml" value="1"
  931.             <?php if($optionarray_def['re_xhtml'] == true){echo 'checked="checked"';} ?> />
  932.         <label for="re_xhtml">Be XHTML 1.0 Strict compliant. <strong>Note</strong>:
  933.         Bad for users who don't have Javascript enabled in their browser
  934.         (Majority do).</label> <br />
  935.         </td>
  936.     </tr>
  937. </table>
  938.  
  939. <h3>About MailHide</h3>
  940. <p><a href="http://mailhide.recaptcha.net/"
  941.     title="mailhide email obfuscation">MailHide</a> uses reCAPTCHA to
  942. protect email adresses displayed on your blog from being harvested for
  943. spam.</p>
  944. <p>Activating MailHide will automatically hide all emails in posts and
  945. comments from spam bots. For example, support@recaptcha.net would become
  946. supp<a
  947.     href="http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE="
  948.     onclick="window.open('http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE=', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;"
  949.     title="Reveal this e-mail address">...</a>@recaptcha.net. There are
  950. also options below for choosing the text to show for hidden emails.</p>
  951. <p>MailHide also requires a public and private key which you can
  952. generate using the <a href="http://mailhide.recaptcha.net/apikey">key
  953. generation service</a>.</p>
  954. <table class="form-table">
  955.     <tr valign="top">
  956.         <th scope="row">MailHide Keys</th>
  957.         <td><!-- MailHide Enabler --> <big>Enable MailHide email obfuscation
  958.         for:</big><br />
  959.         <input type="checkbox" name="use_mailhide_posts"
  960.             id="use_mailhide_posts" value="1"
  961.             <?php if($optionarray_def['use_mailhide_posts'] == true){echo 'checked="checked"';} ?> /><label
  962.             for="use_mailhide_posts">Posts/Pages</label><br />
  963.         <input type="checkbox" name="use_mailhide_comments"
  964.             id="use_mailhide_comments" value="1"
  965.             <?php if($optionarray_def['use_mailhide_comments'] == true){echo 'checked="checked"';} ?> /><label
  966.             for="use_mailhide_comments">Comments</label><br />
  967.         <input type="checkbox" name="use_mailhide_rss" id="use_mailhide_rss"
  968.             value="1"
  969.             <?php if($optionarray_def['use_mailhide_rss'] == true){echo 'checked="checked"';} ?> /><label
  970.             for="use_mailhide_rss">RSS Feed of Posts/Pages</label><br />
  971.         <input type="checkbox" name="use_mailhide_rss_comments"
  972.             id="use_mailhide_rss_comments" value="1"
  973.             <?php if($optionarray_def['use_mailhide_rss_comments'] == true){echo 'checked="checked"';} ?> /><label
  974.             for="use_mailhide_rss_comments">RSS Feed of Comments</label><br />
  975.         <!-- Public Key -->
  976.         <p class="re-keys"><label class="which-key" for="mailhide_pub">Public
  977.         Key:</label> <input name="mailhide_pub" id="mailhide_pub" size="40"
  978.             value="<?php echo $optionarray_def['mailhide_pub']; ?>" /> <br />
  979.         <!-- Private Key --> <label class="which-key" for="mailhide_priv">Private
  980.         Key:</label> <input name="mailhide_priv" id="mailhide_priv" size="40"
  981.             value="<?php echo $optionarray_def['mailhide_priv']; ?>" /></p>
  982.         </td>
  983.     </tr>
  984.     <tr valign="top">
  985.         <th scope="row">Visibility Options</th>
  986.         <td><!-- Don't show mailhide to users who can... -->
  987.         <div class="theme-select"><input type="checkbox" id="mh_bypass"
  988.             name="mh_bypass"
  989.             <?php if($optionarray_def['mh_bypass'] == true){echo 'checked="checked"';} ?> />
  990.         <label for="mh_bypass">Show full email adresses to <strong>registered</strong>
  991.         users who can:</label> <?php recaptcha_dropdown_capabilities('mh_bypasslevel', $optionarray_def['mh_bypasslevel']); // <select> of capabilities ?>
  992.         </div>
  993.         <!-- Email Replacement Text -->
  994.         <p class="re-keys">
  995.         <p>The following allows you to show the replaced links differently.
  996.         Usually, you get something like this, supp<a
  997.             href="http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE="
  998.             onclick="window.open('http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE=', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;"
  999.             title="Reveal this e-mail address">...</a>@recaptcha.net , where the
  1000.         email is broken up into two pieces and then a link with dots is placed
  1001.         in the middle. The <strong>Email Replacement Text</strong> value lets
  1002.         you choose what to name the link and then the <strong>Reveal Link
  1003.         Title</strong> value determines the text that is shown when the link
  1004.         is hovered over.</p>
  1005.         <p>For example, if the <strong>Email Replacement Text</strong> option
  1006.         is set to <strong>HIDDEN EMAIL</strong> and the <strong>Reveal Link
  1007.         Title</strong> option is set to <strong>Click here to reveal this
  1008.         address</strong>, then ALL emails will be hidden like this: <a
  1009.             href="http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE="
  1010.             onclick="window.open('http://mailhide.recaptcha.net/d?k=01a8k2oW96qNZ4JhiFx5zDRg==&amp;c=yifPREOOvfzA0o3dbnnwP8fy91UD8RL4SspHDIKHVRE=', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;"
  1011.             title="Click here to reveal this address">HIDDEN EMAIL</a></p>
  1012.         <p>If you want to maintain the default method of hiding emails then
  1013.         leave both boxes blank.</p>
  1014.         <label class="whch-key" for="mh_replace_link">EMail Replacement Text:</label>
  1015.         <input name="mh_replace_link" id="mh_replace_link" size="40"
  1016.             value="<?php echo $optionarray_def['mh_replace_link']; ?>" /> <br />
  1017.         <label class="which-key" for="mh_replace_title">Reveal Link Title:</label>
  1018.         <input name="mh_replace_title" id="mh_replace_title" size="40"
  1019.             value="<?php echo $optionarray_def['mh_replace_title']; ?>" /></p>
  1020.         </td>
  1021.     </tr>
  1022.     <tr valign="top">
  1023.         <th scope="row">Other Information</th>
  1024.         <td><!-- MailHide CSS -->
  1025.         <p>CSS: You can style the hidden emails and much more in the <strong>recaptcha.css</strong>
  1026.         stylesheet in wp-recaptcha's plugin folder.</p>
  1027.         <p>You can bypass email hiding for an address by enclosing it within <strong>[nohide][/nohide]</strong>,
  1028.         ex. [nohide]some@email.com[/nohide].</p>
  1029.         </td>
  1030.     </tr>
  1031. </table>
  1032. <div class="submit"><input type="submit" name="submit"
  1033.     value="<?php _e('Update Options') ?> &raquo;" /></div>
  1034.  
  1035. </form>
  1036. <p class="copyright">&copy; Copyright 2008&nbsp;&nbsp;<a
  1037.     href="http://recaptcha.net">reCAPTCHA</a></p>
  1038. </div>
  1039. <!-- [wrap] -->
  1040. <!-- ############################## END: ADMIN OPTIONS ##################### -->
  1041.  
  1042.             <?php
  1043. }
  1044.  
  1045. /* =============================================================================
  1046. Apply the admin menu
  1047. ============================================================================= */
  1048.  
  1049. add_action('admin_menu', 'recaptcha_wp_add_options_to_admin');
  1050.  
  1051. // If no reCAPTCHA API keys have been entered
  1052. if ( !($recaptcha_opt ['pubkey'] && $recaptcha_opt['privkey'] ) && !isset($_POST['submit']) ) {
  1053.     function recaptcha_warning() {
  1054.         global $wpmu;
  1055.  
  1056.         $path = plugin_basename(__FILE__);
  1057.         $top = 0;
  1058.         if ($wp_version <= 2.5)
  1059.         $top = 12.7;
  1060.         else
  1061.         $top = 7;
  1062.         echo "
  1063.         <div id='recaptcha-warning' class='updated fade-ff0000'><p><strong>reCAPTCHA is not active</strong> You must <a href='options-general.php?page=" . $path . "'>enter your reCAPTCHA API key</a> for it to work</p></div>
  1064.         <style type='text/css'>
  1065.         #adminmenu { margin-bottom: 5em; }
  1066.         #recaptcha-warning { position: absolute; top: {$top}em; }
  1067.         </style>
  1068.         ";
  1069.     }
  1070.  
  1071.     if (($wpmu == 1 && is_site_admin()) || $wpmu != 1)
  1072.     add_action('admin_footer', 'recaptcha_warning');
  1073.  
  1074.     return;
  1075. }
  1076.  
  1077. $mailhide_enabled = ($recaptcha_opt['use_mailhide_posts'] || $recaptcha_opt['use_mailhide_comments'] || $recaptcha_opt['use_mailhide_rss'] || $recaptcha_opt['use_mailhide_rss_comments']);
  1078.  
  1079. // If the mcrypt PHP module isn't loaded then display an alert
  1080. if (($mailhide_enabled && !extension_loaded('mcrypt')) && !isset($_POST['submit'])) {
  1081.     function mcrypt_warning() {
  1082.         global $wpmu;
  1083.  
  1084.         $path = plugin_basename(__FILE__);
  1085.         $top = 0;
  1086.         if ($wp_version <= 2.5)
  1087.         $top = 12.7;
  1088.         else
  1089.         $top = 7;
  1090.         echo "
  1091.         <div id='recaptcha-warning' class='updated fade-ff0000'><p><strong>MailHide is not active</strong> You must have the <a href='http://us3.php.net/mcrypt'>mcrypt</a> module loaded for it to work</p></div>
  1092.         <style type='text/css'>
  1093.         #adminmenu { margin-bottom: 5em; }
  1094.         #recaptcha-warning { position: absolute; top: {$top}em; }
  1095.         </style>
  1096.         ";
  1097.     }
  1098.  
  1099.     if (($wpmu == 1 && is_site_admin()) || $wpmu != 1)
  1100.     add_action('admin_footer', 'mcrypt_warning');
  1101.  
  1102.     return;
  1103. }
  1104.  
  1105. // If MailHide is enabled but no keys have been entered
  1106. if ($mailhide_enabled && !($recaptcha_opt['mailhide_pub'] && $recaptcha_opt['mailhide_pub']) && !isset($_POST['submit'])) {
  1107.     function mailhide_warning() {
  1108.         global $wpmu;
  1109.  
  1110.         $path = plugin_basename(__FILE__);
  1111.         $top = 0;
  1112.  
  1113.         if ($wp_version <= 2.5)
  1114.         $top = 12.7;
  1115.         else
  1116.         $top = 7;
  1117.            
  1118.         echo "
  1119.         <div id='recaptcha-warning' class='updated fade-ff0000'><p><strong>MailHide is not active</strong> You must <a href='options-general.php?page=" . $path . "'>enter your MailHide API keys</a> for it to work</p></div>
  1120.         <style type='text/css'>
  1121.         #adminmenu { margin-bottom: 5em; }
  1122.         #recaptcha-warning { position: absolute; top: {$top}em; }
  1123.         </style>
  1124.         ";
  1125.     }
  1126.  
  1127.     if (($wpmu == 1 && is_site_admin()) || $wpmu != 1)
  1128.     add_action('admin_footer', 'mailhide_warning');
  1129.  
  1130.     return;
  1131. }
  1132.  
  1133. /* =============================================================================
  1134.  End Apply the admin menu
  1135.  ============================================================================= */
  1136. ?>
Add Comment
Please, Sign In to add comment