web/wp-admin/themes.php
changeset 136 bde1974c263b
child 194 32102edaa81b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /**
       
     3  * Themes administration panel.
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Administration
       
     7  */
       
     8 
       
     9 /** WordPress Administration Bootstrap */
       
    10 require_once('admin.php');
       
    11 
       
    12 if ( !current_user_can('switch_themes') )
       
    13 	wp_die( __( 'Cheatin&#8217; uh?' ) );
       
    14 
       
    15 if ( isset($_GET['action']) ) {
       
    16 	if ( 'activate' == $_GET['action'] ) {
       
    17 		check_admin_referer('switch-theme_' . $_GET['template']);
       
    18 		switch_theme($_GET['template'], $_GET['stylesheet']);
       
    19 		wp_redirect('themes.php?activated=true');
       
    20 		exit;
       
    21 	} else if ( 'delete' == $_GET['action'] ) {
       
    22 		check_admin_referer('delete-theme_' . $_GET['template']);
       
    23 		if ( !current_user_can('update_themes') )
       
    24 			wp_die( __( 'Cheatin&#8217; uh?' ) );
       
    25 		delete_theme($_GET['template']);
       
    26 		wp_redirect('themes.php?deleted=true');
       
    27 		exit;
       
    28 	}
       
    29 }
       
    30 
       
    31 $title = __('Manage Themes');
       
    32 $parent_file = 'themes.php';
       
    33 
       
    34 $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
       
    35 if ( current_user_can('install_themes') ) {
       
    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>';
       
    37 	$help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>' ;
       
    38 }
       
    39 
       
    40 add_contextual_help('themes', $help);
       
    41 
       
    42 add_thickbox();
       
    43 wp_enqueue_script( 'theme-preview' );
       
    44 
       
    45 require_once('admin-header.php');
       
    46 ?>
       
    47 
       
    48 <?php if ( ! validate_current_theme() ) : ?>
       
    49 <div id="message1" class="updated fade"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div>
       
    50 <?php elseif ( isset($_GET['activated']) ) :
       
    51 		if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?>
       
    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
       
    53 		} 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
       
    55 		}
       
    56 	elseif ( isset($_GET['deleted']) ) : ?>
       
    57 <div id="message3" class="updated fade"><p><?php _e('Theme deleted.') ?></p></div>
       
    58 <?php endif; ?>
       
    59 
       
    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" />
       
   256 
       
   257 <?php if ( $page_links ) : ?>
       
   258 <div class="tablenav">
       
   259 <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
       
   260 <br class="clear" />
       
   261 </div>
       
   262 <?php endif; ?>
       
   263 
       
   264 <br class="clear" />
       
   265 
       
   266 <?php
       
   267 // List broken themes, if any.
       
   268 $broken_themes = get_broken_themes();
       
   269 if ( count($broken_themes) ) {
       
   270 ?>
       
   271 
       
   272 <h2><?php _e('Broken Themes'); ?></h2>
       
   273 <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
       
   274 
       
   275 <table id="broken-themes">
       
   276 	<tr>
       
   277 		<th><?php _e('Name'); ?></th>
       
   278 		<th><?php _e('Description'); ?></th>
       
   279 	</tr>
       
   280 <?php
       
   281 	$theme = '';
       
   282 
       
   283 	$theme_names = array_keys($broken_themes);
       
   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 "
       
   292 		<tr $theme>
       
   293 			 <td>$title</td>
       
   294 			 <td>$description</td>
       
   295 		</tr>";
       
   296 	}
       
   297 ?>
       
   298 </table>
       
   299 <?php
       
   300 }
       
   301 ?>
       
   302 </div>
       
   303 
       
   304 <?php require('admin-footer.php'); ?>