웹마스터 팁

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:

제목 글쓴이 날짜
1.7.5에서 추가된 게시물당 최신댓글 불러오기 스킨에서 활용법 [2] file mAKEkr 2014.05.20
Draggable Captcha System for XE1.7.5 Member Module (QapTcha) [7] file 우진홈 2014.05.21
메뉴가 많을때 레이아웃 쉽게 변경하기 웹빌드ver2 2014.05.23
사용자정의에서 날짜형의 경우, 달력의 년수 선택범위를 늘리는 방법 sejin7940 2014.05.24
윈도에서 버츄얼박스 실행 시에 작업표시줄에 보이지 않게 하기 hyun 2014.05.26
유저가 자신의 회원정보 전체를 공개/비공개 설정하게 하는 방법 [2] sejin7940 2014.05.27
홈페이지에 접속한 장치의 너비 구하기 [3] CosignStudio 2014.05.28
게시판 comment 스타일 수정 웹빌드ver2 2014.05.30
[1초팁] Google Fonts의 폰트파일이 XE템플릿 문법으로 불러와지지 않을때 mAKEkr 2014.05.31
PHP에서 Socket.IO 서버로 요청 보내기 [3] 이즈야 2014.06.01
마이피플봇을 이용한 마이피플 알리미 (푸시서비스) 이용하기 [4] garnecia 2014.06.01
회원정보에서 '서명' 수정이 반영되지 않을 경우 Novelic 2014.06.03
에디터에서 나눔고딕 웹폰트, 기본글꼴로 적용하기(구글API이용) [6] file 애니즌 2014.06.06
XHTML 과 CSS 오류검사를 해주는 사이트 입니다. 디테일 2014.06.07
윈도우7/8에서네임서버 운영 POSTZI 2014.06.08
Google Public DNS 강제 Flush Cache 하기 AJKJ 2014.06.08
이거 어디다 올려야 될 지 몰라 여기다 올립니다. 프로그래머님들 읽어보세요. [2] 유샤인 2014.06.10
레이아웃에 배경이미지 업로드 하고 적용시키기 [1] 웹빌드ver2 2014.06.10
익명게시판에서 관리자가 글 수정시 글의 권한이 넘어가지 않도록 하기. [5] 소시덕분에힘받아요 2014.06.11
htm과 html의 차이는 ? 디테일 2014.06.17