PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.7.6
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.7.6
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 6 years ago Elementor 5 years ago Ends 5 years ago Includes 5 years ago Plugins 5 years ago Providers 5 years ago ThirdParty 6 years ago AutoLoader.php 6 years ago Compatibility.php 6 years ago Core.php 5 years ago CoreLegacy.php 5 years ago DisablerLegacy.php 6 years ago Loader.php 6 years ago RestAPI.php 5 years ago Shortcode.php 5 years ago index.html 7 years ago simple_html_dom.php 5 years ago
Core.php
571 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 use EmbedPress\Includes\Traits\Shared;
8
9
10 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
11
12 /**
13 * Entity that glues together all pieces that the plugin is made of, for WordPress 5+.
14 *
15 * @package EmbedPress
16 * @author EmbedPress <help@embedpress.com>
17 * @copyright Copyright (C) 2020 WPDeveloper. All rights reserved.
18 * @license GPLv3 or later
19 * @since 1.0.0
20 */
21 class Core {
22 use Shared;
23
24 /**
25 * The name of the plugin.
26 *
27 * @since 1.0.0
28 * @access protected
29 *
30 * @var string $pluginName The name of the plugin.
31 */
32 protected $pluginName;
33
34 /**
35 * The version of the plugin.
36 *
37 * @since 1.0.0
38 * @access protected
39 *
40 * @var string $pluginVersion The version of the plugin.
41 */
42 protected $pluginVersion;
43
44 /**
45 * An instance of the plugin loader.
46 *
47 * @since 1.0.0
48 * @access protected
49 *
50 * @var Loader $pluginVersion The version of the plugin.
51 */
52 protected $loaderInstance;
53
54 /**
55 * An associative array storing all registered/active EmbedPress plugins and their namespaces.
56 *
57 * @since 1.4.0
58 * @access private
59 * @static
60 *
61 * @var array
62 */
63 private static $plugins = [];
64
65 /**
66 * Initialize the plugin and set its properties.
67 *
68 * @return void
69 * @since 1.0.0
70 *
71 */
72 public function __construct () {
73 $this->pluginName = EMBEDPRESS_PLG_NAME;
74 $this->pluginVersion = EMBEDPRESS_VERSION;
75
76 $this->loaderInstance = new Loader();
77
78 add_action('admin_notices',[$this,'embedpress_admin_notice']);
79 }
80
81 /**
82 * Method that retrieves the plugin name.
83 *
84 * @return string
85 * @since 1.0.0
86 *
87 */
88 public function getPluginName () {
89 return $this->pluginName;
90 }
91
92 /**
93 * Method that retrieves the plugin version.
94 *
95 * @return string
96 * @since 1.0.0
97 *
98 */
99 public function getPluginVersion () {
100 return $this->pluginVersion;
101 }
102
103 /**
104 * Method that retrieves the loader instance.
105 *
106 * @return Loader
107 * @since 1.0.0
108 *
109 */
110 public function getLoader () {
111 return $this->loaderInstance;
112 }
113
114 /**
115 * Method responsible to connect all required hooks in order to make the plugin work.
116 *
117 * @return void
118 * @since 1.0.0
119 *
120 */
121 public function initialize () {
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 $this->admin_notice();
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 add_action('wp_ajax_embedpress_notice_dismiss', ['\\EmbedPress\\Ends\\Back\\Handler', 'embedpress_notice_dismiss']);
140
141 $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
142
143 if ((bool) $plgSettings->enablePluginInAdmin) {
144 $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
145 }
146 } else {
147 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
148
149 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts');
150 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles');
151
152 unset($plgHandlerPublicInstance);
153 }
154
155 // Add support for embeds on AMP pages
156 add_filter('pp_embed_parsed_content', ['\\EmbedPress\\AMP\\EmbedHandler', 'processParsedContent'], 10, 3);
157
158 // Add support for our embeds on Beaver Builder. Without this it only run the native embeds.
159 add_filter('fl_builder_before_render_shortcodes',
160 ['\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes']);
161 $this->start_plugin_tracking();
162 $this->loaderInstance->run();
163 }
164
165 /**
166 * @param $providers
167 *
168 * @return mixed
169 */
170 public function addOEmbedProviders ($providers) {
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' => 'mobypicture',
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 //(https://infogram.com/)
258 //'#https?://(.+\.)?infogram\.com/.+#i' => 'infogram',
259
260 // ChartBlocks (http://www.chartblocks.com/)
261 //'#https?://(.+\.)?public\.chartblocks\.com/c/.+#i' => 'chartblocks',
262
263 // ReleaseWire (http://www.releasewire.com/)
264 //'#https?://(.+\.)?rwire\.com/.+#i' => 'releasewire',
265
266 // ShortNote (https://www.shortnote.jp/)
267 //'#https?://(.+\.)?shortnote\.jp/view/notes/.+#i' => 'shortnote',
268
269 // EgliseInfo (http://egliseinfo.catholique.fr/)
270 '#https?://(.+\.)?egliseinfo\.catholique\.fr/.+#i' => 'egliseinfo',
271
272 // Silk (http://www.silk.co/)
273 '#https?://(.+\.)?silk\.co/explore/.+#i' => 'silk',
274 '#https?://(.+\.)?silk\.co/s/embed/.+#i' => 'silk',
275
276 // http://bambuser.com
277 '#https?://(.+\.)?bambuser\.com/v/.+#i' => 'bambuser',
278
279 // https://clyp.it
280 //'#https?://(.+\.)?clyp\.it/.+#i' => 'clyp',
281
282 // https://gist.github.com
283 '#https?://(.+\.)?gist\.github\.com/.+#i' => 'github',
284
285 // https://portfolium.com
286 //'#https?://(.+\.)?portfolium\.com/.+#i' => 'portfolium',
287
288 // http://rutube.ru
289 '#https?://(.+\.)?rutube\.ru/video/.+#i' => 'rutube',
290
291 // http://www.videojug.com
292 '#https?://(.+\.)?videojug\.com/.+#i' => 'videojug',
293
294 // https://vine.com
295 //'#https?://(.+\.)?vine\.co/v/.+#i' => 'vine',
296
297 // Google Shortened Url
298 '#https?://(.+\.)?goo\.gl/.+#i' => 'google',
299
300 // Google Maps
301 //'#https?://(.+\.)?google\.com/maps/.+#i' => 'googlemaps',
302 //'#https?://(.+\.)?maps\.google\.com/.+#i' => 'googlemaps',
303
304 // Google Docs
305 //'#https?://(.+\.)?docs\.google\.com/(.+/)?(document|presentation|spreadsheets|forms|drawings)/.+#i' => 'googledocs',
306
307 // Twitch.tv
308 //'#https?://(.+\.)?twitch\.tv/.+#i' => 'twitch',
309
310 // Giphy
311 //'#https?://(.+\.)?giphy\.com/gifs/.+#i' => 'giphy',
312 //'#https?://(.+\.)?i\.giphy\.com/.+#i' => 'giphy',
313 //'#https?://(.+\.)?gph\.is/.+#i' => 'giphy',
314
315 // Wistia
316 //'#https?://(.+\.)?wistia\.com/medias/.+#i' => 'wistia',
317 //'#https?://(.+\.)?fast\.wistia\.com/embed/medias/.+#i\.jsonp' => 'wistia',
318 ];
319
320 /**
321 * ========================================
322 * Make sure the $wp_write global is set.
323 * This fix compatibility with JetPack, Classical Editor and Disable Gutenberg. JetPack makes
324 * the oembed_providers filter be called and this activates our class too, but one dependency
325 * of the rest_url method is not loaded yet.
326 */
327 global $wp_rewrite;
328
329 if (!class_exists('\\WP_Rewrite')) {
330 $path = ABSPATH.WPINC.'/class-wp-rewrite.php';
331 if (file_exists($path)) {
332 require_once $path;
333 }
334 }
335
336 if (!is_object($wp_rewrite)) {
337 $wp_rewrite = new \WP_Rewrite();
338 $_GLOBALS['wp_write'] = $wp_rewrite;
339 }
340 /*========================================*/
341
342 foreach ($newProviders as $url => &$data) {
343 $data = [
344 rest_url('embedpress/v1/oembed/'.$data),
345 true,
346 ];
347 }
348
349 $providers = array_merge($providers, $newProviders);
350
351 return $providers;
352 }
353
354 /**
355 * Register OEmbed Rest Routes
356 */
357 public function registerOEmbedRestRoutes () {
358 register_rest_route(
359 'embedpress/v1', '/oembed/(?P<provider>[a-zA-Z0-9\-]+)',
360 [
361 'methods' => \WP_REST_Server::READABLE,
362 'callback' => ['\\EmbedPress\\RestAPI', 'oembed'],
363 'permission_callback' => '__return_true',
364 ]
365 );
366 }
367
368 /**
369 * Callback called right after the plugin has been activated.
370 *
371 * @return void
372 * @since 1.0.0
373 * @static
374 *
375 */
376 public static function onPluginActivationCallback () {
377 flush_rewrite_rules();
378 }
379
380 /**
381 * Callback called right after the plugin has been deactivated.
382 *
383 * @return void
384 * @since 1.0.0
385 * @static
386 *
387 */
388 public static function onPluginDeactivationCallback () {
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 * @return array
396 * @since 1.0.0
397 * @static
398 *
399 */
400 public static function getAdditionalServiceProviders () {
401 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE.'providers.php';
402 if (file_exists($additionalProvidersFilePath)) {
403 include $additionalProvidersFilePath;
404
405 if (isset($additionalServiceProviders)) {
406 return $additionalServiceProviders;
407 }
408 }
409
410 return [];
411 }
412
413 /**
414 * Method that checks if an embed of a given service provider can be responsive.
415 *
416 * @param string $serviceProviderAlias The service's slug.
417 *
418 * @return boolean
419 * @since 1.0.0
420 * @static
421 *
422 */
423 public static function canServiceProviderBeResponsive ($serviceProviderAlias) {
424 return in_array($serviceProviderAlias, [
425 "dailymotion",
426 "kickstarter",
427 "rutube",
428 "ted",
429 "vimeo",
430 "youtube",
431 "ustream",
432 "google-docs",
433 "animatron",
434 "amcharts",
435 "on-aol-com",
436 "animoto",
437 "videojug",
438 'issuu',
439 ]);
440 }
441
442 /**
443 * Method that retrieves the plugin settings defined by the user.
444 *
445 * @return object
446 * @since 1.0.0
447 * @static
448 *
449 */
450 public static function getSettings () {
451 $settings = get_option(EMBEDPRESS_PLG_NAME);
452
453 if (!isset($settings['enablePluginInAdmin'])) {
454 $settings['enablePluginInAdmin'] = true;
455 }
456
457 if (!isset($settings['enablePluginInFront'])) {
458 $settings['enablePluginInFront'] = true;
459 }
460
461 if (!isset($settings['enableGlobalEmbedResize'])) {
462 $settings['enableGlobalEmbedResize'] = false;
463 }
464
465 if (!isset($settings['enableEmbedResizeHeight'])) {
466 $settings['enableEmbedResizeHeight'] = 552;
467 }
468
469 if (!isset($settings['enableEmbedResizeWidth'])) {
470 $settings['enableEmbedResizeWidth'] = 652;
471 }
472
473 return (object) $settings;
474 }
475
476 /**
477 * Method that register an EmbedPress plugin.
478 *
479 * @param array $pluginMeta Associative array containing plugin's name, slug and namespace
480 *
481 * @return void
482 * @since 1.4.0
483 * @static
484 *
485 */
486 public static function registerPlugin ($pluginMeta) {
487 $pluginMeta = json_decode(json_encode($pluginMeta));
488
489 if (empty($pluginMeta->name) || empty($pluginMeta->slug) || empty($pluginMeta->namespace)) {
490 return;
491 }
492
493 if (!isset(self::$plugins[$pluginMeta->slug])) {
494 AutoLoader::register($pluginMeta->namespace,
495 WP_PLUGIN_DIR.'/'.EMBEDPRESS_PLG_NAME.'-'.$pluginMeta->slug.'/'.$pluginMeta->name);
496
497 $plugin = "{$pluginMeta->namespace}\Plugin";
498 if (\defined("{$plugin}::SLUG") && $plugin::SLUG !== null) {
499 self::$plugins[$pluginMeta->slug] = $pluginMeta->namespace;
500
501 $bsFilePath = $plugin::PATH.EMBEDPRESS_PLG_NAME.'-'.$plugin::SLUG.'.php';
502
503 register_activation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onActivationCallback']);
504 register_deactivation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onDeactivationCallback']);
505
506 add_action('admin_init', [$plugin, 'onLoadAdminCallback']);
507
508 add_action(EMBEDPRESS_PLG_NAME.':'.$plugin::SLUG.':settings:register',
509 [$plugin, 'registerSettings']);
510 add_action(EMBEDPRESS_PLG_NAME.':settings:render:tab', [$plugin, 'renderTab']);
511
512 add_filter('plugin_action_links_embedpress-'.$plugin::SLUG.'/embedpress-'.$plugin::SLUG.'.php',
513 [$plugin, 'handleActionLinks'], 10, 2);
514
515 $plugin::registerEvents();
516 }
517 }
518 }
519
520 /**
521 * Retrieve all registered plugins.
522 *
523 * @return array
524 * @since 1.4.0
525 * @static
526 *
527 */
528 public static function getPlugins () {
529 return self::$plugins;
530 }
531
532 /**
533 * Handle links displayed below the plugin name in the WordPress Installed Plugins page.
534 *
535 * @return array
536 * @since 1.4.0
537 * @static
538 *
539 */
540 public static function handleActionLinks ($links, $file) {
541 $settingsLink = '<a href="'.admin_url('admin.php?page=embedpress').'" aria-label="'.__('Open settings page',
542 'embedpress').'">'.__('Settings', 'embedpress').'</a>';
543
544 array_unshift($links, $settingsLink);
545
546 return $links;
547 }
548
549 /**
550 * Method that ensures the API's url are whitelisted to WordPress external requests.
551 *
552 * @param boolean $isAllowed
553 * @param string $host
554 * @param string $url
555 *
556 * @return boolean
557 * @since 1.4.0
558 * @static
559 *
560 */
561 public static function allowApiHost ($isAllowed, $host, $url) {
562 if ($host === EMBEDPRESS_LICENSES_API_HOST) {
563 $isAllowed = true;
564 }
565
566 return $isAllowed;
567 }
568
569
570 }
571