Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eddcbae
add sync state styles
DavidCramer Apr 20, 2020
3baa03f
make default colum status as not synced
DavidCramer Apr 20, 2020
adc6af1
switch message based on sync state and add additional setting
DavidCramer Apr 20, 2020
743d2be
add new bulk and inline actions
DavidCramer Apr 20, 2020
a6e68b6
Adjust the texts in the sync settings page
Apr 20, 2020
0306d4a
add fluid class for responsive videos
DavidCramer Apr 21, 2020
59d18c1
Merge pull request #71 from cloudinary/fix/change-texts
Apr 21, 2020
13498ab
Merge pull request #72 from cloudinary/fix/CLOUD-372
Apr 21, 2020
a19b48a
Add breakpoint flag to convert_url()
Apr 23, 2020
7c33833
Fix typo
Apr 23, 2020
826ad0f
Merge pull request #74 from cloudinary/fix/change-texts
Apr 23, 2020
2d3bb27
Allow initial/primary URL to be changed on request.
DavidCramer Apr 24, 2020
2fc172d
correctly name to
DavidCramer Apr 24, 2020
c010866
merge develop
DavidCramer Apr 24, 2020
31e5857
clean up formatting
DavidCramer Apr 24, 2020
5f86637
clean up standards
DavidCramer Apr 24, 2020
6759ccc
set auto-upload off if upgrading from v1
DavidCramer Apr 24, 2020
3d5fc9f
Bypass updating the attachment URL on admin
Apr 24, 2020
63224dd
Set default for enabled_breakpoints setting
Apr 24, 2020
9131d93
Confirm that $intermediate is an array
Apr 24, 2020
e4a6f6a
Initialize variable
Apr 24, 2020
7117bf1
Merge pull request #77 from cloudinary/feature/CLOUD-389
Apr 25, 2020
dcd865e
Merge pull request #73 from cloudinary/feature/CLOUD-388
Apr 25, 2020
fc18114
Merge pull request #70 from cloudinary/feature/CLOUD-339
Apr 26, 2020
93f7dcd
update version
DavidCramer Apr 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Cloudinary
* Plugin URI: https://cloudinary.com/documentation/wordpress_integration
* Description: With the Cloudinary plugin, you can upload and manage your media assets in the cloud, then deliver them to your users through a fast content delivery network, improving your website’s loading speed and overall user experience. Apply multiple transformations and take advantage of a full digital asset management solution without leaving WordPress.
* Version: 2.0.4
* Version: 2.0.5
* Author: Cloudinary Ltd., XWP
* Author URI: https://cloudinary.com/
* License: GPLv2+
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,19 @@
max-width : 300px;
display : none;
}

&-status {
&-disabled {
color : $color-red;
}

&-enabled {
color : $color-green;
}

&-button.button {
vertical-align : baseline;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,30 @@ public function verify_connection( $data ) {
if ( empty( $data['cloudinary_url'] ) ) {
delete_option( 'cloudinary_connection_signature' );

add_settings_error(
'cloudinary_connect',
'connection_error',
__( 'Connection to Cloudinary has been removed.', 'cloudinary' ),
'notice-warning'
add_settings_error(
'cloudinary_connect',
'connection_error',
__( 'Connection to Cloudinary has been removed.', 'cloudinary' ),
'notice-warning'
);

return $data;
}

$data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] );
$current = $this->plugin->config['settings']['connect'];
$current = $this->plugin->config['settings']['connect'];

if ( $current['cloudinary_url'] === $data['cloudinary_url'] ) {
return $data;
}

// Pattern match to ensure validity of the provided url
if ( ! preg_match( '~^(?:CLOUDINARY_URL=)?cloudinary://[0-9]+:[A-Za-z_0-9]+@[A-Za-z]+~', $data['cloudinary_url'] ) ) {
add_settings_error(
'cloudinary_connect',
'format_mismatch',
__( 'The environment variable URL must be in this format: cloudinary://API_KEY:API_SECRET@CLOUD_NAME', 'cloudinary' ),
'error'
add_settings_error(
'cloudinary_connect',
'format_mismatch',
__( 'The environment variable URL must be in this format: cloudinary://API_KEY:API_SECRET@CLOUD_NAME', 'cloudinary' ),
'error'
);

return $current;
Expand All @@ -152,6 +152,7 @@ public function verify_connection( $data ) {

if ( ! empty( $result['message'] ) ) {
add_settings_error( 'cloudinary_connect', $result['type'], $result['message'], 'error' );

return $current;
}

Expand Down Expand Up @@ -318,6 +319,7 @@ public function setup() {
public function get_config() {
$signature = get_option( 'cloudinary_connection_signature', null );
$version = get_option( 'cloudinary_version' );

if ( empty( $signature ) || version_compare( $this->plugin->version, $version, '>' ) ) {
// Check if there's a previous version, or missing signature.
$cld_url = get_option( 'cloudinary_url', null );
Expand All @@ -332,10 +334,21 @@ public function get_config() {
$data = array(
'cloudinary_url' => $cld_url,
);
// Set auto sync off.
$sync = get_option( 'cloudinary_sync_media' );
if ( empty( $sync ) ) {
$sync = array(
'auto_sync' => '',
'cloudinary_folder' => '',
);
}
$sync['auto_sync'] = 'off';
update_option( 'cloudinary_sync_media', $sync );
delete_option( 'cloudinary_settings_cache' ); // remove the cache.
}

$data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] );
$test = $this->test_connection( $data['cloudinary_url'] );
$test = $this->test_connection( $data['cloudinary_url'] );

if ( 'connection_success' === $test['type'] ) {
$signature = md5( $data['cloudinary_url'] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function get_transformations_from_string( $str, $type = 'image' ) {
* @return string Cloudinary URL.
*/
public function attachment_url( $url, $attachment_id ) {
if ( ! doing_action( 'wp_insert_post_data' ) && wp_attachment_is( 'video', $attachment_id ) ) {
if ( ! doing_action( 'wp_insert_post_data' ) && ! is_admin() ) {
$cloudinary_id = $this->cloudinary_id( $attachment_id );
if ( false !== $cloudinary_id ) {
$url = $this->cloudinary_url( $attachment_id, $cloudinary_id );
Expand Down Expand Up @@ -542,16 +542,16 @@ public function apply_default_transformations( array $transformations, $type = '
/**
* Generate a Cloudinary URL based on attachment ID and required size.
*
* @param int $attachment_id The id of the attachment.
* @param array|string $size The wp size to set for the URL.
* @param array $transformations Set of transformations to apply to this url.
* @param string $cloudinary_id Optional forced cloudinary ID.
* @param bool $breakpoint Flag url is a breakpoint URL to stop re-applying default transformations.
* @param bool $clean Flag to present a clean url (With out a WP size variable.
* @param int $attachment_id The id of the attachment.
* @param array|string $size The wp size to set for the URL.
* @param array $transformations Set of transformations to apply to this url.
* @param string $cloudinary_id Optional forced cloudinary ID.
* @param bool $overwrite_transformations Flag url is a breakpoint URL to stop re-applying default transformations.
* @param bool $clean Flag to present a clean url (With out a WP size variable.
*
* @return string The converted URL.
*/
public function cloudinary_url( $attachment_id, $size = array(), $transformations = array(), $cloudinary_id = null, $breakpoint = false, $clean = false ) {
public function cloudinary_url( $attachment_id, $size = array(), $transformations = array(), $cloudinary_id = null, $overwrite_transformations = false, $clean = false ) {

if ( empty( $cloudinary_id ) ) {
$cloudinary_id = $this->cloudinary_id( $attachment_id );
Expand All @@ -574,7 +574,9 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
// Check size and correct if string or size.
if ( is_string( $size ) || ( is_array( $size ) && 3 === count( $size ) ) ) {
$intermediate = image_get_intermediate_size( $attachment_id, $size );
$size = $this->get_crop( $intermediate['url'], $attachment_id );
if ( is_array( $intermediate ) ) {
$size = $this->get_crop( $intermediate['url'], $attachment_id );
}
}

/**
Expand All @@ -587,7 +589,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
*/
$pre_args['transformation'] = apply_filters( 'cloudinary_transformations', $transformations, $attachment_id );
// Defaults are only to be added on front, main images ( not breakpoints, since these are adapted down), and videos.
if ( ( ! defined( 'REST_REQUEST' ) || false === REST_REQUEST ) && ! is_admin() && false === $breakpoint ) {
if ( ( ! defined( 'REST_REQUEST' ) || false === REST_REQUEST ) && ! is_admin() && false === $overwrite_transformations ) {
$pre_args['transformation'] = $this->apply_default_transformations( $pre_args['transformation'], $resource_type );
}

Expand Down Expand Up @@ -732,17 +734,21 @@ public function filter_downsize( $image, $attachment_id, $size ) {
/**
* Convert an attachment URL to a Cloudinary one.
*
* @param string $url Url to convert.
* @param int $attachment_id Attachment ID.
* @param array $transformations Optional transformations.
* @param string $url Url to convert.
* @param int $attachment_id Attachment ID.
* @param array $transformations Optional transformations.
* @param bool $overwrite_transformations Flag url as having an overwrite transformation.
*
* @return string Converted URL.
*/
public function convert_url( $url, $attachment_id, $transformations = array() ) {
public function convert_url( $url, $attachment_id, $transformations = array(), $overwrite_transformations = true ) {

if ( $this->is_cloudinary_url( $url ) ) {
return $url; // Already is a cloudinary URL, just return.
}
$size = $this->get_crop( $url, $attachment_id );

return $this->cloudinary_url( $attachment_id, $size, $transformations, null, true );
return $this->cloudinary_url( $attachment_id, $size, $transformations, null, $overwrite_transformations, true );
}

/**
Expand Down Expand Up @@ -820,7 +826,7 @@ function ( $item ) use ( $crop ) {
// Use current sources, but convert the URLS.
foreach ( $sources as &$source ) {
if ( ! $this->is_cloudinary_url( $source['url'] ) ) {
$source['url'] = $this->convert_url( $source['url'], $attachment_id, $transformations );
$source['url'] = $this->convert_url( $source['url'], $attachment_id, $transformations, true ); // Overwrite transformations applied, since the $transformations includes globals from the primary URL.
}
}

Expand Down Expand Up @@ -1072,8 +1078,8 @@ public function media_column_value( $column_name, $attachment_id ) {
if ( 'cld_status' === $column_name ) {
if ( $this->is_media( $attachment_id ) ) {
$status = array(
'state' => 'success',
'note' => esc_html__( 'Synced', 'cloudinary' ),
'state' => 'inactive',
'note' => esc_html__( 'Not Synced', 'cloudinary' ),
);
if ( false === $this->cloudinary_id( $attachment_id ) ) {
// If false, lets check why by seeing if the file size is too large.
Expand All @@ -1085,6 +1091,11 @@ public function media_column_value( $column_name, $attachment_id ) {
$status['note'] = sprintf( __( 'File size exceeds the maximum of %s. This media asset will be served from WordPress.', 'cloudinary' ), $max_size_hr );
$status['state'] = 'error';
}
} else {
$status = array(
'state' => 'success',
'note' => esc_html__( 'Synced', 'cloudinary' ),
);
}
// filter status.
$status = apply_filters( 'cloudinary_media_status', $status, $attachment_id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function filter_video_shortcode( $html, $attr ) {
$instance = $this->queue_video_config( $attr['id'], $attr[ $video['fileformat'] ], $video['fileformat'], $args );

// Replace with video tag.
return '<video id="cloudinary-video-' . esc_attr( $instance ) . '"' . $size . '></video>';
return '<video class="cld-fluid" id="cloudinary-video-' . esc_attr( $instance ) . '"' . $size . '></video>';
}

/**
Expand Down Expand Up @@ -423,14 +423,48 @@ public static function register_scripts_styles() {
wp_register_script( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.js', array( 'cld-core' ), self::PLAYER_VER, true );
}

/**
* Filter a video block to add the class for cld-overriding.
*
* @param array $block The current block structure.
* @param array $source_block The source, unfiltered block structure.
*
* @return array
*/
public function filter_video_block_pre_render( $block, $source_block ) {

if ( 'core/video' === $source_block['blockName'] ) {
$classes = 'cld-fluid';
if ( ! empty( $source_block['attrs']['overwrite_transformations'] ) ) {
$classes .= ' cld-overwrite';
}
foreach ( $block['innerContent'] as &$content ) {

$video_tags = $this->media->filter->get_media_tags( $content );
foreach ( $video_tags as $tag ) {
if ( false !== strpos( $tag, 'class="' ) ) {
$content = str_replace( 'class="', 'class="' . $classes . ' ', $content );
} else {
$content = str_replace( '<video ', '<video class="' . $classes . '" ', $content );
}

}
}
}

return $block;
}

/**
* Setup hooks for the filters.
*/
public function setup_hooks() {
add_filter( 'wp_video_shortcode_override', array( $this, 'filter_video_shortcode' ), 10, 2 );
// only filter video tags in front end.
if ( ! is_admin() ) {
add_filter( 'the_content', array( $this, 'filter_video_tags' ), 4 );
add_filter( 'the_content', array( $this, 'filter_video_tags' ) );
// Filter for block rendering.
add_filter( 'render_block_data', array( $this, 'filter_video_block_pre_render' ), 10, 2 );
}
add_action( 'wp_print_styles', array( $this, 'init_player' ) );
add_action( 'wp_footer', array( $this, 'print_video_scripts' ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function can_delete_asset( $all_caps, $caps, $args ) {
list( $request_cap, , $post_id ) = $args;

if ( 'delete_post' === $request_cap && ! empty( $all_caps['delete_posts'] ) && 'attachment' === get_post_type( $post_id ) ) {
if ( ! $this->plugin->components['sync']->is_synced( $post_id ) ) {

// Check if is pending.
if ( ! $this->plugin->components['sync']->is_synced( $post_id ) && $this->plugin->components['sync']->managers['upload']->is_pending( $post_id ) ) {
// Check for errors.
$has_error = $this->plugin->components['media']->get_post_meta( $post_id, Sync::META_KEYS['sync_error'], true );
if ( empty( $has_error ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public function prepare_upload( $post, $down_sync = false ) {
}

// First check if this has a file and it can be uploaded.
$file = get_attached_file( $post->ID );
$file = get_attached_file( $post->ID );
$file_size = 0;
if ( empty( $file ) ) {
return new \WP_Error( 'attachment_no_file', __( 'Attachment did not have a file.', 'cloudinary' ) );
} elseif ( ! file_exists( $file ) ) {
Expand All @@ -347,8 +348,6 @@ public function prepare_upload( $post, $down_sync = false ) {
}
$file = get_attached_file( $post->ID );
$file_size = filesize( $file );
} else {
$file_size = 0;
}
}
} else {
Expand Down
Loading