PageRenderTime 36ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/source/include/spacecp/spacecp_click.php

https://github.com/kuaileshike/upload
PHP | 193 lines | 156 code | 31 blank | 6 comment | 21 complexity | d18e77fa90d10d98e48c9d16c78b1d66 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: spacecp_click.php 25756 2011-11-22 02:47:45Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $clickid = empty($_GET['clickid'])?0:intval($_GET['clickid']);
  12. $idtype = empty($_GET['idtype'])?'':trim($_GET['idtype']);
  13. $id = empty($_GET['id'])?0:intval($_GET['id']);
  14. loadcache('click');
  15. $clicks = empty($_G['cache']['click'][$idtype])?array():$_G['cache']['click'][$idtype];
  16. $click = $clicks[$clickid];
  17. if(empty($click)) {
  18. showmessage('click_error');
  19. }
  20. switch ($idtype) {
  21. case 'picid':
  22. $item = C::t('home_pic')->fetch($id);
  23. if($item) {
  24. $picfield = C::t('home_picfield')->fetch($id);
  25. $album = C::t('home_album')->fetch($item['albumid']);
  26. $item['hotuser'] = $picfield['hotuser'];
  27. $item['friend'] = $album['friend'];
  28. $item['username'] = $album['username'];
  29. }
  30. $tablename = 'home_pic';
  31. break;
  32. case 'aid':
  33. $item = C::t('portal_article_title')->fetch($id);
  34. $tablename = 'portal_article_title';
  35. break;
  36. default:
  37. $idtype = 'blogid';
  38. $item = array_merge(
  39. C::t('home_blog')->fetch($id),
  40. C::t('home_blogfield')->fetch($id)
  41. );
  42. $tablename = 'home_blog';
  43. break;
  44. }
  45. if(!$item) {
  46. showmessage('click_item_error');
  47. }
  48. $hash = md5($item['uid']."\t".$item['dateline']);
  49. if($_GET['op'] == 'add') {
  50. if(!checkperm('allowclick') || $_GET['hash'] != $hash) {
  51. showmessage('no_privilege_click');
  52. }
  53. if($item['uid'] == $_G['uid']) {
  54. showmessage('click_no_self');
  55. }
  56. if(isblacklist($item['uid'])) {
  57. showmessage('is_blacklist');
  58. }
  59. if(C::t('home_clickuser')->count_by_uid_id_idtype($space[uid], $id, $idtype)) {
  60. showmessage('click_have');
  61. }
  62. $setarr = array(
  63. 'uid' => $space['uid'],
  64. 'username' => $_G['username'],
  65. 'id' => $id,
  66. 'idtype' => $idtype,
  67. 'clickid' => $clickid,
  68. 'dateline' => $_G['timestamp']
  69. );
  70. C::t('home_clickuser')->insert($setarr);
  71. C::t($tablename)->update_click($id, $clickid, 1);
  72. hot_update($idtype, $id, $item['hotuser']);
  73. $note_type = '';
  74. $q_note = '';
  75. $q_note_values = array();
  76. $fs = array();
  77. switch ($idtype) {
  78. case 'blogid':
  79. $fs['title_template'] = 'feed_click_blog';
  80. $fs['title_data'] = array(
  81. 'touser' => "<a href=\"home.php?mod=space&uid=$item[uid]\">{$item[username]}</a>",
  82. 'subject' => "<a href=\"home.php?mod=space&uid=$item[uid]&do=blog&id=$item[blogid]\">$item[subject]</a>",
  83. 'click' => $click['name']
  84. );
  85. $note_type = 'clickblog';
  86. $q_note = 'click_blog';
  87. $q_note_values = array(
  88. 'url'=>"home.php?mod=space&uid=$item[uid]&do=blog&id=$item[blogid]",
  89. 'subject'=>$item['subject'],
  90. 'from_id' => $item['blogid'],
  91. 'from_idtype' => 'blogid'
  92. );
  93. break;
  94. case 'aid':
  95. $fs['title_template'] = 'feed_click_article';
  96. $fs['title_data'] = array(
  97. 'touser' => "<a href=\"home.php?mod=space&uid=$item[uid]\">{$item[username]}</a>",
  98. 'subject' => "<a href=\"portal.php?mod=view&aid=$item[aid]\">$item[title]</a>",
  99. 'click' => $click['name']
  100. );
  101. $note_type = 'clickarticle';
  102. $q_note = 'click_article';
  103. $q_note_values = array(
  104. 'url'=>"portal.php?mod=view&aid=$item[aid]",
  105. 'subject'=>$item['title'],
  106. 'from_id' => $item['aid'],
  107. 'from_idtype' => 'aid'
  108. );
  109. break;
  110. case 'picid':
  111. $fs['title_template'] = 'feed_click_pic';
  112. $fs['title_data'] = array(
  113. 'touser' => "<a href=\"home.php?mod=space&uid=$item[uid]\">{$item[username]}</a>",
  114. 'click' => $click['name']
  115. );
  116. $fs['images'] = array(pic_get($item['filepath'], 'album', $item['thumb'], $item['remote']));
  117. $fs['image_links'] = array("home.php?mod=space&uid=$item[uid]&do=album&picid=$item[picid]");
  118. $fs['body_general'] = $item['title'];
  119. $note_type = 'clickpic';
  120. $q_note = 'click_pic';
  121. $q_note_values = array(
  122. 'url'=>"home.php?mod=space&uid=$item[uid]&do=album&picid=$item[picid]",
  123. 'from_id' => $item['picid'],
  124. 'from_idtype' => 'picid'
  125. );
  126. break;
  127. }
  128. if(empty($item['friend']) && ckprivacy('click', 'feed')) {
  129. require_once libfile('function/feed');
  130. $fs['title_data']['hash_data'] = "{$idtype}{$id}";
  131. feed_add('click', $fs['title_template'], $fs['title_data'], '', array(), $fs['body_general'],$fs['images'], $fs['image_links']);
  132. }
  133. updatecreditbyaction('click', 0, array(), $idtype.$id);
  134. require_once libfile('function/stat');
  135. updatestat('click');
  136. notification_add($item['uid'], $note_type, $q_note, $q_note_values);
  137. showmessage('click_success', '', array('idtype' => $idtype, 'id' => $id, 'clickid' => $clickid), array('msgtype' => 3, 'showmsg' => true, 'closetime' => true));
  138. } elseif ($_GET['op'] == 'show') {
  139. $maxclicknum = 0;
  140. foreach ($clicks as $key => $value) {
  141. $value['clicknum'] = $item["click{$key}"];
  142. $value['classid'] = mt_rand(1, 4);
  143. if($value['clicknum'] > $maxclicknum) $maxclicknum = $value['clicknum'];
  144. $clicks[$key] = $value;
  145. }
  146. $perpage = 18;
  147. $page = intval($_GET['page']);
  148. $start = ($page-1)*$perpage;
  149. if($start < 0) $start = 0;
  150. $count = C::t('home_clickuser')->count_by_id_idtype($id, $idtype);
  151. $clickuserlist = array();
  152. $click_multi = '';
  153. if($count) {
  154. foreach(C::t('home_clickuser')->fetch_all_by_id_idtype($id, $idtype, $start, $perpage) as $value) {
  155. $value['clickname'] = $clicks[$value['clickid']]['name'];
  156. $clickuserlist[] = $value;
  157. }
  158. $click_multi = multi($count, $perpage, $page, "home.php?mod=spacecp&ac=click&op=show&clickid=$clickid&idtype=$idtype&id=$id");
  159. }
  160. }
  161. include_once(template('home/spacecp_click'));
  162. ?>