PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-admin/themes.php

https://github.com/enoex/artisanchairs
PHP | 302 lines | 241 code | 41 blank | 20 comment | 50 complexity | 811a00edf47053a750fa9198b160bc26 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') )
  11. wp_die( __( 'Cheatin&#8217; uh?' ) );
  12. if ( 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('update_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. $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
  30. if ( current_user_can('install_themes') ) {
  31. $help .= '<p>' . sprintf(__('You can find additional themes for your site by using the new <a href="%1$s">Theme Browser/Installer</a> functionality or by browsing the <a href="http://wordpress.org/extend/themes/">WordPress Theme Directory</a> directly and installing manually. To install a theme <em>manually</em>, <a href="%2$s">upload its ZIP archive with the new uploader</a> or copy its folder via FTP into your <code>wp-content/themes</code> directory.'), 'theme-install.php', 'theme-install.php?tab=upload' ) . '</p>';
  32. $help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>' ;
  33. }
  34. add_contextual_help('themes', $help);
  35. add_thickbox();
  36. wp_enqueue_script( 'theme-preview' );
  37. require_once('admin-header.php');
  38. ?>
  39. <?php if ( ! validate_current_theme() ) : ?>
  40. <div id="message1" class="updated fade"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  41. <?php elseif ( isset($_GET['activated']) ) :
  42. if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?>
  43. <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings page</a> to configure them.'), admin_url('widgets.php') ); ?></p></div><?php
  44. } else { ?>
  45. <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div><?php
  46. }
  47. elseif ( isset($_GET['deleted']) ) : ?>
  48. <div id="message3" class="updated fade"><p><?php _e('Theme deleted.') ?></p></div>
  49. <?php endif; ?>
  50. <?php
  51. $themes = get_themes();
  52. $ct = current_theme_info();
  53. unset($themes[$ct->name]);
  54. uksort( $themes, "strnatcasecmp" );
  55. $theme_total = count( $themes );
  56. $per_page = 15;
  57. if ( isset( $_GET['pagenum'] ) )
  58. $page = absint( $_GET['pagenum'] );
  59. if ( empty($page) )
  60. $page = 1;
  61. $start = $offset = ( $page - 1 ) * $per_page;
  62. $page_links = paginate_links( array(
  63. 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  64. 'format' => '',
  65. 'prev_text' => __('&laquo;'),
  66. 'next_text' => __('&raquo;'),
  67. 'total' => ceil($theme_total / $per_page),
  68. 'current' => $page
  69. ));
  70. $themes = array_slice( $themes, $start, $per_page );
  71. /**
  72. * Check if there is an update for a theme available.
  73. *
  74. * Will display link, if there is an update available.
  75. *
  76. * @since 2.7.0
  77. *
  78. * @param object $theme Theme data object.
  79. * @return bool False if no valid info was passed.
  80. */
  81. function theme_update_available( $theme ) {
  82. static $themes_update;
  83. if ( !isset($themes_update) )
  84. $themes_update = get_transient('update_themes');
  85. if ( is_object($theme) && isset($theme->stylesheet) )
  86. $stylesheet = $theme->stylesheet;
  87. elseif ( is_array($theme) && isset($theme['Stylesheet']) )
  88. $stylesheet = $theme['Stylesheet'];
  89. else
  90. return false; //No valid info passed.
  91. if ( isset($themes_update->response[ $stylesheet ]) ) {
  92. $update = $themes_update->response[ $stylesheet ];
  93. $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
  94. $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
  95. $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
  96. $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
  97. if ( ! current_user_can('update_themes') )
  98. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  99. else if ( empty($update->package) )
  100. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  101. else
  102. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s" %5$s >upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
  103. }
  104. }
  105. ?>
  106. <div class="wrap">
  107. <?php screen_icon(); ?>
  108. <h2><?php echo esc_html( $title ); ?></h2>
  109. <h3><?php _e('Current Theme'); ?></h3>
  110. <div id="current-theme">
  111. <?php if ( $ct->screenshot ) : ?>
  112. <img src="<?php echo content_url($ct->stylesheet_dir . '/' . $ct->screenshot); ?>" alt="<?php _e('Current theme preview'); ?>" />
  113. <?php endif; ?>
  114. <h4><?php
  115. /* translators: 1: theme title, 2: theme version, 3: theme author */
  116. printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
  117. <p class="theme-description"><?php echo $ct->description; ?></p>
  118. <?php if ($ct->parent_theme) { ?>
  119. <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>
  120. <?php } else { ?>
  121. <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>
  122. <?php } ?>
  123. <?php if ( $ct->tags ) : ?>
  124. <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
  125. <?php endif; ?>
  126. <?php theme_update_available($ct); ?>
  127. </div>
  128. <div class="clear"></div>
  129. <h3><?php _e('Available Themes'); ?></h3>
  130. <div class="clear"></div>
  131. <?php if ( $theme_total ) { ?>
  132. <?php if ( $page_links ) : ?>
  133. <div class="tablenav">
  134. <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  135. number_format_i18n( $start + 1 ),
  136. number_format_i18n( min( $page * $per_page, $theme_total ) ),
  137. number_format_i18n( $theme_total ),
  138. $page_links
  139. ); echo $page_links_text; ?></div>
  140. </div>
  141. <?php endif; ?>
  142. <table id="availablethemes" cellspacing="0" cellpadding="0">
  143. <?php
  144. $style = '';
  145. $theme_names = array_keys($themes);
  146. natcasesort($theme_names);
  147. $table = array();
  148. $rows = ceil(count($theme_names) / 3);
  149. for ( $row = 1; $row <= $rows; $row++ )
  150. for ( $col = 1; $col <= 3; $col++ )
  151. $table[$row][$col] = array_shift($theme_names);
  152. foreach ( $table as $row => $cols ) {
  153. ?>
  154. <tr>
  155. <?php
  156. foreach ( $cols as $col => $theme_name ) {
  157. $class = array('available-theme');
  158. if ( $row == 1 ) $class[] = 'top';
  159. if ( $col == 1 ) $class[] = 'left';
  160. if ( $row == $rows ) $class[] = 'bottom';
  161. if ( $col == 3 ) $class[] = 'right';
  162. ?>
  163. <td class="<?php echo join(' ', $class); ?>">
  164. <?php if ( !empty($theme_name) ) :
  165. $template = $themes[$theme_name]['Template'];
  166. $stylesheet = $themes[$theme_name]['Stylesheet'];
  167. $title = $themes[$theme_name]['Title'];
  168. $version = $themes[$theme_name]['Version'];
  169. $description = $themes[$theme_name]['Description'];
  170. $author = $themes[$theme_name]['Author'];
  171. $screenshot = $themes[$theme_name]['Screenshot'];
  172. $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
  173. $template_dir = $themes[$theme_name]['Template Dir'];
  174. $parent_theme = $themes[$theme_name]['Parent Theme'];
  175. $preview_link = esc_url(get_option('home') . '/');
  176. if ( is_ssl() )
  177. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  178. $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
  179. $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
  180. $tags = $themes[$theme_name]['Tags'];
  181. $thickbox_class = 'thickbox thickbox-preview';
  182. $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
  183. $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
  184. $actions = array();
  185. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
  186. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
  187. if ( current_user_can('update_themes') )
  188. $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url("themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet) . '" onclick="' . "if ( confirm('" . esc_js(sprintf( __("You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete."), $theme_name )) . "') ) {return true;}return false;" . '">' . __('Delete') . '</a>';
  189. $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
  190. $actions = implode ( ' | ', $actions );
  191. ?>
  192. <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
  193. <?php if ( $screenshot ) : ?>
  194. <img src="<?php echo content_url($stylesheet_dir . '/' . $screenshot); ?>" alt="" />
  195. <?php endif; ?>
  196. </a>
  197. <h3><?php
  198. /* translators: 1: theme title, 2: theme version, 3: theme author */
  199. printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
  200. <p class="description"><?php echo $description; ?></p>
  201. <span class='action-links'><?php echo $actions ?></span>
  202. <?php if ($parent_theme) {
  203. /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
  204. <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, $template_dir, $stylesheet_dir, $title, $parent_theme); ?></p>
  205. <?php } else { ?>
  206. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, $template_dir, $stylesheet_dir); ?></p>
  207. <?php } ?>
  208. <?php if ( $tags ) : ?>
  209. <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
  210. <?php endif; ?>
  211. <?php theme_update_available( $themes[$theme_name] ); ?>
  212. <?php endif; // end if not empty theme_name ?>
  213. </td>
  214. <?php } // end foreach $cols ?>
  215. </tr>
  216. <?php } // end foreach $table ?>
  217. </table>
  218. <?php } else { ?>
  219. <p><?php _e('You only have one theme installed at the moment so there is nothing to show you here. Maybe you should download some more to try out.'); ?></p>
  220. <?php } // end if $theme_total?>
  221. <br class="clear" />
  222. <?php if ( $page_links ) : ?>
  223. <div class="tablenav">
  224. <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
  225. <br class="clear" />
  226. </div>
  227. <?php endif; ?>
  228. <br class="clear" />
  229. <?php
  230. // List broken themes, if any.
  231. $broken_themes = get_broken_themes();
  232. if ( count($broken_themes) ) {
  233. ?>
  234. <h2><?php _e('Broken Themes'); ?></h2>
  235. <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
  236. <table width="100%" cellpadding="3" cellspacing="3">
  237. <tr>
  238. <th><?php _e('Name'); ?></th>
  239. <th><?php _e('Description'); ?></th>
  240. </tr>
  241. <?php
  242. $theme = '';
  243. $theme_names = array_keys($broken_themes);
  244. natcasesort($theme_names);
  245. foreach ($theme_names as $theme_name) {
  246. $title = $broken_themes[$theme_name]['Title'];
  247. $description = $broken_themes[$theme_name]['Description'];
  248. $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
  249. echo "
  250. <tr $theme>
  251. <td>$title</td>
  252. <td>$description</td>
  253. </tr>";
  254. }
  255. ?>
  256. </table>
  257. <?php
  258. }
  259. ?>
  260. </div>
  261. <?php require('admin-footer.php'); ?>