PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 0.6.8
Vimeography: Vimeo Video Gallery WordPress Plugin v0.6.8
2.4.9 2.4.8 trunk 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.6 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.6.8.1 0.6.9 0.6.9.1 0.6.9.2 0.7 0.8 All 103 releases
vimeography / vimeography.php

vimeography.php in Vimeography: Vimeo Video Gallery WordPress Plugin 0.6.8, at vimeography.php

654 lines 23.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Vimeography
4 Plugin URI: http://vimeography.com
5 Description: Vimeography is the easiest way to set up a custom Vimeo gallery on your site.
6 Version: 0.6.8
7 Author: Dave Kiss
8 Author URI: http://davekiss.com
9 License: MIT
10 */
11
12 if (!function_exists('json_decode'))
13 wp_die('Vimeography needs the JSON PHP extension.');
14
15 global $wpdb;
16 $wp_upload_dir = wp_upload_dir();
17
18 // Define constants
19 define( 'VIMEOGRAPHY_URL', plugin_dir_url(__FILE__) );
20 define( 'VIMEOGRAPHY_PATH', plugin_dir_path(__FILE__) );
21 define( 'VIMEOGRAPHY_THEME_URL', $wp_upload_dir['baseurl'].'/vimeography-themes/' );
22 define( 'VIMEOGRAPHY_THEME_PATH', $wp_upload_dir['basedir'].'/vimeography-themes/' );
23 define( 'VIMEOGRAPHY_ASSETS_URL', $wp_upload_dir['baseurl'].'/vimeography-assets/' );
24 define( 'VIMEOGRAPHY_ASSETS_PATH', $wp_upload_dir['basedir'].'/vimeography-assets/' );
25 define( 'VIMEOGRAPHY_BASENAME', plugin_basename( __FILE__ ) );
26 define( 'VIMEOGRAPHY_VERSION', '0.6.8');
27 define( 'VIMEOGRAPHY_GALLERY_TABLE', $wpdb->prefix . "vimeography_gallery");
28 define( 'VIMEOGRAPHY_GALLERY_META_TABLE', $wpdb->prefix . "vimeography_gallery_meta");
29 define( 'VIMEOGRAPHY_CURRENT_PAGE', basename($_SERVER['PHP_SELF']));
30
31 require_once(VIMEOGRAPHY_PATH . '/vendor/mustache/Mustache.php');
32
33 class Vimeography
34 {
35 public function __construct()
36 {
37 add_action( 'init', array(&$this, 'vimeography_init') );
38 add_action( 'admin_init', array(&$this, 'vimeography_requires_wordpress_version') );
39 add_action( 'admin_init', array(&$this, 'vimeography_check_if_db_exists') );
40 add_action( 'init', array(&$this, 'vimeography_move_folders') );
41 add_action( 'plugins_loaded', array(&$this, 'vimeography_update_db_to_0_6') );
42 add_action( 'plugins_loaded', array(&$this, 'vimeography_update_db_to_0_7') );
43 add_action( 'plugins_loaded', array(&$this, 'vimeography_update_db_version') );
44 add_action( 'admin_menu', array(&$this, 'vimeography_add_menu') );
45 add_action( 'do_robots', array(&$this, 'vimeography_block_robots') );
46
47 register_activation_hook( VIMEOGRAPHY_BASENAME, array(&$this, 'vimeography_update_tables') );
48
49 add_filter( 'plugin_action_links', array(&$this, 'vimeography_filter_plugin_actions'), 10, 2 );
50 add_shortcode( 'vimeography', array(&$this, 'vimeography_shortcode') );
51
52 // Add shortcode support for widgets
53 add_filter( 'widget_text', 'do_shortcode' );
54 }
55
56 /**
57 * Runs on every page load.
58 *
59 * @access public
60 * @return void
61 */
62 public function vimeography_init()
63 {
64 if(in_array(VIMEOGRAPHY_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))){
65 add_action('admin_footer', array(&$this, 'vimeography_add_mce_popup'));
66 }
67
68 if ( get_user_option('rich_editing') == 'true' ) {
69 add_filter( 'mce_external_plugins', array(&$this, 'vimeography_add_editor_plugin' ));
70 add_filter( 'mce_buttons', array(&$this, 'vimeography_register_editor_button') );
71 }
72
73 // Let's check if the user has a custom robots.txt file.
74 if (file_exists(ABSPATH.'/robots.txt'))
75 {
76 // See if our rule already exists inside of it.
77 $robotstxt = file_get_contents(ABSPATH.'/robots.txt');
78 if (strpos($robotstxt, 'Disallow: '.VIMEOGRAPHY_THEME_PATH) === FALSE)
79 {
80 // Write our rule.
81 $robotstxt .= "\nDisallow: ".VIMEOGRAPHY_THEME_PATH."\n";
82 file_put_contents(ABSPATH.'/robots.txt', $robotstxt);
83 }
84 }
85
86 }
87
88 public function vimeography_register_editor_button($buttons)
89 {
90 array_push( $buttons, "|", "vimeography" );
91 return $buttons;
92 }
93
94 public function vimeography_add_editor_plugin( $plugin_array ) {
95 $plugin_array['vimeography'] = VIMEOGRAPHY_URL . 'media/js/mce.js';
96 return $plugin_array;
97 }
98
99 /**
100 * Check the wordpress version is compatible, and disable plugin if not.
101 *
102 * @access public
103 * @return void
104 */
105 public function vimeography_requires_wordpress_version() {
106 global $wp_version;
107 $plugin = plugin_basename( __FILE__ );
108 $plugin_data = get_plugin_data( __FILE__, false );
109
110 if ( version_compare($wp_version, "3.3", "<" ) ) {
111 if( is_plugin_active($plugin) ) {
112 deactivate_plugins( $plugin );
113 wp_die( "'".$plugin_data['Name']."' requires WordPress 3.3 or higher, and has been deactivated! Please upgrade WordPress and try again.<br /><br />Back to <a href='".admin_url()."'>WordPress admin</a>." );
114 }
115 }
116 }
117
118 public function vimeography_check_if_db_exists()
119 {
120 if (get_option('vimeography_db_version') == FALSE)
121 $this->vimeography_update_db_version();
122 }
123
124 /**
125 * Move the defined folders to the defined target path in wp-content/uploads.
126 *
127 * @access public
128 * @return void
129 */
130 public function vimeography_move_folders()
131 {
132 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'bugsauce/', 'destination' => VIMEOGRAPHY_THEME_PATH.'bugsauce/', 'clear_destination' => true, 'clear_working' => true));
133 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'theme-assets/', 'destination' => VIMEOGRAPHY_ASSETS_PATH, 'clear_destination' => true, 'clear_working' => true));
134
135 // Now, check if the .htaccess exists in the VIMEOGRAPHY_THEME_PATH
136 if (! file_exists(VIMEOGRAPHY_THEME_PATH.'.htaccess'))
137 file_put_contents(VIMEOGRAPHY_THEME_PATH.'.htaccess', "Options All -Indexes\n<FilesMatch \".(htaccess|mustache)$\">\nOrder Allow,Deny\nDeny from all\n</FilesMatch>");
138 }
139
140 /**
141 * Check if the Vimeography database structure needs updated to version 0.6 based on the stored db version.
142 *
143 * @access public
144 * @return void
145 */
146 public function vimeography_update_db_to_0_6()
147 {
148 if (get_option('vimeography_db_version') < 0.6)
149 {
150 global $wpdb;
151 $old_galleries = $wpdb->get_results('SELECT * FROM '.VIMEOGRAPHY_GALLERY_META_TABLE.' AS meta JOIN '.VIMEOGRAPHY_GALLERY_TABLE.' AS gallery ON meta.gallery_id = gallery.id;');
152 $new_galleries = array();
153
154 if (is_array($old_galleries))
155 {
156 foreach ($old_galleries as $old_gallery)
157 {
158 $new_gallery = array();
159
160 $new_gallery['gallery_id'] = $old_gallery->gallery_id;
161 $new_gallery['video_limit'] = $old_gallery->video_count;
162 $new_gallery['featured_video'] = $old_gallery->featured_video;
163 $new_gallery['cache_timeout'] = $old_gallery->cache_timeout;
164 $new_gallery['theme_name'] = $old_gallery->theme_name;
165 switch ($old_gallery->source_type)
166 {
167 case 'user':
168 $new_gallery['source_url'] = 'https://vimeo.com/'.$old_gallery->source_name;
169 break;
170 case 'album':
171 $new_gallery['source_url'] = 'https://vimeo.com/album/'.$old_gallery->source_name;
172 break;
173 case 'group':
174 $new_gallery['source_url'] = 'https://vimeo.com/groups/'.$old_gallery->source_name;
175 break;
176 case 'channel':
177 $new_gallery['source_url'] = 'https://vimeo.com/channels/'.$old_gallery->source_name;
178 break;
179 }
180 $new_galleries[] = $new_gallery;
181 }
182 }
183 $wpdb->query('DROP TABLE '.VIMEOGRAPHY_GALLERY_META_TABLE.';');
184
185 $this->vimeography_update_tables();
186
187 foreach ($new_galleries as $new_gallery)
188 {
189 $wpdb->insert(
190 VIMEOGRAPHY_GALLERY_META_TABLE,
191 $new_gallery
192 );
193 }
194 }
195 }
196
197 /**
198 * Check if the Vimeography database structure needs updated to version 0.7 based on the stored db version.
199 *
200 * @access public
201 * @return void
202 */
203 public function vimeography_update_db_to_0_7()
204 {
205 if (get_option('vimeography_db_version') < 0.7)
206 {
207
208 }
209 }
210
211 /**
212 * Updates the Vimeography version stored in the database.
213 *
214 * @access public
215 * @return void
216 */
217 public function vimeography_update_db_version()
218 {
219 update_option('vimeography_db_version', VIMEOGRAPHY_VERSION);
220 }
221
222 /**
223 * Add Settings link to "installed plugins" admin page.
224 *
225 * @access public
226 * @param mixed $links
227 * @param mixed $file
228 * @return void
229 */
230 public function vimeography_filter_plugin_actions($links, $file)
231 {
232 if ( $file == VIMEOGRAPHY_BASENAME )
233 {
234 $settings_link = '<a href="admin.php?page=vimeography-edit-galleries">' . __('Settings') . '</a>';
235 if (!in_array($settings_link, $links))
236 array_unshift( $links, $settings_link ); // before other links
237 }
238 return $links;
239 }
240
241 /**
242 * Action target that displays the popup to insert a form to a post/page.
243 *
244 * @access public
245 * @return void
246 */
247 public function vimeography_add_mce_popup(){
248 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/mce.php');
249 $mustache = new Vimeography_MCE();
250 $template = $this->_load_template('vimeography/mce');
251 echo $mustache->render($template);
252 }
253
254 /**
255 * Adds a new top level menu to the admin menu.
256 *
257 * @access public
258 * @return void
259 */
260 public function vimeography_add_menu()
261 {
262
263 global $submenu;
264
265 add_menu_page( 'Vimeography Page Title', 'Vimeography', 'manage_options', 'vimeography-edit-galleries', '', VIMEOGRAPHY_URL.'media/img/vimeography-icon.png' );
266 add_submenu_page( 'vimeography-edit-galleries', 'Edit Galleries', 'Edit Galleries', 'manage_options', 'vimeography-edit-galleries', array(&$this, 'vimeography_render_template' ));
267 add_submenu_page( 'vimeography-edit-galleries', 'New Gallery', 'New Gallery', 'manage_options', 'vimeography-new-gallery', array(&$this, 'vimeography_render_template' ));
268 add_submenu_page( 'vimeography-edit-galleries', 'My Themes', 'My Themes', 'manage_options', 'vimeography-my-themes', array(&$this, 'vimeography_render_template' ));
269 $submenu['vimeography-edit-galleries'][500] = array( 'Buy Themes', 'manage_options' , 'http://vimeography.com/themes' );
270 add_submenu_page( 'vimeography-edit-galleries', 'Vimeography Pro', 'Vimeography Pro', 'manage_options', 'vimeography-pro', array(&$this, 'vimeography_render_template' ));
271 add_submenu_page( 'vimeography-edit-galleries', 'Help', 'Help', 'manage_options', 'vimeography-help', array(&$this, 'vimeography_render_template' ));
272
273 }
274
275 public function vimeography_render_template()
276 {
277 if ( !current_user_can( 'manage_options' ) ) {
278 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
279 }
280
281 wp_register_style( 'bootstrap_css', VIMEOGRAPHY_URL.'media/css/bootstrap.min.css');
282 wp_register_style( 'bootstrap_responsive_css', VIMEOGRAPHY_URL.'media/css/bootstrap-responsive.min.css');
283 wp_register_style( 'vimeography-admin.css', VIMEOGRAPHY_URL.'media/css/admin.css');
284 wp_register_script( 'bootstrap_tab_js', VIMEOGRAPHY_URL.'media/js/bootstrap-tab.js');
285 wp_register_script( 'bootstrap_alert_js', VIMEOGRAPHY_URL.'media/js/bootstrap-alert.js');
286 wp_register_script( 'vimeography-admin.js', VIMEOGRAPHY_URL.'media/js/admin.js', 'jquery');
287
288 wp_enqueue_style( 'bootstrap_css');
289 wp_enqueue_style( 'bootstrap_responsive_css');
290 wp_enqueue_style( 'vimeography-admin.css');
291 wp_enqueue_script( 'jquery');
292 wp_enqueue_script( 'bootstrap_tab_js');
293 wp_enqueue_script( 'bootstrap_alert_js');
294 wp_enqueue_script( 'vimeography-admin.js');
295
296 switch(current_filter())
297 {
298 case 'vimeography_page_vimeography-new-gallery':
299 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/new.php');
300 $mustache = new Vimeography_Gallery_New();
301 $template = $this->_load_template('gallery/new');
302 break;
303 case 'toplevel_page_vimeography-edit-galleries':
304 if (isset($_GET['id']))
305 {
306 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/edit.php');
307 $mustache = new Vimeography_Gallery_Edit();
308 $template = $this->_load_template('gallery/edit');
309 }
310 else
311 {
312 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/list.php');
313 $mustache = new Vimeography_Gallery_List();
314 $template = $this->_load_template('gallery/list');
315 }
316 break;
317 case 'vimeography_page_vimeography-my-themes':
318 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/theme/list.php');
319 $mustache = new Vimeography_Theme_List();
320 $template = $this->_load_template('theme/list');
321 break;
322 case 'vimeography_page_vimeography-pro':
323 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/pro.php');
324 $mustache = new Vimeography_Pro();
325 $template = $this->_load_template('vimeography/pro');
326 break;
327 case 'vimeography_page_vimeography-help':
328 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/help.php');
329 $mustache = new Vimeography_Help();
330 $template = $this->_load_template('vimeography/help');
331 break;
332 default:
333 wp_die( __('The admin template for "'.current_filter().'" cannot be found.') );
334 break;
335 }
336 echo $mustache->render($template);
337 }
338
339 protected function _load_template($name)
340 {
341 $path = VIMEOGRAPHY_PATH . 'lib/admin/templates/' . $name .'.mustache';
342 if (! $result = @file_get_contents($path))
343 wp_die('The admin template "'.$name.'" cannot be found.');
344 return $result;
345 }
346
347 /**
348 * Create tables and define defaults when plugin is activated.
349 *
350 * @access public
351 * @return void
352 */
353 public function vimeography_update_tables() {
354 global $wpdb;
355
356 delete_option('vimeography_default_settings');
357 delete_option('vimeography_advanced_settings');
358
359 add_option('vimeography_advanced_settings', array(
360 'active' => FALSE,
361 'client_id' => '',
362 'client_secret' => '',
363 'access_token' => '',
364 'access_token_secret' => '',
365 ));
366
367 add_option('vimeography_default_settings', array(
368 'source_url' => 'https://vimeo.com/channels/staffpicks/',
369 'video_limit' => 20,
370 'featured_video' => '',
371 'cache_timeout' => 3600,
372 'theme_name' => 'bugsauce',
373 ));
374
375 $sql = 'CREATE TABLE '.VIMEOGRAPHY_GALLERY_TABLE.' (
376 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
377 title varchar(150) NOT NULL,
378 date_created datetime NOT NULL,
379 is_active tinyint(1) NOT NULL,
380 PRIMARY KEY (id)
381 );
382 CREATE TABLE '.VIMEOGRAPHY_GALLERY_META_TABLE.' (
383 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
384 gallery_id mediumint(8) unsigned NOT NULL,
385 source_url varchar(100) NOT NULL,
386 video_limit mediumint(7) NOT NULL,
387 featured_video int(9) unsigned DEFAULT NULL,
388 cache_timeout mediumint(7) NOT NULL,
389 theme_name varchar(50) NOT NULL,
390 PRIMARY KEY (id)
391 );
392 ';
393
394 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
395 dbDelta($sql);
396 }
397
398 /**
399 * Read the shortcode and return the output.
400 * example:
401 * [vimeography from='user' named='davekiss' theme='apple']
402 *
403 * @access public
404 * @param mixed $atts
405 * @return void
406 */
407 public function vimeography_shortcode($atts, $content = NULL)
408 {
409
410 // Let's get the data for this gallery from the db
411 if (intval($atts['id']))
412 {
413 global $wpdb;
414 $gallery_info = $wpdb->get_results('SELECT * from '.VIMEOGRAPHY_GALLERY_META_TABLE.' AS meta JOIN '.VIMEOGRAPHY_GALLERY_TABLE.' AS gallery ON meta.gallery_id = gallery.id WHERE meta.gallery_id = '.$atts['id'].' LIMIT 1;');
415 }
416
417 // Get admin panel options
418 $default_settings = get_option('vimeography_default_settings');
419
420 $gallery_settings['theme'] = isset($gallery_info[0]->theme_name) ? $gallery_info[0]->theme_name : $default_settings['theme_name'];
421 $gallery_settings['featured'] = isset($gallery_info[0]->featured_video) ? $gallery_info[0]->featured_video : $default_settings['featured_video'];
422 $gallery_settings['source'] = isset($gallery_info[0]->source_url) ? $gallery_info[0]->source_url : $default_settings['source_url'];
423 $gallery_settings['limit'] = isset($gallery_info[0]->video_limit) ? $gallery_info[0]->video_limit : $default_settings['video_limit'];
424 $gallery_settings['cache'] = isset($gallery_info[0]->cache_timeout) ? $gallery_info[0]->cache_timeout : $default_settings['cache_timeout'];
425
426 // Get shortcode attributes
427 $settings = shortcode_atts( array(
428 'id' => '',
429 'theme' => $gallery_settings['theme'],
430 'featured' => $gallery_settings['featured'],
431 'source' => $gallery_settings['source'],
432 'limit' => $gallery_settings['limit'],
433 'cache' => $gallery_settings['cache'],
434 ), $atts );
435
436 try
437 {
438 require_once(VIMEOGRAPHY_PATH . 'lib/core.php');
439 $vimeography = Vimeography_Core::factory('videos', $settings);
440
441 $settings_check = $settings;
442 $unused_id = array_shift($settings_check);
443
444 // If the shortcode settings are equal to the DB settings, the
445 // gallery isn't being overloaded by shortcode, so proceed to render
446 // the standard cache.
447
448 if ($settings_check == $gallery_settings)
449 {
450 // if cache is set, render it. otherwise, get the json, set the
451 // cache, and render it
452
453 if (($vimeography_data = $this->get_vimeography_cache($settings['id'])) === FALSE)
454 {
455 // cache not set, let's do a new request to the vimeo API
456 // and cache it
457 $vimeography_data = $vimeography->get('videos');
458 $transient = $this->set_vimeography_cache($settings['id'], $vimeography_data, $settings['cache']);
459 }
460 }
461 // Otherwise, let's see if a cache exists for these particular
462 // shortcode settings, and if not, we'll create one using an
463 // alternate cache name generated using an md5 of the serialized
464 // shortcode combines with the gallery id.
465
466 else
467 {
468 $cache_hash = $settings['id'].'_'.md5(serialize($gallery_settings));
469
470 // if cache is set, render it. otherwise, get the json, set the
471 // cache, and render it
472 if (($vimeography_data = $this->get_vimeography_cache($cache_hash)) === FALSE)
473 {
474 // cache not set, let's do a new request to the vimeo API
475 // and cache it
476 $vimeography_data = $vimeography->get('videos');
477 $transient = $this->set_vimeography_cache($cache_hash, $vimeography_data, $settings['cache']);
478 }
479 }
480 return $vimeography->render($vimeography_data);
481 }
482 catch (Vimeography_Exception $e)
483 {
484 return "Vimeography error: ".$e->getMessage();
485 }
486 }
487
488 /**
489 * Adds the VIMEOGRAPHY_THEME_PATH to the virtual robots.txt restricted list.
490 *
491 * @access public
492 * @static
493 * @return void
494 */
495 public static function vimeography_block_robots()
496 {
497 echo 'Disallow: '.VIMEOGRAPHY_THEME_PATH."\n";
498 }
499
500 /**
501 * Get the JSON data stored in the Vimeography cache for the provided gallery id.
502 *
503 * @access public
504 * @static
505 * @param mixed $id
506 * @return void
507 */
508 public static function get_vimeography_cache($id)
509 {
510 return FALSE === ( $vimeography_cache_results = get_transient( 'vimeography_cache_'.$id ) ) ? FALSE : $vimeography_cache_results;
511 }
512
513 /**
514 * Set the JSON data to the Vimeography cache for the provided gallery id.
515 *
516 * @access public
517 * @static
518 * @param mixed $id
519 * @param mixed $data
520 * @param mixed $cache_limit
521 * @return void
522 */
523 public static function set_vimeography_cache($id, $data, $cache_limit)
524 {
525 return set_transient( 'vimeography_cache_'.$id, $data, $cache_limit );
526 }
527
528 /**
529 * Clear the Vimeography cache for the provided gallery id.
530 *
531 * @access public
532 * @static
533 * @param mixed $id
534 * @return void
535 */
536 public static function delete_vimeography_cache($id)
537 {
538 return delete_transient('vimeography_cache_'.$id);
539 }
540
541 /**
542 * Moves the given folder to the given destination.
543 *
544 * @access private
545 * @param array $args (default: array())
546 * @return void
547 */
548 private function _move_folder($args = array())
549 {
550 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
551 // Replaces simple `WP_Filesystem();` call to prevent any extraction issues
552 // @link http://wpquestions.com/question/show/id/2685
553 if (! function_exists('__return_direct'))
554 {
555 function __return_direct() { return 'direct'; }
556 }
557
558 add_filter( 'filesystem_method', '__return_direct' );
559 WP_Filesystem();
560 remove_filter( 'filesystem_method', '__return_direct' );
561
562 global $wp_filesystem;
563 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
564 'clear_destination' => false, 'clear_working' => false,
565 'hook_extra' => array());
566
567 $args = wp_parse_args($args, $defaults);
568 extract($args);
569
570 @set_time_limit( 300 );
571
572 if ( empty($source) || empty($destination) )
573 return new WP_Error('bad_request', 'bad request.');
574
575 // $this->skin->feedback('installing_package');
576
577 //Retain the Original source and destinations
578 $remote_source = $source;
579 $local_destination = $destination;
580
581 if (! $wp_filesystem->dirlist($remote_source)) return FALSE;
582
583 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
584 $remote_destination = $wp_filesystem->find_folder($local_destination);
585
586 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
587 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
588 $source = trailingslashit($source) . trailingslashit($source_files[0]);
589 elseif ( count($source_files) == 0 )
590 return new WP_Error( 'incompatible_archive', 'incompatible archive string', __( 'The plugin contains no files.' ) ); //There are no files?
591 else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
592 $source = trailingslashit($source);
593
594 //Has the source location changed? If so, we need a new source_files list.
595 if ( $source !== $remote_source )
596 $source_files = array_keys( $wp_filesystem->dirlist($source) );
597
598 if ( $clear_destination ) {
599 //We're going to clear the destination if there's something there
600 //$this->skin->feedback('remove_old');
601 $removed = true;
602 if ( $wp_filesystem->exists($remote_destination) )
603 $removed = $wp_filesystem->delete($remote_destination, true);
604 if ( is_wp_error($removed) )
605 return $removed;
606 else if ( ! $removed )
607 return new WP_Error('remove_old_failed', 'couldnt remove old');
608 } elseif ( $wp_filesystem->exists($remote_destination) ) {
609 //If we're not clearing the destination folder and something exists there already, Bail.
610 //But first check to see if there are actually any files in the folder.
611 $_files = $wp_filesystem->dirlist($remote_destination);
612 if ( ! empty($_files) ) {
613 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
614 return new WP_Error('folder_exists', 'folder exists string', $remote_destination );
615 }
616 }
617
618 //Create themes folder, if needed
619 if ( !$wp_filesystem->exists(VIMEOGRAPHY_THEME_PATH) )
620 if ( !$wp_filesystem->mkdir(VIMEOGRAPHY_THEME_PATH, FS_CHMOD_DIR) )
621 return new WP_Error('mkdir_failed', 'mkdir failer string', $remote_destination);
622
623 //Create destination if needed
624 if ( !$wp_filesystem->exists($remote_destination) )
625 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
626 return new WP_Error('mkdir_failed', 'mkdir failer string', $remote_destination);
627
628 // Copy new version of item into place.
629 $result = copy_dir($source, $remote_destination);
630
631 if ( is_wp_error($result) ) {
632 if ( $clear_working )
633 $wp_filesystem->delete($remote_source, true);
634 return $result;
635 }
636
637 //Clear the Working folder?
638 if ( $clear_working )
639 $wp_filesystem->delete($remote_source, true);
640
641 $destination_name = basename( str_replace($local_destination, '', $destination) );
642 if ( '.' == $destination_name )
643 $destination_name = '';
644
645 $result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
646
647 //Bombard the calling function will all the info which we've just used.
648 return $result;
649
650 }
651
652 }
653
654 new Vimeography;