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

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