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