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]); + } + } ?>