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/cvetdv.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\Context; use Bitrix\Main\Type\DateTime; class GRANT_AND_ACCESS extends REALCOMMENTER_HL_GENERAL_PROVIDER { public static function is_any_moder(&$arParams = [], $userId = null) { return self::is_admin($userId) || self::is_local_admin($arParams, $userId) /*|| self::isTheConversatioBrandManager($arParams, $userId)*/; } public static function is_admin($user_id = 0) { return USER::is_admin($user_id); } /** * ������� �����, ����: * - � ��������� ����������: * � USERS_ADD_MOD � ������ ����� ������������-����������� ��������� * TODO: - � ��������� �����, ������ ������������ �� ��������� ������� � ��������� * TODO: - �� ��������� ������� ��������� ��������� - �� ������� ��������� ������� * * @param array $arParams * @param int $user_id * * @return bool */ public static function is_local_admin(&$arParams = [], $user_id = 0) { $user_info = USER::get_info($user_id); if (empty($user_info)) { return false; } if ($arParams && !empty($arParams)) { // ��� ������������-������� ��������� �� ���������� ���������� $USERS_ADD_MOD = $arParams['USERS_ADD_MOD']; if (!empty($USERS_ADD_MOD)) { foreach ($USERS_ADD_MOD as &$id) { $id = (int)preg_replace('~[^0-9,]~', '', $id); } unset($id); if (in_array($user_info['ID'], $USERS_ADD_MOD)) { return true; } } } return false; } /** * ������� ���������, ����: * - � ��������� ����������: * � USERS_ADD_LIMIT_MOD � ������ ����� ������������-�����-���������� ��������� * TODO: - � ��������� �����, ������ ������������ �� ��������� ������� � ��������� * TODO: - �� ��������� ������� ��������� ��������� - �� ������� ��������� ������� * * @param array $arParams * @param int $userId * * @return bool */ public static function isTheConversationBrandManager(&$arParams = [], $userId = 0) { $userInfo = USER::get_info($userId); if (empty($userInfo)) { return false; } if (!empty($arParams)) { // ��� ������������ $usersAddLimitMod = $arParams['USERS_ADD_LIMIT_MOD']; if (!empty($usersAddLimitMod)) { foreach ($usersAddLimitMod as &$id) { $id = (int)preg_replace('~[^0-9,]~', '', $id); } unset($id); if (in_array($userInfo['ID'], $usersAddLimitMod)) { return true; } } } return false; } /** * ������ � �������������� (����) * � �� �����������, � �� ���� ��� � ��������� ���������� �������� ������������� ��������������� * � (?! ������ ������������� ������ ��������) * � ��������� ���������� ������ ����������� �����, � ���������� �� �������� �� � ����� �� �� * � ���� ��: * .. ����� ��������/ * .. ��������� ��������� ��������/ * .. ����� ������� (��� ���������� � ��������� ����������) * .. ��������� ������� (��� ���������� � ��������� ����������) * ...�: * - ���������� ���������� * - ���������� �� ������� * * @param array $arParams * * @return bool */ public static function may_comment(&$arParams = []) { if (self::is_any_moder($arParams)) { return true; } if (self::isTheConversationBrandManager($arParams)) { return true; } if (USER::in_restricted_status()) { return false; } if ( !TalkGroups::is_active($arParams['TALK_GROUP_ID']) || TalkGroups::is_paused($arParams['TALK_GROUP_ID']) ) { return false; } return true; } /** * ����� �� ����� ����� �� ������� ������������ * 1. ����� �� ����� == ������ ��� * 2. ����� �����, * - ���������� �� ����������� * - �������� ������������ == ??? * - �������� ������������ == ������� ��� * - ���������� ����������� * - ������� �� ������ == ������ ��� * - �� ������� �� ������ == ������� ��� * * @param array $arParams * @param bool $real_mode * * @return bool */ public static function restricted_by_auth_limit(&$arParams = [], $real_mode = true) { if (self::is_any_moder($arParams)) { return false; } if (self::isTheConversationBrandManager($arParams)) { return false; } if (!self::auth_limit($arParams)) { return false; } /** * �� ����������� � ��� ������, ������ ��� ��������� �������� */ if (!USER::get_id()) { // ���������� ���� if ($real_mode) { return !self::use_authorization($arParams); } /** * ���������� ���� * �������� ������������ - ������ ������ * �������� ������������ - ������ ������ */ return true; } /** * ���� � ��������� ����������: * � WHO_MAY_COMMENT � ������ ����� ������������, ������ �������� ������������� */ if (!empty($arParams['WHO_MAY_COMMENT'])) { $WHO_MAY_COMMENT = array_values( array_filter( array_unique($arParams['WHO_MAY_COMMENT']))); } else { $WHO_MAY_COMMENT = []; } $user_groups = USER::get_user_groups(); return !array_intersect($user_groups, $WHO_MAY_COMMENT); } public static function auth_limit(&$arParams = []) { return !empty($arParams['WHO_MAY_COMMENT']); } public static function use_authorization(&$arParams = []) { return $arParams['USE_AUTHORIZATION']; } /** * ����� �� ���������� ������� ����������� �� ��������� �����������, * � �����, ����� ����������� ������� � ������ ��������: * - ��������� * - �� ������� * - ������� ������������ * * @param int $comment_id * @param array $arParams * @param array $comment_info * * @return bool */ public static function have_access_by_special_case_of_comment(&$comment_id = 0, &$arParams = [], &$comment_info = []) { if (self::is_any_moder($arParams)) { return true; } if (self::isTheConversationBrandManager($arParams)) { return true; } if ( COMMENTS::in_special_case($comment_id, $arParams, $comment_info) || COMMENTS::frozen($comment_id, $comment_info) ) { return false; } /** * ������ �����. �� �������� ��� � ������� �� ������� */ if ($arParams['BRANCH_IN_SPECIAL_CASE']) { return false; } return true; } /** * ����� �� ������������ ����������� ��� ��� ����� * ... �������� "�������" ���������� * ... ��� ����, ������ �� ���������� ��� ������� * ... � � ��������� ����� � ��������� �� �������������� * * @param $userId * @param DateTime $UF_CREATED_DATE * * @return bool */ public static function may_edit_comment_like_author(&$userId, DateTime &$UF_CREATED_DATE) { if (!$userId || !$UF_CREATED_DATE) { return false; } if (USER::in_restricted_status()) { return false; } $allowed_time_in_minutes = intval(OPTIONS::get('time_for_edit')); if (!$allowed_time_in_minutes) { return false; } $user_id = USER::get_id(); if (!$user_id || $userId != $user_id) { return false; } $diff = TOOLS::get_date_diff($UF_CREATED_DATE); $allowed_diff_in_seconds = $allowed_time_in_minutes * 60; return ($diff <= $allowed_diff_in_seconds); } /** * ������ �� ������� �������������� (�������������, ...) * ... ��������� * * @param array $arParams * @param int $depthLevel * * @return bool */ public static function restrictedDepth(&$arParams = [], $depthLevel = 1) { if (self::is_any_moder($arParams)) { return false; } if (self::isTheConversationBrandManager($arParams)) { return false; } /** * !!! * ����� ������ � ����������������� ���. * �� �����, ��� ����� ������� ����������� ����� ����� ��/����� ���������, * ...�� ������ ��� ������������� ���� */ $depthLevel = (int)$depthLevel; return $arParams['MAX_DEPTH_FOR_USERS'] && $depthLevel >= $arParams['MAX_DEPTH_FOR_USERS']; } public static function is_use_text_editor() { $use_visual_for_user = OPTIONS::get('use_visual_editor'); if ($use_visual_for_user) { return true; } if (self::is_any_moder($arParams)) { return true; } if (self::isTheConversationBrandManager($arParams)) { return true; } return false; } public static function have_access_to_url(&$url_info = [], &$arParams = []) { if (!$url_info || !$arParams) { return false; } if (self::is_any_moder($arParams)) { return true; } if (!$url_info['UF_ACTIVE'] || $url_info['UF_PAUSED']) { return false; } return true; } /** * ��� ����� ����� ����� �� ���������� ������ * * @return bool */ public static function referer_granted_to_domain() { $site_domains = OPTIONS::getModuleDomains(); $referer = Context::getCurrent()->getServer()->get('HTTP_REFERER'); if (!$referer) { return false; } $referer_cleared = preg_replace('~https?://~', '', $referer); foreach ($site_domains as $s_domain) { if (preg_match('~^' . $s_domain . '/~', $referer_cleared)) { return true; } } return false; } }