PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Websites/remote/wp-admin/includes/theme-install.php

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