Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/burlakastudio.realcommenter/lib/ |
Upload File : |
<?php /** * ����� "��������� ����������� D7" ��� ������� * �������� ���� �����: www.realcommenter.com * �������� ���� �����������: burlaka.studio * ����� � ����������: ������� ������� (AlexeyGfi) -> alexeygfi@gmail.com */ namespace Burlakastudio\Realcommenter; use Bitrix\Main\Entity\ReferenceField; class USER { const USER_NOT_FOUND = null; /** * ���������� � ���� * (???) ��� ����� ��������� ��� ���������� * ��������, ���� ��������� ���-�� ������ �� ����� ���������� * TODO: ���������� * * @param int $userId * * @return bool */ public static function in_restricted_status($userId = null) { $userId = $userId ?: self::get_id(); if (!$userId) { return false; } return Sanctions::restrictedUser($userId); } /** * @param int $user_id * * @return bool|null */ public static function is_admin($user_id = 0) { if ($user_id) { $user_info = self::get_info($user_id); if ( !empty($user_info['GROUPS']) && is_array($user_info['GROUPS']) && in_array(1, $user_info['GROUPS'], false) ) { return true; } return false; } global $USER; return $USER->IsAdmin(); } public static function get_id() { global $USER; if (!$USER->IsAuthorized()) { return 0; } return $USER->GetID(); } public static function get_user_groups() { global $USER; return $USER->GetUserGroupArray(); } /** * ������ ����� � �����������. * ���� ������ ��� ���������� - ������ ���. * ���� - ������ (���� �� �����������) * * ��������: * ��� ������� ��������������� ���������� ������� ������ � * $_SESSION[ 'SESS_AUTH' ] (!!! ����� ��� ID � ��� ���� � USER_ID) * * ��� ����� ����� ����� �� ��, ���� ��� ��� ������� * * �� ���: * - ���� ��� �������� ������������ ��� ���������� * - � ���������� ����������� (self::get_id() �� �������) * - � ��������� ��� ��������� � ������ - ������ ��� �� ������ * ...���� �� ��� - ������ �� �� * * @param int $userId * * @return array */ public static function get_info($userId = 0) { $authUserId = self::get_id(); if ( (!$userId && $authUserId) || ($userId && $userId == $authUserId) ) { $info = $_SESSION['SESS_AUTH']; $info['ID'] = $authUserId ?: $info['USER_ID']; /** * ��� ����������! * � ������ � ���� NAME ������� ��� ����������� ��. * * ���� �������������� ����� �� ������ � ��� ������������� ����� � ������ � �������, * ����� � ������� */ $info['FIRST_NAME'] = $info['LAST_NAME'] = $info['SECOND_NAME'] = ''; $info['UF_TAPER_SIGNATURE'] = \CUser::FormatName( \CSite::GetNameFormat(), $info, true, false ); } else if ($userId) { $info = []; $cacheObj = CACHE::getCacheObj(); $cacheKey = CACHE::get_user_key($userId); $cacheTtl = CACHE::getTtl(); if ($cacheObj->initCache($cacheTtl, $cacheKey, TOOLS::getModuleName())) { // ���� �� ��� $info = $cacheObj->getVars(); } else { /** * �� ����������� ������ � ������ ���� ������� ���� ����, ���� ������ * ��� ����� ������������, � ������ ������� user ����� �������� ������ � ��� ����� */ $rawInfo = \Bitrix\Main\UserTable::getList( [ 'filter' => [ 'ID' => $userId, ], 'select' => [ 'ID', 'EMAIL', 'LOGIN', 'PERSONAL_PHOTO', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'PERSONAL_COUNTRY', 'WORK_COUNTRY', 'USR_GROUPS' => 'GROUP.GROUP_ID', ], 'runtime' => [ new \Bitrix\Main\Entity\ReferenceField( 'GROUP', 'Bitrix\Main\UserGroupTable', ['=this.ID' => 'ref.USER_ID'], ['join_type' => 'LEFT'] ), ], ] )->fetchAll(); if (!empty($rawInfo)) { foreach ($rawInfo as $r) { if (empty($info)) { $info = $r; $info['GROUPS'] = []; } if ($r['ID'] == $info['ID']) { $info['GROUPS'][] = $r['USR_GROUPS']; } } $info['UF_TAPER_SIGNATURE'] = \CUser::FormatName( \CSite::GetNameFormat(), $info, true, false ); } if ($cacheObj->startDataCache($cacheTtl, $cacheKey)) { // ���� � �� $cacheObj->endDataCache($info); } } } else { return []; } return $info; } public static function get_email($user_id = '') { if (!$user_id) { return ''; } $user_info = self::get_info($user_id); if (!$user_info) { return ''; } return $user_info['EMAIL']; } public static function get_formatted_name($user_id = false) { $user_info = self::get_info($user_id); return $user_info['UF_TAPER_SIGNATURE']; } /** * ������� �������� ���������� �� ����������� �����, * � ����������� ������� �� ���������� ����� * * @param bool $user_id * * @return bool|string */ public static function get_avatar($user_id = false) { $user_info = self::get_info($user_id); if (!$user_info || !$user_info['PERSONAL_PHOTO']) { return ''; } $arSize = [ 'width' => OPTIONS::get('resize_avatar_width'), 'height' => OPTIONS::get('resize_avatar_height'), ]; $resize_result = \CFile::ResizeImageGet($user_info['PERSONAL_PHOTO'], $arSize); if (!$resize_result || !$resize_result['src']) { return false; } return $resize_result['src']; } /** * @param null $userId * @param int $limit -1 or positive number * @return array * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\SystemException */ public static function getCommentsByUser(&$userId = null, $limit = 10) { $comments = []; if (!$userId) { return $comments; } // ...� ����� $commentsReferences[] = new ReferenceField( 'URL', URL::getDataClass(), ['=this.UF_URL_ID' => 'ref.ID'] ); $filter = [ 'UF_USER_ID' => $userId ]; $order = [ 'UF_CREATED_DATE' => 'DESC' ]; $select = [ 'ID', 'UF_COMMENT', 'UF_COMMENTS_INSIDE', 'URL_NAME' => 'URL.UF_URL', ]; $params = [ 'filter' => $filter, 'order' => $order, 'runtime' => $commentsReferences, 'select' => $select ]; if ($limit > 0) { $params['limit'] = $limit; } $result = COMMENTS::getList($params); while ($arr = $result->fetch()) { PARSER::simplify($arr['UF_COMMENT']); PARSER::trimmer($arr['UF_COMMENT']); $comments[] = $arr; } return $comments; } public static function calculateCommentsByUser($userId = null) { return count(self::getCommentsByUser($userId, -1)); } }