웹마스터 팁

이 방법은, 요즘 흥하는 소셜커머스형 목록을 가진 게시판에 적용되면 좋은 방법입니다.


관리에 유리해진달까요..

function getThumbnail($width = 80, $height = 0, $thumbnail_type = '',$fixed_file_name = false) {
            // Return false if the document doesn't exist
            if(!$this->document_srl) return;
            // If not specify its height, create a square
            if(!$height) $height = $width;
            // Return false if neither attachement nor image files in the document
            if(!$this->get('uploaded_count') && !preg_match("!<img!is", $this->get('content'))) return;
            // Get thumbnai_type information from document module's configuration
            if(!in_array($thumbnail_type, array('crop','ratio'))) {
                $config = $GLOBALS['__document_config__'];
                if(!$config) {
                    $oDocumentModel = &getModel('document');
                    $config = $oDocumentModel->getDocumentConfig();
                    $GLOBALS['__document_config__'] = $config;
                }
                $thumbnail_type = $config->thumbnail_type;
            }
            // Define thumbnail information
			
            $thumbnail_path = sprintf('files/cache/thumbnails/%s',getNumberingPath($this->document_srl, 3));
            $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
            $thumbnail_url  = Context::getRequestUri().$thumbnail_file;
            // Return false if thumbnail file exists and its size is 0. Otherwise, return its path
			/*
            if(file_exists($thumbnail_file)) {
                if(filesize($thumbnail_file)<1) return false;
                else return $thumbnail_url;
            }
			*/
            // Target File
            $source_file = null;
            $is_tmp_file = false;
            // Find an iamge file among attached files if exists
            if($this->get('uploaded_count')) {
                $oFileModel = &getModel('file');
                $file_list = $oFileModel->getFiles($this->document_srl, array(), 'file_srl', true);
                if(count($file_list)) {
					if($fixed_file_name){
						foreach($file_list as $file) {
							if($file->direct_download!='Y') continue;
							if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;
							
							if($file->source_filename == $fixed_file_name){
								$source_file = $file->uploaded_filename;
								break;
							}
						}
					}
					if(!$source_file){
						foreach($file_list as $file) {
							if($file->direct_download!='Y') continue;
							if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;
							
							if(!$source_file) $source_file = $file->uploaded_filename;
							
							if($file->source_filename == 'thumbnail.jpg'){
								$source_file = $file->uploaded_filename; 
								break;
							}
							
							if(!file_exists($source_file)) $source_file = null;
						}
					}
                }
            }
            // If not exists, file an image file from the content
            if(!$source_file) {
                $content = $this->get('content');
                $target_src = null;
                preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
                $cnt = count($matches);
                for($i=0;$i<$cnt;$i++) {
                    $target_src = trim($matches[$i][2]);
                    if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$target_src)) continue;
                    if(preg_match('/\/(common|modules|widgets|addons|layouts)\//i', $target_src)) continue;
                    else {
                        if(!preg_match('/^(http|https):\/\//i',$target_src)) $target_src = Context::getRequestUri().$target_src;
                        $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111,999999).$this->document_srl));
                        if(!is_dir('./files/cache/tmp')) FileHandler::makeDir('./files/cache/tmp');
                        FileHandler::getRemoteFile($target_src, $tmp_file);
                        if(!file_exists($tmp_file)) continue;
                        else {
                            list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file);
                            if($_w<$width || $_h<$height) continue;

                            $source_file = $tmp_file;
                            $is_tmp_file = true;
                            break;
                        }
                    }
                }
            }

            if($source_file){
                $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
            }
            if($is_tmp_file) FileHandler::removeFile($source_file);
            // Return its path if a thumbnail is successfully genetated
            if($output) return $thumbnail_url;
            // Create an empty file not to re-generate the thumbnail
            else FileHandler::writeFile($thumbnail_file, '','w');

            return;
        }


썸네일을 생성하는 document.item.php 의 함수를 수정합니다.


제가 필요해서 만들어 쓰는건데 혹시 필요하신분 있을까봐 공유해봅니다.


함수의 네번째 인자가 추가되었습니다.


추가된 인자는 $fixed_file_name 이며, 기존의 함수가 사용되는곳과의 충돌을 막기위해 기본값을 false로 처리하였습니다.


이것은, 썸네일로 지정할 파일이름이며 첨부된 파일중에 지정한 파일이 있는지 검사합니다.


없는경우 thumbnail.jpg 의 파일명을 가진 파일이 썸네일로 지정이되고, thumbnail.jpg도 없는경우 원래 방식처럼 첨부된 또는 본문내에 삽입된 첫번째 이미지를 썸네일로 생성합니다.



제목 글쓴이 날짜
소스 수정할 때, utf-8로 한글 적는 방법. $lang 때문에 애먹는 분들에게 드리는 초간단 팁... utf-8 <-> euc-kr 변환방법 [2] 최르토스 2013.01.30
NAVER Analytics 모듈 1.5.4.X 에서 사용하기 hhgyu 2013.01.30
문서에서 원하는 썸네일 뽑아오기. [16] Xiso 2013.02.01
[SocialXE] 트위터 로그인시 프로필 사진이 표시되지 않는 문제 해결하기 [3] file TUW 2013.02.03
ShopXE 상품 첨부 - 상품이미지 등록시 첨부 용량 초과 에러 수정 hhgyu 2013.02.05
흥미로운 AND, OR 조건문 엘카 2013.02.10
이미디오 (이미지->동영상) 기능을 적용해보자. [8] file asterisk 2013.02.12
방명록 모듈 1.5.1.1에서 비회원이 남긴글 삭제하기 조슈아킴 2013.02.14
팝업창 자동 사이즈 조절 js Alex 2013.02.17
Content (and확장) 위젯에서 추출대상 첨부이미지일 경우 카테고리명 및 이미지+제목 형식 섬네일 표시 못하는 문제 으흥 2013.02.17
스케치북5 글 관리자만 익명으로 보기 [3] taemin-ho 2013.02.19
[수정1차] XE 1.7.X 용 nginx rewrite rule 입니다! [15] CM(OEZ) 2013.02.21
XE 1.5.X 용 nginx rewrite rule 입니다! CM(OEZ) 2013.02.21
XE 1.4.X 용 nginx rewrite rule 입니다! (xzet 1.4 기준) CM(OEZ) 2013.02.21
XE 그룹아이콘 레벨아이콘 아이콘샵 동시출력하기(모르는분들 있으까봐올립니다.) [1] 모앱 2013.02.22
XE를 아주 간편하게 루트로 옮기기. [23] file LI-NA 2013.02.23
출석부 소시랑 스킨 출석회원없을때 우측위젯이 아래로 떨어지는 현상 해결방법 [3] garnecia 2013.02.23
기본 url 을 공란으로 둔 경우 `잘못된 요청입니다' 메시지 [6] samsara 2013.02.24
Windows 서버에서 XE 속도 대폭 개선 방법 [29] StyleRoot 2013.02.25
RSS 게시판 업데이터 모듈이 SSL 부분적용시 동작하지 않는 문제 해결하기 [25] Gunmania 2013.02.25