웹마스터 팁

카르마님의 외부이미지 저장 애드온을 가지고 사용중인데요.

기존 본문에 있는 이미지를 적용하기 위해서는 일부러 수정을 눌렀다가 저장을 해야 적용이 되는 불편한 점이 있었습니다.

오늘 푸시아님의 도움으로 편하게 본문을 읽어도 바로 외부이미지 저장기법이 적동되도록 수정하는데 성공했습니다.

원 애드온 소스는 카르마님의 사이트에 있구요.

저는 변경된 소스만 공유하도록 하겠습니다. ^^



<?php
    if(!defined("__ZBXE__")) exit();
 
    /**
     * @outimage.addon.php
     * @author 카르마(http://www.wildgreen.co.kr)
     *
     **/
 
    $oDocumentModel = &getModel('document');
 
    $act_arr = array('dispBoardContent','dispBodexContent','dispTextyle','dispBodexContentView','dispBoardContentView');
    $document_act = array('dispBoardContent','procBoardInsertDocument','procBodexInsertDocument');
    $comment_act = array('procBoardInsertComment','procBodexInsertComment');
     
    $ri_avoid_domain = explode(',', $addon_info->ri_avoid_domain);
    array_push($ri_avoid_domain,$_SERVER['HTTP_HOST']);
    require_once('./addons/auto_outimage/auto_outimage.func.php');
 
    if($addon_info->ri_permanent_get =='Y') {
        if($called_position == 'after_module_proc' && in_array($this->act,$document_act) ) {
            $var = $this->variables;
            $document_srl = Context::get('document_srl');;
            if(!$document_srl) return;
            $module_info = $oModuleModel->getModuleInfoByDocumentSrl($document_srl);
            $args->document_srl = $document_srl;
            $output =  executeQuery('document.getDocument', $args);
            $content = $output->data->content;
            //$oDocument = $oDocumentModel->getDocument($document_srl);
            //$content = $oDocument->getContent(false,false,false,false);
            $upload_target_srl = $document_srl;
            $oFileController = &getController('file');
 
            $contImg = extractImage($content);
            if(count($contImg)) {
                $replace = $content;
                foreach($contImg as $src) {
                    $ri_localfile = geRitLocalFile($src,$ri_avoid_domain,'N');
                    if(strcmp($src,$ri_localfile)==true)
                    {
                        $url = parse_url($ri_localfile);
                        $path_parts = pathinfo($url['path']);
                        $file_info['name']=$path_parts['basename'];
                        $file_info['tmp_name']=$ri_localfile;
                        $file_obj = $oFileController->insertFile($file_info,$module_info->module_srl,$upload_target_srl,0,true);
                        if(@$file_obj->variables['uploaded_filename']!=null) $replace = str_replace($src,$file_obj->variables['uploaded_filename'],$replace);
                        @unlink($ri_localfile);
                    }
                }
                $obj->module_srl = $module_info->module_srl;
                $obj->content = $replace;
                $obj->document_srl = $document_srl;
                executeQuery('addons.auto_outimage.updateDocument', $obj);
            }
        } elseif($addon_info->ri_comment_get != 'N' && $called_position == 'after_module_proc' && in_array($this->act,$comment_act)) {
            $var = $this->variables;
            $document_srl = $var[document_srl];
            $module_info = $oModuleModel->getModuleInfoByDocumentSrl($document_srl);
            $comment_srl = $var[comment_srl];
            if(!$comment_srl) return;
            $oCommentModel = &getModel('comment');
            $comment = $oCommentModel->getComment($comment_srl);
            $content = $comment->getContent(false,false,false,false);
             
            $upload_target_srl = $comment_srl;
            $oFileController = &getController('file');
 
            $contImg = extractImage($content);
            if(count($contImg)) {
                foreach($contImg as $src) {
                    $ri_localfile = geRitLocalFile($src,$ri_avoid_domain,'N');
                    if(strcmp($src,$ri_localfile)==true)
                    {
                        $url = parse_url($ri_localfile);
                        $path_parts = pathinfo($url['path']);
                        $file_info['name']=$path_parts['basename'];
                        $file_info['tmp_name']=$ri_localfile;
                        $file_obj = $oFileController->insertFile($file_info,$module_info->module_srl,$upload_target_srl,0,true);
                        if(@$file_obj->variables['uploaded_filename']!=null) $replace = str_replace($src,$file_obj->variables['uploaded_filename'],$replace);
                        @unlink($ri_localfile);
                    }
                }
                $obj->module_srl = $module_info->module_srl;
                $obj->content = $content;
                $obj->comment_srl = $comment_srl;
                $output = executeQuery('addons.auto_outimage.updateComment', $obj);
            }
        }
    } else {
     
    $document_srl = Context::get('document_srl');
    if(!$document_srl) return;
    $current_module_info = Context::get('current_module_info');
     
    $oView = &getView($current_module_info->module);
    $act = $oView->act;
     
    if($_COOKIE['mobile'] || in_array($act,$act_arr) && $called_position == 'before_display_content') {
         
        $oDocument = $oDocumentModel->getDocument($document_srl);
        $content = $oDocument->getContent(false,false,false,false);
        $_comment_list = $oDocument->getComments();
 
        $contImg = extractImage($content);
        if(count($contImg)) {
            $replace = $content;
            foreach($contImg as $src) {
                $ri_localfile = geRitLocalFile($src,$ri_avoid_domain,$addon_info->ri_permanent_get);
                $replace = str_replace($src,$ri_localfile,$replace);
            }
            $output = str_replace($content,$replace,$output);
        }
 
        if($addon_info->ri_comment_get == 'Y' && $oDocument->getCommentCount()) {
            $pattern_comments_area = '/<div class="comment_[0-9]+_[0-9]+ xe_content">(.*?)<!--AfterComment\([0-9]+,[0-9]+\)-->/is';
            preg_match_all($pattern_comments_area, $output,$match);
            if(!count($match[0])) return;
            foreach ($match[0] as $comment) {
                $list = extractImage($comment);
                if(count($list)) {
                    $repcom = $comment;
                    foreach($list as $rfile) {
                        $ri_localfile = geRitLocalFile($rfile,$ri_avoid_domain,$addon_info->ri_permanent_get);
                        $repcom = str_replace($rfile,$ri_localfile,$repcom);
                    }
                    $output = str_replace($comment,$repcom,$output);
                }
            }
 
        }
    }
    }
?>

제목 글쓴이 날짜
외부이미지 저장 애드온을 본문을 읽으면 작동하도록 하자!! 1.7.3적용 [18] 하얀마법 2013.03.16
1.8.3 통합 검색시 제목+내용 으로 하기 불금 2015.06.09
탑으로 가는 버튼이 특정위치에서 나타나게 하기 file 동네남자 2015.06.09
창크기에 따라 생기고 없어지는 배너 만들기 [1] 착한동구 2015.06.05
구글 웹폰트 부분으로 적용하기 착한동구 2015.06.05
알림LITE의 모바일쪽지 확인시 "잘못된 요청" 처리법 [1] Hello_XE 2014.10.28
php 버전을 다운그레이드 하기 [2] 6미리 2015.06.04
간단하게 외부 SMTP 로 인증메일 보내기. [1] file AJKJ 2014.07.22
Hostinger(호스팅어) 등 해외 서버에서 XE 설치화면이 깨진다면 [9] file YJSoft 2015.01.11
구글에서 제공하는 웹폰트 적용법 착한동구 2015.06.04
(오류x, 정보)ckeditor와 xpresseditor의 서식은 서로 다르네요. 반응형만드실 때 주의하실 필요가 있겠습니다. 큰성565 2015.06.04
코어 1.5 모바일에서 닉네임 클릭시 팝업 메뉴안 뜰때.. 착한악마 2015.06.03
자바스트립으로 내용을 숨겼다/보이기 착한동구 2015.06.03
저같은 초보분들이 궁금해 하실것같아서요 [3] file 착한동구 2015.05.08
cloudflare에서 nginx 아이피 제대로 표시하기 [3] natura 2014.11.13
카르마님의 외부 이미지 저장 애드온 에서 swf를 받아오기 불금 2015.06.01
네이버 카페 처럼 조회하고 [2] XE모듈 2015.05.31
타임라인 모듈 두개 이상 생성 및 페이지가 넘어가지 않은 문제에 관하여 함삐까 2015.06.01
스키마 변경 후 쿼리 오류가 발생할 때 신평 2015.06.01
글쓰기 폼에 미리 기본 내용 입력 [24] 송동우 2012.07.18