PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_comment.php

https://github.com/kuaileshike/upload
PHP | 328 lines | 276 code | 46 blank | 6 comment | 53 complexity | 884293ffb4a3f2a46419ad3a04be3e3d MD5 | raw file
  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 28115 2012-02-22 09:47:40Z zhengqingpeng $
  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. 'status' => $comment_status,
  184. );
  185. $cid = C::t('home_comment')->insert($setarr, true);
  186. $action = 'comment';
  187. $becomment = 'getcomment';
  188. $note = $q_note = '';
  189. $note_values = $q_values = array();
  190. switch ($idtype) {
  191. case 'uid':
  192. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=wall&cid=$cid";
  193. $note_type = 'wall';
  194. $note = 'wall';
  195. $note_values = array('url'=>$n_url);
  196. $q_note = 'wall_reply';
  197. $q_values = array('url'=>$n_url);
  198. if($comment) {
  199. $msg = 'note_wall_reply_success';
  200. $magvalues = array('username' => $tospace['username']);
  201. $becomment = '';
  202. } else {
  203. $msg = 'do_success';
  204. $magvalues = array();
  205. $becomment = 'getguestbook';
  206. }
  207. $action = 'guestbook';
  208. break;
  209. case 'picid':
  210. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=album&picid=$id&cid=$cid";
  211. $note_type = 'piccomment';
  212. $note = 'pic_comment';
  213. $note_values = array('url'=>$n_url);
  214. $q_note = 'pic_comment_reply';
  215. $q_values = array('url'=>$n_url);
  216. $msg = 'do_success';
  217. $magvalues = array();
  218. break;
  219. case 'blogid':
  220. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=blog&id=$id&cid=$cid";
  221. $note_type = 'blogcomment';
  222. $note = 'blog_comment';
  223. $note_values = array('url'=>$n_url, 'subject'=>$blog['subject']);
  224. $q_note = 'blog_comment_reply';
  225. $q_values = array('url'=>$n_url);
  226. $msg = 'do_success';
  227. $magvalues = array();
  228. break;
  229. case 'sid':
  230. $n_url = "home.php?mod=space&uid=$tospace[uid]&do=share&id=$id&cid=$cid";
  231. $note_type = 'sharecomment';
  232. $note = 'share_comment';
  233. $note_values = array('url'=>$n_url);
  234. $q_note = 'share_comment_reply';
  235. $q_values = array('url'=>$n_url);
  236. $msg = 'do_success';
  237. $magvalues = array();
  238. break;
  239. }
  240. if(empty($comment)) {
  241. if($tospace['uid'] != $_G['uid']) {
  242. if(ckprivacy('comment', 'feed')) {
  243. require_once libfile('function/feed');
  244. $fs['title_data']['hash_data'] = "{$idtype}{$id}";
  245. 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']);
  246. }
  247. $note_values['from_id'] = $id;
  248. $note_values['from_idtype'] = $idtype;
  249. $note_values['url'] .= "&goto=new#comment_{$cid}_li";
  250. notification_add($tospace['uid'], $note_type, $note, $note_values);
  251. }
  252. } elseif($comment['authorid'] != $_G['uid']) {
  253. notification_add($comment['authorid'], $note_type, $q_note, $q_values);
  254. }
  255. if($comment_status == 1) {
  256. updatemoderate($idtype.'_cid', $cid);
  257. manage_addnotify('verifycommontes');
  258. }
  259. if($stattype) {
  260. include_once libfile('function/stat');
  261. updatestat($stattype);
  262. }
  263. if($tospace['uid'] != $_G['uid']) {
  264. $needle = $id;
  265. if($idtype != 'uid') {
  266. $needle = $idtype.$id;
  267. } else {
  268. $needle = $tospace['uid'];
  269. }
  270. updatecreditbyaction($action, 0, array(), $needle);
  271. if($becomment) {
  272. if($idtype == 'uid') {
  273. $needle = $_G['uid'];
  274. }
  275. updatecreditbyaction($becomment, $tospace['uid'], array(), $needle);
  276. }
  277. }
  278. C::t('common_member_status')->update($_G['uid'], array('lastpost' => $_G['timestamp']), 'UNBUFFERED');
  279. $magvalues['cid'] = $cid;
  280. return array('cid' => $cid, 'msg' => $msg, 'magvalues' => $magvalues);
  281. }
  282. ?>