[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> theme-install.php (source)

   1  <?php
   2  /**
   3   * WordPress Theme Install Administration API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  $themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
  10      'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
  11      'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
  12      'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
  13      'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
  14      'img' => array('src' => array(), 'class' => array(), 'alt' => array())
  15  );
  16  
  17  $theme_field_defaults = array( 'description' => true, 'sections' => false, 'tested' => true, 'requires' => true,
  18      'rating' => true, 'downloaded' => true, 'downloadlink' => true, 'last_updated' => true, 'homepage' => true,
  19      'tags' => true, 'num_ratings' => true
  20  );
  21  
  22  /**
  23   * Retrieve list of WordPress theme features (aka theme tags)
  24   *
  25   * @since 2.8.0
  26   *
  27   * @deprecated since 3.1.0  Use get_theme_feature_list() instead.
  28   *
  29   * @return array
  30   */
  31  function install_themes_feature_list( ) {
  32      if ( !$cache = get_transient( 'wporg_theme_feature_list' ) )
  33          set_transient( 'wporg_theme_feature_list', array( ),  10800);
  34  
  35      if ( $cache  )
  36          return $cache;
  37  
  38      $feature_list = themes_api( 'feature_list', array( ) );
  39      if ( is_wp_error( $feature_list ) )
  40          return $features;
  41  
  42      set_transient( 'wporg_theme_feature_list', $feature_list, 10800 );
  43  
  44      return $feature_list;
  45  }
  46  
  47  /**
  48   * Display search form for searching themes.
  49   *
  50   * @since 2.8.0
  51   */
  52  function install_theme_search_form() {
  53      $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
  54      $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  55      ?>
  56  <p class="install-help"><?php _e('Search for themes by keyword, author, or tag.') ?></p>
  57  
  58  <form id="search-themes" method="get" action="">
  59      <input type="hidden" name="tab" value="search" />
  60      <select    name="type" id="typeselector">
  61      <option value="term" <?php selected('term', $type) ?>><?php _e('Term'); ?></option>
  62      <option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option>
  63      <option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option>
  64      </select>
  65      <input type="text" name="s" size="30" value="<?php echo esc_attr($term) ?>" />
  66      <?php submit_button( __( 'Search' ), 'button', 'search', false ); ?>
  67  </form>
  68  <?php
  69  }
  70  
  71  /**
  72   * Display tags filter for themes.
  73   *
  74   * @since 2.8.0
  75   */
  76  function install_themes_dashboard() {
  77      install_theme_search_form();
  78  ?>
  79  <h4><?php _e('Feature Filter') ?></h4>
  80  <form method="post" action="<?php echo self_admin_url( 'theme-install.php?tab=search' ); ?>">
  81  <p class="install-help"><?php _e('Find a theme based on specific features') ?></p>
  82      <?php
  83      $feature_list = get_theme_feature_list( );
  84      echo '<div class="feature-filter">';
  85  
  86      foreach ( (array) $feature_list as $feature_name => $features ) {
  87          $feature_name = esc_html( $feature_name );
  88          echo '<div class="feature-name">' . $feature_name . '</div>';
  89  
  90          echo '<ol class="feature-group">';
  91          foreach ( $features as $feature => $feature_name ) {
  92              $feature_name = esc_html( $feature_name );
  93              $feature = esc_attr($feature);
  94  ?>
  95  
  96  <li>
  97      <input type="checkbox" name="features[<?php echo $feature; ?>]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
  98      <label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label>
  99  </li>
 100  
 101  <?php    } ?>
 102  </ol>
 103  <br class="clear" />
 104  <?php
 105      } ?>
 106  
 107  </div>
 108  <br class="clear" />
 109  <?php submit_button( __( 'Find Themes' ), 'button', 'search' ); ?>
 110  </form>
 111  <?php
 112  }
 113  add_action('install_themes_dashboard', 'install_themes_dashboard');
 114  
 115  function install_themes_upload($page = 1) {
 116  ?>
 117  <h4><?php _e('Install a theme in .zip format') ?></h4>
 118  <p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.') ?></p>
 119  <form method="post" enctype="multipart/form-data" action="<?php echo self_admin_url('update.php?action=upload-theme') ?>">
 120      <?php wp_nonce_field( 'theme-upload') ?>
 121      <input type="file" name="themezip" />
 122      <?php submit_button( __( 'Install Now' ), 'button', 'install-theme-submit', false ); ?>
 123  </form>
 124      <?php
 125  }
 126  add_action('install_themes_upload', 'install_themes_upload', 10, 1);
 127  
 128  function display_theme($theme, $actions = null, $show_details = true) {
 129      global $themes_allowedtags;
 130  
 131      if ( empty($theme) )
 132          return;
 133  
 134      $name = wp_kses($theme->name, $themes_allowedtags);
 135      $desc = wp_kses($theme->description, $themes_allowedtags);
 136      //if ( strlen($desc) > 30 )
 137      //    $desc =  substr($desc, 0, 15) . '<span class="dots">...</span><span>' . substr($desc, -15) . '</span>';
 138  
 139      $preview_link = $theme->preview_url . '?TB_iframe=true&amp;width=600&amp;height=400';
 140      if ( !is_array($actions) ) {
 141          $actions = array();
 142          $actions[] = '<a href="' . self_admin_url('theme-install.php?tab=theme-information&amp;theme=' . $theme->slug .
 143                                          '&amp;TB_iframe=true&amp;tbWidth=500&amp;tbHeight=385') . '" class="thickbox thickbox-preview onclick" title="' . esc_attr(sprintf(__('Install &#8220;%s&#8221;'), $name)) . '">' . __('Install') . '</a>';
 144          if ( !is_network_admin() )
 145              $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview onclick previewlink" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>';
 146          $actions = apply_filters('theme_install_action_links', $actions, $theme);
 147      }
 148  
 149      $actions = implode ( ' | ', $actions );
 150      ?>
 151  <a class='thickbox thickbox-preview screenshot'
 152      href='<?php echo esc_url($preview_link); ?>'
 153      title='<?php echo esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)); ?>'>
 154  <img src='<?php echo esc_url($theme->screenshot_url); ?>' width='150' />
 155  </a>
 156  <h3><?php echo $name ?></h3>
 157  <span class='action-links'><?php echo $actions ?></span>
 158  <p><?php echo $desc ?></p>
 159  <?php if ( $show_details ) { ?>
 160  <a href="#theme_detail" class="theme-detail hide-if-no-js" tabindex='4'><?php _e('Details') ?></a>
 161  <div class="themedetaildiv hide-if-js">
 162  <p><strong><?php _e('Version:') ?></strong> <?php echo wp_kses($theme->version, $themes_allowedtags) ?></p>
 163  <p><strong><?php _e('Author:') ?></strong> <?php echo wp_kses($theme->author, $themes_allowedtags) ?></p>
 164  <?php if ( ! empty($theme->last_updated) ) : ?>
 165  <p><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $theme->last_updated ?>"><?php printf( __('%s ago'), human_time_diff(strtotime($theme->last_updated)) ) ?></span></p>
 166  <?php endif; if ( ! empty($theme->requires) ) : ?>
 167  <p><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $theme->requires) ?></p>
 168  <?php endif; if ( ! empty($theme->tested) ) : ?>
 169  <p><strong><?php _e('Compatible up to:') ?></strong> <?php echo $theme->tested ?></p>
 170  <?php endif; if ( !empty($theme->downloaded) ) : ?>
 171  <p><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $theme->downloaded), number_format_i18n($theme->downloaded)) ?></p>
 172  <?php endif; ?>
 173  <div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $theme->num_ratings), number_format_i18n($theme->num_ratings)) ?>">
 174      <div class="star star-rating" style="width: <?php echo esc_attr($theme->rating) ?>px"></div>
 175      <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
 176      <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
 177      <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
 178      <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
 179      <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
 180  </div>
 181  </div>
 182  <?php }
 183      /*
 184       object(stdClass)[59]
 185       public 'name' => string 'Magazine Basic' (length=14)
 186       public 'slug' => string 'magazine-basic' (length=14)
 187       public 'version' => string '1.1' (length=3)
 188       public 'author' => string 'tinkerpriest' (length=12)
 189       public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36)
 190       public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68)
 191       public 'rating' => float 80
 192       public 'num_ratings' => int 1
 193       public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49)
 194       public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' (length=214)
 195       public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
 196       */
 197  }
 198  
 199  /**
 200   * Display theme content based on theme list.
 201   *
 202   * @since 2.8.0
 203   */
 204  function display_themes() {
 205      global $wp_list_table;
 206  
 207      $wp_list_table->display();
 208  }
 209  add_action('install_themes_search', 'display_themes');
 210  add_action('install_themes_featured', 'display_themes');
 211  add_action('install_themes_new', 'display_themes');
 212  add_action('install_themes_updated', 'display_themes');
 213  
 214  /**
 215   * Display theme information in dialog box form.
 216   *
 217   * @since 2.8.0
 218   */
 219  function install_theme_information() {
 220      //TODO: This function needs a LOT of UI work :)
 221      global $tab, $themes_allowedtags;
 222  
 223      $api = themes_api('theme_information', array('slug' => stripslashes( $_REQUEST['theme'] ) ));
 224  
 225      if ( is_wp_error($api) )
 226          wp_die($api);
 227  
 228      // Sanitize HTML
 229      foreach ( (array)$api->sections as $section_name => $content )
 230          $api->sections[$section_name] = wp_kses($content, $themes_allowedtags);
 231  
 232      foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key ) {
 233          if ( isset($api->$key) )
 234              $api->$key = wp_kses($api->$key, $themes_allowedtags);
 235      }
 236  
 237      iframe_header( __('Theme Install') );
 238  
 239      if ( empty($api->download_link) ) {
 240          echo '<div id="message" class="error"><p>' . __('<strong>Error:</strong> This theme is currently not available. Please try again later.') . '</p></div>';
 241          iframe_footer();
 242          exit;
 243      }
 244  
 245      if ( !empty($api->tested) && version_compare($GLOBALS['wp_version'], $api->tested, '>') )
 246          echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
 247      else if ( !empty($api->requires) && version_compare($GLOBALS['wp_version'], $api->requires, '<') )
 248          echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This theme has not been marked as <strong>compatible</strong> with your version of WordPress.') . '</p></div>';
 249  
 250      // Default to a "new" theme
 251      $type = 'install';
 252      // Check to see if this theme is known to be installed, and has an update awaiting it.
 253      $update_themes = get_site_transient('update_themes');
 254      if ( is_object($update_themes) && isset($update_themes->response) ) {
 255          foreach ( (array)$update_themes->response as $theme_slug => $theme_info ) {
 256              if ( $theme_slug === $api->slug ) {
 257                  $type = 'update_available';
 258                  $update_file = $theme_slug;
 259                  break;
 260              }
 261          }
 262      }
 263  
 264      $themes = get_themes();
 265      foreach ( $themes as $this_theme ) {
 266          if ( is_array($this_theme) && $this_theme['Stylesheet'] == $api->slug ) {
 267              if ( $this_theme['Version'] == $api->version ) {
 268                  $type = 'latest_installed';
 269              } elseif ( $this_theme['Version'] > $api->version ) {
 270                  $type = 'newer_installed';
 271                  $newer_version = $this_theme['Version'];
 272              }
 273              break;
 274          }
 275      }
 276  ?>
 277  
 278  <div class='available-theme'>
 279  <img src='<?php echo esc_url($api->screenshot_url) ?>' width='300' class="theme-preview-img" />
 280  <h3><?php echo $api->name; ?></h3>
 281  <p><?php printf(__('by %s'), $api->author); ?></p>
 282  <p><?php printf(__('Version: %s'), $api->version); ?></p>
 283  
 284  <?php
 285  $buttons = '<a class="button" id="cancel" href="#" onclick="tb_close();return false;">' . __('Cancel') . '</a> ';
 286  
 287  switch ( $type ) {
 288  default:
 289  case 'install':
 290      if ( current_user_can('install_themes') ) :
 291      $buttons .= '<a class="button-primary" id="install" href="' . wp_nonce_url(self_admin_url('update.php?action=install-theme&theme=' . $api->slug), 'install-theme_' . $api->slug) . '" target="_parent">' . __('Install Now') . '</a>';
 292      endif;
 293      break;
 294  case 'update_available':
 295      if ( current_user_can('update_themes') ) :
 296      $buttons .= '<a class="button-primary" id="install"    href="' . wp_nonce_url(self_admin_url('update.php?action=upgrade-theme&theme=' . $update_file), 'upgrade-theme_' . $update_file) . '" target="_parent">' . __('Install Update Now') . '</a>';
 297      endif;
 298      break;
 299  case 'newer_installed':
 300      if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
 301      ?><p><?php printf(__('Newer version (%s) is installed.'), $newer_version); ?></p><?php
 302      endif;
 303      break;
 304  case 'latest_installed':
 305      if ( current_user_can('install_themes') || current_user_can('update_themes') ) :
 306      ?><p><?php _e('This version is already installed.'); ?></p><?php
 307      endif;
 308      break;
 309  } ?>
 310  <br class="clear" />
 311  </div>
 312  
 313  <p class="action-button">
 314  <?php echo $buttons; ?>
 315  <br class="clear" />
 316  </p>
 317  
 318  <?php
 319      iframe_footer();
 320      exit;
 321  }
 322  add_action('install_themes_pre_theme-information', 'install_theme_information');
 323  


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting