Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: archiveorg-book.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Archive.org Shortcode
[2] Fix | Delete
*
[3] Fix | Delete
* Usage:
[4] Fix | Delete
* [archiveorg-book goodytwoshoes00newyiala]
[5] Fix | Delete
* [archiveorg-book https://www.archive.org/stream/goodytwoshoes00newyiala]
[6] Fix | Delete
* [archiveorg id=goodytwoshoes00newyiala width=480 height=430]
[7] Fix | Delete
[8] Fix | Delete
* <iframe src="https://www.archive.org/stream/goodytwoshoes00newyiala?ui=embed#mode/1up" width="480px" height="430px" frameborder="0" ></iframe>
[9] Fix | Delete
*
[10] Fix | Delete
* @package automattic/jetpack
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[14] Fix | Delete
exit( 0 );
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Get ID of requested archive.org book embed.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.5.0
[21] Fix | Delete
*
[22] Fix | Delete
* @param array $atts Shortcode attributes.
[23] Fix | Delete
*
[24] Fix | Delete
* @return int|string
[25] Fix | Delete
*/
[26] Fix | Delete
function jetpack_shortcode_get_archiveorg_book_id( $atts ) {
[27] Fix | Delete
if ( isset( $atts[0] ) ) {
[28] Fix | Delete
$atts[0] = trim( $atts[0], '=' );
[29] Fix | Delete
if ( preg_match( '#archive.org/stream/(.+)/?$#i', $atts[0], $match ) ) {
[30] Fix | Delete
$id = $match[1];
[31] Fix | Delete
} else {
[32] Fix | Delete
$id = $atts[0];
[33] Fix | Delete
}
[34] Fix | Delete
return $id;
[35] Fix | Delete
}
[36] Fix | Delete
return 0;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Convert an archive.org book shortcode into an embed code.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 4.5.0
[43] Fix | Delete
*
[44] Fix | Delete
* @param array $atts An array of shortcode attributes.
[45] Fix | Delete
* @return string The embed code for the Archive.org book
[46] Fix | Delete
*/
[47] Fix | Delete
function jetpack_archiveorg_book_shortcode( $atts ) {
[48] Fix | Delete
global $content_width;
[49] Fix | Delete
[50] Fix | Delete
if ( isset( $atts[0] ) && empty( $atts['id'] ) ) {
[51] Fix | Delete
$atts['id'] = jetpack_shortcode_get_archiveorg_book_id( $atts );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$atts = shortcode_atts(
[55] Fix | Delete
array(
[56] Fix | Delete
'id' => '',
[57] Fix | Delete
'width' => 480,
[58] Fix | Delete
'height' => 430,
[59] Fix | Delete
),
[60] Fix | Delete
$atts
[61] Fix | Delete
);
[62] Fix | Delete
[63] Fix | Delete
if ( ! $atts['id'] ) {
[64] Fix | Delete
return '<!-- error: missing archive.org book ID -->';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$id = $atts['id'];
[68] Fix | Delete
[69] Fix | Delete
if ( ! $atts['width'] ) {
[70] Fix | Delete
$width = absint( $content_width );
[71] Fix | Delete
} else {
[72] Fix | Delete
$width = (int) $atts['width'];
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
if ( ! $atts['height'] ) {
[76] Fix | Delete
$height = round( ( $width / 640 ) * 360 );
[77] Fix | Delete
} else {
[78] Fix | Delete
$height = (int) $atts['height'];
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
return sprintf(
[82] Fix | Delete
'<div class="embed-archiveorg-book" style="text-align:center;"><iframe title="%s" src="%s" width="%s" height="%s" style="border:0;" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen></iframe></div>',
[83] Fix | Delete
esc_attr__( 'Archive.org Book', 'jetpack' ),
[84] Fix | Delete
esc_url( "https://archive.org/stream/{$id}?ui=embed#mode/1up" ),
[85] Fix | Delete
esc_attr( $width ),
[86] Fix | Delete
esc_attr( $height )
[87] Fix | Delete
);
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
add_shortcode( 'archiveorg-book', 'jetpack_archiveorg_book_shortcode' );
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Compose shortcode from archive.org book iframe.
[94] Fix | Delete
*
[95] Fix | Delete
* @since 4.5.0
[96] Fix | Delete
*
[97] Fix | Delete
* @param string $content Post content.
[98] Fix | Delete
*
[99] Fix | Delete
* @return mixed
[100] Fix | Delete
*/
[101] Fix | Delete
function jetpack_archiveorg_book_embed_to_shortcode( $content ) {
[102] Fix | Delete
if ( ! is_string( $content ) || false === stripos( $content, 'archive.org/stream/' ) ) {
[103] Fix | Delete
return $content;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$regexp = '!<iframe\s+src=[\'"](http|https)://(www.archive|archive)\.org/stream/([^\'"]+)[\'"]((?:\s+\w+(=[\'"][^\'"]*[\'"])?)*)\s></iframe>!i';
[107] Fix | Delete
[108] Fix | Delete
if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) {
[109] Fix | Delete
return $content;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
foreach ( $matches as $match ) {
[113] Fix | Delete
$url = explode( '?', $match[3] );
[114] Fix | Delete
$id = $url[0];
[115] Fix | Delete
[116] Fix | Delete
$params = $match[4];
[117] Fix | Delete
[118] Fix | Delete
$params = wp_kses_hair( $params, array( 'http' ) );
[119] Fix | Delete
[120] Fix | Delete
$width = isset( $params['width'] ) ? absint( $params['width']['value'] ) : 0;
[121] Fix | Delete
$height = isset( $params['height'] ) ? absint( $params['height']['value'] ) : 0;
[122] Fix | Delete
[123] Fix | Delete
$wh = '';
[124] Fix | Delete
if ( $width && $height ) {
[125] Fix | Delete
$wh = ' width=' . $width . ' height=' . $height;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$shortcode = '[archiveorg-book ' . $id . $wh . ']';
[129] Fix | Delete
$content = str_replace( $match[0], $shortcode, $content );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
return $content;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( jetpack_shortcodes_should_hook_pre_kses() ) {
[136] Fix | Delete
add_filter( 'pre_kses', 'jetpack_archiveorg_book_embed_to_shortcode' );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function