Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: googlemaps.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Google Maps embeds.
[2] Fix | Delete
*
[3] Fix | Delete
* Supported formats:
[4] Fix | Delete
* <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14" style="color:#0000FF;text-align:left">Вижте по-голяма карта</a></small>
[5] Fix | Delete
* [googlemaps https://maps.google.com/maps?f=q&hl=en&geocode=&q=San+Francisco,+CA&sll=43.469466,-83.998504&sspn=0.01115,0.025942&g=San+Francisco,+CA&ie=UTF8&z=12&iwloc=addr&ll=37.808156,-122.402458&output=embed&s=AARTsJp56EajYksz3JXgNCwT3LJnGsqqAQ&w=425&h=350]
[6] Fix | Delete
* [googlemaps https://mapsengine.google.com/map/embed?mid=zbBhkou4wwtE.kUmp8K6QJ7SA&w=640&h=480]
[7] Fix | Delete
*
[8] Fix | Delete
* @package automattic/jetpack
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[12] Fix | Delete
exit( 0 );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Google maps iframe - transforms code that looks like that:
[17] Fix | Delete
* <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=bg&amp;geocode=&amp;q=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1,+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F,+%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F&amp;sll=37.0625,-95.677068&amp;sspn=40.545434,79.013672&amp;ie=UTF8&amp;hq=&amp;hnear=%D0%9C%D0%BB%D0%B0%D0%B4%D0%BE%D1%81%D1%82+1&amp;ll=42.654446,23.372061&amp;spn=0.036864,0.077162&amp;t=h&amp;z=14" style="color:#0000FF;text-align:left">Вижте по-голяма карта</a></small>
[18] Fix | Delete
* into the [googlemaps http://...] shortcode format
[19] Fix | Delete
*
[20] Fix | Delete
* @param string $content Post content.
[21] Fix | Delete
*/
[22] Fix | Delete
function jetpack_googlemaps_embed_to_short_code( $content ) {
[23] Fix | Delete
[24] Fix | Delete
if ( ! is_string( $content ) || ( ! str_contains( $content, 'maps.google.' ) && 1 !== preg_match( '@google\.[^/]+/maps?@', $content ) ) ) {
[25] Fix | Delete
return $content;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
/*
[29] Fix | Delete
* IE and TinyMCE format things differently
[30] Fix | Delete
* &lt;iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;output=embed&quot;&gt;&lt;/iframe&gt;&lt;br">https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;output=embed"&gt;&lt;/iframe&gt;&lt;br</a> /&gt;&lt;small&gt;View &lt;a href="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;source=embed">https://maps.google.co.uk/maps/ms?msa=0&amp;amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;t=m&amp;amp;ll=50.91917,-1.398808&amp;amp;spn=0.013225,0.011794&amp;amp;source=embed</a>" style="color:#0000FF;text-align:left"&gt;OARA Membership Discount Map&lt;/a&gt; in a larger map&lt;/small&gt;
[31] Fix | Delete
*/
[32] Fix | Delete
if ( strpos( $content, 'src="<a href="' ) !== false ) {
[33] Fix | Delete
$content = preg_replace_callback( '#&lt;iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="<a href="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)&quot;[^&]*?(?:&(?!gt;)[^&]*?)*?&gt;\s*&lt;/iframe&gt;&lt;br">[^"]*?"&gt;\s*&lt;/iframe&gt;(?:&lt;br</a>\s*/&gt;\s*&lt;small&gt;.*?&lt;/small&gt;)?#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
[34] Fix | Delete
return $content;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
$content = preg_replace_callback( '!\<iframe\s[^>]*?src="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)"[^>]*?\>\s*\</iframe\>(?:\s*(?:\<br\s*/?\>)?\s*\<small\>.*?\</small\>)?!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
[38] Fix | Delete
[39] Fix | Delete
$content = preg_replace_callback( '#&lt;iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="https?://(.*)?\.google\.(.*?)/(.*?)\?(.+?)"[^&]*?(?:&(?!gt;)[^&]*?)*?&gt;\s*&lt;/iframe&gt;(?:\s*(?:&lt;br\s*/?&gt;)?\s*&lt;small&gt;.*?&lt;/small&gt;)?#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content );
[40] Fix | Delete
[41] Fix | Delete
return $content;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Callback transforming a Google Maps iFrame code into a shortcode.
[46] Fix | Delete
*
[47] Fix | Delete
* @param array $match Array of embed parameters used to build the final URL.
[48] Fix | Delete
*/
[49] Fix | Delete
function jetpack_googlemaps_embed_to_short_code_callback( $match ) {
[50] Fix | Delete
[51] Fix | Delete
if ( preg_match( '/\bwidth=[\'"](\d+)(%)?/', $match[0], $width ) ) {
[52] Fix | Delete
$percent = ! empty( $width[2] ) ? '%' : '';
[53] Fix | Delete
$width = absint( $width[1] ) . $percent;
[54] Fix | Delete
} else {
[55] Fix | Delete
$width = 425;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
if ( preg_match( '/\bheight=[\'"](\d+)(%)?/', $match[0], $height ) ) {
[59] Fix | Delete
$percent = ! empty( $height[2] ) ? '%' : '';
[60] Fix | Delete
$height = absint( $height[1] ) . $percent;
[61] Fix | Delete
} else {
[62] Fix | Delete
$height = 350;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$url = "https://{$match[1]}.google.{$match[2]}/{$match[3]}?{$match[4]}&amp;w={$width}&amp;h={$height}";
[66] Fix | Delete
[67] Fix | Delete
/** This action is documented in modules/shortcodes/youtube.php */
[68] Fix | Delete
do_action( 'jetpack_embed_to_shortcode', 'googlemaps', $url );
[69] Fix | Delete
[70] Fix | Delete
return "[googlemaps $url]";
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[74] Fix | Delete
add_filter( 'pre_kses', 'jetpack_googlemaps_embed_to_short_code' );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Display the [googlemaps] shortcode
[79] Fix | Delete
*
[80] Fix | Delete
* @param array $atts Shortcode attributes.
[81] Fix | Delete
*/
[82] Fix | Delete
function jetpack_googlemaps_shortcode( $atts ) {
[83] Fix | Delete
if ( ! isset( $atts[0] ) ) {
[84] Fix | Delete
return '';
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$params = ltrim( $atts[0], '=' );
[88] Fix | Delete
[89] Fix | Delete
$width = 425;
[90] Fix | Delete
$height = 350;
[91] Fix | Delete
[92] Fix | Delete
if ( preg_match( '!^https?://(www|maps|mapsengine)\.google(\.co|\.com)?(\.[a-z]+)?/.*?(\?.+)!i', $params, $match ) ) {
[93] Fix | Delete
$params = str_replace( '&amp;amp;', '&amp;', $params );
[94] Fix | Delete
$params = str_replace( '&amp;', '&', $params );
[95] Fix | Delete
parse_str( $params, $arg );
[96] Fix | Delete
[97] Fix | Delete
if ( isset( $arg['hq'] ) ) {
[98] Fix | Delete
unset( $arg['hq'] );
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
$url = '';
[102] Fix | Delete
foreach ( (array) $arg as $key => $value ) {
[103] Fix | Delete
if ( 'w' === $key ) {
[104] Fix | Delete
$percent = ( str_ends_with( $value, '%' ) ) ? '%' : '';
[105] Fix | Delete
$width = (int) $value . $percent;
[106] Fix | Delete
} elseif ( 'h' === $key ) {
[107] Fix | Delete
$height = (int) $value;
[108] Fix | Delete
} else {
[109] Fix | Delete
$key = str_replace( '_', '.', $key );
[110] Fix | Delete
$url .= esc_attr( "$key=$value&amp;" );
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
$url = substr( $url, 0, -5 );
[114] Fix | Delete
[115] Fix | Delete
$url = str_replace( 'http://', 'https://', $url );
[116] Fix | Delete
[117] Fix | Delete
$css_class = 'googlemaps';
[118] Fix | Delete
[119] Fix | Delete
if ( ! empty( $atts['align'] ) && in_array( strtolower( $atts['align'] ), array( 'left', 'center', 'right' ), true ) ) {
[120] Fix | Delete
$atts['align'] = strtolower( $atts['align'] );
[121] Fix | Delete
[122] Fix | Delete
if ( 'left' === $atts['align'] ) {
[123] Fix | Delete
$css_class .= ' alignleft';
[124] Fix | Delete
} elseif ( 'center' === $atts['align'] ) {
[125] Fix | Delete
$css_class .= ' aligncenter';
[126] Fix | Delete
} elseif ( 'right' === $atts['align'] ) {
[127] Fix | Delete
$css_class .= ' alignright';
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$sandbox = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request()
[132] Fix | Delete
? 'sandbox="allow-popups allow-scripts allow-same-origin"'
[133] Fix | Delete
: '';
[134] Fix | Delete
[135] Fix | Delete
return sprintf(
[136] Fix | Delete
'<div class="%1$s">
[137] Fix | Delete
<iframe width="%2$d" height="%3$d" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" %5$s src="%4$s"></iframe>
[138] Fix | Delete
</div>',
[139] Fix | Delete
esc_attr( $css_class ),
[140] Fix | Delete
absint( $width ),
[141] Fix | Delete
absint( $height ),
[142] Fix | Delete
esc_url( $url ),
[143] Fix | Delete
$sandbox
[144] Fix | Delete
);
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
add_shortcode( 'googlemaps', 'jetpack_googlemaps_shortcode' );
[148] Fix | Delete
[149] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function