You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.6 KiB

7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Class Sitemap
  5. * ------------------------------------------------------------------------
  6. * 사이트맵
  7. */
  8. class Sitemap extends WB_Controller {
  9. /**
  10. * 사이트맵에 등록할 일반 페이지들
  11. */
  12. function pages()
  13. {
  14. $data['list'] = array();
  15. // 메인페이지
  16. $data['list'][] = array(
  17. "loc" => base_url("/"),
  18. "lastmod" => date('Y-m-d'),
  19. "priority" => "0.8",
  20. "changefreq" => "daily"
  21. );
  22. $list = $this->db->get('sitemap')->result_array();
  23. if( count($list) > 0 )
  24. {
  25. foreach($list as $row)
  26. {
  27. $data['list'][] = array(
  28. "loc" => base_url($row['sit_loc']),
  29. "lastmod" => date('Y-m-d'),
  30. "priority" => "{$row['sit_priority']}",
  31. "changefreq" => $row['sit_changefreq']
  32. );
  33. }
  34. }
  35. $this->layout = FALSE;
  36. $result = $this->load->view('tools/sitemap_pages', $data, TRUE);
  37. echo $result;
  38. }
  39. /**
  40. * 통합 사이트맵
  41. */
  42. function index()
  43. {
  44. $list = $this->db->where('brd_lv_read','0')->get('board')->result_array();
  45. ob_start();
  46. echo "<?xml version=\"1.0\" encoding=\"" . config_item('charset') . "\"?".">\n";
  47. echo "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
  48. echo "<sitemap>".PHP_EOL;
  49. echo "<loc>".base_url('sitemap_1.xml')."</loc>".PHP_EOL;
  50. echo "</sitemap>";
  51. foreach ($list as $row) {
  52. echo "<sitemap>".PHP_EOL;
  53. echo "<loc>" . base_url("sitemap_".$row['brd_key'].".xml") . "</loc>\n";
  54. echo "</sitemap>\n";
  55. }
  56. echo "</sitemapindex>\n";
  57. $xml = ob_get_clean();
  58. echo $xml;
  59. }
  60. /**
  61. * 게시판별 사이트맵
  62. * @param $brd_key
  63. */
  64. function board($brd_key)
  65. {
  66. if(empty($brd_key))
  67. {
  68. die('잘못된 접근입니다.');
  69. }
  70. $board = $this->boardlib->get($brd_key, TRUE);
  71. if( !$board OR $board['brd_lv_read'] > 0 )
  72. {
  73. die('이 게시판은 사이트맵을 사용하지 않습니다.');
  74. }
  75. $list = $this->db->where('post_secret', 'N')->where('post_status','Y')->where('brd_key', $brd_key)->from('board_post')->get()->result_array();
  76. $data['list'] = array();
  77. // 게시판 자체 사이트맵 추가
  78. // 게시판글 최종수정일 가져오기
  79. $max_date = $this->db->select_max('upd_datetime', 'max')->where('post_status','Y')->where('brd_key',$brd_key)->from('board_post')->get()->row(0)->max;
  80. $data['list'][] = array(
  81. "loc" => base_url("/board/{$brd_key}"),
  82. "lastmod" => date('Y-m-d', strtotime($max_date)),
  83. "priority" => "0.7",
  84. "changefreq" => "daily"
  85. );
  86. foreach($list as $row)
  87. {
  88. $data['list'][] = array(
  89. "loc" => base_url("/board/{$brd_key}/{$row['post_idx']}"),
  90. "lastmod" => date('Y-m-d', strtotime($row['upd_datetime'])),
  91. "priority" => "0.7",
  92. "changefreq" => "daily"
  93. );
  94. }
  95. $this->layout = FALSE;
  96. $result = $this->load->view('tools/sitemap_pages', $data, TRUE);
  97. echo $result;
  98. }
  99. function __construct()
  100. {
  101. parent::__construct();
  102. header('content-type: text/xml');
  103. header('cache-control: no-cache, must-revalidate');
  104. header('pragma: no-cache');
  105. }
  106. }