웹마스터 팁

modules/document/document.item.php 파일에 getThumbnail() 함수를 참고하여 원본 이미지 주소를 가져오도록 하였습니다.

목적은 widget_lightgallery_skin 의 경우 첨부파일에 대해서만 작동을 하는데 첨부파일이 아닌 본문 삽입 이미지인 경우에도 작동하도록 하기 위함입니다.

 

        /* 썸네일 방식으로 원본 이미지 주소 가져오기 */

        function getThumbnail_oriSrc_min()

        {

                // 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;

                }

 

                        // thumb_image 강제 지정 기능 - sejin7940 ( 120714 - 시작)

                        $args->document_srl = $this->document_srl;

                        $output = executeQuery('document.getDocument', $args, $this->columnList);

                        $thumb_image_srl = $output->data->thumb_image;

                        if($thumb_image_srl) {

                                // Find an iamge file among attached files if exists

                                if($this->get('uploaded_count')) {

                                        $oFileModel = &getModel('file');

                                        $file_list = $oFileModel->getFiles($this->document_srl);

                                        if(count($file_list)) {

                                                foreach($file_list as $file) {

                                                        if($thumb_image_srl == $file->file_srl) {

                                                                if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;

                                                                $source_file = $file->uploaded_filename;

                                                                if(!file_exists($source_file)) $source_file = null;

                                                                else break;

                                                        }

                                                }

                                        }

                                        if($source_file){

                                                                                                return $source_file;

                                        }

                                }

                        }

                        // thumb_image 강제 지정 기능 - sejin7940 ( 120714 - 끝)

 

                // Define thumbnail information

                // Target File

                $source_file = null;

                // 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))

                        {

                                foreach($file_list as $file)

                                {

                                        if($file->direct_download!='Y') continue;

                                        if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;

 

                                        $source_file = $file->uploaded_filename;

                                        if(!file_exists($source_file)) $source_file = null;

                                        else break;

                                }

                        }

                }

                // 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;

 

                                                                                if(!$target_src) continue;

                                                                                else

                                                                                {

                                                                                            $source_file = $target_src;

                                                break;

                                                                                }

                                }

                        }

                }

 

                if($source_file)

                {

                                                return $source_file;

                }

 

                return;

        }