spacecp_share.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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_share.php 33291 2013-05-22 05:59:13Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $sid = intval($_GET['sid']);
  12. if($_GET['op'] == 'delete') {
  13. if(submitcheck('deletesubmit')) {
  14. require_once libfile('function/delete');
  15. deleteshares(array($sid));
  16. showmessage('do_success', $_GET['type']=='view'?'home.php?mod=space&quickforward=1&do=share':dreferer(), array('sid' => $sid), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true));
  17. }
  18. } elseif($_GET['op'] == 'edithot') {
  19. if(!checkperm('manageshare')) {
  20. showmessage('no_privilege_edithot_share');
  21. }
  22. if($sid) {
  23. if(!$share = C::t('home_share')->fetch($sid)) {
  24. showmessage('share_does_not_exist');
  25. }
  26. }
  27. if(submitcheck('hotsubmit')) {
  28. C::t('home_share')->update($sid, array('hot'=>$_POST['hot']));
  29. C::t('home_feed')->update($sid, array('hot'=>$_POST['hot']), 'sid');
  30. showmessage('do_success', dreferer());
  31. }
  32. } else {
  33. if(!checkperm('allowshare') || !helper_access::check_module('share')) {
  34. showmessage('no_privilege_share');
  35. }
  36. cknewuser();
  37. $type = empty($_GET['type'])?'':$_GET['type'];
  38. $id = empty($_GET['id'])?0:intval($_GET['id']);
  39. $note_uid = 0;
  40. $note_message = '';
  41. $note_values = array();
  42. $hotarr = array();
  43. $arr = array();
  44. $feed_hash_data = '';
  45. switch ($type) {
  46. case 'space':
  47. $feed_hash_data = "uid{$id}";
  48. $tospace = getuserbyuid($id);
  49. if(empty($tospace)) {
  50. showmessage('space_does_not_exist');
  51. }
  52. if(isblacklist($tospace['uid'])) {
  53. showmessage('is_blacklist');
  54. }
  55. $arr['itemid'] = $id;
  56. $arr['fromuid'] = $id;
  57. $arr['title_template'] = lang('spacecp', 'share_space');
  58. $arr['body_template'] = '<b>{username}</b><br>{reside}<br>{spacenote}';
  59. $arr['body_data'] = array(
  60. 'username' => "<a href=\"home.php?mod=space&uid=$id\">".$tospace['username']."</a>",
  61. 'reside' => $tospace['resideprovince'].$tospace['residecity'],
  62. 'spacenote' => $tospace['spacenote']
  63. );
  64. loaducenter();
  65. $isavatar = uc_check_avatar($id);
  66. $arr['image'] = $isavatar?avatar($id, 'middle', true):UC_API.'/images/noavatar_middle.gif';
  67. $arr['image_link'] = "home.php?mod=space&uid=$id";
  68. $note_uid = $id;
  69. $note_message = 'share_space';
  70. break;
  71. case 'blog':
  72. $feed_hash_data = "blogid{$id}";
  73. $blog = array_merge(
  74. C::t('home_blog')->fetch($id),
  75. C::t('home_blogfield')->fetch($id)
  76. );
  77. if(!$blog) {
  78. showmessage('blog_does_not_exist');
  79. }
  80. if(in_array($blog['status'], array(1, 2))) {
  81. showmessage('moderate_blog_not_share');
  82. }
  83. if($blog['friend']) {
  84. showmessage('logs_can_not_share');
  85. }
  86. if(isblacklist($blog['uid'])) {
  87. showmessage('is_blacklist');
  88. }
  89. $arr['fromuid'] = $blog['uid'];
  90. $arr['itemid'] = $id;
  91. $arr['title_template'] = lang('spacecp', 'share_blog');
  92. $arr['body_template'] = '<b>{subject}</b><br>{username}<br>{message}';
  93. $arr['body_data'] = array(
  94. 'subject' => "<a href=\"home.php?mod=space&uid=$blog[uid]&do=blog&id=$blog[blogid]\">$blog[subject]</a>",
  95. 'username' => "<a href=\"home.php?mod=space&uid=$blog[uid]\">".$blog['username']."</a>",
  96. 'message' => getstr($blog['message'], 150, 0, 0, 0, -1)
  97. );
  98. if($blog['pic']) {
  99. $arr['image'] = pic_cover_get($blog['pic'], $blog['picflag']);
  100. $arr['image_link'] = "home.php?mod=space&uid=$blog[uid]&do=blog&id=$blog[blogid]";
  101. }
  102. $note_uid = $blog['uid'];
  103. $note_message = 'share_blog';
  104. $note_values = array('url'=>"home.php?mod=space&uid=$blog[uid]&do=blog&id=$blog[blogid]", 'subject'=>$blog['subject'], 'from_id' => $id, 'from_idtype' => 'blogid');
  105. $hotarr = array('blogid', $blog['blogid'], $blog['hotuser']);
  106. break;
  107. case 'album':
  108. $feed_hash_data = "albumid{$id}";
  109. if(!$album = C::t('home_album')->fetch($id)) {
  110. showmessage('album_does_not_exist');
  111. }
  112. if($album['friend']) {
  113. showmessage('album_can_not_share');
  114. }
  115. if(isblacklist($album['uid'])) {
  116. showmessage('is_blacklist');
  117. }
  118. $arr['itemid'] = $id;
  119. $arr['fromuid'] = $album['uid'];
  120. $arr['title_template'] = lang('spacecp', 'share_album');
  121. $arr['body_template'] = '<b>{albumname}</b><br>{username}';
  122. $arr['body_data'] = array(
  123. 'albumname' => "<a href=\"home.php?mod=space&uid=$album[uid]&do=album&id=$album[albumid]\">$album[albumname]</a>",
  124. 'username' => "<a href=\"home.php?mod=space&uid=$album[uid]\">".$album['username']."</a>"
  125. );
  126. $arr['image'] = pic_cover_get($album['pic'], $album['picflag']);
  127. $arr['image_link'] = "home.php?mod=space&uid=$album[uid]&do=album&id=$album[albumid]";
  128. $note_uid = $album['uid'];
  129. $note_message = 'share_album';
  130. $note_values = array('url'=>"home.php?mod=space&uid=$album[uid]&do=album&id=$album[albumid]", 'albumname'=>$album['albumname'], 'from_id' => $id, 'from_idtype' => 'albumid');
  131. break;
  132. case 'pic':
  133. $feed_hash_data = "picid{$id}";
  134. $pic = C::t('home_pic')->fetch($id);
  135. if(!$pic) {
  136. showmessage('image_does_not_exist');
  137. }
  138. $picfield = C::t('home_picfield')->fetch($id);
  139. $album = C::t('home_album')->fetch($pic['albumid']);
  140. $pic = array_merge($pic, $picfield, $album);
  141. if(in_array($pic['status'], array(1, 2))) {
  142. showmessage('moderate_pic_not_share');
  143. }
  144. if($pic['friend']) {
  145. showmessage('image_can_not_share');
  146. }
  147. if(isblacklist($pic['uid'])) {
  148. showmessage('is_blacklist');
  149. }
  150. if(empty($pic['albumid'])) $pic['albumid'] = 0;
  151. if(empty($pic['albumname'])) $pic['albumname'] = lang('spacecp', 'default_albumname');
  152. $arr['itemid'] = $id;
  153. $arr['fromuid'] = $pic['uid'];
  154. $arr['title_template'] = lang('spacecp', 'share_image');
  155. $arr['body_template'] = lang('spacecp', 'album').': <b>{albumname}</b><br>{username}<br>{title}';
  156. $arr['body_data'] = array(
  157. 'albumname' => "<a href=\"home.php?mod=space&uid=$pic[uid]&do=album&id=$pic[albumid]\">$pic[albumname]</a>",
  158. 'username' => "<a href=\"home.php?mod=space&uid=$pic[uid]\">".$pic['username']."</a>",
  159. 'title' => getstr($pic['title'], 100, 0, 0, 0, -1)
  160. );
  161. $arr['image'] = pic_get($pic['filepath'], 'album', $pic['thumb'], $pic['remote']);
  162. $arr['image_link'] = "home.php?mod=space&uid=$pic[uid]&do=album&picid=$pic[picid]";
  163. $note_uid = $pic['uid'];
  164. $note_message = 'share_pic';
  165. $note_values = array('url'=>"home.php?mod=space&uid=$pic[uid]&do=album&picid=$pic[picid]", 'albumname'=>$pic['albumname'], 'from_id' => $id, 'from_idtype' => 'picid');
  166. $hotarr = array('picid', $pic['picid'], $pic['hotuser']);
  167. break;
  168. case 'thread':
  169. $feed_hash_data = "tid{$id}";
  170. $actives = array('share' => ' class="active"');
  171. $thread = C::t('forum_thread')->fetch($id);
  172. if(in_array($thread['displayorder'], array(-2, -3))) {
  173. showmessage('moderate_thread_not_share');
  174. }
  175. require_once libfile('function/post');
  176. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($id);
  177. $arr['title_template'] = lang('spacecp', 'share_thread');
  178. $arr['body_template'] = '<b>{subject}</b><br>{author}<br>{message}';
  179. $attachment = !preg_match("/\[hide=?\d*\](.*?)\[\/hide\]/is", $post['message'], $a) && preg_match("/\[attach\]\d+\[\/attach\]/i", $a[1]);
  180. $post['message'] = messagecutstr($post['message']);
  181. $arr['body_data'] = array(
  182. 'subject' => "<a href=\"forum.php?mod=viewthread&tid=$id\">$thread[subject]</a>",
  183. 'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>",
  184. 'message' => getstr($post['message'], 150, 0, 0, 0, -1)
  185. );
  186. $arr['itemid'] = $id;
  187. $arr['fromuid'] = $thread['authorid'];
  188. $attachment = $attachment ? C::t('forum_attachment_n')->fetch_max_image('tid:'.$id, 'tid', $id) : false;
  189. if($attachment) {
  190. $arr['image'] = pic_get($attachment['attachment'], 'forum', $attachment['thumb'], $attachment['remote'], 1);
  191. $arr['image_link'] = "forum.php?mod=viewthread&tid=$id";
  192. }
  193. $note_uid = $thread['authorid'];
  194. $note_message = 'share_thread';
  195. $note_values = array('url'=>"forum.php?mod=viewthread&tid=$id", 'subject'=>$thread['subject'], 'from_id' => $id, 'from_idtype' => 'tid');
  196. break;
  197. case 'article':
  198. $feed_hash_data = "articleid{$id}";
  199. $article = C::t('portal_article_title')->fetch($id);
  200. if(!$article) {
  201. showmessage('article_does_not_exist');
  202. }
  203. if(in_array($article['status'], array(1, 2))) {
  204. showmessage('moderate_article_not_share');
  205. }
  206. require_once libfile('function/portal');
  207. $article_url = fetch_article_url($article);
  208. $arr['itemid'] = $id;
  209. $arr['fromuid'] = $article['uid'];
  210. $arr['title_template'] = lang('spacecp', 'share_article');
  211. $arr['body_template'] = '<b>{title}</b><br>{username}<br>{summary}';
  212. $arr['body_data'] = array(
  213. 'title' => "<a href=\"$article_url\">$article[title]</a>",
  214. 'username' => "<a href=\"home.php?mod=space&uid=$article[uid]\">".$article['username']."</a>",
  215. 'summary' => getstr($article['summary'], 150, 0, 0, 0, -1)
  216. );
  217. if($article['pic']) {
  218. $arr['image'] = pic_get($article['pic'], 'portal', $article['thumb'], $article['remote'], 1, 1);
  219. $arr['image_link'] = $article_url;
  220. }
  221. $note_uid = $article['uid'];
  222. $note_message = 'share_article';
  223. $note_values = array('url'=>$article_url, 'subject'=>$article['title'], 'from_id' => $id, 'from_idtype' => 'aid');
  224. break;
  225. default:
  226. $actives = array('share' => ' class="active"');
  227. $_G['refer'] = 'home.php?mod=space&uid='.$_G['uid'].'&do=share&view=me';
  228. $type = 'link';
  229. $_GET['op'] = 'link';
  230. $linkdefault = 'http://';
  231. $generaldefault = '';
  232. break;
  233. }
  234. $commentcable = array('blog' => 'blogid', 'pic' => 'picid', 'thread' => 'thread', 'article' => 'article');
  235. if(submitcheck('sharesubmit', 0, $seccodecheck, $secqaacheck)) {
  236. $magvalues = array();
  237. $redirecturl = '';
  238. $showmessagecontent = '';
  239. if($type == 'link') {
  240. $link = dhtmlspecialchars(trim($_POST['link']));
  241. preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", $link, $matches);
  242. $link = $matches[0];
  243. if($link) {
  244. if(!preg_match("/^(http|ftp|https|mms)\:\/\/.{4,300}$/i", $link)) $link = '';
  245. }
  246. if(empty($link)) {
  247. showmessage('url_incorrect_format');
  248. }
  249. $arr['itemid'] = '0';
  250. $arr['fromuid'] = '0';
  251. $arr['title_template'] = lang('spacecp', 'share_link');
  252. $arr['body_template'] = '{link}';
  253. $link_text = sub_url($link, 45);
  254. $arr['body_data'] = array('link'=>"<a href=\"$link\" target=\"_blank\">".$link_text."</a>", 'data'=>$link);
  255. $parseLink = parse_url($link);
  256. require_once libfile('function/discuzcode');
  257. $flashvar = parseflv($link);
  258. if(empty($flashvar) && preg_match("/\.flv$/i", $link)) {
  259. $flashvar = array(
  260. 'flv' => $_G['style']['imgdir'].'/flvplayer.swf?&autostart=true&file='.urlencode($link),
  261. 'imgurl' => ''
  262. );
  263. }
  264. if(!empty($flashvar)) {
  265. $title = geturltitle($link);
  266. if($title) {
  267. $arr['body_data'] = array('link'=>"<a href=\"$link\" target=\"_blank\">".$title."</a>", 'data'=>$link);
  268. }
  269. $arr['title_template'] = lang('spacecp', 'share_video');
  270. $type = 'video';
  271. $arr['body_data']['flashvar'] = $flashvar['flv'];
  272. $arr['body_data']['host'] = 'flash';
  273. $arr['body_data']['imgurl'] = $flashvar['imgurl'];
  274. }
  275. if(preg_match("/\.(mp3|wma)$/i", $link)) {
  276. $arr['title_template'] = lang('spacecp', 'share_music');
  277. $arr['body_data']['musicvar'] = $link;
  278. $type = 'music';
  279. }
  280. if(preg_match("/\.swf$/i", $link)) {
  281. $arr['title_template'] = lang('spacecp', 'share_flash');
  282. $arr['body_data']['flashaddr'] = $link;
  283. $type = 'flash';
  284. }
  285. }
  286. if($_GET['iscomment'] && $_POST['general'] && $commentcable[$type] && $id) {
  287. $_POST['general'] = censor($_POST['general']);
  288. $currenttype = $commentcable[$type];
  289. $currentid = $id;
  290. if($currenttype == 'article') {
  291. $article = C::t('portal_article_title')->fetch($currentid);
  292. include_once libfile('function/portal');
  293. loadcache('portalcategory');
  294. $cat = $_G['cache']['portalcategory'][$article['catid']];
  295. $article['allowcomment'] = !empty($cat['allowcomment']) && !empty($article['allowcomment']) ? 1 : 0;
  296. if(!$article['allowcomment']) {
  297. showmessage('no_privilege_commentadd', '', array(), array('return' => true));
  298. }
  299. if($article['idtype'] == 'blogid') {
  300. $currentid = $article['id'];
  301. $currenttype = 'blogid';
  302. } elseif($article['idtype'] == 'tid') {
  303. $currentid = $article['id'];
  304. $currenttype = 'thread';
  305. }
  306. }
  307. if($currenttype == 'thread') {
  308. if($commentcable[$type] == 'article') {
  309. $_POST['portal_referer'] = $article_url ? $article_url : 'portal.php?mod=view&aid='.$id;
  310. }
  311. $modpost = C::m('forum_post', $currentid);
  312. $params = array(
  313. 'subject' => '',
  314. 'message' => $_POST['general'],
  315. );
  316. $modpost->newreply($params);
  317. if($_POST['portal_referer']) {
  318. $redirecturl = $_POST['portal_referer'];
  319. } else {
  320. if($modnewreplies) {
  321. $redirecturl = "forum.php?mod=viewthread&tid=".$currentid;
  322. } else {
  323. $redirecturl = "forum.php?mod=viewthread&tid=".$currentid."&pid=".$modpost->pid."&page=".$modpost->param('page')."&extra=".$extra."#pid".$modpost->pid;
  324. }
  325. }
  326. $showmessagecontent = ($modnewreplies && $commentcable[$type] != 'article') ? 'do_success_thread_share_mod' : '';
  327. } elseif($currenttype == 'article') {
  328. if(!checkperm('allowcommentarticle')) {
  329. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  330. }
  331. include_once libfile('function/spacecp');
  332. include_once libfile('function/portalcp');
  333. cknewuser();
  334. $waittime = interval_check('post');
  335. if($waittime > 0) {
  336. showmessage('operating_too_fast', '', array('waittime' => $waittime), array('return' => true));
  337. }
  338. $aid = intval($currentid);
  339. $message = $_POST['general'];
  340. $retmessage = addportalarticlecomment($aid, $message);
  341. if($retmessage != 'do_success') {
  342. showmessage($retmessage);
  343. }
  344. } elseif($currenttype == 'picid' || $currenttype == 'blogid') {
  345. if(!checkperm('allowcomment')) {
  346. showmessage('no_privilege_comment', '', array(), array('return' => true));
  347. }
  348. cknewuser();
  349. $waittime = interval_check('post');
  350. if($waittime > 0) {
  351. showmessage('operating_too_fast', '', array('waittime' => $waittime), array('return' => true));
  352. }
  353. $message = getstr($_POST['general'], 0, 0, 0, 2);
  354. if(strlen($message) < 2) {
  355. showmessage('content_is_too_short', '', array(), array('return' => true));
  356. }
  357. include_once libfile('class/bbcode');
  358. $bbcode = & bbcode::instance();
  359. require_once libfile('function/comment');
  360. $cidarr = add_comment($message, $currentid, $currenttype, 0);
  361. if($cidarr['cid']) {
  362. $magvalues['cid'] = $cidarr['cid'];
  363. $magvalues['id'] = $currentid;
  364. }
  365. }
  366. $magvalues['type'] = $commentcable[$type];
  367. }
  368. $arr['body_general'] = getstr($_POST['general'], 150, 0, 0, 1);
  369. $arr['body_general'] = censor($arr['body_general']);
  370. if(censormod($arr['body_general']) || $_G['group']['allowsharemod']) {
  371. $arr['status'] = 1;
  372. } else {
  373. $arr['status'] = 0;
  374. }
  375. $arr['type'] = $type;
  376. $arr['uid'] = $_G['uid'];
  377. $arr['username'] = $_G['username'];
  378. $arr['dateline'] = $_G['timestamp'];
  379. if($arr['status'] == 0 && ckprivacy('share', 'feed')) {
  380. require_once libfile('function/feed');
  381. feed_add('share',
  382. '{actor} '.$arr['title_template'],
  383. array('hash_data' => $feed_hash_data),
  384. $arr['body_template'],
  385. $arr['body_data'],
  386. $arr['body_general'],
  387. array($arr['image']),
  388. array($arr['image_link'])
  389. );
  390. }
  391. $arr['body_data'] = serialize($arr['body_data']);
  392. $sid = C::t('home_share')->insert($arr, true);
  393. switch($type) {
  394. case 'space':
  395. C::t('common_member_status')->increase($id, array('sharetimes' => 1));
  396. break;
  397. case 'blog':
  398. C::t('home_blog')->increase($id, null, array('sharetimes' => 1));
  399. break;
  400. case 'album':
  401. C::t('home_album')->update_num_by_albumid($id, 1, 'sharetimes');
  402. break;
  403. case 'pic':
  404. C::t('home_pic')->update_sharetimes($id);
  405. break;
  406. case 'thread':
  407. C::t('forum_thread')->increase($id, array('sharetimes' => 1));
  408. require_once libfile('function/forum');
  409. update_threadpartake($id);
  410. break;
  411. case 'article':
  412. C::t('portal_article_count')->increase($id, array('sharetimes' => 1));
  413. break;
  414. }
  415. if($arr['status'] == 1) {
  416. updatemoderate('sid', $sid);
  417. manage_addnotify('verifyshare');
  418. }
  419. if($type == 'link' || !(C::t('home_share')->count_by_uid_itemid_type($_G['uid'], $id ? $id : '', $type ? $type : ''))) {
  420. include_once libfile('function/stat');
  421. updatestat('share');
  422. }
  423. if($note_uid && $note_uid != $_G['uid']) {
  424. notification_add($note_uid, 'sharenotice', $note_message, $note_values);
  425. }
  426. $needle = $id ? $type.$id : '';
  427. updatecreditbyaction('createshare', $_G['uid'], array('sharings' => 1), $needle);
  428. $referer = "home.php?mod=space&uid=$_G[uid]&do=share&view=$_GET[view]&from=$_GET[from]";
  429. $magvalues['sid'] = $sid;
  430. if(!$redirecturl) {
  431. $redirecturl = dreferer();
  432. }
  433. if(!$showmessagecontent) {
  434. $showmessagecontent = 'do_success';
  435. }
  436. showmessage($showmessagecontent, $redirecturl, $magvalues, ($_G['inajax'] && $_GET['view'] != 'me' ? array('showdialog'=>1, 'showmsg' => true, 'closetime' => true) : array()));
  437. }
  438. $arr['body_data'] = serialize($arr['body_data']);
  439. require_once libfile('function/share');
  440. $arr = mkshare($arr);
  441. $arr['dateline'] = $_G['timestamp'];
  442. }
  443. if($type != 'link') {
  444. if((C::t('home_share')->count_by_uid_itemid_type($_G['uid'], $id ? $id : '', $type ? $type : ''))) {
  445. showmessage('spacecp_share_repeat');
  446. }
  447. }
  448. $share_count = C::t('home_share')->count_by_uid_itemid_type(0, $id ? $id : '', $type ? $type : '');
  449. include template('home/spacecp_share');
  450. ?>