Skip to content

Commit b60836a

Browse files
committed
New version
1 parent 5e24061 commit b60836a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+41654
-10
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
max_line_length = 120
10+
tab_width = 4
11+
trim_trailing_whitespace = true
12+
13+
[*.js]
14+
indent_size = 2
15+
16+
[*.scss]
17+
indent_size = 2
18+
19+
[views/**.php]
20+
indent_size = 2

.gitignore

Lines changed: 124 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,125 @@
1-
.gitignore
2-
iframely/node_modules
3-
.idea
1+
### Node template
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Microbundle cache
58+
.rpt2_cache/
59+
.rts2_cache_cjs/
60+
.rts2_cache_es/
61+
.rts2_cache_umd/
62+
63+
# Optional REPL history
64+
.node_repl_history
465

5-
# Repository inside plugin directory
6-
.babelrc
7-
iframely.php
8-
readme.txt
9-
src*
10-
ui*
11-
.DS_Store
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
.env.test
75+
76+
# parcel-bundler cache (https://parceljs.org/)
77+
.cache
78+
.parcel-cache
79+
80+
# Next.js build output
81+
.next
82+
out
83+
84+
# Nuxt.js build / generate output
85+
.nuxt
86+
dist
87+
88+
# Gatsby files
89+
.cache/
90+
# Comment in the public line in if your project uses Gatsby and not Next.js
91+
# https://nextjs.org/blog/next-9-1#public-directory-support
92+
# public
93+
94+
# vuepress build output
95+
.vuepress/dist
96+
97+
# Serverless directories
98+
.serverless/
99+
100+
# FuseBox cache
101+
.fusebox/
102+
103+
# DynamoDB Local files
104+
.dynamodb/
105+
106+
# TernJS port file
107+
.tern-port
108+
109+
# Stores VSCode versions used for testing VSCode extensions
110+
.vscode-test
111+
112+
# yarn v2
113+
.yarn/cache
114+
.yarn/unplugged
115+
.yarn/build-state.yml
116+
.yarn/install-state.gz
117+
.pnp.*
118+
119+
# dev/temp
120+
iframely-original.php
121+
assets/js/iframely.js
122+
123+
# local
124+
.idea
125+
release

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Iframely WordPress plugin
2+
3+
## Installation
4+
npm install
5+
6+
### Gutenberg build
7+
npm run build
8+
9+
### Gutenberg watch
10+
npm run start
11+
12+
### Update POT file
13+
gulp clean
14+
wp i18n make-pot . lang/iframely.pot --headers="{\"Project-Id-Version\": \"Iframely\", \"Report-Msgid-Bugs-To\": \"https://wordpress.org/support/plugin/iframely/\", \"Last-Translator\": \"Iframely.com\", \"Language-Team\": \"Iframely.com\"}"
15+
wp i18n make-json lang --no-purge
16+
17+
## Release
18+
19+
Copy plugin files to `release` folder with proper SVN structure:
20+
21+
gulp release
22+
23+
Alternatively, add specific version to `tags` directory:
24+
25+
gulp release --tag=1.0
26+
27+
Clean `release` folder:
28+
29+
gulp clean

app/Activation.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Iframely;
4+
5+
use Iframely\Embed\Cache;
6+
7+
class Activation
8+
{
9+
public static function run(): void
10+
{
11+
if (Plugin::isActivated() || Options::isAllSet()) {
12+
return;
13+
}
14+
15+
Options::setBuiltinsReplace(true);
16+
Options::setPreviewsEnhance(true);
17+
Options::setCacheRefresh(true);
18+
Options::setCacheTtl(Cache::getDefaultTtlValue());
19+
20+
Options::setAllSet(true);
21+
}
22+
}

app/Embed.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Iframely;
4+
5+
use Iframely\Embed\Amp;
6+
use Iframely\Embed\Cache;
7+
use Iframely\Embed\Feed;
8+
use Iframely\Embed\Gutenberg;
9+
use Iframely\Embed\Oembed;
10+
use Iframely\Embed\Shortcode;
11+
12+
class Embed
13+
{
14+
public const IFRAMELY_ENDPOINT_URL = 'https://iframe.ly/api/oembed';
15+
16+
public static function run(): void
17+
{
18+
Oembed::run();
19+
Feed::run();
20+
Amp::run();
21+
Gutenberg::run();
22+
Cache::run();
23+
Shortcode::run();
24+
}
25+
26+
public static function createApiLink(): string
27+
{
28+
$key = Options::getApiKey();
29+
$query = Options::getApiParams();
30+
$origin = preg_replace('#^https?://#i', '', get_bloginfo('url'));
31+
32+
$link = add_query_arg([
33+
'origin' => $origin,
34+
'api_key' => $key,
35+
], self::IFRAMELY_ENDPOINT_URL);
36+
37+
if (!empty($query)) {
38+
parse_str($query, $params);
39+
$link = add_query_arg($params, $link);
40+
}
41+
42+
return $link;
43+
}
44+
}

app/Embed/Amp.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace Iframely\Embed;
4+
5+
use Iframely\Options;
6+
use Iframely\Utils;
7+
8+
class Amp
9+
{
10+
public static function run(): void
11+
{
12+
# Make compatible with Automatic AMP-WP plugin: https://github.com/Automattic/amp-wp
13+
add_filter('oembed_fetch_url', [self::class, 'maybe_add_iframe_amp'], 10, 3);
14+
add_filter('embed_oembed_html', [self::class, 'iframely_filter_oembed_result'], 10, 3);
15+
add_filter('amp_content_embed_handlers', [self::class, 'maybe_disable_default_embed_handlers'], 10, 2);
16+
}
17+
18+
public static function is_iframely_amp($args): bool
19+
{
20+
return
21+
(is_array($args) && array_key_exists('iframely', $args) && $args['iframely'] === 'amp')
22+
|| (is_string($args) && Utils::stringContains($args, 'iframely=amp'))
23+
|| (function_exists('is_amp_endpoint') && is_amp_endpoint());
24+
}
25+
26+
public static function maybe_add_iframe_amp($provider, $args, $url)
27+
{
28+
if (self::is_iframely_amp($args) && Utils::stringContains($provider, 'iframe.ly')) {
29+
$provider = add_query_arg('amp', '1', $provider);
30+
}
31+
return $provider;
32+
}
33+
34+
public static function iframely_filter_oembed_result($html, $url, $args)
35+
{
36+
if (Utils::stringContains($html, '<amp-iframe')) { // covers "amp-iframely"
37+
// Avoid corrupted amp-iframe overflow div as a result of wpautop
38+
remove_filter('the_content', 'wpautop');
39+
// Restore wpautop if it was disabled
40+
add_filter('the_content', [self::class, 'iframely_autop_on_amp'], 1000);
41+
}
42+
43+
return $html;
44+
}
45+
46+
public static function iframely_autop_on_amp($content)
47+
{
48+
// Logic is taken from wpautop itself re <pre>
49+
if (Utils::stringContains($content, '<amp-iframe')) {
50+
$chunks = explode('</amp-iframe>', $content);
51+
$content = '';
52+
53+
foreach ($chunks as $chunk) {
54+
$start = strpos($chunk, '<amp-iframe');
55+
// Malformed html?
56+
if ($start === false) {
57+
$content .= $chunk;
58+
continue;
59+
}
60+
61+
$iframe = substr($chunk, $start) . '</amp-iframe>';
62+
$p = wpautop(substr($chunk, 0, $start));
63+
64+
$content .= $p . $iframe;
65+
}
66+
} else {
67+
$content = wpautop($content);
68+
}
69+
70+
return $content;
71+
}
72+
73+
public static function maybe_disable_default_embed_handlers($embed_handler_classes)
74+
{
75+
//return ! get_site_option( 'iframely_only_shortcode' ) ? array() : $embed_handler_classes;
76+
if (!class_exists('Jetpack_AMP_Support') && Options::isBuiltinsReplaced()) {
77+
return [];
78+
}
79+
return $embed_handler_classes;
80+
}
81+
}
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+

0 commit comments

Comments
 (0)