| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Vimeography |
| 4 |
Plugin URI: https://vimeography.com |
| 5 |
Description: Vimeography is the easiest way to set up a custom Vimeo gallery on your site. |
| 6 |
Version: 2.3.0 |
| 7 |
Requires PHP: 5.3 |
| 8 |
Author: Dave Kiss |
| 9 |
Author URI: https://davekiss.com |
| 10 |
License: GPL3 |
| 11 |
Text Domain: vimeography |
| 12 |
*/ |
| 13 |
|
| 14 |
if (!function_exists('json_decode')) { |
| 15 |
wp_die(__('Vimeography requires the JSON PHP extension.', 'vimeography')); |
| 16 |
} |
| 17 |
|
| 18 |
if (!class_exists('Vimeography')) { |
| 19 |
class Vimeography |
| 20 |
{ |
| 21 |
/** |
| 22 |
* The Vimeography instance |
| 23 |
* |
| 24 |
* @var object |
| 25 |
*/ |
| 26 |
private static $instance = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* Vimeography_Addons object |
| 30 |
* |
| 31 |
* @var object |
| 32 |
* @since 1.2 |
| 33 |
*/ |
| 34 |
public $addons; |
| 35 |
|
| 36 |
/** |
| 37 |
* Vimeography_Update object |
| 38 |
* |
| 39 |
* @var object |
| 40 |
* @since 1.2 |
| 41 |
*/ |
| 42 |
public $updater; |
| 43 |
|
| 44 |
/** |
| 45 |
* Creates or returns an instance of this class. |
| 46 |
* |
| 47 |
* @return Vimeography A single instance of this class. |
| 48 |
*/ |
| 49 |
public static function get_instance() |
| 50 |
{ |
| 51 |
if ( |
| 52 |
!isset(self::$instance) and !(self::$instance instanceof Vimeography) |
| 53 |
) { |
| 54 |
self::$instance = new self(); |
| 55 |
self::$instance->_define_constants(); |
| 56 |
self::$instance->_include_files(); |
| 57 |
Mustache_Autoloader::register(); |
| 58 |
|
| 59 |
if (is_admin()) { |
| 60 |
new Vimeography_Admin_Scripts(); |
| 61 |
new Vimeography_Admin_Actions(); |
| 62 |
new Vimeography_Base(); |
| 63 |
new Vimeography_Admin_Menu(); |
| 64 |
new Vimeography_Admin_Welcome(); |
| 65 |
new Vimeography_Admin_Plugins(); |
| 66 |
self::$instance->updater = new Vimeography_Update(); |
| 67 |
} |
| 68 |
|
| 69 |
// Can save these in public vars if need to access |
| 70 |
new Vimeography_Database(); |
| 71 |
new Vimeography_Deprecated(); |
| 72 |
new Vimeography_Init(); |
| 73 |
self::$instance->addons = new Vimeography_Addons(); |
| 74 |
new Vimeography_Robots(); |
| 75 |
new Vimeography_Shortcode(); |
| 76 |
|
| 77 |
new \Vimeography\Logger(); |
| 78 |
|
| 79 |
new \Vimeography\Api\Galleries(); |
| 80 |
new \Vimeography\Api\Themes(); |
| 81 |
} |
| 82 |
|
| 83 |
return self::$instance; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Empty constructor… boring. |
| 88 |
*/ |
| 89 |
public function __construct() |
| 90 |
{ |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Define all of the constants used throughout the plugin. |
| 95 |
* |
| 96 |
* @return void |
| 97 |
*/ |
| 98 |
private function _define_constants() |
| 99 |
{ |
| 100 |
global $wpdb; |
| 101 |
|
| 102 |
if ( |
| 103 |
!isset($wpdb->vimeography_gallery) && |
| 104 |
!isset($wpdb->vimeography_gallery_meta) |
| 105 |
) { |
| 106 |
$wpdb->vimeography_gallery = $wpdb->prefix . 'vimeography_gallery'; |
| 107 |
$wpdb->vimeography_gallery_meta = |
| 108 |
$wpdb->prefix . 'vimeography_gallery_meta'; |
| 109 |
} |
| 110 |
|
| 111 |
define('VIMEOGRAPHY_URL', plugin_dir_url(__FILE__)); |
| 112 |
define('VIMEOGRAPHY_PATH', plugin_dir_path(__FILE__)); |
| 113 |
define('VIMEOGRAPHY_ASSETS_URL', VIMEOGRAPHY_URL . 'lib/shared/assets/'); |
| 114 |
define( |
| 115 |
'VIMEOGRAPHY_ASSETS_PATH', |
| 116 |
VIMEOGRAPHY_PATH . 'lib/shared/assets/' |
| 117 |
); |
| 118 |
define('VIMEOGRAPHY_CACHE_PATH', WP_CONTENT_DIR . '/vimeography/cache/'); |
| 119 |
define( |
| 120 |
'VIMEOGRAPHY_CUSTOMIZATIONS_PATH', |
| 121 |
WP_CONTENT_DIR . '/vimeography/assets/css/' |
| 122 |
); |
| 123 |
define( |
| 124 |
'VIMEOGRAPHY_CUSTOMIZATIONS_URL', |
| 125 |
content_url() . '/vimeography/assets/css/' |
| 126 |
); |
| 127 |
define('VIMEOGRAPHY_BASENAME', plugin_basename(__FILE__)); |
| 128 |
define('VIMEOGRAPHY_VERSION', '2.3.0'); |
| 129 |
define('VIMEOGRAPHY_CURRENT_PAGE', basename($_SERVER['PHP_SELF'])); |
| 130 |
define('VIMEOGRAPHY_ACCESS_TOKEN', 'eaf47146f04b5550a3e394f3bbf8273f'); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Include the files required by Vimeography. |
| 135 |
* @return [type] |
| 136 |
*/ |
| 137 |
private function _include_files() |
| 138 |
{ |
| 139 |
require_once VIMEOGRAPHY_PATH . 'lib/exception.php'; |
| 140 |
|
| 141 |
// Require Mustache.php |
| 142 |
if (!class_exists('Mustache_Engine')) { |
| 143 |
require_once VIMEOGRAPHY_PATH . |
| 144 |
'/vendor/mustache/mustache/src/Mustache/Autoloader.php'; |
| 145 |
} |
| 146 |
|
| 147 |
if (!class_exists('\Vimeography\Vimeo')) { |
| 148 |
require_once VIMEOGRAPHY_PATH . |
| 149 |
'vendor/vimeo/vimeo-api/src/Vimeo/Vimeo.php'; |
| 150 |
require_once VIMEOGRAPHY_PATH . |
| 151 |
'vendor/vimeo/vimeo-api/src/Vimeo/Exceptions/ExceptionInterface.php'; |
| 152 |
require_once VIMEOGRAPHY_PATH . |
| 153 |
'vendor/vimeo/vimeo-api/src/Vimeo/Exceptions/VimeoRequestException.php'; |
| 154 |
require_once VIMEOGRAPHY_PATH . |
| 155 |
'vendor/vimeo/vimeo-api/src/Vimeo/Exceptions/VimeoUploadException.php'; |
| 156 |
} |
| 157 |
|
| 158 |
require_once VIMEOGRAPHY_PATH . 'lib/database.php'; |
| 159 |
require_once VIMEOGRAPHY_PATH . 'lib/deprecated/deprecated.php'; |
| 160 |
require_once VIMEOGRAPHY_PATH . 'lib/addons.php'; |
| 161 |
require_once VIMEOGRAPHY_PATH . 'lib/rewrite.php'; |
| 162 |
require_once VIMEOGRAPHY_PATH . 'lib/filesystem.php'; |
| 163 |
require_once VIMEOGRAPHY_PATH . 'lib/init.php'; |
| 164 |
require_once VIMEOGRAPHY_PATH . 'lib/robots.php'; |
| 165 |
|
| 166 |
require_once VIMEOGRAPHY_PATH . 'lib/engine.php'; |
| 167 |
require_once VIMEOGRAPHY_PATH . 'lib/shortcode.php'; |
| 168 |
|
| 169 |
require_once VIMEOGRAPHY_PATH . 'lib/logger.php'; |
| 170 |
require_once VIMEOGRAPHY_PATH . 'lib/api/galleries.php'; |
| 171 |
require_once VIMEOGRAPHY_PATH . 'lib/api/themes.php'; |
| 172 |
|
| 173 |
require_once VIMEOGRAPHY_PATH . |
| 174 |
'vimeography-bugsauce/vimeography-bugsauce.php'; |
| 175 |
require_once VIMEOGRAPHY_PATH . |
| 176 |
'vimeography-harvestone/vimeography-harvestone.php'; |
| 177 |
|
| 178 |
if (is_admin()) { |
| 179 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/scripts.php'; |
| 180 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/actions.php'; |
| 181 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/base.php'; |
| 182 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/menu.php'; |
| 183 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/welcome.php'; |
| 184 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/plugins.php'; |
| 185 |
require_once VIMEOGRAPHY_PATH . 'lib/update.php'; |
| 186 |
|
| 187 |
// Gallery block |
| 188 |
require_once VIMEOGRAPHY_PATH . |
| 189 |
'lib/admin/blocks/vimeography-gallery/vimeography-gallery.php'; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Checks if the provided Vimeo URL is valid and if so, returns a |
| 195 |
* string to be used as the collection endpoint. |
| 196 |
* |
| 197 |
* @param string $source_url Source collection of Vimeo videos. |
| 198 |
* @return string Vimeo Resource |
| 199 |
*/ |
| 200 |
public static function validate_vimeo_source($source_url) |
| 201 |
{ |
| 202 |
// Add scheme if it wasn't provided in source url |
| 203 |
$scheme = parse_url($source_url); |
| 204 |
|
| 205 |
if (empty($scheme['scheme'])) { |
| 206 |
$source_url = 'https://' . $source_url; |
| 207 |
} |
| 208 |
|
| 209 |
// Only continue if the parse_url function didn't fail |
| 210 |
// and the host is one of vimeo.com or vimeopro.com |
| 211 |
if ( |
| 212 |
($url = parse_url($source_url)) !== false && |
| 213 |
preg_match('~vimeo(?:pro)?\.com$~', $url['host']) > 0 |
| 214 |
) { |
| 215 |
$host = $url['host']; |
| 216 |
|
| 217 |
$url['path'] = str_replace('/manage', '', $url['path']); |
| 218 |
|
| 219 |
// Create an array with the resource parts |
| 220 |
$url = array_values(array_filter(explode('/', $url['path']), 'strlen')); |
| 221 |
|
| 222 |
// If the array doesn't contain one of the following strings, it |
| 223 |
// must be either a user or a video |
| 224 |
if ( |
| 225 |
in_array($url[0], array( |
| 226 |
'album', |
| 227 |
'albums', |
| 228 |
'showcase', |
| 229 |
'showcases', |
| 230 |
'channels', |
| 231 |
'groups', |
| 232 |
'categories', |
| 233 |
'tags' |
| 234 |
)) !== true |
| 235 |
) { |
| 236 |
if (is_numeric($url[0])) { |
| 237 |
array_unshift($url, 'videos'); |
| 238 |
} else { |
| 239 |
array_unshift($url, 'users'); |
| 240 |
if (isset($url[2])) { |
| 241 |
if ($host != 'vimeo.com') { |
| 242 |
// Convert /users/username/portfolio_name to /users/username/portfolios/portfolio_name |
| 243 |
array_splice($url, 2, 0, array('portfolios')); |
| 244 |
} elseif ($url[2] === 'videos') { |
| 245 |
// Remove 'videos' from '/users/username/videos' |
| 246 |
unset($url[2]); |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
// Make sure the resource is plural |
| 253 |
$url[0] = rtrim($url[0], 's') . 's'; |
| 254 |
$resource = '/' . implode('/', $url); |
| 255 |
|
| 256 |
return $resource; |
| 257 |
} else { |
| 258 |
throw new Vimeography_Exception( |
| 259 |
__( |
| 260 |
'That site doesn\'t look like a valid link to a Vimeo collection.', |
| 261 |
'vimeography' |
| 262 |
) |
| 263 |
); |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
Vimeography::get_instance(); |
| 270 |
|