MC/website/integrations/mybb/central-account-controls.php

36 lines
2.8 KiB
PHP

<?php
// DuneRealms adapter only: native forum content and preferences stay in MyBB.
function dune_central_account_identity($identity){return is_array($identity)&&($identity['nativePermissionManagement']??null)===false;}
function dune_central_account_target($identity,$script,$action=''){
if(!dune_central_account_identity($identity))return null;
$script=basename($script);$action=strtolower($action);
if($script==='private.php')return 'https://cp.dunerealms.com/#post/mail-inbox';
if($script==='usercp.php'){
if(in_array($action,['profile','do_profile','changename','do_changename','avatar','do_avatar','editsig','do_editsig'],true))return 'https://cp.dunerealms.com/#realm/site-profile';
if(in_array($action,['email','do_email','password','do_password'],true))return 'https://cp.dunerealms.com/#realm/security';
}
if($script==='member.php'){
if(in_array($action,['lostpw','do_lostpw','resetpassword','do_resetpassword'],true))return 'https://cp.dunerealms.com/#realm/security';
if(in_array($action,['emailuser','do_emailuser'],true))return 'https://cp.dunerealms.com/#post/mail-inbox';
}
return null;
}
function dune_central_account_permissions(){
if(empty($GLOBALS['dune_central_account_user']))return;
global $mybb;
foreach(['canusepms','cansendpms','cantrackpms','canchangename','canuploadavatars','caneditprofiles','cansendemail'] as $permission)$mybb->usergroup[$permission]=0;
}
function dune_central_account_menu(){
if(empty($GLOBALS['dune_central_account_user']))return;
global $templates;
$templates->cache['usercp_nav_profile']='<tbody><tr><td class="tcat"><strong>DuneRealms account</strong></td></tr></tbody><tbody><tr><td class="trow1"><a href="https://cp.dunerealms.com/#realm/site-profile">Manage profile &amp; identity</a></td></tr><tr><td class="trow1"><a href="https://cp.dunerealms.com/#realm/security">Account security</a></td></tr><tr><td class="trow1"><a href="https://cp.dunerealms.com/#post/mail-inbox">Imperial Post</a></td></tr></tbody>';
}
function dune_central_account_output($html){
if(empty($GLOBALS['dune_central_account_user']))return $html;
return preg_replace_callback('~<a\b([^>]*?)href=(["\x27])([^"\x27]+)\2([^>]*)>([\s\S]*?)</a>~i',static function($m){
$url=parse_url(html_entity_decode($m[3],ENT_QUOTES|ENT_HTML5,'UTF-8'));if(!$url||isset($url['host'])&&strtolower($url['host'])!=='forums.dunerealms.com')return $m[0];
$query=[];parse_str($url['query']??'',$query);$script=basename($url['path']??'');$target=dune_central_account_target(['nativePermissionManagement'=>false],$script,is_string($query['action']??null)?$query['action']:'');if(!$target)return $m[0];
$label=$script==='private.php'?'Imperial Post':(str_contains($target,'security')?'Account security':'Manage account');
return '<a'.$m[1].'href="'.htmlspecialchars($target,ENT_QUOTES,'UTF-8').'"'.$m[4].'>'.$label.'</a>';
},$html);
}