WordPress 3.9
[autoinstalls/wordpress.git] / wp-admin / theme-install.php
1 <?php
2 /**
3  * Install theme administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11 require( ABSPATH . 'wp-admin/includes/theme-install.php' );
12
13 wp_reset_vars( array( 'tab' ) );
14
15 if ( ! current_user_can('install_themes') )
16         wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
17
18 if ( is_multisite() && ! is_network_admin() ) {
19         wp_redirect( network_admin_url( 'theme-install.php' ) );
20         exit();
21 }
22
23 $title = __( 'Add Themes' );
24 $parent_file = 'themes.php';
25
26 if ( ! is_network_admin() ) {
27         $submenu_file = 'themes.php';
28 }
29
30 $sections = array(
31         'featured' => __( 'Featured Themes' ),
32         'popular'  => __( 'Popular Themes' ),
33         'new'      => __( 'Newest Themes' ),
34 );
35
36 $installed_themes = search_theme_directories();
37 foreach ( $installed_themes as $k => $v ) {
38         if ( false !== strpos( $k, '/' ) ) {
39                 unset( $installed_themes[ $k ] );
40         }
41 }
42
43 wp_localize_script( 'theme', '_wpThemeSettings', array(
44         'themes'   => false,
45         'settings' => array(
46                 'isInstall'     => true,
47                 'canInstall'    => current_user_can( 'install_themes' ),
48                 'installURI'    => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
49                 'adminUrl'      => parse_url( self_admin_url(), PHP_URL_PATH )
50         ),
51         'l10n' => array(
52                 'addNew' => __( 'Add New Theme' ),
53                 'search'  => __( 'Search Themes' ),
54                 'searchPlaceholder' => __( 'Search themes...' ), // placeholder (no ellipsis)
55                 'upload' => __( 'Upload Theme' ),
56                 'back'   => __( 'Back' ),
57                 'error'  => __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' )
58         ),
59         'installedThemes' => array_keys( $installed_themes ),
60         'browse' => array(
61                 'sections' => $sections,
62         ),
63 ) );
64
65 wp_enqueue_script( 'theme' );
66
67 /**
68  * Fires before each of the tabs are rendered on the Install Themes page.
69  *
70  * The dynamic portion of the hook name, $tab, refers to the current
71  * theme install tab. Possible values are 'dashboard', 'search', 'upload',
72  * 'featured', 'new', or 'updated'.
73  *
74  * @since 2.8.0
75  */
76 if ( $tab ) {
77         do_action( "install_themes_pre_{$tab}" );
78 }
79
80 $help_overview =
81         '<p>' . sprintf(__('You can find additional themes for your site by using the Theme Browser/Installer on this screen, which will display themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. These themes are designed and developed by third parties, are available free of charge, and are compatible with the license WordPress uses.'), 'https://wordpress.org/themes/') . '</p>' .
82         '<p>' . __('You can Search for themes by keyword, author, or tag, or can get more specific and search by criteria listed in the feature filter. Alternately, you can browse the themes that are Featured, Newest, or Recently Updated. When you find a theme you like, you can preview it or install it.') . '</p>' .
83         '<p>' . __('You can Upload a theme manually if you have already downloaded its ZIP archive onto your computer (make sure it is from a trusted and original source). You can also do it the old-fashioned way and copy a downloaded theme&#8217;s folder via FTP into your <code>/wp-content/themes</code> directory.') . '</p>';
84
85 get_current_screen()->add_help_tab( array(
86         'id'      => 'overview',
87         'title'   => __('Overview'),
88         'content' => $help_overview
89 ) );
90
91 $help_installing =
92         '<p>' . __('Once you have generated a list of themes, you can preview and install any of them. Click on the thumbnail of the theme you&#8217;re interested in previewing. It will open up in a full-screen Preview page to give you a better idea of how that theme will look.') . '</p>' .
93         '<p>' . __('To install the theme so you can preview it with your site&#8217;s content and customize its theme options, click the "Install" button at the top of the left-hand pane. The theme files will be downloaded to your website automatically. When this is complete, the theme is now available for activation, which you can do by clicking the "Activate" link, or by navigating to your Manage Themes screen and clicking the "Live Preview" link under any installed theme&#8217;s thumbnail image.') . '</p>';
94
95 get_current_screen()->add_help_tab( array(
96         'id'      => 'installing',
97         'title'   => __('Previewing and Installing'),
98         'content' => $help_installing
99 ) );
100
101 get_current_screen()->set_help_sidebar(
102         '<p><strong>' . __('For more information:') . '</strong></p>' .
103         '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
104         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
105 );
106
107 include(ABSPATH . 'wp-admin/admin-header.php');
108
109 ?>
110 <div class="wrap">
111         <h2>
112                 <?php echo esc_html( $title ); ?>
113                 <a href="#" class="upload add-new-h2"><?php _e( 'Upload Theme' ); ?></a>
114                 <a href="#" class="browse-themes add-new-h2"><?php _ex( 'Browse', 'themes' ); ?></a>
115         </h2>
116
117         <div class="upload-theme">
118         <?php install_themes_upload(); ?>
119         </div>
120
121         <div class="theme-navigation">
122                 <span class="theme-count"></span>
123                 <a class="theme-section" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>
124                 <a class="theme-section" href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a>
125                 <a class="theme-section" href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a>
126                 <div class="theme-top-filters">
127                         <!-- <span class="theme-filter" data-filter="photoblogging">Photography</span>
128                         <span class="theme-filter" data-filter="responsive-layout">Responsive</span> -->
129                         <a class="more-filters" href="#"><?php _e( 'Feature Filter' ); ?></a>
130                 </div>
131                 <div class="more-filters-container">
132                         <a class="apply-filters button button-secondary" href="#"><?php _e( 'Apply Filters' ); ?><span></span></a>
133                         <a class="clear-filters button button-secondary" href="#"><?php _e( 'Clear' ); ?></a>
134                         <br class="clear" />
135                 <?php
136                 $feature_list = get_theme_feature_list();
137                 foreach ( $feature_list as $feature_name => $features ) {
138                         if ( $feature_name === 'Features' || $feature_name === __( 'Features' ) ) { // hack hack hack
139                                 echo '<div class="filters-group wide-filters-group">';
140                         } else {
141                                 echo '<div class="filters-group">';
142                         }
143                         $feature_name = esc_html( $feature_name );
144                         echo '<h4 class="feature-name">' . $feature_name . '</h4>';
145                         echo '<ol class="feature-group">';
146                         foreach ( $features as $feature => $feature_name ) {
147                                 $feature = esc_attr( $feature );
148                                 echo '<li><input type="checkbox" id="feature-id-' . $feature . '" value="' . $feature . '" /> ';
149                                 echo '<label for="feature-id-' . $feature . '">' . $feature_name . '</label></li>';
150                         }
151                         echo '</ol>';
152                         echo '</div>';
153                 }
154                 ?>
155                         <div class="filtering-by">
156                                 <span><?php _e( 'Filtering by:' ); ?></span>
157                                 <div class="tags"></div>
158                                 <a href="#"><?php _e( 'Edit' ); ?></a>
159                         </div>
160                 </div>
161         </div>
162         <div class="theme-browser"></div>
163         <div class="theme-install-overlay wp-full-overlay expanded"></div>
164
165         <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
166         <span class="spinner"></span>
167
168         <br class="clear" />
169 <?php
170 /**
171  * Fires at the top of each of the tabs on the Install Themes page.
172  *
173  * The dynamic portion of the hook name, $tab, refers to the current
174  * theme install tab. Possible values are 'dashboard', 'search', 'upload',
175  * 'featured', 'new', or 'updated'.
176  *
177  * @since 2.8.0
178  *
179  * @param int $paged Number of the current page of results being viewed.
180  */
181 if ( $tab ) {
182         do_action( "install_themes_{$tab}", $paged );
183 }
184 ?>
185 </div>
186
187 <script id="tmpl-theme" type="text/template">
188         <# if ( data.screenshot_url ) { #>
189                 <div class="theme-screenshot">
190                         <img src="{{ data.screenshot_url }}" alt="" />
191                 </div>
192         <# } else { #>
193                 <div class="theme-screenshot blank"></div>
194         <# } #>
195         <span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
196         <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
197         <h3 class="theme-name">{{ data.name }}</h3>
198
199         <div class="theme-actions">
200                 <a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a>
201                 <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
202         </div>
203
204         <# if ( data.installed ) { #>
205                 <div class="theme-installed"><?php _e( 'Already Installed' ); ?></div>
206         <# } #>
207 </script>
208
209 <script id="tmpl-theme-preview" type="text/template">
210         <div class="wp-full-overlay-sidebar">
211                 <div class="wp-full-overlay-header">
212                         <a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a>
213                 <# if ( data.installed ) { #>
214                         <a href="#" class="button button-primary theme-install disabled"><?php _e( 'Installed' ); ?></a>
215                 <# } else { #>
216                         <a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
217                 <# } #>
218                 </div>
219                 <div class="wp-full-overlay-sidebar-content">
220                         <div class="install-theme-info">
221                                 <h3 class="theme-name">{{ data.name }}</h3>
222                                 <span class="theme-by"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></span>
223
224                                 <img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
225
226                                 <div class="theme-details">
227                                         <div class="rating rating-{{ Math.round( data.rating / 10 ) * 10 }}">
228                                                 <span class="one"></span>
229                                                 <span class="two"></span>
230                                                 <span class="three"></span>
231                                                 <span class="four"></span>
232                                                 <span class="five"></span>
233                                         <# if ( data.num_ratings ) { #>
234                                                 <p class="ratings">{{ data.num_ratings }}</p>
235                                         <# } else { #>
236                                                 <p class="ratings"><?php _e( 'No ratings.' ); ?></p>
237                                         <# } #>
238                                         </div>
239                                         <div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
240                                         <div class="theme-description">{{{ data.description }}}</div>
241                                 </div>
242                         </div>
243                 </div>
244                 <div class="wp-full-overlay-footer">
245                         <a href="#" class="collapse-sidebar" title="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
246                                 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
247                                 <span class="collapse-sidebar-arrow"></span>
248                         </a>
249                         <div class="theme-navigation">
250                                 <a class="previous-theme button" href="#"><?php _e( 'Previous' ); ?></a>
251                                 <a class="next-theme button" href="#"><?php _e( 'Next' ); ?></a>
252                         </div>
253                 </div>
254         </div>
255         <div class="wp-full-overlay-main">
256                 <iframe src="{{ data.preview_url }}" />
257         </div>
258 </script>
259
260 <?php
261 include(ABSPATH . 'wp-admin/admin-footer.php');