PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.1.5
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.1.5
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 8 years ago Ends 7 years ago Plugins 8 years ago Providers 8 years ago ThirdParty 7 years ago AutoLoader.php 8 years ago Core.php 7 years ago Disabler.php 8 years ago Loader.php 8 years ago Shortcode.php 7 years ago index.html 9 years ago
Core.php
387 lines
1 <?php
2 namespace EmbedPress;
3
4 use \EmbedPress\AutoLoader;
5 use \EmbedPress\Loader;
6 use \EmbedPress\Ends\Back\Handler as EndHandlerAdmin;
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.
13 *
14 * @package EmbedPress
15 * @author EmbedPress <help@embedpress.com>
16 * @copyright Copyright (C) 2018 EmbedPress. All rights reserved.
17 * @license GPLv2 or later
18 * @since 1.0.0
19 */
20 class Core
21 {
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 = array();
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_PLG_VERSION;
74
75 $this->loaderInstance = new Loader();
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 \EmbedPress\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 $plgSettings = self::getSettings();
127
128 $settingsClassNamespace = '\EmbedPress\Ends\Back\Settings';
129 add_action('admin_menu', array($settingsClassNamespace, 'registerMenuItem'));
130 add_action('admin_init', array($settingsClassNamespace, 'registerActions'));
131 unset($settingsClassNamespace);
132
133 add_filter('plugin_action_links_embedpress/embedpress.php', array('\EmbedPress\Core', 'handleActionLinks'), 10, 2);
134
135 add_action('admin_enqueue_scripts', array('\EmbedPress\Ends\Back\Handler', 'enqueueStyles'));
136
137 add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
138 add_action('init', array($this, 'configureTinyMCE'), 1);
139
140 $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
141
142 if ((bool)$plgSettings->enablePluginInAdmin) {
143 $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
144 }
145
146 $onAjaxCallbackName = "doShortcodeReceivedViaAjax";
147 $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
148 $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
149
150 $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, "getUrlInfoViaAjax");
151
152 unset($onAjaxCallbackName, $plgHandlerAdminInstance);
153 } else {
154 add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
155
156 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
157
158 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts');
159 $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles');
160
161 unset($plgHandlerPublicInstance);
162 }
163
164 // Add support for embeds on AMP pages
165 add_filter('pp_embed_parsed_content', array('\EmbedPress\AMP\EmbedHandler', 'processParsedContent'), 10, 3);
166
167 // Add support for our embeds on Beaver Builder. Without this it only run the native embeds.
168 add_filter('fl_builder_before_render_shortcodes', array('\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes'));
169
170 $this->loaderInstance->run();
171 }
172
173 /**
174 * Callback called right after the plugin has been activated.
175 *
176 * @since 1.0.0
177 * @static
178 *
179 * @return void
180 */
181 public static function onPluginActivationCallback()
182 {
183 add_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules'));
184 flush_rewrite_rules();
185 }
186
187 /**
188 * Callback called right after the plugin has been deactivated.
189 *
190 * @since 1.0.0
191 * @static
192 *
193 * @return void
194 */
195 public static function onPluginDeactivationCallback()
196 {
197 remove_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules'));
198 flush_rewrite_rules();
199 }
200
201 /**
202 * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file.
203 *
204 * @since 1.0.0
205 * @static
206 *
207 * @return array
208 */
209 public static function getAdditionalServiceProviders()
210 {
211 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE .'providers.php';
212 if (file_exists($additionalProvidersFilePath)) {
213 include $additionalProvidersFilePath;
214
215 if (isset($additionalServiceProviders)) {
216 return $additionalServiceProviders;
217 }
218 }
219
220 return array();
221 }
222
223 /**
224 * Method that checks if an embed of a given service provider can be responsive.
225 *
226 * @since 1.0.0
227 * @static
228 *
229 * @param string $serviceProviderAlias The service's slug.
230 * @return boolean
231 */
232 public static function canServiceProviderBeResponsive($serviceProviderAlias)
233 {
234 return in_array($serviceProviderAlias, array("dailymotion", "kickstarter", "rutube", "ted", "vimeo", "youtube", "ustream", "google-docs", "animatron", "amcharts", "on-aol-com", "animoto", "videojug", 'issuu'));
235 }
236
237 /**
238 * Method that retrieves the plugin settings defined by the user.
239 *
240 * @since 1.0.0
241 * @static
242 *
243 * @return object
244 */
245 public static function getSettings()
246 {
247 $settings = get_option(EMBEDPRESS_PLG_NAME);
248
249 if (!isset($settings['enablePluginInAdmin'])) {
250 $settings['enablePluginInAdmin'] = true;
251 }
252
253 if (!isset($settings['enablePluginInFront'])) {
254 $settings['enablePluginInFront'] = true;
255 }
256
257 return (object)$settings;
258 }
259
260 /**
261 * Method that register an EmbedPress plugin.
262 *
263 * @since 1.4.0
264 * @static
265 *
266 * @param array $pluginMeta Associative array containing plugin's name, slug and namespace
267 * @return void
268 */
269 public static function registerPlugin($pluginMeta)
270 {
271 $pluginMeta = json_decode(json_encode($pluginMeta));
272
273 if (empty($pluginMeta->name) || empty($pluginMeta->slug) || empty($pluginMeta->namespace)) {
274 return;
275 }
276
277 if (!isset(self::$plugins[$pluginMeta->slug])) {
278 AutoLoader::register($pluginMeta->namespace, WP_PLUGIN_DIR .'/'. EMBEDPRESS_PLG_NAME .'-'. $pluginMeta->slug .'/'. $pluginMeta->name);
279
280 $plugin = "{$pluginMeta->namespace}\Plugin";
281 if (\defined("{$plugin}::SLUG") && $plugin::SLUG !== null) {
282 self::$plugins[$pluginMeta->slug] = $pluginMeta->namespace;
283
284 $bsFilePath = $plugin::PATH . EMBEDPRESS_PLG_NAME .'-'. $plugin::SLUG .'.php';
285
286 register_activation_hook($bsFilePath, array($plugin::NAMESPACE_STRING, 'onActivationCallback'));
287 register_deactivation_hook($bsFilePath, array($plugin::NAMESPACE_STRING, 'onDeactivationCallback'));
288
289 add_action('admin_init', array($plugin, 'onLoadAdminCallback'));
290
291 add_action(EMBEDPRESS_PLG_NAME .':'. $plugin::SLUG .':settings:register', array($plugin, 'registerSettings'));
292 add_action(EMBEDPRESS_PLG_NAME .':settings:render:tab', array($plugin, 'renderTab'));
293
294 add_filter('plugin_action_links_embedpress-'. $plugin::SLUG .'/embedpress-'. $plugin::SLUG .'.php', array($plugin, 'handleActionLinks'), 10, 2);
295
296 $plugin::registerEvents();
297 }
298 }
299 }
300
301 /**
302 * Retrieve all registered plugins.
303 *
304 * @since 1.4.0
305 * @static
306 *
307 * @return array
308 */
309 public static function getPlugins()
310 {
311 return self::$plugins;
312 }
313
314 /**
315 * Handle links displayed below the plugin name in the WordPress Installed Plugins page.
316 *
317 * @since 1.4.0
318 * @static
319 *
320 * @return array
321 */
322 public static function handleActionLinks($links, $file)
323 {
324 $settingsLink = '<a href="'. admin_url('admin.php?page=embedpress') .'" aria-label="'. __('Open settings page', 'embedpress') .'">'. __('Settings', 'embedpress') .'</a>';
325
326 array_unshift($links, $settingsLink);
327
328 return $links;
329 }
330
331 /**
332 * Method that ensures the API's url are whitelisted to WordPress external requests.
333 *
334 * @since 1.4.0
335 * @static
336 *
337 * @param boolean $isAllowed
338 * @param string $host
339 * @param string $url
340 *
341 * @return boolean
342 */
343 public static function allowApiHost($isAllowed, $host, $url)
344 {
345 if ($host === EMBEDPRESS_LICENSES_API_HOST) {
346 $isAllowed = true;
347 }
348
349 return $isAllowed;
350 }
351
352 /**
353 * Add filters to configure the TinyMCE editor.
354 *
355 * @since 1.6.2
356 */
357 public function configureTinyMCE()
358 {
359 add_filter('teeny_mce_before_init', array($this, 'hookOnPaste'));
360 add_filter('tiny_mce_before_init', array($this, 'hookOnPaste'));
361 }
362
363 /**
364 * Hook the onPaste methof to the paste_preprocess config in the editor.
365 *
366 * @since 1.6.2
367 *
368 * @param array $mceInit
369 *
370 * @return array
371 */
372 public function hookOnPaste($mceInit)
373 {
374 $settings = self::getSettings();
375
376 if (isset($settings->enablePluginInAdmin) && $settings->enablePluginInAdmin) {
377 // We hook here because the onPaste is sometimes called after the content was already added to the editor.
378 // If you copy text from the editor and paste there, it will give no way to use a normal onPaste event hook
379 // to modify the input since it was already injected.
380 $mceInit['paste_preprocess'] = 'function (plugin, args) {EmbedPress.onPaste(plugin, args);}';
381 }
382
383
384 return $mceInit;
385 }
386 }
387