[최신게시물] 랜덤, 카테고리, 원글 아래 답글 등 (2017-02-05 수정) > 그누보드5 팁자료실

그누보드5 팁자료실

[최신게시물] 랜덤, 카테고리, 원글 아래 답글 등 (2017-02-05 수정) 정보

[최신게시물] 랜덤, 카테고리, 원글 아래 답글 등 (2017-02-05 수정)

본문

그누보드5 / extend / hp5_extend_latest.php  로 파일을 만들어서 업로드합니다.

<?php
if (!defined('_GNUBOARD_')) exit;

//1-1. 최신글 랜덤으로 보이기
//  사용법 : <?php echo hp_latest_rand("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
//1-2. 최신글 랜덤으로 보이기
//  사용법 : <?php echo hp_latest_rand2("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
//2. 카테고리로 최신글 보이기
//  사용법 : <?php echo latest_category("최신글스킨", "게시판이름", 게시물수, 제목글자수, "카테고리이름");? >
//3. 답글이 원본글 밑에 붙는 방식
//  사용법 : <?php echo latest_datetime("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
//4. 작성일자로 최신글 추출
//  사용법 : <?php echo latest_datetime("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
//5. 선택한 그룹별로 원하는 수만큼 보여줌
//  사용법 : <?php echo latest_group("최신글스킨", "그룹이름", 게시물수, 제목글자수, 본문글자수);? >
//6. 배너 최신글 추출
//  사용법 : <?php echo latest_banner_nolink("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션");? >
//7. 작성일자로 최신글 추출(코멘트포함)
//  사용법 : <?php echo latest_datetime2("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션");? >
//8. 최신 코멘트글 추출
//  사용법 : <?php echo latest_comment("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션");? >


//1-1. 최신글 랜덤으로 보이기 ... 2016-11-21 수정 (랜덤추출을 위해 캐시 사용안함)
//  랜덤 추출 함수  rand()  활용
//  사용법 : <?php echo hp_latest_rand("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
// 최신글 랜덤 추출
function hp_latest_rand($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    /*if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-rand-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }*/

    //if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    //}

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

//1-2. 최신글 랜덤으로 보이기
//  랜덤 추출 함수  rand()  활용
//  나너우리 님이 주신 팁 활용
//  사용법 : <?php echo hp_latest_rand2("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
// 최신글 랜덤 추출
function hp_latest_rand($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-rand2-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        //$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";
        //나너우리님의 대체쿼리 시작
        $sql = " select wr_id from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";
        $result = sql_query($sql);
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and ( wr_id in (";
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $sql = $sql.$row[wr_id].",";
        }
        $sql = substr($sql,0,strlen($sql) - 1)."))";
        //나너우리님의 대체쿼리 끝
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

//2. 카테고리로 최신글 보이기
//  사용법 : <?php echo latest_category("최신글스킨", "게시판이름", 게시물수, 제목글자수, "카테고리이름");? >
// 최신글 카테고리 데이타만 추출
function latest_category ($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-category-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where ca_name = '{$options}' order by wr_num limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}


//3. 답글이 원본글 밑에 붙는 방식
//  사용법 : <?php echo latest_re("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
// 최신글 추출 ## 답글이 원본글 밑에 붙는 방식
function latest_re($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-re-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num asc, wr_id asc limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

//4. 작성일자로 최신글 추출
//  사용법 : <?php echo latest_datetime("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
// 작성일자로 최신글 추출
function latest_datetime($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='') {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-datetime-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_datetime desc limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}



//5. 선택한 그룹별로 원하는 수만큼 보여줌
//  사용법 : <?php echo latest_group("최신글스킨", "그룹이름", 게시물수, 제목글자수, 본문글자수);? >
//출처: http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=95895

function latest_group($skin_dir="", $gr_id, $rows=10, $subject_len=40, $contents_len=200, $category="", $orderby="") {
  global $config;
  global $g5;
 
  $list = array();
  $limitrows = $rows;
 
  $sqlgroup = " select bo_table, bo_subject from $g5[board_table] where gr_id = '$gr_id' and  bo_use_search=1 order by bo_order";  // 해피정닷컴 2014-08-28 수정
  $rsgroup = sql_query($sqlgroup);
  //echo $sqlgroup;
  if ($skin_dir)
    $latest_skin_path = G5_PATH."/skin/latest/$skin_dir";
  else
    $latest_skin_path = G5_PATH."/skin/latest/$config[cf_latest_skin]";
 
  for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) {
    $bo_table = $rowgroup[bo_table];
   
    // 테이블 이름구함
    $sql = " select * from {$g5[board_table]} where bo_table = '$bo_table'";
    $board = sql_fetch($sql);
   
    $tmp_write_table = $g5[write_prefix] . $bo_table; // 게시판 테이블 실제이름
   
    // 옵션에 따라 정렬
    $sql = "select * from $tmp_write_table where wr_is_comment = 0 ";
    $sql .= (!$category) ? "" : " and ca_name = '$category' ";
    $sql .= (!$orderby) ? "  order by wr_id desc " : "  order by $orderby desc, wr_id desc ";
    $sql .= " limit $limitrows";
    //echo $sql;
    $result = sql_query($sql);
   
    for ($i=0; $row = sql_fetch_array($result); $i++, $k++) {
     
      if(!$orderby) $op_list[$k] = $row[wr_datetime];
      else  {
        $op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]);
        $op_list[$k] .= $row[wr_datetime];
        $op_list[$k] .= $row[wr_name];
        $op_list[$k] .= $row[wr_10];
      }
     
      $list[$k] = get_list($row, $board, $latest_skin_path, $subject_len, $wr_name, $wr_10);
     
      $list[$k][bo_table] = $board[bo_table];
      $list[$k][bo_subject] = $board[bo_subject];
      $list[$k][wr_name] = $board[wr_name];
      $list[$k][wr_10] = $board[wr_10];
     
      $list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len, $wr_name, $wr_10);
    }
  }
 
  if($k>0) array_multisort($op_list, SORT_DESC, $list);
  if($k>$rows) array_splice($list, $rows);

  ob_start();
  include $latest_skin_path.'/latest.skin.php';
  $content = ob_get_contents();
  ob_end_clean();
  return $content;
}


//6. 배너 최신글 추출
//  사용법 : <?php echo latest_banner_nolink("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션");? >
function latest_banner_nolink($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-banner_nolink-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}


//7. 배너 최신글 추출
//  사용법 : <?php echo latest_datetime2("최신글스킨", "게시판이름", 게시물수, 제목글자수, "옵션");? >
function latest_datetime2($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
{
    global $g5;

    if ($skin_dir)
        $latest_skin_path = G5_PATH."/skin/latest/$skin_dir";
    else
        $latest_skin_path = G5_PATH."/skin/latest/basic";

    $list = array();

    $sql = " select * from ".$g5['board_table']." where bo_table = '$bo_table'";
    $board = sql_fetch($sql);

    $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
    //$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_id desc limit 0, $rows ";
    // 위의 코드 보다 속도가 빠름
    //$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by wr_datetime desc limit 0, $rows ";
    $sql = " select B.wr_id, B.wr_num, B.wr_is_comment, B.wr_subject, ifnull( C.wr_content, '') cmmt, C.wr_id, C.wr_parent from $tmp_write_table B left join $tmp_write_table C on B.wr_is_comment=0 and B.wr_id=C.wr_parent and C.wr_is_comment=1 where B.wr_is_comment=0 and B.wr_id>0 order by B.wr_num, C.wr_comment limit 0, $rows ";
    //explain($sql);
    $result = sql_query($sql);
    $sql2 = 0;
    for ($i=0; $row = sql_fetch_array($result); $i++) {
      if( $sql2 == $row['wr_num']) {
        $sql2= $row['wr_num'];
        $list[$i]['comment_str'].= cut_str( $row['cmmt'], $subject_len).', ';
        continue;
      }
      $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
    }
    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}


//8. 최신 코멘트글 추출
function latest_comment($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="") {
    global $g5;
    //static $css = array();

    if (!$skin_dir) $skin_dir = 'basic';

    if(G5_IS_MOBILE) {
        $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
    } else {
        $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
        $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-comment-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include_once($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 1 order by wr_id desc limit 0, {$rows} ";
        $result = sql_query($sql);
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
        }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".$bo_subject."\";\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

    /*
    // 같은 스킨은 .css 를 한번만 호출한다.
    if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
        echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
        $css[] = $skin_dir;
    }
    */

    ob_start();
    include $latest_skin_path.'/latest.skin.php';
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
?>
추천
3

댓글 32개

여러가지 최근게시글 라이브러리 공개해주셔서 감사합니다.

각 function 마다 사용하는 $cache_file 명칭이 같아 한 사이트에서 같은 게시판을 다양한 형태로 표현할때
중복될 우려가 있습니다.
 $cache_file = G5_DATA_PATH."/cache/latest-호출되는함수명-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";

으로 바꿔 사용하는것을 권장합니다.
카테고리별로 최신글 출력하려고 했는데, 적용하니까 최신글 스킨은 나오긴 나오는데 게시글이 하나도 안나오네요 ㅜㅜ 왜그럴까요??
감사합니다.
즌즌즌님 말씀하신것처럼 출력이 없어...저같은 경우 제목글자수를 각각 다른숫자 넣으니 나오네요...
해결방법있으면 부탁드립니다~
예를들어...
게시물수,제목글자수==>5,20 이렇게 다 같으면 에러.
보통 한페이지에 같은 수로 뽑아오겠지요...

저는 제목글자수에 소수점찍어 다르게 입력하니 나오기는 하네요...
20.1  20.2  20.3  20.4 이런식으로  -.-

페이지 불러오는 속도가 상당히 걸리네요....
다시 한번더 댓글 답니다.

게시판에 글이 등록될 경우 해당 게시판의 캐시파일을 삭제 하는 코드가 latest-{$bo_table}이 있는지 체크를 하더군요.
제가 말씀드린데로 할 경우 새 글 등록시 캐시가 삭제되지 않아 즉각적인 반응이 안될수 도 있습니다.

 $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-호출함수명-{$skin_dir}-{$rows}-{$subject_len}.php";
으로 사용하는게 더 좋을듯 싶습니다.
아.. 그렇군요... 다시 수정하겠습니다.
의견 감사합니다.
... 헉 코멘트 3개 이상 달려서 원글 수정이 안된다고 하네요.. 에구구...

원본 수정이 안되서 아래 링크에만 최종 수정내용으로 교체했습니다.
http://www.happyjung.com/bbs/board.php?bo_table=lecture&wr_id=1680
제가 사용하는 서버가 라즈베리파이라서 10만건 이상일 경우 Random 쿼리가 30초 이상이 걸리네요.. 그래서 랜덤으로 전체를 쿼리하지 않고 인덱스가 있는 wr_id만 검색해서 해당 글을 검색하는 방식으로 수정했습니다. 이렇게 하니 1초 안 걸리네요.

 $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";

부분을 아래와 같이 수정.
        $sql = " select wr_id from {$tmp_write_table} where wr_is_comment = 0 order by rand() desc limit 0, {$rows} ";
        $result = sql_query($sql);
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and ( wr_id in (";
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $sql = $sql.$row[wr_id].",";
        }
        $sql = substr($sql,0,strlen($sql) - 1)."))";
아주 유용한 소스입니다. 감사합니다. 그런데 적용을 하니까 이러한 에러가 발생합니다.

Fatal error: Cannot redeclare latest_rand() (previously declared in /home/hosting_users/tnt4000/www/extend/hp5_extend_latest.php:28) in /home/hosting_users/tnt4000/www/extend/hp5_extend_latest.php on line 184
latest_rand() 가 중복사용되었다는 오류메시지입니다.
다른 파일에서 해당 함수와 동일한 명칭으로 사용되고 있는듯하네요... 둘중 하나는 제거하면 정상이 될껍니다.
잘 사용하고 있는데요...원글에 코멘트가 있을경우 카테고리별 최근글 추출시 코멘트가 리스트로 출력됩니다..
어느 부분을 수정해야 하는지요? ㅡㅡ;
5. 선택한 그룹별로 원하는 수만큼 보여줌 ... 요거 사용하신거죠?
퀴리가 $sql = "select * from $tmp_write_table where wr_is_comment = 0 ";  이렇게 되어있으니 댓글아닌 원글만 추출할텐데... 확인을 해봐야겠네요.
1-1. 최신글 랜덤으로 보이기  의 경우에
<?php echo latest_rand("최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
를 아래와 같이 변경하는것 외에는 동일합니다.
<?php echo latest_rand("theme/최신글스킨", "게시판이름", 게시물수, 제목글자수);? >
답변 감사합니다. 아 저는 그게... 위 소스 그대로 만들어 /extend/ 에 넣으니까 사이트가 아예 안뜨더라구요. 순정 최신버전 테마에서 해봤거든요.
latest_rand  함수가 순정 그누보드에 추가되어서, 그것의 충돌로 인한 문제입니다.
latest_rand  를  hp_latest_rand  로 변경하면 문제가 해결됩니다.
본문 코드도 수정했습니다.
네 새로운 코드는 문제없이 잘 출력이 됩니다. 감사합니다. 멋진소스^^
5.그룹에 2.카테고리별로 까지 조합해보려는데 그럼 그룹의 게시판들의 카테고리가 다 같으란 전제 또는 다 다를거란 전제가 있어야하는데 다 같다는 전제라면 좀 쉽겠죠? 다르다면 게시판 숫자에 카테고리숫자까지 우와. 그건 좀 아닌것 같고.
전체 2,431 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT