웹마스터 팁

1. 개요

이 코드는 1.7.5.2 버전이상에서 테스트 했습니다.

member_srl 을 기록하여 익명게시판에 글 수정권한을 유저가 가지도록 하는데 이를 운영진이 글을 수정하엿을 경우 그 글의 권한이 운영진으로 넘어가게 됩니다. 그렇게 되면서 그 글을 적었던 유저는 그 글을 삭제, 수정 권한이 뺐기는 문제가 있습니다.

2. 해결 방안

기본적으로 XE 게시판 모듈에서 글쓰기와 글수정은 한곳에서 이루어지며, 글 수정의 경우 update 하는 방안으로 처리가 되고 있습니다. 이를 이용하여 동시 다발적으로 member_srl 을 처리하는 부분을 각각 나눠서 글 수정시에는 member_srl 을 다시 기록하지 않도록 하는 것이 바람직합니다.

3. 코드 제공.

https://github.com/xpressengine/xe-core/pull/778/files
을 기본바탕으로 보고 따라코드 적으시면 됩니다.

xe/modules/board/board.controller.php
파일에서

63번째줄부터 77번째줄까지 (빈 줄도 함께 잘라내세요..)을 잘라내기로 짜릅니다. (지워지면서 복사 붙여넣기 되어야 합니다.)

            // if use anonymous is true
            if($this->module_info->use_anonymous == 'Y')
            {
                $this->module_info->admin_mail = '';
                $obj->notify_message = 'N';
                $obj->member_srl = -1*$logged_info->member_srl;
                $obj->email_address = $obj->homepage = $obj->user_id = '';
                $obj->user_name = $obj->nick_name = 'anonymous';
                $bAnonymous = true;
                $oDocument->add('member_srl', $obj->member_srl);
            }
            else
            {
                $bAnonymous = false;
            }

이 코드입니다.

이 잘라낸 코드는 
if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
이라고 적혀있는 if문 속에 넣어주시면 됩니다./100번째줄에 넣으세요./
넣어주실때 $obj->member_srl = -1*$logged_info->member_srl; 문구는 지워야합니다.

            // if use anonymous is true
            if($this->module_info->use_anonymous == 'Y')
            {
                $this->module_info->admin_mail = '';
                $obj->notify_message = 'N';
                $obj->email_address = $obj->homepage = $obj->user_id = '';
                $obj->user_name = $obj->nick_name = 'anonymous';
                $bAnonymous = true;
                $oDocument->add('member_srl', $obj->member_srl);
            }
            else
            {
                $bAnonymous = false;
            }

이렇게 되어야 합니다..

그리고 121번째줄에도 마찬가지로 붙여넣으시고 해당 member_srl 은 지우시지 않으셔도 됩니다

            // if use anonymous is true
            if($this->module_info->use_anonymous == 'Y')
            {
                $this->module_info->admin_mail = '';
                $obj->notify_message = 'N';
                $obj->member_srl = -1*$logged_info->member_srl;
                $obj->email_address = $obj->homepage = $obj->user_id = '';
                $obj->user_name = $obj->nick_name = 'anonymous';
                $bAnonymous = true;
                $oDocument->add('member_srl', $obj->member_srl);
            }
            else
            {
                $bAnonymous = false;
            }

이렇게 해서 procBoardInsertDocument 의 총 코드는 아래코드와 같아야 합니다.

    function procBoardInsertDocument()
    {
        // check grant
        if($this->module_info->module != "board")
        {
            return new Object(-1, "msg_invalid_request");
        }
        if(!$this->grant->write_document)
        {
            return new Object(-1, 'msg_not_permitted');
        }
        $logged_info = Context::get('logged_info');

        // setup variables
        $obj = Context::getRequestVars();
        $obj->module_srl = $this->module_srl;
        if($obj->is_notice!='Y'||!$this->grant->manager) $obj->is_notice = 'N';
        $obj->commentStatus = $obj->comment_status;

        settype($obj->title, "string");
        if($obj->title == '') $obj->title = cut_str(strip_tags($obj->content),20,'...');
        //setup dpcument title tp 'Untitled'
        if($obj->title == '') $obj->title = 'Untitled';

        // unset document style if the user is not the document manager
        if(!$this->grant->manager)
        {
            unset($obj->title_color);
            unset($obj->title_bold);
        }

        // generate document module model object
        $oDocumentModel = getModel('document');

        // generate document module의 controller object
        $oDocumentController = getController('document');

        // check if the document is existed
        $oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager);

        if((!$obj->status && $obj->is_secret == 'Y') || strtoupper($obj->status == 'SECRET'))
        {
            $use_status = explode('|@|', $this->module_info->use_status);
            if(!is_array($use_status) || !in_array('SECRET', $use_status))
            {
                $obj->status = 'PUBLIC';
            }
        }

        // update the document if it is existed
        if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
        {
            if(!$oDocument->isGranted())
            {
                return new Object(-1,'msg_not_permitted');
            }

            if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
            {
                return new Object(-1,'msg_protect_content');
            }

            if(!$this->grant->manager)
            {
                // notice & document style same as before if not manager
                $obj->is_notice = $oDocument->get('is_notice');
                $obj->title_color = $oDocument->get('title_color');
                $obj->title_bold = $oDocument->get('title_bold');
            }

            // modify list_order if document status is temp
            if($oDocument->get('status') == 'TEMP')
            {
                $obj->last_update = $obj->regdate = date('YmdHis');
                $obj->update_order = $obj->list_order = (getNextSequence() * -1);
            }

            // if use anonymous is true
            if($this->module_info->use_anonymous == 'Y')
            {
                $this->module_info->admin_mail = '';
                $obj->notify_message = 'N';
                $obj->email_address = $obj->homepage = $obj->user_id = '';
                $obj->user_name = $obj->nick_name = 'anonymous';
                $bAnonymous = true;
                $oDocument->add('member_srl', $obj->member_srl);
            }
            else
            {
                $bAnonymous = false;
            }


            $output = $oDocumentController->updateDocument($oDocument, $obj);
            $msg_code = 'success_updated';

        // insert a new document otherwise
        } else {
            // if use anonymous is true
            if($this->module_info->use_anonymous == 'Y')
            {
                $this->module_info->admin_mail = '';
                $obj->notify_message = 'N';
                $obj->member_srl = -1*$logged_info->member_srl;
                $obj->email_address = $obj->homepage = $obj->user_id = '';
                $obj->user_name = $obj->nick_name = 'anonymous';
                $bAnonymous = true;
                $oDocument->add('member_srl', $obj->member_srl);
            }
            else
            {
                $bAnonymous = false;
            }

            $output = $oDocumentController->insertDocument($obj, $bAnonymous);
            $msg_code = 'success_registed';
            $obj->document_srl = $output->get('document_srl');

            // send an email to admin user
            if($output->toBool() && $this->module_info->admin_mail)
            {
                $oMail = new Mail();
                $oMail->setTitle($obj->title);
                $oMail->setContent( sprintf("From : <a href=\"%s\">%s</a><br/>\r\n%s", getFullUrl('','document_srl',$obj->document_srl), getFullUrl('','document_srl',$obj->document_srl), $obj->content));
                $oMail->setSender($obj->user_name, $obj->email_address);

                $target_mail = explode(',',$this->module_info->admin_mail);
                for($i=0;$i<count($target_mail);$i++)
                {
                    $email_address = trim($target_mail[$i]);
                    if(!$email_address) continue;
                    $oMail->setReceiptor($email_address, $email_address);
                    $oMail->send();
                }
            }
        }

        // if there is an error
        if(!$output->toBool())
        {
            return $output;
        }

        // return the results
        $this->add('mid', Context::get('mid'));
        $this->add('document_srl', $output->get('document_srl'));

        // alert a message
        $this->setMessage($msg_code);
    }

여기까지 오시느라 수고 많으셧습니다.

댓글로 질문 남겨주셔도 좋습니다 :+1:

제목 글쓴이 날짜
css3 안쪽과 바깥쪽 그림자 만들기 입니다 file 낮은자 2014.03.06
css3 둥근테두리 만들기 낮은자 2014.03.06
XE 어플로 만들때 PUSH 기능처리 방법 웹빌드 2014.03.06
폰갭 제작 어플 gcm 발송시 변수 웹빌드 2014.03.04
페이지 모듈에서 다국어 기능 작동 안 하는 버그 패치법 [1] sejin7940 2014.03.04
xe 홈페이지 폰갭으로 묶을때 웹빌드 2014.03.03
방명록 댓글 줄바꿈 메디칼온 2014.03.03
[팁 시리즈 2] 한글 도메인이나 영문 도메인 설정을 잘못 건드려서 사이트의 모든 기능이 거의 먹통입니다! Omega3 2014.03.01
해외 아이피 차단 방법입니다. [3] Flolida 2014.03.01
정규식 문법 웹엔진 2014.02.28
[팁 시리즈 1] 웹 사이트 이전 및 복구/백업(이)가 되지 않습니다! [6] Omega3 2014.02.28
[10원팁] 서버에 계정추가후 새로설치하는데 CSS가 깨진다? [3] 키스미베이베 2014.02.27
nginx 에서 서브도메인 사용시 로그인유지방법 [3] garnecia 2014.02.26
1.5버전대에서 1.7.4버전으로 업데이트시.. [4] 똑디 2014.02.26
누리고 + KCP 결제 모듈 사용시 "연동 모듈 호출 오류" 가 날때 [1] idkiller 2014.02.26
Specify image dimensions socialskyo 2014.02.26
SFTP 적용하기 [6] Seeean 2014.02.24
모바일 게시판에서 이미지 리사이즈 적용방법 [6] socialskyo 2014.02.24
textyle에서 카카오 보내기 버튼 넣기 웹빌드 2014.02.24
부트스트랩 레이아웃 제작시 메뉴 코딩팁 웹빌드 2014.02.23