xe 애드온 (xe addon) 강좌 (4)
예외 처리 코드 추가
애드온이 게시글 수정할 때 동작 되어 글 수정에 문제가 있습니다.
수정시에도
010-1234-****
이런식으로 나옴. 수정시에는 010-1234-5678 다나와야 하고 view 일때만 * 처리 되야함.
게시글이 노출될 때만 애드온이 동작하도록 수정합니다.
if($called_position == 'after_module_proc' && $this->module=="board") //board 모듈에서만 동작 하도록 함
{
$cur_act = Context::get('act');
if($cur_act != "" && $cur_act != "dispBoardContent") //act 확인
return;
$document_srl = Context::get('document_srl'); //게시글 번호 확인
if(!$document_srl)
return;
$oDocument = Context::get('oDocument'); //문서확인
if(!$oDocument)
return;
if($oDocument->document_srl != $document_srl) //게시글 번호 일치 확인
return;
$pattern = "/(0[0-9]{1,2})-([0-9]{3,4})-([0-9]{4})/i";
$replace = "$1-$2-****";
$oDocument->variables['content'] = preg_replace($pattern, $replace, $oDocument->variables['content']);
}
애드온이 동작할 상황들을 고려해서 코드를 추가합니다.