PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/weibo/action/my.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 436 lines | 385 code | 34 blank | 17 comment | 114 complexity | a9488c424039159d53269adf5dcf9c8c MD5 | raw file
  1. <?php
  2. !defined('A_P') && exit('Forbidden');
  3. S::gp(array('do'));
  4. !$winduid && Showmsg('not_login');
  5. $USCR = 'user_weibo';
  6. S::gp(array('s'));
  7. if($s) {//底部快捷
  8. require_once(R_P.'require/showimg.php');
  9. list($faceurl) = showfacedesign($winddb['icon'],1,'m');
  10. require_once PrintEot('m_weibo_bottom');
  11. pwOutPut();
  12. }
  13. extract(L::config(null, 'o_config'));
  14. $whilelist = array(
  15. 'post','my','attention','refer','comment','lookround','filterweibo','ajax',
  16. 'transmit','postcomment','deletecomment','receive','replay','deleteweibo',
  17. 'conloy','topics','posttopic','page'
  18. );
  19. if (!in_array($do,$whilelist)) {
  20. $do = 'my';
  21. }
  22. $nav = !in_array($do,array('receive')) ? array($do => 'class="current"') : array('refer' => 'class="current"');
  23. $perpage = 20;
  24. if ($do == 'post') {
  25. PostCheck();
  26. S::gp(array('atc_content'),'GP');
  27. S::gp(array('uploadPic', 'ismessage','type'), 'GP');
  28. $type != 'sendweibo' && $type = 'weibo';
  29. if ($o_weibourl != 1) {
  30. preg_match('/http:\/\//i', $atc_content) && Showmsg('weibo_link_close');
  31. }
  32. $userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */
  33. if ($db_tcheck ){
  34. require_once(R_P.'require/postfunc.php');
  35. $userInfo = $userService->get($winduid,false,true);
  36. $userInfo['postcheck'] = unserialize($userInfo['postcheck']);
  37. $userInfo['postcheck']['weibo'] == tcheck($atc_content) && Showmsg('weibo_content_same'); //內容驗證
  38. }
  39. preg_match_all('/@([^\\&\'"\/\*,<>\r\t\n\s#%?@::]+)\s?/i', $atc_content, $matchs);
  40. if($matchs[1]){
  41. $atUids = array();
  42. foreach($matchs[1] as $v){
  43. if(!$v) continue;
  44. $atUids[] = $userService->getUserIdByUserName($v);
  45. }
  46. $attentionService = L::loadClass('Attention', 'friend');/* @var $attentionService PW_Attention */
  47. $blackList = $attentionService->getBlackListToMe($winduid, $atUids);
  48. if($blackList) Showmsg('weibo_cannot_at');
  49. }
  50. if (($return = $weiboService->sendCheck($atc_content, $groupid)) !== true) {
  51. Showmsg($return);
  52. }
  53. if ($ismessage) {
  54. require_once(A_P . 'weibo/require/sendmessage.php');
  55. }
  56. $extra = array();
  57. if ($uploadPic && is_array($uploadPic)) {
  58. $array = array();
  59. $query = $db->query("SELECT p.* FROM pw_cnphoto p LEFT JOIN pw_cnalbum a ON p.aid=a.aid WHERE p.pid IN (" . S::sqlImplode($uploadPic) . ")");
  60. while ($rt = $db->fetch_array($query)) {
  61. $array[$rt['pid']] = $rt;
  62. }
  63. $extra['photos'] = $array;
  64. }
  65. if ($weiboService->send($winduid, $atc_content, $type, 0, $extra)) {
  66. if ($db_tcheck) {
  67. $userInfo['postcheck']['weibo'] = tcheck($atc_content);
  68. $userService->update($winduid, array(), array('postcheck' => serialize($userInfo['postcheck'])));
  69. }
  70. weibocredit('weibo_Post');
  71. Showmsg('mode_o_write_success');
  72. } else {
  73. Showmsg('undefined_action');
  74. }
  75. } elseif ($do == 'my') {
  76. S::gp(array('createtopic'),'G');
  77. $count = $weiboService->getUserWeibosCount($winduid);
  78. $pageCount = ceil($count / $perpage);
  79. $page = validatePage($page,$pageCount);
  80. $weiboList = $weiboService->getUserWeibos($winduid,$page,$perpage);
  81. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=my&', null, 'weiboList.my');
  82. } elseif ($do == 'attention') {
  83. $count = $weiboService->getUserAttentionWeibosNotMeCount($winduid);
  84. $pageCount = ceil($count / $perpage);
  85. $page = validatePage($page,$pageCount);
  86. $weiboList = $weiboService->getUserAttentionWeibosNotMe($winduid,$page,$perpage);
  87. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=attention&', null, 'weiboList.attention');
  88. } elseif ($do == 'conloy') {
  89. $colonyids = array();
  90. $query = $db->query("SELECT cm.ifadmin,c.id FROM pw_cmembers cm LEFT JOIN pw_colonys c ON cm.colonyid=c.id LEFT JOIN pw_members cm2 ON c.admin=cm2.username WHERE cm.uid=" . S::sqlEscape($winduid) . " ORDER BY cm.addtime DESC");
  91. while ($rt = $db->fetch_array($query)) {
  92. if ($rt['ifadmin'] != '-1') {
  93. $colonyids[] = $rt['id'];
  94. }
  95. }
  96. $weiboService = L::loadClass('weibo','sns');/* @var $weiboService PW_Weibo */
  97. $count = $weiboService->getConloysWeibosCount($colonyids);
  98. $pageCount = ceil($count / $perpage);
  99. $page = validatePage($page,$pageCount);
  100. $weiboList = $weiboService->getConloysWeibos($colonyids,$page,$perpage);
  101. } elseif ($do == 'refer') {
  102. if ($winddb['newreferto'] > 0) {
  103. $userService = L::loadClass('UserService', 'user');
  104. $userService->update($winduid, array(), array('newreferto' => 0));
  105. $winddb['newreferto'] = 0;
  106. }
  107. $count = $weiboService->getRefersToMeCount($winduid);
  108. $pageCount = ceil($count / $perpage);
  109. $page = validatePage($page,$pageCount);
  110. $weiboList = $weiboService->getRefersToMe($winduid, $page, $perpage);
  111. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=refer&', null, 'weiboList.refer');
  112. } elseif ($do == 'receive') {
  113. if ($winddb['newcomment'] > 0) {
  114. $userService = L::loadClass('UserService', 'user');
  115. $userService->update($winduid, array(), array('newcomment' => 0));
  116. $winddb['newcomment'] = 0;
  117. }
  118. $commentService = L::loadClass("comment","sns");
  119. $count = $commentService->getUserReceiveCommentsCount($winduid);
  120. $pageCount = ceil($count / $perpage);
  121. $page = validatePage($page,$pageCount);
  122. $commentList = $commentService->getUserReceiveComments($winduid,$page,$perpage);
  123. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=receive&', null, 'weiboList.receive');
  124. } elseif ($do == 'replay') {
  125. S::gp(array('mid','uids','identify','commentpage'), 'GP');
  126. $perpage = 10;
  127. $commentService = L::loadClass("comment","sns");
  128. $userService = L::loadClass('UserService', 'user');
  129. $users = $userService->getByUserIds(array($uids));
  130. $users = current($users);
  131. $replayusername = '回復@'.$users['username'].' : ';
  132. $count = $commentService->getUserCommentOfRelpaysCount($winduid,$mid,$uids);
  133. $pageCount = ceil($count / $perpage);
  134. $page = validatePage($commentpage,$pageCount);
  135. $commentList = $commentService->getUserCommentOfRelpays($winduid,$mid,$uids,$page,$perpage);
  136. $id = $identify ? $mid.'_'.$identify : $mid;
  137. } elseif ($do == 'comment') {
  138. S::gp(array('mid','identify','commentpage','tid'), 'GP');
  139. $perpage = 10;
  140. $commentService = L::loadClass("comment","sns");
  141. $count = $commentService->getCommentsCountByMid($mid);
  142. $pageCount = ceil($count / $perpage);
  143. $page = validatePage($commentpage,$pageCount);
  144. $commentList = $commentService->getCommentsByMid($mid,$page,$perpage);
  145. $id = $identify ? $mid.'_'.$identify : $mid;
  146. } elseif ($do == 'postcomment') {
  147. S::gp(array('mid','ifsendweibo','writeContent','identify','tid','ifReplyThread'), 'GP');
  148. $writeContent = nl2br($writeContent);
  149. $commentService = L::loadClass("comment","sns");
  150. if (($status = $commentService->commentCheck($writeContent)) !== true) {
  151. Showmsg($status);
  152. }
  153. $result = $commentService->comment($winduid,$mid,$writeContent);
  154. if ($result) {
  155. $weiboService->updateCountNum(array('replies' => 1), $mid);
  156. if ($ifsendweibo) {
  157. if (($weiboStatus = $weiboService->sendCheck($writeContent, $groupid)) !== true) {
  158. Showmsg($weiboStatus);
  159. }
  160. $weiboService->send($winduid, $writeContent, 'transmit',$mid, array());
  161. $weiboService->updateCountNum(array('transmit' => 1), $mid);
  162. }
  163. if ($ifReplyThread) {
  164. if (($weiboService->checkReplyRight($tid)) !== true) {
  165. Showmsg('您不能對該貼進行回復');
  166. }
  167. $pingService = L::loadClass('ping', 'forum');
  168. $atc_content = $writeContent."\r\n\r\n[size=2][color=#a5a5a5]內容來自[新鮮事][/color] [/size]";
  169. $pingService->addPost($tid, $atc_content);
  170. }
  171. echo 'ok';
  172. } else {
  173. Showmsg("weibo_cannot_at");
  174. }
  175. $id = $identify ? $mid.'_'.$identify : $mid;
  176. } elseif ($do == 'deletecomment') {
  177. checkVerify();
  178. S::gp(array('cid','mid'));
  179. $weibo = $weiboService->getWeibosByMid($mid);
  180. $commentService = L::loadClass("comment","sns");
  181. if ($weibo['uid'] == $winduid || $commentService->checkCommentAuthor($cid) || S::inArray($windid, $manager)){
  182. if($commentService->deleteComment($cid)){
  183. $weiboService->updateCountNum(array('replies' => -1), $mid,'plus');
  184. }
  185. echo 'ok';
  186. } else {
  187. Showmsg("你沒有權限刪除該評論!");
  188. }
  189. } elseif($do == 'deleteweibo') {
  190. checkVerify();
  191. S::gp(array('mid'));
  192. $weibo = $weiboService->getWeibosByMid($mid);
  193. if ($weibo && ($weibo['uid'] == $winduid || $SYSTEM['delweibo'] || S::inArray($windid, $manager))) {
  194. $weiboService->deleteWeibos($mid);
  195. $type = $weiboService->getType($weibo['type']);
  196. if ($type == 'weibo') {
  197. weibocredit('weibo_Delete');
  198. }
  199. $userCache = L::loadClass('Usercache', 'user');
  200. $userCache->delete($weibo['uid'], 'weibo');
  201. echo 'ok';
  202. } else {
  203. Showmsg("您要刪除的微博不存在");
  204. }
  205. } elseif ($do == 'lookround') {
  206. /* platform weibo app */
  207. $isSiteBindWeibo = false;
  208. $siteBindService = L::loadClass('WeiboSiteBindService', 'sns/weibotoplatform/service'); /* @var $siteBindService PW_WeiboSiteBindService */
  209. if ($siteBindService->isOpen()) {
  210. $isSiteBindWeibo = true;
  211. $userBindService = L::loadClass('WeiboUserBindService', 'sns/weibotoplatform/service'); /* @var $userBindService PW_WeiboUserBindService */
  212. $userBindList = $userBindService->getBindList($winduid);
  213. $isUserBindOne = $userBindService->isBindOne($winduid);
  214. }
  215. $count = $weiboService->getWeibosCount();
  216. $pageCount = ceil($count / $perpage);
  217. $page = validatePage($page,$pageCount);
  218. $weiboList = $weiboService->getWeibos($page,$perpage);
  219. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=lookround&', null, 'weiboList.lookround');
  220. } elseif ($do == 'filterweibo') {
  221. S::gp(array('filter'));
  222. $count = $weiboService->getUserAttentionWeibosCount($winduid,$filter);
  223. $count > 200 && $count = 200;
  224. $pageCount = ceil($count / $perpage);
  225. $page = validatePage($page,$pageCount);
  226. $weiboList = $weiboService->getUserAttentionWeibos($winduid,$filter,$page,$perpage);
  227. $pages = numofpage($weiboCount, $page, ceil($count/$perpage), 'apps.php?q=weibo&do=attention&', 10, 'weiboList.filterWeibo');
  228. } elseif ($do == 'transmit') {
  229. S::gp(array('mid'), 'GP', 2);
  230. if (!$weibo = $weiboService->getWeibosByMid($mid)) {
  231. Showmsg('您轉發的新鮮事不存在,或已被刪除!');
  232. }
  233. $transmits = array();
  234. $type = $weiboService->getType($weibo['type']);
  235. if ($type == 'transmit' && $weibo['objectid']) {
  236. $transmits = $weiboService->getWeibosByMid($weibo['objectid']);
  237. }
  238. $attentionService = L::loadClass('Attention', 'friend');/* @var $attentionService PW_Attention */
  239. $blackList = $attentionService->getBlackListToMe($winduid, array($weibo['uid']));
  240. if (empty($_POST['step'])) {
  241. S::gp(array('istopic','topicname'), 'GP');
  242. $uids = array($weibo['uid']);
  243. if ($transmits) {
  244. $uids[] = $transmits['uid'];
  245. }
  246. $userService = L::loadClass('UserService', 'user');
  247. $uInfo = $userService->getByUserIds($uids);
  248. $weibo = array_merge($weibo, $uInfo[$weibo['uid']]);
  249. if ($transmits) {
  250. $showInfo = array_merge($transmits, $uInfo[$transmits['uid']]);
  251. $dString = ' ||@' . $weibo['username'] . ':' . $weibo['content'];
  252. } else {
  253. $showInfo = $weibo;
  254. $dString = '';
  255. }
  256. if (strpos($showInfo['content'],'[s:') !== false && strpos($showInfo['content'],']') !== false) {
  257. $sParse = L::loadClass('smileparser', 'smile');
  258. $showInfo['content'] = $sParse->parse($showInfo['content']);
  259. }
  260. $showInfo['extra'] = $showInfo['extra'] ? unserialize($showInfo['extra']) : array();
  261. $id = 'transmit_' . $id;
  262. } else {
  263. S::gp(array('atc_content','ifcomment'), 'P');
  264. $tmid = $transmits ? $weibo['objectid'] : $mid;
  265. if (($return = $weiboService->sendCheck($atc_content, $groupid,true)) !== true) {
  266. Showmsg($return);
  267. }
  268. if ($weiboService->send($winduid, $atc_content, 'transmit', $tmid)) {
  269. $weiboService->updateCountNum(array('transmit' => 1), $tmid);
  270. if($transmits){
  271. $weiboService->updateCountNum(array('transmit' => 1), $mid);
  272. }
  273. if ($ifcomment) {
  274. $commentService = L::loadClass("comment","sns");
  275. if($commentService->comment($winduid,$mid,$atc_content)){
  276. $weiboService->updateCountNum(array('replies' => 1), $mid);
  277. }
  278. }
  279. echo "success";
  280. ajax_footer();
  281. } else {
  282. Showmsg('undefined_action');
  283. }
  284. }
  285. } elseif ($do == 'topics') {
  286. /*話題 聚合頁*/
  287. S::gp(array('topic'));
  288. $weiboList = array();
  289. $topicService = L::loadClass('topic','sns'); /* @var $topicService PW_Topic */
  290. $weiboHotTopics = $topicService->getWeiboHotTopics();
  291. if ($topic) {
  292. $searcherService = L::loadclass ( 'searcher', 'search' ); /* @var $searcherService PW_Searcher */
  293. list ($count, $weiboList) = $searcherService->searchWeibo($topic,'','','',$page);
  294. //分頁
  295. $pageCount = ceil($count / $perpage);
  296. $page = validatePage($page,$pageCount);
  297. $pages = numofpage($count, $page, $pageCount, 'apps.php?q=weibo&do=topics&topic='.urlencode($topic).'&', null, 'weiboList.topics');
  298. //end
  299. is_array($weiboList) && $weiboList = $weiboService->buildData($weiboList);
  300. $topicInfo = (array)$topicService->getTopicByName($topic);
  301. $attentionedTopic = $topicService->getOneAttentionedTopic($topicInfo['topicid'],$winduid);
  302. } elseif ($weiboHotTopics) {
  303. $topicIds = array_keys($weiboHotTopics);
  304. $relations = (array)$topicService->getWeiboByTopicIds($topicIds, 20);
  305. $tmpWeibo = $weiboService->getWeibosByMid(array_keys($relations));
  306. $tmpWeibo = $weiboService->buildData($tmpWeibo);
  307. if (is_array($tmpWeibo)) {
  308. //用戶是否關注話題
  309. $attentionedTopics = $topicService->getAttentionedTopicByTopicIds($topicIds,$winduid);
  310. foreach ($relations as $k=>$v) {
  311. !$weiboList[$v['topicid']]['topic'] && $weiboList[$v['topicid']]['topic'] = $weiboHotTopics[$v['topicid']];
  312. $attentionedTopics[$v['topicid']] && $weiboList[$v['topicid']]['topic']['attentioned'] = 1;
  313. $weiboList[$v['topicid']]['weibo'][] = $tmpWeibo[$k];
  314. }
  315. }
  316. }
  317. } elseif ($do == 'posttopic') {
  318. S::gp(array('step','topic'), 'P');
  319. } elseif ($do == 'page') {
  320. S::gp(array('type','page'));
  321. if($type == 'attentionedtopics') {
  322. $page = intval($page);
  323. $attentionedTopics = array();
  324. $perpage = 10;
  325. !$topicService && $topicService = L::loadClass('topic','sns');
  326. $total = $topicService->getUserAttentionTopicNum($winduid);
  327. $pageCount = ceil($total / $perpage);
  328. $page = validatePage($page,$pageCount);
  329. $total && $attentionedTopics = (array)$topicService->getUserAttentionTopics($winduid,$page,$perpage);
  330. $page > 1 && $prepage = $page - 1;
  331. $page < $pageCount && $nextpage = $page + 1;
  332. }
  333. }
  334. if (defined('AJAX')) {
  335. require_once PrintEot('m_ajax');
  336. ajax_footer();
  337. } else {
  338. $userCache = L::loadClass('UserCache', 'user');
  339. $cacheData = $userCache->get($winduid, array('recommendUsers' => 3));
  340. $recommendUsers = $cacheData['recommendUsers'];
  341. if (perf::checkMemcache()){
  342. $_cacheService = Perf::gatherCache('pw_cache');
  343. $rt = $_cacheService->getCacheByName('weiboAuthorSort_5');
  344. } else {
  345. $rt = $db->get_one("SELECT * FROM pw_cache WHERE name='weiboAuthorSort_5'");
  346. }
  347. //$rt = $db->get_one("SELECT * FROM pw_cache WHERE name='weiboAuthorSort_5' AND time>" . S::sqlEscape($timestamp - 86400));
  348. if ($rt && $rt['time'] > $timestamp - 86400) {
  349. $weiboAuthorSort = unserialize($rt['cache']);
  350. is_array($weiboAuthorSort) || $weiboAuthorSort = array();
  351. } else {
  352. $weiboAuthorSort = $weiboService->getAuthorSort(5);
  353. pwQuery::replace(
  354. 'pw_cache',
  355. array(
  356. 'name' => 'weiboAuthorSort_5',
  357. 'cache' => serialize($weiboAuthorSort),
  358. 'time' => $timestamp
  359. )
  360. );
  361. /*
  362. $db->update("REPLACE INTO pw_cache SET " . S::sqlSingle(array(
  363. 'name' => 'weiboAuthorSort_5',
  364. 'cache' => serialize($weiboAuthorSort),
  365. 'time' => $timestamp
  366. )));
  367. */
  368. }
  369. /* 右側話題排行 */
  370. !$topicService && $topicService = L::loadClass('topic','sns'); /* @var $topicService PW_Topic */
  371. !$weiboHotTopics && $weiboHotTopics =$topicService->getWeiboHotTopics();
  372. /*獲取用戶關注的話題*/
  373. $perpage = 10;
  374. $attentionCount = $topicService->getUserAttentionTopicNum($winduid);
  375. $attentionCount && $attentionedTopics = (array)$topicService->getUserAttentionTopics($winduid,1,$perpage);
  376. $attentionCount > $perpage && $nextpage = 2;
  377. is_array($weiboHotTopics) || $weiboHotTopics = array();
  378. /* end 右側話題排行 */
  379. require_once PrintEot('m_weibo');
  380. pwOutPut();
  381. }
  382. function weibocredit($action = 'weibo_Post'){
  383. global $o_weibo_creditset,$o_weibo_creditlog,$onlineip,$winduid,$windid,$credit;
  384. require_once(R_P.'require/credit.php');
  385. $o_weibo_creditset = unserialize($o_weibo_creditset);
  386. $type = ($action == 'weibo_Post') ? true : false;
  387. $creditset = ($type == true) ? getCreditset($o_weibo_creditset['Post'],$type) : getCreditset($o_weibo_creditset['Delete'],$type);
  388. $creditset = array_diff($creditset,array(0));
  389. //積分變動
  390. if ($creditlog = unserialize($o_weibo_creditlog)) {
  391. $credit->appendLogSet($creditlog,'weibo');
  392. $credit->addLog($action, $creditset, array(
  393. 'uid' => $winduid,
  394. 'username' => $windid,
  395. 'ip' => $onlineip
  396. ));
  397. }
  398. if (!empty($creditset)) {
  399. $credit->sets($winduid,$creditset,true);
  400. updateMemberid($winduid);
  401. }
  402. }