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