Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/skyweb24.popuppro/lib/Service/Popup/ |
Upload File : |
<?php namespace Skyweb24\Popuppro\Service\Popup; use Bitrix\Main\Application; use DateTime; use Skyweb24\Popuppro\Abtest\Controller; use Skyweb24\Popuppro\Entity\PopupproTable; use Skyweb24\Popuppro\Service\Condition\ServiceCondition; class ServicePopup { /** * ��������, ����� ������� �������� ���� * @param array $options * @return array */ public static function getAvailablePopups(array $options): array { $res = PopupproTable::getList([ "select" => ["*"], "filter" => ["active" => "Y"], "order" => ["sort" => "asc"] ]); if (empty($_SESSION['skwb24_popuppro_afterTimeSecond'])) { $_SESSION['skwb24_popuppro_afterTimeSecond'] = time(); } $context = Application::getInstance()->getContext(); $request = $context->getRequest(); $httpType = ($request->isHttps()) ? 'https://' : 'http://'; $tmp = $_SERVER['HTTP_HOST']; $tmp = explode(':', $tmp); $tmp = $tmp[0]; $serverBase = $httpType . $tmp; $options['pageUrl'] = str_replace($serverBase, "", $options['pageUrl']); $popupsList = []; $retArr = []; $abtest = new Controller(); $options['domain'] = $tmp; while ($popup = $res->fetch()) { if (ServiceCondition::checkIfAvailable($popup['settings']['condition']['rule'], $options)) { $popupID = $popup['id']; $settings = $popup['settings']; $cCookie = $request->getCookie("skyweb24PopupFilling_" . $popupID); if (!empty($cCookie) && ( $settings["view"]["type"] == 'contact' || $settings["view"]["type"] == 'age' || $settings["view"]["type"] == 'roulette' || $settings["view"]["type"] == 'discount' || $settings["view"]["type"] == 'thimbles' ) ) { continue; } if ( (!empty($settings['timer']['enabled']) && $settings['timer']['enabled'] == "Y" && !empty($settings['timer']['date'])) || ($settings['timer']['daily'] == "Y" && !empty($settings['timer']['daily_time'])) ) { $format = 'd.m.Y H:i:s'; $newTimerDate = $settings['timer']['date']; if ($settings['timer']['daily'] == 'Y' && $settings['timer']['daily_time']) { $newTimerDate = date('d.m.Y') . ' ' . $settings['timer']['daily_time'] . ':00'; } $unixtime = DateTime::createFromFormat($format, $newTimerDate); if (time() > $unixtime->getTimestamp()) { continue; } } $settings['condition']['rule'] = self::resultGroup($settings['condition']['rule'], $options); // $retArr['pp' . $popupID] = $settings['condition']['rule']; $retArr[$popupID] = [ "id" => $popupID, "rule" => $settings['condition']['rule'] ]; } } $abtest->filter($retArr); return array_values($retArr); } /** * ���������� ���� ������� ������ ��������� ���� * @param $group * @param $option * @return mixed */ public static function resultGroup($group, $option) { if (!$group['children']) { return false; } foreach ($group['children'] as &$child) { if ($child['controlId'] == 'CondGroup') { $child = self::resultGroup($child, $option); } else if ($child['controlId'] == 'SITES') { $sitesRes = false; if (!empty($child['values']['value'])) { if (in_array('all', $child['values']['value']) || in_array($option['site'], $child['values']['value'])) { $sitesRes = true; } if ($child['values']['logic'] == 'Equal') { $result[] = $sitesRes; $child = $sitesRes; } else { $child[] = !$sitesRes; } } } else if ($child['controlId'] == 'AFTER_SHOW_COUNT_PAGES') { if ($child['values']['logic'] == 'more') { if ($child['values']['value'] <= $option['countPages']) { $child = true; } else { $child = false; } } else { if ($child['values']['value'] <= $option['countPages']) { $child = false; } else { $child = true; } } } else if ($child['controlId'] == 'AFTER_TIME_SECOND') { $child['values']['default_value'] = intval($child['values']['value']); // ??????? ??????? ?????? ?????? $child['values']['value'] = intval($child['values']['value']) - (time() - $_SESSION['skwb24_popuppro_afterTimeSecond']); // ??????? ??????? ?????? } else if ($child['controlId'] == 'USER_GROUP') { if (!empty($child['values']['value'])) { $userAccess = false; global $USER; if ( !$USER->IsAuthorized() && in_array('unregister', $child['values']['value']) ) { $userAccess = true; } else if ( in_array('firstvisit', $child['values']['value']) && !empty($_SESSION["SESS_GUEST_NEW"]) && $_SESSION["SESS_GUEST_NEW"] == 'Y' && empty($_SESSION['SKYWEB24_SESS_GUEST_NEW']) ) { $userAccess = true; } else { $cuserGroup = $USER->GetUserGroupArray(); $tmpIntersect = array_intersect($cuserGroup, $child['values']['value']); if (count($tmpIntersect) > 0) { $userAccess = true; } } if ($child['values']['logic'] == 'Equal') { $child = $userAccess; } else { $child = !$userAccess; } } } else if ($child['controlId'] == 'DATE') { $tmpDateRes = true; $dateStart = 0; $dateEnd = 0; if (!empty($child['values']['ValueStart'])) { $dateStart = DateTime::createFromFormat('d.m.Y H:i:s', $child['values']['ValueStart'] . ' 00:00:00'); $dateStart = $dateStart->getTimestamp(); } if (!empty($child['values']['ValueEnd'])) { $dateEnd = DateTime::createFromFormat('d.m.Y H:i:s', $child['values']['ValueEnd'] . ' 23:59:59'); $dateEnd = $dateEnd->getTimestamp(); } if ($dateStart != 0 && $dateStart >= $option['dateUser']) { $tmpDateRes = false; } if ($dateEnd != 0 && $dateEnd <= $option['dateUser']) { $tmpDateRes = false; } $child = $tmpDateRes; } else if ($child['controlId'] == 'SHOW_PAGE') { if ($child['values']['logic'] == 'Equal') { $showOnlyPath = false; $tmpShowOnly = trim($child['values']['value']); if (!empty($tmpShowOnly)) { if (strpos($tmpShowOnly, '*') !== false) { $pattern = '|^' . str_replace(['*', '?'], ['(.*)', '\?'], $tmpShowOnly) . '|'; if (preg_match($pattern, $option['pageUrl'], $matches) == 1) { $showOnlyPath = true; } } else if ($option['pageUrl'] == $tmpShowOnly) { $showOnlyPath = true; } } $child = $showOnlyPath; } else if ($child['values']['logic'] == 'Not') { $hideOnlyPath = false; $tmpHideOnly = trim($child['values']['value']); if (!empty($tmpHideOnly)) { if (strpos($tmpHideOnly, '*') !== false) { $pattern = '|^' . str_replace(['*', '?'], ['(.*)', '\?'], $tmpHideOnly) . '|'; if (preg_match($pattern, $option['pageUrl'], $matches) == 1) { $hideOnlyPath = true; } } else if ($option['pageUrl'] == $tmpHideOnly) { $hideOnlyPath = true; } } $child = !$hideOnlyPath; } } else if ($child['controlId'] == 'SHOW_DOMAIN') { $tmpRes = false; $tmpVal = trim($child['values']['value']); if (!empty($tmpVal)) { $tmpVal = str_replace(['/'], '', $tmpVal); $tmpVal = str_replace(['https:', 'http:'], ['', ''], $tmpVal); //$currentDomain = $_SERVER['HTTP_HOST']; $currentDomain = $_SERVER['SERVER_NAME']; if ($child['values']['logic'] == 'Equal' && $tmpVal == $currentDomain) { $tmpRes = true; } else if ($child['values']['logic'] == 'Not' && $tmpVal != $currentDomain) { $tmpRes = true; } } $child = $tmpRes; } } return $group; } }