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