feed.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 1059 2011-03-01 07:25:09Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class feedcontrol extends base {
  9. function __construct() {
  10. $this->feedcontrol();
  11. }
  12. function feedcontrol() {
  13. parent::__construct();
  14. $this->init_input();
  15. }
  16. function onadd() {
  17. $this->load('misc');
  18. $appid = intval($this->input('appid'));
  19. $icon = $this->input('icon');
  20. $uid = intval($this->input('uid'));
  21. $username = $this->input('username');
  22. $body_data = $_ENV['misc']->array2string($this->input('body_data'));
  23. $title_data = $_ENV['misc']->array2string($this->input('title_data'));
  24. $title_template = $this->_parsetemplate($this->input('title_template'));
  25. $body_template = $this->_parsetemplate($this->input('body_template'));
  26. $body_general = $this->input('body_general');
  27. $target_ids = $this->input('target_ids');
  28. $image_1 = $this->input('image_1');
  29. $image_1_link = $this->input('image_1_link');
  30. $image_2 = $this->input('image_2');
  31. $image_2_link = $this->input('image_2_link');
  32. $image_3 = $this->input('image_3');
  33. $image_3_link = $this->input('image_3_link');
  34. $image_4 = $this->input('image_4');
  35. $image_4_link = $this->input('image_4_link');
  36. $hash_template = md5($title_template.$body_template);
  37. $hash_data = md5($title_template.$title_data.$body_template.$body_data);
  38. $dateline = $this->time;
  39. $this->db->query("INSERT INTO ".UC_DBTABLEPRE."feeds SET appid='$appid', icon='$icon', uid='$uid', username='$username',
  40. title_template='$title_template', title_data='$title_data', body_template='$body_template', body_data='$body_data', body_general='$body_general',
  41. image_1='$image_1', image_1_link='$image_1_link', image_2='$image_2', image_2_link='$image_2_link',
  42. image_3='$image_3', image_3_link='$image_3_link', image_4='$image_4', image_4_link='$image_4_link',
  43. hash_template='$hash_template', hash_data='$hash_data', target_ids='$target_ids', dateline='$dateline'");
  44. return $this->db->insert_id();
  45. }
  46. function ondelete() {
  47. $start = $this->input('start');
  48. $limit = $this->input('limit');
  49. $end = $start + $limit;
  50. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."feeds WHERE feedid>'$start' AND feedid<'$end'");
  51. }
  52. function onget() {
  53. $this->load('misc');
  54. $limit = intval($this->input('limit'));
  55. $delete = $this->input('delete');
  56. $feedlist = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."feeds ORDER BY feedid DESC LIMIT $limit");
  57. if($feedlist) {
  58. $maxfeedid = $feedlist[0]['feedid'];
  59. foreach($feedlist as $key => $feed) {
  60. $feed['body_data'] = $_ENV['misc']->string2array($feed['body_data']);
  61. $feed['title_data'] = $_ENV['misc']->string2array($feed['title_data']);
  62. $feedlist[$key] = $feed;
  63. }
  64. }
  65. if(!empty($feedlist)) {
  66. if(!isset($delete) || $delete) {
  67. $this->_delete(0, $maxfeedid);
  68. }
  69. }
  70. return $feedlist;
  71. }
  72. function _delete($start, $end) {
  73. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."feeds WHERE feedid>='$start' AND feedid<='$end'");
  74. }
  75. function _parsetemplate($template) {
  76. $template = str_replace(array("\r", "\n"), '', $template);
  77. $template = str_replace(array('<br>', '<br />', '<BR>', '<BR />'), "\n", $template);
  78. $template = str_replace(array('<b>', '<B>'), '[B]', $template);
  79. $template = str_replace(array('<i>', '<I>'), '[I]', $template);
  80. $template = str_replace(array('<u>', '<U>'), '[U]', $template);
  81. $template = str_replace(array('</b>', '</B>'), '[/B]', $template);
  82. $template = str_replace(array('</i>', '</I>'), '[/I]', $template);
  83. $template = str_replace(array('</u>', '</U>'), '[/U]', $template);
  84. $template = htmlspecialchars($template);
  85. $template = nl2br($template);
  86. $template = str_replace(array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]'), array('<b>', '<i>', '<u>', '</b>', '</i>', '</u>'), $template);
  87. return $template;
  88. }
  89. }
  90. ?>