static function data()
 {
     $transient_key = 'sendpress_tracking_cache';
     $data = get_transient($transient_key);
     // bail if transient is set and valid
     if ($data !== false) {
         return;
     }
     // Make sure to only send tracking data once a week
     set_transient($transient_key, 1, WEEK_IN_SECONDS);
     // Start of Metrics
     global $blog_id, $wpdb;
     $hash = get_option('SendPress_Tracking_Hash', false);
     if (!$hash || empty($hash)) {
         // create and store hash
         $hash = md5(site_url());
         update_option('SendPress_Tracking_Hash', $hash);
     }
     $pts = array();
     $post_types = get_post_types(array('public' => true));
     if (is_array($post_types) && $post_types !== array()) {
         foreach ($post_types as $post_type) {
             $count = wp_count_posts($post_type);
             $pts[$post_type] = $count->publish;
         }
     }
     unset($post_types);
     $comments_count = wp_count_comments();
     $theme_data = wp_get_theme();
     $theme = array('name' => $theme_data->display('Name', false, false), 'theme_uri' => $theme_data->display('ThemeURI', false, false), 'version' => $theme_data->display('Version', false, false), 'author' => $theme_data->display('Author', false, false), 'author_uri' => $theme_data->display('AuthorURI', false, false));
     $theme_template = $theme_data->get_template();
     if ($theme_template !== '' && $theme_data->parent()) {
         $theme['template'] = array('version' => $theme_data->parent()->display('Version', false, false), 'name' => $theme_data->parent()->display('Name', false, false), 'theme_uri' => $theme_data->parent()->display('ThemeURI', false, false), 'author' => $theme_data->parent()->display('Author', false, false), 'author_uri' => $theme_data->parent()->display('AuthorURI', false, false));
     } else {
         $theme['template'] = '';
     }
     unset($theme_template);
     $plugins = array();
     $active_plugin = get_option('active_plugins');
     foreach ($active_plugin as $plugin_path) {
         if (!function_exists('get_plugin_data')) {
             require_once ABSPATH . 'wp-admin/includes/plugin.php';
         }
         $plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
         $slug = str_replace('/' . basename($plugin_path), '', $plugin_path);
         $plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']);
     }
     unset($active_plugins, $plugin_path);
     $lists = SendPress_Data::get_lists();
     $data = array('site' => array('hash' => $hash, 'wp_version' => get_bloginfo('version'), 'sp' => SENDPRESS_VERSION, 'pro' => defined('SENDPRESS_PRO_VERSION') ? SENDPRESS_PRO_VERSION : 0, 'lists' => count($lists->posts), 'subscribers' => SendPress_Data::get_total_subscribers(), 'multisite' => is_multisite(), 'lang' => get_locale()), 'pts' => $pts, 'options' => apply_filters('sp_tracking_filters', array()), 'theme' => $theme, 'plugins' => $plugins);
     $args = array('body' => $data, 'blocking' => false, 'sslverify' => false);
     wp_remote_post('http://api.sendpress.com/api/v1/track/add', $args);
 }
    /**
     * Displays the widget settings controls on the widget panel.
     * Make use of the get_field_id() and get_field_name() function
     * when creating your form elements. This handles the confusing stuff.
     */
    function form($instance)
    {
        /* Set up some default widget settings. */
        $defaults = array('title' => '', 'show_first' => false, 'show_last' => false, 'lists_checked' => true, 'label_display' => 0, 'first_label' => __('First Name', 'sendpress'), 'last_label' => __('Last Name', 'sendpress'), 'email_label' => __('E-Mail', 'sendpress'), 'list_label' => __('List Selection', 'sendpress'), 'desc' => '', 'redirect_page' => false, 'button_text' => __('Submit', 'sendpress'), 'thank_you' => __('Check your inbox now to confirm your subscription.', 'sendpress'));
        $lists = SendPress_Data::get_lists(array('meta_query' => array(array('key' => 'public', 'value' => true))), false);
        $listids = array();
        foreach ($lists as $list) {
            $defaults['list_' . $list->ID] = false;
        }
        $instance = wp_parse_args((array) $instance, $defaults);
        ?>


		<!-- Widget Title: Text Input -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo $instance['title'];
        ?>
" style="width:100%;" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('desc');
        ?>
"><?php 
        _e('Description:', 'sendpress');
        ?>
</label>
			<textarea rows="5" type="text" class="widefat" id="<?php 
        echo $this->get_field_id('desc');
        ?>
" name="<?php 
        echo $this->get_field_name('desc');
        ?>
"><?php 
        echo $instance['desc'];
        ?>
</textarea>
			<!-- <input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('desc');
        ?>
" name="<?php 
        echo $this->get_field_name('desc');
        ?>
" value="<?php 
        echo $instance['desc'];
        ?>
" style="width:100%;" /> -->
		</p>

		<p>
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['show_first'], 'on');
        ?>
 id="<?php 
        echo $this->get_field_id('show_first');
        ?>
" name="<?php 
        echo $this->get_field_name('show_first');
        ?>
" /> 
			<label for="<?php 
        echo $this->get_field_id('show_first');
        ?>
"><?php 
        _e('Collect First Name', 'sendpress');
        ?>
</label>
		</p> 

		<p>
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['show_last'], 'on');
        ?>
 id="<?php 
        echo $this->get_field_id('show_last');
        ?>
" name="<?php 
        echo $this->get_field_name('show_last');
        ?>
" /> 
			<label for="<?php 
        echo $this->get_field_id('show_last');
        ?>
"><?php 
        _e('Collect Last Name', 'sendpress');
        ?>
</label>
		</p> 

		<p>
			<label for="<?php 
        echo $this->get_field_id('label_display');
        ?>
"><?php 
        _e('Display labels inside', 'sendpress');
        ?>
?:</label>
			<input type="radio" name="<?php 
        echo $this->get_field_name('label_display');
        ?>
" value="1"<?php 
        echo $instance['label_display'] == 1 ? ' checked' : '';
        ?>
 /> <?php 
        __('Yes', 'sendpress');
        ?>
			<input type="radio" name="<?php 
        echo $this->get_field_name('label_display');
        ?>
" value="0"<?php 
        echo $instance['label_display'] == 0 ? ' checked' : '';
        ?>
 /> <?php 
        __('No', 'sendpress');
        ?>
		</p>
		<!--
		<p>
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['lists_checked'], 'on');
        ?>
 id="<?php 
        echo $this->get_field_id('lists_checked');
        ?>
" name="<?php 
        echo $this->get_field_name('lists_checked');
        ?>
" /> 
			<label for="<?php 
        echo $this->get_field_id('lists_checked');
        ?>
"><?php 
        _e('Check all lists by default', 'sendpress');
        ?>
</label>
		</p> 
		-->

		<p>
			<label for="<?php 
        echo $this->get_field_id('first_label');
        ?>
"><?php 
        _e('First Name Label:', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('first_label');
        ?>
" name="<?php 
        echo $this->get_field_name('first_label');
        ?>
" value="<?php 
        echo $instance['first_label'];
        ?>
" style="width:100%;" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('last_label');
        ?>
"><?php 
        _e('Last Name Label:', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('last_label');
        ?>
" name="<?php 
        echo $this->get_field_name('last_label');
        ?>
" value="<?php 
        echo $instance['last_label'];
        ?>
" style="width:100%;" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('email_label');
        ?>
"><?php 
        _e('E-Mail Label:', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('email_label');
        ?>
" name="<?php 
        echo $this->get_field_name('email_label');
        ?>
" value="<?php 
        echo $instance['email_label'];
        ?>
" style="width:100%;" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('button_text');
        ?>
"><?php 
        _e('Button Text:', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('button_text');
        ?>
" name="<?php 
        echo $this->get_field_name('button_text');
        ?>
" value="<?php 
        echo $instance['button_text'];
        ?>
" style="width:100%;" />
		</p>
		<p>
			<label for="<?php 
        echo $this->get_field_id('list_label');
        ?>
"><?php 
        _e('Lists Label: multiple lists only', 'sendpress');
        ?>
</label>
			<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('list_label');
        ?>
" name="<?php 
        echo $this->get_field_name('list_label');
        ?>
" value="<?php 
        echo $instance['list_label'];
        ?>
" style="width:100%;" />
		</p>
		<p><b><?php 
        __('Check off the lists you would like<br>users to subscribe to', 'sendpress');
        ?>
.</b></p>
		<?php 
        if (count($lists) === 0) {
            ?>
<p><?php 
            _e('No public lists available', 'sendpress');
            ?>
</p><?php 
        } else {
            foreach ($lists as $list) {
                ?>
				<p>
					<input class="checkbox" type="checkbox" <?php 
                checked($instance['list_' . $list->ID], 'on');
                ?>
 id="<?php 
                echo $this->get_field_id('list_' . $list->ID);
                ?>
" name="<?php 
                echo $this->get_field_name('list_' . $list->ID);
                ?>
" /> 
					<label for="<?php 
                echo $this->get_field_id('list_' . $list->ID);
                ?>
"><?php 
                echo $list->post_title;
                ?>
</label>
				</p> 
				<?php 
            }
        }
        if (!is_wp_error($lists) || !is_wp_error($instance) || !is_wp_error($this)) {
            do_action('sendpress_post_notification_widget_form', $lists, $instance, $this);
        }
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('thank_you');
        ?>
"><?php 
        _e('Thank you message:', 'sendpress');
        ?>
</label>
			<textarea rows="5" type="text" class="widefat" id="<?php 
        echo $this->get_field_id('thank_you');
        ?>
" name="<?php 
        echo $this->get_field_name('thank_you');
        ?>
"><?php 
        echo $instance['thank_you'];
        ?>
</textarea>

		</p>
		<p>
			<label for="<?php 
        echo $this->get_field_id('redirect_page');
        ?>
"><?php 
        _e('Thank You Page (AJAX OFF ONLY):', 'sendpress');
        ?>
</label>
			<select name="<?php 
        echo $this->get_field_name('redirect_page');
        ?>
" id="<?php 
        echo $this->get_field_id('redirect_page');
        ?>
"> 
 <option value="0">
 	<?php 
        $cpageid = $instance['redirect_page'];
        echo esc_attr(__('Default'));
        ?>
</option> 
 <?php 
        $pages = get_pages();
        foreach ($pages as $page) {
            $s = '';
            if ($cpageid == $page->ID) {
                $s = "selected";
            }
            $option = '<option value="' . $page->ID . '" ' . $s . '>';
            $option .= $page->post_title;
            $option .= '</option>';
            echo $option;
        }
        ?>
</select>

		</p>

		
		<?php 
    }
    function signup($settings)
    {
        $lists = SendPress_Data::get_lists(array('meta_query' => array(array('key' => 'public', 'value' => true))), false);
        $listids = array();
        foreach ($lists as $list) {
            if (!array_key_exists('list_' . $list->ID, $settings)) {
                $settings['list_' . $list->ID] = false;
            }
        }
        ?>
		<div class="sp-row">
			<h3><?php 
        echo $settings['post_title'];
        ?>
</h3>
		</div>
		<div class="sp-row">
			<div class="sp-50 sp-first">
				<?php 
        $this->panel_start(__('Signup Ui', 'sendpress'));
        ?>

				<p>
					<label for="_form_description"><?php 
        _e('Description:', 'sendpress');
        ?>
</label>
					<textarea rows="5" type="text" class="widefat" id="_form_description" name="_form_description"><?php 
        echo $settings['_form_description'];
        ?>
</textarea>
				</p>

				<p>
					<label for="_firstname_label"><?php 
        _e('First Name Label:', 'sendpress');
        ?>
</label>
					<input type="text" class="widefat" id="_firstname_label" name="_firstname_label" value="<?php 
        echo $settings['_firstname_label'];
        ?>
" style="width:100%;" />
				</p>

				<p>
					<label for="_lastname_label"><?php 
        _e('Last Name Label:', 'sendpress');
        ?>
</label>
					<input type="text" class="widefat" id="_lastname_label" name="_lastname_label" value="<?php 
        echo $settings['_lastname_label'];
        ?>
" style="width:100%;" />
				</p>

				<p>
					<label for="_email_label"><?php 
        _e('E-Mail Label:', 'sendpress');
        ?>
</label>
					<input type="text" class="widefat" id="_email_label" name="_email_label" value="<?php 
        echo $settings['_email_label'];
        ?>
" style="width:100%;" />
				</p>

				<p>
					<label for="_button_label"><?php 
        _e('Button Text:', 'sendpress');
        ?>
</label>
					<input type="text" class="widefat" id="_button_label" name="_button_label" value="<?php 
        echo $settings['_button_label'];
        ?>
" style="width:100%;" />
				</p>

				<p>
					<label for="_list_label"><?php 
        _e('Lists Label: multiple lists only', 'sendpress');
        ?>
</label>
					<input type="text" class="widefat" id="_list_label" name="_list_label" value="<?php 
        echo $settings['_list_label'];
        ?>
" style="width:100%;" />
				</p>

				<p>
					<label for="_thankyou_message"><?php 
        _e('Thank you message:', 'sendpress');
        ?>
</label>
					<textarea rows="5" type="text" class="widefat" id="_thankyou_message" name="_thankyou_message"><?php 
        echo $settings['_thankyou_message'];
        ?>
</textarea>
				</p>

				<?php 
        $this->panel_end();
        ?>
			</div>
			<div class="sp-50">
				<?php 
        $this->panel_start(__('Shortcode', 'sendpress'));
        ?>
					<p><?php 
        _e('Use the shortcode below to insert this signup form into your posts and pages', 'sendpress');
        ?>
.</p>
					<pre>[sp-form formid=<?php 
        echo $settings['_settings_id'];
        ?>
]</pre>
				<?php 
        $this->panel_end();
        ?>

				<?php 
        $this->panel_start(__('Signup Settings', 'sendpress'));
        ?>
				
				<p>
					<input class="checkbox" type="checkbox" <?php 
        checked($settings['_collect_firstname'], 'on');
        ?>
 id="_collect_firstname" name="_collect_firstname" /> 
					<label for="_collect_firstname"><?php 
        _e('Collect First Name', 'sendpress');
        ?>
</label>
				</p> 

				<p>
					<input class="checkbox" type="checkbox" <?php 
        checked($settings['_collect_lastname'], 'on');
        ?>
 id="_collect_lastname" name="_collect_lastname" /> 
					<label for="_collect_lastname"><?php 
        _e('Collect Last Name', 'sendpress');
        ?>
</label>
				</p> 

				<p>
					<label for="_display_labels_inside_fields"><?php 
        _e('Display labels inside', 'sendpress');
        ?>
?:</label>
					<input type="radio" name="_display_labels_inside_fields" value="1"<?php 
        echo $settings['_display_labels_inside_fields'] == 1 ? ' checked' : '';
        ?>
 /> <?php 
        _e('Yes', 'sendpress');
        ?>
					<input type="radio" name="_display_labels_inside_fields" value="0"<?php 
        echo $settings['_display_labels_inside_fields'] == 0 ? ' checked' : '';
        ?>
 /> <?php 
        _e('No', 'sendpress');
        ?>
				</p>

				<p>
					<label for="_thankyou_page"><?php 
        _e('Thank You Page (AJAX OFF ONLY):', 'sendpress');
        ?>
</label>
					<select name="_thankyou_page" id="_thankyou_page"> 
						 <option value="0">
						 	<?php 
        $cpageid = $settings['_thankyou_page'];
        ?>
						<?php 
        echo esc_attr(__('Default'));
        ?>
</option> 
						 <?php 
        $pages = get_pages();
        foreach ($pages as $page) {
            $s = '';
            if ($cpageid == $page->ID) {
                $s = "selected";
            }
            $option = '<option value="' . $page->ID . '" ' . $s . '>';
            $option .= $page->post_title;
            $option .= '</option>';
            echo $option;
        }
        ?>
					</select>

				</p>

				<p>
					<input class="checkbox" type="checkbox" <?php 
        checked($settings['_lists_checked'], 'on');
        ?>
 id="_lists_checked" name="_lists_checked" /> 
					<label for="_lists_checked"><?php 
        _e('Select Lists by Default', 'sendpress');
        ?>
</label>
				</p> 
				
				
				<p><b><?php 
        _e('Check off the lists you would like', 'sendpress');
        ?>
<br><?php 
        _e('users to subscribe to', 'sendpress');
        ?>
.</b></p>
				<?php 
        if (count($lists) === 0) {
            ?>
<p><?php 
            _e('No public lists available', 'sendpress');
            ?>
</p><?php 
        } else {
            foreach ($lists as $list) {
                ?>
						<p>
							<input class="checkbox" type="checkbox" <?php 
                checked($settings['_list_' . $list->ID], 'on');
                ?>
 id="_list_<?php 
                echo $list->ID;
                ?>
" name="_list_<?php 
                echo $list->ID;
                ?>
" /> 
							<label for="_list_<?php 
                echo $list->ID;
                ?>
"><?php 
                echo $list->post_title;
                ?>
</label>
						</p> 
						<?php 
            }
        }
        do_action('sendpress_post_notification_widget_form_new', $lists, $settings, $this, "_");
        ?>

				<?php 
        $this->panel_end();
        ?>
			</div>
			
		
		</div>
		<input type="hidden" name="_setting_type" id="setting_type" value="form" />
		<input type="hidden" name="_form_type" id="form_type" value="signup_widget" />
		<input type="hidden" name="_settings_id" id="sp_settings_id" value="<?php 
        echo $settings['_settings_id'];
        ?>
" />
		<?php 
    }
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     global $wpdb, $_wp_column_headers;
     $screen = get_current_screen();
     //$this->process_bulk_action();
     /*      
             select t1.* from `sp_sendpress_list_subscribers` as t1 , `sp_sendpress_subscribers` as t2
             where t1.subscriberID = t2.subscriberID and t1.listID = 2*/
     /* -- Pagination parameters -- */
     //Number of elements in your table?
     // $totalitems = $wpdb->query($query); //return the total number of affected rows
     //How many to display per page?
     /* -- Register the Columns -- */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     /* -- Fetch the items -- */
     // $args = array(
     // 'post_type' => 'sendpress_list',
     // 'post_status' => array('publish','draft')
     // );
     //$args = apply_filters('sendpress_list_table_query',array('post_type' => 'sendpress_list','post_status' => array('publish','draft')));
     $query = SendPress_Data::get_lists(array('post_status' => array('publish', 'draft')));
     //$query = new WP_Query( $args );
     $totalitems = $query->found_posts;
     // get the current user ID
     $user = get_current_user_id();
     // get the current admin screen
     $screen = get_current_screen();
     // retrieve the "per_page" option
     $screen_option = $screen->get_option('per_page', 'option');
     $per_page = 10;
     if (!empty($screen_option)) {
         // retrieve the value of the option stored for the current user
         $per_page = get_user_meta($user, $screen_option, true);
         if (empty($per_page) || $per_page < 1) {
             // get the default value if none is set
             $per_page = $screen->get_option('per_page', 'default');
         }
     }
     //Which page is this?
     $paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';
     //Page Number
     if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
         $paged = 1;
     }
     //How many pages do we have in total?
     $totalpages = ceil($totalitems / $per_page);
     //adjust the query to take pagination into account
     if (!empty($paged) && !empty($per_page)) {
         $offset = ($paged - 1) * $per_page;
         // $query.=' LIMIT '.(int)$offset.','.(int)$per_page;
     }
     /* -- Register the pagination -- */
     $this->set_pagination_args(array("total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $per_page));
     $args = array('post_type' => 'sendpress_list', 'post_status' => array('publish', 'draft'), 'posts_per_page' => $per_page, 'paged' => $paged);
     if (isset($_GET['order'])) {
         $args['order'] = $_GET['order'];
     }
     if (isset($_GET['orderby'])) {
         $orderby = $_GET['orderby'];
         $args['orderby'] = $orderby;
         if ($orderby == 'subject') {
             $args['orderby'] = 'meta_value';
             $args['meta_key'] = '_sendpress_subject';
         }
         if ($orderby == 'lastsend') {
             $args['orderby'] = 'meta_value';
             $args['meta_key'] = 'send_date';
         }
     }
     //$args = apply_filters('sendpress_list_table_query',$args);
     $query2 = SendPress_Data::get_lists($args);
     // $query2 = new WP_Query( $args );
     $this->items = $query2->posts;
 }
    static function load_form($attr, $content = null)
    {
        global $load_signup_js, $sendpress_show_thanks, $sendpress_signup_error;
        $load_signup_js = true;
        ob_start();
        $lists = SendPress_Data::get_lists(array('meta_query' => array(array('key' => 'public', 'value' => true))), false);
        extract(shortcode_atts(array('firstname_label' => 'First Name', 'lastname_label' => 'Last Name', 'email_label' => 'EMail', 'list_label' => 'List Selection', 'listids' => '', 'redirect_page' => false, 'lists_checked' => true, 'display_firstname' => false, 'display_lastname' => false, 'label_display' => false, 'desc' => '', 'label_width' => 100, 'thank_you' => 'Thank you for subscribing!', 'button_text' => 'Submit', 'no_list_error' => '<div><b>-- NO LIST HAS BEEN SET! --</b></div>', 'postnotification' => '', 'pnlistid' => 0), $attr));
        $label = filter_var($label_display, FILTER_VALIDATE_BOOLEAN);
        $widget_options = SendPress_Option::get('widget_options');
        ?>
	    
	    <div class="sendpress-signup-form">
			<form id="sendpress_signup" method="POST" <?php 
        if (!$widget_options['load_ajax']) {
            ?>
class="sendpress-signup"<?php 
        } else {
            ?>
action="?sendpress=post"<?php 
        }
        ?>
 >
				<?php 
        if ($widget_options['load_ajax']) {
            echo '<input type="hidden" name="action" value="signup-user" />';
            //echo '<input type="hidden" name="redirect" value="'.get_permalink().'" />';
        }
        if (empty($listids)) {
            echo $no_list_error;
        }
        if ($redirect_page != false && $redirect_page > 0) {
            echo '<input type="hidden" name="redirect" value="' . $redirect_page . '" />';
        }
        ?>
					
				<div id="error"><?php 
        echo $sendpress_signup_error;
        ?>
</div>
				<div id="thanks" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:block;"';
        } else {
            echo 'style="display:none;"';
        }
        ?>
><?php 
        echo $thank_you;
        ?>
</div>
				<div id="form-wrap" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:none;"';
        }
        ?>
>
					<p><?php 
        echo $desc;
        ?>
</p>
					<?php 
        $list_ids = explode(",", $listids);
        if (count($list_ids) > 1) {
            ?>
						<p>
						<label for="list"><?php 
            echo $list_label;
            ?>
:</label>
						<?php 
            foreach ($list_ids as $id) {
                ?>
							<input type="checkbox" name="sp_list[]" class="sp_list" id="list<?php 
                echo $id;
                ?>
" value="<?php 
                echo $id;
                ?>
" <?php 
                if ($lists_checked) {
                    echo 'checked';
                }
                ?>
 /> <?php 
                echo get_the_title($id);
                ?>
<br>
						<?php 
            }
            ?>
	
						</p>
						<?php 
        } else {
            ?>
						<input type="hidden" name="sp_list" id="list" class="sp_list" value="<?php 
            echo $listids;
            ?>
" />

					<?php 
        }
        if (strlen($postnotification) > 0) {
            do_action('sendpress_add_post_notification_list', $postnotification, $pnlistid);
        }
        ?>

					<?php 
        if (filter_var($display_firstname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="firstname">
							<?php 
            if (!$label) {
                ?>
								<label for="firstname"><?php 
                echo $firstname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_firstname" orig="<?php 
            echo $firstname_label;
            ?>
" value="<?php 
            if ($label) {
                echo $firstname_label;
            }
            ?>
"  name="sp_firstname" />
						</p>
					<?php 
        }
        ?>

					<?php 
        if (filter_var($display_lastname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="lastname">
							<?php 
            if (!$label) {
                ?>
								<label for="lastname"><?php 
                echo $lastname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_lastname" orig="<?php 
            echo $lastname_label;
            ?>
" value="<?php 
            if ($label) {
                echo $lastname_label;
            }
            ?>
" name="sp_lastname" />
						</p>
					<?php 
        }
        ?>

					<p name="email">
						<?php 
        if (!$label) {
            ?>
							<label for="email"><?php 
            echo $email_label;
            ?>
:</label>
						<?php 
        }
        ?>
						<input type="text" class="sp_email" orig="<?php 
        echo $email_label;
        ?>
" value="<?php 
        if ($label) {
            echo $email_label;
        }
        ?>
" name="sp_email" />
					</p>
					<p name="extra_fields" class="signup-fields-bottom">
						<?php 
        do_action('sendpress_signup_form_bottom');
        ?>
					</p>

					<p class="submit">
						<input value="<?php 
        echo $button_text;
        ?>
" class="sendpress-submit" type="submit"  id="submit" name="submit"><img class="ajaxloader" src="<?php 
        echo SENDPRESS_URL;
        ?>
/img/ajax-loader.gif" />
					</p>
				</div>
			</form>
		</div> 
	
	    <?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
    private static function signup($options)
    {
        //print_r($options);
        global $load_signup_js, $sendpress_show_thanks, $sendpress_signup_error;
        $sendpress_signup_exists = __("You've already signed up, Thanks!", 'sendpress');
        $load_signup_js = true;
        $no_list_error = '-- NO LIST HAS BEEN SET! --';
        $_listids = '';
        extract($options);
        $lists = SendPress_Data::get_lists(array('meta_query' => array(array('key' => 'public', 'value' => true))), false);
        $default_list_ids = array();
        foreach ($lists as $list) {
            $default_list_ids[] = $list->ID;
        }
        $postnotification = '';
        $pnlistid = array();
        //find post notification list
        foreach ($options as $key => $value) {
            if (strpos($key, '_meta_for_list_') === 0) {
                $pnlistid = array_pop(explode('_', $key));
                $postnotification = $value;
            }
        }
        $label = filter_var($_display_labels_inside_fields, FILTER_VALIDATE_BOOLEAN);
        $widget_options = SendPress_Option::get('widget_options');
        $list_ids = strlen($_listids) > 0 ? explode(",", $_listids) : array();
        if (!$_settings_id && empty($list_ids)) {
            $list_ids = $default_list_ids;
        }
        $post_notifications_code = '';
        if (!is_wp_error($list_ids) || !is_wp_error($postnotification) || !is_wp_error($pnlistid)) {
            $post_notifications_code = apply_filters('sendpress-post-notifications-submit-code', "", $list_ids, $postnotification, $pnlistid);
        }
        ?>

	    <div class="sendpress-signup-form">
			<form id="sendpress_signup" method="POST" <?php 
        if (!$widget_options['load_ajax']) {
            ?>
class="sendpress-signup"<?php 
        } else {
            ?>
action="?sendpress=post"<?php 
        }
        ?>
 >
				<?php 
        if ($widget_options['load_ajax']) {
            echo '<input type="hidden" name="action" value="signup-user" />';
        }
        if (empty($_listids) && strlen($post_notifications_code) == 0 && $_settings_id) {
            echo $no_list_error;
        }
        if ($_thankyou_page != false && $_thankyou_page > 0) {
            echo '<input type="hidden" name="redirect" value="' . $_thankyou_page . '" />';
        }
        ?>
				<div id="exists" style="display:none;"><?php 
        echo $sendpress_signup_exists;
        ?>
</div>
				<div id="error"><?php 
        echo $sendpress_signup_error;
        ?>
</div>
				<div id="thanks" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:block;"';
        } else {
            echo 'style="display:none;"';
        }
        ?>
><?php 
        echo $_thankyou_message;
        ?>
</div>
				<div id="form-wrap" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:none;"';
        }
        ?>
>
					<p><?php 
        echo $_form_description;
        ?>
</p>
					<?php 
        if (count($list_ids) > 0) {
            if (count($list_ids) > 1 || strlen($post_notifications_code) > 0) {
                ?>
							<p>
								<label for="list"><?php 
                echo $_list_label;
                ?>
:</label>
								<?php 
                foreach ($list_ids as $id) {
                    if ($id !== $pnlistid) {
                        ?>
											<input type="checkbox" name="sp_list[]" class="sp_list" id="list<?php 
                        echo $id;
                        ?>
" value="<?php 
                        echo $id;
                        ?>
" <?php 
                        if ($_lists_checked) {
                            echo 'checked';
                        }
                        ?>
 /> <?php 
                        echo get_the_title($id);
                        ?>
<br>
											<?php 
                    }
                }
                ?>
							</p>
							<?php 
            } else {
                ?>
							<input type="hidden" name="sp_list" id="list" class="sp_list" value="<?php 
                echo $list_ids[0];
                ?>
" />
							<?php 
            }
        }
        echo $post_notifications_code;
        ?>

					<?php 
        if (filter_var($_collect_firstname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="sp_firstname">
							<?php 
            if (!$_display_labels_inside_fields) {
                ?>
								<label for="sp_firstname"><?php 
                echo $_firstname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_firstname" <?php 
            if ($_display_labels_inside_fields) {
                ?>
placeholder="<?php 
                echo $_firstname_label;
                ?>
"<?php 
            }
            ?>
 value=""  name="sp_firstname" />
						</p>
					<?php 
        }
        ?>

					<?php 
        if (filter_var($_collect_lastname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="sp_lastname">
							<?php 
            if (!$_display_labels_inside_fields) {
                ?>
								<label for="sp_lastname"><?php 
                echo $_lastname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_lastname" <?php 
            if ($_display_labels_inside_fields) {
                ?>
placeholder="<?php 
                echo $_lastname_label;
                ?>
"<?php 
            }
            ?>
 value="" name="sp_lastname" />
						</p>
					<?php 
        }
        ?>

					<p name="sp_email">
						<?php 
        if (!$_display_labels_inside_fields) {
            ?>
							<label for="sp_email"><?php 
            echo $_email_label;
            ?>
:</label>
						<?php 
        }
        ?>
						<input type="text" class="sp_email" <?php 
        if ($_display_labels_inside_fields) {
            ?>
placeholder="<?php 
            echo $_email_label;
            ?>
"<?php 
        }
        ?>
 value="" name="sp_email" />
					</p>
					<p name="extra_fields" class="signup-fields-bottom">
						<?php 
        do_action('sendpress_signup_form_bottom');
        ?>
					</p>

					<p class="submit">
						<input value="<?php 
        echo $_button_label;
        ?>
" class="sendpress-submit" type="submit"  id="submit" name="submit"><img class="ajaxloader" style="display:none;" src="<?php 
        echo SENDPRESS_URL;
        ?>
/img/ajax-loader.gif" />
					</p>
				</div>
			</form>
		</div>

	    <?php 
    }
function snp_ml_get_sp_lists()
{
    if (defined('SENDPRESS_VERSION')) {
        $lists = SendPress_Data::get_lists();
        foreach ($lists->posts as $v) {
            if ($v->ID && $v->post_title) {
                $list[$v->ID] = array('name' => $v->post_title);
            }
        }
    }
    if (count($list) == 0) {
        $list[0] = array('name' => 'Nothing Found...');
    }
    return $list;
}
    static function load_page($attr, $content = null)
    {
        $action = get_query_var('spmanage');
        //Look for encrypted data
        $info = SendPress_Data::decrypt($action);
        //print_r( $info );
        ?>

<form action="" method="post">
<?php 
        wp_nonce_field(SendPress_Data::nonce());
        ?>
<input type="hidden" name="subscriberid" id="subscriberid" value="<?php 
        echo $info->id;
        ?>
" />
<input type="hidden" name="action" id="action" value="sendpress-manage-shortcode" />
<table cellpadding="0" cellspacing="0" class="table table-condensed table-striped table-bordered">
	<tr>
		<th  ><?php 
        _e('Subscribed', 'sendpress');
        ?>
</th>
		<th  ><?php 
        _e('Unsubscribed', 'sendpress');
        ?>
</th>
		<th  ><?php 
        _e('List', 'sendpress');
        ?>
</th>
		<th class="hidden-phone"><?php 
        _e('Updated', 'sendpress');
        ?>
</th>
		<th class="hidden-phone"><?php 
        _e('Other Info', 'sendpress');
        ?>
</th>
	</tr>
<?php 
        $lists = SendPress_Data::get_lists(apply_filters('sendpress_modify_manage_lists', array('meta_query' => array(array('key' => 'public', 'value' => true)))), false);
        foreach ($lists as $list) {
            $subscriber = SendPress_Data::get_subscriber_list_status($list->ID, $info->id);
            ?>
  	<tr>
  	<?php 
            $checked = isset($subscriber->statusid) && $subscriber->statusid == 2 ? 'checked' : '';
            echo '<td><input type="radio" class="xbutton" data-list="' . $list->ID . '" name="subscribe_' . $list->ID . '" ' . $checked . ' value="2"></td>';
            $checked = isset($subscriber->statusid) && $subscriber->statusid == 3 ? 'checked' : '';
            echo '<td><input type="radio" class="xbutton" data-list="' . $list->ID . '" name="subscribe_' . $list->ID . '" ' . $checked . ' value="3"></td>';
            ?>
  	<td><?php 
            echo $list->post_title;
            ?>
</td>
  	<td class="hidden-phone"><span id="list_<?php 
            echo $list->ID;
            ?>
"><?php 
            if (isset($subscriber->updated)) {
                echo $subscriber->updated;
            } else {
                _e('Never Subscribed', 'sendpress');
            }
            ?>
</span>
	</td>
	<td class="hidden-phone">
		<?php 
            if (is_object($subscriber)) {
                if ($subscriber->statusid != 3 && $subscriber->statusid != 2) {
                    echo $subscriber->status;
                }
            }
            ?>
	</td>
  	<tr>	
    <?php 
        }
        ?>

</table>
<br>
<?php 
        do_action('sendpress_manage_notifications', $info);
        ?>
<input type="submit" class="btn btn-primary" value="<?php 
        _e('Save My Settings', 'sendpress');
        ?>
"/>
</form><?php 
    }
    /**
     * Output the form
     *
     * @param array $atts
     */
    public static function output($atts, $content = null)
    {
        global $load_signup_js, $sendpress_show_thanks, $sendpress_signup_error;
        $load_signup_js = true;
        $sendpress_signup_exists = __("You've already signed up, Thanks!", 'sendpress');
        $lists = SendPress_Data::get_lists(array('meta_query' => array(array('key' => 'public', 'value' => true))), false);
        extract(shortcode_atts(self::options(), $atts));
        $label = filter_var($label_display, FILTER_VALIDATE_BOOLEAN);
        $widget_options = SendPress_Option::get('widget_options');
        $list_ids = strlen($listids) > 0 ? explode(",", $listids) : array();
        $post_notifications_code = apply_filters('sendpress-post-notifications-submit-code', "", $list_ids, $postnotification, $pnlistid);
        ?>

	    <div class="sendpress-signup-form">
			<form id="sendpress_signup" method="POST" <?php 
        if (!$widget_options['load_ajax']) {
            ?>
class="sendpress-signup"<?php 
        } else {
            ?>
action="?sendpress=post"<?php 
        }
        ?>
 >
				<?php 
        if ($widget_options['load_ajax']) {
            echo '<input type="hidden" name="action" value="signup-user" />';
        }
        if (empty($listids) && strlen($post_notifications_code) == 0) {
            echo $no_list_error;
        }
        if ($redirect_page != false && $redirect_page > 0) {
            echo '<input type="hidden" name="redirect" value="' . $redirect_page . '" />';
        }
        ?>
				<div id="exists"><?php 
        echo $sendpress_signup_exists;
        ?>
</div>
				<div id="error"><?php 
        echo $sendpress_signup_error;
        ?>
</div>
				<div id="thanks" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:block;"';
        } else {
            echo 'style="display:none;"';
        }
        ?>
><?php 
        echo $thank_you;
        ?>
</div>
				<div id="form-wrap" <?php 
        if ($sendpress_show_thanks) {
            echo 'style="display:none;"';
        }
        ?>
>
					<p><?php 
        echo $desc;
        ?>
</p>
					<?php 
        if (count($list_ids) > 0) {
            if (count($list_ids) > 1 || strlen($post_notifications_code) > 0) {
                ?>
							<p>
								<label for="list"><?php 
                echo $list_label;
                ?>
:</label>
								<?php 
                foreach ($list_ids as $id) {
                    ?>
										<input type="checkbox" name="sp_list[]" class="sp_list" id="list<?php 
                    echo $id;
                    ?>
" value="<?php 
                    echo $id;
                    ?>
" <?php 
                    if ($lists_checked) {
                        echo 'checked';
                    }
                    ?>
 /> <?php 
                    echo get_the_title($id);
                    ?>
<br>
										<?php 
                }
                ?>
							</p>
							<?php 
            } else {
                ?>
							<input type="hidden" name="sp_list" id="list" class="sp_list" value="<?php 
                echo $listids;
                ?>
" />
							<?php 
            }
        }
        if (is_string($post_notifications_code) && strlen($post_notifications_code) > 0) {
            echo $post_notifications_code;
        }
        if (strlen($postnotification) > 0) {
            do_action('sendpress_add_post_notification_list', $postnotification, $pnlistid);
        }
        ?>

					<?php 
        if (filter_var($display_firstname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="firstname">
							<?php 
            if (!$label) {
                ?>
								<label for="firstname"><?php 
                echo $firstname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_firstname" orig="<?php 
            echo $firstname_label;
            ?>
" value="<?php 
            if ($label) {
                echo $firstname_label;
            }
            ?>
"  name="sp_firstname" />
						</p>
					<?php 
        }
        ?>

					<?php 
        if (filter_var($display_lastname, FILTER_VALIDATE_BOOLEAN)) {
            ?>
						<p name="lastname">
							<?php 
            if (!$label) {
                ?>
								<label for="lastname"><?php 
                echo $lastname_label;
                ?>
:</label>
							<?php 
            }
            ?>
							<input type="text" class="sp_lastname" orig="<?php 
            echo $lastname_label;
            ?>
" value="<?php 
            if ($label) {
                echo $lastname_label;
            }
            ?>
" name="sp_lastname" />
						</p>
					<?php 
        }
        ?>

					<p name="email">
						<?php 
        if (!$label) {
            ?>
							<label for="email"><?php 
            echo $email_label;
            ?>
:</label>
						<?php 
        }
        ?>
						<input type="text" class="sp_email" orig="<?php 
        echo $email_label;
        ?>
" value="<?php 
        if ($label) {
            echo $email_label;
        }
        ?>
" name="sp_email" />
					</p>
					<p name="extra_fields" class="signup-fields-bottom">
						<?php 
        do_action('sendpress_signup_form_bottom');
        ?>
					</p>

					<p class="submit">
						<input value="<?php 
        echo $button_text;
        ?>
" class="sendpress-submit" type="submit"  id="submit" name="submit"><img class="ajaxloader" style="display:none;"  src="<?php 
        echo SENDPRESS_URL;
        ?>
/img/ajax-loader.gif" />
					</p>
				</div>
			</form>
		</div>

	    <?php 
    }