<?php
 class vB_Api_Prefix extends vB_Api { public function fetch($nodeid, $permcheck = true) { if (!$nodeid) { return []; } $data = vB_Library::instance('prefix')->getPrefixData(); if (!isset($data['channelPrefixset'][$nodeid])) { return []; } if ($permcheck) { $userinfo = vB::getCurrentSession()->fetch_userinfo(); $userlib = vB_Library::instance('user'); $membergroups = $userlib->getMemberGroupsArray($userinfo); $infractiongroups = $userlib->getInfractionGroupArray($userinfo); } $result = []; foreach ($data['channelPrefixset'][$nodeid] AS $prefixSetId) { $result[$prefixSetId] = []; foreach ($data['prefixes'][$prefixSetId] AS $prefixid) { $restrictions = []; if (isset($data['restrictions'][$prefixid])) { $restrictions = $data['restrictions'][$prefixid]; } if (!$permcheck OR $this->canUseInternal($prefixid, $restrictions, $membergroups, $infractiongroups)) { $result[$prefixSetId][$prefixid] = [ 'prefixid' => $prefixid, 'restrictions' => $restrictions, ]; } } } return $result; } public function canUse($prefixid) { $library = vB_Library::instance('prefix'); if (!$library->prefixExists($prefixid)) { return ['canuse' => false]; } $userinfo = vB::getCurrentSession()->fetch_userinfo(); $userlib = vB_Library::instance('user'); $membergroups = $userlib->getMemberGroupsArray($userinfo); $infractiongroups = $userlib->getInfractionGroupArray($userinfo); $data = $library->getPrefixData(); $restrictions = []; if (isset($data['restrictions'][$prefixid])) { $restrictions = $data['restrictions'][$prefixid]; } $canuse = $this->canUseInternal($prefixid, $restrictions, $membergroups, $infractiongroups); return ['canuse' => $canuse]; } private function canUseInternal($prefixid, $restrictions, $membergroupids, $infractiongroupids) { if (empty($restrictions)) { return true; } foreach ($restrictions AS $usergroupid) { if (in_array($usergroupid, $infractiongroupids)) { return false; } } return (bool) count(array_diff($membergroupids, $restrictions)); } } 