WordPress.org

Plugin Directory

Changeset 200266


Ignore:
Timestamp:
01/31/10 19:43:40 (8 years ago)
Author:
wmrom
Message:

Updating v1.8

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

Legend:

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

    r194473 r200266  
    33Plugin Name: ONW Simple Contact Form 
    44Plugin URI: http://www.olympianetworks.com/projects/onw-simple-contact-form/ 
    5 Description: This Plugin creates a simple contact form. 
    6 Version: 1.7.2 
     5Description: This Plugin creates a simple contact form using shortcode in posts or pages. 
     6Version: 1.8 
    77Author: John Bloch 
    88Author URI: http://www.olympianetworks.com/about-us/developers/john-p-bloch/ 
     
    3232*/ 
    3333 
    34 include_once('recaptchalib.php'); 
     34// Check to see if reCAPTCHA is enabled 
     35$onw_opts = get_option('onw-simple-contact'); 
     36 
     37// If it is, 
     38if($onw_opts['recaptcha'] == 'on'){ 
     39 
     40  // Include the reCAPTCHA library 
     41  include_once(WP_PLUGIN_DIR . '/onw-simple-contact-form/recaptchalib.php'); 
     42   
     43} 
    3544 
    3645/* 
     
    5867 
    5968function onw_scf_activation_(){ 
     69 
    6070  $options = get_option('onw-simple-contact'); 
     71   
     72  // If there are no options, set the default values 
    6173  if(!$options){ 
     74   
    6275    $ad_email = get_bloginfo('admin_email');  
    6376    // default email is the blog's admin address, reCAPTCHA is off by default 
     77     
    6478    $onw_def_options = array( 
    6579      'to_email' => $ad_email, 
     
    6781      'recaptcha' => 'off', 
    6882      'recaptcha_pubkey' => '', 
    69       'recaptcha_prikey' => '' 
     83      'recaptcha_prikey' => '', 
     84      'labels' => array( 
     85            'top_text' => 'Please use the form below to send an email to the site administrator.', 
     86            'fieldset' => 'Send an Email', 
     87            'name' => 'Name:', 
     88            'email' => 'Email:', 
     89            'message' => 'Message:' 
     90          ), 
     91      'fieldset' => 'yes', 
     92      'box_size' => array ( 
     93            'width' => '50', 
     94            'height' => '10' 
     95          ) 
    7096    ); 
    7197     
    7298    // Add the options to the options table in the database 
    7399    add_option('onw-simple-contact', $onw_def_options); 
    74   } else { 
     100     
     101  } else { // If there are options, make sure all of them are accounted for 
     102   
    75103    if(!isset($options['to_email'])){ 
    76104      $ad_email = get_bloginfo('admin_email'); 
     
    79107      $new_opts['to_email'] = $options['to_email']; 
    80108    } 
     109     
    81110    if(!isset($options['def_subj'])){ 
    82111      $new_opts['def_subj'] = '%email% has sent you a message'; 
     
    84113      $new_opts['def_subj'] = $options['def_subj']; 
    85114    } 
     115     
    86116    if(!isset($options['recaptcha'])){ 
    87117      $new_opts['recaptcha'] = 'off'; 
     
    89119      $new_opts['recaptcha'] = $options['recaptcha']; 
    90120    } 
     121     
    91122    if(!isset($options['recaptcha_pubkey'])){ 
    92123      $new_opts['recaptcha_pubkey'] = ''; 
     
    94125      $new_opts['recaptcha_pubkey'] = $options['recaptcha_pubkey']; 
    95126    } 
     127     
    96128    if(!isset($options['recaptcha_prikey'])){ 
    97129      $new_opts['recaptcha_prikey'] = ''; 
     
    99131      $new_opts['recaptcha_prikey'] = $options['recaptcha_prikey']; 
    100132    } 
     133     
     134    if(!isset($options['labels'])){ 
     135      $new_opts['labels'] = array( 
     136        'top_text' => 'Please use the form below to send an email to the site administrator.', 
     137        'fieldset' => 'Send an Email', 
     138        'name' => 'Name:', 
     139        'email' => 'Email:', 
     140        'message' => 'Message:' 
     141      ); 
     142    } else { 
     143      $new_opts['labels'] = $options['labels']; 
     144    } 
     145     
     146    if(!isset($options['fieldset'])){ 
     147      $new_opts['fieldset'] = 'yes'; 
     148    } else { 
     149      $new_opts['fieldset'] = $options['fieldset']; 
     150    } 
     151     
     152    if(!isset($options['box_size'])){ 
     153      $new_opts['box_size'] = array( 
     154        'width' => '50', 
     155        'height' => '10' 
     156      ); 
     157    } else { 
     158      $new_opts['box_size'] = $options['box_size']; 
     159    } 
     160     
     161    // And update the existing options. 
    101162    update_option('onw-simple-contact',$new_opts); 
    102163  } 
    103164} 
    104165 
     166// Run onw-scf_activation() any time the plugin is activated (this includes when it updates) 
    105167register_activation_hook(__FILE__,'onw_scf_activation_'); 
    106168 
     
    112174function onw_scf_submenu_add(){ 
    113175   
    114   if($_POST['submitted'] == 'submitted'){ // if the form was submitted 
     176  if( $_POST['submitted'] == 'submitted' ){ // if the configuration form was submitted 
     177   
     178    $old_onw_opts = get_option( 'onw-simple-contact' ); 
     179     
     180    $recaptcha = ( $_POST['recaptcha'] == 'on' )? 'on': 'off'; 
     181     
    115182    // update the options with the new values 
    116183    $onw_options_up = array( 
    117184      'to_email' => $_POST['to_email'], 
    118185      'def_subj' => $_POST['def_subj'], 
    119       'recaptcha' => $_POST['recaptcha'], 
     186      'recaptcha' => $recaptcha, 
    120187      'recaptcha_pubkey' => $_POST['recaptcha_pubkey'], 
    121188      'recaptcha_prikey' => $_POST['recaptcha_prikey'] 
    122189    ); 
    123     update_option('onw-simple-contact', $onw_options_up ); 
     190     
     191    // Merge the new values into the old options 
     192    $onw_options_up = array_merge( $old_onw_opts, $onw_options_up ); 
     193     
     194    // And update 
     195    update_option( 'onw-simple-contact', $onw_options_up ); 
     196     
     197  } elseif( $_POST['submitted'] == 'submitted2' ){ // If the display form was submitted 
     198     
     199    // Get the old options 
     200    $old_onw_opts = get_option( 'onw-simple-contact' ); 
     201     
     202    // Set the value for the fieldset toggle 
     203    $fieldset = ( $_POST['display-fieldset'] == 'yes' )? 'yes': 'no'; 
     204     
     205    // Compile the options updates into an array 
     206    $new_onw_opts = array( 
     207      'labels' => array( 
     208            'top_text' => $_POST['upper-text-label'], 
     209            'fieldset' => $_POST['fieldset-legend'], 
     210            'name' => $_POST['name-label'], 
     211            'email' => $_POST['email-label'], 
     212            'message' => $_POST['message-label'] 
     213          ), 
     214      'fieldset' => $fieldset, 
     215      'box_size' => array ( 
     216            'width' => $_POST['m-box-width'], 
     217            'height' => $_POST['m-box-height'] 
     218          ) 
     219    ); 
     220     
     221    // Merge the arrays so you retain the unchanged config values 
     222    $new_onw_opts = array_merge( $old_onw_opts, $new_onw_opts ); 
     223     
     224    // Update the options 
     225    update_option( 'onw-simple-contact', $new_onw_opts ); 
     226     
    124227  } 
    125228   
    126229  // Put the current options into a variable. 
    127   $onw_opt_array = get_option('onw-simple-contact'); 
    128    
    129   // Write the HTML output 
     230  $onw_opt_array = get_option( 'onw-simple-contact' ); 
     231   
     232  // Set the labels and message box size into separate variables for easier access later 
     233  $onwscf_labels = $onw_opt_array['labels']; 
     234  $onw_box_size = $onw_opt_array['box_size']; 
     235   
     236  // Write the Header HTML 
    130237?><div class="wrap"> 
    131238    <h2>ONW Simple Contact Form</h2> 
     239    <ul class="subsubsub"> 
     240      <li> 
     241        <a href="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>"<?php if( $_GET['sp'] != 'display' ) { echo ' class="current"'; } ?>>Configuration</a> | 
     242      </li> 
     243      <li> 
     244        <a href="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>&sp=display"<?php if( $_GET['sp'] == 'display' ) { echo ' class="current"'; } ?>>Display</a> 
     245      </li> 
     246    </ul> 
     247     
     248<?php 
     249   
     250  // If you're looking at the display options page, display the proper page 
     251  if( $_GET['sp'] == 'display' ): 
     252   
     253?> 
     254 
     255    <form name="form1" method="post" action="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>&sp=display&updated=true"> 
     256      <table class="form-table"> 
     257        <tbody> 
     258          <tr> 
     259            <th scope="row"> 
     260              <label for="display-fieldset">Display Fieldset?</label> 
     261            </th> 
     262            <td> 
     263              <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 /> 
     264              <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"'; } ?> /> 
     265            </td> 
     266          </tr> 
     267          <tr> 
     268            <th scope="row"> 
     269              <label>Field Labels</label> 
     270            </th> 
     271            <td> 
     272              <label for="upper-text-label">Top Text:</label> <input type="text" name="upper-text-label" id="upper-text-label" size="70" value="<?php echo $onwscf_labels['top_text']; ?>" /><br /> 
     273              <label for="name-label">Name:</label> <input type="text" name="name-label" id="name-label" size="70" value="<?php echo $onwscf_labels['name']; ?>" /><br /> 
     274              <label for="email-label">Email:</label> <input type="text" name="email-label" id="email-label" size="70" value="<?php echo $onwscf_labels['email']; ?>" /><br /> 
     275              <label for="message-label">Message:</label> <input type="text" name="message-label" id="message-label" size="70" value="<?php echo $onwscf_labels['message']; ?>" /><br /> 
     276            </td> 
     277          </tr> 
     278          <tr> 
     279            <th scope="row"> 
     280              Message Box Size: 
     281            </th> 
     282            <td> 
     283              <label for="m-box-width">Width:</label> <input type="text" name="m-box-width" id="m-box-width" size="3" value="<?php echo $onw_box_size['width']; ?>" /> columns | <label for="m-box-height">Height:</label> <input type="text" name="m-box-height" id="m-box-height" size="3" value="<?php echo $onw_box_size['height']; ?>" /> rows 
     284            </td> 
     285          </tr> 
     286        </tbody> 
     287      </table> 
     288      <input type="hidden" name="submitted" id="submitted" value="submitted2" /> 
     289      <p class="submit"><input type="submit" name="submit" id="submit" value="Update Display Settings" class="button-primary" /></p> 
     290    </form> 
     291 
     292<?php 
     293   
     294  // Otherwise, display the default configuration page. 
     295  else: 
     296   
     297?> 
    132298    <form name="form1" method="post" action="<?php echo $_SERVER['REDIRECT_SCRIPT_URI'] . '?page=' . plugin_basename(__FILE__); ?>&updated=true"> 
    133299      <table class="form-table"> 
     
    165331                } 
    166332              ?>> 
    167                 <option value="on"<?php if($onw_opt_array['recaptcha'] == 'on' ) { echo ' selected="selected"'; } ?>>Enabled</option> 
     333                <option value="on">Enabled</option> 
    168334                <option value="off"<?php if($onw_opt_array['recaptcha'] == 'off' ) { echo ' selected="selected"'; } ?>>Disabled</option> 
    169335              </select>&nbsp;<br /><span class="description">reCAPTCHA is a highly effective (and FREE!) bot check program. It asks those filling out your form to type a slightly distorted word before it will process the form.<br />Before you can enable reCAPTCHA, you have to go to <a href="https://admin.recaptcha.net/accounts/signup/" target="_blank">reCaptcha.net</a> and sign up for a free account. Then, enter the public key and private key from your account in the fields below. Once you have saved the keys here, you will be able to activate reCAPTCHA.</span> 
     
    192358      <p class="submit"><input type="submit" name="submit" id="submit" value="Update Settings" class="button-primary" /></p> 
    193359    </form> 
    194   </div> 
    195360<?php 
     361 
     362  endif; 
     363   
     364  // Finish off the HTML 
     365  echo "\n</div>\n"; 
     366 
    196367} 
    197368 
    198369// Hook the onw_scf_add_options_menu() function onto the admin_menu action 
    199 add_action('admin_menu', 'onw_scf_add_options_menu'); 
     370add_action( 'admin_menu', 'onw_scf_add_options_menu' ); 
    200371 
    201372/* 
     
    215386 
    216387function onw_scf_addbuttons() { 
     388 
    217389// check user permission 
    218390  if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) 
    219391  return; 
     392   
    220393  // Add only in Rich Editor mode 
    221394  if ( get_user_option('rich_editing') == 'true') { 
     395   
    222396    add_filter("mce_external_plugins", "onwscf_mce_plugin_load"); 
    223397    add_filter('mce_buttons', 'onwscf_mce_register_button'); 
     398     
    224399  } 
     400   
    225401} 
    226402 
     
    231407 
    232408function onwscf_mce_plugin_load($plugin_array){ 
     409   
    233410  // Set the url of the editor_plugin.js file 
    234411  $plug = WP_PLUGIN_URL . '/onw-simple-contact-form/js/editor_plugin.js'; 
     412   
    235413  // Add it to the plugin array 
    236414  $plugin_array['onwsc'] = $plug; 
     415   
    237416  // Return the plugin array 
    238417  return $plugin_array; 
     418   
    239419} 
    240420 
     
    244424 */  
    245425 
    246 function onwscf_mce_register_button(&$buttons){ 
     426function onwscf_mce_register_button($buttons){ 
     427 
    247428  // Add the button's name to the array of buttons 
    248429  array_push($buttons, "separator", "onwscb"); 
     430   
    249431  // Return the buttons array 
    250432  return $buttons; 
     433   
    251434} 
    252435 
     
    266449  
    267450function onw_form_output ( $recaptcha, $public_key, $inp = array('name'=>'', 'email'=>'', 'message'=>'', 'check'=>'') ) { 
     451   
     452  // Get the options to insert labels, etc. into form. 
     453  $onw_opts = get_option( 'onw-simple-contact' ); 
     454   
     455  // Put labels and dimensions into their own variables for easier access 
     456  $labels = $onw_opts['labels']; 
     457  $m_size = $onw_opts['box_size']; 
     458   
    268459  // Put the form into a variable... 
    269460  $form_output = ' 
    270   <p>Please use the form below to send an email to the site administrator.</p> 
     461  <p>'.$labels['top_text'].'</p> 
    271462  <form id="onw_contact_form" name="onw_contact_form" method="post" action="#onw_contact_form"> 
     463  '; 
     464   
     465  // If the fieldset toggle is checked... 
     466  if( $onw_opts['fieldset'] == 'yes' ){ 
     467     
     468    // Add the fieldset and legend 
     469    $form_output .= ' 
    272470    <fieldset> 
    273       <legend>Send an Email</legend> 
     471      <legend>'.$labels['fieldset'].'</legend>'; 
     472       
     473  } // End fieldset IF 
     474   
     475  $form_output .= ' 
    274476      <p>All fields are required.</p> 
    275       <p>Name: <input type="text" name="uName" id="uName" value="'.$inp['name'].'" /></p> 
    276       <p>Email: <input type="text" name="uEmail" id="uEmail" value="'.$inp['email'].'" /></p> 
    277       <p>Message:<br /> 
    278       <textarea id="uMessage" name="uMessage" rows="10" cols="50">'.$inp['message'].'</textarea></p>'; 
     477      <p>'.$labels['name'].' <input type="text" name="uName" id="uName" value="'.$inp['name'].'" /></p> 
     478      <p>'.$labels['email'].' <input type="text" name="uEmail" id="uEmail" value="'.$inp['email'].'" /></p> 
     479      <p>'.$labels['message'].'<br /> 
     480      <textarea id="uMessage" name="uMessage" rows="'.$m_size['height'].'" cols="'.$m_size['width'].'">'.$inp['message'].'</textarea></p>'; 
     481       
    279482  if( $recaptcha == 'off' ) { // if reCAPTCHA is off, use the basic check 
    280483    $form_output .= '<p id="bot-check"><img src="'; 
     
    283486      <input type="hidden" name="uVal" id="uVal" value="true" /> 
    284487      <p><input type="button" name="uSend" id="uSend" value="Send" onclick="onwFormValidate()" /></p> 
     488      '; 
     489       
     490    // If the fieldset toggle is checked... 
     491    if( $onw_opts['fieldset'] == 'yes' ){ 
     492       
     493      // Close the fieldset 
     494      $form_output .= ' 
    285495    </fieldset> 
     496    '; 
     497     
     498    } 
     499     
     500    $form_output .= ' 
    286501  </form>'; 
    287502  } else { // Otherwise, use reCAPTCHA 
     503     
    288504    $form_output .= '<p id="bot-check">'.onw_recaptcha_get_html($public_key).'</p> 
    289505        <input type="hidden" name="uVal" id="uVal" value="true" /> 
    290506      <p><input type="button" name="uSend" id="uSend" value="Send" onclick="onwFormValidate()" /></p> 
     507      '; 
     508     
     509    // If the fieldset toggle is checked... 
     510    if( $onw_opts['fieldset'] == 'yes' ){ 
     511       
     512      // Close the fieldset 
     513      $form_output .= ' 
    291514    </fieldset> 
     515    '; 
     516     
     517    } 
     518    $form_output .= ' 
    292519  </form>'; 
    293   } 
     520  } // End reCAPTCHA if/elseif 
    294521   
    295522  // And return that variable. 
  • onw-simple-contact-form/trunk/readme.txt

    r194473 r200266  
    55Requires at least: 2.5 
    66Tested up to: 2.9.1 
    7 Stable tag: 1.7.2 
     7Stable tag: 1.8 
    88 
    99ONW Simple Contact Form is a basic form with reCAPTCHA for sending email from your blog. 
     
    3838 
    3939== Changelog == 
     40 
     41= 1.8 = 
     42 
     43* Fixed a bug in the TinyMCE functions which sometimes caused the editor to disappear 
     44* Added a 'display' tab to the admin page where admins can change the text in the form, as well as remove the fieldset or change the size of the message box. 
    4045 
    4146= 1.7.2 = 
Note: See TracChangeset for help on using the changeset viewer.