rss.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. class rss {
  4. private $db;
  5. function __construct() {
  6. $this->db = pc_base::load_model('content_model');
  7. pc_base::load_app_class('rssbuilder','','','0');
  8. $this->siteid = $_GET['siteid'] ? intval($_GET['siteid']) : '1';
  9. $this->rssid = intval($_GET['rssid']);
  10. define('SITEID', $this->siteid);
  11. }
  12. public function init() {
  13. $siteurl = siteurl(SITEID);
  14. if(empty($this->rssid)) {
  15. $catid = $_GET['catid'] ? intval($_GET['catid']) : '0';
  16. $siteids = getcache('category_content','commons');
  17. $siteid = $siteids[$catid] ? $siteids[$catid] : 1;
  18. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  19. $subcats = subcat($catid,0,1,$siteid);
  20. foreach ($CATEGORYS as $r) if($r['parentid'] == 0) $channel[] = $r;
  21. include template('content','rss');
  22. } else {
  23. $CATEGORYS = getcache('category_content_'.$this->siteid,'commons');
  24. $SITEINFO = getcache('sitelist','commons');
  25. $CAT = $CATEGORYS[$this->rssid];
  26. if(count($CAT) == 0) showmessage(L('missing_part_parameters'),'blank');
  27. $siteid = $CAT['siteid'];
  28. $sitedomain = $SITEINFO[$siteid]['domain']; //获取站点域名
  29. $MODEL = getcache('model','commons');
  30. $modelid = $CAT['modelid'];
  31. $encoding = CHARSET;
  32. $about = SITE_PROTOCOL.SITE_URL;
  33. $title = $CAT['catname'];
  34. $description = $CAT['description'];
  35. $content_html = $CAT['content_ishtml'];
  36. $image_link = "<![CDATA[".$CAT['image']."]]> ";
  37. $category = '';
  38. $cache = 60;
  39. $rssfile = new RSSBuilder($encoding, $about, $title, $description, $image_link, $category, $cache);
  40. $publisher = '';
  41. $creator = SITE_PROTOCOL.SITE_URL;
  42. $date = date('r');
  43. $rssfile->addDCdata($publisher, $creator, $date);
  44. $ids = explode(",",$CAT['arrchildid']);
  45. if(count($ids) == 1 && in_array($this->rssid, $ids)) {
  46. $sql .= "`catid` = '$this->rssid' AND `status` = '99'";
  47. } else {
  48. $sql .= get_sql_catid('category_content_'.$siteid,$this->rssid)." AND `status` = '99'";
  49. }
  50. if(empty($MODEL[$modelid]['tablename'])) showmessage(L('missing_part_parameters'),'blank');
  51. $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  52. $info = $this->db->select($sql,'`title`, `description`, `url`, `inputtime`, `thumb`, `keywords`','0,20','id DESC');
  53. foreach ($info as $r) {
  54. //添加项目
  55. if(!empty($r['thumb'])) $img = "<img src=".thumb($r['thumb'], 150, 150)." border='0' /><br />";else $img = '';
  56. $about = $link = (strpos($r['url'], 'http://') !== FALSE || strpos($r['url'], 'https://') !== FALSE) ? "<![CDATA[".$r['url']."]]> " : (($content_html == 1) ? "<![CDATA[".substr($sitedomain,0,-1).$r['url']."]]> " : "<![CDATA[".substr(APP_PATH,0,-1).$r['url']."]]> ");
  57. $title = "<![CDATA[".$r['title']."]]> ";
  58. $description = "<![CDATA[".$img.$r['description']."]]> ";
  59. $subject = '';
  60. $date = date('Y-m-d H:i:s' , $r['inputtime']);
  61. $author = $PHPCMS['sitename'].' '.SITE_PROTOCOL.SITE_URL;
  62. $comments = '';//注释;
  63. $rssfile->addItem($about, $title, $link, $description, $subject, $date, $author, $comments, $image);
  64. }
  65. $version = '2.00';
  66. $rssfile->outputRSS($version);
  67. }
  68. }
  69. }
  70. ?>