PageRenderTime 51ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

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