PageRenderTime 90ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/space/space_blog.php

https://github.com/kuaileshike/upload
PHP | 360 lines | 294 code | 60 blank | 6 comment | 93 complexity | 73c4f495323edf013cecf13137974d78 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: space_blog.php 25870 2011-11-24 07:05:44Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $minhot = $_G['setting']['feedhotmin']<1?3:$_G['setting']['feedhotmin'];
  12. $page = empty($_GET['page'])?1:intval($_GET['page']);
  13. if($page<1) $page=1;
  14. $id = empty($_GET['id'])?0:intval($_GET['id']);
  15. $_G['colorarray'] = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  16. if($id) {
  17. $blog = array_merge(
  18. C::t('home_blog')->fetch($id),
  19. C::t('home_blogfield')->fetch($id)
  20. );
  21. if($blog['uid'] != $space['uid']) {
  22. $blog = null;
  23. }
  24. if(!(!empty($blog) && ($blog['status'] == 0 || $blog['uid'] == $_G['uid'] || $_G['adminid'] == 1 || $_GET['modblogkey'] == modauthkey($blog['blogid'])))) {
  25. showmessage('view_to_info_did_not_exist');
  26. }
  27. if(!ckfriend($blog['uid'], $blog['friend'], $blog['target_ids'])) {
  28. require_once libfile('function/friend');
  29. $isfriend = friend_check($blog['uid']);
  30. space_merge($space, 'count');
  31. space_merge($space, 'profile');
  32. $_G['privacy'] = 1;
  33. require_once libfile('space/profile', 'include');
  34. include template('home/space_privacy');
  35. exit();
  36. } elseif(!$space['self'] && $blog['friend'] == 4 && $_G['adminid'] != 1) {
  37. $cookiename = "view_pwd_blog_$blog[blogid]";
  38. $cookievalue = empty($_G['cookie'][$cookiename])?'':$_G['cookie'][$cookiename];
  39. if($cookievalue != md5(md5($blog['password']))) {
  40. $invalue = $blog;
  41. include template('home/misc_inputpwd');
  42. exit();
  43. }
  44. }
  45. $classarr = C::t('home_class')->fetch($blog['classid']);
  46. if($blog['catid']) {
  47. $blog['catname'] = C::t('home_blog_category')->fetch_catname_by_catid($blog['catid']);
  48. $blog['catname'] = dhtmlspecialchars($blog['catname']);
  49. }
  50. require_once libfile('function/blog');
  51. $blog['message'] = blog_bbcode($blog['message']);
  52. $otherlist = $newlist = array();
  53. $otherlist = array();
  54. $query = C::t('home_blog')->fetch_all_by_uid($space['uid'], 'dateline', 0, 6);
  55. foreach($query as $value) {
  56. if($value['blogid'] != $blog['blogid'] && empty($value['friend'])) {
  57. $otherlist[] = $value;
  58. }
  59. }
  60. $newlist = array();
  61. $query = C::t('home_blog')->fetch_all_by_hot($minhot, 'dateline', 0, 6);
  62. foreach($query as $value) {
  63. if($value['blogid'] != $blog['blogid'] && empty($value['friend'])) {
  64. $newlist[] = $value;
  65. }
  66. }
  67. $perpage = 20;
  68. $perpage = mob_perpage($perpage);
  69. $start = ($page-1)*$perpage;
  70. ckstart($start, $perpage);
  71. $count = $blog['replynum'];
  72. $list = array();
  73. if($count) {
  74. if($_GET['goto']) {
  75. $page = ceil($count/$perpage);
  76. $start = ($page-1)*$perpage;
  77. } else {
  78. $cid = empty($_GET['cid'])?0:intval($_GET['cid']);
  79. }
  80. $query = C::t('home_comment')->fetch_all_by_id_idtype($id, 'blogid', $start, $perpage, $cid);
  81. foreach($query as $value) {
  82. $list[] = $value;
  83. }
  84. if(empty($list) && empty($cid)) {
  85. $count = C::t('home_comment')->count_by_id_idtype($id, 'blogid');
  86. C::t('home_blog')->update($blog['blogid'], array('replynum'=>$count));
  87. }
  88. }
  89. $multi = multi($count, $perpage, $page, "home.php?mod=space&uid=$blog[uid]&do=$do&id=$id#comment");
  90. if(!$_G['setting']['preventrefresh'] || !$space['self'] && $_G['cookie']['viewid'] != 'blog_'.$blog['blogid']) {
  91. C::t('home_blog')->increase($blog['blogid'], 0, array('viewnum' => 1));
  92. dsetcookie('viewid', 'blog_'.$blog['blogid']);
  93. }
  94. $hash = md5($blog['uid']."\t".$blog['dateline']);
  95. $id = $blog['blogid'];
  96. $idtype = 'blogid';
  97. $maxclicknum = 0;
  98. loadcache('click');
  99. $clicks = empty($_G['cache']['click']['blogid'])?array():$_G['cache']['click']['blogid'];
  100. foreach ($clicks as $key => $value) {
  101. $value['clicknum'] = $blog["click{$key}"];
  102. $value['classid'] = mt_rand(1, 4);
  103. if($value['clicknum'] > $maxclicknum) $maxclicknum = $value['clicknum'];
  104. $clicks[$key] = $value;
  105. }
  106. $clickuserlist = array();
  107. foreach(C::t('home_clickuser')->fetch_all_by_id_idtype($id, $idtype, 0, 24) as $value) {
  108. $value['clickname'] = $clicks[$value['clickid']]['name'];
  109. $clickuserlist[] = $value;
  110. }
  111. $actives = array('me' =>' class="a"');
  112. $diymode = intval($_G['cookie']['home_diymode']);
  113. $tagarray_all = $array_temp = $blogtag_array = $blogmetatag_array = array();
  114. $blogmeta_tag = '';
  115. $tagarray_all = explode("\t", $blog['tag']);
  116. if($tagarray_all) {
  117. foreach($tagarray_all as $var) {
  118. if($var) {
  119. $array_temp = explode(',', $var);
  120. $blogtag_array[] = $array_temp;
  121. $blogmetatag_array[] = $array_temp['1'];
  122. }
  123. }
  124. }
  125. $blog['tag'] = $blogtag_array;
  126. $blogmeta_tag = implode(',', $blogmetatag_array);
  127. $summary = cutstr(strip_tags($blog['message']), 140);
  128. $seodata = array('subject' => $blog['subject'], 'user' => $blog['username'], 'summary' => $summary, 'tags' => $blogmeta_tag);
  129. list($navtitle, $metadescription, $metakeywords) = get_seosetting('blog', $seodata);
  130. if(empty($navtitle)) {
  131. $navtitle = $blog['subject'].' - '.lang('space', 'sb_blog', array('who' => $blog['username']));
  132. $nobbname = false;
  133. } else {
  134. $nobbname = true;
  135. }
  136. if(empty($metakeywords)) {
  137. $metakeywords = $blogmeta_tag ? $blogmeta_tag : $blog['subject'];
  138. }
  139. if(empty($metadescription)) {
  140. $metadescription = $summary;
  141. }
  142. if(!$_G['setting']['relatedlinkstatus']) {
  143. $_G['relatedlinks'] = get_related_link('blog');
  144. } else {
  145. $blog['message'] = parse_related_link($blog['message'], 'blog');
  146. }
  147. include_once template("diy:home/space_blog_view");
  148. } else {
  149. loadcache('blogcategory');
  150. $category = $_G['cache']['blogcategory'];
  151. if(empty($_GET['view'])) $_GET['view'] = 'we';
  152. $perpage = 10;
  153. $perpage = mob_perpage($perpage);
  154. $start = ($page-1)*$perpage;
  155. ckstart($start, $perpage);
  156. $summarylen = 300;
  157. $classarr = array();
  158. $list = array();
  159. $userlist = array();
  160. $stickblogs = array();
  161. $count = $pricount = 0;
  162. $gets = array(
  163. 'mod' => 'space',
  164. 'uid' => $space['uid'],
  165. 'do' => 'blog',
  166. 'view' => $_GET['view'],
  167. 'order' => $_GET['order'],
  168. 'classid' => $_GET['classid'],
  169. 'catid' => $_GET['catid'],
  170. 'clickid' => $_GET['clickid'],
  171. 'fuid' => $_GET['fuid'],
  172. 'searchkey' => $_GET['searchkey'],
  173. 'from' => $_GET['from'],
  174. 'friend' => $_GET['friend']
  175. );
  176. $theurl = 'home.php?'.url_implode($gets);
  177. $multi = '';
  178. $f_index = $searchsubject = '';
  179. $uids = array();
  180. $need_count = true;
  181. if($_GET['view'] == 'all') {
  182. if($_GET['order'] == 'hot') {
  183. $gthot = $minhot;
  184. $orderactives = array('hot' => ' class="a"');
  185. } else {
  186. $orderactives = array('dateline' => ' class="a"');
  187. }
  188. } elseif($_GET['view'] == 'me') {
  189. space_merge($space, 'field_home');
  190. $stickblogs = explode(',', $space['stickblogs']);
  191. $stickblogs = array_filter($stickblogs);
  192. $uids[] = $space['uid'];
  193. $classid = empty($_GET['classid'])?0:intval($_GET['classid']);
  194. $privacyfriend = empty($_GET['friend'])?0:intval($_GET['friend']);
  195. $query = C::t('home_class')->fetch_all_by_uid($space['uid']);
  196. foreach($query as $value) {
  197. $classarr[$value['classid']] = $value['classname'];
  198. }
  199. if($_GET['from'] == 'space') $diymode = 1;
  200. } else {
  201. space_merge($space, 'field_home');
  202. if($space['feedfriend']) {
  203. $fuid_actives = array();
  204. require_once libfile('function/friend');
  205. $fuid = intval($_GET['fuid']);
  206. if($fuid && friend_check($fuid, $space['uid'])) {
  207. $uids[] = $fuid;
  208. $fuid_actives = array($fuid=>' selected');
  209. } else {
  210. $uids = explode(',', $space['feedfriend']);
  211. $theurl = "home.php?mod=space&uid=$space[uid]&do=$do&view=we";
  212. $f_index = 'dateline';
  213. }
  214. $query = C::t('home_friend')->fetch_all_by_uid($space['uid'], 0, 100, true);
  215. foreach($query as $value) {
  216. $userlist[] = $value;
  217. }
  218. } else {
  219. $need_count = false;
  220. }
  221. }
  222. $actives = array($_GET['view'] =>' class="a"');
  223. if($need_count) {
  224. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  225. $searchsubject = $searchkey;
  226. $searchkey = dhtmlspecialchars($searchkey);
  227. }
  228. $catid = empty($_GET['catid'])?0:intval($_GET['catid']);
  229. $count = C::t('home_blog')->count_all_by_search(null, $uids, null, null, $gthot, null, null, null, null, null, $privacyfriend, null, null, null, $classid, $catid, $searchsubject, true);
  230. if($count) {
  231. $query = C::t('home_blog')->fetch_all_by_search(1, null, $uids, null, null, $gthot, null, null, null, null, null, $privacyfriend, null, null, null, 'dateline', 'DESC', $start, $perpage, $classid, $catid, $searchsubject, $f_index);
  232. }
  233. }
  234. if($count) {
  235. foreach($query as $value) {
  236. if(ckfriend($value['uid'], $value['friend'], $value['target_ids']) && ($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1)) {
  237. if(!empty($stickblogs) && in_array($value['blogid'], $stickblogs)) {
  238. continue;
  239. }
  240. if($value['friend'] == 4) {
  241. $value['message'] = $value['pic'] = '';
  242. } else {
  243. $value['message'] = getstr($value['message'], $summarylen, 0, 0, 0, -1);
  244. }
  245. $value['message'] = preg_replace("/&[a-z]+\;/i", '', $value['message']);
  246. if($value['pic']) $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  247. $value['dateline'] = dgmdate($value['dateline']);
  248. $list[] = $value;
  249. } else {
  250. $pricount++;
  251. }
  252. }
  253. $multi = multi($count, $perpage, $page, $theurl);
  254. if(!empty($stickblogs)) {
  255. $list = array_merge(blog_get_stick($space['uid'], $stickblogs, $summarylen), $list);
  256. }
  257. }
  258. dsetcookie('home_diymode', $diymode);
  259. if($_G['uid']) {
  260. if($_GET['view'] == 'all') {
  261. $navtitle = lang('core', 'title_view_all').lang('core', 'title_blog');
  262. } elseif($_GET['view'] == 'me') {
  263. $navtitle = lang('core', 'title_my_blog');
  264. } else {
  265. $navtitle = lang('core', 'title_friend_blog');
  266. }
  267. } else {
  268. if($_GET['order'] == 'hot') {
  269. $navtitle = lang('core', 'title_recommend_blog');
  270. } else {
  271. $navtitle = lang('core', 'title_newest_blog');
  272. }
  273. }
  274. if($space['username']) {
  275. $navtitle = lang('space', 'sb_blog', array('who' => $space['username']));
  276. }
  277. $metakeywords = $navtitle;
  278. $metadescription = $navtitle;
  279. $navtitle = helper_seo::get_title_page($navtitle, $_G['page']);
  280. space_merge($space, 'field_home');
  281. include_once template("diy:home/space_blog_list");
  282. }
  283. function blog_get_stick($uid, $stickblogs, $summarylen) {
  284. $list = array_flip($stickblogs);
  285. if($stickblogs) {
  286. $data_blog = C::t('home_blog')->fetch_all($stickblogs);
  287. $data_blogfield = C::t('home_blogfield')->fetch_all($stickblogs);
  288. foreach($data_blog as $curblogid=>$value) {
  289. $value = array_merge($value, (array)$data_blogfield[$curblogid]);
  290. $value['message'] = getstr($value['message'], $summarylen, 0, 0, 0, -1);
  291. $value['message'] = preg_replace("/&[a-z]+\;/i", '', $value['message']);
  292. if($value['pic']) $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  293. $value['dateline'] = dgmdate($value['dateline']);
  294. $value['stickflag'] = true;
  295. $list[$value['blogid']] = $value;
  296. }
  297. }
  298. return $list;
  299. }
  300. ?>