Projects : mp-wp : mp-wp_genesis

mp-wp/wp-admin/themes.php

Dir - Raw

1<?php
2/**
3 * Themes administration panel.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** WordPress Administration Bootstrap */
10require_once('admin.php');
11
12if ( isset($_GET['action']) ) {
13 check_admin_referer('switch-theme_' . $_GET['template']);
14
15 if ('activate' == $_GET['action']) {
16 switch_theme($_GET['template'], $_GET['stylesheet']);
17 wp_redirect('themes.php?activated=true');
18 exit;
19 }
20}
21
22$title = __('Manage Themes');
23$parent_file = 'themes.php';
24
25add_thickbox();
26wp_enqueue_script( 'theme-preview' );
27
28require_once('admin-header.php');
29?>
30
31<?php if ( ! validate_current_theme() ) : ?>
32<div id="message1" class="updated fade"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
33<?php elseif ( isset($_GET['activated']) ) : ?>
34<div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div>
35<?php endif; ?>
36
37<?php
38$themes = get_themes();
39$ct = current_theme_info();
40
41ksort( $themes );
42$theme_total = count( $themes );
43$per_page = 15;
44
45if ( isset( $_GET['pagenum'] ) )
46 $page = absint( $_GET['pagenum'] );
47
48if ( empty($page) )
49 $page = 1;
50
51$start = $offset = ( $page - 1 ) * $per_page;
52
53$page_links = paginate_links( array(
54 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
55 'format' => '',
56 'prev_text' => __('&laquo;'),
57 'next_text' => __('&raquo;'),
58 'total' => ceil($theme_total / $per_page),
59 'current' => $page
60));
61
62$themes = array_slice( $themes, $start, $per_page );
63
64/**
65 * Check if there is an update for a theme available.
66 *
67 * Will display link, if there is an update available.
68 *
69 * @since 2.7.0
70 *
71 * @param object $theme Theme data object.
72 * @return bool False if no valid info was passed.
73 */
74function theme_update_available( $theme ) {
75 static $themes_update;
76 if ( !isset($themes_update) )
77 $themes_update = get_option('update_themes');
78
79 if ( is_object($theme) && isset($theme->stylesheet) )
80 $stylesheet = $theme->stylesheet;
81 elseif ( is_array($theme) && isset($theme['Stylesheet']) )
82 $stylesheet = $theme['Stylesheet'];
83 else
84 return false; //No valid info passed.
85
86 if ( isset($themes_update->response[ $stylesheet ]) ) {
87 $update = $themes_update->response[ $stylesheet ];
88 $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.
89 $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
90
91 if ( ! current_user_can('update_themes') )
92 printf( __('<p>There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.</p>'), $ct->name, $details_url, $update['new_version']);
93 else if ( empty($update->package) )
94 printf( __('<p>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>.</p>'), $ct->name, $details_url, $update['new_version']);
95 else
96 printf( __('<p>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">upgrade automatically</a>.</p>'), $ct->name, $details_url, $update['new_version'], $update_url );
97 }
98}
99
100?>
101
102<div class="wrap">
103<?php screen_icon(); ?>
104<h2><?php echo wp_specialchars( $title ); ?></h2>
105
106<h3><?php _e('Current Theme'); ?></h3>
107<div id="current-theme">
108<?php if ( $ct->screenshot ) : ?>
109<img src="<?php echo WP_CONTENT_URL . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
110<?php endif; ?>
111<h4><?php printf(_c('%1$s %2$s by %3$s|1: theme title, 2: theme version, 3: theme author'), $ct->title, $ct->version, $ct->author) ; ?></h4>
112<p class="description"><?php echo $ct->description; ?></p>
113<?php if ($ct->parent_theme) { ?>
114 <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>
115<?php } else { ?>
116 <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>
117<?php } ?>
118<?php if ( $ct->tags ) : ?>
119<p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
120<?php endif; ?>
121<?php theme_update_available($ct); ?>
122
123</div>
124<div class="clear"></div>
125<h3><?php _e('Available Themes'); ?></h3>
126<div class="clear"></div>
127
128<?php if ( $page_links ) : ?>
129<div class="tablenav">
130<div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
131 number_format_i18n( $start + 1 ),
132 number_format_i18n( min( $page * $per_page, $theme_total ) ),
133 number_format_i18n( $theme_total ),
134 $page_links
135); echo $page_links_text; ?></div>
136</div>
137<?php endif; ?>
138
139<?php if ( 1 < $theme_total ) { ?>
140<table id="availablethemes" cellspacing="0" cellpadding="0">
141<?php
142$style = '';
143
144$theme_names = array_keys($themes);
145natcasesort($theme_names);
146
147$rows = ceil(count($theme_names) / 3);
148for ( $row = 1; $row <= $rows; $row++ )
149 for ( $col = 1; $col <= 3; $col++ )
150 $table[$row][$col] = array_shift($theme_names);
151
152foreach ( $table as $row => $cols ) {
153?>
154<tr>
155<?php
156foreach ( $cols as $col => $theme_name ) {
157 $class = array('available-theme');
158 if ( $row == 1 ) $class[] = 'top';
159 if ( $col == 1 ) $class[] = 'left';
160 if ( $row == $rows ) $class[] = 'bottom';
161 if ( $col == 3 ) $class[] = 'right';
162?>
163 <td class="<?php echo join(' ', $class); ?>">
164<?php if ( !empty($theme_name) ) :
165 $template = $themes[$theme_name]['Template'];
166 $stylesheet = $themes[$theme_name]['Stylesheet'];
167 $title = $themes[$theme_name]['Title'];
168 $version = $themes[$theme_name]['Version'];
169 $description = $themes[$theme_name]['Description'];
170 $author = $themes[$theme_name]['Author'];
171 $screenshot = $themes[$theme_name]['Screenshot'];
172 $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
173 $preview_link = clean_url( get_option('home') . '/');
174 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true', 'width' => 600, 'height' => 400 ), $preview_link ) );
175 $preview_text = attribute_escape( sprintf( __('Preview of "%s"'), $title ) );
176 $tags = $themes[$theme_name]['Tags'];
177 $thickbox_class = 'thickbox';
178 $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
179 $activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) );
180?>
181 <a href="<?php echo $activate_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
182<?php if ( $screenshot ) : ?>
183 <img src="<?php echo WP_CONTENT_URL . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
184<?php endif; ?>
185 </a>
186 <h3><a class="<?php echo $thickbox_class; ?>" href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3>
187 <p><?php echo $description; ?></p>
188<?php if ( $tags ) : ?>
189 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
190<?php endif; ?>
191 <?php theme_update_available( $themes[$theme_name] ); ?>
192 <noscript><p class="themeactions"><a href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>"><?php _e('Preview'); ?></a> <a href="<?php echo $activate_link; ?>" title="<?php echo $activate_text; ?>"><?php _e('Activate'); ?></a></p></noscript>
193 <div style="display:none;"><a class="previewlink" href="<?php echo $preview_link; ?>"><?php echo $preview_text; ?></a> <a class="activatelink" href="<?php echo $activate_link; ?>"><?php echo $activate_text; ?></a></div>
194<?php endif; // end if not empty theme_name ?>
195 </td>
196<?php } // end foreach $cols ?>
197</tr>
198<?php } // end foreach $table ?>
199</table>
200<?php } ?>
201
202<br class="clear" />
203
204<?php if ( $page_links ) : ?>
205<div class="tablenav">
206<?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
207<br class="clear" />
208</div>
209<?php endif; ?>
210
211<br class="clear" />
212
213<?php
214// List broken themes, if any.
215$broken_themes = get_broken_themes();
216if ( count($broken_themes) ) {
217?>
218
219<h2><?php _e('Broken Themes'); ?></h2>
220<p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
221
222<table width="100%" cellpadding="3" cellspacing="3">
223 <tr>
224 <th><?php _e('Name'); ?></th>
225 <th><?php _e('Description'); ?></th>
226 </tr>
227<?php
228 $theme = '';
229
230 $theme_names = array_keys($broken_themes);
231 natcasesort($theme_names);
232
233 foreach ($theme_names as $theme_name) {
234 $title = $broken_themes[$theme_name]['Title'];
235 $description = $broken_themes[$theme_name]['Description'];
236
237 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
238 echo "
239 <tr $theme>
240 <td>$title</td>
241 <td>$description</td>
242 </tr>";
243 }
244?>
245</table>
246<?php
247}
248?>
249
250<h2><?php _e('Get More Themes'); ?></h2>
251<p><?php _e('You can find additional themes for your site in the <a href="http://wordpress.org/extend/themes/">WordPress theme directory</a>. To install a theme you generally just need to upload the theme folder into your <code>wp-content/themes</code> directory. Once a theme is uploaded, you should see it on this page.'); ?></p>
252
253</div>
254
255<?php require('admin-footer.php'); ?>