mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-31 00:59:58 +09:00
외부페이지에서 이미지/대상링크/배경이미지등의 경로를 제대로 설정하도록 수정
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6263 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
9336c5e28d
commit
925eaed265
2 changed files with 35 additions and 30 deletions
|
|
@ -68,41 +68,31 @@
|
||||||
* @brief 내용에 포함된 src, href의 값을 변경
|
* @brief 내용에 포함된 src, href의 값을 변경
|
||||||
**/
|
**/
|
||||||
function replaceSrc($content, $path) {
|
function replaceSrc($content, $path) {
|
||||||
if(substr($path,-1)!='/') $path.='/';
|
$url_info = parse_url($path);
|
||||||
$this->target_path = $path;
|
$host = sprintf("%s://%s%s",$url_info['scheme'],$url_info['host'],$url_info['port']?':'.$url_info['port']:'');
|
||||||
|
$path = $url_info['path'];
|
||||||
// element의 속성중 value에 " 로 안 묶여 있는 것을 검사하여 묶어줌 - 에러날 수 있음 ex) window.open('*','*','width=320, height=240 ,left=100,top=100')
|
if(substr($path,-1)=='/') $path = substr($path,-1);
|
||||||
//$content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $content);
|
$t = explode('/',$path);
|
||||||
|
$_t = array();
|
||||||
// img, input, a, link등의 href, src값 변경
|
for($i=0,$c=count($t)-1;$i<$c;$i++) {
|
||||||
$content = preg_replace_callback('!<(script|link|a|img|input|iframe)([^>]*)(href|src)=[\'"](.*?)[\'"]!is', array($this, '_replaceSrc'), $content);
|
$v = trim($t[$i]);
|
||||||
|
if(!$v) continue;
|
||||||
// background:url의 값 변경
|
$_t[] = $v;
|
||||||
$content = preg_replace_callback('!url\((.*?)\)!is', array($this, '_replaceBackgroundUrl'), $content);
|
}
|
||||||
|
$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;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _replaceSrc($matches) {
|
function _replacePath($matches) {
|
||||||
$href = $matches[4];
|
$val = trim($matches[3]);
|
||||||
if(preg_match("/^http/i", $href) || $href == '#' || preg_match("/javascript:/i",$href)) return $matches[0];
|
if(preg_match('/^(http|\/|\.\.)/i',$val)) return $matches[0];
|
||||||
|
if(substr($val,0,2)=='./') $val = substr($val,2);
|
||||||
if(substr($href,0,1)=='/') $href = substr($href,1);
|
return sprintf("%s%s%s%s",$matches[1],$matches[2],$this->path.$val,$matches[4]);
|
||||||
$href = $this->target_path.$href;
|
|
||||||
|
|
||||||
$buff = sprintf('<%s%s%s="%s"', $matches[1], $matches[2], $matches[3], $href);
|
|
||||||
return $buff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
else $content = $this->executeFile($path, $caching_interval, $cache_file);
|
else $content = $this->executeFile($path, $caching_interval, $cache_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Context::set('opage_content', $content);
|
Context::set('opage_content', $content);
|
||||||
|
|
||||||
// 결과 출력 템플릿 지정
|
// 결과 출력 템플릿 지정
|
||||||
|
|
@ -107,6 +108,11 @@
|
||||||
@include($path);
|
@include($path);
|
||||||
$content = ob_get_clean();
|
$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);
|
FileHandler::writeFile($cache_file, $content);
|
||||||
|
|
||||||
// include후 결과를 return
|
// include후 결과를 return
|
||||||
|
|
@ -130,5 +136,14 @@
|
||||||
return $content;
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue