Merge pull request 'Fix Alpha application submission' (#8) from dev/MC:dev/alpha-intake-submit into checkpoint/alpha-1.0.0.3

Reviewed-on: unimatrix/MC#8
This commit is contained in:
Unimatrix 2026-11-03 21:28:13 +01:00
commit 2f90a4ab30
5 changed files with 83 additions and 1 deletions

View file

@ -16,7 +16,7 @@ function dune_shared_header($html) {
$html=preg_replace('~https://www\.dunerealms\.com/portal-navigation\.(js|css)(?:\?[^\"\s>]*)?~','/dune-navigation.$1?v=shared-20261102',$html);
if(($_SERVER['HTTP_HOST']??'')==='support.dunerealms.com'&&!str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))$html=str_ireplace('</head>','<script src="/dune-appeal-routing.js" defer></script></head>',$html);
if(($_SERVER['HTTP_HOST']??'')==='support.dunerealms.com'){
$html=str_ireplace('</head>','<link rel="stylesheet" href="/dune-osticket-theme.css?v=20261102-theme"></head>',$html);
$html=str_ireplace('</head>','<link rel="stylesheet" href="/dune-osticket-theme.css?v=20261103-alpha"></head>',$html);
$html=str_ireplace('</head>','<link rel="stylesheet" href="/dune-ticket-compose.css?v=4"><script src="/dune-ticket-compose.js?v=4" defer></script></head>',$html);
$html=str_ireplace('</head>','<link rel="stylesheet" href="/dune-support.css?v=signature-4"></head>',$html);
$html=preg_replace('/<body\b(?![^>]*\bclass=)/i','<body class="dune-support"',$html,1);
@ -37,3 +37,4 @@ function dune_shared_header($html) {
require_once __DIR__.'/native-seo.php';
return dune_native_seo($html);
}

View file

@ -0,0 +1,15 @@
<?php
class Topic {static function lookup($id){return $id===18?new self:null;}function getName(){return 'Alpha Tester Signup';}function getForms(){return [new Definition];}}
class Definition {function getForm($source=false){return new Application;}}
class Application {function getFields(){return [new Field('alpha_minecraft'),new Field('alpha_platform')];}}
class Field {static $epoch='new'; function __construct(public $name){}function get($key){return $this->name;}function getFormName(){return self::$epoch.'_'.$this->name;}function getFormNames(){return [$this->getFormName(),$this->name];}}
class TicketForm {static function objects(){return new self;}function one(){return $this;}function getForm($source=false){return $this;}function getField($name){return new Field($name);}}
require __DIR__.'/alpha-intake.php';
$count=0;function check($value){global $count;if(!$value)throw new Exception('Assertion failed '.($count+1));$count++;}
$_SESSION=['dune_alpha_field_maps'=>[['alpha_minecraft'=>'old_alpha_minecraft','alpha_platform'=>'old_alpha_platform']]];
$_SERVER['REQUEST_METHOD']='POST';$_POST=['topicId'=>18,'old_alpha_minecraft'=>'Test','old_alpha_platform'=>['pc'],'subject'=>'forged','message'=>'forged','other'=>'keep'];
dune_alpha_intake(18);ob_end_clean();
check($_POST['new_subject']==='Alpha tester application');check($_POST['subject']===$_POST['new_subject']);check(str_contains($_POST['new_message'],'structured application'));check($_POST['other']==='keep');check($_POST['new_alpha_minecraft']==='Test');check($_POST['new_alpha_platform']===['pc']);
$before=$_POST;dune_alpha_intake(1);check($_POST===$before);
$_SERVER['REQUEST_METHOD']='GET';ob_start();dune_alpha_intake(18);echo '<html><body></body></html>';ob_end_flush();$html=ob_get_clean();check(str_contains($html,'new_subject'));check(str_contains($html,'row.hidden=alpha'));check(str_contains($html,'MutationObserver'));check(str_contains($html,'field.disabled=alpha'));check(str_contains($html,'header.hidden=alpha'));
echo "$count Alpha intake checks passed\n";

View file

@ -0,0 +1,52 @@
<?php
// Alpha intake uses its structured answers, not a second issue form.
function dune_alpha_intake($topicId) {
$topic = Topic::lookup((int)$topicId);
if (!$topic || $topic->getName() !== 'Alpha Tester Signup') return;
// Preserve server-issued field names across native session rotation.
$applicationFields=[];
foreach ($topic->getForms() as $definition) {
foreach ($definition->getForm()->getFields() as $field) {
if (str_starts_with((string)$field->get('name'),'alpha_')) $applicationFields[]=$field;
}
}
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
foreach ($applicationFields as $field) {
$logical=$field->get('name');
foreach ($_SESSION['dune_alpha_field_maps'] ?? [] as $mapping) {
$old=$mapping[$logical] ?? '';
if ($old && array_key_exists($old,$_POST)) {
$_POST[$field->getFormName()]=$_POST[$old];
$_POST[$logical]=$_POST[$old];
break;
}
}
}
}
$mapping=[];
foreach ($applicationFields as $field) $mapping[$field->get('name')]=$field->getFormName();
$_SESSION['dune_alpha_field_maps'][]=$mapping;
$_SESSION['dune_alpha_field_maps']=array_slice($_SESSION['dune_alpha_field_maps'],-5);
$form = TicketForm::objects()->one()->getForm();
$values = ['subject'=>'Alpha tester application', 'message'=>'Alpha tester application submitted using the structured application form. Please review the application answers attached to this ticket.'];
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
foreach ($values as $name=>$value) {
foreach ($form->getField($name)->getFormNames() as $key) $_POST[$key]=$value;
}
}
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
foreach ($topic->getForms() as $definition) $definition->getForm($_POST);
TicketForm::objects()->one()->getForm($_POST);
}
$names=[];
foreach ($values as $name=>$value) $names[]=$form->getField($name)->getFormName();
$config=json_encode(['topic'=>(int)$topicId,'fields'=>$names], JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_QUOT);
ob_start(function($html)use($config){
if (!str_contains($html,'</body>')) return $html;
$script='<script>(()=>{const c='.$config.';const sync=()=>{const alpha=Number(document.getElementById("topicId")?.value)===c.topic;for(const name of c.fields){const field=document.getElementsByName(name)[0];if(!field)continue;const row=field.closest("tr");if(row){row.hidden=alpha;const header=row.previousElementSibling;if(header?.querySelector(".form-header"))header.hidden=alpha;}field.disabled=alpha;}};document.addEventListener("DOMContentLoaded",()=>{sync();document.getElementById("topicId")?.addEventListener("change",sync);const root=document.getElementById("dynamic-form");if(root)new MutationObserver(sync).observe(root,{childList:true,subtree:true});});})();</script>';
return str_replace('</body>',$script.'</body>',$html);
});
}

View file

@ -22,3 +22,6 @@ body.dune-support :is(.tabs,.nav-tabs){border-radius:9px 9px 0 0!important}body.
@media(max-width:650px){body.dune-support #landing_page{display:flex!important;flex-direction:column;gap:20px}body.dune-support #landing_page :is(.main-content,.pull-right.flush-right){float:none!important;width:100%!important;max-width:100%!important;min-width:0!important;box-sizing:border-box}}
.dune-alpha-invitation{display:flex;align-items:center;gap:24px;border:1px solid #9f874d;border-radius:14px;padding:22px;margin-bottom:24px;background:linear-gradient(135deg,#203d2f,#10271f);clear:both}.dune-alpha-invitation>img{width:180px;height:120px;object-fit:cover;border-radius:9px}.dune-alpha-invitation h2{margin:4px 0 10px!important}.dune-alpha-invitation p{margin:8px 0!important}.dune-alpha-invitation .eyebrow{font-size:10px;color:#d0b675;letter-spacing:.14em}@media(max-width:650px){.dune-alpha-invitation{flex-direction:column;align-items:flex-start}.dune-alpha-invitation>img{width:100%;height:140px}}
/* Readable structured application answers. */
body.dune-support table.custom-data th{background:#203e31!important;color:#e7ce91!important;font-weight:600;text-align:left;vertical-align:top;border-color:#3b5c4b!important}body.dune-support table.custom-data td{background:#153328!important;color:#eee6cd!important;vertical-align:top;border-color:#3b5c4b!important}

View file

@ -0,0 +1,11 @@
<?php
// CLI-only, repeatable native entry-point integration. No core validation removed.
if(PHP_SAPI!=='cli')exit(1);
$path=__DIR__.'/open.php';
$text=file_get_contents($path);
$anchor="require('client.inc.php');";
$hook="\nrequire_once __DIR__.'/alpha-intake.php';\ndune_alpha_intake(\$_POST['topicId'] ?? \$_GET['topicId'] ?? 0);";
if(str_contains($text,"dune_alpha_intake(")){echo "Already installed\n";exit;}
if(substr_count($text,$anchor)!==1)throw new RuntimeException('Unexpected native entry point');
file_put_contents($path,str_replace($anchor,$anchor.$hook,$text));
echo "Installed Alpha intake integration\n";