function_comment.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_comment.php 33714 2013-08-07 01:42:26Z andyzheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function add_comment($message, $id, $idtype, $cid = 0) {
  12. global $_G, $bbcode;
  13. $allowcomment = false;
  14. switch($idtype) {
  15. case 'uid':
  16. $allowcomment = helper_access::check_module('wall');
  17. break;
  18. case 'picid':
  19. $allowcomment = helper_access::check_module('album');
  20. break;
  21. case 'blogid':
  22. $allowcomment = helper_access::check_module('blog');
  23. break;
  24. case 'sid':
  25. $allowcomment = helper_access::check_module('share');
  26. break;
  27. }
  28. if(!$allowcomment) {
  29. showmessage('quickclear_noperm');
  30. }
  31. $summay = getstr($message, 150, 0, 0, 0, -1);
  32. $comment = array();
  33. if($cid) {
  34. $comment = C::t('home_comment')->fetch_by_id_idtype($id, $idtype, $cid);
  35. if($comment && $comment['authorid'] != $_G['uid']) {
  36. $comment['message'] = preg_replace("/\<div class=\"quote\"\>\<blockquote\>.*?\<\/blockquote\>\<\/div\>/is", '', $comment['message']);
  37. $comment['message'] = $bbcode->html2bbcode($comment['message']);
  38. $message = ("<div class=\"quote\"><blockquote><b>".$comment['author']."</b>: ".getstr($comment['message'], 150, 0, 0, 2, 1).'</blockquote></div>').$message;
  39. if($comment['idtype'] == 'uid') {
  40. $id = $comment['authorid'];
  41. }
  42. } else {
  43. $comment = array();
  44. }
  45. }
  46. $hotarr = array();
  47. $stattype = '';
  48. $tospace = $pic = $blog = $album = $share = $poll = array();
  49. switch($idtype) {
  50. case 'uid':
  51. $tospace = getuserbyuid($id);
  52. $stattype = 'wall';
  53. break;
  54. case 'picid':
  55. $pic = C::t('home_pic')->fetch($id);
  56. if(empty($pic)) {
  57. showmessage('view_images_do_not_exist');
  58. }
  59. $picfield = C::t('home_picfield')->fetch($id);
  60. $pic['hotuser'] = $picfield['hotuser'];
  61. $tospace = getuserbyuid($pic['uid']);
  62. $album = array();
  63. if($pic['albumid']) {
  64. $query = C::t('home_album')->fetch($pic['albumid']);
  65. if(!$query['albumid']) {
  66. C::t('home_pic')->update_for_albumid($albumid, array('albumid' => 0));
  67. }
  68. }
  69. if(!ckfriend($album['uid'], $album['friend'], $album['target_ids'])) {
  70. showmessage('no_privilege_ckfriend_pic');
  71. } elseif(!$tospace['self'] && $album['friend'] == 4) {
  72. $cookiename = "view_pwd_album_$album[albumid]";
  73. $cookievalue = empty($_G['cookie'][$cookiename])?'':$_G['cookie'][$cookiename];
  74. if($cookievalue != md5(md5($album['password']))) {
  75. showmessage('no_privilege_ckpassword_pic');
  76. }
  77. }
  78. $hotarr = array('picid', $pic['picid'], $pic['hotuser']);
  79. $stattype = 'piccomment';
  80. break;
  81. case 'blogid':
  82. $blog = array_merge(
  83. C::t('home_blog')->fetch($id),
  84. C::t('home_blogfield')->fetch_targetids_by_blogid($id)
  85. );
  86. if(empty($blog)) {
  87. showmessage('view_to_info_did_not_exist');
  88. }
  89. $tospace = getuserbyuid($blog['uid']);
  90. if(!ckfriend($blog['uid'], $blog['friend'], $blog['target_ids'])) {
  91. showmessage('no_privilege_ckfriend_blog');
  92. } elseif(!$tospace['self'] && $blog['friend'] == 4) {
  93. $cookiename = "view_pwd_blog_$blog[blogid]";
  94. $cookievalue = empty($_G['cookie'][$cookiename])?'':$_G['cookie'][$cookiename];
  95. if($cookievalue != md5(md5($blog['password']))) {
  96. showmessage('no_privilege_ckpassword_blog');
  97. }
  98. }
  99. if(!empty($blog['noreply'])) {
  100. showmessage('do_not_accept_comments');
  101. }
  102. if($blog['target_ids']) {
  103. $blog['target_ids'] .= ",$blog[uid]";
  104. }
  105. $hotarr = array('blogid', $blog['blogid'], $blog['hotuser']);
  106. $stattype = 'blogcomment';
  107. break;
  108. case 'sid':
  109. $share = C::t('home_share')->fetch($id);
  110. if(empty($share)) {
  111. showmessage('sharing_does_not_exist');
  112. }
  113. $tospace = getuserbyuid($share['uid']);
  114. $hotarr = array('sid', $share['sid'], $share['hotuser']);
  115. $stattype = 'sharecomment';
  116. break;
  117. default:
  118. showmessage('non_normal_operation');
  119. break;
  120. }
  121. if(empty($tospace)) {
  122. showmessage('space_does_not_exist', '', array(), array('return' => true));
  123. }
  124. if(isblacklist($tospace['uid'])) {
  125. showmessage('is_blacklist');
  126. }
  127. if($hotarr && $tospace['uid'] != $_G['uid']) {
  128. hot_update($hotarr[0], $hotarr[1], $hotarr[2]);
  129. }
  130. $fs = array();
  131. $fs['icon'] = 'comment';
  132. $fs['target_ids'] = '';
  133. $fs['friend'] = '';
  134. $fs['body_template'] = '';
  135. $fs['body_data'] = array();
  136. $fs['body_general'] = '';
  137. $fs['images'] = array();
  138. $fs['image_links'] = array();
  139. switch ($idtype) {
  140. case 'uid':
  141. $fs['icon'] = 'wall';
  142. $fs['title_template'] = 'feed_comment_space';
  143. $fs['title_data'] = array('touser'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]\">$tospace[username]</a>");
  144. break;
  145. case 'picid':
  146. $fs['title_template'] = 'feed_comment_image';
  147. $fs['title_data'] = array('touser'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]\">".$tospace['username']."</a>");
  148. $fs['body_template'] = '{pic_title}';
  149. $fs['body_data'] = array('pic_title'=>$pic['title']);
  150. $fs['body_general'] = $summay;
  151. $fs['images'] = array(pic_get($pic['filepath'], 'album', $pic['thumb'], $pic['remote']));
  152. $fs['image_links'] = array("home.php?mod=space&uid=$tospace[uid]&do=album&picid=$pic[picid]");
  153. $fs['target_ids'] = $album['target_ids'];
  154. $fs['friend'] = $album['friend'];
  155. break;
  156. case 'blogid':
  157. C::t('home_blog')->increase($id, 0, array('replynum'=>1));
  158. $fs['title_template'] = 'feed_comment_blog';
  159. $fs['title_data'] = array('touser'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]\">".$tospace['username']."</a>", 'blog'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]&do=blog&id=$id\">$blog[subject]</a>");
  160. $fs['target_ids'] = $blog['target_ids'];
  161. $fs['friend'] = $blog['friend'];
  162. break;
  163. case 'sid':
  164. $fs['title_template'] = 'feed_comment_share';
  165. $fs['title_data'] = array('touser'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]\">".$tospace['username']."</a>", 'share'=>"<a href=\"home.php?mod=space&uid=$tospace[uid]&do=share&id=$id\">".str_replace(lang('spacecp', 'share_action'), '', $share['title_template'])."</a>");
  166. break;
  167. }
  168. $message = censor($message);
  169. if(censormod($message)) {
  170. $comment_status = 1;
  171. } else {
  172. $comment_status = 0;
  173. }
  174. $setarr = array(
  175. 'uid' => $tospace['uid'],
  176. 'id' => $id,
  177. 'idtype' => $idtype,
  178. 'authorid' => $_G['uid'],
  179. 'author' => $_G['username'],
  180. 'dateline' => $_G['timestamp'],
  181. 'message' => $message,
  182. 'ip' => $_G['clientip'],
  183. 'port' => $_G['remoteport'],
  184. 'status' => $comment_status,
  185. );
  186. $cid = C::t('home_comment')->insert($setarr, true);
  187. $action = 'comment';
  188. $becomment = 'getcomment';
  189. $note = $q_note = '';
  190. $note_values = $q_values = array();
  191. switch ($idtype) {
  192. case 'uid':
  193. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=wall&cid=$cid";
  194. $note_type = 'wall';
  195. $note = 'wall';
  196. $note_values = array('url'=>$n_url);
  197. $q_note = 'wall_reply';
  198. $q_values = array('url'=>$n_url);
  199. if($comment) {
  200. $msg = 'note_wall_reply_success';
  201. $magvalues = array('username' => $tospace['username']);
  202. $becomment = '';
  203. } else {
  204. $msg = 'do_success';
  205. $magvalues = array();
  206. $becomment = 'getguestbook';
  207. }
  208. $action = 'guestbook';
  209. break;
  210. case 'picid':
  211. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=album&picid=$id&cid=$cid";
  212. $note_type = 'comment';
  213. $note = 'pic_comment';
  214. $note_values = array('url'=>$n_url);
  215. $q_note = 'pic_comment_reply';
  216. $q_values = array('url'=>$n_url);
  217. $msg = 'do_success';
  218. $magvalues = array();
  219. break;
  220. case 'blogid':
  221. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=blog&id=$id&cid=$cid";
  222. $note_type = 'comment';
  223. $note = 'blog_comment';
  224. $note_values = array('url'=>$n_url, 'subject'=>$blog['subject']);
  225. $q_note = 'blog_comment_reply';
  226. $q_values = array('url'=>$n_url);
  227. $msg = 'do_success';
  228. $magvalues = array();
  229. break;
  230. case 'sid':
  231. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=share&id=$id&cid=$cid";
  232. $note_type = 'comment';
  233. $note = 'share_comment';
  234. $note_values = array('url'=>$n_url);
  235. $q_note = 'share_comment_reply';
  236. $q_values = array('url'=>$n_url);
  237. $msg = 'do_success';
  238. $magvalues = array();
  239. break;
  240. }
  241. if(empty($comment)) {
  242. if($tospace['uid'] != $_G['uid']) {
  243. if(ckprivacy('comment', 'feed')) {
  244. require_once libfile('function/feed');
  245. $fs['title_data']['hash_data'] = "{$idtype}{$id}";
  246. feed_add($fs['icon'], $fs['title_template'], $fs['title_data'], $fs['body_template'], $fs['body_data'], $fs['body_general'],$fs['images'], $fs['image_links'], $fs['target_ids'], $fs['friend']);
  247. }
  248. $note_values['from_id'] = $id;
  249. $note_values['from_idtype'] = $idtype;
  250. $note_values['url'] .= "&goto=new#comment_{$cid}_li";
  251. notification_add($tospace['uid'], $note_type, $note, $note_values);
  252. }
  253. } elseif($comment['authorid'] != $_G['uid']) {
  254. notification_add($comment['authorid'], $note_type, $q_note, $q_values);
  255. }
  256. if($comment_status == 1) {
  257. updatemoderate($idtype.'_cid', $cid);
  258. manage_addnotify('verifycommontes');
  259. }
  260. if($stattype) {
  261. include_once libfile('function/stat');
  262. updatestat($stattype);
  263. }
  264. if($tospace['uid'] != $_G['uid']) {
  265. $needle = $id;
  266. if($idtype != 'uid') {
  267. $needle = $idtype.$id;
  268. } else {
  269. $needle = $tospace['uid'];
  270. }
  271. updatecreditbyaction($action, 0, array(), $needle);
  272. if($becomment) {
  273. if($idtype == 'uid') {
  274. $needle = $_G['uid'];
  275. }
  276. updatecreditbyaction($becomment, $tospace['uid'], array(), $needle);
  277. }
  278. }
  279. C::t('common_member_status')->update($_G['uid'], array('lastpost' => $_G['timestamp']), 'UNBUFFERED');
  280. $magvalues['cid'] = $cid;
  281. return array('cid' => $cid, 'msg' => $msg, 'magvalues' => $magvalues);
  282. }
  283. ?>