| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\handler; |
| 3 |
|
| 4 |
/** |
| 5 |
* Feed handler. |
| 6 |
* |
| 7 |
* @author Epiphyt |
| 8 |
* @license GPL2 |
| 9 |
* @package epiphyt\Embed_Privacy |
| 10 |
* @since 1.11.2 |
| 11 |
*/ |
| 12 |
final class Feed { |
| 13 |
/** |
| 14 |
* Initialize functionality. |
| 15 |
*/ |
| 16 |
public static function init() { |
| 17 |
\add_filter( 'embed_privacy_template_markup', [ self::class, 'replace_template' ], 10, 3 ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Replace template in feeds with a link. |
| 22 |
* |
| 23 |
* @param string $markup Embed overlay markup |
| 24 |
* @param \epiphyt\Embed_Privacy\embed\Provider $provider Embed provider |
| 25 |
* @param array $attributes Embed attributes |
| 26 |
* @return string Link markup |
| 27 |
*/ |
| 28 |
public static function replace_template( $markup, $provider, $attributes ) { |
| 29 |
if ( ! \is_feed() ) { |
| 30 |
return $markup; |
| 31 |
} |
| 32 |
|
| 33 |
return self::get_link_markup( $attributes, $provider ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get link markup for the embedded content. |
| 38 |
* |
| 39 |
* @param mixed[] $attributes Embed attributes |
| 40 |
* @param \epiphyt\Embed_Privacy\embed\Provider $provider Embed provider |
| 41 |
* @return string Link markup |
| 42 |
*/ |
| 43 |
public static function get_link_markup( $attributes, $provider ) { |
| 44 |
return \sprintf( |
| 45 |
'<span class="embed-privacy-url"><a href="%1$s">%2$s</a></span>', |
| 46 |
\esc_url( $attributes['embed_url'] ), |
| 47 |
\sprintf( |
| 48 |
/* translators: embed provider title */ |
| 49 |
\esc_html__( 'Open embedded content from %s', 'embed-privacy' ), |
| 50 |
\esc_html( $provider->get_title() ) |
| 51 |
) |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
|