PluginProbe
Embed Privacy / 0.1
Embed Privacy v0.1
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
← All changes | inc/class-embed-privacy.php +76 -1145 1.10.1 → 0.1 View file →
@@ -1,158 +1,33 @@
1 1 <?php
2 2 namespace epiphyt\Embed_Privacy;
3 3
4 -use epiphyt\Embed_Privacy\admin\Fields;
5 -use epiphyt\Embed_Privacy\admin\Settings;
6 -use epiphyt\Embed_Privacy\admin\User_Interface;
7 -use epiphyt\Embed_Privacy\data\Providers;
8 -use epiphyt\Embed_Privacy\data\Replacer;
9 -use epiphyt\Embed_Privacy\embed\Replacement;
10 -use epiphyt\Embed_Privacy\embed\Template;
11 -use epiphyt\Embed_Privacy\handler\Post;
12 -use epiphyt\Embed_Privacy\handler\Shortcode;
13 -use epiphyt\Embed_Privacy\handler\Theme;
14 -use epiphyt\Embed_Privacy\handler\Widget;
15 -use epiphyt\Embed_Privacy\integration\Activitypub;
16 -use epiphyt\Embed_Privacy\integration\Amp;
17 -use epiphyt\Embed_Privacy\integration\Astra;
18 -use epiphyt\Embed_Privacy\integration\Divi;
19 -use epiphyt\Embed_Privacy\integration\Elementor;
20 -use epiphyt\Embed_Privacy\integration\Jetpack;
21 -use epiphyt\Embed_Privacy\integration\Kadence_Blocks;
22 -use epiphyt\Embed_Privacy\integration\Maps_Marker;
23 -use epiphyt\Embed_Privacy\integration\Polylang;
24 -use epiphyt\Embed_Privacy\integration\Shortcodes_Ultimate;
25 -use epiphyt\Embed_Privacy\integration\Twitter;
26 -use epiphyt\Embed_Privacy\thumbnail\Thumbnail;
27 -use ReflectionMethod;
28 -
29 4 /**
30 5 * Two click embed main class.
31 6 *
32 - * @author Epiphyt
33 - * @license GPL2
34 - * @package epiphyt\Embed_Privacy
7 + * @author Epiphyt
8 + * @license GPL2
9 + * @package epiphyt\Embed_Privacy
10 + * @version 0.1
35 11 */
36 12 class Embed_Privacy {
37 13 /**
38 - * @deprecated 1.2.0
39 - * @since 1.1.0
40 - */
41 - const IFRAME_REGEX = '/<iframe(.*?)src="([^"]+)"([^>]*)>((?!<\/iframe).)*<\/iframe>/ms';
42 -
43 - /**
44 - * @since 1.4.0
45 - * @var mixed The cookie content or any error message from json_decode()
46 - */
47 - private $cookie;
48 -
49 - /**
50 - * @since 1.3.5
51 - * @var array Replacements that already have taken place.
52 - */
53 - public $did_replacements = [];
54 -
55 - /**
56 - * @since 1.3.0
57 - * @var array An array of embed providers
58 - */
59 - public $embeds = [];
60 -
61 - /**
62 - * @since 1.10.0
63 - * @var \epiphyt\Embed_Privacy\admin\Fields
64 - */
65 - public $fields;
66 -
67 - /**
68 - * @since 1.10.0
69 - * @var \epiphyt\Embed_Privacy\Frontend
70 - */
71 - public $frontend;
72 -
73 - /**
74 - * @since 1.3.0
75 - * @var bool Whether the current request has any embed processed by Embed Privacy
76 - */
77 - public $has_embed = false;
78 -
79 - /**
80 - * @since 1.10.0
81 - * @var array List of integrations
82 - */
83 - private $integrations = [
84 - Activitypub::class,
85 - Amp::class,
86 - Astra::class,
87 - Divi::class,
88 - Elementor::class,
89 - Jetpack::class,
90 - Kadence_Blocks::class,
91 - Maps_Marker::class,
92 - Polylang::class,
93 - Shortcodes_Ultimate::class,
94 - Twitter::class,
95 - ];
96 -
97 - /**
98 - * @since 1.10.0
99 - * @var bool Whether the current request should be ignored
100 - */
101 - public $is_ignored_request = false;
102 -
103 - /**
104 - * @var \epiphyt\Embed_Privacy\Embed_Privacy
105 - */
106 - public static $instance;
107 -
108 - /**
109 - * @deprecated 1.10.0 Use \EPI_EMBED_PRIVACY_FILE instead
110 - * @var string The full path to the main plugin file
111 - */
112 - public $plugin_file = '';
113 -
114 - /**
115 - * @since 1.10.0
116 - * @var \epiphyt\Embed_Privacy\handler\Shortcode
117 - */
118 - public $shortcode;
119 -
120 - /**
121 - * @deprecated 1.10.0
122 - * @var array Style properties
123 - */
124 - public $style = [
125 - 'container' => [],
126 - 'global' => [],
127 - ];
128 -
129 - /**
130 - * @var \epiphyt\Embed_Privacy\thumbnail\Thumbnail
131 - */
132 - public $thumbnail;
133 -
134 - /**
135 14 * @var bool Determine if we use the cache
136 15 */
137 - public $use_cache;
16 + private $usecache = false;
138 17
139 18 /**
140 - * @deprecated 1.2.0
141 - * @var array The supported media providers
19 + * @var array The supported media providers
142 20 */
143 - public $embed_providers = [ // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder
144 - '.amazon.' => 'Amazon Kindle',
145 - '.amzn.' => 'Amazon Kindle',
146 - 'a.co' => 'Amazon Kindle',
147 - 'z.cn' => 'Amazon Kindle',
21 + public $embed_providers = [
148 22 'animoto.com' => 'Animoto',
149 23 'cloudup.com' => 'Cloudup',
150 - 'crowdsignal.com' => 'Crowdsignal',
24 + 'collegehumor.com' => 'CollegeHumor',
151 25 'dailymotion.com' => 'DailyMotion',
152 26 'facebook.com' => 'Facebook',
153 27 'flickr.com' => 'Flickr',
154 28 'funnyordie.com' => 'Funny Or Die',
29 + 'hulu.com' => 'Hulu',
155 30 'imgur.com' => 'Imgur',
156 31 'instagram.com' => 'Instagram',
157 32 'issuu.com' => 'Issuu',
158 33 'kickstarter.com' => 'Kickstarter',
@@ -158,25 +33,22 @@
158 33 'kickstarter.com' => 'Kickstarter',
159 34 'meetup.com' => 'Meetup',
160 35 'mixcloud.com' => 'Mixcloud',
161 36 'photobucket.com' => 'Photobucket',
162 - 'poll.fm' => 'Crowdsignal',
163 - 'polldaddy.com' => 'Crowdsignal',
37 + 'polldaddy.com' => 'Polldaddy.com',
164 38 'reddit.com' => 'Reddit',
165 39 'reverbnation.com' => 'ReverbNation',
166 40 'scribd.com' => 'Scribd',
167 41 'sketchfab.com' => 'Sketchfab',
168 - 'slideshare.net' => 'SlideShare',
42 + 'slideshare.com' => 'SlideShare',
169 43 'smugmug.com' => 'SmugMug',
170 44 'soundcloud.com' => 'SoundCloud',
171 45 'speakerdeck.com' => 'Speaker Deck',
172 46 'spotify.com' => 'Spotify',
173 - 'survey.fm' => 'Crowdsignal',
174 - 'tiktok.com' => 'TikTok',
175 47 'ted.com' => 'TED',
176 48 'tumblr.com' => 'Tumblr',
177 49 'twitter.com' => 'Twitter',
178 - 'videopress.com' => 'VideoPress',
50 + 'videopress.com' => 'VideoPres',
179 51 'vimeo.com' => 'Vimeo',
180 52 'wordpress.org/plugins' => 'WordPress.org',
181 53 'wordpress.tv' => 'WordPress.tv',
182 54 'youtu.be' => 'YouTube',
@@ -186,1058 +58,117 @@
186 58 /**
187 59 * Embed Privacy constructor.
188 60 */
189 61 public function __construct() {
190 - $this->fields = new Fields();
191 - $this->frontend = new Frontend();
192 - $this->shortcode = new Shortcode();
193 - $this->thumbnail = new Thumbnail();
194 - $this->use_cache = ! \is_admin();
195 - }
196 -
197 - /**
198 - * Initialize the class.
199 - *
200 - * @since 1.2.0
201 - */
202 - public function init() {
203 62 // actions
204 - \add_action( 'init', [ $this, 'load_textdomain' ], 0 );
205 - \add_action( 'init', [ $this, 'set_ignored_request' ] );
206 - \add_action( 'init', [ self::class, 'register_post_type' ], 5 );
207 - \add_action( 'plugins_loaded', [ $this, 'init_integrations' ] );
208 - \add_action( 'save_post_epi_embed', [ $this, 'preserve_backslashes' ] );
63 + \add_action( 'init', [ $this, 'load_textdomain' ] );
64 + \add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] );
209 65
66 + $this->usecache = ! \is_admin();
67 +
210 68 // filters
211 - if ( ! $this->use_cache ) {
69 + if ( ! $this->usecache ) {
212 70 // set ttl to 0 in admin
213 - \add_filter( 'oembed_ttl', '__return_zero' );
71 + \add_filter( 'oembed_ttl', function( $time ) {
72 + return 0;
73 + }, 10, 1 );
214 74 }
215 75
216 - Migration::get_instance()->init();
217 - Post::init();
218 - Providers::get_instance()->init();
219 - Settings::init();
220 - User_Interface::init();
221 - Widget::init();
222 - $this->fields->init();
223 - $this->frontend->init();
224 - $this->shortcode->init();
225 - $this->thumbnail->init();
76 + \add_filter( 'embed_oembed_html', [ $this, 'replace_embeds' ], 10, 3 );
226 77 }
227 78
228 79 /**
229 - * Initialize all integrations, if necessary.
230 - */
231 - public function init_integrations() {
232 - /**
233 - * Filter the integrations.
234 - *
235 - * @since 1.10.0
236 - *
237 - * @param array $integrations List of integrations
238 - */
239 - $this->integrations = (array) \apply_filters( 'embed_privacy_integrations', $this->integrations );
240 -
241 - foreach ( $this->integrations as $integration ) {
242 - if ( ! \method_exists( $integration, 'init' ) ) {
243 - continue;
244 - }
245 -
246 - $reflection = new ReflectionMethod( $integration, 'init' );
247 -
248 - if ( $reflection->isStatic() ) {
249 - $integration::init();
250 - }
251 - else {
252 - ( new $integration() )->init(); // phpcs:ignore NeutronStandard.Functions.VariableFunctions.VariableFunction
253 - }
254 - }
255 - }
256 -
257 - /**
258 80 * Embeds are cached in the postmeta database table and need to be removed
259 81 * whenever the plugin will be enabled or disabled.
260 - *
261 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Post::clear_embed_cache() instead
262 82 */
263 83 public function clear_embed_cache() {
264 - \_doing_it_wrong(
265 - __METHOD__,
266 - \sprintf(
267 - /* translators: alternative method */
268 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
269 - 'epiphyt\Embed_Privacy\handler\Post::clear_embed_cache()'
270 - ),
271 - '1.10.0'
272 - );
273 - Post::clear_embed_cache();
274 - }
275 -
276 - /**
277 - * Deregister assets.
278 - *
279 - * @deprecated 1.10.0
280 - * @since 1.4.6
281 - */
282 - public function deregister_assets() {
283 - \_doing_it_wrong(
284 - __METHOD__,
285 - \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
286 - '1.10.0'
287 - );
288 - }
289 -
290 - /**
291 - * Enqueue our assets for the frontend.
292 - *
293 - * @deprecated 1.4.4 Use epiphyt\Embed_Privacy\Frontend::print_assets() instead
294 - */
295 - public function enqueue_assets() {
296 - \_doing_it_wrong(
297 - __METHOD__,
298 - \sprintf(
299 - /* translators: alternative method */
300 - \esc_html__( 'Use %s instead.', 'embed-privacy' ),
301 - 'epiphyt\Embed_Privacy\Frontend::print_assets()'
302 - ),
303 - '1.4.4'
304 - );
305 - }
306 -
307 - /**
308 - * Get the Embed Privacy cookie.
309 - *
310 - * @return mixed The content of the cookie
311 - */
312 - public function get_cookie() {
313 - if ( empty( $_COOKIE['embed-privacy'] ) ) {
314 - return '';
315 - }
84 + global $wpdb;
316 85
317 - if ( ! empty( $this->cookie ) ) {
318 - return $this->cookie;
319 - }
86 + // the query to delete cache
87 + $query = "DELETE FROM " . $wpdb->get_blog_prefix() . "postmeta
88 + WHERE meta_key LIKE '%_oembed_%'";
320 89
321 - $this->cookie = \json_decode( \sanitize_text_field( \wp_unslash( $_COOKIE['embed-privacy'] ) ) );
322 -
323 - return $this->cookie;
324 - }
325 -
326 - /**
327 - * Get filters for Elementor.
328 - *
329 - * @deprecated 1.3.5
330 - * @since 1.3.0
331 - */
332 - public function get_elementor_filters() {
333 - \_doing_it_wrong(
334 - __METHOD__,
335 - \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
336 - '1.3.5'
337 - );
338 -
339 - if ( ! Elementor::is_used() ) {
340 - return;
341 - }
342 -
343 - // doesn't currently run with YouTube
344 - // see https://github.com/elementor/elementor/issues/14276
345 - \add_filter( 'oembed_result', [ $this, 'replace_embeds' ], 10, 3 );
346 - }
347 -
348 - /**
349 - * Get an embed provider by its name.
350 - *
351 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::get_by_name() instead
352 - * @since 1.3.5
353 - *
354 - * @param string $name The name to search for
355 - * @return \WP_Post|null The embed or null
356 - */
357 - public function get_embed_by_name( $name ) {
358 - \_doing_it_wrong(
359 - __METHOD__,
360 - \sprintf(
361 - /* translators: alternative method */
362 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
363 - 'epiphyt\Embed_Privacy\data\Providers::get_by_name()'
364 - ),
365 - '1.10.0'
366 - );
367 -
368 - if ( empty( $name ) ) {
369 - return null;
370 - }
371 -
372 - $embed_providers = $this->get_embeds();
373 - $embed = null;
374 - $pattern = '/^' . \preg_quote( $name, '/' ) . '\-\d+/';
375 -
376 - foreach ( $embed_providers as $embed_provider ) {
377 - if ( $embed_provider->post_name !== $name && ! \preg_match( $pattern, $embed_provider->post_name ) ) {
378 - continue;
379 - }
90 + if ( \is_plugin_active_for_network( 'embed-privacy/embed-privacy.php' ) ) {
91 + // on networks we need to iterate through every site
92 + $sites = \get_sites( 99999 );
380 93
381 - $embed = $embed_provider;
382 - break;
383 - }
384 -
385 - return $embed;
386 - }
387 -
388 - /**
389 - * Get an embed provider overlay.
390 - *
391 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
392 - * @since 1.3.5
393 - *
394 - * @param \WP_Post $provider An embed provider
395 - * @param string $content The content
396 - * @return string The content with additional overlays of an embed provider
397 - */
398 - public function get_embed_overlay( $provider, $content ) {
399 - \_doing_it_wrong(
400 - __METHOD__,
401 - \sprintf(
402 - /* translators: alternative method */
403 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
404 - 'epiphyt\Embed_Privacy\embed\Replacement::get()'
405 - ),
406 - '1.10.0'
407 - );
408 -
409 - if ( Providers::is_always_active( $provider->post_name ) ) {
410 - return $content;
411 - }
412 -
413 - $overlay = new Replacement( $content );
414 -
415 - if ( $overlay->get_provider()->is_matching( $content ) ) {
416 - $content = Template::get( $overlay->get_provider(), $overlay );
417 - }
418 -
419 - return $content;
420 - }
421 -
422 - /**
423 - * Get a specific type of embeds.
424 - *
425 - * For more information on the accepted arguments in $args, see the
426 - * {@link https://developer.wordpress.org/reference/classes/wp_query/
427 - * WP_Query} documentation in the Developer Handbook.
428 - *
429 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::get_list() instead
430 - * @since 1.3.0
431 - * @since 1.8.0 Added the $args parameter
432 - *
433 - * @param string $type The embed type
434 - * @param array $args Additional arguments
435 - * @return array A list of embeds
436 - */
437 - public function get_embeds( $type = 'all', $args = [] ) {
438 - \_doing_it_wrong(
439 - __METHOD__,
440 - \sprintf(
441 - /* translators: alternative method */
442 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
443 - 'epiphyt\Embed_Privacy\data\Providers::get_list()'
444 - ),
445 - '1.10.0'
446 - );
447 -
448 - if ( ! empty( $this->embeds ) && isset( $this->embeds[ $type ] ) ) {
449 - return $this->embeds[ $type ];
450 - }
451 -
452 - if ( $type === 'all' && isset( $this->embeds['custom'] ) && isset( $this->embeds['oembed'] ) ) {
453 - $this->embeds[ $type ] = \array_merge( $this->embeds['custom'], $this->embeds['oembed'] );
454 -
455 - return $this->embeds[ $type ];
456 - }
457 -
458 - if ( ! empty( $args ) ) {
459 - $hash = \md5( \wp_json_encode( $args ) );
460 - }
461 -
462 - // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query
463 - switch ( $type ) {
464 - case 'custom':
465 - $custom_providers = \get_posts( \array_merge( [
466 - 'meta_query' => [ // phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed.DisallowedPartiallyKeyed
467 - 'relation' => 'OR',
468 - [ // phpcs:ignore Universal.Arrays.MixedKeyedUnkeyedArray.Found, Universal.Arrays.MixedArrayKeyTypes.ImplicitNumericKey
469 - 'compare' => 'NOT EXISTS',
470 - 'key' => 'is_system',
471 - 'value' => 'yes',
472 - ],
473 - [ // phpcs:ignore Universal.Arrays.MixedKeyedUnkeyedArray.Found, Universal.Arrays.MixedArrayKeyTypes.ImplicitNumericKey
474 - 'compare' => '!=',
475 - 'key' => 'is_system',
476 - 'value' => 'yes',
477 - ],
478 - ],
479 - 'no_found_rows' => true,
480 - 'numberposts' => -1,
481 - 'order' => 'ASC',
482 - 'orderby' => 'post_title',
483 - 'post_type' => 'epi_embed',
484 - 'update_post_term_cache' => false,
485 - ], $args ) );
486 - $google_provider = \get_posts( \array_merge( [
487 - 'meta_key' => 'is_system',
488 - 'meta_value' => 'yes',
489 - 'name' => 'google-maps',
490 - 'no_found_rows' => true,
491 - 'post_type' => 'epi_embed',
492 - 'update_post_term_cache' => false,
493 - ], $args ) );
94 + foreach ( $sites as $site ) {
95 + \switch_to_blog( $site );
494 96
495 - if ( ! empty( $hash ) ) {
496 - $this->embeds[ $hash ] = \array_merge( $custom_providers, $google_provider );
497 - }
498 - else {
499 - $this->embeds[ $type ] = \array_merge( $custom_providers, $google_provider );
500 - }
501 - break;
502 - case 'oembed':
503 - $embed_providers = \get_posts( \array_merge( [
504 - 'meta_key' => 'is_system',
505 - 'meta_value' => 'yes',
506 - 'no_found_rows' => true,
507 - 'numberposts' => -1,
508 - 'order' => 'ASC',
509 - 'orderby' => 'post_title',
510 - 'post_type' => 'epi_embed',
511 - 'update_post_term_cache' => false,
512 - ], $args ) );
513 -
514 - if ( ! empty( $hash ) ) {
515 - $this->embeds[ $hash ] = $embed_providers;
516 - }
517 - else {
518 - $this->embeds[ $type ] = $embed_providers;
519 - }
520 - break;
521 - case 'all':
522 - default:
523 - $embed_providers = \get_posts( \array_merge( [
524 - 'no_found_rows' => true,
525 - 'numberposts' => -1,
526 - 'order' => 'ASC',
527 - 'orderby' => 'post_title',
528 - 'post_type' => 'epi_embed',
529 - 'update_post_term_cache' => false,
530 - ], $args ) );
531 -
532 - if ( ! empty( $hash ) ) {
533 - $this->embeds[ $hash ] = $embed_providers;
534 - }
535 - else {
536 - $this->embeds['all'] = $embed_providers;
537 - }
538 - break;
97 + $wpdb->query( $query );
98 + }
539 99 }
540 - // phpcs:enable
541 -
542 - if ( ! empty( $hash ) ) {
543 - return $this->embeds[ $hash ];
100 + else {
101 + $wpdb->query( $query );
544 102 }
545 -
546 - return $this->embeds[ $type ];
547 103 }
548 104
549 105 /**
550 - * Get a list with ignored shortcodes.
551 - *
552 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Shortcode::get_ignored() instead
553 - * @since 1.6.0
554 - *
555 - * @return string[] List with ignored shortcodes
106 + * Enqueue our assets for the frontend.
556 107 */
557 - public function get_ignored_shortcodes() {
558 - \_doing_it_wrong(
559 - __METHOD__,
560 - \sprintf(
561 - /* translators: alternative method */
562 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
563 - 'epiphyt\Embed_Privacy\Shortcode::get_ignored()'
564 - ),
565 - '1.10.0'
566 - );
108 + public function enqueue_assets() {
109 + $suffix = ( \defined( 'DEBUG_MODE' ) && \DEBUG_MODE ? '' : '.min' );
110 + $css_file = \EPI_EMBED_PRIVACY_BASE . 'assets/style/embed-privacy' . $suffix . '.css';
111 + $css_file_url = \EPI_EMBED_PRIVACY_URL . 'assets/style/embed-privacy' . $suffix . '.css';
567 112
568 - return $this->shortcode->get_ignored();
569 - }
570 -
571 - /**
572 - * Get a unique instance of the class.
573 - *
574 - * @since 1.1.0
575 - *
576 - * @return \epiphyt\Embed_Privacy\Embed_Privacy The single instance of this class
577 - */
578 - public static function get_instance() {
579 - if ( self::$instance === null ) {
580 - self::$instance = new self();
581 - }
113 + \wp_enqueue_style( 'embed-privacy', $css_file_url, [], \filemtime( $css_file ) );
582 114
583 - return self::$instance;
584 - }
585 -
586 - /**
587 - * Output a complete template of the overlay.
588 - *
589 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Template::get() instead
590 - * @since 1.1.0
591 - *
592 - * @param string $embed_provider The embed provider
593 - * @param string $embed_provider_lowercase The embed provider without spaces and in lowercase
594 - * @param string $output The output before replacing it
595 - * @param array $args Additional arguments
596 - * @return string The overlay template
597 - */
598 - public function get_output_template( $embed_provider, $embed_provider_lowercase, $output, $args = [] ) {
599 - \_doing_it_wrong(
600 - __METHOD__,
601 - \sprintf(
602 - /* translators: alternative method */
603 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
604 - 'epiphyt\Embed_Privacy\embed\Template::get()'
605 - ),
606 - '1.10.0'
607 - );
115 + $js_file = \EPI_EMBED_PRIVACY_BASE . 'assets/js/embed-privacy' . $suffix . '.js';
116 + $js_file_url = \EPI_EMBED_PRIVACY_URL . 'assets/js/embed-privacy' . $suffix . '.js';
608 117
609 - return Template::get( $embed_provider, $embed_provider_lowercase, $output, $args );
118 + \wp_enqueue_script( 'two-click_embed', $js_file_url, [], \filemtime( $js_file ) );
610 119 }
611 120
612 121 /**
613 - * Get a single overlay for all matching embeds.
614 - *
615 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
616 - * @since 1.2.0
617 - *
618 - * @param string $content The original content
619 - * @param string $embed_provider The embed provider
620 - * @param string $embed_provider_lowercase The embed provider without spaces and in lowercase
621 - * @param array $args Additional arguments
622 - * @return string The updated content
623 - */
624 - public function get_single_overlay( $content, $embed_provider, $embed_provider_lowercase, $args ) {
625 - \_doing_it_wrong(
626 - __METHOD__,
627 - \sprintf(
628 - /* translators: alternative method */
629 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
630 - 'epiphyt\Embed_Privacy\embed\Replacement::get()'
631 - ),
632 - '1.10.0'
633 - );
634 -
635 - $overlay = new Replacement( $content );
636 -
637 - return $overlay->get( $args );
638 - }
639 -
640 - /**
641 - * Get dynamically generated style.
642 - *
643 - * @deprecated 1.10.0
644 - *
645 - * @return string Dynamically generated style
646 - */
647 - public function get_style() {
648 - \_doing_it_wrong(
649 - __METHOD__,
650 - \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
651 - '1.10.0'
652 - );
653 -
654 - /**
655 - * Filter the style properties before generating dynamic styles.
656 - *
657 - * @deprecated 1.10.0
658 - * @since 1.9.0
659 - *
660 - * @param array $style_properties Style properties array
661 - */
662 - $this->style = (array) \apply_filters_deprecated( 'embed_privacy_dynamic_style_properties', $this->style, '1.10.0' );
663 -
664 - /**
665 - * Filter dynamic generated style.
666 - *
667 - * @deprecated 1.10.0
668 - * @since 1.9.0
669 - *
670 - * @param string $style Generated style
671 - * @param array $style_properties Style properties array
672 - */
673 - $style = \apply_filters_deprecated( 'embed_privacy_dynamic_style', '', $this->style, '1.10.0' ); // phpcs:ignore SlevomatCodingStandard.Variables.UselessVariable.UselessVariable
674 -
675 - return $style;
676 - }
677 -
678 - /**
679 - * Check if a post contains an embed.
680 - *
681 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Post::has_embed() instead
682 - * @since 1.3.0
683 - *
684 - * @param \WP_Post|int|null $post A post object, post ID or null
685 - * @return bool True if a post contains an embed, false otherwise
686 - */
687 - public function has_embed( $post = null ) {
688 - \_doing_it_wrong(
689 - __METHOD__,
690 - \sprintf(
691 - /* translators: alternative method */
692 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
693 - 'epiphyt\Embed_Privacy\handler\Post::has_embed()'
694 - ),
695 - '1.10.0'
696 - );
697 -
698 - return Post::has_embed( $post );
699 - }
700 -
701 - /**
702 - * Check if a provider is always active.
703 - *
704 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::is_always_active() instead
705 - * @since 1.1.0
706 - *
707 - * @param string $provider The embed provider in lowercase
708 - * @return bool True if provider is always active, false otherwise
709 - */
710 - public function is_always_active_provider( $provider ) {
711 - \_doing_it_wrong(
712 - __METHOD__,
713 - \sprintf(
714 - /* translators: alternative method */
715 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
716 - 'epiphyt\Embed_Privacy\data\Providers::is_always_active()'
717 - ),
718 - '1.10.0'
719 - );
720 -
721 - return Providers::is_always_active( $provider );
722 - }
723 -
724 - /**
725 - * Check if a post is written in Elementor.
726 - *
727 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Elementor::is_used() instead
728 - * @since 1.3.5
729 - *
730 - * @return bool True if Elementor is used, false otherwise
731 - */
732 - public function is_elementor() {
733 - \_doing_it_wrong(
734 - __METHOD__,
735 - \sprintf(
736 - /* translators: alternative method */
737 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
738 - 'epiphyt\Embed_Privacy\integration\Elementor::is_used()'
739 - ),
740 - '1.10.0'
741 - );
742 -
743 - return Elementor::is_used();
744 - }
745 -
746 - /**
747 - * Check if the current theme is matching your name.
748 - *
749 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Theme::is() instead
750 - * @since 1.3.5
751 - *
752 - * @param string $name The theme name to test
753 - * @return bool True if the current theme is matching, false otherwise
754 - */
755 - public function is_theme( $name ) {
756 - \_doing_it_wrong(
757 - __METHOD__,
758 - \sprintf(
759 - /* translators: alternative method */
760 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
761 - 'epiphyt\Embed_Privacy\handler\Theme::is()'
762 - ),
763 - '1.10.0'
764 - );
765 -
766 - return Theme::is( $name );
767 - }
768 -
769 - /**
770 122 * Load the translation files.
771 123 */
772 124 public function load_textdomain() {
773 - \load_plugin_textdomain( 'embed-privacy', false, \dirname( \plugin_basename( $this->plugin_file ) ) . '/languages' );
125 + \load_plugin_textdomain( 'embed-privacy', false, \EPI_EMBED_PRIVACY_BASE . 'languages' );
774 126 }
775 127
776 128 /**
777 - * Callback for the page output buffer.
778 - *
779 - * @deprecated 1.10.0
780 - *
781 - * @param string $buffer Current buffer
782 - * @return string Updated buffer
783 - */
784 - public function output_buffer_callback( $buffer ) {
785 - \_doing_it_wrong(
786 - __METHOD__,
787 - \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
788 - '1.10.0'
789 - );
790 -
791 - return $buffer;
792 - }
793 -
794 - /**
795 - * Preserve backslashes in regex field.
796 - *
797 - * @since 1.4.0
798 - */
799 - public function preserve_backslashes() {
800 - // phpcs:disable WordPress.Security.NonceVerification.Missing
801 - if ( ! isset( $_POST['regex_default'] ) ) {
802 - return;
803 - }
804 -
805 - $_POST['regex_default'] = \wp_slash( $_POST['regex_default'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
806 - // phpcs:enable
807 - }
808 -
809 - /**
810 - * Handle printing assets.
811 - *
812 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Frontend::print_assets() instead
813 - * @since 1.3.0
814 - */
815 - public function print_assets() {
816 - \_doing_it_wrong(
817 - __METHOD__,
818 - \sprintf(
819 - /* translators: alternative method */
820 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
821 - 'epiphyt\Embed_Privacy\Frontend::print_assets()'
822 - ),
823 - '1.10.0'
824 - );
825 - $this->frontend->print_assets();
826 - }
827 -
828 - /**
829 - * Register our assets for the frontend.
830 - *
831 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Frontend::register_assets() instead
832 - * @since 1.4.4
833 - */
834 - public function register_assets() {
835 - \_doing_it_wrong(
836 - __METHOD__,
837 - \sprintf(
838 - /* translators: alternative method */
839 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
840 - 'epiphyt\Embed_Privacy\Frontend::register_assets()'
841 - ),
842 - '1.10.0'
843 - );
844 - $this->frontend->register_assets();
845 - }
846 -
847 - /**
848 - * Register post type in Polylang to allow translation.
849 - *
850 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Polylang::register_post_type() instead
851 - * @since 1.5.0
852 - *
853 - * @param array $post_types List of current translatable custom post types
854 - * @param bool $is_settings Whether the current page is the settings page
855 - * @return array Updated list of translatable custom post types
856 - */
857 - public function register_polylang_post_type( array $post_types, $is_settings ) {
858 - \_doing_it_wrong(
859 - __METHOD__,
860 - \sprintf(
861 - /* translators: alternative method */
862 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
863 - 'epiphyt\Embed_Privacy\integration\Polylang::register_post_type()'
864 - ),
865 - '1.10.0'
866 - );
867 -
868 - return Polylang::register_post_type( $post_types, $is_settings );
869 - }
870 -
871 - /**
872 - * Register post type.
873 - *
874 - * @since 1.10.0
875 - */
876 - public static function register_post_type() {
877 - \register_post_type(
878 - 'epi_embed',
879 - [ // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder
880 - 'label' => \__( 'Embeds', 'embed-privacy' ),
881 - 'description' => \__( 'Embeds from Embed Privacy', 'embed-privacy' ),
882 - 'supports' => [
883 - 'custom-fields',
884 - 'editor',
885 - 'revisions',
886 - 'thumbnail',
887 - 'title',
888 - ],
889 - 'hierarchical' => false,
890 - 'public' => false,
891 - 'menu_icon' => 'dashicons-format-video',
892 - 'show_in_admin_bar' => false,
893 - 'show_in_menu' => false,
894 - 'show_in_nav_menus' => false,
895 - 'show_in_rest' => false,
896 - 'show_ui' => true,
897 - 'can_export' => true,
898 - 'has_archive' => false,
899 - 'exclude_from_search' => true,
900 - 'publicly_queryable' => false,
901 - 'rewrite' => [
902 - 'pages' => false,
903 - 'with_front' => false,
904 - ],
905 - ]
906 - );
907 - }
908 -
909 - /**
910 129 * Replace embeds with a container and hide the embed with an HTML comment.
911 130 *
912 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_embeds() instead
913 - * @since 1.2.0 Changed behavior of the method
914 - * @since 1.6.0 Added optional $tag parameter
915 - *
916 - * @param string $content The original content
917 - * @param string $tag The shortcode tag if called via do_shortcode
918 - * @return string The updated content
131 + * @param string $output
132 + * @param string $url
133 + * @param array $args
134 + * @return string
919 135 */
920 - public function replace_embeds( $content, $tag = '' ) {
921 - \_doing_it_wrong(
922 - __METHOD__,
923 - \sprintf(
924 - /* translators: alternative method */
925 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
926 - 'epiphyt\Embed_Privacy\data\Replacer::replace_embeds()'
927 - ),
928 - '1.10.0'
929 - );
136 + public function replace_embeds( $output, $url, $args ) {
137 + // don't do anything in admin
138 + if ( ! $this->usecache ) return $output;
930 139
931 - return Replacer::replace_embeds( $content, $tag );
932 - }
933 -
934 - /**
935 - * Replace oembed embeds with a container and hide the embed with an HTML comment.
936 - *
937 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_oembed() instead
938 - * @since 1.2.0
939 - *
940 - * @param string $output The original output
941 - * @param string $url The URL to the embed
942 - * @param array $args Additional arguments of the embed
943 - * @return string The updated embed code
944 - */
945 - public function replace_embeds_oembed( $output, $url, $args ) {
946 - \_doing_it_wrong(
947 - __METHOD__,
948 - \sprintf(
949 - /* translators: alternative method */
950 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
951 - 'epiphyt\Embed_Privacy\data\Replacer::replace_oembed()'
952 - ),
953 - '1.10.0'
954 - );
140 + $embed_provider = '';
955 141
956 - return Replacer::replace_oembed( $output, $url, $args );
957 - }
958 -
959 - /**
960 - * Replace embeds in Divi Builder.
961 - *
962 - * @deprecated 1.10.0
963 - * @since 1.2.0
964 - * @since 1.6.0 Deprecated second parameter
965 - *
966 - * @param string $item_embed The original output
967 - * @param string $url The URL of the embed
968 - * @return string The updated embed code
969 - */
970 - public function replace_embeds_divi( $item_embed, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
971 - \_doing_it_wrong(
972 - __METHOD__,
973 - \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
974 - '1.10.0'
975 - );
976 -
977 - return $item_embed;
978 - }
979 -
980 - /**
981 - * Replace twitter embeds.
982 - *
983 - * @deprecated 1.6.3
984 - * @since 1.6.1
985 - *
986 - * @param string $output The original output
987 - * @param string $url The URL to the embed
988 - * @param array $args Additional arguments of the embed
989 - * @return string The updated embed code
990 - */
991 - public function replace_embeds_twitter( $output, $url, $args ) {
992 - \_doing_it_wrong(
993 - __METHOD__,
994 - \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
995 - '1.6.3'
996 - );
997 -
998 - // do nothing in admin
999 - if ( ! $this->use_cache ) {
1000 - return $output;
142 + // get embed provider name
143 + foreach ( $this->embed_providers as $url_part => $name ) {
144 + // save name of provider and stop loop
145 + if ( \strpos( $url, $url_part ) !== false ) {
146 + $embed_provider = $name;
147 + break;
148 + }
1001 149 }
1002 150
1003 - $provider = Providers::get_instance()->get_by_name( 'twitter' );
151 + // add two click to markup
152 + $embed_class = ' embed-' . ( ! empty( $embed_provider ) ? \sanitize_title( $embed_provider ) : 'default' );
153 + $height = ( ! empty( $args['height'] ) && $args['height'] <= $args['width'] ? 'height: ' . $args['height'] . 'px;' : 'height: 300px;' );
154 + $width = ( ! empty( $args['width'] ) ? 'width: ' . $args['width'] . 'px;' : '' );
155 + $markup = '<div class="embed-container' . $embed_class . '">';
156 + $markup .= '<div class="embed-overlay" style="' . $height . ' ' . $width . '">';
157 + $markup .= '<h3>';
1004 158
1005 - if ( ! $provider->is_matching( $url ) ) {
1006 - return $output;
159 + if ( ! empty( $embed_provider ) ) {
160 + /* translators: the embed provider */
161 + $markup .= \sprintf( \esc_html__( 'Click here to display content from %s', 'embed-privacy' ), $embed_provider );
1007 162 }
1008 -
1009 - if ( Providers::is_always_active( $provider->get_name() ) ) {
1010 - return $output;
163 + else {
164 + $markup .= \esc_html__( 'Click here to display content from external service', 'embed-privacy' );
1011 165 }
1012 166
1013 - if ( \get_option( 'embed_privacy_local_tweets' ) ) {
1014 - // check for local tweets
1015 - return Twitter::get_local_tweet( $output );
1016 - }
167 + $markup .= '</h3>';
168 + $markup .= '</div>';
169 + $markup .= '<div class="embed-content"><!-- ' . $output . ' --></div>';
170 + $markup .= '</div>';
1017 171
1018 - $args['embed_url'] = $url;
1019 - $args['ignore_aspect_ratio'] = true;
1020 - $args['strip_newlines'] = true;
1021 -
1022 - return Template::get( $provider, $output, $args );
1023 - }
1024 -
1025 - /**
1026 - * Replace Google Maps iframes.
1027 - *
1028 - * @deprecated 1.2.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
1029 - * @since 1.1.0
1030 - *
1031 - * @param string $content The post content
1032 - * @return string The post content
1033 - */
1034 - public function replace_google_maps( $content ) {
1035 - \_doing_it_wrong(
1036 - __METHOD__,
1037 - \sprintf(
1038 - /* translators: alternative method */
1039 - \esc_html__( 'Use %s instead.', 'embed-privacy' ),
1040 - 'epiphyt\Embed_Privacy\embed\Replacement::get()'
1041 - ),
1042 - '1.2.0'
1043 - );
1044 -
1045 - $overlay = new Replacement( $content );
1046 -
1047 - return $overlay->get();
1048 - }
1049 -
1050 - /**
1051 - * Replace Maps Marker (Pro) shortcodes.
1052 - *
1053 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Maps_Marker::replace() instead
1054 - * @since 1.5.0
1055 - *
1056 - * @param string $output Shortcode output
1057 - * @param string $tag Shortcode tag
1058 - * @return string Updated shortcode output
1059 - */
1060 - public function replace_maps_marker( $output, $tag ) {
1061 - \_doing_it_wrong(
1062 - __METHOD__,
1063 - \sprintf(
1064 - /* translators: alternative method */
1065 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
1066 - 'epiphyt\Embed_Privacy\integration\Maps_Marker::replace()'
1067 - ),
1068 - '1.10.0'
1069 - );
1070 -
1071 - return Maps_Marker::replace( $output, $tag );
1072 - }
1073 -
1074 - /**
1075 - * Replace video shortcode embeds.
1076 - *
1077 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_video_shortcode() instead
1078 - * @since 1.7.0
1079 - *
1080 - * @param string $output Video shortcode HTML output
1081 - * @param array $atts Array of video shortcode attributes
1082 - * @return string Updated embed code
1083 - */
1084 - public function replace_video_shortcode( $output, $atts ) {
1085 - \_doing_it_wrong(
1086 - __METHOD__,
1087 - \sprintf(
1088 - /* translators: alternative method */
1089 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
1090 - 'epiphyt\Embed_Privacy\data\Replacer::replace_video_shortcode()'
1091 - ),
1092 - '1.10.0'
1093 - );
1094 -
1095 - return Replacer::replace_video_shortcode( $output, $atts );
1096 - }
1097 -
1098 - /**
1099 - * Run a compare check.
1100 - *
1101 - * @since 1.4.4
1102 - *
1103 - * @param mixed $value1 First value to compare
1104 - * @param mixed $value2 Second value to compare
1105 - * @param string $compare Compare operator
1106 - * @return bool Result of comparing the values
1107 - */
1108 - private function run_check_compare( $value1, $value2, $compare ) {
1109 - switch ( $compare ) {
1110 - case '===':
1111 - return $value1 === $value2;
1112 - case '==':
1113 - return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1114 - case '!==':
1115 - return $value1 !== $value2;
1116 - case '!=':
1117 - return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1118 - case '>':
1119 - return $value1 > $value2;
1120 - case '>=':
1121 - return $value1 >= $value2;
1122 - case '<':
1123 - return $value1 < $value2;
1124 - case '<=':
1125 - return $value1 <= $value2;
1126 - default:
1127 - return false;
1128 - }
1129 - }
1130 -
1131 - /**
1132 - * Run additional for a DOM node checks.
1133 - *
1134 - * @since 1.4.4
1135 - * @since 1.10.0 Method is now public
1136 - *
1137 - * @param array $checks A list of checks
1138 - * @param \DOMElement $element The DOM Element
1139 - * @return bool Whether all checks are successful
1140 - */
1141 - public function run_checks( $checks, $element ) {
1142 - if ( empty( $checks ) ) {
1143 - return true;
1144 - }
1145 -
1146 - foreach ( $checks as $check ) {
1147 - if ( $check['type'] === 'attribute' ) {
1148 - $compared = $this->run_check_compare( $element->getAttribute( $check['attribute'] ), $check['value'], $check['compare'] );
1149 -
1150 - if ( ! $compared ) {
1151 - return false;
1152 - }
1153 - }
1154 - }
1155 -
1156 - return true;
1157 - }
1158 -
1159 - /**
1160 - * Check whether this request should be ignored by Embed Privacy.
1161 - *
1162 - * @since 1.10.0
1163 - */
1164 - public function set_ignored_request() {
1165 - /**
1166 - * Filter whether the current request should be ignored.
1167 - *
1168 - * @since 1.10.0
1169 - *
1170 - * @param bool $is_ignored_request Whether the current request should be ignored
1171 - */
1172 - $this->is_ignored_request = (bool) \apply_filters( 'embed_privacy_is_ignored_request', $this->is_ignored_request );
1173 - }
1174 -
1175 - /**
1176 - * Set the plugin file.
1177 - *
1178 - * @deprecated 1.10.0 Use \EPI_EMBED_PRIVACY_FILE instead
1179 - * @since 1.1.0
1180 - *
1181 - * @param string $file The path to the file
1182 - */
1183 - public function set_plugin_file( $file ) {
1184 - if ( \file_exists( $file ) ) {
1185 - $this->plugin_file = $file;
1186 - }
1187 - }
1188 -
1189 - /**
1190 - * Register post type.
1191 - *
1192 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy:\Embed_Privacy:register_post_type() instead
1193 - * @since 1.2.0
1194 - */
1195 - public function set_post_type() {
1196 - \_doing_it_wrong(
1197 - __METHOD__,
1198 - \sprintf(
1199 - /* translators: alternative method */
1200 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
1201 - 'epiphyt\Embed_Privacy\Embed_Privacy::register_post_type()'
1202 - ),
1203 - '1.10.0'
1204 - );
1205 - self::register_post_type();
1206 - }
1207 -
1208 - /**
1209 - * Display an Opt-out shortcode.
1210 - *
1211 - * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Shortcode::opt_out() instead
1212 - * @since 1.2.0
1213 - *
1214 - * @param array $attributes Shortcode attributes
1215 - * @return string The shortcode output
1216 - */
1217 - public function shortcode_opt_out( $attributes ) {
1218 - \_doing_it_wrong(
1219 - __METHOD__,
1220 - \sprintf(
1221 - /* translators: alternative method */
1222 - \esc_html__( 'Use %s instead', 'embed-privacy' ),
1223 - 'epiphyt\Embed_Privacy\handler\Shortcode::opt_out()'
1224 - ),
1225 - '1.10.0'
1226 - );
1227 -
1228 - return Shortcode::opt_out( $attributes );
1229 - }
1230 -
1231 - /**
1232 - * Start an output buffer.
1233 - *
1234 - * @deprecated 1.10.0
1235 - */
1236 - public function start_output_buffer() {
1237 - \_doing_it_wrong(
1238 - __METHOD__,
1239 - \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
1240 - '1.10.0'
1241 - );
172 + return $markup;
1242 173 }
1243 174 }