/bp-forums/bbpress/bb-admin/themes.php

  1. <?php 
  2. require_once('admin.php'); 
  3.  
  4. $themes = bb_get_themes(); 
  5.  
  6. $activetheme = bb_get_option('bb_active_theme'); 
  7. if (!$activetheme) { 
  8. $activetheme = BB_DEFAULT_THEME; 
  9.  
  10. if ( isset($_GET['theme']) ) { 
  11. if ( !bb_current_user_can( 'manage_themes' ) ) { 
  12. wp_redirect( bb_get_uri(null, null, BB_URI_CONTEXT_HEADER) ); 
  13. exit; 
  14.  
  15. bb_check_admin_referer( 'switch-theme' ); 
  16. do_action( 'bb_deactivate_theme_' . $activetheme ); 
  17.  
  18. $theme = stripslashes($_GET['theme']); 
  19. $theme_data = bb_get_theme_data( $theme ); 
  20. if ($theme_data['Name']) { 
  21. $name = $theme_data['Name']; 
  22. } else { 
  23. $name = preg_replace( '/^([a-z0-9_-]+#)/i', '', $theme); 
  24. if ($theme == BB_DEFAULT_THEME) { 
  25. bb_delete_option( 'bb_active_theme' ); 
  26. } else { 
  27. bb_update_option( 'bb_active_theme', $theme ); 
  28. do_action( 'bb_activate_theme_' . $theme ); 
  29. wp_redirect( bb_get_uri('bb-admin/themes.php', array('activated' => 1, 'name' => urlencode( $name ) ), BB_URI_CONTEXT_HEADER + BB_URI_CONTEXT_BB_ADMIN ) ); 
  30. exit; 
  31.  
  32. if ( isset($_GET['activated']) ) 
  33. $theme_notice = bb_admin_notice( sprintf( __( '<strong>Theme "%s" activated</strong>' ), esc_attr($_GET['name'])) ); 
  34.  
  35. if ( !in_array($activetheme, $themes) ) { 
  36. if ($activetheme == BB_DEFAULT_THEME) { 
  37. remove_action( 'bb_admin_notices', $theme_notice ); 
  38. bb_admin_notice( __( '<strong>Default theme is missing.</strong>' ), 'error' ); 
  39. } else { 
  40. bb_delete_option( 'bb_active_theme' ); 
  41. remove_action( 'bb_admin_notices', $theme_notice ); 
  42. bb_admin_notice( __( '<strong>Theme not found. Default theme applied.</strong>' ), 'error' ); 
  43.  
  44. function bb_admin_theme_row( $theme, $position ) { 
  45. $theme_directory = bb_get_theme_directory( $theme ); 
  46. $theme_data = file_exists( $theme_directory . 'style.css' ) ? bb_get_theme_data( $theme ) : false; 
  47. $screen_shot = file_exists( $theme_directory . 'screenshot.png' ) ? esc_url( bb_get_theme_uri( $theme ) . 'screenshot.png' ) : false; 
  48. $activation_url = bb_get_uri('bb-admin/themes.php', array('theme' => urlencode($theme)), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 
  49. $activation_url = esc_url( bb_nonce_url( $activation_url, 'switch-theme' ) ); 
  50.  
  51. if ( 1 === $position || 0 === $position ) { 
  52. echo '<tr>'; 
  53. ?> 
  54. <td class="position-<?php echo( (int) $position ); ?>"> 
  55. <div class="screen-shot"><?php if ( $screen_shot ) : ?><a href="<?php echo $activation_url; ?>" title="<?php echo esc_attr( sprintf( __( 'Activate "%s"' ), $theme_data['Title'] ) ); ?>"><img alt="<?php echo esc_attr( $theme_data['Title'] ); ?>" src="<?php echo $screen_shot; ?>" /></a><?php endif; ?></div> 
  56. <div class="description"> 
  57. <h3 class="themes"> 
  58. <?php 
  59. printf( 
  60. __( '%1$s %2$s by <cite>%3$s</cite>' ),  
  61. $theme_data['Title'],  
  62. $theme_data['Version'],  
  63. $theme_data['Author'] 
  64. ); 
  65. ?> 
  66. </h3> 
  67.  
  68. <?php 
  69. if ( $theme_data['Porter'] ) { 
  70. ?> 
  71. <p> 
  72. <?php 
  73. printf( 
  74. __( 'Ported by <cite>%s</cite>' ),  
  75. $theme_data['Porter'] 
  76. ); 
  77. ?> 
  78. </p> 
  79. <?php 
  80. ?> 
  81.  
  82. <?php echo $theme_data['Description']; // Description is autop'ed ?> 
  83. <?php 
  84. if ( 0 !== $position ) { 
  85. ?> 
  86. <div class="actions"> 
  87. <a href="<?php echo $activation_url; ?>" title="<?php echo esc_attr( sprintf( __( 'Activate "%s"' ), $theme_data['Title'] ) ); ?>"><?php _e( 'Activate' ); ?></a> 
  88. </div> 
  89. <?php 
  90. ?> 
  91. <p class="location"><?php printf(__('All of this theme\'s files are located in the "%s" themes directory.'), $theme_data['Location']); ?></p> 
  92. </div> 
  93. </td> 
  94. <?php 
  95.  
  96. if ( 3 === $position || 0 === $position ) { 
  97. echo '</tr>'; 
  98.  
  99. if ( isset( $bb->safemode ) && $bb->safemode === true ) { 
  100. bb_admin_notice( __( '<strong>"Safe mode" is on, the default theme will be used instead of the active theme indicated below.</strong>' ), 'error' ); 
  101.  
  102. $bb_admin_body_class = ' bb-admin-appearance'; 
  103.  
  104. bb_get_admin_header(); 
  105. ?> 
  106.  
  107. <h2><?php _e('Manage Themes'); ?></h2> 
  108. <?php do_action( 'bb_admin_notices' ); ?> 
  109.  
  110. <h3 class="themes"><?php _e('Current Theme'); ?></h3> 
  111. <div> 
  112. <table class="theme-list-active"> 
  113. <?php bb_admin_theme_row( $themes[$activetheme], 0 ); unset($themes[$activetheme] ); ?> 
  114. </table> 
  115. </div> 
  116.  
  117. <?php if ( !empty($themes) ) : ?> 
  118.  
  119. <h3 class="themes"><?php _e('Available Themes'); ?></h3> 
  120. <div> 
  121. <table class="theme-list"> 
  122. <?php 
  123. $i = 0; 
  124. foreach ( $themes as $theme ) { 
  125. $position = 1 + ( $i % 3 ); 
  126.  
  127. bb_admin_theme_row( $theme, $position ); 
  128.  
  129. $i++; 
  130.  
  131. switch ( $position ) { 
  132. case 1: 
  133. echo '<td class="position-2"></td><td class="position-3"></td></tr>'; 
  134. break; 
  135. case 2: 
  136. echo '<td class="position-3"></td></tr>'; 
  137. break; 
  138. case 3: 
  139. break; 
  140. ?> 
  141. </table> 
  142. </div> 
  143.  
  144. <?php endif; bb_get_admin_footer(); ?> 
.