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.

131 lines
3.7 KiB

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_use_sitemap','Y')->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. $this->load->model('board_model');
  67. if(empty($brd_key))
  68. {
  69. die('잘못된 접근입니다.');
  70. }
  71. $board = $this->board_model->get_board($brd_key, TRUE);
  72. if( !$board OR $board['brd_use_sitemap'] != 'Y' OR $board['brd_lv_read'] > 0 )
  73. {
  74. die('이 게시판은 사이트맵을 사용하지 않습니다.');
  75. }
  76. $list = $this->db->where('post_secret', 'N')->where('post_status','Y')->where('brd_key', $brd_key)->from('board_post')->get()->result_array();
  77. $data['list'] = array();
  78. // 게시판 자체 사이트맵 추가
  79. // 게시판글 최종수정일 가져오기
  80. $max_date = $this->db->select_max('post_modtime', 'max')->where('post_status','Y')->where('brd_key',$brd_key)->from('board_post')->get()->row(0)->max;
  81. $data['list'][] = array(
  82. "loc" => base_url("/board/{$brd_key}"),
  83. "lastmod" => date('Y-m-d', strtotime($max_date)),
  84. "priority" => "0.7",
  85. "changefreq" => "daily"
  86. );
  87. foreach($list as $row)
  88. {
  89. $data['list'][] = array(
  90. "loc" => base_url("/board/{$brd_key}/{$row['post_idx']}"),
  91. "lastmod" => date('Y-m-d', strtotime($row['post_modtime'])),
  92. "priority" => "0.7",
  93. "changefreq" => "daily"
  94. );
  95. }
  96. $this->layout = FALSE;
  97. $result = $this->load->view('tools/sitemap_pages', $data, TRUE);
  98. echo $result;
  99. }
  100. function __construct()
  101. {
  102. parent::__construct();
  103. header('content-type: text/xml');
  104. header('cache-control: no-cache, must-revalidate');
  105. header('pragma: no-cache');
  106. }
  107. }