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

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