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.

88 lines
3.3 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Class Rss
  5. * ------------------------------
  6. * RSS 보기 페이지
  7. */
  8. class Rss extends WB_Controller {
  9. function index($brd_key="")
  10. {
  11. $this->load->model('board_model');
  12. $brd_array = array();
  13. // 통합 RSS 인 경우
  14. if( empty($brd_key) )
  15. {
  16. $board_list = $this->db->where('brd_use_total_rss','Y')->where('brd_lv_read', '0')->get('board')->result_array();
  17. foreach($board_list as $b)
  18. {
  19. $brd_array[] = $b['brd_key'];
  20. }
  21. }
  22. else
  23. {
  24. $board = $this->board_model->get_board($brd_key, TRUE);
  25. if( $board['brd_use_rss'] != 'Y' OR $board['brd_lv_read'] > 0 )
  26. {
  27. die('해당 게시판은 RSS 사용 설정이 되어있지 않습니다.');
  28. }
  29. $brd_array[] = $brd_key;
  30. }
  31. if( count($brd_array) <= 0)
  32. {
  33. die('RSS를 사용할수 있는 게시판이 없습니다.');
  34. }
  35. $post_list = $this->db
  36. ->select('board_post.*,board.brd_title')
  37. ->join('board','board.brd_key=board_post.brd_key','inner')
  38. ->where_in('board_post.brd_key', $brd_array)
  39. ->where('post_status' ,'Y')
  40. ->order_by('post_num DESC, post_reply ASC, post_idx DESC')
  41. ->limit(50)
  42. ->get('board_post')
  43. ->result_array();
  44. header('content-type: text/xml');
  45. header('cache-control: no-cache, must-revalidate');
  46. header('pragma: no-cache');
  47. $title = (empty($brd_key)) ? $this->site->config('site_title').' 통합 RSS': $board['brd_title'] . ' RSS';
  48. $url = (empty($brd_key)) ? base_url() : base_url('board/'.$brd_key);
  49. $copyright = $this->site->config('site_title');
  50. $description = (empty($brd_key)) ? $this->site->config('site_meta_description') : $board['brd_description'];
  51. ob_start();
  52. echo "<?xml version=\"1.0\" encoding=\"" . config_item('charset') . "\"?".">\n";
  53. echo "<rss version=\"2.0\">\n";
  54. echo "<channel>\n";
  55. echo "<title>" . html_escape(element('title', $title)) . "</title>\n";
  56. echo "<link>" . $url . "</link>\n";
  57. if ($copyright) {
  58. echo "<copyright><![CDATA[ " . html_escape($copyright) . "]]></copyright>";
  59. }
  60. if ($description) {
  61. echo "<copyright><![CDATA[ " . html_escape($description) . "]]></copyright>";
  62. }
  63. foreach ($post_list as $row) {
  64. echo "<item>\n";
  65. echo "<title><![CDATA[" . element('post_title', $row) . "]]></title>\n";
  66. echo "<link>" . base_url( "board/{$row['brd_key']}/{$row['post_idx']}") . "</link>\n";
  67. echo "<author>" . html_escape(element('mem_nickname', $row)) . "</author>\n";
  68. echo "<pubDate>" . date('Y-m-d', strtotime($row['post_regtime'])) . "</pubDate>\n";
  69. echo "<description><![CDATA[" . display_html_content($row['post_content']) . "]]></description>\n";
  70. echo "<category>" . html_escape($row['brd_title']) . "</category>\n";
  71. echo "</item>\n";
  72. }
  73. echo "</channel>\n";
  74. echo "</rss>\n";
  75. $xml = ob_get_clean();
  76. echo $xml;
  77. }
  78. }