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

/source/module/portal/portal_view.php

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