WordPress.org

Plugin Directory

Changeset 607610


Ignore:
Timestamp:
10/03/12 19:01:57 (19 months ago)
Author:
MattyRob
Message:

Refreshed Subscribers page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • subscribe2/trunk/admin/subscribers.php

    r604312 r607610  
    44} 
    55 
    6 global $wpdb, $s2nonce; 
    7  
    8 //Get Registered Subscribers for bulk management 
    9 $registered = $this->get_registered(); 
    10 $all_users = $this->get_all_registered(); 
     6global $wpdb, $subscribers, $what, $current_tab; 
    117 
    128// was anything POSTed ? 
    139if ( isset($_POST['s2_admin']) ) { 
    14     check_admin_referer('subscribe2-manage_subscribers' . $s2nonce); 
     10    check_admin_referer('bulk-subscribers'); 
    1511    if ( !empty($_POST['addresses']) ) { 
    1612        $sub_error = ''; 
    1713        $unsub_error = ''; 
    18         foreach ( preg_split ("|[\s,]+|", $_POST['addresses']) as $email ) { 
     14        foreach ( preg_split("|[\s,]+|", $_POST['addresses']) as $email ) { 
    1915            $email = $this->sanitize_email($email); 
    2016            if ( is_email($email) && $_POST['subscribe'] ) { 
     
    4238        echo $message; 
    4339        $_POST['what'] = 'confirmed'; 
    44     } elseif ( isset($_POST['process']) ) { 
    45         if ( isset($_POST['delete']) ) { 
    46             foreach ( $_POST['delete'] as $address ) { 
    47                 $this->delete($address); 
    48             } 
    49             echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) deleted!', 'subscribe2') . "</strong></p></div>"; 
    50         } 
    51         if ( isset($_POST['confirm']) ) { 
    52             global $current_user; 
    53             $this->ip = $current_user->user_login; 
    54             foreach ( $_POST['confirm'] as $address ) { 
    55                 $this->toggle($this->sanitize_email($address)); 
    56             } 
    57             $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>"; 
    58         } 
    59         if ( isset($_POST['unconfirm']) ) { 
    60             global $current_user; 
    61             $this->ip = $current_user->user_login; 
    62             foreach ( $_POST['unconfirm'] as $address ) { 
    63                 $this->toggle($this->sanitize_email($address)); 
    64             } 
    65             $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>"; 
    66         } 
    67         echo $message; 
    68     } elseif ( !empty($_POST['searchterm']) ) { 
    69         $confirmed = $this->get_public(); 
    70         $unconfirmed = $this->get_public(0); 
    71         $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users); 
    72         foreach ( $subscribers as $subscriber ) { 
    73             if ( is_numeric(stripos($subscriber, $_POST['searchterm'])) ) { 
    74                 $result[] = $subscriber; 
    75             } 
    76         } 
     40    } elseif ( $_POST['action'] === 'delete' ) { 
     41        foreach ( $_POST['subscriber'] as $address ) { 
     42            $this->delete($address); 
     43        } 
     44        echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) deleted!', 'subscribe2') . "</strong></p></div>"; 
     45    } elseif ( $_POST['action'] === 'toggle' ) { 
     46        global $current_user; 
     47        $this->ip = $current_user->user_login; 
     48        foreach ( $_POST['subscriber'] as $address ) { 
     49            $this->toggle($address); 
     50        } 
     51        echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>"; 
    7752    } elseif ( isset($_POST['remind']) ) { 
    7853        $this->remind($_POST['reminderemails']); 
     
    9368} 
    9469 
    95 //Get Public Subscribers once for filter 
    96 $confirmed = $this->get_public(); 
    97 $unconfirmed = $this->get_public(0); 
    98 // safety check for our arrays 
    99 if ( '' == $confirmed ) { $confirmed = array(); } 
    100 if ( '' == $unconfirmed ) { $unconfirmed = array(); } 
    101 if ( '' == $registered ) { $registered = array(); } 
    102 if ( '' == $all_users ) { $all_users = array(); } 
     70// detect or define which tab we are in 
     71$current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'public'; 
     72if ( $current_tab == 'registered' ) { 
     73    // Get Registered Subscribers 
     74    $registered = $this->get_registered(); 
     75    $all_users = $this->get_all_registered(); 
     76    // safety check for our arrays 
     77    if ( '' == $registered ) { $registered = array(); } 
     78    if ( '' == $all_users ) { $all_users = array(); } 
     79} else { 
     80    //Get Public Subscribers 
     81    $confirmed = $this->get_public(); 
     82    $unconfirmed = $this->get_public(0); 
     83    // safety check for our arrays 
     84    if ( '' == $confirmed ) { $confirmed = array(); } 
     85    if ( '' == $unconfirmed ) { $unconfirmed = array(); } 
     86} 
    10387 
    10488$reminderform = false; 
    105 $urlpath = str_replace("\\", "/", S2PATH); 
    106 $urlpath = trailingslashit(get_option('siteurl')) . substr($urlpath,strpos($urlpath, "wp-content/")); 
    107 if ( isset($_GET['s2page']) ) { 
    108     $page = (int) $_GET['s2page']; 
    109 } else { 
    110     $page = 1; 
    111 } 
    112  
    113 if ( isset($_POST['what']) ) { 
    114     $page = 1; 
    115     if ( 'all' == $_POST['what'] ) { 
    116         $what = 'all'; 
    117         $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users); 
    118     } elseif ( 'public' == $_POST['what'] ) { 
     89if ( isset($_REQUEST['what']) ) { 
     90    if ( 'public' == $_REQUEST['what'] ) { 
    11991        $what = 'public'; 
    12092        $subscribers = array_merge((array)$confirmed, (array)$unconfirmed); 
    121     } elseif ( 'confirmed' == $_POST['what'] ) { 
     93    } elseif ( 'confirmed' == $_REQUEST['what'] ) { 
    12294        $what = 'confirmed'; 
    12395        $subscribers = $confirmed; 
    124     } elseif ( 'unconfirmed' == $_POST['what'] ) { 
     96    } elseif ( 'unconfirmed' == $_REQUEST['what'] ) { 
    12597        $what = 'unconfirmed'; 
    12698        $subscribers = $unconfirmed; 
     
    129101            $reminderform = true; 
    130102        } 
    131     } elseif ( is_numeric($_POST['what']) ) { 
    132         $what = intval($_POST['what']); 
     103    } elseif ( is_numeric($_REQUEST['what']) ) { 
     104        $what = intval($_REQUEST['what']); 
    133105        $subscribers = $this->get_registered("cats=$what"); 
    134     } elseif ( 'registered' == $_POST['what'] ) { 
     106    } elseif ( 'registered' == $_REQUEST['what'] ) { 
    135107        $what = 'registered'; 
    136108        $subscribers = $registered; 
    137     } elseif ( 'all_users' == $_POST['what'] ) { 
     109    } elseif ( 'all_users' == $_REQUEST['what'] ) { 
    138110        $what = 'all_users'; 
    139111        $subscribers = $all_users; 
    140112    } 
    141 } elseif ( isset($_GET['what']) ) { 
    142     if ( 'all' == $_GET['what'] ) { 
    143         $what = 'all'; 
    144         $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users); 
    145     } elseif ( 'public' == $_GET['what'] ) { 
     113} else { 
     114    if ( $current_tab === 'public' ) { 
    146115        $what = 'public'; 
    147116        $subscribers = array_merge((array)$confirmed, (array)$unconfirmed); 
    148     } elseif ( 'confirmed' == $_GET['what'] ) { 
    149         $what = 'confirmed'; 
    150         $subscribers = $confirmed; 
    151     } elseif ( 'unconfirmed' == $_GET['what'] ) { 
    152         $what = 'unconfirmed'; 
    153         $subscribers = $unconfirmed; 
    154         if ( !empty($subscribers) ) { 
    155             $reminderemails = implode(",", $subscribers); 
    156             $reminderform = true; 
    157         } 
    158     } elseif ( is_numeric($_GET['what']) ) { 
    159         $what = intval($_GET['what']); 
    160         $subscribers = $this->get_registered("cats=$what"); 
    161     } elseif ( 'registered' == $_GET['what'] ) { 
    162         $what = 'registered'; 
    163         $subscribers = $registered; 
    164     } elseif ( 'all_users' == $_GET['what'] ) { 
     117    } else { 
    165118        $what = 'all_users'; 
    166119        $subscribers = $all_users; 
    167120    } 
    168 } else { 
    169     $what = 'all'; 
    170     $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users); 
    171 } 
    172 if ( !empty($_POST['searchterm']) ) { 
    173     $subscribers = &$result; 
    174     $what = 'public'; 
    175 } 
    176  
    177 if ( !empty($subscribers) ) { 
    178     natcasesort($subscribers); 
    179     // Displays a page number strip - adapted from code in Akismet 
    180     $args['what'] = $what; 
    181     $total_subscribers = count($subscribers); 
    182     $total_pages = ceil($total_subscribers / $this->subscribe2_options['entries']); 
    183     $strip = ''; 
    184     if ( $page > 1 ) { 
    185         $args['s2page'] = $page - 1; 
    186         $strip .= '<a class="prev" href="' . esc_url(add_query_arg($args)) . '">&laquo; '. __('Previous Page', 'subscribe2') .'</a>' . "\n"; 
    187     } 
    188     if ( $total_pages > 1 ) { 
    189         for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) { 
    190             if ( $page == $page_num ) { 
    191                 $strip .= "<strong>Page " . $page_num . "</strong>\n"; 
    192             } else { 
    193                 if ( $page_num < 3 || ( $page_num >= $page - 2 && $page_num <= $page + 2 ) || $page_num > $total_pages - 2 ) { 
    194                     $args['s2page'] = $page_num; 
    195                     $strip .= "<a class=\"page-numbers\" href=\"" . esc_url(add_query_arg($args)) . "\">" . $page_num . "</a>\n"; 
    196                     $trunc = true; 
    197                 } elseif ( $trunc == true ) { 
    198                     $strip .= "...\n"; 
    199                     $trunc = false; 
    200                 } 
    201             } 
    202         } 
    203     } 
    204     if ( ( $page ) * $this->subscribe2_options['entries'] < $total_subscribers ) { 
    205         $args['s2page'] = $page + 1; 
    206         $strip .= "<a class=\"next\" href=\"" . esc_url(add_query_arg($args)) . "\">". __('Next Page', 'subscribe2') . " &raquo;</a>\n"; 
    207     } 
    208 } 
     121} 
     122 
     123if ( !empty($_POST['s']) ) { 
     124    foreach ( $subscribers as $subscriber ) { 
     125        if ( is_numeric(stripos($subscriber, $_POST['s'])) ) { 
     126            $result[] = $subscriber; 
     127        } 
     128    } 
     129    $subscribers = $result; 
     130} 
     131 
     132if( !class_exists('WP_List_Table') ){ 
     133    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); 
     134} 
     135// Instantiate and prepare our table data - this also runs the bulk actions 
     136$S2ListTable = new Subscribe2_List_Table(); 
     137$S2ListTable->prepare_items(); 
    209138 
    210139// show our form 
    211140echo "<div class=\"wrap\">"; 
    212141echo "<div id=\"icon-tools\" class=\"icon32\"></div>"; 
    213 echo "<h2>" . __('Manage Subscribers', 'subscribe2') . "</h2>\r\n"; 
     142$tabs = array('public' => 'Public Subscribers', 'registered' => 'Registered Subscribers'); 
     143echo "<h2 class=\"nav-tab-wrapper\">"; 
     144foreach ( $tabs as $tab_key => $tab_caption ) { 
     145    $active = ($current_tab == $tab_key) ? "nav-tab-active" : ""; 
     146    echo "<a class=\"nav-tab " . $active . "\" href=\"?page=s2_tools&amp;tab=" . $tab_key . "\">" . $tab_caption . "</a>"; 
     147} 
     148echo "</h2>"; 
    214149echo "<form method=\"post\">\r\n"; 
    215 if ( function_exists('wp_nonce_field') ) { 
    216     wp_nonce_field('subscribe2-manage_subscribers' . $s2nonce); 
    217 } 
    218 echo "<div class=\"s2_admin\" id=\"s2_add_subscribers\">\r\n"; 
    219 echo "<h2>" . __('Add/Remove Subscribers', 'subscribe2') . "</h2>\r\n"; 
    220 echo "<p>" . __('Enter addresses, one per line or comma-separated', 'subscribe2') . "<br />\r\n"; 
    221 echo "<textarea rows=\"2\" cols=\"80\" name=\"addresses\"></textarea></p>\r\n"; 
    222150echo "<input type=\"hidden\" name=\"s2_admin\" />\r\n"; 
    223 echo "<p class=\"submit\" style=\"border-top: none;\"><input type=\"submit\" class=\"button-primary\" name=\"subscribe\" value=\"" . __('Subscribe', 'subscribe2') . "\" />"; 
    224 echo "&nbsp;<input type=\"submit\" class=\"button-primary\" name=\"unsubscribe\" value=\"" . __('Unsubscribe', 'subscribe2') . "\" /></p>\r\n"; 
    225 echo "</div>\r\n"; 
    226  
    227 // subscriber lists 
    228 echo "<div class=\"s2_admin\" id=\"s2_current_subscribers\">\r\n"; 
    229 echo "<h2>" . __('Current Subscribers', 'subscribe2') . "</h2>\r\n"; 
    230 echo "<br />"; 
    231 $this->display_subscriber_dropdown($what, __('Filter', 'subscribe2')); 
    232 echo "<br /><br />"; 
     151switch ($current_tab) { 
     152    case 'public': 
     153        echo "<div class=\"s2_admin\" id=\"s2_add_subscribers\">\r\n"; 
     154        echo "<h2>" . __('Add/Remove Subscribers', 'subscribe2') . "</h2>\r\n"; 
     155        echo "<p>" . __('Enter addresses, one per line or comma-separated', 'subscribe2') . "<br />\r\n"; 
     156        echo "<textarea rows=\"2\" cols=\"80\" name=\"addresses\"></textarea></p>\r\n"; 
     157        echo "<input type=\"hidden\" name=\"s2_admin\" />\r\n"; 
     158        echo "<p class=\"submit\" style=\"border-top: none;\"><input type=\"submit\" class=\"button-primary\" name=\"subscribe\" value=\"" . __('Subscribe', 'subscribe2') . "\" />"; 
     159        echo "&nbsp;<input type=\"submit\" class=\"button-primary\" name=\"unsubscribe\" value=\"" . __('Unsubscribe', 'subscribe2') . "\" /></p>\r\n"; 
     160        echo "</div>\r\n"; 
     161 
     162        // subscriber lists 
     163        echo "<div class=\"s2_admin\" id=\"s2_current_subscribers\">\r\n"; 
     164        echo "<h2>" . __('Current Subscribers', 'subscribe2') . "</h2>\r\n"; 
     165        echo "<br />"; 
     166        $cats = $this->all_cats(); 
     167        $cat_ids = array(); 
     168        foreach ( $cats as $cat) { 
     169            $cat_ids[] = $cat->term_id; 
     170        } 
     171        $exclude = array_merge(array('all', 'all_users', 'registered'), $cat_ids); 
     172        break; 
     173 
     174    case 'registered': 
     175        echo "<div class=\"s2_admin\" id=\"s2_add_subscribers\">\r\n"; 
     176        echo "<h2>" . __('Add/Remove Subscribers', 'subscribe2') . "</h2>\r\n"; 
     177        echo "<p class=\"submit\" style=\"border-top: none;\"><input type=\"submit\" class=\"button-primary\" name=\"add_user\" value=\"" . __('Add Registered User', 'subscribe2') . "\" formaction=\"" . admin_url() . "user-new.php\" /></p>\r\n"; 
     178 
     179        echo "</div>\r\n"; 
     180 
     181        // subscriber lists 
     182        echo "<div class=\"s2_admin\" id=\"s2_current_subscribers\">\r\n"; 
     183        echo "<h2>" . __('Current Subscribers', 'subscribe2') . "</h2>\r\n"; 
     184        echo "<br />"; 
     185        $exclude = array('public', 'confirmed', 'unconfirmed'); 
     186        break; 
     187} 
     188 
    233189// show the selected subscribers 
    234 $alternate = 'alternate'; 
    235 echo "<table style=\"width: 100%; border-collapse: separate; border-spacing: 0px; *border-collapse: expression('separate', cellSpacing = '0px');\" class=\"widefat\" >"; 
    236 $searchterm = ( isset($_POST['searchterm']) ) ? stripslashes(esc_html($_POST['searchterm'])) : ''; 
    237 echo "<tr class=\"alternate\"><td colspan=\"3\"><input type=\"text\" name=\"searchterm\" value=\"" . $searchterm . "\" /></td>\r\n"; 
    238 echo "<td><input type=\"submit\" class=\"button-secondary\" name=\"search\" value=\"" . __('Search Subscribers', 'subscribe2') . "\" /></td>\r\n"; 
     190echo "<table style=\"width: 100%; border-collapse: separate; border-spacing: 0px; *border-collapse: expression('separate', cellSpacing = '0px');\"><tr>"; 
     191echo "<td style=\"width: 50%; text-align: left;\">"; 
     192$this->display_subscriber_dropdown($what, __('Filter', 'subscribe2'), $exclude); 
     193echo "</td>\r\n"; 
    239194if ( $reminderform ) { 
    240195    echo "<td style=\"width: 25%; text-align: right;\"><input type=\"hidden\" name=\"reminderemails\" value=\"" . $reminderemails . "\" />\r\n"; 
     
    250205    echo "<td style=\"width: 25%;\"></td>"; 
    251206} 
    252 echo "</tr>"; 
    253  
    254 if ( !empty($subscribers) ) { 
    255     echo "<tr><td colspan=\"3\" style=\"text-align: center;\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n"; 
    256     echo "<td style=\"text-align: right;\" colspan=\"3\">" . $strip . "</td></tr>\r\n"; 
    257 } 
    258 if ( !empty($subscribers) ) { 
    259     if ( is_int($this->subscribe2_options['entries']) ) { 
    260         $subscriber_chunks = array_chunk($subscribers, $this->subscribe2_options['entries']); 
    261     } else { 
    262         $subscriber_chunks = array_chunk($subscribers, 25); 
    263     } 
    264     $chunk = $page - 1; 
    265     $subscribers = $subscriber_chunks[$chunk]; 
    266     echo "<tr class=\"alternate\" style=\"height:1.5em;\">\r\n"; 
    267     echo "<td style=\"width: 4%; text-align: center;\">"; 
    268     echo "<img src=\"" . $urlpath . "include/accept.png\" alt=\"&lt;\" title=\"" . __('Confirm this email address', 'subscribe2') . "\" /></td>\r\n"; 
    269     echo "<td style=\"width: 4%; text-align: center;\">"; 
    270     echo "<img src=\"" . $urlpath . "include/exclamation.png\" alt=\"&gt;\" title=\"" . __('Unconfirm this email address', 'subscribe2') . "\" /></td>\r\n"; 
    271     echo "<td style=\"width: 4%; text-align: center;\">"; 
    272     echo "<img src=\"" . $urlpath . "include/cross.png\" alt=\"X\" title=\"" . __('Delete this email address', 'subscribe2') . "\" /></td><td colspan=\"3\"></td></tr>\r\n"; 
    273     echo "<tr class=\"\"><td style=\"text-align: center;\"><input type=\"checkbox\" name=\"checkall\" value=\"confirm_checkall\" /></td>\r\n"; 
    274     echo "<td style=\"text-align: center;\"><input type=\"checkbox\" name=\"checkall\" value=\"unconfirm_checkall\" /></td>\r\n"; 
    275     echo "<td style=\"text-align: center;\"><input type=\"checkbox\" name=\"checkall\" value=\"delete_checkall\" /></td>\r\n"; 
    276     echo "<td colspan =\"3\" style=\"text-align: left;\"><strong>" . __('Select / Unselect All', 'subscribe2') . "</strong></td></tr>\r\n"; 
    277  
    278     foreach ( $subscribers as $subscriber ) { 
    279         echo "<tr class=\"$alternate\" style=\"height:1.5em;\">"; 
    280         echo "<td style=\"text-align: center;\">\r\n"; 
    281         if ( in_array($subscriber, $confirmed) ) { 
    282             echo "</td><td style=\"text-align: center;\">\r\n"; 
    283             echo "<input class=\"unconfirm_checkall\" title=\"" . __('Unconfirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"unconfirm[]\" value=\"" . $subscriber . "\" /></td>\r\n"; 
    284             echo "<td style=\"text-align: center;\">\r\n"; 
    285             echo "<input class=\"delete_checkall\" title=\"" . __('Delete this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"delete[]\" value=\"" . $subscriber . "\" />\r\n"; 
    286             echo "</td>\r\n"; 
    287             echo "<td colspan=\"3\"><span style=\"color:#006600\">&#x221A;&nbsp;&nbsp;</span><abbr title=\"" . $this->signup_ip($subscriber) . "\"><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a></abbr>\r\n"; 
    288             echo "(<span style=\"color:#006600\">" . $this->signup_date($subscriber) . "</span>)\r\n"; 
    289         } elseif ( in_array($subscriber, $unconfirmed) ) { 
    290             echo "<input class=\"confirm_checkall\" title=\"" . __('Confirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"confirm[]\" value=\"" . $subscriber . "\" /></td>\r\n"; 
    291             echo "<td style=\"text-align: center;\"></td>\r\n"; 
    292             echo "<td style=\"text-align: center;\">\r\n"; 
    293             echo "<input class=\"delete_checkall\" title=\"" . __('Delete this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"delete[]\" value=\"" . $subscriber . "\" />\r\n"; 
    294             echo "</td>\r\n"; 
    295             echo "<td colspan=\"3\"><span style=\"color:#FF0000\">&nbsp;!&nbsp;&nbsp;&nbsp;</span><abbr title=\"" . $this->signup_ip($subscriber) . "\"><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a></abbr>\r\n"; 
    296             echo "(<span style=\"color:#FF0000\">" . $this->signup_date($subscriber) . "</span>)\r\n"; 
    297         } elseif ( in_array($subscriber, $all_users) ) { 
    298             $user_info = get_user_by('email', $subscriber); 
    299             echo "</td><td style=\"text-align: center;\"></td><td style=\"text-align: center;\"></td>\r\n"; 
    300             echo "<td colspan=\"3\"><span style=\"color:#006600\">&reg;&nbsp;&nbsp;</span><abbr title=\"" . $user_info->user_login . "\"><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a></abbr>\r\n"; 
    301             echo "(<a href=\"" . get_option('siteurl') . "/wp-admin/admin.php?page=s2&amp;email=" . urlencode($subscriber) . "\">" . __('edit', 'subscribe2') . "</a>)\r\n"; 
    302         } 
    303         echo "</td></tr>\r\n"; 
    304         ('alternate' == $alternate) ? $alternate = '' : $alternate = 'alternate'; 
    305     } 
    306 } else { 
    307     if ( $_POST['searchterm'] ) { 
    308         echo "<tr><td colspan=\"6\" style=\"text-align: center;\"><b>" . __('No matching subscribers found', 'subscribe2') . "</b></td></tr>\r\n"; 
    309     } else { 
    310         echo "<tr><td colspan=\"6\" style=\"text-align: center;\"><b>" . __('NONE', 'subscribe2') . "</b></td></tr>\r\n"; 
    311     } 
    312 } 
    313 if ( !empty($subscribers) ) { 
    314     echo "<tr class=\"$alternate\"><td colspan=\"3\" style=\"text-align: center;\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n"; 
    315     echo "<td colspan=\"3\" style=\"text-align: right;\">" . $strip . "</td></tr>\r\n"; 
    316 } 
    317 echo "</table>\r\n"; 
     207echo "</tr></table>"; 
     208 
     209// output our subscriber table 
     210$S2ListTable->search_box(__('Search', 'subscribe2'), 'search_id'); 
     211$S2ListTable->display(); 
    318212echo "</div>\r\n"; 
    319213 
    320214// show bulk managment form if filtered in some Registered Users 
    321 if ( in_array($what, array('registered', 'all_users')) || is_numeric($what) ) { 
     215if ( $current_tab === 'registered' ) { 
    322216    echo "<div class=\"s2_admin\" id=\"s2_bulk_manage\">\r\n"; 
    323217    echo "<h2>" . __('Bulk Management', 'subscribe2') . "</h2>\r\n"; 
     
    353247// just to be sure 
    354248die; 
     249 
     250class Subscribe2_List_Table extends WP_List_Table { 
     251    function __construct(){ 
     252        global $status, $page; 
     253 
     254        parent::__construct( array( 
     255            'singular'  => 'subscriber', 
     256            'plural'    => 'subscribers', 
     257            'ajax'      => false 
     258        ) ); 
     259    } 
     260 
     261    function column_default($item, $column_name){ 
     262        global $current_tab; 
     263        if ( $current_tab == 'registered' ) { 
     264            switch($column_name){ 
     265                case 'email': 
     266                    return $item[$column_name]; 
     267                default: 
     268                    return print_r($item,true); 
     269            } 
     270        } else { 
     271            switch($column_name){ 
     272                case 'email': 
     273                case 'date': 
     274                    return $item[$column_name]; 
     275                default: 
     276                    return print_r($item,true); 
     277            } 
     278        } 
     279    } 
     280 
     281    function column_email($item){ 
     282        global $current_tab; 
     283        if ( $current_tab == 'registered' ) { 
     284            $actions = array('edit' => sprintf('<a href="?page=%s&amp;email=%s">Edit</a>', 's2', $item['email'])); 
     285            return sprintf('%1$s %2$s', $item['email'], $this->row_actions($actions)); 
     286        } else { 
     287            global $mysubscribe2; 
     288            if ( '0' === $mysubscribe2->is_public($item['email']) ) { 
     289                return sprintf('<span style="color:#FF0000">%1$s</span>', $item['email']); 
     290            } else { 
     291                return sprintf('%1$s', $item['email']); 
     292            } 
     293        } 
     294    } 
     295 
     296    function column_cb($item){ 
     297        return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $item['email']); 
     298    } 
     299 
     300    function get_columns(){ 
     301        global $current_tab; 
     302        if ( $current_tab == 'registered' ) { 
     303            $columns = array('email' => 'Email'); 
     304        } else { 
     305            $columns = array( 
     306                'cb'        => '<input type="checkbox" />', 
     307                'email'     => 'Email', 
     308                'date'      => 'Date' 
     309            ); 
     310        } 
     311        return $columns; 
     312    } 
     313 
     314    function get_sortable_columns() { 
     315        global $current_tab; 
     316        if ( $current_tab == 'registered' ) { 
     317            $sortable_columns = array('email' => array('email', true)); 
     318        } else { 
     319            $sortable_columns = array( 
     320                'email' => array('email', true), 
     321                'date'  => array('date', false) 
     322            ); 
     323        } 
     324        return $sortable_columns; 
     325    } 
     326 
     327    function get_bulk_actions() { 
     328        global $current_tab; 
     329        if ( $current_tab == 'registered' ) { 
     330            return array(); 
     331        } else { 
     332            $actions = array( 
     333                'delete'    => __('Delete', 'subscribe2'), 
     334                'toggle'    => __('Toggle', 'subscribe2') 
     335            ); 
     336            return $actions; 
     337        } 
     338    } 
     339 
     340    function prepare_items() { 
     341 
     342        global $mysubscribe2; 
     343        if ( is_int($mysubscribe2->subscribe2_options['entries']) ) { 
     344            $per_page = $mysubscribe2->subscribe2_options['entries']; 
     345        } else { 
     346            $per_page = 25; 
     347        } 
     348 
     349        $columns = $this->get_columns(); 
     350        $hidden = array(); 
     351        $sortable = $this->get_sortable_columns(); 
     352        $this->_column_headers = array($columns, $hidden, $sortable); 
     353 
     354        global $mysubscribe2, $subscribers, $current_tab; 
     355        $data = array(); 
     356        if ( $current_tab == 'public' ) { 
     357            foreach($subscribers as $email) { 
     358                $data[] = array('email' => $email, 'date' => $mysubscribe2->signup_date($email)); 
     359            } 
     360        } else { 
     361            foreach($subscribers as $email) { 
     362                $data[] = array('email' => $email); 
     363            } 
     364        } 
     365 
     366        function usort_reorder($a,$b){ 
     367            $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'email'; 
     368            $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; 
     369            $result = strcmp($a[$orderby], $b[$orderby]); 
     370            return ($order==='asc') ? $result : -$result; 
     371        } 
     372        usort($data, 'usort_reorder'); 
     373 
     374        $current_page = $this->get_pagenum(); 
     375        $total_items = count($data); 
     376        $data = array_slice($data,(($current_page-1)*$per_page),$per_page); 
     377        $this->items = $data; 
     378 
     379        $this->set_pagination_args( array( 
     380            'total_items' => $total_items, 
     381            'per_page'    => $per_page, 
     382            'total_pages' => ceil($total_items/$per_page) 
     383        ) ); 
     384    } 
     385} 
    355386?> 
Note: See TracChangeset for help on using the changeset viewer.