웹마스터 팁

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


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

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도 없는경우 원래 방식처럼 첨부된 또는 본문내에 삽입된 첫번째 이미지를 썸네일로 생성합니다.



제목 글쓴이 날짜
최신글위젯(content)에 상담게시판 보여주기 [2] 아고라 2009.11.15
XE 관련 질문시 정확하고 빠른 답변을 받기위한 방법의 Tip ????? [7] DuRi 2009.11.16
하나의 게시물을 각각 다르게 보이도록 만드는 방법 2 [5] 된장맛껌 2009.11.16
XE 업데이트 방법 - 제1편 (0.x.x / 1.0.x / 1.1.x / 1.2.x 에서 1.2.4 버전으로 업그레이드) [38] file Gekkou 2009.11.19
XE 업데이트 이후 발생하는 문제들에 대한 대응책 정리 [18] file Gekkou 2009.11.19
ZB4로 현재까지 사이트를 운영하는분들 긴급 상황안내 (???) [2] DuRi 2009.11.20
XE에서 jQuery의 $를 쓸 때에 대한 문제 [7] Hide_D 2009.11.21
apache + php + mysql + Zend Optimizer + eAccelerator [8] file 엘카 2009.11.23
확장변수값 계산하여 게시판 리스트에 출력하기(총계 게시판) [1] file klaist 2009.11.30
파일 첨부가 되지 않는 현상의 해결 [6] 이그누 2009.11.30
IE6 배경 깜빡이는 문제 해결 엘카 2009.12.01
설치하여 사용 중이던 XE의 폴더 옮기기 [1] file 영구만세 2009.12.02
Apache,PHP,MySQL,Zend,OpenSSL,PEAR 설치 메모 [1] 엘카 2009.12.03
코어 업댓후 링크게시판 %3C/P%3E 문제 임시해결 [2] 웰빙샵 지영 2009.12.04
제로보드 XE - 1.3.x 설치부터 기본 홈페이지 만들기 스타호스트 2009.12.05
메인 레이아웃에서 로그인이 안보이는 경우. 김찬회425 2009.12.06
XE 를 루트로 옮기는 방법과 문제 대응책 정리 (도메인 접속시 xe폴더로 이동 없이 바로 사이트 뜨게 하기) [8] file Gekkou 2009.12.06
script를 사용해서 이동한 경로에 amp; 라는 문자가 포함될 때 된장맛껌 2009.12.07
썸네일이 생성되지 않는 문제 [2] 이그누 2009.12.08
웹페이지 메시지 만들기 [초보자대응] [6] file cabnb 2009.12.09