Merge pull request 'Restore and enrich the portal with live Mentat briefing and Imperial Heralds sales' (#438) from feature/portal-community-layout-20261120 into main
All checks were successful
DuneRealms Web CI / web (push) Successful in 2m46s

This commit is contained in:
unimatrix 2026-11-20 21:18:39 +00:00
commit 2d27f73677
17 changed files with 192 additions and 56 deletions

View file

@ -0,0 +1,2 @@
html,body{margin:0;padding:0;background:transparent;color:#eee3c7;font:13px/1.5 system-ui,sans-serif}main,#sidebar-right{width:100%;min-width:0;box-sizing:border-box}.mentat-report{box-sizing:border-box;margin:0;width:100%;padding:18px;border:1px solid #ac8f49;border-radius:12px}.mentat-report h3{font-family:Georgia,serif;font-size:25px}.mentat-report a{color:#eed495}.progression-journal-menu,.progression-directory-menu{display:none!important}#report-host:empty,#content:has(#report-host:empty){display:none}.mentat-guest{padding:20px;border:1px solid #9e8546;border-radius:12px;background:#15352a}.mentat-guest a{color:#eed495}
.mentat-report{border:24px solid transparent;border-image:url('https://www.dunerealms.com/assets/imperial-panel-frame-v1.png') 230 fill / 24px / 0 stretch;border-radius:0;padding:14px;background-clip:padding-box;background-image:linear-gradient(180deg,#0b261b95,#102c22ed 65%),url('https://www.dunerealms.com/assets/political-imperial-chamber-v1.png');background-position:center top;background-size:auto 430px;background-repeat:no-repeat}.mentat-report header{padding-top:14px}.mentat-adviser .mentat-portrait{box-shadow:0 0 0 5px #0b231a,0 0 0 7px #c5a557,0 0 24px #c5a55755}.mentat-report h3{text-shadow:0 2px 5px #000}.mentat-xp{background:#0b251b88;border:1px solid #ab945344;padding:10px;border-radius:6px}

View file

@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Your Mentat Report</title><link rel="stylesheet" href="/v2/cp-v2-progression.css"><link rel="stylesheet" href="/v2/cp-v2-mentat-embed.css"><script type="module" src="/v2/cp-v2-mentat-embed.mjs"></script></head><body><main><div id="content"><div id="report-host"><p role="status">Opening your personal briefing…</p></div></div><aside id="sidebar-right" aria-label="Your personal Mentat Report"></aside></main></body></html>

View file

@ -0,0 +1,5 @@
import {createProgressionSidebar} from './cp-v2-progression-sidebar.mjs';
const host=document.querySelector('#report-host');let report=null;const controller=new AbortController();
function resize(){const height=Math.ceil(document.documentElement.getBoundingClientRect().height);if(height>=100&&height<=1800)for(const origin of ['https://www.dunerealms.com','https://dunerealms.com'])window.parent.postMessage({type:'dune:mentat-size',height},origin);}
async function load(){try{const response=await fetch('/api/progression',{credentials:'same-origin',cache:'no-store',signal:controller.signal});if(response.status===401||response.status===403){host.replaceChildren();host.className='mentat-guest';const h=document.createElement('h2'),p=document.createElement('p'),a=document.createElement('a');h.textContent='Mentat Report';p.textContent='Sign in to see your House adviser, personal level and reputation.';a.textContent='Sign in →';a.href='https://cp.dunerealms.com/';a.target='_top';host.append(h,p,a);resize();return;}if(!response.ok)throw Error('Your briefing is temporarily unavailable.');const data=await response.json();host.replaceChildren();report=createProgressionSidebar(host,{onNavigate:(kind,view)=>{window.top.location.href='https://clans.dunerealms.com/#quests/quests?'+new URLSearchParams({xp:kind,view});}});report.setJournal('personal',data);report.setNavigation('personal','missions');report.showBranches(false);resize();}catch(error){host.textContent=error.message||'Your briefing is temporarily unavailable.';resize();}}
new ResizeObserver(resize).observe(document.body);window.addEventListener('pagehide',()=>{controller.abort();report?.dispose();},{once:true});void load();

View file

@ -423,6 +423,7 @@ export function createPanel(db,settings={},dependencies={}){
if(path.startsWith('/v2/vendor/fullcalendar/')&&['GET','HEAD'].includes(request.method)){const file=path.slice('/v2/vendor/fullcalendar/'.length);if(!calendarVendorFiles.has(file))return new Response('Not found',{status:404});const type=file.endsWith('.js')?'text/javascript':file.endsWith('.css')?'text/css':file.endsWith('.json')?'application/json':'text/plain';return new Response(request.method==='HEAD'?null:await readFile(new URL('./public/cp-v2/vendor/fullcalendar/'+file,import.meta.url)),{headers:{'Content-Type':type+'; charset=utf-8','Cache-Control':'private, no-store','X-Content-Type-Options':'nosniff'}});}
// All authored cp-v2 browser modules share this bounded public directory.
// New components must not require a second, manually maintained route list.
if(path==='/mentat-report')return new Response(request.method==='HEAD'?null:await readFile(new URL('./public/cp-v2/cp-v2-mentat-embed.html',import.meta.url)),{headers:{'Content-Type':'text/html; charset=utf-8','Cache-Control':'private, no-store','X-Content-Type-Options':'nosniff','Content-Security-Policy':PANEL_CSP.replace("img-src 'self' data:;","img-src 'self' data: https://www.dunerealms.com;")}});
if(/^\/(?:v2|cp-v2)\/cp-v2-[a-z0-9-]+\.(?:mjs|css)$/.test(path)){
try{const bytes=await readFile(new URL('./public/cp-v2/'+path.slice(path.lastIndexOf('/')+1),import.meta.url));return new Response(request.method==='HEAD'?null:bytes,{headers:{'Content-Type':path.endsWith('.css')?'text/css; charset=utf-8':'text/javascript; charset=utf-8','Cache-Control':'private, no-store','X-Content-Type-Options':'nosniff'}});}catch(error){if(error.code==='ENOENT')return new Response('Not found',{status:404});throw error;}
}

View file

@ -1,3 +1,4 @@
import {createShopSales} from './shop-sales.mjs';
import {initializePassiveOrders} from './political-passive-orders.mjs';
import {POLITICAL_APPOINTMENT_SCHEMA} from './political-appointments.mjs';
import {NETWORK_LAYOUT_SCHEMA} from './organisation-network.mjs';
@ -35,7 +36,7 @@ import {createMenuBadges} from './menu-badges.mjs';
import {createSearchVisibility} from './search-visibility.mjs';
const root=new URL('./public/',import.meta.url);
const servingCommit=releaseCommitFromModuleUrl(import.meta.url);
const security={'X-Content-Type-Options':'nosniff','Referrer-Policy':'strict-origin-when-cross-origin','Content-Security-Policy':"default-src 'self'; frame-src https://cp.dunerealms.com; img-src 'self' https://www.dunerealms.com https://cp.dunerealms.com https://support.dunerealms.com https://forums.dunerealms.com data:; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; script-src 'self'; connect-src 'self' https://cp.dunerealms.com; base-uri 'self'; object-src 'none'; frame-ancestors 'self'"};
const security={'X-Content-Type-Options':'nosniff','Referrer-Policy':'strict-origin-when-cross-origin','Content-Security-Policy':"default-src 'self'; frame-src https://cp.dunerealms.com; img-src 'self' https://shop.dunerealms.com https://www.dunerealms.com https://cp.dunerealms.com https://support.dunerealms.com https://forums.dunerealms.com data:; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; script-src 'self'; connect-src 'self' https://cp.dunerealms.com; base-uri 'self'; object-src 'none'; frame-ancestors 'self'"};
export function createApplication(db,settings={}) {
const origin=new URL(settings.PUBLIC_ORIGIN||'https://dunerealms.com').origin;
const auth=createAuth(db,origin),publicClans=createPublicClans(db),publicOrganisations=createPublicOrganisations(db);
@ -47,10 +48,12 @@ export function createApplication(db,settings={}) {
const gameLink=createGameLink(db,settings,origin);
const rewards=createCommunityRewards(db,settings,origin);
const publicNews=createPublicNews(db);const publicExchange=createPublicExchange(db,settings);
const shopSales=createShopSales();
const searchVisibility=createSearchVisibility(db);const menuBadges=createMenuBadges(db,settings);
return async function handle(request) {
const url=new URL(request.url);
if(url.pathname==='/ci-build.json'&&servingCommit)return ['GET','HEAD'].includes(request.method)?new Response(request.method==='HEAD'?null:JSON.stringify({commit:servingCommit}),{headers:{'Content-Type':'application/json; charset=utf-8','Cache-Control':'no-store'}}):new Response('Method not allowed',{status:405});
if(url.pathname==='/api/shop-sales')return shopSales(request);
if(url.pathname==='/api/menu-badges')return menuBadges(request);
// Discord publishes canonical /news/:slug-:id links. Route these before
// static assets so published articles cannot fall through to a Worker 404.

View file

@ -0,0 +1,14 @@
const SHOP='https://shop.dunerealms.com';
const FEED=SHOP+'/catalog/dune-shop/sales-feed?currency=EUR';
const cleanText=(v,max)=>typeof v==='string'&&v.length>0&&v.length<=max&&!/[\x00-\x1f\x7f]/.test(v);
function shopURL(value,{product=false}={}){if(typeof value!=='string'||value.length>1800)return null;try{const url=new URL(value,SHOP+'/catalog/');if(url.hostname!=='shop.dunerealms.com'||!['https:','http:'].includes(url.protocol)||url.username||url.password||url.port||product&&!url.pathname.startsWith('/catalog/'))return null;url.protocol='https:';return url.href;}catch{return null;}}
export function projectShopSales(data){
if(data?.source!=='oscommerce'||data.currency!=='EUR'||!Array.isArray(data.items)||data.items.length>24)throw Error('Invalid osCommerce promotion feed');
const items=[];for(const row of data.items){const url=shopURL(row.url,{product:true}),image=shopURL(row.image);if(!Number.isSafeInteger(row.id)||row.id<1||!cleanText(row.name,240)||!cleanText(row.regularPrice,80)||!cleanText(row.salePrice,80)||!Number.isInteger(row.savingPercent)||row.savingPercent<1||row.savingPercent>100||!url)continue;items.push({id:row.id,name:row.name,url,image,regularPrice:row.regularPrice,salePrice:row.salePrice,savingPercent:row.savingPercent});if(items.length===3)break;}
return {source:'oscommerce',brand:'Imperial Heralds',currency:'EUR',items};
}
export function createShopSales({fetcher=fetch,clock=Date.now}={}){
let cached=null,expires=0,pending=null;
const read=()=>{if(cached&&clock()<expires)return Promise.resolve(cached);if(pending)return pending;pending=(async()=>{const response=await fetcher(FEED,{redirect:'error',signal:AbortSignal.timeout(8000),headers:{Accept:'application/json'}});if(!response.ok)throw Error('Shop offers unavailable');const text=await response.text();if(text.length>131072)throw Error('Shop offer response too large');const data=projectShopSales(JSON.parse(text));cached=data;expires=clock()+60000;return data;})().finally(()=>pending=null);return pending;};
return async request=>{if(request.method!=='GET')return Response.json({message:'Read-only shop offers.'},{status:405,headers:{Allow:'GET'}});if(new URL(request.url).search)return Response.json({message:'Unknown shop offer filter.'},{status:400});try{return Response.json(await read(),{headers:{'Cache-Control':'public, max-age=30','X-Content-Type-Options':'nosniff'}});}catch{return Response.json({source:'oscommerce',message:'Shop offers are temporarily unavailable.'},{status:503,headers:{'Cache-Control':'no-store'}});}};
}

View file

@ -3,14 +3,29 @@ namespace frontend\controllers;
use Yii;
use yii\helpers\Html;
final class DuneShopController extends Sceleton {
public function actionSalesFeed() {
Yii::$app->response->format=\yii\web\Response::FORMAT_JSON;
Yii::$app->response->headers->set('Cache-Control','public, max-age=60');
if(!Yii::$app->request->isGet){Yii::$app->response->statusCode=405;return ['message'=>'Read-only shop offers.'];}
$rows=Yii::$app->db->createCommand("SELECT DISTINCT p.products_id,p.products_price,p.products_tax_class_id,pd.products_name FROM products p JOIN platforms_products pp ON pp.products_id=p.products_id AND pp.platform_id=7 JOIN products_description pd ON pd.products_id=p.products_id AND pd.language_id=1 AND pd.platform_id=7 JOIN specials s ON s.products_id=p.products_id WHERE p.products_status=1 AND p.products_price>0 AND s.status=1 AND s.specials_new_products_price>=0 AND s.specials_new_products_price<p.products_price AND (s.start_date IS NULL OR s.start_date='0000-00-00 00:00:00' OR s.start_date<=NOW()) AND (s.expires_date IS NULL OR s.expires_date='0000-00-00 00:00:00' OR s.expires_date>NOW()) ORDER BY p.products_id DESC LIMIT 12")->queryAll();
$currencies=Yii::$container->get('currencies');$items=[];
foreach($rows as $p){
$id=(int)$p['products_id'];$normal=\common\helpers\Product::get_products_price($id,1,$p['products_price']);$special=\common\helpers\Product::get_products_special_price($id,1);
if(!is_numeric($normal)||!is_numeric($special)||(float)$normal<=0||(float)$special<0||(float)$special>=(float)$normal)continue;
$tax=\common\helpers\Tax::get_tax_rate($p['products_tax_class_id']);
$price=fn($value)=>html_entity_decode(strip_tags($currencies->format($currencies->getPriceTaxable($value,$tax,1),true,'EUR','',false,false)),ENT_QUOTES|ENT_HTML5,'UTF-8');
$items[]=['id'=>$id,'name'=>$p['products_name'],'url'=>\yii\helpers\Url::to(['catalog/product','products_id'=>$id],true),'image'=>\common\classes\Images::getImageUrl($id,'Small',1),'regularPrice'=>$price($normal),'salePrice'=>$price($special),'savingPercent'=>max(1,(int)round((1-(float)$special/(float)$normal)*100))];
}
return ['source'=>'oscommerce','brand'=>'Imperial Heralds','currency'=>'EUR','items'=>$items];
}
public function actionIndex() {
$this->view->title='DuneRealms Shop';
$this->view->title='Imperial Heralds · DuneRealms';
$rows=Yii::$app->db->createCommand("SELECT p.products_id,p.products_price,p.products_tax_class_id,pd.products_name,pd.products_description_short,d.kind FROM products p JOIN platforms_products pp ON pp.products_id=p.products_id AND pp.platform_id=7 JOIN products_description pd ON pd.products_id=p.products_id AND pd.language_id=1 AND pd.platform_id=7 LEFT JOIN dune_catalog_import d ON d.products_id=p.products_id WHERE p.products_status=1 ORDER BY p.products_date_added DESC,p.products_id DESC")->queryAll();
$saleIds=Yii::$app->db->createCommand("SELECT DISTINCT products_id FROM specials WHERE EXISTS(SELECT 1 FROM products active JOIN platforms_products pp ON pp.products_id=active.products_id AND pp.platform_id=7 WHERE active.products_id=specials.products_id AND active.products_status=1 AND specials.specials_new_products_price<active.products_price) AND status=1 AND (start_date IS NULL OR start_date='0000-00-00 00:00:00' OR start_date<=NOW()) AND (expires_date IS NULL OR expires_date='0000-00-00 00:00:00' OR expires_date>NOW())")->queryColumn();
$featuredIds=Yii::$app->db->createCommand("SELECT DISTINCT products_id FROM featured WHERE EXISTS(SELECT 1 FROM products active JOIN platforms_products pp ON pp.products_id=active.products_id AND pp.platform_id=7 WHERE active.products_id=featured.products_id AND active.products_status=1) AND status=1 AND (start_date IS NULL OR start_date='0000-00-00 00:00:00' OR start_date<=NOW()) AND (expires_date IS NULL OR expires_date='0000-00-00 00:00:00' OR expires_date>NOW())")->queryColumn();
$sashes=count(array_filter($rows,fn($r)=>$r['kind']==='sash'));$ranks=count(array_filter($rows,fn($r)=>$r['kind']==='rank'));
$base=fn($route)=>Html::encode(\yii\helpers\Url::to([$route]));
$out='<section class="dune-store-welcome"><div><small>THE DUNEREALMS EMPORIUM</small><h1>Carry a piece of the realms.</h1><p>Ceremonial sashes, personal keepsakes and ways to support the community.</p><a class="dune-store-button" href="'.$base('catalog/all-products').'">Browse the collection</a></div><img src="https://www.dunerealms.com/assets/nav-shop-v1.webp" alt=""></section>';
$out='<section class="dune-store-welcome"><div><small>IMPERIAL HERALDS · DUNEREALMS</small><h1>Carry a piece of the realms.</h1><p>Ceremonial sashes, personal keepsakes and ways to support the community.</p><a class="dune-store-button" href="'.$base('catalog/all-products').'">Browse the collection</a></div><img src="https://www.dunerealms.com/assets/imperial-heralds-logo-v1.png" alt=""></section>';
$tiles=[['Sale',count($saleIds)?'Explore current offers':'No sales active right now','catalog/sales','nav-exchange-v2.webp',''],['Ceremonial sashes',$sashes.' designs · made to order','catalog/all-products','nav-clan-v2.webp','sash'],['Donor ranks',$ranks.' ways to support the realms','catalog/all-products','nav-account-v2.webp','rank']];
$out.='<nav class="dune-store-categories" aria-label="Shop collections">';
foreach($tiles as [$title,$text,$route,$icon,$kind]){

View file

@ -34,3 +34,5 @@ html,body{height:auto!important;min-height:0!important}.main-content{min-height:
.dune-store-category--sale{background:linear-gradient(125deg,#542e2a,#292d21)!important;border-color:#b08855!important}.dune-store-category--sale>span{font-size:10px!important;letter-spacing:.1em!important;background:#a24636;border:1px solid #ce8f63;border-radius:5px;padding:6px 8px;color:#fff0cb!important}.dune-store-section--sale{background:linear-gradient(120deg,#38281f,#172e21 65%)!important;border-color:#b08a53!important;border-top:3px solid #b77949!important;box-shadow:0 8px 24px #0003}.dune-store-section--sale>header{border-color:#805b40!important}.dune-store-sale-label{display:inline-block;vertical-align:middle;font-size:10px;line-height:1.2;letter-spacing:.1em;background:#a54737;color:#fff1cf;padding:6px 9px;border:1px solid #d48b60;border-radius:5px;margin-right:8px}.dune-store-section--sale article{border-color:#8c7147!important;background:linear-gradient(145deg,#302f20,#10271b)!important}.dune-store-price del{display:block;color:#a9b3a1;font-size:13px;font-weight:400;margin-bottom:5px}.dune-store-price strong{display:block;color:#f3d28a!important}.dune-store-saving{display:inline-block;font-size:10px;font-weight:600;letter-spacing:.025em;background:#8f3d2e;color:#ffe6b3;border:1px solid #bd7850;border-radius:4px;padding:4px 7px;margin-top:8px}
/* Featured collection: warm gold, distinct from active sale promotions. */
.dune-store-section--featured{border:1px solid #baa15d!important;border-top:3px solid #dfc575!important;background:radial-gradient(ellipse at 35% 0,#7b6b3038,transparent 65%),linear-gradient(125deg,#263d27,#142b1e)!important;box-shadow:0 8px 28px #cfa74612!important}.dune-store-section--featured>header{border-bottom-color:#8d7b47!important}.dune-store-section--featured h2{color:#f3da92!important}.dune-store-section--featured header>a{color:#edd18b!important}.dune-store-section--featured article{border-color:#9a854c!important;background:linear-gradient(145deg,#31462b,#112a1e)!important}.dune-store-section--featured .dune-store-product-art{background:radial-gradient(ellipse,#8b7a394d,transparent 70%)}.dune-store-section--featured .dune-store-button{background:linear-gradient(#655d2e,#3a4829)!important;border-color:#c4a65c!important;color:#fff0c3!important}.dune-store-section--featured .dune-store-empty{border-color:#99844a!important;background:#37492a!important;color:#decf9c!important}
.dune-store-welcome>img[src*="imperial-heralds-logo"]{width:min(440px,46%);height:auto;object-fit:contain;filter:drop-shadow(0 8px 12px #0008)}@media(max-width:700px){.dune-store-welcome>img[src*="imperial-heralds-logo"]{width:min(100%,360px)}}

View file

@ -0,0 +1,29 @@
#!/usr/bin/env python3
"""Publish only the reviewed osCommerce controller/styles; never change shop SQL."""
import argparse, hashlib, os, pathlib, subprocess
parser=argparse.ArgumentParser();parser.add_argument('--apply',action='store_true');args=parser.parse_args()
if os.geteuid()!=0: raise SystemExit('Root operator required')
app=pathlib.Path('/home/dunerealms/apps/oscommerce').resolve(strict=True)
source=pathlib.Path(__file__).resolve().parent
specs=[('DuneShopController.php','lib/frontend/controllers/DuneShopController.php','98a5c5d536cbf8badf5c567eb95e759726f27ffe215609596c72e8a151a58917','c977e5d9383d99c1a75caa15c2e769b1f54966114baa91ab54de45bcc05b752f'),('dune-shop-cards.css','dune-shop-cards.css','6206f3ff2695d73318dd05c92727062d82dff99423d49d37d3a93ba87b20b854','03f8f72ead3b514bd5c426d43ae87757b3c7460d94dd4e78a6bc99f555dd69eb')]
def canonical(path):return path.read_bytes().replace(bytes([13,10]),bytes([10]))
def digest(data):return hashlib.sha256(data).hexdigest()
plan=[]
for name,relative,before,after in specs:
target=(app/relative).resolve(strict=True)
if not target.is_relative_to(app):raise SystemExit('Target escaped the shop root')
body=canonical(source/name)
if digest(body)!=after:raise SystemExit('Unreviewed source: '+name)
current=digest(canonical(target))
if current not in (before,after):raise SystemExit('Live file changed; preserve and review: '+relative)
plan.append((name,target,body,current!=after))
subprocess.run(['php','-l',str(source/'DuneShopController.php')],check=True)
for name,target,body,changed in plan:
if args.apply and changed:
stat=target.stat();temporary=target.with_name('.'+target.name+'.heralds-'+str(os.getpid()))
try:
with temporary.open('xb') as handle:handle.write(body)
temporary.chmod(stat.st_mode & 0o777);os.chown(temporary,stat.st_uid,stat.st_gid);os.replace(temporary,target)
finally:
if temporary.exists():temporary.unlink()
print(('APPLIED' if args.apply and changed else 'UNCHANGED' if not changed else 'READY')+' '+name)

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,6 @@
import test from 'node:test';import assert from 'node:assert/strict';import {readFileSync} from 'node:fs';import {BankFixture} from './postbank-fixture.mjs';import {createShopSales,projectShopSales} from '../node/shop-sales.mjs';
const product={id:76,name:'House sash',url:'https://shop.dunerealms.com/catalog/EUR/catalog/product?products_id=76',image:'/images/sash.png',regularPrice:'€100.00',salePrice:'€80.00',savingPercent:20};const feed=()=>({source:'oscommerce',currency:'EUR',items:[product]});const request=()=>new Request('https://www.dunerealms.com/api/shop-sales');
test('sales display only validated osCommerce products, prices and trusted shop links',()=>{const result=projectShopSales(feed());assert.equal(result.items[0].salePrice,'€80.00');assert.equal(result.items[0].image,'https://shop.dunerealms.com/images/sash.png');assert.throws(()=>projectShopSales({...feed(),source:'azuriom'}));for(const patch of [{url:'https://evil.example/product'},{url:'javascript:alert(1)'},{savingPercent:0}])assert.equal(projectShopSales({...feed(),items:[{...product,...patch}]}).items.length,0);assert.equal(projectShopSales({...feed(),items:[{...product,image:'https://evil.example/tracker'}]}).items[0].image,null);});
test('public sales reads share one bounded cache, refresh after a minute and never forward account credentials',async()=>{let count=0,now=0;const api=createShopSales({clock:()=>now,fetcher:async(url,options)=>{count++;assert.equal(url,'https://shop.dunerealms.com/catalog/dune-shop/sales-feed?currency=EUR');assert.equal(options.redirect,'error');assert.equal(options.headers.Cookie,undefined);return Response.json(feed());}});const responses=await Promise.all([api(request()),api(request()),api(request())]);assert.equal(count,1);assert.ok(responses.every(r=>r.status===200));await api(request());assert.equal(count,1);now=60001;await api(request());assert.equal(count,2);assert.equal((await api(new Request(request().url,{method:'POST'}))).status,405);assert.equal((await api(new Request(request().url+'?customer=other'))).status,400);});
test('unavailable or unrelated shop data produces an honest unavailable state rather than fabricated sales',async()=>{const api=createShopSales({fetcher:async()=>Response.json({source:'azuriom',items:[]})});assert.equal((await api(request())).status,503);const empty=createShopSales({fetcher:async()=>Response.json({...feed(),items:[]})});assert.deepEqual((await(await empty(request())).json()).items,[]);});
test('native osCommerce sale query excludes expired, future, disabled and other-platform offers',async()=>{const db=new BankFixture();try{db.sqlite.function('NOW',()=> '2026-11-20 20:00:00');await db.query('CREATE TABLE products(products_id INTEGER,products_price INTEGER,products_tax_class_id INTEGER,products_status INTEGER)');await db.query('CREATE TABLE platforms_products(products_id INTEGER,platform_id INTEGER)');await db.query('CREATE TABLE products_description(products_id INTEGER,products_name TEXT,language_id INTEGER,platform_id INTEGER)');await db.query('CREATE TABLE specials(products_id INTEGER,specials_new_products_price INTEGER,status INTEGER,start_date TEXT,expires_date TEXT)');for(let id=1;id<=6;id++){await db.query('INSERT INTO products VALUES(?,100,1,?)',[id,id===5?0:1]);await db.query('INSERT INTO platforms_products VALUES(?,?)',[id,id===6?8:7]);await db.query('INSERT INTO products_description VALUES(?,?,1,7)',[id,'Product '+id]);await db.query('INSERT INTO specials VALUES(?,80,?,?,?)',[id,id===4?0:1,id===2?'2026-11-21 00:00:00':null,id===3?'2026-11-19 00:00:00':null]);}const source=readFileSync(new URL('../ops/oscommerce/DuneShopController.php',import.meta.url),'utf8'),action=source.slice(source.indexOf('function actionSalesFeed'),source.indexOf('function actionIndex'));const sql=action.split('createCommand("')[1].split('")->queryAll')[0];assert.deepEqual((await db.query(sql)).map(r=>r.products_id),[1]);}finally{db.close();}});

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

@ -1,3 +1,61 @@
/* Approved community portal; shared masthead and navigation remain unchanged. */
body.portal-community main#main{display:grid;grid-template-columns:minmax(170px,210px) minmax(0,1fr) minmax(210px,270px);gap:22px;width:min(1640px,96%);max-width:none;margin:24px auto;padding:0;align-items:start}.portal-directory,.portal-stories,.portal-realm-status{min-width:0;display:grid;gap:20px}.portal-community-card,.portal-directory-group{padding:20px;border:1px solid #9e8546;border-radius:12px;background:linear-gradient(135deg,#1d4033,#102b23);color:#eee3c7}.portal-directory-group{padding:0;overflow:hidden}.portal-directory-group summary{padding:14px;color:#eed495;font:700 18px Georgia,serif;cursor:pointer;border-bottom:1px solid #687044}.portal-directory-group nav{display:grid;gap:5px;padding:9px}.portal-directory-group a{display:block;padding:10px 12px;border:1px solid #475c3e;border-radius:6px;background:#102b22;text-decoration:none;color:#ede1bc}.portal-directory-group a:hover,.portal-directory-group a:focus-visible{background:#294b37;border-color:#d7b660}.portal-community-card h2{font-family:Georgia,serif;color:#eed495;margin-top:0}.portal-community-card a{color:#eed495}.portal-placeholder{display:block;padding:9px 12px;border-left:2px solid #ab9258;color:#b9cbbd;background:#0c261e;font-size:12px}.portal-briefing{text-align:center;background:linear-gradient(#14352be8,#102b23f2),url('/assets/political-imperial-chamber-v1.png') center/cover}.portal-briefing small{font-size:10px;letter-spacing:.12em}.portal-briefing img{object-fit:contain;margin:8px auto}.portal-community .portal-stories>.dune-page-marker{width:100%;min-height:0!important;padding:18px!important;display:flex;flex-wrap:wrap;gap:12px;border:1px solid #9e8546!important;border-radius:12px;background:linear-gradient(100deg,#102d24e8,#153a2dba),url('/assets/political-imperial-chamber-v1.png') center/cover}.portal-community .portal-stories>.dune-page-marker>img{width:90px!important;height:100px!important;flex-basis:90px!important}.portal-community .portal-stories>.dune-page-marker>div{flex:1;min-width:170px;max-width:none;text-align:left}.portal-community .portal-stories>.dune-page-marker p{font-size:22px!important}.portal-community .portal-realm-status>.world-status{position:static!important;inset:auto!important;transform:none!important;width:100%!important;min-width:0!important;max-width:none!important;margin:0!important;box-sizing:border-box;padding:14px;border:1px solid #9e8546;border-radius:12px;background:#102b23}.portal-community .news-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.portal-community .moderation-columns{display:grid;grid-template-columns:1fr;gap:20px}.portal-community .three-grid{grid-template-columns:1fr}.portal-community #server-bans{min-width:0}.portal-community .portal-stories .panel{margin:0;padding:20px}.portal-community .feature{margin:0;min-height:180px}.portal-community .portal-account-card{max-width:100%;box-sizing:border-box}
@media(max-width:1100px){body.portal-community main#main{grid-template-columns:170px minmax(0,1fr)}.portal-realm-status{grid-column:1/-1;grid-template-columns:repeat(3,minmax(0,1fr))}}@media(max-width:700px){body.portal-community main#main{display:flex;flex-direction:column;width:94%;gap:16px}.portal-directory,.portal-stories,.portal-realm-status{width:100%}.portal-directory{grid-template-columns:1fr}.portal-realm-status{grid-template-columns:1fr}.portal-community .news-grid{grid-template-columns:1fr}}
/* Scope above the legacy portal selectors. Cards respond to their column,
rather than the viewport: three narrow cards must never share half a panel. */
body.portal-redesign.portal-community main#main .moderation-columns{
display:grid;grid-template-columns:minmax(0,1fr);gap:20px;
}
body.portal-redesign.portal-community main#main .three-grid,
body.portal-redesign.portal-community main#main .news-grid{
display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));gap:16px;overflow:visible;
}
body.portal-redesign.portal-community main#main .three-grid>.record-card{
min-width:0;width:100%;max-width:none;
}
body.portal-redesign.portal-community main#main .record-card .card-copy{min-width:0;}
body.portal-redesign.portal-community main#main .record-card dl{
display:grid;grid-template-columns:minmax(0,1fr);gap:0;margin:10px 0 16px;
padding:0;background:none;border:1px solid #536a47;border-radius:7px;overflow:hidden;
}
body.portal-redesign.portal-community main#main .record-card dt{
min-width:0;padding:9px 12px 2px;font-size:10px;letter-spacing:.06em;
text-transform:uppercase;color:#d0ba7c;background:#19392c;
}
body.portal-redesign.portal-community main#main .record-card dd{
min-width:0;margin:0;padding:2px 12px 10px;font-size:13px;line-height:1.5;
color:#eee3c7;background:#19392c;overflow-wrap:anywhere;word-break:normal;
}
body.portal-redesign.portal-community main#main .record-card dt:nth-of-type(even),
body.portal-redesign.portal-community main#main .record-card dd:nth-of-type(even){background:#112d23;}
/* The main menu already provides the directory: keep the portal center wide. */
body.portal-redesign.portal-community main#main{grid-template-columns:minmax(0,1fr) minmax(230px,290px)}
.portal-mentat-frame{display:block;width:100%;min-width:0;border:0;background:transparent;border-radius:12px}
@media(max-width:1100px){body.portal-redesign.portal-community main#main{grid-template-columns:minmax(0,1fr) minmax(210px,260px)}.portal-realm-status{grid-column:auto;grid-template-columns:minmax(0,1fr)}}
@media(max-width:700px){body.portal-redesign.portal-community main#main{display:flex;flex-direction:column}}
/* One imperial Minecraft frame asset, reused by every portal panel. */
body.portal-redesign.portal-community main#main .portal-community-card,
body.portal-redesign.portal-community main#main .portal-stories>.panel,
body.portal-redesign.portal-community main#main .portal-stories>.feature,
body.portal-redesign.portal-community main#main .portal-stories>.dune-page-marker,
body.portal-redesign.portal-community main#main .portal-realm-status>.world-status{
border:24px solid transparent!important;border-image-source:url('/assets/imperial-panel-frame-v1.png')!important;
border-image-slice:230 fill!important;border-image-width:24px!important;border-image-repeat:stretch!important;
border-radius:0!important;background-clip:padding-box!important;box-shadow:0 12px 28px #0005;
padding:14px!important;
}
body.portal-redesign.portal-community main#main .record-card,
body.portal-redesign.portal-community main#main .news-card{border:10px solid transparent;border-image:url('/assets/imperial-panel-frame-v1.png') 230 fill / 10px / 0 stretch;border-radius:0;background-clip:padding-box;}
.portal-shop-sales{position:relative;overflow:hidden;background:linear-gradient(155deg,#421c25ee,#16392df2 55%),url('/assets/clan-atelier-v1.webp') center/cover;color:#f7e8c1;text-align:center}
.portal-shop-sales>img{display:block;width:100%;height:auto;max-height:100px;object-fit:contain;margin:0 auto 12px;filter:drop-shadow(0 5px 7px #0008)}
.portal-shop-sales header{border-top:1px solid #c7a45477;padding-top:14px}.portal-shop-sales h2{font-size:23px;margin:10px 0 6px;text-transform:uppercase;letter-spacing:.04em}
.portal-sale-ribbon{display:inline-block;padding:5px 12px;background:linear-gradient(110deg,#651b2b,#a53c37,#651b2b);color:#fff1bd;border:1px solid #d3ad57;font-size:10px;font-weight:800;letter-spacing:.12em;box-shadow:0 3px 12px #0006}
.portal-sale-state{font-size:11px;line-height:1.55;color:#cccfb7}.portal-sale-items{display:grid;gap:12px;margin:16px 0}
.portal-sale-product{display:grid;grid-template-columns:64px minmax(0,1fr);gap:10px;padding:10px;border:1px solid #aa8d49;border-radius:7px;background:linear-gradient(130deg,#173a2c,#0c251e);color:#eee3c7;text-align:left;text-decoration:none;box-shadow:0 4px 12px #0004}
.portal-sale-product>img{width:64px;height:116px;object-fit:contain;align-self:center;background:#0b231b;border-radius:4px}.portal-sale-product h3{font-size:13px!important;line-height:1.4;margin:7px 0;overflow-wrap:anywhere}.portal-sale-saving{display:inline-block;background:#852c32;border:1px solid #cdac5c;color:#fff0b6;padding:2px 7px;font-size:11px;font-weight:800;border-radius:4px}
.portal-sale-prices{display:grid;gap:2px}.portal-sale-prices del{font-size:11px;color:#c4bcac}.portal-sale-prices strong{font-size:20px;line-height:1.25;color:#f5d57b}.portal-sale-view{display:block;margin-top:8px;font-size:11px;color:#d8bf79}
.portal-sale-action{display:block;padding:12px 8px;border:1px solid #d2b469;border-radius:6px;background:linear-gradient(#8e702f,#54441f);color:#fff0bb!important;font-weight:800;font-size:12px;text-decoration:none;box-shadow:0 5px 14px #0005}.portal-sale-product:hover,.portal-sale-product:focus-visible{outline:2px solid #ead086;outline-offset:2px}
@media(max-width:700px){body.portal-redesign.portal-community main#main .portal-community-card,body.portal-redesign.portal-community main#main .portal-stories>.panel,body.portal-redesign.portal-community main#main .portal-realm-status>.world-status{border-width:18px!important;border-image-width:18px!important;padding:12px!important}}

View file

@ -4,12 +4,12 @@
const el=(tag,text,cls)=>{const node=document.createElement(tag);if(text!==undefined)node.textContent=text;if(cls)node.className=cls;return node;};
const link=(label,href)=>{const a=el('a',label);a.href=href;return a;};
document.body.classList.add('portal-community');
const left=el('aside',undefined,'portal-directory'),center=el('div',undefined,'portal-stories'),right=el('aside',undefined,'portal-realm-status');left.setAttribute('aria-label','Realm directory');right.setAttribute('aria-label','Your realm briefing');
const previous=[...main.children];main.replaceChildren(left,center,right);for(const node of previous)center.append(node);
for(const [title,items]of [['Community',[['Gazette','/news-archive.html'],['Forums','https://forums.dunerealms.com/'],['Staff roster','/staff.html'],['Discord','/discord.html']]],['The realm',[['Political Houses','/government.html'],['Clans','https://clans.dunerealms.com/'],['Companies','https://corp.dunerealms.com/'],['Exchange','/exchange.html']]],['Your adventure',[['Missions & Decisions','https://clans.dunerealms.com/#quests/quests'],['Your account','https://cp.dunerealms.com/'],['Field manual','/manual.html']]]]){
const section=el('details',undefined,'portal-directory-group');section.open=true;section.append(el('summary',title));const nav=el('nav');nav.setAttribute('aria-label',title);for(const [label,href]of items)nav.append(link(label,href));section.append(nav);left.append(section);
}
const report=el('section',undefined,'portal-community-card portal-briefing');const portrait=el('img');portrait.src='/assets/nav-account-v2.webp';portrait.alt='';portrait.width=portrait.height=72;report.append(el('small','J.A.R.V.I.S. · PERSONAL BRIEFING'),el('h2','Mentat Report'),portrait,el('p','Your House adviser, personal level and reputation await in your mission journal.'),link('Open your briefing →','https://clans.dunerealms.com/#quests/quests'));right.append(report);
const center=el('div',undefined,'portal-stories'),right=el('aside',undefined,'portal-realm-status');right.setAttribute('aria-label','Your realm briefing');
const previous=[...main.children];main.replaceChildren(center,right);for(const node of previous)center.append(node);
const report=el('iframe',undefined,'portal-mentat-frame');report.src='https://cp.dunerealms.com/mentat-report';report.title='Your personal Mentat Report';report.setAttribute('sandbox','allow-scripts allow-same-origin allow-top-navigation-by-user-activation');report.height='840';right.append(report);
window.addEventListener('message',event=>{if(event.origin!=='https://cp.dunerealms.com'||event.source!==report.contentWindow||event.data?.type!=='dune:mentat-size'||!Number.isSafeInteger(event.data.height)||event.data.height<100||event.data.height>1800)return;report.height=String(event.data.height);});
const sales=el('section',undefined,'portal-community-card portal-shop-sales');const logo=el('img');logo.src='/assets/imperial-heralds-logo-v1.png';logo.alt='Imperial Heralds';logo.width=260;logo.height=90;const saleHeading=el('header');saleHeading.append(el('span','SPECIAL OFFERS','portal-sale-ribbon'),el('h2','Shop Sales'));const saleItems=el('div',undefined,'portal-sale-items'),saleState=el('p','Opening the Imperial Heralds offers…','portal-sale-state');saleState.setAttribute('role','status');const shopLink=link('Explore all offers →','https://shop.dunerealms.com/catalog/EUR/catalog/sales');shopLink.className='portal-sale-action';sales.append(logo,saleHeading,saleState,saleItems,shopLink);right.append(sales);
void fetch('/api/shop-sales',{cache:'default',credentials:'omit'}).then(async response=>{if(!response.ok)throw Error();return response.json();}).then(data=>{if(data.source!=='oscommerce'||!Array.isArray(data.items))throw Error();window.dispatchEvent(new CustomEvent('dune:shop-promotions',{detail:{active:data.items.length>0,source:'oscommerce'}}));if(!data.items.length){shopLink.href='https://shop.dunerealms.com/catalog/EUR/catalog/all-products';shopLink.textContent='Browse the collection →';}saleState.textContent=data.items.length?'Selected offers from our osCommerce shop.':'No active sales right now. Explore the collection.';for(const item of data.items){const card=el('a',undefined,'portal-sale-product');card.href=item.url;const image=el('img');image.src=item.image||'/assets/imperial-heralds-logo-v1.png';image.alt=item.name;image.loading='lazy';image.onerror=()=>{image.onerror=null;image.src='/assets/imperial-heralds-logo-v1.png';};const copy=el('div'),prices=el('div',undefined,'portal-sale-prices');prices.append(el('del',item.regularPrice),el('strong',item.salePrice));copy.append(el('span','−'+item.savingPercent+'%','portal-sale-saving'),el('h3',item.name),prices,el('span','View offer →','portal-sale-view'));card.append(image,copy);saleItems.append(card);}}).catch(()=>{saleState.textContent='Current offers are temporarily unavailable. Visit Imperial Heralds to browse the collection.';});
for(const [title,copy,href,label]of [['Around the realm','Explore the latest discussions and meet the organisations shaping the season.','https://forums.dunerealms.com/','Visit the forums →'],['Upcoming events','Event highlights will appear here when the portal event feed is connected.',null,null],['Community gallery','A place for player creations and stories. Gallery publishing is not connected yet.',null,null]]){
const section=el('section',undefined,'panel portal-community-card');section.append(el('h2',title),el('p',copy));if(href)section.append(link(label,href));else section.append(el('span','Preview · awaiting connection','portal-placeholder'));center.append(section);
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long