PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 1.1.3
Vimeography: Vimeo Video Gallery WordPress Plugin v1.1.3
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 1.1.3, at vimeography.php

742 lines 25.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: 1.1.3
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 requires the JSON PHP extension.');
14
15 global $wpdb;
16
17 // Define constants
18 define( 'VIMEOGRAPHY_URL', plugin_dir_url(__FILE__) );
19 define( 'VIMEOGRAPHY_PATH', plugin_dir_path(__FILE__) );
20 define( 'VIMEOGRAPHY_THEME_URL', WP_CONTENT_URL . '/vimeography/themes/' );
21 define( 'VIMEOGRAPHY_THEME_PATH', WP_CONTENT_DIR . '/vimeography/themes/' );
22 define( 'VIMEOGRAPHY_ASSETS_URL', WP_CONTENT_URL . '/vimeography/assets/' );
23 define( 'VIMEOGRAPHY_ASSETS_PATH', WP_CONTENT_DIR . '/vimeography/assets/' );
24 define( 'VIMEOGRAPHY_CACHE_URL', WP_CONTENT_URL . '/vimeography/cache/' );
25 define( 'VIMEOGRAPHY_CACHE_PATH', WP_CONTENT_DIR . '/vimeography/cache/' );
26 define( 'VIMEOGRAPHY_BASENAME', plugin_basename( __FILE__ ) );
27 define( 'VIMEOGRAPHY_VERSION', '1.1.3');
28 define( 'VIMEOGRAPHY_GALLERY_TABLE', $wpdb->prefix . "vimeography_gallery");
29 define( 'VIMEOGRAPHY_GALLERY_META_TABLE', $wpdb->prefix . "vimeography_gallery_meta");
30 define( 'VIMEOGRAPHY_CURRENT_PAGE', basename($_SERVER['PHP_SELF']));
31 define( 'VIMEOGRAPHY_CLIENT_ID', 'fc0927c077cb47345eadf7c513d70f4aa564f30d');
32
33 require_once(VIMEOGRAPHY_PATH . 'lib/exception.php');
34
35 // Require Mustache.php
36 if (! class_exists('Mustache_Engine'))
37 {
38 require_once(VIMEOGRAPHY_PATH . '/vendor/mustache.php-master/src/Mustache/Autoloader.php');
39 Mustache_Autoloader::register();
40 }
41
42 class Vimeography
43 {
44 /**
45 * [$themes description]
46 * @var array
47 */
48 public $themes = array();
49
50 /**
51 * [$active_theme description]
52 * @var [type]
53 */
54 public $active_theme = NULL;
55
56 /**
57 * [$instance description]
58 * @var [type]
59 */
60 private static $instance = NULL;
61
62 /**
63 * Creates or returns an instance of this class.
64 *
65 * @return Vimeography A single instance of this class.
66 */
67 public static function get_instance()
68 {
69 if ( NULL == self::$instance )
70 self::$instance = new self;
71
72 return self::$instance;
73 }
74
75 /**
76 * [__construct description]
77 */
78 private function __construct()
79 {
80 add_action( 'init', array($this, 'vimeography_init') );
81 add_action( 'admin_init', array($this, 'vimeography_requires_wordpress_version') );
82 add_action( 'admin_init', array($this, 'vimeography_check_if_db_exists') );
83 add_action( 'admin_init', array($this, 'vimeography_load_updater'));
84 add_action( 'admin_init', array($this, 'vimeography_activate_bugsauce'));
85 add_action( 'init', array($this, 'vimeography_move_folders') );
86 add_action( 'plugins_loaded', array($this, 'vimeography_update_database') );
87 add_action( 'admin_menu', array($this, 'vimeography_add_menu') );
88 add_action( 'do_robots', array($this, 'vimeography_block_robots') );
89
90 // Check the URL for any Vimeography-related parameters
91 add_filter( 'query_vars', array($this, 'vimeography_add_query_vars') );
92 add_action( 'generate_rewrite_rules', array($this, 'vimeography_add_rewrite_rules' ) );
93 add_action( 'parse_request', array($this, 'vimeography_parse_request') );
94
95 register_activation_hook( VIMEOGRAPHY_BASENAME, array($this, 'vimeography_update_tables') );
96 register_activation_hook( VIMEOGRAPHY_BASENAME, array($this, 'vimeography_flush_rewrite_rules') );
97 register_deactivation_hook( VIMEOGRAPHY_BASENAME, array($this, 'vimeography_deactivate_bugsauce') );
98
99 add_filter( 'plugin_action_links', array($this, 'vimeography_filter_plugin_actions'), 10, 2 );
100 add_shortcode( 'vimeography', array($this, 'vimeography_shortcode') );
101
102 // Add shortcode support for widgets
103 add_filter( 'widget_text', 'do_shortcode' );
104
105 // Load the themes that are hooking in to this action.
106 add_action('vimeography/load-theme', array($this, 'vimeography_load_theme'));
107 }
108
109 /**
110 * Check the wordpress version is compatible, and disable plugin if not.
111 *
112 * @access public
113 * @return void
114 */
115 public function vimeography_requires_wordpress_version()
116 {
117 global $wp_version;
118 $plugin_data = get_plugin_data( __FILE__, false );
119
120 if ( version_compare($wp_version, "3.3", "<" ) )
121 {
122 if( is_plugin_active( VIMEOGRAPHY_BASENAME ) )
123 {
124 deactivate_plugins( VIMEOGRAPHY_BASENAME );
125 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>." );
126 }
127 }
128 }
129
130 /**
131 * [vimeography_check_for_updates description]
132 * @return [type] [description]
133 */
134 public function vimeography_load_updater()
135 {
136 require_once(VIMEOGRAPHY_PATH . 'lib/update.php');
137 $updater = new Vimeography_Update;
138 $updater->vimeography_check_installed_theme_activations($this->themes);
139 }
140
141 /**
142 * Runs on every page load.
143 *
144 * @access public
145 * @return void
146 */
147 public function vimeography_init()
148 {
149 require_once(VIMEOGRAPHY_PATH . 'lib/init.php');
150 $init = new Vimeography_Init;
151
152 $init->vimeography_register_jquery();
153 $init->vimeography_add_gallery_helper();
154 $init->vimeography_written_block_robots();
155
156 require_once(VIMEOGRAPHY_PATH . 'lib/ajax.php');
157 new Vimeography_Ajax;
158 }
159
160 /**
161 * [vimeography_load_theme description]
162 * @param [type] $theme_path [description]
163 * @return [type] [description]
164 */
165 public function vimeography_load_theme($theme_path)
166 {
167 $theme = self::_get_theme_data($theme_path);
168
169 $theme['basename'] = plugin_basename($theme_path);
170 $theme['slug'] = substr($theme['basename'], 0, strpos($theme['basename'], "/"));
171 $theme['thumbnail'] = plugins_url(strtolower($theme['name']) .'.jpg', $theme_path);
172 $theme['file_path'] = $theme_path;
173 $theme['plugin_path'] = plugin_dir_path($theme_path);
174 $theme['partials_path'] = plugin_dir_path($theme_path) . 'partials';
175 $theme['settings_file'] = plugin_dir_path($theme_path) . 'settings.php';
176
177 $this->themes[] = $theme;
178 }
179
180 /**
181 * [set_active_theme description]
182 * @param [type] $theme_name [description]
183 */
184 public function set_active_theme($theme_name)
185 {
186 foreach($this->themes as $index => $theme)
187 {
188 if (strtolower($theme['name']) === strtolower($theme_name))
189 {
190 $this->active_theme = $theme;
191 }
192 }
193 return $this;
194 }
195
196 /**
197 * Retrieves the meta data from the headers of a given plugin file.
198 *
199 * @access private
200 * @static
201 * @param mixed $plugin_file
202 * @return void
203 */
204 private static function _get_theme_data($plugin_file)
205 {
206
207 $default_headers = array(
208 'name' => 'Theme Name',
209 'theme-uri' => 'Theme URI',
210 'version' => 'Version',
211 'description' => 'Description',
212 'author' => 'Author',
213 'author-uri' => 'Author URI',
214 );
215
216 return get_file_data( $plugin_file, $default_headers );
217 }
218
219 /**
220 * [vimeography_update_database description]
221 * @return [type] [description]
222 */
223 public function vimeography_update_database()
224 {
225 require_once(VIMEOGRAPHY_PATH . 'lib/database.php');
226 $db = new Vimeography_Database;
227
228 $db->vimeography_update_db_to_0_6();
229 $db->vimeography_update_db_to_0_7();
230 $db->vimeography_update_db_to_0_8();
231 $db->vimeography_update_db_to_1_0();
232 $db->vimeography_update_db_to_1_0_7();
233 $this->vimeography_update_db_version();
234 }
235
236 /**
237 * [vimeography_check_if_db_exists description]
238 * @return [type] [description]
239 */
240 public function vimeography_check_if_db_exists()
241 {
242 if (get_option('vimeography_db_version') == FALSE)
243 $this->vimeography_update_db_version();
244 }
245
246 /**
247 * Updates the Vimeography version stored in the database.
248 *
249 * @access public
250 * @return void
251 */
252 public function vimeography_update_db_version()
253 {
254 update_option('vimeography_db_version', VIMEOGRAPHY_VERSION);
255 }
256
257 /**
258 * Move the defined folders to the defined target path in wp-content/uploads.
259 *
260 * @access public
261 * @return void
262 */
263 public function vimeography_move_folders()
264 {
265 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'vimeography-bugsauce/', 'destination' => str_replace('vimeography/', '', VIMEOGRAPHY_PATH) . 'vimeography-bugsauce/', 'clear_destination' => true, 'clear_working' => true));
266 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'components/', 'destination' => VIMEOGRAPHY_ASSETS_PATH, 'clear_destination' => true, 'clear_working' => true));
267
268 if (! file_exists(VIMEOGRAPHY_CACHE_PATH) )
269 {
270 // creates the dir and it's parent dirs
271 if (! mkdir(VIMEOGRAPHY_CACHE_PATH, 0777, true) )
272 {
273 if( is_plugin_active( VIMEOGRAPHY_BASENAME ) )
274 {
275 deactivate_plugins( VIMEOGRAPHY_BASENAME );
276 wp_die( "Vimeography could not create the cache directory. Please contact your host and request permissions to write to your Wordpress installation's wp-content directory.<br /><br />Back to <a href='".admin_url()."'>WordPress admin</a>." );
277 }
278 }
279 }
280 }
281
282 /**
283 * Add Settings link to "installed plugins" admin page.
284 *
285 * @access public
286 * @param mixed $links
287 * @param mixed $file
288 * @return void
289 */
290 public function vimeography_filter_plugin_actions($links, $file)
291 {
292 if ( $file == VIMEOGRAPHY_BASENAME )
293 {
294 $settings_link = '<a href="admin.php?page=vimeography-edit-galleries">' . __('Settings') . '</a>';
295 if (!in_array($settings_link, $links))
296 array_unshift( $links, $settings_link ); // before other links
297 }
298 return $links;
299 }
300
301 /**
302 * Adds a new top level menu to the admin menu.
303 *
304 * @access public
305 * @return void
306 */
307 public function vimeography_add_menu()
308 {
309 global $submenu;
310
311 add_menu_page( 'Vimeography Page Title', 'Vimeography', 'manage_options', 'vimeography-edit-galleries', '', VIMEOGRAPHY_URL.'media/img/vimeography-icon.png' );
312 add_submenu_page( 'vimeography-edit-galleries', 'Edit Galleries', 'Edit Galleries', 'manage_options', 'vimeography-edit-galleries', array(&$this, 'vimeography_render_template' ));
313 add_submenu_page( 'vimeography-edit-galleries', 'New Gallery', 'New Gallery', 'manage_options', 'vimeography-new-gallery', array(&$this, 'vimeography_render_template' ));
314 add_submenu_page( 'vimeography-edit-galleries', 'Manage Activations', 'Manage Activations', 'manage_options', 'vimeography-manage-activations', array(&$this, 'vimeography_render_template' ));
315 $submenu['vimeography-edit-galleries'][500] = array( 'Vimeography Themes', 'manage_options' , 'http://vimeography.com/themes' );
316 add_submenu_page( 'vimeography-edit-galleries', 'Vimeography Pro', 'Vimeography Pro', 'manage_options', 'vimeography-pro', array(&$this, 'vimeography_render_template' ));
317 add_submenu_page( 'vimeography-edit-galleries', 'Help', 'Help', 'manage_options', 'vimeography-help', array(&$this, 'vimeography_render_template' ));
318 }
319
320 /**
321 * Renders the admin template for the current page.
322 *
323 * @access public
324 * @return void
325 */
326 public function vimeography_render_template()
327 {
328 if ( !current_user_can( 'manage_options' ) )
329 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
330
331 wp_register_style( 'vimeography-bootstrap', VIMEOGRAPHY_URL.'media/css/bootstrap.min.css');
332 wp_register_style( 'vimeography-admin', VIMEOGRAPHY_URL.'media/css/admin.css');
333 wp_register_style( 'vimeography-type', 'http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700');
334
335 wp_register_script( 'vimeography-bootstrap', VIMEOGRAPHY_URL.'media/js/bootstrap.min.js');
336 wp_register_script( 'vimeography-admin', VIMEOGRAPHY_URL.'media/js/admin.js', 'jquery');
337
338 wp_enqueue_style( 'vimeography-bootstrap');
339 wp_enqueue_style( 'vimeography-admin');
340 wp_enqueue_style( 'vimeography-type');
341
342 wp_enqueue_script( 'vimeography-bootstrap');
343 wp_enqueue_script( 'vimeography-admin');
344
345 $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates'),));
346 require_once(VIMEOGRAPHY_PATH . 'lib/admin/base.php');
347
348 switch(current_filter())
349 {
350 case 'vimeography_page_vimeography-new-gallery':
351 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/new.php');
352
353 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
354 {
355 do_action('vimeography-pro/load-new');
356 $view = new Vimeography_Pro_Gallery_New;
357 }
358 else
359 {
360 $view = new Vimeography_Gallery_New;
361 }
362
363 $template = $mustache->loadTemplate('gallery/new');
364 break;
365 case 'toplevel_page_vimeography-edit-galleries':
366 if (isset($_GET['id']))
367 {
368 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/edit.php');
369
370 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
371 {
372 do_action('vimeography-pro/load-editor');
373 $view = new Vimeography_Pro_Gallery_Edit;
374 }
375 else
376 {
377 $view = new Vimeography_Gallery_Edit;
378 }
379
380 $mustache->setPartialsLoader( new Mustache_Loader_CascadingLoader( array(
381 new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates/gallery/edit/partials'),
382 ) )
383 );
384
385 apply_filters('vimeography-pro/load-edit-partials', $mustache->getPartialsLoader());
386
387 //$mustache->setPartialsLoader(new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates/gallery/edit/partials'));
388
389 $template = $mustache->loadTemplate('gallery/edit/layout');
390
391 }
392 else
393 {
394 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/list.php');
395 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
396 {
397 do_action('vimeography-pro/load-list');
398 $view = new Vimeography_Pro_Gallery_List;
399 }
400 else
401 {
402 $view = new Vimeography_Gallery_List;
403 }
404 $template = $mustache->loadTemplate('gallery/list');
405 }
406 break;
407 case 'vimeography_page_vimeography-manage-activations':
408 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/theme/list.php');
409 $view = new Vimeography_Theme_List;
410 $template = $mustache->loadTemplate('theme/list');
411 break;
412 case 'vimeography_page_vimeography-pro':
413 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/pro.php');
414 $view = new Vimeography_Pro_About;
415 $template = $mustache->loadTemplate('vimeography/pro');
416 break;
417 case 'vimeography_page_vimeography-help':
418 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/help.php');
419 $view = new Vimeography_Help;
420 $template = $mustache->loadTemplate('vimeography/help');
421 break;
422 default:
423 wp_die( __('The admin template for "'.current_filter().'" cannot be found.') );
424 break;
425 }
426
427 echo $template->render($view);
428 }
429
430 /**
431 * Create tables and define defaults when plugin is activated.
432 *
433 * @access public
434 * @return void
435 */
436 public function vimeography_update_tables() {
437 global $wpdb;
438
439 delete_option('vimeography_default_settings');
440 delete_option('vimeography_advanced_settings');
441
442 add_option('vimeography_default_settings', array(
443 'source_url' => 'https://vimeo.com/channels/staffpicks/',
444 'resource_uri' => '/channels/staffpicks',
445 'featured_video' => '',
446 'video_limit' => 25,
447 'cache_timeout' => 3600,
448 'theme_name' => 'bugsauce',
449 ));
450
451 $sql = 'CREATE TABLE '.VIMEOGRAPHY_GALLERY_TABLE.' (
452 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
453 title varchar(150) NOT NULL,
454 date_created datetime NOT NULL,
455 is_active tinyint(1) NOT NULL,
456 PRIMARY KEY (id)
457 );
458 CREATE TABLE '.VIMEOGRAPHY_GALLERY_META_TABLE.' (
459 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
460 gallery_id mediumint(8) unsigned NOT NULL,
461 source_url varchar(100) NOT NULL,
462 resource_uri varchar(50) NOT NULL,
463 featured_video varchar(100) DEFAULT NULL,
464 video_limit mediumint(7) NOT NULL,
465 gallery_width varchar(10) DEFAULT NULL,
466 cache_timeout mediumint(7) NOT NULL,
467 theme_name varchar(50) NOT NULL,
468 PRIMARY KEY (id)
469 );
470 ';
471
472 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
473 dbDelta($sql);
474 }
475
476 /**
477 * Checks if the provided Vimeo URL is valid and if so, returns a
478 * string to be used as the collection endpoint.
479 *
480 * @param string $source_url Source collection of Vimeo videos.
481 * @return string Vimeo Resource
482 */
483 public static function validate_vimeo_source($source_url)
484 {
485 $scheme = parse_url($source_url);
486
487 if (empty($scheme['scheme']))
488 $source_url = 'https://' . $source_url;
489
490 if ((($url = parse_url($source_url)) !== FALSE) && (preg_match('~vimeo(?:pro)?\.com$~', $url['host']) > 0))
491 {
492 $host = $url['host'];
493 $url = array_values(array_filter(explode('/', $url['path']), 'strlen'));
494
495 // If the array doesn't contain one of the following strings, it
496 // must be either a user or a video
497 if (in_array($url[0], array('album', 'channels', 'groups', 'categories')) !== TRUE)
498 {
499 if (is_numeric($url[0]))
500 {
501 array_unshift($url, 'videos');
502 }
503 else
504 {
505 array_unshift($url, 'users');
506
507 if (isset($url[2]) AND $host != 'vimeo.com')
508 array_splice($url, 2, 0, array('portfolios'));
509 }
510 }
511
512 // Make sure the resource is plural
513 $url[0] = rtrim($url[0], 's') . 's';
514 $resource = '/' . implode('/', $url);
515
516 return $resource;
517 }
518 else
519 {
520 throw new Vimeography_Exception( __('That site doesn\'t look like a valid link to a Vimeo collection.') );
521 }
522 }
523
524 /**
525 * Read the shortcode and return the output.
526 * example:
527 * [vimeography id="1" theme='apple']
528 *
529 * @access public
530 * @param mixed $atts
531 * @return void
532 */
533 public function vimeography_shortcode($atts, $content = NULL)
534 {
535 require_once(VIMEOGRAPHY_PATH . 'lib/shortcode.php');
536 $shortcode = new Vimeography_Shortcode($atts, $content);
537 return $shortcode->output();
538 }
539
540 /**
541 * Adds the VIMEOGRAPHY_ASSETS_URL to the virtual robots.txt restricted list.
542 *
543 * @access public
544 * @static
545 * @return void
546 */
547 public static function vimeography_block_robots()
548 {
549 $blocked_asset_path = str_ireplace(site_url(), '', VIMEOGRAPHY_ASSETS_URL);
550 echo 'Disallow: '.$blocked_asset_path."\n";
551 }
552
553 /**
554 * [vimeography_add_query_vars description]
555 * @param [type] $vars [description]
556 * @return [type] [description]
557 */
558 public function vimeography_add_query_vars($vars)
559 {
560 $vars[] = 'vimeography_action';
561 $vars[] = 'vimeography_gallery_id';
562 return $vars;
563 }
564
565 /**
566 * Adds custom rewrite rules.
567 * @param [type] $wp_rewrite [description]
568 * @return [type] [description]
569 */
570 function vimeography_add_rewrite_rules($wp_rewrite)
571 {
572 $wp_rewrite->rules = array(
573 'vimeography/([0-9]{1,4})+/refresh\/?' => $wp_rewrite->index . '?vimeography_action=refresh&vimeography_gallery_id=' . $wp_rewrite->preg_index( 1 ),
574 //'vimeography/notify\/?' => $wp_rewrite->index . '?vimeography_action=' . $wp_rewrite->preg_index( 1 ),
575 ) + $wp_rewrite->rules;
576 }
577
578 /**
579 * [vimeography_parse_request description]
580 * @param [type] $wp [description]
581 * @return [type] [description]
582 */
583 public function vimeography_parse_request($wp)
584 {
585 if (array_key_exists('vimeography_action', $wp->query_vars) AND $wp->query_vars['vimeography_action'] == 'refresh')
586 {
587 require_once VIMEOGRAPHY_PATH . 'lib/cache.php';
588 $cache = new Vimeography_Cache($wp->query_vars['vimeography_gallery_id']);
589 if ($cache->exists())
590 $cache->delete();
591 die('Thanks, Vimeo. Cache busted.');
592 }
593 }
594
595 /**
596 * [vimeography_flush_rewrite_rules description]
597 * @return [type] [description]
598 */
599 public function vimeography_flush_rewrite_rules()
600 {
601 return flush_rewrite_rules();
602 }
603
604 /**
605 * [vimeography_activate_plugin description]
606 * @param [type] $basename [description]
607 * @return [type] [description]
608 */
609 public function vimeography_activate_bugsauce()
610 {
611 $bugsauce = str_replace('vimeography/', 'vimeography-bugsauce/', VIMEOGRAPHY_PATH);
612 if ( is_plugin_inactive('vimeography-bugsauce/vimeography-bugsauce.php') AND file_exists($bugsauce) )
613 activate_plugin('vimeography-bugsauce/vimeography-bugsauce.php');
614 }
615
616 /**
617 * [vimeography_activate_plugin description]
618 * @param [type] $basename [description]
619 * @return [type] [description]
620 */
621 public function vimeography_deactivate_bugsauce()
622 {
623 if (is_plugin_active('vimeography-bugsauce/vimeography-bugsauce.php'))
624 deactivate_plugins('vimeography-bugsauce/vimeography-bugsauce.php');
625 }
626
627 /**
628 * Moves the given folder to the given destination.
629 *
630 * @access private
631 * @param array $args (default: array())
632 * @return void
633 */
634 private function _move_folder($args = array())
635 {
636 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
637
638 // Replaces simple `WP_Filesystem();` call to prevent any extraction issues
639 // @link http://wpquestions.com/question/show/id/2685
640 if (! function_exists('__return_direct'))
641 {
642 function __return_direct() { return 'direct'; }
643 }
644
645 add_filter( 'filesystem_method', '__return_direct' );
646 WP_Filesystem();
647 remove_filter( 'filesystem_method', '__return_direct' );
648
649 global $wp_filesystem;
650
651 // Always pass these
652 $defaults = array(
653 'source' => '',
654 'destination' => '',
655 'clear_destination' => false,
656 'clear_working' => false,
657 'hook_extra' => array(),
658 );
659
660 $args = wp_parse_args($args, $defaults);
661 extract($args);
662
663 @set_time_limit( 300 );
664
665 if ( empty($source) || empty($destination) )
666 return new WP_Error('bad_request', 'bad request.');
667
668 //Retain the Original source and destinations
669 $remote_source = $source;
670 $local_destination = $destination;
671
672 if (! $wp_filesystem->dirlist($remote_source))
673 return FALSE;
674
675 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
676 $remote_destination = $wp_filesystem->find_folder($local_destination);
677
678 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
679 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
680 $source = trailingslashit($source) . trailingslashit($source_files[0]);
681 elseif ( count($source_files) == 0 )
682 return new WP_Error( 'incompatible_archive', 'incompatible archive string', __( 'The plugin contains no files.' ) ); //There are no files?
683 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.
684 $source = trailingslashit($source);
685
686 //Has the source location changed? If so, we need a new source_files list.
687 if ( $source !== $remote_source )
688 $source_files = array_keys( $wp_filesystem->dirlist($source) );
689
690 if ( $clear_destination ) {
691 //We're going to clear the destination if there's something there
692 //$this->skin->feedback('remove_old');
693 $removed = true;
694 if ( $wp_filesystem->exists($remote_destination) )
695 $removed = $wp_filesystem->delete($remote_destination, true);
696 if ( is_wp_error($removed) )
697 return $removed;
698 else if ( ! $removed )
699 return new WP_Error('remove_old_failed', 'couldnt remove old');
700 } elseif ( $wp_filesystem->exists($remote_destination) ) {
701 //If we're not clearing the destination folder and something exists there already, Bail.
702 //But first check to see if there are actually any files in the folder.
703 $_files = $wp_filesystem->dirlist($remote_destination);
704 if ( ! empty($_files) ) {
705 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
706 return new WP_Error('folder_exists', 'folder exists string', $remote_destination );
707 }
708 }
709
710 //Create destination if needed
711 if ( !$wp_filesystem->exists($remote_destination) )
712 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
713 return new WP_Error('mkdir_failed', 'mkdir failer string', $remote_destination);
714
715 // Copy new version of item into place.
716 $result = copy_dir($source, $remote_destination);
717
718 if ( is_wp_error($result) ) {
719 if ( $clear_working )
720 $wp_filesystem->delete($remote_source, true);
721 return $result;
722 }
723
724 //Clear the Working folder?
725 if ( $clear_working )
726 $wp_filesystem->delete($remote_source, true);
727
728 $destination_name = basename( str_replace($local_destination, '', $destination) );
729 if ( '.' == $destination_name )
730 $destination_name = '';
731
732 $result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
733
734 //Bombard the calling function will all the info which we've just used.
735 return $result;
736
737 }
738
739 }
740
741 Vimeography::get_instance();
742