WordPress.org

Plugin Directory

Changeset 227565


Ignore:
Timestamp:
04/11/10 05:37:59 (8 years ago)
Author:
wmrom
Message:

Uploading v1.9

Location:
onw-simple-contact-form/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • onw-simple-contact-form/trunk/onw_simple_contact.php

    r200266 r227565  
    44Plugin URI: http://www.olympianetworks.com/projects/onw-simple-contact-form/ 
    55Description: This Plugin creates a simple contact form using shortcode in posts or pages. 
    6 Version: 1.8 
     6Version: 1.9 
    77Author: John Bloch 
    88Author URI: http://www.olympianetworks.com/about-us/developers/john-p-bloch/ 
     
    4040  // Include the reCAPTCHA library 
    4141  include_once(WP_PLUGIN_DIR . '/onw-simple-contact-form/recaptchalib.php'); 
    42    
     42 
    4343} 
     44 
     45unset( $onw_opts ); 
    4446 
    4547/* 
     
    5254 * onw_scf_add_options_menu() adds the ONW Simple Contact page to the 
    5355 * list of settings page on the admin side, but only displays it to users 
    54  * who can manage options.   
     56 * who can manage options. 
    5557 */ 
    5658 
     
    6264 * onw_scf_activation_() registers the default settings and sets new defaults 
    6365 * the user has some but not all of the settings set. 
    64  *  
    65  * onw_scf_activation_ is run when the plugin is activated.       
     66 * 
     67 * This function also checks for the presence of the wp-recaptcha plugin 
     68 * and the wp-recaptcha-library plugin. If either one is active, this plugin 
     69 * will use their api keys and (in the case of wp-recaptcha) the theme color. 
     70 * 
     71 * onw_scf_activation_ is run when the plugin is activated. 
    6672 */ 
    6773 
     
    6975 
    7076  $options = get_option('onw-simple-contact'); 
     77 
     78  // Check if the wp-recaptcha or recaptcha-library plugins are present and 
     79  // active. If so, set some default values from their options. 
     80  $wp_recaptcha = get_option('recaptcha'); 
     81  $recaptcha_library = get_option('msw_wprecaptcha_option'); 
    7182   
     83  $plugins = get_option('active_plugins'); 
     84   
     85  if( !in_array( 'wp-recaptcha/wp-recaptcha.php', $plugins ) ) 
     86    $wp_recaptcha = false; 
     87     
     88  if( !in_array( 'wp-recaptcha-library/recaptcha-library.php', $plugins ) ) 
     89    $recaptcha_library = false; 
     90     
     91  if($wp_recaptcha){ 
     92    $public_key = $wp_recaptcha['pubkey']; 
     93    $private_key = $wp_recaptcha['privkey']; 
     94    $recaptcha_theme = $wp_recaptcha['re_theme']; 
     95  } elseif($recaptcha_library){ 
     96    $public_key = $recaptcha_library['public_key']; 
     97    $private_key = $recaptcha_library['private_key']; 
     98    $recaptcha_theme = 'red'; 
     99  } else { 
     100    $public_key = ''; 
     101    $private_key = ''; 
     102    $recaptcha_theme = 'red'; 
     103  } 
     104 
    72105  // If there are no options, set the default values 
    73106  if(!$options){ 
    74    
    75     $ad_email = get_bloginfo('admin_email');  
     107 
     108    $ad_email = get_bloginfo('admin_email'); 
    76109    // default email is the blog's admin address, reCAPTCHA is off by default 
    77      
     110 
    78111    $onw_def_options = array( 
    79112      'to_email' => $ad_email, 
    80113      'def_subj' => '%email% has sent you a message', 
    81114      'recaptcha' => 'off', 
    82       'recaptcha_pubkey' => '', 
    83       'recaptcha_prikey' => '', 
     115      'recaptcha_theme' => $recaptcha_theme, 
     116      'recaptcha_pubkey' => $public_key, 
     117      'recaptcha_prikey' => $private_key, 
    84118      'labels' => array( 
    85119            'top_text' => 'Please use the form below to send an email to the site administrator.', 
     
    95129          ) 
    96130    ); 
    97      
     131 
    98132    // Add the options to the options table in the database 
    99133    add_option('onw-simple-contact', $onw_def_options); 
    100      
     134 
    101135  } else { // If there are options, make sure all of them are accounted for 
    102    
     136 
    103137    if(!isset($options['to_email'])){ 
    104138      $ad_email = get_bloginfo('admin_email'); 
     
    107141      $new_opts['to_email'] = $options['to_email']; 
    108142    } 
    109      
     143 
    110144    if(!isset($options['def_subj'])){ 
    111145      $new_opts['def_subj'] = '%email% has sent you a message'; 
     
    113147      $new_opts['def_subj'] = $options['def_subj']; 
    114148    } 
    115      
     149 
    116150    if(!isset($options['recaptcha'])){ 
    117151      $new_opts['recaptcha'] = 'off'; 
     
    119153      $new_opts['recaptcha'] = $options['recaptcha']; 
    120154    } 
    121      
    122     if(!isset($options['recaptcha_pubkey'])){ 
    123       $new_opts['recaptcha_pubkey'] = ''; 
     155 
     156    if(!isset($options['recaptcha_theme'])){ 
     157      $new_opts['recaptcha_theme'] = $recaptcha_theme; 
     158    } else { 
     159      $new_opts['recaptcha_theme'] = $options['recaptcha_theme']; 
     160    } 
     161 
     162    if(!isset($options['recaptcha_pubkey']) || $options['recaptcha_pubkey'] == ''){ 
     163      $new_opts['recaptcha_pubkey'] = $public_key; 
    124164    } else { 
    125165      $new_opts['recaptcha_pubkey'] = $options['recaptcha_pubkey']; 
    126166    } 
    127      
    128     if(!isset($options['recaptcha_prikey'])){ 
    129       $new_opts['recaptcha_prikey'] = ''; 
     167 
     168    if(!isset($options['recaptcha_prikey']) || $options['recaptcha_prikey'] == ''){ 
     169      $new_opts['recaptcha_prikey'] = $private_key; 
    130170    } else { 
    131171      $new_opts['recaptcha_prikey'] = $options['recaptcha_prikey']; 
    132172    } 
    133      
     173 
    134174    if(!isset($options['labels'])){ 
    135175      $new_opts['labels'] = array( 
     
    143183      $new_opts['labels'] = $options['labels']; 
    144184    } 
    145      
     185 
    146186    if(!isset($options['fieldset'])){ 
    147187      $new_opts['fieldset'] = 'yes'; 
     
    149189      $new_opts['fieldset'] = $options['fieldset']; 
    150190    } 
    151      
     191 
    152192    if(!isset($options['box_size'])){ 
    153193      $new_opts['box_size'] = array( 
     
    158198      $new_opts['box_size'] = $options['box_size']; 
    159199    } 
    160      
     200 
    161201    // And update the existing options. 
    162202    update_option('onw-simple-contact',$new_opts); 
     
    169209/* 
    170210 * onw_scf_submenu_add() adds the HTML for the options page, and also 
    171  * updates the database.    
     211 * updates the database. 
    172212 */ 
    173213 
    174214function onw_scf_submenu_add(){ 
    175    
     215 
     216  // Set an array with the possible values for the recaptcha theme 
     217  $recaptcha_theme_vals = array( 'red', 'white', 'blackglass', 'clean' ); 
     218 
    176219  if( $_POST['submitted'] == 'submitted' ){ // if the configuration form was submitted 
    177    
     220 
    178221    $old_onw_opts = get_option( 'onw-simple-contact' ); 
    179      
     222 
    180223    $recaptcha = ( $_POST['recaptcha'] == 'on' )? 'on': 'off'; 
    181      
     224 
    182225    // update the options with the new values 
    183226    $onw_options_up = array( 
     
    188231      'recaptcha_prikey' => $_POST['recaptcha_prikey'] 
    189232    ); 
    190      
     233 
    191234    // Merge the new values into the old options 
    192235    $onw_options_up = array_merge( $old_onw_opts, $onw_options_up ); 
    193      
     236 
    194237    // And update 
    195238    update_option( 'onw-simple-contact', $onw_options_up ); 
    196      
     239 
    197240  } elseif( $_POST['submitted'] == 'submitted2' ){ // If the display form was submitted 
    198      
     241 
    199242    // Get the old options 
    200243    $old_onw_opts = get_option( 'onw-simple-contact' ); 
    201      
     244 
    202245    // Set the value for the fieldset toggle 
    203246    $fieldset = ( $_POST['display-fieldset'] == 'yes' )? 'yes': 'no'; 
    204      
     247 
     248    // Determine the value for the recaptcha theme using the array above 
     249    $recaptcha_theme_vals = array( 'red', 'white', 'blackglass', 'clean' ); 
     250    $theme = ( in_array($_POST['recaptcha_theme'],$recaptcha_theme_vals) )? $_POST['recaptcha_theme']: 'red'; 
     251 
    205252    // Compile the options updates into an array 
    206253    $new_onw_opts = array( 
     
    213260          ), 
    214261      'fieldset' => $fieldset, 
     262      'recaptcha_theme' => $theme, 
    215263      'box_size' => array ( 
    216264            'width' => $_POST['m-box-width'], 
     
    218266          ) 
    219267    ); 
    220      
     268 
    221269    // Merge the arrays so you retain the unchanged config values 
    222270    $new_onw_opts = array_merge( $old_onw_opts, $new_onw_opts ); 
    223      
     271 
    224272    // Update the options 
    225273    update_option( 'onw-simple-contact', $new_onw_opts ); 
    226      
    227   } 
    228    
     274 
     275  } 
     276 
    229277  // Put the current options into a variable. 
    230278  $onw_opt_array = get_option( 'onw-simple-contact' ); 
    231    
     279 
    232280  // Set the labels and message box size into separate variables for easier access later 
    233281  $onwscf_labels = $onw_opt_array['labels']; 
    234282  $onw_box_size = $onw_opt_array['box_size']; 
    235    
     283 
    236284  // Write the Header HTML 
    237285?><div class="wrap"> 
     
    245293      </li> 
    246294    </ul> 
    247      
     295 
    248296<?php 
    249    
     297 
    250298  // If you're looking at the display options page, display the proper page 
    251299  if( $_GET['sp'] == 'display' ): 
    252    
     300 
    253301?> 
    254302 
     
    263311              <input type="checkbox" name="display-fieldset" id="display-fieldset" value="yes"<?php if($onw_opt_array['fieldset'] == 'yes') { echo ' checked="checked"'; } ?> onclick="javascript:if(this.checked){document.getElementById('fieldset-legend').disabled = false; } else { document.getElementById('fieldset-legend').disabled = true; };" />&nbsp;&nbsp;<span class="description">The fieldset is the box around the whole form.</span><br /> 
    264312              <label for="fieldset-legend">Fieldset Text:</label>&nbsp;&nbsp;<input type="text" name="fieldset-legend" id="fieldset-legend" size="40" value="<?php echo $onwscf_labels['fieldset']; ?>"<?php if($onw_opt_array['fieldset'] != 'yes' ){ echo ' disabled="disabled"'; } ?> /> 
     313            </td> 
     314          </tr> 
     315          <tr> 
     316            <th scope="row"> 
     317              <label for="recaptcha_theme">Recaptcha Color Scheme</label> 
     318            </th> 
     319            <td> 
     320              <select name="recaptcha_theme" id="recaptcha_theme"> 
     321<?php 
     322foreach($recaptcha_theme_vals as $rtv){ 
     323  $default_selected = ( $rtv == $onw_opt_array['recaptcha_theme'] )? " selected='selected'": ""; 
     324  echo " 
     325                <option value='$rtv'$default_selected>".ucfirst($rtv)."</option>"; 
     326} 
     327?> 
     328              </select> 
    265329            </td> 
    266330          </tr> 
     
    291355 
    292356<?php 
    293    
     357 
    294358  // Otherwise, display the default configuration page. 
    295359  else: 
    296    
     360 
    297361?> 
    298362    <form name="form1" method="post" action="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>&updated=true"> 
     
    314378              <input type="text" name="def_subj" id="def_subj" value="<?php 
    315379              $onw_def_subj = str_replace('\\','',$onw_opt_array['def_subj']); 
    316               echo str_replace('"','&rdquo;',$onw_def_subj);  
     380              echo str_replace('"','&rdquo;',$onw_def_subj); 
    317381              ?>" size="80" />&nbsp;<br /><span class="description">The default subject is the subject line in the email that forms will use unless another subject line is given in the shortcode.<br /> 
    318382              <br />To use the user's given name (the one they provide in the form) use </span>%name%<span class="description"><br /> 
     
    326390            <td> 
    327391              <select name="recaptcha" id="recaptcha"<?php 
    328                 if( $onw_opt_array['recaptcha_pubkey'] == '' || $onw_opt_array['recaptcha_prikey'] == '' ) {  
     392                if( $onw_opt_array['recaptcha_pubkey'] == '' || $onw_opt_array['recaptcha_prikey'] == '' ) { 
    329393                  // if either one of the keys is empty, disable the dropdown 
    330394                  echo ' disabled="disabled"'; 
     
    361425 
    362426  endif; 
    363    
     427 
    364428  // Finish off the HTML 
    365429  echo "\n</div>\n"; 
     
    372436/* 
    373437================================================================================ 
    374                           TINYMCE RTE INTEGRATION       
     438                          TINYMCE RTE INTEGRATION 
    375439================================================================================ 
    376440*/ 
     
    380444 * if the logged in user is allowed to edit post/pages and if they have 
    381445 * the rich text editor turned on. 
    382  *  
     446 * 
    383447 * onw_sce_addbuttons hooks the filter for registering the onwsc plugin 
    384  * with tinyMCE editors, as well as inserting the correct button.     
     448 * with tinyMCE editors, as well as inserting the correct button. 
    385449 */ 
    386450 
     
    390454  if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) 
    391455  return; 
    392    
     456 
    393457  // Add only in Rich Editor mode 
    394458  if ( get_user_option('rich_editing') == 'true') { 
    395    
     459 
    396460    add_filter("mce_external_plugins", "onwscf_mce_plugin_load"); 
    397461    add_filter('mce_buttons', 'onwscf_mce_register_button'); 
    398      
    399   } 
    400    
     462 
     463  } 
     464 
    401465} 
    402466 
    403467/** 
    404468 * onwscf_mce_plugin_load adds the tinyMCE plugin to the array of registered 
    405  * plugins whenever a tinyMCE editor is initialized.   
    406  */  
     469 * plugins whenever a tinyMCE editor is initialized. 
     470 */ 
    407471 
    408472function onwscf_mce_plugin_load($plugin_array){ 
    409    
     473 
    410474  // Set the url of the editor_plugin.js file 
    411475  $plug = WP_PLUGIN_URL . '/onw-simple-contact-form/js/editor_plugin.js'; 
    412    
     476 
    413477  // Add it to the plugin array 
    414478  $plugin_array['onwsc'] = $plug; 
    415    
     479 
    416480  // Return the plugin array 
    417481  return $plugin_array; 
    418    
     482 
    419483} 
    420484 
    421485/** 
    422486 * onwscf_mce_register_button adds the button information to the array 
    423  * of tinyMCE buttons.  
    424  */  
     487 * of tinyMCE buttons. 
     488 */ 
    425489 
    426490function onwscf_mce_register_button($buttons){ 
     
    428492  // Add the button's name to the array of buttons 
    429493  array_push($buttons, "separator", "onwscb"); 
    430    
     494 
    431495  // Return the buttons array 
    432496  return $buttons; 
    433    
     497 
    434498} 
    435499 
     
    445509/* 
    446510 * The onw_form_output() function prepares the HTML which will get 
    447  * inserted into the page if the form has not yet been submitted.  
    448  */ 
    449   
     511 * inserted into the page if the form has not yet been submitted. 
     512 */ 
     513 
    450514function onw_form_output ( $recaptcha, $public_key, $inp = array('name'=>'', 'email'=>'', 'message'=>'', 'check'=>'') ) { 
    451    
     515 
    452516  // Get the options to insert labels, etc. into form. 
    453517  $onw_opts = get_option( 'onw-simple-contact' ); 
    454    
     518 
    455519  // Put labels and dimensions into their own variables for easier access 
    456520  $labels = $onw_opts['labels']; 
    457521  $m_size = $onw_opts['box_size']; 
    458    
     522 
    459523  // Put the form into a variable... 
    460524  $form_output = ' 
     
    462526  <form id="onw_contact_form" name="onw_contact_form" method="post" action="#onw_contact_form"> 
    463527  '; 
    464    
     528 
    465529  // If the fieldset toggle is checked... 
    466530  if( $onw_opts['fieldset'] == 'yes' ){ 
    467      
     531 
    468532    // Add the fieldset and legend 
    469533    $form_output .= ' 
    470534    <fieldset> 
    471535      <legend>'.$labels['fieldset'].'</legend>'; 
    472        
     536 
    473537  } // End fieldset IF 
    474    
     538 
    475539  $form_output .= ' 
    476540      <p>All fields are required.</p> 
     
    479543      <p>'.$labels['message'].'<br /> 
    480544      <textarea id="uMessage" name="uMessage" rows="'.$m_size['height'].'" cols="'.$m_size['width'].'">'.$inp['message'].'</textarea></p>'; 
    481        
     545 
    482546  if( $recaptcha == 'off' ) { // if reCAPTCHA is off, use the basic check 
    483547    $form_output .= '<p id="bot-check"><img src="'; 
     
    487551      <p><input type="button" name="uSend" id="uSend" value="Send" onclick="onwFormValidate()" /></p> 
    488552      '; 
    489        
     553 
    490554    // If the fieldset toggle is checked... 
    491555    if( $onw_opts['fieldset'] == 'yes' ){ 
    492        
     556 
    493557      // Close the fieldset 
    494558      $form_output .= ' 
    495559    </fieldset> 
    496560    '; 
    497      
    498     } 
    499      
     561 
     562    } 
     563 
    500564    $form_output .= ' 
    501565  </form>'; 
    502566  } else { // Otherwise, use reCAPTCHA 
    503      
     567 
    504568    $form_output .= '<p id="bot-check">'.onw_recaptcha_get_html($public_key).'</p> 
    505569        <input type="hidden" name="uVal" id="uVal" value="true" /> 
    506570      <p><input type="button" name="uSend" id="uSend" value="Send" onclick="onwFormValidate()" /></p> 
    507571      '; 
    508      
     572 
    509573    // If the fieldset toggle is checked... 
    510574    if( $onw_opts['fieldset'] == 'yes' ){ 
    511        
     575 
    512576      // Close the fieldset 
    513577      $form_output .= ' 
    514578    </fieldset> 
    515579    '; 
    516      
     580 
    517581    } 
    518582    $form_output .= ' 
    519583  </form>'; 
    520584  } // End reCAPTCHA if/elseif 
    521    
     585 
    522586  // And return that variable. 
    523   return $form_output;   
     587  return $form_output; 
    524588} // End of onw_form_output function 
    525589 
     
    527591 * The onw_form_val_js() function prepares the html which will get inserted 
    528592 * into the page just above the form.  This is for client-side validation 
    529  * of the form input.   
    530  */ 
    531  
    532 function onw_form_val_js($recaptcha) { 
    533    
     593 * of the form input. 
     594 */ 
     595 
     596function onw_form_val_js($recaptcha, $recaptcha_color) { 
     597 
    534598  // Prepare the javascript and assign it to a variable... 
    535   $js_output = '<script language="Javascript" type="text/javascript"> 
     599  $js_output = '<script language="Javascript" type="text/javascript">'; 
     600  if($recaptcha != 'off'){ 
     601    $js_output .= ' 
     602    var RecaptchaOptions = { theme: "' . $recaptcha_color . '" };'; 
     603  } 
     604  $js_output .= ' 
    536605    function onwFormValidate(){ 
    537606      var nameField = document.getElementById("uName"); 
     
    578647    } 
    579648  </script>'; 
    580    
     649 
    581650  // And return that variable. 
    582651  return $js_output; 
     
    588657 * to validate the email. If the email is ok (which it should be, thanks 
    589658 * to the javascript validation), the input is passed into an associative 
    590  * array and the array is returned.    
     659 * array and the array is returned. 
    591660 */ 
    592661 
    593662function onw_form_validate($recaptcha, $private_key){ 
    594    
     663 
    595664  // Pass the 'name' input into a variable 
    596665  $u_name = $_POST['uName']; 
     
    599668  // Pass the 'message' input into a variable 
    600669  $u_message = stripslashes($_POST['uMessage']); 
    601    
     670 
    602671  if( $recaptcha == 'off' ) { // if reCAPTCHA is off, validate the basic check 
    603672    // And pass the robot check into a variable 
     
    607676    else 
    608677      $u_check = intval( $u_check ); 
    609      
     678 
    610679    if ( $u_check != 11 ) 
    611680      return '<span style="color:red;">Please prove you are not a robot by correctly answering the question.</span>'; 
     
    616685    } 
    617686  } // end of reCAPTCHA if 
    618    
     687 
    619688  // Sanitize the name and message 
    620689  $u_name = htmlspecialchars( $u_name, ENT_QUOTES ); 
    621690  // Remove HTML tags with a regular expression 
    622691  $u_message = preg_replace( '/<[^>]+>/', '', $u_message ); 
    623    
     692 
    624693  // Validate the email 
    625694  $filter_email = is_email( $u_email ); 
     
    629698    return '<span style="color:red;">Enter a real email address.</span>'; 
    630699  // Otherwise... 
    631    
     700 
    632701  // Pass the inputs into another associative array... 
    633702  $onw_inputs = array('name'=>$u_name, 'email'=>$u_email, 'message'=>$u_message); 
    634    
     703 
    635704  // And return it. 
    636705  return $onw_inputs; 
    637    
     706 
    638707} // End of onw_form_validate() function 
    639708 
     
    645714 * the onw_form_validate() function above. When it has finished compiling 
    646715 * the variables, it inserts them into an indexed array, and returns 
    647  * the array.      
     716 * the array. 
    648717 */ 
    649718 
    650719function onw_compile_the_email($onw_inputs, $onw_the_to_email, $subject) { 
    651    
     720 
    652721  // First prepare the message body with the message, time sent, 
    653722  // and name/email of sender. 
    654723  $onw_body = $onw_inputs['message']."\n 
    655724  Sent ".date("l jS \of F Y h:i:s A e").' by '.$onw_inputs['name'].' ('.$onw_inputs['email'].').'; 
    656    
     725 
    657726  if($subject == '' || !isset($subject)){ 
    658727    $onw_def_sub = get_option('onw-simple-contact'); 
     
    664733  $replace_with = array($onw_inputs['name'],$onw_inputs['email']); 
    665734  $onw_subject = preg_replace($look_for,$replace_with,$onw_base_sub); 
    666    
     735 
    667736  // Prepare the 'from' header w/ the input email 
    668737  $onw_from = 'From: '.$onw_inputs['email']; 
    669    
     738 
    670739  // Prepare the 'to' variable. Uses the blog's admin email address 
    671740  if ( is_email($onw_the_to_email) ) { 
     
    676745    $onw_to = get_bloginfo('admin_email'); 
    677746  } 
    678    
     747 
    679748  // Prepare the indexed array to be returned by inserting the variables... 
    680749  $return_info = array($onw_to, $onw_subject, $onw_body, $onw_from); 
    681    
     750 
    682751  // And return the array. 
    683752  return $return_info; 
     
    689758 * was just to satisfy the requirements of the add_shortcode() function. 
    690759 * The function compiles HTML which will be put into the storycontent when 
    691  * the shortcode is used.     
     760 * the shortcode is used. 
    692761 */ 
    693762 
    694763function onw_aggregate_function($atts){ 
    695    
     764 
    696765  // Get the options from the database for the defaults. 
    697766  $onw_scf_opt = get_option('onw-simple-contact'); 
     
    702771  'subject' => $onw_scf_opt['def_subj'] 
    703772  ), $atts ) ); 
    704    
     773 
    705774  $recaptcha_on = strcasecmp( $onw_recaptcha, 'on' ); 
    706775  $recaptcha_off = strcasecmp( $onw_recaptcha, 'off' ); 
    707    
     776 
    708777  if ( $recaptcha_on != 0 && $recaptcha_off != 0 ) 
    709778    $onw_recaptcha = $onw_scf_opt['recaptcha']; 
    710    
     779 
    711780  // Check to see if the form has been submitted 
    712781  if ( !isset($_POST['uVal']) ) { // If it hasn't... 
    713      
     782 
    714783    // The output will be the javascript... 
    715     $output = onw_form_val_js($onw_recaptcha); 
     784    $output = onw_form_val_js($onw_recaptcha,$onw_scf_opt['recaptcha_theme']); 
    716785    // And the form itself. 
    717786    $output .= onw_form_output($onw_recaptcha, $onw_scf_opt['recaptcha_pubkey']); 
    718      
     787 
    719788  } else { // Otherwise... 
    720    
     789 
    721790    // Validate the form inputs, 
    722791    $onw_form_inputs = onw_form_validate($onw_recaptcha, $onw_scf_opt['recaptcha_prikey']); 
     
    739808      $output = $o_1.'<p>'.$onw_form_inputs.'</p>'.$o_2; 
    740809    } 
    741      
     810 
    742811  } // End of if() to see if form was submitted 
    743    
     812 
    744813  // Return the output to put into the story content. 
    745814  return $output; 
    746    
     815 
    747816} // End of onw_aggregate_function() 
    748817 
     
    752821add_shortcode('onw_simple_contact_form', 'onw_aggregate_function'); 
    753822 
     823/* function update_all_recaptcha_information() updates onw simple contact form's 
     824 * recaptcha information whenever any of the supported recaptcha plugins are updated. 
     825 * The function also updates the respective plugins when they are present and onw-simple-contact 
     826 * is updated 
     827 * 
     828 * As of now, only Jorge Peña's WP-reCAPTCHA plugin and Matt Walters' WP reCAPTCHA Library 
     829 * plugin. 
     830 */ 
     831function update_all_recaptcha_information($opt, $old, $new){ 
     832  // Grab the options 
     833  $c = get_option('onw-simple-contact'); 
     834  // Set update status to false so we can check whether anything changed. 
     835  $update = false; 
     836   
     837  // If the wp-recaptcha plugin was updated, check its values for changes 
     838  if($opt == 'recaptcha'){ 
     839    if(isset($old['pubkey']) && $old['pubkey'] != $new['pubkey']){ 
     840      $update = ($c['recaptcha_pubkey'] == $new['pubkey'])? $update: true; 
     841      $c['recaptcha_pubkey'] = $new['pubkey']; 
     842    } 
     843    if(isset($old['privkey']) && $old['privkey'] != $new['privkey']){ 
     844      $update = ($c['recaptcha_prikey'] == $new['privkey'])? $update: true; 
     845      $c['recaptcha_prikey'] = $new['privkey']; 
     846    } 
     847    if(isset($old['re_theme']) && $old['re_theme'] != $new['re_theme']){ 
     848      $update = ($c['recaptcha_theme'] == $new['re_theme'])? $update: true; 
     849      $c['recaptcha_theme'] = $new['re_theme']; 
     850    } 
     851    if($update) 
     852      update_option('onw-simple-contact', $c); 
     853  } 
     854   
     855  // If the wp-recaptcha-library plugin was updated, check the values for changes 
     856  if( $opt == 'msw_wprecaptcha_option' ){ 
     857    if(isset($old['public_key']) && $old['public_key'] != $new['public_key']){ 
     858      $update = ($c['recaptcha_pubkey'] == $new['public_key'])? $update: true; 
     859      $c['recaptcha_pubkey'] = $new['public_key']; 
     860    } 
     861    if(isset($old['private_key']) && $old['private_key'] != $new['private_key']){ 
     862      $update = ($c['recaptcha_prikey'] == $new['private_key'])? $update: true; 
     863      $c['recaptcha_prikey'] = $new['private_key']; 
     864    } 
     865    if($update) 
     866      update_option('onw-simple-contact', $c); 
     867  } 
     868   
     869  // If onw-simple-contact was updated, check differences and update existing options as necessary 
     870  if( $opt == 'onw-simple-contact' ){ 
     871    // Grab the options for the other plugins 
     872    $wp_recaptcha = get_option('recaptcha'); 
     873    $wp_recaptcha_lib = get_option('msw_wprecaptcha_option'); 
     874     
     875    // If the plugins aren't active, don't update their values. 
     876    if( !in_array( 'wp-recaptcha/wp-recaptcha.php', $plugins ) ) 
     877      $wp_recaptcha = false; 
     878    if( !in_array( 'wp-recaptcha-library/recaptcha-library.php', $plugins ) ) 
     879      $wp_recaptcha_lib = false; 
     880 
     881    // Updated for changed public key 
     882    if( $old['recaptcha_pubkey'] != $new['recaptcha_pubkey'] ){ 
     883      if($wp_recaptcha && ( $wp_recaptcha['pubkey'] != $new['recaptcha_pubkey'] ) ){ 
     884        $update = true; 
     885        $wp_recaptcha['pubkey'] = $new['recaptcha_pubkey']; 
     886      } 
     887      if($wp_recaptcha_lib && ( $wp_recaptcha_lib['public_key'] != $new['recaptcha_pubkey'] ) ){ 
     888        $update = true; 
     889        $wp_recaptcha_lib['public_key'] = $new['recaptcha_pubkey']; 
     890      } 
     891    } 
     892     
     893    // updated for changed private key 
     894    if( $old['recaptcha_prikey'] != $new['recaptcha_prikey'] ){ 
     895      if($wp_recaptcha && ( $wp_recaptcha['privkey'] != $new['recaptcha_prikey'] ) ){ 
     896        $update = true; 
     897        $wp_recaptcha['privkey'] = $new['recaptcha_prikey']; 
     898      } 
     899      if($wp_recaptcha_lib && ( $wp_recaptcha_lib['private_key'] != $new['recaptcha_prikey'] ) ){ 
     900        $update = true; 
     901        $wp_recaptcha_lib['private_key'] = $new['recaptcha_prikey']; 
     902      } 
     903    } 
     904     
     905    // updated for changed theme color 
     906    if( $old['recaptcha_theme'] != $new['recaptcha_theme'] ){ 
     907      if($wp_recaptcha && ( $wp_recaptcha['re_theme'] != $new['recaptcha_theme'] ) ){ 
     908        $update = true; 
     909        $wp_recaptcha['re_theme'] = $new['recaptcha_theme']; 
     910      } 
     911    } 
     912     
     913    // update the options for whichever plugin is available (if any at all) 
     914    if($wp_recaptcha) 
     915      update_option( 'recaptcha', $wp_recaptcha ); 
     916    if($wp_recaptcha_lib) 
     917      update_option( 'msw_wprecaptcha_option', $wp_recaptcha_lib ); 
     918  } 
     919} 
     920 
     921// Hook onto the 'updated_option' action to update info as necessary 
     922add_action( 'updated_option', 'update_all_recaptcha_information', 10, 3 ); 
     923add_action( 'updated_option', 'update_all_recaptcha_information', 10, 3 ); 
     924 
    754925?> 
  • onw-simple-contact-form/trunk/readme.txt

    r206430 r227565  
    55Requires at least: 2.5 
    66Tested up to: 2.9.2 
    7 Stable tag: 1.8 
     7Stable tag: 1.9 
    88 
    99ONW Simple Contact Form is a basic form with reCAPTCHA for sending email from your blog. 
     
    1515It has the option of using [reCAPTCHA](http://www.recaptcha.net), or a very primitive version if you don't want to use reCAPTCHA. The ONW reCAPTCHA integration *WILL NOT* cause any conflicting errors with other reCAPTCHA installations on your WordPress. It asks for a name, email address, and body text, and then emails all of it to an email you specify (if you don't give it an address, the form will default to the blog's administrative email address). 
    1616 
     17If you have reCAPTCHA on your WordPress already, this plugin will check for the existence of certain plugins and will automatically sync the api key settings, as well as the reCAPTCHA theme setting, where applicable. As of now, the following plugins are checked: 
     18 
     191. WP-reCAPTCHA by Jorge Peña 
     202. WP-reCAPTCHA-Library by Matt Walters 
     21 
    1722== Installation == 
    1823 
     
    23285. In the popup box, you can either set an email address and subject for the form, or you can leave the form blank and use the defaults (set under the options page). 
    24296. You still have the option of adding the shortcode manually. The basic shortcode is `[onw_simple_contact_form]`. You can specify a non-default email address buy adding the `to_email` argument to the shortcode to define the recipient address. If you use this, the shortcode will look like `[onw_simple_contact_form to_email="youremail@example.com"]`. If you use anything other than an email address (or leave the argument out altogether) the email will send to the blog's admin address. 
    25 7. If you want to use reCAPTCHA, [sign up for a free account](https://admin.recaptcha.net/accounts/signup/). Then enter the public and private API keys in the appropriate fields in the ONW options page. Finally, select "enabled" on the form to turn reCAPTCHA on. Also, you have the option of overriding the settings in an individual post by adding the `onw_recaptcha` argument. You cannot set a reCAPTCHA override with the tinyMCE button. So if you wanted to disable reCAPTCHA for a certain form, you would write `[onw_simple_contact_form onw_recaptcha="off"]`.  The only values that the plugin wil recognize are 'on' and 'off'.  Anything else will cause the form to revert to the default settings (as set in the settings tab for ONW Simple Contact). 
     307. If you want to use reCAPTCHA, [sign up for a free account](https://admin.recaptcha.net/accounts/signup/). Then enter the public and private API keys in the appropriate fields in the ONW options page (if you already have a plugin listed above, this should already be done). Finally, select "enabled" on the form to turn reCAPTCHA on. Also, you have the option of overriding the settings in an individual post by adding the `onw_recaptcha` argument. You cannot set a reCAPTCHA override with the tinyMCE button. So if you wanted to disable reCAPTCHA for a certain form, you would write `[onw_simple_contact_form onw_recaptcha="off"]`.  The only values that the plugin wil recognize are 'on' and 'off'.  Anything else will cause the form to revert to the default settings (as set in the settings tab for ONW Simple Contact). 
    26318. For the subject of the email, you will have a default setting, but can override the default with either the tinyMCE button or manually in the shortcode. Also, in the subject, the email will replace `%name%` with the user's name (as they entered it) and will replace `%email%` with the user's email (as they entered it). The shortcode argument for the subject is `subject`. 
    2732 
     
    3843 
    3944== Changelog == 
     45 
     46= 1.9 = 
     47 
     48* Added reCAPTCHA theme support. Users can now use the admin panel to change the look and feel of the form 
     49* Added settings checks for other reCAPTCHA plugins to automatically copy api key and theme settings for onw-simple-contact-form 
    4050 
    4151= 1.8 = 
Note: See TracChangeset for help on using the changeset viewer.