A
A
Aili2019-11-11 19:12:22
1C-Bitrix
Aili, 2019-11-11 19:12:22

Bitrix: how to process all images in the detailed description of an element?

Hello. I need to process images in item detail.
But somehow the code does not work (the code was written in result_modifier.php), apparently at the stage of the last str_replace.
And how to make it work, I don’t understand :( Help, please.

foreach($arResult["ITEMS"] as $arItem)
{
$patternSRC="/[^>]+src=(\"|')(.+?)(\"|')[^>]*>/si";
$pattern2="/(alt|src|title)=(\"|')(.+?)(\"|')/si";
$pattern="/<img([^>]*)\/?>/si";
preg_match_all($pattern,$arItem['DETAIL_TEXT'],$matches);
$modifiedImages=array();
foreach($matches[1] as $k=>$image){
    preg_match_all($pattern2,$image,$Attrmatches);
    $attributes=array();
    foreach($Attrmatches[1] as $kT=>$Tmp){
     $attributes[$Tmp]=$Attrmatches[3][$kT];
    }
    $modifiedImages[$matches[0][$k]]=$attributes;
}
$arItem['DETAIL_TEXT']=str_replace(SITE_SERVER_NAME,"",$arItem['DETAIL_TEXT']);
$arItem['DETAIL_TEXT']=str_replace(str_replace("http://","http://www.",SITE_SERVER_NAME),"",$arItem['DETAIL_TEXT']);
foreach ($modifiedImages as $image=>$attributes) {
    $imgSrc='<a class="fancy" href="'.$attributes["src"].'" title="'.$attributes["title"].'" >';
    $imgSrc.=CFile::ShowImage($attributes["src"], 300, 300, "alt='".$attributes["alt"]."' title='".$attributes["title"]."'  style='float:margin: 5px;'", "", false);
    $imgSrc.="</a>";
    $arItem['DETAIL_TEXT']=str_replace($image,$imgSrc,$arItem['DETAIL_TEXT']);
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question