Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowby committed Mar 1, 2022
1 parent 5e24061 commit b60836a
Show file tree
Hide file tree
Showing 80 changed files with 41,654 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
trim_trailing_whitespace = true

[*.js]
indent_size = 2

[*.scss]
indent_size = 2

[views/**.php]
indent_size = 2
134 changes: 124 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,125 @@
.gitignore
iframely/node_modules
.idea
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Repository inside plugin directory
.babelrc
iframely.php
readme.txt
src*
ui*
.DS_Store
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# dev/temp
iframely-original.php
assets/js/iframely.js

# local
.idea
release
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Iframely WordPress plugin

## Installation
npm install

### Gutenberg build
npm run build

### Gutenberg watch
npm run start

### Update POT file
gulp clean
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\"}"
wp i18n make-json lang --no-purge

## Release

Copy plugin files to `release` folder with proper SVN structure:

gulp release

Alternatively, add specific version to `tags` directory:

gulp release --tag=1.0

Clean `release` folder:

gulp clean
22 changes: 22 additions & 0 deletions app/Activation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Iframely;

use Iframely\Embed\Cache;

class Activation
{
public static function run(): void
{
if (Plugin::isActivated() || Options::isAllSet()) {
return;
}

Options::setBuiltinsReplace(true);
Options::setPreviewsEnhance(true);
Options::setCacheRefresh(true);
Options::setCacheTtl(Cache::getDefaultTtlValue());

Options::setAllSet(true);
}
}
44 changes: 44 additions & 0 deletions app/Embed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Iframely;

use Iframely\Embed\Amp;
use Iframely\Embed\Cache;
use Iframely\Embed\Feed;
use Iframely\Embed\Gutenberg;
use Iframely\Embed\Oembed;
use Iframely\Embed\Shortcode;

class Embed
{
public const IFRAMELY_ENDPOINT_URL = 'https://iframe.ly/api/oembed';

public static function run(): void
{
Oembed::run();
Feed::run();
Amp::run();
Gutenberg::run();
Cache::run();
Shortcode::run();
}

public static function createApiLink(): string
{
$key = Options::getApiKey();
$query = Options::getApiParams();
$origin = preg_replace('#^https?://#i', '', get_bloginfo('url'));

$link = add_query_arg([
'origin' => $origin,
'api_key' => $key,
], self::IFRAMELY_ENDPOINT_URL);

if (!empty($query)) {
parse_str($query, $params);
$link = add_query_arg($params, $link);
}

return $link;
}
}
94 changes: 94 additions & 0 deletions app/Embed/Amp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Iframely\Embed;

use Iframely\Options;
use Iframely\Utils;

class Amp
{
public static function run(): void
{
# Make compatible with Automatic AMP-WP plugin: https://github.com/Automattic/amp-wp
add_filter('oembed_fetch_url', [self::class, 'maybe_add_iframe_amp'], 10, 3);
add_filter('embed_oembed_html', [self::class, 'iframely_filter_oembed_result'], 10, 3);
add_filter('amp_content_embed_handlers', [self::class, 'maybe_disable_default_embed_handlers'], 10, 2);
}

public static function is_iframely_amp($args): bool
{
return
(is_array($args) && array_key_exists('iframely', $args) && $args['iframely'] === 'amp')
|| (is_string($args) && Utils::stringContains($args, 'iframely=amp'))
|| (function_exists('is_amp_endpoint') && is_amp_endpoint());
}

public static function maybe_add_iframe_amp($provider, $args, $url)
{
if (self::is_iframely_amp($args) && Utils::stringContains($provider, 'iframe.ly')) {
$provider = add_query_arg('amp', '1', $provider);
}
return $provider;
}

public static function iframely_filter_oembed_result($html, $url, $args)
{
if (Utils::stringContains($html, '<amp-iframe')) { // covers "amp-iframely"
// Avoid corrupted amp-iframe overflow div as a result of wpautop
remove_filter('the_content', 'wpautop');
// Restore wpautop if it was disabled
add_filter('the_content', [self::class, 'iframely_autop_on_amp'], 1000);
}

return $html;
}

public static function iframely_autop_on_amp($content)
{
// Logic is taken from wpautop itself re <pre>
if (Utils::stringContains($content, '<amp-iframe')) {
$chunks = explode('</amp-iframe>', $content);
$content = '';

foreach ($chunks as $chunk) {
$start = strpos($chunk, '<amp-iframe');
// Malformed html?
if ($start === false) {
$content .= $chunk;
continue;
}

$iframe = substr($chunk, $start) . '</amp-iframe>';
$p = wpautop(substr($chunk, 0, $start));

$content .= $p . $iframe;
}
} else {
$content = wpautop($content);
}

return $content;
}

public static function maybe_disable_default_embed_handlers($embed_handler_classes)
{
//return ! get_site_option( 'iframely_only_shortcode' ) ? array() : $embed_handler_classes;
if (!class_exists('Jetpack_AMP_Support') && Options::isBuiltinsReplaced()) {
return [];
}
return $embed_handler_classes;
}
}













Loading

0 comments on commit b60836a

Please sign in to comment.