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