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