Skip to content

Commit

Permalink
Merge pull request #43 from itteco/v1.1.0
Browse files Browse the repository at this point in the history
V1.1.0
  • Loading branch information
yellowby authored Dec 4, 2023
2 parents d3255e4 + 1dbba46 commit eb99984
Show file tree
Hide file tree
Showing 28 changed files with 15,394 additions and 12,892 deletions.
1 change: 1 addition & 0 deletions admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/Embed/Amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function is_iframely_amp($args): bool
|| (function_exists('is_amp_endpoint') && is_amp_endpoint());
}

public static function maybe_add_iframe_amp($provider, $args, $url)
public static function maybe_add_iframe_amp($provider, $url, $args)
{
if (self::is_iframely_amp($args) && Utils::stringContains($provider, 'iframe.ly')) {
$provider = add_query_arg('amp', '1', $provider);
Expand Down
45 changes: 37 additions & 8 deletions app/Embed/Gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static function run(): void

public static function init(): void
{
# Always extract &iframely={serialized options} that we append to URLs
# and add these options into the oEmbed endpoint's query-string parameters
add_filter('oembed_fetch_url', [self::class, 'maybe_add_iframely_url_options'], 20, 3);

if (!current_user_can('edit_posts')) {
return;
}
Expand All @@ -31,7 +35,7 @@ public static function init(): void
public static function iframely_flag_ajax_oembed($width)
{
add_filter('embed_defaults', [self::class, 'iframely_bust_gutenberg_cache'], 10, 1);
add_filter('oembed_fetch_url', [self::class, 'maybe_add_gutenberg_1'], 10, 3);
add_filter('oembed_fetch_url', [self::class, 'maybe_add_gutenberg_1'], 20, 3);
add_filter('oembed_result', [self::class, 'inject_events_proxy_to_gutenberg'], 10, 3);

# The core's code doesn't even bother to look into default values and just hardcodes 600.
Expand All @@ -44,25 +48,50 @@ public static function iframely_flag_ajax_oembed($width)

public static function iframely_bust_gutenberg_cache($args)
{
$args['gutenberg'] = 1;
$args['gutenberg'] = 2;
return $args;
}

public static function maybe_add_gutenberg_1($provider, $args, $url)
public static function maybe_add_gutenberg_1($provider, $url, $args)
{
if (Utils::stringContains($provider, 'iframe.ly')) {
if (!Utils::stringContains($provider, 'iframe=card')) {
$provider = add_query_arg('iframe', '1', $provider);
$provider = add_query_arg('iframe', '1', $provider);
$provider = add_query_arg('import', '0', $provider);
$provider = add_query_arg('ssl', '1', $provider);
$provider = add_query_arg('gutenberg', '2', $provider);
}
return $provider;
}

public static function maybe_add_iframely_url_options($provider, $url, $args)
{
# Options are added to URL the URL in utils.js this way:
# 'iframely=' + encodeURIComponent(window.btoa(JSON.stringify(query)));
if (Utils::stringContains($provider, 'iframe.ly') && Utils::stringContains($url, 'iframely=')) {
$parsed_url = parse_url($url);
if (isset($parsed_url['query'])) {
$params = array();
parse_str($parsed_url['query'], $params);

if (isset($params['iframely'])) {
$options_str = base64_decode(urldecode($params['iframely']));
$options_query = json_decode($options_str);

foreach ($options_query as $key => $value) {
$provider = add_query_arg($key, $value, $provider);
}
}
}
$provider = add_query_arg('gutenberg', '1', $provider);
}
return $provider;
}

public static function inject_events_proxy_to_gutenberg($html, $url, $args)
{
if (!empty(trim($html))) { // != trims $html
return $html . '<script type="text/javascript">window.addEventListener("message",function(e){window.parent.postMessage(e.data,"*");},false);</script>';
if (!empty(trim($html))) {
return $html .
'<style>body{overflow: hidden}</style>' .
'<script type="text/javascript">window.addEventListener("message",function(e){window.top.postMessage(e.data,"*");},false);</script>';
}
return $html;
}
Expand Down
23 changes: 17 additions & 6 deletions app/Embed/Oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Iframely\Embed;
use Iframely\Options;
use Iframely\Utils;

class Oembed
{
Expand All @@ -23,6 +24,9 @@ public static function run(): void

# Always add iframely as oembed provider for any iframe.ly short link
wp_oembed_add_provider('#https?://iframe\.ly/.+#i', Embed::createApiLink(), true);

# Fix URL query-string settings by replacing &iframe=card into &iframe=1&card=1
add_filter('oembed_fetch_url', [self::class, 'maybe_replace_iframe_card'], 10, 3);
}

public static function maybe_remove_wp_self_embeds($result, $url, $args)
Expand All @@ -40,10 +44,17 @@ public static function maybe_reverse_oembed_providers($providers)

return $providers;
}
}






public static function maybe_replace_iframe_card($provider, $url, $args)
{
if (Utils::stringContains($provider, 'iframe.ly') && Utils::stringContains($provider, 'iframe=card')) {
if (Utils::stringContains($provider, 'iframe=card-small')) {
$provider = add_query_arg('card', 'small', $provider);
} else {
$provider = add_query_arg('card', '1', $provider);
}
$provider = add_query_arg('iframe', '1', $provider);
}
return $provider;
}
}
12 changes: 9 additions & 3 deletions app/UI/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public static function run(): void

// Load assets
add_action('admin_enqueue_scripts', [self::class, 'enqueue']);
add_action('enqueue_block_editor_assets', [self::class, 'enqueueEditor']);
}

public static function register(): void
{
if (is_multisite()) {
add_submenu_page('settings.php', __('Iframely', 'iframely'), __('Iframely', 'iframely'), 'install_plugins', 'iframely', [self::class, 'render']);
add_submenu_page('settings.php', __('Iframely', 'iframely'), __('Iframely', 'iframely'), 'manage_network_options', 'iframely', [self::class, 'render']);
} else {
add_options_page(__('Iframely', 'iframely'), __('Iframely', 'iframely'), 'manage_options', 'iframely', [self::class, 'render']);
}
Expand All @@ -36,11 +37,16 @@ public static function register(): void
public static function enqueue(): void
{
$screen = get_current_screen();
$screens = ['post', 'settings_page_iframely-network', 'settings_page_iframely'];
$screens = ['settings_page_iframely-network', 'settings_page_iframely'];
if (!($screen !== null && in_array($screen->id, $screens))) {
return;
}
wp_enqueue_style('iframely-admin', Plugin::asset('index.css'), [], IFRAMELY_VERSION);
wp_enqueue_style('iframely-admin', Plugin::asset('admin.css'), [], IFRAMELY_VERSION);
}

public static function enqueueEditor(): void
{
wp_enqueue_style('iframely-options', Plugin::asset('index.css'), [], IFRAMELY_VERSION);
}

public static function render(): void
Expand Down
1 change: 1 addition & 0 deletions build/admin.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => 'c51082815623e6e262ce');
1 change: 1 addition & 0 deletions build/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added build/admin.js
Empty file.
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '2b787e75d61c1a84f7e7');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'a4ffcff9e90dcd142020');
Loading

0 comments on commit eb99984

Please sign in to comment.