AMP
2 years ago
Elementor
1 year ago
Ends
1 year ago
Includes
1 year ago
Plugins
1 year ago
Providers
1 year ago
ThirdParty
1 year ago
AutoLoader.php
2 years ago
Compatibility.php
2 years ago
Core.php
1 year ago
CoreLegacy.php
1 year ago
DisablerLegacy.php
2 years ago
Loader.php
2 years ago
RestAPI.php
1 year ago
Shortcode.php
1 year ago
index.html
7 years ago
simple_html_dom.php
4 years ago
CoreLegacy.php
377 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 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 11 | |
| 12 | /** |
| 13 | * Entity that glues together all pieces that the plugin is made of, for WordPress before 5.0. |
| 14 | * |
| 15 | * @package EmbedPress |
| 16 | * @author EmbedPress <help@embedpress.com> |
| 17 | * @copyright Copyright (C) 2021 WPDeveloper. All rights reserved. |
| 18 | * @license GPLv3 or later |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | class CoreLegacy |
| 22 | { |
| 23 | use Shared; |
| 24 | /** |
| 25 | * The name of the plugin. |
| 26 | * |
| 27 | * @since 1.0.0 |
| 28 | * @access protected |
| 29 | * |
| 30 | * @var string $pluginName The name of the plugin. |
| 31 | */ |
| 32 | protected $pluginName; |
| 33 | |
| 34 | /** |
| 35 | * The version of the plugin. |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | * @access protected |
| 39 | * |
| 40 | * @var string $pluginVersion The version of the plugin. |
| 41 | */ |
| 42 | protected $pluginVersion; |
| 43 | |
| 44 | /** |
| 45 | * An instance of the plugin loader. |
| 46 | * @since 1.0.0 |
| 47 | * @access protected |
| 48 | * @var 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 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 | $this->start_plugin_tracking(); |
| 127 | |
| 128 | if (is_admin()) { |
| 129 | new EmbedpressSettings(); |
| 130 | $plgSettings = self::getSettings(); |
| 131 | |
| 132 | add_action( 'init', [ $this, 'admin_notice' ] ); |
| 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 | add_action('init', ['\\EmbedPress\\DisablerLegacy', 'run'], 1); |
| 140 | add_action('init', [$this, 'configureTinyMCE'], 1); |
| 141 | |
| 142 | $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion()); |
| 143 | |
| 144 | if ( $plgSettings->enablePluginInAdmin ) { |
| 145 | $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts'); |
| 146 | } |
| 147 | |
| 148 | $onAjaxCallbackName = "doShortcodeReceivedViaAjax"; |
| 149 | $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, |
| 150 | $onAjaxCallbackName); |
| 151 | $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, |
| 152 | $onAjaxCallbackName); |
| 153 | |
| 154 | $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, |
| 155 | "getUrlInfoViaAjax"); |
| 156 | |
| 157 | unset($onAjaxCallbackName, $plgHandlerAdminInstance); |
| 158 | } else { |
| 159 | add_action('init', ['\\EmbedPress\\DisablerLegacy', 'run'], 1); |
| 160 | |
| 161 | $plgSettings = Core::getSettings(); |
| 162 | |
| 163 | if (!is_admin() && $plgSettings->enablePluginInFront ) { |
| 164 | $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion()); |
| 165 | |
| 166 | $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueScripts'); |
| 167 | $this->loaderInstance->add_action('wp_enqueue_scripts', $plgHandlerPublicInstance, 'enqueueStyles'); |
| 168 | |
| 169 | unset($plgHandlerPublicInstance); |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | |
| 174 | // Add support for embeds on AMP pages |
| 175 | add_filter('pp_embed_parsed_content', ['\\EmbedPress\\AMP\\EmbedHandler', 'processParsedContent'], 10, 3); |
| 176 | |
| 177 | // Add support for our embeds on Beaver Builder. Without this it only run the native embeds. |
| 178 | add_filter('fl_builder_before_render_shortcodes', |
| 179 | ['\\EmbedPress\\ThirdParty\\BeaverBuilder', 'before_render_shortcodes']); |
| 180 | |
| 181 | $this->loaderInstance->run(); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Callback called right after the plugin has been activated. |
| 186 | * |
| 187 | * @since 1.0.0 |
| 188 | * @static |
| 189 | * |
| 190 | * @return void |
| 191 | */ |
| 192 | public static function onPluginActivationCallback() |
| 193 | { |
| 194 | add_filter('rewrite_rules_array', ['\\EmbedPress\\DisablerLegacy', 'disableDefaultEmbedRewriteRules']); |
| 195 | flush_rewrite_rules(); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Callback called right after the plugin has been deactivated. |
| 200 | * |
| 201 | * @since 1.0.0 |
| 202 | * @static |
| 203 | * |
| 204 | * @return void |
| 205 | */ |
| 206 | public static function onPluginDeactivationCallback() |
| 207 | { |
| 208 | remove_filter('rewrite_rules_array', ['\\EmbedPress\\DisablerLegacy', 'disableDefaultEmbedRewriteRules']); |
| 209 | flush_rewrite_rules(); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file. |
| 214 | * |
| 215 | * @since 1.0.0 |
| 216 | * @static |
| 217 | * |
| 218 | * @return array |
| 219 | */ |
| 220 | public static function getAdditionalServiceProviders() |
| 221 | { |
| 222 | $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE . 'providers.php'; |
| 223 | if (file_exists($additionalProvidersFilePath)) { |
| 224 | include $additionalProvidersFilePath; |
| 225 | if (isset($additionalServiceProviders)) { |
| 226 | return apply_filters( 'embedpress_additional_service_providers', $additionalServiceProviders); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return apply_filters( 'embedpress_additional_service_providers', []); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Method that checks if an embed of a given service provider can be responsive. |
| 235 | * |
| 236 | * @since 1.0.0 |
| 237 | * @static |
| 238 | * |
| 239 | * @param string $serviceProviderAlias The service's slug. |
| 240 | * |
| 241 | * @return boolean |
| 242 | */ |
| 243 | public static function canServiceProviderBeResponsive($serviceProviderAlias) |
| 244 | { |
| 245 | return in_array($serviceProviderAlias, [ |
| 246 | "dailymotion", |
| 247 | "kickstarter", |
| 248 | "rutube", |
| 249 | "ted", |
| 250 | "vimeo", |
| 251 | "youtube", |
| 252 | "ustream", |
| 253 | "google-docs", |
| 254 | "animatron", |
| 255 | "amcharts", |
| 256 | "on-aol-com", |
| 257 | "animoto", |
| 258 | "videojug", |
| 259 | 'issuu', |
| 260 | ]); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Method that retrieves the plugin settings defined by the user. |
| 265 | * |
| 266 | * @since 1.0.0 |
| 267 | * @static |
| 268 | * |
| 269 | * @return object |
| 270 | */ |
| 271 | public static function getSettings() |
| 272 | { |
| 273 | $settings = get_option(EMBEDPRESS_PLG_NAME); |
| 274 | |
| 275 | if ( ! isset($settings['enablePluginInAdmin'])) { |
| 276 | $settings['enablePluginInAdmin'] = true; |
| 277 | } |
| 278 | |
| 279 | if ( ! isset($settings['enablePluginInFront'])) { |
| 280 | $settings['enablePluginInFront'] = true; |
| 281 | } |
| 282 | |
| 283 | return (object)$settings; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /** |
| 288 | * Retrieve all registered plugins. |
| 289 | * |
| 290 | * @since 1.4.0 |
| 291 | * @static |
| 292 | * |
| 293 | * @return array |
| 294 | */ |
| 295 | public static function getPlugins() |
| 296 | { |
| 297 | return self::$plugins; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Handle links displayed below the plugin name in the WordPress Installed Plugins page. |
| 302 | * |
| 303 | * @since 1.4.0 |
| 304 | * @static |
| 305 | * |
| 306 | * @return array |
| 307 | */ |
| 308 | public static function handleActionLinks($links, $file) |
| 309 | { |
| 310 | $settingsLink = '<a href="' . admin_url('admin.php?page=embedpress') . '" aria-label="' . __('Open settings page', |
| 311 | 'embedpress') . '">' . __('Settings', 'embedpress') . '</a>'; |
| 312 | |
| 313 | array_unshift($links, $settingsLink); |
| 314 | if ( !apply_filters('embedpress/is_allow_rander', false) ) { |
| 315 | $links[] = '<a href="https://wpdeveloper.com/in/upgrade-embedpress" target="_blank" class="embedpress-go-pro-action" style="color: green">'.__('Go Pro', 'embedpress').'</a>'; |
| 316 | } |
| 317 | return $links; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /** |
| 322 | * Method that ensures the API's url are whitelisted to WordPress external requests. |
| 323 | * |
| 324 | * @since 1.4.0 |
| 325 | * @static |
| 326 | * |
| 327 | * @param boolean $isAllowed |
| 328 | * @param string $host |
| 329 | * @param string $url |
| 330 | * |
| 331 | * @return boolean |
| 332 | */ |
| 333 | public static function allowApiHost($isAllowed, $host, $url) |
| 334 | { |
| 335 | if ($host === EMBEDPRESS_LICENSES_API_HOST) { |
| 336 | $isAllowed = true; |
| 337 | } |
| 338 | |
| 339 | return $isAllowed; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Add filters to configure the TinyMCE editor. |
| 344 | * |
| 345 | * @since 1.6.2 |
| 346 | */ |
| 347 | public function configureTinyMCE() |
| 348 | { |
| 349 | add_filter('teeny_mce_before_init', [$this, 'hookOnPaste']); |
| 350 | add_filter('tiny_mce_before_init', [$this, 'hookOnPaste']); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Hook the onPaste methof to the paste_preprocess config in the editor. |
| 355 | * |
| 356 | * @since 1.6.2 |
| 357 | * |
| 358 | * @param array $mceInit |
| 359 | * |
| 360 | * @return array |
| 361 | */ |
| 362 | public function hookOnPaste($mceInit) |
| 363 | { |
| 364 | $settings = self::getSettings(); |
| 365 | |
| 366 | if (isset($settings->enablePluginInAdmin) && $settings->enablePluginInAdmin) { |
| 367 | // We hook here because the onPaste is sometimes called after the content was already added to the editor. |
| 368 | // If you copy text from the editor and paste there, it will give no way to use a normal onPaste event hook |
| 369 | // to modify the input since it was already injected. |
| 370 | $mceInit['paste_preprocess'] = 'function (plugin, args) { if (typeof EmbedPress !== "undefined") {EmbedPress.onPaste(plugin, args); } }'; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | return $mceInit; |
| 375 | } |
| 376 | } |
| 377 |