add_hook('index_end','dune_sections_index'); $plugins->add_hook('pre_output_page','dune_sections_style'); function dune_sections_style($html){return str_replace('','',$html);} function dune_sections_info(){return ['name'=>'DuneRealms forum sections','description'=>'Category panels with native permission-aware forum rows and child links.','website'=>'https://www.dunerealms.com','author'=>'DuneRealms','version'=>'1.0.0','compatibility'=>'18*'];} function dune_sections_escape($text){return htmlspecialchars((string)$text,ENT_QUOTES,'UTF-8');} function dune_sections_visible($forum,$all){ foreach(explode(',',$forum['parentlist']??(string)$forum['fid'])as$id){ if(!isset($all[(int)$id])||empty($all[(int)$id]['active']))return false; $permissions=forum_permissions((int)$id); if(empty($permissions['canview'])||!forum_password_validated($all[(int)$id],true))return false; } return true; } function dune_sections_children($id,$all){ $children=array_filter($all,fn($f)=>(int)$f['pid']===$id&&dune_sections_visible($f,$all)); usort($children,fn($a,$b)=>((int)$a['disporder']<=>(int)$b['disporder'])?:((int)$a['fid']<=>(int)$b['fid'])); return $children; } function dune_sections_links($children){ return implode('',array_map(fn($f)=>''.dune_sections_escape($f['name']).'',$children)); } function dune_sections_index(){ global $cache,$mybb,$forums,$fcache,$db,$theme,$collapsed,$collapsedimg,$collapsedthead; if(empty($mybb->settings['dune_sections_enabled']))return; $all=$cache->read('forums');$roots=dune_sections_children(0,$all);$html=''; $systemRoot=0; if($db->table_exists('dune_system_boards')){$record=$db->fetch_array($db->simple_select('dune_system_boards','fid',"kind='system' AND organisation_id='root'"));$systemRoot=(int)($record['fid']??0);} foreach($roots as$root){ $panels=dune_sections_children((int)$root['fid'],$all);if(!$panels)$panels=[$root]; $system=(int)$root['fid']===$systemRoot;$key='cat_'.(int)$root['fid'];$toggle=''; if($system){$label=empty($collapsed[$key.'_e'])?'Collapse System Boards':'Expand System Boards';$toggle='
'.$label.'
';} $html.='
'.$toggle.'

COMMUNITY FORUMS

'.dune_sections_escape($root['name']).'

'; if($system)$html.='
'; $html.='
'; foreach($panels as$panel){ $children=dune_sections_children((int)$panel['fid'],$all); $html.='

'.dune_sections_escape($panel['name']).'

'.dune_sections_escape(strip_tags($panel['description'])).'

SUBCATEGORY
'; $previous=$mybb->settings['hideprivateforums'];$mybb->settings['hideprivateforums']=1; try{ if($children){$rows=build_forumbits((int)$panel['fid'],2);} elseif($panel['type']==='f'){ $copy=$panel;$copy['name']='Discussions';$copy['description']='';$virtual=-991; $before=$fcache[$virtual]??null;$fcache[$virtual]=[0=>[(int)$panel['fid']=>$copy]]; try{$rows=build_forumbits($virtual,2);}finally{if($before===null)unset($fcache[$virtual]);else $fcache[$virtual]=$before;} }else $rows=null; }finally{$mybb->settings['hideprivateforums']=$previous;} if($rows&&!empty($rows['forum_list']))$html.=''.$rows['forum_list'].'
ForumThreadsPostsLast post
'; else if($children)$html.='
Forums'.dune_sections_links($children).'
'; else $html.='

No visible forums in this section.

'; $html.='
'; } $html.='
'.($system?'
':'').'
'; } if($html)$forums=$html; }