PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/themes.php

https://github.com/shlomsky/lim
PHP | 285 lines | 238 code | 37 blank | 10 comment | 55 complexity | f9702f42a9f066cd826036f00aa8a797 MD5 | raw file
  1. <?php
  2. /**
  3. * Themes administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
  11. wp_die( __( 'Cheatin&#8217; uh?' ) );
  12. if ( current_user_can('switch_themes') && isset($_GET['action']) ) {
  13. if ( 'activate' == $_GET['action'] ) {
  14. check_admin_referer('switch-theme_' . $_GET['template']);
  15. switch_theme($_GET['template'], $_GET['stylesheet']);
  16. wp_redirect('themes.php?activated=true');
  17. exit;
  18. } else if ( 'delete' == $_GET['action'] ) {
  19. check_admin_referer('delete-theme_' . $_GET['template']);
  20. if ( !current_user_can('delete_themes') )
  21. wp_die( __( 'Cheatin&#8217; uh?' ) );
  22. delete_theme($_GET['template']);
  23. wp_redirect('themes.php?deleted=true');
  24. exit;
  25. }
  26. }
  27. $title = __('Manage Themes');
  28. $parent_file = 'themes.php';
  29. if ( current_user_can( 'switch_themes' ) ) :
  30. $help = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>';
  31. $help .= '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Preview link. To change themes, click the Activate link.') . '</p>';
  32. if ( current_user_can('install_themes') )
  33. $help .= '<p>' . sprintf(__('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are licensed under the GNU General Public License, version 2, just like WordPress. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/') . '</p>';
  34. $help .= '<p><strong>' . __('For more information:') . '</strong></p>';
  35. $help .= '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>';
  36. $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
  37. add_contextual_help($current_screen, $help);
  38. add_thickbox();
  39. wp_enqueue_script( 'theme-preview' );
  40. endif;
  41. require_once('./admin-header.php');
  42. if ( is_multisite() && current_user_can('edit_themes') ) {
  43. ?><div id="message0" class="updated"><p><?php printf( __('Administrator: new themes must be activated in the <a href="%s">Network Themes</a> screen before they appear here.'), admin_url( 'ms-themes.php') ); ?></p></div><?php
  44. }
  45. ?>
  46. <?php if ( ! validate_current_theme() ) : ?>
  47. <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  48. <?php elseif ( isset($_GET['activated']) ) :
  49. if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
  50. <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
  51. } else { ?>
  52. <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
  53. }
  54. elseif ( isset($_GET['deleted']) ) : ?>
  55. <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
  56. <?php endif; ?>
  57. <?php
  58. $themes = get_allowed_themes();
  59. $ct = current_theme_info();
  60. unset($themes[$ct->name]);
  61. uksort( $themes, "strnatcasecmp" );
  62. $theme_total = count( $themes );
  63. $per_page = 15;
  64. if ( isset( $_GET['pagenum'] ) )
  65. $page = absint( $_GET['pagenum'] );
  66. if ( empty($page) )
  67. $page = 1;
  68. $start = $offset = ( $page - 1 ) * $per_page;
  69. $page_links = paginate_links( array(
  70. 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  71. 'format' => '',
  72. 'prev_text' => __('&laquo;'),
  73. 'next_text' => __('&raquo;'),
  74. 'total' => ceil($theme_total / $per_page),
  75. 'current' => $page
  76. ));
  77. $themes = array_slice( $themes, $start, $per_page );
  78. ?>
  79. <div class="wrap">
  80. <?php screen_icon(); ?>
  81. <h2><a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><?php if ( current_user_can('install_themes') ) { ?><a href="theme-install.php" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a><?php } ?></h2>
  82. <h3><?php _e('Current Theme'); ?></h3>
  83. <div id="current-theme">
  84. <?php if ( $ct->screenshot ) : ?>
  85. <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
  86. <?php endif; ?>
  87. <h4><?php
  88. /* translators: 1: theme title, 2: theme version, 3: theme author */
  89. printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
  90. <p class="theme-description"><?php echo $ct->description; ?></p>
  91. <?php if ( current_user_can('edit_themes') && $ct->parent_theme ) { ?>
  92. <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, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ), $ct->title, $ct->parent_theme); ?></p>
  93. <?php } else { ?>
  94. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ) ); ?></p>
  95. <?php } ?>
  96. <?php if ( $ct->tags ) : ?>
  97. <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
  98. <?php endif; ?>
  99. <?php theme_update_available($ct); ?>
  100. </div>
  101. <div class="clear"></div>
  102. <?php
  103. if ( ! current_user_can( 'switch_themes' ) ) {
  104. echo '</div>';
  105. require( './admin-footer.php' );
  106. exit;
  107. }
  108. ?>
  109. <h3><?php _e('Available Themes'); ?></h3>
  110. <div class="clear"></div>
  111. <?php if ( $theme_total ) { ?>
  112. <?php if ( $page_links ) : ?>
  113. <div class="tablenav">
  114. <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  115. number_format_i18n( $start + 1 ),
  116. number_format_i18n( min( $page * $per_page, $theme_total ) ),
  117. number_format_i18n( $theme_total ),
  118. $page_links
  119. ); echo $page_links_text; ?></div>
  120. </div>
  121. <?php endif; ?>
  122. <table id="availablethemes" cellspacing="0" cellpadding="0">
  123. <?php
  124. $style = '';
  125. $theme_names = array_keys($themes);
  126. natcasesort($theme_names);
  127. $table = array();
  128. $rows = ceil(count($theme_names) / 3);
  129. for ( $row = 1; $row <= $rows; $row++ )
  130. for ( $col = 1; $col <= 3; $col++ )
  131. $table[$row][$col] = array_shift($theme_names);
  132. foreach ( $table as $row => $cols ) {
  133. ?>
  134. <tr>
  135. <?php
  136. foreach ( $cols as $col => $theme_name ) {
  137. $class = array('available-theme');
  138. if ( $row == 1 ) $class[] = 'top';
  139. if ( $col == 1 ) $class[] = 'left';
  140. if ( $row == $rows ) $class[] = 'bottom';
  141. if ( $col == 3 ) $class[] = 'right';
  142. ?>
  143. <td class="<?php echo join(' ', $class); ?>">
  144. <?php if ( !empty($theme_name) ) :
  145. $template = $themes[$theme_name]['Template'];
  146. $stylesheet = $themes[$theme_name]['Stylesheet'];
  147. $title = $themes[$theme_name]['Title'];
  148. $version = $themes[$theme_name]['Version'];
  149. $description = $themes[$theme_name]['Description'];
  150. $author = $themes[$theme_name]['Author'];
  151. $screenshot = $themes[$theme_name]['Screenshot'];
  152. $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
  153. $template_dir = $themes[$theme_name]['Template Dir'];
  154. $parent_theme = $themes[$theme_name]['Parent Theme'];
  155. $theme_root = $themes[$theme_name]['Theme Root'];
  156. $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
  157. $preview_link = esc_url(get_option('home') . '/');
  158. if ( is_ssl() )
  159. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  160. $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
  161. $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
  162. $tags = $themes[$theme_name]['Tags'];
  163. $thickbox_class = 'thickbox thickbox-preview';
  164. $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
  165. $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
  166. $actions = array();
  167. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
  168. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
  169. if ( current_user_can('delete_themes') )
  170. $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url("themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet) . '" onclick="' . "return confirm('" . esc_js(sprintf( __("You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete."), $theme_name )) . "');" . '">' . __('Delete') . '</a>';
  171. $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
  172. $actions = implode ( ' | ', $actions );
  173. ?>
  174. <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
  175. <?php if ( $screenshot ) : ?>
  176. <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
  177. <?php endif; ?>
  178. </a>
  179. <h3><?php
  180. /* translators: 1: theme title, 2: theme version, 3: theme author */
  181. printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
  182. <p class="description"><?php echo $description; ?></p>
  183. <span class='action-links'><?php echo $actions ?></span>
  184. <?php if ( current_user_can('edit_themes') && $parent_theme ) {
  185. /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
  186. <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.'), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme); ?></p>
  187. <?php } else { ?>
  188. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
  189. <?php } ?>
  190. <?php if ( $tags ) : ?>
  191. <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
  192. <?php endif; ?>
  193. <?php theme_update_available( $themes[$theme_name] ); ?>
  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 } else { ?>
  201. <p><?php
  202. if ( current_user_can('install_themes') )
  203. printf(__('You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <em><a href="%s">Install Themes</a></em> tab above.'), 'theme-install.php');
  204. else
  205. printf(__('Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.'), get_site_option('site_name'));
  206. ?></p>
  207. <?php } // end if $theme_total?>
  208. <br class="clear" />
  209. <?php if ( $page_links ) : ?>
  210. <div class="tablenav">
  211. <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
  212. <br class="clear" />
  213. </div>
  214. <?php endif; ?>
  215. <br class="clear" />
  216. <?php
  217. // List broken themes, if any.
  218. $broken_themes = get_broken_themes();
  219. if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
  220. ?>
  221. <h2><?php _e('Broken Themes'); ?> <?php if ( is_multisite() ) _e( '(Site admin only)' ); ?></h2>
  222. <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
  223. <table id="broken-themes">
  224. <tr>
  225. <th><?php _e('Name'); ?></th>
  226. <th><?php _e('Description'); ?></th>
  227. </tr>
  228. <?php
  229. $theme = '';
  230. $theme_names = array_keys($broken_themes);
  231. natcasesort($theme_names);
  232. foreach ($theme_names as $theme_name) {
  233. $title = $broken_themes[$theme_name]['Title'];
  234. $description = $broken_themes[$theme_name]['Description'];
  235. $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
  236. echo "
  237. <tr $theme>
  238. <td>$title</td>
  239. <td>$description</td>
  240. </tr>";
  241. }
  242. ?>
  243. </table>
  244. <?php
  245. }
  246. ?>
  247. </div>
  248. <?php require('./admin-footer.php'); ?>