feed.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: feed.php 1139 2012-05-08 09:02:11Z liulanbo $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class feedcontrol extends base
  9. {
  10. function __construct()
  11. {
  12. $this->feedcontrol();
  13. }
  14. function feedcontrol()
  15. {
  16. parent::__construct();
  17. $this->init_input();
  18. }
  19. function onadd()
  20. {
  21. $this->load('misc');
  22. $appid = intval($this->input('appid'));
  23. $icon = $this->input('icon');
  24. $uid = intval($this->input('uid'));
  25. $username = $this->input('username');
  26. $body_data = $_ENV['misc']->array2string($this->input('body_data'));
  27. $title_data = $_ENV['misc']->array2string($this->input('title_data'));
  28. $title_template = $this->_parsetemplate($this->input('title_template'));
  29. $body_template = $this->_parsetemplate($this->input('body_template'));
  30. $body_general = $this->input('body_general');
  31. $target_ids = $this->input('target_ids');
  32. $image_1 = $this->input('image_1');
  33. $image_1_link = $this->input('image_1_link');
  34. $image_2 = $this->input('image_2');
  35. $image_2_link = $this->input('image_2_link');
  36. $image_3 = $this->input('image_3');
  37. $image_3_link = $this->input('image_3_link');
  38. $image_4 = $this->input('image_4');
  39. $image_4_link = $this->input('image_4_link');
  40. $hash_template = md5($title_template . $body_template);
  41. $hash_data = md5($title_template . $title_data . $body_template . $body_data);
  42. $dateline = $this->time;
  43. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "feeds SET appid='$appid', icon='$icon', uid='$uid', username='$username',
  44. title_template='$title_template', title_data='$title_data', body_template='$body_template', body_data='$body_data', body_general='$body_general',
  45. image_1='$image_1', image_1_link='$image_1_link', image_2='$image_2', image_2_link='$image_2_link',
  46. image_3='$image_3', image_3_link='$image_3_link', image_4='$image_4', image_4_link='$image_4_link',
  47. hash_template='$hash_template', hash_data='$hash_data', target_ids='$target_ids', dateline='$dateline'");
  48. return $this->db->insert_id();
  49. }
  50. function ondelete()
  51. {
  52. $start = $this->input('start');
  53. $limit = $this->input('limit');
  54. $end = $start + $limit;
  55. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "feeds WHERE feedid>'$start' AND feedid<'$end'");
  56. }
  57. function onget()
  58. {
  59. $this->load('misc');
  60. $limit = intval($this->input('limit'));
  61. $delete = $this->input('delete');
  62. $feedlist = $this->db->fetch_all("SELECT * FROM " . UC_DBTABLEPRE . "feeds ORDER BY feedid DESC LIMIT $limit");
  63. if ($feedlist)
  64. {
  65. $maxfeedid = $feedlist[0]['feedid'];
  66. foreach ($feedlist as $key => $feed)
  67. {
  68. $feed['body_data'] = $_ENV['misc']->string2array($feed['body_data']);
  69. $feed['title_data'] = $_ENV['misc']->string2array($feed['title_data']);
  70. $feedlist[$key] = $feed;
  71. }
  72. }
  73. if (!empty($feedlist))
  74. {
  75. if (!isset($delete) || $delete)
  76. {
  77. $this->_delete(0, $maxfeedid);
  78. }
  79. }
  80. return $feedlist;
  81. }
  82. function _delete($start, $end)
  83. {
  84. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "feeds WHERE feedid>='$start' AND feedid<='$end'");
  85. }
  86. function _parsetemplate($template)
  87. {
  88. $template = str_replace(array("\r", "\n"), '', $template);
  89. $template = str_replace(array('<br>', '<br />', '<BR>', '<BR />'), "\n", $template);
  90. $template = str_replace(array('<b>', '<B>'), '[B]', $template);
  91. $template = str_replace(array('<i>', '<I>'), '[I]', $template);
  92. $template = str_replace(array('<u>', '<U>'), '[U]', $template);
  93. $template = str_replace(array('</b>', '</B>'), '[/B]', $template);
  94. $template = str_replace(array('</i>', '</I>'), '[/I]', $template);
  95. $template = str_replace(array('</u>', '</U>'), '[/U]', $template);
  96. $template = dhtmlspecialchars($template);
  97. $template = nl2br($template);
  98. $template = str_replace(array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]'), array('<b>', '<i>', '<u>', '</b>', '</i>', '</u>'), $template);
  99. return $template;
  100. }
  101. }