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