view.skin.php 뷰페이지에서 본문 링크제거. 이미지 링크는 예외
그누보드5 순정 basic 게시판 기준입니다.
정규식으로 간단하게도 할수 있는데 외부에서 불러온 코드나 html 직접 작성 코드때문에
좀 더 확실하게 반영한 버전 입니다.
뷰페이지에서 a 태그를 찾고 href 링크를 제거합니다. (css 밑줄도 제거)
에디터에서 이미지를 넣을 경우 새창보기 등에 사용된 view_image 클래스의 링크는 제거 하지 않습니다.
view.skin.php 에서 아래 코드를 찾습니다.
[code]
<!-- 본문 내용 시작 { -->
<div id="bo_v_con"><?php echo get_view_thumbnail($view['content']); ?></div>
<?php //echo $view['rich_content']; // {이미지:0} 과 같은 코드를 사용할 경우 ?>
<!-- } 본문 내용 끝 -->
[/code]
그리고 아래 코드를 다음과 같이 변경합니다.
[code]
<?php
// 본문 내용 가져오기
$adp_content = get_view_thumbnail($view['content']);
// DOMDocument를 사용하여 HTML 파싱
$adp_dom = new DOMDocument();
// HTML5 호환성과 한글 깨짐 방지를 위한 설정
libxml_use_internal_errors(true);
$adp_dom->loadHTML('<?xml encoding="utf-8" ?>' . $adp_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
// 모든 a 태그 찾기
$adp_aTags = $adp_dom->getElementsByTagName('a');
// a 태그를 배열로 변환
$adp_aTagsArray = [];
foreach ($adp_aTags as $adp_aTag) {
$adp_aTagsArray[] = $adp_aTag;
}
// 각 a 태그 처리
foreach ($adp_aTagsArray as $adp_aTag) {
$adp_class = $adp_aTag->getAttribute('class');
// view_image 클래스가 없는 a 태그에서만 href 제거
if (strpos($adp_class, 'view_image') === false) {
$adp_aTag->removeAttribute('href');
// 기존 style 속성 가져오기
$adp_existingStyle = $adp_aTag->getAttribute('style');
$adp_newStyle = $adp_existingStyle;
// text-decoration: none 추가
if (!empty($adp_existingStyle)) {
$adp_newStyle = rtrim($adp_existingStyle, '; ') . '; text-decoration: none !important;';
} else {
$adp_newStyle = 'text-decoration: none !important;';
}
$adp_aTag->setAttribute('style', $adp_newStyle);
}
}
// 수정된 HTML 출력
$adp_modifiedContent = $adp_dom->saveHTML();
// XML 선언 제거 (필요한 경우)
$adp_modifiedContent = preg_replace('/^<\?xml[^>]*\?>/', '', $adp_modifiedContent);
?>
[/code]
추가로 게시판 설정의 여분필드 bo_1 에 1 입력시에만 작동하게 할수도 있습니다.
1 입력시 적용. 공백으로 두시면 순정 그대로 작동합니다.

[code]
<?php if(isset($board['bo_1']) && $board['bo_1']){ // 게시판 설정의 여분필드 bo_1 값이 있다면 ?>
<?php
// 본문 내용 가져오기
$adp_content = get_view_thumbnail($view['content']);
// DOMDocument를 사용하여 HTML 파싱
$adp_dom = new DOMDocument();
// HTML5 호환성과 한글 깨짐 방지를 위한 설정
libxml_use_internal_errors(true);
$adp_dom->loadHTML('<?xml encoding="utf-8" ?>' . $adp_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
// 모든 a 태그 찾기
$adp_aTags = $adp_dom->getElementsByTagName('a');
// a 태그를 배열로 변환
$adp_aTagsArray = [];
foreach ($adp_aTags as $adp_aTag) {
$adp_aTagsArray[] = $adp_aTag;
}
// 각 a 태그 처리
foreach ($adp_aTagsArray as $adp_aTag) {
$adp_class = $adp_aTag->getAttribute('class');
// view_image 클래스가 없는 a 태그에서만 href 제거
if (strpos($adp_class, 'view_image') === false) {
$adp_aTag->removeAttribute('href');
// 기존 style 속성 가져오기
$adp_existingStyle = $adp_aTag->getAttribute('style');
$adp_newStyle = $adp_existingStyle;
// text-decoration: none 추가
if (!empty($adp_existingStyle)) {
$adp_newStyle = rtrim($adp_existingStyle, '; ') . '; text-decoration: none !important;';
} else {
$adp_newStyle = 'text-decoration: none !important;';
}
$adp_aTag->setAttribute('style', $adp_newStyle);
}
}
// 수정된 HTML 출력
$adp_modifiedContent = $adp_dom->saveHTML();
// XML 선언 제거 (필요한 경우)
$adp_modifiedContent = preg_replace('/^<\?xml[^>]*\?>/', '', $adp_modifiedContent);
?>
<?php } else { ?>
<!-- 본문 내용 시작 { -->
<div id="bo_v_con"><?php echo get_view_thumbnail($view['content']); ?></div>
<?php //echo $view['rich_content']; // 과 같은 코드를 사용할 경우 ?>
<!-- } 본문 내용 끝 -->
<?php } ?>
[/code]
댓글 5개
감사합니다
좋은 소스 감사합니다~
관리자는 게시판 별로 on, off 가 가능한 기능이 있다면 좋을것같네요
@데코이 게시판 설정의 여분필드로 on/off 할수 있게 추가했습니다.
@애드프로 와 이렇게나 빨리 감사합니다~
감사합니다 ^^
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4415 | ||
| 2484 | 1년 전 | 1264 | ||
| 2483 | 1년 전 | 865 | ||
| 2482 | 1년 전 | 715 | ||
| 2481 | 1년 전 | 1085 | ||
| 2480 | 1년 전 | 1185 | ||
| 2479 | 1년 전 | 841 | ||
| 2478 | 1년 전 | 1177 | ||
| 2477 | 1년 전 | 780 | ||
| 2476 | 1년 전 | 1587 | ||
| 2475 | 1년 전 | 924 | ||
| 2474 |
|
1년 전 | 935 | |
| 2473 | 1년 전 | 1522 | ||
| 2472 | 1년 전 | 861 | ||
| 2471 | 1년 전 | 918 | ||
| 2470 | 1년 전 | 789 | ||
| 2469 | 1년 전 | 1373 | ||
| 2468 | 1년 전 | 2961 | ||
| 2467 | 1년 전 | 853 | ||
| 2466 |
|
1년 전 | 1481 | |
| 2465 | 1년 전 | 805 | ||
| 2464 | 1년 전 | 1184 | ||
| 2463 | 1년 전 | 1353 | ||
| 2462 | 1년 전 | 1146 | ||
| 2461 |
|
1년 전 | 1174 | |
| 2460 | 1년 전 | 760 | ||
| 2459 | 1년 전 | 949 | ||
| 2458 | 1년 전 | 1345 | ||
| 2457 | 1년 전 | 1267 | ||
| 2456 |
|
1년 전 | 773 | |
| 2455 |
블랙캣77
|
1년 전 | 1499 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기