WordPress 4.1-scripts
[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 $installed_themes = search_theme_directories();
31 foreach ( $installed_themes as $k => $v ) {
32         if ( false !== strpos( $k, '/' ) ) {
33                 unset( $installed_themes[ $k ] );
34         }
35 }
36
37 wp_localize_script( 'theme', '_wpThemeSettings', array(
38         'themes'   => false,
39         'settings' => array(
40                 'isInstall'     => true,
41                 'canInstall'    => current_user_can( 'install_themes' ),
42                 'installURI'    => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
43                 'adminUrl'      => parse_url( self_admin_url(), PHP_URL_PATH )
44         ),
45         'l10n' => array(
46                 'addNew' => __( 'Add New Theme' ),
47                 'search'  => __( 'Search Themes' ),
48                 'searchPlaceholder' => __( 'Search themes...' ), // placeholder (no ellipsis)
49                 'upload' => __( 'Upload Theme' ),
50                 'back'   => __( 'Back' ),
51                 '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>.' )
52         ),
53         'installedThemes' => array_keys( $installed_themes ),
54 ) );
55
56 wp_enqueue_script( 'theme' );
57
58 if ( $tab ) {
59         /**
60          * Fires before each of the tabs are rendered on the Install Themes page.
61          *
62          * The dynamic portion of the hook name, `$tab`, refers to the current
63          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
64          * 'featured', 'new', or 'updated'.
65          *
66          * @since 2.8.0
67          */
68         do_action( "install_themes_pre_{$tab}" );
69 }
70
71 $help_overview =
72         '<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>' .
73         '<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, Popular, or Latest. When you find a theme you like, you can preview it or install it.') . '</p>' .
74         '<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>';
75
76 get_current_screen()->add_help_tab( array(
77         'id'      => 'overview',
78         'title'   => __('Overview'),
79         'content' => $help_overview
80 ) );
81
82 $help_installing =
83         '<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>' .
84         '<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>';
85
86 get_current_screen()->add_help_tab( array(
87         'id'      => 'installing',
88         'title'   => __('Previewing and Installing'),
89         'content' => $help_installing
90 ) );
91
92 get_current_screen()->set_help_sidebar(
93         '<p><strong>' . __('For more information:') . '</strong></p>' .
94         '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
95         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
96 );
97
98 include(ABSPATH . 'wp-admin/admin-header.php');
99
100 ?>
101 <div class="wrap">
102         <h2><?php
103         echo esc_html( $title );
104
105         /**
106          * Filter the tabs shown on the Add Themes screen.
107          *
108          * This filter is for backwards compatibility only, for the suppression
109          * of the upload tab.
110          *
111          * @since 2.8.0
112          *
113          * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
114          */
115         $tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
116         if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
117                 echo ' <a href="#" class="upload add-new-h2">' . __( 'Upload Theme' ) . '</a>';
118                 echo ' <a href="#" class="browse-themes add-new-h2">' . _x( 'Browse', 'themes' ) . '</a>';
119         }
120         ?></h2>
121
122         <div class="upload-theme">
123         <?php install_themes_upload(); ?>
124         </div>
125
126         <div class="wp-filter">
127                 <div class="filter-count">
128                         <span class="count theme-count"></span>
129                 </div>
130
131                 <ul class="filter-links">
132                         <li><a href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a></li>
133                         <li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
134                         <li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
135                 </ul>
136
137                 <a class="drawer-toggle" href="#"><?php _e( 'Feature Filter' ); ?></a>
138
139                 <div class="search-form"></div>
140
141                 <div class="filter-drawer">
142                         <div class="buttons">
143                                 <a class="apply-filters button button-secondary" href="#"><?php _e( 'Apply Filters' ); ?><span></span></a>
144                                 <a class="clear-filters button button-secondary" href="#"><?php _e( 'Clear' ); ?></a>
145                         </div>
146                 <?php
147                 $feature_list = get_theme_feature_list();
148                 foreach ( $feature_list as $feature_name => $features ) {
149                         echo '<div class="filter-group">';
150                         $feature_name = esc_html( $feature_name );
151                         echo '<h4>' . $feature_name . '</h4>';
152                         echo '<ol class="feature-group">';
153                         foreach ( $features as $feature => $feature_name ) {
154                                 $feature = esc_attr( $feature );
155                                 echo '<li><input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
156                                 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label></li>';
157                         }
158                         echo '</ol>';
159                         echo '</div>';
160                 }
161                 ?>
162                         <div class="filtered-by">
163                                 <span><?php _e( 'Filtering by:' ); ?></span>
164                                 <div class="tags"></div>
165                                 <a href="#"><?php _e( 'Edit' ); ?></a>
166                         </div>
167                 </div>
168         </div>
169         <div class="theme-browser content-filterable"></div>
170         <div class="theme-install-overlay wp-full-overlay expanded"></div>
171
172         <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
173         <span class="spinner"></span>
174
175         <br class="clear" />
176 <?php
177 if ( $tab ) {
178         /**
179          * Fires at the top of each of the tabs on the Install Themes page.
180          *
181          * The dynamic portion of the hook name, `$tab`, refers to the current
182          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
183          * 'featured', 'new', or 'updated'.
184          *
185          * @since 2.8.0
186          *
187          * @param int $paged Number of the current page of results being viewed.
188          */
189         do_action( "install_themes_{$tab}", $paged );
190 }
191 ?>
192 </div>
193
194 <script id="tmpl-theme" type="text/template">
195         <# if ( data.screenshot_url ) { #>
196                 <div class="theme-screenshot">
197                         <img src="{{ data.screenshot_url }}" alt="" />
198                 </div>
199         <# } else { #>
200                 <div class="theme-screenshot blank"></div>
201         <# } #>
202         <span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
203         <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
204         <h3 class="theme-name">{{ data.name }}</h3>
205
206         <div class="theme-actions">
207                 <a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a>
208                 <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
209         </div>
210
211         <# if ( data.installed ) { #>
212                 <div class="theme-installed"><?php _ex( 'Already Installed', 'theme' ); ?></div>
213         <# } #>
214 </script>
215
216 <script id="tmpl-theme-preview" type="text/template">
217         <div class="wp-full-overlay-sidebar">
218                 <div class="wp-full-overlay-header">
219                         <a href="#" class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></a>
220                         <a href="#" class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></a>
221                         <a href="#" class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></a>
222                 <# if ( data.installed ) { #>
223                         <a href="#" class="button button-primary theme-install disabled"><?php _ex( 'Installed', 'theme' ); ?></a>
224                 <# } else { #>
225                         <a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
226                 <# } #>
227                 </div>
228                 <div class="wp-full-overlay-sidebar-content">
229                         <div class="install-theme-info">
230                                 <h3 class="theme-name">{{ data.name }}</h3>
231                                 <span class="theme-by"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></span>
232
233                                 <img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
234
235                                 <div class="theme-details">
236                                         <div class="rating rating-{{ Math.round( data.rating / 10 ) * 10 }}">
237                                                 <span class="one"></span>
238                                                 <span class="two"></span>
239                                                 <span class="three"></span>
240                                                 <span class="four"></span>
241                                                 <span class="five"></span>
242                                         <# if ( data.num_ratings ) { #>
243                                                 <small class="ratings">{{ data.num_ratings }}</small>
244                                         <# } else { #>
245                                                 <small class="ratings"><?php _e( 'No ratings.' ); ?></small>
246                                         <# } #>
247                                         </div>
248                                         <div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
249                                         <div class="theme-description">{{{ data.description }}}</div>
250                                 </div>
251                         </div>
252                 </div>
253                 <div class="wp-full-overlay-footer">
254                         <a href="#" class="collapse-sidebar" title="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
255                                 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
256                                 <span class="collapse-sidebar-arrow"></span>
257                         </a>
258                 </div>
259         </div>
260         <div class="wp-full-overlay-main">
261                 <iframe src="{{ data.preview_url }}" />
262         </div>
263 </script>
264
265 <?php
266 include(ABSPATH . 'wp-admin/admin-footer.php');