Changeset 3086107
- Timestamp:
- 05/13/2024 09:00:35 PM (11 months ago)
- Location:
- alttext-ai/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/class-atai-settings.php (modified) (1 diff)
-
admin/js/admin.js (modified) (1 diff)
-
atai.php (modified) (2 diffs)
-
includes/class-atai-attachment.php (modified) (10 diffs)
-
includes/class-atai-utility.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
alttext-ai/trunk/README.txt
r3082790 r3086107 6 6 Requires at least: 4.7 7 7 Tested up to: 6.5 8 Stable tag: 1. 4.98 Stable tag: 1.5.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 65 65 66 66 == Changelog == 67 = 1.5.0 = 68 Sanitize DB queries 69 67 70 = 1.4.9 = 68 71 Minify JS -
alttext-ai/trunk/admin/class-atai-settings.php
r3076089 r3086107 337 337 'atai_timeout', 338 338 array( 339 'default' => ' 15',339 'default' => '20', 340 340 ) 341 341 ); -
alttext-ai/trunk/admin/js/admin.js
r3082790 r3086107 1 !function(){"use strict";const{__:e,sprintf:t}=wp.i18n;function a(){jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_bulk_generate",security:wp_atai.security_bulk_generate,posts_per_page:window.atai.postsPerPage,last_post_id:window.atai.lastPostId,keywords:window.atai.bulkGenerateKeywords,negativeKeywords:window.atai.bulkGenerateNegativeKeywords,mode:window.atai.bulkGenerateMode,onlyAttached:window.atai.bulkGenerateOnlyAttached,onlyNew:window.atai.bulkGenerateOnlyNew,batchId:window.atai.bulkGenerateBatchId},url:wp_atai.ajax_url,success:function(t){window.atai.progressCurrent+=t.process_count,window.atai.progressSuccessful+=t.success_count,window.atai.lastPostId=t.last_post_id,window.atai.progressBarEl.data("current",window.atai.progressCurrent),window.atai.progressCurrentEl.text(window.atai.progressCurrent),window.atai.progressSuccessfulEl.text(window.atai.progressSuccessful);const n=100*window.atai.progressCurrent/window.atai.progressMax;window.atai.progressBarEl.css("width",n+"%"),window.atai.progressPercent.text(n.toFixed(2)+"%"),t.recursive?a():(window.atai.progressButtonCancel.hide(),window.atai.progressBarWrapper.hide(),window.atai.progressButtonFinished.show(),window.atai.progressHeading.text(e("Update complete!","alttext-ai")),window.atai.redirectUrl=t?.redirect_url)},error:function(t){console.log(t),window.atai.progressButtonCancel.hide(),window.atai.progressBarWrapper.hide(),window.atai.progressButtonFinished.show(),window.atai.progressHeading.text(e("The update was stopped due to a server error. Restart the update to pick up where it left off.","alttext-ai"))}})}function n(e){return e.split(",").map((function(e){return e.trim()})).filter((function(e){return e.length>0})).slice(0,6)}function i(e){e=e.replace(/[[]/,"\\[").replace(/[\]]/,"\\]");let t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(window.location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function r(e,t,a){let n=document.getElementById(e),i=document.getElementById(t);if(i&&i.remove(),n){let e=s(t,a,"modal");return n.appendChild(e),!0}return!1}function s(t,a,i){const r=new URL(window.location.href);r.searchParams.set("atai_action","generate");const s=document.createElement("div");s.id=t;const o=document.createElement("a");o.id=t+"-anchor",o.href=r,o.className="button-secondary button-large";const c=document.createElement("div");c.id=t+"-checkbox-wrapper";const d=document.createElement("input");d.type="checkbox",d.id=t+"-keywords-checkbox",d.name="atai-generate-button-keywords-checkbox";const l=document.createElement("label");l.htmlFor="atai-generate-button-keywords-checkbox",l.innerText="Add SEO keywords";const u=document.createElement("div");u.id=t+"-textfield-wrapper",u.style.display="none";const p=document.createElement("input");p.type="text",p.id=t+"-textfield",p.name="atai-generate-button-keywords",p.size=40,c.appendChild(d),c.appendChild(l),u.appendChild(p),d.addEventListener("change",(function(){this.checked?(u.style.display="block",p.setSelectionRange(0,0),p.focus()):u.style.display="none"}));wp_atai.can_user_upload_files&&"error"!==(e=>{let t="error";return jQuery.ajax({type:"post",dataType:"json",async:!1,data:{action:"atai_check_image_eligibility",security:wp_atai.security_check_attachment_eligibility,attachment_id:e},url:wp_atai.ajax_url,success:function(e){t=e.status}}),t})(a)||(o.classList.add("disabled"),d.disabled=!0),o.title=e("AltText.ai: Update alt text for this single image","alttext-ai"),o.onclick=function(){this.classList.add("disabled");let t=this.querySelector("span");t&&(t.innerText=e("Processing...","alttext-ai"))};const w=document.createElement("img");w.src=wp_atai.icon_button_generate,w.alt=e("Update Alt Text with AltText.ai","alttext-ai"),o.appendChild(w);const g=document.createElement("span");g.innerText=e("Update Alt Text","alttext-ai"),o.appendChild(g),s.appendChild(o),s.appendChild(c),s.appendChild(u);const y=document.createElement("span");return y.classList.add("atai-update-notice"),s.appendChild(y),o.addEventListener("click",(async function(t){t.preventDefault(),wp_atai.has_api_key||(window.location.href=wp_atai.settings_page_url+"&api_key_missing=1");const r="single"==i?document.getElementById("title"):document.querySelector('[data-setting="title"] input'),s="single"==i?document.getElementById("attachment_caption"):document.querySelector('[data-setting="caption"] textarea'),c="single"==i?document.getElementById("attachment_content"):document.querySelector('[data-setting="description"] textarea'),l="single"==i?document.getElementById("attachment_alt"):document.querySelector('[data-setting="alt"] textarea'),u=d.checked?n(p.value):[];y&&(y.innerText="",y.classList.remove("atai-update-notice--success","atai-update-notice--error"));const w=await function(t,a=[]){return t?new Promise(((e,n)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_single_generate",security:wp_atai.security_single_generate,attachment_id:t,keywords:a},url:wp_atai.ajax_url,success:function(t){e(t)},error:function(e){n(new Error("AJAX request failed"))}})})):Promise.reject(new Error(e("Attachment ID is missing","alttext-ai")))}(a,u);if("success"===w.status)l.value=w.alt_text,"yes"===wp_atai.should_update_title&&(r.value=w.alt_text,"single"==i&&r.previousElementSibling.classList.add("screen-reader-text")),"yes"===wp_atai.should_update_caption&&(s.value=w.alt_text),"yes"===wp_atai.should_update_description&&(c.value=w.alt_text),y.innerText=e("Updated","alttext-ai"),y.classList.add("atai-update-notice--success"),setTimeout((()=>{y.classList.remove("atai-update-notice--success")}),3e3);else{let t=e("Unable to generate alt text. Check error logs for details.","alttext-ai");w?.message&&(t=w.message),y.innerText=t,y.classList.add("atai-update-notice--error")}o.classList.remove("disabled"),o.querySelector("span").innerText=e("Update Alt Text","alttext-ai")})),s}window.atai=window.atai||{postsPerPage:1,lastPostId:0,intervals:{},redirectUrl:""},jQuery("[data-edit-history-trigger]").on("click",(async function(){const t=this,a=t.dataset.attachmentId,n=document.getElementById("edit-history-input-"+a).value.replace(/\n/g,"");t.disabled=!0;const i=await function(t,a=""){return t?new Promise(((e,n)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_edit_history",security:wp_atai.security_edit_history,attachment_id:t,alt_text:a},url:wp_atai.ajax_url,success:function(t){e(t)},error:function(e){n(new Error("AJAX request failed"))}})})):Promise.reject(new Error(e("Attachment ID is missing","alttext-ai")))}(a,n);"success"!==i.status&&alert(e("Unable to update alt text for this image.","alttext-ai"));const r=document.getElementById("edit-history-success-"+a);r.classList.remove("hidden"),setTimeout((()=>{r.classList.add("hidden")}),2e3),t.disabled=!1})),jQuery("[data-bulk-generate-start]").on("click",(function(){const t=i("atai_action")||"normal",r=i("atai_batch_id")||0;"bulk-select-generate"!==t||r||alert(e("Invalid batch ID","alttext-ai")),window.atai.bulkGenerateKeywords=n(jQuery("[data-bulk-generate-keywords]").val()??""),window.atai.bulkGenerateNegativeKeywords=n(jQuery("[data-bulk-generate-negative-keywords]").val()??""),window.atai.progressWrapperEl=jQuery("[data-bulk-generate-progress-wrapper]"),window.atai.progressHeading=jQuery("[data-bulk-generate-progress-heading]"),window.atai.progressBarWrapper=jQuery("[data-bulk-generate-progress-bar-wrapper]"),window.atai.progressBarEl=jQuery("[data-bulk-generate-progress-bar]"),window.atai.progressPercent=jQuery("[data-bulk-generate-progress-percent]"),window.atai.progressCurrentEl=jQuery("[data-bulk-generate-progress-current]"),window.atai.progressCurrent=window.atai.progressBarEl.data("current"),window.atai.progressSuccessfulEl=jQuery("[data-bulk-generate-progress-successful]"),window.atai.progressSuccessful=window.atai.progressBarEl.data("successful"),window.atai.progressMax=window.atai.progressBarEl.data("max"),window.atai.progressButtonCancel=jQuery("[data-bulk-generate-cancel]"),window.atai.progressButtonFinished=jQuery("[data-bulk-generate-finished]"),"bulk-select-generate"===t?(window.atai.bulkGenerateMode="bulk-select",window.atai.bulkGenerateBatchId=r):(window.atai.bulkGenerateMode=jQuery("[data-bulk-generate-mode-all]").is(":checked")?"all":"missing",window.atai.bulkGenerateOnlyAttached=jQuery("[data-bulk-generate-only-attached]").is(":checked")?"1":"0",window.atai.bulkGenerateOnlyNew=jQuery("[data-bulk-generate-only-new]").is(":checked")?"1":"0"),jQuery("#bulk-generate-form").hide(),window.atai.progressWrapperEl.show(),a()})),jQuery("[data-bulk-generate-mode-all]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-bulk-generate-only-attached]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-bulk-generate-only-new]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-post-bulk-generate]").on("click",(async function(t){if("#atai-bulk-generate"!==this.getAttribute("href"))return;if(t.preventDefault(),function(){try{if(window.wp&&wp.data&&wp.blocks)return wp.data.select("core/editor").isEditedPostDirty()}catch(e){return console.error("Error checking Gutenberg post dirty status: ",e),!0}return!0}()){if(!confirm(e("[AltText.ai] Make sure to save any changes before proceeding -- any unsaved changes will be lost. Are you sure you want to continue?","alttext-ai")))return}const a=document.getElementById("post_ID")?.value,i=this.querySelector("span"),r=this.nextElementSibling,s=i.innerText,o=document.querySelector("[data-post-bulk-generate-overwrite]")?.checked||!1,c=document.querySelector("[data-post-bulk-generate-process-external]")?.checked||!1,d=document.querySelector("[data-post-bulk-generate-keywords-checkbox]"),l=document.querySelector("[data-post-bulk-generate-keywords]"),u=d?.checked?n(l?.value):[];if(!a)return r.innerText=e("This is not a valid post.","alttext-ai"),void r.classList.add("atai-update-notice--error");this.classList.add("disabled"),i.innerText=e("Processing...","alttext-ai");const p=await function(t,a=!1,n=!1,i=[]){return t?new Promise(((r,s)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_enrich_post_content",security:wp_atai.security_enrich_post_content,post_id:t,overwrite:a,process_external:n,keywords:i},url:wp_atai.ajax_url,success:function(e){r(e)},error:function(t){s(new Error(e("AJAX request failed","alttext-ai")))}})})):Promise.reject(new Error(e("Post ID is missing","alttext-ai")))}(a,o,c,u);if(p.success)window.location.reload();else{let t=e("Unable to generate alt text. Check error logs for details.","alttext-ai");r.innerText=t,r.classList.add("atai-update-notice--error")}this.classList.remove("disabled"),i.innerText=s})),document.addEventListener("DOMContentLoaded",(()=>{wp?.blocks&&jQuery.ajax({url:wp_atai.ajax_url,type:"GET",data:{action:"atai_check_enrich_post_content_transient",security:wp_atai.security_enrich_post_content_transient},success:function(e){e?.success&&wp.data.dispatch("core/notices").createNotice("success",e.data.message,{isDismissible:!0})}})})),jQuery('[name="handle_api_key"]').on("click",(function(){"Clear API Key"===this.value&&jQuery('[name="atai_api_key"]').val("")})),jQuery(".notice--atai.is-dismissible").on("click",".notice-dismiss",(function(){jQuery.ajax(wp_atai.ajax_url,{type:"POST",data:{action:"atai_expire_insufficient_credits_notice",security:wp_atai.security_insufficient_credits_notice}})})),document.addEventListener("DOMContentLoaded",(async()=>{const e=window.location.href.includes("post.php")&&jQuery("body").hasClass("post-type-attachment"),t=window.location.href.includes("post-new.php")||window.location.href.includes("post.php")&&!jQuery("body").hasClass("post-type-attachment"),a=window.location.href.includes("upload.php");let n=null,o="atai-generate-button",c="alt-text-description";if(e){if(n=i("post"),!n)return!1;if(n=parseInt(n,10),!n)return;let e=document.getElementById(c);if(e){let t=s(o,n,"single");e.appendChild(t)}}else{if(!a&&!t)return!1;if(n=i("item"),jQuery(document).on("click","ul.attachments li.attachment",(function(){let e=jQuery(this);e.attr("data-id")&&(n=parseInt(e.attr("data-id"),10),n&&r(c,o,n))})),document.addEventListener("click",(function(e){if(!e.target.matches(".media-modal .right, .media-modal .left"))return;const t=new URLSearchParams(window.location.search);n=t.get("item"),n&&r(c,o,n)})),!n)return!1;if(n){let e=0;window.atai.intervals.singleModal=setInterval((()=>{if(e++,e>20)return void clearInterval(interval);if(n=parseInt(n,10),!n)return;r(c,o,n)&&clearInterval(window.atai.intervals.singleModal)}),500)}}}))}();1 !function(){"use strict";const{__:e,sprintf:t}=wp.i18n;function a(){jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_bulk_generate",security:wp_atai.security_bulk_generate,posts_per_page:window.atai.postsPerPage,last_post_id:window.atai.lastPostId,keywords:window.atai.bulkGenerateKeywords,negativeKeywords:window.atai.bulkGenerateNegativeKeywords,mode:window.atai.bulkGenerateMode,onlyAttached:window.atai.bulkGenerateOnlyAttached,onlyNew:window.atai.bulkGenerateOnlyNew,batchId:window.atai.bulkGenerateBatchId},url:wp_atai.ajax_url,success:function(t){window.atai.progressCurrent+=t.process_count,window.atai.progressSuccessful+=t.success_count,window.atai.lastPostId=t.last_post_id,window.atai.progressBarEl.data("current",window.atai.progressCurrent),window.atai.progressCurrentEl.text(window.atai.progressCurrent),window.atai.progressSuccessfulEl.text(window.atai.progressSuccessful);const n=100*window.atai.progressCurrent/window.atai.progressMax;window.atai.progressBarEl.css("width",n+"%"),window.atai.progressPercent.text(n.toFixed(2)+"%"),t.recursive?a():(window.atai.progressButtonCancel.hide(),window.atai.progressBarWrapper.hide(),window.atai.progressButtonFinished.show(),window.atai.progressHeading.text(e("Update complete!","alttext-ai")),window.atai.redirectUrl=t?.redirect_url)},error:function(t){console.log(t),window.atai.progressButtonCancel.hide(),window.atai.progressBarWrapper.hide(),window.atai.progressButtonFinished.show(),window.atai.progressHeading.text(e("The update was stopped due to a server error. Restart the update to pick up where it left off.","alttext-ai"))}})}function n(e){return e.split(",").map((function(e){return e.trim()})).filter((function(e){return e.length>0})).slice(0,6)}function i(e){e=e.replace(/[[]/,"\\[").replace(/[\]]/,"\\]");let t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(window.location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function r(e,t,a){let n=document.getElementById(e),i=document.getElementById(t);if(i&&i.remove(),n){let e=s(t,a,"modal");return e.className=n.className,n.parentNode.replaceChild(e,n),!0}return!1}function s(t,a,i){const r=new URL(window.location.href);r.searchParams.set("atai_action","generate");const s=document.createElement("div");s.id=t;const o=document.createElement("a");o.id=t+"-anchor",o.href=r,o.className="button-secondary button-large";const d=document.createElement("div");d.id=t+"-checkbox-wrapper";const c=document.createElement("input");c.type="checkbox",c.id=t+"-keywords-checkbox",c.name="atai-generate-button-keywords-checkbox";const l=document.createElement("label");l.htmlFor="atai-generate-button-keywords-checkbox",l.innerText="Add SEO keywords";const u=document.createElement("div");u.id=t+"-textfield-wrapper",u.style.display="none";const p=document.createElement("input");p.type="text",p.id=t+"-textfield",p.name="atai-generate-button-keywords",p.size=40,d.appendChild(c),d.appendChild(l),u.appendChild(p),c.addEventListener("change",(function(){this.checked?(u.style.display="block",p.setSelectionRange(0,0),p.focus()):u.style.display="none"}));wp_atai.can_user_upload_files&&"error"!==(e=>{let t="error";return jQuery.ajax({type:"post",dataType:"json",async:!1,data:{action:"atai_check_image_eligibility",security:wp_atai.security_check_attachment_eligibility,attachment_id:e},url:wp_atai.ajax_url,success:function(e){t=e.status}}),t})(a)||(o.classList.add("disabled"),c.disabled=!0),o.title=e("AltText.ai: Update alt text for this single image","alttext-ai"),o.onclick=function(){this.classList.add("disabled");let t=this.querySelector("span");t&&(t.innerText=e("Processing...","alttext-ai"))};const w=document.createElement("img");w.src=wp_atai.icon_button_generate,w.alt=e("Update Alt Text with AltText.ai","alttext-ai"),o.appendChild(w);const g=document.createElement("span");g.innerText=e("Update Alt Text","alttext-ai"),o.appendChild(g),s.appendChild(o),s.appendChild(d),s.appendChild(u);const y=document.createElement("span");return y.classList.add("atai-update-notice"),s.appendChild(y),o.addEventListener("click",(async function(t){t.preventDefault(),wp_atai.has_api_key||(window.location.href=wp_atai.settings_page_url+"&api_key_missing=1");const r="single"==i?document.getElementById("title"):document.querySelector('[data-setting="title"] input'),s="single"==i?document.getElementById("attachment_caption"):document.querySelector('[data-setting="caption"] textarea'),d="single"==i?document.getElementById("attachment_content"):document.querySelector('[data-setting="description"] textarea'),l="single"==i?document.getElementById("attachment_alt"):document.querySelector('[data-setting="alt"] textarea'),u=c.checked?n(p.value):[];y&&(y.innerText="",y.classList.remove("atai-update-notice--success","atai-update-notice--error"));const w=await function(t,a=[]){return t?new Promise(((e,n)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_single_generate",security:wp_atai.security_single_generate,attachment_id:t,keywords:a},url:wp_atai.ajax_url,success:function(t){e(t)},error:function(e){n(new Error("AJAX request failed"))}})})):Promise.reject(new Error(e("Attachment ID is missing","alttext-ai")))}(a,u);if("success"===w.status)l.value=w.alt_text,"yes"===wp_atai.should_update_title&&(r.value=w.alt_text,"single"==i&&r.previousElementSibling.classList.add("screen-reader-text")),"yes"===wp_atai.should_update_caption&&(s.value=w.alt_text),"yes"===wp_atai.should_update_description&&(d.value=w.alt_text),y.innerText=e("Updated","alttext-ai"),y.classList.add("atai-update-notice--success"),setTimeout((()=>{y.classList.remove("atai-update-notice--success")}),3e3);else{let t=e("Unable to generate alt text. Check error logs for details.","alttext-ai");w?.message&&(t=w.message),y.innerText=t,y.classList.add("atai-update-notice--error")}o.classList.remove("disabled"),o.querySelector("span").innerText=e("Update Alt Text","alttext-ai")})),s}window.atai=window.atai||{postsPerPage:1,lastPostId:0,intervals:{},redirectUrl:""},jQuery("[data-edit-history-trigger]").on("click",(async function(){const t=this,a=t.dataset.attachmentId,n=document.getElementById("edit-history-input-"+a).value.replace(/\n/g,"");t.disabled=!0;const i=await function(t,a=""){return t?new Promise(((e,n)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_edit_history",security:wp_atai.security_edit_history,attachment_id:t,alt_text:a},url:wp_atai.ajax_url,success:function(t){e(t)},error:function(e){n(new Error("AJAX request failed"))}})})):Promise.reject(new Error(e("Attachment ID is missing","alttext-ai")))}(a,n);"success"!==i.status&&alert(e("Unable to update alt text for this image.","alttext-ai"));const r=document.getElementById("edit-history-success-"+a);r.classList.remove("hidden"),setTimeout((()=>{r.classList.add("hidden")}),2e3),t.disabled=!1})),jQuery("[data-bulk-generate-start]").on("click",(function(){const t=i("atai_action")||"normal",r=i("atai_batch_id")||0;"bulk-select-generate"!==t||r||alert(e("Invalid batch ID","alttext-ai")),window.atai.bulkGenerateKeywords=n(jQuery("[data-bulk-generate-keywords]").val()??""),window.atai.bulkGenerateNegativeKeywords=n(jQuery("[data-bulk-generate-negative-keywords]").val()??""),window.atai.progressWrapperEl=jQuery("[data-bulk-generate-progress-wrapper]"),window.atai.progressHeading=jQuery("[data-bulk-generate-progress-heading]"),window.atai.progressBarWrapper=jQuery("[data-bulk-generate-progress-bar-wrapper]"),window.atai.progressBarEl=jQuery("[data-bulk-generate-progress-bar]"),window.atai.progressPercent=jQuery("[data-bulk-generate-progress-percent]"),window.atai.progressCurrentEl=jQuery("[data-bulk-generate-progress-current]"),window.atai.progressCurrent=window.atai.progressBarEl.data("current"),window.atai.progressSuccessfulEl=jQuery("[data-bulk-generate-progress-successful]"),window.atai.progressSuccessful=window.atai.progressBarEl.data("successful"),window.atai.progressMax=window.atai.progressBarEl.data("max"),window.atai.progressButtonCancel=jQuery("[data-bulk-generate-cancel]"),window.atai.progressButtonFinished=jQuery("[data-bulk-generate-finished]"),"bulk-select-generate"===t?(window.atai.bulkGenerateMode="bulk-select",window.atai.bulkGenerateBatchId=r):(window.atai.bulkGenerateMode=jQuery("[data-bulk-generate-mode-all]").is(":checked")?"all":"missing",window.atai.bulkGenerateOnlyAttached=jQuery("[data-bulk-generate-only-attached]").is(":checked")?"1":"0",window.atai.bulkGenerateOnlyNew=jQuery("[data-bulk-generate-only-new]").is(":checked")?"1":"0"),jQuery("#bulk-generate-form").hide(),window.atai.progressWrapperEl.show(),a()})),jQuery("[data-bulk-generate-mode-all]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-bulk-generate-only-attached]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-bulk-generate-only-new]").on("change",(function(){window.location.href=this.dataset.url})),jQuery("[data-post-bulk-generate]").on("click",(async function(t){if("#atai-bulk-generate"!==this.getAttribute("href"))return;if(t.preventDefault(),function(){try{if(window.wp&&wp.data&&wp.blocks)return wp.data.select("core/editor").isEditedPostDirty()}catch(e){return console.error("Error checking Gutenberg post dirty status: ",e),!0}return!0}()){if(!confirm(e("[AltText.ai] Make sure to save any changes before proceeding -- any unsaved changes will be lost. Are you sure you want to continue?","alttext-ai")))return}const a=document.getElementById("post_ID")?.value,i=this.querySelector("span"),r=this.nextElementSibling,s=i.innerText,o=document.querySelector("[data-post-bulk-generate-overwrite]")?.checked||!1,d=document.querySelector("[data-post-bulk-generate-process-external]")?.checked||!1,c=document.querySelector("[data-post-bulk-generate-keywords-checkbox]"),l=document.querySelector("[data-post-bulk-generate-keywords]"),u=c?.checked?n(l?.value):[];if(!a)return r.innerText=e("This is not a valid post.","alttext-ai"),void r.classList.add("atai-update-notice--error");this.classList.add("disabled"),i.innerText=e("Processing...","alttext-ai");const p=await function(t,a=!1,n=!1,i=[]){return t?new Promise(((r,s)=>{jQuery.ajax({type:"post",dataType:"json",data:{action:"atai_enrich_post_content",security:wp_atai.security_enrich_post_content,post_id:t,overwrite:a,process_external:n,keywords:i},url:wp_atai.ajax_url,success:function(e){r(e)},error:function(t){s(new Error(e("AJAX request failed","alttext-ai")))}})})):Promise.reject(new Error(e("Post ID is missing","alttext-ai")))}(a,o,d,u);if(p.success)window.location.reload();else{let t=e("Unable to generate alt text. Check error logs for details.","alttext-ai");r.innerText=t,r.classList.add("atai-update-notice--error")}this.classList.remove("disabled"),i.innerText=s})),document.addEventListener("DOMContentLoaded",(()=>{wp?.blocks&&jQuery.ajax({url:wp_atai.ajax_url,type:"GET",data:{action:"atai_check_enrich_post_content_transient",security:wp_atai.security_enrich_post_content_transient},success:function(e){e?.success&&wp.data.dispatch("core/notices").createNotice("success",e.data.message,{isDismissible:!0})}})})),jQuery('[name="handle_api_key"]').on("click",(function(){"Clear API Key"===this.value&&jQuery('[name="atai_api_key"]').val("")})),jQuery(".notice--atai.is-dismissible").on("click",".notice-dismiss",(function(){jQuery.ajax(wp_atai.ajax_url,{type:"POST",data:{action:"atai_expire_insufficient_credits_notice",security:wp_atai.security_insufficient_credits_notice}})})),document.addEventListener("DOMContentLoaded",(async()=>{const e=window.location.href.includes("post.php")&&jQuery("body").hasClass("post-type-attachment"),t=window.location.href.includes("post-new.php")||window.location.href.includes("post.php")&&!jQuery("body").hasClass("post-type-attachment"),a=window.location.href.includes("upload.php");let n=null,o="atai-generate-button";if(e){if(n=i("post"),!n)return!1;if(n=parseInt(n,10),!n)return;let e=document.getElementsByClassName("attachment-alt-text")[0];if(e){let t=s(o,n,"single");setTimeout((()=>{!function(e,t){if(e.hasChildNodes()){for(const a of e.childNodes)if("BUTTON"==a.nodeName)return void e.replaceChild(t,a);e.appendChild(t)}else e.appendChild(t)}(e,t)}),200)}}else{if(!a&&!t)return!1;if(n=i("item"),jQuery(document).on("click","ul.attachments li.attachment",(function(){let e=jQuery(this);e.attr("data-id")&&(n=parseInt(e.attr("data-id"),10),n&&r("alt-text-description",o,n))})),document.addEventListener("click",(function(e){if(!e.target.matches(".media-modal .right, .media-modal .left"))return;const t=new URLSearchParams(window.location.search);n=t.get("item"),n&&r("alt-text-description",o,n)})),!n)return!1;if(n){let e=0;window.atai.intervals.singleModal=setInterval((()=>{if(e++,e>30)return void clearInterval(window.atai.intervals.singleModal);if(n=parseInt(n,10),!n)return void clearInterval(window.atai.intervals.singleModal);r("alt-text-description",o,n)&&clearInterval(window.atai.intervals.singleModal)}),200)}}}))}(); -
alttext-ai/trunk/atai.php
r3082790 r3086107 16 16 * Plugin URI: https://alttext.ai/product 17 17 * Description: Automatically generate image alt text with AltText.ai. 18 * Version: 1. 4.918 * Version: 1.5.0 19 19 * Author: AltText.ai 20 20 * Author URI: https://alttext.ai … … 33 33 * Current plugin version. 34 34 */ 35 define( 'ATAI_VERSION', '1. 4.9' );35 define( 'ATAI_VERSION', '1.5.0' ); 36 36 37 37 /** -
alttext-ai/trunk/includes/class-atai-attachment.php
r3074350 r3086107 239 239 ON image_posts.post_parent = parent_posts.id 240 240 WHERE 241 image_posts.id = {$attachment_id}241 image_posts.id = %d 242 242 AND 243 243 parent_posts.post_type = 'product' … … 246 246 SQL; 247 247 248 $product_title_data = $wpdb->get_results( $ find_product_title_sql);248 $product_title_data = $wpdb->get_results( $wpdb->prepare($find_product_title_sql, $attachment_id) ); 249 249 250 250 if ( count( $product_title_data ) == 0 || strlen( $product_title_data[0]->product_title ) == 0 ) { … … 310 310 311 311 // Attempt to get the related post ID directly from WordPress based on the attachment: 312 $fetch_post_sql = "select post_parent from {$wpdb->posts} where ID = {$attachment_id}";313 $post_results = $wpdb->get_results( $ fetch_post_sql);312 $fetch_post_sql = "select post_parent from {$wpdb->posts} where ID = %d"; 313 $post_results = $wpdb->get_results( $wpdb->prepare($fetch_post_sql, $attachment_id) ); 314 314 315 315 if ( count( $post_results ) > 0 ) { … … 392 392 // If post ID is null, we may still be able to get it directly from the Yoast data for this attachment: 393 393 if ( ! $post_id ) { 394 $yoast_post_sql = "select post_id from {$wpdb->prefix}yoast_seo_links where target_post_id = {$attachment_id}";395 $results = $wpdb->get_results( $ yoast_post_sql);394 $yoast_post_sql = "select post_id from {$wpdb->prefix}yoast_seo_links where target_post_id = %d"; 395 $results = $wpdb->get_results( $wpdb->prepare($yoast_post_sql, $attachment_id) ); 396 396 397 397 if ( count( $results ) > 0 ) { … … 409 409 from {$wpdb->postmeta} 410 410 where meta_key = '_yoast_wpseo_focuskw' 411 and post_id = {$post_id};411 and post_id = %d 412 412 SQL; 413 413 414 $keywords = $wpdb->get_results( $ keyword_sql);414 $keywords = $wpdb->get_results( $wpdb->prepare($keyword_sql, $post_id) ); 415 415 416 416 if ( count( $keywords ) == 0 || strlen( $keywords[0]->focus_keywords ) == 0 ) { … … 425 425 from {$wpdb->postmeta} 426 426 where meta_key = '_yoast_wpseo_focuskeywords' 427 and post_id = {$post_id};427 and post_id = %d 428 428 SQL; 429 429 430 $keywords = $wpdb->get_results( $ keyword_sql);430 $keywords = $wpdb->get_results( $wpdb->prepare($keyword_sql, $post_id) ); 431 431 432 432 if ( count( $keywords ) > 0 ) { … … 516 516 from {$wpdb->postmeta} 517 517 where meta_key = 'rank_math_focus_keyword' 518 and post_id = {$post_id};518 and post_id = %d 519 519 SQL; 520 520 521 $keywords = $wpdb->get_results( $ keyword_sql);521 $keywords = $wpdb->get_results( $wpdb->prepare($keyword_sql, $post_id) ); 522 522 523 523 if ( count( $keywords ) == 0 || strlen( $keywords[0]->focus_keywords ) == 0 ) { … … 556 556 from {$wpdb->postmeta} 557 557 where meta_key = '_seopress_analysis_target_kw' 558 and post_id = {$post_id};558 and post_id = %d 559 559 SQL; 560 560 561 $keywords = $wpdb->get_results( $ keyword_sql);561 $keywords = $wpdb->get_results( $wpdb->prepare($keyword_sql, $post_id) ); 562 562 563 563 if ( count( $keywords ) == 0 || strlen( $keywords[0]->focus_keywords ) == 0 ) { … … 625 625 select COALESCE(post_title, '') as title 626 626 from {$wpdb->posts} 627 where ID = (select post_parent from {$wpdb->posts} where ID = {$attachment_id});627 where ID = (select post_parent from {$wpdb->posts} where ID = %d); 628 628 SQL; 629 629 630 $keyword_source = $wpdb->get_results( $ keyword_sql);630 $keyword_source = $wpdb->get_results( $wpdb->prepare($keyword_sql, $attachment_id) ); 631 631 if ( count( $keyword_source ) == 0 || strlen( $keyword_source[0]->title ) == 0 ) { 632 632 return; … … 674 674 675 675 global $wpdb; 676 $post_id = $_REQUEST['post_id'] ?? 0;677 $last_post_id = $_REQUEST['last_post_id'] ?? 0;678 $query_limit = $_REQUEST['posts_per_page'] ? ?1;676 $post_id = intval($_REQUEST['post_id']); 677 $last_post_id = intval($_REQUEST['last_post_id']); 678 $query_limit = $_REQUEST['posts_per_page'] ? intval($_REQUEST['posts_per_page']) : 1; 679 679 $keywords = $_REQUEST['keywords'] ?? []; 680 680 $negative_keywords = $_REQUEST['negativeKeywords'] ?? []; -
alttext-ai/trunk/includes/class-atai-utility.php
r3079660 r3086107 233 233 inner join {$wpdb->term_taxonomy} tt on tt.term_id = terms.term_id 234 234 inner join {$wpdb->term_relationships} tr on tr.term_taxonomy_id = tt.term_taxonomy_id 235 where tr.object_id = {$attachment_id}235 where tr.object_id = %d 236 236 and tt.taxonomy = 'language'; 237 237 SQL; 238 238 239 $lang_data = $wpdb->get_results( $ language_sql);239 $lang_data = $wpdb->get_results( $wpdb->prepare($language_sql, $attachment_id) ); 240 240 $language = NULL; 241 241
Note: See TracChangeset
for help on using the changeset viewer.