From 8dc11b9a9c2efde3786745d7ceec958b79611d8b Mon Sep 17 00:00:00 2001 From: Dukagjin Surdulli Date: Thu, 9 Apr 2020 19:29:23 -0400 Subject: [PATCH 01/58] Ensure 100% width for videos. --- .../php/media/class-video.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index a461f841f..3091d085a 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -369,29 +369,29 @@ public function print_video_scripts() { var cldVideos = ; for ( var videoInstance in cldVideos ) { - var cldConfig = cldVideos[ videoInstance ]; - var cldId = 'cloudinary-video-' + videoInstance; - cld.videoPlayer( cldId, cldConfig ); + var cldConfig = cldVideos[ videoInstance ]; + var cldId = 'cloudinary-video-' + videoInstance; + cld.videoPlayer( cldId, cldConfig ); } window.addEventListener( 'load', function() { - for ( var videoInstance in cldVideos ) { - var cldId = 'cloudinary-video-' + videoInstance; - var videoContainer = document.getElementById( cldId ); - var videoElement = videoContainer.getElementsByTagName( 'video' ); - - if ( videoElement.length === 1 ) { - videoElement = videoElement[0]; - - - config['video_freeform'] ): ?> - videoElement.src = videoElement.src.replace( - 'upload/', - 'upload/config['video_freeform'] ) ?>/' - ); - - } - } + for ( var videoInstance in cldVideos ) { + var cldId = 'cloudinary-video-' + videoInstance; + var videoContainer = document.getElementById( cldId ); + var videoElement = videoContainer.getElementsByTagName( 'video' ); + + if ( videoElement.length === 1 ) { + videoElement = videoElement[0]; + videoElement.style.width = '100%'; + + config['video_freeform'] ): ?> + videoElement.src = videoElement.src.replace( + 'upload/', + 'upload/config['video_freeform'] ) ?>/' + ); + + } + } } ); Date: Tue, 14 Apr 2020 14:12:58 -0400 Subject: [PATCH 02/58] Add check to see whether transformation is already applied --- .../css/cloudinary.css | 318 +++++++++++++++- .../js/block-editor.js | 353 +++++++++++++++++- .../js/cloudinary.js | 183 ++++++++- .../php/media/class-video.php | 10 +- 4 files changed, 857 insertions(+), 7 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css index 7df57b89b..263568e5f 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css @@ -1 +1,317 @@ -@font-face{font-family:cloudinary;src:url(../css/fonts/cloudinary.eot);src:url(../css/fonts/cloudinary.eot#iefix) format("embedded-opentype"),url(../css/fonts/cloudinary.ttf) format("truetype"),url(../css/fonts/cloudinary.woff) format("woff"),url(../css/cloudinary.svg#cloudinary) format("svg");font-weight:400;font-style:normal}.dashicons-cloudinary{speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.dashicons-cloudinary:before{font-family:cloudinary!important;content:"\e900"}.dashicons-cloudinary.success{color:#558b2f}.dashicons-cloudinary.error{color:#dd2c00}.dashicons-cloudinary.error:before{content:"\e901"}.dashicons-cloudinary.warning:before{content:"\e902"}.dashicons-cloudinary.warning{color:#fd9d2c}.column-cld_status{width:5.5em}.column-cld_status .dashicons-cloudinary{display:inline-block}.column-cld_status .dashicons-cloudinary:before{font-size:1.8rem}.form-field .error-notice,.form-table .error-notice{display:none;color:#dd2c00}.form-field input.cld-field:invalid,.form-table input.cld-field:invalid{border-color:#dd2c00}.form-field input.cld-field:invalid+.error-notice,.form-table input.cld-field:invalid+.error-notice{display:inline-block}.cloudinary-welcome{background-image:url(../css/logo.svg);background-repeat:no-repeat;background-size:153px;background-position:top 12px right 20px}.settings-image{max-width:100%;padding-top:5px}.settings-tabs>li{display:inline-block}.settings-tabs>li a{padding:.6em}.settings-tabs>li a.active{background-color:#fff}.settings-tab-section{padding:20px 0 0;max-width:1030px;position:relative}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard{display:flex;align-items:flex-start;align-content:flex-start;margin-top:40px}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-description{width:55%;margin:0 auto 0 0}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content{width:35%;margin:0 auto}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content .dashicons{color:#9ea3a8}.settings-tab-section.cloudinary-welcome .settings-tab-section-card{margin-top:0}.settings-tab-section-fields .field-heading th{display:block;width:auto;color:#23282d;font-size:1.1em;margin:1em 0}.settings-tab-section-fields .field-heading td{display:none;visibility:hidden}.settings-tab-section-fields .regular-textarea{width:100%;height:60px}.settings-tab-section-fields .dashicons{text-decoration:none;vertical-align:middle}.settings-tab-section-fields a .dashicons{color:#5f5f5f}.settings-tab-section-fields-dashboard-error{font-size:1.2em;color:#5f5f5f}.settings-tab-section-fields-dashboard-error .dashicons{color:#ac0000}.settings-tab-section-fields-dashboard-error .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success{font-size:1.2em;color:#23282d}.settings-tab-section-fields-dashboard-success.expanded{padding-top:40px}.settings-tab-section-fields-dashboard-success .dashicons{color:#4fb651}.settings-tab-section-fields-dashboard-success .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success .description{color:#5f5f5f;font-weight:400;margin-top:12px}.settings-tab-section-card{box-sizing:border-box;border:1px solid #e5e5e5;background-color:#fff;box-shadow:0 1px 1px 0 rgba(0,0,0,.07);padding:20px 23px;margin-top:12px}.settings-tab-section-card .dashicons{font-size:1.4em}.settings-tab-section-card h2{font-size:1.8em;font-weight:400;margin-top:0}.settings-tab-section-card.pull-right{width:450px;padding:12px;float:right;position:relative;z-index:10}.settings-tab-section-card.pull-right img.settings-image{box-shadow:0 2px 4px 0 rgba(0,0,0,.5);border:1px solid #979797;margin-top:12px}.settings-tab-section-card.pull-right h3,.settings-tab-section-card.pull-right h4{margin-top:0}.settings-tab-section .field-row-cloudinary_url,.settings-tab-section .field-row-signup{display:block}.settings-tab-section .field-row-cloudinary_url td,.settings-tab-section .field-row-cloudinary_url th,.settings-tab-section .field-row-signup td,.settings-tab-section .field-row-signup th{display:block;width:auto;padding:10px 0 0}.settings-tab-section .field-row-cloudinary_url td .sign-up,.settings-tab-section .field-row-cloudinary_url th .sign-up,.settings-tab-section .field-row-signup td .sign-up,.settings-tab-section .field-row-signup th .sign-up{vertical-align:baseline}.settings-tab-section.connect .form-table{display:inline-block;width:auto;max-width:580px}.settings-valid{color:#558b2f;font-size:30px}.settings-valid-field{border-color:#558b2f!important}.settings-invalid-field{border-color:#dd2c00!important}.sync .spinner{display:inline-block;visibility:visible;float:none;margin:0 5px 0 0}.sync-media,.sync-media-progress{display:none}.sync-media-progress-outer{height:20px;margin:20px 0 10px;width:500px;background-color:#e5e5e5;position:relative}.sync-media-progress-outer .progress-bar{width:0;height:20px;background-color:#558b2f;transition:width .25s}.sync-media-progress-notice{color:#dd2c00}.sync-media-resource{width:100px;display:inline-block}.sync-media-error{color:#dd2c00}.sync-count{font-weight:700}.sync-details{margin-top:10px}.sync .button.start-sync,.sync .button.stop-sync{display:none;padding:0 16px}.sync .button.start-sync .dashicons,.sync .button.stop-sync .dashicons{line-height:2.2em}.sync .progress-text{padding:12px 4px 12px 12px;display:inline-block;font-weight:700}.sync .completed{max-width:300px;display:none}.cloudinary-widget{height:100%}.cloudinary-widget-wrapper{height:100%;overflow:hidden;background-image:url("data:image/svg+xml;base64,PHN2ZyBjbGFzcz0ic3Bpbm5lciIgdmlld0JveD0iLTQgLTQgMTUxIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48c3R5bGU+QGtleWZyYW1lcyBjb2xvcnN7MCUsdG97c3Ryb2tlOiMwMDc4ZmZ9NTAle3N0cm9rZTojMGUyZjVhfX1Aa2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX1ALXdlYmtpdC1rZXlmcmFtZXMgY29sb3JzezAlLHRve3N0cm9rZTojMDA3OGZmfTUwJXtzdHJva2U6IzBlMmY1YX19QC13ZWJraXQta2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX08L3N0eWxlPjxwYXRoIGQ9Ik0xMjEuNjYzIDkwLjYzOGMtMS43OTYgMC05OS4zMy0uNDk4LTEwMS40NzQtMS40NzhDOC42ODUgODMuODc3IDEuMjUgNzIuMTk2IDEuMjUgNTkuMzk2YzAtMTYuNjU2IDEyLjc5Ny0zMC42MSAyOS4wNTItMzIuMzIzIDcuNDktMTUuNzA2IDIzLjE4Ni0yNS43MDcgNDAuNzE0LTI1LjcwNyAyMC45OCAwIDM5LjIxNSAxNC43NTIgNDMuOTQ1IDM0LjkwNyAxNS4wOS4yNDUgMjcuMjkgMTIuNjMgMjcuMjkgMjcuODIyIDAgMTEuOTY4LTcuNzM4IDIyLjU1LTE5LjI1NiAyNi4zMyIgc3Ryb2tlLXdpZHRoPSI5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3R5bGU9InRyYW5zZm9ybS1vcmlnaW46Y2VudGVyOy13ZWJraXQtYW5pbWF0aW9uOmRhc2ggMnMgZWFzZS1pbi1vdXQgaW5maW5pdGUsY29sb3JzIDhzIGVhc2UtaW4tb3V0IGluZmluaXRlO2FuaW1hdGlvbjpkYXNoIDJzIGVhc2UtaW4tb3V0IGluZmluaXRlLGNvbG9ycyA4cyBlYXNlLWluLW91dCBpbmZpbml0ZSIgc3Ryb2tlLWRhc2hhcnJheT0iMjgwIi8+PC9zdmc+");background-repeat:no-repeat;background-position:50%;background-size:150px}.attachment-actions .button.edit-attachment,.attachment-info .edit-attachment{display:none}.global-transformations-preview{position:relative;max-width:600px}.global-transformations-spinner{display:none}.global-transformations-button.button-primary{display:none;position:absolute;z-index:100}.global-transformations-url{margin-bottom:5px;margin-top:5px}.global-transformations-url-transformation{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:#51a3ff}.global-transformations-url-file{color:#f2d864}.global-transformations-url-link{display:block;padding:16px;background-color:#262c35;text-decoration:none;color:#fff;border-radius:6px;overflow:hidden;text-overflow:ellipsis}.global-transformations-url-link:hover{color:#888;text-decoration:underline}.cld-tax-order-list-item{border:1px solid #efefef;padding:4px;margin:0 0 -1px;background-color:#fff}.cld-tax-order-list-item.no-items{color:#888;text-align:center;display:none}.cld-tax-order-list-item.no-items:last-child{display:block}.cld-tax-order-list-item.ui-sortable-helper{box-shadow:0 2px 5px rgba(0,0,0,.2)}.cld-tax-order-list-item-placeholder{background-color:#efefef;height:45px;margin:0}.cld-tax-order-list-item-handle{cursor:grab;margin-right:4px;color:#999}.cld-tax-order-list-type{width:45%;display:inline-block;margin-right:8px}.cld-tax-order-list-type input{margin-right:4px!important}.cloudinary-media-library{position:relative;margin-left:-20px}@media screen and (max-width:782px){.cloudinary-media-library{margin-left:-10px}} \ No newline at end of file +@font-face { + font-family: 'cloudinary'; + src: url(../css/fonts/cloudinary.eot); + src: url(../css/fonts/cloudinary.eot#iefix) format("embedded-opentype"), url(../css/fonts/cloudinary.ttf) format("truetype"), url(../css/fonts/cloudinary.woff) format("woff"), url(../css/cloudinary.svg#cloudinary) format("svg"); + font-weight: normal; + font-style: normal; } + +.dashicons-cloudinary { + /* use !important to prevent issues with browser extensions that change fonts */ + speak: none; + font-style: normal; + font-weight: normal; + font-variant: normal; + text-transform: none; + line-height: 1; + /* Better Font Rendering =========== */ + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } + .dashicons-cloudinary:before { + font-family: 'cloudinary' !important; + content: '\e900'; } + .dashicons-cloudinary.success { + color: #558b2f; } + .dashicons-cloudinary.error { + color: #dd2c00; } + .dashicons-cloudinary.error:before { + content: '\e901'; } + .dashicons-cloudinary.warning { + color: #fd9d2c; } + .dashicons-cloudinary.warning:before { + content: '\e902'; } + .dashicons-cloudinary.warning { + color: #fd9d2c; } + .dashicons-cloudinary.warning { + color: #fd9d2c; } + +.column-cld_status { + width: 5.5em; } + .column-cld_status .dashicons-cloudinary { + display: inline-block; } + .column-cld_status .dashicons-cloudinary:before { + font-size: 1.8rem; } + +.form-field .error-notice, .form-table .error-notice { + display: none; + color: #dd2c00; } + +.form-field input.cld-field:invalid, .form-table input.cld-field:invalid { + border-color: #dd2c00; } + .form-field input.cld-field:invalid + .error-notice, .form-table input.cld-field:invalid + .error-notice { + display: inline-block; } + +.cloudinary-welcome { + background-image: url(../css/logo.svg); + background-repeat: no-repeat; + background-size: 153px; + background-position: top 12px right 20px; } + +.settings-image { + max-width: 100%; + padding-top: 5px; } + +.settings-tabs > li { + display: inline-block; } + .settings-tabs > li a { + padding: .6em; } + .settings-tabs > li a.active { + background-color: #ffffff; } + +.settings-tab-section { + padding: 20px 0 0 0; + max-width: 1030px; + position: relative; } + .settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard { + display: flex; + align-items: flex-start; + align-content: flex-start; + margin-top: 40px; } + .settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-description { + width: 55%; + margin: 0 auto 0 0; } + .settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content { + width: 35%; + margin: 0 auto; } + .settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content .dashicons { + color: #9EA3A8; } + .settings-tab-section.cloudinary-welcome .settings-tab-section-card { + margin-top: 0; } + .settings-tab-section-fields .field-heading th { + display: block; + width: auto; + color: #23282d; + font-size: 1.1em; + margin: 1em 0; } + .settings-tab-section-fields .field-heading td { + display: none; + visibility: hidden; } + .settings-tab-section-fields .regular-textarea { + width: 100%; + height: 60px; } + .settings-tab-section-fields .dashicons { + text-decoration: none; + vertical-align: middle; } + .settings-tab-section-fields a .dashicons { + color: #5F5F5F; } + .settings-tab-section-fields-dashboard-error { + font-size: 1.2em; + color: #5F5F5F; } + .settings-tab-section-fields-dashboard-error .dashicons { + color: #AC0000; } + .settings-tab-section-fields-dashboard-error .button { + font-size: 1.1em; + height: 40px; + line-height: 40px; + padding-right: 40px; + padding-left: 40px; } + .settings-tab-section-fields-dashboard-success { + font-size: 1.2em; + color: #23282d; } + .settings-tab-section-fields-dashboard-success.expanded { + padding-top: 40px; } + .settings-tab-section-fields-dashboard-success .dashicons { + color: #4FB651; } + .settings-tab-section-fields-dashboard-success .button { + font-size: 1.1em; + height: 40px; + line-height: 40px; + padding-right: 40px; + padding-left: 40px; } + .settings-tab-section-fields-dashboard-success .description { + color: #5F5F5F; + font-weight: normal; + margin-top: 12px; } + .settings-tab-section-card { + box-sizing: border-box; + border: 1px solid #E5E5E5; + background-color: #FFFFFF; + box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.07); + padding: 20px 23px; + margin-top: 12px; } + .settings-tab-section-card .dashicons { + font-size: 1.4em; } + .settings-tab-section-card h2 { + font-size: 1.8em; + font-weight: normal; + margin-top: 0; } + .settings-tab-section-card.pull-right { + width: 450px; + padding: 12px; + float: right; + position: relative; + z-index: 10; } + .settings-tab-section-card.pull-right img.settings-image { + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5); + border: 1px solid #979797; + margin-top: 12px; } + .settings-tab-section-card.pull-right h4, .settings-tab-section-card.pull-right h3 { + margin-top: 0; } + .settings-tab-section .field-row-cloudinary_url, .settings-tab-section .field-row-signup { + display: block; } + .settings-tab-section .field-row-cloudinary_url td, .settings-tab-section .field-row-cloudinary_url th, .settings-tab-section .field-row-signup td, .settings-tab-section .field-row-signup th { + display: block; + width: auto; + padding: 10px 0 0; } + .settings-tab-section .field-row-cloudinary_url td .sign-up, .settings-tab-section .field-row-cloudinary_url th .sign-up, .settings-tab-section .field-row-signup td .sign-up, .settings-tab-section .field-row-signup th .sign-up { + vertical-align: baseline; } + .settings-tab-section.connect .form-table { + display: inline-block; + width: auto; + max-width: 580px; } + +.settings-valid { + color: #558b2f; + font-size: 30px; } + .settings-valid-field { + border-color: #558b2f !important; } + +.settings-invalid-field { + border-color: #dd2c00 !important; } + +.sync .spinner { + display: inline-block; + visibility: visible; + float: none; + margin: 0 5px 0 0; } + +.sync-media { + display: none; } + .sync-media-progress { + display: none; } + .sync-media-progress-outer { + height: 20px; + margin: 20px 0 10px; + width: 500px; + background-color: #e5e5e5; + position: relative; } + .sync-media-progress-outer .progress-bar { + width: 0; + height: 20px; + background-color: #558b2f; + transition: width 250ms; } + .sync-media-progress-notice { + color: #dd2c00; } + .sync-media-resource { + width: 100px; + display: inline-block; } + .sync-media-error { + color: #dd2c00; } + +.sync-count { + font-weight: bold; } + +.sync-details { + margin-top: 10px; } + +.sync .button.stop-sync, .sync .button.start-sync { + display: none; + padding: 0 16px; } + .sync .button.stop-sync .dashicons, .sync .button.start-sync .dashicons { + line-height: 2.2em; } + +.sync .progress-text { + padding: 12px 4px 12px 12px; + display: inline-block; + font-weight: bold; } + +.sync .completed { + max-width: 300px; + display: none; } + +.cloudinary-widget { + height: 100%; } + .cloudinary-widget-wrapper { + height: 100%; + overflow: hidden; + background-image: url("data:image/svg+xml;base64,PHN2ZyBjbGFzcz0ic3Bpbm5lciIgdmlld0JveD0iLTQgLTQgMTUxIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PCFbQ0RBVEFbCiAgICAgIEBrZXlmcmFtZXMgY29sb3JzIHsKICAgICAgICAwJSB7IHN0cm9rZTogIzAwNzhGRjsgfQogICAgICAgICAgNTAlIHsgc3Ryb2tlOiAjMGUyZjVhOyB9CiAgICAgICAgICAxMDAlIHsgc3Ryb2tlOiAjMDA3OEZGOyB9CiAgICAgIH0KCiAgICAgIEBrZXlmcmFtZXMgZGFzaCB7CiAgICAgICAwJSB7IHN0cm9rZS1kYXNob2Zmc2V0OiA1NjA7IH0KICAgICAgIDUwJSB7CiAgICAgICAgICBzdHJva2UtZGFzaG9mZnNldDogMDsKICAgICAgIH0KICAgICAgIDEwMCUgeyAgIHN0cm9rZS1kYXNob2Zmc2V0OiA1NjA7IH0KICAgICAgfQogICAgICBALXdlYmtpdC1rZXlmcmFtZXMgY29sb3JzIHsKICAgICAgICAwJSB7IHN0cm9rZTogIzAwNzhmZjsgfQogICAgICAgICAgNTAlIHsgc3Ryb2tlOiAjMGUyZjVhOyB9CiAgICAgICAgICAxMDAlIHsgc3Ryb2tlOiAjMDA3OGZmOyB9CiAgICAgIH0KCiAgICAgIEAtd2Via2l0LWtleWZyYW1lcyBkYXNoIHsKICAgICAgIDAlIHsgc3Ryb2tlLWRhc2hvZmZzZXQ6IDU2MDsgfQogICAgICAgNTAlIHsKICAgICAgICAgIHN0cm9rZS1kYXNob2Zmc2V0OiAwOwogICAgICAgfQogICAgICAgMTAwJSB7ICAgc3Ryb2tlLWRhc2hvZmZzZXQ6IDU2MDsKICAgICAgIH0KICAgICAgfQogICAgICAucGF0aCB7CiAgICAgICAgc3Ryb2tlLWRhc2hhcnJheTogMjgwOwogICAgICAgIHN0cm9rZS1kYXNob2Zmc2V0OiAwOwogICAgICAgIHRyYW5zZm9ybS1vcmlnaW46IGNlbnRlcjsKICAgICAgICAtd2Via2l0LWFuaW1hdGlvbjoKICAgICAgICAgIGRhc2ggMnMgZWFzZS1pbi1vdXQgaW5maW5pdGUsIGNvbG9ycyA4cyBlYXNlLWluLW91dCBpbmZpbml0ZTsKICAgICAgICBhbmltYXRpb246CiAgICAgICAgICBkYXNoIDJzIGVhc2UtaW4tb3V0IGluZmluaXRlLCBjb2xvcnMgOHMgZWFzZS1pbi1vdXQgaW5maW5pdGU7CiAgICAgIH0KICAgIF1dPjwvc3R5bGU+CiAgPHBhdGggY2xhc3M9InBhdGgiIGQ9Ik0xMjEuNjYzIDkwLjYzOGMtMS43OTYgMC05OS4zMy0uNDk4LTEwMS40NzQtMS40NzhDOC42ODUgODMuODc3IDEuMjUgNzIuMTk2IDEuMjUgNTkuMzk2YzAtMTYuNjU2IDEyLjc5Ny0zMC42MSAyOS4wNTItMzIuMzIzIDcuNDktMTUuNzA2IDIzLjE4Ni0yNS43MDcgNDAuNzE0LTI1LjcwNyAyMC45OCAwIDM5LjIxNSAxNC43NTIgNDMuOTQ1IDM0LjkwNyAxNS4wOS4yNDUgMjcuMjkgMTIuNjMgMjcuMjkgMjcuODIyIDAgMTEuOTY4LTcuNzM4IDIyLjU1LTE5LjI1NiAyNi4zMyIgc3Ryb2tlLXdpZHRoPSI5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPgo8L3N2Zz4K"); + background-repeat: no-repeat; + background-position: center; + background-size: 150px; } + +.attachment-info .edit-attachment { + display: none; } + +.attachment-actions .button.edit-attachment { + display: none; } + +.global-transformations-preview { + position: relative; + max-width: 600px; } + +.global-transformations-spinner { + display: none; } + +.global-transformations-button.button-primary { + display: none; + position: absolute; + z-index: 100; } + +.global-transformations-url { + margin-bottom: 5px; + margin-top: 5px; } + .global-transformations-url-transformation { + max-width: 100px; + overflow: hidden; + text-overflow: ellipsis; + color: #51A3FF; } + .global-transformations-url-file { + color: #f2d864; } + .global-transformations-url-link { + display: block; + padding: 16px; + background-color: #262c35; + text-decoration: none; + color: #fff; + border-radius: 6px; + overflow: hidden; + text-overflow: ellipsis; } + .global-transformations-url-link:hover { + color: #888888; + text-decoration: underline; } + +.cld-tax-order-list-item { + border: 1px solid #efefef; + padding: 4px; + margin: 0 0 -1px; + background-color: #ffffff; } + .cld-tax-order-list-item.no-items { + color: #888; + text-align: center; + display: none; } + .cld-tax-order-list-item.no-items:last-child { + display: block; } + .cld-tax-order-list-item.ui-sortable-helper { + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); } + .cld-tax-order-list-item-placeholder { + background-color: #efefef; + height: 45px; + margin: 0; } + .cld-tax-order-list-item-handle { + cursor: grab; + margin-right: 4px; + color: #999; } + +.cld-tax-order-list-type { + width: 45%; + display: inline-block; + margin-right: 8px; } + .cld-tax-order-list-type input { + margin-right: 4px !important; } + +.cloudinary-media-library { + position: relative; + margin-left: -20px; } + @media screen and (max-width: 782px) { + .cloudinary-media-library { + margin-left: -10px; } } + diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/block-editor.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/block-editor.js index 38488de8c..f3bce37b8 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/block-editor.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/block-editor.js @@ -1 +1,352 @@ -!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=6)}([function(t,e){!function(){t.exports=this.wp.element}()},function(t,e){!function(){t.exports=this.wp.i18n}()},function(t,e){!function(){t.exports=this.wp.components}()},function(t,e,r){var n=r(5);t.exports=function(t){for(var e=1;e=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./js/src/main.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./css/src/main.scss": +/*!***************************!*\ + !*** ./css/src/main.scss ***! + \***************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack:///./css/src/main.scss?"); + +/***/ }), + +/***/ "./js/src/components/global-transformations.js": +/*!*****************************************************!*\ + !*** ./js/src/components/global-transformations.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* global window wp */\nconst Global_Transformations = {\n\tsample: {\n\t\timage: document.getElementById( 'transformation-sample-image' ),\n\t\tvideo: document.getElementById( 'transformation-sample-video' ),\n\t},\n\tpreview: {\n\t\timage: document.getElementById( 'sample-image' ),\n\t\tvideo: document.getElementById( 'sample-video' ),\n\t},\n\tfields: document.getElementsByClassName( 'cld-field' ),\n\tbutton: {\n\t\timage: document.getElementById( 'refresh-image-preview' ),\n\t\tvideo: document.getElementById( 'refresh-video-preview' ),\n\t},\n\tspinner: {\n\t\timage : document.getElementById( 'image-loader' ),\n\t\tvideo : document.getElementById( 'video-loader' ),\n\t},\n\tactiveItem: null,\n\telements: {\n\t\timage: [],\n\t\tvideo: [],\n\t},\n\t_placeItem: function( item ) {\n\t\tif ( null !== item ) {\n\t\t\titem.style.display = 'block';\n\t\t\titem.style.visibility = 'visible';\n\t\t\titem.style.position = 'absolute';\n\t\t\titem.style.top = (item.parentElement.clientHeight / 2) - (item.clientHeight / 2) + 'px';\n\t\t\titem.style.left = (item.parentElement.clientWidth / 2) - (item.clientWidth / 2) + 'px';\n\t\t}\n\t},\n\t_setLoading: function( type ) {\n\t\tthis.button[ type ].style.display = 'block';\n\t\tthis._placeItem( this.button[ type ] );\n\t\tthis.preview[ type ].style.opacity = '0.1';\n\n\t\t},\n\t_build: function( type ) {\n\t\tthis.sample[ type ].innerHTML = '';\n\t\tthis.elements[ type ] = [];\n\t\tfor (let item of this.fields) {\n\t\t\tif( type !== item.dataset.context ){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet value = item.value.trim();\n\t\t\tif ( value.length ) {\n\n\t\t\t\tif ( 'select-one' === item.type ) {\n\t\t\t\t\tif ( 'none' === value ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tvalue = item.dataset.meta + '_' + value;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet type = item.dataset.context;\n\t\t\t\t\tvalue = this._transformations( value, type, true );\n\t\t\t\t}\n\t\t\t\t// Apply value if valid.\n\t\t\t\tif( value ) {\n\t\t\t\t\tthis.elements[ type ].push( value );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlet transformations = '';\n\t\tif ( this.elements[ type ].length ) {\n\t\t\ttransformations = '/' + this.elements[ type ].join( ',' ).replace( / /g, '%20' );\n\t\t}\n\t\tthis.sample[ type ].textContent = transformations;\n\t\tthis.sample[ type ].parentElement.href = 'https://res.cloudinary.com/demo/' + this.sample[ type ].parentElement.innerText.trim().replace('../', '').replace( / /g, '%20' );\n\t},\n\t_clearLoading: function( type ) {\n\t\tthis.spinner[ type ].style.visibility = 'hidden';\n\t\tthis.activeItem = null;\n\t\tthis.preview[ type ].style.opacity = 1;\n\t},\n\t_refresh: function( e, type ) {\n\t\tif( e ) {\n\t\t\te.preventDefault();\n\t\t}\n\t\tlet self = this;\n\t\tlet new_src = CLD_GLOBAL_TRANSFORMATIONS[ type ].preview_url + self.elements[ type ].join( ',' ) + CLD_GLOBAL_TRANSFORMATIONS[ type ].file;\n\t\tthis.button[ type ].style.display = 'none';\n\t\tthis._placeItem( this.spinner[ type ] );\n\t\tif ( type === 'image' ) {\n\t\t\tlet newImg = new Image;\n\t\t\tnewImg.onload = function() {\n\t\t\t\tself.preview[ type ].src = this.src;\n\t\t\t\tself._clearLoading( type );\n\t\t\t\tnewImg.remove();\n\t\t\t};\n\t\t\tnewImg.onerror = function() {\n\t\t\t\talert( CLD_GLOBAL_TRANSFORMATIONS[type].error );\n\t\t\t\tself._clearLoading( type );\n\t\t\t};\n\t\t\tnewImg.src = new_src;\n\t\t}else{\n\t\t\tlet transformations = self._transformations( self.elements[ type ].join( ',' ), type );\n\t\t\tsamplePlayer.source( { publicId: 'dog', transformation: transformations } );\n\t\t\tself._clearLoading( type );\n\t\t}\n\t},\n\t_transformations : function( input, type, string = false ){\n\t\tlet set = CLD_GLOBAL_TRANSFORMATIONS[ type ].valid_types;\n\t\tlet value = null;\n\t\tlet elements = input.split( '/' );\n\t\tlet valid_elements = [];\n\t\tfor (let i = 0; i < elements.length; i++) {\n\t\t\tlet parts = elements[ i ].split(',');\n\t\t\tlet valid_parts;\n\t\t\tif( true === string ) {\n\t\t\t\tvalid_parts = [];\n\t\t\t}else{\n\t\t\t\tvalid_parts = {};\n\t\t\t}\n\t\t\tfor (let p = 0; p < parts.length; p++) {\n\t\t\t\tlet key_val = parts[ p ].trim().split('_');\n\t\t\t\tif( key_val.length <= 1 || typeof set[ key_val[0] ] === 'undefined' ){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlet option = key_val.shift();\n\t\t\t\tlet instruct = key_val.join( '_' );\n\t\t\t\tif( true === string ) {\n\t\t\t\t\tif( 'f' === option || 'q' === option ){\n\t\t\t\t\t\tfor( let t in this.elements[ type ] ){\n\t\t\t\t\t\t\tif( option + '_' === this.elements[ type ][ t ].substr(0,2 ) ){\n\t\t\t\t\t\t\t\tthis.elements[ type ].splice(t,1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tvalid_parts.push( parts[ p ] );\n\t\t\t\t}else{\n\t\t\t\t\tvalid_parts[ set[ option ] ] = instruct.trim();\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet length = 0;\n\t\t\tif( true === string ) {\n\t\t\t\tlength = valid_parts.length;\n\t\t\t}else{\n\t\t\t\tlength = Object.keys( valid_parts ).length;\n\t\t\t}\n\t\t\tif ( length ) {\n\t\t\t\tif( true === string ) {\n\t\t\t\t\tvalid_parts = valid_parts.join( ',' );\n\t\t\t\t}\n\t\t\t\tvalid_elements.push( valid_parts );\n\t\t\t}\n\t\t}\n\n\t\tif ( valid_elements.length ) {\n\t\t\tif( true === string ) {\n\t\t\t\tvalue = valid_elements.join( '/' ).trim();\n\t\t\t}else{\n\t\t\t\tvalue = valid_elements;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t},\n\t_reset: function() {\n\t\tfor (let item of this.fields) {\n\t\t\titem.value = null;\n\t\t}\n\t\tfor( let type in this.button ) {\n\t\t\tthis._build( type );\n\t\t\tthis._refresh( null, type );\n\t\t}\n\t},\n\t_input: function( input ){\n\t\tif( typeof input.dataset.context !== 'undefined' && input.dataset.context.length ) {\n\t\t\tlet type = input.dataset.context;\n\t\t\tthis._setLoading( type );\n\t\t\tthis._build( type );\n\t\t}\n\t},\n\t_init: function() {\n\n\t\tif ( typeof CLD_GLOBAL_TRANSFORMATIONS !== 'undefined' ) {\n\t\t\tlet self = this;\n\n\t\t\tdocument.addEventListener( 'DOMContentLoaded', function( ev ) {\n\t\t\t\tfor( let type in self.button ) {\n\t\t\t\t\tif( self.button[ type ] ) {\n\t\t\t\t\t\tself.button[ type ].addEventListener( 'click', function( e ) {\n\t\t\t\t\t\t\tself._refresh( e, type );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (let item of self.fields) {\n\t\t\t\t\titem.addEventListener( 'input', function(){\n\t\t\t\t\t\tself._input( this );\n\t\t\t\t\t} );\n\t\t\t\t\titem.addEventListener( 'change', function() {\n\t\t\t\t\t\tself._input( this );\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\t// Init.\n\t\t\t\tfor( let type in CLD_GLOBAL_TRANSFORMATIONS ) {\n\t\t\t\t\tself._build( type );\n\t\t\t\t\tself._refresh( null, type );\n\t\t\t\t}\n\t\t\t} );\n\t\t\t// listen to AJAX add-tag complete\n\t\t\tjQuery(document).ajaxComplete(function(event, xhr, settings) {\n\n\t\t\t\t// bail early if is other ajax call\n\t\t\t\tif( settings.data.indexOf('action=add-tag') === -1 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// bail early if response contains error\n\t\t\t\tif( xhr.responseText.indexOf('wp_error') !== -1 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tself._reset();\n\t\t\t});\n\t\t}\n\t},\n};\n\n// Init.\nGlobal_Transformations._init();\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Global_Transformations);\n\n\n//# sourceURL=webpack:///./js/src/components/global-transformations.js?"); + +/***/ }), + +/***/ "./js/src/components/media-library.js": +/*!********************************************!*\ + !*** ./js/src/components/media-library.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* global window wp */\nconst Media_Library = {\n\twpWrap: document.getElementById( 'wpwrap' ),\n\twpContent: document.getElementById( 'wpbody-content' ),\n\tlibraryWrap: document.getElementById( 'cloudinary-embed' ),\n\t_init: function() {\n\t\tlet self = this;\n\t\tif ( typeof CLD_ML !== 'undefined' ) {\n\n\t\t\tcloudinary.openMediaLibrary( CLD_ML.mloptions, {\n\t\t\t\t\tinsertHandler: function( data ) {\n\t\t\t\t\t\t// @todo: Determin what to do here.\n\t\t\t\t\t\talert( 'Import is not yet implemented.' );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\n\t\t\twindow.addEventListener( 'resize', function( ev ) {\n\t\t\t\tself._resize();\n\t\t\t} );\n\n\t\t\tself._resize();\n\t\t}\n\t},\n\t_resize: function() {\n\t\tlet style = getComputedStyle( this.wpContent );\n\t\tthis.libraryWrap.style.height = (this.wpWrap.offsetHeight - parseInt( style.getPropertyValue( 'padding-bottom' ) )) + 'px';\n\t},\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Media_Library);\n\n// Init.\nMedia_Library._init();\n\n\n//# sourceURL=webpack:///./js/src/components/media-library.js?"); + +/***/ }), + +/***/ "./js/src/components/settings-page.js": +/*!********************************************!*\ + !*** ./js/src/components/settings-page.js ***! + \********************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +eval("(function() {\n\n\tjQuery( document ).ready( function( $ ) {\n\n\t\t// Initilize instance events\n\t\t$( document ).on( 'tabs.init', function() {\n\n\t\t\tvar tabs = $( '.settings-tab-trigger' ),\n\t\t\t sections = $( '.settings-tab-section' );\n\n\t\t\t// Create instance bindings\n\t\t\t$( this ).on( 'click', '.settings-tab-trigger', function( e ) {\n\t\t\t\tvar clicked = $( this ),\n\t\t\t\t target = $( clicked.attr( 'href' ) );\n\n\t\t\t\t// Trigger an instance action.\n\t\t\t\te.preventDefault();\n\n\t\t\t\ttabs.removeClass( 'active' );\n\t\t\t\tsections.removeClass( 'active' );\n\n\t\t\t\tclicked.addClass( 'active' );\n\t\t\t\ttarget.addClass( 'active' );\n\n\t\t\t\t// Trigger the tabbed event.\n\t\t\t\t$( document ).trigger( 'settings.tabbed', clicked );\n\n\t\t\t} );\n\n\t\t\t// Bind conditions.\n\t\t\t$( '.cld-field' ).not( '[data-condition=\"false\"]' ).each( function() {\n\t\t\t\tconst field = $(this);\n\t\t\t\tconst condition = field.data('condition');\n\t\t\t\tfor (let f in condition) {\n\t\t\t\t\tconst value = condition[ f ];\n\t\t\t\t\tconst target = $( '#field-' + f );\n\t\t\t\t\tconst wrapper = field.closest('tr');\n\t\t\t\t\ttarget.on('change init', function(){\n\t\t\t\t\t\tif( this.value === value || this.checked ){\n\t\t\t\t\t\t\twrapper.show();\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\twrapper.hide();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\ttarget.trigger('init');\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t$('#field-cloudinary_url').on('input change', function(){\n\t\t\t\tlet field = $(this),\n\t\t\t\t\tvalue = field.val();\n\n\t\t\t\tlet reg = new RegExp(/^(cloudinary:\\/\\/){1}(\\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g );\n\t\t\t\tif( reg.test( value ) ){\n\t\t\t\t\tfield.addClass( 'settings-valid-field' );\n\t\t\t\t\tfield.removeClass( 'settings-invalid-field' );\n\t\t\t\t}else{\n\t\t\t\t\tfield.removeClass( 'settings-valid-field' );\n\t\t\t\t\tfield.addClass( 'settings-invalid-field' );\n\t\t\t\t}\n\t\t\t}).trigger('change' );\n\n\n\t\t} );\n\n\t\t// On Ready, find all render trigger elements and fire their events.\n\t\t$( '.render-trigger[data-event]' ).each( function() {\n\t\t\tvar trigger = $( this ),\n\t\t\t event = trigger.data( 'event' );\n\t\t\ttrigger.trigger( event, this );\n\t\t} );\n\t} );\n\n})( window, jQuery );\n\n\n//# sourceURL=webpack:///./js/src/components/settings-page.js?"); + +/***/ }), + +/***/ "./js/src/components/sync.js": +/*!***********************************!*\ + !*** ./js/src/components/sync.js ***! + \***********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* global window wp */\n\nconst Sync = {\n\tprogress: document.getElementById( 'progress-wrapper' ),\n\tsubmitButton: document.getElementById( 'submit' ),\n\tstopButton: document.getElementById( 'stop-sync' ),\n\tprogressCount: document.getElementById( 'sync-progress' ),\n\tbarSyncCount: document.getElementById( 'sync-total' ),\n\tcompleted: document.getElementById( 'completed-notice' ),\n\tshow: 'inline-block',\n\thide: 'none',\n\tgetStatus: function getStatus() {\n\t\tvar self = this,\n\t\t\tresourceType = [],\n\t\t\turl = cloudinaryApi.restUrl + 'cloudinary/v1/attachments',\n\t\t\tparams;\n\n\t\twp.ajax.send( {\n\t\t\turl: url,\n\t\t\ttype: 'GET',\n\t\t\tbeforeSend: function( request ) {\n\t\t\t\trequest.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce );\n\t\t\t},\n\t\t} ).done( function( data ) {\n\t\t\tif ( data.done < data.total ) {\n\t\t\t\tsetTimeout( Sync.getStatus, 2000 );\n\t\t\t}\n\t\t\tSync._updateUI( data );\n\t\t} );\n\t},\n\tstopSync: function stopSync() {\n\t\tvar self = this,\n\t\t\turl = cloudinaryApi.restUrl + 'cloudinary/v1/sync';\n\n\t\twp.ajax.send( {\n\t\t\turl: url,\n\t\t\tdata: {\n\t\t\t\tstop: true,\n\t\t\t},\n\t\t\tbeforeSend: function( request ) {\n\t\t\t\trequest.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce );\n\t\t\t},\n\t\t} ).done( function( data ) {\n\t\t\tSync._updateUI( data );\n\t\t} );\n\t},\n\tpushAttachments: function pushAttachments() {\n\t\tvar self = this,\n\t\t\turl = cloudinaryApi.restUrl + 'cloudinary/v1/sync';\n\n\t\twp.ajax.send( {\n\t\t\turl: url,\n\t\t\tbeforeSend: function( request ) {\n\t\t\t\trequest.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce );\n\t\t\t},\n\t\t} );\n\t},\n\t_updateUI: function _updateUI( data ) {\n\t\tif ( data.percent < 100 && typeof data.started !== 'undefined' ) {\n\t\t\tthis.submitButton.style.display = this.hide;\n\t\t\tthis.stopButton.style.display = this.show;\n\t\t}\n\t\telse if ( data.percent >= 100 && typeof data.started !== 'undefined' ) {\n\t\t\tthis.submitButton.style.display = this.hide;\n\t\t\tthis.stopButton.style.display = this.show;\n\t\t}\n\t\telse if ( data.pending > 0 ) {\n\t\t\tthis.submitButton.style.display = this.show;\n\t\t\tthis.stopButton.style.display = this.hide;\n\t\t}\n\t\telse if ( data.processing > 0 ) {\n\t\t\tthis.stopButton.style.display = this.show;\n\t\t}\n\t\telse {\n\t\t\tthis.stopButton.style.display = this.hide;\n\t\t}\n\n\t\tif ( data.percent < 100 ) {\n\t\t\tthis.barSyncCount.innerText = data.total;\n\t\t\tthis.progressCount.innerText = data.done;\n\t\t\tthis.progress.style.display = this.show;\n\t\t}\n\t\telse {\n\t\t\tthis.completed.style.display = this.show;\n\t\t\tthis.progress.style.display = this.hide;\n\t\t}\n\t},\n\t_start: function _start( e ) {\n\t\te.preventDefault();\n\t\tSync.stopButton.style.display = Sync.show;\n\t\tSync.submitButton.style.display = Sync.hide;\n\t\tSync.pushAttachments();\n\t},\n\t_reset: function _reset( e ) {\n\t\tSync.submitButton.style.display = Sync.hide;\n\t\tSync.getStatus();\n\t},\n\t_init: function( fn ) {\n\n\t\tif ( typeof cloudinaryApi !== 'undefined' ) {\n\t\t\tif ( document.attachEvent ? document.readyState === 'complete' : document.readyState !== 'loading' ) {\n\t\t\t\tfn();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdocument.addEventListener( 'DOMContentLoaded', fn );\n\t\t\t}\n\t\t}\n\t},\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Sync);\n\n// Init.\nSync._init( function() {\n\tSync._reset();\n\tSync.submitButton.addEventListener( 'click', Sync._start );\n\tSync.stopButton.addEventListener( 'click', Sync.stopSync );\n} );\n\n\n//# sourceURL=webpack:///./js/src/components/sync.js?"); + +/***/ }), + +/***/ "./js/src/components/terms_order.js": +/*!******************************************!*\ + !*** ./js/src/components/terms_order.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* global window wp wpAjax */\n\nconst Terms_Order = {\n template: '',\n tags: jQuery( '#cld-tax-items' ),\n tagDelimiter: ( window.tagsSuggestL10n && window.tagsSuggestL10n.tagDelimiter ) || ',',\n startId: null,\n _init: function() {\n // Check that we found the tax-items.\n if ( !this.tags.length ) {\n return;\n }\n\n const self = this;\n this._sortable();\n\n // Setup ajax overrides.\n if ( typeof wpAjax !== 'undefined' ) {\n wpAjax.procesParseAjaxResponse = wpAjax.parseAjaxResponse;\n wpAjax.parseAjaxResponse = function( response, settingsResponse, element ) {\n let newResponse = wpAjax.procesParseAjaxResponse( response, settingsResponse, element );\n if ( !newResponse.errors && newResponse.responses[ 0 ] ) {\n if ( jQuery( '[data-taxonomy=\"' + newResponse.responses[ 0 ].what + '\"]' ).length ) {\n const data = jQuery( newResponse.responses[ 0 ].data );\n const text = data.find( 'label' ).last().text().trim();\n self._pushItem( newResponse.responses[ 0 ].what, text );\n }\n }\n\n return newResponse;\n };\n }\n\n if ( typeof window.tagBox !== 'undefined' ) {\n window.tagBox.processflushTags = window.tagBox.flushTags;\n window.tagBox.flushTags = function( el, a, f ) {\n if ( typeof f === 'undefined' ) {\n let text, list;\n const taxonomy = el.prop( 'id' );\n const newTag = jQuery( 'input.newtag', el );\n\n a = a || false;\n\n text = a ? jQuery( a ).text() : newTag.val();\n list = window.tagBox.clean( text ).split( self.tagDelimiter );\n for ( var i in list ) {\n var tag = taxonomy + ':' + list[ i ];\n if ( !jQuery( '[data-item=\"' + tag + '\"]' ).length ) {\n self._pushItem( tag, list[ i ] );\n }\n }\n }\n\n return this.processflushTags( el, a, f );\n };\n\n window.tagBox.processTags = window.tagBox.parseTags;\n\n window.tagBox.parseTags = function( el ) {\n const id = el.id;\n const num = id.split( '-check-num-' )[ 1 ];\n const taxonomy = id.split( '-check-num-' )[ 0 ];\n const taxBox = jQuery( el ).closest( '.tagsdiv' );\n const tagsTextarea = taxBox.find( '.the-tags' );\n const tagToRemove = window.tagBox.clean( tagsTextarea.val() ).split( self.tagDelimiter )[ num ];\n\n new wp.api.collections.Tags()\n .fetch( { data: { slug: tagToRemove } } )\n .done( ( tag ) => {\n const tagFromDatabase = tag.length ? jQuery( '[data-item=\"' + taxonomy + ':' + tag[ 0 ].id + '\"]' ) : false;\n\n if ( tagFromDatabase.length ) {\n tagFromDatabase.remove();\n }\n else {\n jQuery( `.cld-tax-order-list-item:contains(${ tagToRemove })` ).remove();\n --self.startId;\n }\n this.processTags( el );\n } );\n };\n }\n\n jQuery( 'body' ).on( 'change', '.selectit input', function() {\n const clickedItem = jQuery( this );\n const id = clickedItem.val();\n const checked = clickedItem.is( ':checked' );\n const text = clickedItem.parent().text().trim();\n\n if ( true === checked ) {\n if( ! self.tags.find(`[data-item=\"category:${ id }\"]`).length ) {\n self._pushItem( `category:${ id }`, text );\n }\n }\n else {\n self.tags.find( `[data-item=\"category:${ id }\"]` ).remove();\n }\n } );\n },\n _createItem: function( id, name ) {\n const li = jQuery( '
  • ' );\n const icon = jQuery( '' );\n const input = jQuery( '' );\n\n li.addClass( 'cld-tax-order-list-item' ).attr( 'data-item', id );\n input.addClass( 'cld-tax-order-list-item-input' ).attr( 'type', 'hidden' ).attr( 'name', 'cld_tax_order[]' ).val( id );\n icon.addClass( 'dashicons dashicons-menu cld-tax-order-list-item-handle' );\n\n li.append( icon ).append( name ).append( input ); // phpcs:ignore\n // WordPressVIPMinimum.JS.HTMLExecutingFunctions.append\n\n return li;\n },\n _pushItem: function( id, text ) {\n let item = this._createItem( id, text );\n this.tags.append( item ); // phpcs:ignore\n // WordPressVIPMinimum.JS.HTMLExecutingFunctions.append\n },\n _sortable: function() {\n const items = jQuery( '.cld-tax-order-list' );\n\n items.sortable( {\n connectWith: '.cld-tax-order',\n axis: 'y',\n handle: '.cld-tax-order-list-item-handle',\n placeholder: 'cld-tax-order-list-item-placeholder',\n forcePlaceholderSize: true,\n helper: 'clone',\n } );\n }\n};\n\nif ( typeof window.CLDN !== 'undefined' ) {\n Terms_Order._init();\n // Init checked categories.\n jQuery( '[data-wp-lists] .selectit input[checked]' ).map( ( ord, check ) => {\n jQuery( check ).trigger( 'change' );\n } );\n}\n\n// Gutenberg.\nif ( wp.data && wp.data.select( 'core/editor' ) ) {\n const orderSet = {};\n wp.data.subscribe( function() {\n let taxonomies = wp.data.select( 'core' ).getTaxonomies();\n\n if ( taxonomies ) {\n for ( let t in taxonomies ) {\n const set = wp.data.select( 'core/editor' ).getEditedPostAttribute( taxonomies[ t ].rest_base );\n orderSet[ taxonomies[ t ].slug ] = set;\n }\n }\n } );\n\n const el = wp.element.createElement;\n const CustomizeTaxonomySelector = ( OriginalComponent ) => {\n class CustomHandler extends OriginalComponent {\n constructor( props ) {\n super( props );\n\n this.currentItems = jQuery( '.cld-tax-order-list-item' )\n .map( ( _, taxonomy ) => jQuery( taxonomy ).data( 'item' ) ).get();\n }\n\n makeItem( item ) {\n // Prevent duplicates in the tax order box\n if ( this.currentItems.includes( this.getId( item ) ) ) {\n return;\n }\n\n const row = this.makeElement( item );\n const box = jQuery( '#cld-tax-items' );\n box.append( row ); // phpcs:ignore\n // WordPressVIPMinimum.JS.HTMLExecutingFunctions.append\n }\n\n removeItem( item ) {\n const elementWithId = jQuery( `[data-item=\"${ this.getId( item ) }\"]` );\n\n if ( elementWithId.length ) {\n elementWithId.remove();\n\n this.currentItems = this.currentItems.filter( ( taxIdentifier ) => {\n return taxIdentifier !== this.getId( item );\n } );\n }\n }\n\n findOrCreateTerm( termName ) {\n termName = super.findOrCreateTerm( termName );\n termName.then( ( item ) => this.makeItem( item ) );\n\n return termName;\n }\n\n onChange( event ) {\n super.onChange( event );\n const item = this.pickItem( event );\n\n if ( item ) {\n if ( orderSet[ this.props.slug ].includes( item.id ) ) {\n this.makeItem( item );\n }\n else {\n this.removeItem( item );\n }\n }\n }\n\n pickItem( event ) {\n if ( typeof event === 'object' ) {\n if ( event.target ) {\n for ( let p in this.state.availableTerms ) {\n if ( this.state.availableTerms[ p ].id === parseInt( event.target.value ) ) {\n return this.state.availableTerms[ p ];\n }\n }\n // Tags that are already registered need to be selected\n // separately as its expected that they return back\n // with an \"id\" property.\n }\n else if ( Array.isArray( event ) ) {\n // Figure out the diff between the current state and\n // the event and determine which tag is getting removed\n let enteredTag = this.state.selectedTerms.filter( flatItem => !event.includes( flatItem ) )[ 0 ];\n\n if ( typeof enteredTag === 'undefined' ) {\n // If the above returns undefined, then we presume\n // the user is adding, so reverse the logic to\n // figure out the new item\n enteredTag = event.filter( flatItem => !this.state.selectedTerms.includes( flatItem ) )[ 0 ];\n }\n\n return this.state.availableTerms.find( ( item ) => item.name === enteredTag );\n }\n }\n else if ( typeof event === 'number' ) {\n for ( let p in this.state.availableTerms ) {\n if ( this.state.availableTerms[ p ].id === event ) {\n return this.state.availableTerms[ p ];\n }\n }\n }\n else {\n let text;\n\n // add or remove.\n if ( event.length > this.state.selectedTerms.length ) {\n // Added.\n for ( let o in event ) {\n if ( this.state.selectedTerms.indexOf( event[ o ] ) === -1 ) {\n text = event[ o ];\n }\n }\n }\n else {\n // removed.\n for ( let o in this.state.selectedTerms ) {\n if ( event.indexOf( this.state.selectedTerms[ o ] ) === -1 ) {\n text = this.state.selectedTerms[ o ];\n }\n }\n }\n\n for ( let p in this.state.availableTerms ) {\n if ( this.state.availableTerms[ p ].name === text ) {\n return this.state.availableTerms[ p ];\n }\n }\n }\n }\n\n getId( item ) {\n return `${ this.props.slug }:${ item.id }`;\n }\n\n makeElement( item ) {\n const li = jQuery( '
  • ' );\n const icon = jQuery( '' );\n const input = jQuery( '' );\n\n li\n .addClass( 'cld-tax-order-list-item' )\n .attr( 'data-item', this.getId( item ) );\n\n input\n .addClass( 'cld-tax-order-list-item-input' )\n .attr( 'type', 'hidden' )\n .attr( 'name', 'cld_tax_order[]' ).val( this.getId( item ) );\n\n icon.addClass( 'dashicons dashicons-menu cld-tax-order-list-item-handle' );\n\n li.append( icon ).append( item.name ).append( input ); // phpcs:ignore\n // WordPressVIPMinimum.JS.HTMLExecutingFunctions.append\n\n return li;\n }\n }\n\n return ( props ) => el( CustomHandler, props );\n };\n\n wp.hooks.addFilter(\n 'editor.PostTaxonomyType',\n 'cld',\n CustomizeTaxonomySelector\n );\n}\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Terms_Order);\n\n\n//# sourceURL=webpack:///./js/src/components/terms_order.js?"); + +/***/ }), + +/***/ "./js/src/components/widget.js": +/*!*************************************!*\ + !*** ./js/src/components/widget.js ***! + \*************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +eval("/* global window wp Backbone */\nif ( wp.media && window.CLDN ) {\n\n\twp.media.events.on( 'editor:image-edit', function( props ){\n\t\tprops.metadata.cldoverwrite = null;\n\t\tlet classes = props.image.className.split( ' ' );\n\t\tif( classes.indexOf('cld-overwrite' ) >= 0 ){\n\t\t\tprops.metadata.cldoverwrite = 'true';\n\t\t}\n\t} );\n\twp.media.events.on( 'editor:image-update', function( props ){\n\t\tlet classes = props.image.className.split( ' ' );\n\t\tif( props.metadata.cldoverwrite && classes.indexOf('cld-overwrite' ) === -1 ) {\n\t\t\tclasses.push( 'cld-overwrite' );\n\t\t} else if( ! props.metadata.cldoverwrite && classes.indexOf('cld-overwrite' ) >= 0 ) {\n\t\t\tdelete classes[ classes.indexOf('cld-overwrite' ) ];\n\t\t}\n\n\t\tprops.image.className = classes.join( ' ' );\n\t} );\n\n\t// Intercept props and inject cld-overwrite class.\n\tlet currentOverwrite = null;\n\tlet imageProps = wp.media.string.props;\n\twp.media.string.props = function( props, asset ){\n\t\tif( props.cldoverwrite ){\n\t\t\tprops.classes = [ 'cld-overwrite' ];\n\t\t\tcurrentOverwrite = true;\n\t\t}\n\t\tlet newProps = imageProps( props, asset );\n\t\treturn newProps;\n\t}\n\t// Intercept ajax post, and send the cld-overwrite flag, and transformations.\n\twp.media.post = function( action, data ) {\n\n\t\tif ( 'send-attachment-to-editor' === action ) {\n\t\t\tlet state = wp.media.editor.get().state();\n\t\t\tlet attach = state.get( 'selection' ).get( data.attachment );\n\t\t\tif ( attach.attributes.transformations ) {\n\t\t\t\tdata.attachment.transformations = attach.attributes.transformations;\n\t\t\t}\n\t\t\tif( data.html.indexOf('cld-overwrite') > -1 || true === currentOverwrite ){\n\t\t\t\tdata.attachment.cldoverwrite = true;\n\t\t\t\tcurrentOverwrite = null;\n\t\t\t}\n\n\t\t}\n\t\t// Return the original.\n\t\treturn wp.ajax.post( action, data );\n\t};\n\n\tlet Library = wp.media.controller.Library;\n\tlet MediaFrame = wp.media.view.MediaFrame.Select;\n\tlet MediaFramePost = wp.media.view.MediaFrame.Post;\n\tlet MediaFrameImageDetails = wp.media.view.MediaFrame.ImageDetails;\n\tlet MediaFrameVideoDetails = wp.media.view.MediaFrame.VideoDetails;\n\tlet Cloudinary = wp.media.View.extend( {\n\t\ttagName: 'div',\n\t\tclassName: 'cloudinary-widget',\n\t\ttemplate: wp.template( 'cloudinary-dam' ),\n\t\tactive: false,\n\t\ttoolbar: null,\n\t\tframe: null,\n\t\tready: function() {\n\t\t\tlet controller = this.controller;\n\t\t\tlet selection = this.model.get( 'selection' );\n\t\t\tlet library = this.model.get( 'library' );\n\t\t\tlet attachment = wp.media.model.Attachment;\n\t\t\t// Set widget to same as model.\n\t\t\tCLDN.mloptions.multiple = controller.options.multiple;\n\t\t\tif ( this.cid !== this.active ) {\n\t\t\t\tCLDN.mloptions.inline_container = '#cloudinary-dam-' + controller.cid;\n\t\t\t\tif ( 1 === selection.length ) {\n\t\t\t\t\tvar att = attachment.get( selection.models[ 0 ].id );\n\t\t\t\t\tif ( typeof att.attributes.public_id !== 'undefined' ) {\n\t\t\t\t\t\tCLDN.mloptions.asset = {resource_id: att.attributes.public_id };\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tCLDN.mloptions.asset = null;\n\t\t\t\t}\n\t\t\t\twindow.ml = cloudinary.openMediaLibrary( CLDN.mloptions, {\n\t\t\t\t\t\tinsertHandler: function( data ) {\n\t\t\t\t\t\t\tfor (let i = 0; i < data.assets.length; i++) {\n\t\t\t\t\t\t\t\tlet temp = data.assets[ i ];\n\t\t\t\t\t\t\t\twp.media.post( 'cloudinary-down-sync', {\n\t\t\t\t\t\t\t\t\tnonce: CLDN.nonce,\n\t\t\t\t\t\t\t\t\tasset: temp,\n\t\t\t\t\t\t\t\t} ).done( function( asset ) {\n\t\t\t\t\t\t\t\t\tlet update_asset = function( asset, attach ){\n\t\t\t\t\t\t\t\t\t\tasset.uploading = false;\n\t\t\t\t\t\t\t\t\t\tattach.set( asset );\n\t\t\t\t\t\t\t\t\t\twp.Uploader.queue.remove( attach );\n\t\t\t\t\t\t\t\t\t\tif ( wp.Uploader.queue.length === 0 ) {\n\t\t\t\t\t\t\t\t\t\t\twp.Uploader.queue.reset();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( typeof asset.fetch !== 'undefined' ) {\n\n\t\t\t\t\t\t\t\t\t\tlet attach = attachment.get( asset.attachment_id );\n\t\t\t\t\t\t\t\t\t\tattach.set( asset );\n\t\t\t\t\t\t\t\t\t\tlibrary.add( attach );\n\t\t\t\t\t\t\t\t\t\twp.Uploader.queue.add( attach );\n\t\t\t\t\t\t\t\t\t\twp.ajax.send( {\n\t\t\t\t\t\t\t\t\t\t\turl: asset.fetch,\n\t\t\t\t\t\t\t\t\t\t\tbeforeSend: function( request ) {\n\t\t\t\t\t\t\t\t\t\t\t\trequest.setRequestHeader( 'X-WP-Nonce', CLDN.nonce );\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\t\tsrc: asset.url,\n\t\t\t\t\t\t\t\t\t\t\t\tfilename: asset.filename,\n\t\t\t\t\t\t\t\t\t\t\t\tattachment_id: asset.attachment_id,\n\t\t\t\t\t\t\t\t\t\t\t\ttransformations: asset.transformations\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} ).done( function( asset ) {\n\t\t\t\t\t\t\t\t\t\t\tlet attach = attachment.get( asset.id );\n\t\t\t\t\t\t\t\t\t\t\tupdate_asset( asset, attach );\n\t\t\t\t\t\t\t\t\t\t} ).fail( function( data ) {\n\t\t\t\t\t\t\t\t\t\t\tupdate_asset( asset, attach );\n\t\t\t\t\t\t\t\t\t\t\tlibrary.remove( attach );\n\t\t\t\t\t\t\t\t\t\t\tselection.remove( attach );\n\n\t\t\t\t\t\t\t\t\t\t\tif( typeof data === 'string' ) {\n\t\t\t\t\t\t\t\t\t\t\t\talert( data );\n\t\t\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\t\t\tif( data.status === 500 ){\n\t\t\t\t\t\t\t\t\t\t\t\t\talert('HTTP error.');\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\n\t\t\t\t\t\t\t\t\t\tlet attach = attachment.get( asset.id );\n\t\t\t\t\t\t\t\t\t\tattach.set( asset );\n\t\t\t\t\t\t\t\t\t\tselection.add( attach );\n\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( wp.Uploader.queue.length === 0 ) {\n\t\t\t\t\t\t\t\t\t\twp.Uploader.queue.reset();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcontroller.content.mode( 'browse' );\n\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tdocument.querySelectorAll( '.dam-cloudinary' )[ 0 ]\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.active = this.cid;\n\t\t\treturn this;\n\t\t},\n\t} );\n\tlet extend_type = function( type ) {\n\t\tlet obj = {\n\n\t\t\t/**\n\t\t\t * Bind region mode event callbacks.\n\t\t\t *\n\t\t\t * @see media.controller.Region.render\n\t\t\t */\n\t\t\tbindHandlers: function() {\n\t\t\t\ttype.prototype.bindHandlers.apply( this, arguments );\n\t\t\t\tthis.on( 'content:render:cloudinary', this.cloudinaryContent, this );\n\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Render callback for the router region in the `browse` mode.\n\t\t\t *\n\t\t\t * @param {wp.media.view.Router} routerView\n\t\t\t */\n\t\t\tbrowseRouter: function( routerView ) {\n\n\t\t\t\ttype.prototype.browseRouter.apply( this, arguments );\n\t\t\t\tlet state_id = this.state().get( 'id' );\n\t\t\t\trouterView.set( {\n\t\t\t\t\tcloudinary: {\n\t\t\t\t\t\ttext: 'Cloudinary',\n\t\t\t\t\t\tpriority: 60\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\t/**\n\t\t\t * Render callback for the content region in the `upload` mode.\n\t\t\t */\n\t\t\tcloudinaryContent: function( contentRegion ) {\n\t\t\t\tlet state = this.state();\n\t\t\t\tlet view = new Cloudinary( {\n\t\t\t\t\tcontroller: this,\n\t\t\t\t\tmodel: state,\n\t\t\t\t} ).render();\n\t\t\t\tthis.content.set( view );\n\t\t\t},\n\t\t};\n\n\t\treturn obj;\n\t};\n\t// Extending the current media library frames to add a new tab to each area.\n\twp.media.view.MediaFrame.Select = MediaFrame.extend( extend_type( MediaFrame ) );\n\twp.media.view.MediaFrame.Post = MediaFramePost.extend( extend_type( MediaFramePost ) );\n\twp.media.view.MediaFrame.ImageDetails = MediaFrameImageDetails.extend( extend_type( MediaFrameImageDetails ) );\n\twp.media.view.MediaFrame.VideoDetails = MediaFrameVideoDetails.extend( extend_type( MediaFrameVideoDetails ) );\n\n}\n\n\n//# sourceURL=webpack:///./js/src/components/widget.js?"); + +/***/ }), + +/***/ "./js/src/main.js": +/*!************************!*\ + !*** ./js/src/main.js ***! + \************************/ +/*! exports provided: cloudinary */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"cloudinary\", function() { return cloudinary; });\n/* harmony import */ var _components_settings_page__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./components/settings-page */ \"./js/src/components/settings-page.js\");\n/* harmony import */ var _components_settings_page__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_components_settings_page__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _components_sync__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/sync */ \"./js/src/components/sync.js\");\n/* harmony import */ var _components_widget__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./components/widget */ \"./js/src/components/widget.js\");\n/* harmony import */ var _components_widget__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_components_widget__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _components_global_transformations__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/global-transformations */ \"./js/src/components/global-transformations.js\");\n/* harmony import */ var _components_terms_order__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./components/terms_order */ \"./js/src/components/terms_order.js\");\n/* harmony import */ var _components_media_library__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./components/media-library */ \"./js/src/components/media-library.js\");\n/* harmony import */ var _css_src_main_scss__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../css/src/main.scss */ \"./css/src/main.scss\");\n/* harmony import */ var _css_src_main_scss__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_css_src_main_scss__WEBPACK_IMPORTED_MODULE_6__);\n/* global window */\n/**\n * Main JS.\n */\n\n// Components\n\n\n\n\n\n\n\n\n\n// jQuery, because reasons.\nconst $ = window.$ = window.jQuery;\n\n// Global Constants\nconst cloudinary = {\n\tsettings: (_components_settings_page__WEBPACK_IMPORTED_MODULE_0___default()),\n\tsync: _components_sync__WEBPACK_IMPORTED_MODULE_1__[\"default\"],\n\twidget: (_components_widget__WEBPACK_IMPORTED_MODULE_2___default()),\n\tGlobal_Transformations: _components_global_transformations__WEBPACK_IMPORTED_MODULE_3__[\"default\"],\n\tTerms_Order: _components_terms_order__WEBPACK_IMPORTED_MODULE_4__[\"default\"],\n\tMedia_Library: _components_media_library__WEBPACK_IMPORTED_MODULE_5__[\"default\"],\n};\n\n\n\n//# sourceURL=webpack:///./js/src/main.js?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index 3091d085a..6d9f94add 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -385,10 +385,12 @@ public function print_video_scripts() { videoElement.style.width = '100%'; config['video_freeform'] ): ?> - videoElement.src = videoElement.src.replace( - 'upload/', - 'upload/config['video_freeform'] ) ?>/' - ); + if ( videoElement.src.indexOf( 'config['video_freeform'] ) ?>' ) === -1 ) { + videoElement.src = videoElement.src.replace( + 'upload/', + 'upload/config['video_freeform'] ) ?>/' + ); + } } } From 2359228bb21754154f4fb9884bd1cdb304cbc3f3 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 15 Apr 2020 12:45:18 +0200 Subject: [PATCH 03/58] Simplify cache rebuild based on version update. --- .../php/class-connect.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 7f2b62d39..163d9d5ee 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -10,7 +10,6 @@ use Cloudinary\Component\Config; use Cloudinary\Component\Notice; use Cloudinary\Component\Setup; -use Cloudinary\Connect\API; /** * Cloudinary connection class. @@ -302,25 +301,33 @@ public function setup() { */ public function get_config() { $signature = get_option( 'cloudinary_connection_signature', null ); - if ( empty( $signature ) ) { - // Check if theres a previous version. - $version = get_option( 'cloudinary_version' ); - if ( version_compare( $this->plugin->version, $version, '>' ) ) { + $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 ); + if ( is_null( $cld_url ) ) { + // Post V1. + $data = get_option( 'cloudinary_connect', array() ); + if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) { + return null; // return null to indicate not valid. + } + } else { + // from V1 to V2. $data = array( - 'cloudinary_url' => get_option( 'cloudinary_url' ), + 'cloudinary_url' => $cld_url, ); - $test = $this->test_connection( $data['cloudinary_url'] ); - if ( 'connection_success' === $test['type'] ) { - $signature = md5( $data['cloudinary_url'] ); - - // remove filters as we've already verified it and 'add_settings_error()' isin't available yet. - remove_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) ); - update_option( 'cloudinary_connect', $data ); - update_option( 'cloudinary_connection_signature', $signature ); - update_option( 'cloudinary_version', $this->plugin->version ); - delete_option( 'cloudinary_settings_cache' ); // remove the cache. - $this->plugin->config['settings']['connect'] = $data; // Set the connection url for this round. - } + } + $test = $this->test_connection( $data['cloudinary_url'] ); + if ( 'connection_success' === $test['type'] ) { + $signature = md5( $data['cloudinary_url'] ); + + // remove filters as we've already verified it and 'add_settings_error()' isin't available yet. + remove_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) ); + update_option( 'cloudinary_connect', $data ); + update_option( 'cloudinary_connection_signature', $signature ); + update_option( 'cloudinary_version', $this->plugin->version ); + delete_option( 'cloudinary_settings_cache' ); // remove the cache. + $this->plugin->config['settings']['connect'] = $data; // Set the connection url for this round. } } From b072e0606304d6dfca1d685d04a1af3a89b7d586 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 15 Apr 2020 13:33:58 +0200 Subject: [PATCH 04/58] add actual sync_key to uploaded items as well as down synced. --- .../php/class-media.php | 16 ++++++++++++---- .../php/media/class-video.php | 4 ++-- .../php/sync/class-push-sync.php | 17 ++++++++--------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index cd966dc35..f91414f2a 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -1006,7 +1006,7 @@ public function down_sync_asset() { } $transformations = $this->get_transformations_from_string( $url ); if ( ! empty( $transformations ) ) { - $sync_key .= wp_json_encode( $transformations ); + $sync_key .= wp_json_encode( $transformations ); $asset['transformations'] = $transformations; } // Check Format and url extension. @@ -1228,6 +1228,14 @@ public function get_post_meta( $post_id, $key, $single = false ) { $data = $this->build_cached_meta( $post_id, $key, $single ); } + // If public_id, ensure there's a sync_key saved. + if ( '_public_id' === $key && empty( $meta_data[ Sync::META_KEYS['cloudinary'] ]['_sync_key'] ) ) { + + //$sync_key = '_' . md5( $data ); + //$this->update_post_meta( $post_id, '_sync_key', $sync_key ); + //update_post_meta( $post_id, $sync_key, true ); // Set sync_key. + } + return $data; } @@ -1252,9 +1260,9 @@ public function build_cached_meta( $post_id, $key, $single ) { /** * Update cloudinary metadata. * - * @param int $post_id The attachment ID. - * @param string $key The meta key to get. - * @param array $data $the meta data to update. + * @param int $post_id The attachment ID. + * @param string $key The meta key to get. + * @param string|array $data $the meta data to update. */ public function update_post_meta( $post_id, $key, $data ) { $meta_data = wp_get_attachment_metadata( $post_id, true ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index 3091d085a..b2075d2bd 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -383,7 +383,7 @@ public function print_video_scripts() { if ( videoElement.length === 1 ) { videoElement = videoElement[0]; videoElement.style.width = '100%'; - + config['video_freeform'] ): ?> videoElement.src = videoElement.src.replace( 'upload/', @@ -427,7 +427,7 @@ 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' ), 10 ); + add_filter( 'the_content', array( $this, 'filter_video_tags' ), 4 ); } add_action( 'wp_print_styles', array( $this, 'init_player' ) ); add_action( 'wp_footer', array( $this, 'print_video_scripts' ) ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index f69020e31..a1a9ae025 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -585,15 +585,14 @@ public function push_attachments( $attachments ) { // Remove records of breakpoints. delete_post_meta( $attachment->ID, Sync::META_KEYS['breakpoints'] ); } - if ( empty( $upload['options']['responsive_breakpoints']['transformation'] ) ) { - // a transformation breakpoints only ever happens on a down sync. - $sync_key = md5( $upload['options']['public_id'] ); - $meta_data[ $sync_key ] = true; - $meta_data[ '_' . $sync_key ] = true; - update_post_meta( $attachment->ID, $sync_key, true ); - // Add base ID. - update_post_meta( $attachment->ID, '_' . $sync_key, true ); - } + } + if ( ! empty( $upload['options']['public_id'] ) ) { + // a transformation breakpoints only ever happens on a down sync. + $sync_key = '_' . md5( $upload['options']['public_id'] ); + $meta_data['sync_key'] = true; + + // Add base ID. + update_post_meta( $attachment->ID, $sync_key, true ); } $stats['success'][] = $attachment->post_title; $meta = wp_get_attachment_metadata( $attachment->ID, true ); From a7459d21566b1902a17610f317cdfd8d2d733005 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 15 Apr 2020 14:07:23 +0200 Subject: [PATCH 05/58] add video front-end style overrides --- .../css/src/video.scss | 9 +++++++++ .../css/video.css | 1 + .../js/cloudinary.js | 2 +- .../php/media/class-video.php | 7 +++++-- .../webpack.config.js | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/video.scss create mode 100644 cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/video.css diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/video.scss b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/video.scss new file mode 100644 index 000000000..1c2cf9b48 --- /dev/null +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/video.scss @@ -0,0 +1,9 @@ +// Frontend video styles. +.cld { + &-video { + &-player { + max-width: 100%; + } + } +} + diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/video.css b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/video.css new file mode 100644 index 000000000..1a254a1ec --- /dev/null +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/video.css @@ -0,0 +1 @@ +.cld-video-player{max-width:100%} \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js index e12099400..e2580b210 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js @@ -1 +1 @@ -!function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=3)}([function(e,t){window,jQuery,jQuery(document).ready((function(e){e(document).on("tabs.init",(function(){var t=e(".settings-tab-trigger"),i=e(".settings-tab-section");e(this).on("click",".settings-tab-trigger",(function(n){var s=e(this),a=e(s.attr("href"));n.preventDefault(),t.removeClass("active"),i.removeClass("active"),s.addClass("active"),a.addClass("active"),e(document).trigger("settings.tabbed",s)})),e(".cld-field").not('[data-condition="false"]').each((function(){const t=e(this),i=t.data("condition");for(let n in i){const s=i[n],a=e("#field-"+n),r=t.closest("tr");a.on("change init",(function(){this.value===s||this.checked?r.show():r.hide()})),a.trigger("init")}})),e("#field-cloudinary_url").on("input change",(function(){let t=e(this),i=t.val();new RegExp(/^(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g).test(i)?(t.addClass("settings-valid-field"),t.removeClass("settings-invalid-field")):(t.removeClass("settings-valid-field"),t.addClass("settings-invalid-field"))})).trigger("change")})),e(".render-trigger[data-event]").each((function(){var t=e(this),i=t.data("event");t.trigger(i,this)}))}))},function(e,t){if(wp.media&&window.CLDN){wp.media.events.on("editor:image-edit",(function(e){e.metadata.cldoverwrite=null,e.image.className.split(" ").indexOf("cld-overwrite")>=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file +!function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=4)}([function(e,t){window,jQuery,jQuery(document).ready((function(e){e(document).on("tabs.init",(function(){var t=e(".settings-tab-trigger"),i=e(".settings-tab-section");e(this).on("click",".settings-tab-trigger",(function(n){var s=e(this),a=e(s.attr("href"));n.preventDefault(),t.removeClass("active"),i.removeClass("active"),s.addClass("active"),a.addClass("active"),e(document).trigger("settings.tabbed",s)})),e(".cld-field").not('[data-condition="false"]').each((function(){const t=e(this),i=t.data("condition");for(let n in i){const s=i[n],a=e("#field-"+n),r=t.closest("tr");a.on("change init",(function(){this.value===s||this.checked?r.show():r.hide()})),a.trigger("init")}})),e("#field-cloudinary_url").on("input change",(function(){let t=e(this),i=t.val();new RegExp(/^(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g).test(i)?(t.addClass("settings-valid-field"),t.removeClass("settings-invalid-field")):(t.removeClass("settings-valid-field"),t.addClass("settings-invalid-field"))})).trigger("change")})),e(".render-trigger[data-event]").each((function(){var t=e(this),i=t.data("event");t.trigger(i,this)}))}))},function(e,t){if(wp.media&&window.CLDN){wp.media.events.on("editor:image-edit",(function(e){e.metadata.cldoverwrite=null,e.image.className.split(" ").indexOf("cld-overwrite")>=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index b2075d2bd..6b50934a1 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -104,6 +104,7 @@ public function init_player() { if ( ! empty( $has_video ) || ! empty( $video_tags ) ) { // Setup initial scripts. wp_enqueue_style( 'cld-player' ); + wp_enqueue_style( 'cld-player-local' ); wp_enqueue_script( 'cld-player' ); // Init cld script object. @@ -414,8 +415,10 @@ public function enqueue_block_assets() { /** * Register assets for the player. */ - public static function register_scripts_styles() { + public function register_scripts_styles() { wp_register_style( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.css', null, self::PLAYER_VER ); + wp_register_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER ); + wp_register_script( 'cld-core', 'https://unpkg.com/cloudinary-core@' . self::CORE_VER . '/cloudinary-core-shrinkwrap.min.js', null, self::CORE_VER, true ); 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 ); } @@ -434,6 +437,6 @@ public function setup_hooks() { // Add inline scripts for gutenberg. add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_assets' ) ); - self::register_scripts_styles(); + $this->register_scripts_styles(); } } diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/webpack.config.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/webpack.config.js index 2e0f62269..93b3c8dc9 100755 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/webpack.config.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/webpack.config.js @@ -39,6 +39,7 @@ const cldCore = { ...sharedConfig, entry: { 'cloudinary': './js/src/main.js', + 'video': './css/src/video.scss', }, output: { path: path.resolve( process.cwd(), 'js' ), From ef5785d001aa98f20e769ac70f43bf23aba91e97 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 15 Apr 2020 14:23:45 +0200 Subject: [PATCH 06/58] update readme for 5.4 support --- .../readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/readme.txt b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/readme.txt index 3cde4c176..19fdc2fbe 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/readme.txt +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/readme.txt @@ -2,7 +2,7 @@ Contributors: Cloudinary, XWP, Automattic Tags: images, videos, DAM, optimizations, CDN, media, gallery, photo, photos, picture, pictures, thumbnail, upload, admin, administration, api, cms, dashboard, editor, integration, manage, mobile, social-media Requires at least: 4.7 -Tested up to: 5.3.2 +Tested up to: 5.4 Requires PHP: 5.6 Stable tag: trunk License: GPLv2 From 35522189ecb3409128d60bfbbd2822a53c49caa6 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 15 Apr 2020 14:41:06 +0200 Subject: [PATCH 07/58] remove green check --- .../ui-definitions/tabs/sync-media-content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php index 11b58d552..a2b8345d2 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php @@ -9,7 +9,7 @@ plugin->config['connect'] ) ) : ?>
    - +


    From 9f8fc74231c132d933223deefcef1ee9c8bb0957 Mon Sep 17 00:00:00 2001 From: Dukagjin Surdulli Date: Wed, 15 Apr 2020 18:46:07 -0400 Subject: [PATCH 08/58] Improve regex on connection URL --- .../js/cloudinary.js | 2 +- .../js/src/components/settings-page.js | 2 +- .../js/video.js | 1 + .../php/class-connect.php | 33 +++++++++++++++---- .../ui-definitions/tabs/settings-connect.php | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js index e2580b210..fd36fd6cc 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/cloudinary.js @@ -1 +1 @@ -!function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=4)}([function(e,t){window,jQuery,jQuery(document).ready((function(e){e(document).on("tabs.init",(function(){var t=e(".settings-tab-trigger"),i=e(".settings-tab-section");e(this).on("click",".settings-tab-trigger",(function(n){var s=e(this),a=e(s.attr("href"));n.preventDefault(),t.removeClass("active"),i.removeClass("active"),s.addClass("active"),a.addClass("active"),e(document).trigger("settings.tabbed",s)})),e(".cld-field").not('[data-condition="false"]').each((function(){const t=e(this),i=t.data("condition");for(let n in i){const s=i[n],a=e("#field-"+n),r=t.closest("tr");a.on("change init",(function(){this.value===s||this.checked?r.show():r.hide()})),a.trigger("init")}})),e("#field-cloudinary_url").on("input change",(function(){let t=e(this),i=t.val();new RegExp(/^(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g).test(i)?(t.addClass("settings-valid-field"),t.removeClass("settings-invalid-field")):(t.removeClass("settings-valid-field"),t.addClass("settings-invalid-field"))})).trigger("change")})),e(".render-trigger[data-event]").each((function(){var t=e(this),i=t.data("event");t.trigger(i,this)}))}))},function(e,t){if(wp.media&&window.CLDN){wp.media.events.on("editor:image-edit",(function(e){e.metadata.cldoverwrite=null,e.image.className.split(" ").indexOf("cld-overwrite")>=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("

  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file +!function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=4)}([function(e,t){window,jQuery,jQuery(document).ready((function(e){e(document).on("tabs.init",(function(){var t=e(".settings-tab-trigger"),i=e(".settings-tab-section");e(this).on("click",".settings-tab-trigger",(function(n){var s=e(this),a=e(s.attr("href"));n.preventDefault(),t.removeClass("active"),i.removeClass("active"),s.addClass("active"),a.addClass("active"),e(document).trigger("settings.tabbed",s)})),e(".cld-field").not('[data-condition="false"]').each((function(){const t=e(this),i=t.data("condition");for(let n in i){const s=i[n],a=e("#field-"+n),r=t.closest("tr");a.on("change init",(function(){this.value===s||this.checked?r.show():r.hide()})),a.trigger("init")}})),e("#field-cloudinary_url").on("input change",(function(){let t=e(this),i=t.val();new RegExp(/^(?:CLOUDINARY_URL=)?(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g).test(i)?(t.addClass("settings-valid-field"),t.removeClass("settings-invalid-field")):(t.removeClass("settings-valid-field"),t.addClass("settings-invalid-field"))})).trigger("change")})),e(".render-trigger[data-event]").each((function(){var t=e(this),i=t.data("event");t.trigger(i,this)}))}))},function(e,t){if(wp.media&&window.CLDN){wp.media.events.on("editor:image-edit",(function(e){e.metadata.cldoverwrite=null,e.image.className.split(" ").indexOf("cld-overwrite")>=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/settings-page.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/settings-page.js index 3000d58ec..6c638d976 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/settings-page.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/settings-page.js @@ -50,7 +50,7 @@ let field = $(this), value = field.val(); - let reg = new RegExp(/^(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g ); + let reg = new RegExp(/^(?:CLOUDINARY_URL=)?(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g ); if( reg.test( value ) ){ field.addClass( 'settings-valid-field' ); field.removeClass( 'settings-invalid-field' ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js new file mode 100644 index 000000000..6c75b6b82 --- /dev/null +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js @@ -0,0 +1 @@ +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}({3:function(e,t,r){}}); \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 163d9d5ee..5a9dd1f83 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -118,27 +118,43 @@ public function media_library_script() { 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']; + if ( $current['cloudinary_url'] === $data['cloudinary_url'] ) { return $data; } - if ( ! preg_match( '~^cloudinary://~', $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' ); + // 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' + ); return $current; } $result = $this->test_connection( $data['cloudinary_url'] ); + if ( ! empty( $result['message'] ) ) { add_settings_error( 'cloudinary_connect', $result['type'], $result['message'], 'error' ); - return $current; } + add_settings_error( 'cloudinary_connect', 'connection_success', __( 'Successfully connected to Cloudinary.', 'cloudinary' ), 'updated' ); update_option( 'cloudinary_connection_signature', md5( $data['cloudinary_url'] ) ); @@ -169,9 +185,9 @@ function ( $a ) { if ( 4 > count( $valid ) ) { $result['type'] = 'invalid_url'; $result['message'] = sprintf( - // translators: Placeholder refers to the expected URL format. + // translators: Placeholder refers to the expected URL format. __( 'Incorrect Format. Expecting: %s', 'cloudinary' ), - 'cloudinary://API_Key:API_Secret@Cloud_Name' + 'cloudinary://API_KEY:API_SECRET@CLOUD_NAME' ); return $result; @@ -305,7 +321,7 @@ public function get_config() { 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 ); - if ( is_null( $cld_url ) ) { + if ( null === $cld_url ) { // Post V1. $data = get_option( 'cloudinary_connect', array() ); if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) { @@ -317,7 +333,10 @@ public function get_config() { 'cloudinary_url' => $cld_url, ); } + + $data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] ); $test = $this->test_connection( $data['cloudinary_url'] ); + if ( 'connection_success' === $test['type'] ) { $signature = md5( $data['cloudinary_url'] ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-connect.php index 898eff7e1..7a92de572 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-connect.php @@ -15,7 +15,7 @@ 'fields' => array( 'cloudinary_url' => array( 'label' => __( 'Environment variable URL', 'cloudinary' ), - 'placeholder' => 'cloudinary://API_Key:API_Secret@Cloud_Name', + 'placeholder' => 'cloudinary://API_KEY:API_SECRET@CLOUD_NAME', 'required' => true, 'suffix' => '', ), From 665030cb920da8df4f2b563a5e68464302032b2c Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 16 Apr 2020 07:59:00 +0200 Subject: [PATCH 09/58] revert static scripts enqueue --- .../php/media/class-video.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index d1fbf6b5b..3f7ec14f9 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -104,7 +104,7 @@ public function init_player() { if ( ! empty( $has_video ) || ! empty( $video_tags ) ) { // Setup initial scripts. wp_enqueue_style( 'cld-player' ); - wp_enqueue_style( 'cld-player-local' ); + wp_enqueue_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER ); wp_enqueue_script( 'cld-player' ); // Init cld script object. @@ -417,10 +417,8 @@ public function enqueue_block_assets() { /** * Register assets for the player. */ - public function register_scripts_styles() { + public static function register_scripts_styles() { wp_register_style( 'cld-player', 'https://unpkg.com/cloudinary-video-player@' . self::PLAYER_VER . '/dist/cld-video-player.min.css', null, self::PLAYER_VER ); - wp_register_style( 'cld-player-local', $this->media->plugin->dir_url . 'css/video.css', null, self::PLAYER_VER ); - wp_register_script( 'cld-core', 'https://unpkg.com/cloudinary-core@' . self::CORE_VER . '/cloudinary-core-shrinkwrap.min.js', null, self::CORE_VER, true ); 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 ); } From ed4e1e79c2e40fbd93c8a95e727eeb64605c25df Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 16 Apr 2020 08:03:19 +0200 Subject: [PATCH 10/58] bump version --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index 65cb8434a..fb8992f19 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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.3 + * Version: 2.0.4 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 66606b221d53dc9dc2e8561f362ef2539f08bd45 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 16 Apr 2020 08:06:08 +0200 Subject: [PATCH 11/58] remove video.js --- .../js/video.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js deleted file mode 100644 index 6c75b6b82..000000000 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/video.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}({3:function(e,t,r){}}); \ No newline at end of file From eddcbae2c5a1b9020f17a8a4445c7f3ad09a0c6a Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 20 Apr 2020 15:40:38 +0200 Subject: [PATCH 12/58] add sync state styles --- .../css/cloudinary.css | 2 +- .../css/src/components/_sync.scss | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css index 7df57b89b..83fecdab6 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css @@ -1 +1 @@ -@font-face{font-family:cloudinary;src:url(../css/fonts/cloudinary.eot);src:url(../css/fonts/cloudinary.eot#iefix) format("embedded-opentype"),url(../css/fonts/cloudinary.ttf) format("truetype"),url(../css/fonts/cloudinary.woff) format("woff"),url(../css/cloudinary.svg#cloudinary) format("svg");font-weight:400;font-style:normal}.dashicons-cloudinary{speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.dashicons-cloudinary:before{font-family:cloudinary!important;content:"\e900"}.dashicons-cloudinary.success{color:#558b2f}.dashicons-cloudinary.error{color:#dd2c00}.dashicons-cloudinary.error:before{content:"\e901"}.dashicons-cloudinary.warning:before{content:"\e902"}.dashicons-cloudinary.warning{color:#fd9d2c}.column-cld_status{width:5.5em}.column-cld_status .dashicons-cloudinary{display:inline-block}.column-cld_status .dashicons-cloudinary:before{font-size:1.8rem}.form-field .error-notice,.form-table .error-notice{display:none;color:#dd2c00}.form-field input.cld-field:invalid,.form-table input.cld-field:invalid{border-color:#dd2c00}.form-field input.cld-field:invalid+.error-notice,.form-table input.cld-field:invalid+.error-notice{display:inline-block}.cloudinary-welcome{background-image:url(../css/logo.svg);background-repeat:no-repeat;background-size:153px;background-position:top 12px right 20px}.settings-image{max-width:100%;padding-top:5px}.settings-tabs>li{display:inline-block}.settings-tabs>li a{padding:.6em}.settings-tabs>li a.active{background-color:#fff}.settings-tab-section{padding:20px 0 0;max-width:1030px;position:relative}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard{display:flex;align-items:flex-start;align-content:flex-start;margin-top:40px}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-description{width:55%;margin:0 auto 0 0}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content{width:35%;margin:0 auto}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content .dashicons{color:#9ea3a8}.settings-tab-section.cloudinary-welcome .settings-tab-section-card{margin-top:0}.settings-tab-section-fields .field-heading th{display:block;width:auto;color:#23282d;font-size:1.1em;margin:1em 0}.settings-tab-section-fields .field-heading td{display:none;visibility:hidden}.settings-tab-section-fields .regular-textarea{width:100%;height:60px}.settings-tab-section-fields .dashicons{text-decoration:none;vertical-align:middle}.settings-tab-section-fields a .dashicons{color:#5f5f5f}.settings-tab-section-fields-dashboard-error{font-size:1.2em;color:#5f5f5f}.settings-tab-section-fields-dashboard-error .dashicons{color:#ac0000}.settings-tab-section-fields-dashboard-error .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success{font-size:1.2em;color:#23282d}.settings-tab-section-fields-dashboard-success.expanded{padding-top:40px}.settings-tab-section-fields-dashboard-success .dashicons{color:#4fb651}.settings-tab-section-fields-dashboard-success .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success .description{color:#5f5f5f;font-weight:400;margin-top:12px}.settings-tab-section-card{box-sizing:border-box;border:1px solid #e5e5e5;background-color:#fff;box-shadow:0 1px 1px 0 rgba(0,0,0,.07);padding:20px 23px;margin-top:12px}.settings-tab-section-card .dashicons{font-size:1.4em}.settings-tab-section-card h2{font-size:1.8em;font-weight:400;margin-top:0}.settings-tab-section-card.pull-right{width:450px;padding:12px;float:right;position:relative;z-index:10}.settings-tab-section-card.pull-right img.settings-image{box-shadow:0 2px 4px 0 rgba(0,0,0,.5);border:1px solid #979797;margin-top:12px}.settings-tab-section-card.pull-right h3,.settings-tab-section-card.pull-right h4{margin-top:0}.settings-tab-section .field-row-cloudinary_url,.settings-tab-section .field-row-signup{display:block}.settings-tab-section .field-row-cloudinary_url td,.settings-tab-section .field-row-cloudinary_url th,.settings-tab-section .field-row-signup td,.settings-tab-section .field-row-signup th{display:block;width:auto;padding:10px 0 0}.settings-tab-section .field-row-cloudinary_url td .sign-up,.settings-tab-section .field-row-cloudinary_url th .sign-up,.settings-tab-section .field-row-signup td .sign-up,.settings-tab-section .field-row-signup th .sign-up{vertical-align:baseline}.settings-tab-section.connect .form-table{display:inline-block;width:auto;max-width:580px}.settings-valid{color:#558b2f;font-size:30px}.settings-valid-field{border-color:#558b2f!important}.settings-invalid-field{border-color:#dd2c00!important}.sync .spinner{display:inline-block;visibility:visible;float:none;margin:0 5px 0 0}.sync-media,.sync-media-progress{display:none}.sync-media-progress-outer{height:20px;margin:20px 0 10px;width:500px;background-color:#e5e5e5;position:relative}.sync-media-progress-outer .progress-bar{width:0;height:20px;background-color:#558b2f;transition:width .25s}.sync-media-progress-notice{color:#dd2c00}.sync-media-resource{width:100px;display:inline-block}.sync-media-error{color:#dd2c00}.sync-count{font-weight:700}.sync-details{margin-top:10px}.sync .button.start-sync,.sync .button.stop-sync{display:none;padding:0 16px}.sync .button.start-sync .dashicons,.sync .button.stop-sync .dashicons{line-height:2.2em}.sync .progress-text{padding:12px 4px 12px 12px;display:inline-block;font-weight:700}.sync .completed{max-width:300px;display:none}.cloudinary-widget{height:100%}.cloudinary-widget-wrapper{height:100%;overflow:hidden;background-image:url("data:image/svg+xml;base64,PHN2ZyBjbGFzcz0ic3Bpbm5lciIgdmlld0JveD0iLTQgLTQgMTUxIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48c3R5bGU+QGtleWZyYW1lcyBjb2xvcnN7MCUsdG97c3Ryb2tlOiMwMDc4ZmZ9NTAle3N0cm9rZTojMGUyZjVhfX1Aa2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX1ALXdlYmtpdC1rZXlmcmFtZXMgY29sb3JzezAlLHRve3N0cm9rZTojMDA3OGZmfTUwJXtzdHJva2U6IzBlMmY1YX19QC13ZWJraXQta2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX08L3N0eWxlPjxwYXRoIGQ9Ik0xMjEuNjYzIDkwLjYzOGMtMS43OTYgMC05OS4zMy0uNDk4LTEwMS40NzQtMS40NzhDOC42ODUgODMuODc3IDEuMjUgNzIuMTk2IDEuMjUgNTkuMzk2YzAtMTYuNjU2IDEyLjc5Ny0zMC42MSAyOS4wNTItMzIuMzIzIDcuNDktMTUuNzA2IDIzLjE4Ni0yNS43MDcgNDAuNzE0LTI1LjcwNyAyMC45OCAwIDM5LjIxNSAxNC43NTIgNDMuOTQ1IDM0LjkwNyAxNS4wOS4yNDUgMjcuMjkgMTIuNjMgMjcuMjkgMjcuODIyIDAgMTEuOTY4LTcuNzM4IDIyLjU1LTE5LjI1NiAyNi4zMyIgc3Ryb2tlLXdpZHRoPSI5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3R5bGU9InRyYW5zZm9ybS1vcmlnaW46Y2VudGVyOy13ZWJraXQtYW5pbWF0aW9uOmRhc2ggMnMgZWFzZS1pbi1vdXQgaW5maW5pdGUsY29sb3JzIDhzIGVhc2UtaW4tb3V0IGluZmluaXRlO2FuaW1hdGlvbjpkYXNoIDJzIGVhc2UtaW4tb3V0IGluZmluaXRlLGNvbG9ycyA4cyBlYXNlLWluLW91dCBpbmZpbml0ZSIgc3Ryb2tlLWRhc2hhcnJheT0iMjgwIi8+PC9zdmc+");background-repeat:no-repeat;background-position:50%;background-size:150px}.attachment-actions .button.edit-attachment,.attachment-info .edit-attachment{display:none}.global-transformations-preview{position:relative;max-width:600px}.global-transformations-spinner{display:none}.global-transformations-button.button-primary{display:none;position:absolute;z-index:100}.global-transformations-url{margin-bottom:5px;margin-top:5px}.global-transformations-url-transformation{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:#51a3ff}.global-transformations-url-file{color:#f2d864}.global-transformations-url-link{display:block;padding:16px;background-color:#262c35;text-decoration:none;color:#fff;border-radius:6px;overflow:hidden;text-overflow:ellipsis}.global-transformations-url-link:hover{color:#888;text-decoration:underline}.cld-tax-order-list-item{border:1px solid #efefef;padding:4px;margin:0 0 -1px;background-color:#fff}.cld-tax-order-list-item.no-items{color:#888;text-align:center;display:none}.cld-tax-order-list-item.no-items:last-child{display:block}.cld-tax-order-list-item.ui-sortable-helper{box-shadow:0 2px 5px rgba(0,0,0,.2)}.cld-tax-order-list-item-placeholder{background-color:#efefef;height:45px;margin:0}.cld-tax-order-list-item-handle{cursor:grab;margin-right:4px;color:#999}.cld-tax-order-list-type{width:45%;display:inline-block;margin-right:8px}.cld-tax-order-list-type input{margin-right:4px!important}.cloudinary-media-library{position:relative;margin-left:-20px}@media screen and (max-width:782px){.cloudinary-media-library{margin-left:-10px}} \ No newline at end of file +@font-face{font-family:cloudinary;src:url(../css/fonts/cloudinary.eot);src:url(../css/fonts/cloudinary.eot#iefix) format("embedded-opentype"),url(../css/fonts/cloudinary.ttf) format("truetype"),url(../css/fonts/cloudinary.woff) format("woff"),url(../css/cloudinary.svg#cloudinary) format("svg");font-weight:400;font-style:normal}.dashicons-cloudinary{speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.dashicons-cloudinary:before{font-family:cloudinary!important;content:"\e900"}.dashicons-cloudinary.success{color:#558b2f}.dashicons-cloudinary.error{color:#dd2c00}.dashicons-cloudinary.error:before{content:"\e901"}.dashicons-cloudinary.warning:before{content:"\e902"}.dashicons-cloudinary.warning{color:#fd9d2c}.column-cld_status{width:5.5em}.column-cld_status .dashicons-cloudinary{display:inline-block}.column-cld_status .dashicons-cloudinary:before{font-size:1.8rem}.form-field .error-notice,.form-table .error-notice{display:none;color:#dd2c00}.form-field input.cld-field:invalid,.form-table input.cld-field:invalid{border-color:#dd2c00}.form-field input.cld-field:invalid+.error-notice,.form-table input.cld-field:invalid+.error-notice{display:inline-block}.cloudinary-welcome{background-image:url(../css/logo.svg);background-repeat:no-repeat;background-size:153px;background-position:top 12px right 20px}.settings-image{max-width:100%;padding-top:5px}.settings-tabs>li{display:inline-block}.settings-tabs>li a{padding:.6em}.settings-tabs>li a.active{background-color:#fff}.settings-tab-section{padding:20px 0 0;max-width:1030px;position:relative}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard{display:flex;align-items:flex-start;align-content:flex-start;margin-top:40px}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-description{width:55%;margin:0 auto 0 0}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content{width:35%;margin:0 auto}.settings-tab-section.cloudinary-welcome .settings-tab-section-fields-dashboard-content .dashicons{color:#9ea3a8}.settings-tab-section.cloudinary-welcome .settings-tab-section-card{margin-top:0}.settings-tab-section-fields .field-heading th{display:block;width:auto;color:#23282d;font-size:1.1em;margin:1em 0}.settings-tab-section-fields .field-heading td{display:none;visibility:hidden}.settings-tab-section-fields .regular-textarea{width:100%;height:60px}.settings-tab-section-fields .dashicons{text-decoration:none;vertical-align:middle}.settings-tab-section-fields a .dashicons{color:#5f5f5f}.settings-tab-section-fields-dashboard-error{font-size:1.2em;color:#5f5f5f}.settings-tab-section-fields-dashboard-error .dashicons{color:#ac0000}.settings-tab-section-fields-dashboard-error .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success{font-size:1.2em;color:#23282d}.settings-tab-section-fields-dashboard-success.expanded{padding-top:40px}.settings-tab-section-fields-dashboard-success .dashicons{color:#4fb651}.settings-tab-section-fields-dashboard-success .button{font-size:1.1em;height:40px;line-height:40px;padding-right:40px;padding-left:40px}.settings-tab-section-fields-dashboard-success .description{color:#5f5f5f;font-weight:400;margin-top:12px}.settings-tab-section-card{box-sizing:border-box;border:1px solid #e5e5e5;background-color:#fff;box-shadow:0 1px 1px 0 rgba(0,0,0,.07);padding:20px 23px;margin-top:12px}.settings-tab-section-card .dashicons{font-size:1.4em}.settings-tab-section-card h2{font-size:1.8em;font-weight:400;margin-top:0}.settings-tab-section-card.pull-right{width:450px;padding:12px;float:right;position:relative;z-index:10}.settings-tab-section-card.pull-right img.settings-image{box-shadow:0 2px 4px 0 rgba(0,0,0,.5);border:1px solid #979797;margin-top:12px}.settings-tab-section-card.pull-right h3,.settings-tab-section-card.pull-right h4{margin-top:0}.settings-tab-section .field-row-cloudinary_url,.settings-tab-section .field-row-signup{display:block}.settings-tab-section .field-row-cloudinary_url td,.settings-tab-section .field-row-cloudinary_url th,.settings-tab-section .field-row-signup td,.settings-tab-section .field-row-signup th{display:block;width:auto;padding:10px 0 0}.settings-tab-section .field-row-cloudinary_url td .sign-up,.settings-tab-section .field-row-cloudinary_url th .sign-up,.settings-tab-section .field-row-signup td .sign-up,.settings-tab-section .field-row-signup th .sign-up{vertical-align:baseline}.settings-tab-section.connect .form-table{display:inline-block;width:auto;max-width:580px}.settings-valid{color:#558b2f;font-size:30px}.settings-valid-field{border-color:#558b2f!important}.settings-invalid-field{border-color:#dd2c00!important}.sync .spinner{display:inline-block;visibility:visible;float:none;margin:0 5px 0 0}.sync-media,.sync-media-progress{display:none}.sync-media-progress-outer{height:20px;margin:20px 0 10px;width:500px;background-color:#e5e5e5;position:relative}.sync-media-progress-outer .progress-bar{width:0;height:20px;background-color:#558b2f;transition:width .25s}.sync-media-progress-notice{color:#dd2c00}.sync-media-resource{width:100px;display:inline-block}.sync-media-error{color:#dd2c00}.sync-count{font-weight:700}.sync-details{margin-top:10px}.sync .button.start-sync,.sync .button.stop-sync{display:none;padding:0 16px}.sync .button.start-sync .dashicons,.sync .button.stop-sync .dashicons{line-height:2.2em}.sync .progress-text{padding:12px 4px 12px 12px;display:inline-block;font-weight:700}.sync .completed{max-width:300px;display:none}.sync-status-disabled{color:#dd2c00}.sync-status-enabled{color:#558b2f}.sync-status-button.button{vertical-align:baseline}.cloudinary-widget{height:100%}.cloudinary-widget-wrapper{height:100%;overflow:hidden;background-image:url("data:image/svg+xml;base64,PHN2ZyBjbGFzcz0ic3Bpbm5lciIgdmlld0JveD0iLTQgLTQgMTUxIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48c3R5bGU+QGtleWZyYW1lcyBjb2xvcnN7MCUsdG97c3Ryb2tlOiMwMDc4ZmZ9NTAle3N0cm9rZTojMGUyZjVhfX1Aa2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX1ALXdlYmtpdC1rZXlmcmFtZXMgY29sb3JzezAlLHRve3N0cm9rZTojMDA3OGZmfTUwJXtzdHJva2U6IzBlMmY1YX19QC13ZWJraXQta2V5ZnJhbWVzIGRhc2h7MCUsdG97c3Ryb2tlLWRhc2hvZmZzZXQ6NTYwfTUwJXtzdHJva2UtZGFzaG9mZnNldDowfX08L3N0eWxlPjxwYXRoIGQ9Ik0xMjEuNjYzIDkwLjYzOGMtMS43OTYgMC05OS4zMy0uNDk4LTEwMS40NzQtMS40NzhDOC42ODUgODMuODc3IDEuMjUgNzIuMTk2IDEuMjUgNTkuMzk2YzAtMTYuNjU2IDEyLjc5Ny0zMC42MSAyOS4wNTItMzIuMzIzIDcuNDktMTUuNzA2IDIzLjE4Ni0yNS43MDcgNDAuNzE0LTI1LjcwNyAyMC45OCAwIDM5LjIxNSAxNC43NTIgNDMuOTQ1IDM0LjkwNyAxNS4wOS4yNDUgMjcuMjkgMTIuNjMgMjcuMjkgMjcuODIyIDAgMTEuOTY4LTcuNzM4IDIyLjU1LTE5LjI1NiAyNi4zMyIgc3Ryb2tlLXdpZHRoPSI5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3R5bGU9InRyYW5zZm9ybS1vcmlnaW46Y2VudGVyOy13ZWJraXQtYW5pbWF0aW9uOmRhc2ggMnMgZWFzZS1pbi1vdXQgaW5maW5pdGUsY29sb3JzIDhzIGVhc2UtaW4tb3V0IGluZmluaXRlO2FuaW1hdGlvbjpkYXNoIDJzIGVhc2UtaW4tb3V0IGluZmluaXRlLGNvbG9ycyA4cyBlYXNlLWluLW91dCBpbmZpbml0ZSIgc3Ryb2tlLWRhc2hhcnJheT0iMjgwIi8+PC9zdmc+");background-repeat:no-repeat;background-position:50%;background-size:150px}.attachment-actions .button.edit-attachment,.attachment-info .edit-attachment{display:none}.global-transformations-preview{position:relative;max-width:600px}.global-transformations-spinner{display:none}.global-transformations-button.button-primary{display:none;position:absolute;z-index:100}.global-transformations-url{margin-bottom:5px;margin-top:5px}.global-transformations-url-transformation{max-width:100px;overflow:hidden;text-overflow:ellipsis;color:#51a3ff}.global-transformations-url-file{color:#f2d864}.global-transformations-url-link{display:block;padding:16px;background-color:#262c35;text-decoration:none;color:#fff;border-radius:6px;overflow:hidden;text-overflow:ellipsis}.global-transformations-url-link:hover{color:#888;text-decoration:underline}.cld-tax-order-list-item{border:1px solid #efefef;padding:4px;margin:0 0 -1px;background-color:#fff}.cld-tax-order-list-item.no-items{color:#888;text-align:center;display:none}.cld-tax-order-list-item.no-items:last-child{display:block}.cld-tax-order-list-item.ui-sortable-helper{box-shadow:0 2px 5px rgba(0,0,0,.2)}.cld-tax-order-list-item-placeholder{background-color:#efefef;height:45px;margin:0}.cld-tax-order-list-item-handle{cursor:grab;margin-right:4px;color:#999}.cld-tax-order-list-type{width:45%;display:inline-block;margin-right:8px}.cld-tax-order-list-type input{margin-right:4px!important}.cloudinary-media-library{position:relative;margin-left:-20px}@media screen and (max-width:782px){.cloudinary-media-library{margin-left:-10px}} \ No newline at end of file diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_sync.scss b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_sync.scss index d5536a061..ade7882b1 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_sync.scss +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_sync.scss @@ -70,5 +70,19 @@ max-width : 300px; display : none; } + + &-status { + &-disabled { + color : $color-red; + } + + &-enabled { + color : $color-green; + } + + &-button.button { + vertical-align : baseline; + } + } } From 3baa03f4f28a59ed3b65023191323db10fd18896 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 20 Apr 2020 15:41:00 +0200 Subject: [PATCH 13/58] make default colum status as not synced --- .../php/class-media.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index f91414f2a..e155ace61 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -1072,8 +1072,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. @@ -1085,6 +1085,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 ); From adc6af19dd327a4e39370c8e2dadbd35c5f3b0ad Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 20 Apr 2020 15:41:38 +0200 Subject: [PATCH 14/58] switch message based on sync state and add additional setting --- .../tabs/settings-sync-media.php | 7 ++++++ .../tabs/sync-media-content.php | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php index 997b43b15..31bc75286 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php @@ -13,6 +13,13 @@ 'hide_button' => true, 'requires_config' => true, 'fields' => array( + 'auto_sync' => array( + 'label' => __( 'Auto-Sync', 'cloudinary' ), + 'suffix' => __( 'Enable Auto-Sync', 'cloudinary' ) . ' ', + 'description' => __( 'When enabled, all assets will be automatically pushed to your Cloudinary account on demand.', 'cloudinary' ), + 'type' => 'checkbox', + 'default' => 'on', + ), 'cloudinary_folder' => array( 'label' => __( 'Cloudinary folder path', 'cloudinary' ), 'description' => __( 'Specify the folder in your Cloudinary account where WordPress assets are uploaded to. All assets uploaded to WordPress from this point on will be synced to the specified folder in Cloudinary. Leave blank to use the root of your Cloudinary library.', 'cloudinary' ), diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php index a2b8345d2..6b981416d 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php @@ -5,15 +5,27 @@ * @package Cloudinary */ +$autosync = false; +if ( isset( $this->plugin->config['settings']['sync_media']['auto_sync'] ) && 'on' === $this->plugin->config['settings']['sync_media']['auto_sync'] ) { + $autosync = true; +} ?> plugin->config['connect'] ) ) : ?>
    - -

    -
    - -

    + + +

    +
    + +

    + + +

    +
    + +

    +
    From 743d2bee2c9321bc002c4c69ff6f959f91e00004 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 20 Apr 2020 15:44:22 +0200 Subject: [PATCH 15/58] add new bulk and inline actions --- .../php/sync/class-delete-sync.php | 4 +- .../php/sync/class-upload-sync.php | 125 ++++++++++++++++-- 2 files changed, 114 insertions(+), 15 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php index 3852f38a4..4a85cc520 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php @@ -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 ) ) { diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php index 2c4bc7f62..fac04d969 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php @@ -53,7 +53,7 @@ class Upload_Sync { * @param bool $enabled Is this feature enabled. * @param object $pusher An object that implements `push_attachments`. Default: null. */ - public function __construct( \Cloudinary\Plugin $plugin, $enabled = true, $pusher = null ) { + public function __construct( \Cloudinary\Plugin $plugin, $enabled = false, $pusher = null ) { $this->plugin = $plugin; $this->pusher = $pusher; $this->enabled = $enabled; @@ -71,6 +71,94 @@ private function register_hooks() { add_filter( 'cloudinary_media_status', array( $this, 'filter_status' ), 10, 2 ); // Hook for on demand upload push. add_action( 'shutdown', array( $this, 'init_background_upload' ) ); + // Hook into auto upload sync. + add_filter( 'cloudinary_on_demand_sync_enabled', array( $this, 'auto_sync_enabled' ) ); + // Handle bulk and inline actions. + add_filter( 'handle_bulk_actions-upload', array( $this, 'handle_bulk_actions' ), 10, 3 ); + // Add inline action. + add_filter( 'media_row_actions', array( $this, 'add_inline_action' ), 10, 2 ); + + // Add Bulk actions. + add_filter( 'bulk_actions-upload', function ( $actions ) { + $cloudinary_actions = array( + 'cloudinary-push' => __( 'Push to Cloudinary', 'cloudinary' ), + ); + + return array_merge( $cloudinary_actions, $actions ); + } ); + } + + /** + * Add an inline action for manual sync. + * + * @param array $actions All actions. + * @param \WP_Post $post The current post object. + * + * @return array + */ + function add_inline_action( $actions, $post ) { + if ( ! $this->plugin->components['sync']->is_synced( $post->ID ) ) { + if ( current_user_can( 'delete_post', $post->ID ) ) { + $action_url = add_query_arg( + array( + 'action' => 'cloudinary-push', + 'media[]' => $post->ID, + '_wpnonce' => wp_create_nonce( 'bulk-media' ), + ), + 'upload.php' + ); + + $actions['cloudinary-push'] = sprintf( + '%s', + $action_url, + /* translators: %s: Attachment title. */ + esc_attr( sprintf( __( 'Push to Cloudinary “%s”' ), 'asd' ) ), + __( 'Push to Cloudinary', 'cloudinary' ) + ); + } + } + + return $actions; + } + + /** + * Handles bulk actions for attachments. + * + * @param string $location The location to redirect after. + * @param string $action The action to handle. + * @param array $post_ids Post ID's to action. + * + * @return string + */ + public function handle_bulk_actions( $location, $action, $post_ids ) { + + switch ( $action ) { + case 'cloudinary-push' : + foreach ( $post_ids as $post_id ) { + if ( ! $this->plugin->components['sync']->is_synced( $post_id ) ) { + $this->prep_upload( $post_id ); + } + } + break; + } + + return $location; + + } + + /** + * Check if auto-sync is enabled. + * + * @param bool $enabled Flag to determine if autosync is enabled. + * + * @return bool + */ + public function auto_sync_enabled( $enabled ) { + if ( isset( $this->plugin->config['settings']['sync_media']['auto_sync'] ) && 'on' === $this->plugin->config['settings']['sync_media']['auto_sync'] ) { + $enabled = true; + } + + return $enabled; } /** @@ -114,25 +202,34 @@ public function prep_on_demand_upload( $cloudinary_id, $attachment_id ) { if ( $attachment_id && false === $cloudinary_id ) { // Check that this has not already been prepared for upload. if ( ! $this->is_pending( $attachment_id ) && apply_filters( 'cloudinary_on_demand_sync_enabled', $this->enabled ) ) { - $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); - $file = get_attached_file( $attachment_id ); - // Get the file size to make sure it can exist in cloudinary. - if ( file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { - $this->add_to_sync( $attachment_id ); - } else { - // Check if the src is a url. - $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); - if ( $this->plugin->components['media']->is_cloudinary_url( $file ) ) { - // Download sync. - $this->add_to_sync( $attachment_id ); - } - } + $this->prep_upload( $attachment_id ); } } return $cloudinary_id; } + /** + * Prep an attachment for upload. + * + * @param int $attachment_id The attachment ID to prep for upload. + */ + public function prep_upload( $attachment_id ) { + $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); + $file = get_attached_file( $attachment_id ); + // Get the file size to make sure it can exist in cloudinary. + if ( file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { + $this->add_to_sync( $attachment_id ); + } else { + // Check if the src is a url. + $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); + if ( $this->plugin->components['media']->is_cloudinary_url( $file ) ) { + // Download sync. + $this->add_to_sync( $attachment_id ); + } + } + } + /** * Add an attachment ID to the to_sync array. * From a6e68b6346862273e2c0f3c9d3182442a6fba014 Mon Sep 17 00:00:00 2001 From: Dukagjin Surdulli Date: Mon, 20 Apr 2020 17:43:59 -0400 Subject: [PATCH 16/58] Adjust the texts in the sync settings page --- .../ui-definitions/tabs/settings-sync-media.php | 1 + .../ui-definitions/tabs/sync-media-content.php | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php index 997b43b15..2eb39f767 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-sync-media.php @@ -15,6 +15,7 @@ 'fields' => array( 'cloudinary_folder' => array( 'label' => __( 'Cloudinary folder path', 'cloudinary' ), + 'placeholder' => __( 'e.g.: wordpress_assets/', 'cloudinary' ), 'description' => __( 'Specify the folder in your Cloudinary account where WordPress assets are uploaded to. All assets uploaded to WordPress from this point on will be synced to the specified folder in Cloudinary. Leave blank to use the root of your Cloudinary library.', 'cloudinary' ), 'sanitize_callback' => array( '\Cloudinary\Media', 'sanitize_cloudinary_folder' ), 'suffix' => '', diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php index a2b8345d2..2a9dcca27 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-content.php @@ -9,10 +9,9 @@ plugin->config['connect'] ) ) : ?>
    - +

    -
    - +

    From 0306d4acfbbacdef683214a441ca16481308e616 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 21 Apr 2020 14:28:45 +0200 Subject: [PATCH 17/58] add fluid class for responsive videos --- .../php/media/class-video.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index 3f7ec14f9..f971948dd 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -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 ''; + return ''; } /** @@ -423,6 +423,38 @@ 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( '
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file +!function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=3)}([function(e,t){window,jQuery,jQuery(document).ready((function(e){e(document).on("tabs.init",(function(){var t=e(".settings-tab-trigger"),i=e(".settings-tab-section");e(this).on("click",".settings-tab-trigger",(function(n){var s=e(this),a=e(s.attr("href"));n.preventDefault(),t.removeClass("active"),i.removeClass("active"),s.addClass("active"),a.addClass("active"),e(document).trigger("settings.tabbed",s)})),e(".cld-field").not('[data-condition="false"]').each((function(){const t=e(this),i=t.data("condition");for(let n in i){const s=i[n],a=e("#field-"+n),r=t.closest("tr");a.on("change init",(function(){this.value===s||this.checked?r.show():r.hide()})),a.trigger("init")}})),e("#field-cloudinary_url").on("input change",(function(){let t=e(this),i=t.val();new RegExp(/^(?:CLOUDINARY_URL=)?(cloudinary:\/\/){1}(\d)*[:]{1}[^:@]*[@]{1}[^@]*$/g).test(i)?(t.addClass("settings-valid-field"),t.removeClass("settings-invalid-field")):(t.removeClass("settings-valid-field"),t.addClass("settings-invalid-field"))})).trigger("change")})),e(".render-trigger[data-event]").each((function(){var t=e(this),i=t.data("event");t.trigger(i,this)}))}))},function(e,t){if(wp.media&&window.CLDN){wp.media.events.on("editor:image-edit",(function(e){e.metadata.cldoverwrite=null,e.image.className.split(" ").indexOf("cld-overwrite")>=0&&(e.metadata.cldoverwrite="true")})),wp.media.events.on("editor:image-update",(function(e){let t=e.image.className.split(" ");e.metadata.cldoverwrite&&-1===t.indexOf("cld-overwrite")?t.push("cld-overwrite"):!e.metadata.cldoverwrite&&t.indexOf("cld-overwrite")>=0&&delete t[t.indexOf("cld-overwrite")],e.image.className=t.join(" ")}));let e=null,t=wp.media.string.props;wp.media.string.props=function(i,n){return i.cldoverwrite&&(i.classes=["cld-overwrite"],e=!0),t(i,n)},wp.media.post=function(t,i){if("send-attachment-to-editor"===t){let t=wp.media.editor.get().state().get("selection").get(i.attachment);t.attributes.transformations&&(i.attachment.transformations=t.attributes.transformations),(i.html.indexOf("cld-overwrite")>-1||!0===e)&&(i.attachment.cldoverwrite=!0,e=null)}return wp.ajax.post(t,i)};wp.media.controller.Library;let i=wp.media.view.MediaFrame.Select,n=wp.media.view.MediaFrame.Post,s=wp.media.view.MediaFrame.ImageDetails,a=wp.media.view.MediaFrame.VideoDetails,r=wp.media.View.extend({tagName:"div",className:"cloudinary-widget",template:wp.template("cloudinary-dam"),active:!1,toolbar:null,frame:null,ready:function(){let e=this.controller,t=this.model.get("selection"),i=this.model.get("library"),n=wp.media.model.Attachment;if(CLDN.mloptions.multiple=e.options.multiple,this.cid!==this.active){if(CLDN.mloptions.inline_container="#cloudinary-dam-"+e.cid,1===t.length){var s=n.get(t.models[0].id);void 0!==s.attributes.public_id&&(CLDN.mloptions.asset={resource_id:s.attributes.public_id})}else CLDN.mloptions.asset=null;window.ml=cloudinary.openMediaLibrary(CLDN.mloptions,{insertHandler:function(s){for(let a=0;a=100&&void 0!==e.started?(this.submitButton.style.display=this.hide,this.stopButton.style.display=this.show):e.pending>0?(this.submitButton.style.display=this.show,this.stopButton.style.display=this.hide):e.processing>0?this.stopButton.style.display=this.show:this.stopButton.style.display=this.hide,e.percent<100?(this.barSyncCount.innerText=e.total,this.progressCount.innerText=e.done,this.progress.style.display=this.show):(this.completed.style.display=this.show,this.progress.style.display=this.hide)},_start:function(e){e.preventDefault(),a.stopButton.style.display=a.show,a.submitButton.style.display=a.hide,a.pushAttachments()},_reset:function(e){a.submitButton.style.display=a.hide,a.getStatus()},_init:function(e){"undefined"!=typeof cloudinaryApi&&((document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?e():document.addEventListener("DOMContentLoaded",e))}};var r=a;a._init((function(){a._reset(),a.submitButton.addEventListener("click",a._start),a.stopButton.addEventListener("click",a.stopSync)}));var o=i(1),l=i.n(o);const d={sample:{image:document.getElementById("transformation-sample-image"),video:document.getElementById("transformation-sample-video")},preview:{image:document.getElementById("sample-image"),video:document.getElementById("sample-video")},fields:document.getElementsByClassName("cld-field"),button:{image:document.getElementById("refresh-image-preview"),video:document.getElementById("refresh-video-preview")},spinner:{image:document.getElementById("image-loader"),video:document.getElementById("video-loader")},activeItem:null,elements:{image:[],video:[]},_placeItem:function(e){null!==e&&(e.style.display="block",e.style.visibility="visible",e.style.position="absolute",e.style.top=e.parentElement.clientHeight/2-e.clientHeight/2+"px",e.style.left=e.parentElement.clientWidth/2-e.clientWidth/2+"px")},_setLoading:function(e){this.button[e].style.display="block",this._placeItem(this.button[e]),this.preview[e].style.opacity="0.1"},_build:function(e){this.sample[e].innerHTML="",this.elements[e]=[];for(let t of this.fields){if(e!==t.dataset.context)continue;let i=t.value.trim();if(i.length){if("select-one"===t.type){if("none"===i)continue;i=t.dataset.meta+"_"+i}else{let e=t.dataset.context;i=this._transformations(i,e,!0)}i&&this.elements[e].push(i)}}let t="";this.elements[e].length&&(t="/"+this.elements[e].join(",").replace(/ /g,"%20")),this.sample[e].textContent=t,this.sample[e].parentElement.href="https://res.cloudinary.com/demo/"+this.sample[e].parentElement.innerText.trim().replace("../","").replace(/ /g,"%20")},_clearLoading:function(e){this.spinner[e].style.visibility="hidden",this.activeItem=null,this.preview[e].style.opacity=1},_refresh:function(e,t){e&&e.preventDefault();let i=this,n=CLD_GLOBAL_TRANSFORMATIONS[t].preview_url+i.elements[t].join(",")+CLD_GLOBAL_TRANSFORMATIONS[t].file;if(this.button[t].style.display="none",this._placeItem(this.spinner[t]),"image"===t){let e=new Image;e.onload=function(){i.preview[t].src=this.src,i._clearLoading(t),e.remove()},e.onerror=function(){alert(CLD_GLOBAL_TRANSFORMATIONS[t].error),i._clearLoading(t)},e.src=n}else{let e=i._transformations(i.elements[t].join(","),t);samplePlayer.source({publicId:"dog",transformation:e}),i._clearLoading(t)}},_transformations:function(e,t,i=!1){let n=CLD_GLOBAL_TRANSFORMATIONS[t].valid_types,s=null,a=e.split("/"),r=[];for(let e=0;e{const n=!!i.length&&jQuery('[data-item="'+s+":"+i[0].id+'"]');n.length?n.remove():(jQuery(`.cld-tax-order-list-item:contains(${r})`).remove(),--e.startId),this.processTags(t)})}),jQuery("body").on("change",".selectit input",(function(){const t=jQuery(this),i=t.val(),n=t.is(":checked"),s=t.parent().text().trim();!0===n?e.tags.find(`[data-item="category:${i}"]`).length||e._pushItem(`category:${i}`,s):e.tags.find(`[data-item="category:${i}"]`).remove()}))},_createItem:function(e,t){const i=jQuery("
  • "),n=jQuery(""),s=jQuery("");return i.addClass("cld-tax-order-list-item").attr("data-item",e),s.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(e),n.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),i.append(n).append(t).append(s),i},_pushItem:function(e,t){let i=this._createItem(e,t);this.tags.append(i)},_sortable:function(){jQuery(".cld-tax-order-list").sortable({connectWith:".cld-tax-order",axis:"y",handle:".cld-tax-order-list-item-handle",placeholder:"cld-tax-order-list-item-placeholder",forcePlaceholderSize:!0,helper:"clone"})}};if(void 0!==window.CLDN&&(u._init(),jQuery("[data-wp-lists] .selectit input[checked]").map((e,t)=>{jQuery(t).trigger("change")})),wp.data&&wp.data.select("core/editor")){const e={};wp.data.subscribe((function(){let t=wp.data.select("core").getTaxonomies();if(t)for(let i in t){const n=wp.data.select("core/editor").getEditedPostAttribute(t[i].rest_base);e[t[i].slug]=n}}));const t=wp.element.createElement,i=i=>{class n extends i{constructor(e){super(e),this.currentItems=jQuery(".cld-tax-order-list-item").map((e,t)=>jQuery(t).data("item")).get()}makeItem(e){if(this.currentItems.includes(this.getId(e)))return;const t=this.makeElement(e);jQuery("#cld-tax-items").append(t)}removeItem(e){const t=jQuery(`[data-item="${this.getId(e)}"]`);t.length&&(t.remove(),this.currentItems=this.currentItems.filter(t=>t!==this.getId(e)))}findOrCreateTerm(e){return(e=super.findOrCreateTerm(e)).then(e=>this.makeItem(e)),e}onChange(t){super.onChange(t);const i=this.pickItem(t);i&&(e[this.props.slug].includes(i.id)?this.makeItem(i):this.removeItem(i))}pickItem(e){if("object"==typeof e){if(e.target){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===parseInt(e.target.value))return this.state.availableTerms[t]}else if(Array.isArray(e)){let t=this.state.selectedTerms.filter(t=>!e.includes(t))[0];return void 0===t&&(t=e.filter(e=>!this.state.selectedTerms.includes(e))[0]),this.state.availableTerms.find(e=>e.name===t)}}else if("number"==typeof e){for(let t in this.state.availableTerms)if(this.state.availableTerms[t].id===e)return this.state.availableTerms[t]}else{let t;if(e.length>this.state.selectedTerms.length)for(let i in e)-1===this.state.selectedTerms.indexOf(e[i])&&(t=e[i]);else for(let i in this.state.selectedTerms)-1===e.indexOf(this.state.selectedTerms[i])&&(t=this.state.selectedTerms[i]);for(let e in this.state.availableTerms)if(this.state.availableTerms[e].name===t)return this.state.availableTerms[e]}}getId(e){return`${this.props.slug}:${e.id}`}makeElement(e){const t=jQuery("
  • "),i=jQuery(""),n=jQuery("");return t.addClass("cld-tax-order-list-item").attr("data-item",this.getId(e)),n.addClass("cld-tax-order-list-item-input").attr("type","hidden").attr("name","cld_tax_order[]").val(this.getId(e)),i.addClass("dashicons dashicons-menu cld-tax-order-list-item-handle"),t.append(i).append(e.name).append(n),t}}return e=>t(n,e)};wp.hooks.addFilter("editor.PostTaxonomyType","cld",i)}var p=u;const m={wpWrap:document.getElementById("wpwrap"),wpContent:document.getElementById("wpbody-content"),libraryWrap:document.getElementById("cloudinary-embed"),_init:function(){let e=this;"undefined"!=typeof CLD_ML&&(cloudinary.openMediaLibrary(CLD_ML.mloptions,{insertHandler:function(e){alert("Import is not yet implemented.")}}),window.addEventListener("resize",(function(t){e._resize()})),e._resize())},_resize:function(){let e=getComputedStyle(this.wpContent);this.libraryWrap.style.height=this.wpWrap.offsetHeight-parseInt(e.getPropertyValue("padding-bottom"))+"px"}};var h=m;m._init();i(2);i.d(t,"cloudinary",(function(){return f}));window.$=window.jQuery;const f={settings:s.a,sync:r,widget:l.a,Global_Transformations:c,Terms_Order:p,Media_Library:h}}]); \ No newline at end of file From 3d5fc9f03938fbc1413f050bc25f62f35b8d637f Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Fri, 24 Apr 2020 12:26:41 +0100 Subject: [PATCH 27/58] Bypass updating the attachment URL on admin --- .../php/class-media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index 5d5d1366b..9aa9299ae 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -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' ) ) { + 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 ); From bbb6fba62e68919cefb4e68273cc8528959c290f Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 24 Apr 2020 13:30:39 +0200 Subject: [PATCH 28/58] add notice handling and ui on dashboard. --- .../php/class-connect.php | 90 +++++++++++++++---- .../ui-definitions/tabs/dashboard-content.php | 29 +++++- 2 files changed, 96 insertions(+), 23 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 5a9dd1f83..645a399e3 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -61,6 +61,13 @@ class Connect implements Config, Setup, Notice { */ public $handle; + /** + * Holder of general notices. + * + * @var array + */ + protected $notices = array(); + /** * Initiate the plugin resources. * @@ -119,30 +126,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; @@ -152,6 +159,7 @@ public function verify_connection( $data ) { if ( ! empty( $result['message'] ) ) { add_settings_error( 'cloudinary_connect', $result['type'], $result['message'], 'error' ); + return $current; } @@ -304,7 +312,6 @@ public function setup() { } } $this->usage = $stats; - } } @@ -335,7 +342,7 @@ public function get_config() { } $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'] ); @@ -353,16 +360,61 @@ public function get_config() { return $signature; } + /** + * Set usage notices if limits are towards higher end. + */ + public function usage_notices() { + if ( ! empty( $this->usage ) ) { + foreach ( $this->usage as $stat => $values ) { + if ( ! is_array( $values ) || ! isset( $values['used_percent'] ) || $values['used_percent'] <= 0 ) { + continue; + } + if ( $values['used_percent'] >= 1 ) { + $link = null; + $link_text = null; + if ( 90 <= $values['used_percent'] ) { + // 90% used - show error. + $level = 'error'; + $link = 'https://cloudinary.com/console/lui/upgrade_options'; + $link_text = __( 'Upgrade Plan' ); + } elseif ( 80 <= $values['used_percent'] ) { + $level = 'warning'; + } elseif ( 70 <= $values['used_percent'] ) { + $level = 'neutral'; + } else { + continue; + } + // translators: Placeholders are URLS and percentage values. + $message = sprintf( + __( + ' Cloudinary Quota: %1$s at %2$s %4$s', + 'cloudinary' + ), + ucwords( $stat ), + $values['used_percent'] . '%', + $link, + $link_text + ); + $this->notices[] = array( + 'message' => $message, + 'type' => $level, + 'dismissible' => false, + ); + } + } + } + } + /** * Get admin notices. */ public function get_notices() { - $screen = get_current_screen(); - $notices = array(); + $this->usage_notices(); + $screen = get_current_screen(); if ( empty( $this->plugin->config['connect'] ) ) { if ( is_object( $screen ) && in_array( $screen->id, $this->plugin->components['settings']->handles, true ) ) { - $link = '' . __( 'Connect', 'cloudinary' ) . ' '; - $notices[] = array( + $link = '' . __( 'Connect', 'cloudinary' ) . ' '; + $this->notices[] = array( 'message' => $link . __( 'your Cloudinary account with WordPress to get started.', 'cloudinary' ), 'type' => 'error', 'dismissible' => true, @@ -370,7 +422,7 @@ public function get_notices() { } } - return $notices; + return $this->notices; } } diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php index 2137dbeba..4bad4aab6 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php @@ -6,7 +6,7 @@ */ $video_url = ''; // Left blank for when we get the final video URL. - +$usage = $this->plugin->components['connect']->usage; ?>
    @@ -27,6 +27,27 @@
    +
    +
    + | + + + | + + + + | + + + + + +
    +
    +
    + + +
    @@ -59,8 +80,8 @@
    From 63224dd52885d4b15f0d8efb1ecdf9cff7423b60 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Fri, 24 Apr 2020 16:43:59 +0100 Subject: [PATCH 29/58] Set default for enabled_breakpoints setting --- .../tabs/settings-global-transformations.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-global-transformations.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-global-transformations.php index 4bba414ce..77f96bed7 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-global-transformations.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/settings-global-transformations.php @@ -19,9 +19,10 @@ 'label' => __( 'Responsive Image Settings', 'cloudinary' ), ), 'enable_breakpoints' => array( - 'label' => __( 'Enable Breakpoints', 'cloudinary' ), - 'suffix' => __( 'Enable breakpoint generation on upload.', 'cloudinary' ), - 'type' => 'checkbox', + 'label' => __( 'Enable Breakpoints', 'cloudinary' ), + 'suffix' => __( 'Enable breakpoint generation on upload.', 'cloudinary' ), + 'type' => 'checkbox', + 'default' => 'off', ), 'breakpoints' => array( 'label' => __( 'Max breakpoints', 'cloudinary' ), From 9131d93df96adb212b3d4ff3b2351bf4d8081aeb Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Fri, 24 Apr 2020 16:44:20 +0100 Subject: [PATCH 30/58] Confirm that $intermediate is an array --- .../php/class-media.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index f91414f2a..6bae12a0e 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -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 ); + } } /** From e4a6f6a51a730e3e2f80cad8bc2247528757b086 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Fri, 24 Apr 2020 16:44:32 +0100 Subject: [PATCH 31/58] Initialize variable --- .../php/sync/class-push-sync.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index a1a9ae025..254e2e577 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -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 ) ) { @@ -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 { From 687d3f36710ef6bf626f9d85e40fb40747313b63 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sat, 25 Apr 2020 07:25:16 +0200 Subject: [PATCH 32/58] improve consistancey on meta and allow switching between account types --- .../php/class-connect.php | 148 +++++++++++------- .../php/class-media.php | 6 +- .../php/sync/class-push-sync.php | 6 +- .../php/sync/class-upload-sync.php | 4 +- .../ui-definitions/tabs/dashboard-content.php | 36 ++++- 5 files changed, 130 insertions(+), 70 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 645a399e3..97706257e 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -68,6 +68,19 @@ class Connect implements Config, Setup, Notice { */ protected $notices = array(); + /** + * Holds the meta keys for connect meta to maintain consistency. + */ + const META_KEYS = array( + 'usage' => '_cloudinary_usage', + 'last_usage' => '_cloudinary_last_usage', + 'signature' => 'cloudinary_connection_signature', + 'version' => 'cloudinary_version', + 'url' => 'cloudinary_url', + 'connect' => 'cloudinary_connect', + 'cache' => 'cloudinary_settings_cache', + ); + /** * Initiate the plugin resources. * @@ -124,7 +137,7 @@ public function media_library_script() { */ public function verify_connection( $data ) { if ( empty( $data['cloudinary_url'] ) ) { - delete_option( 'cloudinary_connection_signature' ); + delete_option( self::META_KEYS['signature'] ); add_settings_error( 'cloudinary_connect', @@ -164,7 +177,7 @@ public function verify_connection( $data ) { } add_settings_error( 'cloudinary_connect', 'connection_success', __( 'Successfully connected to Cloudinary.', 'cloudinary' ), 'updated' ); - update_option( 'cloudinary_connection_signature', md5( $data['cloudinary_url'] ) ); + update_option( self::META_KEYS['signature'], md5( $data['cloudinary_url'] ) ); return $data; } @@ -221,11 +234,14 @@ function ( $a ) { } $this->config_from_url( $url ); - $test = new Connect\Api( $this, $this->plugin->version ); - $test = $test->ping(); - if ( is_wp_error( $test ) ) { + $test = new Connect\Api( $this, $this->plugin->version ); + $test_result = $test->ping(); + if ( is_wp_error( $test_result ) ) { $result['type'] = 'connection_error'; - $result['message'] = ucwords( str_replace( '_', ' ', $test->get_error_message() ) ); + $result['message'] = ucwords( str_replace( '_', ' ', $test_result->get_error_message() ) ); + } else { + $this->api = $test; + $this->usage_stats( true ); } return $result; @@ -297,22 +313,34 @@ public function setup() { // Get the cloudinary url from plugin config. $config = $this->plugin->config['settings']['connect']; if ( ! empty( $config['cloudinary_url'] ) ) { - $this->config_from_url( $config['cloudinary_url'] ); - $this->api = new Connect\Api( $this, $this->plugin->version ); - $stats = get_transient( '_cloudinary_usage' ); - if ( empty( $stats ) ) { - // Get users plan. - $stats = $this->plugin->components['connect']->api->usage(); - if ( ! is_wp_error( $stats ) && ! empty( $stats['media_limits'] ) ) { - $stats['max_image_size'] = $stats['media_limits']['image_max_size_bytes']; - $stats['max_video_size'] = $stats['media_limits']['video_max_size_bytes']; - set_transient( '_cloudinary_usage', $stats, HOUR_IN_SECONDS ); - } + $this->usage_stats( true ); + } + } + + /** + * Set the usage stats from the Cloudinary API. + * + * @param bool $refresh Flag to force a refresh. + */ + public function usage_stats( $refresh = false ) { + $stats = get_transient( self::META_KEYS['usage'] ); + if ( empty( $stats ) || true === $refresh ) { + // Get users plan. + $stats = $this->api->usage(); + if ( ! is_wp_error( $stats ) && ! empty( $stats['media_limits'] ) ) { + $stats['max_image_size'] = $stats['media_limits']['image_max_size_bytes']; + $stats['max_video_size'] = $stats['media_limits']['video_max_size_bytes']; + set_transient( self::META_KEYS['usage'], $stats, HOUR_IN_SECONDS ); + update_option( self::META_KEYS['last_usage'], $stats );// Save the last successful call to prevent crashing. + } else { + // Handle error by logging and fetching the last success. + // @todo : log issue. + $stats = get_option( self::META_KEYS['last_usage'] ); } - $this->usage = $stats; } + $this->usage = $stats; } /** @@ -323,14 +351,14 @@ public function setup() { * @return array The array of the config options stored. */ public function get_config() { - $signature = get_option( 'cloudinary_connection_signature', null ); - $version = get_option( 'cloudinary_version' ); + $signature = get_option( self::META_KEYS['signature'], null ); + $version = get_option( self::META_KEYS['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 ); + $cld_url = get_option( self::META_KEYS['url'], null ); if ( null === $cld_url ) { // Post V1. - $data = get_option( 'cloudinary_connect', array() ); + $data = get_option( self::META_KEYS['connect'], array() ); if ( ! isset( $data['cloudinary_url'] ) || empty( $data['cloudinary_url'] ) ) { return null; // return null to indicate not valid. } @@ -349,10 +377,10 @@ public function get_config() { // remove filters as we've already verified it and 'add_settings_error()' isin't available yet. remove_filter( 'pre_update_option_cloudinary_connect', array( $this, 'verify_connection' ) ); - update_option( 'cloudinary_connect', $data ); - update_option( 'cloudinary_connection_signature', $signature ); - update_option( 'cloudinary_version', $this->plugin->version ); - delete_option( 'cloudinary_settings_cache' ); // remove the cache. + update_option( self::META_KEYS['connect'], $data ); + update_option( self::META_KEYS['signature'], $signature ); + update_option( self::META_KEYS['version'], $this->plugin->version ); + delete_option( self::META_KEYS['cache'] ); // remove the cache. $this->plugin->config['settings']['connect'] = $data; // Set the connection url for this round. } } @@ -365,42 +393,46 @@ 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['used_percent'] ) || $values['used_percent'] <= 0 ) { + + if ( ! is_array( $values ) || ! isset( $values[ $usage_type ] ) || 0 > $values[ $usage_type ] ) { continue; } - if ( $values['used_percent'] >= 1 ) { - $link = null; - $link_text = null; - if ( 90 <= $values['used_percent'] ) { - // 90% used - show error. - $level = 'error'; - $link = 'https://cloudinary.com/console/lui/upgrade_options'; - $link_text = __( 'Upgrade Plan' ); - } elseif ( 80 <= $values['used_percent'] ) { - $level = 'warning'; - } elseif ( 70 <= $values['used_percent'] ) { - $level = 'neutral'; - } else { - continue; - } - // translators: Placeholders are URLS and percentage values. - $message = sprintf( - __( - ' Cloudinary Quota: %1$s at %2$s %4$s', - 'cloudinary' - ), - ucwords( $stat ), - $values['used_percent'] . '%', - $link, - $link_text - ); - $this->notices[] = array( - 'message' => $message, - 'type' => $level, - 'dismissible' => false, - ); + + $link = null; + $link_text = null; + if ( 90 <= $values[ $usage_type ] ) { + // 90% used - show error. + $level = 'error'; + $link = 'https://cloudinary.com/console/lui/upgrade_options'; + $link_text = __( 'Upgrade Plan' ); + } elseif ( 80 <= $values[ $usage_type ] ) { + $level = 'warning'; + } elseif ( 70 <= $values[ $usage_type ] ) { + $level = 'neutral'; + } else { + continue; } + // translators: Placeholders are URLS and percentage values. + $message = sprintf( + __( + ' Cloudinary Quota: %1$s at %2$s %4$s', + 'cloudinary' + ), + ucwords( $stat ), + $values[ $usage_type ] . '%', + $link, + $link_text + ); + $this->notices[] = array( + 'message' => $message, + 'type' => $level, + 'dismissible' => false, + ); } } } diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index f91414f2a..9f0233445 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -1078,9 +1078,9 @@ public function media_column_value( $column_name, $attachment_id ) { if ( false === $this->cloudinary_id( $attachment_id ) ) { // If false, lets check why by seeing if the file size is too large. $file = get_attached_file( $attachment_id ); // Get the file size to make sure it can exist in cloudinary. - $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); - if ( file_exists( $file ) && filesize( $file ) > $this->plugin->components['connect']->usage[ $max_size ] ) { - $max_size_hr = size_format( $this->plugin->components['connect']->usage[ $max_size ] ); + $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'image_max_size_bytes' : 'video_max_size_bytes' ); + if ( file_exists( $file ) && filesize( $file ) > $this->plugin->components['connect']->usage['media_limits'][ $max_size ] ) { + $max_size_hr = size_format( $this->plugin->components['connect']->usage['media_limits'][ $max_size ] ); // translators: variable is file size. $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'; diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index a1a9ae025..2c63aba0a 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -356,10 +356,10 @@ public function prepare_upload( $post, $down_sync = false ) { } $resource_type = $this->get_resource_type( $post ); - $max_size = ( 'image' === $resource_type ? 'max_image_size' : 'max_video_size' ); + $max_size = ( 'image' === $resource_type ? 'image_max_size_bytes' : 'video_max_size_bytes' ); - if ( $file_size > $this->plugin->components['connect']->usage[ $max_size ] ) { - $max_size_hr = size_format( $this->plugin->components['connect']->usage[ $max_size ] ); + if ( $file_size > $this->plugin->components['connect']->usage['media_limits'][ $max_size ] ) { + $max_size_hr = size_format( $this->plugin->components['connect']->usage['media_limits'][ $max_size ] ); // translators: variable is file size. $error = sprintf( __( 'File size exceeds the maximum of %s. This media asset will be served from WordPress.', 'cloudinary' ), $max_size_hr ); $this->plugin->components['media']->delete_post_meta( $post->ID, Sync::META_KEYS['pending'] ); // Remove Flag. diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php index 2c4bc7f62..140b91876 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php @@ -114,10 +114,10 @@ public function prep_on_demand_upload( $cloudinary_id, $attachment_id ) { if ( $attachment_id && false === $cloudinary_id ) { // Check that this has not already been prepared for upload. if ( ! $this->is_pending( $attachment_id ) && apply_filters( 'cloudinary_on_demand_sync_enabled', $this->enabled ) ) { - $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); + $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'image_max_size_bytes' : 'video_max_size_bytes' ); $file = get_attached_file( $attachment_id ); // Get the file size to make sure it can exist in cloudinary. - if ( file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { + if ( file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage['media_limits'][ $max_size ] ) { $this->add_to_sync( $attachment_id ); } else { // Check if the src is a url. diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php index 4bad4aab6..71233db23 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php @@ -7,6 +7,27 @@ $video_url = ''; // Left blank for when we get the final video URL. $usage = $this->plugin->components['connect']->usage; +// Different account version have usage limits. +if ( isset( $usage['credits'] ) ) { + // New credit system. + $usage['credits'] = array( + 'limit' => $usage['credits']['limit'], + 'used_percent' => $usage['credits']['used_percent'], + ); + $usage['storage'] = array( + 'limit' => $usage['storage']['usage'], + 'used_percent' => $usage['storage']['credits_usage'], + ); + $usage['transformations'] = array( + 'limit' => $usage['transformations']['usage'], + 'used_percent' => $usage['transformations']['credits_usage'], + ); + $usage['bandwidth'] = array( + 'limit' => $usage['bandwidth']['usage'], + 'used_percent' => $usage['bandwidth']['credits_usage'], + ); +} + ?>
    @@ -30,15 +51,22 @@
    | - + + + + | + + + + | - + | - + @@ -53,7 +81,7 @@
    Image or Video Settings.', 'cloudinary' From 5526d0e9bc91859b38cce6bd5c4635848b9a6d19 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sat, 25 Apr 2020 07:28:34 +0200 Subject: [PATCH 33/58] clean up video js error --- .../ui-definitions/tabs/dashboard-content.php | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php index 71233db23..1e3ab94f7 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php @@ -28,6 +28,16 @@ ); } +$manage_text = sprintf( + // translators: Placeholders are URLS. + __( + 'Manage Image or Video Settings.', + 'cloudinary' + ), + 'admin.php?page=cld_global_transformation', + 'admin.php?page=cld_global_transformation&tab=global_video_transformations' +); + ?>
    @@ -79,25 +89,14 @@
    - Image or Video Settings.', - 'cloudinary' - ), - 'admin.php?page=cld_global_transformation', - 'admin.php?page=cld_global_transformation&tab=global_video_transformations' - ); - - // Video Player for dashboard. - $player = array(); - $player[] = 'var cld = cloudinary.Cloudinary.new({ cloud_name: \'demo\' });'; - $player[] = 'var samplePlayer = cld.videoPlayer(\'dashboard-player\', { fluid : true } );'; - wp_add_inline_script( 'cld-player', implode( $player ) ); - - ?> +

    From 93f7dcd27d4ec9ebf273f844fb25df84f47fce60 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 27 Apr 2020 06:04:53 +0200 Subject: [PATCH 34/58] update version --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index fb8992f19..c1f9da00d 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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+ From 24abd9c51bd38e3ac34ef8625c3e69c3702e51f0 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 30 Apr 2020 10:36:03 +0100 Subject: [PATCH 35/58] Prevent warnings when variable type does not match the expectation --- .../php/connect/class-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php index bad5c3d94..75c0bbb27 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php @@ -186,6 +186,9 @@ public static function generate_transformation_string( array $options, $type = ' $transformations = array_map( function ( $item ) use ( $transformation_index ) { $transform = array(); + if ( is_string ( $item ) ) { + return $item; + } foreach ( $item as $type => $value ) { // phpcs:ignore $key = array_search( $type, $transformation_index, true ); if ( 'wpsize' === $type ) { @@ -241,7 +244,7 @@ public function cloudinary_url( $public_id, $args = array(), $size = array(), $c $url_parts[] = self::generate_transformation_string( $args['transformation'] ); } // Add size. - if ( ! empty( $size ) ) { + if ( ! empty( $size ) && is_array( $size ) ) { if ( true === $clean ) { $size['clean'] = true; } From 78bc23e76bed25413488a029cd6529ddfa88a60d Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 5 May 2020 16:57:32 +0200 Subject: [PATCH 36/58] version bump --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index c1f9da00d..6867039ec 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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.5 + * Version: 2.0.6 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 0cfbe8445c9b890532a8f2fa7d26cbb85409135c Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 8 May 2020 09:22:32 +0200 Subject: [PATCH 37/58] make method to get stat value. --- .../php/class-connect.php | 28 ++++++++++++ .../ui-definitions/tabs/dashboard-content.php | 44 +++++-------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 97706257e..f2f5aadd1 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -343,6 +343,34 @@ public function usage_stats( $refresh = false ) { $this->usage = $stats; } + /** + * Get a usage stat for display. + * + * @param string $type The type of stat to get. + * @param string|null $stat The stat to get. + * + * @return bool|string + */ + public function get_usage_stat( $type, $stat = null ) { + $value = false; + if ( isset( $this->usage[ $type ] ) ) { + if ( is_string( $this->usage[ $type ] ) ) { + $value = $this->usage[ $type ]; + } elseif ( is_array( $this->usage[ $type ] ) && isset( $this->usage[ $type ][ $stat ] ) ) { + $value = $this->usage[ $type ][ $stat ]; + } elseif ( is_array( $this->usage[ $type ] ) ) { + + 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']; + } + } + } + + return $value; + } + /** * Gets the config of a connection. * diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php index 1e3ab94f7..1916d3322 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php @@ -5,28 +5,8 @@ * @package Cloudinary */ -$video_url = ''; // Left blank for when we get the final video URL. -$usage = $this->plugin->components['connect']->usage; -// Different account version have usage limits. -if ( isset( $usage['credits'] ) ) { - // New credit system. - $usage['credits'] = array( - 'limit' => $usage['credits']['limit'], - 'used_percent' => $usage['credits']['used_percent'], - ); - $usage['storage'] = array( - 'limit' => $usage['storage']['usage'], - 'used_percent' => $usage['storage']['credits_usage'], - ); - $usage['transformations'] = array( - 'limit' => $usage['transformations']['usage'], - 'used_percent' => $usage['transformations']['credits_usage'], - ); - $usage['bandwidth'] = array( - 'limit' => $usage['bandwidth']['usage'], - 'used_percent' => $usage['bandwidth']['credits_usage'], - ); -} +$video_url = ''; // Left blank for when we get the final video URL. +$connection = $this->plugin->components['connect']; $manage_text = sprintf( // translators: Placeholders are URLS. @@ -60,25 +40,25 @@

    - | - + get_usage_stat( 'plan' ) ); ?> | + get_usage_stat( 'credits', 'limit' ) ) : ?> - - | + get_usage_stat( 'credits', 'limit' ) ) ); ?> + get_usage_stat( 'credits', 'used_percent' ) . '%' ); ?> | - - | + get_usage_stat( 'storage', 'limit' ) ) ); ?> + get_usage_stat( 'storage', 'used_percent' ) . '%' ); ?> | - - | + get_usage_stat( 'transformations', 'limit' ) ) ); ?> + get_usage_stat( 'transformations', 'used_percent' ) . '%' ); ?> | - - + get_usage_stat( 'bandwidth', 'limit' ) ) ); ?> + get_usage_stat( 'bandwidth', 'used_percent' ) . '%' ); ?>

    From 20399d25ff9c18779b44fa8dd1fb3c10ba714bd4 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 13 May 2020 15:20:42 +0100 Subject: [PATCH 38/58] Fix a if condition that could stop a listing page. See CLOUD 409. --- .../php/sync/class-delete-sync.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php index 4a85cc520..0d8c4f817 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-delete-sync.php @@ -65,7 +65,8 @@ public function can_delete_asset( $all_caps, $caps, $args ) { $has_error = $this->plugin->components['media']->get_post_meta( $post_id, Sync::META_KEYS['sync_error'], true ); if ( empty( $has_error ) ) { $all_caps['delete_posts'] = false; - if ( filter_input( INPUT_GET, 'action', FILTER_DEFAULT ) ) { + $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING ); + if ( ! empty( $action ) && '-1' !== $action ) { wp_die( esc_html__( 'Sorry, you can’t delete an asset until it has fully synced with Cloudinary. Try again once syncing is complete.', 'cloudinary' ) ); } } From 547645e94a975d848439253a9e8a3235016c384c Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 14 May 2020 17:33:44 +0100 Subject: [PATCH 39/58] Replace the bulk sync status feedback script --- .../js/src/components/sync.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/sync.js b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/sync.js index 941580985..e08df5416 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/sync.js +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/js/src/components/sync.js @@ -4,11 +4,10 @@ const Sync = { progress: document.getElementById( 'progress-wrapper' ), submitButton: document.getElementById( 'submit' ), stopButton: document.getElementById( 'stop-sync' ), - progressCount: document.getElementById( 'sync-progress' ), - barSyncCount: document.getElementById( 'sync-total' ), completed: document.getElementById( 'completed-notice' ), show: 'inline-block', hide: 'none', + isRunning: false, getStatus: function getStatus() { var self = this, resourceType = [], @@ -22,8 +21,9 @@ const Sync = { request.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce ); }, } ).done( function( data ) { - if ( data.done < data.total ) { - setTimeout( Sync.getStatus, 2000 ); + Sync.isRunning = data.is_running; + if ( Sync.isRunning ) { + setTimeout( Sync.getStatus, 10000 ); } Sync._updateUI( data ); } ); @@ -32,6 +32,8 @@ const Sync = { var self = this, url = cloudinaryApi.restUrl + 'cloudinary/v1/sync'; + Sync.isRunning = false; + wp.ajax.send( { url: url, data: { @@ -48,11 +50,16 @@ const Sync = { var self = this, url = cloudinaryApi.restUrl + 'cloudinary/v1/sync'; + Sync.isRunning = true; + Sync.progress.style.display = Sync.show; + wp.ajax.send( { url: url, beforeSend: function( request ) { request.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce ); }, + } ).done( function ( data ) { + setTimeout( Sync.getStatus, 10000 ); } ); }, _updateUI: function _updateUI( data ) { @@ -75,13 +82,14 @@ const Sync = { this.stopButton.style.display = this.hide; } - if ( data.percent < 100 ) { - this.barSyncCount.innerText = data.total; - this.progressCount.innerText = data.done; + if ( data.percent === 100 ) { + this.completed.style.display = this.show; + } + + if ( this.isRunning ) { this.progress.style.display = this.show; } else { - this.completed.style.display = this.show; this.progress.style.display = this.hide; } }, From e41b014e9d7e21b578779899c8540bca5ef8e78d Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 14 May 2020 17:34:16 +0100 Subject: [PATCH 40/58] Improve consistency --- .../php/sync/class-upload-queue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php index 6d0b77683..9260630ba 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php @@ -37,7 +37,7 @@ class Upload_Queue { * * @var bool */ - private $running = null; + private $running = false; /** * Upload_Queue constructor. @@ -127,7 +127,7 @@ public function mark( $id, $type = 'done' ) { * @return bool */ public function is_running() { - if ( null === $this->running ) { + if ( false === $this->running ) { $queue = $this->get_queue(); $this->running = empty( $queue['started'] ) ? false : true; } From c79963d10cc56e3906d14c01a97db44d1846c997 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 14 May 2020 17:34:47 +0100 Subject: [PATCH 41/58] Add running flag to the REST response --- .../php/sync/class-upload-queue.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php index 9260630ba..e76dbedae 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php @@ -175,6 +175,8 @@ public function get_queue_status() { $this->stop_queue(); } + $return['is_running'] = $this->is_running(); + return $return; } From c9d6735f551368ab323e2ce2bc103ccf6f40c96c Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 14 May 2020 17:35:04 +0100 Subject: [PATCH 42/58] Add loading icon --- .../css/loading.svg | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/loading.svg diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/loading.svg b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/loading.svg new file mode 100644 index 000000000..0cf4e763f --- /dev/null +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/loading.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + From f06bcea4a3f3689d86769babd73a90bf5725d261 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 14 May 2020 17:35:37 +0100 Subject: [PATCH 43/58] Replace the out of status by the simple syncing icon --- .../ui-definitions/tabs/sync-media-footer.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php index 509472490..6bbf1d7c8 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php @@ -26,7 +26,10 @@ - / + + <?php esc_attr_e( 'Syncing…', 'cloudinary' ); ?> + +
    From f696a047c48df67c12551c3f82bc798008bfb185 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Tue, 19 May 2020 12:31:27 +0200 Subject: [PATCH 44/58] update texts and remove forced reload. --- .../php/class-connect.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index 7a2e9b50e..90b15c803 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -315,7 +315,7 @@ public function setup() { if ( ! empty( $config['cloudinary_url'] ) ) { $this->config_from_url( $config['cloudinary_url'] ); $this->api = new Connect\Api( $this, $this->plugin->version ); - $this->usage_stats( true ); + $this->usage_stats(); } } @@ -448,18 +448,20 @@ public function usage_notices() { // 90% used - show error. $level = 'error'; $link = 'https://cloudinary.com/console/lui/upgrade_options'; - $link_text = __( 'Upgrade Plan' ); + $link_text = __( 'upgrade your account', 'cloudinary' ); } elseif ( 80 <= $values[ $usage_type ] ) { $level = 'warning'; + $link_text = __( 'upgrade your account', 'cloudinary' ); } elseif ( 70 <= $values[ $usage_type ] ) { $level = 'neutral'; + $link_text = __( 'upgrade your account', 'cloudinary' ); } else { continue; } // translators: Placeholders are URLS and percentage values. $message = sprintf( __( - ' Cloudinary Quota: %1$s at %2$s %4$s', + ' You are %2$s of the way through your monthly quota for %1$s on your Cloudinary account. If you exceed your quota, the Cloudinary plugin will be deactivated until your next billing cycle and your media assets will be served from your WordPress Media Library. You may wish to %4$s and increase your quota to ensure you maintain full functionality.', 'cloudinary' ), ucwords( $stat ), From 5760d7bb47e27f74a9e33d68d565824d6a7ff173 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 19 May 2020 15:15:39 +0100 Subject: [PATCH 45/58] Update loading url --- .../ui-definitions/tabs/sync-media-footer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php index 6bbf1d7c8..63a2da3c2 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/sync-media-footer.php @@ -27,7 +27,7 @@ - <?php esc_attr_e( 'Syncing…', 'cloudinary' ); ?> + <?php esc_attr_e( 'Syncing…', 'cloudinary' ); ?> From 397ee44e5cabcf4c5dd871892203c9fa93a5d0ab Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 May 2020 10:10:16 +0100 Subject: [PATCH 46/58] Check vars before use them --- .../php/class-media.php | 5 ++++- .../php/sync/class-push-sync.php | 2 +- .../php/sync/class-upload-sync.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index cd966dc35..737e09088 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -574,7 +574,10 @@ 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 ) ) { + return false; + } + $size = $this->get_crop( $intermediate['url'], $attachment_id ); } /** diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index f69020e31..90e0b0779 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -358,7 +358,7 @@ public function prepare_upload( $post, $down_sync = false ) { $resource_type = $this->get_resource_type( $post ); $max_size = ( 'image' === $resource_type ? 'max_image_size' : 'max_video_size' ); - if ( $file_size > $this->plugin->components['connect']->usage[ $max_size ] ) { + if ( ! empty( $this->plugin->components['connect']->usage[ $max_size ] ) && $file_size > $this->plugin->components['connect']->usage[ $max_size ] ) { $max_size_hr = size_format( $this->plugin->components['connect']->usage[ $max_size ] ); // translators: variable is file size. $error = sprintf( __( 'File size exceeds the maximum of %s. This media asset will be served from WordPress.', 'cloudinary' ), $max_size_hr ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php index 2c4bc7f62..8187af545 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php @@ -117,7 +117,7 @@ public function prep_on_demand_upload( $cloudinary_id, $attachment_id ) { $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); $file = get_attached_file( $attachment_id ); // Get the file size to make sure it can exist in cloudinary. - if ( file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { + if ( ! empty( $this->plugin->components['connect']->usage[ $max_size ] ) && file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { $this->add_to_sync( $attachment_id ); } else { // Check if the src is a url. From 1fe6402b7364ff18c01b57386f736109cd23ca62 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 May 2020 10:10:38 +0100 Subject: [PATCH 47/58] Try to set SVGs size --- .../php/media/class-filter.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php index 5c2b0890a..553b4117a 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-filter.php @@ -671,6 +671,45 @@ public function filter_image_block_pre_render( $block, $source_block ) { return $block; } + /** + * Attempt to set the width and height for SVGs. + * + * @param array|false $image The image details. + * @param int $attachment_id The attachment ID. + * @param string|int[] $size The requested image size. + * + * @return array|false + */ + public function filter_svg_image_size( $image, $attachment_id, $size ) { + if ( is_array( $image ) && preg_match('/\.svg$/i', $image[0] ) && $image[1] <= 1 ) { + $image[1] = $image[2] = null; + + if ( is_array( $size ) ) { + $image[1] = $size[0]; + $image[2] = $size[1]; + } elseif ( false !== ( $xml = simplexml_load_file( $image[0] ) ) ) { + $attr = $xml->attributes(); + $viewbox = explode( ' ', $attr->viewBox ); + + // Get width + if ( isset( $attr->width ) && preg_match( '/\d+/', $attr->width, $value ) ) { + $image[1] = (int) $value[0]; + } elseif ( 4 === count( $viewbox ) ) { + $image[1] = (int) $viewbox[2]; + } + + // Get height + if ( isset( $attr->height ) && preg_match( '/\d+/', $attr->height, $value ) ) { + $image[2] = (int) $value[0]; + } elseif ( 4 === count( $viewbox ) ) { + $image[2] = (int) $viewbox[3]; + } + } + } + + return $image; + } + /** * Setup hooks for the filters. */ @@ -709,5 +748,7 @@ function ( $type ) use ( $filter ) { // Filter for block rendering. add_filter( 'render_block_data', array( $this, 'filter_image_block_pre_render' ), 10, 2 ); + // Try to get SVGs size. + add_filter( 'wp_get_attachment_image_src', array( $this, 'filter_svg_image_size' ), 10, 3 ); } } From 6572de6a848328a55df2d0c435606de45021dd15 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 May 2020 16:47:51 +0100 Subject: [PATCH 48/58] Move the queue resume to the shutdown --- .../php/sync/class-push-sync.php | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index f69020e31..8289e17cf 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -40,6 +40,13 @@ class Push_Sync { */ private $sync_types; + /** + * Holds the ID of the last attachment synced. + * + * @var int + */ + protected $post_id; + /** * Push_Sync constructor. * @@ -200,19 +207,33 @@ public function rest_push_attachments( \WP_REST_Request $request ) { if ( ! $this->plugin->components['sync']->managers['queue']->is_running() ) { // Check it wasn't stopped. return $this->rest_get_queue_status(); } - $post_id = $this->plugin->components['sync']->managers['queue']->get_post(); + + $this->post_id = $this->plugin->components['sync']->managers['queue']->get_post(); + // No post, end of queue. - if ( empty( $post_id ) ) { + if ( empty( $this->post_id ) ) { $this->plugin->components['sync']->managers['queue']->stop_queue(); return $this->rest_get_queue_status(); } + add_action( 'shutdown', array( $this, 'resume_queue' ) ); + + return $this->rest_get_queue_status(); + } + + /** + * Resume the bulk sync. + * + * @return bool|\WP_REST_Response + */ + public function resume_queue() { // Check if there is a Cloudinary ID in case this was synced on-demand before being processed by the queue. add_filter( 'cloudinary_on_demand_sync_enabled', '__return_false' ); // Disable the on-demand sync since we want the status. add_filter( 'cloudinary_id', '__return_false' ); // Disable the on-demand sync since we want the status. - if ( false === $this->plugin->components['media']->cloudinary_id( $post_id ) ) { - $stat = $this->push_attachments( array( $post_id ) ); + + if ( false === $this->plugin->components['media']->cloudinary_id( $this->post_id ) ) { + $stat = $this->push_attachments( array( $this->post_id ) ); if ( ! empty( $stat['processed'] ) ) { $result = 'done'; } else { @@ -226,8 +247,7 @@ public function rest_push_attachments( \WP_REST_Request $request ) { $result = 'done'; } - return $this->call_thread( $post_id, $result ); - + return $this->call_thread( $this->post_id, $result ); } /** @@ -246,7 +266,8 @@ private function call_thread( $last_id = null, $last_result = null ) { $params['last_id'] = $last_id; $params['last_result'] = $last_result; } - // Setup background call to cintinue the queue. + + // Setup background call to continue the queue. $this->plugin->components['api']->background_request( 'process', $params ); return $this->rest_get_queue_status(); From 7b3d9f7dc72f9c99dd939b68db36c62be6a4cb58 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 26 May 2020 17:02:19 +0100 Subject: [PATCH 49/58] Add a fallback cron job that ensures that the queue is resumed --- .../php/sync/class-upload-queue.php | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php index 6d0b77683..c21f4391a 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php @@ -39,6 +39,20 @@ class Upload_Queue { */ private $running = null; + /** + * The cron frequency to ensure that the queue is progressing. + * + * @var int + */ + protected $cron_frequency; + + /** + * The cron offset since the last update. + * + * @var int + */ + protected $cron_start_offset; + /** * Upload_Queue constructor. * @@ -46,6 +60,20 @@ class Upload_Queue { */ public function __construct( \Cloudinary\Plugin $plugin ) { $this->plugin = $plugin; + + $this->cron_frequency = apply_filters( 'cloudinary_cron_frequency', 600 ); + $this->cron_start_offset = apply_filters( 'cloudinary_cron_start_offset', 60 ); + + $this->load_hooks(); + } + + /** + * Load the Upload Queue hooks. + * + * @return void + */ + public function load_hooks() { + add_action( 'cloudinary_resume_queue', array( $this, 'maybe_resume_queue' ) ); } /** @@ -85,6 +113,7 @@ public function get_post() { if ( ! empty( $queue['pending'] ) ) { $id = array_shift( $queue['pending'] ); $queue['processing'][] = $id; + $queue['last_update'] = current_time( 'timestamp' ); $this->set_queue( $queue ); } } @@ -209,7 +238,6 @@ public function build_queue() { // Transform attachments. $return = array( 'pending' => array(), - 'large' => array(), 'done' => array(), 'processing' => array(), 'error' => array(), @@ -233,17 +261,41 @@ public function stop_queue() { $this->set_queue( $queue ); } $this->running = false; - } + wp_clear_scheduled_hook( 'cloudinary_resume_queue' ); + } /** - * Startthe queue by setting the started flag. + * Start the queue by setting the started flag. + * + * @return void */ public function start_queue() { $queue = $this->get_queue(); - $queue['started'] = current_time( 'timestamp' ); + $queue['started'] = $queue['last_update'] = current_time( 'timestamp' ); $this->set_queue( $queue ); $this->running = true; + + if ( ! wp_next_scheduled( 'cloudinary_resume_queue' ) ) { + wp_schedule_single_event( time() + $this->cron_frequency, 'cloudinary_resume_queue' ); + } } + /** + * Maybe resume the queue. + * This is a fallback mechanism to resume the queue when it stops unexpectedly. + * + * @return void + */ + public function maybe_resume_queue() { + $now = current_time( 'timestamp' ); + $queue = $this->get_queue(); + + + if ( $now - $queue['last_update'] > $this->cron_start_offset ) { + $this->plugin->components['api']->background_request( 'process', array() ); + } + + wp_schedule_single_event( $now + $this->cron_frequency, 'cloudinary_resume_queue' ); + } } From 1a9d9fd5ef17388b63dfb3e96eca59129870022e Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 27 May 2020 14:14:54 +0100 Subject: [PATCH 50/58] Use constants for better readability --- .../php/sync/class-upload-queue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php index c21f4391a..e1b86e5a9 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php @@ -61,8 +61,8 @@ class Upload_Queue { public function __construct( \Cloudinary\Plugin $plugin ) { $this->plugin = $plugin; - $this->cron_frequency = apply_filters( 'cloudinary_cron_frequency', 600 ); - $this->cron_start_offset = apply_filters( 'cloudinary_cron_start_offset', 60 ); + $this->cron_frequency = apply_filters( 'cloudinary_cron_frequency', 10 * MINUTE_IN_SECONDS ); + $this->cron_start_offset = apply_filters( 'cloudinary_cron_start_offset', MINUTE_IN_SECONDS ); $this->load_hooks(); } From 24990f40747f325633d584069a1e0fe72a581d2c Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 27 May 2020 14:16:21 +0100 Subject: [PATCH 51/58] Check if the queue is running --- .../php/sync/class-upload-queue.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php index e1b86e5a9..a6599fe99 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-queue.php @@ -291,8 +291,7 @@ public function maybe_resume_queue() { $now = current_time( 'timestamp' ); $queue = $this->get_queue(); - - if ( $now - $queue['last_update'] > $this->cron_start_offset ) { + if ( $now - $queue['last_update'] > $this->cron_start_offset && $this->is_running() ) { $this->plugin->components['api']->background_request( 'process', array() ); } From 1ea3f83f481b8bd6825c5d6753bc67151aed40a5 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 29 May 2020 14:57:40 +0200 Subject: [PATCH 52/58] bump version --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index 6867039ec..160324658 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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.6 + * Version: 2.0.9 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 0e0bded8eaa438033d8c4e1d3158f9b26ea1fad5 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sun, 31 May 2020 12:29:28 +0200 Subject: [PATCH 53/58] typo on size key --- .../php/sync/class-upload-sync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php index 967549e1c..11377b172 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-upload-sync.php @@ -202,7 +202,7 @@ public function prep_on_demand_upload( $cloudinary_id, $attachment_id ) { if ( $attachment_id && false === $cloudinary_id ) { // Check that this has not already been prepared for upload. if ( ! $this->is_pending( $attachment_id ) && apply_filters( 'cloudinary_on_demand_sync_enabled', $this->enabled ) ) { - $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'image_max_size_bytes' : 'video_max_size_bytes' ); + $max_size = ( wp_attachment_is_image( $attachment_id ) ? 'max_image_size' : 'max_video_size' ); $file = get_attached_file( $attachment_id ); // Get the file size to make sure it can exist in cloudinary. if ( ! empty( $this->plugin->components['connect']->usage[ $max_size ] ) && file_exists( $file ) && filesize( $file ) < $this->plugin->components['connect']->usage[ $max_size ] ) { From 7d5663b0595ba1250e1858c2b6be39e3476ec28e Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sun, 31 May 2020 12:36:11 +0200 Subject: [PATCH 54/58] bump version --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index 160324658..ac07ce435 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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.9 + * Version: 2.1.0 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 498fe931bdebe41c6253ea919448c84ee6c1198f Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sun, 31 May 2020 16:07:59 +0200 Subject: [PATCH 55/58] if size not found, get basic full --- .../php/class-media.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index 3a697c70f..0861ebd1d 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -574,10 +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 ); - if ( ! is_array( $intermediate ) ) { - return false; + if ( is_array( $intermediate ) ) { + $size = $this->get_crop( $intermediate['url'], $attachment_id ); } - $size = $this->get_crop( $intermediate['url'], $attachment_id ); } /** From 50242100a5f1b0a20204123e3c0b017a5c7ee516 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 1 Jun 2020 10:56:28 +0200 Subject: [PATCH 56/58] bump version --- .../cloudinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php index ac07ce435..23c09bc93 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/cloudinary.php @@ -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.0 + * Version: 2.1.1 * Author: Cloudinary Ltd., XWP * Author URI: https://cloudinary.com/ * License: GPLv2+ From 690d3fe4c8f37e129d039620ba79d875d717439d Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 1 Jun 2020 13:39:46 +0200 Subject: [PATCH 57/58] fix missed typo --- .../php/sync/class-push-sync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php index 527fd68dd..892e86a50 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-push-sync.php @@ -376,7 +376,7 @@ public function prepare_upload( $post, $down_sync = false ) { } $resource_type = $this->get_resource_type( $post ); - $max_size = ( 'image' === $resource_type ? 'image_max_size_bytes' : 'video_max_size_bytes' ); + $max_size = ( 'image' === $resource_type ? 'max_image_size' : 'max_video_size' ); if ( ! empty( $this->plugin->components['connect']->usage[ $max_size ] ) && $file_size > $this->plugin->components['connect']->usage[ $max_size ] ) { $max_size_hr = size_format( $this->plugin->components['connect']->usage[ $max_size ] ); From b4cb1fc3001d697d83030de511272fa267ce2810 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 1 Jun 2020 13:41:07 +0200 Subject: [PATCH 58/58] remove debug test code --- .../php/class-media.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index 0861ebd1d..56b38edf2 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -1239,14 +1239,6 @@ public function get_post_meta( $post_id, $key, $single = false ) { $data = $this->build_cached_meta( $post_id, $key, $single ); } - // If public_id, ensure there's a sync_key saved. - if ( '_public_id' === $key && empty( $meta_data[ Sync::META_KEYS['cloudinary'] ]['_sync_key'] ) ) { - - //$sync_key = '_' . md5( $data ); - //$this->update_post_meta( $post_id, '_sync_key', $sync_key ); - //update_post_meta( $post_id, $sync_key, true ); // Set sync_key. - } - return $data; }