PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/my30dc/my30dc.com
PHP | 222 lines | 169 code | 34 blank | 19 comment | 29 complexity | 21ff585f8d622dc9a181cd1c4ad231d3 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Themes List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_Themes_List_Table extends WP_List_Table {
  11. var $search = array();
  12. var $features = array();
  13. function ajax_user_can() {
  14. // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes.
  15. return current_user_can('switch_themes');
  16. }
  17. function prepare_items() {
  18. global $ct;
  19. $ct = current_theme_info();
  20. $themes = get_allowed_themes();
  21. if ( ! empty( $_REQUEST['s'] ) ) {
  22. $search = strtolower( stripslashes( $_REQUEST['s'] ) );
  23. $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
  24. $this->search = array_unique( $this->search );
  25. }
  26. if ( !empty( $_REQUEST['features'] ) ) {
  27. $this->features = $_REQUEST['features'];
  28. $this->features = array_map( 'trim', $this->features );
  29. $this->features = array_map( 'sanitize_title_with_dashes', $this->features );
  30. $this->features = array_unique( $this->features );
  31. }
  32. if ( $this->search || $this->features ) {
  33. foreach ( $themes as $key => $theme ) {
  34. if ( !$this->search_theme( $theme ) )
  35. unset( $themes[ $key ] );
  36. }
  37. }
  38. unset( $themes[$ct->name] );
  39. uksort( $themes, "strnatcasecmp" );
  40. $per_page = 24;
  41. $page = $this->get_pagenum();
  42. $start = ( $page - 1 ) * $per_page;
  43. $this->items = array_slice( $themes, $start, $per_page );
  44. $this->set_pagination_args( array(
  45. 'total_items' => count( $themes ),
  46. 'per_page' => $per_page,
  47. ) );
  48. }
  49. function no_items() {
  50. if ( $this->search || $this->features ) {
  51. _e( 'No items found.' );
  52. return;
  53. }
  54. if ( is_multisite() ) {
  55. if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
  56. printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) );
  57. return;
  58. } elseif ( current_user_can( 'manage_network_themes' ) ) {
  59. printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) );
  60. return;
  61. }
  62. // else, fallthrough. install_themes doesn't help if you can't enable it.
  63. } else {
  64. if ( current_user_can( 'install_themes' ) ) {
  65. printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) );
  66. return;
  67. }
  68. }
  69. // Fallthrough.
  70. printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) );
  71. }
  72. function tablenav( $which = 'top' ) {
  73. if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
  74. return;
  75. ?>
  76. <div class="tablenav themes <?php echo $which; ?>">
  77. <?php $this->pagination( $which ); ?>
  78. <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
  79. <br class="clear" />
  80. </div>
  81. <?php
  82. }
  83. function display() {
  84. // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
  85. ?>
  86. <?php $this->tablenav( 'top' ); ?>
  87. <div id="availablethemes">
  88. <?php $this->display_rows_or_placeholder(); ?>
  89. </div>
  90. <?php $this->tablenav( 'bottom' ); ?>
  91. <?php
  92. }
  93. function get_columns() {
  94. return array();
  95. }
  96. function display_rows() {
  97. $themes = $this->items;
  98. $theme_names = array_keys( $themes );
  99. natcasesort( $theme_names );
  100. foreach ( $theme_names as $theme_name ) {
  101. $class = array( 'available-theme' );
  102. ?>
  103. <div class="<?php echo join( ' ', $class ); ?>">
  104. <?php if ( !empty( $theme_name ) ) :
  105. $template = $themes[$theme_name]['Template'];
  106. $stylesheet = $themes[$theme_name]['Stylesheet'];
  107. $title = $themes[$theme_name]['Title'];
  108. $version = $themes[$theme_name]['Version'];
  109. $description = $themes[$theme_name]['Description'];
  110. $author = $themes[$theme_name]['Author'];
  111. $screenshot = $themes[$theme_name]['Screenshot'];
  112. $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
  113. $template_dir = $themes[$theme_name]['Template Dir'];
  114. $parent_theme = $themes[$theme_name]['Parent Theme'];
  115. $theme_root = $themes[$theme_name]['Theme Root'];
  116. $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
  117. $preview_link = esc_url( get_option( 'home' ) . '/' );
  118. if ( is_ssl() )
  119. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  120. $preview_link = htmlspecialchars( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ), $preview_link ) );
  121. $preview_text = esc_attr( sprintf( __( 'Preview of &#8220;%s&#8221;' ), $title ) );
  122. $tags = $themes[$theme_name]['Tags'];
  123. $thickbox_class = 'thickbox thickbox-preview';
  124. $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=".urlencode( $template )."&amp;stylesheet=".urlencode( $stylesheet ), 'switch-theme_' . $template );
  125. $activate_text = esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) );
  126. $actions = array();
  127. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>';
  128. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>';
  129. if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
  130. $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $theme_name ) ) . "' );" . '">' . __( 'Delete' ) . '</a>';
  131. $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] );
  132. $actions = implode ( ' | ', $actions );
  133. ?>
  134. <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
  135. <?php if ( $screenshot ) : ?>
  136. <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
  137. <?php endif; ?>
  138. </a>
  139. <h3><?php
  140. /* translators: 1: theme title, 2: theme version, 3: theme author */
  141. printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
  142. <p class="description"><?php echo $description; ?></p>
  143. <span class='action-links'><?php echo $actions ?></span>
  144. <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) {
  145. /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
  146. <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ); ?></p>
  147. <?php } else { ?>
  148. <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
  149. <?php } ?>
  150. <?php if ( $tags ) : ?>
  151. <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p>
  152. <?php endif; ?>
  153. <?php theme_update_available( $themes[$theme_name] ); ?>
  154. <?php endif; // end if not empty theme_name ?>
  155. </div>
  156. <?php } // end foreach $theme_names
  157. }
  158. function search_theme( $theme ) {
  159. $matched = 0;
  160. // Match all phrases
  161. if ( count( $this->search ) > 0 ) {
  162. foreach ( $this->search as $word ) {
  163. $matched = 0;
  164. // In a tag?
  165. if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
  166. $matched = 1;
  167. // In one of the fields?
  168. foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
  169. if ( stripos( $theme[$field], $word ) !== false )
  170. $matched++;
  171. }
  172. if ( $matched == 0 )
  173. return false;
  174. }
  175. }
  176. // Now search the features
  177. if ( count( $this->features ) > 0 ) {
  178. foreach ( $this->features as $word ) {
  179. // In a tag?
  180. if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
  181. return false;
  182. }
  183. }
  184. // Only get here if each word exists in the tags or one of the fields
  185. return true;
  186. }
  187. }
  188. ?>