WordPress 4.5
[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                 'themesFound'   => __( 'Number of Themes found: %d' ),
53                 'noThemesFound' => __( 'No themes found. Try a different search.' ),
54                 'collapseSidebar'    => __( 'Collapse Sidebar' ),
55                 'expandSidebar'      => __( 'Expand Sidebar' ),
56         ),
57         'installedThemes' => array_keys( $installed_themes ),
58 ) );
59
60 wp_enqueue_script( 'theme' );
61
62 if ( $tab ) {
63         /**
64          * Fires before each of the tabs are rendered on the Install Themes page.
65          *
66          * The dynamic portion of the hook name, `$tab`, refers to the current
67          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
68          * 'featured', 'new', or 'updated'.
69          *
70          * @since 2.8.0
71          */
72         do_action( "install_themes_pre_{$tab}" );
73 }
74
75 $help_overview =
76         '<p>' . sprintf(
77                         /* translators: %s: Theme Directory URL */
78                         __( '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.' ),
79                         __( 'https://wordpress.org/themes/' )
80                 ) . '</p>' .
81         '<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.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>' .
82         '<p>' . __( '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>' .
83         '<p>' . sprintf(
84                         /* translators: %s: /wp-content/themes */
85                         __( '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 %s directory.' ),
86                         '<code>/wp-content/themes</code>'
87                 ) . '</p>';
88
89 get_current_screen()->add_help_tab( array(
90         'id'      => 'overview',
91         'title'   => __('Overview'),
92         'content' => $help_overview
93 ) );
94
95 $help_installing =
96         '<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>' .
97         '<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>';
98
99 get_current_screen()->add_help_tab( array(
100         'id'      => 'installing',
101         'title'   => __('Previewing and Installing'),
102         'content' => $help_installing
103 ) );
104
105 get_current_screen()->set_help_sidebar(
106         '<p><strong>' . __('For more information:') . '</strong></p>' .
107         '<p>' . __('<a href="https://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
108         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
109 );
110
111 include(ABSPATH . 'wp-admin/admin-header.php');
112
113 ?>
114 <div class="wrap">
115         <h1><?php
116         echo esc_html( $title );
117
118         /**
119          * Filter the tabs shown on the Add Themes screen.
120          *
121          * This filter is for backwards compatibility only, for the suppression
122          * of the upload tab.
123          *
124          * @since 2.8.0
125          *
126          * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
127          */
128         $tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
129         if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
130                 echo ' <a href="#" class="upload page-title-action">' . __( 'Upload Theme' ) . '</a>';
131                 echo ' <a href="#" class="browse-themes page-title-action">' . _x( 'Browse', 'themes' ) . '</a>';
132         }
133         ?></h1>
134
135         <div class="upload-theme">
136         <?php install_themes_upload(); ?>
137         </div>
138
139         <h2 class="screen-reader-text"><?php _e( 'Filter themes list' ); ?></h2>
140
141         <div class="wp-filter">
142                 <div class="filter-count">
143                         <span class="count theme-count"></span>
144                 </div>
145
146                 <ul class="filter-links">
147                         <li><a href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a></li>
148                         <li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
149                         <li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
150                         <li><a href="#" data-sort="favorites"><?php _ex( 'Favorites', 'themes' ); ?></a></li>
151                 </ul>
152
153                 <a class="drawer-toggle" href="#"><?php _e( 'Feature Filter' ); ?></a>
154
155                 <div class="search-form"></div>
156
157                 <div class="favorites-form">
158                         <?php
159                         $action = 'save_wporg_username_' . get_current_user_id();
160                         if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
161                                 $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
162                                 update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
163                         } else {
164                                 $user = get_user_option( 'wporg_favorites' );
165                         }
166                         ?>
167                         <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p>
168
169                         <p>
170                                 <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label>
171                                 <input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
172                                 <input type="search" id="wporg-username-input" value="<?php echo esc_attr( $user ); ?>" />
173                                 <input type="button" class="button button-secondary favorites-form-submit" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
174                         </p>
175                 </div>
176
177                 <div class="filter-drawer">
178                         <div class="buttons">
179                                 <a class="apply-filters button button-secondary" href="#"><?php _e( 'Apply Filters' ); ?><span></span></a>
180                                 <a class="clear-filters button button-secondary" href="#"><?php _e( 'Clear' ); ?></a>
181                         </div>
182                 <?php
183                 $feature_list = get_theme_feature_list();
184                 foreach ( $feature_list as $feature_name => $features ) {
185                         echo '<fieldset class="filter-group">';
186                         $feature_name = esc_html( $feature_name );
187                         echo '<legend>' . $feature_name . '</legend>';
188                         echo '<div class="filter-group-feature">';
189                         foreach ( $features as $feature => $feature_name ) {
190                                 $feature = esc_attr( $feature );
191                                 echo '<input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
192                                 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label><br>';
193                         }
194                         echo '</div>';
195                         echo '</fieldset>';
196                 }
197                 ?>
198                         <div class="filtered-by">
199                                 <span><?php _e( 'Filtering by:' ); ?></span>
200                                 <div class="tags"></div>
201                                 <a href="#"><?php _e( 'Edit' ); ?></a>
202                         </div>
203                 </div>
204         </div>
205         <h2 class="screen-reader-text"><?php _e( 'Themes list' ); ?></h2>
206         <div class="theme-browser content-filterable"></div>
207         <div class="theme-install-overlay wp-full-overlay expanded"></div>
208
209         <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
210         <span class="spinner"></span>
211
212 <?php
213 if ( $tab ) {
214         /**
215          * Fires at the top of each of the tabs on the Install Themes page.
216          *
217          * The dynamic portion of the hook name, `$tab`, refers to the current
218          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
219          * 'featured', 'new', or 'updated'.
220          *
221          * @since 2.8.0
222          *
223          * @param int $paged Number of the current page of results being viewed.
224          */
225         do_action( "install_themes_{$tab}", $paged );
226 }
227 ?>
228 </div>
229
230 <script id="tmpl-theme" type="text/template">
231         <# if ( data.screenshot_url ) { #>
232                 <div class="theme-screenshot">
233                         <img src="{{ data.screenshot_url }}" alt="" />
234                 </div>
235         <# } else { #>
236                 <div class="theme-screenshot blank"></div>
237         <# } #>
238         <span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
239         <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
240         <h3 class="theme-name">{{ data.name }}</h3>
241
242         <div class="theme-actions">
243                 <a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a>
244                 <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
245         </div>
246
247         <# if ( data.installed ) { #>
248                 <div class="theme-installed"><?php _ex( 'Already Installed', 'theme' ); ?></div>
249         <# } #>
250 </script>
251
252 <script id="tmpl-theme-preview" type="text/template">
253         <div class="wp-full-overlay-sidebar">
254                 <div class="wp-full-overlay-header">
255                         <a href="#" class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></a>
256                         <a href="#" class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></a>
257                         <a href="#" class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></a>
258                 <# if ( data.installed ) { #>
259                         <a href="#" class="button button-primary theme-install disabled"><?php _ex( 'Installed', 'theme' ); ?></a>
260                 <# } else { #>
261                         <a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
262                 <# } #>
263                 </div>
264                 <div class="wp-full-overlay-sidebar-content">
265                         <div class="install-theme-info">
266                                 <h3 class="theme-name">{{ data.name }}</h3>
267                                 <span class="theme-by"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></span>
268
269                                 <img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
270
271                                 <div class="theme-details">
272                                         <# if ( data.rating ) { #>
273                                                 <div class="theme-rating">
274                                                         {{{ data.stars }}}
275                                                         <span class="num-ratings" aria-hidden="true">({{ data.num_ratings }})</span>
276                                                 </div>
277                                         <# } else { #>
278                                                 <span class="no-rating"><?php _e( 'This theme has not been rated yet.' ); ?></span>
279                                         <# } #>
280                                         <div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
281                                         <div class="theme-description">{{{ data.description }}}</div>
282                                 </div>
283                         </div>
284                 </div>
285                 <div class="wp-full-overlay-footer">
286                         <div class="devices">
287                                 <button type="button" class="preview-desktop active" aria-pressed="true" data-device="desktop"><span class="screen-reader-text"><?php _e( 'Enter desktop preview mode' ); ?></span></button>
288                                 <button type="button" class="preview-tablet" aria-pressed="false" data-device="tablet"><span class="screen-reader-text"><?php _e( 'Enter tablet preview mode' ); ?></span></button>
289                                 <button type="button" class="preview-mobile" aria-pressed="false" data-device="mobile"><span class="screen-reader-text"><?php _e( 'Enter mobile preview mode' ); ?></span></button>
290                         </div>
291                         <button type="button" class="collapse-sidebar button-secondary" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
292                                 <span class="collapse-sidebar-arrow"></span>
293                                 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
294                         </button>
295                 </div>
296         </div>
297         <div class="wp-full-overlay-main">
298                 <iframe src="{{ data.preview_url }}" title="<?php esc_attr_e( 'Preview' ); ?>" />
299         </div>
300 </script>
301
302 <?php
303 include(ABSPATH . 'wp-admin/admin-footer.php');