Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: smartframe.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Smartframe.io embed
[2] Fix | Delete
*
[3] Fix | Delete
* Example URL: https://mikael-korpela.smartframe.io/p/mantymetsa_1630927773870/7673dc41a775fb845cc26acf24f1fe4?t=rql1c6dbpv2
[4] Fix | Delete
* Example embed code: <script src="https://embed.smartframe.io/6ae67829d1264ee0ea6071a788940eae.js" data-image-id="mantymetsa_1630927773870" data-width="100%" data-max-width="1412px"></script>
[5] Fix | Delete
*
[6] Fix | Delete
* @package automattic/jetpack
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[10] Fix | Delete
exit( 0 );
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[14] Fix | Delete
add_action( 'init', 'jetpack_smartframe_enable_embeds' );
[15] Fix | Delete
} else {
[16] Fix | Delete
jetpack_smartframe_enable_embeds();
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Register smartframe as oembed provider. Add filter to reverse iframes to shortcode. Register [smartframe] shortcode.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 10.2.0
[23] Fix | Delete
*/
[24] Fix | Delete
function jetpack_smartframe_enable_embeds() {
[25] Fix | Delete
// Support their oEmbed Endpoint.
[26] Fix | Delete
wp_oembed_add_provider( '#https?://(.*?)\.smartframe\.(io|net)/.*#i', 'https://oembed.smartframe.io/', true );
[27] Fix | Delete
[28] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[29] Fix | Delete
// Allow script to be filtered to short code (so direct copy+paste can be done).
[30] Fix | Delete
add_filter( 'pre_kses', 'jetpack_shortcodereverse_smartframe' );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
// Actually display the smartframe Embed.
[34] Fix | Delete
add_shortcode( 'smartframe', 'jetpack_smartframe_shortcode' );
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Compose shortcode based on smartframe iframes.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 10.2.0
[41] Fix | Delete
*
[42] Fix | Delete
* @param string $content Post content.
[43] Fix | Delete
*
[44] Fix | Delete
* @return mixed
[45] Fix | Delete
*/
[46] Fix | Delete
function jetpack_shortcodereverse_smartframe( $content ) {
[47] Fix | Delete
if ( ! is_string( $content ) || false === stripos( $content, 'embed.smartframe' ) ) {
[48] Fix | Delete
return $content;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
[52] Fix | Delete
$regexp = '!<script\ssrc="https://embed\.smartframe\.(?:io|net)/(\w+)\.js"\sdata-image-id="(.*?)"(?:\sdata-width="(?:\d+(?:%|px))"\s)?(?:data-max-width="(\d+(%|px)))?"></script>!i';
[53] Fix | Delete
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
[54] Fix | Delete
[55] Fix | Delete
foreach ( compact( 'regexp', 'regexp_ent' ) as $regexp ) {
[56] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[57] Fix | Delete
continue;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
foreach ( $matches as $match ) {
[61] Fix | Delete
// We need at least a script ID and an image ID.
[62] Fix | Delete
if ( ! isset( $match[1] ) || ! isset( $match[2] ) ) {
[63] Fix | Delete
continue;
[64] Fix | Delete
}
[65] Fix | Delete
$shortcode = sprintf(
[66] Fix | Delete
'[smartframe script-id="%1$s" image-id="%2$s"%3$s]',
[67] Fix | Delete
esc_attr( $match[1] ),
[68] Fix | Delete
esc_attr( $match[2] ),
[69] Fix | Delete
! empty( $match[3] ) ? ' max-width="' . esc_attr( $match[3] ) . '"' : ''
[70] Fix | Delete
);
[71] Fix | Delete
$content = str_replace( $match[0], $shortcode, $content );
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
/** This action is documented in modules/widgets/social-media-icons.php */
[75] Fix | Delete
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'smartframe' );
[76] Fix | Delete
[77] Fix | Delete
return $content;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Parse shortcode arguments and render its output.
[82] Fix | Delete
*
[83] Fix | Delete
* @since 10.2.0
[84] Fix | Delete
*
[85] Fix | Delete
* @param array $atts Shortcode parameters.
[86] Fix | Delete
*
[87] Fix | Delete
* @return string
[88] Fix | Delete
*/
[89] Fix | Delete
function jetpack_smartframe_shortcode( $atts ) {
[90] Fix | Delete
if ( ! empty( $atts['image-id'] ) ) {
[91] Fix | Delete
$image_id = $atts['image-id'];
[92] Fix | Delete
} else {
[93] Fix | Delete
return '<!-- Missing smartframe image-id -->';
[94] Fix | Delete
}
[95] Fix | Delete
if ( ! empty( $atts['script-id'] ) ) {
[96] Fix | Delete
$script_id = $atts['script-id'];
[97] Fix | Delete
} else {
[98] Fix | Delete
return '<!-- Missing smartframe script-id -->';
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
$params = array(
[102] Fix | Delete
// ignore width for now, smartframe embed code has it "100%". % isn't allowed in oembed, making it 100px.
[103] Fix | Delete
// 'width' => isset( $atts['width'] ) ? (int) $atts['width'] : null,.
[104] Fix | Delete
'max-width' => isset( $atts['max-width'] ) ? (int) $atts['max-width'] : null,
[105] Fix | Delete
);
[106] Fix | Delete
[107] Fix | Delete
$embed_url = sprintf(
[108] Fix | Delete
'https://imagecards.smartframe.io/%1$s/%2$s',
[109] Fix | Delete
esc_attr( $script_id ),
[110] Fix | Delete
esc_attr( $image_id )
[111] Fix | Delete
);
[112] Fix | Delete
[113] Fix | Delete
// wrap the embed with wp-block-embed__wrapper, otherwise it would be aligned to the very left of the viewport.
[114] Fix | Delete
return sprintf(
[115] Fix | Delete
'<div class="wp-block-embed__wrapper">%1$s</div>',
[116] Fix | Delete
wp_oembed_get( $embed_url, array_filter( $params ) )
[117] Fix | Delete
);
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function