From 2a0d5d5304ca80e971fd2d439eb3cee20933f82d Mon Sep 17 00:00:00 2001 From: Justin Goff Date: Wed, 20 Jul 2022 11:16:01 -0500 Subject: [PATCH] support for csv files --- dist/scripts/admin.js | 2 +- lib/Admin.php | 10 ++++++++++ lib/Admin/tiles/generic_binary.php | 6 +++--- lib/Plugin.php | 1 + src/scripts/admin.js | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/dist/scripts/admin.js b/dist/scripts/admin.js index f22eb88..8ea19f3 100644 --- a/dist/scripts/admin.js +++ b/dist/scripts/admin.js @@ -1 +1 @@ -!function(e){var t={};function a(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=t,a.d=function(e,t,i){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(a.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(i,n,function(t){return e[t]}.bind(null,n));return i},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t,a){"use strict";a(1),function(e){var t=e("#widen-media"),a=e(".pagination-links .button"),i=e(".add-to-library"),n=e("#widen-save-collection");function d(){e("#widen-search-submit").attr("disabled",!0),e("#widen-search-spinner").addClass("is-active"),e("#widen-search-results").addClass("disabled",!0)}t.submit(function(){d()}),a.click(function(){d()}),i.click(function(t){t.preventDefault();var a,i,n,d=e(this);i=(a=d).closest(".tile"),n=i.find(".spinner"),a.attr("disabled",!0),i.addClass("disabled",!0),n.addClass("is-active");var r={},o=e(this).attr("data-type"),l=e(this).attr("data-format"),c=e(this).attr("data-ext"),u=e(this).attr("data-id"),s=e(this).attr("data-filename"),f=e(this).attr("data-description"),_=e(this).attr("data-url"),m=e(this).attr("data-templated-url"),p=e(this).attr("data-thumbnail-url"),b=e(this).attr("data-fields");switch(o){case"image":r={action:"widen_media_add_image_to_library",nonce:widen_media.ajax_nonce,type:o,id:u,filename:s,description:f,url:_,templatedUrl:m,fields:b};break;case"pdf":r={action:"widen_media_add_image_to_library",nonce:widen_media.ajax_nonce,type:o,id:u,filename:s,description:f,url:_,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"office":r={action:"widen_media_add_office_file_to_library",nonce:widen_media.ajax_nonce,type:o,ext:c,id:u,filename:s,description:f,url:_,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"video":r={action:"widen_media_add_video_to_library",nonce:widen_media.ajax_nonce,type:o,format:l,id:u,filename:s,description:f,url:_,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"audio":r={action:"widen_media_add_audio_to_library",nonce:widen_media.ajax_nonce,type:o,id:u,filename:s,description:f,url:_}}e.ajax({url:widen_media.ajax_url,type:"POST",data:r}).done(function(e){window.location.reload()})}),n.click(function(t){t.preventDefault();var a=e('[name="prev_search"]').val(),i=e("#widen_image_query_data").html(),n={action:"widen_media_save_collection",nonce:widen_media.ajax_nonce,query:a,items:i};e.ajax({url:widen_media.ajax_url,type:"POST",data:n}).done(function(e){window.location.reload()})})}(jQuery)},function(e,t,a){}]); \ No newline at end of file +!function(e){var a={};function t(i){if(a[i])return a[i].exports;var n=a[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,t),n.l=!0,n.exports}t.m=e,t.c=a,t.d=function(e,a,i){t.o(e,a)||Object.defineProperty(e,a,{enumerable:!0,get:i})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,a){if(1&a&&(e=t(e)),8&a)return e;if(4&a&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&a&&"string"!=typeof e)for(var n in e)t.d(i,n,function(a){return e[a]}.bind(null,n));return i},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,a){return Object.prototype.hasOwnProperty.call(e,a)},t.p="",t(t.s=0)}([function(e,a,t){"use strict";t(1),function(e){var a=e("#widen-media"),t=e(".pagination-links .button"),i=e(".add-to-library"),n=e("#widen-save-collection");function d(){e("#widen-search-submit").attr("disabled",!0),e("#widen-search-spinner").addClass("is-active"),e("#widen-search-results").addClass("disabled",!0)}a.submit(function(){d()}),t.click(function(){d()}),i.click(function(a){a.preventDefault();var t,i,n,d=e(this);i=(t=d).closest(".tile"),n=i.find(".spinner"),t.attr("disabled",!0),i.addClass("disabled",!0),n.addClass("is-active");var r={},o=e(this).attr("data-type"),l=e(this).attr("data-format"),c=e(this).attr("data-ext"),s=e(this).attr("data-id"),u=e(this).attr("data-filename"),_=e(this).attr("data-description"),f=e(this).attr("data-url"),m=e(this).attr("data-templated-url"),p=e(this).attr("data-thumbnail-url"),b=e(this).attr("data-fields");switch(o){case"image":r={action:"widen_media_add_image_to_library",nonce:widen_media.ajax_nonce,type:o,id:s,filename:u,description:_,url:f,templatedUrl:m,fields:b};break;case"pdf":r={action:"widen_media_add_image_to_library",nonce:widen_media.ajax_nonce,type:o,id:s,filename:u,description:_,url:f,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"office":r={action:"widen_media_add_office_file_to_library",nonce:widen_media.ajax_nonce,type:o,ext:c,id:s,filename:u,description:_,url:f,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"generic":r={action:"widen_media_add_generic_file_to_library",nonce:widen_media.ajax_nonce,type:o,ext:c,id:s,filename:u,description:_,url:f,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"video":r={action:"widen_media_add_video_to_library",nonce:widen_media.ajax_nonce,type:o,format:l,id:s,filename:u,description:_,url:f,templatedUrl:m,thumbnailUrl:p,fields:b};break;case"audio":r={action:"widen_media_add_audio_to_library",nonce:widen_media.ajax_nonce,type:o,id:s,filename:u,description:_,url:f}}e.ajax({url:widen_media.ajax_url,type:"POST",data:r}).done(function(e){window.location.reload()})}),n.click(function(a){a.preventDefault();var t=e('[name="prev_search"]').val(),i=e("#widen_image_query_data").html(),n={action:"widen_media_save_collection",nonce:widen_media.ajax_nonce,query:t,items:i};e.ajax({url:widen_media.ajax_url,type:"POST",data:n}).done(function(e){window.location.reload()})})}(jQuery)},function(e,a,t){}]); \ No newline at end of file diff --git a/lib/Admin.php b/lib/Admin.php index 07c145b..8ca716d 100644 --- a/lib/Admin.php +++ b/lib/Admin.php @@ -582,6 +582,16 @@ public function add_image_to_library(): void { } } + if ( 'generic' === $asset_data['type'] ) { + // check generic file extension and apply correct mimetype. + if ( 'csv' === $asset_data['ext'] ) { + $asset_data['mime_type'] = 'text/csv'; + } + if ( 'xml' === $asset_data['ext'] ) { + $asset_data['mime_type'] = 'application/xml'; + } + } + if ( 'video' === $asset_data['type'] ) { if ( 'MPEG4' === $asset_data['format'] ) { $asset_data['mime_type'] = 'video/mp4'; diff --git a/lib/Admin/tiles/generic_binary.php b/lib/Admin/tiles/generic_binary.php index 7a74499..ec13b50 100644 --- a/lib/Admin/tiles/generic_binary.php +++ b/lib/Admin/tiles/generic_binary.php @@ -60,10 +60,10 @@ class="tile__image blur-up lazyload"