D
D
dev4002016-07-04 17:37:23
PHP
dev400, 2016-07-04 17:37:23

Hauling a template of standard Bitrix components?

How to deal with this crap? (catalogue component template)
Already my hands are shaking)) and my head hurts. Maybe there is some normal way to edit? Without the visibility of Bitrix elements, etc., so that everything is on point

<?
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true)
  die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);

$arViewModeList = $arResult['VIEW_MODE_LIST'];

$arViewStyles = array(
  'LIST' => array(
    'CONT' => 'bx_sitemap',
    'TITLE' => 'bx_sitemap_title',
    'LIST' => 'bx_sitemap_ul'
  ),
  'LINE' => array(
    'CONT' => 'bx_catalog_line',
    'TITLE' => 'bx_catalog_line_category_title',
    'LIST' => 'bx_catalog_line_ul',
    'EMPTY_IMG' => $this->GetFolder() . '/images/line-empty.png'
  ),
  'TEXT' => array(
    'CONT' => 'bx_catalog_text',
    'TITLE' => 'bx_catalog_text_category_title',
    'LIST' => 'bx_catalog_text_ul'
  ),
  'TILE' => array(
    'CONT' => 'bx_catalog_tile',
    'TITLE' => 'bx_catalog_tile_category_title',
    'LIST' => 'bx_catalog_tile_ul',
    'EMPTY_IMG' => $this->GetFolder() . '/images/tile-empty.png'
  )
);
$arCurView    = $arViewStyles[$arParams['VIEW_MODE']];

$strSectionEdit        = CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "SECTION_EDIT");
$strSectionDelete      = CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "SECTION_DELETE");
$arSectionDeleteParams = array(
  "CONFIRM" => GetMessage('CT_BCSL_ELEMENT_DELETE_CONFIRM')
);

?><div class="<?
echo $arCurView['CONT'];
?>"><?
  if ('Y' == $arParams['SHOW_PARENT_NAME'] && 0 < $arResult['SECTION']['ID']) {
    $this->AddEditAction($arResult['SECTION']['ID'], $arResult['SECTION']['EDIT_LINK'], $strSectionEdit);
    $this->AddDeleteAction($arResult['SECTION']['ID'], $arResult['SECTION']['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);

    ?><h1
    class="<?
    echo $arCurView['TITLE'];
    ?>"
    id="<?
    echo $this->GetEditAreaId($arResult['SECTION']['ID']);
    ?>"
    ><a href="<?
    echo $arResult['SECTION']['SECTION_PAGE_URL'];
    ?>"><?
      echo (isset($arResult['SECTION']["IPROPERTY_VALUES"]["SECTION_PAGE_TITLE"]) && $arResult['SECTION']["IPROPERTY_VALUES"]["SECTION_PAGE_TITLE"] != "" ? $arResult['SECTION']["IPROPERTY_VALUES"]["SECTION_PAGE_TITLE"] : $arResult['SECTION']['NAME']);
      ?></a></h1><?
  }
  if (0 < $arResult["SECTIONS_COUNT"]) {
    ?>
    <ul class="<?
    echo $arCurView['LIST'];
    ?>">
      <?
      switch ($arParams['VIEW_MODE']) {
      case 'LINE':
        foreach ($arResult['SECTIONS'] as &$arSection) {
          $this->AddEditAction($arSection['ID'], $arSection['EDIT_LINK'], $strSectionEdit);
          $this->AddDeleteAction($arSection['ID'], $arSection['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);

          if (false === $arSection['PICTURE'])
            $arSection['PICTURE'] = array(
              'SRC' => $arCurView['EMPTY_IMG'],
              'ALT' => ('' != $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_ALT"] ? $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_ALT"] : $arSection["NAME"]),
              'TITLE' => ('' != $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_TITLE"] ? $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_TITLE"] : $arSection["NAME"])
            );
          ?><li id="<?
          echo $this->GetEditAreaId($arSection['ID']);
          ?>">
          <a
            href="<?
            echo $arSection['SECTION_PAGE_URL'];
            ?>"
            class="bx_catalog_line_img"
            style="background-image: url('<?
            echo $arSection['PICTURE']['SRC'];
            ?>');"
            title="<?
            echo $arSection['PICTURE']['TITLE'];
            ?>"
          ></a>
          <h2 class="bx_catalog_line_title"><a href="<?
            echo $arSection['SECTION_PAGE_URL'];
            ?>"><?
              echo $arSection['NAME'];
              ?></a><?
            if ($arParams["COUNT_ELEMENTS"]) {
              ?> <span>(<?
              echo $arSection['ELEMENT_CNT'];
              ?>)</span><?
            }
            ?></h2><?
          if ('' != $arSection['DESCRIPTION']) {
            ?><p class="bx_catalog_line_description"><?
            echo $arSection['DESCRIPTION'];
            ?></p><?
          }
          ?><div style="clear: both;"></div>
          </li><?
        }
        unset($arSection);
        break;
      case 'TEXT':
        foreach ($arResult['SECTIONS'] as &$arSection) {
          $this->AddEditAction($arSection['ID'], $arSection['EDIT_LINK'], $strSectionEdit);
          $this->AddDeleteAction($arSection['ID'], $arSection['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);

          ?><li id="<?
          echo $this->GetEditAreaId($arSection['ID']);
          ?>"><h2 class="bx_catalog_text_title"><a href="<?
            echo $arSection['SECTION_PAGE_URL'];
            ?>"><?
              echo $arSection['NAME'];
              ?></a><?
            if ($arParams["COUNT_ELEMENTS"]) {
              ?> <span>(<?
              echo $arSection['ELEMENT_CNT'];
              ?>)</span><?
            }
            ?></h2></li><?
        }
        unset($arSection);
        break;
      case 'TILE':
        foreach ($arResult['SECTIONS'] as &$arSection) {
          $this->AddEditAction($arSection['ID'], $arSection['EDIT_LINK'], $strSectionEdit);
          $this->AddDeleteAction($arSection['ID'], $arSection['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);

          if (false === $arSection['PICTURE'])
            $arSection['PICTURE'] = array(
              'SRC' => $arCurView['EMPTY_IMG'],
              'ALT' => ('' != $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_ALT"] ? $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_ALT"] : $arSection["NAME"]),
              'TITLE' => ('' != $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_TITLE"] ? $arSection["IPROPERTY_VALUES"]["SECTION_PICTURE_FILE_TITLE"] : $arSection["NAME"])
            );
          ?><li id="<?
          echo $this->GetEditAreaId($arSection['ID']);
          ?>">
        <a
          href="<?
          echo $arSection['SECTION_PAGE_URL'];
          ?>"
          class="bx_catalog_tile_img"
          style="background-image:url('<?
          echo $arSection['PICTURE']['SRC'];
          ?>');"
          title="<?
          echo $arSection['PICTURE']['TITLE'];
          ?>"
        > </a><?
          if ('Y' != $arParams['HIDE_SECTION_NAME']) {
            ?><h2 class="bx_catalog_tile_title"><a href="<?
            echo $arSection['SECTION_PAGE_URL'];
            ?>"><?
            echo $arSection['NAME'];
            ?></a><?
            if ($arParams["COUNT_ELEMENTS"]) {
              ?> <span>(<?
              echo $arSection['ELEMENT_CNT'];
              ?>)</span><?
            }
            ?></h2><?
          }
          ?></li><?
        }
        unset($arSection);
        break;
      case 'LIST':
      $intCurrentDepth = 1;
      $boolFirst       = true;
      foreach ($arResult['SECTIONS'] as &$arSection) {
      $this->AddEditAction($arSection['ID'], $arSection['EDIT_LINK'], $strSectionEdit);
      $this->AddDeleteAction($arSection['ID'], $arSection['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);

      if ($intCurrentDepth < $arSection['RELATIVE_DEPTH_LEVEL']) {
        if (0 < $intCurrentDepth)
          echo "\n", str_repeat("\t", $arSection['RELATIVE_DEPTH_LEVEL']), '<ul>';
      } elseif ($intCurrentDepth == $arSection['RELATIVE_DEPTH_LEVEL']) {
        if (!$boolFirst)
          echo '</li>';
      } else {
        while ($intCurrentDepth > $arSection['RELATIVE_DEPTH_LEVEL']) {
          echo '</li>', "\n", str_repeat("\t", $intCurrentDepth), '</ul>', "\n", str_repeat("\t", $intCurrentDepth - 1);
          $intCurrentDepth--;
        }
        echo str_repeat("\t", $intCurrentDepth - 1), '</li>';
      }

      echo (!$boolFirst ? "\n" : ''), str_repeat("\t", $arSection['RELATIVE_DEPTH_LEVEL']);
      ?><li id="<?= $this->GetEditAreaId($arSection['ID']); ?>"><h2 class="bx_sitemap_li_title"><a href="<?
          echo $arSection["SECTION_PAGE_URL"];
          ?>"><?
            echo $arSection["NAME"];
            ?><?
            if ($arParams["COUNT_ELEMENTS"]) {
              ?> <span>(<?
              echo $arSection["ELEMENT_CNT"];
              ?>)</span><?
            }
            ?></a></h2><?

        $intCurrentDepth = $arSection['RELATIVE_DEPTH_LEVEL'];
        $boolFirst       = false;
        }
        unset($arSection);
        while ($intCurrentDepth > 1) {
          echo '</li>', "\n", str_repeat("\t", $intCurrentDepth), '</ul>', "\n", str_repeat("\t", $intCurrentDepth - 1);
          $intCurrentDepth--;
        }
        if ($intCurrentDepth > 0) {
          echo '</li>', "\n";
        }
        break;
        }
        ?>
    </ul>
    <?
    echo ('LINE' != $arParams['VIEW_MODE'] ? '<div style="clear: both;"></div>' : '');
  }
  ?></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-07-04
@dev400

To successfully complete the task, you need knowledge of php, logic, dexterity, patience.
Change the code, see the result in the browser. Pull the layout on Bitrix a couple of dozen times and you will be like a fish in water.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question