]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/themes.php
Wordpress 2.8.3-scripts
[autoinstalls/wordpress.git] / wp-admin / themes.php
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 ); ?></h2>
131
132 <h3><?php _e('Current Theme'); ?></h3>
133 <div id="current-theme">
134 <?php if ( $ct->screenshot ) : ?>
135 <img src="<?php echo content_url($ct->stylesheet_dir . '/' . $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, $ct->template_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, $ct->template_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         $preview_link = esc_url(get_option('home') . '/');
207         if ( is_ssl() )
208                 $preview_link = str_replace( 'http://', 'https://', $preview_link );
209         $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
210         $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
211         $tags = $themes[$theme_name]['Tags'];
212         $thickbox_class = 'thickbox thickbox-preview';
213         $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
214         $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
215         $actions = array();
216         $actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
217         $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
218         if ( current_user_can('update_themes') )
219                 $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>';
220         $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
221
222         $actions = implode ( ' | ', $actions );
223 ?>
224                 <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
225 <?php if ( $screenshot ) : ?>
226                         <img src="<?php echo content_url($stylesheet_dir . '/' . $screenshot); ?>" alt="" />
227 <?php endif; ?>
228                 </a>
229 <h3><?php
230         /* translators: 1: theme title, 2: theme version, 3: theme author */
231         printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
232 <p class="description"><?php echo $description; ?></p>
233 <span class='action-links'><?php echo $actions ?></span>
234         <?php if ($parent_theme) {
235         /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
236         <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, $template_dir, $stylesheet_dir, $title, $parent_theme); ?></p>
237 <?php } else { ?>
238         <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, $template_dir, $stylesheet_dir); ?></p>
239 <?php } ?>
240 <?php if ( $tags ) : ?>
241 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
242 <?php endif; ?>
243                 <?php theme_update_available( $themes[$theme_name] ); ?>
244 <?php endif; // end if not empty theme_name ?>
245         </td>
246 <?php } // end foreach $cols ?>
247 </tr>
248 <?php } // end foreach $table ?>
249 </table>
250 <?php } else { ?>
251 <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>
252 <?php } // end if $theme_total?>
253 <br class="clear" />
254
255 <?php if ( $page_links ) : ?>
256 <div class="tablenav">
257 <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
258 <br class="clear" />
259 </div>
260 <?php endif; ?>
261
262 <br class="clear" />
263
264 <?php
265 // List broken themes, if any.
266 $broken_themes = get_broken_themes();
267 if ( count($broken_themes) ) {
268 ?>
269
270 <h2><?php _e('Broken Themes'); ?></h2>
271 <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
272
273 <table width="100%" cellpadding="3" cellspacing="3">
274         <tr>
275                 <th><?php _e('Name'); ?></th>
276                 <th><?php _e('Description'); ?></th>
277         </tr>
278 <?php
279         $theme = '';
280
281         $theme_names = array_keys($broken_themes);
282         natcasesort($theme_names);
283
284         foreach ($theme_names as $theme_name) {
285                 $title = $broken_themes[$theme_name]['Title'];
286                 $description = $broken_themes[$theme_name]['Description'];
287
288                 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
289                 echo "
290                 <tr $theme>
291                          <td>$title</td>
292                          <td>$description</td>
293                 </tr>";
294         }
295 ?>
296 </table>
297 <?php
298 }
299 ?>
300 </div>
301
302 <?php require('admin-footer.php'); ?>