PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/akeda/bmw-id-hris
PHP | 388 lines | 283 code | 51 blank | 54 comment | 60 complexity | 370aff590ea33232d99cfabe4a0a1307 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;
  22. $current_site = get_current_site();
  23. $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
  24. $per_page = $this->get_items_per_page( 'sites_network_per_page' );
  25. $pagenum = $this->get_pagenum();
  26. $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : '';
  27. $wild = '';
  28. if ( false !== strpos($s, '*') ) {
  29. $wild = '%';
  30. $s = trim($s, '*');
  31. }
  32. $like_s = esc_sql( like_escape( $s ) );
  33. // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
  34. // to avoid expensive count queries.
  35. if ( !$s && wp_is_large_network() ) {
  36. if ( !isset($_REQUEST['orderby']) )
  37. $_GET['orderby'] = $_REQUEST['orderby'] = '';
  38. if ( !isset($_REQUEST['order']) )
  39. $_GET['order'] = $_REQUEST['order'] = 'DESC';
  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]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
  45. preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
  46. preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
  47. preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
  48. // IPv4 address
  49. $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
  50. if ( !$reg_blog_ids )
  51. $reg_blog_ids = array( 0 );
  52. $query = "SELECT *
  53. FROM {$wpdb->blogs}
  54. WHERE site_id = '{$wpdb->siteid}'
  55. AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
  56. } else {
  57. if ( is_numeric($s) && empty( $wild ) ) {
  58. $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
  59. } elseif ( is_subdomain_install() ) {
  60. $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
  61. $blog_s .= $wild . '.' . $current_site->domain;
  62. $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
  63. } else {
  64. if ( $like_s != trim('/', $current_site->path) )
  65. $blog_s = $current_site->path . $like_s . $wild . '/';
  66. else
  67. $blog_s = $like_s;
  68. $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )";
  69. }
  70. }
  71. $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
  72. if ( $order_by == 'registered' ) {
  73. $query .= ' ORDER BY registered ';
  74. } elseif ( $order_by == 'lastupdated' ) {
  75. $query .= ' ORDER BY last_updated ';
  76. } elseif ( $order_by == 'blogname' ) {
  77. if ( is_subdomain_install() )
  78. $query .= ' ORDER BY domain ';
  79. else
  80. $query .= ' ORDER BY path ';
  81. } elseif ( $order_by == 'blog_id' ) {
  82. $query .= ' ORDER BY blog_id ';
  83. } else {
  84. $order_by = null;
  85. }
  86. if ( isset( $order_by ) ) {
  87. $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
  88. $query .= $order;
  89. }
  90. // Don't do an unbounded count on large networks
  91. if ( ! wp_is_large_network() )
  92. $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
  93. $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
  94. $this->items = $wpdb->get_results( $query, ARRAY_A );
  95. if ( wp_is_large_network() )
  96. $total = count($this->items);
  97. $this->set_pagination_args( array(
  98. 'total_items' => $total,
  99. 'per_page' => $per_page,
  100. ) );
  101. }
  102. function no_items() {
  103. _e( 'No sites found.' );
  104. }
  105. function get_bulk_actions() {
  106. $actions = array();
  107. if ( current_user_can( 'delete_sites' ) )
  108. $actions['delete'] = __( 'Delete' );
  109. $actions['spam'] = _x( 'Mark as Spam', 'site' );
  110. $actions['notspam'] = _x( 'Not Spam', 'site' );
  111. return $actions;
  112. }
  113. function pagination( $which ) {
  114. global $mode;
  115. parent::pagination( $which );
  116. if ( 'top' == $which )
  117. $this->view_switcher( $mode );
  118. }
  119. function get_columns() {
  120. $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
  121. $sites_columns = array(
  122. 'cb' => '<input type="checkbox" />',
  123. 'blogname' => $blogname_columns,
  124. 'lastupdated' => __( 'Last Updated' ),
  125. 'registered' => _x( 'Registered', 'site' ),
  126. 'users' => __( 'Users' )
  127. );
  128. if ( has_filter( 'wpmublogsaction' ) )
  129. $sites_columns['plugins'] = __( 'Actions' );
  130. /**
  131. * Filter the displayed site columns in Sites list table.
  132. *
  133. * @since MU
  134. *
  135. * @param array $sites_columns An array of displayed site columns. Default 'cb',
  136. * 'blogname', 'lastupdated', 'registered', 'users'.
  137. */
  138. $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
  139. return $sites_columns;
  140. }
  141. function get_sortable_columns() {
  142. return array(
  143. 'blogname' => 'blogname',
  144. 'lastupdated' => 'lastupdated',
  145. 'registered' => 'blog_id',
  146. );
  147. }
  148. function display_rows() {
  149. global $mode;
  150. $status_list = array(
  151. 'archived' => array( 'site-archived', __( 'Archived' ) ),
  152. 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
  153. 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
  154. 'mature' => array( 'site-mature', __( 'Mature' ) )
  155. );
  156. $class = '';
  157. foreach ( $this->items as $blog ) {
  158. $class = ( 'alternate' == $class ) ? '' : 'alternate';
  159. reset( $status_list );
  160. $blog_states = array();
  161. foreach ( $status_list as $status => $col ) {
  162. if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
  163. $class = $col[0];
  164. $blog_states[] = $col[1];
  165. }
  166. }
  167. $blog_state = '';
  168. if ( ! empty( $blog_states ) ) {
  169. $state_count = count( $blog_states );
  170. $i = 0;
  171. $blog_state .= ' - ';
  172. foreach ( $blog_states as $state ) {
  173. ++$i;
  174. ( $i == $state_count ) ? $sep = '' : $sep = ', ';
  175. $blog_state .= "<span class='post-state'>$state$sep</span>";
  176. }
  177. }
  178. echo "<tr class='$class'>";
  179. $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path'];
  180. list( $columns, $hidden ) = $this->get_column_info();
  181. foreach ( $columns as $column_name => $column_display_name ) {
  182. $style = '';
  183. if ( in_array( $column_name, $hidden ) )
  184. $style = ' style="display:none;"';
  185. switch ( $column_name ) {
  186. case 'cb': ?>
  187. <th scope="row" class="check-column">
  188. <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?>
  189. <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label>
  190. <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
  191. <?php endif; ?>
  192. </th>
  193. <?php
  194. break;
  195. case 'id':?>
  196. <th scope="row">
  197. <?php echo $blog['blog_id'] ?>
  198. </th>
  199. <?php
  200. break;
  201. case 'blogname':
  202. echo "<td class='column-$column_name $column_name'$style>"; ?>
  203. <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
  204. <?php
  205. if ( 'list' != $mode ) {
  206. switch_to_blog( $blog['blog_id'] );
  207. 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>';
  208. restore_current_blog();
  209. }
  210. // Preordered.
  211. $actions = array(
  212. 'edit' => '', 'backend' => '',
  213. 'activate' => '', 'deactivate' => '',
  214. 'archive' => '', 'unarchive' => '',
  215. 'spam' => '', 'unspam' => '',
  216. 'delete' => '',
  217. 'visit' => '',
  218. );
  219. $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
  220. $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
  221. if ( get_current_site()->blog_id != $blog['blog_id'] ) {
  222. if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
  223. $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>';
  224. else
  225. $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>';
  226. if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
  227. $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>';
  228. else
  229. $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>';
  230. if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
  231. $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>';
  232. else
  233. $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>';
  234. if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
  235. $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>';
  236. }
  237. $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
  238. /**
  239. * Filter the action links displayed for each site in the Sites list table.
  240. *
  241. * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
  242. * default for each site. The site's status determines whether to show the
  243. * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
  244. * 'Not Spam' or 'Spam' link for each site.
  245. *
  246. * @since 3.1.0
  247. *
  248. * @param array $actions An array of action links to be displayed.
  249. * @param int $blog_id The site ID.
  250. * @param string $blogname Site path, formatted depending on whether it is a sub-domain
  251. * or subdirectory multisite install.
  252. */
  253. $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
  254. echo $this->row_actions( $actions );
  255. ?>
  256. </td>
  257. <?php
  258. break;
  259. case 'lastupdated':
  260. echo "<td class='$column_name column-$column_name'$style>";
  261. if ( 'list' == $mode )
  262. $date = 'Y/m/d';
  263. else
  264. $date = 'Y/m/d \<\b\r \/\> g:i:s a';
  265. echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
  266. </td>
  267. <?php
  268. break;
  269. case 'registered':
  270. echo "<td class='$column_name column-$column_name'$style>";
  271. if ( $blog['registered'] == '0000-00-00 00:00:00' )
  272. echo '&#x2014;';
  273. else
  274. echo mysql2date( $date, $blog['registered'] );
  275. ?>
  276. </td>
  277. <?php
  278. break;
  279. case 'users':
  280. echo "<td class='$column_name column-$column_name'$style>";
  281. $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
  282. if ( is_array( $blogusers ) ) {
  283. $blogusers_warning = '';
  284. if ( count( $blogusers ) > 5 ) {
  285. $blogusers = array_slice( $blogusers, 0, 5 );
  286. $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
  287. }
  288. foreach ( $blogusers as $user_object ) {
  289. echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
  290. if ( 'list' != $mode )
  291. echo '( ' . $user_object->user_email . ' )';
  292. echo '<br />';
  293. }
  294. if ( $blogusers_warning != '' )
  295. echo '<strong>' . $blogusers_warning . '</strong><br />';
  296. }
  297. ?>
  298. </td>
  299. <?php
  300. break;
  301. case 'plugins': ?>
  302. <?php if ( has_filter( 'wpmublogsaction' ) ) {
  303. echo "<td class='$column_name column-$column_name'$style>";
  304. /**
  305. * Fires inside the auxiliary 'Actions' column of the Sites list table.
  306. *
  307. * By default this column is hidden unless something is hooked to the action.
  308. *
  309. * @since MU
  310. *
  311. * @param int $blog_id The site ID.
  312. */
  313. do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
  314. </td>
  315. <?php }
  316. break;
  317. default:
  318. echo "<td class='$column_name column-$column_name'$style>";
  319. /**
  320. * Fires for each registered custom column in the Sites list table.
  321. *
  322. * @since 3.1.0
  323. *
  324. * @param string $column_name The name of the column to display.
  325. * @param int $blog_id The site ID.
  326. */
  327. do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
  328. echo "</td>";
  329. break;
  330. }
  331. }
  332. ?>
  333. </tr>
  334. <?php
  335. }
  336. }
  337. }