]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/themes.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / themes.php
1 <?php
2 require_once('admin.php');
3
4 if ( isset($_GET['action']) ) {
5         check_admin_referer('switch-theme_' . $_GET['template']);
6
7         if ('activate' == $_GET['action']) {
8                 switch_theme($_GET['template'], $_GET['stylesheet']);
9                 wp_redirect('themes.php?activated=true');
10                 exit;
11         }
12 }
13
14 $title = __('Manage Themes');
15 $parent_file = 'themes.php';
16
17 add_thickbox();
18 wp_enqueue_script( 'theme-preview' );
19
20 require_once('admin-header.php');
21 ?>
22
23 <?php if ( ! validate_current_theme() ) : ?>
24 <div id="message1" class="updated fade"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div>
25 <?php elseif ( isset($_GET['activated']) ) : ?>
26 <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div>
27 <?php endif; ?>
28
29 <?php
30 $themes = get_themes();
31 $ct = current_theme_info();
32
33 ksort( $themes );
34 $theme_total = count( $themes );
35 $per_page = 15;
36
37 if ( isset( $_GET['pagenum'] ) )
38         $page = absint( $_GET['pagenum'] );
39
40 if ( empty($page) )
41         $page = 1;
42
43 $start = $offset = ( $page - 1 ) * $per_page;
44
45 $page_links = paginate_links( array(
46         'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
47         'format' => '',
48         'total' => ceil($theme_total / $per_page),
49         'current' => $page
50 ));
51
52 $themes = array_slice( $themes, $start, $per_page );
53
54 ?>
55
56 <div class="wrap">
57 <h2><?php _e('Current Theme'); ?></h2>
58 <div id="current-theme">
59 <?php if ( $ct->screenshot ) : ?>
60 <img src="<?php echo WP_CONTENT_URL . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
61 <?php endif; ?>
62 <h3><?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) ; ?></h3>
63 <p class="description"><?php echo $ct->description; ?></p>
64 <?php if ($ct->parent_theme) { ?>
65         <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>
66 <?php } else { ?>
67         <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>
68 <?php } ?>
69 <?php if ( $ct->tags ) : ?>
70 <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
71 <?php endif; ?>
72 </div>
73
74 <h2><?php _e('Available Themes'); ?></h2>
75 <br class="clear" />
76
77 <?php if ( $page_links ) : ?>
78 <div class="tablenav">
79 <?php echo "<div class='tablenav-pages'>$page_links</div>"; ?>
80 <br class="clear" />
81 </div>
82 <br class="clear" />
83 <?php endif; ?>
84
85 <?php if ( 1 < $theme_total ) { ?>
86 <table id="availablethemes" cellspacing="0" cellpadding="0">
87 <?php
88 $style = '';
89
90 $theme_names = array_keys($themes);
91 natcasesort($theme_names);
92
93 $rows = ceil(count($theme_names) / 3);
94 for ( $row = 1; $row <= $rows; $row++ )
95         for ( $col = 1; $col <= 3; $col++ )
96                 $table[$row][$col] = array_shift($theme_names);
97
98 foreach ( $table as $row => $cols ) {
99 ?>
100 <tr>
101 <?php
102 foreach ( $cols as $col => $theme_name ) {
103         $class = array('available-theme');
104         if ( $row == 1 ) $class[] = 'top';
105         if ( $col == 1 ) $class[] = 'left';
106         if ( $row == $rows ) $class[] = 'bottom';
107         if ( $col == 3 ) $class[] = 'right';
108 ?>
109         <td class="<?php echo join(' ', $class); ?>">
110 <?php if ( !empty($theme_name) ) :
111         $template = $themes[$theme_name]['Template'];
112         $stylesheet = $themes[$theme_name]['Stylesheet'];
113         $title = $themes[$theme_name]['Title'];
114         $version = $themes[$theme_name]['Version'];
115         $description = $themes[$theme_name]['Description'];
116         $author = $themes[$theme_name]['Author'];
117         $screenshot = $themes[$theme_name]['Screenshot'];
118         $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
119         $preview_link = clean_url( get_option('home') . '/');
120         $preview_link = add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true', 'width' => 600, 'height' => 400 ), $preview_link );
121         $preview_text = attribute_escape( sprintf( __('Preview of "%s"'), $title ) );
122         $tags = $themes[$theme_name]['Tags'];
123         $thickbox_class = 'thickbox';
124         $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
125         $activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) );
126 ?>
127                 <a href="<?php echo $activate_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
128 <?php if ( $screenshot ) : ?>
129                         <img src="<?php echo WP_CONTENT_URL . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
130 <?php endif; ?>
131                 </a>
132                 <h3><a class="<?php echo $thickbox_class; ?>" href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3>
133                 <p><?php echo $description; ?></p>
134 <?php if ( $tags ) : ?>
135                 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
136                 <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>
137 <?php endif; ?>
138                 <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>
139 <?php endif; // end if not empty theme_name ?>
140         </td>
141 <?php } // end foreach $cols ?>
142 </tr>
143 <?php } // end foreach $table ?>
144 </table>
145 <?php } ?>
146
147 <br class="clear" />
148
149 <?php if ( $page_links ) : ?>
150 <div class="tablenav">
151 <?php echo "<div class='tablenav-pages'>$page_links</div>"; ?>
152 <br class="clear" />
153 </div>
154 <?php endif; ?>
155
156 <br class="clear" />
157
158 <?php
159 // List broken themes, if any.
160 $broken_themes = get_broken_themes();
161 if ( count($broken_themes) ) {
162 ?>
163
164 <h2><?php _e('Broken Themes'); ?></h2>
165 <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
166
167 <table width="100%" cellpadding="3" cellspacing="3">
168         <tr>
169                 <th><?php _e('Name'); ?></th>
170                 <th><?php _e('Description'); ?></th>
171         </tr>
172 <?php
173         $theme = '';
174
175         $theme_names = array_keys($broken_themes);
176         natcasesort($theme_names);
177
178         foreach ($theme_names as $theme_name) {
179                 $title = $broken_themes[$theme_name]['Title'];
180                 $description = $broken_themes[$theme_name]['Description'];
181
182                 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
183                 echo "
184                 <tr $theme>
185                          <td>$title</td>
186                          <td>$description</td>
187                 </tr>";
188         }
189 ?>
190 </table>
191 <?php
192 }
193 ?>
194
195 <h2><?php _e('Get More Themes'); ?></h2>
196 <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>
197
198 </div>
199
200 <?php require('admin-footer.php'); ?>