Skip to content

Commit eb99984

Browse files
authored
Merge pull request #43 from itteco/v1.1.0
V1.1.0
2 parents d3255e4 + 1dbba46 commit eb99984

28 files changed

+15394
-12892
lines changed

admin.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Embed/Amp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function is_iframely_amp($args): bool
2323
|| (function_exists('is_amp_endpoint') && is_amp_endpoint());
2424
}
2525

26-
public static function maybe_add_iframe_amp($provider, $args, $url)
26+
public static function maybe_add_iframe_amp($provider, $url, $args)
2727
{
2828
if (self::is_iframely_amp($args) && Utils::stringContains($provider, 'iframe.ly')) {
2929
$provider = add_query_arg('amp', '1', $provider);

app/Embed/Gutenberg.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public static function run(): void
1515

1616
public static function init(): void
1717
{
18+
# Always extract &iframely={serialized options} that we append to URLs
19+
# and add these options into the oEmbed endpoint's query-string parameters
20+
add_filter('oembed_fetch_url', [self::class, 'maybe_add_iframely_url_options'], 20, 3);
21+
1822
if (!current_user_can('edit_posts')) {
1923
return;
2024
}
@@ -31,7 +35,7 @@ public static function init(): void
3135
public static function iframely_flag_ajax_oembed($width)
3236
{
3337
add_filter('embed_defaults', [self::class, 'iframely_bust_gutenberg_cache'], 10, 1);
34-
add_filter('oembed_fetch_url', [self::class, 'maybe_add_gutenberg_1'], 10, 3);
38+
add_filter('oembed_fetch_url', [self::class, 'maybe_add_gutenberg_1'], 20, 3);
3539
add_filter('oembed_result', [self::class, 'inject_events_proxy_to_gutenberg'], 10, 3);
3640

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

4549
public static function iframely_bust_gutenberg_cache($args)
4650
{
47-
$args['gutenberg'] = 1;
51+
$args['gutenberg'] = 2;
4852
return $args;
4953
}
5054

51-
public static function maybe_add_gutenberg_1($provider, $args, $url)
55+
public static function maybe_add_gutenberg_1($provider, $url, $args)
5256
{
5357
if (Utils::stringContains($provider, 'iframe.ly')) {
54-
if (!Utils::stringContains($provider, 'iframe=card')) {
55-
$provider = add_query_arg('iframe', '1', $provider);
58+
$provider = add_query_arg('iframe', '1', $provider);
59+
$provider = add_query_arg('import', '0', $provider);
60+
$provider = add_query_arg('ssl', '1', $provider);
61+
$provider = add_query_arg('gutenberg', '2', $provider);
62+
}
63+
return $provider;
64+
}
65+
66+
public static function maybe_add_iframely_url_options($provider, $url, $args)
67+
{
68+
# Options are added to URL the URL in utils.js this way:
69+
# 'iframely=' + encodeURIComponent(window.btoa(JSON.stringify(query)));
70+
if (Utils::stringContains($provider, 'iframe.ly') && Utils::stringContains($url, 'iframely=')) {
71+
$parsed_url = parse_url($url);
72+
if (isset($parsed_url['query'])) {
73+
$params = array();
74+
parse_str($parsed_url['query'], $params);
75+
76+
if (isset($params['iframely'])) {
77+
$options_str = base64_decode(urldecode($params['iframely']));
78+
$options_query = json_decode($options_str);
79+
80+
foreach ($options_query as $key => $value) {
81+
$provider = add_query_arg($key, $value, $provider);
82+
}
83+
}
5684
}
57-
$provider = add_query_arg('gutenberg', '1', $provider);
5885
}
5986
return $provider;
6087
}
6188

6289
public static function inject_events_proxy_to_gutenberg($html, $url, $args)
6390
{
64-
if (!empty(trim($html))) { // != trims $html
65-
return $html . '<script type="text/javascript">window.addEventListener("message",function(e){window.parent.postMessage(e.data,"*");},false);</script>';
91+
if (!empty(trim($html))) {
92+
return $html .
93+
'<style>body{overflow: hidden}</style>' .
94+
'<script type="text/javascript">window.addEventListener("message",function(e){window.top.postMessage(e.data,"*");},false);</script>';
6695
}
6796
return $html;
6897
}

app/Embed/Oembed.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Iframely\Embed;
66
use Iframely\Options;
7+
use Iframely\Utils;
78

89
class Oembed
910
{
@@ -23,6 +24,9 @@ public static function run(): void
2324

2425
# Always add iframely as oembed provider for any iframe.ly short link
2526
wp_oembed_add_provider('#https?://iframe\.ly/.+#i', Embed::createApiLink(), true);
27+
28+
# Fix URL query-string settings by replacing &iframe=card into &iframe=1&card=1
29+
add_filter('oembed_fetch_url', [self::class, 'maybe_replace_iframe_card'], 10, 3);
2630
}
2731

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

4145
return $providers;
4246
}
43-
}
44-
45-
46-
47-
48-
4947

48+
public static function maybe_replace_iframe_card($provider, $url, $args)
49+
{
50+
if (Utils::stringContains($provider, 'iframe.ly') && Utils::stringContains($provider, 'iframe=card')) {
51+
if (Utils::stringContains($provider, 'iframe=card-small')) {
52+
$provider = add_query_arg('card', 'small', $provider);
53+
} else {
54+
$provider = add_query_arg('card', '1', $provider);
55+
}
56+
$provider = add_query_arg('iframe', '1', $provider);
57+
}
58+
return $provider;
59+
}
60+
}

app/UI/Settings.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public static function run(): void
2222

2323
// Load assets
2424
add_action('admin_enqueue_scripts', [self::class, 'enqueue']);
25+
add_action('enqueue_block_editor_assets', [self::class, 'enqueueEditor']);
2526
}
2627

2728
public static function register(): void
2829
{
2930
if (is_multisite()) {
30-
add_submenu_page('settings.php', __('Iframely', 'iframely'), __('Iframely', 'iframely'), 'install_plugins', 'iframely', [self::class, 'render']);
31+
add_submenu_page('settings.php', __('Iframely', 'iframely'), __('Iframely', 'iframely'), 'manage_network_options', 'iframely', [self::class, 'render']);
3132
} else {
3233
add_options_page(__('Iframely', 'iframely'), __('Iframely', 'iframely'), 'manage_options', 'iframely', [self::class, 'render']);
3334
}
@@ -36,11 +37,16 @@ public static function register(): void
3637
public static function enqueue(): void
3738
{
3839
$screen = get_current_screen();
39-
$screens = ['post', 'settings_page_iframely-network', 'settings_page_iframely'];
40+
$screens = ['settings_page_iframely-network', 'settings_page_iframely'];
4041
if (!($screen !== null && in_array($screen->id, $screens))) {
4142
return;
4243
}
43-
wp_enqueue_style('iframely-admin', Plugin::asset('index.css'), [], IFRAMELY_VERSION);
44+
wp_enqueue_style('iframely-admin', Plugin::asset('admin.css'), [], IFRAMELY_VERSION);
45+
}
46+
47+
public static function enqueueEditor(): void
48+
{
49+
wp_enqueue_style('iframely-options', Plugin::asset('index.css'), [], IFRAMELY_VERSION);
4450
}
4551

4652
public static function render(): void

build/admin.asset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('dependencies' => array(), 'version' => 'c51082815623e6e262ce');

build/admin.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/admin.js

Whitespace-only changes.

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '2b787e75d61c1a84f7e7');
1+
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'a4ffcff9e90dcd142020');

0 commit comments

Comments
 (0)