Your IP : 216.73.217.143


Current Path : /home/ereika83/public_html/wp-content/plugins/genesis-club-pro/classes/
Upload File :
Current File : /home/ereika83/public_html/wp-content/plugins/genesis-club-pro/classes/class-form.php

<?php

class Genesis_Club_Form extends Genesis_Club_Module {
   
   const OPTION_NAME = 'form';
   const PRIVACY = 'We guarantee 100% privacy. Your information will not be shared';
   
	private $autoresponders = array(
	  	'infusionsoft-legacy' => array( 
	  		'action' => 'https://%1$s.infusionsoft.com/AddForms/processFormSecure.jsp',
    		'fixed'=> array(
    			'infusion_type' => 'CustomWebForm'),
			'vars'=> array(
				'email' => 'Contact0Email',
				'fullname' => 'Contact0FirstName',
				'firstname' => 'Contact0FirstName',
				'lastname' => 'Contact0LastName',
				'telephone' => 'Contact0Phone1',
				'infusion_xid' =>  'infusion_xid',
				'infusion_name' => 'infusion_name',
				'app' => '')
		),
	  	'infusionsoft' => array( 
	  		'action' => 'https://%1$s.infusionsoft.com/app/form/process/%2$s',
    		'fixed'=> array(
    			'infusionsoft_version' => '1.29.10.21'),
			'vars'=> array(
				'email' => 'inf_field_Email',
				'fullname' => 'inf_field_FirstName',
				'firstname' => 'inf_field_FirstName',
				'lastname' => 'inf_field_LastName',
				'telephone' => 'inf_field_Phone1',
				'inf_form_xid' =>  'inf_form_xid',
				'inf_form_name' => 'inf_form_name',
				'app' => '')
		),

	  	'sendreach' => array( 
	  		'action' => 'https://register.sendreach.com/forms/?listid=%1$s',
    		'fixed'=> array(),
			'vars'=> array(
				'email' => 'email',
				'fullname' => 'name',
				'firstname' => 'first_name',
				'lastname' => 'last_name',
				'telephone' => 'cell',
				'lid' => '')
		),

	  	'mailchimp' => array( 
	  		'action' => 'http://%1$s.list-manage.com/subscribe/post?u=%2$s&amp;id=%3$s&amp;b_%2$s_%3$s=',
    		'fixed'=> array(),
			'vars'=> array(
				'email' => 'EMAIL',
				'fullname' => 'FNAME',
				'firstname' => 'FNAME',
				'lastname' => 'LNAME',
				'telephone' => 'PHONE',
				'app' => '',
				'mcu' => '',
				'mcid' => '')
		),

  		'aweber' => array( 
  			'action' => 'http://www.aweber.com/scripts/addlead.pl',
    		'fixed'=> array (
    			'meta_required' => 'email',
    			'meta_message' => 1),
    		'vars'=> array(	'email' => 'email',
    			'fullname' => 'name',
    			'firstname' => 'name (awf_first)',
     			'lastname' => 'name (awf_last)', 			
				'telephone' => 'custom phone',
    			'listname' => 'listname',
    			'meta_adtracking' => 'meta_adtracking',
    			'redirect' => 'redirect',
    			'custom_list' => 'custom list',
				'custom_tracking' => 'custom tracking',
				'custom_source' => 'custom source')
    	)
	);		


	private $defaults = array(
 		'id' => '',
 		'class' => '',
		'background' => '',
		'padding' => '',
 		'button_text' => 'Sign Up Now!!',
		'placeholder' => false,
		'show_last_name' => false,
		'show_telephone' => false,
		'email_only' => false,
		'single_line' => false,
        'privacy' => false,
    	'to' => 'aweber',
 		'listname' => '',
 		'redirect' => '',
 		'meta_adtracking' => '',
		'custom_tracking' => '',
		'custom_source' => '',
		'custom_list' => '',
		'app' => '',
		'mcu' => '',
		'mcid' => '',
		'lid' => '',
 		'infusion_xid' => '',
 		'inf_form_xid' => '',
 		'inf_form_name' => '',
 		'infusion_name' => '',	
	);

	function get_defaults() {
       return $this->defaults; 
    }

	function get_options_name() {
       return self::OPTION_NAME; 
    }	

	function init() {
		add_shortcode('genesis_club_form', array($this,'display'));
		add_shortcode('genesis-club-form', array($this,'display'));
		add_action('template_redirect', array($this,'dispatch'));
		add_action('wp', array($this,'check_for_shortcode')) ;
		add_filter('widget_text', 'do_shortcode', 11);
	}

	function check_for_shortcode() {
		if ($this->utils->post_has_shortcode('genesis-club-form','single_line'))
			add_action('wp_print_scripts', array($this,'single_line_css'));	
	}

	public function display($attr) {
        $params = shortcode_atts( $this->defaults, $attr ); //apply plugin defaults
		$background = $params['background']; unset($params['background']);
		$button_text = $params['button_text']; unset($params['button_text']);
		$class = $params['class']; unset($params['class']);
		$id = $params['id']; unset($params['id']);
		$email_only = $params['email_only']; unset($params['email_only']);
		$show_last_name = $params['show_last_name']; unset($params['show_last_name']);
		$show_telephone = $params['show_telephone']; unset($params['show_telephone']);
		if ($show_telephone 
		&& ($show_telephone != 1) 
		&& ($show_telephone != 'on') 
		&& (('aweber'==$params['to']) || ('mailchimp'==$params['to']))) 
			$params['telephone_field'] = $show_telephone;  //custom field for telephone number
		$padding = $params['padding']; unset($params['padding']);
		$placeholder = !empty($params['placeholder']); unset($params['placeholder']);
		$single_line = !empty($params['single_line']); unset($params['single_line']);
		$privacy = $params['privacy'] ? sprintf('<p class="privacy">$1$s</p>', $params['privacy'] == 'on' ? self::PRIVACY : $params['privacy'] ) : ''; unset($params['privacy']);
		$sep = $single_line ? '' : '<br/>'; 
		$hidden='';
		foreach ($params as $key => $val) {
			if (!empty($val)) 
				$hidden .= sprintf('<input type="hidden" name="%1$s" value="%2$s" />',
					str_replace('custom_','custom ',$key), $val);
		}
		if (! $email_only) {
			if ($show_last_name) {
				$ln1 = $placeholder ? '' : '<label for="firstname">First Name</label>';
				$pn1 = $placeholder ? 'placeholder="First Name"' : '';
				$input1 = sprintf('%1$s <input type="text" id="firstname" name="firstname" %2$s value="" />%3$s',  $ln1, $pn1, $sep);
				$ln2 = $placeholder ? '' : '<label for="lastname">Last Name</label>';
				$pn2 = $placeholder ? 'placeholder="Last Name"' : '';
				$input2 = sprintf('%1$s <input type="text" id="lastname" name="lastname" %2$s value="" />%3$s',  $ln2, $pn2, $sep);
			} else {
				$ln = $placeholder ? '' : '<label for="fullname">Name</label>';
				$pn = $placeholder ? 'placeholder="Name"' : '';
				$input1 = sprintf('%1$s <input type="text" id="fullname" name="fullname" %2$s value="" />%3$s',  $ln, $pn, $sep);
				$input2 = '';
			}
		}
		$le = $placeholder ? '' : '<label for="email">Email</label>';
		$pe = $placeholder ? 'placeholder="Email"' : '';
		$input3 = sprintf('%1$s <input type="text" id="email" name="email" %2$s value="" />%3$s',  $le, $pe, $sep);

		if ($show_telephone) { 
			$lt = $placeholder ? '' : '<label for="telephone">Phone</label>';
			$pt = $placeholder ? 'placeholder="Telephone"' : '';
			$input4 = sprintf('%1$s <input type="text" id="telephone" name="telephone" %2$s value="" />%3$s',  $lt, $pt, $sep);
		} else {
			$input4 = '';
		}

		$classes = array('genesis-club-form');
		if ($single_line) $classes[] = 'single-line';
		$class = sprintf(' class="%1$s"',trim(implode(' ', $classes) . ' ' . $class));
		if (!empty($id)) $id = sprintf(' id="%1$s"', $id);	
		$style ='';
		if (!empty($background)) $style .= sprintf('background: url(%1$s);',$background);
		if (!empty($padding)) $style .= sprintf('padding: %1$s;',$padding);
		if (!empty($style)) $style = sprintf(' style="%1$s"',$style);
		$result = <<< FORM
<form{$id}{$class}{$style} method="post">
<input type="hidden" name="form_storm" value="submit"/>{$hidden}
{$input1}{$input2}{$input3}{$input4}<button>{$button_text}</button>{$privacy}
</form>
FORM;
		return $result;
	}

	public function dispatch() {
	    if (array_key_exists('form_storm', $_REQUEST) 
	    && ($_REQUEST['form_storm'] == "submit")) 
	    	$this->forward_form();
	}

	private function forward_form () {
    	$to = $_REQUEST['to'] ;

		if( ! array_key_exists($to,$this->autoresponders)) {
			wp_redirect(home_url());
			exit;
		}
		$autoresponder = $this->autoresponders[$to];		
		$action = $this->derive_action($to, $autoresponder);
		$postvars = $autoresponder['fixed'];
        $vars = $autoresponder['vars'];
		if (array_key_exists('telephone_field', $_REQUEST)) $vars['telephone'] = $_REQUEST['telephone_field']; //override default
        foreach ($_REQUEST as $key => $value) {
			$val = 'email'==$key ? sanitize_email($value) : sanitize_text_field($value);
            if (array_key_exists($key, $vars) && !empty($val) && ($new_key = $vars[$key])) $postvars[$new_key] = $val;
		}
		printf('<form id="cfrm" method="POST" action="%1$s">', $action);
		foreach($postvars as $k => $v) printf ('<input type="hidden" name="%1$s" value="%2$s" />', $k, htmlentities($v));
		print('</form><script type="text/javascript">document.getElementById("cfrm").submit();</script>');
		exit;
	}

	private function derive_action($autoresponder, $config) {
		$action = $config['action'];
		switch ($autoresponder) {

			case 'infusionsoft-legacy': { 
        		if (array_key_exists('app',$_REQUEST)) {
 					$action = sprintf($action, $_REQUEST['app']); 
        		} 
        		break;
			}

			case 'infusionsoft': { 
        		if (array_key_exists('app',$_REQUEST) && array_key_exists('inf_form_xid',$_REQUEST)) {
 					$action = sprintf($action, $_REQUEST['app'], $_REQUEST['inf_form_xid']); 
        		} 
        		break;
			}

			case 'mailchimp': { 
        		if (array_key_exists('app',$_REQUEST) 
        		&& array_key_exists('mcu',$_REQUEST) 
        		&& array_key_exists('mcid',$_REQUEST)) {
 					$action = sprintf($action, $_REQUEST['app'], $_REQUEST['mcu'], $_REQUEST['mcid']); 
        		} 
        		break;
			}
			case 'sendreach': { 
        		if (array_key_exists('lid',$_REQUEST)) {
 					$action = sprintf($action, $_REQUEST['lid']); 
        		} 
        		break;
			}			
		}
		return $action;
	}

	public function single_line_css() {
		print <<< CSS
<style type="text/css">
.genesis-club-form.single-line input { width: auto; margin-right: 1em; }
</style>

CSS;
	}
	
}