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/aby.telegram/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/aby.telegram/lib/module.php
<?php

namespace Aby\Telegram;

use \Bitrix\Main\Localization\Loc;
use \Bitrix\Main\Config\Option;
use \Bitrix\Main\SystemException;
use \Bitrix\Main\EventManager;
use Exception;

Loc::loadMessages(__FILE__);

class Module
{
    private $required_php_version = '7.0';
    private $required_php_extensions = array(
        'curl',
        'json',
        'mbstring',
    );

    private $options = [];
    private $moduleId;

    public function __construct(){
        $this->moduleId = 'aby.telegram';

        $this->loadOptions();
    }

    /**
     * @throws \Bitrix\Main\ArgumentNullException
     */
    private function loadOptions(){
        if($this->moduleId){
            $this->options = Option::getForModule($this->moduleId);
        }
    }

    /**
     * @return string
     */
    public function getModuleId()
    {
        return $this->moduleId;
    }

    /**
     * @param $key
     * @param null $default
     * @return mixed|null
     */
    public function getOption($key, $default = null){
        return isset($this->options[$key]) ? $this->options[$key] : $default;
    }

    /**
     * @return array
     */
    public function checkRequirements(){
        $result = array(1, '');

        if (phpversion() < $this->required_php_version) {
            $result = array(0, Loc::getMessage("AB_TELEGRAM_INSTALL_ERROR_PHP_VERSION", array(
                "{VERSION}" => phpversion(),
                "{REQUIRED}" => $this->required_php_version
            )));
        }

        if($result[0]){
            foreach ($this->required_php_extensions as $extension) {
                if (!extension_loaded($extension)) {
                    $result = array(0, Loc::getMessage('AB_TELEGRAM_INSTALL_ERROR_PHP_EXTENSIONS', array(
                        '{EXTENSION}' => $extension,
                    )));
                    break;
                }
            }
        }

        if($result[0]){
            if(ini_get('mbstring.func_overload') == "2"){
                $result = array(0, Loc::getMessage('AB_TELEGRAM_INSTALL_ERROR_OVERLOAD'));
            }
        }

        return $result;
    }

    /**
     * Check Installed Events
     */
    public function checkInstallEvents()
    {
        $eventManager = EventManager::getInstance();
        $moduleEvents = $this->getModuleEventsNew();

        foreach ($moduleEvents as $module => $events) {
            foreach ($events as $event => $handler) {
                $result = $eventManager->findEventHandlers($module, $event);
                $installed = 0;

                if($result && is_array($result) && count($result)){
                    foreach($result as $item){
                        if($item["TO_MODULE_ID"] == $this->moduleId){
                            $installed = 1;
                            break;
                        }
                    }
                }

                if(!$installed){
                    $eventManager->registerEventHandler(
                        $module,
                        $event,
                        $this->moduleId,
                        $handler["namespace"],
                        $handler["method"]
                    );
                }
            }
        }
    }

    /**
     * Get module new events
     * @return array
     */
    private function getModuleEventsNew()
    {
        $arInstalledModules = \Bitrix\Main\ModuleManager::getInstalledModules();

        $events = array(
            'main' => array(
                'OnAfterUserRegister' => array(
                    'namespace' => 'Aby\\Telegram\\Event',
                    'method' => 'UserRegister',
                ),
                'OnAfterUserSimpleRegister' => array(
                    'namespace' => 'Aby\\Telegram\\Event',
                    'method' => 'UserRegister',
                ),
            ),
        );

        if(isset($arInstalledModules["form"])){
            $events['form'] = array(
                'onAfterResultAdd' => array(
                    'namespace' => 'Aby\\Telegram\\Event',
                    'method' => 'FormResultAdd',
                ),
                'onAfterResultUpdate' => array(
                    'namespace' => 'Aby\\Telegram\\Event',
                    'method' => 'FormResultUpdate',
                ),
            );
        }

        if(isset($arInstalledModules["blog"])){
            $events['blog'] = array(
                'OnCommentAdd' => array(
                    'namespace' => 'Aby\\Telegram\\Event',
                    'method' => 'BlogCommentAdd',
                ),
            );
        }

        return $events;
    }

    /**
     * @param $type
     * @param $event
     * @param array $data
     * @throws \Bitrix\Main\ArgumentNullException
     */
    public function processEvent($type, $event, $data = array()){
        // Check token
        $token = $this->getOption('token', '');
        if(!$token){
            return;
        }

        // Get general receivers
        $chat_ids = $this->getOption('chat_ids', '');

        // Get templates
        $templates = $this->parseEventSettings();
        if(!count($templates)){
            return;
        }

        // Find templates for the event
        $templates = $this->findEventTemplates($templates, $type, $event, $data);
        if(!count($templates)){
            return;
        }

        // Form template data
        $templates_data = array();

        if(in_array($type, array("iblock_add", "iblock_edit"))){
            $templates_data = $this->getTemplateDataIBlock($event["IBLOCK_ID"], $event["ID"]);
        }else if($type == "new_order"){
            $templates_data = $this->getTemplateDataSaleOrder($event);
        }else if($type == "order_payed"){
            $templates_data = $this->getTemplateDataOrderPayed($data);
        }else if($type == "order_status_changed"){
            $templates_data = $this->getTemplateDataOrderStatusChanged($data);
        }else if($type == "order_canceled"){
            $templates_data = $this->getTemplateDataOrderCanceled($data);
        }else if(in_array($type, array("form_add", "form_edit"))){
            $templates_data = $this->getTemplateDataForm($data["web_form_id"], $data["result_id"]);
        }else if($type == "blog_comment_add"){
            $templates_data = $this->getTemplateDataBlogComment($data["comment_id"]);
        }else if($type == "user_register"){
            $templates_data = $this->getTemplateDataUserRegister($event);
        }

        foreach($templates as $template){
            // Check template receivers
            $receivers = trim($template["template_chat_ids"]) ? trim($template["template_chat_ids"]) : trim($chat_ids);
            if(!$receivers){
                continue;
            }

            $receivers_array = explode(",", $receivers);
            if(!count($receivers_array)){
                continue;
            }
            foreach($receivers_array as $item_key => $item){
                $receivers_array[$item_key] = trim($item);
            }

            // Check site
            if($template["site_id"]){
                if($template["site_id"] != $templates_data["SITE"]["ID"]){
                    continue;
                }
            }

            // Render template
            $text_rendered = (new Template())->render($template["template"], $templates_data);
            if(!$text_rendered){
                continue;
            }

            // Send
            (new Notification())->send($token, $receivers_array, $text_rendered);
        }
    }

    /**
     * @param array $default
     * @return array
     */
    public function parseEventSettings($default = array()){
        $templates = array();

        $check_options = count($default) ? $default : $this->options;

        if(count($check_options)){
            foreach($check_options as $option_name => $option_value){
                if(strpos($option_name, "template[") !== false){
                    $option_num = substr($option_name, 9, strpos($option_name, ']') - 9);
                    $option_key = substr($option_name, strpos($option_name, ']') + 2, strlen($option_name) - strpos($option_name, ']') - 3);

                    if(!isset($templates[$option_num])){
                        $templates[$option_num] = array();
                    }

                    $templates[$option_num][$option_key] = $option_value;
                }
            }
        }

        return $templates;
    }

    /**
     * @param $templates
     * @param $type
     * @param $event
     * @param $data
     * @return array
     */
    protected function findEventTemplates($templates, $type, $event, $data){
        $return = array();

        foreach($templates as $template){
            if($template["event_active"] != "1"){
                continue;
            }

            if(!$template["template"]){
                continue;
            }

            if($template["event"] != $type){
                continue;
            }

            if(in_array($type, array("iblock_add", "iblock_edit"))){
                if(!$template["event_iblock"]){
                    continue;
                }

                if($event["IBLOCK_ID"] != $template["event_iblock"]){
                    continue;
                }
            }

            if(in_array($type, array("form_add", "form_edit")) && $template["event_form"]){
                if($data["web_form_id"] != $template["event_form"]){
                    continue;
                }
            }

            if($type == "blog_comment_add" && $template["event_blog"]){
                if($event["BLOG_ID"] != $template["event_blog"]){
                    continue;
                }
            }

            $return[] = $template;
        }

        return $return;
    }

    /**
     * @param $iblock_id
     * @param $id
     * @return array
     */
    public function getTemplateDataIBlock($iblock_id, $id){
        $result = array();

        $res = \CIBlockElement::GetList(array(), array("IBLOCK_ID" => $iblock_id, "ID" => $id), false, array("nPageSize"=>50), array());
        while($ob = $res->GetNextElement())
        {
            $arFields = $ob->GetFields();
            $arProps = $ob->GetProperties();

            $result = $arFields;
            $result["PROPERTIES"] = $arProps;
            $result["SITE"]["ID"] = $arFields["LID"];

            foreach($arProps as $prop_key => $prop_value){
                if(isset($prop_value["LINK_IBLOCK_ID"]) && $prop_value["LINK_IBLOCK_ID"]){
                    $result["PROPERTIES"][$prop_key]["VALUE_LINKED"] = $this->getLinkedPropertiesData($prop_value["LINK_IBLOCK_ID"], $prop_value["VALUE"]);
                }
            }
        }

        if(!count($result)){
            (new Log())->write_log("Element not found (IBLOCK_ID: $iblock_id, ID: $id)", __FILE__, __LINE__);
        }

        $result["LINK"] = $this->get_site_url($result["SITE"]["ID"])."/bitrix/admin/iblock_element_edit.php?IBLOCK_ID=$iblock_id&type=".$this->get_iblock_type($iblock_id)."&ID=$id";

        return $result;
    }

    /**
     * @param int|string $LINK_IBLOCK_ID
     * @param string $MULTIPLE
     * @param mixed $VALUE
     * @return string
     */
    private function getLinkedPropertiesData($LINK_IBLOCK_ID, $VALUE)
    {
        $return = "";

        $res = \CIBlockElement::GetList(array(), array("IBLOCK_ID" => $LINK_IBLOCK_ID, "ID" => $VALUE), false, array("nPageSize"=>50), array());
        while($ob = $res->GetNextElement())
        {
            $arFields = $ob->GetFields();

            if(isset($arFields["NAME"])){
                if($return) $return .= ", ";
                $return .= $arFields["NAME"];
            }
        }

        return $return;
    }

    /**
     * @param \Bitrix\Main\Event $event
     * @return array
     */
    public function getTemplateDataSaleOrder(\Bitrix\Main\Event $event){
        $result = array();

        $get_products_prices = $this->getOption('get_products_prices', '');
        $get_products_remains = $this->getOption('get_products_remains', '');
        $get_coupons = $this->getOption('get_coupons', '');

        \CModule::IncludeModule('iblock');

        $order = $event->getParameter("ENTITY");
        $order_id = $order->getId();

        // Site
        $site_id = $order->getSiteId();
        $result["SITE"]["ID"] = $site_id;

        $rsSites = \CSite::GetByID($site_id);
        $arSite = $rsSites->Fetch();
        $result["SITE"]["NAME"] = $arSite["NAME"];
        $result["SITE"]["SERVER_NAME"] = $arSite["SERVER_NAME"];
        // Site

        $site_url = $this->get_site_url($site_id);
        $result["ID"] = $order_id;
        $result["LINK"] = $site_url."/bitrix/admin/sale_order_view.php?ID=$order_id";

        // Get properties
        $result["PROPERTIES"] = $this->collect_order_properties($order);

        if($ACCOUNT_NUMBER = $order->getField("ACCOUNT_NUMBER")){
            $result["ACCOUNT_NUMBER"] = $ACCOUNT_NUMBER;
        }
        // Get properties

        // Cart
        $result["ITEMS"] = array();
        $basket = $order->getBasket();
        $product_ids = array();
        $products_fields = array();
        $products_properties = array();
        $products_ids_clear = array();

        foreach ($basket as $basketItem) {
            $ProductId = $basketItem->getProductId();
            $mxResult = \CCatalogSku::GetProductInfo($ProductId);
            if (is_array($mxResult)){
                $product_ids[] = $mxResult['ID'];
                $products_ids_clear[$ProductId] = $mxResult['ID'];
            }else{
                $product_ids[] = $ProductId;
                $products_ids_clear[$ProductId] = $ProductId;
            }
        }

        if(count($product_ids)){
            $res = \CIBlockElement::GetList(array(), array("ID" => $product_ids), false, array("nPageSize"=>50), array());
            while($ob = $res->GetNextElement())
            {
                $arFields = $ob->GetFields();
                $arProps = $ob->GetProperties();

                $products_fields[$arFields["ID"]] = $arFields;
                $products_properties[$arFields["ID"]] = $arProps;
            }
        }

        foreach ($basket as $basketItem) {
            $ProductId = $basketItem->getProductId();
            $basketPropertyCollection = $basketItem->getPropertyCollection();

            $check_product_id = 0;
            if(isset($products_ids_clear[$ProductId])){
                $check_product_id = $products_ids_clear[$ProductId];
            }

            $ITEM_PROPS = $basketPropertyCollection->getPropertyValues();
            if($check_product_id && isset($products_properties[$check_product_id])){
                $ITEM_PROPS = array_merge($ITEM_PROPS, $products_properties[$check_product_id]);
            }

            $DETAIL_PAGE_URL = "";
            if($check_product_id && isset($products_fields[$check_product_id])){
                $DETAIL_PAGE_URL = $products_fields[$check_product_id]["DETAIL_PAGE_URL"];
            }

            $ITEM_PRICES = array();
            if($get_products_prices == "Y"){
                if($check_product_id){
                    $prices_result = \CPrice::GetListEx(array(),
                        array(
                            "PRODUCT_ID" => $check_product_id,
                        )
                    );
                    while ($arPrices = $prices_result->Fetch()){
                        $ITEM_PRICES[$arPrices["CATALOG_GROUP_ID"]] = $arPrices["PRICE"];
                    }
                }
            }

            $ITEM_REMAINS = array();
            $ITEM_REMAINS_TEXT = "";
            $ITEM_REMAINS_TEXT_WITH_ADDRESS = "";

            if($get_products_remains == "Y"){
                $remains_result = \CCatalogStoreProduct::GetList(array(),
                    array(
                        "PRODUCT_ID" => $ProductId,
                    )
                );
                while ($arRemains = $remains_result->Fetch()){
                    $ITEM_REMAINS[$arRemains["STORE_ID"]] = $arRemains["AMOUNT"];

                    if($arRemains["AMOUNT"]) {
                        if ($ITEM_REMAINS_TEXT) $ITEM_REMAINS_TEXT .= "\n";
                        if ($ITEM_REMAINS_TEXT_WITH_ADDRESS) $ITEM_REMAINS_TEXT_WITH_ADDRESS .= "\n";

                        $ITEM_REMAINS_TEXT .= $arRemains["STORE_NAME"] . ": " . $arRemains["AMOUNT"];
                        $ITEM_REMAINS_TEXT_WITH_ADDRESS .= $arRemains["STORE_NAME"] . " (".$arRemains["STORE_ADDR"]."): " . $arRemains["AMOUNT"];
                    }
                }
            }

            $result["ITEMS"][] = array(
                "PRODUCT_ID" => $ProductId,
                "DETAIL_PAGE_URL" => $site_url.$DETAIL_PAGE_URL,
                "NAME" => $basketItem->getField('NAME'),
                "QUANTITY" => $basketItem->getQuantity(),
                "PRICE" => $basketItem->getPrice(),
                "PROPERTIES" => $ITEM_PROPS,
                "PRICES" => $ITEM_PRICES,
                "REMAINS" => $ITEM_REMAINS,
                "REMAINS_TEXT" => $ITEM_REMAINS_TEXT,
                "REMAINS_TEXT_WITH_ADDRESS" => $ITEM_REMAINS_TEXT_WITH_ADDRESS,
            );
        }
        // Cart

        // Delivery
        $result["DELIVERY"] = array(
            "DELIVERY_ID" => "",
            "DELIVERY_NAME" => "",
            "DELIVERY_PRICE" => $order->getDeliveryPrice(),
            "BASKET_WEIGHT" => $basket->getWeight(),
        );

        $shipmentCollection = $order->getShipmentCollection();
        foreach ($shipmentCollection as $shipment) {
            $result["DELIVERY"]["DELIVERY_ID"] = $shipment->getDeliveryId();
            $result["DELIVERY"]["DELIVERY_NAME"] = $shipment->getDeliveryName();

            $result["DELIVERY"]["STORE"] = [];
            if ($storeId = $shipment->getStoreId()) {
                $store = \Bitrix\Catalog\StoreTable::getById($storeId)->fetch();
                $result["DELIVERY"]["STORE"] = $store;
            }
        }
        // Delivery

        // Payment
        $result["PAYMENT"]["SUM"] = $order->getPrice();
        $result["PAYMENT"]["DISCOUNT"] = $order->getDiscountPrice();
        $result["PAYMENT"]["CURRENCY"] = $order->getCurrency();
        $result["PAYMENT"]["PAYMENT_SYSTEM_ID"] = "";
        $result["PAYMENT"]["PAYMENT_SYSTEM_NAME"] = "";

        $paymentCollection = $order->getPaymentCollection();
        foreach ($paymentCollection as $payment) {
            $result["PAYMENT"]["PAYMENT_SYSTEM_ID"] = $payment->getPaymentSystemId();
            $result["PAYMENT"]["PAYMENT_SYSTEM_NAME"] = $payment->getPaymentSystemName();
        }
        // Payment

        // Created by user
        if($USER_ID = $order->getField("CREATED_BY")){
            $result["USER_ID"] = $USER_ID;

            $rsUser = \CUser::GetByID($USER_ID);
            $arUser = $rsUser->Fetch();
            $result["USER"] = $arUser;
        }
        // Created by user

        // Coupons
        $COUPONS = array();

        if($get_coupons == "Y"){
            $couponList = \Bitrix\Sale\Internals\OrderCouponsTable::getList(array(
                'filter' => array('=ORDER_ID' => $order_id)
            ));
            while ($coupon = $couponList->fetch())
            {
                $COUPONS[] = $coupon;
            }
        }

        $result["COUPONS"] = $COUPONS;
        // Coupons

        return $result;
    }

    /**
     * @param $order
     * @return array
     */
    private function collect_order_properties($order)
    {
        $PROPERTIES = array();
        $propertyCollection = $order->getPropertyCollection();
        $propArray = $propertyCollection->getArray();
        $newPropArray = array();

        foreach($propArray["properties"] as $propItems){
            if($propItems["VALUE"][0]!=""){
                $newPropArray[$propItems["PROPS_GROUP_ID"]][$propItems["ID"]] = $propItems;
            }
        }

        foreach($propArray["groups"] as $propGroup) {
            if (is_array($newPropArray[$propGroup["ID"]])) {
                foreach ($newPropArray[$propGroup["ID"]] as $arPropGroupItem) {
                    $PROPERTIES[$arPropGroupItem["CODE"]] = $arPropGroupItem["VALUE"][0];
                }
            }
        }

        if($USER_DESCRIPTION = $order->getField("USER_DESCRIPTION")){
            $PROPERTIES["USER_DESCRIPTION"] = $USER_DESCRIPTION;
        }
        if($COMMENTS = $order->getField("COMMENTS")){
            $PROPERTIES["COMMENTS"] = $COMMENTS;
        }

        if($PROPERTIES["LOCATION"]){
            $arLocs = \CSaleLocation::GetByID($PROPERTIES["LOCATION"]);
            if($arLocs && count($arLocs)){
                $location_text = "";

                if($arLocs["COUNTRY_NAME"]){
                    $location_text = $arLocs["COUNTRY_NAME"];
                }
                if($arLocs["REGION_NAME"]){
                    if($location_text) $location_text .= ", ";
                    $location_text .= $arLocs["REGION_NAME"];
                }
                if($arLocs["CITY_NAME"]){
                    if($location_text) $location_text .= ", ";
                    $location_text .= $arLocs["CITY_NAME"];
                }

                $PROPERTIES["LOCATION"] = $location_text;
            }
        }

        return $PROPERTIES;
    }

    /**
     * @param int $site_id
     * @return string
     */
    public function get_site_url($site_id = 0){
        if (isset($_SERVER['HTTPS']))
            $scheme = $_SERVER['HTTPS'];
        else
            $scheme = '';
        if (($scheme) && ($scheme != 'off')) $scheme = 'https';
        else $scheme = 'https';

        $server = \Bitrix\Main\HttpApplication::getInstance()->getContext()->getServer();

        if(!$server){
            (new Log())->write_log("Server object not found", __FILE__, __LINE__);
        }

        $HttpHost = $server->getHttpHost() ?: '';

        if(!$HttpHost && $site_id){
            // cron
            $rsSites = \CSite::GetByID($site_id);
            $arSite = $rsSites->Fetch();
            $HttpHost = $arSite["SERVER_NAME"];
        }

        return $scheme."://".$HttpHost;
    }

    /**
     * @param $ID
     * @return string
     */
    public function get_iblock_type($ID){
        try{
            $arIblock = \Bitrix\Iblock\IblockTable::getList(array(
                'filter' => array('ID' => $ID)
            ))->fetch();

            return $arIblock["IBLOCK_TYPE_ID"];
        }catch (SystemException $e){
            (new Log())->write_log("Get IBlock type exception: ".$e->getMessage(), __FILE__, __LINE__);
        }

        return '';
    }

    /**
     * @param array $data
     * @return array
     * @throws \Bitrix\Main\ArgumentNullException
     */
    public function getTemplateDataOrderPayed($data = array()){
        $result = array();

        if(!isset($data["order_id"]) || !$data["order_id"]){
            return $result;
        }

        $order_id = $data["order_id"];
        $result["ID"] = $order_id;

        \CModule::IncludeModule("sale");
        $order = \Bitrix\Sale\Order::load($order_id);
        $result["SUM"] = $order->getPrice();

        $result["PAYMENT_SYSTEM_ID"] = "";
        $result["PAYMENT_SYSTEM_NAME"] = "";

        $paymentCollection = $order->getPaymentCollection();
        foreach ($paymentCollection as $payment) {
            $result["PAYMENT_SYSTEM_ID"] = $payment->getPaymentSystemId();
            $result["PAYMENT_SYSTEM_NAME"] = $payment->getPaymentSystemName();
        }

        $site_id = $order->getSiteId();
        $result["SITE"]["ID"] = $site_id;

        $result["LINK"] = $this->get_site_url($site_id)."/bitrix/admin/sale_order_view.php?ID=$order_id";

        // Get properties
        $result["PROPERTIES"] = $this->collect_order_properties($order);

        if($ACCOUNT_NUMBER = $order->getField("ACCOUNT_NUMBER")){
            $result["ACCOUNT_NUMBER"] = $ACCOUNT_NUMBER;
        }
        // Get properties

        return $result;
    }

    /**
     * @param array $data
     * @return array
     * @throws \Bitrix\Main\ArgumentNullException
     */
    public function getTemplateDataOrderStatusChanged($data = array()){
        $result = array();

        if(!isset($data["order_id"]) || !$data["order_id"]){
            return $result;
        }
        if(!isset($data["val"]) || !$data["val"]){
            return $result;
        }

        $order_id = $data["order_id"];
        $new_status = $data["val"];
        $result["ID"] = $order_id;

        \CModule::IncludeModule("sale");
        $order = \Bitrix\Sale\Order::load($order_id);
        $site_id = $order->getSiteId();
        $result["SITE"]["ID"] = $site_id;

        $result["LINK"] = $this->get_site_url($site_id)."/bitrix/admin/sale_order_view.php?ID=$order_id";

        $arStatus = \CSaleStatus::GetByID($new_status);
        $result["STATUS"] = $arStatus["NAME"];

        // Get properties
        $result["PROPERTIES"] = $this->collect_order_properties($order);

        if($ACCOUNT_NUMBER = $order->getField("ACCOUNT_NUMBER")){
            $result["ACCOUNT_NUMBER"] = $ACCOUNT_NUMBER;
        }
        // Get properties

        return $result;
    }

    /**
     * @param array $data
     * @return array
     * @throws \Bitrix\Main\ArgumentNullException
     */
    public function getTemplateDataOrderCanceled($data = array()){
        $result = array();

        if(!isset($data["order_id"]) || !$data["order_id"]){
            return $result;
        }

        $order_id = $data["order_id"];
        $description = $data["description"];
        $result["ID"] = $order_id;
        $result["DESCRIPTION"] = $description;

        \CModule::IncludeModule("sale");
        $order = \Bitrix\Sale\Order::load($order_id);
        $site_id = $order->getSiteId();
        $result["SITE"]["ID"] = $site_id;

        $result["LINK"] = $this->get_site_url($site_id)."/bitrix/admin/sale_order_view.php?ID=$order_id";

        // Get properties
        $result["PROPERTIES"] = $this->collect_order_properties($order);

        if($ACCOUNT_NUMBER = $order->getField("ACCOUNT_NUMBER")){
            $result["ACCOUNT_NUMBER"] = $ACCOUNT_NUMBER;
        }
        // Get properties

        return $result;
    }

    /**
     * @param $web_form_id
     * @param $result_id
     * @return array
     */
    public function getTemplateDataForm($web_form_id, $result_id)
    {
        $arResult = array();
        $arAnswer2 = array();
        $arAnswer = \CFormResult::GetDataByID($result_id, array(), $arResult, $arAnswer2);

        $result = $arResult;

        $result["LINK"] = $this->get_site_url()."/bitrix/admin/form_result_edit.php?lang=ru&WEB_FORM_ID=$web_form_id&RESULT_ID=$result_id";

        $answers = array();
        if(count($arAnswer)){
            foreach($arAnswer as $code => $data){
                $this_answer = array();
                $answer_value = "";

                foreach($data as $answer_variant){
                    $this_answer["FIELD_ID"] = $answer_variant["FIELD_ID"];
                    $this_answer["TITLE"] = strip_tags($answer_variant["TITLE"]);

                    if(in_array($answer_variant["FIELD_TYPE"], array("text", "textarea", "email", "hidden", "url", "password"))){
                        $answer_value = $answer_variant["USER_TEXT"];
                    }else if(in_array($answer_variant["FIELD_TYPE"], array("radio", "checkbox", "dropdown", "multiselect"))){
                        if($answer_value) $answer_value .= ', ';
                        $answer_value .= $answer_variant["ANSWER_TEXT"];
                    }else if($answer_variant["FIELD_TYPE"] == "date"){
                        $answer_value = $answer_variant["USER_DATE"];
                    }else if(!$answer_variant["FIELD_TYPE"]){
                        $answer_value = $answer_variant["USER_TEXT"];
                    }
                }

                if(!$answer_value){
                    continue;
                }

                $this_answer['ANSWER_VALUE'] = $answer_value;

                $answers[] = $this_answer;
            }
        }

        $result["ANSWERS"] = $answers;

        $result["SERVER"] = $_SERVER;

        // User
        if($result["USER_ID"]){
            $rsUser = \CUser::GetByID($result["USER_ID"]);
            $arUser = $rsUser->Fetch();
            $result["USER"] = $arUser;
        }
        // User

        return $result;
    }

    /**
     * @param $comment_id
     *
     * @return array
     */
    public function getTemplateDataBlogComment($comment_id)
    {
        // Достаем сам комментарий
        $arComment = \CBlogComment::GetByID($comment_id);

        if(is_array($arComment)){
            if(isset($arComment["POST_TEXT"])) {
                $arComment["POST_TEXT"] = strip_tags($arComment["POST_TEXT"]);
            }
            if(isset($arComment["PATH"])) {
                $arComment["PATH"] = html_entity_decode($arComment["PATH"]);
                $arComment["PATH"] = str_replace("#comment_id#", $comment_id, $arComment["PATH"]);

                if(mb_strpos($arComment["PATH"], "http") !== 0){
                    $arComment["PATH"] = $this->get_site_url().$arComment["PATH"];
                }
            }
        }

        $result = $arComment;
        // Достаем сам комментарий

        // Достаем блог
        $arBlog = \CBlog::GetByID($arComment["BLOG_ID"]);
        $result["BLOG"] = $arBlog;
        // Достаем блог

        // Достаем группу блога
        $arBlogGroup = \CBlogGroup::GetByID($arBlog["GROUP_ID"]);
        $result["BLOG_GROUP"] = $arBlogGroup;
        $result["SITE"]["ID"] = $arBlogGroup["SITE_ID"];
        // Достаем группу блога

        // Достаем сообщение блога
        $arPost = \CBlogPost::GetByID($arComment["POST_ID"]);
        $result["POST"] = $arPost;
        // Достаем сообщение блога

        // Достаем пользовательские поля
        global $USER_FIELD_MANAGER;
        $arUserField = $USER_FIELD_MANAGER->GetUserFields('BLOG_COMMENT', $comment_id);
        $result["USER_FIELD"] = $arUserField;
        // Достаем пользовательские поля

        $result["SERVER"] = $_SERVER;

        // Пользователь
        if($result["AUTHOR_ID"]){
            $rsUser = \CUser::GetByID($result["AUTHOR_ID"]);
            $arUser = $rsUser->Fetch();
            $result["AUTHOR"] = $arUser;
        }
        // Пользователь

        $result["LINK"] = $this->get_site_url($arBlogGroup["SITE_ID"])."/bitrix/admin/blog_comment.php";

        return $result;
    }

    /**
     * @param array $arFields
     * @return array
     */
    public function getTemplateDataUserRegister($arFields){
        $result = $arFields;

        $result["SITE"]["ID"] = $arFields["SITE_ID"];
        $result["LINK"] = $this->get_site_url($arFields["SITE_ID"])."/bitrix/admin/user_edit.php?ID=".$arFields["USER_ID"];

        return $result;
    }

    /**
     * @param string $message
     * @param string $receivers
     * @param string $token
     * @return bool
     * @throws Exception
     */
    public function simple_message(string $message, string $receivers = '', string $token = ''): bool
    {
        if(!$token){
            $token = $this->getOption('token', '');
        }
        if(!$token){
            throw new Exception('Не найден токен');
        }

        if(!$receivers){
            $receivers = $this->getOption('chat_ids', '');
        }
        $receivers = trim($receivers);
        if(!$receivers){
            throw new Exception('Не найден получатель');
        }

        $receivers_array = explode(",", $receivers);
        if(!count($receivers_array)){
            throw new Exception('Не найден получатель');
        }
        foreach($receivers_array as $item_key => $item){
            $receivers_array[$item_key] = trim($item);
        }

        return (new Notification())->send($token, $receivers_array, $message);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit