Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: googleapps.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Google Docs and Google Calendar Shortcode
[2] Fix | Delete
*
[3] Fix | Delete
* Presentation:
[4] Fix | Delete
* <iframe src="https://docs.google.com/present/embed?id=dhfhrphh_123drp8s65c&interval=15&autoStart=true&loop=true&size=l" frameborder="0" width="700" height="559"></iframe>
[5] Fix | Delete
* <iframe src="https://docs.google.com/presentation/embed?id=13ItX4jV0SOSdr-ZjHarcpTh9Lr4omfsHAp87jpxv8-0&start=false&loop=false&delayms=3000" frameborder="0" width="960" height="749" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
[6] Fix | Delete
*
[7] Fix | Delete
* Document:
[8] Fix | Delete
* <iframe src="https://docs.google.com/document/pub?id=1kDatklacdZ_tZUOpWtt_ONzY97Ldj2zFcuO9LBY2Ln4&amp;embedded=true"></iframe>
[9] Fix | Delete
* <iframe src="https://docs.google.com/document/d/1kDatklacdZ_tZUOpWtt_ONzY97Ldj2zFcuO9LBY2Ln4/pub?embedded=true"></iframe>
[10] Fix | Delete
* <iframe src="https://docs.google.com/document/d/e/2PACX-1vRkpIdasKL-eKXDjJgpEONduUspZTz0YmKaajfie0eJYnzikuyusuG1_V8X8T9XflN9l8A1oCM2sgEA/pub?embedded=true"></iframe>
[11] Fix | Delete
*
[12] Fix | Delete
* External document:
[13] Fix | Delete
* <iframe width=100% height=560px frameborder=0 src=https://docs.google.com/a/pranab.in/viewer?a=v&pid=explorer&chrome=false&embedded=true&srcid=1VTMwdgGiDMt8MCr75-YkQP-4u9WmEp1Qvf6C26KYBgFilxU2qndpd-VHhBIn&hl=en></iframe>
[14] Fix | Delete
*
[15] Fix | Delete
* Spreadsheet Form:
[16] Fix | Delete
* <iframe src="https://spreadsheets.google.com/embeddedform?formkey=dEVOYnMzZG5jMUpGbjFMYjFYNVB3NkE6MQ" width="760" height="710" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
[17] Fix | Delete
*
[18] Fix | Delete
* Spreadsheet Widget:
[19] Fix | Delete
* <iframe width='500' height='300' frameborder='0' src='https://spreadsheets1.google.com/a/petedavies.com/pub?hl=en&hl=en&key=0AjSij7nlnXvKdHNsNjRSWG12YmVfOEFwdlMxQ3J1S1E&single=true&gid=0&output=html&widget=true'></iframe>
[20] Fix | Delete
* <iframe width='500' height='300' frameborder='0' src='https://spreadsheets.google.com/spreadsheet/pub?hl=en&hl=en&key=0AhInIwfvYrIUdGJiTXhtUEhBSFVPUzdRZU5OMDlqdnc&output=html&widget=true'></iframe>
[21] Fix | Delete
*
[22] Fix | Delete
* Calendar:
[23] Fix | Delete
* <iframe src="https://www.google.com/calendar/embed?src=serjant%40gmail.com&ctz=Europe/Sofia" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
[24] Fix | Delete
* <iframe src="http://www.google.com/calendar/hosted/belcastro.com/embed?src=n8nr8sd6v9hnus3nmlk7ed1238%40group.calendar.google.com&ctz=Europe/Zurich" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
[25] Fix | Delete
*
[26] Fix | Delete
* Customized calendar:
[27] Fix | Delete
* <iframe src="https://www.google.com/calendar/embed?title=asdf&amp;showTitle=0&amp;showNav=0&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;
[28] Fix | Delete
* showTz=0&amp;mode=AGENDA&amp;height=300&amp;wkst=2&amp;hl=fi&amp;bgcolor=%23ffcccc&amp;src=m52gdmbgelo3itf00u1v44g0ns%40group.calendar.google.com&amp;color=%234E5D6C&amp;
[29] Fix | Delete
* src=serjant%40gmail.com&amp;color=%235229A3&amp;ctz=Europe%2FRiga" style=" border:solid 1px #777 " width="500" height="300" frameborder="0" scrolling="no"></iframe>
[30] Fix | Delete
*
[31] Fix | Delete
* Generic
[32] Fix | Delete
* <iframe src="https://docs.google.com/file/d/0B0SIdZW7iu-zX1RWREJpMXVHZVU/preview" width="640" height="480"></iframe>
[33] Fix | Delete
*
[34] Fix | Delete
* @package automattic/jetpack
[35] Fix | Delete
*/
[36] Fix | Delete
[37] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[38] Fix | Delete
exit( 0 );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[42] Fix | Delete
add_filter( 'pre_kses', 'googleapps_embed_to_shortcode' );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
add_shortcode( 'googleapps', 'googleapps_shortcode' );
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Reverse iframe embed to shortcode mapping HTML attributes to shortcode attributes.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 4.5.0
[51] Fix | Delete
*
[52] Fix | Delete
* @param string $content Post content.
[53] Fix | Delete
*
[54] Fix | Delete
* @return mixed
[55] Fix | Delete
*/
[56] Fix | Delete
function googleapps_embed_to_shortcode( $content ) {
[57] Fix | Delete
if (
[58] Fix | Delete
! is_string( $content )
[59] Fix | Delete
|| false === stripos( $content, '<iframe' )
[60] Fix | Delete
&& false === stripos( $content, '.google.com' )
[61] Fix | Delete
) {
[62] Fix | Delete
return $content;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$regexp = '#<iframe((?:\s+\w+="[^"]*")*?)\s*src="https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/(?!maps)([-\w\./]+)(?:\?)?([^"]+)?"\s*((?:\s+\w+="[^"]*")*?)>.*?</iframe>#i';
[66] Fix | Delete
$regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) );
[67] Fix | Delete
$regexp_squot = str_replace( '"', "'", $regexp );
[68] Fix | Delete
$regexp_ent_squot = str_replace( '"', "'", $regexp_ent );
[69] Fix | Delete
$regexp_noquot = '!<iframe(.*?)src=https://(docs|drive)\.google\.com/[-\.\w/]*?(viewer)\?(.*?)>(.*?)</iframe>!';
[70] Fix | Delete
$regexp_ent_noquot = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $regexp_noquot, ENT_NOQUOTES ) );
[71] Fix | Delete
[72] Fix | Delete
foreach ( compact( 'regexp', 'regexp_ent', 'regexp_squot', 'regexp_ent_squot', 'regexp_noquot', 'regexp_ent_noquot' ) as $reg => $regexp ) {
[73] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[74] Fix | Delete
continue;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
foreach ( $matches as $match ) {
[78] Fix | Delete
$params = $match[1] . $match[5];
[79] Fix | Delete
if ( in_array( $reg, array( 'regexp_ent', 'regexp_ent_squot' ), true ) ) {
[80] Fix | Delete
$params = html_entity_decode( $params, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$params = wp_kses_hair( $params, array( 'http' ) );
[84] Fix | Delete
[85] Fix | Delete
$width = 0;
[86] Fix | Delete
$height = 0;
[87] Fix | Delete
[88] Fix | Delete
if ( isset( $params['width'] ) ) {
[89] Fix | Delete
$width = (int) $params['width']['value'];
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
if ( isset( $params['height'] ) ) {
[93] Fix | Delete
$height = (int) $params['height']['value'];
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
// allow the user to specify width greater than 200 inside text widgets.
[97] Fix | Delete
if (
[98] Fix | Delete
$width > 400
[99] Fix | Delete
// We don't need to check a nonce here. A nonce is already checked "further up" in most code paths.
[100] Fix | Delete
// In the case where no nonce is ever checked, setting this $_POST parameter doesn't do anything the submitter couldn't already do (set the width/height).
[101] Fix | Delete
&& isset( $_POST['widget-text'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
[102] Fix | Delete
) {
[103] Fix | Delete
$width = 200;
[104] Fix | Delete
$height = 200;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
$attributes = '';
[108] Fix | Delete
if ( isset( $params['width'] ) && '100%' === $params['width']['value'] ) {
[109] Fix | Delete
$width = '100%';
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if ( $width ) {
[113] Fix | Delete
$attributes = ' width="' . $width . '"';
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
if ( $height ) {
[117] Fix | Delete
$attributes .= ' height="' . $height . '"';
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$domain = 'spreadsheets';
[121] Fix | Delete
if ( in_array( $match[2], array( 'docs', 'drive', 'www', 'calendar' ), true ) ) {
[122] Fix | Delete
$domain = $match[2];
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
// Make sure this is actually something that the shortcode supports. If it's not, leave the HTML alone.
[126] Fix | Delete
if ( ! googleapps_validate_domain_and_dir( $domain, $match[3] ) ) {
[127] Fix | Delete
continue;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/** This action is documented in modules/widgets/social-media-icons.php */
[131] Fix | Delete
do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', googleapps_service_name( $domain, $match[3] ) );
[132] Fix | Delete
[133] Fix | Delete
$content = str_replace( $match[0], '[googleapps domain="' . $domain . '" dir="' . $match[3] . '" query="' . esc_attr( $match[4] ) . '"' . $attributes . ' /]', $content );
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
return $content;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Parse shortcode attributes and output a Google Docs embed.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 4.5.0
[144] Fix | Delete
*
[145] Fix | Delete
* @param array $atts Shortcode attributes.
[146] Fix | Delete
*
[147] Fix | Delete
* @return string
[148] Fix | Delete
*/
[149] Fix | Delete
function googleapps_shortcode( $atts ) {
[150] Fix | Delete
global $content_width;
[151] Fix | Delete
[152] Fix | Delete
$attr = shortcode_atts(
[153] Fix | Delete
array(
[154] Fix | Delete
'width' => '100%',
[155] Fix | Delete
'height' => '560',
[156] Fix | Delete
'domain' => 'docs',
[157] Fix | Delete
'dir' => 'document',
[158] Fix | Delete
'query' => '',
[159] Fix | Delete
'src' => '',
[160] Fix | Delete
),
[161] Fix | Delete
$atts
[162] Fix | Delete
);
[163] Fix | Delete
[164] Fix | Delete
if ( is_numeric( $content_width ) && $content_width > 0 && is_numeric( $attr['width'] ) && $attr['width'] > $content_width ) {
[165] Fix | Delete
$attr['width'] = $content_width;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( is_numeric( $content_width ) && $content_width > 0 && '560' === $attr['height'] ) {
[169] Fix | Delete
$attr['height'] = floor( $content_width * 3 / 4 );
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
if ( isset( $atts[0] ) && $atts[0] ) {
[173] Fix | Delete
$attr['src'] = $atts[0];
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
if ( $attr['src'] && preg_match( '!https?://(docs|drive|spreadsheets\d*|calendar|www)*\.google\.com/([-\w\./]+)\?([^"]+)!', $attr['src'], $matches ) ) {
[177] Fix | Delete
$attr['domain'] = $matches[1];
[178] Fix | Delete
$attr['dir'] = $matches[2];
[179] Fix | Delete
parse_str( htmlspecialchars_decode( $matches[3], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ), $query_ar );
[180] Fix | Delete
$query_ar['chrome'] = 'false';
[181] Fix | Delete
$query_ar['embedded'] = 'true';
[182] Fix | Delete
$attr['query'] = http_build_query( $query_ar );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ( ! googleapps_validate_domain_and_dir( $attr['domain'], $attr['dir'] ) ) {
[186] Fix | Delete
return '<!-- Unsupported URL -->';
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
$attr['query'] = $attr['dir'] . '?' . $attr['query'];
[190] Fix | Delete
[191] Fix | Delete
/** This action is documented in modules/widgets/social-media-icons.php */
[192] Fix | Delete
do_action( 'jetpack_bump_stats_extras', 'embeds', googleapps_service_name( $attr['domain'], $attr['dir'] ) );
[193] Fix | Delete
[194] Fix | Delete
return sprintf(
[195] Fix | Delete
'<iframe src="%s" frameborder="0" width="%s" height="%s" marginheight="0" marginwidth="0" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>',
[196] Fix | Delete
esc_url( 'https://' . $attr['domain'] . '.google.com/' . $attr['query'] ),
[197] Fix | Delete
esc_attr( $attr['width'] ),
[198] Fix | Delete
esc_attr( $attr['height'] )
[199] Fix | Delete
);
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Check that the domain blogs to a Google Apps domain.
[204] Fix | Delete
*
[205] Fix | Delete
* @since 4.5.0
[206] Fix | Delete
*
[207] Fix | Delete
* @param string $domain Google subdomain.
[208] Fix | Delete
* @param string $dir Subdirectory of the shared URL.
[209] Fix | Delete
*
[210] Fix | Delete
* @return bool
[211] Fix | Delete
*/
[212] Fix | Delete
function googleapps_validate_domain_and_dir( $domain, $dir ) {
[213] Fix | Delete
if ( ! in_array( $domain, array( 'docs', 'drive', 'www', 'spreadsheets', 'calendar' ), true ) ) {
[214] Fix | Delete
return false;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
// Calendars.
[218] Fix | Delete
if ( ( 'www' === $domain || 'calendar' === $domain ) && ! str_starts_with( $dir, 'calendar/' ) ) {
[219] Fix | Delete
return false;
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
// Docs.
[223] Fix | Delete
if ( in_array( $domain, array( 'docs', 'drive' ), true ) && ! preg_match( '![-\.\w/]*(presentation/embed|presentation/d/(.*)|present/embed|document/pub|spreadsheets/d/(.*)|document/d/(e/)?[\w-]+/pub|file/d/[\w-]+/preview|viewer|forms/d/(.*)/viewform|spreadsheet/\w+)$!', $dir ) ) {
[224] Fix | Delete
return false;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
// Spreadsheets.
[228] Fix | Delete
if ( 'spreadsheets' === $domain && ! preg_match( '!^([-\.\w/]+/pub|[-\.\w/]*embeddedform)$!', $dir ) ) {
[229] Fix | Delete
return false;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
return true;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Get the name of the service we'll be embedding.
[237] Fix | Delete
*
[238] Fix | Delete
* @since 4.5.0
[239] Fix | Delete
*
[240] Fix | Delete
* @param string $domain Google subdomain.
[241] Fix | Delete
* @param string $dir Subdirectory of the shared URL.
[242] Fix | Delete
*
[243] Fix | Delete
* @return string
[244] Fix | Delete
*/
[245] Fix | Delete
function googleapps_service_name( $domain, $dir ) {
[246] Fix | Delete
switch ( $domain ) {
[247] Fix | Delete
case 'drive':
[248] Fix | Delete
case 'docs':
[249] Fix | Delete
$service_name = ( 'present/embed' === $dir ) ? 'googledocs_presentation' : 'googledocs_document';
[250] Fix | Delete
break;
[251] Fix | Delete
case 'spreadsheets':
[252] Fix | Delete
$service_name = ( 'embeddedform' === $dir ) ? 'googledocs_form' : 'googledocs_spreadsheet';
[253] Fix | Delete
break;
[254] Fix | Delete
case 'calendar':
[255] Fix | Delete
default:
[256] Fix | Delete
$service_name = 'google_calendar';
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
return $service_name;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function