From 925eaed265790cdf0b0117e9cc50b8dd28c39038 Mon Sep 17 00:00:00 2001 From: zero Date: Mon, 4 May 2009 06:12:56 +0000 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EB=B6=80=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80/=EB=8C=80?= =?UTF-8?q?=EC=83=81=EB=A7=81=ED=81=AC/=EB=B0=B0=EA=B2=BD=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=93=B1=EC=9D=98=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=9C=EB=8C=80=EB=A1=9C=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6263 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- modules/opage/opage.controller.php | 50 ++++++++++++------------------ modules/opage/opage.view.php | 15 +++++++++ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/modules/opage/opage.controller.php b/modules/opage/opage.controller.php index b6599c748..abaebe022 100644 --- a/modules/opage/opage.controller.php +++ b/modules/opage/opage.controller.php @@ -68,41 +68,31 @@ * @brief 내용에 포함된 src, href의 값을 변경 **/ function replaceSrc($content, $path) { - if(substr($path,-1)!='/') $path.='/'; - $this->target_path = $path; - - // element의 속성중 value에 " 로 안 묶여 있는 것을 검사하여 묶어줌 - 에러날 수 있음 ex) window.open('*','*','width=320, height=240 ,left=100,top=100') - //$content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $content); - - // img, input, a, link등의 href, src값 변경 - $content = preg_replace_callback('!<(script|link|a|img|input|iframe)([^>]*)(href|src)=[\'"](.*?)[\'"]!is', array($this, '_replaceSrc'), $content); - - // background:url의 값 변경 - $content = preg_replace_callback('!url\((.*?)\)!is', array($this, '_replaceBackgroundUrl'), $content); + $url_info = parse_url($path); + $host = sprintf("%s://%s%s",$url_info['scheme'],$url_info['host'],$url_info['port']?':'.$url_info['port']:''); + $path = $url_info['path']; + if(substr($path,-1)=='/') $path = substr($path,-1); + $t = explode('/',$path); + $_t = array(); + for($i=0,$c=count($t)-1;$i<$c;$i++) { + $v = trim($t[$i]); + if(!$v) continue; + $_t[] = $v; + } + $path = $host.implode('/',$_t); + if(substr($path,-1)!='/') $path .= '/'; + $this->path = $path; + $content = preg_replace_callback('/(src=|href=|url\()("|\')?([^"\'\)]+)("|\'\))?/is',array($this,'_replacePath'),$content); return $content; } - function _replaceSrc($matches) { - $href = $matches[4]; - if(preg_match("/^http/i", $href) || $href == '#' || preg_match("/javascript:/i",$href)) return $matches[0]; - - if(substr($href,0,1)=='/') $href = substr($href,1); - $href = $this->target_path.$href; - - $buff = sprintf('<%s%s%s="%s"', $matches[1], $matches[2], $matches[3], $href); - return $buff; + function _replacePath($matches) { + $val = trim($matches[3]); + if(preg_match('/^(http|\/|\.\.)/i',$val)) return $matches[0]; + if(substr($val,0,2)=='./') $val = substr($val,2); + return sprintf("%s%s%s%s",$matches[1],$matches[2],$this->path.$val,$matches[4]); } - function _replaceBackgroundUrl($matches) { - $href = $matches[1]; - if(preg_match("/^http/i",$href) || $href == '#' || preg_match("/javascript:/i",$href)) return $matches[0]; - - if(substr($href,0,1)=='/') $href = substr($href,1); - $href = $this->target_path.$href; - - $buff = sprintf('url(%s)', $href); - return $buff; - } } ?> diff --git a/modules/opage/opage.view.php b/modules/opage/opage.view.php index 2fe18ff3a..c70d4b6e7 100644 --- a/modules/opage/opage.view.php +++ b/modules/opage/opage.view.php @@ -37,6 +37,7 @@ else $content = $this->executeFile($path, $caching_interval, $cache_file); } + Context::set('opage_content', $content); // 결과 출력 템플릿 지정 @@ -107,6 +108,11 @@ @include($path); $content = ob_get_clean(); + // 상대경로를 절대경로로 변경 + $path_info = pathinfo($path); + $this->path = realpath($path_info['dirname']).'/'; + $content = preg_replace_callback('/(src=|href=|url\()("|\')?([^"\'\)]+)("|\'\))?/is',array($this,'_replacePath'),$content); + FileHandler::writeFile($cache_file, $content); // include후 결과를 return @@ -130,5 +136,14 @@ return $content; } + function _replacePath($matches) { + $val = trim($matches[3]); + if(preg_match('/^(http|\/|\.\.)/i',$val)) return $matches[0]; + if(substr($val,0,2)=='./') $val = substr($val,2); + + $p = str_replace(_XE_PATH_,'',$this->path); + return sprintf("%s%s%s%s",$matches[1],$matches[2],getUrl('').$val,$matches[4]); + } + } ?>