PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/source/module/forum/forum_redirect.php

https://github.com/kuaileshike/upload
PHP | 151 lines | 115 code | 30 blank | 6 comment | 51 complexity | 8d3ce38b190f22798462dbbe144d338c 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: forum_redirect.php 28464 2012-03-01 06:35:27Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. foreach(array('pid', 'ptid', 'authorid', 'ordertype', 'postno') as $k) {
  12. $$k = !empty($_GET[$k]) ? intval($_GET[$k]) : 0;
  13. }
  14. if(empty($_GET['goto']) && $ptid) {
  15. $_GET['goto'] = 'findpost';
  16. }
  17. if($_GET['goto'] == 'findpost') {
  18. $post = $thread = array();
  19. if($ptid) {
  20. $thread = get_thread_by_tid($ptid);
  21. }
  22. if($pid) {
  23. if($thread) {
  24. $post = C::t('forum_post')->fetch($thread['posttableid'], $pid);
  25. } else {
  26. $post = get_post_by_pid($pid);
  27. }
  28. if($post && empty($thread)) {
  29. $thread = get_thread_by_tid($post['tid']);
  30. }
  31. }
  32. if(empty($thread)) {
  33. showmessage('thread_nonexistence');
  34. } else {
  35. $tid = $thread['tid'];
  36. }
  37. if(empty($pid)) {
  38. if($postno) {
  39. if(getstatus($thread['status'], 3)) {
  40. $rowarr = C::t('forum_post')->fetch_all_by_tid_position($thread['posttableid'], $ptid, $postno);
  41. $pid = $rowarr[0]['pid'];
  42. }
  43. if($pid) {
  44. $post = C::t('forum_post')->fetch($thread['posttableid'], $pid);
  45. if($post['invisible'] != 0) {
  46. $post = array();
  47. }
  48. } else {
  49. $postno = $postno > 1 ? $postno - 1 : 0;
  50. $post = C::t('forum_post')->fetch_visiblepost_by_tid($thread['posttableid'], $ptid, $postno);
  51. }
  52. }
  53. }
  54. if(empty($post)) {
  55. if($ptid) {
  56. header("HTTP/1.1 301 Moved Permanently");
  57. dheader("Location: forum.php?mod=viewthread&tid=$ptid");
  58. } else {
  59. showmessage('post_check', NULL, array('tid' => $ptid));
  60. }
  61. } else {
  62. $pid = $post['pid'];
  63. }
  64. $ordertype = !isset($_GET['ordertype']) && getstatus($thread['status'], 4) ? 1 : $ordertype;
  65. if($thread['special'] == 2 || C::t('forum_threaddisablepos')->fetch($tid)) {
  66. $curpostnum = C::t('forum_post')->count_by_tid_dateline($thread['posttableid'], $tid, $post['dateline']);
  67. } else {
  68. if($thread['maxposition']) {
  69. $maxposition = $thread['maxposition'];
  70. } else {
  71. $maxposition = C::t('forum_post')->fetch_maxposition_by_tid($thread['posttableid'], $tid);
  72. }
  73. $thread['replies'] = $maxposition;
  74. $curpostnum = $post['position'];
  75. }
  76. if($ordertype != 1) {
  77. $page = ceil($curpostnum / $_G['ppp']);
  78. } elseif($curpostnum > 1) {
  79. $page = ceil(($thread['replies'] - $curpostnum + 3) / $_G['ppp']);
  80. } else {
  81. $page = 1;
  82. }
  83. if($thread['special'] == 2 && C::t('forum_trade')->check_goods($pid)) {
  84. header("HTTP/1.1 301 Moved Permanently");
  85. dheader("Location: forum.php?mod=viewthread&do=tradeinfo&tid=$tid&pid=$pid");
  86. }
  87. $authoridurl = $authorid ? '&authorid='.$authorid : '';
  88. $ordertypeurl = $ordertype ? '&ordertype='.$ordertype : '';
  89. header("HTTP/1.1 301 Moved Permanently");
  90. dheader("Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? "&modthreadkey=$modthreadkey": '')."#pid$pid");
  91. }
  92. if(empty($_G['thread'])) {
  93. showmessage('thread_nonexistence');
  94. }
  95. if($_GET['goto'] == 'lastpost') {
  96. $pageadd = '';
  97. if(!getstatus($_G['thread'], 4)) {
  98. $page = ceil(($_G['thread']['special'] ? $_G['thread']['replies'] : $_G['thread']['replies'] + 1) / $_G['ppp']);
  99. $pageadd = $page > 1 ? '&page='.$page : '';
  100. }
  101. dheader('Location: forum.php?mod=viewthread&tid='.$_G['tid'].$pageadd.'#lastpost');
  102. } elseif($_GET['goto'] == 'nextnewset' || $_GET['goto'] == 'nextoldset') {
  103. $lastpost = $_G['thread']['lastpost'];
  104. $glue = '<';
  105. $sort = 'DESC';
  106. if($_GET['goto'] == 'nextnewset') {
  107. $glue = '>';
  108. $sort = 'ASC';
  109. }
  110. $next = C::t('forum_thread')->fetch_next_tid_by_fid_lastpost($_G['fid'], $lastpost, $glue, $sort, $_G['thread']['threadtableid']);
  111. if($next) {
  112. dheader("Location: forum.php?mod=viewthread&tid=$next");
  113. } elseif($_GET['goto'] == 'nextnewset') {
  114. showmessage('redirect_nextnewset_nonexistence');
  115. } else {
  116. showmessage('redirect_nextoldset_nonexistence');
  117. }
  118. } else {
  119. showmessage('undefined_action', NULL);
  120. }
  121. ?>