403Webshell
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 :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/burlakastudio.realcommenter/lib/VOTING.php
<?php
/**
 * ����� "��������� ����������� D7" ��� �������
 * �������� ���� �����: www.realcommenter.com
 * �������� ���� �����������: burlaka.studio
 * ����� � ����������: ������� ������� (AlexeyGfi) -> alexeygfi@gmail.com
 */

namespace Burlakastudio\Realcommenter;

require_once 'VOTING_TABLE.php';

class VOTING extends REALCOMMENTER_HL_GENERAL_PROVIDER
{

    /**
     * ��� ����� ��������, �� ������������ �� ���������� (������� � ����)
     *
     * ������� ����� ������������.
     * �� ��� �� �������������� ��������� true
     * � �������� �� �������� ���������� �� ������� � ����������
     * ������ ��������� ���-�� �������
     *
     * @param array $arParams
     * @param bool $user_id
     *
     * @return bool
     */
    public static function may_vote(&$arParams = [], $user_id = false)
    {

        if (!$user_id) {
            $user_id = USER::get_id();
        }

        if ($user_id && USER::in_restricted_status($user_id)) {
            return false;
        }

        if (!$user_id && !$arParams['USE_VOTES_FOR_ALL']) {
            return false;
        }


        return true;

    }

    public static function restricted_by_author(&$comment_info = 0, &$user_id = false)
    {
        if (empty($comment_info) || !$comment_info['UF_USER_ID']) {
            return false;
        }

        if (!$user_id) {
            $user_id = USER::get_id();

            if (!$user_id) {
                return false;
            }
        }

        return ($comment_info['UF_USER_ID'] == $user_id);

    }

    public static function voted_yet(&$comment_id = 0, &$user_id = false)
    {

        if (!$comment_id) {
            return false;
        }

        if (!$user_id) {
            $user_id = USER::get_id();
        }

        if (!$user_id) {
            /**
             * TODO: ��������������� - ������ �� ����, �� ��������� �� �� �� �����������
             */
            return false;
        }

        /**
         * �� ���� � ���������� - ������ ������������, �� ������ �� ��� ���������.
         * ��� ���� ���������� �����.
         *
         * �������� ����� �����, ����� ��������� ���������� � ���-�� ��������
         */
        $user_votes = self::get_user_votes($user_id);

        if (!empty($user_votes) && in_array($comment_id, $user_votes)) {
            return true;
        } else {
            return false;
        }

    }

    public static function get_user_votes(&$user_id = null)
    {

        $user_votes = [];

        if (!$user_id) {
            return $user_votes;
        }

        /**
         * �� ���� � ���������� - ������ ������������, �� ������ �� ��� ���������.
         * ��� ���� ���������� �����.
         *
         * �������� ����� �����, ����� ��������� ���������� � ���-�� ��������
         */
        $cache_obj = CACHE::getCacheObj();
        $cache_key = CACHE::get_user_key_for_voting($user_id);
        $cache_TTL = CACHE::getTtl();

        if ($cache_obj->initCache($cache_TTL, $cache_key, TOOLS::getModuleName())) {
            $user_votes = $cache_obj->getVars();
        } else {

            $hl_class = self::getDataClass();
            $user_votes = $hl_class::getList([
                'filter' => ['UF_USER_ID' => $user_id],
                'limit' => 1,
                'select' => [
                    new \Bitrix\Main\ORM\Fields\ExpressionField('COMMENTS_LIST', 'GROUP_CONCAT(UF_COMMENT_ID)')
                ],
            ])->fetchAll();

            if (!empty($user_votes)) {
                $user_votes = array_shift($user_votes);
                $user_votes = explode(',', $user_votes['COMMENTS_LIST']);
            }

            if ($cache_obj->startDataCache($cache_TTL, $cache_key)) {
                // ���� � ��
                $cache_obj->endDataCache($user_votes);
            }

        }

        return $user_votes;
    }

    /**
     * @param int $commentId
     * @param int $voteWeight
     * @param array $arParams
     *
     * @return bool
     * @throws \Exception
     */
    public static function voting(&$commentId = 0, &$voteWeight = 0, &$arParams = [])
    {

        if (!$commentId || !$voteWeight || !self::may_vote($arParams)) {
            return false;
        }

        if (!$commentId) {
            return false;
        }

        /**
         * ���� �����.
         * ����� ������������ ��� � ������ �������,
         * ...������ ���� ������ � ������� � �����������
         */

        EVENT::call('OnBeforeVoteAdd', [
            'comment_id' => &$commentId,
            'vote_weight' => &$voteWeight,
            'arParams' => &$arParams
        ]);

        /**
         * ���� ����� ������� ��������� ������, ����� ������ ������ ������� ������� ��� ������
         */
        if (!$voteWeight) {
            return false;
        }

        $userId = USER::get_id();

        $voteResult = self::add([
            'UF_COMMENT_ID' => $commentId,
            'UF_USER_ID' => $userId,
            'UF_VOTE' => $voteWeight > 0 ? 1 : -1
        ]);

        if (!$voteResult->isSuccess()) {
            throw new \Exception(implode(', ', $voteResult->getErrorMessages()));
        }

        // ����� � ���������� � ������ ����������
        $votes = self::vote_stat_recalc($commentId);

        EVENT::call('OnAfterVoteAdd', [
            'comment_id' => &$commentId,
            'votes' => &$votes,
            'user_id' => $userId,
            'arParams' => &$arParams
        ]);

        return true;

    }

    /**
     * @param int $comment_id
     *
     * @return array|bool
     */
    private static function vote_stat_recalc($comment_id = 0)
    {

        if (!$comment_id) {
            return false;
        }

        $comment_info = COMMENTS::getCommentInfo($comment_id);

        $votes_arr = self::getList_EX(
            [
                'UF_COMMENT_ID' => $comment_id
            ],
            [
                'UF_VOTE' => 'asc'
            ]
        );

        $votes = [
            'PLUS' => 0,
            'MINUS' => 0
        ];

        foreach ($votes_arr as $v) {
            $votes[($v['UF_VOTE'] > 0 ? 'PLUS' : 'MINUS')]++;
        }

        $update_fields = [];

        if ($votes['PLUS'] != $comment_info['UF_VOTES_PLUS']) {
            $update_fields['UF_VOTES_PLUS'] = $votes['PLUS'];
        }

        if ($votes['MINUS'] != $comment_info['UF_VOTES_MINUS']) {
            $update_fields['UF_VOTES_MINUS'] = $votes['MINUS'];
        }

        if (!empty($update_fields)) {
            COMMENTS::update($comment_id, $update_fields);
        }

        return $votes;

    }

    public static function get_vote_up_title()
    {
        return \Bitrix\Main\Localization\Loc::getMessage('VOTE_UP_TITLE');
    }

    public static function get_vote_down_title()
    {
        return \Bitrix\Main\Localization\Loc::getMessage('VOTE_DOWN_TITLE');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit