spacecp_follow.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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: spacecp_follow.php 32667 2013-02-28 07:07:30Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $ops = array('add', 'del', 'bkname', 'checkfeed', 'relay', 'getfeed', 'delete', 'newthread');
  12. $op = in_array($_GET['op'], $ops) ? $_GET['op'] : '';
  13. if($op == 'add') {
  14. $_GET['handlekey'] = $_GET['handlekey'] ? $_GET['handlekey'] : 'followmod';
  15. $followuid = intval($_GET['fuid']);
  16. if($_GET['hash'] != FORMHASH || empty($followuid)) {
  17. exit('Access Denied');
  18. }
  19. if($_G['uid'] == $followuid) {
  20. showmessage('follow_not_follow_self');
  21. }
  22. $special = intval($_GET['special']) ? intval($_GET['special']) : 0;
  23. $followuser = getuserbyuid($followuid);
  24. $mutual = 0;
  25. $followed = C::t('home_follow')->fetch_by_uid_followuid($followuid, $_G['uid']);
  26. if(!empty($followed)) {
  27. if($followed['status'] == '-1') {
  28. showmessage('follow_other_unfollow');
  29. }
  30. $mutual = 1;
  31. C::t('home_follow')->update_by_uid_followuid($followuid, $_G['uid'], array('mutual'=>1));
  32. }
  33. $followed = C::t('home_follow')->fetch_by_uid_followuid($_G['uid'], $followuid);
  34. if(empty($followed)) {
  35. $followdata = array(
  36. 'uid' => $_G['uid'],
  37. 'username' => $_G['username'],
  38. 'followuid' => $followuid,
  39. 'fusername' => $followuser['username'],
  40. 'status' => 0,
  41. 'mutual' => $mutual,
  42. 'dateline' => TIMESTAMP
  43. );
  44. C::t('home_follow')->insert($followdata, false, true);
  45. C::t('common_member_count')->increase($_G['uid'], array('following' => 1));
  46. C::t('common_member_count')->increase($followuid, array('follower' => 1, 'newfollower' => 1));
  47. notification_add($followuid, 'follower', 'member_follow_add', array('count' => $count, 'from_id'=>$_G['uid'], 'from_idtype' => 'following'), 1);
  48. } elseif($special) {
  49. $status = $special == 1 ? 1 : 0;
  50. C::t('home_follow')->update_by_uid_followuid($_G['uid'], $followuid, array('status'=>$status));
  51. $special = $special == 1 ? 2 : 1;
  52. } else {
  53. showmessage('follow_followed_ta');
  54. }
  55. $type = !$special ? 'add' : 'special';
  56. showmessage('follow_add_succeed', dreferer(), array('fuid' => $followuid, 'type' => $type, 'special' => $special, 'from' => !empty($_GET['from']) ? $_GET['from'] : 'list'), array('closetime' => '2', 'showmsg' => '1'));
  57. } elseif($op == 'del') {
  58. $_GET['handlekey'] = $_GET['handlekey'] ? $_GET['handlekey'] : 'followmod';
  59. $delfollowuid = intval($_GET['fuid']);
  60. if(empty($delfollowuid)) {
  61. exit('Access Denied');
  62. }
  63. $affectedrows = C::t('home_follow')->delete_by_uid_followuid($_G['uid'], $delfollowuid);
  64. if($affectedrows) {
  65. C::t('home_follow')->update_by_uid_followuid($delfollowuid, $_G['uid'], array('mutual'=>0));
  66. C::t('common_member_count')->increase($_G['uid'], array('following' => -1));
  67. C::t('common_member_count')->increase($delfollowuid, array('follower' => -1, 'newfollower' => -1));
  68. }
  69. showmessage('follow_cancel_succeed', dreferer(), array('fuid' => $delfollowuid, 'type' => 'del', 'from' => !empty($_GET['from']) ? $_GET['from'] : 'list'), array('closetime' => '2', 'showmsg' => '1'));
  70. } elseif($op == 'bkname') {
  71. $followuid = intval($_GET['fuid']);
  72. $followuser = C::t('home_follow')->fetch_by_uid_followuid($_G['uid'], $followuid);
  73. if(empty($followuser)) {
  74. showmessage('follow_not_assignation_user');
  75. }
  76. if(submitcheck('editbkname')) {
  77. $bkname = cutstr(strip_tags($_GET['bkname']), 30, '');
  78. C::t('home_follow')->update_by_uid_followuid($_G['uid'], $followuid, array('bkname'=>$bkname));
  79. showmessage('follow_remark_succeed', dreferer(), array('bkname' => $bkname, 'btnstr' => empty($bkname) ? lang('spacecp', 'follow_add_remark') : lang('spacecp', 'follow_modify_remark')), array('showdialog'=>true, 'closetime' => true));
  80. }
  81. } elseif($op == 'newthread') {
  82. if(!helper_access::check_module('follow')) {
  83. showmessage('quickclear_noperm');
  84. }
  85. if(submitcheck('topicsubmit')) {
  86. if(empty($_GET['syncbbs'])) {
  87. $fid = intval($_G['setting']['followforumid']);
  88. if(!($fid && C::t('forum_forum')->fetch($fid))) {
  89. $fid = 0;
  90. }
  91. if(!$fid) {
  92. $gid = C::t('forum_forum')->fetch_fid_by_name(lang('spacecp', 'follow_specified_group'));
  93. if(!$gid) {
  94. $gid = C::t('forum_forum')->insert(array('type' => 'group', 'name' => lang('spacecp', 'follow_specified_group'), 'status' => 0), true);
  95. C::t('forum_forumfield')->insert(array('fid' => $gid));
  96. }
  97. $forumarr = array(
  98. 'fup' => $gid,
  99. 'type' => 'forum',
  100. 'name' => lang('spacecp', 'follow_specified_forum'),
  101. 'status' => 1,
  102. 'allowsmilies' => 1,
  103. 'allowbbcode' => 1,
  104. 'allowimgcode' => 1
  105. );
  106. $fid = C::t('forum_forum')->insert($forumarr, true);
  107. C::t('forum_forumfield')->insert(array('fid' => $fid));
  108. C::t('common_setting')->update('followforumid', $fid);
  109. include libfile('function/cache');
  110. updatecache('setting');
  111. }
  112. } else {
  113. $fid = intval($_GET['fid']);
  114. }
  115. loadcache(array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist', 'albumcategory'));
  116. if(empty($_GET['syncbbs'])) {
  117. $_GET['subject'] = cutstr($_GET['message'], 75, '');
  118. }
  119. $_POST['replysubmit'] = true;
  120. $_GET['fid'] = $fid;
  121. $_GET['action'] = 'newthread';
  122. $_GET['allownoticeauthor'] = '1';
  123. include_once libfile('function/forum');
  124. require_once libfile('function/post');
  125. loadforum();
  126. $_G['forum']['picstyle'] = 0;
  127. $skipmsg = 1;
  128. include_once libfile('forum/post', 'module');
  129. }
  130. } elseif($op == 'relay') {
  131. if(!helper_access::check_module('follow')) {
  132. showmessage('quickclear_noperm');
  133. }
  134. $tid = intval($_GET['tid']);
  135. $preview = $post = array();
  136. $preview = C::t('forum_threadpreview')->fetch($tid);
  137. if(empty($preview)) {
  138. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
  139. if($post['anonymous']) {
  140. showmessage('follow_anonymous_unfollow');
  141. }
  142. }
  143. if(empty($post) && empty($preview)) {
  144. showmessage('follow_content_not_exist');
  145. }
  146. if(submitcheck('relaysubmit')) {
  147. if(strlen($_GET['note'])>140) {
  148. showmessage('follow_input_word_limit');
  149. }
  150. $count = C::t('home_follow_feed')->count_by_uid_tid($_G['uid'], $tid);
  151. if(!$count) {
  152. $count = C::t('home_follow_feed')->count_by_uid_tid($_G['uid'], $tid);
  153. }
  154. if($count && empty($_GET['addnewreply'])) {
  155. showmessage('follow_only_allow_the_relay_time');
  156. }
  157. if($_GET['addnewreply']) {
  158. $_G['setting']['seccodestatus'] = 0;
  159. $_G['setting']['secqaa']['status'] = 0;
  160. $_POST['replysubmit'] = true;
  161. $_GET['tid'] = $tid;
  162. $_GET['action'] = 'reply';
  163. $_GET['message'] = $_GET['note'];
  164. include_once libfile('function/forum');
  165. require_once libfile('function/post');
  166. loadforum();
  167. $inspacecpshare = 1;
  168. include_once libfile('forum/post', 'module');
  169. }
  170. require_once libfile('function/discuzcode');
  171. require_once libfile('function/followcode');
  172. $followfeed = array(
  173. 'uid' => $_G['uid'],
  174. 'username' => $_G['username'],
  175. 'tid' => $tid,
  176. 'note' => cutstr(followcode(dhtmlspecialchars($_GET['note']), 0, 0, 0, false), 140),
  177. 'dateline' => TIMESTAMP
  178. );
  179. C::t('home_follow_feed')->insert($followfeed);
  180. C::t('common_member_count')->increase($_G['uid'], array('feeds'=>1));
  181. if(empty($preview)) {
  182. require_once libfile('function/discuzcode');
  183. require_once libfile('function/followcode');
  184. $feedcontent = array(
  185. 'tid' => $tid,
  186. 'content' => followcode($post['message'], $post['tid'], $post['pid'], 1000),
  187. );
  188. C::t('forum_threadpreview')->insert($feedcontent);
  189. C::t('forum_thread')->update_status_by_tid($tid, '512');
  190. } else {
  191. C::t('forum_threadpreview')->update_relay_by_tid($tid, 1);
  192. }
  193. showmessage('relay_feed_success', dreferer(), array(), array('showdialog'=>true, 'closetime' => true));
  194. }
  195. $fastpost = $_G['setting']['fastpost'];
  196. } elseif($op == 'checkfeed') {
  197. header('Content-Type: text/javascript');
  198. require_once libfile("function/member");
  199. checkfollowfeed();
  200. exit;
  201. } elseif($op == 'getfeed') {
  202. $archiver = $_GET['archiver'] ? true : false;
  203. $uid = intval($_GET['uid']);
  204. $page = empty($_GET['page']) ? 1 : intval($_GET['page']);
  205. if($page<1) $page=1;
  206. $perpage = 20;
  207. $start = ($page-1)*$perpage;
  208. if($uid) {
  209. $list = getfollowfeed($uid, 'self', $archiver, $start, $perpage);
  210. } else {
  211. $type = in_array($_GET['viewtype'], array('special', 'follow', 'other')) ? $_GET['viewtype'] : 'follow';
  212. $list = getfollowfeed($type == 'other' ? 0 : $_G['uid'], $type, $archiver, $start, $perpage);
  213. }
  214. if(empty($list['feed'])) {
  215. $list = false;
  216. }
  217. if(!isset($_G['cache']['forums'])) {
  218. loadcache('forums');
  219. }
  220. } elseif($op == 'delete') {
  221. $archiver = false;
  222. $feed = C::t('home_follow_feed')->fetch_by_feedid($_GET['feedid']);
  223. if(empty($feed)) {
  224. $feed = C::t('home_follow_feed')->fetch_by_feedid($_GET['feedid'], true);
  225. $archiver = true;
  226. }
  227. if(empty($feed)) {
  228. showmessage('follow_specify_follow_not_exist', '', array(), array('return' => true));
  229. } elseif($feed['uid'] != $_G['uid'] && $_G['adminid'] != 1) {
  230. showmessage('quickclear_noperm', '', array(), array('return' => true));
  231. }
  232. if(submitcheck('deletesubmit')) {
  233. if(C::t('home_follow_feed')->delete_by_feedid($_GET['feedid'], $archiver)) {
  234. C::t('common_member_count')->increase($feed['uid'], array('feeds'=>-1));
  235. C::t('forum_threadpreview')->update_relay_by_tid($feed['tid'], -1);
  236. showmessage('do_success', dreferer(), array('feedid' => $_GET['feedid']), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
  237. } else {
  238. showmessage('failed_to_delete_operation');
  239. }
  240. }
  241. }
  242. include template('home/spacecp_follow');
  243. ?>