forked from unimatrix/web
25 lines
3.3 KiB
PHP
25 lines
3.3 KiB
PHP
<?php
|
|
function dune_system_board_embed(&$page): void {
|
|
global $db;
|
|
if (basename($_SERVER['SCRIPT_NAME'] ?? '')==='index.php' && $db->table_exists('dune_system_boards')) {
|
|
$root=$db->fetch_array($db->simple_select('dune_system_boards','fid',"kind='system' AND organisation_id='root'"));
|
|
$fid=(int)($root['fid'] ?? 0);
|
|
if ($fid>0) $page=str_replace('</body>','<script>(()=>{const key="system-boards-expanded",body=document.getElementById("cat_'.$fid.'_e"),button=document.getElementById("cat_'.$fid.'_img");if(!body||!button)return;try{if(localStorage.getItem(key)!=="1"){body.style.display="none";button.src=button.src.replace("collapse.png","collapse_collapsed.png");button.alt="+";}button.addEventListener("click",()=>setTimeout(()=>localStorage.setItem(key,body.style.display==="none"?"0":"1"),0));}catch{}})();</script></body>',$page);
|
|
}
|
|
if (($_GET['dune_embed'] ?? '') !== '1') return;
|
|
$fid=(int)($_GET['fid'] ?? 0); $identity=$GLOBALS['dune_system_board_identity'] ?? [];
|
|
$boards=dune_system_board_registry(); $parents=[];
|
|
$query=$db->simple_select('forums','fid,pid'); while($row=$db->fetch_array($query))$parents[(int)$row['fid']]=(int)$row['pid'];
|
|
foreach($identity['systemBoards']['organisations'] ?? [] as $grant){
|
|
$board=$boards[($grant['kind'] ?? '').':'.($grant['id'] ?? '')] ?? null;
|
|
if(!$board||($grant['manage'] ?? false)!==true||!dune_board_descendant($fid,(int)$board['fid'],$parents))continue;
|
|
$href='/system-board-manage.php?kind='.rawurlencode($grant['kind']).'&organisation='.rawurlencode($grant['id']).'&dune_embed=1';
|
|
$page=preg_replace('/(<body\b[^>]*>)/i','$1<div class="system-board-tools"><a href="'.$href.'">Manage board · Add forum or category</a></div>',$page,1);
|
|
}
|
|
$style = '<style>html,body{min-height:0!important;height:auto!important}#header,#footer,.navigation,.breadcrumb,.dune-shared-header,.dune-shared-footer{display:none!important}#container,#content{width:auto!important;max-width:none!important;margin:0!important;padding:14px!important}.system-board-tools{margin:12px 0}</style>';
|
|
$script = <<<'JS'
|
|
<script>(()=>{const parents=new Set(['https://cp.dunerealms.com','https://clans.dunerealms.com','https://corp.dunerealms.com','https://pol.dunerealms.com']);const send=()=>{const height=Math.ceil(Math.max(document.body.scrollHeight,document.body.getBoundingClientRect().height))+16;if(parent!==window&&height>=100&&height<=200000)for(const origin of parents)parent.postMessage({type:'dune-embed-size',height},origin);};for(const a of document.querySelectorAll('a[href]')){try{const u=new URL(a.href);if(u.origin===location.origin&&!u.pathname.startsWith('/admin/')&&!u.pathname.endsWith('dune-sso.php')){u.searchParams.set('dune_embed','1');a.href=u.href;}}catch{}}for(const f of document.forms){const input=document.createElement('input');input.type='hidden';input.name='dune_embed';input.value='1';f.append(input);try{const u=new URL(f.action);if(u.origin===location.origin){u.searchParams.set('dune_embed','1');f.action=u.href;}}catch{}}window.addEventListener('message',e=>{if(e.source===parent&&parents.has(e.origin)&&e.data?.type==='dune-embed-measure')send();});new ResizeObserver(send).observe(document.body);send();})();</script>
|
|
JS;
|
|
$page = str_replace('</head>', $style.'</head>', $page);
|
|
$page = str_replace('</body>', $script.'</body>', $page);
|
|
}
|

Staff