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/Burn.php
<?php
/**
 * ����� "��������� ����������� D7" ��� �������
 * �������� ���� �����: www.realcommenter.com
 * �������� ���� �����������: burlaka.studio
 * ����� � ����������: ������� ������� (AlexeyGfi) -> alexeygfi@gmail.com
 */

namespace Burlakastudio\Realcommenter;

use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Type\DateTime;
use CFile;

class Burn
{

    public static function burnTalkHeader(&$containerInfo = [], $arParams = [])
    {
        $talkHeaderTemplate = HTML_TEMPLATER::get('talk_header', $arParams);
        $talkHeaderTitle = ($arParams['lang_commentr_tree_title']) ?: Loc::getMessage('REALCOMMENTER_TPL_COMMENTS_TITLE');

        $replace_with = [
            '#TITLE#' => $talkHeaderTitle,
            '#CNT#' => $containerInfo['UF_COMMENTS_INSIDE']
                ? '<ins>' . $containerInfo['UF_COMMENTS_INSIDE'] . '</ins>'
                : ''
        ];

        return str_replace(
            array_keys($replace_with),
            array_values($replace_with),
            $talkHeaderTemplate
        );
    }

    public static function burnSortAndFilterEmptyResult(&$arParams = [])
    {
        $template = HTML_TEMPLATER::get('sort_and_filter_empty_result', $arParams);
        $message = $arParams['SORT_FILTER_RESULT_EMPTY_MESSAGE'] ?: '';

        $replace_with = [
            '#MSG#' => $message,
        ];

        return str_replace(
            array_keys($replace_with),
            array_values($replace_with),
            $template
        );
    }

    /**
     * ������ $node_info:
     *
     * [INFO] => Array
     * (
     * [ID] => 2
     * [UF_ACTIVE] => 1
     * [UF_COMMENT] => werwerwerwerwer
     * [UF_SIGNATURE] =>
     * [UF_EMAIL] =>
     * [UF_UPLOADS] => a:0:{}
     * [UF_USER_ID] => 1
     * [UF_VOTES_PLUS] =>
     * [UF_VOTES_MINUS] =>
     * [UF_FROZEN] => 0
     * [UF_UFO] => 0
     * [UF_SMILES_ACTIVE] => 0
     * [UF_RATE_VALUE] =>
     * [UF_PROOF_AWAITING] => 0
     * [UF_URL_ID] => 2
     * [UF_PARENT_ID] =>
     * [UF_DEPTH_LEVEL] => 1
     * [UF_CREATED_DATE] => Bitrix\Main\Type\DateTime Object (
     * [value:protected] => DateTime Object (
     * [date] => 2018-12-13 14:31:00.000000
     * [timezone_type] => 3
     * [timezone] => Europe/Moscow
     * )
     * )
     *
     * [COMM_STAT] => 7
     * )
     *
     * @param array $nodeInfo
     * @param array $arParams
     *
     * @return string
     */
    public static function burnCommentHeader(&$nodeInfo = [], &$arParams = [])
    {

        if (empty($nodeInfo)) {
            return '';
        }

        $userCssStatuses = [];
        if (USER::in_restricted_status($nodeInfo['UF_USER_ID'])) {
            $userCssStatuses[] = '_blocked';
        }

        if ($arParams['SHOW_MODERATOR_STATUS'] && $nodeInfo['UF_USER_ID']) {
            if (
                USER::is_admin($nodeInfo['UF_USER_ID'])
                || GRANT_AND_ACCESS::is_local_admin($arParams, $nodeInfo['UF_USER_ID'])
            ) {
                $userCssStatuses[] = '_admin';
            }

            if (
            GRANT_AND_ACCESS::isTheConversationBrandManager(
                $arParams,
                $nodeInfo['UF_USER_ID']
            )
            ) {
                $userCssStatuses[] = '_brand';
            }
        }

        $signatureDataAttributes = [];
        $signatureTitle = '';

        if (Sanctions::userHaveBan($nodeInfo['UF_USER_ID'])) {
            $userCssStatuses[] = '_have_ban';
            $signatureTitle = Loc::getMessage('USER_IN_BAN');
        } else {
            $userWarnings = Sanctions::getWarningsCount($nodeInfo['UF_USER_ID']);
            if ($userWarnings) {
                $userCssStatuses[] = '_have_warnings';
                $signatureDataAttributes[] = "data-warnings='{$userWarnings}'";
                $signatureTitle = Loc::getMessage('USER_HAS_WARNINGS');
            }
        }

        $timeStr = self::burn_comment_time($nodeInfo['UF_CREATED_DATE'], $arParams);

        $commentHeaderTpl = HTML_TEMPLATER::get('comment_header', $arParams);

        /**
         * ���� � ��� � ��������� ���������� ������ ���������� �����
         */
        if ($arParams['SHOW_COMMENT_LINKS']) {

//            if ($arParams['CLOSE_COMMENT_LINKS_IN_NOINDEX']) {
//                $commentHeaderTpl = str_replace(
//                    '#COMMENT_A_TAG#',
//                    '<noindex>#COMMENT_A_TAG#</noindex>',
//                    $commentHeaderTpl
//                );
//            }

            $commentHeaderTpl = str_replace(
                '#COMMENT_A_TAG#',
                HTML_TEMPLATER::get('comment_header_a_tag', $arParams),
                $commentHeaderTpl
            );
        }

        $search = [
            '#IMG#' => self::burn_commenter_avatar($nodeInfo['UF_USER_ID'], $arParams),
            '#CSS_STATUS#' => implode(' ', $userCssStatuses),
            '#SIGNATURE#' => self::burn_comment_signature($nodeInfo, $arParams),
            '#TIME#' => $arParams['HIDE_TIME_IN_DATA_ATTRIBUTE'] ? '' : $timeStr,
            '#TIME_IN_DATA_ATTRIBUTE#' => $arParams['HIDE_TIME_IN_DATA_ATTRIBUTE'] ? 'data-time="' . $timeStr . '"' : '',
            '#ID#' => $nodeInfo['ID'],
            '#CLEARED_URL#' => $arParams['URL'],
            '#?&#' => strpos($arParams['URL'], '?') ? '&' : '?',
//            '#REL_NO_FOLLOW#' => $arParams['CLOSE_COMMENT_LINKS_IN_NOINDEX'] ? "rel='nofollow'" : '',
            '#REL_NO_FOLLOW#' => '',
            '#SIGNATURE_DATA_ATTRIBUTE#' => implode(' ', $signatureDataAttributes),
            '#SIGNATURE_TITLE#' => $signatureTitle ? "title='{$signatureTitle}'" : '',
            '#COMMENT_A_TAG#' => '', // ��������� ������
        ];


        if ($arParams['SHOW_USER_LINK']) {
            $user_personal_link = self::get_user_personal_link($nodeInfo['UF_USER_ID']);

            if ($user_personal_link) {
                $commentHeaderTpl = str_replace(
                    '#SIGNATURE#',
                    sprintf('<a href="%s">#SIGNATURE#</a>', $user_personal_link),
                    $commentHeaderTpl
                );
            }
        }

        EVENT::call('OnBeforeCommentHeaderBurn', [
            'commentHeaderTpl' => &$commentHeaderTpl,
            'keyValuesForReplace' => &$search,
            'arParams' => $arParams,
            'nodeInfo' => &$nodeInfo
        ]);

        return str_replace(array_keys($search), array_values($search), $commentHeaderTpl);

    }

    /**
     * ��������� ������ ������� ������� ���������, ����������� ������� �������
     *
     * @param DateTime $ufCreatedDate
     * @param array $arParams
     *
     * @return string
     */
    public static function burn_comment_time(DateTime &$ufCreatedDate, &$arParams = [])
    {

        if (!$ufCreatedDate || (!$arParams['SHOW_DATE'] && !$arParams['SHOW_TIME'])) {
            return '';
        }

        $timestamp = $ufCreatedDate->getTimestamp();
        $diff = TOOLS::get_date_diff($ufCreatedDate);

        list($seconds, $cminute, $chour, $mday, $wday, $mon, $year, $yday, $weekday, $month, $timestamp) =
            array_values(getdate($timestamp));

        $cminute = sprintf('%02d', $cminute);
        $chour = sprintf('%02d', $chour);
        $mday = sprintf('%02d', $mday);
        $mon = sprintf('%02d', $mon);

        $datetimeString = '';

        if ($diff < 60 * 60 * 24) {
            /*
            4 ������� ���������:

            ������� �����
            30 ������ �����
            59 ������ �����

            ������ �����
            20 ����� �����
            48 ����� �����
            53 ����� �����
            59 ����� �����

            ��� �����, � 19:10
            2 ���� �����, � 21:13
            3 ���� �����, � 22:11

            ����, 15:40
            */
            if ($diff == 0) {
                $diff = 1;
            }

            if ($diff && $diff <= 59) {

                $seconds_lang = TOOLS::num_lang($diff);
                $datetimeString =
                    (($diff > 1) ? $diff . ' ' : '')
                    . Loc::getMessage('ITAPE_TIME_' . $seconds_lang . 'SECOND') . ' '
                    . Loc::getMessage('ITAPE_TIME_AGO');

            } else if ($diff > 59 && $diff <= 60 * 59) {

                $diff_minutes = floor($diff / 60);
                $minutes_lang = TOOLS::num_lang($diff_minutes);
                $datetimeString =
                    (($diff_minutes > 1) ? $diff_minutes . ' ' : '')
                    . Loc::getMessage('ITAPE_TIME_' . $minutes_lang . 'MINUTES') . ' '
                    . Loc::getMessage('ITAPE_TIME_AGO');

            } else if ($diff > 60 * 59 && $diff < 60 * 60 * 3) {

                $diff_hours = floor($diff / (60 * 60));
                $hours_lang = TOOLS::num_lang($diff_hours);
                $datetimeString = (($diff_hours > 1) ? $diff_hours . ' ' : '')
                    . Loc::getMessage('ITAPE_TIME_' . $hours_lang . 'HOURS') . ' '
                    . Loc::getMessage('ITAPE_TIME_AGO')
                    . Loc::getMessage('ITAPE_TIME_PREFFIX') . $chour . ':' . $cminute;

            } else {
                //����� ����, ��� ����� - "������" ��� "����"
                $now_day = date('d');

                if ((int)$now_day != (int)$mday) {
                    //����
                    $datetimeString =
                        Loc::getMessage('ITAPE_TIME_YESTERDAY')
                        . Loc::getMessage('ITAPE_TIME_PREFFIX') . $chour . ':' . $cminute;
                } else {
                    //������
                    $datetimeString =
                        Loc::getMessage('ITAPE_TIME_TODAY')
                        . Loc::getMessage('ITAPE_TIME_PREFFIX') . $chour . ':' . $cminute;
                }

            }
        } else {

            if ($arParams['SHOW_DATE']) {
                $datetimeString .= TOOLS::format_date($mday . '.' . $mon . '.' . $year, $arParams);
            }

            if ($arParams['SHOW_TIME']) {

                if ($arParams['SHOW_DATE']) {
                    $datetimeString .= Loc::getMessage('ITAPE_TIME_PREFFIX');
                }

                $datetimeString .= $chour . ':' . $cminute;
            }

        }

        return $datetimeString;
    }

    /**
     * ������ ����������.
     *
     * ���� ������ ��� ���������� - ������ �� ������.
     * ���� ����� �� �������� ������� - ��������� �������� ������
     * !!! �������� ������ ���� � css::empty, �� ��� ��������� �������� ����� ������
     *
     * @param integer $UF_USER_ID
     * @param array $arParams
     *
     * @return string
     */
    public static function burn_commenter_avatar(&$UF_USER_ID, &$arParams = [])
    {

        $user_image_path = '';

        if ($UF_USER_ID) {
            $user_image_path = USER::get_avatar($UF_USER_ID);
        }

        if ($user_image_path) {

//            $image_schemed = SCHEMA_ORG::mark_person_author_image($arParams);
            return '<abbr><img src="' . $user_image_path . '" alt="#SIGNATURE#"></abbr>';

        } elseif ($arParams['SHOW_ANONYM_PICTORGAMM']) {
            return '<abbr></abbr>';
        }

        return '';

    }

    /**
     * ��������� ������.
     * �� �����������:
     *      - ������, �������� ���� � ����������
     *      - ������ ����������, ���� ��� ��� USER_ID
     *      - ������� ���� "������"
     *
     * @param array $node_info
     * @param array $arParams
     *
     * @return mixed|string
     */
    public static function burn_comment_signature(&$node_info = [], &$arParams = [])
    {

        if ($node_info['UF_SIGNATURE']) {
            return $node_info['UF_SIGNATURE'];
        }

        $signature = '';

        if ($node_info['UF_USER_ID']) {
            $signature = USER::get_formatted_name($node_info['UF_USER_ID']);
        }

        if (!$signature) {
            $signature = Loc::getMessage('ITAPE_ANONYM_SIGNATURE');
        }

        return $signature;
    }

    public static function get_user_personal_link(&$user_id = 0, &$user_info = [])
    {

        $user_path_template = OPTIONS::get('user_path_template');

        if ($user_id) {
            if (!$user_info) {
                $user_info = USER::get_info($user_id);

                if (empty($user_info)) {
                    return '';
                }

                $user_path_template = str_replace([
                    '#USER_ID#',
                    '#USER_LOGIN#'
                ], [
                    $user_info['ID'],
                    $user_info['LOGIN']
                ], $user_path_template);

                return $user_path_template;
            }
        }

        return '';

    }

    /**
     * ���� � ����������� � �������� ���������
     *
     * @param array $nodeInfo
     * @param array $arParams
     *
     * @return string
     */
    public static function burnCommentAside(&$nodeInfo = [], &$arParams = [])
    {

        if (empty($nodeInfo)) {
            return '';
        }

        /**
         * ���� � ������������.
         * ������� �������:
         *      - ����������� ������� � �����
         *      - ����������� ������, �� ���������� �� ����� ���������:
         *          - ��� ������������
         *          - �������� ���������
         *      - ����������� ������,
         *          �� ����-�� �� ���������� ����� ���������� (�� ��� ��������� ������, ���� �������)
         *      - ����������� ������ � ���������� ����� ���������
         *
         * "USE_VOTES" => "Y", // ���������� ����������� ��� ���
         * "USE_VOTES_FOR_ALL" => "N", // ����� �� ��������������� ���������
         *
         */

        $voteblock = '';

        if ($arParams['USE_VOTES']) {

            /**
             * <div class="brc_voteblock #VOTE_DENIED#" id="ivt_#ID#">
             * <ins #VOTE_EMO# title="#VOTE_TITLE#">#VOTE_WEIGHT#</ins>
             * <abbr class="br_iva_btn _up" title="#VOTE_UP_TITLE#" onclick="itape_vote( #ID#, 1 )"></abbr>
             * <abbr class="br_iva_btn _down" title="#VOTE_DOWN_TITLE#" onclick="itape_vote( #ID#, 0 )"></abbr>
             * </div>
             *
             * ��� #VOTE_DENIED# - css-����� "_used"
             */

            $votedPlus = $nodeInfo['UF_VOTES_PLUS'] ?? 0;
            $votedMinus = $nodeInfo['UF_VOTES_MINUS'] ?? 0;

            $voteWeight = (int)$votedPlus - (int)$votedMinus;

            /**
             * � ����� ��������� ��������� �������� �� �������������:
             * +13 =>  +25 / -12
             */
            $voteTitle = [];
            if ((int)$nodeInfo['UF_VOTES_PLUS']) {
                $voteTitle[] = '+' . (int)$nodeInfo['UF_VOTES_PLUS'];
            }

            if ((int)$nodeInfo['UF_VOTES_MINUS']) {
                $voteTitle[] = '-' . (int)$nodeInfo['UF_VOTES_MINUS'];
            }

            $voteEmo = '';
            $voteIndicator = 0;

            if ($voteWeight > 0) {
                $voteEmo = 'p';
                $voteIndicator = '+' . $voteWeight;
            } else if ($voteWeight < 0) {
                $voteEmo = 'n';
                $voteIndicator = '&ndash;' . abs($voteWeight);
            } else if (
                $voteWeight === 0 &&
                ($nodeInfo['UF_VOTES_PLUS'] || $nodeInfo['UF_VOTES_MINUS']) &&
                !OPTIONS::get('show_clear_zero_in_complex_voting')
            ) {

                /**
                 * ����� �������, ����� ����� ������� == 0, �� ��� �� ������ ���, ��� ���������!
                 */
                $voteEmo = 'z';

                $voteIndicator = sprintf(
                    '0 (+%s/&ndash;%s)',
                    abs($nodeInfo['UF_VOTES_PLUS']),
                    abs($nodeInfo['UF_VOTES_MINUS'])
                );
            }

            /**
             * �������� ���� �� "��� ������������" � "�������� ���������".
             *
             * ����� �� ����� ��������� �� ������ ���������� � ������� � "��� ������������",
             * ...���� ������� ��������, �� ���� ��� ��� �������������
             *
             * ��� �� -- ���� �� � ����
             */
            $voted = false;
            if (
//				!$arParams[ 'BRANCH_IN_SPECIAL_CASE' ]
//				&& VOTING::may_vote( $arParams )
                Voting::votedYet($nodeInfo['ID']) ||
                Voting::restrictedByAuthor($nodeInfo) ||
                Sanctions::restrictedUser()
            ) {
                $voted = true;
            }

            $voteRestricted = false;
            if (
                $arParams['BRANCH_IN_SPECIAL_CASE']
                || !Voting::mayVote($arParams)
            ) {
                $voteRestricted = true;
            }

            $voteblockTpl = '
				<div class="brc_voteblock #VOTE_DENIED#" id="ivt_#ID#">
					<ins #VOTE_EMO# title="#VOTE_TITLE#">#VOTE_WEIGHT#</ins>
					'
                . (
                $voteRestricted
                    ? ''
                    : '
							<abbr class="br_iva_btn _up" data-votes="#VOTED_PLUS#" title="#VOTE_UP_TITLE#" #VOTE_ACTION#></abbr>
							<abbr class="br_iva_btn _down" data-votes="#VOTED_MINUS#" title="#VOTE_DOWN_TITLE#" #VOTE_ACTION#></abbr>
						'
                )
                . ' </div> ';

            $search = [
                '#VOTE_DENIED#' => ($voted ? '_used' : ''),
                '#VOTE_EMO#' => ($voteEmo ? 'data-emo="' . $voteEmo . '"' : ''),
                '#VOTE_TITLE#' => implode(' / ', $voteTitle),
                '#VOTE_WEIGHT#' => $voteIndicator,
                '#VOTE_UP_TITLE#' => Voting::getVoteUpTitle(),
                '#VOTE_DOWN_TITLE#' => Voting::getVoteDownTitle(),
                // � ���� onclick �����, ���� �� ������� ������� ����������������� dom-�������� ��� ������ ���
                '#VOTE_ACTION#' => '',
                '#ID#' => $nodeInfo['ID'],
                '#VOTED_PLUS#' => $votedPlus,
                '#VOTED_MINUS#' => $votedMinus,
            ];

            EVENT::call('OnBeforeVotesBlockBurn', [
                'voteblockTpl' => &$voteblockTpl,
                'keyValuesForReplace' => &$search,
                'arParams' => $arParams,
                'nodeInfo' => $nodeInfo
            ]);

            $voteblock = str_replace(array_keys($search), array_values($search), $voteblockTpl);

        }

        /**
         * ��������� ����:
         *      - ������ ����� ���� ���������� �����, ��������� ��� ������� ���������
         */
        if (GRANT_AND_ACCESS::is_any_moder($arParams)) {
            $admin_block = '<del><ins></ins></del>';
        } else {
            $admin_block = '';
        }

        $aside_tpl = HTML_TEMPLATER::get('comment_aside', $arParams);

        return str_replace(
            [
                '#VOTE_BLOCK#',
                '#ADMIN_BLOCK#',
            ],
            [
                $voteblock,
                $admin_block,
            ],
            $aside_tpl
        );


    }

    public static function burn_comment_text(&$nodeInfo = [], &$arParams = [])
    {

        if ($nodeInfo['UF_UFO']) {
            return self::burnUFOMessage($nodeInfo, $arParams);
        }

        $simplifyForMail = $arParams['SIMPLIFY_TO_TEXT'] ?? null;
        if ($simplifyForMail) {
            /**
             * ������ ��� ����� ���� �...��� < ���� ����� > ����
             * � ������� �������� �������� ��� ���
             */
            $nodeInfo['UF_COMMENT'] = str_replace(["<", ">"], ["&lt;", "&gt;"], $nodeInfo['UF_COMMENT']);
        }

        return str_replace(
            [
                '#TEXT#'
            ],
            [
                $nodeInfo['UF_COMMENT']
            ],
            HTML_TEMPLATER::get('comment_text', $arParams)
        );

    }

    public static function burnUFOMessage(&$nodeInfo = [], &$arParams = [])
    {
        $result = '';

        if ($nodeInfo['UF_UFO']) {

            $ufoText = OPTIONS::get('ufo_message');
            if (!$ufoText) {
                $ufoText = Loc::getMessage('UFO_MESSAGE');
            }

            $result = str_replace(
                '#UFO_MSG#',
                $ufoText,
                HTML_TEMPLATER::get('comment_text_frozen', $arParams)
            );
        }

        return $result;
    }

    public static function proofAwaitingTitle(&$nodeInfo = [], &$arParams = [])
    {
        $result = '';

        if ($nodeInfo['UF_PROOF_AWAITING']) {

//            $ufoText = OPTIONS::get('ufo_message');
//            if (!$ufoText) {
//                $ufoText = Loc::getMessage('UFO_MESSAGE');
//            }

            $result = str_replace(
                '#TITLE#',
                Loc::getMessage('PROOF_AWAITING_DATA_ATTRIBUTE_TITLE'),
                HTML_TEMPLATER::get('proof_awaiting', $arParams)
            );
        }

        return $result;
    }

    public static function burn_addi_fields_aside(&$nodeInfo = [], &$arParams = [])
    {

        if ($nodeInfo['UF_UFO']) {
            return self::burnUFOMessage($nodeInfo, $arParams);
        }

        $result = '';

        if (isset($nodeInfo['AF_VALUES']) && !empty($nodeInfo['AF_VALUES'])) {

            $collected = [];

            $groupId = $arParams['TALK_GROUP_ID'] ?? null;

            if (!$groupId && isset($nodeInfo['TALK_GROUP_ID']) && $nodeInfo['TALK_GROUP_ID']) {
                $groupId = $nodeInfo['TALK_GROUP_ID'];
            }

            if (!$groupId && $nodeInfo['UF_URL_ID']) {
                $groupId = (URL::getInfo(['id' => $nodeInfo['UF_URL_ID']]))['UF_GROUP_ID'] ?? null;
            }

            if (!$groupId) {
                return $result;
            }

            $addiFields = AdditionalFields::getFieldsByGroup($groupId/*$arParams['TALK_GROUP_ID']*/);

            // $addiFields ������, ������ ��� ������ �������� ����������
            foreach ($addiFields as $fieldId => $fieldSettings) {

                $fieldValue = $nodeInfo['AF_VALUES'][$fieldId] ?? null;

                $simplifyForMail = $arParams['SIMPLIFY_TO_TEXT'] ?? null;
                if ($simplifyForMail) {

                    /**
                     * ������ ��� ����� ���� �...��� < ���� ����� > ����
                     * � ������� �������� �������� ��� ���
                     */
                    $fieldValue = str_replace(["<", ">"], ["&lt;", "&gt;"], $fieldValue);

                    $collected[] = str_replace(
                        [
                            '#AF_TITLE#',
                            '#AF_VALUE#',
                        ],
                        [
                            $fieldSettings['UF_NAME'],
                            $fieldValue,
                        ],
                        HTML_TEMPLATER::get('afRatingMailTemplate', $arParams)
                    );

                    continue;

                }


                if ($fieldSettings['UF_TYPE'] === 'text') {

                    $afTextTpl = $afTextTpl ?? HTML_TEMPLATER::get('afTextTemplate', $arParams);

                    $collected[] =
                        str_replace(
                            [
                                '#AF_TITLE#',
                                '#AF_VALUE#',
                            ],
                            [
                                $fieldSettings['UF_NAME'],
                                $fieldValue
                            ],
                            $afTextTpl
                        );
                } else if ($fieldSettings['UF_TYPE'] === 'rating' && (int)$fieldValue) {
                    /**
                     * (int required)
                     *
                     * When we change field type (f.e. from text to rating)
                     * it may contain old value:
                     * "We glad to use your proposals"
                     */


                    $afRatingTpl = $afRatingTpl ?? HTML_TEMPLATER::get('afRatingTemplate', $arParams);

                    $showLabelText = $fieldSettings['UF_SETTINGS']['show_label_text'] ?? 'yes';

                    $collected[] =
                        str_replace(
                            [
                                '#AF_TITLE#',
                                '#AF_VALUE#',
                                '#SHAPE_POSITION#',
                                '#SHAPE#',
                            ],
                            [
                                $fieldSettings['UF_NAME'],
                                $fieldValue,
                                $fieldSettings['UF_SETTINGS']['rating_block_position'],
                                $fieldSettings['UF_SETTINGS']['shape_of_piece'] ?? 'star'
                            ],
                            ($showLabelText === 'no') ?
                                // https://regex101.com/r/vNUU5l/1
                                preg_replace(
                                    ' ~#(IF_TITLE#)(?!\1).*?\1~is' . BX_UTF_PCRE_MODIFIER,
                                    '', $afRatingTpl
                                )
                                : preg_replace(
                                ' ~#\/?IF_TITLE#~is' . BX_UTF_PCRE_MODIFIER,
                                '', $afRatingTpl
                            )
                        );
                }
            }

            $result = str_replace(
                [
                    '#TEXT#'
                ],
                [
                    implode('', $collected)
                ],
                HTML_TEMPLATER::get('comment_text', $arParams)
            );
        }

        return $result;

    }

    public
    static function burnCommentUploads(&$nodeInfo = [], &$arParams = [])
    {

        if (
            !$nodeInfo['UF_UPLOADS']
            || $nodeInfo['UF_UFO']
        ) {
            return '';
        }

        $ufUploads = $nodeInfo['UF_UPLOADS'];
        if (!is_array($ufUploads)) {
            $ufUploads = @unserialize($ufUploads, ['allowed_class' => false]);
        }

        if (empty($ufUploads)) {
            return '';
        }

        $preparedFiles = self::prepare_upload_files($ufUploads);

        $resultPictures = $preparedFiles['result_pictures'];
        $resultFiles = $preparedFiles['result_files'];

        if (empty($resultPictures) && empty($resultFiles)) {
            return '';
        }

        $_tpl = HTML_TEMPLATER::get('comment_uploads', $arParams);

        return str_replace(
            '#UPLOADS_LIST#',
            self::pack_upload_files_to_html($resultPictures, $resultFiles, $arParams),
            $_tpl
        );

    }

    public
    static function prepare_upload_files(&$UF_UPLOADS = [])
    {

        $result_pictures = [];
        $result_files = [];

        foreach ($UF_UPLOADS as $file_id) {
            $file_info = CFile::GetFileArray($file_id);
            $is_image = CFile::IsImage($file_info['FILE_NAME']);

            if ($is_image) {

                $arSize = [
                    'width' => (int)OPTIONS::get('resize_small_width'),
                    'height' => (int)OPTIONS::get('resize_small_height'),
                ];

                //29-01-title.jpg
                list($_filename, $_fileext) = explode('.', $file_info['FILE_NAME']);

                $file_thumb = sprintf(
                    '/upload/%s/%s_thumb_%d_%d_%s.%s',
                    $file_info['SUBDIR'],
                    $_filename,
                    $arSize['width'],
                    $arSize['height'],
                    filemtime($_SERVER['DOCUMENT_ROOT'] . $file_info['SRC']),
                    $_fileext
                );

                //$file_thumb= '/upload/' . $file_info[ 'SUBDIR' ] . '/' . $_filename . '_thumb' . '.' . $_fileext;
                $file_thumb_full = $_SERVER['DOCUMENT_ROOT'] . $file_thumb;

                /**
                 * �������� �������������� �������.
                 * ������ ������ ������ ��������� �� ����-�� ���������� ����
                 *
                 * ��������, �� ������� ���������� �����.
                 * ����������, ��� ���������� �������� �����, � ��� �������� �� ���.
                 *
                 * �������� ��� � �������������� ��������������� ����.
                 * ��� ���� ���������, ����� ��� � ������� ������ ���� ������������
                 *
                 *
                 * ����� ������: ��������� ��������� �������.
                 */

                if (!file_exists($file_thumb_full)) {
                    $resize_result = CFile::ResizeImageFile(
                        $_SERVER['DOCUMENT_ROOT'] . $file_info['SRC'],
                        $file_thumb_full,
                        $arSize
                    );

                    if (!$resize_result) {
                        continue;
                    }
                }

                $result_pictures[$file_id] = $file_thumb;

            } else {
                $result_files[$file_id] = [
                    'filename' => $file_info['FILE_NAME'],
                    'path' => $file_info['SRC']
                ];
            }

        }

        return [
            'result_pictures' => $result_pictures,
            'result_files' => $result_files
        ];

    }

    public
    static function pack_upload_files_to_html(&$result_pictures = [], &$result_files = [], &$arParams = [])
    {

        $_images_result = '';
        if (!empty($result_pictures)) {

            $comment_uploads_picture_piece = HTML_TEMPLATER::get('comment_uploads_picture_piece', $arParams);
            $comment_uploads_pictures_together = HTML_TEMPLATER::get('comment_uploads_pictures_together', $arParams);

            $_images = [];
            foreach ($result_pictures as $file_id => $image_path) {

                $_images[] = str_replace(
                    [
                        '#DATA_ATTRIBUTE#',
                        '#PICTURE_ID#',
                        '#PICTURE_PATH#'
                    ],
                    [
                        OPTIONS::get('custom_gallery_image_data_attribute'),
                        $file_id,
                        $image_path
                    ],
                    $comment_uploads_picture_piece
                );
            }

            //$_images_result= sprintf( "<div class='uploaded_images'>%s</div>", implode( '', $_images ) );
            $_images_result = str_replace(
                [
                    '#PICTURES_ALL_TOGETHER#',
                ],
                [
                    implode('', $_images)
                ],
                $comment_uploads_pictures_together
            );

        }


        $_links_result = '';
        if (!empty($result_files)) {

            $comment_uploads_file_piece = HTML_TEMPLATER::get('comment_uploads_file_piece', $arParams);
            $comment_uploads_files_together = HTML_TEMPLATER::get('comment_uploads_files_together', $arParams);

            $_links = [];
            foreach ($result_files as $file_id => $file_info) {

                $_links[] = str_replace(
                    [
                        '#FILE_ID#',
                        '#DOWNLOAD_URL#',
                        '#FILENAME#',
                    ],
                    [
                        $file_id,
                        $file_info['path'],
                        $file_info['filename'],
                    ],
                    $comment_uploads_file_piece
                );

            }

            $_links_result = str_replace(
                [
                    '#FILES_ALL_TOGETHER#',
                ],
                [
                    implode('', $_links)
                ],
                $comment_uploads_files_together
            );

        }

        return $_images_result . $_links_result;
    }

    public
    static function burn_ambushed_comment_form($position = 'top', $force_msg = '')
    {

        if (!$position || !in_array($position, ['top', 'bottom'])) {
            return '';
        }

        $write_comment_label = $force_msg ? $force_msg : Loc::getMessage('ITAPE_AMBUSHED_FORM_LABEL');

        $form_tpl = HTML_TEMPLATER::get('ambushed_form', $arParams);

        return str_replace(
            [
                '#POSITION#',
                '#COMMENT_LABEL#'
            ],
            [
                $position,
                $write_comment_label
            ],
            $form_tpl
        );

    }

//    public
//    static function schemaOrgWrapper($type = 'open', &$node_info = [], &$arParams = [])
//    {
//
//        if (
//        !SCHEMA_ORG::in_use($arParams)
//        ) {
//            return '';
//        }
//
//        if ($type === 'open') {
//
//            $schema_org_wrapper = HTML_TEMPLATER::get('schema_org_wrapper');
//            /**
//             * @var DateTime $time_str
//             */
//            $time_str = $node_info['UF_CREATED_DATE'];
//
//            if (!$schema_org_wrapper) {
//                return '';
//            }
//
//            $schema_org_wrapper = str_replace(
//                [
//                    '#ITEM_REVIEWED#',
//                    '#DATE_PUBLISHED#',
//                ],
//                [
//                    '<!--##SCHEMA_ORG_REVIEWED_ITEM_TITLE##-->',
//                    $time_str->toString()
//
//                ],
//                $schema_org_wrapper
//            );
//
//            return $schema_org_wrapper;
//
//        }
//
//        return '</div>';
//
//    }

    public
    static function additionalField(&$data)
    {

        /*
        TODO:
            <div class="brf_additionals">
                <div>
                    <span>�����������: </span>
                    <div><input type="text" data-input="ADDI[23][]" data-addit-id="23"></div>
                </div>
                <div>
                    <span>����������: </span>
                    <div><textarea class="_error" data-input="ADDI[25][]" data-addit-id="25"></textarea></div>
                </div>
                <div>
                    <span>�������: </span> <abbr>1 / 2 / 3 / 4 / 5</abbr>
                    <input type="hidden" data-input="ADDI[27][]" data-addit-id="27">
                </div>
                <div>
                    <span>�����: </span>
                    <select data-addit-id="301">
                        <option value="1">������������</option>
                        <option value="2">��� ����</option>
                        <option value="3">��������</option>
                        <option value="4">�����</option>
                        <option value="5">������</option>
                    </select>
                </div>
            </div>
        <? */

        $result = '';

        if (empty($data)) {
            return $result;
        }

        $tpl = '';

        if ($data['UF_TYPE'] === 'text') {
            if (
                isset($data['UF_SETTINGS']['height'])
                && (int)$data['UF_SETTINGS']['height'] === 1
            ) {
                $tpl = HTML_TEMPLATER::get('additionalFieldInputText');
            } else {
                $tpl = HTML_TEMPLATER::get('additionalFieldInputTextarea');
            }
        } else if ($data['UF_TYPE'] === 'rating') {

            $tpl = HTML_TEMPLATER::get('additionalFieldRating');
            $defaults = (AdditionalFields::getDefaultFieldTypes())['rating']['options'];

            // Either stored value or field settings or default settings
            if (!$data['VALUE']) {
                $data['VALUE'] = $data['UF_SETTINGS']['mark_default'] ??
                    $defaults['mark_default']['default'];
            }

            $data['SHAPE'] = $data['UF_SETTINGS']['shape_of_piece'] ??
                $defaults['shape_of_piece']['default'];

            $data['SHAPE_VS_TITLE_POSITION'] = $data['UF_SETTINGS']['rating_block_position'] ??
                $defaults['rating_block_position']['default'];
        }

        if ($tpl) {
            $search = [
                '#FIELD_LANG#' => $data['UF_NAME'],
                '#REQUIRED#' => $data['UF_REQUIRED'] ? 'data-require="1"' : '',
                '#FIELD_ID#' => $data['ID'],
                '#SHAPE_VS_TITLE_POSITION#' => $data['SHAPE_VS_TITLE_POSITION'] ?? '',
                '#MULTIPLE#' => '',
                '#VALUE#' => $data['VALUE'],
                '#SHAPE#' => $data['SHAPE'] ?? '',
            ];

            $result = str_replace(array_keys($search), array_values($search), $tpl);
        }

        return $result;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit