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

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