Theme Test Drive - Version 2.7

Version Description

Download this release

Release Info

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

Code changes from version 2.6.3 to 2.7

Files changed (2) hide show
  1. readme.txt +6 -1
  2. themedrive.php +505 -558
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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.6
7
Stable tag: trunk
8
9
Safely test drive any theme as an administrator, while visitors use the default one.
@@ -19,6 +19,9 @@ Best part is you can even set the testing theme options (if it has them) in the
19
You can also preview any theme by adding "?theme=xxx" to your blog URL. For example http://www.myblog.com/?theme=Default
20
21
Changelog:
22
v2.6: Added user access level
23
24
v2.5.2: removed the thumbnail preview
@@ -31,6 +34,8 @@ v2.0:
31
- Instant theme preview using a live thumbnail preview
32
- Added ?theme=xxx to your URL's to preview the desired theme. Example http://www.myblog.com/?theme=Default
33
34
== Installation ==
35
36
1. Upload the whole plugin folder to your /wp-content/plugins/ folder.
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.7
7
Stable tag: trunk
8
9
Safely test drive any theme as an administrator, while visitors use the default one.
19
You can also preview any theme by adding "?theme=xxx" to your blog URL. For example http://www.myblog.com/?theme=Default
20
21
Changelog:
22
+
23
+ v2.7: WP 2.7 cleanup and security update
24
+
25
v2.6: Added user access level
26
27
v2.5.2: removed the thumbnail preview
34
- Instant theme preview using a live thumbnail preview
35
- Added ?theme=xxx to your URL's to preview the desired theme. Example http://www.myblog.com/?theme=Default
36
37
+ Plugin by Vladimir Prelovac. Need a <a href="http://www.prelovac.com/vladimir/services">WordPress Expert</a>?
38
+
39
== Installation ==
40
41
1. Upload the whole plugin folder to your /wp-content/plugins/ folder.
themedrive.php CHANGED
@@ -1,494 +1,444 @@
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.6.3
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.6.3";
19
-
20
- $wp_themedrive_plugin_url = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/'. dirname( plugin_basename(__FILE__) );
21
-
22
- function themedrive_handle_theme($package)
23
- {
24
- // select theme handling by commenting one of these funcitons
25
-
26
- themedrive_handle_theme_liberal($package);
27
-
28
- //themedrive_handle_theme_rigid($package);
29
- }
30
-
31
-
32
- function themedrive_unzip($file, $dir) {
33
- if( ! current_user_can('edit_files')) {
34
- echo 'Oops, sorry you are not authorized to do this';
35
- return false;
36
- }
37
- if(! class_exists('PclZip')) {
38
- require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
39
- }
40
-
41
-
42
- $unzipArchive = new PclZip($file);
43
- $list=$unzipArchive->properties();
44
- if (!$list['nb'])
45
- return false;
46
- //echo "Number of files in archive : ".$list['nb']."<br>";
47
-
48
- echo "Copying the files<br>";
49
- $result=$unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
50
- if($result == 0) {
51
- echo 'Could not unarchive the file: '.$unzipArchive->errorInfo(true).' <br />';
52
- return false;
53
- }
54
- else {
55
- //print_r($result);
56
- foreach ($result as $item)
57
- {
58
- if ($item['status']!='ok')
59
- echo $item['stored_filename'].' ... '.$item['status'].'<br>';
60
- }
61
- return true;
62
- }
63
- }
64
-
65
- function themedrive_handle_theme_liberal( $package) {
66
-
67
- echo "Downloading the theme from ".$package."<br>";
68
- $file = download_url($package);
69
-
70
- if ( is_wp_error($file) )
71
- {
72
- echo 'Download failed: '.$file->get_error_message();
73
- return;
74
- }
75
-
76
- echo "Unpacking the theme<br>";
77
-
78
- // Unzip theme to theme directory
79
- $result = themedrive_unzip($file, ABSPATH . "wp-content/themes/"); //theme dir
80
-
81
- // Once extracted, delete the package
82
- unlink($file);
83
-
84
- if ($result)
85
- echo "<br>Theme installed successfully.<br><br>";
86
- else {
87
- echo "<br>Error installing the theme.<br><br>You can try installing the theme manually: <a href=\"$package\">$package</a><br><br>";
88
- }
89
- return;
90
-
91
- }
92
-
93
-
94
-
95
- function themedrive_handle_theme_rigid( $package) {
96
- global $wp_filesystem;
97
-
98
- if ( ! $wp_filesystem || !is_object($wp_filesystem) )
99
- WP_Filesystem($credentials);
100
-
101
-
102
- if ( ! is_object($wp_filesystem) ) {
103
-
104
- echo '<strong><em>Could not access filesystem.</strong></em><br><br>';
105
- return;
106
- }
107
-
108
-
109
-
110
- if ( $wp_filesystem->errors->get_error_code() ){
111
-
112
- echo '<strong><em>Filesystem error '. $wp_filesystem->errors->get_error_message().'</strong></em><br><br>';
113
- return ;
114
- }
115
-
116
- //Get the Base folder
117
- $base = $wp_filesystem->get_base_dir();
118
-
119
- if ( empty($base) )
120
- {
121
- echo '<strong><em>Unable to locate WordPress directory.</strong></em><br><br>';
122
- return ;
123
- }
124
-
125
-
126
-
127
- echo "Downloading theme file from ".$package."<br>";
128
- $file = download_url($package);
129
-
130
- if ( is_wp_error($file) )
131
- {
132
- echo '<strong><em>Download failed : '.$file->get_error_message().'</strong></em><br><br>';
133
- return;
134
- }
135
-
136
-
137
- $working_dir = $base . 'wp-content/upgrade/themes';
138
-
139
- // Clean up working directory
140
- if ( $wp_filesystem->is_dir($working_dir) )
141
- $wp_filesystem->delete($working_dir, true);
142
-
143
-
144
- echo "Unpacking the theme<br>";
145
- // Unzip package to theme directory
146
- $result = unzip_file($file, $working_dir);
147
- if ( is_wp_error($result) ) {
148
- unlink($file);
149
- $wp_filesystem->delete($working_dir, true);
150
- echo '<strong><em>Unpack failed : '. $result->get_error_message() .'</strong></em><br><br>';
151
- return ;
152
- }
153
-
154
- echo "Installing the theme<br>";
155
- // Copy new version of plugin into place.
156
- if ( !copy_dir($working_dir,$base . "wp-content/themes") ) {
157
- $wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
158
- echo '<strong><em>Installation failed (theme already installed?)</strong></em><br><br>';
159
- return;
160
- }
161
-
162
- //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
163
- $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
164
-
165
- // Remove working directory
166
- $wp_filesystem->delete($working_dir, true);
167
-
168
- // Once extracted, delete the package
169
- unlink($file);
170
-
171
- echo "Theme installed successfully.<br><br>";
172
- return;
173
-
174
- }
175
-
176
- function themedrive_get_theme()
177
- {
178
- $gettheme=get_option('td_themes');
179
-
180
- if (!empty($gettheme)) {
181
- return $gettheme;
182
- } else {
183
- return '';
184
- }
185
- }
186
-
187
- function themedrive_get_level()
188
- {
189
- $getlevel=get_option('td_level');
190
-
191
- if (!empty($getlevel)) {
192
- return 'level_'.$getlevel;
193
- } else {
194
- return 'level_10';
195
- }
196
- }
197
-
198
- function themedrive_determine_theme()
199
- {
200
-
201
- if (!isset($_GET['theme'])) {
202
- if (! current_user_can(themedrive_get_level()) ) { // not admin
203
- return false;
204
- } else {
205
- $theme = themedrive_get_theme();
206
- if ($theme == '') {
207
- // no admin-only theme defined, short-circuit out
208
- return false;
209
- }
210
- }
211
- }
212
-
213
- $all=$_GET+$_POST;
214
- if (isset($all['theme'])) {
215
- $theme = $all['theme'];
216
- }
217
-
218
- $theme_data = get_theme($theme);
219
-
220
- if (! empty($theme_data) ) {
221
- // Don't let people peek at unpublished themes
222
- if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
223
- return false;
224
- }
225
- return $theme_data;
226
- }
227
-
228
- // perhaps they are using the theme directory instead of title
229
- $themes = get_themes();
230
-
231
- foreach($themes as $theme_data) {
232
- // use Stylesheet as it's unique to the theme - Template could point to another theme's templates
233
- if ($theme_data['Stylesheet'] == $theme) {
234
- // Don't let people peek at unpublished themes
235
- if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
236
- return false;
237
- }
238
- return $theme_data;
239
- }
240
- }
241
-
242
- return false;
243
-
244
- }
245
-
246
- function themedrive_get_template($template)
247
- {
248
- $theme = themedrive_determine_theme();
249
- if ($theme === false) {
250
- return $template;
251
- }
252
-
253
- return $theme['Template'];
254
- }
255
-
256
- function themedrive_get_stylesheet($stylesheet)
257
- {
258
- $theme = themedrive_determine_theme();
259
- if ($theme === false) {
260
- return $stylesheet;
261
- }
262
-
263
- return $theme['Stylesheet'];
264
- }
265
-
266
- function themedrive_switcher()
267
- {
268
- $themes = get_themes();
269
-
270
- $default_theme = get_current_theme();
271
-
272
- if (count($themes) > 1) {
273
- $theme_names = array_keys($themes);
274
- natcasesort($theme_names);
275
-
276
-
277
- $ts = '<br /> <select name="td_themes">'."\n" ;
278
- $tp = '<div id="theme_preview">
279
<div class="theme_links"><strong>Instant Theme Preview</strong><br/><br/>Hover over the link, reload the page if needed.<br/><ul>';
280
-
281
- foreach($theme_names as $theme_name) {
282
- // Skip unpublished themes.
283
- if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish') {
284
- continue;
285
- }
286
-
287
- if ((themedrive_get_theme() == $theme_name)
288
- || ((themedrive_get_theme()=='') && ($theme_name == $default_theme))) {
289
- $ts .= ' <option value="'.$theme_name.'" selected="selected">'
290
- . htmlspecialchars($theme_name)
291
- . '</option>'."\n"
292
- ;
293
- } else {
294
- $ts .= ' <option value="'.$theme_name.'">'
295
- . htmlspecialchars($theme_name)
296
- . '</option>'."\n"
297
- ;
298
- }
299
- $tp.='<li><a href="'.trailingslashit(get_option('siteurl')).'?theme='.htmlspecialchars($theme_name).'">'.$theme_name.'</a></li>';
300
-
301
- }
302
- $ts .= ' </select>'."\n\n";
303
- $tp.='</ul></div></div>';
304
- }
305
- // echo $tp;
306
-
307
- echo $ts;
308
if (themedrive_is_enabled()) {
309
- echo '<strong>Theme Test Drive is Enabled.</strong><br /><br /><br />';
310
- } else {
311
- echo 'Theme Test Drive is Disabled.<br /><br /><br />';
312
- }
313
-
314
-
315
-
316
-
317
- }
318
-
319
- add_filter('template', 'themedrive_get_template');
320
- add_filter('stylesheet', 'themedrive_get_stylesheet');
321
-
322
-
323
-
324
- // Admin Panel
325
- function themedrive_add_pages()
326
- {
327
- add_theme_page( 'Theme Test Drive Options', 'Theme Test Drive', 8, __FILE__, 'themedrive_options_page');
328
- }
329
-
330
-
331
- function themedrive_is_enabled()
332
- {
333
- return get_option('td_themes');
334
- }
335
-
336
- // Options Page
337
- function themedrive_options_page()
338
- {
339
- global $themedrive_localversion;
340
- global $wp_themedrive_plugin_url;
341
-
342
- $status=themedrive_getinfo();
343
-
344
- $theVersion = $status[1];
345
- $theMessage = $status[3];
346
-
347
- if( (version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1) )
348
- {
349
- $msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
350
- _e('<div id="message" class="updated fade"><p>' . $msg . '</p></div>');
351
- }
352
-
353
- if ($_POST['button']=='Enable') {
354
-
355
- $themedrive = $_POST['td_themes'];
356
- update_option('td_themes', $themedrive);
357
-
358
- $access_level = (int) $_POST['access_level'];
359
- update_option('td_level', $access_level);
360
- $msg_status = "Theme Test Drive Enabled for administrator with ".$themedrive.' theme.';
361
-
362
-
363
-
364
- // Show message
365
- _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
366
-
367
- } else if ($_POST['button']=='Disable') {
368
-
369
- // Delete the option from the DB if it's empty
370
- delete_option('td_themes');
371
-
372
- $msg_status = "Theme Test Drive has been disabled.";
373
-
374
- // Show message
375
- _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
376
-
377
- }
378
-
379
-
380
- _e('<style type="text/css"> div#dbx-content a{ text-decoration:none; }
381
- </style> ');
382
-
383
-
384
- global $wp_version;
385
- if(version_compare($wp_version,"2.5",">=")) { _e(' <style type="text/css">
386
- .wrap { max-width:1000px !important; } div#moremeta { float:right;
387
- width:220px; margin-left:10px; } div#advancedstuff { width:770px; }
388
- div#poststuff { margin-top:10px; } fieldset.dbx-box { margin-bottom:5px; }
389
-
390
- </style>
391
- <!--[if lt IE 7]>
392
- <style type="text/css">
393
- div#advancedstuff {
394
- width:735px;
395
- }
396
- </style>
397
- <![endif]-->
398
-
399
- ');
400
- }
401
-
402
- $access_level=get_option('td_level');
403
- if (empty($access_level))
404
- $access_level='10';
405
-
406
- $imgpath=$wp_themedrive_plugin_url.'/i';
407
-
408
- // Configuration Page
409
- _e('
410
-
411
- <div class="wrap" id="options-div">
412
- <form name="form_themedrive" method="post" action="' . $_SERVER['REQUEST_URI'] . '">
413
- <h2>Theme Test Drive '.$themedrive_localversion.'</h2>
414
- <div id="poststuff">
415
- <div id="moremeta">
416
- <div id="sidebarBlocks" class="dbx-group">
417
- <fieldset id="about" class="dbx-box">
418
- <h3 class="dbx-handle">Information</h3>
419
- <div id="dbx-content">
420
- <img src="'. $imgpath.'/home.png"><a href="http://www.prelovac.com/vladimir/wordpress-plugins/theme-test-drive"> Theme Test Drive Home</a><br /><br />
421
- <img src="'. $imgpath.'/help.png"><a href="http://www.prelovac.com/vladimir/forum"> Plugin Forums</a><br /><br />
422
- <img src="'. $imgpath.'/rate.png"><a href="http://wordpress.org/extend/plugins/theme-test-drive/"> Rate this plugin</a><br /><br />
423
- <img src="'. $imgpath.'/more.png"><a href="http://www.prelovac.com/vladimir/wordpress-plugins"> My WordPress Plugins</a><br /><br />
424
- <br />
425
-
426
- <p align="center">
427
- <img src="'. $imgpath.'/p1.png"></p>
428
-
429
- <p> <img src="'. $imgpath.'/idea.png"><a href="http://www.prelovac.com/vladimir/services"> Need a WordPress Expert?</a></p>
430
- </div>
431
- </div>
432
- </div>
433
-
434
- <div id="advancedstuff"> <!-- Used to locate blocks in the main area. -->
435
-
436
- <div id="mainBlocks" class="dbx-group" >
437
- <div class="dbx-b-ox-wrapper">
438
- <fieldset id="block-description" class="dbx-box">');
439
-
440
- if (isset($_POST['theme_install']))
441
- {
442
- echo '
443
- <div class="dbx-h-andle-wrapper">
444
- <h3 class="dbx-handle">Theme installation</h3>
445
- </div>';
446
-
447
- $install_theme=!isset($_POST['install_theme'])? '': $_POST['install_theme'];
448
-
449
- if ($install_theme!='')
450
- {
451
- themedrive_handle_theme($install_theme);
452
-
453
- }
454
- else
455
- echo "No theme URL specified.<br>";
456
- echo '<br><br>';
457
- }
458
459
460
461
462
-
463
- _e('
464
-
465
-
466
-
467
- <div class="dbx-h-andle-wrapper">
468
- <h3 class="dbx-handle">Easy Theme Installation</h3>
469
- </div>
470
- Enter the URL to the theme zip file and click Install theme.<br><br>
471
- <input style="border:1px solid #D1D1D1;width:400px;" name="install_theme" id="install_theme" value=""/>
472
- <br>
473
- <input class="button" type="submit" name="theme_install" value="Install theme &raquo;" />
474
- <br><br><br>
475
-
476
- <div class="dbx-h-andle-wrapper">
477
- <h3 class="dbx-handle">Usage</h3>
478
</div>
479
- <div class="dbx-c-ontent-wrapper">
480
- <div class="dbx-content">
481
- <p>Select a theme to preview live on the site. Only administrator will be able to see the selected theme. </p>
482
- <p>Additionally you may add "?theme=xxx" to your blog url, where xxx is the theme name you want to test.
483
- </p>
484
- ');
485
-
486
- themedrive_switcher();
487
488
-
489
- _e('
490
- <p>You can specify the level of users to have access to the selected theme preview. By default it is set to 10 (admin only). Level 7 are editors, level 4 are authors and level 1 are contributors. The access level is ignored for accessing the site with ?theme=xxx paramaeter. </p><br />
491
- <input style="border:1px solid #D1D1D1;width:100px;" name="access_level" id="access_level" value="'.$access_level.'" /> Access level<br /><br />
492
<p>
493
<strong>Disabling:</strong> If you wish to stop using Theme Test Drive, press <em>Disable</em> button.
494
Alternatively, disabling this plug-in should also do the trick.
@@ -496,90 +446,87 @@ Alternatively, disabling this plug-in should also do the trick.
496
497
498
<p class="submit">
499
- <input type="submit" name="button" value="Enable" />
500
- <input type="submit" name="button" value="Disable" />
501
</p>
502
503
</form>
504
505
-
506
-
507
-
508
-
509
- </div>
510
- </div>
511
-
512
- </fieldset>
513
-
514
</div>
515
</div>
516
</div>
517
- <h4>plugin by <a href="http://www.prelovac.com/vladimir/">Vladimir Prelovac</a></h4>
518
</div>
519
520
521
- ');
522
-
523
- }
524
- // themedrive_options_page
525
-
526
- // Add Options Page
527
- add_action('admin_menu', 'themedrive_add_pages');
528
-
529
-
530
- add_action( 'after_plugin_row', 'themedrive_check_plugin_version' );
531
-
532
- function themedrive_getinfo()
533
- {
534
- $checkfile = "http://svn.wp-plugins.org/theme-test-drive/trunk/themedrive.chk";
535
-
536
- $status=array();
537
- return $status;
538
- $vcheck = wp_remote_fopen($checkfile);
539
-
540
- if($vcheck)
541
- {
542
- $version = $themedrive_localversion;
543
-
544
- $status = explode('@', $vcheck);
545
- return $status;
546
- }
547
- }
548
-
549
- function themedrive_check_plugin_version($plugin)
550
- {
551
- global $plugindir,$themedrive_localversion;
552
-
553
- if( strpos($plugin,'themedrive.php')!==false )
554
- {
555
-
556
-
557
- $status=themedrive_getinfo();
558
-
559
- $theVersion = $status[1];
560
- $theMessage = $status[3];
561
-
562
- if( (version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1) )
563
- {
564
- $msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
565
- echo '<td colspan="5" class="plugin-update" style="line-height:1.2em;">'.$msg.'</td>';
566
- } else {
567
- return;
568
- }
569
-
570
- }
571
- }
572
-
573
- function themdrive_js() {
574
- echo '<script type="text/javascript">var bubbleImagePath="'.get_bloginfo('wpurl').'/wp-content/plugins/theme-test-drive/bg.png"</script>';
575
- echo "\n";
576
- echo '<script src="'.get_bloginfo('wpurl').'/wp-content/plugins/theme-test-drive/previewbubble.js" type="text/javascript"></script>';
577
- echo "\n";
578
- }
579
-
580
-
581
- //add_action("admin_head","themdrive_js");
582
-
583
- //$tp.= '<p><img src="http://thumbnailspro.com/thumb.php?url='.trailingslashit(get_option('siteurl')).'?theme='.htmlspecialchars($theme_name).'&s=400" /><br /></p>';
584
- //<p><img src="http://images.websnapr.com/?size=s&key=42d1W6HhpB0B&url='.trailingslashit(get_option('siteurl')).'?theme='.themedrive_get_theme().'" /><br /></p>
585
?>
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.7
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.7";
19
+
20
+ $wp_themedrive_plugin_url = trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__));
21
+
22
+ function themedrive_handle_theme($package)
23
+ {
24
+ // select theme handling by commenting one of these funcitons
25
+
26
+ themedrive_handle_theme_liberal($package);
27
+
28
+ //themedrive_handle_theme_rigid($package);
29
+ }
30
+
31
+
32
+ function themedrive_unzip($file, $dir)
33
+ {
34
+ if (!current_user_can('edit_files')) {
35
+ echo 'Oops, sorry you are not authorized to do this';
36
+ return false;
37
+ }
38
+ if (!class_exists('PclZip')) {
39
+ require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
40
+ }
41
+
42
+
43
+ $unzipArchive = new PclZip($file);
44
+ $list = $unzipArchive->properties();
45
+ if (!$list['nb'])
46
+ return false;
47
+ //echo "Number of files in archive : ".$list['nb']."<br>";
48
+
49
+ echo "Copying the files<br>";
50
+ $result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
51
+ if ($result == 0) {
52
+ echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . ' <br />';
53
+ return false;
54
+ } else {
55
+ //print_r($result);
56
+ foreach ($result as $item) {
57
+ if ($item['status'] != 'ok')
58
+ echo $item['stored_filename'] . ' ... ' . $item['status'] . '<br>';
59
+ }
60
+ return true;
61
+ }
62
+ }
63
+
64
+ function themedrive_handle_theme_liberal($package)
65
+ {
66
+ echo "Downloading the theme from " . $package . "<br>";
67
+ $file = download_url($package);
68
+
69
+ if (is_wp_error($file)) {
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
+ //theme dir
78
+ $result = themedrive_unzip($file, ABSPATH . "wp-content/themes/");
79
+
80
+ // Once extracted, delete the package
81
+ unlink($file);
82
+
83
+ if ($result)
84
+ echo "<br>Theme installed successfully.<br><br>";
85
+ else {
86
+ echo "<br>Error installing the theme.<br><br>You can try installing the theme manually: <a href=\"$package\">$package</a><br><br>";
87
+ }
88
+ return;
89
+ }
90
+
91
+
92
+
93
+ function themedrive_handle_theme_rigid($package)
94
+ {
95
+ global $wp_filesystem;
96
+
97
+ if (!$wp_filesystem || !is_object($wp_filesystem))
98
+ WP_Filesystem($credentials);
99
+
100
+
101
+ if (!is_object($wp_filesystem)) {
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
+ echo '<strong><em>Filesystem error ' . $wp_filesystem->errors->get_error_message() . '</strong></em><br><br>';
110
+ return;
111
+ }
112
+
113
+ //Get the Base folder
114
+ $base = $wp_filesystem->get_base_dir();
115
+
116
+ if (empty($base)) {
117
+ echo '<strong><em>Unable to locate WordPress directory.</strong></em><br><br>';
118
+ return;
119
+ }
120
+
121
+
122
+
123
+ echo "Downloading theme file from " . $package . "<br>";
124
+ $file = download_url($package);
125
+
126
+ if (is_wp_error($file)) {
127
+ echo '<strong><em>Download failed : ' . $file->get_error_message() . '</strong></em><br><br>';
128
+ return;
129
+ }
130
+
131
+
132
+ $working_dir = $base . 'wp-content/upgrade/themes';
133
+
134
+ // Clean up working directory
135
+ if ($wp_filesystem->is_dir($working_dir))
136
+ $wp_filesystem->delete($working_dir, true);
137
+
138
+
139
+ echo "Unpacking the theme<br>";
140
+ // Unzip package to theme directory
141
+ $result = unzip_file($file, $working_dir);
142
+ if (is_wp_error($result)) {
143
+ unlink($file);
144
+ $wp_filesystem->delete($working_dir, true);
145
+ echo '<strong><em>Unpack failed : ' . $result->get_error_message() . '</strong></em><br><br>';
146
+ return;
147
+ }
148
+
149
+ echo "Installing the theme<br>";
150
+ // Copy new version of plugin into place.
151
+ if (!copy_dir($working_dir, $base . "wp-content/themes")) {
152
+ //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
153
+ $wp_filesystem->delete($working_dir, true);
154
+ echo '<strong><em>Installation failed (theme already installed?)</strong></em><br><br>';
155
+ return;
156
+ }
157
+
158
+ //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
159
+ $filelist = array_keys($wp_filesystem->dirlist($working_dir));
160
+
161
+ // Remove working directory
162
+ $wp_filesystem->delete($working_dir, true);
163
+
164
+ // Once extracted, delete the package
165
+ unlink($file);
166
+
167
+ echo "Theme installed successfully.<br><br>";
168
+ return;
169
+ }
170
+
171
+ function themedrive_get_theme()
172
+ {
173
+ $gettheme = get_option('td_themes');
174
+
175
+ if (!empty($gettheme)) {
176
+ return $gettheme;
177
+ } else {
178
+ return '';
179
+ }
180
+ }
181
+
182
+ function themedrive_get_level()
183
+ {
184
+ $getlevel = get_option('td_level');
185
+
186
+ if (!empty($getlevel)) {
187
+ return 'level_' . $getlevel;
188
+ } else {
189
+ return 'level_10';
190
+ }
191
+ }
192
+
193
+ function themedrive_determine_theme()
194
+ {
195
+ if (!isset($_GET['theme'])) {
196
+ if (!current_user_can(themedrive_get_level())) {
197
+ // not admin
198
+ return false;
199
+ } else {
200
+ $theme = themedrive_get_theme();
201
+ if ($theme == '') {
202
+ // no admin-only theme defined, short-circuit out
203
+ return false;
204
+ }
205
+ }
206
+ }
207
+
208
+ $all = $_GET + $_POST;
209
+ if (isset($all['theme'])) {
210
+ $theme = $all['theme'];
211
+ }
212
+
213
+ $theme_data = get_theme($theme);
214
+
215
+ if (!empty($theme_data)) {
216
+ // Don't let people peek at unpublished themes
217
+ if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
218
+ return false;
219
+ }
220
+ return $theme_data;
221
+ }
222
+
223
+ // perhaps they are using the theme directory instead of title
224
+ $themes = get_themes();
225
+
226
+ foreach ($themes as $theme_data) {
227
+ // use Stylesheet as it's unique to the theme - Template could point to another theme's templates
228
+ if ($theme_data['Stylesheet'] == $theme) {
229
+ // Don't let people peek at unpublished themes
230
+ if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
231
+ return false;
232
+ }
233
+ return $theme_data;
234
+ }
235
+ }
236
+
237
+ return false;
238
+ }
239
+
240
+ function themedrive_get_template($template)
241
+ {
242
+ $theme = themedrive_determine_theme();
243
+ if ($theme === false) {
244
+ return $template;
245
+ }
246
+
247
+ return $theme['Template'];
248
+ }
249
+
250
+ function themedrive_get_stylesheet($stylesheet)
251
+ {
252
+ $theme = themedrive_determine_theme();
253
+ if ($theme === false) {
254
+ return $stylesheet;
255
+ }
256
+
257
+ return $theme['Stylesheet'];
258
+ }
259
+
260
+ function themedrive_switcher()
261
+ {
262
+ $themes = get_themes();
263
+
264
+ $default_theme = get_current_theme();
265
+
266
+ if (count($themes) > 1) {
267
+ $theme_names = array_keys($themes);
268
+ natcasesort($theme_names);
269
+
270
+
271
+ $ts = '<select name="td_themes">' . "\n";
272
+ $tp = '<div id="theme_preview">
273
<div class="theme_links"><strong>Instant Theme Preview</strong><br/><br/>Hover over the link, reload the page if needed.<br/><ul>';
274
+
275
+ foreach ($theme_names as $theme_name) {
276
+ // Skip unpublished themes.
277
+ if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish') {
278
+ continue;
279
+ }
280
+
281
+ if ((themedrive_get_theme() == $theme_name) || ((themedrive_get_theme() == '') && ($theme_name == $default_theme))) {
282
+ $ts .= ' <option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>' . "\n";
283
+ } else {
284
+ $ts .= ' <option value="' . $theme_name . '">' . htmlspecialchars($theme_name) . '</option>' . "\n";
285
+ }
286
+ $tp .= '<li><a href="' . trailingslashit(get_option('siteurl')) . '?theme=' . htmlspecialchars($theme_name) . '">' . $theme_name . '</a></li>';
287
+ }
288
+ $ts .= ' </select>' . "\n\n";
289
+ $tp .= '</ul></div></div>';
290
+ }
291
+ // echo $tp;
292
+
293
+ echo $ts;
294
if (themedrive_is_enabled()) {
295
+ echo '<strong>Theme Test Drive is Enabled.</strong><br />';
296
+ } else {
297
+ echo 'Theme Test Drive is Disabled.<br />';
298
+ }
299
+ }
300
+
301
+ add_filter('template', 'themedrive_get_template');
302
+ add_filter('stylesheet', 'themedrive_get_stylesheet');
303
+
304
+
305
+
306
+ // Admin Panel
307
+ function themedrive_add_pages()
308
+ {
309
+ add_theme_page('Theme Test Drive Options', 'Theme Test Drive', 8, __FILE__, 'themedrive_options_page');
310
+ }
311
+
312
+
313
+ function themedrive_is_enabled()
314
+ {
315
+ return get_option('td_themes');
316
+ }
317
+
318
+ // Options Page
319
+ function themedrive_options_page()
320
+ {
321
+ global $themedrive_localversion;
322
+ global $wp_themedrive_plugin_url;
323
+
324
+ $status = themedrive_getinfo();
325
+
326
+ $theVersion = $status[1];
327
+ $theMessage = $status[3];
328
+
329
+
330
+
331
+ if ((version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1)) {
332
+ $msg = 'Latest version available ' . ' <strong>' . $theVersion . '</strong><br />' . $theMessage;
333
+ _e('<div id="message" class="updated fade"><p>' . $msg . '</p></div>');
334
+ }
335
+
336
+ if ($_POST['button'] == 'Enable') {
337
+ check_admin_referer('theme-drive');
338
+ $themedrive = $_POST['td_themes'];
339
+ update_option('td_themes', $themedrive);
340
+
341
+ $access_level = (int)$_POST['access_level'];
342
+ update_option('td_level', $access_level);
343
+ $msg_status = "Theme Test Drive Enabled for administrator with " . $themedrive . ' theme.';
344
+
345
+
346
+
347
+ // Show message
348
+ _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
349
+ } elseif ($_POST['button'] == 'Disable') {
350
+ check_admin_referer('theme-drive');
351
+ // Delete the option from the DB if it's empty
352
+ delete_option('td_themes');
353
+
354
+ $msg_status = "Theme Test Drive has been disabled.";
355
+
356
+ // Show message
357
+ _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
358
+ }
359
+
360
361
362
363
+ $access_level = get_option('td_level');
364
+ if (empty($access_level))
365
+ $access_level = '10';
366
+
367
+ $imgpath = $wp_themedrive_plugin_url . '/i';
368
+ ?>
369
+ <div class="wrap" style="max-width:950px !important;">
370
+ <h2>Plugin Central</h2>
371
+
372
+ <div id="poststuff" style="margin-top:10px;">
373
+
374
+ <div id="sideblock" style="float:right;width:220px;margin-left:10px;">
375
+ <h3>Information</h3>
376
+ <div id="dbx-content" style="text-decoration:none;">
377
+ <img src="<?php
378
+ echo $imgpath
379
+ ?>/home.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins/plugin-central"> Plugin Central Home</a><br /><br />
380
+ <img src="<?php
381
+ echo $imgpath
382
+ ?>/help.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/forum"> Plugin Forums</a><br /><br />
383
+ <img src="<?php
384
+ echo $imgpath
385
+ ?>/rate.png"><a style="text-decoration:none;" href="http://wordpress.org/extend/plugins/plugin-central/"> Rate Pluign Central</a><br /><br />
386
+ <img src="<?php
387
+ echo $imgpath
388
+ ?>/more.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins"> My WordPress Plugins</a><br /><br />
389
+ <br />
390
391
+ <p align="center">
392
+ <img src="<?php
393
+ echo $imgpath
394
+ ?>/p1.png"></p>
395
+
396
+ <p> <img src="<?php
397
+ echo $imgpath
398
+ ?>/idea.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/services"> Need a WordPress Expert?</a></p>
399
+ </div>
400
</div>
401
402
+ <div id="mainblock" style="width:710px">
403
+
404
+ <div class="dbx-content">
405
+ <form name="form_apu" method="post" action="<?php
406
+ echo $action_url
407
+ ?>">
408
+ <?php
409
+ wp_nonce_field('theme-drive');
410
+
411
+ if (isset($_POST['theme_install'])) {
412
+ echo '<h3>Theme installation</h3>';
413
+
414
+ $install_theme = !isset($_POST['install_theme']) ? '' : $_POST['install_theme'];
415
+
416
+ if ($install_theme != '') {
417
+ themedrive_handle_theme($install_theme);
418
+ } else
419
+ echo "No theme URL specified.<br>";
420
+ echo '<br><br>';
421
+ }
422
+ ?>
423
+
424
+
425
+ <h3>Easy Theme Installation</h3>
426
+
427
+ Enter the URL to the theme zip file and click Install theme.<br><br>
428
+ <input style="border:1px solid #D1D1D1;width:400px;" name="install_theme" id="install_theme" value="" />
429
+ <br>
430
+ <input class="button" type="submit" name="theme_install" value="Install theme &raquo;" class="button-primary" />
431
+
432
+ <h3 class="dbx-handle">Usage</h3>
433
+ <p>Select a theme to preview live on the site. Only administrator will be able to see the selected theme. </p>
434
+ <p>Additionally you may add "?theme=xxx" to your blog url, where xxx is the theme name you want to test.</p>
435
+ <?php
436
+ themedrive_switcher();
437
+ ?>
438
+ <p>You can specify the level of users to have access to the selected theme preview. By default it is set to 10 (admin only). Level 7 are editors, level 4 are authors and level 1 are contributors. The access level is ignored for accessing the site with ?theme=xxx paramaeter. </p>
439
+ <input style="border:1px solid #D1D1D1;width:100px;" name="access_level" id="access_level" value="<?php
440
+ echo $access_level
441
+ ?>" /> Access level<br />
442
<p>
443
<strong>Disabling:</strong> If you wish to stop using Theme Test Drive, press <em>Disable</em> button.
444
Alternatively, disabling this plug-in should also do the trick.
446
447
448
<p class="submit">
449
+ <?php
450
+ if (themedrive_get_theme())
451
+ :
452
+ ?>
453
+ <input type="submit" name="button" value="Disable Theme Drive" class="button-primary" />
454
+ <?php
455
+ else
456
+ :
457
+ ?>
458
+ <input type="submit" name="button" value="Enable Theme Drive" class="button-primary" />
459
+ <?php
460
+ endif;
461
+ ?>
462
+
463
</p>
464
465
</form>
466
467
</div>
468
</div>
469
</div>
470
+ <h4>a plugin by <a href="http://www.prelovac.com/vladimir/">Vladimir Prelovac</a></h4>
471
</div>
472
473
474
+ <?php
475
+ }
476
+ // themedrive_options_page
477
+
478
+ // Add Options Page
479
+ add_action('admin_menu', 'themedrive_add_pages');
480
+
481
+
482
+ add_action('after_plugin_row', 'themedrive_check_plugin_version');
483
+
484
+ function themedrive_getinfo()
485
+ {
486
+ $checkfile = "http://svn.wp-plugins.org/theme-test-drive/trunk/themedrive.chk";
487
+
488
+ $status = array();
489
+ return $status;
490
+ $vcheck = wp_remote_fopen($checkfile);
491
+
492
+ if ($vcheck) {
493
+ $version = $themedrive_localversion;
494
+
495
+ $status = explode('@', $vcheck);
496
+ return $status;
497
+ }
498
+ }
499
+
500
+ function themedrive_check_plugin_version($plugin)
501
+ {
502
+ global $plugindir, $themedrive_localversion;
503
+
504
+ if (strpos($plugin, 'themedrive.php') !== false) {
505
+ $status = themedrive_getinfo();
506
+
507
+ $theVersion = $status[1];
508
+ $theMessage = $status[3];
509
+
510
+ if ((version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1)) {
511
+ $msg = 'Latest version available ' . ' <strong>' . $theVersion . '</strong><br />' . $theMessage;
512
+ echo '<td colspan="5" class="plugin-update" style="line-height:1.2em;">' . $msg . '</td>';
513
+ } else {
514
+ return;
515
+ }
516
+ }
517
+ }
518
+
519
+ function themdrive_js()
520
+ {
521
+ echo '<script type="text/javascript">var bubbleImagePath="' . get_bloginfo('wpurl') . '/wp-content/plugins/theme-test-drive/bg.png"</script>';
522
+ echo "\n";
523
+ echo '<script src="' . get_bloginfo('wpurl') . '/wp-content/plugins/theme-test-drive/previewbubble.js" type="text/javascript"></script>';
524
+ echo "\n";
525
+ }
526
+
527
+
528
+ //add_action("admin_head","themdrive_js");
529
+
530
+ //$tp.= '<p><img src="http://thumbnailspro.com/thumb.php?url='.trailingslashit(get_option('siteurl')).'?theme='.htmlspecialchars($theme_name).'&s=400" /><br /></p>';
531
+ //<p><img src="http://images.websnapr.com/?size=s&key=42d1W6HhpB0B&url='.trailingslashit(get_option('siteurl')).'?theme='.themedrive_get_theme().'" /><br /></p>
532
?>