function cc_form_meta_box_formlists_select($post, $metabox = array())
{
    $form = $metabox['args'][0];
    $checked_lists = !empty($form['lists']) ? $form['lists'] : NULL;
    $output = KWSContactList::outputHTML('all', array('checked' => $checked_lists, 'type' => 'checkboxes'));
    ?>
<div class="posttypediv lists-meta-box">
	<h4 class="smallmarginbottom"><?php 
    esc_html_e('Lists', 'ctct');
    constant_contact_tip(__('Contacts will be added to the selected lists by default. You can override this selection when you configure a Form Designer widget. You can also specify different list IDs when inserting a form into content using the shortcode.', 'ctct'));
    ?>
</h4>
	<div class="tabs-panel tabs-panel-active" id="ctct-form-list-select">
		<ul class="ctct-checkboxes categorychecklist form-no-clear">
		<?php 
    echo $output;
    ?>
		</ul>
	</div>
	<h4 class="smallmarginbottom"><?php 
    esc_html_e('List Selection Format', 'ctct');
    ?>
</h4>
	<ul class="list-selection-format">
		<li><label><input type="radio" name="list_format" <?php 
    ctct_check_radio($form, 'list_format', 'checkbox');
    ?>
 /> <?php 
    esc_html_e('Checkbox List', 'ctct');
    ?>
</label></li>
		<li><label><input type="radio" name="list_format" <?php 
    ctct_check_radio($form, 'list_format', 'dropdown');
    ?>
 /> <?php 
    esc_html_e('Dropdown Field', 'ctct');
    ?>
</label></li>
		<li><label><input type="radio" name="list_format" <?php 
    ctct_check_radio($form, 'list_format', 'hidden', true);
    ?>
 /> <?php 
    esc_html_e('Hidden', 'ctct');
    ?>
</label></li>
	</ul>

	<h4 class="smallmarginbottom"><?php 
    esc_html_e('Checked by default?', 'ctct');
    ?>
</h4>
	<label for="checked_by_default" class="checkbox toggle_comment_form">
		<input name="checked_by_default" id="checked_by_default" type="checkbox" value="true" checked="checked" style="margin-right:.25em;" /><?php 
    esc_html_e('Should the list checkboxes be checked by default?', 'ctct');
    ?>
	</label>

</div>
<?php 
}
    /**
     * 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;
    }
 function processAjax()
 {
     global $wpdb;
     // this is how you get access to the database
     // Remove the cache for this whole joint
     add_filter('ctct_cache', '__return_false');
     $id = (int) @$_REQUEST['id'];
     $component = esc_html(@$_REQUEST['component']);
     $field = esc_attr(@$_REQUEST['field']);
     $value = @$_REQUEST['value'];
     $value = is_array($value) ? $value : esc_attr($value);
     $parent = esc_attr(@$_REQUEST['parent']);
     $parent = !empty($parent) ? $parent . '_' : NULL;
     if (!isset($_REQUEST['_wpnonce']) || isset($_REQUEST['_wpnonce']) && !wp_verify_nonce($_REQUEST['_wpnonce'], 'ctct') && !defined('DOING_AJAX')) {
         $response['errors'] = __('You\'re not authorized to be here.', 'ctct');
     } elseif (empty($field)) {
         $response['errors'] = __('There is no field defined.', 'ctct');
     } elseif (!isset($_REQUEST['value'])) {
         $response['errors'] = __('There is no value defined.', 'ctct');
     } else {
         $KWSConstantContact = new KWSConstantContact();
         switch ($component) {
             case 'Contact':
                 try {
                     $KWSContact = new KWSContact($KWSConstantContact->getContact(CTCT_ACCESS_TOKEN, $id));
                     // Did anything change?
                     // Check unformattet, then formatted.
                     $nothingChanged = $value === $KWSContact->get($parent . $field) || $value === $KWSContact->get($parent . $field, true);
                     // Lists need to be handled slightly differently.
                     if ($parent . $field === 'lists') {
                         // Get the lists for the contact
                         $existingLists = $KWSContact->get($parent . $field, true);
                         $items = $value;
                         $value = array();
                         foreach ($items as $key => $item) {
                             $value[] = new KWSContactList(array('id' => $item['value']));
                             $compareLists[] = $item['value'];
                         }
                         // If nothing changed, the arrays should be the same
                         // and the diff should be empty
                         $diff = kws_array_diff($existingLists, $compareLists);
                         $nothingChanged = empty($diff);
                     }
                     if ($nothingChanged) {
                         $response['message'] = __('Nothing changed.', 'ctct');
                         $response['code'] = 204;
                     } else {
                         $updatable = $KWSContact->set($parent . $field, $value);
                         if (!$updatable) {
                             $response['message'] = __('This field is not updatable.', 'ctct');
                             $response['code'] = 400;
                         } else {
                             $fetch = $KWSConstantContact->updateContact(CTCT_ACCESS_TOKEN, $KWSContact);
                             $response['message'] = __('Successfully updated.', 'ctct');
                             $response['code'] = 200;
                             delete_transient('ctct_all_contacts');
                             /**
                              * Set this so that next time the user refreshes the contact page,
                              * CTCT_Admin_Contacts::single() will catch it and force refresh.
                              *
                              * @see CTCT_Admin_Contacts::single()
                              */
                             add_option('ctct_refresh_contact_' . $KWSContact->get('id'), 1);
                         }
                     }
                 } catch (Exception $e) {
                     $response['message'] = $e->getErrors();
                     $response['code'] = 400;
                 }
                 break;
             case 'ContactList':
                 try {
                     $KWSList = new KWSContactList($KWSConstantContact->getList(CTCT_ACCESS_TOKEN, $id));
                     if ($value === $KWSList->get($field)) {
                         $response['message'] = __('Nothing changed.', 'ctct');
                         $response['code'] = 204;
                     } else {
                         $updatable = $KWSList->set($field, $value);
                         if (!$updatable) {
                             $response['message'] = __('This field is not updatable.', 'ctct');
                             $response['code'] = 400;
                         } else {
                             $fetch = $KWSConstantContact->updateList(CTCT_ACCESS_TOKEN, $KWSList);
                             $response['message'] = __('Successfully updated.', 'ctct');
                             $response['code'] = 200;
                             delete_transient('ctct_all_lists');
                         }
                     }
                 } catch (Exception $e) {
                     $response['message'] = $e->getErrors();
                     $response['code'] = 400;
                 }
                 break;
             default:
                 $response['message'] = __('There is no component defined.', 'ctct');
                 $response['code'] = 400;
                 break;
         }
     }
     wp_die(json_encode($response));
 }
    /** @see WP_Widget->form */
    function form($instance)
    {
        extract($instance);
        ?>
			<h2><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Widget Title:', 'ctct');
        ?>
</label></h2>
			<p>
			<input type="text" class="widefat" id="<?php 
        echo esc_attr($this->get_field_id('title'));
        ?>
" name="<?php 
        echo esc_attr($this->get_field_name('title'));
        ?>
" value="<?php 
        if (!empty($title)) {
            echo esc_attr($title);
        } else {
            echo __('Newsletter', 'ctct');
        }
        ?>
" /></p>

			<h2><label for="<?php 
        echo $this->get_field_id('list');
        ?>
"><?php 
        _e('Newsletter List:', 'ctct');
        ?>
</label></h2>
			<span class="description" style="font-style:normal;"><?php 
        _e('Users will be subscribed to the following lists when submitted.', 'ctct');
        ?>
</span>
			<p>
<?php 
        $lists = array('' => __('Select a list...', 'ctct'));
        $lists = $this->cc->getAllLists();
        #IDX_Plus::r($lists);
        if (!$lists) {
            echo '<div class="error"><p>' . __('Unable to load lists() from Constant Contact.', 'ctct') . '</p></div>';
        } else {
            $listHTML = KWSContactList::outputHTML($lists, array('type' => 'checkboxes', 'format' => '%%name%%', 'name_attr' => $this->get_field_name('lists'), 'id_attr' => $this->get_field_id('ctct-%%id%%'), 'checked' => $instance['lists']));
            echo $listHTML;
        }
    }
</th>
    </thead>
    <tbody>
        <?php 
$alt = '';
$html = '';
foreach ($Contact as $key => $value) {
    $alt = empty($alt) ? ' class="alt"' : '';
    #if(!$Contact->is_editable($key)) { continue; }
    $html .= '<tr' . $alt . '>';
    $html .= sprintf('<th scope="row" valign="top" class="column-name">%s</th>', $Contact->getLabel($key));
    $html .= '<td>';
    if (is_array($value)) {
        switch ($key) {
            case 'lists':
                $html .= KWSContactList::outputHTML('all', array('type' => 'checkboxes', 'checked' => $Contact->get('lists', true)));
                break;
            case 'addresses':
                if ($personal = $Contact->get('personal_address', true)) {
                    $html .= sprintf('<h3>%s</h3> <div>%s</div>', __('Personal Address', 'ctct'), $personal);
                }
                if ($business = $Contact->get('business_address', true)) {
                    $html .= sprintf('<h3>%s</h3> <div>%s</div>', __('Business Address', 'ctct'), $business);
                }
                break;
            case 'email_addresses':
                $html .= sprintf('<span class="editable" data-name="' . $key . '">%s</span>', $Contact->get('email_address'));
                break;
            case 'notes':
                // Constant Contact got rid of Notes for now.
                $html .= $Contact->is_editable($key) ? sprintf('<span class="editable" data-name="' . $key . '">%s</span>', $Contact->get('notes')) : $Contact->get('notes');
    /**
     * HTML Signup form to be used in widget and shortcode
     *
     * Based on original widget code but broken out to be used in shortcode and
     * any other place where non-logged-in users will be signing up.
     *
     * Modify the output by calling `add_filter('constant_contact_form', 'your_function');`
     *
     * @param array|string $passed_args Settings for generating the signup form
     * @param boolean $echo True: Echo the form; False: return form output.
     * @return string Form HTML output
     */
    static function signup_form($passed_args, $echo = true)
    {
        do_action('ctct_debug', 'constant_contact_public_signup_form', $passed_args, @$_POST);
        $output = $error_output = $success = $process_class = $hiddenlistoutput = '';
        $default_args = array('before' => null, 'after' => null, 'formid' => 0, 'redirect_url' => false, 'lists' => array(), 'title' => '', 'exclude_lists' => array(), 'description' => '', 'show_list_selection' => false, 'list_selection_title' => __('Add me to these lists:', 'ctct'), 'list_selection_format' => NULL, 'list_format' => NULL, 'widget' => false);
        $settings = shortcode_atts($default_args, $passed_args);
        /**
         * This unique id will be used to differentiate from other forms on the same page.
         * It will also be used to store cached forms.
         *
         * Only get the first 10 characters, since that's all we really need.
         * @var string
         */
        $unique_id = substr(sha1(maybe_serialize($settings)), 0, 10);
        $form = CTCT_Form_Designer_Helper::get_form($settings['formid']);
        // Merge using the form settings
        $settings = shortcode_atts($settings, $form);
        // Override one more time using the passed args as the final
        $settings = shortcode_atts($settings, $passed_args);
        // BACKWARD COMPATIBILITY
        $settings['list_selection_format'] = empty($settings['list_selection_format']) ? $settings['list_format'] : $settings['list_selection_format'];
        extract($settings, EXTR_SKIP);
        // The form does not exist.
        if (!$form) {
            do_action('ctct_log', sprintf('Form #%s does not exist. Called on %s', $formid, esc_url(add_query_arg(array()))));
            if (current_user_can('manage_options')) {
                return '<!-- Constant Contact API Error: Form #' . $formid . ' does not exist. -->';
            }
            return false;
        }
        // If other lists aren't passed to the function,
        // use the default lists defined in the form designer.
        if (empty($lists) && !empty($form['lists'])) {
            $lists = $form['lists'];
        }
        $selected = $lists;
        if ($widget) {
            $lists = isset($form['lists']) ? $form['lists'] : null;
            $show_list_selection = !empty($form['formfields']) && is_array($form['formfields']) ? in_array('lists', $form['formfields']) : null;
            $list_selection_format = @$form['list_format'];
            $selected = isset($form['checked_by_default']) ? $form['checked_by_default'] : false;
        }
        /**
         * Make it possible to call using shortcode comma separated values. eg: lists=1,2,3
         */
        if (is_string($lists)) {
            $lists = explode(',', $lists);
        }
        // The form is retrieved from constant_contact_retrieve_form()
        // and then the variables are replaced further down the function.
        if ($formid !== '' && function_exists('constant_contact_retrieve_form')) {
            $force = isset($_REQUEST['cache']) || isset($_REQUEST['uniqueformid']) && $_REQUEST['uniqueformid'] === $unique_id ? true : false;
            $form = constant_contact_retrieve_form($formid, $force, $unique_id, $lists);
        } elseif (!function_exists('constant_contact_retrieve_form') && current_user_can('manage_options')) {
            echo '<!-- Constant Contact API Error: `constant_contact_retrieve_form` function does not exist. -->';
        }
        // If the form returns an error, we want to get out of here!
        if (empty($form) || is_wp_error($form)) {
            if (is_wp_error($form)) {
                do_action('ctct_debug', 'Form is empty or WP_Error', $form);
            }
            return false;
        }
        // Modify lists with this filter
        $lists = apply_filters('constant_contact_form_designer_lists', apply_filters('constant_contact_form_designer_lists_' . $formid, $lists));
        /**
         * Display errors or Success message if the form was submitted.
         */
        $ProcessForm = CTCT_Process_Form::getInstance();
        $errors = $ProcessForm->getErrors();
        $success = '';
        /**
         * Success message: If no errors AND signup was successful show the success message
         */
        if (!empty($errors)) {
            $process_class = ' has_errors';
            $error_output = '';
            do_action('ctct_debug', 'Handling errors in constant_contact_public_signup_form', $errors);
            // Set up error display
            $error_output .= '<div id="constant-contact-signup-errors" class="error">';
            $error_output .= '<ul>';
            foreach ($errors as $error) {
                $error_data = $error->get_error_data();
                $error_label_for = '';
                // We only want simple error data that we can output here. Akismet triggers an array instead of a string.
                if (is_string($error_data)) {
                    /**
                     * The input ID is stored in the WP_Error error data.
                     * @see CTCT_Process_Form::checkRequired()
                     */
                    $error_field_id = CTCT_Form_Designer_Output::get_field_id($ProcessForm->id(), $error_data);
                    $error_label_for = ' for="' . esc_attr($error_field_id) . '"';
                }
                $error_output .= '<li><label' . $error_label_for . '>' . $error->get_error_message() . '</label></li>';
            }
            $error_output .= '</ul>';
            $error_output .= '</div>';
            // Filter output so text can be modified by plugins/themes
            $error_output = apply_filters('constant_contact_form_errors', $error_output);
        } elseif (is_a($ProcessForm->getResults(), 'Ctct\\Components\\Contacts\\Contact')) {
            $process_class = ' has_success';
            $success = '<p class="success cc_success">';
            $success .= esc_html__('Success, you have been subscribed.', 'ctct');
            $success .= '</p>';
            $success = apply_filters('constant_contact_form_success', $success);
            // Force refresh of the form
        }
        $form = str_replace('<!-- %%SUCCESS%% -->', $success, $form);
        $form = str_replace('<!-- %%ERRORS%% -->', $error_output, $form);
        $form = str_replace('<!-- %%PROCESSED_CLASS%% -->', $process_class, $form);
        // Generate the current page url, removing the success _GET query arg if it exists
        $current_page_url = remove_query_arg('success', CTCT_Form_Designer_Helper::current_page_url());
        $form = str_replace('<!-- %%ACTION%% -->', $current_page_url, $form);
        if (strpos($form, '%%LISTSELECTION%%') > 0) {
            $listsOutput = '';
            // If lists are submitted, use those.
            // Otherwise, consider all/no lists selected based on `$selected` setting.
            $selected = !empty($_POST['lists']) ? (array) $_POST['lists'] : (bool) $selected;
            // Remove the cache for this whole joint
            $listsOutput = KWSContactList::outputHTML($lists, array('fill' => true, 'id_attr' => $unique_id . '-%%id%%', 'showhidden' => false, 'checked' => $selected, 'type' => $list_selection_format ? $list_selection_format : 'hidden'));
            // If you're showing list selection, show the label and wrap it in a container.
            $listsOutput = '<div class="cc_newsletter input-text-wrap cc-input-type-' . esc_attr($list_selection_format) . '">
                ' . $listsOutput . '
            </div>';
            $form = str_replace('<!-- %%LISTSELECTION%% -->', $listsOutput, $form);
        }
        /**
         * Finish form output including a hidden field for referrer and submit button
         */
        $hiddenoutput = '
	        <div>
	            <input type="hidden" id="cc_redirect_url" name="cc_redirect_url" value="' . urlencode($redirect_url) . '" />
	            <input type="hidden" id="cc_referral_url" name="cc_referral_url" value="' . urlencode($current_page_url) . '" />
	            <input type="hidden" name="cc_referral_post_id" value="' . get_the_ID() . '" />
	            <input type="hidden" name="uniqueformid" value="' . $unique_id . '" />
	            <input type="hidden" name="ccformid" value="' . $formid . '" />
	        </div>';
        $form = str_replace('<!-- %%HIDDEN%% -->', $hiddenoutput, $form);
        // All remaining tags should be removed.
        $form = preg_replace('/\\%\\%(.*?)\\%\\%/ism', '', $form);
        $output = apply_filters('constant_contact_form', apply_filters('constant_contact_form_' . $formid, $form));
        do_action('ctct_debug', 'form output', $output);
        /**
         * Echo the output if $settings['echo'] is true
         */
        if ($echo) {
            echo $output;
        }
        /**
         * And always return the $output
         */
        return $output;
    }
 /**
  * Convert an array of List objects into HTML output
  *
  * @param  array $passed_items List array
  * @param  array $atts Settings; `fill`, `selected`, `format`; `format` should use replacement tags with the tag being the name of the var of the List object you want to replace. For example, `%%name%% (%%contact_count%% Contacts)` will return an item with the content "List Name (140 Contacts)"
  *
  * `showhidden` If true, will exclude lists that have a status of "hidden" in http://dotcms.constantcontact.com/docs/contact-list-api/contactlist-collection.html
  *
  * @return [type]        [description]
  */
 static function outputHTML($passed_items = array(), $atts = array())
 {
     $settings = wp_parse_args($atts, array('type' => 'checkboxes', 'fill' => true, 'format' => '<span>%%name%%</span>', 'id_attr' => 'ctct-%%id%%', 'name_attr' => 'lists', 'checked' => array(), 'include' => array(), 'showhidden' => true, 'class' => '', 'blank' => ''));
     extract($settings);
     $items = array();
     // Tell the cache that if the current requests are forced to be
     // refreshed, the cache should also reset this key.
     // See Cache_WP_HTTP
     add_filter('flush_key', function () {
         return 'ctct_all_lists';
     });
     if ($passed_items === 'all') {
         $items = WP_CTCT::getInstance()->cc->getAllLists();
     } elseif (!empty($passed_items) && is_array($passed_items)) {
         foreach ($passed_items as $item) {
             global $list_id;
             if ($fill) {
                 $list_id = is_object($item) ? $item->id : $item;
                 $list_id = esc_attr($list_id);
                 // Tell Cache_WP_HTTP to use the following key
                 // as the transient name
                 add_filter('ctct_cachekey', function () {
                     global $list_id;
                     return 'ctct_list_' . $list_id;
                 });
                 $item = WP_CTCT::getInstance()->cc->getList(CTCT_ACCESS_TOKEN, $list_id);
             }
             $items[] = $item;
         }
     }
     $before = $before_item = $after_item = $after = '';
     switch ($type) {
         case 'hidden':
             $format = '<input type="hidden" value="%%id%%" name="%%name_attr%%[]" />';
             break;
         case 'ul':
             $before = '<ul class="ul-square">';
             $before_item = '<li>';
             $after_item = '</li>';
             $after = '</ul>';
             break;
         case 'dropdown':
         case 'select':
         case 'multiselect':
             $multiple = '';
             // Even though the multiselect option is no longer available
             // in the settings, keep this around for backward compatibility.
             // And if crazy people want multi-selects
             if ($type === 'select' || $type === 'multiselect') {
                 $multiple = ' multiple="multiple"';
             }
             $before = '<select name="%%name_attr%%"' . $multiple . ' class="select2 ctct-lists">';
             $before_item = '<option value="%%id%%">';
             $after_item = '</option>';
             $after = '</select>';
             // Allow passing a blank item title
             if (!empty($blank)) {
                 $before .= '<option value="">' . esc_html($blank) . '</option>';
             }
             break;
         case 'checkbox':
         case 'checkboxes':
             $before = '<ul class="ctct-lists ctct-checkboxes ' . esc_attr($class) . '">';
             $before_item = '<li><label for="%%id_attr%%"><input type="checkbox" id="%%id_attr%%" value="%%id%%" name="%%name_attr%%[]" %%checked%% /> ';
             $after_item = '</label></li>';
             $after = '</ul>';
             break;
     }
     $output = $before;
     $items_output = '';
     foreach ($items as &$item) {
         // If include was specified, then we need to skip lists not included
         if (is_array($passed_items) && (!empty($include) && !in_array($item->id, $include)) || $item->status === 'HIDDEN' && !$showhidden) {
             #continue;
         }
         $item = new KWSContactList($item);
         $item_content = !empty($format) || is_null($format) ? $format : $item->name;
         $tmp_output = $before_item . $item_content . $after_item . "\n";
         $tmp_output = str_replace('%%id%%', sanitize_title($item->get('id')), $tmp_output);
         $tmp_output = str_replace('%%name%%', $item->get('name', false), $tmp_output);
         $tmp_output = str_replace('%%status%%', $item->get('status', false), $tmp_output);
         $tmp_output = str_replace('%%contact_count%%', $item->get('contact_count', true), $tmp_output);
         $tmp_output = str_replace('%%checked%%', checked(in_array($item->get('id'), (array) $checked) || is_null($checked) && $item->get('status') === 'ACTIVE', true, false), $tmp_output);
         $items_output .= $tmp_output;
     }
     $output .= $items_output;
     $output .= $after;
     $output = str_replace('%%name_attr%%', $name_attr, $output);
     $output = str_replace('%%id_attr%%', $id_attr, $output);
     return $output;
 }
    <tbody>
        <?php 
$alt = '';
$html = '';
foreach ($Campaign as $key => $value) {
    if (empty($value)) {
        continue;
    }
    $alt = empty($alt) ? ' class="alt"' : '';
    $html .= '<tr' . $alt . '>';
    if (is_array($value)) {
        switch ($key) {
            case 'sent_to_contact_lists':
            case 'lists':
                $html .= sprintf('<th scope="row" valign="top" class="column-name">%s</th>
                        <td>%s</td>', $Campaign->getLabel($key), KWSContactList::outputHTML($Campaign->get($key), array('type' => 'ul')));
                break;
            case 'click_through_details':
                $clickThroughOutput = '';
                if (!empty($value)) {
                    $clickThroughOutput = '<ul class="ul-disc">';
                    foreach ((array) $value as $click) {
                        $clickThroughOutput .= '<li>';
                        $clickThroughOutput .= '<a class="block" href="' . $click->url . '">' . $click->url . '</a>';
                        $clickThroughOutput .= '<strong>' . sprintf('%d %s', $click->click_count, _n(__('Click', 'ctct'), __('Clicks', 'ctct'), $click->click_count)) . '</strong>';
                        $clickThroughOutput .= '</li>';
                    }
                    $clickThroughOutput .= '</ul>';
                }
                $html .= sprintf('<th scope="row" valign="top" class="column-name">%s</th>
                        <td>%s</td>', $Campaign->getLabel($key), $clickThroughOutput);
    /**
     * 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 
    }
</th>
			<th scope="col" class="count manage-column column-name"><?php 
_e('Contact Count', 'ctct');
?>
</th>
			<th scope="col" class="view manage-column column-name"><?php 
_e('View List Contacts', 'ctct');
?>
</th>
		</tr>
	</thead>
	<tbody>

<?php 
foreach ((array) $Lists as $List) {
    $List = new KWSContactList($List);
    $alt = empty($alt) ? 'class="alt"' : '';
    ?>
		<tr <?php 
    echo $alt;
    ?>
>
			<td class="column-id">
				<?php 
    echo $List->get('id');
    ?>
			</td>
			<td class="column-name">
				<?php 
    echo $List->get('name', true);
    ?>
    /**
     * Generate the settings page layout and settings fields
     *
     * @filter CTCT_Settings_array
     * @action CTCT_Settings_sections
     * @uses register_setting()
     * @uses add_settings_section()
     * @uses add_settings_field()
     * @return array Array of settings to be shown in the admin.
     */
    function settings_init()
    {
        global $plugin_page;
        register_setting('ctct_settings', 'ctct_settings');
        if ($plugin_page !== 'constant-contact-api') {
            return;
        }
        // We don't need this yet unless it's configured.
        if (!$this->cc->isConfigured()) {
            return;
        }
        add_settings_section('setup', '<i class="dashicons dashicons-admin-settings"></i> ' . __('Setup', 'ctct'), '', 'constant-contact-api');
        // Hook in here for more tabs.
        do_action('ctct_settings_sections');
        add_settings_section('registration', '<i class="dashicons dashicons-forms"></i> ' . __('Registration Form', 'ctct'), '<h3>' . esc_html__('Configure how users sign up.', 'ctct') . '</h3>', 'constant-contact-api');
        add_settings_section('comments', '<i class="dashicons dashicons-admin-comments
"></i> ' . __('Comment Form', 'ctct'), '<h3>' . esc_html__('Configure how users sign up.', 'ctct') . '</h3>', 'constant-contact-api');
        add_settings_section('spam', '<i class="dashicons dashicons-trash"></i> ' . __('Spam Prevention', 'ctct'), '<h3>' . esc_html__('How do you want to prevent spam?', 'ctct') . '</h3>', 'constant-contact-api');
        $groups = array('setup' => array(array('type' => 'html', 'content' => kws_ob_include(CTCT_DIR_PATH . 'views/admin/view.setup.php', $this)), array('id' => 'eventspot', 'type' => 'checkbox', 'desc' => __('Enable EventSpot Integration', 'ctct'), 'label' => __('Enable integration with Constant Contact Events (EventSpot)?', 'ctct')), array('type' => 'checkboxes', 'id' => 'logging', 'options' => array('activity' => __('Log Constant Contact Activity', 'ctct'), 'error' => __('Log Errors & Exceptions', 'ctct'), 'debug' => __('Detailed Debugging Logs (Do not leave enabled! Server-intensive.)', 'ctct')), 'desc' => __('Activity Logs', 'ctct'), 'label' => __('Log different activity from the plugin, including form submissions and the results ("Constant Contact Activity").', 'ctct'))), 'registration' => array(array('type' => 'heading', 'desc' => __('WordPress Registration Form', 'ctct'), 'label' => sprintf(__('Add signup options to WordPress\' <a href="%s" rel="external">registration form.</a>', 'ctct'), site_url('wp-login.php?action=register'))), array('type' => 'radio', 'id' => 'register_page_method', 'options' => array('none' => __('Disabled', 'ctct'), 'checkbox' => __('Single Checkbox - show users a checkbox which, if ticked, will automatically subscribe them to the lists you select below in the "Active Contact Lists" section.', 'ctct'), 'checkboxes' => __('List of Checkboxes - show a bullet list with the name of the list and a checkbox option for them to sign up', 'ctct'), 'dropdown' => __('Dropdown List', 'ctct')), 'toggle' => 'registration', 'desc' => __('User Subscription Method', 'ctct')), array('id' => 'default_opt_in', 'togglegroup' => 'registration_checkbox registration_checkboxes', 'type' => 'checkbox', 'desc' => __('Opt-in users by default?', 'ctct'), 'label' => __('Should the opt-in checkbox(es) be checked by default? If using the "List Selection" method, should lists be pre-selected by default.', 'ctct')), array('type' => 'lists', 'id' => 'registration_checkbox_lists', 'togglegroup' => 'registration_checkbox', 'desc' => __('Lists for Registration', 'ctct'), 'label' => __('<strong>Checkbox:</strong> What lists will users be added to when checking the opt-in box?<br />Others: What lists will users be presented with?', 'ctct'), 'options' => KWSContactList::outputHTML('all', array('type' => 'checkboxes', 'format' => '%%name%%', 'name_attr' => 'ctct_settings[registration_checkbox_lists]', 'id_attr' => 'constant-contact-api_registration_checkbox_lists_%%id%%', 'checked' => self::get('registration_checkbox_lists'), 'class' => 'toggle_registration_checkbox toggle_registration_checkboxes toggle_registration_dropdown')), 'help' => __('When users sign up for your newsletter while registering for a WordPress account, they will be added to the following lists.', 'ctct')), array('id' => 'signup_description', 'togglegroup' => 'registration_checkbox registration_checkboxes registration_dropdown', 'type' => 'textarea', 'desc' => __('Signup Description', 'ctct'), 'label' => __('Signup form description text displayed on the registration screen and user profile setting, if enabled. HTML is allowed. Paragraphs will be added automatically like in posts.', 'ctct')), array('type' => 'radio', 'togglegroup' => 'registration_checkbox registration_checkboxes registration_dropdown', 'id' => 'signup_description_position', 'options' => array('before' => __('Before the Opt-in', 'ctct'), 'after' => __('After the Opt-in', 'ctct')), 'desc' => __('Signup Description Position', 'ctct')), array('id' => 'signup_title', 'togglegroup' => 'registration_checkbox registration_checkboxes registration_dropdown', 'type' => 'text', 'desc' => __('Signup Title', 'ctct'), 'label' => __('Title for the signup form displayed on the registration screen and user profile settings if enabled.', 'ctct')), array('type' => 'text', 'togglegroup' => 'registration_dropdown', 'id' => 'default_select_option_text', 'desc' => __('Default Option Text', 'ctct'), 'label' => __('If "Opt-in users by default" (below) is not checked, this will be the default option in the dropdown menu. Leave blank to not show this option.', 'ctct')), array('type' => 'heading', 'desc' => __('Profile Page', 'ctct')), array('type' => 'checkbox', 'id' => 'profile_page_form', 'label' => __('Allow users to modify their subscription on their WordPress profile page', 'ctct'), 'desc' => __('Show Form on Profile Page?', 'ctct'), 'help' => __('Do you want users to be able to update their subscriptions inside WordPress?', 'ctct'))), 'comments' => array(array('type' => 'heading', 'desc' => __('Comment Form', 'ctct')), array('type' => 'checkbox', 'id' => 'comment_form_signup', 'label' => __('Add a checkbox for subscribing to a newsletter below a comment form', 'ctct'), 'toggle' => 'comment_form', 'desc' => __('Comment Form Signup', 'ctct')), array('togglegroup' => 'comment_form', 'type' => 'checkbox', 'id' => 'comment_form_default', 'desc' => __('Checked by default?', 'ctct'), 'label' => __('Should the checkbox be checked by default?', 'ctct')), array('type' => 'lists', 'id' => 'comment_form_lists', 'togglegroup' => 'comment_form', 'desc' => __('Lists for Comment Form', 'ctct'), 'label' => __('What lists will users be added to when signing up with the Comment Form?', 'ctct'), 'options' => KWSContactList::outputHTML('all', array('type' => 'checkboxes', 'format' => '%%name%%', 'name_attr' => 'ctct_settings[comment_form_lists]', 'id_attr' => 'constant-contact-api_comment_form_lists_%%id%%', 'class' => 'toggle_comment_form', 'checked' => self::get('comment_form_lists')))), array('togglegroup' => 'comment_form', 'type' => 'text', 'id' => 'comment_form_check_text', 'desc' => __('Subscribe Message', 'ctct')), array('togglegroup' => 'comment_form', 'type' => 'text', 'id' => 'comment_form_subscribed_text', 'desc' => __('Already Subscribed Message', 'ctct')), array('togglegroup' => 'comment_form', 'type' => 'checkbox', 'id' => 'comment_form_clear', 'label' => __('Uncheck if this causes layout issues', 'ctct'), 'desc' => __('Add a CSS \'clear\' to the checkbox?', 'ctct'))), 'spam' => array(array('type' => 'checkboxes', 'id' => 'spam_methods', 'toggle' => 'spam_methods', 'options' => array('datavalidation' => __('Verify Email Addresses with <a href="http://katz.si/datavalidation" rel="external">DataValidation.com</a>', 'ctct') . constant_contact_tip(__('DataValidation.com is the best way to verify that when users submit a form, the submitted email address is valid.', 'ctct'), false), 'akismet' => __('Akismet', 'ctct') . self::get_plugin_status_message('akismet'), 'wangguard' => __('WangGuard WordPress Plugin', 'ctct') . self::get_plugin_status_message('wangguard'), 'smtp' => __('Validate Email Addresses Via SMTP (<a href="http://katz.si/smtpvalidation" rel="external">See the project</a>)', 'ctct') . constant_contact_tip(__('Uses server methods to verify emails: checks for a valid domain, then sends a request for a read receipt.', 'ctct'), false)), 'desc' => __('What services do you want to use to prevent spam submissions of your forms?', 'ctct')), array('type' => 'heading', 'togglegroup' => 'spam_methods_datavalidation', 'desc' => __('DataValidation.com Settings', 'ctct')), array('type' => 'text', 'togglegroup' => 'spam_methods_datavalidation', 'id' => 'datavalidation_api_key', 'desc' => __('DataValidation.com: API Key', 'ctct'), 'label' => sprintf(__('Enter your DataValidation.com API key. %sSign up for a key here%s.', 'ctct'), '<a href="https://developer.datavalidation.com" rel="external">', '</a>')), array('type' => 'checkbox', 'togglegroup' => 'spam_methods_datavalidation', 'id' => 'datavalidation_prevent_ambiguous', 'desc' => __('DataValidation.com: Should "ambiguous" responses be blocked?', 'ctct'), 'label' => __('Ambiguous Responses basically mean that the email looks good, it has valid DNS, it has a valid MX record, it even has an email server, but for a myriad of reasons it does not accept any connections to it. Could be connection refused, could be the server is down, etc.', 'ctct'))), 'forms' => array(array('type' => 'checkboxes', 'id' => 'forms', 'options' => array('formstack' => __('<a href="http://www.formstack.com/r/31575458">Formstack</a>', 'ctct'), 'after' => __('After the Opt-in', 'ctct')), 'desc' => __('Forms', 'ctct'))));
        $groups = apply_filters('ctct_settings_array', $groups);
        $i = 0;
        if (empty($groups)) {
            return;
        }
        foreach ($groups as $group => $settings) {
            foreach ($settings as $setting) {
                $i++;
                $setting['page'] = isset($setting['page']) ? $setting['page'] : 'constant-contact-api';
                $setting['callback'] = isset($setting['callback']) ? $setting['callback'] : array('CTCT_Settings', 'setting_input_generator');
                $setting['desc'] = isset($setting['desc']) ? $setting['desc'] : '';
                if (isset($setting['type']) && $setting['type'] === 'heading') {
                    $setting['id'] = sanitize_title($setting['desc']);
                }
                $setting['id'] = isset($setting['id']) ? $setting['id'] : '';
                extract($setting);
                unset($setting['callback']);
                add_settings_field($id, $desc, $callback, $page, $group, $setting);
            }
        }
    }