PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.7.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.7.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 / CoreLegacy.php
embedpress / EmbedPress Last commit date
AMP 6 years ago Elementor 5 years ago Ends 5 years ago Includes 5 years ago Plugins 6 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 6 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
CoreLegacy.php
420 lines
1 <?php
2
3 namespace EmbedPress;
4
5 use EmbedPress\Ends\Back\Handler as EndHandlerAdmin;
6 use EmbedPress\Ends\Front\Handler as EndHandlerPublic;
7
8 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
9
10 /**
11 * Entity that glues together all pieces that the plugin is made of, for WordPress before 5.0.
12 *
13 * @package EmbedPress
14 * @author EmbedPress <help@embedpress.com>
15 * @copyright Copyright (C) 2020 WPDeveloper. All rights reserved.
16 * @license GPLv3 or later
17 * @since 1.0.0
18 */
19 class CoreLegacy
20 {
21 use \EmbedPress\Includes\Traits\Shared;
22 /**
23 * The name of the plugin.
24 *
25 * @since 1.0.0
26 * @access protected
27 *
28 * @var string $pluginName The name of the plugin.
29 */
30 protected $pluginName;
31
32 /**
33 * The version of the plugin.
34 *
35 * @since 1.0.0
36 * @access protected
37 *
38 * @var string $pluginVersion The version of the plugin.
39 */
40 protected $pluginVersion;
41
42 /**
43 * An instance of the plugin loader.
44 *
45 * @since 1.0.0
46 * @access protected
47 *
48 * @var \EmbedPress\Loader $pluginVersion The version of the plugin.
49 */
50 protected $loaderInstance;
51
52 /**
53 * An associative array storing all registered/active EmbedPress plugins and their namespaces.
54 *
55 * @since 1.4.0
56 * @access private
57 * @static
58 *
59 * @var array
60 */
61 private static $plugins = [];
62
63 /**
64 * Initialize the plugin and set its properties.
65 *
66 * @since 1.0.0
67 *
68 * @return void
69 */
70 public function __construct()
71 {
72 $this->pluginName = EMBEDPRESS_PLG_NAME;
73 $this->pluginVersion = EMBEDPRESS_VERSION;
74
75 $this->loaderInstance = new Loader();
76 add_action('admin_notices',[$this,'embedpress_admin_notice']);
77 }
78
79 /**
80 * Method that retrieves the plugin name.
81 *
82 * @since 1.0.0
83 *
84 * @return string
85 */
86 public function getPluginName()
87 {
88 return $this->pluginName;
89 }
90
91 /**
92 * Method that retrieves the plugin version.
93 *
94 * @since 1.0.0
95 *
96 * @return string
97 */
98 public function getPluginVersion()
99 {
100 return $this->pluginVersion;
101 }
102
103 /**
104 * Method that retrieves the loader instance.
105 *
106 * @since 1.0.0
107 *
108 * @return \EmbedPress\Loader
109 */
110 public function getLoader()
111 {
112 return $this->loaderInstance;
113 }
114
115 /**
116 * Method responsible to connect all required hooks in order to make the plugin work.
117 *
118 * @since 1.0.0
119 *
120 * @return void
121 */
122 public function initialize()
123 {
124 global $wp_actions;
125
126 if (is_admin()) {
127 $plgSettings = self::getSettings();
128 $this->admin_notice();
129 $settingsClassNamespace = '\\EmbedPress\\Ends\\Back\\Settings';
130 add_action('admin_menu', [$settingsClassNamespace, 'registerMenuItem']);
131 add_action('admin_init', [$settingsClassNamespace, 'registerActions']);
132 unset($settingsClassNamespace);
133
134 add_filter('plugin_action_links_embedpress/embedpress.php',
135 ['\\EmbedPress\\CoreLegacy', 'handleActionLinks'], 10, 2);
136
137 add_action('admin_enqueue_scripts', ['\\EmbedPress\\Ends\\Back\\Handler', 'enqueueStyles']);
138 add_action('wp_ajax_embedpress_notice_dismiss', ['\\EmbedPress\\Ends\\Back\\Handler', 'embedpress_notice_dismiss']);
139
140 add_action('init', ['\\EmbedPress\\DisablerLegacy', 'run'], 1);
141 add_action('init', [$this, 'configureTinyMCE'], 1);
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
149 $onAjaxCallbackName = "doShortcodeReceivedViaAjax";
150 $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance,
151 $onAjaxCallbackName);
152 $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance,
153 $onAjaxCallbackName);
154
155 $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance,
156 "getUrlInfoViaAjax");
157
158 unset($onAjaxCallbackName, $plgHandlerAdminInstance);
159 } else {
160 add_action('init', ['\\EmbedPress\\DisablerLegacy', 'run'], 1);
161
162 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
163
164 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts');
165 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles');
166
167 unset($plgHandlerPublicInstance);
168 }
169
170 // Add support for embeds on AMP pages
171 add_filter('pp_embed_parsed_content', ['\\EmbedPress\\AMP\\EmbedHandler', 'processParsedContent'], 10, 3);
172
173 // Add support for our embeds on Beaver Builder. Without this it only run the native embeds.
174 add_filter('fl_builder_before_render_shortcodes',
175 ['\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes']);
176
177 $this->start_plugin_tracking();
178 $this->loaderInstance->run();
179 }
180
181 /**
182 * Callback called right after the plugin has been activated.
183 *
184 * @since 1.0.0
185 * @static
186 *
187 * @return void
188 */
189 public static function onPluginActivationCallback()
190 {
191 add_filter('rewrite_rules_array', ['\\EmbedPress\\DisablerLegacy', 'disableDefaultEmbedRewriteRules']);
192 flush_rewrite_rules();
193 }
194
195 /**
196 * Callback called right after the plugin has been deactivated.
197 *
198 * @since 1.0.0
199 * @static
200 *
201 * @return void
202 */
203 public static function onPluginDeactivationCallback()
204 {
205 remove_filter('rewrite_rules_array', ['\\EmbedPress\\DisablerLegacy', 'disableDefaultEmbedRewriteRules']);
206 flush_rewrite_rules();
207 }
208
209 /**
210 * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file.
211 *
212 * @since 1.0.0
213 * @static
214 *
215 * @return array
216 */
217 public static function getAdditionalServiceProviders()
218 {
219 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE . 'providers.php';
220 if (file_exists($additionalProvidersFilePath)) {
221 include $additionalProvidersFilePath;
222
223 if (isset($additionalServiceProviders)) {
224 return $additionalServiceProviders;
225 }
226 }
227
228 return [];
229 }
230
231 /**
232 * Method that checks if an embed of a given service provider can be responsive.
233 *
234 * @since 1.0.0
235 * @static
236 *
237 * @param string $serviceProviderAlias The service's slug.
238 *
239 * @return boolean
240 */
241 public static function canServiceProviderBeResponsive($serviceProviderAlias)
242 {
243 $providers = [
244
245 ];
246
247 return in_array($serviceProviderAlias, [
248 "dailymotion",
249 "kickstarter",
250 "rutube",
251 "ted",
252 "vimeo",
253 "youtube",
254 "ustream",
255 "google-docs",
256 "animatron",
257 "amcharts",
258 "on-aol-com",
259 "animoto",
260 "videojug",
261 'issuu',
262 ]);
263 }
264
265 /**
266 * Method that retrieves the plugin settings defined by the user.
267 *
268 * @since 1.0.0
269 * @static
270 *
271 * @return object
272 */
273 public static function getSettings()
274 {
275 $settings = get_option(EMBEDPRESS_PLG_NAME);
276
277 if ( ! isset($settings['enablePluginInAdmin'])) {
278 $settings['enablePluginInAdmin'] = true;
279 }
280
281 if ( ! isset($settings['enablePluginInFront'])) {
282 $settings['enablePluginInFront'] = true;
283 }
284
285 return (object)$settings;
286 }
287
288 /**
289 * Method that register an EmbedPress plugin.
290 *
291 * @since 1.4.0
292 * @static
293 *
294 * @param array $pluginMeta Associative array containing plugin's name, slug and namespace
295 *
296 * @return void
297 */
298 public static function registerPlugin($pluginMeta)
299 {
300 $pluginMeta = json_decode(json_encode($pluginMeta));
301
302 if (empty($pluginMeta->name) || empty($pluginMeta->slug) || empty($pluginMeta->namespace)) {
303 return;
304 }
305
306 if ( ! isset(self::$plugins[$pluginMeta->slug])) {
307 AutoLoader::register($pluginMeta->namespace,
308 WP_PLUGIN_DIR . '/' . EMBEDPRESS_PLG_NAME . '-' . $pluginMeta->slug . '/' . $pluginMeta->name);
309
310 $plugin = "{$pluginMeta->namespace}\Plugin";
311 if (\defined("{$plugin}::SLUG") && $plugin::SLUG !== null) {
312 self::$plugins[$pluginMeta->slug] = $pluginMeta->namespace;
313
314 $bsFilePath = $plugin::PATH . EMBEDPRESS_PLG_NAME . '-' . $plugin::SLUG . '.php';
315
316 register_activation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onActivationCallback']);
317 register_deactivation_hook($bsFilePath, [$plugin::NAMESPACE_STRING, 'onDeactivationCallback']);
318
319 add_action('admin_init', [$plugin, 'onLoadAdminCallback']);
320
321 add_action(EMBEDPRESS_PLG_NAME . ':' . $plugin::SLUG . ':settings:register',
322 [$plugin, 'registerSettings']);
323 add_action(EMBEDPRESS_PLG_NAME . ':settings:render:tab', [$plugin, 'renderTab']);
324
325 add_filter('plugin_action_links_embedpress-' . $plugin::SLUG . '/embedpress-' . $plugin::SLUG . '.php',
326 [$plugin, 'handleActionLinks'], 10, 2);
327
328 $plugin::registerEvents();
329 }
330 }
331 }
332
333 /**
334 * Retrieve all registered plugins.
335 *
336 * @since 1.4.0
337 * @static
338 *
339 * @return array
340 */
341 public static function getPlugins()
342 {
343 return self::$plugins;
344 }
345
346 /**
347 * Handle links displayed below the plugin name in the WordPress Installed Plugins page.
348 *
349 * @since 1.4.0
350 * @static
351 *
352 * @return array
353 */
354 public static function handleActionLinks($links, $file)
355 {
356 $settingsLink = '<a href="' . admin_url('admin.php?page=embedpress') . '" aria-label="' . __('Open settings page',
357 'embedpress') . '">' . __('Settings', 'embedpress') . '</a>';
358
359 array_unshift($links, $settingsLink);
360
361 return $links;
362 }
363
364 /**
365 * Method that ensures the API's url are whitelisted to WordPress external requests.
366 *
367 * @since 1.4.0
368 * @static
369 *
370 * @param boolean $isAllowed
371 * @param string $host
372 * @param string $url
373 *
374 * @return boolean
375 */
376 public static function allowApiHost($isAllowed, $host, $url)
377 {
378 if ($host === EMBEDPRESS_LICENSES_API_HOST) {
379 $isAllowed = true;
380 }
381
382 return $isAllowed;
383 }
384
385 /**
386 * Add filters to configure the TinyMCE editor.
387 *
388 * @since 1.6.2
389 */
390 public function configureTinyMCE()
391 {
392 add_filter('teeny_mce_before_init', [$this, 'hookOnPaste']);
393 add_filter('tiny_mce_before_init', [$this, 'hookOnPaste']);
394 }
395
396 /**
397 * Hook the onPaste methof to the paste_preprocess config in the editor.
398 *
399 * @since 1.6.2
400 *
401 * @param array $mceInit
402 *
403 * @return array
404 */
405 public function hookOnPaste($mceInit)
406 {
407 $settings = self::getSettings();
408
409 if (isset($settings->enablePluginInAdmin) && $settings->enablePluginInAdmin) {
410 // We hook here because the onPaste is sometimes called after the content was already added to the editor.
411 // If you copy text from the editor and paste there, it will give no way to use a normal onPaste event hook
412 // to modify the input since it was already injected.
413 $mceInit['paste_preprocess'] = 'function (plugin, args) {EmbedPress.onPaste(plugin, args);}';
414 }
415
416
417 return $mceInit;
418 }
419 }
420