{"id":156,"date":"2026-10-19T19:13:49","date_gmt":"2026-10-19T17:13:49","guid":{"rendered":"https:\/\/hwn2.com\/?page_id=156"},"modified":"2026-10-19T21:23:36","modified_gmt":"2026-10-19T19:23:36","slug":"publier-sur-hwn2","status":"publish","type":"page","link":"https:\/\/hwn2.com\/?page_id=156","title":{"rendered":"Publier sur HWN2"},"content":{"rendered":"\n<style>\nhtml:has(.hwn2-publisher){margin-top:0!important}.hwn2-publisher{--navy:#132636;--red:#b62637;--muted:#586874;--paper:#f5f6f4;font:16px\/1.5 Arial,sans-serif;background:var(--paper);color:var(--navy);min-height:100vh;padding-bottom:36px}.hwn2-publisher *{box-sizing:border-box}.hwn2-publisher [hidden]{display:none!important}.hwn2-publisher header{background:#fff;border-bottom:1px solid #dbe1e5;padding:14px 20px;display:flex;justify-content:space-between;align-items:center;gap:14px}.hwn2-publisher header img{width:112px;height:auto}.hwn2-publisher header p{font-size:13px;margin:0;color:var(--muted)}.hwn2-publisher h1{font-size:24px;margin:0;line-height:1.2}.hwn2-publisher h2{font-size:22px;margin:0 0 18px}.hwn2-publisher h3{font-size:20px;margin:0 0 12px}.hwn2-publisher .pub-shell{max-width:760px;margin:auto;padding:20px}.hwn2-publisher .pub-tabs{display:flex;gap:10px;margin-bottom:20px}.hwn2-publisher button,.hwn2-publisher .pub-link{min-height:48px;border-radius:8px;border:1px solid #bdc9d1;background:#fff;color:var(--navy);padding:12px 16px;font:inherit;font-weight:700;cursor:pointer;text-decoration:none;display:inline-flex;justify-content:center;align-items:center}.hwn2-publisher .pub-tabs button{flex:1}.hwn2-publisher .pub-tabs button[aria-pressed=true],.hwn2-publisher .primary{background:var(--navy);color:#fff;border-color:var(--navy)}.hwn2-publisher .publish{background:var(--red);border-color:var(--red);color:white}.hwn2-publisher button:disabled{opacity:.55;cursor:wait}.hwn2-publisher button:focus-visible,.hwn2-publisher input:focus-visible,.hwn2-publisher select:focus-visible,.hwn2-publisher textarea:focus-visible,.hwn2-publisher a:focus-visible{outline:3px solid #277ba8;outline-offset:3px}.hwn2-publisher .pub-card{background:#fff;padding:24px;border:1px solid #dbe1e5;border-radius:12px;margin-bottom:18px}.hwn2-publisher label{display:block;font-weight:700;margin:20px 0 7px}.hwn2-publisher label:first-child{margin-top:0}.hwn2-publisher input:not([type=checkbox]),.hwn2-publisher textarea,.hwn2-publisher select{display:block;width:100%;padding:13px 12px;font:inherit;border:1px solid #b9c5cc;border-radius:7px;background:#fff;color:var(--navy);min-height:48px}.hwn2-publisher textarea{min-height:180px;resize:vertical}.hwn2-publisher .pub-hint{font-size:13px;color:var(--muted);margin:7px 0}.hwn2-publisher .pub-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:22px}.hwn2-publisher .pub-actions>*{flex:1}.hwn2-publisher .pub-photo{width:min(100%,270px);aspect-ratio:9\/16;object-fit:contain;background:#edf0ec;border-radius:8px;display:block;margin:16px auto}.hwn2-publisher .pub-status{padding:12px 16px;border-radius:8px;background:#e8eef2;margin:0 0 18px;overflow-wrap:anywhere}.hwn2-publisher .pub-status.error{background:#fff0ee;color:#922235}.hwn2-publisher .pub-demo{padding:10px 18px;background:#fff1cb;font-size:14px;text-align:center}.hwn2-publisher .pub-pill{font-size:12px;display:inline-block;padding:5px 9px;border-radius:20px;background:#edf1f4;margin:0 5px 10px 0}.hwn2-publisher .pub-list{list-style:none;margin:0;padding:0}.hwn2-publisher .pub-body{white-space:pre-wrap;overflow-wrap:anywhere}.hwn2-publisher .pub-danger{color:#a01c2c;border-color:#e1bbc1}.hwn2-publisher .pub-security{text-align:center;font-size:12px;color:var(--muted);margin-top:20px}.hwn2-publisher .pub-empty{color:var(--muted)}.hwn2-publisher .pub-title-row{display:flex;align-items:start;justify-content:space-between;gap:10px}.hwn2-publisher .pub-title-row button{min-height:40px;padding:6px 10px;font-size:13px}.hwn2-publisher .pub-check{display:flex;gap:10px;align-items:start;font-size:14px;font-weight:400}.hwn2-publisher .pub-check input{margin-top:4px}.hwn2-publisher .pub-login{max-width:480px;margin:30px auto}.hwn2-publisher .pub-date-row{display:grid;grid-template-columns:1fr 1fr;gap:14px}\nbody:has(.hwn2-publisher) #masthead,body:has(.hwn2-publisher) #colophon,body:has(.hwn2-publisher) #wpadminbar,body:has(.hwn2-publisher) .entry-header{display:none}body:has(.hwn2-publisher) #content .ast-container{max-width:none;padding:0}body:has(.hwn2-publisher) #primary,body:has(.hwn2-publisher) .ast-article-single{margin:0;padding:0}body:has(.hwn2-publisher) .entry-content{margin:0}@media(max-width:520px){.hwn2-publisher header{padding:12px 16px}.hwn2-publisher header img{width:88px}.hwn2-publisher h1{font-size:21px}.hwn2-publisher .pub-shell{padding:16px}.hwn2-publisher .pub-card{padding:20px}.hwn2-publisher .pub-actions{flex-direction:column}.hwn2-publisher .pub-date-row{grid-template-columns:1fr}}\n.hwn2-publisher .pub-with-photo .pub-fixed-band{height:280px;overflow:auto;overscroll-behavior:contain;margin-bottom:16px;padding:12px;border:1px solid #dbe1e5;border-radius:8px}.hwn2-publisher #pub-crop-canvas{display:block;width:min(100%,270px);height:auto;aspect-ratio:9\/16;margin:auto;background:#edf0ec}.hwn2-publisher input[type=range]{padding:0;accent-color:var(--red)}\n.hwn2-publisher #pub-review:not(.pub-with-photo) .pub-fixed-band{height:auto;min-height:280px;overflow:visible;margin-bottom:0;padding:12px;border:1px solid #dbe1e5;border-radius:8px}.hwn2-publisher #pub-review:not(.pub-with-photo) .pub-body{font-size:18px;line-height:1.65}.hwn2-publisher .pub-with-photo .pub-fixed-band .pub-body{font-size:16px;line-height:1.5}\n<\/style>\n<div class=\"hwn2-publisher\" id=\"hwn2-publisher\">\n <div id=\"pub-demo\" class=\"pub-demo\" hidden>D\u00e9monstration \u2014 aucune publication n\u2019est envoy\u00e9e \u00e0 HWN2.<\/div>\n <header><img decoding=\"async\" src=\"https:\/\/hwn2.com\/wp-content\/uploads\/2026\/10\/logo-hwn2-transparent-v2.png\" alt=\"HWN2\"><div><h1>Publier sur HWN2<\/h1><p id=\"pub-account\">Acc\u00e8s de publication<\/p><\/div><\/header>\n <main class=\"pub-shell\">\n  <div id=\"pub-status\" class=\"pub-status\" role=\"status\" aria-live=\"polite\">V\u00e9rification de la connexion\u2026<\/div>\n  <section id=\"pub-login\" class=\"pub-card pub-login\" hidden><h2>Votre espace de publication<\/h2><p>Connectez-vous avec <strong>FredActusHwn2<\/strong> pour retrouver vos publications.<\/p><a class=\"pub-link primary\" id=\"pub-login-link\">Se connecter<\/a><p class=\"pub-hint\">Utilisez le compte de publication, avec son propre mot de passe.<\/p><\/section>\n  <div id=\"pub-app\" hidden>\n   <nav class=\"pub-tabs\" aria-label=\"Publications\"><button type=\"button\" id=\"pub-new\" aria-pressed=\"true\">Nouvelle publication<\/button><button type=\"button\" id=\"pub-mine\" aria-pressed=\"false\">Mes publications<\/button><\/nav>\n   <section id=\"pub-editor\"><form id=\"pub-form\" class=\"pub-card\">\n    <div class=\"pub-title-row\"><h2 id=\"pub-editor-title\">Quoi de neuf ?<\/h2><span id=\"pub-edit-pill\" class=\"pub-pill\" hidden>Modification<\/span><\/div>\n    <label for=\"pub-kind\">O\u00f9 publier ?<\/label><select id=\"pub-kind\"><option value=\"6\">Actualit\u00e9s<\/option><option value=\"7\">\u00c9v\u00e9nements<\/option><\/select>\n    <label for=\"pub-title\">Titre<\/label><input id=\"pub-title\" maxlength=\"180\" required autocomplete=\"off\" placeholder=\"Un titre court et clair\">\n    <fieldset id=\"pub-event-fields\" style=\"margin:20px 0;padding:16px;border:1px solid #bdc9d1;border-radius:8px\"><legend>Dates et heures (facultatives)<\/legend><label for=\"pub-event-date\">D\u00e9but : date et heure<\/label><input id=\"pub-event-date\" type=\"datetime-local\"><label for=\"pub-event-end\">Fin : date et heure<\/label><input id=\"pub-event-end\" type=\"datetime-local\"><p class=\"pub-hint\">Pour une actualit\u00e9 ou un \u00e9v\u00e9nement. Vous pouvez laisser la fin vide si elle n\u2019est pas encore connue.<\/p><\/fieldset>\n    <label for=\"pub-text\">Votre texte<\/label><textarea id=\"pub-text\" required placeholder=\"Racontez votre actualit\u00e9\u2026\"><\/textarea>\n    <div id=\"pub-rich-warning\" hidden><label class=\"pub-check\"><input id=\"pub-rich-consent\" type=\"checkbox\">J\u2019accepte de remplacer la mise en forme avanc\u00e9e de cet article si je modifie son texte.<\/label><\/div>\n    \n    <label for=\"pub-web-link\">Lien web (facultatif)<\/label><input id=\"pub-web-link\" type=\"url\" inputmode=\"url\" placeholder=\"https:\/\/www.exemple.fr\" autocomplete=\"off\"><p class=\"pub-hint\">Site de l\u2019\u00e9v\u00e9nement, r\u00e9servation ou renseignements. Le lien sera affich\u00e9 dans l\u2019article.<\/p>\n    <label for=\"pub-photo\">Photo (facultative)<\/label><input id=\"pub-photo\" type=\"file\" accept=\"image\/jpeg,image\/png,image\/webp\"><p class=\"pub-hint\">Choisissez une photo du t\u00e9l\u00e9phone. Vous pouvez publier uniquement du texte. Si vous ajoutez une photo, son format portrait 9:16 est obligatoire. Si n\u00e9cessaire, ajustez le cadrage ci-dessous. JPEG, PNG ou WebP, jusqu\u2019\u00e0 8 Mo.<\/p>\n    <section id=\"pub-crop\" class=\"pub-card\" hidden><h3>Ajuster au format 9:16<\/h3><p class=\"pub-hint\">D\u00e9placez le cadrage et zoomez pour conserver la bonne partie de la photo. Votre original reste sur le t\u00e9l\u00e9phone.<\/p><canvas id=\"pub-crop-canvas\" width=\"270\" height=\"480\" aria-label=\"Aper\u00e7u du recadrage au format 9:16\"><\/canvas><label for=\"pub-crop-zoom\">Zoom<\/label><input id=\"pub-crop-zoom\" type=\"range\" min=\"1\" max=\"3\" step=\"0.01\" value=\"1\"><label for=\"pub-crop-x\">Position horizontale<\/label><input id=\"pub-crop-x\" type=\"range\" min=\"0\" max=\"100\" value=\"50\"><label for=\"pub-crop-y\">Position verticale<\/label><input id=\"pub-crop-y\" type=\"range\" min=\"0\" max=\"100\" value=\"50\"><p id=\"pub-crop-info\" class=\"pub-hint\"><\/p><button id=\"pub-crop-apply\" type=\"button\" class=\"primary\">Valider ce cadrage 9:16<\/button><\/section>\n    <button id=\"pub-recrop\" type=\"button\" hidden>R\u00e9ajuster le cadrage<\/button>\n    <img id=\"pub-photo-preview\" class=\"pub-photo\" alt=\"Photo choisie pour la publication\" hidden><button id=\"pub-remove-photo\" type=\"button\" hidden>Retirer cette photo<\/button>\n    <div class=\"pub-actions\"><button id=\"pub-draft\" type=\"button\">Enregistrer le brouillon<\/button><button id=\"pub-check\" class=\"publish\" type=\"submit\">V\u00e9rifier avant publication<\/button><\/div>\n   <\/form><\/section>\n   <section id=\"pub-review\" class=\"pub-card\" hidden><h2>Dernier coup d\u2019\u0153il<\/h2><div class=\"pub-fixed-band\" tabindex=\"0\" aria-label=\"Texte de la publication, d\u00e9filement possible\"><p id=\"pub-review-kind\" class=\"pub-pill\"><\/p><h3 id=\"pub-review-title\"><\/h3><p id=\"pub-review-event\"><\/p><p id=\"pub-review-text\" class=\"pub-body\"><\/p><\/div><img id=\"pub-review-photo\" class=\"pub-photo\" alt=\"Aper\u00e7u de la photo\" hidden><p id=\"pub-review-web\" hidden><a id=\"pub-review-link\" target=\"_blank\" rel=\"noopener noreferrer\">Consulter le site<\/a><\/p><p id=\"pub-review-message\"><\/p><div class=\"pub-actions\"><button type=\"button\" id=\"pub-back\">Modifier<\/button><button type=\"button\" id=\"pub-confirm\" class=\"publish\">Confirmer la publication<\/button><\/div><\/section>\n   <section id=\"pub-list-screen\" hidden><h2>Mes publications<\/h2><div class=\"pub-actions\" style=\"margin:0 0 18px\"><button type=\"button\" id=\"pub-refresh\">Actualiser<\/button><button type=\"button\" id=\"pub-trash-toggle\">Voir la corbeille<\/button><\/div><ul id=\"pub-list\" class=\"pub-list\"><\/ul><button type=\"button\" id=\"pub-more\" hidden>Afficher les suivantes<\/button><\/section>\n  <\/div>\n  <p class=\"pub-security\">Acc\u00e8s r\u00e9serv\u00e9 aux publications. Aucun mot de passe n\u2019est enregistr\u00e9 dans cet \u00e9cran.<\/p>\n <\/main>\n<\/div>\n\n<script>\n(function () {\n 'use strict';\n var root=document.getElementById('hwn2-publisher'); if(!root) return;\n var demo=window.HWN2_PUBLICATION_DEMO===true;\n var state={needsCrop:false,cropImage:null,cropToken:0,nonce:'',user:null,id:0,media:0,photoUrl:'',file:null,busy:false,original:null,initialText:'',initialEvent:'',initialEnd:'',initialLink:'',trash:false,page:1,more:false,uncertain:false};\n var demoPosts=[],demoMedia={},seq=9000;\n function el(id){return document.getElementById('pub-'+id);}\n function status(text,error){el('status').textContent=text;el('status').classList.toggle('error',!!error);}\n function plain(source){var d=new DOMParser().parseFromString(source||'','text\/html');d.querySelectorAll('br').forEach(function(b){b.replaceWith('\\n');});d.querySelectorAll('p,div,h1,h2,h3,li').forEach(function(p){p.appendChild(d.createTextNode('\\n\\n'));});return d.body.textContent.trim();}\n function escapeText(value){var d=document.createElement('div');d.textContent=value;return d.innerHTML;}\n function safeWebLink(value){if(!value.trim())return '';var u=new URL(value.trim());if(!['http:','https:'].includes(u.protocol))throw new Error('Utilisez un lien commen\u00e7ant par https:\/\/ ou http:\/\/.');if(u.username||u.password)throw new Error('Le lien ne doit contenir aucun identifiant ni mot de passe.');return u.href;}\n function attribute(value){return escapeText(value).replace(\/\"\/g,String.fromCharCode(38)+'#34;').replace(\/'\/g,String.fromCharCode(38)+'#39;');}\n function paragraphs(value){return value.trim().split(\/\\n\\s*\\n\/).map(function(p){return '<p>'+escapeText(p).replace(\/\\n\/g,'<br>')+'<\/p>';}).join('\\n');}\n function friendly(value){return new Date(value).toLocaleString('fr-FR',{dateStyle:'long',timeStyle:'short'});}\n function busy(value){state.busy=value;root.querySelectorAll('button').forEach(function(b){b.disabled=value;});}\n function endpoint(path,params){var u=new URL('\/',location.origin);u.searchParams.set('rest_route','\/wp\/v2\/'+path);Object.entries(params||{}).forEach(function(pair){u.searchParams.set(pair[0],pair[1]);});return u;}\n async function nonce(){var u=new URL('\/wp-admin\/admin-ajax.php',location.origin);u.searchParams.set('action','rest-nonce');var response=await fetch(u,{credentials:'same-origin',cache:'no-store'});if(!response.ok)throw new Error('Connexion n\u00e9cessaire.');var token=(await response.text()).trim();if(!\/^[a-z0-9]{10}$\/i.test(token))throw new Error('Connexion n\u00e9cessaire.');state.nonce=token;}\n async function api(path,method,data,params){\n  if(demo)return demoApi(path,method,data,params);\n  var headers={'X-WP-Nonce':state.nonce};var options={method:method||'GET',credentials:'same-origin',cache:'no-store',headers:headers};\n  if(data instanceof FormData)options.body=data;else if(data){headers['Content-Type']='application\/json';options.body=JSON.stringify(data);}\n  var response=await fetch(endpoint(path,params),options);var json;\n  try{json=await response.json();}catch(e){throw new Error('R\u00e9ponse illisible. V\u00e9rifiez Mes publications avant de r\u00e9essayer.');}\n  if(!response.ok){var error=new Error(plain(json.message)||'L\u2019op\u00e9ration a \u00e9t\u00e9 refus\u00e9e.');error.code=json.code;throw error;}\n  return {data:json,total:parseInt(response.headers.get('X-WP-TotalPages')||'1',10)};\n }\n function demoApi(path,method,data,params){\n  if(path==='users\/me')return {data:{id:99,name:'FredActusHwn2',roles:['rdacteur_actualits_hwn2'],capabilities:{publish_posts:true,upload_files:true}}};\n  if([path==='posts',method==='POST'].every(Boolean)){var post={id:++seq,author:99,status:'draft',title:{raw:data.title,rendered:data.title},content:{raw:data.content,rendered:data.content},excerpt:{raw:data.excerpt},categories:data.categories,featured_media:0,date_gmt:new Date().toISOString().slice(0,19)};demoPosts.unshift(post);return {data:post};}\n  if(path==='posts')return {data:demoPosts.filter(function(p){return params.status==='trash'?p.status==='trash':p.status!=='trash';}),total:1};\n  if([path==='media',method==='POST'].every(Boolean)){var mediaId=++seq;demoMedia[mediaId]=state.photoUrl;return {data:{id:mediaId,source_url:state.photoUrl}};}\n  if(path.startsWith('media\/'))return {data:{id:state.media,source_url:demoMedia[Number(path.split('\/')[1])]}};\n  if(path.startsWith('posts\/')){var id=Number(path.split('\/')[1]),p=demoPosts.find(function(q){return q.id===id;});if(!p)throw new Error('Publication introuvable.');if(method==='DELETE'){p.status='trash';return {data:p};}if(method==='POST'){Object.entries(data).forEach(function(pair){var k=pair[0],v=pair[1];p[k]=['title','content','excerpt'].includes(k)?{raw:v,rendered:v}:v;});}return {data:p};}\n  throw new Error('Op\u00e9ration de d\u00e9monstration indisponible.');\n }\n function photo(url){el('photo-preview').hidden=!url;el('photo-preview').src=url||'';el('remove-photo').hidden=!url;}\n function screen(which){el('editor').hidden=which!=='editor';el('list-screen').hidden=which!=='list';el('review').hidden=which!=='review';el('new').setAttribute('aria-pressed',String(which!=='list'));el('mine').setAttribute('aria-pressed',String(which==='list'));}\n function reset(){state.cropToken++;state.needsCrop=false;state.cropImage=null;el('crop').hidden=true;el('recrop').hidden=true;state.id=0;state.media=0;state.file=null;state.original=null;state.initialText='';state.initialEvent='';state.initialEnd='';state.initialLink='';state.uncertain=false;if(!demo){if(state.photoUrl.startsWith('blob:'))URL.revokeObjectURL(state.photoUrl);}state.photoUrl='';el('form').reset();syncDateBounds();el('draft').hidden=false;el('edit-pill').hidden=true;el('rich-warning').hidden=true;el('editor-title').textContent='Quoi de neuf ?';photo('');conditional();screen('editor');status(demo?'D\u00e9monstration : essayez sans rien publier.':'Pr\u00eat \u00e0 \u00e9crire une publication.');}\n function conditional(){el('event-fields').hidden=false;}\n function dateSummary(){var start=el('event-date').value,end=el('event-end').value;return (start?'D\u00e9but : '+friendly(start):'')+([start,end].every(Boolean)?' \u2014 ':'')+(end?'Fin : '+friendly(end):'');}\n function syncDateBounds(){el('event-end').min=el('event-date').value||'';}\n el('event-date').addEventListener('input',syncDateBounds);\n function validate(final){var start=el('event-date').value,end=el('event-end').value;if([end,!start].every(Boolean)){status('Renseignez la date et l\u2019heure de d\u00e9but avant la fin.',true);screen('editor');return false;}if([start,end,end<start].every(Boolean)){status('La date et l\u2019heure de fin doivent \u00eatre post\u00e9rieures ou \u00e9gales au d\u00e9but.',true);screen('editor');return false;}if(state.needsCrop){status('Validez le recadrage 9:16 de la photo avant de continuer.',true);screen('editor');return false;}try{safeWebLink(el('web-link').value);}catch(e){status(e.message||'V\u00e9rifiez le lien web.',true);return false;}if(!el('form').reportValidity())return false;if(el('rich-warning').hidden===false){if(el('text').value!==state.initialText){if(!el('rich-consent').checked){status('Confirmez le remplacement de la mise en forme, ou conservez le texte actuel.',true);return false;}}}return true;}\n function content(){var event=el('event-date').value,end=el('event-end').value;var link=safeWebLink(el('web-link').value);var body;\n  if(state.original){if(el('text').value===state.initialText){if([event===state.initialEvent,end===state.initialEnd].every(Boolean)){if(link===state.initialLink)return state.original.content.raw;}}}\n  body=paragraphs(el('text').value);\n  if(state.original){if(el('text').value===state.initialText){var doc=new DOMParser().parseFromString(state.original.content.raw,'text\/html');doc.querySelectorAll('.hwn2-event-date,.hwn2-web-link').forEach(function(e){e.remove();});body=doc.body.innerHTML;}}\n  if(event)body='<p class=\"hwn2-event-date\" data-hwn2-event-date=\"'+attribute(event)+'\" data-hwn2-event-end=\"'+attribute(end)+'\">'+escapeText(dateSummary())+'<\/p>\\n'+body;\n  if(link)body+='\\n<p class=\"hwn2-web-link\"><a href=\"'+attribute(link)+'\" target=\"_blank\" rel=\"noopener noreferrer\">Consulter le site<\/a><\/p>';\n  return body;\n }\n function payload(target){var text=el('text').value.trim();var event=el('event-date').value;var excerpt=(event?dateSummary()+'. ':'')+text.replace(\/\\s+\/g,' ');var p={title:el('title').value.trim(),content:content(),excerpt:excerpt.slice(0,360),categories:[Number(el('kind').value)],status:target,featured_media:state.media,comment_status:'closed',ping_status:'closed'};\n  if(target==='publish'){p.date_gmt=new Date().toISOString();if(state.original){if(state.original.status==='publish')p.date_gmt=state.original.date_gmt;}}\n  if(state.original){p.categories=Array.from(new Set(state.original.categories.filter(function(c){return ![6,7].includes(c);}).concat(p.categories)));p.comment_status=state.original.comment_status;p.ping_status=state.original.ping_status;}\n  return p;\n }\n async function save(target){if(state.busy)return;if(state.uncertain){status('Un envoi pr\u00e9c\u00e9dent a \u00e9t\u00e9 interrompu. V\u00e9rifiez Mes publications avant de lancer une nouvelle publication.',true);screen('list');await list(true);return;}if(!validate(target!=='draft'))return;busy(true);var creating=false;\n  try{if(!demo)await nonce();if(!state.id){status('Enregistrement du brouillon\u2026');creating=true;var draft=payload('draft');delete draft.featured_media;var created=await api('posts','POST',draft);state.id=created.data.id;creating=false;}\n   if(state.file){status('Envoi de la photo\u2026');var upload=new FormData();upload.append('file',state.file,state.file.name);upload.append('post',String(state.id));var media=await api('media','POST',upload);state.media=media.data.id;state.file=null;}\n   status('Enregistrement de la publication\u2026');var result=await api('posts\/'+state.id,'POST',payload(target));state.original=result.data;\n   var verified=await api('posts\/'+state.id,'GET',null,{context:'edit'});if(verified.data.status!==target)throw new Error('Le statut demand\u00e9 n\u2019est pas confirm\u00e9. Consultez Mes publications.');\n   screen('list');state.trash=false;state.page=1;await list(true);status(demo?'D\u00e9monstration enregistr\u00e9e uniquement dans cet aper\u00e7u.':target==='draft'?'Brouillon enregistr\u00e9.':'Publication enregistr\u00e9e et en ligne.');\n  }catch(e){if(creating)state.uncertain=true;status((state.id?'Un brouillon ou une publication existe d\u00e9j\u00e0 : ne recr\u00e9ez pas de doublon. ':'')+e.message,true);}finally{busy(false);}\n }\n async function list(resetPage){if(resetPage)state.page=1;var params={context:'edit',author:String(state.user.id),per_page:'20',page:String(state.page),status:state.trash?'trash':'draft,pending,future,publish,private',orderby:'modified',order:'desc'};\n  var result=await api('posts','GET',null,params);if(resetPage)el('list').replaceChildren();state.more=state.page<result.total;el('more').hidden=!state.more;el('trash-toggle').textContent=state.trash?'Voir les publications':'Voir la corbeille';\n  if(!result.data.length){var empty=document.createElement('li');empty.className='pub-card pub-empty';empty.textContent=state.trash?'La corbeille est vide.':'Aucune publication pour ce compte. Touchez Nouvelle publication pour commencer.';el('list').appendChild(empty);}\n  result.data.forEach(function(p){if(p.author!==state.user.id)return;var li=document.createElement('li');li.className='pub-card';var tag=document.createElement('span');tag.className='pub-pill';tag.textContent=({publish:'En ligne',draft:'Brouillon',future:'Programm\u00e9e',pending:'En attente',trash:'Corbeille',private:'Priv\u00e9e'})[p.status]||p.status;var h=document.createElement('h3');h.textContent=plain(p.title.raw||p.title.rendered)||'Sans titre';li.append(tag,h);var actions=document.createElement('div');actions.className='pub-actions';var edit=document.createElement('button');edit.type='button';edit.textContent=state.trash?'Restaurer en brouillon':'Modifier';edit.addEventListener('click',function(){if(state.trash)restore(p);else load(p.id);});actions.appendChild(edit);if(!state.trash){var remove=document.createElement('button');remove.type='button';remove.className='pub-danger';remove.textContent='Supprimer';remove.addEventListener('click',function(){trash(p);});actions.appendChild(remove);}li.appendChild(actions);el('list').appendChild(li);});\n }\n async function load(id){if(state.busy)return;busy(true);try{var p=(await api('posts\/'+id,'GET',null,{context:'edit'})).data;if(p.author!==state.user.id)throw new Error('Cette publication appartient \u00e0 un autre compte.');reset();state.id=p.id;state.media=p.featured_media||0;state.original=p;el('title').value=p.title.raw||plain(p.title.rendered);var doc=new DOMParser().parseFromString(p.content.raw||'','text\/html');var event=doc.querySelector('.hwn2-event-date');if(event){state.initialEvent=event.getAttribute('data-hwn2-event-date')||'';state.initialEnd=event.getAttribute('data-hwn2-event-end')||'';event.remove();}var web=doc.querySelector('.hwn2-web-link');if(web){var a=web.querySelector('a');if(a){try{state.initialLink=safeWebLink(a.getAttribute('href')||'');}catch(e){state.initialLink='';}}web.remove();}el('web-link').value=state.initialLink;state.initialText=plain(doc.body.innerHTML);el('text').value=state.initialText;el('event-date').value=state.initialEvent;el('event-end').value=state.initialEnd;syncDateBounds();el('kind').value=p.categories.includes(7)?'7':'6';el('edit-pill').hidden=false;el('editor-title').textContent='Modifier la publication';el('draft').hidden=p.status==='publish';el('rich-warning').hidden=!\/<(?:img|figure|table|ul|ol|a|strong|em|h[1-6])\\b\/i.test(doc.body.innerHTML);if(state.media){var m=(await api('media\/'+state.media,'GET')).data;state.photoUrl=m.source_url;photo(state.photoUrl);await inspectPhoto(state.photoUrl);}conditional();screen('editor');status(p.status==='publish'?'Cette publication est en ligne. V\u00e9rifiez les changements avant de les confirmer.':'Publication ouverte pour modification.');}catch(e){status(e.message,true);}finally{busy(false);}}\n async function trash(post){if(state.busy)return;if(!window.confirm('Placer \u00ab '+plain(post.title.raw||post.title.rendered)+' \u00bb dans la corbeille ? La publication dispara\u00eetra du site.'))return;busy(true);try{if(!demo)await nonce();var result=await api('posts\/'+post.id,'DELETE',null,{force:'false'});if(result.data.status!=='trash')throw new Error('Le placement dans la corbeille n\u2019est pas confirm\u00e9.');await list(true);status(demo?'D\u00e9monstration plac\u00e9e dans la corbeille de cet aper\u00e7u.':'Publication plac\u00e9e dans la corbeille. La dur\u00e9e de conservation d\u00e9pend des r\u00e9glages WordPress.');}catch(e){status(e.message,true);}finally{busy(false);}}\n async function restore(post){if(state.busy)return;busy(true);try{if(!demo)await nonce();var result=await api('posts\/'+post.id,'POST',{status:'draft'});if(result.data.status!=='draft')throw new Error('La restauration n\u2019est pas confirm\u00e9e.');await list(true);status('Publication restaur\u00e9e en brouillon.');}catch(e){status(e.message,true);}finally{busy(false);}}\n el('kind').addEventListener('change',conditional);\n function cropRect(width,height,zoom,x,y){var w=Math.min(width,height*9\/16)\/zoom;var h=w*16\/9;return {x:(width-w)*x\/100,y:(height-h)*y\/100,width:w,height:h};}\n function drawCrop(){if(!state.cropImage)return;var img=state.cropImage;var r=cropRect(img.naturalWidth,img.naturalHeight,Number(el('crop-zoom').value),Number(el('crop-x').value),Number(el('crop-y').value));var canvas=el('crop-canvas'),ctx=canvas.getContext('2d');ctx.fillStyle='#ffffff';ctx.fillRect(0,0,canvas.width,canvas.height);ctx.drawImage(img,r.x,r.y,r.width,r.height,0,0,canvas.width,canvas.height);el('crop-info').textContent=r.width<1080?'Sortie : 1080 \u00d7 1920 pixels. Cette photo peut perdre en nettet\u00e9 \u00e0 l\u2019agrandissement.':'Sortie : 1080 \u00d7 1920 pixels.';return r;}\n function openCrop(){if(!state.cropImage)return;state.needsCrop=true;el('crop').hidden=false;el('photo-preview').hidden=true;el('recrop').hidden=true;el('crop-zoom').value='1';el('crop-x').value='50';el('crop-y').value='50';drawCrop();}\n async function inspectPhoto(url){var token=++state.cropToken;state.needsCrop=true;state.cropImage=null;el('crop').hidden=true;el('recrop').hidden=true;var img=new Image();img.src=url;try{await img.decode();if(token!==state.cropToken)return;state.cropImage=img;if(img.naturalWidth*16!==img.naturalHeight*9){openCrop();status('Cette photo n\u2019est pas au format 9:16. Ajustez puis validez le cadrage.');}else{state.needsCrop=false;photo(url);el('recrop').hidden=false;status('Photo au format 9:16 v\u00e9rifi\u00e9.');}}catch(e){if(token!==state.cropToken)return;status('Impossible de v\u00e9rifier cette photo. Choisissez une autre image.',true);}}\n ['crop-zoom','crop-x','crop-y'].forEach(function(id){el(id).addEventListener('input',drawCrop);});\n el('recrop').addEventListener('click',openCrop);\n el('crop-apply').addEventListener('click',async function(){if(state.busy)return;if(!state.cropImage)return;var token=state.cropToken,r=drawCrop(),img=state.cropImage;busy(true);try{var canvas=document.createElement('canvas');canvas.width=1080;canvas.height=1920;var ctx=canvas.getContext('2d');ctx.fillStyle='#ffffff';ctx.fillRect(0,0,1080,1920);ctx.drawImage(img,r.x,r.y,r.width,r.height,0,0,1080,1920);var blob=await new Promise(function(resolve,reject){canvas.toBlob(function(b){if(b)resolve(b);else reject(new Error('Le recadrage a \u00e9chou\u00e9.'));},'image\/jpeg',0.9);});if(token!==state.cropToken)return;state.file=new File([blob],'hwn2-photo-9x16.jpg',{type:'image\/jpeg'});if(!demo){if(state.photoUrl.startsWith('blob:'))URL.revokeObjectURL(state.photoUrl);}state.photoUrl=URL.createObjectURL(blob);state.needsCrop=false;el('crop').hidden=true;el('recrop').hidden=false;photo(state.photoUrl);status('Cadrage valid\u00e9 : photo 1080 \u00d7 1920, format 9:16. Elle sera envoy\u00e9e lors de l\u2019enregistrement.');}catch(e){status('Impossible de recadrer cette image. Choisissez une photo du t\u00e9l\u00e9phone.',true);}finally{busy(false);}});\n el('photo').addEventListener('change',async function(){var file=el('photo').files[0];if(!file)return;if(!['image\/jpeg','image\/png','image\/webp'].includes(file.type)){status('Choisissez une photo JPEG, PNG ou WebP.',true);el('photo').value='';return;}if(file.size>8*1024*1024){status('La photo d\u00e9passe 8 Mo. Choisissez une version plus l\u00e9g\u00e8re.',true);el('photo').value='';return;}if(!demo){if(state.photoUrl.startsWith('blob:'))URL.revokeObjectURL(state.photoUrl);}state.file=file;state.photoUrl=URL.createObjectURL(file);photo(state.photoUrl);await inspectPhoto(state.photoUrl);});\n el('remove-photo').addEventListener('click',function(){state.cropToken++;state.needsCrop=false;state.cropImage=null;el('crop').hidden=true;el('recrop').hidden=true;if(!demo){if(state.photoUrl.startsWith('blob:'))URL.revokeObjectURL(state.photoUrl);}state.file=null;state.media=0;state.photoUrl='';el('photo').value='';photo('');});\n el('new').addEventListener('click',function(){if(state.busy)return;if(el('title').value||el('text').value){if(!window.confirm('Ouvrir une nouvelle publication et quitter le texte affich\u00e9 ? Les changements non enregistr\u00e9s seront perdus.'))return;}reset();});\n el('mine').addEventListener('click',async function(){if(state.busy)return;screen('list');try{await list(true);}catch(e){status(e.message,true);}});\n el('refresh').addEventListener('click',async function(){try{if(!demo)await nonce();await list(true);status('Liste actualis\u00e9e.');}catch(e){status(e.message,true);}});\n el('trash-toggle').addEventListener('click',async function(){state.trash=!state.trash;try{await list(true);}catch(e){status(e.message,true);}});\n el('more').addEventListener('click',async function(){state.page++;try{await list(false);}catch(e){state.page--;status(e.message,true);}});\n el('draft').addEventListener('click',function(){save('draft');});\n el('form').addEventListener('submit',function(e){e.preventDefault();if(!validate(true))return;el('review-kind').textContent=el('kind').value==='7'?'\u00c9v\u00e9nement':'Actualit\u00e9';el('review-title').textContent=el('title').value;el('review-text').textContent=el('text').value;el('review-event').textContent=dateSummary();var webLink=safeWebLink(el('web-link').value);el('review-web').hidden=!webLink;el('review-link').href=webLink||'#';el('review-link').textContent=webLink?'Consulter le site : '+new URL(webLink).hostname:'Consulter le site';el('review').classList.toggle('pub-with-photo',!!state.photoUrl);el('review-photo').hidden=!state.photoUrl;el('review-photo').src=state.photoUrl||'';el('review-message').textContent=state.id?'Les changements seront visibles imm\u00e9diatement apr\u00e8s confirmation.':'Publication imm\u00e9diate apr\u00e8s confirmation.';if(state.original){if(state.original.status==='future')el('review-message').textContent='Cette publication \u00e9tait programm\u00e9e. Confirmer la publiera imm\u00e9diatement.';}el('confirm').textContent=state.id?'Confirmer la publication \/ modification':'Confirmer la publication';screen('review');});\n el('back').addEventListener('click',function(){screen('editor');});el('confirm').addEventListener('click',function(){save('publish');});\n async function init(){if(demo)el('demo').hidden=false;var login=new URL('\/wp-login.php',demo?'https:\/\/hwn2.com':location.origin);if(!demo)login.searchParams.set('redirect_to',location.href);el('login-link').href=login.href;try{if(!demo)await nonce();var me=(await api('users\/me','GET',null,{context:'edit'})).data;if(!me.roles.includes('rdacteur_actualits_hwn2'))throw new Error('Ouvrez cet espace avec le compte de publication FredActusHwn2.');if(!me.capabilities.publish_posts)throw new Error('Ce compte ne peut pas publier.');state.user=me;el('account').textContent=me.name||'Compte de publication';el('app').hidden=false;reset();}catch(e){el('login').hidden=false;status(e.message||'Connectez-vous avec votre compte de publication.',true);}}\n init();\n})();\n\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>D\u00e9monstration \u2014 aucune publication n\u2019est envoy\u00e9e \u00e0 HWN2. Publier sur HWN2 Acc\u00e8s de publication V\u00e9rification de la connexion\u2026 Votre espace [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-156","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/pages\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hwn2.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156"}],"version-history":[{"count":3,"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/pages\/156\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/hwn2.com\/index.php?rest_route=\/wp\/v2\/pages\/156\/revisions\/167"}],"wp:attachment":[{"href":"https:\/\/hwn2.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}