Advertisement
Gistrec

Редиректы в highload блоке

Jul 25th, 2018
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. // init.php
  2.  
  3. $redirectHlblock = Bitrix\Highloadblock\HighloadBlockTable::getById(3)->fetch();
  4. $redirectEntity = Bitrix\Highloadblock\HighloadBlockTable::compileEntity($redirectHlblock);
  5. $redirectClass = $redirectEntity->getDataClass();
  6.  
  7. // Редиректы
  8. $redirectData = $redirectClass::getList(
  9.     array(
  10.     "select" => array("*"),
  11.     "filter" => array(
  12.         'UF_SITE_ID'  => SITE_ID,
  13.         'UF_URL_FROM' => $APPLICATION->GetCurPage(false),
  14.         '>UF_ACTIVE'  => 0,
  15.         )
  16.     )
  17. )->fetch();
  18.  
  19. if (isset($redirectData['UF_URL_TO']) && !empty($redirectData['UF_URL_TO'])) {
  20.     $status = CUserFieldEnum::GetList(array(), array('ID' => $redirectData['UF_STATUS']))->fetch();
  21.     LocalRedirect($redirectData['UF_URL_TO'], true, $status['VALUE']);
  22. }
  23.  
  24. // Подмена URL
  25. $replaceData = $redirectClass::getList(
  26.     array(
  27.     "select" => array("*"),
  28.     "filter" => array(
  29.         'UF_SITE_ID' => SITE_ID,
  30.         'UF_URL_TO'  => $APPLICATION->GetCurPage(false),
  31.         '>UF_ACTIVE' => 0,
  32.         )
  33.     )
  34. )->fetch();
  35. if ($replaceData) {
  36.     $context  = Bitrix\Main\Application::getInstance()->getContext();
  37.     $server   = $context->getServer();
  38.     $arServer = $server->toArray();
  39.  
  40.     $_SERVER['REQUEST_URI'] = $replaceData['UF_URL_FROM'];
  41.     $arServer['REQUEST_URI'] = $replaceData['UF_URL_FROM'];
  42.     $server->set($arServer);
  43.     $context->initialize(
  44.         new Bitrix\Main\HttpRequest($server, array() , array() , array() , $_COOKIE),
  45.         $context->getResponse(),
  46.         $server
  47.     );
  48.     $APPLICATION->reinitPath();
  49.     define('INCLUDE_CATALOG_INDEX', true);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement