wp/wp-admin/includes/theme-install.php
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 /**
       
     3  * WordPress Theme Install Administration API
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Administration
       
     7  */
       
     8 
       
     9 $themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
       
    10 	'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
       
    11 	'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
       
    12 	'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
       
    13 	'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
       
    14 	'img' => array('src' => array(), 'class' => array(), 'alt' => array())
       
    15 );
       
    16 
       
    17 $theme_field_defaults = array( 'description' => true, 'sections' => false, 'tested' => true, 'requires' => true,
       
    18 	'rating' => true, 'downloaded' => true, 'downloadlink' => true, 'last_updated' => true, 'homepage' => true,
       
    19 	'tags' => true, 'num_ratings' => true
       
    20 );
       
    21 
       
    22 /**
       
    23  * Retrieve list of WordPress theme features (aka theme tags)
       
    24  *
       
    25  * @since 2.8.0
       
    26  *
       
    27  * @deprecated since 3.1.0 Use get_theme_feature_list() instead.
       
    28  *
       
    29  * @return array
       
    30  */
       
    31 function install_themes_feature_list() {
       
    32 	_deprecated_function( __FUNCTION__, '3.1', 'get_theme_feature_list()' );
       
    33 
       
    34 	if ( !$cache = get_transient( 'wporg_theme_feature_list' ) )
       
    35 		set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
       
    36 
       
    37 	if ( $cache )
       
    38 		return $cache;
       
    39 
       
    40 	$feature_list = themes_api( 'feature_list', array() );
       
    41 	if ( is_wp_error( $feature_list ) )
       
    42 		return array();
       
    43 
       
    44 	set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
       
    45 
       
    46 	return $feature_list;
       
    47 }
       
    48 
       
    49 /**
       
    50  * Display search form for searching themes.
       
    51  *
       
    52  * @since 2.8.0
       
    53  */
       
    54 function install_theme_search_form( $type_selector = true ) {
       
    55 	$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
       
    56 	$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
       
    57 	if ( ! $type_selector )
       
    58 		echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>';
       
    59 	?>
       
    60 <form id="search-themes" method="get" action="">
       
    61 	<input type="hidden" name="tab" value="search" />
       
    62 	<?php if ( $type_selector ) : ?>
       
    63 	<label class="screen-reader-text" for="typeselector"><?php _e('Type of search'); ?></label>
       
    64 	<select	name="type" id="typeselector">
       
    65 	<option value="term" <?php selected('term', $type) ?>><?php _e('Keyword'); ?></option>
       
    66 	<option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option>
       
    67 	<option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option>
       
    68 	</select>
       
    69 	<label class="screen-reader-text" for="s"><?php
       
    70 	switch ( $type ) {
       
    71 		case 'term':
       
    72 			_e( 'Search by keyword' );
       
    73 			break;
       
    74 		case 'author':
       
    75 			_e( 'Search by author' );
       
    76 			break;
       
    77 		case 'tag':
       
    78 			_e( 'Search by tag' );
       
    79 			break;
       
    80 	}
       
    81 	?></label>
       
    82 	<?php else : ?>
       
    83 	<label class="screen-reader-text" for="s"><?php _e('Search by keyword'); ?></label>
       
    84 	<?php endif; ?>
       
    85 	<input type="search" name="s" id="s" size="30" value="<?php echo esc_attr($term) ?>" autofocus="autofocus" />
       
    86 	<?php submit_button( __( 'Search' ), 'button', 'search', false ); ?>
       
    87 </form>
       
    88 <?php
       
    89 }
       
    90 
       
    91 /**
       
    92  * Display tags filter for themes.
       
    93  *
       
    94  * @since 2.8.0
       
    95  */
       
    96 function install_themes_dashboard() {
       
    97 	install_theme_search_form( false );
       
    98 ?>
       
    99 <h4><?php _e('Feature Filter') ?></h4>
       
   100 <p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p>
       
   101 
       
   102 <form method="get" action="">
       
   103 	<input type="hidden" name="tab" value="search" />
       
   104 	<?php
       
   105 	$feature_list = get_theme_feature_list();
       
   106 	echo '<div class="feature-filter">';
       
   107 
       
   108 	foreach ( (array) $feature_list as $feature_name => $features ) {
       
   109 		$feature_name = esc_html( $feature_name );
       
   110 		echo '<div class="feature-name">' . $feature_name . '</div>';
       
   111 
       
   112 		echo '<ol class="feature-group">';
       
   113 		foreach ( $features as $feature => $feature_name ) {
       
   114 			$feature_name = esc_html( $feature_name );
       
   115 			$feature = esc_attr($feature);
       
   116 ?>
       
   117 
       
   118 <li>
       
   119 	<input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
       
   120 	<label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label>
       
   121 </li>
       
   122 
       
   123 <?php	} ?>
       
   124 </ol>
       
   125 <br class="clear" />
       
   126 <?php
       
   127 	} ?>
       
   128 
       
   129 </div>
       
   130 <br class="clear" />
       
   131 <?php submit_button( __( 'Find Themes' ), 'button', 'search' ); ?>
       
   132 </form>
       
   133 <?php
       
   134 }
       
   135 add_action('install_themes_dashboard', 'install_themes_dashboard');
       
   136 
       
   137 function install_themes_upload($page = 1) {
       
   138 ?>
       
   139 <h4><?php _e('Install a theme in .zip format'); ?></h4>
       
   140 <p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.'); ?></p>
       
   141 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-theme'); ?>">
       
   142 	<?php wp_nonce_field( 'theme-upload'); ?>
       
   143 	<input type="file" name="themezip" />
       
   144 	<?php submit_button( __( 'Install Now' ), 'button', 'install-theme-submit', false ); ?>
       
   145 </form>
       
   146 	<?php
       
   147 }
       
   148 add_action('install_themes_upload', 'install_themes_upload', 10, 1);
       
   149 
       
   150 /**
       
   151  * Prints a theme on the Install Themes pages.
       
   152  *
       
   153  * @deprecated 3.4.0
       
   154  */
       
   155 function display_theme( $theme ) {
       
   156 	_deprecated_function( __FUNCTION__, '3.4' );
       
   157 	global $wp_list_table;
       
   158 	$wp_list_table->single_row( $theme );
       
   159 }
       
   160 
       
   161 /**
       
   162  * Display theme content based on theme list.
       
   163  *
       
   164  * @since 2.8.0
       
   165  */
       
   166 function display_themes() {
       
   167 	global $wp_list_table;
       
   168 
       
   169 	$wp_list_table->display();
       
   170 }
       
   171 add_action('install_themes_search', 'display_themes');
       
   172 add_action('install_themes_featured', 'display_themes');
       
   173 add_action('install_themes_new', 'display_themes');
       
   174 add_action('install_themes_updated', 'display_themes');
       
   175 
       
   176 /**
       
   177  * Display theme information in dialog box form.
       
   178  *
       
   179  * @since 2.8.0
       
   180  */
       
   181 function install_theme_information() {
       
   182 	global $tab, $themes_allowedtags, $wp_list_table;
       
   183 
       
   184 	$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
       
   185 
       
   186 	if ( is_wp_error( $theme ) )
       
   187 		wp_die( $theme );
       
   188 
       
   189 	iframe_header( __('Theme Install') );
       
   190 	$wp_list_table->theme_installer_single( $theme );
       
   191 	iframe_footer();
       
   192 	exit;
       
   193 }
       
   194 add_action('install_themes_pre_theme-information', 'install_theme_information');