viewthread.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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: viewthread.php 36278 2016-12-09 07:52:35Z nemohou $
  7. */
  8. if (!defined('IN_MOBILE_API')) {
  9. exit('Access Denied');
  10. }
  11. $_GET['mod'] = 'viewthread';
  12. include_once 'forum.php';
  13. class mobile_api {
  14. function common() {
  15. }
  16. function output() {
  17. global $_G, $thread;
  18. if ($GLOBALS['hiddenreplies']) {
  19. foreach ($GLOBALS['postlist'] as $k => $post) {
  20. if (!$post['first'] && $_G['uid'] != $post['authorid'] && $_G['uid'] != $_G['forum_thread']['authorid'] && !$_G['forum']['ismoderator']) {
  21. $GLOBALS['postlist'][$k]['message'] = lang('plugin/mobile', 'mobile_post_author_visible');
  22. $GLOBALS['postlist'][$k]['attachments'] = array();
  23. }
  24. }
  25. }
  26. $_G['thread']['lastpost'] = dgmdate($_G['thread']['lastpost']);
  27. $_G['thread']['ordertype'] = $GLOBALS['ordertype'];
  28. $_G['thread']['recommend'] = $_G['uid'] && C::t('forum_memberrecommend')->fetch_by_recommenduid_tid($_G['uid'], $_G['tid']) ? 1 : 0;
  29. if (!empty($_GET['viewpid'])) {
  30. $GLOBALS['postlist'][$_GET['viewpid']] = $GLOBALS['post'];
  31. }
  32. if ($GLOBALS['rushreply']) {
  33. $_G['thread']['rushreply'] = $GLOBALS['rushreply'];
  34. $_G['thread']['rushresult'] = $GLOBALS['rushresult'];
  35. }
  36. foreach ($GLOBALS['comments'] as $pid => $comments) {
  37. $comments = mobile_core::getvalues($comments, array('/^\d+$/'), array('id', 'tid', 'pid', 'author', 'authorid', 'dateline', 'comment', 'avatar'));
  38. foreach ($comments as $k => $c) {
  39. $comments[$k]['avatar'] = avatar($c['authorid'], 'small', true);
  40. $comments[$k]['dateline'] = dgmdate($c['dateline'], 'u');
  41. }
  42. $GLOBALS['comments'][$pid] = $comments;
  43. }
  44. $variable = array(
  45. 'thread' => $_G['thread'],
  46. 'fid' => $_G['fid'],
  47. 'postlist' => array_values(mobile_core::getvalues($GLOBALS['postlist'], array('/^\d+$/'), array('pid', 'tid', 'author', 'first', 'dbdateline', 'dateline', 'username', 'adminid', 'memberstatus', 'authorid', 'username', 'groupid', 'memberstatus', 'status', 'message', 'number', 'memberstatus', 'groupid', 'attachment', 'attachments', 'attachlist', 'imagelist', 'anonymous', 'position', 'rewardfloor', 'replycredit'))),
  48. 'allowpostcomment' => $_G['setting']['allowpostcomment'],
  49. 'comments' => $GLOBALS['comments'],
  50. 'commentcount' => $GLOBALS['commentcount'],
  51. 'ppp' => $_G['ppp'],
  52. 'setting_rewriterule' => $_G['setting']['rewriterule'],
  53. 'setting_rewritestatus' => $_G['setting']['rewritestatus'],
  54. 'forum_threadpay' => $_G['forum_threadpay'],
  55. 'cache_custominfo_postno' => $_G['cache']['custominfo']['postno'],
  56. );
  57. if (!empty($GLOBALS['threadsortshow'])) {
  58. $optionlist = array();
  59. foreach ($GLOBALS['threadsortshow']['optionlist'] AS $key => $val) {
  60. $val['optionid'] = $key;
  61. $optionlist[] = $val;
  62. }
  63. if (!empty($optionlist)) {
  64. $GLOBALS['threadsortshow']['optionlist'] = $optionlist;
  65. $GLOBALS['threadsortshow']['threadsortname'] = $_G['forum']['threadsorts']['types'][$thread['sortid']];
  66. }
  67. }
  68. $threadsortshow = mobile_core::getvalues($GLOBALS['threadsortshow'], array('/^(?!typetemplate).*$/'));
  69. if (!empty($threadsortshow)) {
  70. $variable['threadsortshow'] = $threadsortshow;
  71. }
  72. foreach ($variable['postlist'] as $k => $post) {
  73. if (!$_G['forum']['ismoderator'] && $_G['setting']['bannedmessages'] & 1 && (($post['authorid'] && !$post['username']) || ($_G['thread']['digest'] == 0 && ($post['groupid'] == 4 || $post['groupid'] == 5 || $post['memberstatus'] == '-1')))) {
  74. $message = lang('forum/template', 'message_banned');
  75. } elseif (!$_G['forum']['ismoderator'] && $post['status'] & 1) {
  76. $message = lang('forum/template', 'message_single_banned');
  77. } elseif ($GLOBALS['needhiddenreply']) {
  78. $message = lang('forum/template', 'message_ishidden_hiddenreplies');
  79. } elseif ($post['first'] && $_G['forum_threadpay']) {
  80. $message = lang('forum/template', 'pay_threads') . ' ' . $GLOBALS['thread']['price'] . ' ' . $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['unit'] . $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]]['title'];
  81. } elseif ($_G['forum_discuzcode']['passwordlock']) {
  82. $message = lang('forum/template', 'message_password_exists');
  83. } else {
  84. $message = '';
  85. }
  86. if ($message) {
  87. $variable['postlist'][$k]['message'] = $message;
  88. }
  89. if ($post['anonymous'] && !$_G['forum']['ismoderator']) {
  90. $variable['postlist'][$k]['username'] = $variable['postlist'][$k]['author'] = $_G['setting']['anonymoustext'];
  91. $variable['postlist'][$k]['adminid'] = $variable['postlist'][$k]['groupid'] = $variable['postlist'][$k]['authorid'] = 0;
  92. if ($post['first']) {
  93. $variable['thread']['authorid'] = 0;
  94. }
  95. }
  96. if (strpos($variable['postlist'][$k]['message'], '[/tthread]') !== FALSE) {
  97. $matches = array();
  98. preg_match('/\[tthread=(.+?),(.+?)\](.*?)\[\/tthread\]/', $variable['postlist'][$k]['message'], $matches);
  99. $variable['postlist'][$k]['message'] = preg_replace('/\[tthread=(.+?)\](.*?)\[\/tthread\]/', lang('plugin/qqconnect', 'connect_tthread_message', array('username' => $matches[1], 'nick' => $matches[2])), $variable['postlist'][$k]['message']);
  100. }
  101. $variable['postlist'][$k]['message'] = preg_replace("/<a\shref=\"([^\"]+?)\"\starget=\"_blank\">\[viewimg\]<\/a>/is", "<img src=\"\\1\" />", $variable['postlist'][$k]['message']);
  102. $variable['postlist'][$k]['message'] = mobile_api::_findimg($variable['postlist'][$k]['message']);
  103. if ($GLOBALS['aimgs'][$post['pid']]) {
  104. $imagelist = array();
  105. foreach ($GLOBALS['aimgs'][$post['pid']] as $aid) {
  106. $extra = '';
  107. $url = mobile_api::_parseimg('', $GLOBALS['postlist'][$post['pid']]['attachments'][$aid]['url'] . $GLOBALS['postlist'][$post['pid']]['attachments'][$aid]['attachment'], '');
  108. if ($GLOBALS['postlist'][$post['pid']]['attachments'][$aid]['thumb']) {
  109. $extra = 'file="' . $url . '" ';
  110. $url .= '.thumb.jpg';
  111. }
  112. $extra .= 'attach="' . $post['pid'] . '" ';
  113. if (strexists($variable['postlist'][$k]['message'], '[attach]' . $aid . '[/attach]')) {
  114. $variable['postlist'][$k]['message'] = str_replace('[attach]' . $aid . '[/attach]', mobile_image($url, $extra), $variable['postlist'][$k]['message']);
  115. unset($variable['postlist'][$k]['attachments'][$aid]);
  116. } elseif (!in_array($aid, $_G['forum_attachtags'][$post['pid']])) {
  117. $imagelist[] = $aid;
  118. }
  119. }
  120. $variable['postlist'][$k]['imagelist'] = $imagelist;
  121. }
  122. $variable['postlist'][$k]['message'] = preg_replace("/\[attach\]\d+\[\/attach\]/i", '', $variable['postlist'][$k]['message']);
  123. $variable['postlist'][$k]['message'] = preg_replace('/(&nbsp;){2,}/', '', $variable['postlist'][$k]['message']);
  124. $variable['postlist'][$k]['dateline'] = strip_tags($post['dateline']);
  125. $variable['postlist'][$k]['groupiconid'] = mobile_core::usergroupIconId($post['groupid']);
  126. }
  127. if (!empty($GLOBALS['polloptions'])) {
  128. $variable['special_poll']['polloptions'] = $GLOBALS['polloptions'];
  129. $variable['special_poll']['expirations'] = $GLOBALS['expirations'];
  130. $variable['special_poll']['multiple'] = $GLOBALS['multiple'];
  131. $variable['special_poll']['maxchoices'] = $GLOBALS['maxchoices'];
  132. $variable['special_poll']['voterscount'] = $GLOBALS['voterscount'];
  133. $variable['special_poll']['visiblepoll'] = $GLOBALS['visiblepoll'];
  134. $variable['special_poll']['allowvote'] = $_G['group']['allowvote'];
  135. $variable['special_poll']['remaintime'] = $thread['remaintime'];
  136. }
  137. if (!empty($GLOBALS['rewardprice'])) {
  138. $variable['special_reward']['rewardprice'] = $GLOBALS['rewardprice'] . ' ' . $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]['title'];
  139. $variable['special_reward']['bestpost'] = $GLOBALS['bestpost'];
  140. }
  141. if (!empty($GLOBALS['trades'])) {
  142. $variable['special_trade'] = $GLOBALS['trades'];
  143. }
  144. if (!empty($GLOBALS['debate'])) {
  145. $variable['special_debate'] = $GLOBALS['debate'];
  146. }
  147. if (!empty($GLOBALS['activity'])) {
  148. $variable['special_activity'] = $GLOBALS['activity'];
  149. $variable['special_activity']['allapplynum'] = $GLOBALS['allapplynum'];
  150. if ($_G['setting']['activitycredit'] && $GLOBALS['activity']['credit'] && !$GLOBALS['applied']) {
  151. $variable['special_activity']['creditcost'] = $GLOBALS['activity']['credit'] . ' ' . $_G['setting']['extcredits'][$_G['setting']['activitycredit']]['title'];
  152. }
  153. $setting = array();
  154. foreach ($GLOBALS['activity']['ufield']['userfield'] as $field) {
  155. $setting[$field] = $_G['cache']['profilesetting'][$field];
  156. }
  157. $variable['special_activity']['joinfield'] = mobile_core::getvalues($setting, array('/./'), array('fieldid', 'formtype', 'available', 'title', 'formtype', 'choices'));
  158. $variable['special_activity']['userfield'] = $GLOBALS['ufielddata']['userfield'];
  159. $variable['special_activity']['extfield'] = $GLOBALS['ufielddata']['extfield'];
  160. $variable['special_activity']['basefield'] = mobile_core::getvalues($GLOBALS['applyinfo'], array('message', 'payment'));
  161. $variable['special_activity']['closed'] = $GLOBALS['activityclose'];
  162. if ($GLOBALS['applied'] && $GLOBALS['isverified'] < 2) {
  163. if (!$GLOBALS['isverified']) {
  164. $variable['special_activity']['status'] = 'wait';
  165. } else {
  166. $variable['special_activity']['status'] = 'joined';
  167. }
  168. if (!$GLOBALS['activityclose']) {
  169. $variable['special_activity']['button'] = 'cancel';
  170. }
  171. } elseif (!$GLOBALS['activityclose']) {
  172. if ($GLOBALS['isverified'] != 2) {
  173. $variable['special_activity']['status'] = 'join';
  174. } else {
  175. $variable['special_activity']['status'] = 'complete';
  176. }
  177. $variable['special_activity']['button'] = 'join';
  178. }
  179. }
  180. $variable['forum']['password'] = $variable['forum']['password'] ? '1' : '0';
  181. mobile_core::result(mobile_core::variable($variable));
  182. }
  183. function _findimg($string) {
  184. return preg_replace_callback('/(<img src=\")(.+?)(\".*?\>)/is', array(__CLASS__, 'findimg_callback_parseimg_123'), $string);
  185. }
  186. static function findimg_callback_parseimg_123($matches) {
  187. return mobile_api::_parseimg($matches[1], $matches[2], $matches[3]);
  188. }
  189. function _parseimg($before, $img, $after) {
  190. $before = stripslashes($before);
  191. $after = stripslashes($after);
  192. if (!in_array(strtolower(substr($img, 0, 6)), array('http:/', 'https:', 'ftp://'))) {
  193. global $_G;
  194. $img = $_G['siteurl'] . $img;
  195. }
  196. return $before . $img . $after;
  197. }
  198. }
  199. ?>