';
if ($si_contact_opt['text_message_sent'] != '') {
$ctf_thank_you .= $si_contact_opt['text_message_sent'];
} else {
$ctf_thank_you .= esc_html(__('Your message has been sent, thank you.', 'si-contact-form'));
}
$ctf_thank_you .= '
';
if ($ctf_redirect_enable == 'true') {
$wp_plugin_url = WP_PLUGIN_URL;
$ctf_thank_you .= <<
EOT;
$ctf_thank_you .= '
'.esc_html( __('Redirecting', 'si-contact-form')).' ... ';
// do not remove the above EOT line
}
// add numbered keys starting with 1 to the $contacts array
$cont = array();
$ct = 1;
foreach ($ctf_contacts as $v) {
$cont["$ct"] = $v;
$ct++;
}
$contacts = $cont;
unset($cont);
// initialize vars
$string = '';
$this->si_contact_error = 0;
$si_contact_error_print = '';
$message_sent = 0;
$mail_to = '';
$to_contact = '';
$name = '';
$email = '';
$email2 = '';
$subject = '';
$message = '';
$captcha_code = '';
// add another field here like above
// optional extra fields
foreach( array(1, 2, 3, 4, 5, 6, 7, 8) as $val ) {
if ($si_contact_opt['ex_field'.$val.'_label'] != '') {
${'ex_field'.$val} = '';
${'si_contact_error_ex_field'.$val} = '';
}
}
$si_contact_error_captcha = '';
$si_contact_error_contact = '';
$si_contact_error_name = '';
$si_contact_error_email = '';
$si_contact_error_email2 = '';
$si_contact_error_double_email = '';
$si_contact_error_subject = '';
$si_contact_error_message = '';
// add another field here like above
// see if WP user
global $current_user, $user_ID;
get_currentuserinfo();
// process form now
if (isset($_POST['si_contact_action']) && ($_POST['si_contact_action'] == 'send')) {
// check all input variables
$cid = $this->ctf_clean_input($_POST['si_contact_CID']);
if(empty($cid)) {
$this->si_contact_error = 1;
$si_contact_error_contact = ($si_contact_opt['error_contact_select'] != '') ? esc_html($si_contact_opt['error_contact_select']) : esc_html( __('Selecting a contact is required.', 'si-contact-form') );
}
else if (!isset($contacts[$cid]['CONTACT'])) {
$this->si_contact_error = 1;
$si_contact_error_contact = __('Requested Contact not found.', 'si-contact-form');
}
if (empty($ctf_contacts)) {
$this->si_contact_error = 1;
}
$mail_to = ( isset($contacts[$cid]['EMAIL']) ) ? $this->ctf_clean_input($contacts[$cid]['EMAIL']) : '';
$to_contact = ( isset($contacts[$cid]['CONTACT']) ) ? $this->ctf_clean_input($contacts[$cid]['CONTACT']): '';
$name = $this->ctf_name_case($this->ctf_clean_input($_POST['si_contact_name']));
$email = strtolower($this->ctf_clean_input($_POST['si_contact_email']));
if ($ctf_enable_double_email == 'true') {
$email2 = strtolower($this->ctf_clean_input($_POST['si_contact_email2']));
}
if ($si_contact_opt['hidden_subject_enable'] != 'true') {
$subject = $this->ctf_name_case($this->ctf_clean_input($_POST['si_contact_subject']));
}
$message = $this->ctf_clean_input($_POST['si_contact_message']);
if ( $this->isCaptchaEnabled() ) {
$captcha_code = $this->ctf_clean_input($_POST['si_contact_captcha_code']);
}
// add another field here like above
// check posted input for email injection attempts
// fights common spammer tactics
// look for newline injections
$this->ctf_forbidifnewlines($name);
$this->ctf_forbidifnewlines($email);
if ($ctf_enable_double_email == 'true') {
$this->ctf_forbidifnewlines($email2);
}
$this->ctf_forbidifnewlines($subject);
// look for lots of other injections
$forbidden = 0;
$forbidden = $this->ctf_spamcheckpost();
if ($forbidden) {
wp_die(__('Contact Form has Invalid Input', 'si-contact-form'));
}
// check for banned ip
if( $ctf_enable_ip_bans && in_array($_SERVER['REMOTE_ADDR'], $ctf_banned_ips) ) {
wp_die(__('Your IP is Banned', 'si-contact-form'));
}
// CAPS Decapitator
if ($si_contact_opt['name_case_enable'] == 'true' && !preg_match("/[a-z]/", $message)) {
$message = $this->ctf_name_case($message);
}
if(empty($name)) {
$this->si_contact_error = 1;
$si_contact_error_name = ($si_contact_opt['error_name'] != '') ? esc_html($si_contact_opt['error_name']) : esc_html( __('Your name is required.', 'si-contact-form') );
}
if (!$this->ctf_validate_email($email)) {
$this->si_contact_error = 1;
$si_contact_error_email = ($si_contact_opt['error_email'] != '') ? esc_html($si_contact_opt['error_email']) : esc_html( __('A proper e-mail address is required.', 'si-contact-form') );
}
if ($ctf_enable_double_email == 'true' && !$this->ctf_validate_email($email2)) {
$this->si_contact_error = 1;
$si_contact_error_email2 = ($si_contact_opt['error_email'] != '') ? esc_html($si_contact_opt['error_email']) : esc_html( __('A proper e-mail address is required.', 'si-contact-form') );
}
if ($ctf_enable_double_email == 'true' && ($email != $email2) ) {
$this->si_contact_error = 1;
$si_contact_error_double_email = ($si_contact_opt['error_email2'] != '') ? esc_html($si_contact_opt['error_email2']) : esc_html( __('The two e-mail addresses did not match, please enter again.', 'si-contact-form') );
}
// optional extra fields
foreach( array(1, 2, 3, 4, 5, 6, 7, 8) as $val ) {
if ($si_contact_opt['ex_field'.$val.'_label'] != '') {
${'ex_field'.$val} = $this->ctf_clean_input($_POST["si_contact_ex_field$val"]);
if(empty(${'ex_field'.$val}) && $si_contact_opt['ex_field'.$val.'_req'] == 'true') {
$this->si_contact_error = 1;
${'si_contact_error_ex_field'.$val} = ($si_contact_opt['error_field'] != '') ? esc_html($si_contact_opt['error_field']) : esc_html( __('This field is required.', 'si-contact-form') );
}
}
} // end foreach
if ($si_contact_opt['hidden_subject_enable'] != 'true' && empty($subject)) {
$this->si_contact_error = 1;
$si_contact_error_subject = ($si_contact_opt['error_subject'] != '') ? esc_html($si_contact_opt['error_subject']) : esc_html( __('Subject text is required.', 'si-contact-form') );
}
if(empty($message)) {
$this->si_contact_error = 1;
$si_contact_error_message = ($si_contact_opt['error_message'] != '') ? esc_html($si_contact_opt['error_message']) : esc_html( __('Message text is required.', 'si-contact-form') );
}
// Check with Akismet, but only if Akismet is installed, activated, and has a KEY. (Recommended for spam control).
if( function_exists('akismet_http_post') && get_option('wordpress_api_key') ){
global $akismet_api_host, $akismet_api_port;
$c['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
$c['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$c['referrer'] = $_SERVER['HTTP_REFERER'];
$c['blog'] = get_option('home');
$c['permalink'] = get_permalink();
$c['comment_type'] = 'sicontactform';
$c['comment_author'] = $name;
$c['comment_content'] = $message;
//$c['comment_content'] = "viagra-test-123"; // uncomment this to test spam detection
$ignore = array( 'HTTP_COOKIE' );
foreach ( $_SERVER as $key => $value )
if ( !in_array( $key, $ignore ) )
$c["$key"] = $value;
$query_string = '';
foreach ( $c as $key => $data )
$query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
if ( 'true' == $response[1] ) {
$this->si_contact_error = 1; // Akismet says it is spam.
$si_contact_error_message = ($si_contact_opt['error_input'] != '') ? esc_html($si_contact_opt['error_input']) : esc_html( __('Contact Form has Invalid Input', 'si-contact-form') );
}
} // end if(function_exists('akismet_http_post')){
// add another field here like 4 lines above (only if you want it to be required)
// begin captcha check if enabled
// captcha is optional but recommended to prevent spam bots from spamming your contact form
if ( $this->isCaptchaEnabled() ) {
/* uncomment for temporary advanced debugging only
echo "";
echo "COOKIE ";
var_dump($_COOKIE);
echo "\n\n";
echo "SESSION ";
var_dump($_SESSION);
echo " \n";
*/
if (!isset($_SESSION['securimage_code_value']) || empty($_SESSION['securimage_code_value'])) {
$this->si_contact_error = 1;
$si_contact_error_captcha = __('Could not read CAPTCHA cookie. Make sure you have cookies enabled and not blocking in your web browser settings. Or another plugin is conflicting. See plugin FAQ.', 'si-contact-form');
}else{
if (empty($captcha_code) || $captcha_code == '') {
$this->si_contact_error = 1;
$si_contact_error_captcha = ($si_contact_opt['error_captcha_blank'] != '') ? esc_html($si_contact_opt['error_captcha_blank']) : esc_html( __('Please complete the CAPTCHA.', 'si-contact-form') );
} else {
include_once "$captcha_path_cf/securimage.php";
$img = new Securimage();
$valid = $img->check("$captcha_code");
// Check, that the right CAPTCHA password has been entered, display an error message otherwise.
if($valid == true) {
// ok can continue
} else {
$this->si_contact_error = 1;
$si_contact_error_captcha = ($si_contact_opt['error_captcha_wrong'] != '') ? esc_html($si_contact_opt['error_captcha_wrong']) : esc_html( __('That CAPTCHA was incorrect.', 'si-contact-form') );
}
}
}
} // end if enable captcha
// end captcha check
if (!$this->si_contact_error) {
// ok to send the email, so prepare the email message
// lines separated by \n on Unix and \r\n on Windows
if (!defined('PHP_EOL'))
define ('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
$subj = ($si_contact_opt['hidden_subject_enable'] == 'true') ? $si_contact_opt['email_subject'] : $si_contact_opt['email_subject'] ." $subject";
$msg = __('To', 'si-contact-form').": $to_contact
".__('From', 'si-contact-form').":
$name
$email
";
// optional extra fields
foreach( array(1, 2, 3, 4, 5, 6, 7, 8) as $val ) {
if ($si_contact_opt['ex_field'.$val.'_label'] != '') {
$msg .= $si_contact_opt['ex_field'.$val.'_label']." ${'ex_field'.$val}
";
}
}
$msg .= "
".__('Message', 'si-contact-form').":
$message
";
// add another field here (in the $msg code above)
// add some info about sender to the email message
$userdomain = '';
$userdomain = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$user_info_string = '';
if ($user_ID != '' && !current_user_can('level_10') ) {
//user logged in
$user_info_string .= __('From a WordPress user', 'si-contact-form').': '.$current_user->user_login . PHP_EOL;
}
$user_info_string .= __('Sent from (ip address)', 'si-contact-form').': '.$_SERVER['REMOTE_ADDR']." ($userdomain)" . PHP_EOL;
$user_info_string .= __('Date/Time', 'si-contact-form').': '.date_i18n(get_option('date_format').' '.get_option('time_format'), time() ) . PHP_EOL;
$user_info_string .= __('Coming from (referer)', 'si-contact-form').': '.get_permalink() . PHP_EOL;
$user_info_string .= __('Using (user agent)', 'si-contact-form').': '.$this->ctf_clean_input($_SERVER['HTTP_USER_AGENT']) . PHP_EOL . PHP_EOL;
$msg .= $user_info_string;
// wordwrap email message
if ($ctf_wrap_message) {
$msg = wordwrap($msg, 70);
}
// prepare the email header
if ($ctf_email_on_this_domain != '') {
$header = "From: $ctf_email_on_this_domain" . PHP_EOL;
} else {
$header = "From: $name <$email>" . PHP_EOL;
}
if ($ctf_email_address_bcc !='')
$header .= "Bcc: " . $ctf_email_address_bcc . PHP_EOL;
$header .= "Reply-To: $email" . PHP_EOL;
$header .= "Return-Path: $email" . PHP_EOL;
$header .= 'Content-type: text/plain; charset='. get_option('blog_charset') . PHP_EOL;
@ini_set('sendmail_from', $email); // needed for some windows servers
if (!wp_mail($mail_to,$subj,$msg,$header)) {
die('' . __('The e-mail could not be sent.', 'si-contact-form') . " \n" .
__('Possible reason: your host may have disabled the mail() function.', 'si-contact-form') . '
');
}
$message_sent = 1;
} // end if ! error
} // end if posted si_contact_action = send
if($message_sent) {
// thank you mesage is printed here
$string .= $ctf_thank_you;
}else{
if (!$this->si_contact_error) {
// welcome intro is printed here unless message is sent
$string .= $ctf_welcome_intro;
}
$this->ctf_border_style = 'style="'.$si_contact_opt['border_style'].'"';
$this->ctf_select_style = 'style="'.$si_contact_opt['select_style'].'"';
$this->ctf_title_style = 'style="'.$si_contact_opt['title_style'].'"';
$this->ctf_field_style = 'style="'.$si_contact_opt['field_style'].'"';
$this->ctf_error_style = 'style="'.$si_contact_opt['error_style'].'"';
$ctf_field_size = absint($si_contact_opt['field_size']);
$this->ctf_aria_required = ($si_contact_opt['aria_required'] == 'true') ? ' aria-required="true" ' : '';
$string .= '
';
if ($si_contact_opt['border_enable'] == 'true') {
$string .= '
\n \n" : '';
$string .= '
ctf_title_style.'>
';
if ($si_contact_opt['border_enable'] == 'true') {
$string .= '
';
}
$string .= '
';
if ($si_contact_opt['enable_credit_link'] == 'true') {
$string .= '
'.__('Powered by', 'si-contact-form'). ' '.__('Fast and Secure Contact Form', 'si-contact-form'). '
';
}
$string .= '
';
}
return $string;
} // end function si_contact_form_short_code
// checks if captcha is enabled based on the current captcha permission settings set in the plugin options
function isCaptchaEnabled() {
global $user_ID, $si_contact_opt;
if ($si_contact_opt['captcha_enable'] !== 'true') {
return false; // captcha setting is disabled for si contact
}
// skip the captcha if user is loggged in and the settings allow
if (isset($user_ID) && intval($user_ID) > 0 && $si_contact_opt['captcha_perm'] == 'true') {
// skip the CAPTCHA display if the minimum capability is met
if ( current_user_can( $si_contact_opt['captcha_perm_level'] ) ) {
// skip capthca
return false;
}
}
return true;
} // end function isCaptchaEnabled
function captchaCheckRequires() {
global $captcha_path_cf;
$ok = 'ok';
// Test for some required things, print error message if not OK.
if ( !extension_loaded('gd') || !function_exists('gd_info') ) {
$this->captchaRequiresError .= 'ctf_error_style.'>'.__('ERROR: si-contact-form.php plugin says GD image support not detected in PHP!', 'si-contact-form').'
';
$this->captchaRequiresError .= ''.__('Contact your web host and ask them why GD image support is not enabled for PHP.', 'si-contact-form').'
';
$ok = 'no';
}
if ( !function_exists('imagepng') ) {
$this->captchaRequiresError .= 'ctf_error_style.'>'.__('ERROR: si-contact-form.php plugin says imagepng function not detected in PHP!', 'si-contact-form').'
';
$this->captchaRequiresError .= ''.__('Contact your web host and ask them why imagepng function is not enabled for PHP.', 'si-contact-form').'
';
$ok = 'no';
}
if ( !file_exists("$captcha_path_cf/securimage.php") ) {
$this->captchaRequiresError .= 'ctf_error_style.'>'.__('ERROR: si-contact-form.php plugin says captcha_library not found.', 'si-contact-form').'
';
$ok = 'no';
}
if ($ok == 'no') return false;
return true;
}
// this function adds the captcha to the contact form
function addCaptchaToContactForm($si_contact_error_captcha) {
global $user_ID, $captcha_url_cf, $si_contact_opt;
$string = '';
// Test for some required things, print error message right here if not OK.
if ($this->captchaCheckRequires()) {
// the captch html
$string = '
ctf_title_style.'>
';
$string .= ($si_contact_opt['title_capt'] != '') ? esc_html( $si_contact_opt['title_capt'] ) : esc_html( __('CAPTCHA Code', 'si-contact-form')).':';
$string .= '
'.$this->ctf_echo_if_error($si_contact_error_captcha).'
ctf_field_style.' type="text" value="" name="si_contact_captcha_code" id="si_contact_captcha_code" '.$this->ctf_aria_required.' size="'.absint($si_contact_opt['captcha_field_size']).'" />
captchaRequiresError;
}
return $string;
} // end function addCaptchaToContactForm
// shows contact form errors
function ctf_echo_if_error($this_error){
if ($this->si_contact_error) {
if (!empty($this_error)) {
return '
ctf_error_style.'>'.esc_html($this_error) . '
'."\n";
}
}
} // end function ctf_echo_if_error
// functions for protecting and validating form input vars
function ctf_clean_input($string) {
if (is_string($string)) {
return trim($this->ctf_sanitize_string(strip_tags($this->ctf_stripslashes($string))));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = $this->ctf_clean_input($value);
}
return $string;
} else {
return $string;
}
} // end function ctf_clean_input
// functions for protecting and validating form vars
function ctf_sanitize_string($string) {
$string = preg_replace("/ +/", ' ', trim($string));
return preg_replace("/[<>]/", '_', $string);
} // end function ctf_sanitize_string
// functions for protecting and validating form vars
function ctf_stripslashes($string) {
if (get_magic_quotes_gpc()) {
return stripslashes($string);
} else {
return $string;
}
} // end function ctf_stripslashes
// functions for protecting and validating form input vars
function ctf_output_string($string) {
return str_replace('"', '"', $string);
} // end function ctf_output_string
// A function knowing about name case (i.e. caps on McDonald etc)
// $name = name_case($name);
function ctf_name_case($name) {
global $si_contact_opt;
if ($si_contact_opt['name_case_enable'] !== 'true') {
return $name; // name_case setting is disabled for si contact
}
if ($name == '') return '';
$break = 0;
$newname = strtoupper($name[0]);
for ($i=1; $i < strlen($name); $i++) {
$subed = substr($name, $i, 1);
if (((ord($subed) > 64) && (ord($subed) < 123)) ||
((ord($subed) > 48) && (ord($subed) < 58))) {
$word_check = substr($name, $i - 2, 2);
if (!strcasecmp($word_check, 'Mc') || !strcasecmp($word_check, "O'")) {
$newname .= strtoupper($subed);
}else if ($break){
$newname .= strtoupper($subed);
}else{
$newname .= strtolower($subed);
}
$break = 0;
}else{
// not a letter - a boundary
$newname .= $subed;
$break = 1;
}
}
return $newname;
} // end function ctf_name_case
// checks proper email syntax (not perfect, none of these are, but this is the best I can find)
function ctf_validate_email($email) {
global $si_contact_opt;
//check for all the non-printable codes in the standard ASCII set,
//including null bytes and newlines, and return false immediately if any are found.
if (preg_match("/[\\000-\\037]/",$email)) {
return false;
}
// regular expression used to perform the email syntax check
// http://fightingforalostcause.net/misc/2006/compare-email-regex.php
//$pattern = "/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|asia|cat|jobs|tel|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i";
//$pattern = "/^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/i";
$pattern = "/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?si_contact_error = 1;
}
} // end function ctf_forbidifnewlines
// helps spam protect email input
// blocks contact form posted from other domains
function ctf_spamcheckpost() {
if(!isset($_SERVER['HTTP_USER_AGENT'])){
return 1;
}
// Make sure the form was indeed POST'ed:
// (requires your html form to use: si_contact_action="post")
if(!$_SERVER['REQUEST_METHOD'] == "POST"){
return 2;
}
// Make sure the form was posted from an approved host name.
if ($this->ctf_domain_protect == 'true') {
// Host names from where the form is authorized to be posted from:
if (is_array($this->ctf_domain)) {
$this->ctf_domain = array_map(strtolower, $this->ctf_domain);
$authHosts = $this->ctf_domain;
} else {
$this->ctf_domain = strtolower($this->ctf_domain);
$authHosts = array("$this->ctf_domain");
}
// Where have we been posted from?
if( isset($_SERVER['HTTP_REFERER']) and trim($_SERVER['HTTP_REFERER']) != '' ) {
$fromArray = parse_url(strtolower($_SERVER['HTTP_REFERER']));
// Test to see if the $fromArray used www to get here.
$wwwUsed = strpos($fromArray['host'], "www.");
if(!in_array(($wwwUsed === false ? $fromArray['host'] : substr(stristr($fromArray['host'], '.'), 1)), $authHosts)){
return 3;
}
}
} // end if domain protect
// check posted input for email injection attempts
// Check for these common exploits
// if you edit any of these do not break the syntax of the regex
$input_expl = "/(content-type|mime-version|content-transfer-encoding|to:|bcc:|cc:|document.cookie|document.write|onmouse|onkey|onclick|onload)/i";
// Loop through each POST'ed value and test if it contains one of the exploits fromn $input_expl:
foreach($_POST as $k => $v){
$v = strtolower($v);
if( preg_match($input_expl, $v) ){
return 4;
}
}
return 0;
} // end function ctf_spamcheckpost
function si_contact_plugin_action_links( $links, $file ) {
//Static so we don't call plugin_basename on every plugin row.
static $this_plugin;
if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
if ( $file == $this_plugin ){
$settings_link = ' ' . esc_html( __( 'Settings', 'si-contact-form' ) ) . ' ';
array_unshift( $links, $settings_link ); // before other links
}
return $links;
} // end function si_contact_plugin_action_links
function si_contact_form_num() {
$form_num = '';
if ( isset($_GET['ctf_form_num']) && is_numeric($_GET['ctf_form_num']) && $_GET['ctf_form_num'] <= SI_CONTACT_FORM_MAX_FORMS ) {
$form_num = (int)$_GET['ctf_form_num'];
}
return $form_num;
} // end function si_contact_form_num
// load things during init
function si_contact_init() {
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain('si-contact-form', false, dirname(plugin_basename(__FILE__)).'/languages' );
}
} // end function si_contact_init
function si_contact_get_options($form_num) {
global $si_contact_opt, $si_contact_option_defaults;
$si_contact_option_defaults = array(
'donated' => 'false',
'welcome' => __('
Comments or questions are welcome.
', 'si-contact-form'),
'email_to' => __('Webmaster', 'si-contact-form').','.get_option('admin_email'),
'email_from' => '',
'email_bcc' => '',
'email_subject' => get_option('blogname') . ' ' .__('Contact:', 'si-contact-form'),
'hidden_subject_enable' => 'false',
'double_email' => 'false',
'name_case_enable' => 'true',
'domain_protect' => 'true',
'email_check_dns' => 'true',
'captcha_enable' => 'true',
'captcha_perm' => 'false',
'captcha_perm_level' => 'read',
'redirect_enable' => 'true',
'redirect_url' => 'index.php',
'border_enable' => 'false',
'border_width' => '375',
'border_style' => 'border: 1px solid black;',
'title_style' => 'text-align:left; padding-top:10px;',
'select_style' => 'text-align:left;',
'field_style' => 'text-align:left;',
'error_style' => 'color:red; text-align:left;',
'captcha_div_style' => 'width:215px; padding-top:5px; text-align:left; float:left;',
'captcha_image_style' => 'padding-bottom:10px; float:left; border-style:none; margin:0;',
'audio_image_style' => 'padding-top:2px; vertical-align:top; float:left; border-style:none; margin:0;',
'reload_image_style' => 'vertical-align:top; float:left; border-style:none; margin:0;',
'button_style' => 'margin 0;',
'field_size' => '40',
'captcha_field_size' => '6',
'text_cols' => '40',
'text_rows' => '15',
'aria_required' => 'false',
'auto_fill_enable' => 'true',
'title_border' => '',
'title_dept' => '',
'title_select' => '',
'title_name' => '',
'title_email' => '',
'title_email2' => '',
'title_email2_help' => '',
'title_subj' => '',
'title_mess' => '',
'title_capt' => '',
'title_submit' => '',
'text_message_sent' => '',
'tooltip_captcha' => '',
'tooltip_audio' => '',
'tooltip_refresh' => '',
'enable_credit_link' => 'true',
'error_contact_select' => '',
'error_name' => '',
'error_email' => '',
'error_email2' => '',
'error_field' => '',
'error_subject' => '',
'error_message' => '',
'error_input' => '',
'error_captcha_blank' => '',
'error_captcha_wrong' => '',
'error_correct' => '',
);
// optional extra fields
foreach( array(1, 2, 3, 4, 5, 6, 7, 8) as $val ) {
$si_contact_option_defaults['ex_field'.$val.'_req'] = 'false';
$si_contact_option_defaults['ex_field'.$val.'_label'] = '';
}
// upgrade path from old version
if (!get_option('si_contact_form') && get_option('si_contact_email_to')) {
// just now updating, migrate settings
$si_contact_option_defaults = $this->si_contact_migrate($si_contact_option_defaults);
}
// install the option defaults
add_option('si_contact_form', $si_contact_option_defaults, '', 'yes');
// multi-form
for ($i = 2; $i <= SI_CONTACT_FORM_MAX_FORMS; $i++) {
add_option("si_contact_form$i", $si_contact_option_defaults, '', 'yes');
}
// get the options from the database
$si_contact_opt = get_option("si_contact_form$form_num");
// array merge incase this version has added new options
$si_contact_opt = array_merge($si_contact_option_defaults, $si_contact_opt);
// strip slashes on get options array
foreach($si_contact_opt as $key => $val) {
$si_contact_opt[$key] = $this->ctf_stripslashes($val);
}
if ($si_contact_opt['captcha_image_style'] == '' && $si_contact_opt['audio_image_style'] == '') {
// if styles seem to be blank, reset styles
$style_resets_arr = array('border_enable','border_width','border_style','title_style','field_style','error_style','captcha_div_style','captcha_image_style','audio_image_style','reload_image_style','button_style','field_size','text_cols','text_rows');
foreach($style_resets_arr as $style_reset) {
$si_contact_opt[$style_reset] = $si_contact_option_defaults[$style_reset];
}
}
} // end function si_contact_get_options
function si_contact_start_session() {
// a PHP session cookie is set so that the captcha can be remembered and function
// this has to be set before any header output
// echo "starting session ctf";
// start cookie session, but do not start session if captcha is disabled in options
if( !isset( $_SESSION ) ) { // play nice with other plugins
session_cache_limiter ('private, must-revalidate');
session_start();
//echo "session started ctf";
}
} // end function si_contact_start_session
function si_contact_migrate($si_contact_option_defaults) {
// read the options from the prior version
$new_options = array ();
foreach($si_contact_option_defaults as $key => $val) {
$new_options[$key] = $this->ctf_stripslashes( get_option( "si_contact_$key" ));
// now delete the options from the prior version
delete_option("si_contact_$key");
}
// delete settings no longer used
delete_option('si_contact_email_language');
delete_option('si_contact_email_charset');
delete_option('si_contact_email_encoding');
// by returning this the old settings will carry over to the new version
return $new_options;
} // end function si_contact_migrate
function get_captcha_url_cf() {
// The captcha URL cannot be on a different domain as the site rewrites to or the cookie won't work
// also the path has to be correct or the image won't load.
// WP_PLUGIN_URL was not getting the job done! this code should fix it.
//http://media.example.com/wordpress WordPress address get_option( 'siteurl' )
//http://tada.example.com Blog address get_option( 'home' )
//http://example.com/wordpress WordPress address get_option( 'siteurl' )
//http://example.com/ Blog address get_option( 'home' )
$site_uri = parse_url(get_option('home'));
$home_uri = parse_url(get_option('siteurl'));
$captcha_url_cf = WP_PLUGIN_URL . '/si-contact-form/captcha-secureimage';
if ($site_uri['host'] == $home_uri['host']) {
$captcha_url_cf = WP_PLUGIN_URL . '/si-contact-form/captcha-secureimage';
} else {
$captcha_url_cf = get_option( 'home' ) . '/'.PLUGINDIR.'/si-contact-form/captcha-secureimage';
}
return $captcha_url_cf;
}
} // end of class
} // end of if class
// Pre-2.8 compatibility
if ( ! function_exists( 'esc_html' ) ) {
function esc_html( $text ) {
return wp_specialchars( $text );
}
}
// Pre-2.8 compatibility
if ( ! function_exists( 'esc_attr' ) ) {
function esc_attr( $text ) {
return attribute_escape( $text );
}
}
if (class_exists("siContactForm")) {
$si_contact_form = new siContactForm();
}
if (isset($si_contact_form)) {
$captcha_url_cf = $si_contact_form->get_captcha_url_cf();
$captcha_path_cf = WP_PLUGIN_DIR . '/si-contact-form/captcha-secureimage';
// si_contact initialize options
add_action('init', array(&$si_contact_form, 'si_contact_init'),1);
// start the PHP session
add_action('init', array(&$si_contact_form,'si_contact_start_session'),2);
//add_action('parse_request', array(&$si_contact_form,'si_contact_start_session'),2);
//add_action('plugins_loaded', array(&$si_contact_form,'si_contact_start_session'),2);
// si contact form admin options
add_action('admin_menu', array(&$si_contact_form,'si_contact_add_tabs'),1);
// adds "Settings" link to the plugin action page
add_filter( 'plugin_action_links', array(&$si_contact_form,'si_contact_plugin_action_links'),10,2);
// use shortcode to print the contact form or process contact form logic
// can use dashes or underscores: [si-contact-form] or [si_contact_form]
add_shortcode('si_contact_form', array(&$si_contact_form,'si_contact_form_short_code'),1);
add_shortcode('si-contact-form', array(&$si_contact_form,'si_contact_form_short_code'),1);
// options deleted when this plugin is deleted in WP 2.7+
if ( function_exists('register_uninstall_hook') )
register_uninstall_hook(__FILE__, 'si_contact_unset_options');
}
?>