PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.3.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.3.0
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Core.php
embedpress / EmbedPress Last commit date
AMP 7 years ago Ends 7 years ago Plugins 7 years ago Providers 7 years ago ThirdParty 7 years ago AutoLoader.php 7 years ago Compatibility.php 7 years ago Core.php 7 years ago CoreLegacy.php 7 years ago DisablerLegacy.php 7 years ago Loader.php 7 years ago RestAPI.php 7 years ago Shortcode.php 7 years ago index.html 7 years ago
Core.php
564 lines
1 <?php
2
3 namespace EmbedPress;
4
5 use EmbedPress\Ends\Back\Handler as EndHandlerAdmin;
6 use EmbedPress\Ends\Front\Handler as EndHandlerPublic;
7
8 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
9
10 /**
11 * Entity that glues together all pieces that the plugin is made of, for WordPress 5+.
12 *
13 * @package EmbedPress
14 * @author EmbedPress <help@embedpress.com>
15 * @copyright Copyright (C) 2018 EmbedPress. All rights reserved.
16 * @license GPLv2 or later
17 * @since 1.0.0
18 */
19 class Core
20 {
21 /**
22 * The name of the plugin.
23 *
24 * @since 1.0.0
25 * @access protected
26 *
27 * @var string $pluginName The name of the plugin.
28 */
29 protected $pluginName;
30
31 /**
32 * The version of the plugin.
33 *
34 * @since 1.0.0
35 * @access protected
36 *
37 * @var string $pluginVersion The version of the plugin.
38 */
39 protected $pluginVersion;
40
41 /**
42 * An instance of the plugin loader.
43 *
44 * @since 1.0.0
45 * @access protected
46 *
47 * @var \EmbedPress\Loader $pluginVersion The version of the plugin.
48 */
49 protected $loaderInstance;
50
51 /**
52 * An associative array storing all registered/active EmbedPress plugins and their namespaces.
53 *
54 * @since 1.4.0
55 * @access private
56 * @static
57 *
58 * @var array
59 */
60 private static $plugins = [];
61
62 /**
63 * Initialize the plugin and set its properties.
64 *
65 * @since 1.0.0
66 *
67 * @return void
68 */
69 public function __construct()
70 {
71 $this->pluginName = EMBEDPRESS_PLG_NAME;
72 $this->pluginVersion = EMBEDPRESS_VERSION;
73
74 $this->loaderInstance = new Loader();
75 }
76
77 /**
78 * Method that retrieves the plugin name.
79 *
80 * @since 1.0.0
81 *
82 * @return string
83 */
84 public function getPluginName()
85 {
86 return $this->pluginName;
87 }
88
89 /**
90 * Method that retrieves the plugin version.
91 *
92 * @since 1.0.0
93 *
94 * @return string
95 */
96 public function getPluginVersion()
97 {
98 return $this->pluginVersion;
99 }
100
101 /**
102 * Method that retrieves the loader instance.
103 *
104 * @since 1.0.0
105 *
106 * @return \EmbedPress\Loader
107 */
108 public function getLoader()
109 {
110 return $this->loaderInstance;
111 }
112
113 /**
114 * Method responsible to connect all required hooks in order to make the plugin work.
115 *
116 * @since 1.0.0
117 *
118 * @return void
119 */
120 public function initialize()
121 {
122 global $wp_actions;
123
124 add_filter('oembed_providers', [$this, 'addOEmbedProviders']);
125 add_action('rest_api_init', [$this, 'registerOEmbedRestRoutes']);
126
127 if (is_admin()) {
128 $plgSettings = self::getSettings();
129
130 $settingsClassNamespace = '\\EmbedPress\\Ends\\Back\\Settings';
131 add_action('admin_menu', [$settingsClassNamespace, 'registerMenuItem']);
132 add_action('admin_init', [$settingsClassNamespace, 'registerActions']);
133 unset($settingsClassNamespace);
134
135 add_filter('plugin_action_links_embedpress/embedpress.php', ['\\EmbedPress\\Core', 'handleActionLinks'], 10,
136 2);
137
138 add_action('admin_enqueue_scripts', ['\\EmbedPress\\Ends\\Back\\Handler', 'enqueueStyles']);
139
140 $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
141
142 if ((bool)$plgSettings->enablePluginInAdmin) {
143 $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
144 }
145 } else {
146 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
147
148 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts');
149 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles');
150
151 unset($plgHandlerPublicInstance);
152 }
153
154 // Add support for embeds on AMP pages
155 add_filter('pp_embed_parsed_content', ['\\EmbedPress\\AMP\\EmbedHandler', 'processParsedContent'], 10, 3);
156
157 // Add support for our embeds on Beaver Builder. Without this it only run the native embeds.
158 add_filter('fl_builder_before_render_shortcodes',
159 ['\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes']);
160
161 $this->loaderInstance->run();
162 }
163
164 /**
165 * @param $providers
166 *
167 * @return mixed
168 */
169 public function addOEmbedProviders($providers)
170 {
171 $newProviders = [
172 // Viddler
173 '#https?://(.+\.)?viddler\.com/v/.+#i' => 'viddler',
174
175 // Deviantart.com (http://www.deviantart.com)
176 '#https?://(.+\.)?deviantart\.com/art/.+#i' => 'devianart',
177 '#https?://(.+\.)?deviantart\.com/.+#i' => 'devianart',
178 '#https?://(.+\.)?deviantart\.com/.*/d.+#i' => 'devianart',
179 '#https?://(.+\.)?fav\.me/.+#i' => 'devianart',
180 '#https?://(.+\.)?sta\.sh/.+#i' => 'devianart',
181
182 // chirbit.com (http://www.chirbit.com/)
183 '#https?://(.+\.)?chirb\.it/.+#i' => 'chirbit',
184
185
186 // nfb.ca (http://www.nfb.ca/)
187 '#https?://(.+\.)?nfb\.ca/film/.+#i' => 'nfb',
188
189 // Dotsub (http://dotsub.com/)
190 '#https?://(.+\.)?dotsub\.com/view/.+#i' => 'dotsub',
191
192 // Rdio (http://rdio.com/)
193 '#https?://(.+\.)?rdio\.com/(artist|people)/.+#i' => 'rdio',
194
195 // Sapo Videos (http://videos.sapo.pt)
196 '#https?://(.+\.)?videos\.sapo\.pt/.+#i' => 'sapo',
197
198 // Official FM (http://official.fm)
199 '#https?://(.+\.)?official\.fm/(tracks|playlists)/.+#i' => 'officialfm',
200
201 // HuffDuffer (http://huffduffer.com)
202 '#https?://(.+\.)?huffduffer\.com/.+#i' => 'huffduffer',
203
204 // Shoudio (http://shoudio.com)
205 '#https?://(.+\.)?shoudio\.(com|io)/.+#i' => 'shoudio',
206
207 // Moby Picture (http://www.mobypicture.com)
208 '#https?://(.+\.)?mobypicture\.com/user/.+/view/.+#i' => 'mobypicture',
209 '#https?://(.+\.)?moby\.to/.+#i',
210
211 // 23HQ (http://www.23hq.com)
212 '#https?://(.+\.)?23hq\.com/.+/photo/.+#i' => '23hq',
213
214 // Cacoo (https://cacoo.com)
215 '#https?://(.+\.)?cacoo\.com/diagrams/.+#i' => 'cacoo',
216
217 // Dipity (http://www.dipity.com)
218 '#https?://(.+\.)?dipity\.com/.+#i' => 'dipity',
219
220 // Roomshare (http://roomshare.jp)
221 '#https?://(.+\.)?roomshare\.jp/(en/)?post/.+#i' => 'roomshare',
222
223 // Crowd Ranking (http://crowdranking.com)
224 '#https?://(.+\.)?c9ng\.com/.+#i' => 'crowd',
225
226 // CircuitLab (https://www.circuitlab.com/)
227 '#https?://(.+\.)?circuitlab\.com/circuit/.+#i' => 'circuitlab',
228
229 // Coub (http://coub.com/)
230 '#https?://(.+\.)?coub\.com/(view|embed)/.+#i' => 'coub',
231
232 // Ustream (http://www.ustream.tv)
233 '#https?://(.+\.)?ustream\.(tv|com)/.+#i' => 'ustream',
234
235 // Daily Mile (http://www.dailymile.com)
236 '#https?://(.+\.)?dailymile\.com/people/.+/entries/.+#i' => 'daily',
237
238 // Sketchfab (http://sketchfab.com)
239 '#https?://(.+\.)?sketchfab\.com/models/.+#i' => 'sketchfab',
240 '#https?://(.+\.)?sketchfab\.com/.+/folders/.+#i' => 'sketchfab',
241
242 // AudioSnaps (http://audiosnaps.com)
243 '#https?://(.+\.)?audiosnaps\.com/k/.+#i' => 'audiosnaps',
244
245 // RapidEngage (https://rapidengage.com)
246 '#https?://(.+\.)?rapidengage\.com/s/.+#i' => 'rapidengage',
247
248 // Getty Images (http://www.gettyimages.com/)
249 '#https?://(.+\.)?gty\.im/.+#i' => 'gettyimages',
250 '#https?://(.+\.)?gettyimages\.com/detail/photo/.+#i' => 'gettyimages',
251
252 // amCharts Live Editor (http://live.amcharts.com/)
253 '#https?://(.+\.)?live\.amcharts\.com/.+#i' => 'amcharts',
254
255 // Infogram (https://infogr.am/)
256 '#https?://(.+\.)?infogr\.am/.+#i' => 'infogram',
257
258 // ChartBlocks (http://www.chartblocks.com/)
259 '#https?://(.+\.)?public\.chartblocks\.com/c/.+#i' => 'chartblocks',
260
261 // ReleaseWire (http://www.releasewire.com/)
262 '#https?://(.+\.)?rwire\.com/.+#i' => 'releasewire',
263
264 // ShortNote (https://www.shortnote.jp/)
265 '#https?://(.+\.)?shortnote\.jp/view/notes/.+#i' => 'shortnote',
266
267 // EgliseInfo (http://egliseinfo.catholique.fr/)
268 '#https?://(.+\.)?egliseinfo\.catholique\.fr/.+#i' => 'egliseinfo',
269
270 // Silk (http://www.silk.co/)
271 '#https?://(.+\.)?silk\.co/explore/.+#i' => 'silk',
272 '#https?://(.+\.)?silk\.co/s/embed/.+#i' => 'silk',
273
274 // http://bambuser.com
275 '#https?://(.+\.)?bambuser\.com/v/.+#i' => 'bambuser',
276
277 // https://clyp.it
278 '#https?://(.+\.)?clyp\.it/.+#i' => 'clyp',
279
280 // https://gist.github.com
281 '#https?://(.+\.)?gist\.github\.com/.+#i' => 'github',
282
283 // https://portfolium.com
284 '#https?://(.+\.)?portfolium\.com/.+#i' => 'portfolium',
285
286 // http://rutube.ru
287 '#https?://(.+\.)?rutube\.ru/video/.+#i' => 'rutube',
288
289 // http://www.videojug.com
290 '#https?://(.+\.)?videojug\.com/.+#i' => 'videojug',
291
292 // https://vine.com
293 '#https?://(.+\.)?vine\.co/v/.+#i' => 'vine',
294
295 // Google Shortened Url
296 '#https?://(.+\.)?goo\.gl/.+#i' => 'google',
297
298 // Google Maps
299 '#https?://(.+\.)?google\.com/maps/.+#i' => 'googlemaps',
300 '#https?://(.+\.)?maps\.google\.com/.+#i' => 'googlemaps',
301
302 // Google Docs
303 '#https?://(.+\.)?docs\.google\.com/(.+/)?(document|presentation|spreadsheets|forms|drawings)/.+#i' => 'googledocs',
304
305 // Twitch.tv
306 '#https?://(.+\.)?twitch\.tv/.+#i' => 'twitch',
307
308 // Giphy
309 '#https?://(.+\.)?giphy\.com/gifs/.+#i' => 'giphy',
310 '#https?://(.+\.)?i\.giphy\.com/.+#i' => 'giphy',
311 '#https?://(.+\.)?gph\.is/.+#i' => 'giphy',
312
313 // Wistia
314 '#https?://(.+\.)?wistia\.com/medias/.+#i' => 'wistia',
315 '#https?://(.+\.)?fast\.wistia\.com/embed/medias/.+#i\.jsonp' => 'wistia',
316 ];
317
318 /**
319 * ========================================
320 * Make sure the $wp_write global is set.
321 * This fix compatibility with JetPack, Classical Editor and Disable Gutenberg. JetPack makes
322 * the oembed_providers filter be called and this activates our class too, but one dependency
323 * of the rest_url method is not loaded yet.
324 */
325 global $wp_rewrite;
326
327 if ( ! class_exists('\\WP_Rewrite')) {
328 $path = ABSPATH . WPINC . '/class-wp-rewrite.php';
329 if (file_exists($path)) {
330 require_once $path;
331 }
332 }
333
334 if ( ! is_object($wp_rewrite)) {
335 $wp_rewrite = new \WP_Rewrite();
336 $_GLOBALS['wp_write'] = $wp_rewrite;
337 }
338 /*========================================*/
339
340 foreach ($newProviders as $url => &$data) {
341 $data = [
342 rest_url('embedpress/v1/oembed/' . $data),
343 true,
344 ];
345 }
346
347 $providers = array_merge($providers, $newProviders);
348
349 return $providers;
350 }
351
352 /**
353 * Register OEmbed Rest Routes
354 */
355 public function registerOEmbedRestRoutes()
356 {
357 register_rest_route(
358 'embedpress/v1', '/oembed/(?P<provider>[a-zA-Z0-9\-]+)',
359 [
360 'methods' => \WP_REST_Server::READABLE,
361 'callback' => ['\\EmbedPress\\RestAPI', 'oembed'],
362 ]
363 );
364 }
365
366 /**
367 * Callback called right after the plugin has been activated.
368 *
369 * @since 1.0.0
370 * @static
371 *
372 * @return void
373 */
374 public static function onPluginActivationCallback()
375 {
376 flush_rewrite_rules();
377 }
378
379 /**
380 * Callback called right after the plugin has been deactivated.
381 *
382 * @since 1.0.0
383 * @static
384 *
385 * @return void
386 */
387 public static function onPluginDeactivationCallback()
388 {
389 flush_rewrite_rules();
390 }
391
392 /**
393 * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file.
394 *
395 * @since 1.0.0
396 * @static
397 *
398 * @return array
399 */
400 public static function getAdditionalServiceProviders()
401 {
402 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE . 'providers.php';
403 if (file_exists($additionalProvidersFilePath)) {
404 include $additionalProvidersFilePath;
405
406 if (isset($additionalServiceProviders)) {
407 return $additionalServiceProviders;
408 }
409 }
410
411 return [];
412 }
413
414 /**
415 * Method that checks if an embed of a given service provider can be responsive.
416 *
417 * @since 1.0.0
418 * @static
419 *
420 * @param string $serviceProviderAlias The service's slug.
421 *
422 * @return boolean
423 */
424 public static function canServiceProviderBeResponsive($serviceProviderAlias)
425 {
426 return in_array($serviceProviderAlias, [
427 "dailymotion",
428 "kickstarter",
429 "rutube",
430 "ted",
431 "vimeo",
432 "youtube",
433 "ustream",
434 "google-docs",
435 "animatron",
436 "amcharts",
437 "on-aol-com",
438 "animoto",
439 "videojug",
440 'issuu',
441 ]);
442 }
443
444 /**
445 * Method that retrieves the plugin settings defined by the user.
446 *
447 * @since 1.0.0
448 * @static
449 *
450 * @return object
451 */
452 public static function getSettings()
453 {
454 $settings = get_option(EMBEDPRESS_PLG_NAME);
455
456 if ( ! isset($settings['enablePluginInAdmin'])) {
457 $settings['enablePluginInAdmin'] = true;
458 }
459
460 if ( ! isset($settings['enablePluginInFront'])) {
461 $settings['enablePluginInFront'] = true;
462 }
463
464 return (object)$settings;
465 }
466
467 /**
468 * Method that register an EmbedPress plugin.
469 *
470 * @since 1.4.0
471 * @static
472 *
473 * @param array $pluginMeta Associative array containing plugin's name, slug and namespace
474 *
475 * @return void
476 */
477 public static function registerPlugin($pluginMeta)
478 {
479 $pluginMeta = json_decode(json_encode($pluginMeta));
480
481 if (empty($pluginMeta->name) || empty($pluginMeta->slug) || empty($pluginMeta->namespace)) {
482 return;
483 }
484
485 if ( ! isset(self::$plugins[$pluginMeta->slug])) {
486 AutoLoader::register($pluginMeta->namespace,
487 WP_PLUGIN_DIR . '/' . EMBEDPRESS_PLG_NAME . '-' . $pluginMeta->slug . '/' . $pluginMeta->name);
488
489 $plugin = "{$pluginMeta->namespace}\Plugin";
490 if (\defined("{$plugin}::SLUG") && $plugin::SLUG !== null) {
491 self::$plugins[$pluginMeta->slug] = $pluginMeta->namespace;
492
493 $bsFilePath = $plugin::PATH . EMBEDPRESS_PLG_NAME . '-' . $plugin::SLUG . '.php';
494
495 register_activation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onActivationCallback']);
496 register_deactivation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onDeactivationCallback']);
497
498 add_action('admin_init', [$plugin, 'onLoadAdminCallback']);
499
500 add_action(EMBEDPRESS_PLG_NAME . ':' . $plugin::SLUG . ':settings:register',
501 [$plugin, 'registerSettings']);
502 add_action(EMBEDPRESS_PLG_NAME . ':settings:render:tab', [$plugin, 'renderTab']);
503
504 add_filter('plugin_action_links_embedpress-' . $plugin::SLUG . '/embedpress-' . $plugin::SLUG . '.php',
505 [$plugin, 'handleActionLinks'], 10, 2);
506
507 $plugin::registerEvents();
508 }
509 }
510 }
511
512 /**
513 * Retrieve all registered plugins.
514 *
515 * @since 1.4.0
516 * @static
517 *
518 * @return array
519 */
520 public static function getPlugins()
521 {
522 return self::$plugins;
523 }
524
525 /**
526 * Handle links displayed below the plugin name in the WordPress Installed Plugins page.
527 *
528 * @since 1.4.0
529 * @static
530 *
531 * @return array
532 */
533 public static function handleActionLinks($links, $file)
534 {
535 $settingsLink = '<a href="' . admin_url('admin.php?page=embedpress') . '" aria-label="' . __('Open settings page',
536 'embedpress') . '">' . __('Settings', 'embedpress') . '</a>';
537
538 array_unshift($links, $settingsLink);
539
540 return $links;
541 }
542
543 /**
544 * Method that ensures the API's url are whitelisted to WordPress external requests.
545 *
546 * @since 1.4.0
547 * @static
548 *
549 * @param boolean $isAllowed
550 * @param string $host
551 * @param string $url
552 *
553 * @return boolean
554 */
555 public static function allowApiHost($isAllowed, $host, $url)
556 {
557 if ($host === EMBEDPRESS_LICENSES_API_HOST) {
558 $isAllowed = true;
559 }
560
561 return $isAllowed;
562 }
563 }
564