rest_url('citami/v1/aeo-draft'), 'nonce' => wp_create_nonce('wp_rest'), 'postId' => $post ? (int) $post->ID : 0, 't' => array( 'title' => citami_t('Bozza scritta dalla piattaforma', 'Draft written by the platform'), 'intro' => citami_t('Solo dal testo salvato di questa pagina. Non è ancora nella pagina: decidi tu.', 'From this page\'s saved text only. It is not on the page yet: you decide.'), 'tldr' => citami_t('Risposta breve', 'Short answer'), 'use' => citami_t('Usa la bozza', 'Use the draft'), 'discard' => citami_t('Scarta', 'Discard'), 'retry' => citami_t('Riscrivi', 'Rewrite'), 'now' => citami_t('Ora nella pagina', 'Now on the page'), 'proposed'=> citami_t('Proposta', 'Proposed'), 'none' => citami_t('nessuna risposta breve', 'no short answer'), 'faqAdd' => citami_t('%d FAQ da aggiungere in fondo alla pagina', '%d FAQ to add at the bottom of the page'), 'useNote' => citami_t('"Usa la bozza" scrive risposta breve e FAQ nei campi di questo box e le salva; il resto della pagina resta com\'è.', '"Use the draft" writes the short answer and FAQ into this box\'s fields and saves them; the rest of the page stays as it is.'), 'busy' => citami_t('Sto scrivendo… 10-20 secondi', 'Writing… 10-20 seconds'), 'working' => citami_t('Un momento…', 'One moment…'), 'error' => citami_t('La piattaforma non ha risposto: riprova tra poco.', 'The platform did not answer: try again shortly.'), ), ); $js = <<<'JS' (function(C){ if(!C||!C.postId||!window.fetch)return; function esc(s){var d=document.createElement("div");d.textContent=s==null?"":String(s);return d.innerHTML;} function holder(){var h=document.getElementById("citami-aeo-draft");if(h)return h;var b=document.getElementById("citami_seo");if(!b)return null;var inside=b.querySelector(".citami-seo-box")||b.querySelector(".inside")||b;h=document.createElement("div");h.id="citami-aeo-draft";h.className="citami-aeo-draft";h.setAttribute("data-citami","aeo-draft");inside.insertBefore(h,inside.firstChild);return h;} function sync(applied){if(!applied)return;try{var tl=document.getElementById("citami_tldr");if(tl&&typeof applied.tldr==="string")tl.value=applied.tldr;var box=document.querySelector(".citami-faq-editor");if(!box||!Array.isArray(applied.faq))return;var rows=box.querySelector(".citami-faq-rows"),tpl=box.querySelector(".citami-faq-template");if(!rows||!tpl)return;rows.innerHTML="";applied.faq.forEach(function(it){var n=tpl.content.cloneNode(true);var q=n.querySelector("input"),a=n.querySelector("textarea");if(q)q.value=it.q||"";if(a)a.value=it.a||"";rows.appendChild(n);});}catch(e){}window.dispatchEvent(new Event("citami:refresh"));} function render(d,msg,ok){var h=holder();if(!h)return;var b=h.closest(".postbox");if(b&&b.classList.contains("closed"))b.classList.remove("closed");var html='

'+esc(C.t.title)+''+(d?' '+esc(C.t.intro)+'':'')+'

';if(msg)html+='

'+esc(msg)+'

';if(d){var cur=document.getElementById("citami_tldr");cur=cur?cur.value.trim():"";if(d.tldr)html+='
'+esc(C.t.now)+'

'+(cur?esc(cur):""+esc(C.t.none)+"")+'

'+esc(C.t.proposed)+'

'+esc(d.tldr)+'

';if(d.faq&&d.faq.length){html+=''+esc(C.t.faqAdd.replace("%d",d.faq.length))+'
';d.faq.forEach(function(f){html+="
"+esc(f.q)+"
"+esc(f.a)+"
";});html+="
";}html+='

'+esc(C.t.use)+' '+esc(C.t.retry)+' '+esc(C.t.discard)+'

'+esc(C.t.useNote)+"

";}h.innerHTML=html;h.style.outline="2px solid #7c3aed";h.style.outlineOffset="4px";h.scrollIntoView({block:"center"});} document.addEventListener("click",function(e){var a=e.target&&e.target.closest?e.target.closest("a"):null;if(!a)return;var act=a.getAttribute("data-citami-draft"),kind="both";if(!act){var href=a.getAttribute("href")||"";if(href.indexOf("action=citami_aeo_draft")<0)return;var m=/[?&]do=([a-z_]+)/.exec(href);act=m?m[1]:"generate";var k=/[?&]kind=([a-z_]+)/.exec(href);if(k)kind=k[1];} if(["generate","apply","discard"].indexOf(act)<0)return;e.preventDefault();if(a.getAttribute("aria-busy"))return;a.setAttribute("aria-busy","true");a.style.opacity=".7";a.textContent=act==="generate"?C.t.busy:C.t.working; fetch(C.rest,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-WP-Nonce":C.nonce},body:JSON.stringify({post_id:C.postId,do:act,kind:kind})}).then(function(r){return r.json();}).then(function(d){if(act==="apply"&&d.ok)sync(d.applied);render(d.draft,d.message,d.ok!==false);}).catch(function(){render(null,C.t.error,false);}).then(function(){a.removeAttribute("aria-busy");a.style.opacity="";});},true); if(location.hash==="#citami-aeo-draft"){var n=0,t=setInterval(function(){var el=document.getElementById("citami-aeo-draft");if(el){var bx=el.closest(".postbox");if(bx&&bx.classList.contains("closed"))bx.classList.remove("closed");el.scrollIntoView({block:"center"});clearInterval(t);}if(++n>40)clearInterval(t);},250);} })(CITAMI_CFG); JS; return str_replace('CITAMI_CFG', wp_json_encode($cfg), $js); } /** Front-end: singular content, or anywhere the locations shortcode may print. */ function citami_front_assets_needed() { if (is_admin()) { return false; } if (is_singular()) { return true; } return function_exists('citami_locations') && !empty(citami_locations()); } add_action('wp_enqueue_scripts', function () { if (!citami_front_assets_needed()) { return; } wp_enqueue_style('citami-front', citami_asset_url('front.css'), array(), CITAMI_PLUGIN_VERSION); }); /** * 2.70.2 — the stylesheet of the standalone /ai-info documents (no theme, no * wp_head): registered, enqueued and printed by WordPress (wp_print_styles), * never a hand-written tag. 2.73.1 — no fallback tag either (WordPress.org * review). Returns the markup WordPress prints, for the document's head. */ function citami_ai_info_style_tag() { wp_register_style('citami-ai-info', citami_asset_url('ai-info.css'), array(), CITAMI_PLUGIN_VERSION); wp_enqueue_style('citami-ai-info'); ob_start(); wp_print_styles(array('citami-ai-info')); $tag = trim((string) ob_get_clean()); return $tag === '' ? '' : $tag . "\n"; }