Skip to content

Commit

Permalink
3.3.5
Browse files Browse the repository at this point in the history
* Video and audio short tag is now filtered to insure that the correct URL is always being used, vital for signed URLs
* Fix for importing Offload Media 1.x metadata
* Updated Freemius SDK
  • Loading branch information
jawngee committed Nov 22, 2019
1 parent 87db1c0 commit f8adb08
Show file tree
Hide file tree
Showing 114 changed files with 19,557 additions and 11,458 deletions.
191 changes: 188 additions & 3 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,34 @@ public function __construct( $toolName, $toolInfo, $toolManager )
}

}


add_filter(
'do_parse_request',
function ( $do, \WP $wp ) {

if ( strpos( $_SERVER['REQUEST_URI'], '/__mcloud/attachment' ) === 0 ) {
$postId = sanitize_text_field( arrayPath( $_REQUEST, 'pid', null ) );
$nonce = sanitize_text_field( arrayPath( $_REQUEST, 'nonce', null ) );
if ( empty($postId) || empty($nonce) ) {
return $do;
}
if ( !wp_verify_nonce( $nonce, 'mcloud_view_attachment_' . $postId ) ) {
return $do;
}
$url = wp_get_attachment_url( $postId );

if ( !empty($url) ) {
wp_redirect( $url, 302 );
exit;
}

}

return $do;
},
100,
2
);
}

//endregion
Expand Down Expand Up @@ -460,6 +487,18 @@ function ( $filename ) {
}
return $sizes;
} );
add_filter(
'wp_video_shortcode',
[ $this, 'filterVideoShortcode' ],
PHP_INT_MAX,
5
);
add_filter(
'wp_audio_shortcode',
[ $this, 'filterAudioShortcode' ],
PHP_INT_MAX,
5
);
$this->hookupUI();
} else {

Expand Down Expand Up @@ -1396,9 +1435,23 @@ public function prepareAttachmentForJS( $response, $attachment, $meta )
if ( empty($meta) || !isset( $meta['s3'] ) ) {
$meta = get_post_meta( $attachment->ID, 'ilab_s3_info', true );
}
if ( isset( $response['filename'] ) && strpos( $response['filename'], '?' ) !== false ) {
$response['filename'] = preg_replace( '/(\\?.*)/', '', $response['filename'] );
}

if ( isset( $meta['s3'] ) ) {
$response['s3'] = $meta['s3'];
if ( isset( $response['type'] ) && is_admin() ) {
if ( $this->client()->usesSignedURLs( $response['type'] ) ) {

if ( empty($_REQUEST['post_id']) ) {
$response['url'] = home_url( '/__mcloud/attachment?pid=' . $attachment->ID . '&nonce=' . wp_create_nonce( 'mcloud_view_attachment_' . $attachment->ID ) );
} else {
$response['url'] = $this->client()->url( $meta['s3']['key'] );
}

}
}
if ( !isset( $response['s3']['privacy'] ) ) {
$response['s3']['privacy'] = StorageGlobals::privacy( $attachment->post_mime_type );
}
Expand Down Expand Up @@ -1673,15 +1726,21 @@ private function importStatelessMetadata( $post_id, $meta, $statelessData )
*/
private function importOffloadMetadata( $post_id, $meta, $offloadS3Data )
{
$provider = arrayPath( $offloadS3Data, 'provider', null );
$provider = arrayPath( $offloadS3Data, 'provider', 's3' );
$bucket = arrayPath( $offloadS3Data, 'bucket', null );
$region = arrayPath( $offloadS3Data, 'region', null );
$key = arrayPath( $offloadS3Data, 'key', null );
if ( empty($provider) || empty($bucket) || empty($key) || !in_array( $provider, [ 'aws', 'do', 'gcp' ] ) ) {
if ( empty($provider) || empty($bucket) || empty($key) || !in_array( $provider, [
's3',
'aws',
'do',
'gcp'
] ) ) {
return null;
}
$providerMap = [
'aws' => 's3',
's3' => 's3',
'do' => 'do',
'gcp' => 'google',
];
Expand Down Expand Up @@ -2150,6 +2209,132 @@ public function filterContent( $content )
return $content;
}

/**
* @param string $output Video shortcode HTML output.
* @param array $atts Array of video shortcode attributes.
* @param string $video Video file.
* @param int $post_id Post ID.
* @param string $library Media library used for the video shortcode.
* @return string
* @throws StorageException
*/
public function filterVideoShortcode(
$output,
$atts,
$video,
$post_id,
$library
)
{

if ( isset( $atts['src'] ) ) {
$default_types = wp_get_video_extensions();
$postId = null;
foreach ( $default_types as $type ) {

if ( !empty($atts[$type]) ) {
$url = $atts[$type];
if ( strpos( $url, '?' ) !== false ) {
$url = preg_replace( '/(\\?.*)/', '', $url );
}
$baseFile = ltrim( parse_url( $url, PHP_URL_PATH ), '/' );
if ( empty($baseFile) ) {
return $output;
}
global $wpdb ;
$query = $wpdb->prepare( "select post_id from {$wpdb->postmeta} where meta_key='_wp_attached_file' and meta_value = %s", $baseFile );
$postId = $wpdb->get_var( $query );
if ( empty($postId) ) {
return $output;
}
break;
}

}
if ( empty($postId) ) {
return $output;
}
$post = get_post( $postId );
$meta = wp_get_attachment_metadata( $post->ID );
$url = $this->getAttachmentURL( null, $post->ID );

if ( !empty($url) ) {
$mime = arrayPath( $meta, 'mime_type', $post->post_mime_type );
$insert = "<source type='{$mime}' src='{$url}'/>";
$insert .= "<a href='{$url}'>{$post->post_title}</a>";
if ( preg_match( '/<video(?:[^>]*)>((?s).*)<\\/video>/m', $output, $matches ) ) {
$output = str_replace( $matches[1], $insert, $output );
}
}

}

return $output;
}

/**
* @param string $output Audio shortcode HTML output.
* @param array $atts Array of audio shortcode attributes.
* @param string $audio Audio file.
* @param int $post_id Post ID.
* @param string $library Media library used for the audio shortcode.
* @return string
* @throws StorageException
*/
public function filterAudioShortcode(
$output,
$atts,
$audio,
$post_id,
$library
)
{

if ( isset( $atts['src'] ) ) {
$default_types = wp_get_audio_extensions();
$postId = null;
foreach ( $default_types as $type ) {

if ( !empty($atts[$type]) ) {
$url = $atts[$type];
if ( strpos( $url, '?' ) !== false ) {
$url = preg_replace( '/(\\?.*)/', '', $url );
}
$baseFile = ltrim( parse_url( $url, PHP_URL_PATH ), '/' );
if ( empty($baseFile) ) {
return $output;
}
global $wpdb ;
$query = $wpdb->prepare( "select post_id from {$wpdb->postmeta} where meta_key='_wp_attached_file' and meta_value = %s", $baseFile );
$postId = $wpdb->get_var( $query );
if ( empty($postId) ) {
return $output;
}
break;
}

}
if ( empty($postId) ) {
return $output;
}
$post = get_post( $postId );
$meta = wp_get_attachment_metadata( $post->ID );
$url = $this->getAttachmentURL( null, $post->ID );

if ( !empty($url) ) {
$mime = arrayPath( $meta, 'mime_type', $post->post_mime_type );
$insert = "<source type='{$mime}' src='{$url}'/>";
$insert .= "<a href='{$url}'>{$post->post_title}</a>";
if ( preg_match( '/<audio(?:[^>]*)>((?s).*)<\\/audio>/m', $output, $matches ) ) {
$output = str_replace( $matches[1], $insert, $output );
}
}

}

return $output;
}

private function generateSrcSet( $id, $sizeName )
{
if ( $this->allSizes === null ) {
Expand Down
1 change: 1 addition & 0 deletions classes/Utilities/VideoProbe.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function probe($file) {
'length_formatted' => $this->timecode(floatval(arrayPath($data,'format/duration'))),
'dataformat' => arrayPath($data, 'format/format_long_name', "unknown"),
'fileformat' => strtolower($extension),
'mime_type' => 'video/'.strtolower($extension),
'video' => [
'codec' => arrayPath($videoStream, 'codec_name', null),
'profile' => arrayPath($videoStream, 'profile', null),
Expand Down
2 changes: 1 addition & 1 deletion external/Freemius/assets/css/admin/account.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f8adb08

Please sign in to comment.