web/website/integrations/mybb/system-board-manage.php
2026-11-21 20:22:37 +01:00

45 lines
3.8 KiB
PHP

<?php
define('IN_MYBB', 1);
require __DIR__.'/global.php';
require_once __DIR__.'/system-board-membership.php';
require_once '/home/dunerealms/apps/integrations/bridge.php';
header('Cache-Control: private, no-store');
$identity = dune_bridge('identity', ['sessionRef'=>$_SESSION['dune_session_ref'] ?? '']);
if (!$identity || empty($mybb->user['uid'])) { http_response_code(403); exit('Sign in to manage your board.'); }
try { dune_apply_system_board_membership($identity); }
catch (Throwable $error) { http_response_code(503); exit('Board management is temporarily unavailable.'); }
$kind = $mybb->get_input('kind'); $id = $mybb->get_input('organisation');
$grant = null;
foreach ($identity['systemBoards']['organisations'] as $item) if ($item['kind']===$kind && $item['id']===$id && ($item['manage'] ?? false)===true) $grant=$item;
if (!$grant) { http_response_code(404); exit('Board management is not available to your account.'); }
$boards=dune_system_board_registry(); $board=$boards[$kind.':'.$id] ?? null;
if (!$board) { http_response_code(503); exit('This board has not been published yet.'); }
$root=(int)$board['fid']; $parents=[]; $forums=[];
$query=$db->simple_select('forums','*');
while ($row=$db->fetch_array($query)) { $parents[(int)$row['fid']]=(int)$row['pid']; $forums[(int)$row['fid']]=$row; }
$error='';
if ($mybb->request_method==='post') {
verify_post_check($mybb->get_input('my_post_key'));
$parent=$mybb->get_input('parent', MyBB::INPUT_INT); $name=trim($mybb->get_input('name')); $type=$mybb->get_input('forum_type');
if (!dune_board_descendant($parent,$root,$parents) || !isset($forums[$parent]) || empty($forums[$parent]['active'])) $error='Choose a parent inside your own board.';
elseif ($name==='' || mb_strlen($name)>70 || !in_array($type,['c','f'],true)) $error='Choose a name of up to 70 characters and a valid type.';
else {
$row=$forums[$parent]; unset($row['fid']);
foreach (['threads','posts','lastpost','lastposteruid','unapprovedthreads','unapprovedposts','deletedthreads','deletedposts'] as $key) if (array_key_exists($key,$row)) $row[$key]=0;
foreach (['lastposter','lastpostsubject','linkto','password','rules','rulestitle'] as $key) if (array_key_exists($key,$row)) $row[$key]='';
$row=array_merge($row,['name'=>htmlspecialchars($name,ENT_QUOTES|ENT_SUBSTITUTE,'UTF-8'),'description'=>'','pid'=>$parent,'type'=>$type,'parentlist'=>'','disporder'=>1000,'active'=>0,'open'=>1,'allowhtml'=>0]);
foreach ($row as $key=>$value) if (is_string($value)) $row[$key]=$db->escape_string($value);
$fid=(int)$db->insert_query('forums',$row);
$db->update_query('forums',['parentlist'=>$db->escape_string($forums[$parent]['parentlist'].','.$fid),'active'=>1],'fid='.$fid);
// No explicit child grants: MyBB inherits the protected ancestor's
// permissions and local moderators. There is no organisation quota.
$cache->update_forums(); $cache->update_forumpermissions();
log_moderator_action(['fid'=>$fid], 'Created organisation child board');
header('Location: /forumdisplay.php?fid='.$fid.'&dune_embed=1',true,303); exit;
}
}
require_once __DIR__.'/system-board-manage-view.php';
require_once __DIR__.'/system-board-embed.php';
$allowedParents=array_values(array_filter($forums,fn($forum)=>!empty($forum['active'])&&dune_board_descendant((int)$forum['fid'],$root,$parents)));
$html=dune_render_board_management(['kind'=>$kind,'organisation'=>$id,'root'=>$root,'parents'=>$allowedParents,'postKey'=>$mybb->post_code,'parent'=>$mybb->request_method==='post'?$mybb->get_input('parent',MyBB::INPUT_INT):$root,'name'=>$mybb->request_method==='post'?$mybb->get_input('name'):'','type'=>$mybb->request_method==='post'?$mybb->get_input('forum_type'):'f','error'=>$error]);
$_GET['dune_embed']='1';dune_system_board_embed($html);echo $html;