PageRenderTime 35ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

/source/module/portal/portal_view.php

https://github.com/jinbo51/DiscuzX
PHP | 344 lines | 294 code | 44 blank | 6 comment | 110 complexity | a768fc47d56c734333edd23c62960363 MD5 | raw file
Possible License(s): BSD-3-Clause
  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: portal_view.php 33047 2013-04-12 08:46:56Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $aid = empty($_GET['aid'])?0:intval($_GET['aid']);
  12. if(empty($aid)) {
  13. showmessage('view_no_article_id');
  14. }
  15. $article = C::t('portal_article_title')->fetch($aid);
  16. require_once libfile('function/portalcp');
  17. $categoryperm = getallowcategory($_G['uid']);
  18. if(empty($article) || ($article['status'] > 0 && $article['uid'] != $_G['uid'] && !$_G['group']['allowmanagearticle'] && empty($categoryperm[$article['catid']]['allowmanage']) && $_G['adminid'] != 1 && $_GET['modarticlekey'] != modauthkey($article['aid']))) {
  19. showmessage('view_article_no_exist');
  20. }
  21. if(!empty($_G['setting']['antitheft']['allow']) && empty($_G['setting']['antitheft']['disable']['article']) && empty($_G['cache']['portalcategory'][$article['catid']]['noantitheft'])) {
  22. helper_antitheft::check($aid, 'aid');
  23. }
  24. if(!empty($_G['setting']['makehtml']['flag']) && $article['htmlmade'] && !isset($_G['makehtml']) && empty($_GET['diy']) && empty($article['url'])) {
  25. dheader('location:'. fetch_article_url($article));
  26. }
  27. $article_count = C::t('portal_article_count')->fetch($aid);
  28. if($article_count) $article = array_merge($article_count, $article);
  29. if($article_count) {
  30. C::t('portal_article_count')->increase($aid, array('viewnum'=>1));
  31. unset($article_count);
  32. } else {
  33. C::t('portal_article_count')->insert(array(
  34. 'aid'=>$aid,
  35. 'catid'=>$article['catid'],
  36. 'viewnum'=>1));
  37. }
  38. if($article['url']) {
  39. if(!isset($_G['makehtml'])) {
  40. dheader("location:{$article['url']}");
  41. }
  42. exit();
  43. }
  44. $cat = category_remake($article['catid']);
  45. $article['pic'] = pic_get($article['pic'], '', $article['thumb'], $article['remote'], 1, 1);
  46. $page = intval($_GET['page']);
  47. if($page<1) $page = 1;
  48. $content = $contents = array();
  49. $multi = '';
  50. $content = C::t('portal_article_content')->fetch_by_aid_page($aid, $page);
  51. if($article['contents'] && $article['showinnernav']) {
  52. foreach(C::t('portal_article_content')->fetch_all($aid) as $value) {
  53. $contents[] = $value;
  54. }
  55. if(empty($contents)) {
  56. C::t('portal_article_content')->update($aid, array('showinnernav' => '0'));
  57. }
  58. }
  59. require_once libfile('function/blog');
  60. $content['content'] = blog_bbcode($content['content']);
  61. if(!empty($_G['setting']['makehtml']['flag']) && $article['htmlmade']) {
  62. $_caturl = $_G['cache']['portalcategory'][$cat['topid']]['domain'] ? $_G['cache']['portalcategory'][$cat['topid']]['caturl'] : '';
  63. $viewurl = $_caturl.$article['htmldir'].$article['htmlname'].'{page}.'.$_G['setting']['makehtml']['extendname'];
  64. unset($_caturl);
  65. } else {
  66. $viewurl = "portal.php?mod=view&aid=$aid";
  67. }
  68. $multi = multi($article['contents'], 1, $page, $viewurl);
  69. $org = array();
  70. if($article['idtype'] == 'tid' || $content['idtype']=='pid') {
  71. $thread = $firstpost = array();
  72. require_once libfile('function/discuzcode');
  73. require_once libfile('function/forum');
  74. $thread = get_thread_by_tid($article[id]);
  75. if(!empty($thread)) {
  76. if($content['idtype']=='pid') {
  77. $firstpost = C::t('forum_post')->fetch($thread['posttableid'], $content['id']);
  78. } else {
  79. $firstpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($article['id']);
  80. }
  81. if($firstpost && $firstpost['tid'] == $article['id']) {
  82. $firstpost['uid'] = $firstpost['authorid'];
  83. $firstpost['username'] = $firstpost['author'];
  84. }
  85. }
  86. if(!empty($firstpost) && !empty($thread) && $thread['displayorder'] != -1) {
  87. $_G['tid'] = $article['id'];
  88. $aids = array();
  89. $firstpost['message'] = $content['content'];
  90. if($thread['attachment']) {
  91. $_G['group']['allowgetimage'] = 1;
  92. if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $firstpost['message'], $matchaids)) {
  93. $aids = $matchaids[1];
  94. }
  95. }
  96. if($aids) {
  97. parseforumattach($firstpost, $aids);
  98. }
  99. $content['content'] = $firstpost['message'];
  100. $content['pid'] = $firstpost['pid'];
  101. $org = $firstpost;
  102. $org_url = "forum.php?mod=viewthread&tid=$article[id]";
  103. } else {
  104. C::t('portal_article_title')->update($aid, array('id' => 0, 'idtype' => ''));
  105. C::t('portal_article_content')->update_by_aid($aid, array('id' => 0, 'idtype' => ''));
  106. }
  107. } elseif($article['idtype']=='blogid') {
  108. $org = C::t('home_blog')->fetch($article['id']);
  109. if(empty($org)) {
  110. C::t('portal_article_title')->update($aid, array('id' => 0, 'idtype' => ''));
  111. dheader('location: '. fetch_article_url($article));
  112. exit();
  113. }
  114. }
  115. $article['related'] = array();
  116. if(($relateds = C::t('portal_article_related')->fetch_all_by_aid($aid))) {
  117. foreach(C::t('portal_article_title')->fetch_all(array_keys($relateds)) as $raid => $value) {
  118. $value['uri'] = fetch_article_url($value);
  119. $article['related'][$raid] = $value;
  120. }
  121. }
  122. $article['allowcomment'] = !empty($cat['allowcomment']) && !empty($article['allowcomment']) ? 1 : 0;
  123. $_G['catid'] = $_GET['catid'] = $article['catid'];
  124. $common_url = '';
  125. $commentlist = array();
  126. if($article['allowcomment']) {
  127. if($org && empty($article['owncomment'])) {
  128. if($article['idtype'] == 'blogid') {
  129. $common_url = "home.php?mod=space&uid=$org[uid]&do=blog&id=$article[id]";
  130. $form_url = "home.php?mod=spacecp&ac=comment";
  131. $article['commentnum'] = C::t('home_comment')->count_by_id_idtype($article['id'], 'blogid');
  132. if($article['commentnum']) {
  133. $query = C::t('home_comment')->fetch_all_by_id_idtype($article['id'], 'blogid', 0, 20, '', 'DESC');
  134. foreach($query as $value) {
  135. if($value['status'] == 0 || $_G['adminid'] == 1 || $value['uid'] == $_G['uid']) {
  136. $commentlist[] = $value;
  137. }
  138. }
  139. }
  140. } elseif($article['idtype'] == 'tid') {
  141. $common_url = "forum.php?mod=viewthread&tid=$article[id]";
  142. $form_url = "forum.php?mod=post&action=reply&tid=$article[id]&replysubmit=yes&infloat=yes&handlekey=fastpost";
  143. require_once libfile('function/discuzcode');
  144. $posttable = empty($thread['posttable']) ? getposttablebytid($article['id']) : $thread['posttable'];
  145. $_G['tid'] = $article['id'];
  146. $article['commentnum'] = getcount($posttable, array('tid'=>$article['id'], 'first'=>'0'));
  147. if($article['allowcomment'] && $article['commentnum']) {
  148. $attachpids = $attachtags = array();
  149. $_G['group']['allowgetattach'] = $_G['group']['allowgetimage'] = 1;
  150. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$article['id'], $article['id'], true, 'ASC', 0, 20, null, 0) as $value) {
  151. $value['uid'] = $value['authorid'];
  152. $value['username'] = $value['author'];
  153. if($value['status'] != 1 && !$value['first']) {
  154. $value['message'] = discuzcode($value['message'], $value['smileyoff'], $value['bbcodeoff'], $value['htmlon']);
  155. $value['cid'] = $value['pid'];
  156. $commentlist[$value['pid']] = $value;
  157. if($value['attachment']) {
  158. $attachpids[] = $value['pid'];
  159. if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $value['message'], $matchaids)) {
  160. $attachtags[$value['pid']] = $matchaids[1];
  161. }
  162. }
  163. }
  164. }
  165. if($attachpids) {
  166. require_once libfile('function/attachment');
  167. parseattach($attachpids, $attachtags, $commentlist);
  168. }
  169. }
  170. }
  171. } else {
  172. $common_url = "portal.php?mod=comment&id=$aid&idtype=aid";
  173. $form_url = "portal.php?mod=portalcp&ac=comment";
  174. $query = C::t('portal_comment')->fetch_all_by_id_idtype($aid, 'aid', 'dateline', 'DESC', 0, 20);
  175. $pricount = 0;
  176. foreach($query as $value) {
  177. if($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1) {
  178. $value['allowop'] = 1;
  179. $commentlist[] = $value;
  180. } else {
  181. $pricount += 1;
  182. }
  183. }
  184. }
  185. }
  186. $hash = md5($article['uid']."\t".$article['dateline']);
  187. $id = $article['aid'];
  188. $idtype = 'aid';
  189. loadcache('click');
  190. $clicks = empty($_G['cache']['click']['aid'])?array():$_G['cache']['click']['aid'];
  191. $maxclicknum = 0;
  192. foreach ($clicks as $key => $value) {
  193. $value['clicknum'] = $article["click{$key}"];
  194. $value['classid'] = mt_rand(1, 4);
  195. if($value['clicknum'] > $maxclicknum) $maxclicknum = $value['clicknum'];
  196. $clicks[$key] = $value;
  197. }
  198. $clickuserlist = array();
  199. foreach(C::t('home_clickuser')->fetch_all_by_id_idtype($id, $idtype, 0, 24) as $value) {
  200. $value['clickname'] = $clicks[$value['clickid']]['name'];
  201. $clickuserlist[] = $value;
  202. }
  203. $article['timestamp'] = $article['dateline'];
  204. $article['dateline'] = dgmdate($article['dateline']);
  205. foreach($cat['ups'] as $val) {
  206. $cats[] = $val['catname'];
  207. }
  208. $seodata = array('firstcat' => $cats[0], 'secondcat' => $cats[1], 'curcat' => $cat['catname'], 'subject' => $article['title'], 'user' => $article['username'], 'summary' => $article['summary'], 'page' => intval($_GET['page']));
  209. list($navtitle, $metadescription, $metakeywords) = get_seosetting('article', $seodata);
  210. if(empty($navtitle)) {
  211. $navtitle = helper_seo::get_title_page($article['title'], $_G['page']).' - '.$cat['catname'];
  212. $nobbname = false;
  213. } else {
  214. $nobbname = true;
  215. }
  216. if(empty($metakeywords)) {
  217. $metakeywords = $article['title'];
  218. }
  219. if(empty($metadescription)) {
  220. $metadescription = $article['summary'] ? $article['summary'] : $article['title'];
  221. }
  222. $seccodecheck = $_G['group']['seccode'] ? $_G['setting']['seccodestatus'] & 4 : 0;
  223. $secqaacheck = $_G['group']['seccode'] ? $_G['setting']['secqaa']['status'] & 2 : 0;
  224. $catid = $article['catid'];
  225. if(!$_G['setting']['relatedlinkstatus']) {
  226. $_G['relatedlinks'] = get_related_link('article');
  227. } else {
  228. $content['content'] = parse_related_link($content['content'], 'article');
  229. }
  230. if(isset($_G['makehtml'])) {
  231. helper_makehtml::portal_article($cat, $article, $page);
  232. }
  233. portal_get_per_next_article($article);
  234. $tpldirectory = '';
  235. $articleprimaltplname = $cat['articleprimaltplname'];
  236. if(strpos($articleprimaltplname, ':') !== false) {
  237. list($tpldirectory, $articleprimaltplname) = explode(':', $articleprimaltplname);
  238. }
  239. include_once template("diy:portal/view:{$catid}", NULL, $tpldirectory, NULL, $articleprimaltplname);
  240. function parseforumattach(&$post, $aids) {
  241. global $_G;
  242. if(($aids = array_unique($aids))) {
  243. require_once libfile('function/attachment');
  244. $finds = $replaces = array();
  245. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$post['tid'], 'aid', $aids) as $attach) {
  246. $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
  247. $attach['dateline'] = dgmdate($attach['dateline'], 'u');
  248. $extension = strtolower(fileext($attach['filename']));
  249. $attach['ext'] = $extension;
  250. $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
  251. $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
  252. $attach['attachsize'] = sizecount($attach['filesize']);
  253. $attach['refcheck'] = (!$attach['remote'] && $_G['setting']['attachrefcheck']) || ($attach['remote'] && ($_G['setting']['ftp']['hideurl'] || ($attach['isimage'] && $_G['setting']['attachimgpost'] && strtolower(substr($_G['setting']['ftp']['attachurl'], 0, 3)) == 'ftp')));
  254. $aidencode = packaids($attach);
  255. $widthcode = attachwidth($attach['width']);
  256. $is_archive = $_G['forum_thread']['is_archived'] ? "&fid=".$_G['fid']."&archiveid=".$_G['forum_thread']['archiveid'] : '';
  257. if($attach['isimage']) {
  258. $attachthumb = getimgthumbname($attach['attachment']);
  259. if($_G['setting']['thumbstatus'] && $attach['thumb']) {
  260. $replaces[$attach['aid']] = "<a href=\"javascript:;\"><img id=\"_aimg_$attach[aid]\" aid=\"$attach[aid]\" onclick=\"zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[forum][showexif]}')\"
  261. zoomfile=\"".($attach['refcheck']? "forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes&nothumb=yes" : $attach['url'].$attach['attachment'])."\"
  262. src=\"".($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid=$aidencode" : $attach['url'].$attachthumb)."\" alt=\"$attach[imgalt]\" title=\"$attach[imgalt]\" w=\"$attach[width]\" /></a>";
  263. } else {
  264. $replaces[$attach['aid']] = "<img id=\"_aimg_$attach[aid]\" aid=\"$attach[aid]\"
  265. zoomfile=\"".($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes&nothumb=yes" : $attach['url'].$attach['attachment'])."\"
  266. src=\"".($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes " : $attach['url'].$attach['attachment'])."\" $widthcode alt=\"$attach[imgalt]\" title=\"$attach[imgalt]\" w=\"$attach[width]\" />";
  267. }
  268. } else {
  269. $replaces[$attach['aid']] = "$attach[attachicon]<a href=\"forum.php?mod=attachment{$is_archive}&aid=$aidencode\" onmouseover=\"showMenu({'ctrlid':this.id,'pos':'12'})\" id=\"aid$attach[aid]\" target=\"_blank\">$attach[filename]</a>";
  270. }
  271. $finds[$attach['aid']] = '[attach]'.$attach['aid'].'[/attach]';
  272. }
  273. if($finds && $replaces) {
  274. $post['message'] = str_ireplace($finds, $replaces, $post['message']);
  275. }
  276. }
  277. }
  278. function portal_get_per_next_article(&$article) {
  279. $data = array();
  280. $aids = array();
  281. if($article['preaid']) {
  282. $aids[$article['preaid']] = $article['preaid'];
  283. }
  284. if($article['nextaid']) {
  285. $aids[$article['nextaid']] = $article['nextaid'];
  286. }
  287. if($aids) {
  288. $data = C::t('portal_article_title')->fetch_all($aids);
  289. foreach ($data as $aid => &$value) {
  290. $value['url'] = fetch_article_url($value);
  291. }
  292. }
  293. if($data[$article['preaid']]) {
  294. $article['prearticle'] = $data[$article['preaid']];
  295. }
  296. if($data[$article['nextaid']]) {
  297. $article['nextarticle'] = $data[$article['nextaid']];
  298. }
  299. }
  300. ?>