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/skyweb24.popuppro/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/skyweb24.popuppro/lib/statistics.php
<?

namespace Skyweb24\Popuppro;

use Bitrix\Main\Mail\Event,
    Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);

class Statistics
{

    /**
     * @param int $idPopup id current popup
     * @param string $type type statistic:
     *    stat_show - popup is open,
     *    stat_action - in popup target action occurred,
     *    stat_time - popup close (set time show and type close)
     * @param array $request [
     *    int popupTime - popup show time (second),
     *    string closeType[
     *        closeWindow - the user close browser window
     *        closeByEsc - the user push escape key
     *        closeByTextButton the user click textButoon in popup
     *        closeByPopupIcon - the user click BX.PopupWindow.closeIcon
     *        closeByPopupOveray - - the user click in BX.PopupWindow.closeIcon
     *    ] - type of close popup,
     *    string site_url - domain name,
     *    string url - url where popup is show
     * ]
     */
    private $tableStat = 'skyweb24_popuppro_stat';

    public function __construct($popupId, $type, $request)
    {
        $this->id = $popupId;

        $detect = new Detectdevice;
        $this->os = $detect->getOS();
        $this->browser = $detect->getBrowser();
        $this->device = $detect->getDevice();
        $this->remoteIp = $_SERVER['REMOTE_ADDR'];

        if ($type == 'stat_show') {
            $this->openPopup($request);
        }
        elseif ($type == 'stat_action') {
            $this->setActionPopup($request);
        }
        elseif ($type == 'stat_time') {
            $this->setClosePopup($request);
        }

    }

    public function setClosePopup($request)
    {
        if(!filter_var("http://" . $request['url'], FILTER_VALIDATE_URL)) {
            return false;
        }

        $this->updateStatistic([
            'id_popup' => $this->id,
            'url' => $request['url'],
            'site_url' => $request['site_url'],
            'device' => $this->device,
            'os' => $this->os,
            'browser' => $this->browser,
            'ip' => $this->remoteIp,
            'show_time' => ($request['popupTime'] > 900) ? 900 : $request['popupTime'],
            'close_type' => $request['closeType'],
        ]);
        $this->removeCurrentStat();
    }

    public function setActionPopup($request)
    {
        $fields = [
            'id_popup' => $this->id,
            'device' => $this->device,
            'os' => $this->os,
            'browser' => $this->browser,
            'ip' => $this->remoteIp,
            'target_action' => "Y",
            "abtest_id" => \Skyweb24\Popuppro\Abtest\Controller::getAbTestUseId($this->id)
        ];
        if (!empty($request['url'])) {
            $fields['url'] = $request['url'];
        }
        if (!empty($request['url'])) {
            $fields['site_url'] = $request['site_url'];
        }

        if(!empty($fields['site_url'])) {
            if(!filter_var("http://" . $fields['site_url'], FILTER_VALIDATE_URL)) {
                return false;
            }
        }

        if(!empty($fields['url'])) {
            if(!filter_var("http://" . $fields['url'], FILTER_VALIDATE_URL)) {
                return false;
            }
        }

        if(empty($fields['url'])) {
            return false;
        }

        $this->updateStatistic($fields);
    }

    public function openPopup($request)
    {
        if(!filter_var("http://" . $request['url'], FILTER_VALIDATE_URL)) {
            return false;
        }

        $res = \Skyweb24\Popuppro\Entity\StatTable::add([
            'id_popup' => $this->id,
            'url' => $request['url'],
            'site_url' => $request['site_url'],
            'device' => $this->device,
            'os' => $this->os,
            'browser' => $this->browser,
            'ip' => $this->remoteIp,
            'abtest_id' => \Skyweb24\Popuppro\Abtest\Controller::getAbTestUseId($this->id)
        ]);
        $this->setCurrentStat($res->getId());
    }

    private function setCurrentStat($id)
    {
        $_SESSION['sw24PopupCurrentStatId'] = $id;
    }

    private function getCurrentStat()
    {
        return empty($_SESSION['sw24PopupCurrentStatId']) ? 0 : $_SESSION['sw24PopupCurrentStatId'];
    }

    private function removeCurrentStat()
    {
        unset($_SESSION['sw24PopupCurrentStatId']);
    }

    private function updateStatistic($fields)
    {
        switch ($fields["close_type"]) {
            case "closeByPopupIcon":
            case "closeWindow":
            case "closeTargetAction":
            case "closeByPopupOveray":
            case "closeByEsc":
            case "":
                $trigger = true;
                break;
        }
        if($trigger) {
            $currentStatId = $this->getCurrentStat();
            if ($currentStatId == 0) {
                \Skyweb24\Popuppro\Entity\StatTable::add($fields);
            } else {
                \Skyweb24\Popuppro\Entity\StatTable::update($currentStatId, $fields);
            }
        }
    }

    public function reset(){

        $arStatisticIds = [];
        $rsStatisticItems = \Skyweb24\Popuppro\Entity\StatTable::getList([
            "select" => [
                "id"
            ],
            "filter" => [
                "id_popup" => $this->id
            ]
        ]);

        while ($arStatisticItem = $rsStatisticItems->fetch())
        {
            array_push($arStatisticIds, $arStatisticItem['id']);
        }

         \Skyweb24\Popuppro\Entity\PopupproTable::update($this->id, [
             "stat_show" => 0,
             "stat_time" => 0,
             "stat_action" => 0
         ]);
        return \Skyweb24\Popuppro\Entity\StatTable::deleteGroupById($arStatisticIds);

    }

    public function getStatDevice($id)
    {
        global $DB;
        $table = $this->tableStat;

        $result = $DB->Query("SELECT `device`, COUNT(`device`) AS `count`
                        FROM `{$table}`
                        WHERE `id_popup` = '{$id}'
                        GROUP BY `device`");
        while ($row = $result->Fetch()) {
            $rows[$row['device']] = $row['count'];
        }
        return $rows;
    }

    public function getStatClose($id)
    {
        global $DB;
        $table = $this->tableStat;
        $result = $DB->Query("SELECT `close_type`, COUNT(`close_type`) AS `count`
                    FROM `{$table}`
                    WHERE `id_popup` = '{$id}'
                    GROUP BY `close_type`");

        while ($row = $result->Fetch()) {
            $rows[$row['close_type']] = $row['count'];
        }
        return $rows;
    }

    public function getStatActivePage($sort = "shows_popup")
    {
        global $DB;
        $arResult = [];
        $result = $DB->Query(
            "select
            count(url) as shows_popup,
            count(CASE WHEN target_action='Y' THEN 1 ELSE NULL END) as target,
            url,
            id_popup,
            (count(CASE WHEN target_action='Y' THEN 1 ELSE NULL END) / count(url)) * 100  as conversion
            from " . $this->tableStat . "
            where url is not null and url != ''AND id_popup = {$this->id}
            group by url
            order by {$sort} desc
            LIMIT 10"
        );

        while ($row = $result->Fetch()) {
            $arResult[] = $row;
        }
        return $arResult;
    }

    public function getStatActive($id, $type = "hour")
    {
        global $DB;
        $table = $this->tableStat;
        $arResult = [];

        if ($type == "hour") {
            $result = $DB->Query(
                "SELECT DATE_FORMAT(`date`, '%H') as `date`,
                COUNT(`show_time`) as `time`
                FROM `{$table}`
                WHERE `id_popup` = '{$id}'
                GROUP BY DATE_FORMAT(`date`, '%H')
                ORDER BY DATE_FORMAT(`date`, '%H') ASC"
            );

            while ($row = $result->Fetch()) {
                $arResult[$row['date']] = $row['time'];
            }

            if ($arResult) {
                $arDateHour = [];

                for ($i = 0; $i <= 24; $i++) {
                    $arDateHour[$i]["showTime"] = 0;
                }

                foreach ($arResult as $key => $value) {
                    $arDateHour[(int)$key]["showTime"] = $value;
                }
                return $arDateHour;
            }
            return false;


        }
        else {
            $result = $DB->Query(
                "SELECT DATE_FORMAT(`date`, '%a') as `date`,
                COUNT(`show_time`) as `time`
                FROM `{$table}`
                WHERE `id_popup` = '{$id}'
                GROUP BY DATE_FORMAT(`date`, '%a')
                ORDER BY DATE_FORMAT(`date`, '%a') ASC"
            );

            while ($row = $result->Fetch()) {
                $arResult[$row['date']] = $row['time'];
            }

            if ($arResult) {
                $arDateDay = [
                    1 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_MONDAY'),
                        "showTime" => 0
                    ],
                    2 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_TUESDAY'),
                        "showTime" => 0
                    ],
                    3 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_WEDNESDAY'),
                        "showTime" => 0
                    ],
                    4 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_THURSDAY'),
                        "showTime" => 0
                    ],
                    5 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_FRIDAY'),
                        "showTime" => 0
                    ],
                    6 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_SATURDAY'),
                        "showTime" => 0
                    ],
                    7 => [
                        "day" => GetMessage('skyweb24.popuppro_DAY_SUNDAY'),
                        "showTime" => 0
                    ],
                ];
                foreach ($arResult as $key => $value) {

                    $numberDay = date("N", strtotime($key));
                    $arDateDay[$numberDay]['showTime'] = $value;
                }

                return $arDateDay;
            }

            return false;

        }

    }

    public static function getAbTestStatistic($abTestId, $popupIds)
    {

        $arResult['stat_conversion'] = self::getAbTestConversion($abTestId, $popupIds);
        $arResult['stat_close_type'] = self::getAbTestCloseType($abTestId, $popupIds);

        return $arResult;
    }

    public static function getAbTestConversion($abTestId, $popupIds, $format = true)
    {
        $arResult = [];
        $res = \Skyweb24\Popuppro\Entity\StatTable::getList([
            "select" => [
                "id_popup",
                new \Bitrix\Main\Entity\ExpressionField('count_show', 'COUNT(%s)', ["id_popup"]),
                "target_action",
                new \Bitrix\Main\Entity\ExpressionField('count_target_action', 'COUNT(%s)', ["target_action"]),
            ],
            "filter" => [
                "abtest_id" => $abTestId,
                "id_popup" => [
                    $popupIds['A'],
                    $popupIds['B']
                ]
            ],
            "group" => [
                "target_action",
                "id_popup"
            ]
        ]);

        while ($row = $res->fetch())
        {
            if($row['target_action'] == "Y")
            {
                $arResult[$row['id_popup']]['count_target_action'] += $row['count_target_action'];
            }
            $arResult[$row['id_popup']]['count_show'] += $row['count_show'];
        }


        if($format)
        {
            $arResultFormat = [];
            foreach ($arResult as $popupId => $popup) {
                $arResultFormat[$popupId] = [
                    [
                        "title" => Loc::getMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CONVERSION_COUNT_SHOW"),
                        "value" => $popup['count_show']
                    ],
                    [
                        "title" => Loc::getMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CONVERSION_COUNT_TARGET_ACTION"),
                        "value" => $popup['count_target_action']
                    ]
                ];
            }
            return $arResultFormat;
        }

        return $arResult ?: [];
    }

    public static function getAbTestCloseType($abTestId, $popupIds, $format = true)
    {
        $arResult = [];
        $res = \Skyweb24\Popuppro\Entity\StatTable::getList([
            "select" => [
                "id_popup",
                "close_type",
                new \Bitrix\Main\Entity\ExpressionField('count_close_type', 'COUNT(%s)', ["close_type"]),
            ],
            "filter" => [
                "abtest_id" => $abTestId,
                "!close_type" => false,
                "id_popup" => [ $popupIds['A'], $popupIds['B'] ]
            ],
            "group" => [
                "id_popup",
            ]
        ]);

        while ($row = $res->fetch())
        {
            $arResult[$row['id_popup']][] = [
                "title" => $row['close_type'],
                "value" => $row['count_close_type']
            ];
        }

        if($format)
        {
            $arResultFormat = [];
            foreach ($arResult as $popupId => $types) {
                foreach ($types as $type) {
                    $title = "";
                    switch ($type['title']) {
                        case "closeByPopupOveray":
                            $title = GetMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CLOSE_BY_POPUP_OVERLAY");
                            break;
                        case "closeWindow":
                            $title = loc::getMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CLOSE_WINDOW");
                            break;
                        case "closeByPopupIcon":
                            $title = loc::getMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CLOSE_BY_POPUP_ICON");
                            break;
                        case "closeByEsc":
                            $title = GetMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CLOSE_BY_ESC");
                            break;
                        case "closeByTextButton":
                            $title = GetMessage("SKYWEB24_POPUPPRO_ABTEST_REPORT_CLOSE_BY_TEXT_BUTTON");
                            break;
                    }
                    $arResultFormat[$popupId][] = [
                        "title" => $title,
                        "value" => $type['value']
                    ];
                }
            }
            return $arResultFormat;
        }

        return $arResult ?: [];
    }

}

?>

Youez - 2016 - github.com/yon3zu
LinuXploit