<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_19261"> HTML 미리보기 정기 교체 <br><div class="blockcode"> <div id="code_PgI"><ol> <li><?php if(!definated('BASEPATH')) exit('직접 스크립트 액세스가 허용되지 않습니다.');<li> /**<li> * HTML 교체 처리 클래스, 다음 교체 고려 <li> * 1. img src: '/<img(. ?)src=(['" ])?(. ?)([ >] ? )/i'</li> <li> * 2. a href : '/<a(. ?)href=(['" ])?(. ?)([ >] ?)/i'</li> <li> * 3 . ifram.src : '/<iframe(. ?)src=(['" ])?(. ?)([ >] ?)/i'</li> <li> * 4. 프레임 src : '/< ; 프레임(. ?)src=(['" ])?(. ?)([ >] ?)/i'</li> <li> * 5. js : '/window.open([( ] ?)([ ' " ] ?)(. ?)([ ) ?])/i'</li> <li> * 6. css : '/Background(. ?)url([( ])(['" ] ?)(. ?) ( [ ) ?])/i'</li> <li>*/</li> <li> class Myreplace {</li> <li> private $moudle_array = array('udata','tdata','tresult','dresult');</li> <li> private $content;</li> <li> private $relative_dirname;</li> <li> private $projectid ;</li> <li> 비공개 $moudle;</li> <li> 함수 __construct() {</li> <li> $this->CI = &get_instance ();</li> <li> }</li> <li> </li> <li> /**</li> <li> * 바꾸기 </li> <li> * @param string $content HTML 콘텐츠 </li> <li> * @param string $relative 상대 경로 </li> <li> * @param int $projectid 프로젝트 ID</li> <li> * @moudle string $moudle 템플릿 식별: udata,tdata,tresult,dresult</li> <li>*/</li> <li> 공개 함수 my_replace($content,$relative,$projectid,$moudle) {</li> <li> $this->content = $content;</li> <li> $this->relative_dirname = $relative;</li> <li> $this- >projectid = $projectid;</li> <li> if(in_array(strtolower($moudle),$this->moudle_array))</li> <li> $this->moudle = $moudle;</li> <li> else 종료;</li> <li> switch($this->moudle) {</li> <li> 케이스 'udata':</li> <li> $this->CI->load->model('mupload_data','model');</li> <li> break; </li> <li> 케이스 'tdata':</li> <li> $this->CI->load->model('taskdata','model');</li> <li> break;</li> <li> 케이스 'tresult':</li> <li> $this->CI->load->model('taskresult','model');</li> <li> break;</li> <li> 케이스 'dresult':</li> <li> $this->CI-> load->model('dmsresult','model');</li> <li> break;</li> <li> 기본값:</li> <li> break;</li> <li> }</li> <li> </li> <li> $pattern = '/<img(. ?)src=(['" ])?(. ?)([ >] ?)/i';</li> <li> $content = preg_replace_callback( $pattern, array($this, 'image_replace') , $content ) ;</li> <li> $pattern = '/<a(. ?)href=(['" ])?(. ?)([ >] ?)/i';</li> <li> $content = preg_replace_callback( $pattern , array($this, 'html_replace') , $content );</li> <li> $pattern = '/<iframe(. ?)src=(['" ])?(. ?)([ >] ?) /i';</li> <li> $content = preg_replace_callback( $pattern, array($this, 'iframe_replace') , $content );</li> <li> $pattern = '/<frame(. ?)src=(['" ])?(. ?)([ >] ?)/i'; </li> <li> $content = preg_replace_callback( $pattern, array($this, 'frame_replace'), $content );</li> <li> $pattern = '/window.open([( ] ?)(['" ] ?)( . ?)([ )] ?)/i';</li> <li> $content = preg_replace_callback( $pattern, array($this, 'js_replace'), $content );</li> <li> $pattern = '/배경(. ? )url([( ])(['" ] ?)(. ?)([ ) ?])/i';</li> <li> $content = preg_replace_callback( $pattern, array($this, 'css_replace'), $ content);</li> <li> return $content;</li> <li> }</li> <li> </li> <li> 비공개 함수 image_replace($matches) {</li> <li> if(count($matches) < 4) return '';<li> if ( 비어 있음($matches[3]) ) return '';<li> $matches[3] = rtrim($matches[3],''"/');<li> //获取图文字id<li> $parent_dir_num = substr_count( $matches[3], '../');<li> $relative_dirname = $this->relative_dirname;</li> <li> for($i=0; $i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $relativepath = rtrim($relative_dirname,'/') '/'.ltrim ($matches[3],'./');<li> $image_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid);</li> <li> //输출</li> <li> if( !empty($image_id) ) {</li> <li> if($this->moudle == 'dresult') {</li> <li> return "<img".$matches[1]."src =".$matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/readpic/$image_id?pid= ".$this->프로젝트 ID .$matches[2]. $matches[4];</li> <li> } else {</li> <li> return "<img".$matches[1]."src=".$matches[2].$this->CI->config- >item("base_url")."cdms/".$this->moudle."/picfile/$image_id?pid=".$this->projectid .$matches[2]. $matches[4];</li> <li> }</li> <li> } else {</li> <li> return "<img".$matches[1]."src=".$matches[2].$matches[3].$ 일치[2].$matches[4];<li> }<li> }<li> <li> 비공개 함수 html_replace( $matches ) {<li> if(count($matches) < 4) return '';<li> if(empty($matches[3]) ) return ''; <li> //href 링크($matches[3])가 http, www 또는 mailto로 시작하는 경우 처리되지 않습니다. <li> //if(preg_match('/^[http|www|mailto](. ? )/i',$matches[3])) <li> // "<a".$matches[1]."href=".$matches[2].$matches[3].$matches를 반환합니다. [ 4];<li> $matches[3] = rtrim($matches[3],''"/');<li> //앵커 포인트 처리<li> if(substr_count($matches[3],' # ')>0) </li> <li> $matches[3] = substr($matches[3],0,strrpos($matches[3],'#')) </li> <li> //html ID 가져오기 </li> <li> $parent_dir_num = substr_count( $matches[3], '../');</li> <li> $relative_dirname = $this->relative_dirname;</li> <li> for($i=0; $i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $relativepath = rtrim($relative_dirname,'/') '/ '.ltrim($matches[3],'./');<li> $txtfile_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid);</li> <li> / /output</li> <li> if( !empty($txtfile_id ) ) {</li> <li> if($this->moudle == 'dresult') {</li> <li> return "<a".$matches[1] ." href=".$matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id ?pid =".$this->projectid .$matches[2].$matches[4];</li> <li> } else {</li> <li> return "<a".$matches[1]."href=" .$ 일치[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=". $this ->projectid .$matches[2].$matches[4];</li> <li> }</li> <li> } else {</li> <li> return "<a".$matches[1]."href=". $matches [2].$matches[3].$matches[2].$matches[4];<li> }<li> }<li> <li> 비공개 함수 iframe_replace( $matches ) {<li> if (count ($matches) < 4) return '';<li> if(empty($matches[3]) ) return '';<li> $matches[3] = rtrim($matches[3],' '" /');<li> <li> //앵커 포인트 처리<li> if(substr_count($matches[3],'#')>0) </li> <li> $matches[3] = substr($ match[ 3],0,strrpos($matches[3],'#'));</li> <li> //html ID 가져오기</li> <li> $parent_dir_num = substr_count( $matches[3], '../' );</li> <li> $relative_dirname = $this->relative_dirname;</li> <li> for($i=0; $i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos( $relative_dirname, "/") );<li> }<li> $relativepath = rtrim($relative_dirname,'/') '/'.ltrim($matches[3],'./');<li> $txtfile_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid);</li> <li> //출력</li> <li> if( !empty($txtfile_id ) ) {</li> <li> if( $this->moudle == 'dresult') { </li> <li> return "<iframe".$matches[1]."src=".$matches[2].$this->CI- >config ->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$this->projectid .$matches[2].$ match[4 ];</li> <li> } else {</li> <li> return "<iframe".$matches[1]."src=".$matches[2].$this->CI->config-> ;item( "base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid .$matches[2].$matches[4]; </li> <li> }</li> <li> } else {</li> <li> return "<iframe".$matches[1]."src=".$matches[2].$matches[3].$matches[2].$ match[4 ];<li> }<li> }<li> <li> 비공개 함수 frame_replace( $matches ) { <li> if(count($matches) < 4) return '';<li> if( 비어 있음($ matchs[3]) ) return '';<li> $matches[3] = rtrim($matches[3],''"/');<li> //앵커 포인트 처리<li> if( substr_count($ matches[3],'#')>0) </li> <li> $matches[3] = substr($matches[3],0,strrpos($matches[3],'#'));</li> <li> / /html의 ID 가져오기</li> <li> $parent_dir_num = substr_count( $matches[3], '../');</li> <li> $relative_dirname = $this->relative_dirname;</li> <li> for($i =0; $ i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $relativepath = rtrim($ 상대_디렉터리이름,'/ ') .'/'.ltrim($matches[3],'./');<li> $txtfile_id = $this->CI->model->get_id_by_path_and_project($relativepath,$ this-> projectid);</li> <li> //출력</li> <li> if( !empty($txtfile_id ) ) {</li> <li> if($this->moudle == 'dresult') { </li> <li> return "< ;frame".$matches[1]."src=".$matches[2].$this->CI->config->item("base_url")."cdms/".$this-> ;moudle." /readfile/$txtfile_id?pid=".$this->projectid.$matches[2].$matches[4];</li> <li> }else {</li> <li> return "<frame".$matches[1]."src=".$matches[2].$this->CI->config->item("base_url")." cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this->projectid.$matches[2].$matches[4];</li> <li> }</li> <li> } else {</li> <li> return "<frame".$matches[1]."src=".$matches[2].$matches[3].$matches[2].$matches[4];<li> } <li> }<li> <li> 비공개 함수 js_replace( $matches ){<li> if(count($matches) < 4) return '';<li> if( 비어 있음($matches[3]) ) return '';<li> //处理链接<li> $arr_html = Split(',',$matches[3]);<li> $href = $arr_html[0];<li> $other = '' ;<li> for($i=0; $i<count($arr_html); $i )<li> $other = $arr_html[$i].", ";<li> $other = rtrim($other ,", ");<li> $href =rtrim($href,''"');<li> //관리锚点<li> if(substr_count($href,'#')>0) </li> <li> return "window.open".$matches[1].$matches[2].$matches[3].$matches[4];;</li> <li> //获取html적id</li> <li> $parent_dir_num = substr_count ( $href, '../');</li> <li> $relative_dirname = $this->relative_dirname;</li> <li> for($i=0; $i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $relativepath = rtrim($relative_dirname,'/') . '/'.ltrim($href,'./');<li> $txtfile_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid);</li> <li> //출출</li> <li> if( !empty($txtfile_id ) ) {</li> <li> if($this->moudle == 'dresult') { </li> <li> return "window.open".$matches[1]. $matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/readfile/$txtfile_id?pid=".$ this->projectid.$matches[2].','.$other.$matches[4];</li> <li> } else {</li> <li> return "window.open".$matches[1].$matches[ 2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=".$this-> ;projectid.$matches[2].','.$other.$matches[4];</li> <li> }</li> <li> } else {</li> <li> return "window.open".$matches[1].$matches [2].$matches[3].$matches[4];</li> <li> }</li> <li> }</li> <li> </li> <li> 비공개 함수 css_replace( $matches ) {</li> <li> if(count($matches) < 5) return '';<li> if(empty($matches[4]) ) return '';<li> <li> $matches[4] = rtrim($matches[4],''"/') ;<li> //설명 ID<li> $parent_dir_num = substr_count( $matches[4], '../');<li> $relative_dirname = $this->relative_dirname;</li> <li> for($ 나는=0; $i<$parent_dir_num; $i ) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $relativepath = rtrim($relative_dirname,'/') . '/'.ltrim($matches[4],'./');<li> $image_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid); </li> <li> //출현</li> <li> if( !empty($image_id) ) {</li> <li> if($this->moudle == 'dresult') {</li> <li> return "Background".$matches[1] ."url".$matches[2].$matches[3].$this->CI->config->item("base_url")."cdms/".$this->moudle." /readpic/$image_id?pid=".$this->projectid .$matches[3]. $matches[5];</li> <li> } else {</li> <li> return "Background".$matches[1]."url".$matches[2].$matches[3].$this->CI-> ;config->item("base_url")."cdms/".$this->moudle."/picfile/$image_id?pid=".$this->projectid .$matches[3]. $matches[5];</li> <li> }</li> <li> } else {</li> <li> return "Background".$matches[1]."url".$matches[2].$matches[3].$matches[4 ].$matches[3].$matches[5];</li> <li> }</li> <li> }</li> <li> }</li> <li> <li>/* Myreplace.php 끝 */</li> <li>/* 위치: /application /libraries/Myreplace.php */</li> </ol></div> <em onclick="copycode($('code_PgI'));">复代码</em> </div> </td></tr></table> <div id="comment_19261" class="cm"> </div> <div id="post_rate_div_19261"></div> <br><br>