<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(!define('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>]+?)/i'<li> * 4. フレーム src : '/< フレーム(.+?)src=(['" ])?(.+?)([ >]+?)/i'<li> * 5. js : '/window.open([( ]+?)( [ '" ]+?)(.+?)([ )+?])/i'<li> * 6. css : '/background(.+?)url([( ])(['" ]+?) ( .+?)([ )+?])/i'<li>*/<li> class Myreplace {<li> private $moudle_array = array(' udata','tdata','tresult','dresult');<li>プライベート $content;<li>プライベート $relative_dirname;<li>プライベート $プロジェクト ID;<li>プライベート $moudle;<li>関数 __construct() {<li> $this->CI = &get_instance ();<li> }<li> <li> /**<li> * 置換 <li> * @param string $content HTML コンテンツ <li> * @param string $relative 相対パス <li> * @param int $projectid プロジェクト ID <li> * @moudle string $moudle テンプレート識別子: udata,tdata,tresult,dresult<li>*/<li> public function my_replace($content,$relative,$projectid,$moudle) {<li> $this->content = $content;</li> <li> $this-> ;relative_dirname = $relative;</li> <li> $this->projectid = $projectid;</li> <li> if(in_array(strto lower($moudle),$this->moudle_array))</li> <li> $this->moudle = $moudle;</li> <li> else exit ;</li> <li> switch($this->moudle) {</li> <li> case 'udata':</li> <li> $this->CI->load->model('mupload_data','model');</li> <li> Break;</li> <li> case 'tdata ':</li> <li> $this->CI->load->model('taskdata','model');</li> <li> Break;</li> <li> case 'tresult':</li> <li> $this->CI->load-> model('taskresult','model');</li> <li>break;</li> <li>case 'dresult':</li> <li> $this->CI->load->model('dmsresult','model');</li> <li>break;</li> <li>default :</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>]+?)/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 = '/background(.+?)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) if( empty($matches[3]) ) return ''; </li> <li> $matches[3] = rtrim($matches[3],''"/');</li> <li> //画像を取ったid</li> <li> $parent_dir_num = substr_count( $matches[3], '../');</li> <li> $相対ディレクトリ名 = $this->相対ディレクトリ名;</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].$matches[2].$一致[4];<li> }<li> }<li> <li> private function html_replace( $matches ) {<li> if(count($matches) < 4) return '';<li> if( empty($matches[3]) ) return '';<li> //If href link ( If $matches[3]) http または www または mailto で始まる場合、処理されません<li> //if(preg_match('/^[http|www|mailto](.+?)/i',$matches[3] ) ) <li> // return "<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> $matches[3] = substr($matches[ 3 ],0,strrpos($matches[3],'#')); <li> //htmlのIDを取得します<li> $parent_dir_num = substr_count( $matches[3], '../');<li> $relative_dirname = $this ->relative_dirname;<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> } else {<li> return "<a".$matches[1]."href= ". $matches[2].$this->CI->config->item("base_url")."cdms/".$this->moudle."/txtfile/$txtfile_id?pid=" .$ this->projectid .$matches[2].$matches[4];<li> }<li> } else {<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> $matches[3] = substr($matches[3],0,strrpos($matches[3],'#'));<li> //ID を取得html の<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> $txtfile_id = $this->CI->model->get_id_by_path_and_project($relativepath,$this->projectid);<li> //Output<li> if( !empty($txtfile_id ) ) {<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].$matches [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].$matches[4];<li> }<li> }<li> <li> private function Frame_replace ( $matches ) { <li> if(count($matches) < 4) return '';<li> if( empty($matches[3]) ) return '';<li> $matches[3] = rtrim($ matches[3 ],''"/');<li> //アンカーポイントを処理<li> if(substr_count($matches[3],'#')>0) <li> $matches[3] = substr($matches[3] ],0 ,strrpos($matches[3],'#'));<li> //html の ID を取得します<li> $parent_dir_num = substr_count( $matches[3], '../');<li> $relative_dirname = $ this-> 相対ディレクトリ名;</li> <li> for($i=0; $i<$parent_dir_num; $i++) {<li> $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );<li> }<li> $相対パス = rtrim( $relative_dirname,'/') . '/'.ltrim($matches[3],'./');<li> $txtfile_id = $this->CI->model->get_id_by_path_and_project($ relativepath,$this ->projectid);<li> //Output<li> if( !empty($txtfile_id ) ) {<li> if($this->moudle == 'dresult') { <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> }else {<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 "<フレーム".$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( empty($matches[3]) ) return '';<li> //处理链接<li> $arr_html = split(',',$一致[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> return "window.open".$matches[1].$matches[2].$matches[3].$matches[4];;<li> //获取htmlのid<li> $parent_dir_num = substr_count( $href, '../');<li> $relative_dirname = $this->relative_dirname;</li> <li> for($i=0; $i $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );</li> <li> }</li> <li> $relativepath = rtrim($relative_dirname,'/') 。 '/'.ltrim($href,'./');</li> <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->相対ディレクトリ名;</li> <li> for($i=0; $i $relative_dirname = substr( $relative_dirname, 0, strrpos($relative_dirname,"/") );</li> <li> }</li> <li> $relativepath = rtrim($relative_dirname,'/') 。 '/'.ltrim($matches[4],'./');</li> <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->プロジェクトID .$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->プロジェクトid .$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></iframe> </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>