html_end 함수를 class로 변경

This commit is contained in:
chicpro
2014-02-13 13:30:06 +09:00
parent 1c552404c0
commit 0463ecc23f

View File

@ -2170,7 +2170,30 @@ if (!function_exists('file_put_contents')) {
// HTML 마지막 처리 // HTML 마지막 처리
function html_end() function html_end()
{ {
global $config, $g5, $member; $end = new html_process();
return $end->run();
}
class html_process {
protected $links = array();
function css_callback1($m) {
$s = $m[0];
if(preg_match('/<link[^>]+>/i', $s)) {
preg_match_all("/(<![^>]+>)|(<link[^>]+>)/is", $s, $m);
$this->links = array_merge($this->links, $m[0]);
}
return '';
}
function css_callback2($m) {
$this->links = array_merge($this->links, array($m[0]));
return '';
}
function run()
{
global $config, $g5, $member, $css;
// 현재접속자 처리 // 현재접속자 처리
$tmp_sql = " select count(*) as cnt from {$g5['login_table']} where lo_ip = '{$_SERVER['REMOTE_ADDR']}' "; $tmp_sql = " select count(*) as cnt from {$g5['login_table']} where lo_ip = '{$_SERVER['REMOTE_ADDR']}' ";
@ -2195,13 +2218,23 @@ function html_end()
$buffer = ob_get_contents(); $buffer = ob_get_contents();
ob_end_clean(); ob_end_clean();
preg_match('#<body>(.*)</body>#is', $buffer, $bodys); preg_match('#<body>(.*)</body>#is', $buffer, $bodys);
preg_match_all('/[\n\r]?(<!.*)?(<link[^>]+>).*(<!.*>)?/i', $bodys[0], $links);
$bodys = preg_replace_callback("/<!--\[[^가-힣]*\]-->/is", 'html_process::css_callback1', $bodys);
$bodys = preg_replace_callback("/<!--\s*<link[^>]+>\s*-->/is", 'html_process::css_callback2', $bodys);
$bodys = preg_replace_callback("/<link[^>]+>/is", 'html_process::css_callback2', $bodys);
$links = array_unique($this->links);
$stylesheet = ''; $stylesheet = '';
$links[0] = array_unique($links[0]);
foreach ($links[0] as $key=>$link) { foreach($links as $link) {
//$link = PHP_EOL.$links[0][$i]; if(!trim($link))
$stylesheet .= $link; continue;
if(preg_match('/<link[^>]+>/i', $link))
$buffer = preg_replace('#'.$link.'#', '', $buffer); $buffer = preg_replace('#'.$link.'#', '', $buffer);
$stylesheet .= PHP_EOL.$link;
} }
/* /*
</title> </title>
@ -2210,7 +2243,7 @@ function html_end()
*/ */
return preg_replace('#(</title>[^<]*<link[^>]+>)#', "$1$stylesheet", $buffer); return preg_replace('#(</title>[^<]*<link[^>]+>)#', "$1$stylesheet", $buffer);
} }
}
// 휴대폰번호의 숫자만 취한 후 중간에 하이픈(-)을 넣는다. // 휴대폰번호의 숫자만 취한 후 중간에 하이픈(-)을 넣는다.
function hyphen_hp_number($hp) function hyphen_hp_number($hp)