Settings | Donate
Version: 3.1.5.4
Author: Mike Challis
Author URI: http://www.642weather.com/weather/scripts.php
*/
$ctf_version = '3.1.5.4';
/* Copyright (C) 2008-2012 Mike Challis (http://www.fastsecurecontactform.com/contact)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// settings get deleted when plugin is deleted from admin plugins page
// this must be outside the class or it does not work
function si_contact_unset_options() {
delete_option('si_contact_form');
delete_option('si_contact_form_gb');
// multi-forms (a unique configuration for each contact form)
for ($i = 2; $i <= 100; $i++) {
delete_option("si_contact_form$i");
}
} // end function si_contact_unset_options
if (!class_exists('siContactForm')) {
class siContactForm {
var $si_contact_error;
var $uploaded_files;
var $ctf_notes_style;
var $ctf_version;
var $ctf_add_script;
var $vcita_add_script;
function si_contact_add_tabs() {
add_submenu_page('plugins.php', __('FS Contact Form Options', 'si-contact-form'), __('FS Contact Form Options', 'si-contact-form'), 'manage_options', __FILE__,array(&$this,'si_contact_options_page'));
}
function si_contact_update_lang() {
global $si_contact_opt, $si_contact_option_defaults;
// a few language options need to be re-translated now.
// had to do this becuse the options were actually needed to be set before the language translator was initialized
// update translation for these options (for when switched from English to another lang)
if ($si_contact_opt['welcome'] == '
Comments or questions are welcome.
' ) {
$si_contact_opt['welcome'] = __('
Comments or questions are welcome.
', 'si-contact-form');
$si_contact_option_defaults['welcome'] = $si_contact_opt['welcome'];
}
if ($si_contact_opt['email_to'] == 'Webmaster,'.get_option('admin_email')) {
$si_contact_opt['email_to'] = __('Webmaster', 'si-contact-form').','.get_option('admin_email');
$si_contact_option_defaults['email_to'] = $si_contact_opt['email_to'];
}
if ($si_contact_opt['email_subject'] == get_option('blogname') . ' ' .'Contact:') {
$si_contact_opt['email_subject'] = get_option('blogname') . ' ' .__('Contact:', 'si-contact-form');
$si_contact_option_defaults['email_subject'] = $si_contact_opt['email_subject'];
}
} // end function si_contact_update_lang
function si_contact_options_page() {
global $captcha_url_cf, $si_contact_opt, $si_contact_gb, $si_contact_gb_defaults, $si_contact_option_defaults, $ctf_version;
require_once(WP_PLUGIN_DIR . '/si-contact-form/admin/si-contact-form-admin.php');
} // end function si_contact_options_page
/* --- vCita Admin Functions - Start --- */
/**
* Add the vcita Javascript to the admin section
*/
function vcita_add_admin_js() {
if(isset($_GET['page']) && is_string($_GET['page']) && preg_match('/si-contact-form.php$/',$_GET['page']) ) {
wp_enqueue_script('jquery');
wp_register_script('vcita_fscf', plugins_url('vcita/vcita_fscf.js', __FILE__), array('jquery'), '1.1', true);
wp_register_script('vcita_fscf_admin', plugins_url('vcita/vcita_fscf_admin.js', __FILE__), array('jquery'), '1.1', true);
wp_print_scripts('vcita_fscf');
wp_print_scripts('vcita_fscf_admin');
}
}
/**
* Validate the user is initialized currenctly be performing the following.
* 1. Migration from old versions.
* 2. New User - enable vCita if the auto install flag is set to true
* 3. Upgrade - enable vCita if wasn't previously disabled - Currently nothing is done
*/
function vcita_validate_initialized_user($form_num, $form_params, $general_params, $previous_version) {
$auto_install = $general_params['vcita_auto_install'];
$curr_version = $general_params['ctf_version'];
$vcita_dismiss = $general_params['vcita_dismiss'];
// Check if a initializtion is required
if (!isset($form_params['vcita_initialized']) || $form_params['vcita_initialized'] == 'false') {
// New Install - Only enable vCita
// This will cause the notification about misconfigured installation be shown.
if ($auto_install == 'true' && $vcita_dismiss == "false") {
$form_params['vcita_enabled'] = 'true';
}
// Currently nothing during upgrade.
$form_params['vcita_initialized'] = 'true'; // Mark as initialized
update_option("si_contact_form$form_num", $form_params);
}
$confirm_token = '';
if (isset($form_params['vcita_confirm_token']))
$confirm_token = $form_params['vcita_confirm_token'];
// Migrate token to the new field
if (!empty($confirm_token) && !empty($form_params['vcita_uid'])) {
$form_params['vcita_confirm_tokens'] = '';
$form_params = $this->vcita_set_confirmation_token($form_params, $confirm_token);
$form_params['vcita_confirm_token'] = null;
update_option("si_contact_form$form_num", $form_params);
}
// check if the approved flag should be turned on, happens when:
// When user available, enabled and approve is false (this can only happen if form is an old version)
if (isset($form_params['vcita_enabled']) && $form_params['vcita_enabled'] == 'true' &&
isset($form_params['vcita_uid']) && !empty($form_params['vcita_uid']) &&
(!isset($form_params['vcita_approved']) || $form_params['vcita_approved'] == 'false')) {
$form_params['vcita_approved'] = 'true';
update_option("si_contact_form$form_num", $form_params);
}
return $form_params;
}
/**
* Use the vCita API to get a user, either create a new one or get the id of an available user
* In case the "default" email is used, no action takes place.
*
* @return array of the user name, id and if he finished the registration or not
*/
function vcita_generate_or_validate_user($params) {
$used_email = $params['vcita_email'];
// Don't create / validate if this isn't the expert
if (empty($_SESSION) || empty($_SESSION["vcita_expert"]) || !$_SESSION["vcita_expert"]) {
return $params;
}
// Only generate a user if the mail isn't the default one.
if ($used_email == 'mail@example.com') {
$params['vcita_uid'] = '';
return $params;
}
extract($this->vcita_post_contents("http://www.vcita.com/api/experts?id=".$params['vcita_uid'].
"&email=".urlencode($used_email).
"&first_name=".urlencode($params['vcita_first_name'])."&last_name=".
urlencode($params['vcita_last_name'])."&ref=wp-fscf&o=int.1"));
return $this->vcita_parse_user_info($params, $success, $raw_data);
}
/*
* Parse the result from the vCita API.
* Update all the parameters with the given values / error.
*/
function vcita_parse_user_info($params, $success, $raw_data) {
$previous_id = isset($params['vcita_uid']) ? $params['vcita_uid'] : '';
$params['vcita_initialized'] = 'false';
$params['vcita_uid'] = '';
if (!$success) {
$params['vcita_last_error'] = "Temporary problem, please try again later";
} else {
$data = json_decode($raw_data);
if ($data->{'success'} == 1) {
$params['vcita_confirmed'] = $data->{'confirmed'};
$params['vcita_last_error'] = "";
$params['vcita_uid'] = $data->{'id'};
$params['vcita_initialized'] = 'true';
$params['vcita_first_name'] = $data->{'first_name'};
$params['vcita_last_name'] = $data->{'last_name'};
if ($previous_id != $data->{'id'}) {
$params = $this->vcita_set_confirmation_token($params, $data->{'confirmation_token'});
}
if (isset($data->{'email'}) && !empty($data->{'email'})) {
$params['vcita_email'] = $data->{'email'};
}
} else {
$params['vcita_last_error'] = $data-> {'error'};
}
}
return $params;
}
/**
* Disconnect the user from vCita by removing his details.
*/
function vcita_disconnect_form($form_params) {
global $si_contact_option_defaults;
$form_params['vcita_approved'] = $si_contact_option_defaults['vcita_approved'];
$form_params['vcita_uid'] = $si_contact_option_defaults['vcita_uid'];
$form_params['vcita_email'] = $si_contact_option_defaults['vcita_email'];
$form_params['vcita_first_name'] = $si_contact_option_defaults['vcita_first_name'];
$form_params['vcita_last_name'] = $si_contact_option_defaults['vcita_last_name'];
$form_params['vcita_initialized'] = 'true'; // Don't re-enable next time
// On Purpose keeping the confirmation_tokens
return $form_params;
}
/**
* Perform an HTTP POST Call to retrieve the data for the required content.
*
* @param $url
* @return array - raw_data and a success flag
*/
function vcita_post_contents($url) {
$response = wp_remote_post($url, array('header' => array('Accept' => 'application/json; charset=utf-8'),
'timeout' => 10));
return $this->vcita_parse_response($response);
}
/**
* Perform an HTTP GET Call to retrieve the data for the required content.
*
* @param $url
* @return array - raw_data and a success flag
*/
function vcita_get_contents($url) {
$response = wp_remote_get($url, array('header' => array('Accept' => 'application/json; charset=utf-8'),
'timeout' => 10));
return $this->vcita_parse_response($response);
}
/**
* Parse the HTTP response and return the data and if was successful or not.
*/
function vcita_parse_response($response) {
$success = false;
$raw_data = "Unknown error";
if (is_wp_error($response)) {
$raw_data = $response->get_error_message();
} elseif (!empty($response['response'])) {
if ($response['response']['code'] != 200) {
$raw_data = $response['response']['message'];
} else {
$success = true;
$raw_data = $response['body'];
}
}
return compact('raw_data', 'success');
}
/**
* Add the dynamic notification area based on the current user status
*
* This notification is for the Meeting scheduler section (Not for page header notifications)
*/
function vcita_add_notification($params) {
$confirmation_token = $this->vcita_get_confirmation_token($params);
if ($params['vcita_enabled'] == 'false') {
$message = 'Meeting Scheduler is disabled, please check the box below to allow users to request meetings via your contact form';
$message_type = "fsc-notice";
} elseif (!empty($params['vcita_last_error'])) {
$message = $params['vcita_last_error'];
$message_type = "fsc-error";
} elseif (!empty($params['vcita_uid'])) {
$message_type = "fsc-notice";
$message = "vCita Meeting Scheduler is active ";
if (!$params['vcita_confirmed'] && !empty($confirmation_token)) {
$message .= " Click below to set your meeting options and availability".
"
";
$message_type = "fsc-error";
} elseif (!empty($params['vcita_last_name'])) {
$message .= "Active account: ".$params['vcita_first_name']." ".$params['vcita_last_name'];
}
} elseif ($this->vcita_get_email($params) == 'mail@example.com') {
$message = "You are currently using the default mail: mail@example.com, To activate - please enter you email below.";
$message_type = "fsc-notice";
} elseif ($params['vcita_enabled'] == 'true') {
$message = "Please configure your vCita Meeting Scheduler below.";
$message_type = "fsc-notice";
}
echo "
".$message."
";
echo "";
}
/**
* Location for the vcita banner
*/
function vcita_banner_location() {
return plugins_url( 'vcita/vcita_banner.jpg' , __FILE__ );
}
/**
* Add the vCita advanced configuraion links to user admin.
* Show the settings only if the user is available
*/
function vcita_add_config($params) {
// Only show the Edit link in case the user is available
if (!empty($params["vcita_uid"]) && $params['vcita_enabled'] == 'true') {
$confirmation_token = $this->vcita_get_confirmation_token($params);
$vcita_curr_notifcation = "
";
if ($params['vcita_confirmed']) {
$vcita_curr_notifcation .= "
";
} else {
$notification_created = false;
}
return $notification_created;
}
/**
* Check if registration for the given form wasn't completed yet.
*/
function vcita_should_complete_registration($form_params) {
$vcita_confirmation_token = $this->vcita_get_confirmation_token($form_params);
return isset($form_params['vcita_uid']) && !empty($form_params['vcita_uid']) && $form_params['vcita_enabled'] == 'true' && !$form_params['vcita_confirmed'] && !empty($vcita_confirmation_token);
}
/**
* Check if a notification for the current form should be displayed to the user
*/
function vcita_should_notify_missing_details($form_params) {
return isset($form_params['vcita_uid']) && empty($form_params['vcita_uid']) && $form_params['vcita_enabled'] == 'true';
}
/**
* Check if should display a warning in the admin section
* Warning will be shown in all admin pages (as being done by many other plugins)
* Won't shown for the actual fast contact page - it is being called directly from the page
*/
function si_contact_vcita_admin_warning() {
if (!isset($_GET['page']) || !preg_match('/si-contact-form.php$/',$_GET['page'])) {
$si_contact_global_tmp = get_option("si_contact_form_gb");
if (class_exists("siContactForm") && !isset($si_contact_form) ) {
$si_contact_form = new siContactForm();
if (empty($si_contact_global_tmp)) {
$this->vcita_print_admin_page_notification();
} else {
$vcita_never_used = true;
for ($i = 1; $i <= $si_contact_global_tmp['max_forms']; $i++) {
$form_num = ($i == 1) ? "" : $i;
$si_form_params = get_option("si_contact_form$form_num");
if ($this->vcita_print_admin_page_notification($si_contact_global_tmp, $si_form_params, $form_num)) {
$vcita_never_used = false;
return;
} else if ($this->vcita_is_form_used($si_form_params)) {
$vcita_never_used = false;
}
}
if ($vcita_never_used && $this->vcita_should_show_when_not_used($si_contact_global_tmp)) {
$this->vcita_print_admin_page_notification($si_contact_global_tmp, null); // Put the general
}
}
}
}
}
/**
* Get the email which should be used for vcita meeting scheduling
*/
function vcita_get_email($params) {
if (!empty($params["vcita_email"])) {
return $params["vcita_email"];
} else {
return $this->si_contact_extract_email($params["email_to"]);
}
}
/*
* Check if the user is already available in vCita
*/
function vcita_check_user($params) {
extract($this->vcita_get_contents("http://www.vcita.com/api/experts/".$params['vcita_uid']));
return $this->vcita_parse_user_info($params, $success, $raw_data);
}
/**
* Get the confirmation token matches the current user
*/
function vcita_get_confirmation_token($params) {
$token = "";
if (!empty($params["vcita_confirm_tokens"])) {
$token = "";
$tokens = explode("|", $params["vcita_confirm_tokens"]);
if (count($tokens) > 0) {
foreach ($tokens as $raw_token) {
$token_values = explode("-", $raw_token);
if (!empty($raw_token) && $token_values[0] == $params["vcita_uid"]) {
$token = $token_values[1];
if (!empty($_SESSION) && $_SESSION['vcita_expert']) {
$_SESSION['vcita_owner-of-'.$params['vcita_uid']] = true;
}
break;
}
}
}
}
return $token;
}
/**
* Set the confirmation for the current user
*/
function vcita_set_confirmation_token($params, $confirmation_token) {
if (!empty($confirmation_token)) {
$tokens = explode("|", $params["vcita_confirm_tokens"]);
array_push($tokens, $params["vcita_uid"]."-".$confirmation_token);
$params["vcita_confirm_tokens"] = implode("|", $tokens);
}
return $params;
}
/**
* Check if the vcita confirmation token should be saved.
* Currently this means it will be also saved in the client side in a dedicated cookie.
*/
function vcita_should_store_expert_confirmation_token($params) {
$confirmation_token = $this->vcita_get_confirmation_token($params);
if (!empty($confirmation_token) && !empty($_SESSION) && $_SESSION['vcita_owner-of-'.$params['vcita_uid']]) {
return $confirmation_token;
} else {
return "";
}
}
/**
* Flip the dismiss flag to true and make all the neccessary adjustments.
*/
function vcita_dismiss_pending_notification($global_params, $current_form_num) {
global $si_contact_opt;
// Go over all the forms and disable the pending ones
for ($i = 1; $i <= $global_params['max_forms']; $i++) {
$form_num = ($i == 1) ? "" : $i;
if ($current_form_num == $form_num) {
$si_form_params = $si_contact_opt;
} else {
$si_form_params = get_option("si_contact_form$form_num");
}
if ($this->vcita_should_complete_registration($si_form_params) ||
$this->vcita_should_notify_missing_details($si_form_params)) {
$si_form_params['vcita_enabled'] = 'false';
$si_form_params['vcita_last_error'] = '';
$si_form_params['vcita_uid'] = '';
$si_form_params['vcita_first_name'] = '';
$si_form_params['vcita_last_name'] = '';
$si_form_params['vcita_email'] = '';
update_option("si_contact_form$form_num", $si_form_params);
// Also update the global variable
if ($current_form_num == $form_num) {
$si_contact_opt = $si_form_params;
}
}
}
// Put the dismiss flag
$global_params["vcita_dismiss"] = "true";
update_option("si_contact_form_gb", $global_params);
return $global_params;
}
/**
* True / False if notification should be displayed if user didn't use vCita
*
* True only if upgrade user (never had auto install vCita)
*/
function vcita_should_show_when_not_used($global_params) {
return isset($global_params['vcita_auto_install']) && $global_params['vcita_auto_install'] == "false";
}
/**
* vCita form is used if one of the following:
*
* - form enabled
* - has a vcita_uid
* - has a confirmation_token -> in the past had a user
*/
function vcita_is_form_used($form_param) {
return ((isset($form_param["vcita_enabled"]) && $form_param["vcita_enabled"] == "true") ||
(isset($form_param["vcita_uid"]) && !empty($form_param["vcita_uid"])) ||
(isset($form_param["vcita_confirm_tokens"]) && !empty($form_param["vcita_confirm_tokens"])));
}
/**
* Check if vcita is used in any form
*/
function vcita_is_being_used() {
$si_contact_global_tmp = get_option("si_contact_form_gb");
for ($i = 1; $i <= $si_contact_global_tmp['max_forms']; $i++) {
$form_num = ($i == 1) ? "" : $i;
$si_form_params = get_option("si_contact_form$form_num");
if ($this->vcita_is_form_used($si_form_params)) {
return true;
}
}
return false;
}
/* --- vCita Admin Functions - End --- */
/* --- vCita Contact Functions - Start --- */
/**
* Add the vcita script to the pages of the fast secure
*/
function vcita_si_contact_add_script(){
global $si_contact_opt, $vcita_add_script;
if (!$vcita_add_script)
return;
wp_enqueue_script('jquery');
wp_register_script('vcita_fscf', plugins_url('vcita/vcita_fscf.js', __FILE__), array('jquery'), '1.1', true);
wp_print_scripts('vcita_fscf');
?>
\n";
$this->si_contact_from_name = $from_name;
$this->si_contact_from_email = $from_email;
$this->si_contact_mail_sender = $from_email;
$header .= "Reply-To: $reply_to\n"; // for php mail and wp_mail
$header .= "X-Sender: $this->si_contact_from_email\n"; // for php mail
$header .= "Return-Path: $this->si_contact_from_email\n"; // for php mail
if ($html_mail == 'true') {
$header .= 'Content-Type: text/html; charset='. get_option('blog_charset') . $php_eol;
} else {
$header .= 'Content-Type: text/plain; charset='. get_option('blog_charset') . $php_eol;
}
if(isset($si_contact_opt['email_subject']) && $si_contact_opt['email_subject'] != '') {
$subj = $si_contact_opt['email_subject'] ." $subj";
}
@ini_set('sendmail_from' , $this->si_contact_from_email);
if ($si_contact_opt['php_mailer_enable'] == 'php') {
$header_php .= $header;
if (!$safe_mode) {
// Pass the Return-Path via sendmail's -f command.
@mail($email,$subj,$msg,$header_php, '-f '.$from_email);
} else {
// the fifth parameter is not allowed in safe mode
@mail($email,$subj,$msg,$header_php);
}
}else if ($si_contact_opt['php_mailer_enable'] == 'geekmail') {
// autoresponder sending with geekmail
require_once WP_PLUGIN_DIR . '/si-contact-form/ctf_geekMail-1.0.php';
$ctf_geekMail = new ctf_geekMail();
if ($html_mail == 'true') {
$ctf_geekMail->setMailType('html');
} else {
$ctf_geekMail->setMailType('text');
}
$ctf_geekMail->_setcharSet(get_option('blog_charset'));
$ctf_geekMail->_setnewLine($php_eol);
$ctf_geekMail->return_path($from_email);
$ctf_geekMail->x_sender($from_email);
$ctf_geekMail->from($from_email, $from_name);
$ctf_geekMail->_replyTo($reply_to);
$ctf_geekMail->to($email);
$ctf_geekMail->subject($subj);
$ctf_geekMail->message($msg);
@$ctf_geekMail->send();
} else {
add_filter( 'wp_mail_from_name', array(&$this,'si_contact_form_from_name'),1);
add_filter( 'wp_mail_from', array(&$this,'si_contact_form_from_email'),1);
add_action('phpmailer_init', array(&$this,'si_contact_form_mail_sender'),1);
@wp_mail($email,$subj,$msg,$header);
}
}
/**
* Extract the mail contained and the received argument.
* Handles the following usecases:
* 1. Name and email concatenation - Webmaster,mail@example.com
* 2. Only email
*
* Returns the email address
*/
function si_contact_extract_email($ctf_extracted_email) {
$ctf_trimmed_email = trim($ctf_extracted_email);
if(!preg_match("/,/", $ctf_trimmed_email) ) { // single email without,name
$name = ''; // name,email
$email = $ctf_trimmed_email;
} else{
list($name, $email) = preg_split('#(? permission_level
$choices = array (
$this->ctf_output_string( __('All registered users', 'si-contact-form')) => 'read',
$this->ctf_output_string( __('Edit posts', 'si-contact-form')) => 'edit_posts',
$this->ctf_output_string( __('Publish Posts', 'si-contact-form')) => 'publish_posts',
$this->ctf_output_string( __('Moderate Comments', 'si-contact-form')) => 'moderate_comments',
$this->ctf_output_string( __('Administer site', 'si-contact-form')) => 'level_10'
);
// print the