안드류KIM

add_stylesheet와 add_javascript의 방법에 파일수정시간으로 버전명 달기

· 2023-04-09 (일) 11:59:50 · 4633 · 2

https://sir.kr/g5_tip/18640 해당 팁의 css, js 파일의 수정 시간을 verison에 수정하는 기능을 그누보드에서 제공하는 add_stylesheet와 add_javascript의 방법을 수정해서 올려드립니다.

common.lib.php파일을 열어서 아래 부분을 찾아서 변경해주시면 되겠습니다.

 

function add_stylesheet($stylesheet, $order=0)

{

    global $html_process;

 

    $patten = "/<link[^>]*href=[\"']?([^>\"']+)[\"']?[^>]*>/i";

    preg_match_all($patten, $stylesheet, $match);

    $file = $match[1][0];

    if(strpos($file, G5_URL) !== false) {

        $file_location = str_replace(G5_URL, '', $file);

        $file_real_location = G5_PATH.'/'.$file_location;

        if (file_exists($file_real_location)) {

            $file_ver = "?ver=".date( 'YmdHis', filemtime($file_real_location));

        }

        $stylesheet = str_replace($file, $file.$file_ver, stripslashes($stylesheet));

    }

    if(trim($stylesheet) && method_exists($html_process, 'merge_stylesheet'))

        $html_process->merge_stylesheet($stylesheet, $order);

}

 

function add_javascript($javascript, $order=0)

{

    global $html_process;

 

    $patten = "/<script[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i";

    preg_match_all($patten, $javascript, $match);

    $file = $match[1][0];

    if(strpos($file, G5_URL) !== false) {

        $file_location = str_replace(G5_URL, '', $file);

        $file_real_location = G5_PATH.'/'.$file_location;

        if (file_exists($file_real_location)) {

            $file_ver = "?ver=".date( 'YmdHis', filemtime($file_real_location));

        }

        $javascript = str_replace($file, $file.$file_ver, stripslashes($javascript));

    }

    if(trim($javascript) && method_exists($html_process, 'merge_javascript'))

        $html_process->merge_javascript($javascript, $order);

}

|

댓글 2개

유용한 정보 감사합니다.
2023-04-11 (화) 09:00:15
감사합니다. ^^
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,790건
+
제목 글쓴이 날짜 조회
23-05-12 조회 5,136
23-05-10 조회 5,226
23-05-08 조회 5,645
23-05-04 조회 8,804
23-04-26 조회 5,409
23-04-24 조회 6,477
23-04-22 조회 5,319
23-04-22 조회 4,708
23-04-17 조회 5,714
23-04-16 조회 5,396
23-04-16 조회 5,274
23-04-15 조회 5,345
23-04-15 조회 7,443
23-04-14 조회 6,303
23-04-14 조회 5,372
23-04-13 조회 4,979
23-04-12 조회 5,400
23-04-11 조회 5,268
23-04-11 조회 4,728
23-04-09 조회 4,634
23-04-06 조회 5,728
23-04-05 조회 4,860
23-04-05 조회 4,443
23-04-03 조회 6,442
23-03-29 조회 4,407
23-03-29 조회 4,990
23-03-29 조회 5,000
23-03-29 조회 4,554
23-03-24 조회 4,444
23-03-23 조회 5,742