diff --git a/.gitignore b/.gitignore index 485dee64..53279ea5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +log diff --git a/assets/css/admin.css b/assets/css/admin.css index a243cb49..31673c66 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -72,4 +72,12 @@ textarea#episode_embed_code { .ssp-episode-details-label { font-weight: bold; +} + +#series_image_preview { + max-width: 160px; +} + +#series_upload_image_button .dashicons { + vertical-align: middle; } \ No newline at end of file diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 517efafc..65ba70cf 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -#dashboard_right_now a.podcast-count:before,#dashboard_right_now span.podcast-count:before{content:"\f482"}.feed-series-list-container{margin-top:8px}#feed-series-toggle{cursor:pointer;float:left;margin-top:5px;color:#aaa}#feed-series-toggle:hover{color:#777}#feed-series-toggle:before{font-family:dashicons;font-size:150%}#feed-series-toggle.series-open:before{content:"\f142"}#feed-series-toggle.series-closed:before{content:"\f140"}#feed-series-list{margin:0}.view-feed-link{text-decoration:none}.view-feed-link span{font-size:100%;margin-top:2px;margin-bottom:-2px}#podcast_settings .update-nag{margin:0;padding:1px 9pt}textarea#episode_embed_code{width:100%;height:60px}.episode_embed_code_size_option{width:50px}#podcast-episode-data p{line-height:1.8}#podcast-episode-data input[type="radio"]{vertical-align:middle !important}#podcast-episode-data input[type="text"]{min-width:50%}.ssp-episode-details-label{font-weight:bold} \ No newline at end of file +#dashboard_right_now a.podcast-count:before,#dashboard_right_now span.podcast-count:before{content:"\f482"}.feed-series-list-container{margin-top:8px}#feed-series-toggle{cursor:pointer;float:left;margin-top:5px;color:#aaa}#feed-series-toggle:hover{color:#777}#feed-series-toggle:before{font-family:dashicons;font-size:150%}#feed-series-toggle.series-open:before{content:"\f142"}#feed-series-toggle.series-closed:before{content:"\f140"}#feed-series-list{margin:0}.view-feed-link{text-decoration:none}.view-feed-link span{font-size:100%;margin-top:2px;margin-bottom:-2px}#podcast_settings .update-nag{margin:0;padding:1px 9pt}textarea#episode_embed_code{width:100%;height:60px}.episode_embed_code_size_option{width:50px}#podcast-episode-data p{line-height:1.8}#podcast-episode-data input[type="radio"]{vertical-align:middle !important}#podcast-episode-data input[type="text"]{min-width:50%}.ssp-episode-details-label{font-weight:bold}#series_image_preview{max-width:160px}#series_upload_image_button .dashicons{vertical-align:middle} \ No newline at end of file diff --git a/assets/images/no-image.png b/assets/images/no-image.png new file mode 100644 index 00000000..a6bc908c Binary files /dev/null and b/assets/images/no-image.png differ diff --git a/assets/js/admin.js b/assets/js/admin.js index 7c2024f8..1481cde5 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -1,7 +1,7 @@ jQuery(document).ready(function($) { // Uploading files - var file_frame; + var file_frame, series_img_frame; jQuery.fn.ssp_upload_media_file = function( button, preview_media ) { var button_id = button.attr('id'); @@ -41,6 +41,63 @@ jQuery(document).ready(function($) { file_frame.open(); }; + /* Add/Edit Series Image */ + jQuery('#series_upload_image_button').click(function( event ){ + event.preventDefault(); + var send_attachment_bkp = wp.media.editor.send.attachment; + var button = $(this); + var button_id = button.attr('id'); + var preview_id = button_id.replace( '_upload', '' ).replace( '_button', '_preview' ); + var field_id = button_id.replace( '_upload', '' ).replace( '_button', '_id' ); + + // If the media frame already exists, reopen it. + if ( series_img_frame ) { + series_img_frame.open(); + return; + } + + // Create the media frame. + series_img_frame = wp.media({ + title: jQuery( this ).data( 'uploader_title' ), + button: { + text: jQuery( this ).data( 'uploader_button_text' ), + }, + library: { + type: [ 'image' ] + }, + multiple: false + }); + + series_img_frame.on( 'select', function() { + // Get media attachment details from the frame state + var attachment = series_img_frame.state().get('selection').first().toJSON(); + + // Send the attachment URL to our custom image input field. + $('#' + preview_id).attr('src', attachment.url); + + // Send the attachment id to our hidden input + $('#' + field_id).val(attachment.id); + }); + + // Finally, open the modal on click + series_img_frame.open(); + }); + + /* Remove/clear Series Image */ + jQuery('#series_remove_image_button').click(function( event ){ + event.preventDefault(); + var button = $(this); + var button_id = button.attr('id'); + var preview_id = button_id.replace( '_remove', '' ).replace( '_button', '_preview' ); + var field_id = button_id.replace( '_remove', '' ).replace( '_button', '_id' ); + + if ( confirm('Are you sure?') ) { + var src = $('#' + preview_id).attr('data-src'); + $('#' + preview_id).attr('src', src); + $('#' + field_id).val(''); + } + }); + /* ADD/EDIT EPISODE */ jQuery('#upload_audio_file_button').click(function( event ){ diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 1896c94f..cde69ca8 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -jQuery(document).ready(function(b){var a;jQuery.fn.ssp_upload_media_file=function(e,d){var c=e.attr("id");var f=c.replace("_button","");var g=c.replace("_button","_preview");if(a){a.open();return}a=wp.media.frames.file_frame=wp.media({title:jQuery(this).data("uploader_title"),button:{text:jQuery(this).data("uploader_button_text")},multiple:false});console.log(a);a.on("select",function(){var h=a.state().get("selection").first().toJSON();console.log(h);jQuery("#"+f).val(h.url);if(d){jQuery("#"+g).attr("src",h.url)}});a.open()};jQuery("#upload_audio_file_button").click(function(c){c.preventDefault();jQuery.fn.ssp_upload_media_file(jQuery(this),false)});jQuery("#episode_embed_code").click(function(){jQuery(this).select()});jQuery(".episode_embed_code_size_option").change(function(){var e=jQuery("#episode_embed_code_width").val();var c=jQuery("#episode_embed_code_height").val();var d=jQuery("#post_ID").val();jQuery.post(ajaxurl,{action:"update_episode_embed_code",width:e,height:c,post_id:d},function(f){if(f){jQuery("#episode_embed_code").val(f);jQuery("#episode_embed_code").select()}})});jQuery(".ssp-datepicker").datepicker({changeMonth:true,changeYear:true,showAnim:"slideDown",dateFormat:"d MM, yy",altField:"#date_recorded",altFormat:"dd-mm-yy",onClose:function(g,f){var h=b.datepicker.parseDate("d MM, yy",g);var c=b.datepicker.formatDate("dd-mm-yy",h);var e=b(this).attr("id").replace("_display","");b("#"+e).val(c)}});jQuery(".ssp-datepicker").change(function(){var d=jQuery(this).val();if(!d){var e=jQuery(this).attr("id");var c=e.replace("_display","");jQuery("#"+c).val("")}});jQuery("#feed-series-toggle").click(function(c){if(jQuery(this).hasClass("series-open")){jQuery("#feed-series-list").slideUp("fast");jQuery(this).removeClass("series-open");jQuery(this).addClass("series-closed")}else{if(jQuery(this).hasClass("series-closed")){jQuery("#feed-series-list").slideDown("fast");jQuery(this).removeClass("series-closed");jQuery(this).addClass("series-open")}}});jQuery("#ss_podcasting_data_image_button").click(function(){jQuery.fn.ssp_upload_media_file(jQuery(this),true)});jQuery("#ss_podcasting_data_image_delete").click(function(){jQuery("#ss_podcasting_data_image").val("");jQuery("#ss_podcasting_data_image_preview").remove();return false})}); \ No newline at end of file +jQuery(document).ready(function(c){var b,a;jQuery.fn.ssp_upload_media_file=function(f,e){var d=f.attr("id");var g=d.replace("_button","");var h=d.replace("_button","_preview");if(b){b.open();return}b=wp.media.frames.file_frame=wp.media({title:jQuery(this).data("uploader_title"),button:{text:jQuery(this).data("uploader_button_text")},multiple:false});console.log(b);b.on("select",function(){var i=b.state().get("selection").first().toJSON();console.log(i);jQuery("#"+g).val(i.url);if(e){jQuery("#"+h).attr("src",i.url)}});b.open()};jQuery("#series_upload_image_button").click(function(h){h.preventDefault();var d=wp.media.editor.send.attachment;var f=c(this);var e=f.attr("id");var i=e.replace("_upload","").replace("_button","_preview");var g=e.replace("_upload","").replace("_button","_id");if(a){a.open();return}a=wp.media({title:jQuery(this).data("uploader_title"),button:{text:jQuery(this).data("uploader_button_text")},library:{type:["image"]},multiple:false});a.on("select",function(){var j=a.state().get("selection").first().toJSON();c("#"+i).attr("src",j.url);c("#"+g).val(j.id)});a.open()});jQuery("#series_remove_image_button").click(function(g){g.preventDefault();var e=c(this);var d=e.attr("id");var h=d.replace("_remove","").replace("_button","_preview");var f=d.replace("_remove","").replace("_button","_id");if(confirm("Are you sure?")){var i=c("#"+h).attr("data-src");c("#"+h).attr("src",i);c("#"+f).val("")}});jQuery("#upload_audio_file_button").click(function(d){d.preventDefault();jQuery.fn.ssp_upload_media_file(jQuery(this),false)});jQuery("#episode_embed_code").click(function(){jQuery(this).select()});jQuery(".episode_embed_code_size_option").change(function(){var f=jQuery("#episode_embed_code_width").val();var d=jQuery("#episode_embed_code_height").val();var e=jQuery("#post_ID").val();jQuery.post(ajaxurl,{action:"update_episode_embed_code",width:f,height:d,post_id:e},function(g){if(g){jQuery("#episode_embed_code").val(g);jQuery("#episode_embed_code").select()}})});jQuery(".ssp-datepicker").datepicker({changeMonth:true,changeYear:true,showAnim:"slideDown",dateFormat:"d MM, yy",altField:"#date_recorded",altFormat:"dd-mm-yy",onClose:function(h,g){var i=c.datepicker.parseDate("d MM, yy",h);var e=c.datepicker.formatDate("dd-mm-yy",i);var f=c(this).attr("id").replace("_display","");c("#"+f).val(e)}});jQuery(".ssp-datepicker").change(function(){var e=jQuery(this).val();if(!e){var f=jQuery(this).attr("id");var d=f.replace("_display","");jQuery("#"+d).val("")}});jQuery("#feed-series-toggle").click(function(d){if(jQuery(this).hasClass("series-open")){jQuery("#feed-series-list").slideUp("fast");jQuery(this).removeClass("series-open");jQuery(this).addClass("series-closed")}else{if(jQuery(this).hasClass("series-closed")){jQuery("#feed-series-list").slideDown("fast");jQuery(this).removeClass("series-closed");jQuery(this).addClass("series-open")}}});jQuery("#ss_podcasting_data_image_button").click(function(){jQuery.fn.ssp_upload_media_file(jQuery(this),true)});jQuery("#ss_podcasting_data_image_delete").click(function(){jQuery("#ss_podcasting_data_image").val("");jQuery("#ss_podcasting_data_image_preview").remove();return false})}); \ No newline at end of file diff --git a/assets/js/fileupload.js b/assets/js/fileupload.js index a2ff96f7..20aba77b 100644 --- a/assets/js/fileupload.js +++ b/assets/js/fileupload.js @@ -39,6 +39,11 @@ jQuery( document ).ready( function ( $ ) { return isValid; } + function sanitizeName(name) { + var punctuationlessName = name.replace(/[,\/#!$%\^&\*;:{}=\-_`'~()+"|? ]/g," "); + return punctuationlessName.replace(/\s{1,}/g,"-"); + } + /** * Of the upload_credentials object isn't available */ @@ -47,9 +52,6 @@ jQuery( document ).ready( function ( $ ) { var bucket = upload_credentials.bucket; var show_slug = upload_credentials.show_slug; var episodes_url = upload_credentials.episodes_url; - var access_key_id = upload_credentials.access_key_id; - var policy = upload_credentials.policy; - var signature = upload_credentials.signature; /** * Creates instance of plupload @@ -61,15 +63,7 @@ jQuery( document ).ready( function ( $ ) { multi_selection: false, container: 'ssp_upload_container', url: 'https://' + bucket + '.s3.amazonaws.com:443/', - multipart_params: { - 'key': show_slug + '/${filename}', - 'Filename': show_slug + '/${filename}', - 'acl': 'public-read', - 'Content-Type': '', - 'AWSAccessKeyId': access_key_id, - 'policy': policy, - 'signature': signature - } + multipart_params: {} } ); /** @@ -98,6 +92,23 @@ jQuery( document ).ready( function ( $ ) { } } ); + /** + * Sanatizes the file name for upload + */ + uploader.bind('BeforeUpload', function (up, file) { + var file_name = sanitizeName(file.name); + var multipart_params = { + 'key': upload_credentials.show_slug + '/' + file_name, + 'Filename': upload_credentials.show_slug + '/' + file_name, + 'acl': 'public-read', + 'Content-Type': '', + 'AWSAccessKeyId': upload_credentials.access_key_id, + 'policy': upload_credentials.policy, + 'signature': upload_credentials.signature + } + uploader.settings.multipart_params = multipart_params; + }); + /** * Show an error if anything goes wrong */ @@ -121,10 +132,11 @@ jQuery( document ).ready( function ( $ ) { // we're only expecting one file to be uploaded var file = files[ 0 ]; + var file_name = sanitizeName(file.name); var filesize_raw = file.size; var file_size = plupload.formatSize(file.size); - var uploaded_file = 'https://s3.amazonaws.com/' + bucket + '/' + show_slug + '/' + file.name; - var episode_file = episodes_url + show_slug + '/' + file.name; + var uploaded_file = 'https://s3.amazonaws.com/' + bucket + '/' + show_slug + '/' + file_name; + var episode_file = episodes_url + show_slug + '/' + file_name; // push podmotor_file_path to wp_ajax_ssp_store_podmotor_file $.ajax( { diff --git a/assets/js/fileupload.min.js b/assets/js/fileupload.min.js index 5de5caab..d46a583a 100644 --- a/assets/js/fileupload.min.js +++ b/assets/js/fileupload.min.js @@ -1 +1 @@ -jQuery(document).ready(function(d){function h(l){d(".peek-a-bar").hide().remove();var k=new d.peekABar({padding:"1em",animation:{type:"fade",duration:1000},cssClass:"ssp-notification-bar",backgroundColor:"#4aa3df"});k.show({html:l})}function a(l){var k=l.type;var m=k.split("/");var n=false;if("audio"==m[0]||"video"==m[0]){n=true}return n}if(typeof upload_credentials!="undefined"){var b=upload_credentials.bucket;var i=upload_credentials.show_slug;var f=upload_credentials.episodes_url;var j=upload_credentials.access_key_id;var g=upload_credentials.policy;var c=upload_credentials.signature;var e=new plupload.Uploader({runtimes:"html5",browse_button:"ssp_select_file",multi_selection:false,container:"ssp_upload_container",url:"https://"+b+".s3.amazonaws.com:443/",multipart_params:{key:i+"/${filename}",Filename:i+"/${filename}",acl:"public-read","Content-Type":"",AWSAccessKeyId:j,policy:g,signature:c}});e.init();e.bind("Init",function(){d("#ssp_upload_notification").remove()});e.bind("FilesAdded",function(k,m){var l=m[0];if(a(l)){h('Uploading file to Castos Hosting. You can continue editing this post while the file uploads. ');e.start()}else{h("You have selected an invalid file type, please select a valid audio or video file.")}});e.bind("Error",function(k,l){alert("Error #"+l.code+": "+l.message)});e.bind("UploadProgress",function(k,l){d("#ssp_upload_progress").html(l.percent+"%")});e.bind("UploadComplete",function(l,q){h("Processing Castos Hosting file.");var p=q[0];var n=p.size;var k=plupload.formatSize(p.size);var m="https://s3.amazonaws.com/"+b+"/"+i+"/"+p.name;var o=f+i+"/"+p.name;d.ajax({method:"GET",url:ajaxurl,data:{action:"ssp_store_podmotor_file",podmotor_file_path:m}}).done(function(r){if(r.status=="success"){h("Uploading file to Castos Hosting Complete.");d("#podmotor_file_id").val(r.file_id);d("#filesize_raw").val(n);d("#filesize").val(k);d("#duration").val(r.file_duration);d("#upload_audio_file").val(o);d(".peek-a-bar").fadeOut(5000)}else{h(r.message)}})})}}); \ No newline at end of file +jQuery(document).ready(function(e){function h(j){e(".peek-a-bar").hide().remove();var i=new e.peekABar({padding:"1em",animation:{type:"fade",duration:1000},cssClass:"ssp-notification-bar",backgroundColor:"#4aa3df"});i.show({html:j})}function d(j){var i=j.type;var k=i.split("/");var l=false;if("audio"==k[0]||"video"==k[0]){l=true}return l}function c(i){var j=i.replace(/[,\/#!$%\^&\*;:{}=\-_`'~()+"|? ]/g," ");return j.replace(/\s{1,}/g,"-")}if(typeof upload_credentials!="undefined"){var g=upload_credentials.bucket;var b=upload_credentials.show_slug;var a=upload_credentials.episodes_url;var f=new plupload.Uploader({runtimes:"html5",browse_button:"ssp_select_file",multi_selection:false,container:"ssp_upload_container",url:"https://"+g+".s3.amazonaws.com:443/",multipart_params:{}});f.init();f.bind("Init",function(){e("#ssp_upload_notification").remove()});f.bind("FilesAdded",function(i,k){var j=k[0];if(d(j)){h('Uploading file to Castos Hosting. You can continue editing this post while the file uploads. ');f.start()}else{h("You have selected an invalid file type, please select a valid audio or video file.")}});f.bind("BeforeUpload",function(j,k){var l=c(k.name);var i={key:upload_credentials.show_slug+"/"+l,Filename:upload_credentials.show_slug+"/"+l,acl:"public-read","Content-Type":"",AWSAccessKeyId:upload_credentials.access_key_id,policy:upload_credentials.policy,signature:upload_credentials.signature};f.settings.multipart_params=i});f.bind("Error",function(i,j){alert("Error #"+j.code+": "+j.message)});f.bind("UploadProgress",function(i,j){e("#ssp_upload_progress").html(j.percent+"%")});f.bind("UploadComplete",function(j,o){h("Processing Castos Hosting file.");var n=o[0];var p=c(n.name);var l=n.size;var i=plupload.formatSize(n.size);var k="https://s3.amazonaws.com/"+g+"/"+b+"/"+p;var m=a+b+"/"+p;e.ajax({method:"GET",url:ajaxurl,data:{action:"ssp_store_podmotor_file",podmotor_file_path:k}}).done(function(q){if(q.status=="success"){h("Uploading file to Castos Hosting Complete.");e("#podmotor_file_id").val(q.file_id);e("#filesize_raw").val(l);e("#filesize").val(i);e("#duration").val(q.file_duration);e("#upload_audio_file").val(m);e(".peek-a-bar").fadeOut(5000)}else{h(q.message)}})})}}); \ No newline at end of file diff --git a/includes/class-ssp-admin.php b/includes/class-ssp-admin.php index ee7a54a2..d34c0643 100644 --- a/includes/class-ssp-admin.php +++ b/includes/class-ssp-admin.php @@ -24,6 +24,18 @@ class SSP_Admin { private $home_url; private $script_suffix; + /** + * Unique identifier for the plugin. + * + * The variable name is used as the text domain when internationalizing strings of text. + * Its value should match the Text Domain file header in the main plugin file. + * + * @since 1.0.0 + * + * @var string + */ + protected $plugin_slug; + /** * Constructor * @@ -40,6 +52,7 @@ public function __construct( $file, $version ) { $this->template_path = trailingslashit( $this->dir ) . 'templates/'; $this->home_url = trailingslashit( home_url() ); $this->token = 'podcast'; + $this->plugin_slug = 'seriously-simple-podcasting'; $this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; @@ -93,6 +106,12 @@ public function __construct( $file, $version ) { add_filter( 'manage_edit-series_columns', array( $this, 'edit_series_columns' ) ); add_filter( 'manage_series_custom_column', array( $this, 'add_series_columns' ), 1, 3 ); + // Series term meta forms + add_action( 'series_add_form_fields', array( $this, 'add_series_term_meta_fields' ), 10, 2 ); + add_action( 'series_edit_form_fields', array( $this, 'edit_series_term_meta_fields'), 10, 2) ; + add_action( 'created_series', array( $this, 'save_series_meta'), 10, 2 ); + add_action( 'edited_series', array( $this, 'update_series_meta'), 10, 2 ); + // Dashboard widgets. add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); @@ -180,25 +199,25 @@ public function setup_permastruct() { public function register_post_type() { $labels = array( - 'name' => _x( 'Podcast', 'post type general name', 'seriously-simple-podcasting' ), - 'singular_name' => _x( 'Podcast', 'post type singular name', 'seriously-simple-podcasting' ), - 'add_new' => _x( 'Add New', 'podcast', 'seriously-simple-podcasting' ), - 'add_new_item' => sprintf( __( 'Add New %s', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'edit_item' => sprintf( __( 'Edit %s', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'new_item' => sprintf( __( 'New %s', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'all_items' => sprintf( __( 'All %s', 'seriously-simple-podcasting' ), __( 'Episodes', 'seriously-simple-podcasting' ) ), - 'view_item' => sprintf( __( 'View %s', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'search_items' => sprintf( __( 'Search %a', 'seriously-simple-podcasting' ), __( 'Episodes', 'seriously-simple-podcasting' ) ), - 'not_found' => sprintf( __( 'No %s Found', 'seriously-simple-podcasting' ), __( 'Episodes', 'seriously-simple-podcasting' ) ), - 'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'seriously-simple-podcasting' ), __( 'Episodes', 'seriously-simple-podcasting' ) ), + 'name' => _x( 'Podcast', 'post type general name', $this->plugin_slug ), + 'singular_name' => _x( 'Podcast', 'post type singular name', $this->plugin_slug ), + 'add_new' => _x( 'Add New', 'podcast', $this->plugin_slug ), + 'add_new_item' => sprintf( __( 'Add New %s', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'edit_item' => sprintf( __( 'Edit %s', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'new_item' => sprintf( __( 'New %s', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'all_items' => sprintf( __( 'All %s', $this->plugin_slug ), __( 'Episodes', $this->plugin_slug ) ), + 'view_item' => sprintf( __( 'View %s', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'search_items' => sprintf( __( 'Search %a', $this->plugin_slug ), __( 'Episodes', $this->plugin_slug ) ), + 'not_found' => sprintf( __( 'No %s Found', $this->plugin_slug ), __( 'Episodes', $this->plugin_slug ) ), + 'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', $this->plugin_slug ), __( 'Episodes', $this->plugin_slug ) ), 'parent_item_colon' => '', - 'menu_name' => __( 'Podcast', 'seriously-simple-podcasting' ), - 'filter_items_list' => sprintf( __( 'Filter %s list', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'items_list_navigation' => sprintf( __( '%s list navigation', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), - 'items_list' => sprintf( __( '%s list', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), + 'menu_name' => __( 'Podcast', $this->plugin_slug ), + 'filter_items_list' => sprintf( __( 'Filter %s list', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'items_list_navigation' => sprintf( __( '%s list navigation', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), + 'items_list' => sprintf( __( '%s list', $this->plugin_slug ), __( 'Episode', $this->plugin_slug ) ), ); - $slug = apply_filters( 'ssp_archive_slug', __( 'podcast', 'seriously-simple-podcasting' ) ); + $slug = apply_filters( 'ssp_archive_slug', __( 'podcast', $this->plugin_slug ) ); $args = array( 'labels' => $labels, @@ -247,25 +266,25 @@ private function register_taxonomies() { $podcast_post_types = ssp_post_types( true ); $series_labels = array( - 'name' => __( 'Podcast Series', 'seriously-simple-podcasting' ), - 'singular_name' => __( 'Series', 'seriously-simple-podcasting' ), - 'search_items' => __( 'Search Series', 'seriously-simple-podcasting' ), - 'all_items' => __( 'All Series', 'seriously-simple-podcasting' ), - 'parent_item' => __( 'Parent Series', 'seriously-simple-podcasting' ), - 'parent_item_colon' => __( 'Parent Series:', 'seriously-simple-podcasting' ), - 'edit_item' => __( 'Edit Series', 'seriously-simple-podcasting' ), - 'update_item' => __( 'Update Series', 'seriously-simple-podcasting' ), - 'add_new_item' => __( 'Add New Series', 'seriously-simple-podcasting' ), - 'new_item_name' => __( 'New Series Name', 'seriously-simple-podcasting' ), - 'menu_name' => __( 'Series', 'seriously-simple-podcasting' ), - 'view_item' => __( 'View Series', 'seriously-simple-podcasting' ), - 'popular_items' => __( 'Popular Series', 'seriously-simple-podcasting' ), - 'separate_items_with_commas' => __( 'Separate series with commas', 'seriously-simple-podcasting' ), - 'add_or_remove_items' => __( 'Add or remove Series', 'seriously-simple-podcasting' ), - 'choose_from_most_used' => __( 'Choose from the most used Series', 'seriously-simple-podcasting' ), - 'not_found' => __( 'No Series Found', 'seriously-simple-podcasting' ), - 'items_list_navigation' => __( 'Series list navigation', 'seriously-simple-podcasting' ), - 'items_list' => __( 'Series list', 'seriously-simple-podcasting' ), + 'name' => __( 'Podcast Series', $this->plugin_slug ), + 'singular_name' => __( 'Series', $this->plugin_slug ), + 'search_items' => __( 'Search Series', $this->plugin_slug ), + 'all_items' => __( 'All Series', $this->plugin_slug ), + 'parent_item' => __( 'Parent Series', $this->plugin_slug ), + 'parent_item_colon' => __( 'Parent Series:', $this->plugin_slug ), + 'edit_item' => __( 'Edit Series', $this->plugin_slug ), + 'update_item' => __( 'Update Series', $this->plugin_slug ), + 'add_new_item' => __( 'Add New Series', $this->plugin_slug ), + 'new_item_name' => __( 'New Series Name', $this->plugin_slug ), + 'menu_name' => __( 'Series', $this->plugin_slug ), + 'view_item' => __( 'View Series', $this->plugin_slug ), + 'popular_items' => __( 'Popular Series', $this->plugin_slug ), + 'separate_items_with_commas' => __( 'Separate series with commas', $this->plugin_slug ), + 'add_or_remove_items' => __( 'Add or remove Series', $this->plugin_slug ), + 'choose_from_most_used' => __( 'Choose from the most used Series', $this->plugin_slug ), + 'not_found' => __( 'No Series Found', $this->plugin_slug ), + 'items_list_navigation' => __( 'Series list navigation', $this->plugin_slug ), + 'items_list' => __( 'Series list', $this->plugin_slug ), ); $series_args = array( @@ -322,6 +341,106 @@ private function register_taxonomies() { } + /** + * Adds series term metaboxes to the new series form. + */ + public function add_series_term_meta_fields( $taxonomy ) { + // Add series image upload metabox. + $this->series_image_uploader( $taxonomy ); + } + + /** + * Adds series term metaboxes to the edit series form. + */ + public function edit_series_term_meta_fields( $term, $taxonomy ) { + // Add series image edit/upload metabox. + $this->series_image_uploader ( $taxonomy, $mode = 'UPDATE', $term = $term ); + } + + /** + * Series Image Uploader metabox for add/edit. + */ + public function series_image_uploader( $taxonomy, $mode = 'CREATE', $term = null ) { + $series_settings = $this->token . '_series_image_settings'; + // Define a default image. + $default_image = esc_url( $this->assets_url . 'images/no-image.png' ); + if ( $term !== null ) { + $media_id = get_term_meta( $term->term_id, $series_settings, true ); + } + $image_width = "auto"; + $image_height = "auto"; + + if ( $mode == 'UPDATE' && !empty( $media_id ) ) { + $image_attributes = wp_get_attachment_image_src( $media_id, array( $image_width, $image_height ) ); + $src = $image_attributes[0]; + } else { + $src = $default_image; + $media_id = ''; + } + + $series_img_title = __( 'Series Image', $this->plugin_slug ); + $upload_btn_text = __( 'Choose series image', $this->plugin_slug ); + $upload_btn_value = __( 'Add Image', $this->plugin_slug ); + $upload_btn_title = __( 'Choose an image file', $this->plugin_slug ); + $series_img_desc = __( "Set an image as the artwork for the series. No image will be set if not provided.", $this->plugin_slug); + + $series_img_form_label = <<{$series_img_title} +HTML; + + $series_img_form_fields = <<
+{$series_img_desc}
+HTML; + + if ( $mode == 'CREATE' ) { + echo << + {$series_img_form_label} + {$series_img_form_fields} + +HTML; + } else if ( $mode == 'UPDATE' ) { + echo << +