[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/wp-admin/ -> themes.php (source)

   1  <?php
   2  /**
   3   * Themes administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('admin.php');
  11  
  12  if ( !current_user_can('switch_themes') )
  13      wp_die( __( 'Cheatin&#8217; uh?' ) );
  14  
  15  if ( isset($_GET['action']) ) {
  16      if ( 'activate' == $_GET['action'] ) {
  17          check_admin_referer('switch-theme_' . $_GET['template']);
  18          switch_theme($_GET['template'], $_GET['stylesheet']);
  19          wp_redirect('themes.php?activated=true');
  20          exit;
  21      } else if ( 'delete' == $_GET['action'] ) {
  22          check_admin_referer('delete-theme_' . $_GET['template']);
  23          if ( !current_user_can('update_themes') )
  24              wp_die( __( 'Cheatin&#8217; uh?' ) );
  25          delete_theme($_GET['template']);
  26          wp_redirect('themes.php?deleted=true');
  27          exit;
  28      }
  29  }
  30  
  31  $title = __('Manage Themes');
  32  $parent_file = 'themes.php';
  33  
  34  $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
  35  if ( current_user_can('install_themes') ) {
  36      $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>';
  37      $help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>' ;
  38  }
  39  
  40  add_contextual_help($current_screen, $help);
  41  
  42  add_thickbox();
  43  wp_enqueue_script( 'theme-preview' );
  44  
  45  require_once ('admin-header.php');
  46  if ( is_multisite() && current_user_can('edit_themes') ) {
  47      ?><div id="message0" class="updated fade"><p><?php _e('Administrator: new themes must be activated in the <a href="ms-themes.php">Themes Admin</a> page before they appear here.'); ?></p></div><?php
  48  }
  49  ?>
  50  
  51  <?php if ( ! validate_current_theme() ) : ?>
  52  <div id="message1" class="updated"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div>
  53  <?php elseif ( isset($_GET['activated']) ) :
  54          if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?>
  55  <div id="message2" class="updated"><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
  56          } else { ?>
  57  <div id="message2" class="updated"><p><?php printf(__('New theme activated. <a href="%s">Visit site</a>'), get_bloginfo('url') . '/'); ?></p></div><?php
  58          }
  59      elseif ( isset($_GET['deleted']) ) : ?>
  60  <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
  61  <?php endif; ?>
  62  
  63  <?php
  64  $themes = get_allowed_themes();
  65  $ct = current_theme_info();
  66  unset($themes[$ct->name]);
  67  
  68  uksort( $themes, "strnatcasecmp" );
  69  $theme_total = count( $themes );
  70  $per_page = 15;
  71  
  72  if ( isset( $_GET['pagenum'] ) )
  73      $page = absint( $_GET['pagenum'] );
  74  
  75  if ( empty($page) )
  76      $page = 1;
  77  
  78  $start = $offset = ( $page - 1 ) * $per_page;
  79  
  80  $page_links = paginate_links( array(
  81      'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  82      'format' => '',
  83      'prev_text' => __('&laquo;'),
  84      'next_text' => __('&raquo;'),
  85      'total' => ceil($theme_total / $per_page),
  86      'current' => $page
  87  ));
  88  
  89  $themes = array_slice( $themes, $start, $per_page );
  90  
  91  /**
  92   * Check if there is an update for a theme available.
  93   *
  94   * Will display link, if there is an update available.
  95   *
  96   * @since 2.7.0
  97   *
  98   * @param object $theme Theme data object.
  99   * @return bool False if no valid info was passed.
 100   */
 101  function theme_update_available( $theme ) {
 102      static $themes_update;
 103  
 104      if ( !current_user_can('update_themes' ) )
 105          return;
 106  
 107      if ( !isset($themes_update) )
 108          $themes_update = get_site_transient('update_themes');
 109  
 110      if ( is_object($theme) && isset($theme->stylesheet) )
 111          $stylesheet = $theme->stylesheet;
 112      elseif ( is_array($theme) && isset($theme['Stylesheet']) )
 113          $stylesheet = $theme['Stylesheet'];
 114      else
 115          return false; //No valid info passed.
 116  
 117      if ( isset($themes_update->response[ $stylesheet ]) ) {
 118          $update = $themes_update->response[ $stylesheet ];
 119          $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
 120          $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.
 121          $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
 122          $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;"';
 123  
 124          if ( ! current_user_can('update_themes') )
 125              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']);
 126          else if ( empty($update['package']) )
 127              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']);
 128          else
 129              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 );
 130      }
 131  }
 132  
 133  ?>
 134  
 135  <div class="wrap">
 136  <?php screen_icon(); ?>
 137  <h2><a href="themes.php" class="menu-tabs"><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?></a> <a href="theme-install.php" class="menu-tabs menu-tab-inactive"><?php echo esc_html_x('Install Themes', 'theme'); ?></a><?php } ?></h2>
 138  
 139  <h3><?php _e('Current Theme'); ?></h3>
 140  <div id="current-theme">
 141  <?php if ( $ct->screenshot ) : ?>
 142  <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
 143  <?php endif; ?>
 144  <h4><?php
 145      /* translators: 1: theme title, 2: theme version, 3: theme author */
 146      printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
 147  <p class="theme-description"><?php echo $ct->description; ?></p>
 148  <?php if ( current_user_can('edit_themes') && $ct->parent_theme ) { ?>
 149      <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>
 150  <?php } else { ?>
 151      <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>
 152  <?php } ?>
 153  <?php if ( $ct->tags ) : ?>
 154  <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
 155  <?php endif; ?>
 156  <?php theme_update_available($ct); ?>
 157  
 158  </div>
 159  
 160  <div class="clear"></div>
 161  <h3><?php _e('Available Themes'); ?></h3>
 162  <div class="clear"></div>
 163  
 164  <?php if ( $theme_total ) { ?>
 165  
 166  <?php if ( $page_links ) : ?>
 167  <div class="tablenav">
 168  <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
 169      number_format_i18n( $start + 1 ),
 170      number_format_i18n( min( $page * $per_page, $theme_total ) ),
 171      number_format_i18n( $theme_total ),
 172      $page_links
 173  ); echo $page_links_text; ?></div>
 174  </div>
 175  <?php endif; ?>
 176  
 177  <table id="availablethemes" cellspacing="0" cellpadding="0">
 178  <?php
 179  $style = '';
 180  
 181  $theme_names = array_keys($themes);
 182  natcasesort($theme_names);
 183  
 184  $table = array();
 185  $rows = ceil(count($theme_names) / 3);
 186  for ( $row = 1; $row <= $rows; $row++ )
 187      for ( $col = 1; $col <= 3; $col++ )
 188          $table[$row][$col] = array_shift($theme_names);
 189  
 190  foreach ( $table as $row => $cols ) {
 191  ?>
 192  <tr>
 193  <?php
 194  foreach ( $cols as $col => $theme_name ) {
 195      $class = array('available-theme');
 196      if ( $row == 1 ) $class[] = 'top';
 197      if ( $col == 1 ) $class[] = 'left';
 198      if ( $row == $rows ) $class[] = 'bottom';
 199      if ( $col == 3 ) $class[] = 'right';
 200  ?>
 201      <td class="<?php echo join(' ', $class); ?>">
 202  <?php if ( !empty($theme_name) ) :
 203      $template = $themes[$theme_name]['Template'];
 204      $stylesheet = $themes[$theme_name]['Stylesheet'];
 205      $title = $themes[$theme_name]['Title'];
 206      $version = $themes[$theme_name]['Version'];
 207      $description = $themes[$theme_name]['Description'];
 208      $author = $themes[$theme_name]['Author'];
 209      $screenshot = $themes[$theme_name]['Screenshot'];
 210      $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
 211      $template_dir = $themes[$theme_name]['Template Dir'];
 212      $parent_theme = $themes[$theme_name]['Parent Theme'];
 213      $theme_root = $themes[$theme_name]['Theme Root'];
 214      $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
 215      $preview_link = esc_url(get_option('home') . '/');
 216      if ( is_ssl() )
 217          $preview_link = str_replace( 'http://', 'https://', $preview_link );
 218      $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
 219      $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
 220      $tags = $themes[$theme_name]['Tags'];
 221      $thickbox_class = 'thickbox thickbox-preview';
 222      $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
 223      $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
 224      $actions = array();
 225      $actions[] = '<a href="' . $activate_link .  '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
 226      $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
 227      if ( current_user_can('update_themes') )
 228          $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>';
 229      $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
 230  
 231      $actions = implode ( ' | ', $actions );
 232  ?>
 233          <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
 234  <?php if ( $screenshot ) : ?>
 235              <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
 236  <?php endif; ?>
 237          </a>
 238  <h3><?php
 239      /* translators: 1: theme title, 2: theme version, 3: theme author */
 240      printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
 241  <p class="description"><?php echo $description; ?></p>
 242  <span class='action-links'><?php echo $actions ?></span>
 243      <?php if ( current_user_can('edit_themes') && $parent_theme ) {
 244      /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
 245      <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>
 246  <?php } else { ?>
 247      <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>
 248  <?php } ?>
 249  <?php if ( $tags ) : ?>
 250  <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
 251  <?php endif; ?>
 252          <?php theme_update_available( $themes[$theme_name] ); ?>
 253  <?php endif; // end if not empty theme_name ?>
 254      </td>
 255  <?php } // end foreach $cols ?>
 256  </tr>
 257  <?php } // end foreach $table ?>
 258  </table>
 259  <?php } else { ?>
 260  <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>
 261  <?php } // end if $theme_total?>
 262  <br class="clear" />
 263  
 264  <?php if ( $page_links ) : ?>
 265  <div class="tablenav">
 266  <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
 267  <br class="clear" />
 268  </div>
 269  <?php endif; ?>
 270  
 271  <br class="clear" />
 272  
 273  <?php
 274  // List broken themes, if any.
 275  $broken_themes = get_broken_themes();
 276  if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
 277  ?>
 278  
 279  <h2><?php _e('Broken Themes'); ?> <?php if ( is_multisite() ) _e( '(Site admin only)' ); ?></h2>
 280  <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
 281  
 282  <table id="broken-themes">
 283      <tr>
 284          <th><?php _e('Name'); ?></th>
 285          <th><?php _e('Description'); ?></th>
 286      </tr>
 287  <?php
 288      $theme = '';
 289  
 290      $theme_names = array_keys($broken_themes);
 291      natcasesort($theme_names);
 292  
 293      foreach ($theme_names as $theme_name) {
 294          $title = $broken_themes[$theme_name]['Title'];
 295          $description = $broken_themes[$theme_name]['Description'];
 296  
 297          $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
 298          echo "
 299          <tr $theme>
 300               <td>$title</td>
 301               <td>$description</td>
 302          </tr>";
 303      }
 304  ?>
 305  </table>
 306  <?php
 307  }
 308  ?>
 309  </div>
 310  
 311  <?php require ('admin-footer.php'); ?>


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7