spacecp_favorite.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_favorite.php 34278 2013-12-03 09:46:45Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $_GET['type'] = in_array($_GET['type'], array("thread", "forum", "group", "blog", "album", "article", "all")) ? $_GET['type'] : 'all';
  12. if($_GET['op'] == 'delete') {
  13. if($_GET['checkall']) {
  14. if($_GET['favorite']) {
  15. $deletecounter = array();
  16. $data = C::t('home_favorite')->fetch_all($_GET['favorite']);
  17. foreach($data as $dataone) {
  18. switch($dataone['idtype']) {
  19. case 'fid':
  20. $deletecounter['fids'][] = $dataone['id'];
  21. break;
  22. default:
  23. break;
  24. }
  25. }
  26. if($deletecounter['fids']) {
  27. C::t('forum_forum')->update_forum_counter($deletecounter['fids'], 0, 0, 0, 0, -1);
  28. }
  29. C::t('home_favorite')->delete($_GET['favorite'], false, $_G['uid']);
  30. if($_G['setting']['cloud_status']) {
  31. $favoriteService = Cloud::loadClass('Service_Client_Favorite');
  32. $favoriteService->remove($_G['uid'], $_GET['favorite'], TIMESTAMP);
  33. }
  34. }
  35. showmessage('favorite_delete_succeed', 'home.php?mod=space&uid='.$_G['uid'].'&do=favorite&view=me&type='.$_GET['type'].'&quickforward=1');
  36. } else {
  37. $favid = intval($_GET['favid']);
  38. $thevalue = C::t('home_favorite')->fetch($favid);
  39. if(empty($thevalue) || $thevalue['uid'] != $_G['uid']) {
  40. showmessage('favorite_does_not_exist');
  41. }
  42. if(submitcheck('deletesubmit')) {
  43. switch($thevalue['idtype']) {
  44. case 'fid':
  45. C::t('forum_forum')->update_forum_counter($thevalue['id'], 0, 0, 0, 0, -1);
  46. break;
  47. default:
  48. break;
  49. }
  50. C::t('home_favorite')->delete($favid);
  51. if($_G['setting']['cloud_status']) {
  52. $favoriteService = Cloud::loadClass('Service_Client_Favorite');
  53. $favoriteService->remove($_G['uid'], $favid);
  54. }
  55. showmessage('do_success', 'home.php?mod=space&uid='.$_G['uid'].'&do=favorite&view=me&type='.$_GET['type'].'&quickforward=1', array('favid' => $favid, 'id' => $thevalue['id']), array('showdialog'=>1, 'showmsg' => true, 'closetime' => true, 'locationtime' => 3));
  56. }
  57. }
  58. } else {
  59. cknewuser();
  60. $type = empty($_GET['type']) ? '' : $_GET['type'];
  61. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  62. $spaceuid = empty($_GET['spaceuid']) ? 0 : intval($_GET['spaceuid']);
  63. $idtype = $title = $icon = '';
  64. switch($type) {
  65. case 'thread':
  66. $idtype = 'tid';
  67. $thread = C::t('forum_thread')->fetch($id);
  68. $title = $thread['subject'];
  69. $icon = '<img src="static/image/feed/thread.gif" alt="thread" class="vm" /> ';
  70. break;
  71. case 'forum':
  72. $idtype = 'fid';
  73. $foruminfo = C::t('forum_forum')->fetch($id);
  74. loadcache('forums');
  75. $forum = $_G['cache']['forums'][$id];
  76. if(!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'])) || strstr($forum['users'], "\t$_G[uid]\t")) {
  77. $title = $foruminfo['status'] != 3 ? $foruminfo['name'] : '';
  78. $icon = '<img src="static/image/feed/discuz.gif" alt="forum" class="vm" /> ';
  79. }
  80. break;
  81. case 'blog':
  82. $idtype = 'blogid';
  83. $bloginfo = C::t('home_blog')->fetch($id);
  84. $title = ($bloginfo['uid'] == $spaceuid) ? $bloginfo['subject'] : '';
  85. $icon = '<img src="static/image/feed/blog.gif" alt="blog" class="vm" /> ';
  86. break;
  87. case 'group':
  88. $idtype = 'gid';
  89. $foruminfo = C::t('forum_forum')->fetch($id);
  90. $title = $foruminfo['status'] == 3 ? $foruminfo['name'] : '';
  91. $icon = '<img src="static/image/feed/group.gif" alt="group" class="vm" /> ';
  92. break;
  93. case 'album':
  94. $idtype = 'albumid';
  95. $result = C::t('home_album')->fetch($id, $spaceuid);
  96. $title = $result['albumname'];
  97. $icon = '<img src="static/image/feed/album.gif" alt="album" class="vm" /> ';
  98. break;
  99. case 'space':
  100. $idtype = 'uid';
  101. $_member = getuserbyuid($id);
  102. $title = $_member['username'];
  103. $unset($_member);
  104. $icon = '<img src="static/image/feed/profile.gif" alt="space" class="vm" /> ';
  105. break;
  106. case 'article':
  107. $idtype = 'aid';
  108. $article = C::t('portal_article_title')->fetch($id);
  109. $title = $article['title'];
  110. $icon = '<img src="static/image/feed/article.gif" alt="article" class="vm" /> ';
  111. break;
  112. }
  113. if(empty($idtype) || empty($title)) {
  114. showmessage('favorite_cannot_favorite');
  115. }
  116. $fav = C::t('home_favorite')->fetch_by_id_idtype($id, $idtype, $_G['uid']);
  117. if($fav) {
  118. showmessage('favorite_repeat');
  119. }
  120. $description = $extrajs = '';
  121. $description_show = nl2br($description);
  122. $fav_count = C::t('home_favorite')->count_by_id_idtype($id, $idtype);
  123. if(submitcheck('favoritesubmit') || ($type == 'forum' || $type == 'group' || $type == 'thread') && $_GET['formhash'] == FORMHASH) {
  124. $arr = array(
  125. 'uid' => intval($_G['uid']),
  126. 'idtype' => $idtype,
  127. 'id' => $id,
  128. 'spaceuid' => $spaceuid,
  129. 'title' => getstr($title, 255),
  130. 'description' => getstr($_POST['description'], '', 0, 0, 1),
  131. 'dateline' => TIMESTAMP
  132. );
  133. $favid = C::t('home_favorite')->insert($arr, true);
  134. if($_G['setting']['cloud_status']) {
  135. $favoriteService = Cloud::loadClass('Service_Client_Favorite');
  136. $favoriteService->add($arr['uid'], $favid, $arr['id'], $arr['idtype'], $arr['title'], $arr['description'], TIMESTAMP);
  137. }
  138. switch($type) {
  139. case 'thread':
  140. C::t('forum_thread')->increase($id, array('favtimes'=>1));
  141. require_once libfile('function/forum');
  142. update_threadpartake($id);
  143. break;
  144. case 'forum':
  145. C::t('forum_forum')->update_forum_counter($id, 0, 0, 0, 0, 1);
  146. $extrajs = '<script type="text/javascript">$("number_favorite_num").innerHTML = parseInt($("number_favorite_num").innerHTML)+1;$("number_favorite").style.display="";</script>';
  147. dsetcookie('nofavfid', '', -1);
  148. break;
  149. case 'blog':
  150. C::t('home_blog')->increase($id, $spaceuid, array('favtimes' => 1));
  151. break;
  152. case 'group':
  153. C::t('forum_forum')->update_forum_counter($id, 0, 0, 0, 0, 1);
  154. break;
  155. case 'album':
  156. C::t('home_album')->update_num_by_albumid($id, 1, 'favtimes', $spaceuid);
  157. break;
  158. case 'space':
  159. C::t('common_member_status')->increase($id, array('favtimes' => 1));
  160. break;
  161. case 'article':
  162. C::t('portal_article_count')->increase($id, array('favtimes' => 1));
  163. break;
  164. }
  165. showmessage('favorite_do_success', dreferer(), array('id' => $id, 'favid' => $favid), array('showdialog' => true, 'closetime' => true, 'extrajs' => $extrajs));
  166. }
  167. }
  168. include template('home/spacecp_favorite');
  169. ?>