Ticket #302: rollover_themes.txt

File rollover_themes.txt, 6.5 kB (added by dsader, 1 year ago)
Line 
1 <?php
2 require_once('admin.php');
3
4 $themes = get_themes();
5 $ct = current_theme_info();
6 $allowed_themes = get_site_allowed_themes();
7 if( $allowed_themes == false )
8         $allowed_themes = array();
9
10 $blog_allowed_themes = wpmu_get_blog_allowedthemes();
11 if( is_array( $blog_allowed_themes ) )
12         $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
13 if( $blog_id != 1 )
14         unset( $allowed_themes[ "h3" ] );
15
16 if( isset( $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false )
17     $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true;
18
19 reset( $themes );
20 foreach( $themes as $key => $theme ) {
21     if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
22                 unset( $themes[ $key ] );
23     }
24 }
25 reset( $themes );
26
27 if ( isset($_GET['action']) ) {
28         check_admin_referer('switch-theme_' . $_GET['template']);
29
30         if ('activate' == $_GET['action']) {
31                 $found = false;
32                 while( list( $key, $details ) = each( $themes ) ) {
33                         if( $details[ 'Template' ] == $_GET['template'] && $details[ 'Stylesheet' ] == $_GET['stylesheet'] ) {
34                                 $found = true;
35                                 break;
36                         }
37                 }
38                 if( $found == true ) {
39                         if ( isset($_GET['template']) )
40                                 update_option('template', $_GET['template']);
41
42                         if ( isset($_GET['stylesheet']) )
43                                 update_option('stylesheet', $_GET['stylesheet']);
44
45                         do_action('switch_theme', get_current_theme());
46
47                         wp_redirect('themes.php?activated=true');
48                 } else {
49                         wp_redirect('themes.php');
50                 }
51                 exit;
52         }
53 }
54
55 $title = __('Manage Themes');
56 $parent_file = 'themes.php';
57 require_once('admin-header.php');
58 ?>
59
60 <?php if ( ! validate_current_theme() ) : ?>
61 <div id="message1" class="updated fade"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div>
62 <?php elseif ( isset($_GET['activated']) ) : ?>
63 <div id="message2" class="updated fade"><p><?php printf(__('New theme activated. <a href="%s">View site &raquo;</a>'), get_bloginfo('home') . '/'); ?></p></div>
64 <?php endif; ?>
65
66 <!-- User Themes go here -->
67 <div class="wrap">
68 <h2><?php _e('Current Theme'); ?></h2>
69 <div id="currenttheme">
70 <?php if ( $ct->screenshot ) : ?>
71 <img src="<?php echo get_option('siteurl') . '/' . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
72 <?php endif; ?>
73 <p><?php
74         $cTheme = get_current_theme();
75         echo "<p>The currently active theme is <b>$cTheme</b>, ";
76         if (get_option('ut_use_user_theme') == 1 )
77              echo "from the <b>User Themes</b> library.</p>";
78         else
79              echo "from the <b>System Themes</b> library.</p>";
80         ?></p>
81 </div>
82 <br style="clear: both" />
83 <h2> </h2>
84 </div>
85 <?php
86 $theme_names = array_keys($themes);
87 natcasesort($theme_names);
88 ?>
89 <div class="wrap">
90 <form>
91 <table id='the-list-x' width='auto'>
92 <tr style='background-color: #444444; color:#ffffff;'>
93 <td colspan='5'>System Themes <i style='font-size:.8em'>(no editing)</i></td></tr>
94 <?php
95 foreach ($theme_names as $theme_name) {
96         $template = $themes[$theme_name]['Template'];
97         $stylesheet = $themes[$theme_name]['Stylesheet'];
98         $title = $themes[$theme_name]['Title'];
99         $version = $themes[$theme_name]['Version'];
100         $description = $themes[$theme_name]['Description'];
101         $author = $themes[$theme_name]['Author'];
102         $screenshot = $themes[$theme_name]['Screenshot'];
103         $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
104            $alt = $alt == '' ? 'alternate' : '';
105         $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=$template&amp;stylesheet=$stylesheet", 'switch-theme_' . $template);
106 ?>
107 <tr class='<?php echo $alt; ?>'><td><a style='text-decoration: none; color: black;' href='<?php echo $activate_link; ?>'<?php echo "onMouseOver=\"preview('" . get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot . "', getTopPosition(this));\"onMouseOut=\"unpreview();\"
108 "; ?>><?php echo "$title"; ?></a></td>
109 <td><?php echo "$description"; ?></td>
110 <?php if( is_site_admin() ) { ?>
111 <td><?php echo "$version"; ?></td>
112 <td><?php echo "$author"; ?></td>
113 <?php } ?>
114 <td><a href='<?php echo $activate_link; ?>'>Activate</a></td>
115 </tr>
116 <?php }
117 ?>
118 </form>
119 </table>
120 </div>
121 <script>
122         var pendingOpen = 0;
123         var open = 0;
124         var pendingClose = 0;
125         function preview(url, top) {
126            document.getElementById('previewbox').style.top=top-100 + "px";
127            document.getElementById('previewimage').src=url;
128            pendingOpen = 1;
129            pendingClose = 0;
130            setTimeout('showpreview()', 1000);
131         }
132         function unpreview() {
133           pendingClose = 1;
134           setTimeout('hidepreview()', 400);
135         }
136         function showpreview() {
137            if (pendingOpen == 0) { return; }
138            var p = document.getElementById('previewbox');
139            p.style.visibility='visible';
140         }
141         function hidepreview() {
142            if  (pendingClose == 0 ) {return;}
143            pendingClose = 0;
144            pendingOpen = 0;
145            var p = document.getElementById('previewbox');
146            p.style.visibility='hidden';
147         }
148         function getTopPosition(e) {
149            p = 0;
150            while (e!=null) {
151               p += e.offsetTop;
152               e = e.offsetParent;
153            }
154            return p;
155         }
156       </script>
157
158       <style>
159          #previewbox {
160              visibility: hidden;     
161              width: 200px;
162              height: 200px;
163              background-color: white;
164              border: 5px solid #cccccc;
165              position: absolute;
166              left: 220px;
167              top: 300px;
168          }
169       </style>
170       <div id='previewbox'>
171          <img id='previewimage' width='200' height='200' border='0' src='http://www.google.com/intl/en/images/logo.gif'/>
172       </div>
173
174 <!--End User Themes-->
175
176
177 <?php
178
179 // List broken themes, if any.
180 $broken_themes = get_broken_themes();
181 if ( is_site_admin() && count($broken_themes) ) {
182 ?>
183
184 <h2><?php _e('Broken Themes'); ?> (Site admin only)</h2>
185 <p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p>
186
187 <table width="100%" cellpadding="3" cellspacing="3">
188         <tr>
189                 <th><?php _e('Name'); ?></th>
190                 <th><?php _e('Description'); ?></th>
191         </tr>
192 <?php
193         $theme = '';
194
195         $theme_names = array_keys($broken_themes);
196         natcasesort($theme_names);
197
198         foreach ($theme_names as $theme_name) {
199                 $title = $broken_themes[$theme_name]['Title'];
200                 $description = $broken_themes[$theme_name]['Description'];
201
202                 $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
203                 echo "
204                 <tr $theme>
205                          <td>$title</td>
206                          <td>$description</td>
207                 </tr>";
208         }
209 ?>
210 </table>
211 <?php
212 }
213 ?>
214 <br clear="all" />
215 </div>
216
217 <?php require('admin-footer.php'); ?>