XE 코어 업데이트후 자동으로 사용자 수정 code를 php 파일에 넣고 저장하기(어드민 페이지의 대시보드 이용)
- 모듈
- 일본어선생
- Apr 18, 2015
- 470
PHP 파일 자체를 수정하는 방법입니다.
xe/modules/document/document.item.php
위 파일에 특정한 코드를 변경하여 사용하는 경우에 참고하기 바랍니다.
저는 getThumbnail() 함수에 아래와 같은 트리거 코드를 추가하여 사용중입니다. XE 코어를 업데이트 할 때마다 document.item.php파일을 수정해 주어야 합니다.
어드민 페이지의 대시보드가 열리면서 각 모듈의 xxx.class.php 파일의 checkUpdate() 함수가 실행되는 점을 활용하였습니다.
function checkUpdate() { $trigger_code = "\t\t".'//* 썸네일 마법사 모듈을 위해 추가된 트리거 시작 *//'."\r\n". "\t\t".'$this->adds( array("width" => $width, "height" => $height, "thumbnail_type" => $thumbnail_type));'."\r\n". "\t\t".'// trigger 호출 (before)'."\r\n". "\t\t".'$output = ModuleHandler::triggerCall("document.getThumbnail", "before", $this);'."\r\n". "\t\t".'if($this->variables["thumbnail_url"]) return $this->variables["thumbnail_url"];'."\r\n". "\t\t".'//* 썸네일 마법사 모듈을 위해 추가된 트리거 끝 *//'."\r\n"; $trigger_code_target_ = 'document.getThumbnail'; $trigger_code_target = '// Return false if neither attachement nor image files in the document'; $file_url = _XE_PATH_ . 'modules/document/document.item.php'; $filecontent = file_get_contents($file_url); // 트리거 코드 삽입 if(strpos($filecontent, $trigger_code_target_) !== false) { //echo $trigger_code_target_.'이미 있음'; } else { //echo '새로 추가'; $pos = strpos($filecontent, $trigger_code_target); $filecontent = substr($filecontent, 0, $pos).$trigger_code."\r\n"."\t\t".substr($filecontent, $pos); //$filecontent = str_replace($trigger_code_target, $trigger_code."\r\n".$trigger_code_target,$filecontent); file_put_contents($file_url, $filecontent); } $oModuleModel = getModel('module'); //썸네일 주소 리턴 if(!$oModuleModel->getTrigger('document.getThumbnail', 'thumbnail_wizard', 'controller', 'triggerGetThumbnail', 'before')) return true; if(!$oModuleModel->getTrigger('module.dispAdditionSetup', 'thumbnail_wizard', 'view', 'triggerDispThumbnail_wizardAdditionSetup', 'after')) return true; return FALSE; }
file_get_contents() 와 file_put_contents() 함수로 파일을 열고 저장합니다.
원본 xe/modules/document/document.item.php
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // 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; }
함수 실행후 xe/modules/document/document.item.php
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // 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; //* 썸네일 마법사 모듈을 위해 추가된 트리거 시작 *// $this->adds( array("width" => $width, "height" => $height, "thumbnail_type" => $thumbnail_type)); // trigger 호출 (before) $output = ModuleHandler::triggerCall("document.getThumbnail", "before", $this); if($this->variables["thumbnail_url"]) return $this->variables["thumbnail_url"]; //* 썸네일 마법사 모듈을 위해 추가된 트리거 끝 *// // 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; }
위의 방법을 이용하면 다른 php 파일도 직접 내용을 수정하거나 추가할 수 있습니다.