/**
     * Hook into show_user_profile action to display our user subscription settings if necessary
     *
     * @global  $cc
     *
     * @param <type> $user
     *
     * @return <type>
     */
    function display($user)
    {
        $Contact = new KWSContact($this->cc->getContactByEmail($user->data->user_email));
        if ($Contact && current_user_can('edit_users') && !isset($_GET['debug-user-display'])) {
            echo sprintf(__('
				<p><img src="%s" width="225" height="33" alt="Constant Contact" class="block" /><a href="%s">Admin-Only: Edit this User\'s Details</a> %s</p>
			', 'ctct'), plugins_url('images/admin/logo-horizontal.png', CTCT_FILE), admin_url('admin.php?page=constant-contact-contacts&amp;edit=' . $Contact->id), constant_contact_tip(__('Users will not see this link or the Constant Contact logo.', 'ctct'), false));
        }
        if (!$this->subscribe_method) {
            return;
        }
        $register_page_method = CTCT_Settings::get('profile_page_form');
        // Prepare the description from the settings screen
        $signup_description = CTCT_Settings::get('signup_description');
        if ($signup_description) {
            $signup_description = wpautop($signup_description);
            $signup_description = "<div class='description'>{$signup_description}</div>";
        }
        ?>
		<h3><?php 
        echo CTCT_Settings::get('signup_title');
        ?>
</h3>
		<?php 
        echo $signup_description;
        ?>

		<p><?php 
        $lists = (array) $Contact->get('lists', true);
        echo KWSContactList::outputHTML('all', array('checked' => $lists));
        ?>
</p>
		<br/>
	<?php 
    }
 /**
  * Outputs the checkbox area below the comment form that allows
  * commenters to subscribe to the email list.
  *
  * @since 1.0.0
  *
  * @todo  Add checks as to whether someone's already subscribed. The logic's there, just not the check.
  * @return null Return early if in the admin or the email list hasn't been set
  */
 public function comment_form()
 {
     /** Don't do anything if we are in the admin */
     if (is_admin()) {
         return;
     }
     $checked = $status = '';
     $clear = CTCT_Settings::get('comment_form_clear') ? 'style="clear: both;"' : '';
     if (current_user_can('administrator') && !isset($_GET['debug_comment_form'])) {
         $output = '<p class="ctct-subscribe" ' . $clear . '><label>' . CTCT_Settings::get('comment_form_admin_text') . '</label></p>';
     } elseif ('subscribed' == $status) {
         $output = '<p class="ctct-subscribe" ' . $clear . '>' . CTCT_Settings::get('comment_form_subscribed_text') . '</p>';
     } elseif ('pending' == $status) {
         $output = '<p class="ctct-subscribe" ' . $clear . '>' . CTCT_Settings::get('comment_form_pending_text') . '</p>';
     } else {
         $output = '<p class="ctct-subscribe" ' . $clear . '>';
         $output .= sprintf('<label for="ctct-comment-subscribe"><input type="checkbox" name="ctct-subscribe" id="ctct-comment-subscribe" value="subscribe" style="width: auto;" %s /> %s</label>', $checked, CTCT_Settings::get('comment_form_check_text'));
         $output .= '</p>';
     }
     echo apply_filters('ctct_comment_form_checkbox_output', $output);
 }
    /**
     * Hook into 'register_form' action to show our subscription form to users while they are registering themselves
     *
     * @return <type>
     */
    function form()
    {
        $reg = '';
        $regform = '
		<style>
			.ctct-register { margin-bottom:16px }
			.ctct-register p { margin:8px 0 }
		</style>';
        // Margin bottom is to match .login form .input bottom margin.
        // Sorry for the hack.
        $regform .= '<div class="ctct-register">';
        $title = CTCT_Settings::get('signup_title');
        switch ($this->method) {
            case 'checkbox':
                $reg = '<p class="ctct-subscribe">';
                $reg .= sprintf('<label for="ctct-registration-subscribe"><input type="checkbox" name="ctct-subscribe" id="ctct-registration-subscribe" value="subscribe" style="width: auto;" %s /> %s</label>', checked(CTCT_Settings::get('default_opt_in'), true, false), $title);
                $reg .= '</p>';
                $title = false;
                break;
            default:
                $title = empty($title) ? '' : '<label>' . $title . '</label>';
                $include = CTCT_Settings::get('registration_checkbox_lists');
                $checked = isset($_POST['lists']) ? $_POST['lists'] : (CTCT_Settings::get('default_opt_in') ? true : false);
                $reg .= KWSContactList::outputHTML($include, array('type' => $this->method, 'checked' => $checked, 'blank' => CTCT_Settings::get('default_select_option_text')));
                break;
        }
        // Prepare the description from the settings screen
        $signup_description = trim(rtrim(CTCT_Settings::get('signup_description')));
        if (!empty($signup_description)) {
            $signup_description = wpautop($signup_description);
            $signup_description = "<div class='description'>{$signup_description}</div>";
        }
        $regform .= CTCT_Settings::get('signup_description_position') === 'before' ? $title . $signup_description . $reg : $title . $reg . $signup_description;
        $regform .= '</div>';
        $regform = apply_filters('constant_contact_register_form', $regform);
        echo $regform;
    }
 /**
  * Validate email based on user settings.
  *
  * First, verify email using `is_email()` WordPress function (required)
  *
  * Then, process email validation based on settings.
  *
  * @param  KWSContact $Contact Contact object
  *
  * @return WP_Error|boolean|void    If valid, return `true`, otherwise return a WP_Error object.
  */
 function validateEmail(KWSContact &$Contact)
 {
     if (!class_exists('DataValidation')) {
         include_once CTCT_DIR_PATH . 'lib/class.datavalidation.php';
     }
     if (!class_exists('SMTP_validateEmail')) {
         include_once CTCT_DIR_PATH . 'lib/mail/smtp_validateEmail.class.php';
     }
     $email = $Contact->get('email');
     $is_valid = array();
     // 1: Check if it's an email at all
     if (empty($email)) {
         do_action('ctct_activity', 'Empty email address', $email);
         $this->errors[] = new WP_Error('empty_email', __('Please enter your email address.', 'ctct'), 'email_address');
         return;
     } elseif (!is_email($email)) {
         do_action('ctct_activity', 'Invalid email address', $email);
         $this->errors[] = new WP_Error('not_email', __('Invalid email address.', 'ctct'), 'email_address');
         return;
     }
     $methods = (array) CTCT_Settings::get('spam_methods');
     // 2: Akismet validation
     if (in_array('akismet', $methods)) {
         $akismetCheck = $this->akismetCheck($Contact);
         if (is_wp_error($akismetCheck)) {
             $this->errors[] = $akismetCheck;
             return;
         }
     }
     // 3: WangGuard validation
     if (in_array('wangguard', $methods) && function_exists('wangguard_verify_email') && wangguard_server_connectivity_ok()) {
         global $wangguard_api_host;
         // If WangGuard isn't set up yet, set'er up!
         if (empty($wangguard_api_host)) {
             wangguard_init();
         }
         $return = wangguard_verify_email($email, wangguard_getRemoteIP(), wangguard_getRemoteProxyIP());
         if ($return == 'checked' || $return == 'not-checked') {
             do_action('ctct_activity', 'WangGuard validation passed.', $email, $return);
         } else {
             $this->errors[] = new WP_Error('wangguard', __('Email validation failed.', 'ctct'), $email, $return);
             return;
         }
     }
     // 4: DataValidation.com validation
     if (in_array('datavalidation', $methods) && class_exists('DataValidation')) {
         $Validate = new DataValidation(CTCT_Settings::get('datavalidation_api_key'));
         $validation = $Validate->validate($email);
         $process_inconclusive = apply_filters('ctct_process_inconclusive_emails', true);
         if (is_wp_error($validation)) {
             do_action('ctct_activity', 'DataValidation.com error', 'The email was not processed because of the error: ' . $validation->get_error_message());
             return;
         } elseif ($validation === false || $validation === NULL && !$process_inconclusive) {
             do_action('ctct_activity', 'DataValidation validation failed.', $email, $Validate);
             $message = isset($Validate->message) ? $Validate->message : __('Not a valid email.', 'ctct');
             $this->errors[] = new WP_Error('datavalidation', $message, $email, $Validate);
             return;
         }
         if ($validation === NULL) {
             do_action('ctct_activity', 'DataValidation validation inconclusive.', $email, $Validate);
         } elseif ($validation === true) {
             do_action('ctct_activity', 'DataValidation validation passed.', $email, $Validate);
         }
     }
     // 5: SMTP validation
     if (in_array('smtp', $methods) && class_exists('SMTP_validateEmail')) {
         try {
             $SMTP_Validator = new SMTP_validateEmail();
             // Timeout after 1 second
             $SMTP_Validator->max_conn_time = 1;
             $SMTP_Validator->max_read_time = 1;
             $SMTP_Validator->debug = 0;
             // Prevent PHP notices about timeouts
             ob_start();
             $results = $SMTP_Validator->validate(array($email), get_option('admin_email'));
             ob_clean();
             if (isset($results[$email])) {
                 // True = passed
                 if ($results[$email]) {
                     do_action('ctct_activity', 'SMTP validation passed.', $email, $results);
                     return true;
                 } else {
                     do_action('ctct_activity', 'SMTP validation failed.', $email, $results);
                     $this->errors[] = new WP_Error('smtp', __('Email validation failed.', 'ctct'), $email, $results);
                     return false;
                 }
             } else {
                 do_action('ctct_activity', 'SMTP validation did not work', 'Returned empty results. Maybe it timed out?');
                 return true;
             }
         } catch (Exception $e) {
             do_action('ctct_error', 'SMTP validation broke.', $e);
             return;
         }
     }
     return true;
 }
 function include_files()
 {
     /** Helpers */
     include_once CTCT_DIR_PATH . 'lib/cache-http.php';
     include_once CTCT_DIR_PATH . 'inc/functions.php';
     // TODO: Flesh out the help tabs
     include_once CTCT_DIR_PATH . 'inc/help.php';
     /** Classes */
     include_once CTCT_DIR_PATH . 'classes/class.ctct_process_form.php';
     include_once CTCT_DIR_PATH . 'classes/class.kwscontact.php';
     include_once CTCT_DIR_PATH . 'classes/class.kwscontactlist.php';
     include_once CTCT_DIR_PATH . 'classes/class.kwscampaign.php';
     include_once CTCT_DIR_PATH . 'classes/class.kwsajax.php';
     include_once CTCT_DIR_PATH . 'classes/class.ctct_admin_page.php';
     include_once CTCT_DIR_PATH . 'classes/class.ctct_settings.php';
     include_once CTCT_DIR_PATH . 'classes/class.ctct_admin.php';
     include_once CTCT_DIR_PATH . 'lib/kwslog.php';
     $this->log = new KWSLog('ctct', 'Constant Contact');
     /** Admin pages */
     include_once CTCT_DIR_PATH . 'admin/profile.php';
     include_once CTCT_DIR_PATH . 'admin/campaigns.php';
     include_once CTCT_DIR_PATH . 'admin/contacts.php';
     include_once CTCT_DIR_PATH . 'admin/lists.php';
     // If the plugin is not configured, don't do anything else.
     if (!is_ctct_configured()) {
         return;
     }
     /** Modules */
     include_once CTCT_DIR_PATH . 'lib/registration.php';
     include_once CTCT_DIR_PATH . 'lib/constant-analytics/constant-analytics.php';
     include_once CTCT_DIR_PATH . 'lib/comment-form-signup.php';
     include_once CTCT_DIR_PATH . 'lib/simple-widget.php';
     if (CTCT_Settings::get('eventspot')) {
         include_once CTCT_DIR_PATH . 'lib/eventspot/eventspot.php';
     }
     include_once CTCT_DIR_PATH . 'lib/form-designer/form-designer.php';
 }
 /**
  * Set the default settings. Each setting has a key value in an array and the default is the value.
  * Settings can be accessed here without necessarily being visible in get_settings(). get_settings() is only for UI
  * @filter ctct_default_settings
  * @filter ctct_settings_filter
  * @return array $settings array
  */
 private static function set_settings()
 {
     $option = get_option('ctct_settings');
     $defaults = apply_filters('ctct_default_settings', array('general' => '', 'eventspot' => true, 'logging' => array('activity'), 'register_page_method' => 'none', 'list_selection_format' => 'checkbox', 'default_opt_in' => 1, 'signup_title' => __('Receive our Newsletter', 'ctct'), 'signup_description' => __('Subscribe to the Newsletter', 'ctct'), 'default_select_option_text' => __('Select a List&hellip;', 'ctct'), 'signup_description_position' => 'before', 'comment_form_signup' => true, 'comment_form_check_text' => __('Subscribe me to your mailing list', 'ctct'), 'comment_form_subscribed_text' => __('You are currently subscribed to our mailing list', 'ctct'), 'comment_form_admin_text' => __('You are the administrator - no need to subscribe you to the mailing list', 'ctct'), 'comment_form_clear' => true, 'spam_methods' => array('akismet')));
     /**
      * When there is an array of checkboxes and none are checked,
      * the field isn't set and so it reverts to defaults. That's not ideal.
      * The sizeof() check is to get the defaults even when the license key is set.
      */
     foreach ($defaults as $k => $v) {
         if (!empty($option) && is_array($option) && sizeof($option) > 10 && is_array($v) && !isset($option[$k])) {
             $option[$k] = array();
         }
     }
     $options = apply_filters('ctct_settings_filter', wp_parse_args($option, $defaults));
     self::$options = $options;
     return $options;
 }
    function content()
    {
        ?>
		<form action="options.php" method="post">
		<?php 
        settings_fields('ctct_settings');
        CTCT_Settings::do_settings_sections('constant-contact-api');
        ?>
		</form>
	<?php 
    }