PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/source/include/space/space_blog.php

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