Beispiel #1
0
 /**
  * @param $documentType
  * @param bool $withExtended
  * @return array|bool
  */
 public function GetAllowableUserGroups($documentType, $withExtended = false)
 {
     $documentType = trim($documentType);
     if (strlen($documentType) <= 0) {
         return false;
     }
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     $result = array("Author" => GetMessage("IBD_DOCUMENT_AUTHOR"));
     $groupsId = array(1);
     $extendedGroupsCode = array();
     if (CIBlock::getArrayByID($iblockId, "RIGHTS_MODE") === "E") {
         $rights = new CIBlockRights($iblockId);
         foreach ($rights->getGroups() as $iblockGroupCode) {
             if (preg_match("/^G(\\d+)\$/", $iblockGroupCode, $match)) {
                 $groupsId[] = $match[1];
             } else {
                 $extendedGroupsCode[] = $iblockGroupCode;
             }
         }
     } else {
         foreach (CIBlock::getGroupPermissions($iblockId) as $groupId => $perm) {
             if ($perm > "R") {
                 $groupsId[] = $groupId;
             }
         }
     }
     $groupsIterator = CGroup::getListEx(array("NAME" => "ASC"), array("ID" => $groupsId));
     while ($group = $groupsIterator->fetch()) {
         $result[$group["ID"]] = $group["NAME"];
     }
     if ($withExtended && $extendedGroupsCode) {
         foreach ($extendedGroupsCode as $groupCode) {
             $result['group_' . $groupCode] = CBPHelper::getExtendedGroupName($groupCode);
         }
     }
     return $result;
 }
Beispiel #2
0
 public static function parseStringParameterMatches($matches, $documentType = null)
 {
     $result = "";
     $documentType = is_array($documentType) ? array_filter($documentType) : null;
     if ($matches[1] == "user") {
         $user = $matches[2];
         $l = strlen("user_");
         if (substr($user, 0, $l) == "user_") {
             $result = CBPHelper::ConvertUserToPrintableForm(intval(substr($user, $l)));
         } elseif (strpos($user, 'group_') === 0) {
             $result = htmlspecialcharsbx(CBPHelper::getExtendedGroupName($user));
         } elseif ($documentType) {
             $v = implode(",", $documentType);
             if (!array_key_exists($v, self::$userGroupsCache)) {
                 self::$userGroupsCache[$v] = CBPDocument::GetAllowableUserGroups($documentType);
             }
             $result = self::$userGroupsCache[$v][$user];
         } else {
             $result = $user;
         }
     } elseif ($matches[1] == "group") {
         if (strpos($matches[2], 'group_') === 0) {
             $result = htmlspecialcharsbx(CBPHelper::getExtendedGroupName($matches[2]));
         } elseif ($documentType) {
             $v = implode(",", $documentType);
             if (!array_key_exists($v, self::$userGroupsCache)) {
                 self::$userGroupsCache[$v] = CBPDocument::GetAllowableUserGroups($documentType);
             }
             $result = self::$userGroupsCache[$v][$matches[2]];
         } else {
             $result = $matches[2];
         }
     } else {
         $result = $matches[0];
     }
     return $result;
 }