라이믹스에서 리스트에서 글본문 중 설문조사 영역이 노출 안되는 문제가 궁금합니다.
리스트에서 본문 내용을 출력하게 했는데요.
설문조사는 동작을 안하던데 이건 어떻게 해야 나오는지 혹시 아시는 분 계실까요?
{$document->getContent(false)}
이렇게 하면 글 본문 텍스트는 출력되는데 설문조사는 안나오네요 ㅠ
사용한 코드
@php
$maxLength = 350;
if(mb_strlen(strip_tags($document->getContent(false))) > $maxLength){
// $content = preg_replace('/<img[^>]*>/', '', $document->variables['content']);
// $shortContent = mb_substr($content, 0, $maxLength) . '...';
$fullUrl = getUrl('document_srl', $document->document_srl); // 문서의 URL 생성
$content = $document->getSummary($maxLength);
$content .= " <a href='" . $fullUrl . "' class='read-more'>더보기</a>";
echo $content;
}else{
// echo '이하';
$content = preg_replace('/<img[^>]*>/', '', $document->variables['content']);
// echo $document->getContent(false);
echo $content;
}
@endphp
@if($document->getUploadedFiles())
<div class="img-box">
@foreach($document->getUploadedFiles() as $key => $file)
<img src="{$file->uploaded_filename}">
@php
$path = pathinfo($file->source_filename);
$ext = strtolower($path['extension']);
@endphp
@endforeach
</div>
@endif
{!! $document->getContent(false) !!}
이렇게 하면 나오네요. 대신 설문조사가 있으니 답글 작성 버튼이 안 먹히네요.
#버그
일반이미지
<img src="/files/attach/images/2025/02/03/2e00d24f27eaa491f1b16480dbac8674.jpg" style="width: auto;" class="fr-fic fr-dii">
설문조사 컴포넌트
<img src="../../../../common/img/blank.gif" poll_srl="472053" editor_component="poll_maker" skin="default" style="width: 400px; height: 300px; border: 2px dotted rgb(67, 113, 185); background: url('./modules/editor/components/poll_maker/tpl/poll_maker_component.gif') center center no-repeat;" class="fr-fil fr-dib">
@php $maxLength = 350; if(mb_strlen(strip_tags($document->getContent(false))) > $maxLength){ // $content = preg_replace('/<img[^>]*>/', '', $document->variables['content']); // $shortContent = mb_substr($content, 0, $maxLength) . '...'; $fullUrl = getUrl('document_srl', $document->document_srl); // 문서의 URL 생성 $content = $document->getSummary($maxLength); $content .= " <a href='" . $fullUrl . "' class='read-more'>더보기</a>"; echo $content; }else{ // echo '이하'; // $content = preg_replace('/<p><br><\/p>/', '', $document->variables['content']); $content = preg_replace('/<img[^>]*>/', '', $document->variables['content']); $content = preg_replace('/<br\s*\/?>/i', '', $content); // echo $document->getContent(false); echo $content; } @endphp
라이믹스에서 본문 글을 출력하지 않고 별도의 칸에 출력하게 해주고 있어.
그런데 문제는 설문조사도 동일한 img 태그로 시작한다는거지.
1) 일반이미지
<img src="/files/attach/images/2025/02/03/2e00d24f27eaa491f1b16480dbac8674.jpg" style="width: auto;" class="fr-fic fr-dii">
2) 설문조사 컴포넌트
<img src="../../../../common/img/blank.gif" poll_srl="472053" editor_component="poll_maker" skin="default" style="width: 400px; height: 300px; border: 2px dotted rgb(67, 113, 185); background: url('./modules/editor/components/poll_maker/tpl/poll_maker_component.gif') center center no-repeat;" class="fr-fil fr-dib">
이런 차이가 있어. 설문조사 컴포넌트에서는 editor_component라는 값이 있는데 이 값이 있으면 제외하지 않고, 딱 일반이미지인 경우만 컨텐츠에서 제외해서 출력하도록 해주고 싶어.
기존 코드에서 이미지를 제거하는 부분이 있어.. 수정함.
@php $maxLength = 300; // 본문 텍스트의 최대 길이 // 문서의 본문 내용 $content = $document->variables['content']; // 설문조사 이미지가 포함된 부분을 찾아서 $survey에 저장 $survey = ''; if (preg_match_all('/<img[^>]*\beditor_component="poll_maker"[^>]*>/i', $content, $matches)) { $survey = implode('', $matches[0]); } // 본문에서 설문조사 이미지 제거 $contentWithoutSurveyImages = preg_replace('/<img[^>]*\beditor_component="poll_maker"[^>]*>/i', '', $content); // 본문 내용이 300자보다 길면 자르고 '더보기' 링크 추가 $shortContent = mb_substr(strip_tags($contentWithoutSurveyImages), 0, $maxLength); if (mb_strlen(strip_tags($contentWithoutSurveyImages)) > $maxLength) { $fullUrl = getUrl('document_srl', $document->document_srl); // 문서의 URL 생성 $shortContent .= " <a href='" . $fullUrl . "' class='read-more'>더보기</a>"; } // 설문조사만 포함된 경우 (이미지 태그만 존재) $imgOnly = !empty($survey) && empty(strip_tags($contentWithoutSurveyImages)); // 본문과 설문조사 이미지 또는 이미지 목록을 나누어 출력 if ($imgOnly) { // 이미지 태그만 있는 경우 echo "<div class='content-text'>" . $shortContent . "</div>"; echo "<div class='survey-images' onclick='event.stopPropagation();'>" . $survey . "</div>"; } else { // 본문이 있고 설문조사가 있는 경우 if (!empty($survey)) { // 본문과 설문조사를 분리해서 출력 echo "<div class='content-text'>" . $shortContent . "</div>"; echo "<div class='survey-images' onclick='event.stopPropagation();'>" . $survey . "</div>"; } else { // 본문만 출력 echo "<div class='content-text'>" . $shortContent . "</div>"; } // 설문조사가 없는 경우에만 이미지를 출력 $uploadfiles = $document->getUploadedFiles(); if ($uploadfiles !== null && is_array($uploadfiles)) { $filecount = count($uploadfiles); if ($filecount == 1 && empty($survey)) { // 이미지가 1개일 경우 썸네일 출력 (설문조사 없는 경우) $thumbnail = $document->getThumbnail(230, 230, 'fill'); echo "<div class='img-box'><img src='" . $thumbnail . "' alt='thumbnail'></div>"; } elseif ($filecount > 1 && empty($survey)) { // 이미지가 여러개일 경우 이미지 출력 (설문조사 없는 경우) echo "<div class='img-box'>"; foreach ($uploadfiles as $key => $file) { if (strpos($file->mime_type, 'image/') === 0) { echo "<img src='" . $file->uploaded_filename . "' alt='image'>"; } } echo "</div>"; } } } @endphp