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

791 lines 26.7 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.7
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', content_url() . '/vimeography/themes/' );
21 define( 'VIMEOGRAPHY_THEME_PATH', WP_CONTENT_DIR . '/vimeography/themes/' );
22 define( 'VIMEOGRAPHY_ASSETS_URL', content_url() . '/vimeography/assets/' );
23 define( 'VIMEOGRAPHY_ASSETS_PATH', WP_CONTENT_DIR . '/vimeography/assets/' );
24 define( 'VIMEOGRAPHY_CACHE_URL', 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.7');
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 $db->vimeography_update_db_to_1_1_6();
281 $this->vimeography_update_db_version();
282 }
283
284 /**
285 * [vimeography_check_if_db_exists description]
286 * @return [type] [description]
287 */
288 public function vimeography_check_if_db_exists()
289 {
290 if (get_option('vimeography_db_version') == FALSE)
291 $this->vimeography_update_db_version();
292 }
293
294 /**
295 * Updates the Vimeography version stored in the database.
296 *
297 * @access public
298 * @return void
299 */
300 public function vimeography_update_db_version()
301 {
302 update_option('vimeography_db_version', VIMEOGRAPHY_VERSION);
303 }
304
305 /**
306 * Move the defined folders to the defined target path in wp-content/uploads.
307 *
308 * @access public
309 * @return void
310 */
311 public function vimeography_move_folders()
312 {
313 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'vimeography-bugsauce/', 'destination' => str_replace('vimeography/', '', VIMEOGRAPHY_PATH) . 'vimeography-bugsauce/', 'clear_destination' => true, 'clear_working' => true));
314 $this->_move_folder(array('source' => VIMEOGRAPHY_PATH . 'components/', 'destination' => VIMEOGRAPHY_ASSETS_PATH, 'clear_destination' => true, 'clear_working' => true));
315
316 if (! file_exists(VIMEOGRAPHY_CACHE_PATH) )
317 {
318 // creates the dir and it's parent dirs
319 if (! mkdir(VIMEOGRAPHY_CACHE_PATH, 0777, true) )
320 {
321 if( is_plugin_active( VIMEOGRAPHY_BASENAME ) )
322 {
323 deactivate_plugins( VIMEOGRAPHY_BASENAME );
324 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>." );
325 }
326 }
327 }
328 }
329
330 /**
331 * Add Settings link to "installed plugins" admin page.
332 *
333 * @access public
334 * @param mixed $links
335 * @param mixed $file
336 * @return void
337 */
338 public function vimeography_filter_plugin_actions($links, $file)
339 {
340 if ( $file == VIMEOGRAPHY_BASENAME )
341 {
342 $settings_link = '<a href="admin.php?page=vimeography-edit-galleries">' . __('Settings') . '</a>';
343 if (!in_array($settings_link, $links))
344 array_unshift( $links, $settings_link ); // before other links
345 }
346 return $links;
347 }
348
349 /**
350 * Adds a new top level menu to the admin menu.
351 *
352 * @access public
353 * @return void
354 */
355 public function vimeography_add_menu()
356 {
357 global $submenu;
358
359 add_menu_page( 'Vimeography Page Title', 'Vimeography', 'manage_options', 'vimeography-edit-galleries', '', VIMEOGRAPHY_URL.'media/img/vimeography-icon.png' );
360 add_submenu_page( 'vimeography-edit-galleries', 'Edit Galleries', 'Edit Galleries', 'manage_options', 'vimeography-edit-galleries', array(&$this, 'vimeography_render_template' ));
361 add_submenu_page( 'vimeography-edit-galleries', 'New Gallery', 'New Gallery', 'manage_options', 'vimeography-new-gallery', array(&$this, 'vimeography_render_template' ));
362 add_submenu_page( 'vimeography-edit-galleries', 'Manage Activations', 'Manage Activations', 'manage_options', 'vimeography-manage-activations', array(&$this, 'vimeography_render_template' ));
363 if ( current_user_can( 'manage_options' ) )
364 $submenu['vimeography-edit-galleries'][500] = array( 'Vimeography Themes', 'manage_options' , 'http://vimeography.com/themes' );
365 add_submenu_page( 'vimeography-edit-galleries', 'Vimeography Pro', 'Vimeography Pro', 'manage_options', 'vimeography-pro', array(&$this, 'vimeography_render_template' ));
366 add_submenu_page( 'vimeography-edit-galleries', 'Help', 'Help', 'manage_options', 'vimeography-help', array(&$this, 'vimeography_render_template' ));
367 }
368
369 /**
370 * Renders the admin template for the current page.
371 *
372 * @access public
373 * @return void
374 */
375 public function vimeography_render_template()
376 {
377 if ( !current_user_can( 'manage_options' ) )
378 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
379
380 wp_register_style( 'vimeography-bootstrap', VIMEOGRAPHY_URL.'media/css/bootstrap.min.css');
381 wp_register_style( 'vimeography-admin', VIMEOGRAPHY_URL.'media/css/admin.css');
382 wp_register_style( 'vimeography-type', 'http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700');
383
384 wp_register_script( 'vimeography-bootstrap', VIMEOGRAPHY_URL.'media/js/bootstrap.min.js');
385 wp_register_script( 'vimeography-admin', VIMEOGRAPHY_URL.'media/js/admin.js', 'jquery');
386
387 wp_enqueue_style( 'vimeography-bootstrap');
388 wp_enqueue_style( 'vimeography-admin');
389 wp_enqueue_style( 'vimeography-type');
390
391 wp_enqueue_script( 'vimeography-bootstrap');
392 wp_enqueue_script( 'vimeography-admin');
393
394 $mustache = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates'),));
395 require_once(VIMEOGRAPHY_PATH . 'lib/admin/base.php');
396
397 switch(current_filter())
398 {
399 case 'vimeography_page_vimeography-new-gallery':
400 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/new.php');
401
402 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
403 {
404 do_action('vimeography-pro/load-new');
405 $view = new Vimeography_Pro_Gallery_New;
406 }
407 else
408 {
409 $view = new Vimeography_Gallery_New;
410 }
411
412 $template = $mustache->loadTemplate('gallery/new');
413 break;
414 case 'toplevel_page_vimeography-edit-galleries':
415 if (isset($_GET['id']))
416 {
417 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/edit.php');
418
419 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
420 {
421 do_action('vimeography-pro/load-editor');
422 $view = new Vimeography_Pro_Gallery_Edit;
423 }
424 else
425 {
426 $view = new Vimeography_Gallery_Edit;
427 }
428
429 $mustache->setPartialsLoader( new Mustache_Loader_CascadingLoader( array(
430 new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates/gallery/edit/partials'),
431 ) )
432 );
433
434 apply_filters('vimeography-pro/load-edit-partials', $mustache->getPartialsLoader());
435
436 //$mustache->setPartialsLoader(new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates/gallery/edit/partials'));
437
438 $template = $mustache->loadTemplate('gallery/edit/layout');
439
440 }
441 else
442 {
443 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/gallery/list.php');
444 if (is_plugin_active('vimeography-pro/vimeography-pro.php'))
445 {
446 do_action('vimeography-pro/load-list');
447 $view = new Vimeography_Pro_Gallery_List;
448 }
449 else
450 {
451 $view = new Vimeography_Gallery_List;
452 }
453 $template = $mustache->loadTemplate('gallery/list');
454 }
455 break;
456 case 'vimeography_page_vimeography-manage-activations':
457 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/theme/list.php');
458 $view = new Vimeography_Theme_List;
459 $template = $mustache->loadTemplate('theme/list');
460 break;
461 case 'vimeography_page_vimeography-pro':
462 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/pro.php');
463 $view = new Vimeography_Pro_About;
464 $template = $mustache->loadTemplate('vimeography/pro');
465 break;
466 case 'vimeography_page_vimeography-help':
467 require_once(VIMEOGRAPHY_PATH . 'lib/admin/view/vimeography/help.php');
468 $view = new Vimeography_Help;
469 $template = $mustache->loadTemplate('vimeography/help');
470 break;
471 default:
472 wp_die( __('The admin template for "'.current_filter().'" cannot be found.') );
473 break;
474 }
475
476 echo $template->render($view);
477 }
478
479 /**
480 * Create tables and define defaults when plugin is activated.
481 *
482 * @access public
483 * @return void
484 */
485 public function vimeography_update_tables() {
486 global $wpdb;
487
488 delete_option('vimeography_default_settings');
489 delete_option('vimeography_advanced_settings');
490
491 add_option('vimeography_default_settings', array(
492 'source_url' => 'https://vimeo.com/channels/staffpicks/',
493 'resource_uri' => '/channels/staffpicks',
494 'featured_video' => '',
495 'video_limit' => 25,
496 'cache_timeout' => 3600,
497 'theme_name' => 'bugsauce',
498 ));
499
500 $sql = 'CREATE TABLE '.VIMEOGRAPHY_GALLERY_TABLE.' (
501 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
502 title varchar(150) NOT NULL,
503 date_created datetime NOT NULL,
504 is_active tinyint(1) NOT NULL,
505 PRIMARY KEY (id)
506 );
507 CREATE TABLE '.VIMEOGRAPHY_GALLERY_META_TABLE.' (
508 id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
509 gallery_id mediumint(8) unsigned NOT NULL,
510 source_url varchar(100) NOT NULL,
511 resource_uri varchar(100) NOT NULL,
512 featured_video varchar(100) DEFAULT NULL,
513 video_limit mediumint(7) NOT NULL,
514 gallery_width varchar(10) DEFAULT NULL,
515 cache_timeout mediumint(7) NOT NULL,
516 theme_name varchar(50) NOT NULL,
517 PRIMARY KEY (id)
518 );
519 ';
520
521 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
522 dbDelta($sql);
523 }
524
525 /**
526 * Checks if the provided Vimeo URL is valid and if so, returns a
527 * string to be used as the collection endpoint.
528 *
529 * @param string $source_url Source collection of Vimeo videos.
530 * @return string Vimeo Resource
531 */
532 public static function validate_vimeo_source($source_url)
533 {
534 $scheme = parse_url($source_url);
535
536 if (empty($scheme['scheme']))
537 $source_url = 'https://' . $source_url;
538
539 if ((($url = parse_url($source_url)) !== FALSE) && (preg_match('~vimeo(?:pro)?\.com$~', $url['host']) > 0))
540 {
541 $host = $url['host'];
542 $url = array_values(array_filter(explode('/', $url['path']), 'strlen'));
543
544 // If the array doesn't contain one of the following strings, it
545 // must be either a user or a video
546 if (in_array($url[0], array('album', 'channels', 'groups', 'categories')) !== TRUE)
547 {
548 if (is_numeric($url[0]))
549 {
550 array_unshift($url, 'videos');
551 }
552 else
553 {
554 array_unshift($url, 'users');
555
556 if (isset($url[2]) AND $host != 'vimeo.com')
557 array_splice($url, 2, 0, array('portfolios'));
558 }
559 }
560
561 // Make sure the resource is plural
562 $url[0] = rtrim($url[0], 's') . 's';
563 $resource = '/' . implode('/', $url);
564
565 return $resource;
566 }
567 else
568 {
569 throw new Vimeography_Exception( __('That site doesn\'t look like a valid link to a Vimeo collection.') );
570 }
571 }
572
573 /**
574 * Read the shortcode and return the output.
575 * example:
576 * [vimeography id="1" theme='apple']
577 *
578 * @access public
579 * @param mixed $atts
580 * @return void
581 */
582 public function vimeography_shortcode($atts, $content = NULL)
583 {
584 require_once(VIMEOGRAPHY_PATH . 'lib/shortcode.php');
585 $shortcode = new Vimeography_Shortcode($atts, $content);
586 return $shortcode->output();
587 }
588
589 /**
590 * Adds the VIMEOGRAPHY_ASSETS_URL to the virtual robots.txt restricted list.
591 *
592 * @access public
593 * @static
594 * @return void
595 */
596 public static function vimeography_block_robots()
597 {
598 $blocked_asset_path = str_ireplace(site_url(), '', VIMEOGRAPHY_ASSETS_URL);
599 echo 'Disallow: '.$blocked_asset_path."\n";
600 }
601
602 /**
603 * [vimeography_add_query_vars description]
604 * @param [type] $vars [description]
605 * @return [type] [description]
606 */
607 public function vimeography_add_query_vars($vars)
608 {
609 $vars[] = 'vimeography_action';
610 $vars[] = 'vimeography_gallery_id';
611 return $vars;
612 }
613
614 /**
615 * Adds custom rewrite rules.
616 * @param [type] $wp_rewrite [description]
617 * @return [type] [description]
618 */
619 function vimeography_add_rewrite_rules($wp_rewrite)
620 {
621 $wp_rewrite->rules = array(
622 'vimeography/([0-9]{1,4})+/refresh\/?' => $wp_rewrite->index . '?vimeography_action=refresh&vimeography_gallery_id=' . $wp_rewrite->preg_index( 1 ),
623 //'vimeography/notify\/?' => $wp_rewrite->index . '?vimeography_action=' . $wp_rewrite->preg_index( 1 ),
624 ) + $wp_rewrite->rules;
625 }
626
627 /**
628 * [vimeography_parse_request description]
629 * @param [type] $wp [description]
630 * @return [type] [description]
631 */
632 public function vimeography_parse_request($wp)
633 {
634 if (array_key_exists('vimeography_action', $wp->query_vars) AND $wp->query_vars['vimeography_action'] == 'refresh')
635 {
636 require_once VIMEOGRAPHY_PATH . 'lib/cache.php';
637 $cache = new Vimeography_Cache($wp->query_vars['vimeography_gallery_id']);
638 if ($cache->exists())
639 $cache->delete();
640 die('Thanks, Vimeo. Cache busted.');
641 }
642 }
643
644 /**
645 * [vimeography_flush_rewrite_rules description]
646 * @return [type] [description]
647 */
648 public function vimeography_flush_rewrite_rules()
649 {
650 return flush_rewrite_rules();
651 }
652
653 /**
654 * [vimeography_activate_plugin description]
655 * @param [type] $basename [description]
656 * @return [type] [description]
657 */
658 public function vimeography_activate_bugsauce()
659 {
660 $bugsauce = str_replace('vimeography/', 'vimeography-bugsauce/', VIMEOGRAPHY_PATH);
661 if ( is_plugin_inactive('vimeography-bugsauce/vimeography-bugsauce.php') AND file_exists($bugsauce) )
662 activate_plugin('vimeography-bugsauce/vimeography-bugsauce.php');
663 }
664
665 /**
666 * [vimeography_activate_plugin description]
667 * @param [type] $basename [description]
668 * @return [type] [description]
669 */
670 public function vimeography_deactivate_bugsauce()
671 {
672 if (is_plugin_active('vimeography-bugsauce/vimeography-bugsauce.php'))
673 deactivate_plugins('vimeography-bugsauce/vimeography-bugsauce.php');
674 }
675
676 /**
677 * Moves the given folder to the given destination.
678 *
679 * @access private
680 * @param array $args (default: array())
681 * @return void
682 */
683 private function _move_folder($args = array())
684 {
685 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
686
687 // Replaces simple `WP_Filesystem();` call to prevent any extraction issues
688 // @link http://wpquestions.com/question/show/id/2685
689 if (! function_exists('__return_direct'))
690 {
691 function __return_direct() { return 'direct'; }
692 }
693
694 add_filter( 'filesystem_method', '__return_direct' );
695 WP_Filesystem();
696 remove_filter( 'filesystem_method', '__return_direct' );
697
698 global $wp_filesystem;
699
700 // Always pass these
701 $defaults = array(
702 'source' => '',
703 'destination' => '',
704 'clear_destination' => false,
705 'clear_working' => false,
706 'hook_extra' => array(),
707 );
708
709 $args = wp_parse_args($args, $defaults);
710 extract($args);
711
712 @set_time_limit( 300 );
713
714 if ( empty($source) || empty($destination) )
715 return new WP_Error('bad_request', 'bad request.');
716
717 //Retain the Original source and destinations
718 $remote_source = $source;
719 $local_destination = $destination;
720
721 if (! $wp_filesystem->dirlist($remote_source))
722 return FALSE;
723
724 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
725 $remote_destination = $wp_filesystem->find_folder($local_destination);
726
727 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
728 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
729 $source = trailingslashit($source) . trailingslashit($source_files[0]);
730 elseif ( count($source_files) == 0 )
731 return new WP_Error( 'incompatible_archive', 'incompatible archive string', __( 'The plugin contains no files.' ) ); //There are no files?
732 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.
733 $source = trailingslashit($source);
734
735 //Has the source location changed? If so, we need a new source_files list.
736 if ( $source !== $remote_source )
737 $source_files = array_keys( $wp_filesystem->dirlist($source) );
738
739 if ( $clear_destination ) {
740 //We're going to clear the destination if there's something there
741 //$this->skin->feedback('remove_old');
742 $removed = true;
743 if ( $wp_filesystem->exists($remote_destination) )
744 $removed = $wp_filesystem->delete($remote_destination, true);
745 if ( is_wp_error($removed) )
746 return $removed;
747 else if ( ! $removed )
748 return new WP_Error('remove_old_failed', 'couldnt remove old');
749 } elseif ( $wp_filesystem->exists($remote_destination) ) {
750 //If we're not clearing the destination folder and something exists there already, Bail.
751 //But first check to see if there are actually any files in the folder.
752 $_files = $wp_filesystem->dirlist($remote_destination);
753 if ( ! empty($_files) ) {
754 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
755 return new WP_Error('folder_exists', 'folder exists string', $remote_destination );
756 }
757 }
758
759 //Create destination if needed
760 if ( !$wp_filesystem->exists($remote_destination) )
761 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
762 return new WP_Error('mkdir_failed', 'mkdir failer string', $remote_destination);
763
764 // Copy new version of item into place.
765 $result = copy_dir($source, $remote_destination);
766
767 if ( is_wp_error($result) ) {
768 if ( $clear_working )
769 $wp_filesystem->delete($remote_source, true);
770 return $result;
771 }
772
773 //Clear the Working folder?
774 if ( $clear_working )
775 $wp_filesystem->delete($remote_source, true);
776
777 $destination_name = basename( str_replace($local_destination, '', $destination) );
778 if ( '.' == $destination_name )
779 $destination_name = '';
780
781 $result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
782
783 //Bombard the calling function will all the info which we've just used.
784 return $result;
785
786 }
787
788 }
789
790 Vimeography::get_instance();
791