diff --git a/assets/css/1.php b/assets/css/1.php deleted file mode 100644 index fefd77e..0000000 --- a/assets/css/1.php +++ /dev/null @@ -1,31 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/2.php b/assets/css/2.php deleted file mode 100644 index 77a4fec..0000000 --- a/assets/css/2.php +++ /dev/null @@ -1,67 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/3.php b/assets/css/3.php deleted file mode 100644 index fb5f418..0000000 --- a/assets/css/3.php +++ /dev/null @@ -1,45 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/4.php b/assets/css/4.php deleted file mode 100644 index 1a6aa7e..0000000 --- a/assets/css/4.php +++ /dev/null @@ -1,45 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/5.php b/assets/css/5.php deleted file mode 100644 index a9272a7..0000000 --- a/assets/css/5.php +++ /dev/null @@ -1,44 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/global.php b/assets/css/global.php deleted file mode 100644 index 60e7bc2..0000000 --- a/assets/css/global.php +++ /dev/null @@ -1,75 +0,0 @@ - \ No newline at end of file diff --git a/assets/css/ssi-wpjm-admin.css b/assets/css/ssi-wpjm-admin.css index 70b6810..89c529f 100644 --- a/assets/css/ssi-wpjm-admin.css +++ b/assets/css/ssi-wpjm-admin.css @@ -9,4 +9,121 @@ img.ssi-image { } .wp-core-ui .ssi-hidden { display: none; +} +.ssi-wpjm-input--image, +.ssi-wpjm-input--gallery { + display: none; +} +.ssi-wpjm-image, +.ssi-wpjm-gallery-image{ + border: 4px solid #CCCCCC; + padding: 4px; + margin-top: 20px; + margin-bottom: 20px; +} +.ssi-wpjm-image-wrapper { + position: relative; + width: 25em; +} +.ssi-wpjm-image-wrapper img { + max-width: 100%; + height: auto; + box-sizing: border-box; +} +.ssi-wpjm-image--remove, +.ssi-wpjm-gallery--remove { + position: absolute; + font-size: 28px; + cursor: pointer; +} + +.ssi-wpjm-gallery-item { + display: inline-block; + margin: 0; + margin-right: 32px; +} +.ssi-wpjm-input-description { + font-style: italic; +} +.form-table .ssi-wpjm-gallery-button, +.form-table .ssi-wpjm-image-button { + margin-bottom: 8px; +} + +.setting-type--section { + border-top: 1px solid #CCCCCC; +} +.ssi-wpjm-settings-form .setting-type--section th { + flex-basis: 100%; + font-size: 130%; + font-weight: bold; +} +.ssi-wpjm-settings-form .setting-type--section { + gap: 0; +} + +.ssi-wpjm-settings-form .setting-type--hidden { + display: none; +} + +.ssi-wpjm-settings-form tr { + display: flex; + flex-wrap: wrap; + column-gap: 2em; +} +.ssi-wpjm-settings-form th { + padding: 20px 0 0; + flex-basis: 25%; +} +.ssi-wpjm-settings-form td { + padding: 15px 0; +} +.ssi-wpjm-settings-form .form-table { + width: 100%; +} + +@media screen and (min-width: 1000px) { + .ssi-wpjm-settings-form .form-table { + width: calc(100% - 520px - 4em); + } +} + + +.ssi-wpjm-template-preview { + + max-width: var(--hdsmi-template--width); + +} + +@media screen and (min-width: 1000px) { + + .ssi-wpjm-template-preview { + + position: fixed; + bottom: 3em; + right: 2em; + + } + +} + +.ssi-wpjm-template-preview .hdsmi-template { + + --hdsmi-template--width: 80vw; + box-shadow: 20px 20px 40px rgba(0,0,0,0.2); + +} + +@media screen and (min-width: 600px) { + + .ssi-wpjm-template-preview .hdsmi-template { + + --hdsmi-template--width: 520px; + + } + +} + +.ssi-wpjm-error { + color: red; } \ No newline at end of file diff --git a/assets/css/ssi-wpjm-generate.css b/assets/css/ssi-wpjm-generate.css new file mode 100644 index 0000000..d18f27c --- /dev/null +++ b/assets/css/ssi-wpjm-generate.css @@ -0,0 +1,319 @@ +/** + * CSS rules that apply to all templates. + */ +body { + margin: 0; + padding: 0 +} + + .hdsmi-template { + + --hdsmi-template--width: 100vw; + --hdsmi-template--unit: calc(var(--hdsmi-template--width) / 100); + --hdsmi--text--color: white; + --hdsmi--text--background-color: transparent; + --hdsmi--background-color: rgb(23, 139, 145); + --hdsmi--font-family: sans-serif; + --hdsmi--font-size: 6; + --hdsmi--title--font-size: 6; + --hdsmi--title--font-weight: inherit; + --hdsmi--title--text-transform: inherit; + --hdsmi--location--font-size: 4; + --hdsmi--location--font-weight: inherit; + --hdsmi--location--text-transform: inherit; + --hdsmi--salary--font-size: 3; + --hdsmi--salary--font-weight: inherit; + --hdsmi--salary--text-transform: inherit; + --hdsmi--image--background-blend-mode: none; + --hdsmi--logo--height: 4; + --hdsmi--logo--width: auto; + + width: var(--hdsmi-template--width); + aspect-ratio: 120/63; + display: grid; + place-items: center; + background-color: var(--hdsmi--background-color); + +} + +.hdsmi-template__inner { + position: relative; + aspect-ratio: 120/63; + width: 100% +} +.hdsmi-template__text { + font-size: calc(var(--hdsmi--font-size) * var(--hdsmi-template--unit)); + line-height: var(--hdsmi--line-height); + font-family: var(--hdsmi--font-family); + color: var(--hdsmi--text--color) +} +.hdsmi-template__title { + color: var(--hdsmi--title--color,var(--hdsmi--text--color)); + font-size: calc(var(--hdsmi--title--font-size, var(--hdsmi--font-size)) * var(--hdsmi-template--unit)); + font-weight: var(--hdsmi--title--font-weight); + text-transform: var(--hdsmi--title--text-transform) +} +.hdsmi-template__location { + color: var(--hdsmi--location--color,var(--hdsmi--text--color)); + font-size: calc(var(--hdsmi--location--font-size, var(--hdsmi--font-size)) * var(--hdsmi-template--unit)); + font-weight: var(--hdsmi--location--font-weight); + text-transform: var(--hdsmi--location--text-transform) +} +.hdsmi-template__salary { + color: var(--hdsmi--salary--color,var(--hdsmi--text--color)); + font-size: calc(var(--hdsmi--salary--font-size, var(--hdsmi--font-size)) * var(--hdsmi-template--unit)); + font-weight: var(--hdsmi--salary--font-weight); + text-transform: var(--hdsmi--salary--text-transform) +} +.hdsmi-template__logo { + height: calc(var(--hdsmi--logo--height) * var(--hdsmi-template--unit)); + width: var(--hdsmi--logo--width) +} +.hdsmi-template__image { + display: block; +} + +/* Template 1 */ + +.hdsmi-template.hdsmi-template--1 { + --hdsmi--template--font-weight: bold; + --hdsmi--line-height: 1.5; + --hdsmi--line-gap: .1em; +} +.hdsmi-template--1 .hdsmi-template__inner { + display: flex; + align-items: center; + width: 100% +} +.hdsmi-template--1 .hdsmi-template__text { + width: 66.66%; + display: flex; + flex-direction: column; + align-items: flex-start; + gap: calc(2 * var(--hdsmi-template--unit)); + padding: calc(3 * var(--hdsmi-template--unit)) +} + +.hdsmi-template--1 .hdsmi-template__text > * { + display: block; +} + +.hdsmi-template--1 .hdsmi-template__text > * > [class*="__inner"] { + display: inline; + line-height: var(--hdsmi--line-height); + padding: calc( ( ( (1em * var(--hdsmi--line-height)) - 1em) / 2) - (var(--hdsmi--line-gap) / 2) ) calc(2 * var(--hdsmi-template--unit)); + background-color: var(--hdsmi--text--background-color); + -webkit-box-decoration-break: clone; + box-decoration-break: clone +} + +.hdsmi-template--1 .hdsmi-template__image { + align-self: stretch; + width: 33%; + height: auto; + object-fit: cover +} +.hdsmi-template--1 .hdsmi-template__logo { + position: absolute; + top: calc(3 * var(--hdsmi-template--unit)); + right: calc(3 * var(--hdsmi-template--unit)) +} + +/* Template 2 */ + +.hdsmi-template--2 { + --hdsmi--location--font-size: 2.5; + --hdsmi--line-height: 1.25; +} +.hdsmi-template--2 .hdsmi-template__inner { + display: flex; + flex-direction: column; + justify-content: flex-end +} +.hdsmi-template--2 .hdsmi-template__image { + position: absolute; + z-index: 0; + top: 0; + left: 0; + right: 0; + bottom: 0; + width: 100%; + height: 100%; + object-fit: cover +} +.hdsmi-template--2 .hdsmi-template__text { + position: relative; + z-index: 1; + display: flex; + flex-direction: column; + gap: calc(2 * var(--hdsmi-template--unit)); + padding: 0 calc(6 * var(--hdsmi-template--unit)) calc(4 * var(--hdsmi-template--unit)) +} +.hdsmi-template--2 .hdsmi-template__text:after { + content: ''; + position: absolute; + z-index: -1; + top: calc(-10 * var(--hdsmi-template--unit)); + left: 0; + right: 0; + bottom: 0; + background: linear-gradient(#00000000,var(--hdsmi--text--background-color) 70%,var(--hdsmi--text--background-color)) +} +.hdsmi-template--2 .hdsmi-template__title { + order: 2 +} +.hdsmi-template--2 .hdsmi-template__location { + text-transform: uppercase; + order: 1; + margin-top: auto +} +.hdsmi-template--2 .hdsmi-template__salary { + order: 3; + font-weight: 700 +} +.hdsmi-template--2 .hdsmi-template__logo { + position: absolute; + top: calc(3 * var(--hdsmi-template--unit)); + left: calc(6 * var(--hdsmi-template--unit)) +} + +/* Template 3 */ + +.hdsmi-template--3 { + --hdsmi--title--font-weight: bold; + --hdsmi--line-height: 1.25; +} +.hdsmi-template--3 { + --hdsmi--title--font-size: 4; + --hdsmi--location--font-size: 3; + --hdsmi--logo--height: 6; +} +.hdsmi-template--3 .hdsmi-template__text { + width: calc(66.6 * var(--hdsmi-template--unit)); + z-index: 2; + position: absolute; + bottom: calc(4 * var(--hdsmi-template--unit)); + left: calc(4 * var(--hdsmi-template--unit)); + background-color: var(--hdsmi--text--background-color); + padding: calc(2 * var(--hdsmi-template--unit)); + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: calc(2 * var(--hdsmi-template--unit)) +} +.hdsmi-template--3 .hdsmi-template__title { + width: 100% +} +.hdsmi-template--3 .hdsmi-template__salary { + /* margin-left: auto */ +} +.hdsmi-template--3 .hdsmi-template__image { + width: calc(66.6 * var(--hdsmi-template--unit)); + height: calc(40 * var(--hdsmi-template--unit)); + position: absolute; + z-index: 1; + top: calc(5 * var(--hdsmi-template--unit)); + right: 0; + bottom: calc(5 * var(--hdsmi-template--unit)); + object-fit: cover +} +.hdsmi-template--3 .hdsmi-template__logo { + position: absolute; + top: calc(3 * var(--hdsmi-template--unit)); + left: calc(3 * var(--hdsmi-template--unit)) +} + +/* Template 4 */ + +.hdsmi-template--4 { + --hdsmi--title--font-size: 4; + --hdsmi--location--font-size: 2.5; + --hdsmi--salary--font-size: 2.5; + --hdsmi--logo--height: 5; + --hdsmi--line-height: 1.25; +} +.hdsmi-template--4 .hdsmi-template__inner { + display: grid; + align-items: end; + justify-items: center +} +.hdsmi-template--4 .hdsmi-template__image { + width: 100%; + height: 100%; + position: absolute; + z-index: 0; + top: 0; + bottom: 0; + left: 0; + right: 0; + object-fit: cover; +} +.hdsmi-template--4 .hdsmi-template__text { + position: relative; + z-index: 1; + max-width: 66.66%; + background-color: var(--hdsmi--text--background-color); + padding: calc(4 * var(--hdsmi-template--unit)); + margin: calc(4 * var(--hdsmi-template--unit)) 1calc(5 * var(--hdsmi-template--unit)); + text-align: center; + display: flex; + flex-direction: column; + gap: calc(2 * var(--hdsmi-template--unit)) +} +.hdsmi-template--4 .hdsmi-template__logo { + position: absolute; + top: calc(3 * var(--hdsmi-template--unit)); + z-index: 0 +} + +/* Template 5 */ + +.hdsmi-template--5 { + --hdsmi--line-height: 1.5; + --hdsmi--line-gap: .1em; + --hdsmi--title--font-size: 5; + --hdsmi--location--font-size: 3; + --hdsmi--logo--height: 3; +} +.hdsmi-template--5 .hdsmi-template__text { + line-height: calc(.1 * var(--hdsmi-template--unit)); + width: calc( (50 * var(--hdsmi-template--unit)) + (8 * var(--hdsmi-template--unit))); + position: absolute; + top: 50%; + left: calc(50% - calc(10 * var(--hdsmi-template--unit))); + transform: translateY(-50%); + padding-top: calc(var(--hdsmi--logo--height) * var(--hdsmi-template--unit)); +} + +.hdsmi-template--5 .hdsmi-template__text > * { + display: block; + margin: .5em 0; +} + +.hdsmi-template--5 .hdsmi-template__text > * > [class*="__inner"] { + display: inline; + line-height: var(--hdsmi--line-height); + padding: calc( ( ( (1em * var(--hdsmi--line-height)) - 1em) / 2) - (var(--hdsmi--line-gap) / 2) ) calc(2 * var(--hdsmi-template--unit)); + + background-color: var(--hdsmi--text--background-color); + -webkit-box-decoration-break: clone; + box-decoration-break: clone +} +.hdsmi-template--5 .hdsmi-template__text > :after { + content: "\A"; + white-space: pre-line +} +.hdsmi-template--5 .hdsmi-template__title { + +} +.hdsmi-template--5 .hdsmi-template__image { + width: calc(50 * var(--hdsmi-template--unit)); + height: 100%; + object-fit: cover +} +.hdsmi-template--5 .hdsmi-template__logo { + position: absolute; + top: calc(3 * var(--hdsmi-template--unit)); + right: calc(3 * var(--hdsmi-template--unit)) +} diff --git a/assets/img/google-font-family-example.jpg b/assets/img/google-font-family-example.jpg new file mode 100644 index 0000000..03d3840 Binary files /dev/null and b/assets/img/google-font-family-example.jpg differ diff --git a/assets/img/google-font-url-example.jpg b/assets/img/google-font-url-example.jpg new file mode 100644 index 0000000..096daf6 Binary files /dev/null and b/assets/img/google-font-url-example.jpg differ diff --git a/assets/img/no-image.jpg b/assets/img/no-image.jpg new file mode 100644 index 0000000..d2fcabd Binary files /dev/null and b/assets/img/no-image.jpg differ diff --git a/assets/js/ssi-wpjm-admin.js b/assets/js/ssi-wpjm-editor.js similarity index 73% rename from assets/js/ssi-wpjm-admin.js rename to assets/js/ssi-wpjm-editor.js index 835314e..13b9cad 100644 --- a/assets/js/ssi-wpjm-admin.js +++ b/assets/js/ssi-wpjm-editor.js @@ -24,17 +24,27 @@ // what happens on success. success: function( response, status, request ) { - // set the image src to the response. - $( '.ssi-image' ).attr( 'src', response.url ); + // if the response is a success. + if ( false !== response.success ) { - // change the media id in the delete button. - $( '.delete-ssi-image-button' ).data( 'media-id', response.id ); + // set the image src to the response. + $( '.ssi-image' ).attr( 'src', response.url ); - // remove the hidden class for the delete button. - $( '.delete-ssi-image-button' ).removeClass( 'ssi-hidden' ); + // change the media id in the delete button. + $( '.delete-ssi-image-button' ).data( 'media-id', response.id ); + + // remove the hidden class for the delete button. + $( '.delete-ssi-image-button' ).removeClass( 'ssi-hidden' ); + + // add the hidden class for the add button. + $( '.generate-ssi-image-button' ).addClass( 'ssi-hidden' ); + + } else { - // add the hidden class for the add button. - $( '.generate-ssi-image-button' ).addClass( 'ssi-hidden' ); + $( '.ssi-wpjm-error' ).remove(); + $( '.ssi-wpjm-spinner' ).before( '
' + response.error + '
' ); + + } // hide the deploy spinner. $( '.ssi-wpjm-spinner' ).hide(); @@ -44,8 +54,8 @@ /* what happens on success */ error: function( response ) { - console.log( 'Error' ); - console.log( response ); + // hide the deploy spinner. + $( '.ssi-wpjm-spinner' ).hide(); } @@ -103,8 +113,8 @@ /* what happens on success */ error: function( response ) { - console.log( 'Error' ); - console.log( response ); + // hide the deploy spinner. + $( '.ssi-wpjm-spinner' ).hide(); } diff --git a/assets/js/ssi-wpjm-settings.js b/assets/js/ssi-wpjm-settings.js new file mode 100644 index 0000000..6b480e7 --- /dev/null +++ b/assets/js/ssi-wpjm-settings.js @@ -0,0 +1,313 @@ +(function( $ ) { + + // Add Color Picker to all inputs that have .ssi-wpjm-input--color-picker + $( function() { + $( '.ssi-wpjm-input--color-picker' ).wpColorPicker(); + }); + + $('body').on('click', '.ssi-wpjm-image-button', function(e) { + e.preventDefault(); + + // get the previous input. + var inputID = $( this ).prev(); + var imgID = $( inputID ).prev().children('img')[0]; + + ssi_wpjm_image_uploader = wp.media({ + title: 'Image', + button: { + text: 'Use this image' + }, + multiple: false + }).on('select', function() { + + var attachment = ssi_wpjm_image_uploader.state().get('selection').first().toJSON(); + $( inputID ).val(attachment.id); + $( imgID ).attr( 'src', attachment.sizes.full.url ); + }) + .open(); + }); + + $('body').on('click', '.ssi-wpjm-image--remove', function(e) { + + // get the previous input. + var img = $( this ).prev(); + + $( img ).attr( 'src', $( this ).data( 'placeholder' ) ); + $( '#' + $( this ).data( 'input-id' ) ).val(''); + + }); + + $('body').on('click', '.ssi-wpjm-gallery-button', function(e) { + + e.preventDefault(); + + // get the current values. + currentValue = $( this ).prev().val(); + + // if current value is currently empty. + if ( currentValue === '' ) { + currentValues = []; + } else { + currentValues = currentValue.split( ',' ); + } + + // get the current gallery images stored. + var galleryImageIds = $( this ).prev(); + + // get the gallery wrapper element. + var galleryWrapper = galleryImageIds.prev(); + + ssi_wpjm_gallery_uploader = wp.media({ + title: 'Image', + button: { + text: 'Use this image' + }, + multiple: true + }).on('select', function() { + + var attachments = ssi_wpjm_gallery_uploader.state().get('selection').toJSON(); + + // loop through each of the attachments selected. + $.each( attachments , function( index, val ) { + + // if this attachment id is not already in the current values array. + if ( currentValues.indexOf( val.id + '' ) !== 0 ) { + + // add attachment ID to the array. + currentValues.push( val.id ); + + // output a new figure and image element on the page. + + // create a new figure element. + imageFigure = $( '' ); + + // create the removal span. + removeSpan = $( '' ); + removeSpan.attr( 'data-image-id', val.id ); + + // add the span for removing. + $( imageFigure ).prepend( removeSpan ); + + imageEl = $( '' ) + imageEl.attr( 'src', val.sizes.thumbnail.url ); + + // add a new image to the figure. + $( imageFigure ).prepend( imageEl ); + + // append to the gallery wrapper. + $( galleryWrapper ).prepend( imageFigure ); + + + } + + }); + + // convert the current values array to a new values string. + newValues = currentValues.toString(); + + // set the input to the new current values. + $( galleryImageIds ).val( newValues ); + + }) + .open(); + + }); + + $('body').on('click', '.ssi-wpjm-gallery--remove', function(e) { + + // get the previous input. + var img = $( this ).prev(); + var figure = $( img ).parent(); + + // remove this image. + figure.remove(); + + // get the current value of the background images input. + // NEED TO FIND THIS DYNAMICALLY BASED ON WHERE WE ARE ON CLICK! + var currentImages = $( '#ssi_wpjm_background_images-input').val(); + var currentImagesArray = currentImages.split( ',' ); + + var imageID = $( this ).data( 'image-id' ); + + // find the key of this image id in the current images array. + var key = currentImagesArray.indexOf( imageID + '' ); + + // remove the imageID from the current images array. + currentImagesArray.splice( key, 1 ); + + // NEED TO FIND THIS DYNAMICALLY BASED ON WHERE WE ARE ON CLICK! + $( '.ssi-wpjm-input--gallery' ).val( currentImagesArray ); + + }); + + + + + + + /* Live preview settings */ + + /* Logo size */ + var logoSize = document.querySelector("#ssi_wpjm_logo_size"); + + logoSize.addEventListener("change", function() { + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--logo--height", this.value); + }); + + /* Text color */ + $('#ssi_wpjm_text_color').iris({ + //hide: false, + change: function(event, ui) { + // event = standard jQuery event, produced by whichever control was changed. + // ui = standard jQuery UI object, with a color member containing a Color.js object + + // update customproperty on 'Clear' button press. + $('.wp-picker-clear').on('click', function(){ + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--text--background-color", 'transparent'); + + }); + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--text--color", ui.color.toString()); + + // update the color preview background color. + $(this).parents('.wp-picker-container').find('.button.wp-color-result').css('background-color', ui.color.toString()); + + } + }); + + /* Text background color */ + //var added_clearer = false; + $('#ssi_wpjm_text_bg_color').iris({ + //hide: false, + change: function(event, ui) { + // event = standard jQuery event, produced by whichever control was changed. + // ui = standard jQuery UI object, with a color member containing a Color.js object + + // update customproperty on 'Clear' button press. + $('.wp-picker-clear').on('click', function(){ + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--text--background-color", 'transparent'); + + }); + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--text--background-color", ui.color.toString()); + + // update the color preview background color. + $(this).parents('.wp-picker-container').find('.button.wp-color-result').css('background-color', ui.color.toString()); + + } + }); + + + /* Background color */ + $('#ssi_wpjm_bg_color').iris({ + //hide: false, + change: function(event, ui) { + // event = standard jQuery event, produced by whichever control was changed. + // ui = standard jQuery UI object, with a color member containing a Color.js object + + // update customproperty on 'Clear' button press. + $('.wp-picker-clear').on('click', function(){ + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--text--background-color", 'transparent'); + + }); + + // update the custom property. + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--background-color", ui.color.toString()); + + // update the color preview background color. + $(this).parents('.wp-picker-container').find('.button.wp-color-result').css('background-color', ui.color.toString()); + + } + }); + + /* Title font size */ + var titleFontSize = document.querySelector("#ssi_wpjm_title_size"); + + titleFontSize.addEventListener("change", function() { + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--title--font-size", this.value); + }); + + /* Location font size */ + var locationFontSize = document.querySelector("#ssi_wpjm_location_size"); + + locationFontSize.addEventListener("change", function() { + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--location--font-size", this.value); + }); + + /* Salary font size */ + var salaryFontSize = document.querySelector("#ssi_wpjm_salary_size"); + + salaryFontSize.addEventListener("change", function() { + var newFontSize = this.value; + document.querySelector(".hdsmi-template").style.setProperty("--hdsmi--salary--font-size", newFontSize); + }); + + /* Template choice */ + var templateChoice = document.querySelector("#ssi_wpjm_template"); + + templateChoice.addEventListener("change", function() { + + var template = document.querySelector(".hdsmi-template"); + + template.classList.remove('hdsmi-template--1', 'hdsmi-template--2', 'hdsmi-template--3', 'hdsmi-template--4', 'hdsmi-template--5'); + + template.classList.add("hdsmi-template--" + this.value); + + }); + + /* Logo file */ + $('img.ssi-wpjm-image').on('load', function () { + $('.hdsmi-template__logo').attr('src', $('img.ssi-wpjm-image').attr('src')); + }); + + /* Background images */ + + $('img.ssi-wpjm-gallery-image').on('load', function () { + + imgSrc = $(this).attr('src'); + fullImgSrc = imgSrc.replace("-150x150", ""); + $('.hdsmi-template__image').attr('src', fullImgSrc); + + }); + + $(document).on('click', '.ssi-wpjm-gallery-image', function () { + + // get the image source. + imgSrc = $(this).attr('src'); + fullImgSrc = imgSrc.replace("-150x150", ""); + + // set template image source. + $('.hdsmi-template__image').attr('src', fullImgSrc); + + }); + + /* Placeholder text fields */ + $('.hdsmi-template__text > * ').on('focusout', function () { + + //console.log('Focusout'); + + // find the inner element + editableText = $(this).find('[contenteditable="true"]'); + + // get the content. + thisContent = editableText.text(); + //console.log(thisContent); + + // get the data-input value. + dataInputValue = editableText.data('input'); + //console.log(dataInputValue); + + // set the input value. + $('#' + dataInputValue).val(thisContent); + + }); + +})( jQuery ); \ No newline at end of file diff --git a/endpoints/generate-html.php b/endpoints/generate-html.php new file mode 100644 index 0000000..de89a14 --- /dev/null +++ b/endpoints/generate-html.php @@ -0,0 +1,254 @@ + ssi_wpjm_get_template(), + 'post_id' => $post_id, + 'bg_color' => ssi_wpjm_get_bg_color(), + 'bg_text_color' => ssi_wpjm_get_text_bg_color(), + 'text_color' => ssi_wpjm_get_text_color(), + 'title_size' => ssi_wpjm_get_title_font_size(), + 'location_size' => ssi_wpjm_get_location_font_size(), + 'salary_size' => ssi_wpjm_get_salary_font_size(), + 'google_font_url' => ssi_wpjm_get_google_font_url(), + 'google_font_family' => ssi_wpjm_get_google_font_family(), + 'logo_size' => ssi_wpjm_get_logo_size(), + 'image' => wp_get_attachment_image_url( ssi_wpjm_get_random_image_id(), 'full' ), + 'logo' => wp_get_attachment_image_url( ssi_wpjm_get_logo_id(), 'full' ), +); + +// if the current post has a featured image. +if ( has_post_thumbnail( $args['post_id'] ) ) { + + // set the image url to that of the featured image. + $args['image'] = get_the_post_thumbnail_url( $args['post_id'], 'full' ); + +} + +// allow the args to be filtered. +$args = apply_filters( 'ssi_wpjm_endpoint_generate_args', $args ); + +// set the location of the template file, making it filterable. +$template_location = apply_filters( 'ssi_wpjm_endpoint_generate_template_location', SSI_WPJM_LOCATION . '/templates/', $args ); + +// start output buffering. +ob_start(); + +?> + + + + + + + + + + + + + + + + + + +'; diff --git a/endpoints/generate.php b/endpoints/generate.php deleted file mode 100644 index 82b6173..0000000 --- a/endpoints/generate.php +++ /dev/null @@ -1,173 +0,0 @@ - get_option( 'ssi_wpjm_template' ), - 'job_post' => $job_post, - 'bg_color' => get_option( 'ssi_wpjm_bg_color' ), - 'bg_text_color' => get_option( 'ssi_wpjm_text_bg_color' ), - 'text_color' => get_option( 'ssi_wpjm_text_color' ), - 'image' => wp_get_attachment_image_url( ssi_wpjm_get_random_image_id(), 'full' ), - 'logo' => wp_get_attachment_image_url( get_option( 'ssi_wpjm_logo_id' ), 'full' ), -); - -// allow the args to be filtered. -$args = apply_filters( 'ssi_wpjm_endpoint_generate_args', $args ); - -// set the location of the template file, making it filterable. -$template_location = apply_filters( 'ssi_wpjm_generate_template_location', SSI_WPJM_LOCATION . '/templates/', $args ); -$template_css_location = apply_filters( 'ssi_wpjm_generate_template_css_location', SSI_WPJM_LOCATION . '/assets/css/', $args ); - -// start output buffering. -ob_start(); - -// load the template markup, passing our args. -load_template( SSI_WPJM_LOCATION . '/assets/css/global.php', true, $args ); - -// if our template exists. -if ( file_exists( $template_css_location . $args['template'] . '.php' ) ) { - - // load the template markup, passing our args. - load_template( $template_css_location . $args['template'] . '.php', true, $args ); - -} - -// if our template exists. -if ( file_exists( $template_location . $args['template'] . '.php' ) ) { - - // load the template markup, passing our args. - load_template( $template_location . $args['template'] . '.php', true, $args ); - -} - -// get the contents of the buffer, the template markup and clean the buffer. -$text = ob_get_clean(); - -// find all of the strings that need replacing. -preg_match_all( "/\[[^\]]*\]/", $text, $matches ); - -// if we have matches. -if ( $matches !== false ) { - - // loop through the matches. - foreach ( $matches[0] as $match ) { - - // remove the brackets for the string. - $match_value = str_replace( '[', '', $match ); - $match_value = str_replace( ']', '', $match_value ); - - // if this is a meta replace. - if ( strpos( $match_value, 'meta' ) !== false ) { - - // remove the meta: string - $match_key = str_replace( 'meta:', '', $match_value ); - - // get the value of this meta. - $match_value = get_post_meta( $args['job_post'], $match_key, true ); - - // filter the match post value. - $match_value = apply_filters( 'ssi_wpjm_template_' . $match_key, $match_value, $match_key ); - - // replace the original text string with the new - $text = str_replace( $match, $match_value, $text ); - - } - - // if this is a tax replace. - if ( strpos( $match_value, 'tax' ) !== false ) { - - // remove the tax: string - $match_key = str_replace( 'tax:', '', $match_value ); - - // get the value of this meta. - $match_value = wp_strip_all_tags( - get_the_term_list( - $args['job_post'], - $match_key, - '', - ', ', - '' - ) - ); - - // filter the match post value. - $match_value = apply_filters( 'ssi_wpjm_template_' . $match_key, $match_value, $match_key ); - - // replace the original text string with the new - $text = str_replace( $match, $match_value, $text ); - - } - - // if this is a post field replace. - if ( strpos( $match_value, 'post' ) !== false ) { - - // remove the tax: string - $match_key = str_replace( 'post:', '', $match_value ); - - // get the value of this meta. - $match_value = get_post_field( $match_key, $args['job_post'] ); - - // if we have no job post id. - if ( empty( $args['job_post'] ) ) { - - // set the match value to the site title. - $match_value = get_bloginfo( 'title' ); - - } - - // filter the match post value. - $match_value = apply_filters( 'ssi_wpjm_template_' . $match_key, $match_value, $match_key ); - - // replace the original text string with the new - $text = str_replace( $match, $match_value, $text ); - - } - - // if we have a logo. - if ( empty( $args['logo'] ) ) { - - // set the logo to a transparent image. - $args['logo'] = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; - - } - - // if we have a image. - if ( empty( $args['image'] ) ) { - - // set the image to a transparent image. - $args['logo'] = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; - - } - - // if we have a template. - if ( empty( $args['template'] ) ) { - - // default the template. - $args['template'] = '1'; - - } - - // replace the logo string. - $text = str_replace( '[logo]', $args['logo'], $text ); - - // replace the template string. - $text = str_replace( '[template]', $args['template'], $text ); - - // replace the image string. - $text = str_replace( '[image]', $args['image'], $text ); - - } - -} - -echo $text; diff --git a/inc/admin-menu.php b/inc/admin-menu.php new file mode 100644 index 0000000..39b01b4 --- /dev/null +++ b/inc/admin-menu.php @@ -0,0 +1,161 @@ + + +ID ) ) . '">preview it first if you like.', 'simpe-social-images-wpjm' ); ?>
- // we should be showing the button so remove the hide class. - $key = array_search( 'delete-ssi-image-button--hidden', $delete_button_class, true ); + + + - // output the delete button. - ?> + " id="delete-ssi-image" data-endpoint-url="" data-media-id="" data-placeholder-img=""> - - + // set class for the delete button. + $delete_button_class = array( + 'button-secondary', + 'delete-ssi-image-button', + 'ssi-hidden', + ); + + // if there is a current social image set. + if ( $social_image_id !== 0 ) { - + // if we have found the class. + if ( $key !== false ) { - + // remove the class from the array. + unset( $delete_button_class[ $key ] ); - + // output the delete button. + ?> - + - + + + + + + + + social->facebook->getImage(); + + // if we have a custom open graph image set. + if ( ! empty( $custom_og_image ) ) { + + // prevent this plugin outputting an og image. + add_filter( 'ssi_wpjm_render_og_image_tags', '__return_false' ); + + } + + // return the meta tags. + return $facebook_tags; +} + +add_filter( 'aioseo_facebook_tags', 'ssi_wpjm_aioseo_change_open_graph_tags' ); + +/** + * Change Twitter image output with All in one SEO if necessary. + * + * @param string $url URL of the image. + */ +function ssi_wpjm_aioseo_change_twitter_tags( $twitter_tags ) { + + // if this is not a single job. + if ( ! is_singular( 'job_listing') ) { + return $twitter_tags; + } + + // get custom twitter images. + $custom_twitter_image = \aioseo()->social->twitter->getImage(); + + // if we have a custom twitter image set. + if ( ! empty( $custom_twitter_image ) ) { + + // prevent this plugin outputting a twitter image. + add_filter( 'ssi_wpjm_render_twitter_image_tags', '__return_false' ); + + } + + // return the meta tags. + return $twitter_tags; +} + +add_filter( 'aioseo_twitter_tags', 'ssi_wpjm_aioseo_change_twitter_tags' ); diff --git a/inc/plugins/rank-math-seo.php b/inc/plugins/rank-math-seo.php new file mode 100644 index 0000000..6e36415 --- /dev/null +++ b/inc/plugins/rank-math-seo.php @@ -0,0 +1,89 @@ + 'ssi_wpjm_license_key', - 'label' => __( 'License Key', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter your license key for the Simple Social Images service. You can signup for a license here.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), - array( - 'name' => 'ssi_wpjm_template', - 'std' => '', - 'label' => __( 'Template', 'simple-social-images-wpjm' ), - 'desc' => __( 'Choose your template for the social sharing images that are generated.', 'simple-social-images-wpjm' ), - 'type' => 'select', - 'options' => array( - '1' => __( 'Template 1', 'simple-social-images-wpjm' ), - '2' => __( 'Template 2', 'simple-social-images-wpjm' ), - '3' => __( 'Template 3', 'simple-social-images-wpjm' ), - '4' => __( 'Template 4', 'simple-social-images-wpjm' ), - '5' => __( 'Template 5', 'simple-social-images-wpjm' ), - ), - 'attributes' => array(), - ), - array( - 'name' => 'ssi_wpjm_text_color', - 'label' => __( 'Text Colour', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter the hex code of your text colour. The text on your image will be this colour.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), - array( - 'name' => 'ssi_wpjm_text_bg_color', - 'label' => __( 'Text Background Colour', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter the hex code of your text background colour. The colour behind your text on your image will be this colour.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), - array( - 'name' => 'ssi_wpjm_bg_color', - 'label' => __( 'Background Colour', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter the hex code of your background colour.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), - array( - 'name' => 'ssi_wpjm_images', - 'label' => __( 'Image IDs', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter a comma seperated list of WordPress attachment IDs of the images you want to be randomly used when your image is generated.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), + // get the registered settings. + $settings = ssi_wpjm_get_settings(); + + // if we have no settings. + if ( empty( $settings ) ) { + return; + } + + // set up default option args. + $defaults = array( + 'label' => '', + 'option_name' => '', + 'input_type' => 'text', + 'type' => 'string', + 'description' => '', + 'sanitize_callback' => null, + 'show_in_rest' => false, + 'order' => 10, + ); + + // loop through each setting. + foreach ( $settings as $setting ) { + + // merge the args with defaults. + $args = wp_parse_args( $setting, $defaults ); + + // if no setting key is set. + if ( '' === $args['option_name'] ) { + + // don't register the setting. + continue; + + } + + // register this setting. + register_setting( + 'ssi_wpjm_settings', // setting group name. + $args['option_name'], // setting name - the option key. array( - 'name' => 'ssi_wpjm_logo_id', - 'label' => __( 'Logo Attachment ID', 'simple-social-images-wpjm' ), - 'desc' => __( 'Enter the attachment IDs of the image you want to use as the logo.', 'simple-social-images-wpjm' ), - 'type' => 'text', - 'attributes' => array(), - ), - ), - array( - 'before' => __( 'Simple Social Images generates a automatic, beautiful and branded image for each job which, if the job is shared on social media, for example LinkedIn, shows as the preview image for the job. This really makes your jobs stand out from the crowd in social media feeds. Enter your settings below.', 'simple-social-image-wpjm' ), + 'type' => $args['type'], + 'group' => 'ssi_wpjm_settings', + 'description' => $args['description'], + 'sanitize_callback' => $args['sanitize_callback'], + 'show_in_rest' => $args['show_in_rest'], + ) + ); + + } + +} + +add_action( 'admin_init', 'ssi_wpjm_register_settings' ); + +/** + * Registers the plugins default settings. + * + * @param array $settings The current array of settings. + * @return array $settings The modified array of settings. + */ +function ssi_wpjm_register_default_settings( $settings ) { + + $settings['license_key'] = array( + 'option_name' => 'ssi_wpjm_license_key', + 'label' => __( 'License Key', 'simple-social-images-wpjm' ), + 'description' => sprintf( __( 'Enter your %1$sSimple Social Images%2$s license key. This is required in order to generate your social sharing images.', 'simple-social-images-wpjm' ), '', '' ), + 'input_type' => 'text', + 'order' => 10, + ); + + $settings['template_section'] = array( + 'option_name' => 'ssi_wpjm_template_section', + 'label' => __( 'Template Settings', 'simple-social-images-wpjm' ), + 'input_type' => 'section', + 'order' => 12, + ); + + $settings['template'] = array( + 'option_name' => 'ssi_wpjm_template', + 'label' => __( 'Select a Template', 'simple-social-images-wpjm' ), + 'description' => __( 'Choose which template to use.', 'simple-social-images-wpjm' ), + 'input_type' => 'select', + 'options' => array( + '1' => __( 'Template 1', 'simple-social-images-wpjm' ), + '2' => __( 'Template 2', 'simple-social-images-wpjm' ), + '3' => __( 'Template 3', 'simple-social-images-wpjm' ), + '4' => __( 'Template 4', 'simple-social-images-wpjm' ), + '5' => __( 'Template 5', 'simple-social-images-wpjm' ), ), + 'order' => 15, ); - // return the settings array. + $settings['colors_section'] = array( + 'option_name' => 'ssi_wpjm_colors_section', + 'label' => __( 'Colour Settings', 'simple-social-images-wpjm' ), + 'input_type' => 'section', + 'order' => 20, + ); + + $settings['text_color'] = array( + 'option_name' => 'ssi_wpjm_text_color', + 'label' => __( 'Text Colour', 'simple-social-images-wpjm' ), + 'description' => __( 'Enter or choose the text colour.', 'simple-social-images-wpjm' ), + 'input_type' => 'color_picker', + 'order' => 30, + ); + + $settings['text_bg_color'] = array( + 'option_name' => 'ssi_wpjm_text_bg_color', + 'label' => __( 'Text Background Colour', 'simple-social-images-wpjm' ), + 'description' => __( 'Enter or choose the text background colour.', 'simple-social-images-wpjm' ), + 'input_type' => 'color_picker', + 'order' => 40, + ); + + $settings['bg_color'] = array( + 'option_name' => 'ssi_wpjm_bg_color', + 'label' => __( 'Background Colour', 'simple-social-images-wpjm' ), + 'description' => __( 'Enter or choose the background colour.', 'simple-social-images-wpjm' ), + 'input_type' => 'color_picker', + 'order' => 50, + ); + + $settings['logo_section'] = array( + 'option_name' => 'ssi_wpjm_logo_section', + 'label' => __( 'Logo Settings', 'simple-social-images-wpjm' ), + 'input_type' => 'section', + 'order' => 60, + ); + + $settings['logo'] = array( + 'option_name' => 'ssi_wpjm_logo', + 'label' => __( 'Image', 'simple-social-images-wpjm' ), + 'description' => __( 'Upload your logo to display on your images.', 'simple-social-images-wpjm' ), + 'input_type' => 'image', + 'order' => 70, + ); + + $settings['logo_size'] = array( + 'option_name' => 'ssi_wpjm_logo_size', + 'label' => __( 'Size', 'simple-social-images-wpjm' ), + 'description' => __( 'Select a size for the logo.', 'simple-social-images-wpjm' ), + 'input_type' => 'range', + 'min' => '4', + 'max' => '12', + 'step' => '0.1', + 'order' => 80, + ); + + $settings['background_images_section'] = array( + 'option_name' => 'ssi_wpjm_background_images_section', + 'label' => __( 'Background Images Settings', 'simple-social-images-wpjm' ), + 'input_type' => 'section', + 'order' => 90, + ); + + $settings['background_images'] = array( + 'option_name' => 'ssi_wpjm_background_images', + 'label' => __( 'Add Images', 'simple-social-images-wpjm' ), + 'description' => __( 'Upload background images to use on your template. Each template uses the background image slightly differently. Images are chosen at random from the images uploaded here, assuming your job does not have a featured image.', 'simple-social-images-wpjm' ), + 'input_type' => 'gallery', + 'order' => 100, + ); + + $settings['fonts_section'] = array( + 'option_name' => 'ssi_wpjm_font_sizes_section', + 'label' => __( 'Font Settings', 'simple-social-images-wpjm' ), + 'input_type' => 'section', + 'order' => 110, + ); + + $settings['title_size'] = array( + 'option_name' => 'ssi_wpjm_title_size', + 'label' => __( 'Title Size', 'simple-social-images-wpjm' ), + 'description' => __( 'Select a size for the title.', 'simple-social-images-wpjm' ), + 'input_type' => 'range', + 'min' => '2', + 'max' => '8', + 'step' => '0.5', + 'order' => 120, + ); + + $settings['location_size'] = array( + 'option_name' => 'ssi_wpjm_location_size', + 'label' => __( 'Location Size', 'simple-social-images-wpjm' ), + 'description' => __( 'Select a size for the location.', 'simple-social-images-wpjm' ), + 'input_type' => 'range', + 'min' => '2', + 'max' => '8', + 'step' => '0.5', + 'order' => 130, + ); + + $settings['salary_size'] = array( + 'option_name' => 'ssi_wpjm_salary_size', + 'label' => __( 'Salary Size', 'simple-social-images-wpjm' ), + 'description' => __( 'Select a size for the salary.', 'simple-social-images-wpjm' ), + 'input_type' => 'range', + 'min' => '2', + 'max' => '8', + 'step' => '0.5', + 'order' => 140, + ); + + $settings['google_font_url'] = array( + 'option_name' => 'ssi_wpjm_google_font_url', + 'label' => __( 'Google Font URL', 'simple-social-images-wpjm' ), + 'description' => __( 'Enter the URL of the Google font you wish to use.', 'simple-social-images-wpjm' ), + 'description' => sprintf( __( 'Enter the URL of the Google font. %1$sSee an example of what is required%2$s (the highlighted text).', 'simple-social-images-wpjm' ), '', '' ), + 'input_type' => 'text', + 'sanitize_callback' => 'sanitize_url', + 'order' => 150, + ); + + $settings['google_font_family'] = array( + 'option_name' => 'ssi_wpjm_google_font_family', + 'label' => __( 'Google Font Family', 'simple-social-images-wpjm' ), + 'description' => sprintf( __( 'Enter the name of the Google font family. %1$sSee an example of what is required%2$s (the highlighted text).', 'simple-social-images-wpjm' ), '', '' ), + 'input_type' => 'text', + 'order' => 160, + ); + + $settings['title_placeholder_text'] = array( + 'option_name' => 'ssi_wpjm_title_placeholder_text', + 'label' => __( 'Title Placeholder Text', 'simple-social-images-wpjm' ), + 'input_type' => 'hidden', + 'order' => 170, + ); + + $settings['salary_placeholder_text'] = array( + 'option_name' => 'ssi_wpjm_salary_placeholder_text', + 'label' => __( 'Salary Placeholder Text', 'simple-social-images-wpjm' ), + 'input_type' => 'hidden', + 'order' => 170, + ); + + $settings['location_placeholder_text'] = array( + 'option_name' => 'ssi_wpjm_location_placeholder_text', + 'label' => __( 'Location Placeholder Text', 'simple-social-images-wpjm' ), + 'input_type' => 'hidden', + 'order' => 170, + ); + + // return the registered settings array. return $settings; } -add_filter( 'job_manager_settings', 'ssi_wpjm_register_settings', 10, 1 ); +add_filter( 'ssi_wpjm_settings', 'ssi_wpjm_register_default_settings' ); + +/** + * Controls the output of text input setting. + * + * @param array $setting an array of the current setting. + * @param mixed $value the current value of this setting saved in the database. + */ +function ssi_wpjm_setting_input_type_text( $setting, $value ) { + + // handle output for a text input. + ?> + + + + + + + + + + + + + + + + + + + + + + + + + +