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