Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: getty.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Getty shortcode
[2] Fix | Delete
*
[3] Fix | Delete
* [getty src="82278805" width="$width" height="$height"]
[4] Fix | Delete
* <div class="getty embed image" style="background-color:#fff;display:inline-block;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#a7a7a7;font-size:11px;width:100%;max-width:462px;"><div style="padding:0;margin:0;text-align:left;"><a href="http://www.gettyimages.com/detail/82278805" target="_blank" style="color:#a7a7a7;text-decoration:none;font-weight:normal !important;border:none;display:inline-block;">Embed from Getty Images</a></div><div style="overflow:hidden;position:relative;height:0;padding:80.086580% 0 0 0;width:100%;"><iframe src="//embed.gettyimages.com/embed/82278805?et=jGiu6FXXSpJDGf1SnwLV2g&sig=TFVNFtqghwNw5iJQ1MFWnI8f4Y40_sfogfZLhai6SfA=" width="462" height="370" scrolling="no" frameborder="0" style="display:inline-block;position:absolute;top:0;left:0;width:100%;height:100%;"></iframe></div><p style="margin:0;"></p></div>
[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_getty_enable_embeds' );
[15] Fix | Delete
} else {
[16] Fix | Delete
jetpack_getty_enable_embeds();
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Register Getty as oembed provider. Add filter to reverse iframes to shortcode. Register [getty] shortcode.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 4.5.0
[23] Fix | Delete
* @since 5.8.0 removed string parameter.
[24] Fix | Delete
*/
[25] Fix | Delete
function jetpack_getty_enable_embeds() {
[26] Fix | Delete
[27] Fix | Delete
// Support their oEmbed Endpoint.
[28] Fix | Delete
wp_oembed_add_provider( '#https?://www\.gettyimages\.com/detail/.*#i', 'https://embed.gettyimages.com/oembed/', true );
[29] Fix | Delete
wp_oembed_add_provider( '#https?://(www\.)?gty\.im/.*#i', 'https://embed.gettyimages.com/oembed/', true );
[30] Fix | Delete
[31] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[32] Fix | Delete
// Allow iframes to be filtered to short code (so direct copy+paste can be done).
[33] Fix | Delete
add_filter( 'pre_kses', 'wpcom_shortcodereverse_getty' );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
// Actually display the Getty Embed.
[37] Fix | Delete
add_shortcode( 'getty', 'jetpack_getty_shortcode' );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Filters the oEmbed provider URL for Getty URLs to include site URL host as
[42] Fix | Delete
* caller if available, falling back to "wordpress.com". Must be applied at
[43] Fix | Delete
* time of embed in case that `init` is too early (WP.com REST API).
[44] Fix | Delete
*
[45] Fix | Delete
* @module shortcodes
[46] Fix | Delete
*
[47] Fix | Delete
* @since 5.8.0
[48] Fix | Delete
*
[49] Fix | Delete
* @see WP_oEmbed::fetch
[50] Fix | Delete
*
[51] Fix | Delete
* @return string oEmbed provider URL
[52] Fix | Delete
*/
[53] Fix | Delete
add_filter( 'oembed_fetch_url', 'getty_add_oembed_endpoint_caller' );
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Filter the embeds to add a caller parameter.
[57] Fix | Delete
*
[58] Fix | Delete
* @param string $provider URL of the oEmbed provider.
[59] Fix | Delete
*/
[60] Fix | Delete
function getty_add_oembed_endpoint_caller( $provider ) {
[61] Fix | Delete
// By time filter is called, original provider URL has had url, maxwidth,
[62] Fix | Delete
// maxheight query parameters added.
[63] Fix | Delete
if ( ! str_starts_with( $provider, 'https://embed.gettyimages.com/oembed/' ) ) {
[64] Fix | Delete
return $provider;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// Set the caller argument to pass to Getty's oembed provider.
[68] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[69] Fix | Delete
[70] Fix | Delete
// Only include caller for non-private sites.
[71] Fix | Delete
if ( ! function_exists( 'is_private_blog' ) || ! is_private_blog() ) {
[72] Fix | Delete
$host = wp_parse_url( get_bloginfo( 'url' ), PHP_URL_HOST );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
// Fall back to WordPress.com.
[76] Fix | Delete
if ( empty( $host ) ) {
[77] Fix | Delete
$host = 'wordpress.com';
[78] Fix | Delete
}
[79] Fix | Delete
} else {
[80] Fix | Delete
$host = wp_parse_url( get_home_url(), PHP_URL_HOST );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return add_query_arg( 'caller', $host, $provider );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Compose shortcode based on Getty iframes.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 4.5.0
[90] Fix | Delete
*
[91] Fix | Delete
* @param string $content Post content.
[92] Fix | Delete
*
[93] Fix | Delete
* @return mixed
[94] Fix | Delete
*/
[95] Fix | Delete
function wpcom_shortcodereverse_getty( $content ) {
[96] Fix | Delete
if ( ! is_string( $content ) || false === stripos( $content, '.gettyimages.com/' ) ) {
[97] Fix | Delete
return $content;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$regexp = '!<iframe\s+src=[\'"](https?:)?//embed\.gettyimages\.com/embed(/|/?\?assets=)([a-z0-9_-]+(,[a-z0-9_-]+)*)[^\'"]*?[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i';
[101] Fix | Delete
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
[102] Fix | Delete
[103] Fix | Delete
// Markup pattern for 2017 embed syntax with significant differences from the prior pattern.
[104] Fix | Delete
$regexp_2017 = '!<a.+?class=\'gie-(single|slideshow)\'.+?gie\.widgets\.load\({([^}]+)}\).+?embed-cdn\.gettyimages\.com/widgets\.js.+?</script>!';
[105] Fix | Delete
$regexp_2017_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp_2017, ENT_NOQUOTES ) );
[106] Fix | Delete
[107] Fix | Delete
foreach ( compact( 'regexp_2017', 'regexp_2017_ent', 'regexp', 'regexp_ent' ) as $reg => $regexp ) {
[108] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[109] Fix | Delete
continue;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
foreach ( $matches as $match ) {
[113] Fix | Delete
if ( 'regexp_2017' === $reg || 'regexp_2017_ent' === $reg ) {
[114] Fix | Delete
// Extract individual keys from the matched JavaScript object.
[115] Fix | Delete
$params = $match[2];
[116] Fix | Delete
if ( ! preg_match_all( '!(?P<key>\w+)\s*:\s*([\'"](?P<value>[^\'"]*?)(px)?[\'"])!', $params, $key_matches, PREG_SET_ORDER ) ) {
[117] Fix | Delete
continue;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
foreach ( $key_matches as $key_match ) {
[121] Fix | Delete
switch ( $key_match['key'] ) {
[122] Fix | Delete
case 'items':
[123] Fix | Delete
$ids = $key_match['value'];
[124] Fix | Delete
break;
[125] Fix | Delete
case 'w':
[126] Fix | Delete
$width = (int) $key_match['value'];
[127] Fix | Delete
break;
[128] Fix | Delete
case 'h':
[129] Fix | Delete
$height = (int) $key_match['value'];
[130] Fix | Delete
break;
[131] Fix | Delete
case 'tld':
[132] Fix | Delete
$tld = $key_match['value'];
[133] Fix | Delete
break;
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
} else {
[137] Fix | Delete
$params = $match[5];
[138] Fix | Delete
if ( 'regexp_ent' === $reg ) {
[139] Fix | Delete
$params = html_entity_decode( $params, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
[140] Fix | Delete
}
[141] Fix | Delete
$params = wp_kses_hair( $params, array( 'http' ) );
[142] Fix | Delete
[143] Fix | Delete
$ids = esc_html( $match[3] );
[144] Fix | Delete
$width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0;
[145] Fix | Delete
$height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( empty( $ids ) ) {
[149] Fix | Delete
continue;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
$shortcode = '[getty src="' . esc_attr( $ids ) . '"';
[153] Fix | Delete
if ( ! empty( $width ) ) {
[154] Fix | Delete
$shortcode .= ' width="' . esc_attr( $width ) . '"';
[155] Fix | Delete
}
[156] Fix | Delete
if ( ! empty( $height ) ) {
[157] Fix | Delete
$shortcode .= ' height="' . esc_attr( $height ) . '"';
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/*
[161] Fix | Delete
* While it does not appear to have any practical impact, Getty has
[162] Fix | Delete
* requested that we include TLD in the embed request
[163] Fix | Delete
*/
[164] Fix | Delete
if ( ! empty( $tld ) ) {
[165] Fix | Delete
$shortcode .= ' tld="' . esc_attr( $tld ) . '"';
[166] Fix | Delete
}
[167] Fix | Delete
$shortcode .= ']';
[168] Fix | Delete
[169] Fix | Delete
$content = str_replace( $match[0], $shortcode, $content );
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
// strip out enclosing div and any other markup.
[174] Fix | Delete
$regexp = '%<div class="getty\s[^>]*+>.*?<div[^>]*+>(\[getty[^\]]*+\])\s*</div>.*?</div>%is';
[175] Fix | Delete
$regexp_ent = str_replace( array( '&amp;#0*58;', '[^&gt;]' ), array( '&amp;#0*58;|&#0*58;', '[^&]' ), htmlspecialchars( $regexp, ENT_NOQUOTES ) );
[176] Fix | Delete
[177] Fix | Delete
foreach ( compact( 'regexp', 'regexp_ent' ) as $reg => $regexp ) {
[178] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[179] Fix | Delete
continue;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
foreach ( $matches as $match ) {
[183] Fix | Delete
$content = str_replace( $match[0], $match[1], $content );
[184] Fix | Delete
}
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
/** This action is documented in modules/widgets/social-media-icons.php */
[188] Fix | Delete
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'getty' );
[189] Fix | Delete
[190] Fix | Delete
return $content;
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Parse shortcode arguments and render its output.
[195] Fix | Delete
*
[196] Fix | Delete
* @since 4.5.0
[197] Fix | Delete
*
[198] Fix | Delete
* @param array $atts Shortcode parameters.
[199] Fix | Delete
* @param string $content Content enclosed by shortcode tags.
[200] Fix | Delete
*
[201] Fix | Delete
* @return string
[202] Fix | Delete
*/
[203] Fix | Delete
function jetpack_getty_shortcode( $atts, $content = '' ) {
[204] Fix | Delete
[205] Fix | Delete
if ( ! empty( $content ) ) {
[206] Fix | Delete
$src = $content;
[207] Fix | Delete
} elseif ( ! empty( $atts['src'] ) ) {
[208] Fix | Delete
$src = $atts['src'];
[209] Fix | Delete
} elseif ( ! empty( $atts[0] ) ) {
[210] Fix | Delete
$src = $atts[0];
[211] Fix | Delete
} else {
[212] Fix | Delete
return '<!-- Missing Getty Source ID -->';
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
$src = preg_replace( '/^([\da-z-]+(,[\da-z-]+)*).*$/', '$1', $src );
[216] Fix | Delete
[217] Fix | Delete
$params = array(
[218] Fix | Delete
'width' => isset( $atts['width'] ) ? (int) $atts['width'] : null,
[219] Fix | Delete
'height' => isset( $atts['height'] ) ? (int) $atts['height'] : null,
[220] Fix | Delete
);
[221] Fix | Delete
[222] Fix | Delete
if ( ! empty( $atts['tld'] ) ) {
[223] Fix | Delete
$params['tld'] = $atts['tld'];
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
return wp_oembed_get( 'https://gty.im/' . $src, array_filter( $params ) );
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function