web/wp-admin/themes.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once('admin.php');
    10 require_once('./admin.php');
    11 
    11 
    12 if ( !current_user_can('switch_themes') )
    12 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
    13 	wp_die( __( 'Cheatin’ uh?' ) );
    13 	wp_die( __( 'Cheatin’ uh?' ) );
    14 
    14 
    15 if ( isset($_GET['action']) ) {
    15 $wp_list_table = _get_list_table('WP_Themes_List_Table');
       
    16 
       
    17 if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
    16 	if ( 'activate' == $_GET['action'] ) {
    18 	if ( 'activate' == $_GET['action'] ) {
    17 		check_admin_referer('switch-theme_' . $_GET['template']);
    19 		check_admin_referer('switch-theme_' . $_GET['stylesheet']);
    18 		switch_theme($_GET['template'], $_GET['stylesheet']);
    20 		$theme = wp_get_theme( $_GET['stylesheet'] );
    19 		wp_redirect('themes.php?activated=true');
    21 		if ( ! $theme->exists() || ! $theme->is_allowed() )
       
    22 			wp_die( __( 'Cheatin’ uh?' ) );
       
    23 		switch_theme( $theme->get_template(), $theme->get_stylesheet() );
       
    24 		wp_redirect( admin_url('themes.php?activated=true') );
    20 		exit;
    25 		exit;
    21 	} else if ( 'delete' == $_GET['action'] ) {
    26 	} elseif ( 'delete' == $_GET['action'] ) {
    22 		check_admin_referer('delete-theme_' . $_GET['template']);
    27 		check_admin_referer('delete-theme_' . $_GET['stylesheet']);
    23 		if ( !current_user_can('update_themes') )
    28 		$theme = wp_get_theme( $_GET['stylesheet'] );
       
    29 		if ( !current_user_can('delete_themes') || ! $theme->exists() )
    24 			wp_die( __( 'Cheatin’ uh?' ) );
    30 			wp_die( __( 'Cheatin’ uh?' ) );
    25 		delete_theme($_GET['template']);
    31 		delete_theme($_GET['stylesheet']);
    26 		wp_redirect('themes.php?deleted=true');
    32 		wp_redirect( admin_url('themes.php?deleted=true') );
    27 		exit;
    33 		exit;
    28 	}
    34 	}
    29 }
    35 }
    30 
    36 
       
    37 $wp_list_table->prepare_items();
       
    38 
    31 $title = __('Manage Themes');
    39 $title = __('Manage Themes');
    32 $parent_file = 'themes.php';
    40 $parent_file = 'themes.php';
    33 
    41 
    34 $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
    42 if ( current_user_can( 'switch_themes' ) ) :
    35 if ( current_user_can('install_themes') ) {
    43 
    36 	$help .= '<p>' . sprintf(__('You can find additional themes for your site by using the new <a href="%1$s">Theme Browser/Installer</a> functionality or by browsing the <a href="http://wordpress.org/extend/themes/">WordPress Theme Directory</a> directly and installing manually.  To install a theme <em>manually</em>, <a href="%2$s">upload its ZIP archive with the new uploader</a> or copy its folder via FTP into your <code>wp-content/themes</code> directory.'), 'theme-install.php', 'theme-install.php?tab=upload' ) . '</p>';
    44 $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' .
    37 	$help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>' ;
    45 	'<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Live Preview link (see "Previewing and Customizing" help tab). To change themes, click the Activate link.') . '</p>';
    38 }
    46 
    39 
    47 get_current_screen()->add_help_tab( array(
    40 add_contextual_help('themes', $help);
    48 	'id'      => 'overview',
       
    49 	'title'   => __('Overview'),
       
    50 	'content' => $help_manage
       
    51 ) );
       
    52 
       
    53 if ( current_user_can( 'install_themes' ) ) {
       
    54 	if ( is_multisite() ) {
       
    55 		$help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
       
    56 	} else {
       
    57 		$help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/' ) . '</p>';
       
    58 	}
       
    59 
       
    60 	get_current_screen()->add_help_tab( array(
       
    61 		'id'      => 'adding-themes',
       
    62 		'title'   => __('Adding Themes'),
       
    63 		'content' => $help_install
       
    64 	) );
       
    65 }
    41 
    66 
    42 add_thickbox();
    67 add_thickbox();
    43 wp_enqueue_script( 'theme-preview' );
    68 
    44 
    69 endif; // switch_themes
    45 require_once('admin-header.php');
    70 
    46 ?>
    71 if ( current_user_can( 'edit_theme_options' ) ) {
    47 
    72 	$help_customize =
    48 <?php if ( ! validate_current_theme() ) : ?>
    73 		'<p>' . __('Click on the "Live Preview" link under any theme to preview that theme and change theme options in a separate, full-screen view. Any installed theme can be previewed and customized in this way.') . '</p>'.
    49 <div id="message1" class="updated fade"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div>
    74 		'<p>' . __('The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates.') . '</p>' .
       
    75 		'<p>' . __('In the left-hand pane you can edit the theme settings. The settings will differ, depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the "Save &amp; Activate" button at the top of the left-hand pane.') . '</p>' .
       
    76 		'<p>' . __('When previewing on smaller monitors, you can use the "Collapse" icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the Collapse icon again.') . '</p>';
       
    77 
       
    78 	get_current_screen()->add_help_tab( array(
       
    79 		'id'		=> 'customize-preview-themes',
       
    80 		'title'		=> __('Previewing and Customizing'),
       
    81 		'content'	=> $help_customize
       
    82 	) );
       
    83 }
       
    84 
       
    85 get_current_screen()->set_help_sidebar(
       
    86 	'<p><strong>' . __('For more information:') . '</strong></p>' .
       
    87 	'<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
       
    88 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
       
    89 );
       
    90 
       
    91 wp_enqueue_script( 'theme' );
       
    92 wp_enqueue_script( 'customize-loader' );
       
    93 
       
    94 require_once('./admin-header.php');
       
    95 ?>
       
    96 
       
    97 <div class="wrap"><?php
       
    98 screen_icon();
       
    99 if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
       
   100 <h2 class="nav-tab-wrapper">
       
   101 <a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><a href="<?php echo admin_url( 'theme-install.php'); ?>" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a>
       
   102 <?php else : ?>
       
   103 <h2><?php echo esc_html( $title ); ?>
       
   104 <?php endif; ?>
       
   105 </h2>
       
   106 <?php
       
   107 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
       
   108 <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
    50 <?php elseif ( isset($_GET['activated']) ) :
   109 <?php elseif ( isset($_GET['activated']) ) :
    51 		if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?>
   110 		if ( isset( $_GET['previewed'] ) ) { ?>
    52 <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings page</a> to configure them.'), admin_url('widgets.php') ); ?></p></div><?php
   111 		<div id="message2" class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>.' ), home_url( '/' ) ); ?></p></div>
       
   112 		<?php } elseif ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
       
   113 <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
    53 		} else { ?>
   114 		} else { ?>
    54 <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div><?php
   115 <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
    55 		}
   116 		}
    56 	elseif ( isset($_GET['deleted']) ) : ?>
   117 	elseif ( isset($_GET['deleted']) ) : ?>
    57 <div id="message3" class="updated fade"><p><?php _e('Theme deleted.') ?></p></div>
   118 <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
       
   119 <?php
       
   120 endif;
       
   121 
       
   122 $ct = wp_get_theme();
       
   123 $screenshot = $ct->get_screenshot();
       
   124 $class = $screenshot ? 'has-screenshot' : '';
       
   125 
       
   126 $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;' ), $ct->display('Name') );
       
   127 
       
   128 ?>
       
   129 <div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
       
   130 	<?php if ( $screenshot ) : ?>
       
   131 		<?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
       
   132 		<a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>">
       
   133 			<img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
       
   134 		</a>
       
   135 		<?php endif; ?>
       
   136 		<img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
       
   137 	<?php endif; ?>
       
   138 
       
   139 	<h3><?php _e('Current Theme'); ?></h3>
       
   140 	<h4>
       
   141 		<?php echo $ct->display('Name'); ?>
       
   142 	</h4>
       
   143 
       
   144 	<div>
       
   145 		<ul class="theme-info">
       
   146 			<li><?php printf( __('By %s'), $ct->display('Author') ); ?></li>
       
   147 			<li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li>
       
   148 		</ul>
       
   149 		<p class="theme-description"><?php echo $ct->display('Description'); ?></p>
       
   150 		<?php theme_update_available( $ct ); ?>
       
   151 	</div>
       
   152 
       
   153 	<?php
       
   154 	// Pretend you didn't see this.
       
   155 	$options = array();
       
   156 	if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
       
   157 		foreach ( (array) $submenu['themes.php'] as $item) {
       
   158 			$class = '';
       
   159 			if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] )
       
   160 				continue;
       
   161 			// 0 = name, 1 = capability, 2 = file
       
   162 			if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
       
   163 				$class = ' class="current"';
       
   164 			if ( !empty($submenu[$item[2]]) ) {
       
   165 				$submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
       
   166 				$menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
       
   167 				if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
       
   168 					$options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
       
   169 				else
       
   170 					$options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
       
   171 			} else if ( current_user_can($item[1]) ) {
       
   172 				if ( file_exists(ABSPATH . 'wp-admin/' . $item[2]) ) {
       
   173 					$options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>";
       
   174 				} else {
       
   175 					$options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
       
   176 				}
       
   177 			}
       
   178 		}
       
   179 	}
       
   180 
       
   181 	if ( $options || current_user_can( 'edit_theme_options' ) ) :
       
   182 	?>
       
   183 	<div class="theme-options">
       
   184 		<?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
       
   185 		<a id="customize-current-theme-link" href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"><?php _e( 'Customize' ); ?></a>
       
   186 		<?php
       
   187 		endif; // edit_theme_options
       
   188 		if ( $options ) :
       
   189 		?>
       
   190 		<span><?php _e( 'Options:' )?></span>
       
   191 		<ul>
       
   192 			<?php foreach ( $options as $option ) : ?>
       
   193 				<li><?php echo $option; ?></li>
       
   194 			<?php endforeach; ?>
       
   195 		</ul>
       
   196 	</div>
       
   197 	<?php
       
   198 		endif; // options
       
   199 	endif; // options || edit_theme_options
       
   200 	?>
       
   201 
       
   202 </div>
       
   203 
       
   204 <br class="clear" />
       
   205 <?php
       
   206 if ( ! current_user_can( 'switch_themes' ) ) {
       
   207 	echo '</div>';
       
   208 	require( './admin-footer.php' );
       
   209 	exit;
       
   210 }
       
   211 ?>
       
   212 
       
   213 <form class="search-form filter-form" action="" method="get">
       
   214 
       
   215 <h3 class="available-themes"><?php _e('Available Themes'); ?></h3>
       
   216 
       
   217 <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?>
       
   218 
       
   219 <p class="search-box">
       
   220 	<label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
       
   221 	<input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
       
   222 	<?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
       
   223 	<a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
       
   224 </p>
       
   225 
       
   226 <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
       
   227 <?php $feature_list = get_theme_feature_list(); ?>
       
   228 	<div class="feature-filter">
       
   229 		<p class="install-help"><?php _e('Theme filters') ?></p>
       
   230 	<?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
       
   231 		<input type="hidden" name="filter" value="1" />
       
   232 	<?php endif; ?>
       
   233 	<?php foreach ( $feature_list as $feature_name => $features ) :
       
   234 			$feature_name = esc_html( $feature_name ); ?>
       
   235 
       
   236 		<div class="feature-container">
       
   237 			<div class="feature-name"><?php echo $feature_name ?></div>
       
   238 
       
   239 			<ol class="feature-group">
       
   240 				<?php foreach ( $features as $key => $feature ) :
       
   241 						$feature_name = $feature;
       
   242 						$feature_name = esc_html( $feature_name );
       
   243 						$feature = esc_attr( $feature );
       
   244 						?>
       
   245 				<li>
       
   246 					<input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
       
   247 					<label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
       
   248 				</li>
       
   249 				<?php endforeach; ?>
       
   250 			</ol>
       
   251 		</div>
       
   252 	<?php endforeach; ?>
       
   253 
       
   254 	<div class="feature-container">
       
   255 		<?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?>
       
   256 		&nbsp;
       
   257 		<a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a>
       
   258 	</div>
       
   259 	<br/>
       
   260 	</div>
       
   261 	<br class="clear"/>
       
   262 </div>
       
   263 
    58 <?php endif; ?>
   264 <?php endif; ?>
    59 
   265 
    60 <?php
       
    61 $themes = get_themes();
       
    62 $ct = current_theme_info();
       
    63 unset($themes[$ct->name]);
       
    64 
       
    65 uksort( $themes, "strnatcasecmp" );
       
    66 $theme_total = count( $themes );
       
    67 $per_page = 15;
       
    68 
       
    69 if ( isset( $_GET['pagenum'] ) )
       
    70 	$page = absint( $_GET['pagenum'] );
       
    71 
       
    72 if ( empty($page) )
       
    73 	$page = 1;
       
    74 
       
    75 $start = $offset = ( $page - 1 ) * $per_page;
       
    76 
       
    77 $page_links = paginate_links( array(
       
    78 	'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
       
    79 	'format' => '',
       
    80 	'prev_text' => __('&laquo;'),
       
    81 	'next_text' => __('&raquo;'),
       
    82 	'total' => ceil($theme_total / $per_page),
       
    83 	'current' => $page
       
    84 ));
       
    85 
       
    86 $themes = array_slice( $themes, $start, $per_page );
       
    87 
       
    88 /**
       
    89  * Check if there is an update for a theme available.
       
    90  *
       
    91  * Will display link, if there is an update available.
       
    92  *
       
    93  * @since 2.7.0
       
    94  *
       
    95  * @param object $theme Theme data object.
       
    96  * @return bool False if no valid info was passed.
       
    97  */
       
    98 function theme_update_available( $theme ) {
       
    99 	static $themes_update;
       
   100 	if ( !isset($themes_update) )
       
   101 		$themes_update = get_transient('update_themes');
       
   102 
       
   103 	if ( is_object($theme) && isset($theme->stylesheet) )
       
   104 		$stylesheet = $theme->stylesheet;
       
   105 	elseif ( is_array($theme) && isset($theme['Stylesheet']) )
       
   106 		$stylesheet = $theme['Stylesheet'];
       
   107 	else
       
   108 		return false; //No valid info passed.
       
   109 
       
   110 	if ( isset($themes_update->response[ $stylesheet ]) ) {
       
   111 		$update = $themes_update->response[ $stylesheet ];
       
   112 		$theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
       
   113 		$details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
       
   114 		$update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
       
   115 		$update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
       
   116 
       
   117 		if ( ! current_user_can('update_themes') )
       
   118 			printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
       
   119 		else if ( empty($update->package) )
       
   120 			printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
       
   121 		else
       
   122 			printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s" %5$s >upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
       
   123 	}
       
   124 }
       
   125 
       
   126 ?>
       
   127 
       
   128 <div class="wrap">
       
   129 <?php screen_icon(); ?>
       
   130 <h2><?php echo esc_html( $title ); ?> <a href="theme-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a></h2>
       
   131 
       
   132 <h3><?php _e('Current Theme'); ?></h3>
       
   133 <div id="current-theme">
       
   134 <?php if ( $ct->screenshot ) : ?>
       
   135 <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
       
   136 <?php endif; ?>
       
   137 <h4><?php
       
   138 	/* translators: 1: theme title, 2: theme version, 3: theme author */
       
   139 	printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
       
   140 <p class="theme-description"><?php echo $ct->description; ?></p>
       
   141 <?php if ($ct->parent_theme) { ?>
       
   142 	<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.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ), $ct->title, $ct->parent_theme); ?></p>
       
   143 <?php } else { ?>
       
   144 	<p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ) ); ?></p>
       
   145 <?php } ?>
       
   146 <?php if ( $ct->tags ) : ?>
       
   147 <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
       
   148 <?php endif; ?>
       
   149 <?php theme_update_available($ct); ?>
       
   150 
       
   151 </div>
       
   152 
       
   153 <div class="clear"></div>
       
   154 <h3><?php _e('Available Themes'); ?></h3>
       
   155 <div class="clear"></div>
       
   156 
       
   157 <?php if ( $theme_total ) { ?>
       
   158 
       
   159 <?php if ( $page_links ) : ?>
       
   160 <div class="tablenav">
       
   161 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
       
   162 	number_format_i18n( $start + 1 ),
       
   163 	number_format_i18n( min( $page * $per_page, $theme_total ) ),
       
   164 	number_format_i18n( $theme_total ),
       
   165 	$page_links
       
   166 ); echo $page_links_text; ?></div>
       
   167 </div>
       
   168 <?php endif; ?>
       
   169 
       
   170 <table id="availablethemes" cellspacing="0" cellpadding="0">
       
   171 <?php
       
   172 $style = '';
       
   173 
       
   174 $theme_names = array_keys($themes);
       
   175 natcasesort($theme_names);
       
   176 
       
   177 $table = array();
       
   178 $rows = ceil(count($theme_names) / 3);
       
   179 for ( $row = 1; $row <= $rows; $row++ )
       
   180 	for ( $col = 1; $col <= 3; $col++ )
       
   181 		$table[$row][$col] = array_shift($theme_names);
       
   182 
       
   183 foreach ( $table as $row => $cols ) {
       
   184 ?>
       
   185 <tr>
       
   186 <?php
       
   187 foreach ( $cols as $col => $theme_name ) {
       
   188 	$class = array('available-theme');
       
   189 	if ( $row == 1 ) $class[] = 'top';
       
   190 	if ( $col == 1 ) $class[] = 'left';
       
   191 	if ( $row == $rows ) $class[] = 'bottom';
       
   192 	if ( $col == 3 ) $class[] = 'right';
       
   193 ?>
       
   194 	<td class="<?php echo join(' ', $class); ?>">
       
   195 <?php if ( !empty($theme_name) ) :
       
   196 	$template = $themes[$theme_name]['Template'];
       
   197 	$stylesheet = $themes[$theme_name]['Stylesheet'];
       
   198 	$title = $themes[$theme_name]['Title'];
       
   199 	$version = $themes[$theme_name]['Version'];
       
   200 	$description = $themes[$theme_name]['Description'];
       
   201 	$author = $themes[$theme_name]['Author'];
       
   202 	$screenshot = $themes[$theme_name]['Screenshot'];
       
   203 	$stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
       
   204 	$template_dir = $themes[$theme_name]['Template Dir'];
       
   205 	$parent_theme = $themes[$theme_name]['Parent Theme'];
       
   206 	$theme_root = $themes[$theme_name]['Theme Root'];
       
   207 	$theme_root_uri = $themes[$theme_name]['Theme Root URI'];
       
   208 	$preview_link = esc_url(get_option('home') . '/');
       
   209 	if ( is_ssl() )
       
   210 		$preview_link = str_replace( 'http://', 'https://', $preview_link );
       
   211 	$preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
       
   212 	$preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
       
   213 	$tags = $themes[$theme_name]['Tags'];
       
   214 	$thickbox_class = 'thickbox thickbox-preview';
       
   215 	$activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
       
   216 	$activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
       
   217 	$actions = array();
       
   218 	$actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
       
   219 	$actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
       
   220 	if ( current_user_can('update_themes') )
       
   221 		$actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url("themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet) . '" onclick="' . "if ( confirm('" . esc_js(sprintf( __("You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete."), $theme_name )) . "') ) {return true;}return false;" . '">' . __('Delete') . '</a>';
       
   222 	$actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
       
   223 
       
   224 	$actions = implode ( ' | ', $actions );
       
   225 ?>
       
   226 		<a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
       
   227 <?php if ( $screenshot ) : ?>
       
   228 			<img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
       
   229 <?php endif; ?>
       
   230 		</a>
       
   231 <h3><?php
       
   232 	/* translators: 1: theme title, 2: theme version, 3: theme author */
       
   233 	printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
       
   234 <p class="description"><?php echo $description; ?></p>
       
   235 <span class='action-links'><?php echo $actions ?></span>
       
   236 	<?php if ($parent_theme) {
       
   237 	/* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
       
   238 	<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>
       
   239 <?php } else { ?>
       
   240 	<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>
       
   241 <?php } ?>
       
   242 <?php if ( $tags ) : ?>
       
   243 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
       
   244 <?php endif; ?>
       
   245 		<?php theme_update_available( $themes[$theme_name] ); ?>
       
   246 <?php endif; // end if not empty theme_name ?>
       
   247 	</td>
       
   248 <?php } // end foreach $cols ?>
       
   249 </tr>
       
   250 <?php } // end foreach $table ?>
       
   251 </table>
       
   252 <?php } else { ?>
       
   253 <p><?php _e('You only have one theme installed at the moment so there is nothing to show you here.  Maybe you should download some more to try out.'); ?></p>
       
   254 <?php } // end if $theme_total?>
       
   255 <br class="clear" />
   266 <br class="clear" />
   256 
   267 
   257 <?php if ( $page_links ) : ?>
   268 <?php $wp_list_table->display(); ?>
   258 <div class="tablenav">
   269 
   259 <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
   270 </form>
   260 <br class="clear" />
   271 <br class="clear" />
   261 </div>
       
   262 <?php endif; ?>
       
   263 
       
   264 <br class="clear" />
       
   265 
   272 
   266 <?php
   273 <?php
   267 // List broken themes, if any.
   274 // List broken themes, if any.
   268 $broken_themes = get_broken_themes();
   275 if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
   269 if ( count($broken_themes) ) {
   276 ?>
   270 ?>
   277 
   271 
   278 <h3><?php _e('Broken Themes'); ?></h3>
   272 <h2><?php _e('Broken Themes'); ?></h2>
   279 <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
   273 <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
       
   274 
   280 
   275 <table id="broken-themes">
   281 <table id="broken-themes">
   276 	<tr>
   282 	<tr>
   277 		<th><?php _e('Name'); ?></th>
   283 		<th><?php _ex('Name', 'theme name'); ?></th>
   278 		<th><?php _e('Description'); ?></th>
   284 		<th><?php _e('Description'); ?></th>
   279 	</tr>
   285 	</tr>
   280 <?php
   286 <?php
   281 	$theme = '';
   287 	$alt = '';
   282 
   288 	foreach ( $broken_themes as $broken_theme ) {
   283 	$theme_names = array_keys($broken_themes);
   289 		$alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"';
   284 	natcasesort($theme_names);
       
   285 
       
   286 	foreach ($theme_names as $theme_name) {
       
   287 		$title = $broken_themes[$theme_name]['Title'];
       
   288 		$description = $broken_themes[$theme_name]['Description'];
       
   289 
       
   290 		$theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
       
   291 		echo "
   290 		echo "
   292 		<tr $theme>
   291 		<tr $alt>
   293 			 <td>$title</td>
   292 			 <td>" . $broken_theme->get('Name') ."</td>
   294 			 <td>$description</td>
   293 			 <td>" . $broken_theme->errors()->get_error_message() . "</td>
   295 		</tr>";
   294 		</tr>";
   296 	}
   295 	}
   297 ?>
   296 ?>
   298 </table>
   297 </table>
   299 <?php
   298 <?php
   300 }
   299 }
   301 ?>
   300 ?>
   302 </div>
   301 </div>
   303 
   302 
   304 <?php require('admin-footer.php'); ?>
   303 <?php require('./admin-footer.php'); ?>