PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.4.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.4.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 6 years ago Elementor 4 years ago Ends 4 years ago Includes 4 years ago Plugins 4 years ago Providers 5 years ago ThirdParty 4 years ago AutoLoader.php 6 years ago Compatibility.php 6 years ago Core.php 4 years ago CoreLegacy.php 4 years ago DisablerLegacy.php 6 years ago Loader.php 6 years ago RestAPI.php 5 years ago Shortcode.php 4 years ago index.html 7 years ago simple_html_dom.php 4 years ago
Core.php
541 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
82 /**
83 * Method that retrieves the plugin name.
84 *
85 * @return string
86 * @since 1.0.0
87 *
88 */
89 public function getPluginName () {
90 return $this->pluginName;
91 }
92
93 /**
94 * Method that retrieves the plugin version.
95 *
96 * @return string
97 * @since 1.0.0
98 *
99 */
100 public function getPluginVersion () {
101 return $this->pluginVersion;
102 }
103
104 /**
105 * Method that retrieves the loader instance.
106 *
107 * @return Loader
108 * @since 1.0.0
109 *
110 */
111 public function getLoader () {
112 return $this->loaderInstance;
113 }
114
115 /**
116 * Method responsible to connect all required hooks in order to make the plugin work.
117 *
118 * @return void
119 * @since 1.0.0
120 *
121 */
122 public function initialize () {
123 global $wp_actions;
124 add_filter('oembed_providers', [$this, 'addOEmbedProviders']);
125 add_action('rest_api_init', [$this, 'registerOEmbedRestRoutes']);
126
127 $this->start_plugin_tracking();
128
129 if (is_admin()) {
130 new EmbedpressSettings();
131 $plgSettings = self::getSettings();
132 $this->admin_notice();
133 add_filter('plugin_action_links_embedpress/embedpress.php', ['\\EmbedPress\\Core', 'handleActionLinks'], 10,
134 2);
135
136 add_action('admin_enqueue_scripts', ['\\EmbedPress\\Ends\\Back\\Handler', 'enqueueStyles']);
137 add_action('wp_ajax_embedpress_notice_dismiss', ['\\EmbedPress\\Ends\\Back\\Handler', 'embedpress_notice_dismiss']);
138
139 $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
140
141 if ( $plgSettings->enablePluginInAdmin ) {
142 $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
143 }
144 } else {
145 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
146
147 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts');
148 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles');
149
150 unset($plgHandlerPublicInstance);
151 }
152
153 // Add support for embeds on AMP pages
154 add_filter('pp_embed_parsed_content', ['\\EmbedPress\\AMP\\EmbedHandler', 'processParsedContent'], 10, 3);
155
156 // Add support for our embeds on Beaver Builder. Without this it only run the native embeds.
157 add_filter('fl_builder_before_render_shortcodes',
158 ['\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes']);
159 $this->loaderInstance->run();
160
161 }
162
163 /**
164 * @param $providers
165 *
166 * @return mixed
167 */
168 public function addOEmbedProviders ($providers) {
169 $newProviders = [
170 // Viddler
171 '#https?://(.+\.)?viddler\.com/v/.+#i' => 'viddler',
172
173 // Deviantart.com (http://www.deviantart.com)
174 // '#https?://(.+\.)?deviantart\.com/art/.+#i' => 'devianart',
175 // '#https?://(.+\.)?deviantart\.com/.+#i' => 'devianart',
176 // '#https?://(.+\.)?deviantart\.com/.*/d.+#i' => 'devianart',
177 // '#https?://(.+\.)?fav\.me/.+#i' => 'devianart',
178 // '#https?://(.+\.)?sta\.sh/.+#i' => 'devianart',
179
180 // chirbit.com (http://www.chirbit.com/)
181 //'#https?://(.+\.)?chirb\.it/.+#i' => 'chirbit',
182
183
184 // nfb.ca (http://www.nfb.ca/)
185 //'#https?://(.+\.)?nfb\.ca/film/.+#i' => 'nfb',
186
187 // Dotsub (http://dotsub.com/)
188 //'#https?://(.+\.)?dotsub\.com/view/.+#i' => 'dotsub',
189
190 // Rdio (http://rdio.com/)
191 '#https?://(.+\.)?rdio\.com/(artist|people)/.+#i' => 'rdio',
192
193 // Sapo Videos (http://videos.sapo.pt)
194 //'#https?://(.+\.)?videos\.sapo\.pt/.+#i' => 'sapo',
195
196 // Official FM (http://official.fm)
197 '#https?://(.+\.)?official\.fm/(tracks|playlists)/.+#i' => 'officialfm',
198
199 // HuffDuffer (http://huffduffer.com)
200 //'#https?://(.+\.)?huffduffer\.com/.+#i' => 'huffduffer',
201
202 // Shoudio (http://shoudio.com)
203 //'#https?://(.+\.)?shoudio\.(com|io)/.+#i' => 'shoudio',
204
205 // Moby Picture (http://www.mobypicture.com)
206 '#https?://(.+\.)?mobypicture\.com/user/.+/view/.+#i' => 'mobypicture',
207 '#https?://(.+\.)?moby\.to/.+#i' => 'mobypicture',
208
209 // 23HQ (http://www.23hq.com)
210 //'#https?://(.+\.)?23hq\.com/.+/photo/.+#i' => '23hq',
211
212 // Cacoo (https://cacoo.com)
213 '#https?://(.+\.)?cacoo\.com/diagrams/.+#i' => 'cacoo',
214
215 // Dipity (http://www.dipity.com)
216 '#https?://(.+\.)?dipity\.com/.+#i' => 'dipity',
217
218 // Roomshare (http://roomshare.jp)
219 //'#https?://(.+\.)?roomshare\.jp/(en/)?post/.+#i' => 'roomshare',
220
221 // Crowd Ranking (http://crowdranking.com)
222 '#https?://(.+\.)?c9ng\.com/.+#i' => 'crowd',
223
224 // CircuitLab (https://www.circuitlab.com/)
225 //'#https?://(.+\.)?circuitlab\.com/circuit/.+#i' => 'circuitlab',
226
227 // Coub (http://coub.com/)
228 //'#https?://(.+\.)?coub\.com/(view|embed)/.+#i' => 'coub',
229
230 // Ustream (http://www.ustream.tv)
231 //'#https?://(.+\.)?ustream\.(tv|com)/.+#i' => 'ustream',
232
233 // Daily Mile (http://www.dailymile.com)
234 '#https?://(.+\.)?dailymile\.com/people/.+/entries/.+#i' => 'daily',
235
236 // Sketchfab (http://sketchfab.com)
237 '#https?://(.+\.)?sketchfab\.com/models/.+#i' => 'sketchfab',
238 '#https?://(.+\.)?sketchfab\.com/.+/folders/.+#i' => 'sketchfab',
239
240 // AudioSnaps (http://audiosnaps.com)
241 '#https?://(.+\.)?audiosnaps\.com/k/.+#i' => 'audiosnaps',
242
243 // RapidEngage (https://rapidengage.com)
244 '#https?://(.+\.)?rapidengage\.com/s/.+#i' => 'rapidengage',
245
246 // Getty Images (http://www.gettyimages.com/)
247 //'#https?://(.+\.)?gty\.im/.+#i' => 'gettyimages',
248 //'#https?://(.+\.)?gettyimages\.com/detail/photo/.+#i' => 'gettyimages',
249
250 // amCharts Live Editor (http://live.amcharts.com/)
251 //'#https?://(.+\.)?live\.amcharts\.com/.+#i' => 'amcharts',
252
253 // Infogram (https://infogr.am/)
254 //'#https?://(.+\.)?infogr\.am/.+#i' => 'infogram',
255 //(https://infogram.com/)
256 //'#https?://(.+\.)?infogram\.com/.+#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 register_rest_route(
357 'embedpress/v1', '/oembed/(?P<provider>[a-zA-Z0-9\-]+)',
358 [
359 'methods' => \WP_REST_Server::READABLE,
360 'callback' => ['\\EmbedPress\\RestAPI', 'oembed'],
361 'permission_callback' => '__return_true',
362 ]
363 );
364 }
365
366 /**
367 * Callback called right after the plugin has been activated.
368 *
369 * @return void
370 * @since 1.0.0
371 * @static
372 *
373 */
374 public static function onPluginActivationCallback () {
375 $dirname = wp_get_upload_dir()['basedir'].'/embedpress';
376 if (!file_exists($dirname)) {
377 mkdir($dirname, 0777);
378 }
379 flush_rewrite_rules();
380 embedpress_schedule_cache_cleanup();
381 }
382
383 /**
384 * Callback called right after the plugin has been deactivated.
385 *
386 * @return void
387 * @since 1.0.0
388 * @static
389 *
390 */
391 public static function onPluginDeactivationCallback () {
392 flush_rewrite_rules();
393 embedpress_cache_cleanup();
394 $timestamp = wp_next_scheduled( 'embedpress_backup_cleanup_action' );
395 if ( $timestamp ) {
396 wp_unschedule_event( $timestamp, 'embedpress_backup_cleanup_action' );
397 }
398 }
399
400 /**
401 * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file.
402 *
403 * @return array
404 * @since 1.0.0
405 * @static
406 *
407 */
408 public static function getAdditionalServiceProviders () {
409 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE.'providers.php';
410 if (file_exists($additionalProvidersFilePath)) {
411 include $additionalProvidersFilePath;
412
413 if (isset($additionalServiceProviders)) {
414 return apply_filters( 'embedpress_additional_service_providers', $additionalServiceProviders);
415 }
416 }
417
418 return apply_filters( 'embedpress_additional_service_providers', []);
419
420 }
421
422 /**
423 * Method that checks if an embed of a given service provider can be responsive.
424 *
425 * @param string $serviceProviderAlias The service's slug.
426 *
427 * @return boolean
428 * @since 1.0.0
429 * @static
430 *
431 */
432 public static function canServiceProviderBeResponsive ($serviceProviderAlias) {
433 return in_array($serviceProviderAlias, [
434 "dailymotion",
435 "kickstarter",
436 "rutube",
437 "ted",
438 "vimeo",
439 "youtube",
440 "ustream",
441 "google-docs",
442 "animatron",
443 "amcharts",
444 "on-aol-com",
445 "animoto",
446 "videojug",
447 'issuu',
448 ]);
449 }
450
451 /**
452 * Method that retrieves the plugin settings defined by the user.
453 *
454 * @return object
455 * @since 1.0.0
456 * @static
457 *
458 */
459 public static function getSettings () {
460 $settings = get_option(EMBEDPRESS_PLG_NAME);
461
462 if (!isset($settings['enablePluginInAdmin'])) {
463 $settings['enablePluginInAdmin'] = true;
464 }
465
466 if (!isset($settings['enablePluginInFront'])) {
467 $settings['enablePluginInFront'] = true;
468 }
469
470 if (!isset($settings['enableGlobalEmbedResize'])) {
471 $settings['enableGlobalEmbedResize'] = false;
472 }
473
474 if (!isset($settings['enableEmbedResizeHeight'])) {
475 $settings['enableEmbedResizeHeight'] = 550; // old 552
476 }
477
478 if (!isset($settings['enableEmbedResizeWidth'])) {
479 $settings['enableEmbedResizeWidth'] = 600; // old 652
480 }
481
482 return (object) $settings;
483 }
484
485
486 /**
487 * Retrieve all registered plugins.
488 *
489 * @return array
490 * @since 1.4.0
491 * @static
492 *
493 */
494 public static function getPlugins () {
495 return self::$plugins;
496 }
497
498 /**
499 * Handle links displayed below the plugin name in the WordPress Installed Plugins page.
500 *
501 * @return array
502 * @since 1.4.0
503 * @static
504 *
505 */
506 public static function handleActionLinks($links, $file)
507 {
508 $settingsLink = '<a href="' . admin_url('admin.php?page=embedpress') . '" aria-label="' . __('Open settings page',
509 'embedpress') . '">' . __('Settings', 'embedpress') . '</a>';
510
511 array_unshift($links, $settingsLink);
512 if ( !is_embedpress_pro_active() ) {
513 $links[] = '<a href="https://wpdeveloper.com/in/upgrade-embedpress" target="_blank" class="embedpress-go-pro-action" style="color: green">'.__('Go Pro', 'embedpress').'</a>';
514 }
515 return $links;
516 }
517
518
519 /**
520 * Method that ensures the API's url are whitelisted to WordPress external requests.
521 *
522 * @param boolean $isAllowed
523 * @param string $host
524 * @param string $url
525 *
526 * @return boolean
527 * @since 1.4.0
528 * @static
529 *
530 */
531 public static function allowApiHost ($isAllowed, $host, $url) {
532 if ($host === EMBEDPRESS_LICENSES_API_HOST) {
533 $isAllowed = true;
534 }
535
536 return $isAllowed;
537 }
538
539
540 }
541