wp/wp-admin/includes/class-wp-plugin-install-list-table.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     7  * @since 3.1.0
     7  * @since 3.1.0
     8  * @access private
     8  * @access private
     9  */
     9  */
    10 class WP_Plugin_Install_List_Table extends WP_List_Table {
    10 class WP_Plugin_Install_List_Table extends WP_List_Table {
    11 
    11 
    12 	function ajax_user_can() {
    12 	public $order = 'ASC';
       
    13 	public $orderby = null;
       
    14 	public $groups = array();
       
    15 
       
    16 	private $error;
       
    17 
       
    18 	public function ajax_user_can() {
    13 		return current_user_can('install_plugins');
    19 		return current_user_can('install_plugins');
    14 	}
    20 	}
    15 
    21 
    16 	function prepare_items() {
    22 	/**
       
    23 	 * Return a list of slugs of installed plugins, if known.
       
    24 	 *
       
    25 	 * Uses the transient data from the updates API to determine the slugs of
       
    26 	 * known installed plugins. This might be better elsewhere, perhaps even
       
    27 	 * within get_plugins().
       
    28 	 *
       
    29 	 * @since 4.0.0
       
    30 	 * @access protected
       
    31 	 */
       
    32 	protected function get_installed_plugin_slugs() {
       
    33 		$slugs = array();
       
    34 
       
    35 		$plugin_info = get_site_transient( 'update_plugins' );
       
    36 		if ( isset( $plugin_info->no_update ) ) {
       
    37 			foreach ( $plugin_info->no_update as $plugin ) {
       
    38 				$slugs[] = $plugin->slug;
       
    39 			}
       
    40 		}
       
    41 
       
    42 		if ( isset( $plugin_info->response ) ) {
       
    43 			foreach ( $plugin_info->response as $plugin ) {
       
    44 				$slugs[] = $plugin->slug;
       
    45 			}
       
    46 		}
       
    47 
       
    48 		return $slugs;
       
    49 	}
       
    50 
       
    51 	public function prepare_items() {
    17 		include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    52 		include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    18 
    53 
    19 		global $tabs, $tab, $paged, $type, $term;
    54 		global $tabs, $tab, $paged, $type, $term;
    20 
    55 
    21 		wp_reset_vars( array( 'tab' ) );
    56 		wp_reset_vars( array( 'tab' ) );
    24 
    59 
    25 		$per_page = 30;
    60 		$per_page = 30;
    26 
    61 
    27 		// These are the tabs which are shown on the page
    62 		// These are the tabs which are shown on the page
    28 		$tabs = array();
    63 		$tabs = array();
    29 		$tabs['dashboard'] = __( 'Search' );
    64 
    30 		if ( 'search' == $tab )
    65 		if ( 'search' == $tab )
    31 			$tabs['search']	= __( 'Search Results' );
    66 			$tabs['search']	= __( 'Search Results' );
    32 		$tabs['upload']    = __( 'Upload' );
       
    33 		$tabs['featured']  = _x( 'Featured', 'Plugin Installer' );
    67 		$tabs['featured']  = _x( 'Featured', 'Plugin Installer' );
    34 		$tabs['popular']   = _x( 'Popular', 'Plugin Installer' );
    68 		$tabs['popular']   = _x( 'Popular', 'Plugin Installer' );
    35 		$tabs['new']       = _x( 'Newest', 'Plugin Installer' );
    69 		$tabs['recommended']   = _x( 'Recommended', 'Plugin Installer' );
    36 		$tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
    70 		$tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
    37 
    71 		if ( $tab === 'beta' || false !== strpos( $GLOBALS['wp_version'], '-' ) ) {
    38 		$nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
    72 			$tabs['beta']      = _x( 'Beta Testing', 'Plugin Installer' );
       
    73 		}
       
    74 		if ( current_user_can( 'upload_plugins' ) ) {
       
    75 			// No longer a real tab. Here for filter compatibility.
       
    76 			// Gets skipped in get_views().
       
    77 			$tabs['upload'] = __( 'Upload Plugin' );
       
    78 		}
       
    79 
       
    80 		$nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
    39 
    81 
    40 		/**
    82 		/**
    41 		 * Filter the tabs shown on the Plugin Install screen.
    83 		 * Filter the tabs shown on the Plugin Install screen.
    42 		 *
    84 		 *
    43 		 * @since 2.7.0
    85 		 * @since 2.7.0
    44 		 *
    86 		 *
    45 		 * @param array $tabs The tabs shown on the Plugin Install screen. Defaults are 'dashboard', 'search',
    87 		 * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
    46 		 *                    'upload', 'featured', 'popular', 'new', and 'favorites'.
    88 		 *                    'recommended', 'favorites', and 'upload'.
    47 		 */
    89 		 */
    48 		$tabs = apply_filters( 'install_plugins_tabs', $tabs );
    90 		$tabs = apply_filters( 'install_plugins_tabs', $tabs );
    49 
    91 
    50 		/**
    92 		/**
    51 		 * Filter tabs not associated with a menu item on the Plugin Install screen.
    93 		 * Filter tabs not associated with a menu item on the Plugin Install screen.
    58 
   100 
    59 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
   101 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
    60 		if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
   102 		if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    61 			$tab = key( $tabs );
   103 			$tab = key( $tabs );
    62 
   104 
    63 		$args = array( 'page' => $paged, 'per_page' => $per_page );
   105 		$args = array(
       
   106 			'page' => $paged,
       
   107 			'per_page' => $per_page,
       
   108 			'fields' => array(
       
   109 				'last_updated' => true,
       
   110 				'icons' => true,
       
   111 				'active_installs' => true
       
   112 			),
       
   113 			// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
       
   114 			'locale' => get_locale(),
       
   115 			'installed_plugins' => $this->get_installed_plugin_slugs(),
       
   116 		);
    64 
   117 
    65 		switch ( $tab ) {
   118 		switch ( $tab ) {
    66 			case 'search':
   119 			case 'search':
    67 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
   120 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
    68 				$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
   121 				$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
    77 					case 'author':
   130 					case 'author':
    78 						$args['author'] = $term;
   131 						$args['author'] = $term;
    79 						break;
   132 						break;
    80 				}
   133 				}
    81 
   134 
    82 				add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 );
       
    83 				break;
   135 				break;
    84 
   136 
    85 			case 'featured':
   137 			case 'featured':
       
   138 				$args['fields']['group'] = true;
       
   139 				$this->orderby = 'group';
       
   140 				// No break!
    86 			case 'popular':
   141 			case 'popular':
    87 			case 'new':
   142 			case 'new':
       
   143 			case 'beta':
       
   144 			case 'recommended':
    88 				$args['browse'] = $tab;
   145 				$args['browse'] = $tab;
    89 				break;
   146 				break;
    90 
   147 
    91 			case 'favorites':
   148 			case 'favorites':
    92 				$user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
   149 				$user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
   105 		}
   162 		}
   106 
   163 
   107 		/**
   164 		/**
   108 		 * Filter API request arguments for each Plugin Install screen tab.
   165 		 * Filter API request arguments for each Plugin Install screen tab.
   109 		 *
   166 		 *
   110 		 * The dynamic portion of the hook name, $tab, refers to the plugin install tabs.
   167 		 * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
   111 		 * Default tabs are 'dashboard', 'search', 'upload', 'featured', 'popular', 'new',
   168 		 * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
   112 		 * and 'favorites'.
       
   113 		 *
   169 		 *
   114 		 * @since 3.7.0
   170 		 * @since 3.7.0
   115 		 *
   171 		 *
   116 		 * @param array|bool $args Plugin Install API arguments.
   172 		 * @param array|bool $args Plugin Install API arguments.
   117 		 */
   173 		 */
   120 		if ( !$args )
   176 		if ( !$args )
   121 			return;
   177 			return;
   122 
   178 
   123 		$api = plugins_api( 'query_plugins', $args );
   179 		$api = plugins_api( 'query_plugins', $args );
   124 
   180 
   125 		if ( is_wp_error( $api ) )
   181 		if ( is_wp_error( $api ) ) {
   126 			wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
   182 			$this->error = $api;
       
   183 			return;
       
   184 		}
   127 
   185 
   128 		$this->items = $api->plugins;
   186 		$this->items = $api->plugins;
       
   187 
       
   188 		if ( $this->orderby ) {
       
   189 			uasort( $this->items, array( $this, 'order_callback' ) );
       
   190 		}
   129 
   191 
   130 		$this->set_pagination_args( array(
   192 		$this->set_pagination_args( array(
   131 			'total_items' => $api->info['results'],
   193 			'total_items' => $api->info['results'],
   132 			'per_page' => $per_page,
   194 			'per_page' => $args['per_page'],
   133 		) );
   195 		) );
   134 	}
   196 
   135 
   197 		if ( isset( $api->info['groups'] ) ) {
   136 	function no_items() {
   198 			$this->groups = $api->info['groups'];
   137 		_e( 'No plugins match your request.' );
   199 		}
   138 	}
   200 	}
   139 
   201 
   140 	function get_views() {
   202 	public function no_items() {
       
   203 		if ( isset( $this->error ) ) {
       
   204 			$message = $this->error->get_error_message() . '<p class="hide-if-no-js"><a href="#" class="button" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a></p>';
       
   205 		} else {
       
   206 			$message = __( 'No plugins match your request.' );
       
   207 		}
       
   208 		echo '<div class="no-plugin-results">' . $message . '</div>';
       
   209 	}
       
   210 
       
   211 	protected function get_views() {
   141 		global $tabs, $tab;
   212 		global $tabs, $tab;
   142 
   213 
   143 		$display_tabs = array();
   214 		$display_tabs = array();
   144 		foreach ( (array) $tabs as $action => $text ) {
   215 		foreach ( (array) $tabs as $action => $text ) {
   145 			$class = ( $action == $tab ) ? ' class="current"' : '';
   216 			$class = ( $action == $tab ) ? ' current' : '';
   146 			$href = self_admin_url('plugin-install.php?tab=' . $action);
   217 			$href = self_admin_url('plugin-install.php?tab=' . $action);
   147 			$display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
   218 			$display_tabs['plugin-install-'.$action] = "<a href='$href' class='$class'>$text</a>";
   148 		}
   219 		}
       
   220 		// No longer a real tab.
       
   221 		unset( $display_tabs['plugin-install-upload'] );
   149 
   222 
   150 		return $display_tabs;
   223 		return $display_tabs;
   151 	}
   224 	}
   152 
   225 
   153 	function display_tablenav( $which ) {
   226 	/**
   154 		if ( 'top' ==  $which ) { ?>
   227 	 * Override parent views so we can use the filter bar display.
       
   228 	 */
       
   229 	public function views() {
       
   230 		$views = $this->get_views();
       
   231 
       
   232 		/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
       
   233 		$views = apply_filters( "views_{$this->screen->id}", $views );
       
   234 
       
   235 ?>
       
   236 <div class="wp-filter">
       
   237 	<ul class="filter-links">
       
   238 		<?php
       
   239 		if ( ! empty( $views ) ) {
       
   240 			foreach ( $views as $class => $view ) {
       
   241 				$views[ $class ] = "\t<li class='$class'>$view";
       
   242 			}
       
   243 			echo implode( " </li>\n", $views ) . "</li>\n";
       
   244 		}
       
   245 		?>
       
   246 	</ul>
       
   247 
       
   248 	<?php install_search_form( isset( $views['plugin-install-search'] ) ); ?>
       
   249 </div>
       
   250 <?php
       
   251 	}
       
   252 
       
   253 	/**
       
   254 	 * Override the parent display() so we can provide a different container.
       
   255 	 */
       
   256 	public function display() {
       
   257 		$singular = $this->_args['singular'];
       
   258 
       
   259 		$data_attr = '';
       
   260 
       
   261 		if ( $singular ) {
       
   262 			$data_attr = " data-wp-lists='list:$singular'";
       
   263 		}
       
   264 
       
   265 		$this->display_tablenav( 'top' );
       
   266 
       
   267 ?>
       
   268 <div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
       
   269 
       
   270 	<div id="the-list"<?php echo $data_attr; ?>>
       
   271 		<?php $this->display_rows_or_placeholder(); ?>
       
   272 	</div>
       
   273 </div>
       
   274 <?php
       
   275 		$this->display_tablenav( 'bottom' );
       
   276 	}
       
   277 
       
   278 	/**
       
   279 	 * @param string $which
       
   280 	 */
       
   281 	protected function display_tablenav( $which ) {
       
   282 		if ( $GLOBALS['tab'] === 'featured' ) {
       
   283 			return;
       
   284 		}
       
   285 
       
   286 		if ( 'top' ==  $which ) {
       
   287 			wp_referer_field();
       
   288 		?>
   155 			<div class="tablenav top">
   289 			<div class="tablenav top">
   156 				<div class="alignleft actions">
   290 				<div class="alignleft actions">
   157 					<?php
   291 					<?php
   158 					/**
   292 					/**
   159 					 * Fires before the Plugin Install table header pagination is displayed.
   293 					 * Fires before the Plugin Install table header pagination is displayed.
   172 			</div>
   306 			</div>
   173 		<?php
   307 		<?php
   174 		}
   308 		}
   175 	}
   309 	}
   176 
   310 
   177 	function get_table_classes() {
   311 	protected function get_table_classes() {
   178 		extract( $this->_args );
   312 		return array( 'widefat', $this->_args['plural'] );
   179 
   313 	}
   180 		return array( 'widefat', $plural );
   314 
   181 	}
   315 	public function get_columns() {
   182 
   316 		return array();
   183 	function get_columns() {
   317 	}
   184 		return array(
   318 
   185 			'name'        => _x( 'Name', 'plugin name' ),
   319 	/**
   186 			'version'     => __( 'Version' ),
   320 	 * @param object $plugin_a
   187 			'rating'      => __( 'Rating' ),
   321 	 * @param object $plugin_b
   188 			'description' => __( 'Description' ),
   322 	 * @return int
   189 		);
   323 	 */
   190 	}
   324 	private function order_callback( $plugin_a, $plugin_b ) {
   191 
   325 		$orderby = $this->orderby;
   192 	function display_rows() {
   326 		if ( ! isset( $plugin_a->$orderby, $plugin_b->$orderby ) ) {
       
   327 			return 0;
       
   328 		}
       
   329 
       
   330 		$a = $plugin_a->$orderby;
       
   331 		$b = $plugin_b->$orderby;
       
   332 
       
   333 		if ( $a == $b ) {
       
   334 			return 0;
       
   335 		}
       
   336 
       
   337 		if ( 'DESC' == $this->order ) {
       
   338 			return ( $a < $b ) ? 1 : -1;
       
   339 		} else {
       
   340 			return ( $a < $b ) ? -1 : 1;
       
   341 		}
       
   342 	}
       
   343 
       
   344 	public function display_rows() {
   193 		$plugins_allowedtags = array(
   345 		$plugins_allowedtags = array(
   194 			'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
   346 			'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
   195 			'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
   347 			'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
   196 			'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
   348 			'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
   197 			'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
   349 			'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
   198 		);
   350 		);
   199 
   351 
   200 		list( $columns, $hidden ) = $this->get_column_info();
   352 		$plugins_group_titles = array(
   201 
   353 			'Performance' => _x( 'Performance', 'Plugin installer group title' ),
   202 		$style = array();
   354 			'Social'      => _x( 'Social',      'Plugin installer group title' ),
   203 		foreach ( $columns as $column_name => $column_display_name ) {
   355 			'Tools'       => _x( 'Tools',       'Plugin installer group title' ),
   204 			$style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
   356 		);
   205 		}
   357 
       
   358 		$group = null;
   206 
   359 
   207 		foreach ( (array) $this->items as $plugin ) {
   360 		foreach ( (array) $this->items as $plugin ) {
   208 			if ( is_object( $plugin ) )
   361 			if ( is_object( $plugin ) ) {
   209 				$plugin = (array) $plugin;
   362 				$plugin = (array) $plugin;
   210 
   363 			}
       
   364 
       
   365 			// Display the group heading if there is one
       
   366 			if ( isset( $plugin['group'] ) && $plugin['group'] != $group ) {
       
   367 				if ( isset( $this->groups[ $plugin['group'] ] ) ) {
       
   368 					$group_name = $this->groups[ $plugin['group'] ];
       
   369 					if ( isset( $plugins_group_titles[ $group_name ] ) ) {
       
   370 						$group_name = $plugins_group_titles[ $group_name ];
       
   371 					}
       
   372 				} else {
       
   373 					$group_name = $plugin['group'];
       
   374 				}
       
   375 
       
   376 				// Starting a new group, close off the divs of the last one
       
   377 				if ( ! empty( $group ) ) {
       
   378 					echo '</div></div>';
       
   379 				}
       
   380 
       
   381 				echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
       
   382 				// needs an extra wrapping div for nth-child selectors to work
       
   383 				echo '<div class="plugin-items">';
       
   384 
       
   385 				$group = $plugin['group'];
       
   386 			}
   211 			$title = wp_kses( $plugin['name'], $plugins_allowedtags );
   387 			$title = wp_kses( $plugin['name'], $plugins_allowedtags );
   212 			//Limit description to 400char, and remove any HTML.
   388 
   213 			$description = strip_tags( $plugin['description'] );
   389 			// Remove any HTML from the description.
   214 			if ( strlen( $description ) > 400 )
   390 			$description = strip_tags( $plugin['short_description'] );
   215 				$description = mb_substr( $description, 0, 400 ) . '&#8230;';
       
   216 			//remove any trailing entities
       
   217 			$description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
       
   218 			//strip leading/trailing & multiple consecutive lines
       
   219 			$description = trim( $description );
       
   220 			$description = preg_replace( "|(\r?\n)+|", "\n", $description );
       
   221 			//\n => <br>
       
   222 			$description = nl2br( $description );
       
   223 			$version = wp_kses( $plugin['version'], $plugins_allowedtags );
   391 			$version = wp_kses( $plugin['version'], $plugins_allowedtags );
   224 
   392 
   225 			$name = strip_tags( $title . ' ' . $version );
   393 			$name = strip_tags( $title . ' ' . $version );
   226 
   394 
   227 			$author = $plugin['author'];
   395 			$author = wp_kses( $plugin['author'], $plugins_allowedtags );
   228 			if ( ! empty( $plugin['author'] ) )
   396 			if ( ! empty( $author ) ) {
   229 				$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
   397 				$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
   230 
   398 			}
   231 			$author = wp_kses( $author, $plugins_allowedtags );
       
   232 
   399 
   233 			$action_links = array();
   400 			$action_links = array();
   234 			$action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
       
   235 								'&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
       
   236 								esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
       
   237 
   401 
   238 			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
   402 			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
   239 				$status = install_plugin_install_status( $plugin );
   403 				$status = install_plugin_install_status( $plugin );
   240 
   404 
   241 				switch ( $status['status'] ) {
   405 				switch ( $status['status'] ) {
   242 					case 'install':
   406 					case 'install':
   243 						if ( $status['url'] )
   407 						if ( $status['url'] ) {
   244 							$action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
   408 							/* translators: 1: Plugin name and version. */
       
   409 							$action_links[] = '<a class="install-now button" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Install %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Install Now' ) . '</a>';
       
   410 						}
       
   411 
   245 						break;
   412 						break;
   246 					case 'update_available':
   413 					case 'update_available':
   247 						if ( $status['url'] )
   414 						if ( $status['url'] ) {
   248 							$action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
   415 							/* translators: 1: Plugin name and version */
       
   416 							$action_links[] = '<a class="update-now button" data-plugin="' . esc_attr( $status['file'] ) . '" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Update %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Update Now' ) . '</a>';
       
   417 						}
       
   418 
   249 						break;
   419 						break;
   250 					case 'latest_installed':
   420 					case 'latest_installed':
   251 					case 'newer_installed':
   421 					case 'newer_installed':
   252 						$action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
   422 						$action_links[] = '<span class="button button-disabled" title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
   253 						break;
   423 						break;
   254 				}
   424 				}
       
   425 			}
       
   426 
       
   427 			$details_link   = self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
       
   428 								'&amp;TB_iframe=true&amp;width=600&amp;height=550' );
       
   429 
       
   430 			/* translators: 1: Plugin name and version. */
       
   431 			$action_links[] = '<a href="' . esc_url( $details_link ) . '" class="thickbox" aria-label="' . esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '" data-title="' . esc_attr( $name ) . '">' . __( 'More Details' ) . '</a>';
       
   432 
       
   433 			if ( !empty( $plugin['icons']['svg'] ) ) {
       
   434 				$plugin_icon_url = $plugin['icons']['svg'];
       
   435 			} elseif ( !empty( $plugin['icons']['2x'] ) ) {
       
   436 				$plugin_icon_url = $plugin['icons']['2x'];
       
   437 			} elseif ( !empty( $plugin['icons']['1x'] ) ) {
       
   438 				$plugin_icon_url = $plugin['icons']['1x'];
       
   439 			} else {
       
   440 				$plugin_icon_url = $plugin['icons']['default'];
   255 			}
   441 			}
   256 
   442 
   257 			/**
   443 			/**
   258 			 * Filter the install action links for a plugin.
   444 			 * Filter the install action links for a plugin.
   259 			 *
   445 			 *
   261 			 *
   447 			 *
   262 			 * @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
   448 			 * @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
   263 			 * @param array $plugin       The plugin currently being listed.
   449 			 * @param array $plugin       The plugin currently being listed.
   264 			 */
   450 			 */
   265 			$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
   451 			$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
       
   452 
       
   453 			$date_format = __( 'M j, Y @ H:i' );
       
   454 			$last_updated_timestamp = strtotime( $plugin['last_updated'] );
   266 		?>
   455 		?>
   267 		<tr>
   456 		<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
   268 			<td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong>
   457 			<div class="plugin-card-top">
   269 				<div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
   458 				<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox plugin-icon"><img src="<?php echo esc_attr( $plugin_icon_url ) ?>" /></a>
   270 			</td>
   459 				<div class="name column-name">
   271 			<td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td>
   460 					<h4><a href="<?php echo esc_url( $details_link ); ?>" class="thickbox"><?php echo $title; ?></a></h4>
   272 			<td class="vers column-rating"<?php echo $style['rating']; ?>>
   461 				</div>
   273 				<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'] ) ) ?>">
   462 				<div class="action-links">
   274 					<div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin['rating'] ) ); ?>px"></div>
   463 					<?php
   275 				</div>
   464 						if ( $action_links ) {
   276 			</td>
   465 							echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
   277 			<td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>
   466 						}
   278 		</tr>
   467 					?>
       
   468 				</div>
       
   469 				<div class="desc column-description">
       
   470 					<p><?php echo $description; ?></p>
       
   471 					<p class="authors"><?php echo $author; ?></p>
       
   472 				</div>
       
   473 			</div>
       
   474 			<div class="plugin-card-bottom">
       
   475 				<div class="vers column-rating">
       
   476 					<?php wp_star_rating( array( 'rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?>
       
   477 					<span class="num-ratings">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
       
   478 				</div>
       
   479 				<div class="column-updated">
       
   480 					<strong><?php _e( 'Last Updated:' ); ?></strong> <span title="<?php echo esc_attr( date_i18n( $date_format, $last_updated_timestamp ) ); ?>">
       
   481 						<?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
       
   482 					</span>
       
   483 				</div>
       
   484 				<div class="column-downloaded">
       
   485 					<?php
       
   486 					if ( $plugin['active_installs'] >= 1000000 ) {
       
   487 						$active_installs_text = _x( '1+ Million', 'Active plugin installs' );
       
   488 					} else {
       
   489 						$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
       
   490 					}
       
   491 					printf( __( '%s Active Installs' ), $active_installs_text );
       
   492 					?>
       
   493 				</div>
       
   494 				<div class="column-compatibility">
       
   495 					<?php
       
   496 					if ( ! empty( $plugin['tested'] ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
       
   497 						echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
       
   498 					} elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
       
   499 						echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
       
   500 					} else {
       
   501 						echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
       
   502 					}
       
   503 					?>
       
   504 				</div>
       
   505 			</div>
       
   506 		</div>
   279 		<?php
   507 		<?php
   280 		}
   508 		}
       
   509 
       
   510 		// Close off the group divs of the last one
       
   511 		if ( ! empty( $group ) ) {
       
   512 			echo '</div></div>';
       
   513 		}
   281 	}
   514 	}
   282 }
   515 }