Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/videopre...
File: shortcode.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[2] Fix | Delete
exit( 0 );
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* VideoPress Shortcode Handler
[7] Fix | Delete
*
[8] Fix | Delete
* This file may or may not be included from the Jetpack VideoPress module.
[9] Fix | Delete
*/
[10] Fix | Delete
class VideoPress_Shortcode {
[11] Fix | Delete
/**
[12] Fix | Delete
* Singleton VideoPress_Shortcode instance.
[13] Fix | Delete
*
[14] Fix | Delete
* @var VideoPress_Shortcode
[15] Fix | Delete
*/
[16] Fix | Delete
protected static $instance;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* VideoPress_Shortcode constructor.
[20] Fix | Delete
*/
[21] Fix | Delete
protected function __construct() {
[22] Fix | Delete
// Only add the shortcode if it hasn't already been added by the standalone VideoPress plugin.
[23] Fix | Delete
if ( ! shortcode_exists( 'videopress' ) ) {
[24] Fix | Delete
add_shortcode( 'videopress', array( $this, 'shortcode_callback' ) );
[25] Fix | Delete
add_shortcode( 'wpvideo', array( $this, 'shortcode_callback' ) );
[26] Fix | Delete
[27] Fix | Delete
add_filter( 'wp_video_shortcode_override', array( $this, 'video_shortcode_override' ), 10, 4 );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$this->add_video_embed_hander();
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* VideoPress_Shortcode initialization.
[35] Fix | Delete
*
[36] Fix | Delete
* @return VideoPress_Shortcode
[37] Fix | Delete
*/
[38] Fix | Delete
public static function initialize() {
[39] Fix | Delete
if ( ! isset( self::$instance ) ) {
[40] Fix | Delete
self::$instance = new self();
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
return self::$instance;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Translate a 'videopress' or 'wpvideo' shortcode and arguments into a video player display.
[48] Fix | Delete
*
[49] Fix | Delete
* Expected input formats:
[50] Fix | Delete
*
[51] Fix | Delete
* [videopress OcobLTqC]
[52] Fix | Delete
* [wpvideo OcobLTqC]
[53] Fix | Delete
*
[54] Fix | Delete
* @link https://codex.wordpress.org/Shortcode_API Shortcode API
[55] Fix | Delete
* @param array $attr shortcode attributes.
[56] Fix | Delete
* @return string HTML markup or blank string on fail
[57] Fix | Delete
*/
[58] Fix | Delete
public function shortcode_callback( $attr ) {
[59] Fix | Delete
global $content_width;
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* We only accept GUIDs as a first unnamed argument.
[63] Fix | Delete
*/
[64] Fix | Delete
$guid = isset( $attr[0] ) ? $attr[0] : null;
[65] Fix | Delete
[66] Fix | Delete
if ( isset( $attr['postid'] ) ) {
[67] Fix | Delete
$guid = get_post_meta( $attr['postid'], 'videopress_guid', true );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Make sure the GUID passed in matches how actual GUIDs are formatted.
[72] Fix | Delete
*/
[73] Fix | Delete
if ( ! videopress_is_valid_guid( $guid ) ) {
[74] Fix | Delete
return '';
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Set the defaults
[79] Fix | Delete
*/
[80] Fix | Delete
$defaults = array(
[81] Fix | Delete
'w' => 0, // Width of the video player, in pixels
[82] Fix | Delete
'at' => 0, // How many seconds in to initially seek to
[83] Fix | Delete
'hd' => true, // Whether to display a high definition version
[84] Fix | Delete
'loop' => false, // Whether to loop the video repeatedly
[85] Fix | Delete
'freedom' => false, // Whether to use only free/libre codecs
[86] Fix | Delete
'autoplay' => false, // Whether to autoplay the video on load
[87] Fix | Delete
'permalink' => true, // Whether to display the permalink to the video
[88] Fix | Delete
'flashonly' => false, // Whether to support the Flash player exclusively
[89] Fix | Delete
'defaultlangcode' => false, // Default language code
[90] Fix | Delete
'cover' => true, // Whether to scale the video to its container.
[91] Fix | Delete
'muted' => false, // Whether the video should start without sound.
[92] Fix | Delete
'controls' => true, // Whether the video should display controls.
[93] Fix | Delete
'playsinline' => false, // Whether the video should be allowed to play inline (for browsers that support this).
[94] Fix | Delete
'useaveragecolor' => false, // Whether the video should use the seekbar automatic average color.
[95] Fix | Delete
'preloadcontent' => 'metadata', // Setting for how the browser should preload the video (none, metadata, auto).
[96] Fix | Delete
);
[97] Fix | Delete
[98] Fix | Delete
// Make sure "false" will be actually false.
[99] Fix | Delete
foreach ( $attr as $key => $value ) {
[100] Fix | Delete
if ( is_string( $value ) && 'false' === strtolower( $value ) ) {
[101] Fix | Delete
$attr[ $key ] = false;
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
if ( isset( $attr['preload'] ) ) {
[106] Fix | Delete
$attr['preloadcontent'] = $attr['preload'];
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$attr = shortcode_atts( $defaults, $attr, 'videopress' );
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Cast the attributes, post-input.
[113] Fix | Delete
*/
[114] Fix | Delete
$attr['width'] = absint( $attr['w'] );
[115] Fix | Delete
$attr['hd'] = (bool) $attr['hd'];
[116] Fix | Delete
$attr['freedom'] = (bool) $attr['freedom'];
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* If the provided width is less than the minimum allowed
[120] Fix | Delete
* width, or greater than `$content_width` ignore.
[121] Fix | Delete
*/
[122] Fix | Delete
if ( $attr['width'] < VIDEOPRESS_MIN_WIDTH ) {
[123] Fix | Delete
$attr['width'] = 0;
[124] Fix | Delete
} elseif ( isset( $content_width ) && $content_width > VIDEOPRESS_MIN_WIDTH && $attr['width'] > $content_width ) {
[125] Fix | Delete
$attr['width'] = 0;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* If there was an invalid or unspecified width, set the width equal to the theme's `$content_width`.
[130] Fix | Delete
*/
[131] Fix | Delete
if ( 0 === $attr['width'] && isset( $content_width ) && $content_width >= VIDEOPRESS_MIN_WIDTH ) {
[132] Fix | Delete
$attr['width'] = (int) $content_width;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* If the width isn't an even number, reduce it by one (making it even).
[137] Fix | Delete
*/
[138] Fix | Delete
if ( 1 === ( $attr['width'] % 2 ) ) {
[139] Fix | Delete
--$attr['width'];
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Filter the default VideoPress shortcode options.
[144] Fix | Delete
*
[145] Fix | Delete
* @module videopress
[146] Fix | Delete
*
[147] Fix | Delete
* @since 2.5.0
[148] Fix | Delete
*
[149] Fix | Delete
* @param array $args Array of VideoPress shortcode options.
[150] Fix | Delete
*/
[151] Fix | Delete
$options = apply_filters(
[152] Fix | Delete
'videopress_shortcode_options',
[153] Fix | Delete
array(
[154] Fix | Delete
'at' => (int) $attr['at'],
[155] Fix | Delete
'hd' => $attr['hd'],
[156] Fix | Delete
'cover' => (bool) $attr['cover'],
[157] Fix | Delete
'loop' => $attr['loop'],
[158] Fix | Delete
'freedom' => $attr['freedom'],
[159] Fix | Delete
'autoplay' => $attr['autoplay'],
[160] Fix | Delete
'permalink' => $attr['permalink'],
[161] Fix | Delete
'force_flash' => (bool) $attr['flashonly'],
[162] Fix | Delete
'defaultlangcode' => $attr['defaultlangcode'],
[163] Fix | Delete
'forcestatic' => false, // This used to be a displayed option, but now is only.
[164] Fix | Delete
'muted' => $attr['muted'],
[165] Fix | Delete
'controls' => $attr['controls'],
[166] Fix | Delete
'playsinline' => $attr['playsinline'],
[167] Fix | Delete
'useAverageColor' => (bool) $attr['useaveragecolor'], // The casing is intentional, shortcode params are lowercase, but player expects useAverageColor
[168] Fix | Delete
'preloadContent' => $attr['preloadcontent'], // The casing is intentional, shortcode params are lowercase, but player expects preloadContent
[169] Fix | Delete
// accessible via the `videopress_shortcode_options` filter.
[170] Fix | Delete
)
[171] Fix | Delete
);
[172] Fix | Delete
[173] Fix | Delete
// Register VideoPress scripts
[174] Fix | Delete
wp_register_script( 'videopress', 'https://v0.wordpress.com/js/videopress.js', array( 'jquery', 'swfobject' ), '1.09', false );
[175] Fix | Delete
[176] Fix | Delete
require_once __DIR__ . '/class.videopress-video.php';
[177] Fix | Delete
require_once __DIR__ . '/class.videopress-player.php';
[178] Fix | Delete
[179] Fix | Delete
$player = new VideoPress_Player( $guid, $attr['width'], $options );
[180] Fix | Delete
[181] Fix | Delete
if ( is_feed() ) {
[182] Fix | Delete
return $player->as_xml();
[183] Fix | Delete
} else {
[184] Fix | Delete
return $player->as_html();
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Override the standard video short tag to also process videopress files as well.
[190] Fix | Delete
*
[191] Fix | Delete
* This will, parse the src given, and if it is a videopress file, it will parse as the
[192] Fix | Delete
* VideoPress shortcode instead.
[193] Fix | Delete
*
[194] Fix | Delete
* @param string $html Empty variable to be replaced with shortcode markup.
[195] Fix | Delete
* @param array $attr Attributes of the video shortcode.
[196] Fix | Delete
* @param string $content Video shortcode content.
[197] Fix | Delete
* @param int $instance Unique numeric ID of this video shortcode instance.
[198] Fix | Delete
*
[199] Fix | Delete
* @return string
[200] Fix | Delete
*/
[201] Fix | Delete
public function video_shortcode_override( $html, $attr, $content, $instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[202] Fix | Delete
$videopress_guid = null;
[203] Fix | Delete
[204] Fix | Delete
if ( isset( $attr['videopress_guid'] ) ) {
[205] Fix | Delete
$videopress_guid = $attr['videopress_guid'];
[206] Fix | Delete
} else {
[207] Fix | Delete
// Handle the different possible url attributes
[208] Fix | Delete
$url_keys = array( 'src', 'mp4' );
[209] Fix | Delete
[210] Fix | Delete
foreach ( $url_keys as $key ) {
[211] Fix | Delete
if ( isset( $attr[ $key ] ) ) {
[212] Fix | Delete
$url = $attr[ $key ];
[213] Fix | Delete
// phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText
[214] Fix | Delete
if ( preg_match( '@videos.(videopress\.com|files\.wordpress\.com)/([a-z0-9]{8})/@i', $url, $matches ) ) {
[215] Fix | Delete
$videopress_guid = $matches[2];
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
// Also test for videopress oembed url, which is used by the Video Media Widget.
[219] Fix | Delete
if ( ! $videopress_guid && preg_match( '@https://videopress.com/v/([a-z0-9]{8})@i', $url, $matches ) ) {
[220] Fix | Delete
$videopress_guid = $matches[1];
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
// Also test for old v.wordpress.com oembed URL.
[224] Fix | Delete
if ( ! $videopress_guid && preg_match( '|^https?://v\.wordpress\.com/([a-zA-Z\d]{8})(.+)?$|i', $url, $matches ) ) { // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText
[225] Fix | Delete
$videopress_guid = $matches[1];
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
break;
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
if ( $videopress_guid ) {
[234] Fix | Delete
$videopress_attr = array( $videopress_guid );
[235] Fix | Delete
if ( isset( $attr['width'] ) ) {
[236] Fix | Delete
$videopress_attr['w'] = (int) $attr['width'];
[237] Fix | Delete
}
[238] Fix | Delete
if ( isset( $attr['muted'] ) ) {
[239] Fix | Delete
$videopress_attr['muted'] = $attr['muted'];
[240] Fix | Delete
}
[241] Fix | Delete
if ( isset( $attr['autoplay'] ) ) {
[242] Fix | Delete
$videopress_attr['autoplay'] = $attr['autoplay'];
[243] Fix | Delete
}
[244] Fix | Delete
if ( isset( $attr['loop'] ) ) {
[245] Fix | Delete
$videopress_attr['loop'] = $attr['loop'];
[246] Fix | Delete
}
[247] Fix | Delete
// The core video block doesn't support the cover attribute, setting it to false for consistency.
[248] Fix | Delete
$videopress_attr['cover'] = false;
[249] Fix | Delete
[250] Fix | Delete
// Then display the VideoPress version of the stored GUID!
[251] Fix | Delete
return $this->shortcode_callback( $videopress_attr );
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
return '';
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Register a VideoPress handler for direct links to .mov files (and potential other non-handled types later).
[259] Fix | Delete
*/
[260] Fix | Delete
public function add_video_embed_hander() {
[261] Fix | Delete
// These are the video extensions that VideoPress can transcode and considers video as well (even if core does not).
[262] Fix | Delete
$extensions = array( 'mov' );
[263] Fix | Delete
$override_extensions = implode( '|', $extensions );
[264] Fix | Delete
[265] Fix | Delete
$regex = "#^https?://videos.(videopress.com|files.wordpress.com)/.+?.($override_extensions)$#i";
[266] Fix | Delete
[267] Fix | Delete
/** This filter is already documented in core/wp-includes/embed.php */
[268] Fix | Delete
$filter = apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' );
[269] Fix | Delete
wp_embed_register_handler( 'video', $regex, $filter, 10 );
[270] Fix | Delete
}
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
VideoPress_Shortcode::initialize();
[274] Fix | Delete
[275] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function