PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-plugin-install-list-table.php

https://bitbucket.org/jstroschein/wordpress-3.5.1-clean
PHP | 238 lines | 181 code | 43 blank | 14 comment | 23 complexity | ae416f1ac0c1f21332005488b0060b98 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Installer List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_Plugin_Install_List_Table extends WP_List_Table {
  11. function ajax_user_can() {
  12. return current_user_can('install_plugins');
  13. }
  14. function prepare_items() {
  15. include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
  16. global $tabs, $tab, $paged, $type, $term;
  17. wp_reset_vars( array( 'tab' ) );
  18. $paged = $this->get_pagenum();
  19. $per_page = 30;
  20. // These are the tabs which are shown on the page
  21. $tabs = array();
  22. $tabs['dashboard'] = __( 'Search' );
  23. if ( 'search' == $tab )
  24. $tabs['search'] = __( 'Search Results' );
  25. $tabs['upload'] = __( 'Upload' );
  26. $tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
  27. $tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
  28. $tabs['new'] = _x( 'Newest', 'Plugin Installer' );
  29. $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
  30. $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
  31. $tabs = apply_filters( 'install_plugins_tabs', $tabs );
  32. $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
  33. // If a non-valid menu tab has been selected, And its not a non-menu action.
  34. if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
  35. $tab = key( $tabs );
  36. $args = array( 'page' => $paged, 'per_page' => $per_page );
  37. switch ( $tab ) {
  38. case 'search':
  39. $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
  40. $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  41. switch ( $type ) {
  42. case 'tag':
  43. $args['tag'] = sanitize_title_with_dashes( $term );
  44. break;
  45. case 'term':
  46. $args['search'] = $term;
  47. break;
  48. case 'author':
  49. $args['author'] = $term;
  50. break;
  51. }
  52. add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 );
  53. break;
  54. case 'featured':
  55. case 'popular':
  56. case 'new':
  57. $args['browse'] = $tab;
  58. break;
  59. case 'favorites':
  60. $user = isset( $_GET['user'] ) ? stripslashes( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
  61. update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
  62. if ( $user )
  63. $args['user'] = $user;
  64. else
  65. $args = false;
  66. add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
  67. break;
  68. default:
  69. $args = false;
  70. }
  71. if ( !$args )
  72. return;
  73. $api = plugins_api( 'query_plugins', $args );
  74. if ( is_wp_error( $api ) )
  75. wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
  76. $this->items = $api->plugins;
  77. $this->set_pagination_args( array(
  78. 'total_items' => $api->info['results'],
  79. 'per_page' => $per_page,
  80. ) );
  81. }
  82. function no_items() {
  83. _e( 'No plugins match your request.' );
  84. }
  85. function get_views() {
  86. global $tabs, $tab;
  87. $display_tabs = array();
  88. foreach ( (array) $tabs as $action => $text ) {
  89. $class = ( $action == $tab ) ? ' class="current"' : '';
  90. $href = self_admin_url('plugin-install.php?tab=' . $action);
  91. $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
  92. }
  93. return $display_tabs;
  94. }
  95. function display_tablenav( $which ) {
  96. if ( 'top' == $which ) { ?>
  97. <div class="tablenav top">
  98. <div class="alignleft actions">
  99. <?php do_action( 'install_plugins_table_header' ); ?>
  100. </div>
  101. <?php $this->pagination( $which ); ?>
  102. <br class="clear" />
  103. </div>
  104. <?php } else { ?>
  105. <div class="tablenav bottom">
  106. <?php $this->pagination( $which ); ?>
  107. <br class="clear" />
  108. </div>
  109. <?php
  110. }
  111. }
  112. function get_table_classes() {
  113. extract( $this->_args );
  114. return array( 'widefat', $plural );
  115. }
  116. function get_columns() {
  117. return array(
  118. 'name' => _x( 'Name', 'plugin name' ),
  119. 'version' => __( 'Version' ),
  120. 'rating' => __( 'Rating' ),
  121. 'description' => __( 'Description' ),
  122. );
  123. }
  124. function display_rows() {
  125. $plugins_allowedtags = array(
  126. 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
  127. 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
  128. 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
  129. 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
  130. );
  131. list( $columns, $hidden ) = $this->get_column_info();
  132. $style = array();
  133. foreach ( $columns as $column_name => $column_display_name ) {
  134. $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
  135. }
  136. foreach ( (array) $this->items as $plugin ) {
  137. if ( is_object( $plugin ) )
  138. $plugin = (array) $plugin;
  139. $title = wp_kses( $plugin['name'], $plugins_allowedtags );
  140. //Limit description to 400char, and remove any HTML.
  141. $description = strip_tags( $plugin['description'] );
  142. if ( strlen( $description ) > 400 )
  143. $description = mb_substr( $description, 0, 400 ) . '&#8230;';
  144. //remove any trailing entities
  145. $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
  146. //strip leading/trailing & multiple consecutive lines
  147. $description = trim( $description );
  148. $description = preg_replace( "|(\r?\n)+|", "\n", $description );
  149. //\n => <br>
  150. $description = nl2br( $description );
  151. $version = wp_kses( $plugin['version'], $plugins_allowedtags );
  152. $name = strip_tags( $title . ' ' . $version );
  153. $author = $plugin['author'];
  154. if ( ! empty( $plugin['author'] ) )
  155. $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
  156. $author = wp_kses( $author, $plugins_allowedtags );
  157. $action_links = array();
  158. $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
  159. '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
  160. esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
  161. if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
  162. $status = install_plugin_install_status( $plugin );
  163. switch ( $status['status'] ) {
  164. case 'install':
  165. if ( $status['url'] )
  166. $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
  167. break;
  168. case 'update_available':
  169. if ( $status['url'] )
  170. $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
  171. break;
  172. case 'latest_installed':
  173. case 'newer_installed':
  174. $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
  175. break;
  176. }
  177. }
  178. $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
  179. ?>
  180. <tr>
  181. <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong>
  182. <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
  183. </td>
  184. <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td>
  185. <td class="vers column-rating"<?php echo $style['rating']; ?>>
  186. <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'] ), number_format_i18n( $plugin['num_ratings'] ) ) ?>">
  187. <div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin['rating'] ) ); ?>px"></div>
  188. </div>
  189. </td>
  190. <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>
  191. </tr>
  192. <?php
  193. }
  194. }
  195. }