Theme Test Drive - Version 2.5

Version Description

Download this release

Release Info

Developer freediver
Plugin Icon 128x128 Theme Test Drive
Version 2.5
Comparing to
See all releases

Version 2.5

Files changed (12) hide show
  1. bg.png +0 -0
  2. help.png +0 -0
  3. home.png +0 -0
  4. idea.png +0 -0
  5. more.png +0 -0
  6. p1.png +0 -0
  7. previewbubble.js +137 -0
  8. readme.txt +95 -0
  9. screenshot-1.png +0 -0
  10. screenshot-2.png +0 -0
  11. themedrive.chk +2 -0
  12. themedrive.php +565 -0
bg.png ADDED
Binary file
help.png ADDED
Binary file
home.png ADDED
Binary file
idea.png ADDED
Binary file
more.png ADDED
Binary file
p1.png ADDED
Binary file
previewbubble.js ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Preview Bubble Javascript by Juan Xavier Larrea <xavier@websnapr.com>
3
+ http://www.websnapr.com
4
+
5
+ ---
6
+
7
+ Ingenier�a inversa por Javier P�rez <javier.perez.m@gmail.com>
8
+ http://javierperez.eu
9
+
10
+ ---
11
+
12
+ WordPress 2+ Plugin by Andufo <info@andufo.com>
13
+ http://andufo.com
14
+ */
15
+
16
+ if(typeof Array.prototype.push!="function") {
17
+ Array.prototype.push=ArrayPush;
18
+ function ArrayPush(_1) {
19
+ this[this.length] = _1;
20
+ }
21
+ }
22
+ function WSR_getElementsByClassName(node, tag_name, class_name) {
23
+ if (!node)
24
+ return;
25
+ var nodes =(tag_name=="*" && node.all) ? node.all : node.getElementsByTagName(tag_name);
26
+ var data = new Array();
27
+ class_name = class_name.replace(/\-/g,"\\-");
28
+ var find_class = new RegExp("(^|\\s)" + class_name + "(\\s|$)");
29
+ var n;
30
+ for(var i=0;i<nodes.length;i++){
31
+ n = nodes[i];
32
+ if(find_class.test(n.className)) {
33
+ data.push(n);
34
+ }
35
+ }
36
+ return(data);
37
+ }
38
+ function bindBubbles(e) {
39
+ var entries = WSR_getElementsByClassName(document.getElementById("theme_preview"), "div", "theme_links");
40
+ if (!entries) return;
41
+ for(var i=0;i<entries.length;i++) {
42
+ var nodes = entries[i].getElementsByTagName('a');
43
+ for(var j=0;j<nodes.length;j++) {
44
+ str = new String(nodes[j]);
45
+ var myDomain = "http://"+document.domain;
46
+ var flgExternal = str.search(myDomain);
47
+ var flgFtp = str.search("ftp://");
48
+ var flgMailto = str.search("mailto:");
49
+ if( flgFtp==-1 && flgMailto==-1) {
50
+ var flgNoFile = 1;
51
+ if(str.substr(str.lastIndexOf(".")+1).match(/zip|exe|rar|swf|mp3|wav|mid|avi|mov|mpg|mpeg|wmv|pdf|doc|ppt|xls|jpeg|jpg|gif|png/)) flgNoFile = 0;
52
+ if(flgNoFile) {
53
+ if(window.addEventListener) {
54
+ nodes[j].addEventListener("mouseover",attachBubble,false);
55
+ nodes[j].addEventListener("mouseout",detachBubble,false);
56
+ } else {
57
+ nodes[j].attachEvent("onmouseover",attachBubble);
58
+ nodes[j].attachEvent("onmouseout",detachBubble);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ function attachBubble(_b, url_image) {
66
+ var _c;
67
+ if(_b["srcElement"]) {
68
+ _c=_b["srcElement"];
69
+ } else {
70
+ _c=_b["target"];
71
+ }
72
+ var _d=_c.href;
73
+ var _e=findPos(_c)[0]+5;
74
+ var _f=findPos(_c)[1]+17;
75
+ var _10=document.createElement("div");
76
+ _10.className="previewbubble";
77
+ _10.setAttribute("style","text-align: left;z-index: 99999;position: absolute;top: "+_f+"px ;left: "+_e+"px ;background: url("+ bubbleImagePath +");width: 461px;height: 330px;padding-top: 40px;padding-left: 40px;padding-bottom: 0;padding-right: 0;margin: 0;");
78
+ _10.style.width="441px";
79
+ _10.style.position="absolute";
80
+ _10.style.top=_f;
81
+ _10.style.zIndex=99999;
82
+ _10.style.left=_e;
83
+ _10.style.textAlign="left";
84
+ _10.style.height="320px";
85
+ _10.style.paddingTop="55px";
86
+ _10.style.paddingLeft="50px";
87
+ _10.style.paddingBottom="0";
88
+ _10.style.paddingRight="0";
89
+ _10.style.marginTop="0";
90
+ _10.style.marginLeft="0";
91
+ _10.style.marginBottom="0";
92
+ _10.style.marginRight="0";
93
+ _10.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bubbleImagePath + "',sizingMethod='scale')";
94
+ var img=document.createElement("img");
95
+ img.setAttribute("style","margin: 0;padding: 0;border: 0");
96
+ img.style.paddingTop="0";
97
+ img.style.paddingLeft="0";
98
+ img.style.paddingBottom="0";
99
+ img.style.paddingRight="0";
100
+ img.style.marginTop="0";
101
+ img.style.marginLeft="0";
102
+ img.style.marginBottom="0";
103
+ img.style.marginRight="0";
104
+ img.style.borderTop="0";
105
+ img.style.borderLeft="0";
106
+ img.style.borderBottom="0";
107
+ img.style.borderRight="0";
108
+ img.setAttribute("src", url_image ? url_image :("http://images.websnapr.com/?size=m&key=42d1W6HhpB0B&url="+_d));
109
+ img.setAttribute("width",400);
110
+ img.setAttribute("height",300);
111
+ img.setAttribute("alt","Snapshot");
112
+ _10.appendChild(img);
113
+ document.getElementsByTagName("body")[0].appendChild(_10);
114
+ }
115
+ function detachBubble(_12) {
116
+ lbActions=WSR_getElementsByClassName(document,"div","previewbubble");
117
+ for(i=0;i<lbActions.length;i++) {
118
+ lbActions[i].parentNode.removeChild(lbActions[i]);
119
+ }
120
+ }
121
+ if(window.addEventListener){
122
+ addEventListener("load",bindBubbles,false);
123
+ } else {
124
+ attachEvent("onload",bindBubbles);
125
+ }
126
+ function findPos(obj) {
127
+ var _14=curtop=0;
128
+ if(obj.offsetParent) {
129
+ _14=obj.offsetLeft;
130
+ curtop=obj.offsetTop;
131
+ while(obj=obj.offsetParent) {
132
+ _14+=obj.offsetLeft;
133
+ curtop+=obj.offsetTop;
134
+ }
135
+ }
136
+ return [_14,curtop];
137
+ }
readme.txt ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Theme Test Drive ===
2
+ Contributors: freediver
3
+ Donate link: https://www.networkforgood.org/donation/MakeDonation.aspx?ORGID2=920155875
4
+ Tags: theme, themes, admin, test
5
+ Requires at least: 2.3
6
+ Tested up to: 2.5.1
7
+ Stable tag: 2.5
8
+
9
+ Safely test drive any theme as an administrator, while visitors use the default one.
10
+
11
+ == Description ==
12
+
13
+ Theme Test Drive Wordpress plugin allows you to safely test drive any theme on your blog as administrator, while visitors still use the default one.
14
+
15
+ It happens completely transparent and they will not even notice you run a different theme for yourself.
16
+
17
+ Best part is you can even set the testing theme options (if it has them) in the Admin panel while you are testing the theme.
18
+
19
+ Since version 2.0 Theme Test Drive features instant theme preview using a website thumbnail service.
20
+
21
+ You can also preview any theme by adding "?theme=xxx" to your blog URL. For example http://www.myblog.com/?theme=Default
22
+
23
+ Changes v2.5:
24
+ - Easy theme installation: Install your themes using a built in installer
25
+ - Ability to use folder name as well as "?theme=xxx" paramter for instant preview (thanks Michael Stewart!)
26
+
27
+ Changes v2.0:
28
+ - Instant theme preview using a live thumbnail preview
29
+ - Added ?theme=xxx to your URL's to preview the desired theme. Example http://www.myblog.com/?theme=Default
30
+
31
+ == Installation ==
32
+
33
+ 1. Upload the whole plugin folder to your /wp-content/plugins/ folder.
34
+
35
+ 2. Go to the Plugins page and activate the plugin.
36
+
37
+ 3. Use the Options page to set the theme you want to test drive.
38
+
39
+ The selected theme will be visible only to blog administrator.
40
+
41
+ Other visitors of the blog will always see the default theme.
42
+
43
+ Note: if you use WP-Cache plugin, you might need to disable it (or setup to exclude pages)
44
+
45
+
46
+ == Credits ==
47
+
48
+ Some of the functions of Theme Test Drive plugin came from other plugins. So I can at least thank these people:
49
+
50
+ * [Ryan Boren](http://boren.nu/ "Ryan Boren") for his [Theme Switcher](http://dev.wp-plugins.org/wiki/ThemeSwitcher "Theme Switcher") plugin
51
+ * [Andres Santos](http://andufo.com "Andres Santos") for his [wp-websnapr](http://andufo.com/proyectos/plugins/wp-websnapr" "wp-websnapr") plugin
52
+ * [Oliver](http://www.deliciousdays.com/ "Oliver") for his [cforms II](http://www.deliciousdays.com/cforms-plugin "cforms II") plugin
53
+ * [Scott](http://www.plaintxt.org/ "Scott") for his excellent readme.txt file
54
+ * [WebSnapr](http://www.websnapr.com "WebSnapr") folks for their service
55
+
56
+ Thanks.
57
+
58
+ == License ==
59
+
60
+ This file is part of Theme Test Drive.
61
+
62
+ Theme Test Drive is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
63
+
64
+ Theme Test Drive is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
65
+
66
+ You should have received a copy of the GNU General Public License along with Theme Test Drive. If not, see <http://www.gnu.org/licenses/>.
67
+
68
+
69
+ == Screenshots ==
70
+
71
+ 1. Instant theme preview and theme installation
72
+ 2. Plugin in action
73
+
74
+
75
+
76
+
77
+ == Frequently Asked Questions ==
78
+
79
+ = How do I correctly use this plugin? =
80
+
81
+ Go to Admin Panel, Design, Theme Test Drive. Select the theme you want to preview and click enable.
82
+
83
+ Additionally you may click on any of the instant preview links, or wait for a preview thumbnail to generate.
84
+
85
+ = How does instant image preview work? =
86
+
87
+ The image is fetched using a thumbnail webservice. It may need some time to generate the image so you may want to reload the page.
88
+
89
+ = Can I suggest an feature for the plugin? =
90
+
91
+ Of course, visit <a href="http://www.prelovac.com/vladimir/wordpress-plugins/theme-test-drive#comments">Theme Test Drive Home Page</a>
92
+
93
+ = I love your work, are you available for hire? =
94
+
95
+ Yes I am, visit my <a href="http://www.prelovac.com/vladimir/services">WordPress Services</a> page to find out more.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
themedrive.chk ADDED
@@ -0,0 +1,2 @@
 
 
1
+ Version@2.0@
2
+ Message@<ul><li>Live theme preview and theme install.</li></ul>
themedrive.php ADDED
@@ -0,0 +1,565 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Theme Test Drive
4
+ Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/theme-test-drive
5
+ Description: Safely test drive any theme while visitors are using the default one. Includes instant theme preview via thumbnail.
6
+ Author: Vladimir Prelovac
7
+ Version: 2.5
8
+ Author URI: http://www.prelovac.com/vladimir/
9
+
10
+ To-Do:
11
+ - localization
12
+ - theme upload
13
+ - theme page snapshots
14
+ */
15
+
16
+ // // // PLUGIN CODE // // //
17
+
18
+ $themedrive_localversion="2.5";
19
+
20
+ function themedrive_handle_theme($package)
21
+ {
22
+ // select theme handling by commenting one of these funcitons
23
+
24
+ themedrive_handle_theme_liberal($package);
25
+
26
+ //themedrive_handle_theme_rigid($package);
27
+ }
28
+
29
+
30
+ function themedrive_unzip($file, $dir) {
31
+ if( ! current_user_can('edit_files')) {
32
+ echo 'Oops, sorry you are not authorized to do this';
33
+ return false;
34
+ }
35
+ if(! class_exists('PclZip')) {
36
+ require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
37
+ }
38
+
39
+
40
+ $unzipArchive = new PclZip($file);
41
+ $list=$unzipArchive->properties();
42
+ if (!$list['nb'])
43
+ return false;
44
+ //echo "Number of files in archive : ".$list['nb']."<br>";
45
+
46
+ echo "Copying the files<br>";
47
+ $result=$unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
48
+ if($result == 0) {
49
+ echo 'Could not unarchive the file: '.$unzipArchive->errorInfo(true).' <br />';
50
+ return false;
51
+ }
52
+ else {
53
+ //print_r($result);
54
+ foreach ($result as $item)
55
+ {
56
+ if ($item['status']!='ok')
57
+ echo $item['stored_filename'].' ... '.$item['status'].'<br>';
58
+ }
59
+ return true;
60
+ }
61
+ }
62
+
63
+ function themedrive_handle_theme_liberal( $package) {
64
+
65
+ echo "Downloading the theme from ".$package."<br>";
66
+ $file = download_url($package);
67
+
68
+ if ( is_wp_error($file) )
69
+ {
70
+ echo 'Download failed: '.$file->get_error_message();
71
+ return;
72
+ }
73
+
74
+ echo "Unpacking the theme<br>";
75
+
76
+ // Unzip theme to theme directory
77
+ $result = themedrive_unzip($file, ABSPATH . "wp-content/themes/"); //theme dir
78
+
79
+ // Once extracted, delete the package
80
+ unlink($file);
81
+
82
+ if ($result)
83
+ echo "<br>Theme installed successfully.<br><br>";
84
+ else {
85
+ echo "<br>Error installing the theme.<br><br>You can try installing the theme manually: <a href=\"$package\">$package</a><br><br>";
86
+ }
87
+ return;
88
+
89
+ }
90
+
91
+
92
+
93
+ function themedrive_handle_theme_rigid( $package) {
94
+ global $wp_filesystem;
95
+
96
+ if ( ! $wp_filesystem || !is_object($wp_filesystem) )
97
+ WP_Filesystem($credentials);
98
+
99
+
100
+ if ( ! is_object($wp_filesystem) ) {
101
+
102
+ echo '<strong><em>Could not access filesystem.</strong></em><br><br>';
103
+ return;
104
+ }
105
+
106
+
107
+
108
+ if ( $wp_filesystem->errors->get_error_code() ){
109
+
110
+ echo '<strong><em>Filesystem error '. $wp_filesystem->errors->get_error_message().'</strong></em><br><br>';
111
+ return ;
112
+ }
113
+
114
+ //Get the Base folder
115
+ $base = $wp_filesystem->get_base_dir();
116
+
117
+ if ( empty($base) )
118
+ {
119
+ echo '<strong><em>Unable to locate WordPress directory.</strong></em><br><br>';
120
+ return ;
121
+ }
122
+
123
+
124
+
125
+ echo "Downloading theme file from ".$package."<br>";
126
+ $file = download_url($package);
127
+
128
+ if ( is_wp_error($file) )
129
+ {
130
+ echo '<strong><em>Download failed : '.$file->get_error_message().'</strong></em><br><br>';
131
+ return;
132
+ }
133
+
134
+
135
+ $working_dir = $base . 'wp-content/upgrade/themes';
136
+
137
+ // Clean up working directory
138
+ if ( $wp_filesystem->is_dir($working_dir) )
139
+ $wp_filesystem->delete($working_dir, true);
140
+
141
+
142
+ echo "Unpacking the theme<br>";
143
+ // Unzip package to theme directory
144
+ $result = unzip_file($file, $working_dir);
145
+ if ( is_wp_error($result) ) {
146
+ unlink($file);
147
+ $wp_filesystem->delete($working_dir, true);
148
+ echo '<strong><em>Unpack failed : '. $result->get_error_message() .'</strong></em><br><br>';
149
+ return ;
150
+ }
151
+
152
+ echo "Installing the theme<br>";
153
+ // Copy new version of plugin into place.
154
+ if ( !copy_dir($working_dir,$base . "wp-content/themes") ) {
155
+ $wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
156
+ echo '<strong><em>Installation failed (theme already installed?)</strong></em><br><br>';
157
+ return;
158
+ }
159
+
160
+ //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
161
+ $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
162
+
163
+ // Remove working directory
164
+ $wp_filesystem->delete($working_dir, true);
165
+
166
+ // Once extracted, delete the package
167
+ unlink($file);
168
+
169
+ echo "Theme installed successfully.<br><br>";
170
+ return;
171
+
172
+ }
173
+
174
+ function themedrive_get_theme()
175
+ {
176
+ $gettheme=get_option('td_themes');
177
+
178
+ if (!empty($gettheme)) {
179
+ return $gettheme;
180
+ } else {
181
+ return '';
182
+ }
183
+ }
184
+
185
+ function themedrive_determine_theme()
186
+ {
187
+
188
+ if (!isset($_GET['theme'])) {
189
+ if (! current_user_can('level_10') ) { // not admin
190
+ return false;
191
+ } else {
192
+ $theme = themedrive_get_theme();
193
+ if ($theme == '') {
194
+ // no admin-only theme defined, short-circuit out
195
+ return false;
196
+ }
197
+ }
198
+ }
199
+
200
+ if (isset($_GET['theme'])) {
201
+ $theme = $_GET['theme'];
202
+ }
203
+
204
+ $theme_data = get_theme($theme);
205
+
206
+ if (! empty($theme_data) ) {
207
+ // Don't let people peek at unpublished themes
208
+ if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
209
+ return false;
210
+ }
211
+ return $theme_data;
212
+ }
213
+
214
+ // perhaps they are using the theme directory instead of title
215
+ $themes = get_themes();
216
+
217
+ foreach($themes as $theme_data) {
218
+ // use Stylesheet as it's unique to the theme - Template could point to another theme's templates
219
+ if ($theme_data['Stylesheet'] == $theme) {
220
+ // Don't let people peek at unpublished themes
221
+ if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
222
+ return false;
223
+ }
224
+ return $theme_data;
225
+ }
226
+ }
227
+
228
+ return false;
229
+
230
+ }
231
+
232
+ function themedrive_get_template($template)
233
+ {
234
+ $theme = themedrive_determine_theme();
235
+ if ($theme === false) {
236
+ return $template;
237
+ }
238
+
239
+ return $theme['Template'];
240
+ }
241
+
242
+ function themedrive_get_stylesheet($stylesheet)
243
+ {
244
+ $theme = themedrive_determine_theme();
245
+ if ($theme === false) {
246
+ return $stylesheet;
247
+ }
248
+
249
+ return $theme['Stylesheet'];
250
+ }
251
+
252
+ function themedrive_switcher()
253
+ {
254
+ $themes = get_themes();
255
+
256
+ $default_theme = get_current_theme();
257
+
258
+ if (count($themes) > 1) {
259
+ $theme_names = array_keys($themes);
260
+ natcasesort($theme_names);
261
+
262
+
263
+ $ts = '<br/><p><strong>Live Theme Preview</strong><br/><br/>Select a theme to preview live on the site. Only administrator will be able to see the selected theme. </strong></p> <select name="td_themes">'."\n" ;
264
+ $tp = '<div id="theme_preview">
265
+ <div class="theme_links"><strong>Instant Theme Preview</strong><br/><br/>Hover over the link, reload the page if needed.<br/><ul>';
266
+
267
+ foreach($theme_names as $theme_name) {
268
+ // Skip unpublished themes.
269
+ if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish') {
270
+ continue;
271
+ }
272
+
273
+ if ((themedrive_get_theme() == $theme_name)
274
+ || ((themedrive_get_theme()=='') && ($theme_name == $default_theme))) {
275
+ $ts .= ' <option value="'.$theme_name.'" selected="selected">'
276
+ . htmlspecialchars($theme_name)
277
+ . '</option>'."\n"
278
+ ;
279
+ } else {
280
+ $ts .= ' <option value="'.$theme_name.'">'
281
+ . htmlspecialchars($theme_name)
282
+ . '</option>'."\n"
283
+ ;
284
+ }
285
+ $tp.='<li><a href="'.trailingslashit(get_option('siteurl')).'?theme='.htmlspecialchars($theme_name).'">'.$theme_name.'</a></li>';
286
+ }
287
+ $ts .= ' </select>'."\n\n";
288
+ $tp.='</ul></div></div>';
289
+ }
290
+ echo $tp;
291
+
292
+ echo $ts;
293
+ if (themedrive_is_enabled()) {
294
+ echo '<strong>Theme Test Drive is Enabled.</strong><br /><br /><br />';
295
+ } else {
296
+ echo 'Theme Test Drive is Disabled.<br /><br /><br />';
297
+ }
298
+
299
+
300
+
301
+
302
+ }
303
+
304
+ add_filter('template', 'themedrive_get_template');
305
+ add_filter('stylesheet', 'themedrive_get_stylesheet');
306
+
307
+
308
+
309
+ // Admin Panel
310
+ function themedrive_add_pages()
311
+ {
312
+ add_theme_page( 'Theme Test Drive Options', 'Theme Test Drive', 8, __FILE__, 'themedrive_options_page');
313
+ }
314
+
315
+
316
+ function themedrive_is_enabled()
317
+ {
318
+ return get_option('td_themes');
319
+ }
320
+
321
+ // Options Page
322
+ function themedrive_options_page()
323
+ {
324
+ global $themedrive_localversion;
325
+
326
+ $status=themedrive_getinfo();
327
+
328
+ $theVersion = $status[1];
329
+ $theMessage = $status[3];
330
+
331
+ if( (version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1) )
332
+ {
333
+ $msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
334
+ _e('<div id="message" class="updated fade"><p>' . $msg . '</p></div>');
335
+ }
336
+
337
+ if ($_POST['button']=='Enable') {
338
+
339
+ $themedrive = $_POST['td_themes'];
340
+ update_option('td_themes', $themedrive);
341
+ $msg_status = "Theme Test Drive Enabled for administrator with ".$themedrive.' theme.';
342
+
343
+
344
+
345
+ // Show message
346
+ _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
347
+
348
+ } else if ($_POST['button']=='Disable') {
349
+
350
+ // Delete the option from the DB if it's empty
351
+ delete_option('td_themes');
352
+
353
+ $msg_status = "Theme Test Drive has been disabled.";
354
+
355
+ // Show message
356
+ _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
357
+
358
+ }
359
+
360
+
361
+ _e('<style type="text/css"> div#dbx-content a{ text-decoration:none; }
362
+ </style> ');
363
+
364
+
365
+ global $wp_version;
366
+ if(version_compare($wp_version,"2.5",">=")) { _e(' <style type="text/css">
367
+ .wrap { max-width:1000px !important; } div#moremeta { float:right;
368
+ width:220px; margin-left:10px; } div#advancedstuff { width:770px; }
369
+ div#poststuff { margin-top:10px; } fieldset.dbx-box { margin-bottom:5px; }
370
+
371
+ </style>
372
+ <!--[if lt IE 7]>
373
+ <style type="text/css">
374
+ div#advancedstuff {
375
+ width:735px;
376
+ }
377
+ </style>
378
+ <![endif]-->
379
+
380
+ ');
381
+ }
382
+
383
+ // Configuration Page
384
+ _e('
385
+
386
+ <div class="wrap" id="options-div">
387
+ <form name="form_themedrive" method="post" action="' . $_SERVER['REQUEST_URI'] . '">
388
+ <h2>Theme Test Drive '.$themedrive_localversion.'</h2>
389
+ <div id="poststuff">
390
+ <div id="moremeta">
391
+ <div id="sidebarBlocks" class="dbx-group">
392
+ <fieldset id="about" class="dbx-box">
393
+ <h3 class="dbx-handle">Information</h3>
394
+ <div id="dbx-content">
395
+ <img src="'. trailingslashit(get_option('siteurl')). 'wp-content/plugins/theme-test-drive/home.png"><a href="http://www.prelovac.com/vladimir/wordpress-plugins/theme-test-drive"> Theme Test Drive Home</a><br /><br />
396
+ <img src="'. trailingslashit(get_option('siteurl')). 'wp-content/plugins/theme-test-drive/idea.png"><a href="http://www.prelovac.com/vladimir/wordpress-plugins/theme-test-drive#comments"> Suggest a Feature</a><br /><br />
397
+ <img src="'. trailingslashit(get_option('siteurl')). 'wp-content/plugins/theme-test-drive/more.png"><a href="http://www.prelovac.com/vladimir/wordpress-plugins"> My WordPress Plugins</a><br /><br />
398
+ <br />
399
+
400
+ <p align="center">
401
+ <img src="'. trailingslashit(get_option('siteurl')). 'wp-content/plugins/theme-test-drive/p1.png"></p>
402
+
403
+ <p> <img src="'. trailingslashit(get_option('siteurl')). 'wp-content/plugins/theme-test-drive/help.png"><a href="http://www.prelovac.com/vladimir/services"> Need a WordPress Expert?</a></p>
404
+ </div>
405
+ </div>
406
+ </div>
407
+
408
+ <div id="advancedstuff"> <!-- Used to locate blocks in the main area. -->
409
+
410
+ <div id="mainBlocks" class="dbx-group" >
411
+ <div class="dbx-b-ox-wrapper">
412
+ <fieldset id="block-description" class="dbx-box">');
413
+
414
+ if (isset($_POST['theme_install']))
415
+ {
416
+ echo '
417
+ <div class="dbx-h-andle-wrapper">
418
+ <h3 class="dbx-handle">Theme installation</h3>
419
+ </div>';
420
+
421
+ $install_theme=!isset($_POST['install_theme'])? '': $_POST['install_theme'];
422
+
423
+ if ($install_theme!='')
424
+ {
425
+ themedrive_handle_theme($install_theme);
426
+
427
+ }
428
+ else
429
+ echo "No theme URL specified.<br>";
430
+ echo '<br><br>';
431
+ }
432
+
433
+
434
+
435
+
436
+
437
+ _e('
438
+
439
+
440
+
441
+ <div class="dbx-h-andle-wrapper">
442
+ <h3 class="dbx-handle">Easy Theme Installation</h3>
443
+ </div>
444
+ Enter the URL to the theme zip file and click Install theme.<br><br>
445
+ <input style="border:1px solid #D1D1D1;width:400px;" name="install_theme" id="install_theme" value=""/>
446
+ <br>
447
+ <input class="button" type="submit" name="theme_install" value="Install theme &raquo;" />
448
+ <br><br><br>
449
+ <div class="dbx-h-andle-wrapper">
450
+ <h3 class="dbx-handle">Options</h3>
451
+ </div>
452
+ <div class="dbx-c-ontent-wrapper">
453
+ <div class="dbx-content">
454
+
455
+ <p>
456
+ Theme Test Drive allows you to safely test any theme as an administrator, while your visitors still see the default theme.
457
+ </p>
458
+ <p>
459
+ <strong>Usage:</strong> Select the theme you want to test drive below and press <em>Enable</em> button. Open your Blog home page. Additionally you may add "?theme=xxx" to your blog url, where xxx is the theme name you want to test.
460
+ </p>
461
+
462
+
463
+
464
+
465
+
466
+ <br />');
467
+
468
+ themedrive_switcher();
469
+
470
+
471
+ _e('
472
+
473
+
474
+ <p>
475
+ <strong>Disabling:</strong> If you wish to stop using Theme Test Drive, press <em>Disable</em> button.
476
+ Alternatively, disabling this plug-in should also do the trick.
477
+ </p>
478
+
479
+
480
+ <p class="submit">
481
+ <input type="submit" name="button" value="Enable" />
482
+ <input type="submit" name="button" value="Disable" />
483
+ </p>
484
+
485
+ </form>
486
+
487
+
488
+
489
+
490
+
491
+ </div>
492
+ </div>
493
+
494
+ </fieldset>
495
+
496
+ </div>
497
+ </div>
498
+ </div>
499
+ <h4>plugin by <a href="http://www.prelovac.com/vladimir/">Vladimir Prelovac</a></h4>
500
+ </div>
501
+
502
+
503
+ ');
504
+
505
+ }
506
+ // themedrive_options_page
507
+
508
+ // Add Options Page
509
+ add_action('admin_menu', 'themedrive_add_pages');
510
+
511
+
512
+ add_action( 'after_plugin_row', 'themedrive_check_plugin_version' );
513
+
514
+ function themedrive_getinfo()
515
+ {
516
+ $checkfile = "http://svn.wp-plugins.org/theme-test-drive/trunk/themedrive.chk";
517
+
518
+ $status=array();
519
+ return $status;
520
+ $vcheck = wp_remote_fopen($checkfile);
521
+
522
+ if($vcheck)
523
+ {
524
+ $version = $themedrive_localversion;
525
+
526
+ $status = explode('@', $vcheck);
527
+ return $status;
528
+ }
529
+ }
530
+
531
+ function themedrive_check_plugin_version($plugin)
532
+ {
533
+ global $plugindir,$themedrive_localversion;
534
+
535
+ if( strpos($plugin,'themedrive.php')!==false )
536
+ {
537
+
538
+
539
+ $status=themedrive_getinfo();
540
+
541
+ $theVersion = $status[1];
542
+ $theMessage = $status[3];
543
+
544
+ if( (version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1) )
545
+ {
546
+ $msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
547
+ echo '<td colspan="5" class="plugin-update" style="line-height:1.2em;">'.$msg.'</td>';
548
+ } else {
549
+ return;
550
+ }
551
+
552
+ }
553
+ }
554
+
555
+ function themdrive_js() {
556
+ echo '<script type="text/javascript">var bubbleImagePath="'.get_bloginfo('wpurl').'/wp-content/plugins/theme-test-drive/bg.png"</script>';
557
+ echo "\n";
558
+ echo '<script src="'.get_bloginfo('wpurl').'/wp-content/plugins/theme-test-drive/previewbubble.js" type="text/javascript"></script>';
559
+ echo "\n";
560
+ }
561
+ add_action("admin_head","themdrive_js");
562
+
563
+ // <p><img src="http://thumbnailspro.com/thumb.php?url='.trailingslashit(get_option('siteurl')).'?theme='.themedrive_get_theme().'&s=400" /><br /></p>
564
+ //<p><img src="http://images.websnapr.com/?size=s&key=42d1W6HhpB0B&url='.trailingslashit(get_option('siteurl')).'?theme='.themedrive_get_theme().'" /><br /></p>
565
+ ?>