diff --git a/website/FORUM-NEWS-REVISIONS-372.md b/website/FORUM-NEWS-REVISIONS-372.md index 96129426..96fbf15b 100644 --- a/website/FORUM-NEWS-REVISIONS-372.md +++ b/website/FORUM-NEWS-REVISIONS-372.md @@ -22,3 +22,6 @@ This checkpoint is staged only. Merge/deployment, backup paths, live existing-to Native subject compatibility follow-up: MyBB limits subjects to85characters while website titles allow120. Forum subjects are truncated with MyBB's Unicode-aware helper, the full long title is retained at the start of the post, and the Archived prefix also stays within85characters. The native temporary-table test now covers long-title editing, archive and republish without losing the full title. + +Canonical article follow-up: browser verification found that the server-rendered /news/ route still omitted author attribution and the confirmed forum link. It now shares the public forum-link resolver, escapes the public author name, shows the shared category label and provides Go to forum post only after confirmed delivery.23focused Node checks pass. Native Markdown-style headings and bullet lists are safely translated to a small BBCode subset; user brackets remain escaped. Rendering version2 triggers reconciliation without creating duplicate topics. The actual MyBB temporary-table test also validates formatting, full long-title retention and reply preservation. + diff --git a/website/integrations/forum-news.php b/website/integrations/forum-news.php index 2154faf0..a3475139 100644 --- a/website/integrations/forum-news.php +++ b/website/integrations/forum-news.php @@ -34,12 +34,19 @@ try{ if($saved&&!$mapping)throw new Exception('Revision mapping requires reconciliation'); if($saved&&$saved['revision']===$revision&&$saved['state']===$state){$reply($mapping['tid']);exit;} $safe=fn($s)=>str_replace(['[',']'],['[',']'],(string)$s);$url='https://www.dunerealms.com/news-archive.html?post='.$input['id']; + $formatBody=function($body)use($safe){ + $out=[];$list=false;foreach(preg_split('/\r\n|\r|\n/',$body)as$line){ + if(preg_match('/^#{1,3}\s+(.+)$/u',trim($line),$heading)){if($list){$out[]='[/list]';$list=false;}$out[]='[b]'.$safe($heading[1]).'[/b]';} + elseif(preg_match('/^[-*]\s+(.+)$/u',trim($line),$bullet)){if(!$list){$out[]='[list]';$list=true;}$out[]='[*]'.$safe($bullet[1]);} + else{if($list){$out[]='[/list]';$list=false;}$out[]=$safe($line);} + }if($list)$out[]='[/list]';return implode("\n",$out); + }; if($status==='published'){ $labels=['world'=>'World','news'=>'NEWS','maintenance'=>'Maintenance','changelogs'=>'Changelogs','events'=>'Events','community'=>'Community','unis_blog'=>"Uni’s Blog"];$label=$labels[$input['category']??'news']??'NEWS';$prefix=$db->fetch_array($db->simple_select('threadprefixes','pid',"prefix='".$db->escape_string($label)."' AND forums='14'")); if(!$prefix){$prefix=['pid'=>$db->insert_query('threadprefixes',['prefix'=>$label,'displaystyle'=>''.htmlspecialchars_uni($label).'','forums'=>'14','groups'=>'-1'])];$cache->update_threadprefixes();} // MyBB's native validator limits subjects to85 characters; website titles allow120. $subject=my_substr($input['title'],0,85);$prefix_id=(int)$prefix['pid']; - $message='[b]'.$safe($label).'[/b]'."\n".'Written by '.$safe($input['author_name']??'DuneRealms')."\n".'Originally published '.gmdate('j F Y, H:i',(int)($input['published_at']/1000))." UTC\n\n".$safe($input['body'])."\n\n[url=".$url."]Read the original article[/url]\n\n[size=x-small]".$marker.'[/size]'; + $message='[b]'.$safe($label).'[/b]'."\n".'Written by '.$safe($input['author_name']??'DuneRealms')."\n".'Originally published '.gmdate('j F Y, H:i',(int)($input['published_at']/1000))." UTC\n\n".$formatBody($input['body'])."\n\n[url=".$url."]Read the original article[/url]\n\n[size=x-small]".$marker.'[/size]'; if(my_strlen($input['title'])>85)$message='[b]'.$safe($input['title'])."[/b]\n\n".$message; }else{ $subject=my_substr('[Archived] '.preg_replace('/^\[Archived\] /','',$thread['subject']),0,85);$prefix_id=(int)$thread['prefix']; diff --git a/website/node/forum-news.mjs b/website/node/forum-news.mjs index 36ae4cd1..84b91deb 100644 --- a/website/node/forum-news.mjs +++ b/website/node/forum-news.mjs @@ -9,7 +9,7 @@ const nativeSend=post=>new Promise((resolve,reject)=>{const child=execFile('/usr export function forumNewsRevision(row,time){ // Withdrawal payloads deliberately contain no current draft/private/future content. const post=row.status==='published'&&row.published_at!=null&&Number.isFinite(Number(row.published_at))&&Number(row.published_at)<=time - ?{id:row.id,status:'published',title:row.title,body:row.body,category:row.category,published_at:Number(row.published_at),author_name:row.author_name||'DuneRealms'} + ?{id:row.id,status:'published',title:row.title,body:row.body,category:row.category,published_at:Number(row.published_at),author_name:row.author_name||'DuneRealms',format_version:2} :{id:row.id,status:'archived'}; return {...post,revision:createHash('sha256').update(JSON.stringify(post)).digest('hex')}; } diff --git a/website/node/news.mjs b/website/node/news.mjs index 1adc6b35..6772a7f1 100644 --- a/website/node/news.mjs +++ b/website/node/news.mjs @@ -14,7 +14,7 @@ export async function initializeNews(db){ await db.prepare('INSERT INTO website_posts(id,source_key,category,title,body,status,author_id,created_at,updated_at,published_at,version) VALUES(?,?,?,?,?,?,?,?,?,?,1) ON CONFLICT(source_key) DO UPDATE SET source_key=excluded.source_key').bind(randomUUID(),key,'changelogs',String(release.title||release.version).slice(0,120),body,'published','release-register',date,date,date).run(); } } -async function forumLinks(db,posts){try{if(!posts.length)return posts;const{results}=await db.prepare('SELECT post_id,thread_id FROM forum_news_delivery WHERE post_id IN ('+posts.map(()=>'?').join(',')+") AND thread_id>0 AND state='sent'").bind(...posts.map(p=>p.id)).all();const links=new Map(results.filter(r=>Number.isSafeInteger(Number(r.thread_id))&&Number(r.thread_id)>0).map(r=>[r.post_id,'https://forums.dunerealms.com/showthread.php?tid='+Number(r.thread_id)]));return posts.map(p=>({...p,forum_url:links.get(p.id)||null}));}catch{return posts.map(p=>({...p,forum_url:null}));}} +export async function forumLinks(db,posts){try{if(!posts.length)return posts;const{results}=await db.prepare('SELECT post_id,thread_id FROM forum_news_delivery WHERE post_id IN ('+posts.map(()=>'?').join(',')+") AND thread_id>0 AND state='sent'").bind(...posts.map(p=>p.id)).all();const links=new Map(results.filter(r=>Number.isSafeInteger(Number(r.thread_id))&&Number(r.thread_id)>0).map(r=>[r.post_id,'https://forums.dunerealms.com/showthread.php?tid='+Number(r.thread_id)]));return posts.map(p=>({...p,forum_url:links.get(p.id)||null}));}catch{return posts.map(p=>({...p,forum_url:null}));}} export function createPublicNews(db){return async request=>{ const url=new URL(request.url);if(request.method!=='GET')return json({message:'Method not allowed'},405); if(url.pathname==='/api/home/forum'){ diff --git a/website/node/search-visibility.mjs b/website/node/search-visibility.mjs index 37860a44..091dc779 100644 --- a/website/node/search-visibility.mjs +++ b/website/node/search-visibility.mjs @@ -1,4 +1,5 @@ import {renderNewsBody} from './news-format.mjs'; +import {forumLinks,NEWS_CATEGORIES} from './news.mjs'; import {SHARED_HEADER,SHARED_HEAD} from '../scripts/portal-navigation.mjs'; const base='https://www.dunerealms.com'; const esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); @@ -12,7 +13,7 @@ const pages={ '/staff.html':['DuneRealms Staff & Contributors','Meet the DuneRealms community staff and project contributors.'] }; export const newsPath=p=>'/news/'+p.title.toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'').slice(0,75)+'-'+p.id; -const published="SELECT id,title,body,category,published_at,updated_at FROM website_posts WHERE status='published' AND published_at<=?"; +const published="SELECT p.id,p.title,p.body,p.category,p.published_at,p.updated_at,COALESCE(a.display_name,a.username,'DuneRealms') author_name FROM website_posts p LEFT JOIN site_accounts a ON a.id=p.author_id WHERE p.status='published' AND p.published_at<=?"; const ld=data=>''; function metadata(html,{title,description,canonical,type='website',image=base+'/assets/dunerealms-season-logo-v2.png',structured}){ html=html.replace(/


'+esc(p.body.slice(0,180))+'
Read more →