PageRenderTime 25ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/skudatech/af-sample-wordpress
PHP | 361 lines | 274 code | 78 blank | 9 comment | 63 complexity | 490d8537a651583d521e401750f2cef4 MD5 | raw file
  1. <?php
  2. /**
  3. * MS Themes List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_MS_Themes_List_Table extends WP_List_Table {
  11. var $site_id;
  12. var $is_site_themes;
  13. function __construct() {
  14. global $status, $page;
  15. $default_status = get_user_option( 'themes_last_view' );
  16. if ( empty( $default_status ) )
  17. $default_status = 'all';
  18. $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : $default_status;
  19. if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search' ) ) )
  20. $status = 'all';
  21. if ( $status != $default_status && 'search' != $status )
  22. update_user_meta( get_current_user_id(), 'themes_last_view', $status );
  23. $page = $this->get_pagenum();
  24. $screen = get_current_screen();
  25. $this->is_site_themes = ( 'site-themes-network' == $screen->id ) ? true : false;
  26. if ( $this->is_site_themes )
  27. $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  28. parent::__construct( array(
  29. 'plural' => 'themes'
  30. ) );
  31. }
  32. function get_table_classes() {
  33. return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes
  34. }
  35. function ajax_user_can() {
  36. $menu_perms = get_site_option( 'menu_items', array() );
  37. if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
  38. return false;
  39. if ( $this->is_site_themes && !current_user_can('manage_sites') )
  40. return false;
  41. elseif ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
  42. return false;
  43. return true;
  44. }
  45. function prepare_items() {
  46. global $status, $themes, $totals, $page, $orderby, $order, $s;
  47. wp_reset_vars( array( 'orderby', 'order', 's' ) );
  48. $themes = array(
  49. 'all' => apply_filters( 'all_themes', get_themes() ),
  50. 'search' => array(),
  51. 'enabled' => array(),
  52. 'disabled' => array(),
  53. 'upgrade' => array()
  54. );
  55. $site_allowed_themes = get_site_allowed_themes();
  56. if ( !$this->is_site_themes ) {
  57. $allowed_themes = $site_allowed_themes;
  58. $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
  59. } else {
  60. $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
  61. $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
  62. }
  63. $current = get_site_transient( 'update_themes' );
  64. foreach ( (array) $themes['all'] as $key => $theme ) {
  65. $theme_key = $theme['Stylesheet'];
  66. if ( isset( $allowed_themes [ $theme_key ] ) ) {
  67. $themes['all'][$key]['enabled'] = true;
  68. $themes['enabled'][$key] = $themes['all'][$key];
  69. }
  70. else {
  71. $themes['all'][$key]['enabled'] = false;
  72. $themes['disabled'][$key] = $themes['all'][$key];
  73. }
  74. if ( isset( $current->response[ $theme['Template'] ] ) )
  75. $themes['upgrade'][$key] = $themes['all'][$key];
  76. if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
  77. unset( $themes['all'][$key] );
  78. unset( $themes['enabled'][$key] );
  79. unset( $themes['disabled'][$key] );
  80. }
  81. }
  82. if ( !current_user_can( 'update_themes' ) || $this->is_site_themes )
  83. $themes['upgrade'] = array();
  84. if ( $s ) {
  85. $status = 'search';
  86. $themes['search'] = array_filter( $themes['all'], array( &$this, '_search_callback' ) );
  87. }
  88. $totals = array();
  89. foreach ( $themes as $type => $list )
  90. $totals[ $type ] = count( $list );
  91. if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
  92. $status = 'all';
  93. $this->items = $themes[ $status ];
  94. $total_this_page = $totals[ $status ];
  95. if ( $orderby ) {
  96. $orderby = ucfirst( $orderby );
  97. $order = strtoupper( $order );
  98. uasort( $this->items, array( &$this, '_order_callback' ) );
  99. }
  100. $start = ( $page - 1 ) * $themes_per_page;
  101. if ( $total_this_page > $themes_per_page )
  102. $this->items = array_slice( $this->items, $start, $themes_per_page );
  103. $this->set_pagination_args( array(
  104. 'total_items' => $total_this_page,
  105. 'per_page' => $themes_per_page,
  106. ) );
  107. }
  108. function _search_callback( $theme ) {
  109. static $term;
  110. if ( is_null( $term ) )
  111. $term = stripslashes( $_REQUEST['s'] );
  112. $search_fields = array( 'Name', 'Title', 'Description', 'Author', 'Author Name', 'Author URI', 'Template', 'Stylesheet' );
  113. foreach ( $search_fields as $field )
  114. if ( stripos( $theme[ $field ], $term ) !== false )
  115. return true;
  116. return false;
  117. }
  118. function _order_callback( $theme_a, $theme_b ) {
  119. global $orderby, $order;
  120. $a = $theme_a[$orderby];
  121. $b = $theme_b[$orderby];
  122. if ( $a == $b )
  123. return 0;
  124. if ( 'DESC' == $order )
  125. return ( $a < $b ) ? 1 : -1;
  126. else
  127. return ( $a < $b ) ? -1 : 1;
  128. }
  129. function no_items() {
  130. global $themes;
  131. if ( !empty( $themes['all'] ) )
  132. _e( 'No themes found.' );
  133. else
  134. _e( 'You do not appear to have any themes available at this time.' );
  135. }
  136. function get_columns() {
  137. global $status;
  138. return array(
  139. 'cb' => '<input type="checkbox" />',
  140. 'name' => __( 'Theme' ),
  141. 'description' => __( 'Description' ),
  142. );
  143. }
  144. function get_sortable_columns() {
  145. return array(
  146. 'name' => 'name',
  147. );
  148. }
  149. function get_views() {
  150. global $totals, $status;
  151. $status_links = array();
  152. foreach ( $totals as $type => $count ) {
  153. if ( !$count )
  154. continue;
  155. switch ( $type ) {
  156. case 'all':
  157. $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
  158. break;
  159. case 'enabled':
  160. $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
  161. break;
  162. case 'disabled':
  163. $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
  164. break;
  165. case 'upgrade':
  166. $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
  167. break;
  168. }
  169. if ( $this->is_site_themes )
  170. $url = 'site-themes.php?id=' . $this->site_id;
  171. else
  172. $url = 'themes.php';
  173. if ( 'search' != $type ) {
  174. $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
  175. esc_url( add_query_arg('theme_status', $type, $url) ),
  176. ( $type == $status ) ? ' class="current"' : '',
  177. sprintf( $text, number_format_i18n( $count ) )
  178. );
  179. }
  180. }
  181. return $status_links;
  182. }
  183. function get_bulk_actions() {
  184. global $status;
  185. $actions = array();
  186. if ( 'enabled' != $status )
  187. $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
  188. if ( 'disabled' != $status )
  189. $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
  190. if ( ! $this->is_site_themes ) {
  191. if ( current_user_can( 'delete_themes' ) )
  192. $actions['delete-selected'] = __( 'Delete' );
  193. if ( current_user_can( 'update_themes' ) )
  194. $actions['update-selected'] = __( 'Update' );
  195. }
  196. return $actions;
  197. }
  198. function bulk_actions( $which ) {
  199. global $status;
  200. parent::bulk_actions( $which );
  201. }
  202. function current_action() {
  203. return parent::current_action();
  204. }
  205. function display_rows() {
  206. foreach ( $this->items as $key => $theme )
  207. $this->single_row( $key, $theme );
  208. }
  209. function single_row( $key, $theme ) {
  210. global $status, $page, $s;
  211. $context = $status;
  212. if ( $this->is_site_themes )
  213. $url = "site-themes.php?id={$this->site_id}&amp;";
  214. else
  215. $url = 'themes.php?';
  216. // preorder
  217. $actions = array(
  218. 'enable' => '',
  219. 'disable' => '',
  220. 'edit' => '',
  221. 'delete' => ''
  222. );
  223. $theme_key = $theme['Stylesheet'];
  224. if ( empty( $theme['enabled'] ) )
  225. $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
  226. else
  227. $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'disable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
  228. if ( current_user_can('edit_themes') )
  229. $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . urlencode( $theme['Name'] )) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
  230. if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
  231. $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
  232. $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );
  233. $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context );
  234. $class = empty( $theme['enabled'] ) ? 'inactive' : 'active';
  235. $checkbox_id = "checkbox_" . md5($theme['Name']);
  236. $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme['Name'] . "</label>";
  237. $description = '<p>' . $theme['Description'] . '</p>';
  238. $theme_name = $theme['Name'];
  239. $id = sanitize_title( $theme_name );
  240. echo "<tr id='$id' class='$class'>";
  241. list( $columns, $hidden ) = $this->get_column_info();
  242. foreach ( $columns as $column_name => $column_display_name ) {
  243. $style = '';
  244. if ( in_array( $column_name, $hidden ) )
  245. $style = ' style="display:none;"';
  246. switch ( $column_name ) {
  247. case 'cb':
  248. echo "<th scope='row' class='check-column'>$checkbox</th>";
  249. break;
  250. case 'name':
  251. echo "<td class='theme-title'$style><strong>$theme_name</strong>";
  252. echo $this->row_actions( $actions, true );
  253. echo "</td>";
  254. break;
  255. case 'description':
  256. echo "<td class='column-description desc'$style>
  257. <div class='theme-description'>$description</div>
  258. <div class='$class second theme-version-author-uri'>";
  259. $theme_meta = array();
  260. if ( !empty( $theme['Version'] ) )
  261. $theme_meta[] = sprintf( __( 'Version %s' ), $theme['Version'] );
  262. if ( !empty( $theme['Author'] ) )
  263. $theme_meta[] = sprintf( __( 'By %s' ), $theme['Author'] );
  264. if ( !empty( $theme['Theme URI'] ) )
  265. $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
  266. $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
  267. echo implode( ' | ', $theme_meta );
  268. echo "</div></td>";
  269. break;
  270. default:
  271. echo "<td class='$column_name column-$column_name'$style>";
  272. do_action( 'manage_themes_custom_column', $column_name, $theme_key, $theme );
  273. echo "</td>";
  274. }
  275. }
  276. echo "</tr>";
  277. if ( $this->is_site_themes )
  278. remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' );
  279. do_action( 'after_theme_row', $theme_key, $theme, $status );
  280. do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status );
  281. }
  282. }
  283. ?>