Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
20b816d
Disable off option in Autoplay when necessary
May 15, 2020
f5af421
Fix the logic on disabling the 'off' option
May 22, 2020
dac7a5c
Production build js assets
May 23, 2020
d108b8c
Fixes bug where fetched images don't load
May 30, 2020
731758c
Implement a cleaner fix
May 30, 2020
e7b7574
Merge pull request #84 from cloudinary/add/355-disable-off-option
Jun 4, 2020
bb5b810
Merge pull request #92 from cloudinary/fix/fetched-images-bug
Jun 4, 2020
9046ad3
Merge branch 'develop' into fix/$wpsize_!_cld_full!-error
Jun 4, 2020
769c432
Ensure does not become part of final front url
Jun 4, 2020
cf3b880
Merge pull request #97 from cloudinary/uat
pereirinha Jun 5, 2020
7d93b0c
Update PR
Jun 5, 2020
0ca58e4
Merge pull request #95 from cloudinary/fix/$wpsize_!_cld_full!-error
Jun 5, 2020
0f2c695
Merge pull request #103 from cloudinary/master
Jun 11, 2020
14acc06
Add overwrite_transformation check for global transformations
Jun 13, 2020
5f92834
Add overwrite_transformations check for global transformations
Jun 19, 2020
70596d2
add rename sync type
DavidCramer Jun 23, 2020
f5f4e6a
add public_id sync state
DavidCramer Jun 23, 2020
82a0b49
fix upgrade check to return if v2 meta exists.
DavidCramer Jun 23, 2020
d245cef
cleanup meta checking
DavidCramer Jun 23, 2020
43355d3
cleanup settings use.
DavidCramer Jun 23, 2020
9a9ab05
use the generated signature as a default for stored.
DavidCramer Jun 25, 2020
3d720c6
move to get_signature method.
DavidCramer Jun 25, 2020
c71b2e0
cache signatures and cleanup.
DavidCramer Jun 25, 2020
3722a90
Add usage warning to transformation spots in the plugin
Jun 25, 2020
f737934
Add warning to transformation settings
Jun 25, 2020
383a22f
add calculation based percentages for credit types
DavidCramer Jun 29, 2020
5023371
use the public id's synced path rather than folder set.
DavidCramer Jun 29, 2020
c3abb68
Merge pull request #110 from cloudinary/master
Jun 29, 2020
373d871
Merge pull request #109 from cloudinary/fix/quota-calculations
Jun 29, 2020
562affe
reorganise sync types in logicial order
DavidCramer Jun 30, 2020
10c11ff
simplify public_id / folder split
DavidCramer Jun 30, 2020
043b82c
add folder_sync to maintain sync structure and cleanup code
DavidCramer Jun 30, 2020
e124f2d
add folder_sync upgrade script for 1.2.1 and below.
DavidCramer Jun 30, 2020
ec573e6
Merge pull request #105 from cloudinary/feature/public-id-sync
Jun 30, 2020
ec80adc
rebuild assets
DavidCramer Jun 30, 2020
1208e26
Handle error from prepare_upload.
DavidCramer Jul 1, 2020
cd38003
return not synced if exeeding
DavidCramer Jul 1, 2020
3d3e28a
version bump
DavidCramer Jul 1, 2020
48d84a4
ltrim forward slashes on public ID
DavidCramer Jul 1, 2020
735c00c
Merge pull request #112 from cloudinary/fix/ltrim-forward-slash
pereirinha Jul 1, 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.1.2
* Version: 2.1.3
* 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 @@ -208,3 +208,11 @@
}
}
}

.settings-warning {
display: inline-block;
padding: 5px 7px;
background-color: #ffea98;
border-left: 4px solid #ffcc00;
box-shadow: 0px 0px 5px 0px rgba(112,112,112,0.4);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
(function() {

// Disable the "off" dropdown option for Autoplay if
// the player isn't set to Cloudinary or if Show Controls if unchecked.
const disableAutoplayOff = function() {
const player = jQuery( '#field-video_player' ).val();
const showControls = jQuery( '#field-video_controls' ).prop( 'checked' );
const offSelection = jQuery( '#field-video_autoplay_mode option[value="off"]' );

if ( player === 'cld' && ! showControls ) {
offSelection.prop( 'disabled', true );
if ( offSelection.prop( 'selected' ) ) {
offSelection.next().prop( 'selected', true );
}
} else {
offSelection.prop( 'disabled', false );
}
}

disableAutoplayOff();
jQuery( document ).on( 'change', '#field-video_player', disableAutoplayOff );
jQuery( document ).on( 'change', '#field-video_controls', disableAutoplayOff );

jQuery( document ).ready( function( $ ) {

// Initilize instance events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ public function get_usage_stat( $type, $stat = null ) {
if ( 'limit' === $stat && isset( $this->usage[ $type ]['usage'] ) ) {
$value = $this->usage[ $type ]['usage'];
} elseif ( 'used_percent' === $stat && isset( $this->usage[ $type ]['credits_usage'] ) ) {
$value = $this->usage[ $type ]['credits_usage'];
// Calculate percentage based on credit limit and usage.
$value = round( $this->usage[ $type ]['credits_usage']/$this->usage['credits']['limit'] * 100, 2 );
}
}
}
Expand Down Expand Up @@ -432,28 +433,27 @@ public function get_config() {
*/
public function usage_notices() {
if ( ! empty( $this->usage ) ) {
$usage_type = 'used_percent';
if ( isset( $this->usage['credits'] ) ) {
$usage_type = 'credits_usage';
}
foreach ( $this->usage as $stat => $values ) {

if ( ! is_array( $values ) || ! isset( $values[ $usage_type ] ) || 0 > $values[ $usage_type ] ) {
if ( ! is_array( $values ) ) {
continue;
}
$usage = $this->get_usage_stat( $stat, 'used_percent' );
if ( empty ( $usage ) ) {
continue;
}

$link = null;
$link_text = null;
if ( 90 <= $values[ $usage_type ] ) {
if ( 90 <= $usage ) {
// 90% used - show error.
$level = 'error';
$link = 'https://cloudinary.com/console/lui/upgrade_options';
$link_text = __( 'upgrade your account', 'cloudinary' );
} elseif ( 80 <= $values[ $usage_type ] ) {
$level = 'warning';
} elseif ( 80 <= $usage ) {
$level = 'warning';
$link_text = __( 'upgrade your account', 'cloudinary' );
} elseif ( 70 <= $values[ $usage_type ] ) {
$level = 'neutral';
} elseif ( 70 <= $usage ) {
$level = 'neutral';
$link_text = __( 'upgrade your account', 'cloudinary' );
} else {
continue;
Expand All @@ -465,7 +465,7 @@ public function usage_notices() {
'cloudinary'
),
ucwords( $stat ),
$values[ $usage_type ] . '%',
$usage . '%',
$link,
$link_text
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ public function down_sync_asset() {
if ( $format !== $file_info['extension'] ) {
// Format transformation.
$this->set_transformation( $transformations, 'fetch_format', $file_info['extension'] );
$url = $file_info['dirname'] . '/' . $file_info['filename'] . '.' . $format;
$url = $file_info['dirname'] . '/' . $file_info['filename'] . '.' . $file_info['extension'];
}
// Try to find the Attachment ID in context meta data.
$attachment_id = $this->get_id_from_sync_key( $sync_key );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Sync implements Setup, Assets {
'transformation' => '_transformations',
'sync_error' => '_sync_error',
'cloudinary' => '_cloudinary_v2',
'folder_sync' => '_folder_sync',
);

/**
Expand Down Expand Up @@ -100,8 +101,9 @@ public function is_active() {
*/
public function is_synced( $post_id ) {
$return = false;
$signature = $this->plugin->components['media']->get_post_meta( $post_id, self::META_KEYS['signature'], true );
if ( ! empty( $signature ) && $this->generate_signature( $post_id ) === $signature ) {
$signature = $this->get_signature( $post_id );
$expecting = $this->generate_signature( $post_id );
if ( ! empty( $signature ) && ! empty( $expecting ) && $expecting === $signature ) {
$return = $signature;
}

Expand All @@ -113,10 +115,16 @@ public function is_synced( $post_id ) {
*
* @param int $post_id The post id to generate a signature for.
*
* @return string
* @return string|bool
*/
public function generate_signature( $post_id ) {
$upload = $this->managers['push']->prepare_upload( $post_id );
$upload = $this->managers['push']->prepare_upload( $post_id );
// Check if has an error (ususally due to file quotas).
if ( is_wp_error( $upload ) ) {
$this->plugin->components['media']->get_post_meta( $post_id, self::META_KEYS['sync_error'], $upload->get_error_message() );

return false;
}
$credentials = $this->plugin->components['connect']->get_credentials();
$upload['cloud_name'] = $credentials['cloud_name'];
$return = array_map(
Expand All @@ -133,6 +141,31 @@ function ( $item ) {
return $return;
}

/**
* Get the current sync signature of an asset.
*
* @param int $post_id The post ID.
*
* @return array|bool
*/
public function get_signature( $post_id ) {
static $signatures = array(); // Cache signatures already fetched.

$return = false;
if ( ! empty( $signatures[ $post_id ] ) ) {
$return = $signatures[ $post_id ];
} else {
$signature = $this->plugin->components['media']->get_post_meta( $post_id, self::META_KEYS['signature'], true );
if ( ! empty( $signature ) ) {
$base_signatures = $this->generate_signature( $post_id );
$signatures[ $post_id ] = wp_parse_args( $signature, $base_signatures );
$return = $signatures[ $post_id ];
}
}

return $return;
}

/**
* Additional component setup.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,17 @@ function ( $item ) use ( $transformation_index ) {
if ( is_string ( $item ) ) {
return $item;
}

foreach ( $item as $type => $value ) { // phpcs:ignore
$key = array_search( $type, $transformation_index, true );
if ( 'wpsize' === $type ) {
if ( false !== strpos( $type, 'wpsize' ) ) {
if ( ! empty( $item['clean'] ) ) {
continue;
}

$value = '!' . $value . '!';
}

if ( false !== $key ) {
$transform[] = $key . '_' . $value;
}
Expand Down Expand Up @@ -236,13 +239,19 @@ public function cloudinary_url( $public_id, $args = array(), $size = array(), $c
$args['version'] = 'v1';
}

// Determine if we're dealing with a fetched
// ...or uploaded image and update the URL accordingly.
$asset_endpoint = filter_var( $public_id, FILTER_VALIDATE_URL ) ? 'fetch' : 'upload';

$url_parts = array(
'https:/',
$this->url( $args['resource_type'], 'upload' ),
$this->url( $args['resource_type'], $asset_endpoint ),
);

if ( ! empty( $args['transformation'] ) ) {
$url_parts[] = self::generate_transformation_string( $args['transformation'] );
}

// Add size.
if ( ! empty( $size ) && is_array( $size ) ) {
if ( true === $clean ) {
Expand All @@ -252,7 +261,6 @@ public function cloudinary_url( $public_id, $args = array(), $size = array(), $c
}

$url_parts[] = $args['version'];

$url_parts[] = $public_id;

// Clear out empty parts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function __construct( \Cloudinary\Media $media ) {
public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
if ( false === $cloudinary_id ) {
// Backwards compat.
$meta = wp_get_attachment_metadata( $attachment_id );
$meta = wp_get_attachment_metadata( $attachment_id );
if ( ! empty( $meta[ Sync::META_KEYS['cloudinary'] ] ) ) {
return $cloudinary_id; // Current version.
}
$public_id = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true );

/*
Expand All @@ -59,6 +62,24 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
// Has public ID, but not fully down synced.
$cloudinary_id = $public_id;
}
} else {
// Backwards compat.
$folder_sync = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], true );
if ( 0 === strlen( $folder_sync ) ) {
// Does not exist, add it to be compatible with v1.2.2.
$public_id = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true );
// Set the folder sync to 0 to flag it by default as not synced.
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], '0' );
if ( false !== strpos( $public_id, '/' ) ) {
$path = pathinfo( $public_id );
$asset_folder = trailingslashit( $path['dirname'] );
$cloudinary_folder = trailingslashit( $this->media->plugin->config['settings']['sync_media']['cloudinary_folder'] );
if ( $asset_folder === $cloudinary_folder ) {
// The asset folder matches the defined cloudinary folder, flag it as being in a folder sync.
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], '1' );
}
}
}
}

return $cloudinary_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public function filter_video_shortcode( $html, $attr ) {
if ( ! empty( $transformations ) ) {
$args['transformation'] = $transformations;
}
$args['overwrite_transformations'] = $overwrite_transformations;
// Size settings.
$size = '';
if ( ! empty( $attr['width'] ) ) {
Expand Down Expand Up @@ -307,6 +308,8 @@ public function filter_video_tags( $content ) {
if ( false !== strpos( $classes, 'cld-overwrite' ) ) {
$overwrite_transformations = true;
}
$args['overwrite_transformations'] = $overwrite_transformations;

$cloudinary_url = $this->media->cloudinary_url( $attachment_id, false, false, null, $overwrite_transformations );
// Bail replacing the video URL for cases where it doesn't exist.
// Cases are, for instance, when the file size is larger than the API limits — free accounts.
Expand Down Expand Up @@ -388,15 +391,19 @@ public function print_video_scripts() {
if ( videoElement.length === 1 ) {
videoElement = videoElement[0];
videoElement.style.width = '100%';

<?php if ( $this->config['video_freeform'] ): ?>
if ( videoElement.src.indexOf( '<?php echo esc_js( $this->config['video_freeform'] ) ?>' ) === -1 ) {
videoElement.src = videoElement.src.replace(
'upload/',
'upload/<?php echo esc_js( $this->config['video_freeform'] ) ?>/'
);
}

if (
videoElement.src.indexOf( '<?php echo esc_js( $this->config['video_freeform'] ) ?>' ) === -1 &&
! cldVideos[videoInstance]['overwrite_transformations']
) {
videoElement.src = videoElement.src.replace(
'upload/',
'upload/<?php echo esc_js( $this->config['video_freeform'] ) ?>/'
);
}
<?php endif ?>

}
}
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ function ( $val ) use ( $media ) {
$public_id = strstr( $public_id, '.' . $path['extension'], true );
// Save public ID.
$media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );
// Check if the asset is in the same folder as the defined Cloudinary folder.
if ( false !== strpos( $public_id, '/' ) ) {
$path = pathinfo( $public_id );
$asset_folder = trailingslashit( $path['dirname'] );
$cloudinary_folder = trailingslashit( $this->plugin->config['settings']['sync_media']['cloudinary_folder'] );
if ( $asset_folder === $cloudinary_folder ) {
// The asset folder matches the defined cloudinary folder, flag it as being in a folder sync.
$media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], true );
}
}

return $this->download_asset( $attachment_id, $file, basename( $file ), $media->get_transformations_from_string( $file ) );
}
Expand Down
Loading