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