PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/class-wp-ms-sites-list-table.php

https://bitbucket.org/jstroschein/wordpress-3.5.1-clean
PHP | 344 lines | 280 code | 50 blank | 14 comment | 59 complexity | ed5559dbff3c7b5b104e1ee7acd24ffb MD5 | raw file
  1. <?php
  2. /**
  3. * Sites List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_MS_Sites_List_Table extends WP_List_Table {
  11. function __construct( $args = array() ) {
  12. parent::__construct( array(
  13. 'plural' => 'sites',
  14. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  15. ) );
  16. }
  17. function ajax_user_can() {
  18. return current_user_can( 'manage_sites' );
  19. }
  20. function prepare_items() {
  21. global $s, $mode, $wpdb, $current_site;
  22. $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
  23. $per_page = $this->get_items_per_page( 'sites_network_per_page' );
  24. $pagenum = $this->get_pagenum();
  25. $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
  26. $wild = '';
  27. if ( false !== strpos($s, '*') ) {
  28. $wild = '%';
  29. $s = trim($s, '*');
  30. }
  31. $like_s = esc_sql( like_escape( $s ) );
  32. // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
  33. // to avoid expensive count queries.
  34. if ( !$s && wp_is_large_network() ) {
  35. if ( !isset($_REQUEST['orderby']) )
  36. $_GET['orderby'] = $_REQUEST['orderby'] = '';
  37. if ( !isset($_REQUEST['order']) )
  38. $_GET['order'] = $_REQUEST['order'] = 'DESC';
  39. }
  40. $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
  41. if ( empty($s) ) {
  42. // Nothing to do.
  43. } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
  44. preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
  45. preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
  46. preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
  47. // IPv4 address
  48. $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
  49. if ( !$reg_blog_ids )
  50. $reg_blog_ids = array( 0 );
  51. $query = "SELECT *
  52. FROM {$wpdb->blogs}
  53. WHERE site_id = '{$wpdb->siteid}'
  54. AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
  55. } else {
  56. if ( is_numeric($s) && empty( $wild ) ) {
  57. $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
  58. } elseif ( is_subdomain_install() ) {
  59. $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
  60. $blog_s .= $wild . '.' . $current_site->domain;
  61. $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
  62. } else {
  63. if ( $like_s != trim('/', $current_site->path) )
  64. $blog_s = $current_site->path . $like_s . $wild . '/';
  65. else
  66. $blog_s = $like_s;
  67. $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )";
  68. }
  69. }
  70. $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
  71. if ( $order_by == 'registered' ) {
  72. $query .= ' ORDER BY registered ';
  73. } elseif ( $order_by == 'lastupdated' ) {
  74. $query .= ' ORDER BY last_updated ';
  75. } elseif ( $order_by == 'blogname' ) {
  76. if ( is_subdomain_install() )
  77. $query .= ' ORDER BY domain ';
  78. else
  79. $query .= ' ORDER BY path ';
  80. } elseif ( $order_by == 'blog_id' ) {
  81. $query .= ' ORDER BY blog_id ';
  82. } else {
  83. $order_by = null;
  84. }
  85. if ( isset( $order_by ) ) {
  86. $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
  87. $query .= $order;
  88. }
  89. // Don't do an unbounded count on large networks
  90. if ( ! wp_is_large_network() )
  91. $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
  92. $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
  93. $this->items = $wpdb->get_results( $query, ARRAY_A );
  94. if ( wp_is_large_network() )
  95. $total = count($this->items);
  96. $this->set_pagination_args( array(
  97. 'total_items' => $total,
  98. 'per_page' => $per_page,
  99. ) );
  100. }
  101. function no_items() {
  102. _e( 'No sites found.' );
  103. }
  104. function get_bulk_actions() {
  105. $actions = array();
  106. if ( current_user_can( 'delete_sites' ) )
  107. $actions['delete'] = __( 'Delete' );
  108. $actions['spam'] = _x( 'Mark as Spam', 'site' );
  109. $actions['notspam'] = _x( 'Not Spam', 'site' );
  110. return $actions;
  111. }
  112. function pagination( $which ) {
  113. global $mode;
  114. parent::pagination( $which );
  115. if ( 'top' == $which )
  116. $this->view_switcher( $mode );
  117. }
  118. function get_columns() {
  119. $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
  120. $sites_columns = array(
  121. 'cb' => '<input type="checkbox" />',
  122. 'blogname' => $blogname_columns,
  123. 'lastupdated' => __( 'Last Updated' ),
  124. 'registered' => _x( 'Registered', 'site' ),
  125. 'users' => __( 'Users' )
  126. );
  127. if ( has_filter( 'wpmublogsaction' ) )
  128. $sites_columns['plugins'] = __( 'Actions' );
  129. $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
  130. return $sites_columns;
  131. }
  132. function get_sortable_columns() {
  133. return array(
  134. 'blogname' => 'blogname',
  135. 'lastupdated' => 'lastupdated',
  136. 'registered' => 'blog_id',
  137. );
  138. }
  139. function display_rows() {
  140. global $current_site, $mode;
  141. $status_list = array(
  142. 'archived' => array( 'site-archived', __( 'Archived' ) ),
  143. 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
  144. 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
  145. 'mature' => array( 'site-mature', __( 'Mature' ) )
  146. );
  147. $class = '';
  148. foreach ( $this->items as $blog ) {
  149. $class = ( 'alternate' == $class ) ? '' : 'alternate';
  150. reset( $status_list );
  151. $blog_states = array();
  152. foreach ( $status_list as $status => $col ) {
  153. if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
  154. $class = $col[0];
  155. $blog_states[] = $col[1];
  156. }
  157. }
  158. $blog_state = '';
  159. if ( ! empty( $blog_states ) ) {
  160. $state_count = count( $blog_states );
  161. $i = 0;
  162. $blog_state .= ' - ';
  163. foreach ( $blog_states as $state ) {
  164. ++$i;
  165. ( $i == $state_count ) ? $sep = '' : $sep = ', ';
  166. $blog_state .= "<span class='post-state'>$state$sep</span>";
  167. }
  168. }
  169. echo "<tr class='$class'>";
  170. $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
  171. list( $columns, $hidden ) = $this->get_column_info();
  172. foreach ( $columns as $column_name => $column_display_name ) {
  173. $style = '';
  174. if ( in_array( $column_name, $hidden ) )
  175. $style = ' style="display:none;"';
  176. switch ( $column_name ) {
  177. case 'cb': ?>
  178. <th scope="row" class="check-column">
  179. <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
  180. <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
  181. </th>
  182. <?php
  183. break;
  184. case 'id':?>
  185. <th valign="top" scope="row">
  186. <?php echo $blog['blog_id'] ?>
  187. </th>
  188. <?php
  189. break;
  190. case 'blogname':
  191. echo "<td class='column-$column_name $column_name'$style>"; ?>
  192. <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
  193. <?php
  194. if ( 'list' != $mode ) {
  195. switch_to_blog( $blog['blog_id'] );
  196. echo '<p>' . sprintf( _x( '%1$s &#8211; <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>';
  197. restore_current_blog();
  198. }
  199. // Preordered.
  200. $actions = array(
  201. 'edit' => '', 'backend' => '',
  202. 'activate' => '', 'deactivate' => '',
  203. 'archive' => '', 'unarchive' => '',
  204. 'spam' => '', 'unspam' => '',
  205. 'delete' => '',
  206. 'visit' => '',
  207. );
  208. $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
  209. $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
  210. if ( $current_site->blog_id != $blog['blog_id'] ) {
  211. if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
  212. $actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>';
  213. else
  214. $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span>';
  215. if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
  216. $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Unarchive' ) . '</a></span>';
  217. else
  218. $actions['archive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
  219. if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
  220. $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
  221. else
  222. $actions['spam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
  223. if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
  224. $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Delete' ) . '</a></span>';
  225. }
  226. $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
  227. $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
  228. echo $this->row_actions( $actions );
  229. ?>
  230. </td>
  231. <?php
  232. break;
  233. case 'lastupdated':
  234. echo "<td valign='top' class='$column_name column-$column_name'$style>";
  235. if ( 'list' == $mode )
  236. $date = 'Y/m/d';
  237. else
  238. $date = 'Y/m/d \<\b\r \/\> g:i:s a';
  239. echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
  240. </td>
  241. <?php
  242. break;
  243. case 'registered':
  244. echo "<td valign='top' class='$column_name column-$column_name'$style>";
  245. if ( $blog['registered'] == '0000-00-00 00:00:00' )
  246. echo '&#x2014;';
  247. else
  248. echo mysql2date( $date, $blog['registered'] );
  249. ?>
  250. </td>
  251. <?php
  252. break;
  253. case 'users':
  254. echo "<td valign='top' class='$column_name column-$column_name'$style>";
  255. $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
  256. if ( is_array( $blogusers ) ) {
  257. $blogusers_warning = '';
  258. if ( count( $blogusers ) > 5 ) {
  259. $blogusers = array_slice( $blogusers, 0, 5 );
  260. $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
  261. }
  262. foreach ( $blogusers as $user_object ) {
  263. echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
  264. if ( 'list' != $mode )
  265. echo '( ' . $user_object->user_email . ' )';
  266. echo '<br />';
  267. }
  268. if ( $blogusers_warning != '' )
  269. echo '<strong>' . $blogusers_warning . '</strong><br />';
  270. }
  271. ?>
  272. </td>
  273. <?php
  274. break;
  275. case 'plugins': ?>
  276. <?php if ( has_filter( 'wpmublogsaction' ) ) {
  277. echo "<td valign='top' class='$column_name column-$column_name'$style>";
  278. do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
  279. </td>
  280. <?php }
  281. break;
  282. default:
  283. echo "<td class='$column_name column-$column_name'$style>";
  284. do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
  285. echo "</td>";
  286. break;
  287. }
  288. }
  289. ?>
  290. </tr>
  291. <?php
  292. }
  293. }
  294. }