block_blog.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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: block_blog.php 29655 2012-04-24 05:51:56Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_blog extends discuz_block {
  12. var $setting = array();
  13. function block_blog() {
  14. $this->setting = array(
  15. 'blogids' => array(
  16. 'title' => 'bloglist_blogids',
  17. 'type' => 'text'
  18. ),
  19. 'uids' => array(
  20. 'title' => 'bloglist_uids',
  21. 'type' => 'text',
  22. ),
  23. 'catid' => array(
  24. 'title' => 'bloglist_catid',
  25. 'type'=>'mselect',
  26. ),
  27. 'picrequired' => array(
  28. 'title' => 'bloglist_picrequired',
  29. 'type' => 'radio',
  30. 'default' => '0'
  31. ),
  32. 'orderby' => array(
  33. 'title' => 'bloglist_orderby',
  34. 'type' => 'mradio',
  35. 'value' => array(
  36. array('dateline', 'bloglist_orderby_dateline'),
  37. array('viewnum', 'bloglist_orderby_viewnum'),
  38. array('replynum', 'bloglist_orderby_replynum'),
  39. array('hot', 'bloglist_orderby_hot')
  40. ),
  41. 'default' => 'dateline'
  42. ),
  43. 'hours' => array(
  44. 'title' => 'bloglist_hours',
  45. 'type' => 'mradio',
  46. 'value' => array(
  47. array('', 'bloglist_hours_nolimit'),
  48. array('1', 'bloglist_hours_hour'),
  49. array('24', 'bloglist_hours_day'),
  50. array('168', 'bloglist_hours_week'),
  51. array('720', 'bloglist_hours_month'),
  52. array('8760', 'bloglist_hours_year'),
  53. ),
  54. 'default' => ''
  55. ),
  56. 'titlelength' => array(
  57. 'title' => 'bloglist_titlelength',
  58. 'type' => 'text',
  59. 'default' => 40
  60. ),
  61. 'summarylength' => array(
  62. 'title' => 'bloglist_summarylength',
  63. 'type' => 'text',
  64. 'default' => 80
  65. ),
  66. 'startrow' => array(
  67. 'title' => 'bloglist_startrow',
  68. 'type' => 'text',
  69. 'default' => 0
  70. ),
  71. );
  72. }
  73. function name() {
  74. return lang('blockclass', 'blockclass_blog_script_blog');
  75. }
  76. function blockclass() {
  77. return array('blog', lang('blockclass', 'blockclass_space_blog'));
  78. }
  79. function fields() {
  80. return array(
  81. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  82. 'url' => array('name' => lang('blockclass', 'blockclass_blog_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  83. 'title' => array('name' => lang('blockclass', 'blockclass_blog_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  84. 'summary' => array('name' => lang('blockclass', 'blockclass_blog_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  85. 'pic' => array('name' => lang('blockclass', 'blockclass_blog_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  86. 'dateline' => array('name' => lang('blockclass', 'blockclass_blog_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  87. 'uid' => array('name' => lang('blockclass', 'blockclass_blog_field_uid'), 'formtype' => 'text', 'datatype' => 'int'),
  88. 'username' => array('name' => lang('blockclass', 'blockclass_blog_field_username'), 'formtype' => 'text', 'datatype' => 'string'),
  89. 'avatar' => array('name' => lang('blockclass', 'blockclass_blog_field_avatar'), 'formtype' => 'text', 'datatype' => 'string'),
  90. 'avatar_middle' => array('name' => lang('blockclass', 'blockclass_blog_field_avatar_middle'), 'formtype' => 'text', 'datatype' => 'string'),
  91. 'avatar_big' => array('name' => lang('blockclass', 'blockclass_blog_field_avatar_big'), 'formtype' => 'text', 'datatype' => 'string'),
  92. 'replynum' => array('name' => lang('blockclass', 'blockclass_blog_field_replynum'), 'formtype' => 'text', 'datatype' => 'int'),
  93. 'viewnum' => array('name' => lang('blockclass', 'blockclass_blog_field_viewnum'), 'formtype' => 'text', 'datatype' => 'int'),
  94. 'click1' => array('name' => lang('blockclass', 'blockclass_blog_field_click1'), 'formtype' => 'text', 'datatype' => 'int'),
  95. 'click2' => array('name' => lang('blockclass', 'blockclass_blog_field_click2'), 'formtype' => 'text', 'datatype' => 'int'),
  96. 'click3' => array('name' => lang('blockclass', 'blockclass_blog_field_click3'), 'formtype' => 'text', 'datatype' => 'int'),
  97. 'click4' => array('name' => lang('blockclass', 'blockclass_blog_field_click4'), 'formtype' => 'text', 'datatype' => 'int'),
  98. 'click5' => array('name' => lang('blockclass', 'blockclass_blog_field_click5'), 'formtype' => 'text', 'datatype' => 'int'),
  99. 'click6' => array('name' => lang('blockclass', 'blockclass_blog_field_click6'), 'formtype' => 'text', 'datatype' => 'int'),
  100. 'click7' => array('name' => lang('blockclass', 'blockclass_blog_field_click7'), 'formtype' => 'text', 'datatype' => 'int'),
  101. 'click8' => array('name' => lang('blockclass', 'blockclass_blog_field_click8'), 'formtype' => 'text', 'datatype' => 'int'),
  102. );
  103. }
  104. function fieldsconvert() {
  105. return array(
  106. 'forum_thread' => array(
  107. 'name' => lang('blockclass', 'blockclass_forum_thread'),
  108. 'script' => 'thread',
  109. 'searchkeys' => array('username', 'uid', 'viewnum', 'replynum'),
  110. 'replacekeys' => array('author', 'authorid', 'views', 'replies'),
  111. ),
  112. 'group_thread' => array(
  113. 'name' => lang('blockclass', 'blockclass_group_thread'),
  114. 'script' => 'groupthread',
  115. 'searchkeys' => array('username', 'uid', 'viewnum', 'replynum'),
  116. 'replacekeys' => array('author', 'authorid', 'views', 'replies'),
  117. ),
  118. 'portal_article' => array(
  119. 'name' => lang('blockclass', 'blockclass_portal_article'),
  120. 'script' => 'article',
  121. 'searchkeys' => array('replynum'),
  122. 'replacekeys' => array('commentnum'),
  123. ),
  124. );
  125. }
  126. function getsetting() {
  127. global $_G;
  128. $settings = $this->setting;
  129. if(!empty($settings['catid'])) {
  130. $settings['catid']['value'][] = array(0, lang('portalcp', 'block_all_category'));
  131. loadcache('blogcategory');
  132. foreach($_G['cache']['blogcategory'] as $value) {
  133. if($value['level'] == 0) {
  134. $settings['catid']['value'][] = array($value['catid'], $value['catname']);
  135. if($value['children']) {
  136. foreach($value['children'] as $catid2) {
  137. $value2 = $_G['cache']['blogcategory'][$catid2];
  138. $settings['catid']['value'][] = array($value2['catid'], '-- '.$value2['catname']);
  139. if($value2['children']) {
  140. foreach($value2['children'] as $catid3) {
  141. $value3 = $_G['cache']['blogcategory'][$catid3];
  142. $settings['catid']['value'][] = array($value3['catid'], '---- '.$value3['catname']);
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. return $settings;
  151. }
  152. function getdata($style, $parameter) {
  153. global $_G;
  154. $parameter = $this->cookparameter($parameter);
  155. $blogids = !empty($parameter['blogids']) ? explode(',',$parameter['blogids']) : array();
  156. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  157. $catid = !empty($parameter['catid']) ? $parameter['catid'] : array();
  158. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  159. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  160. $hours = isset($parameter['hours']) ? intval($parameter['hours']) : '';
  161. $titlelength = $parameter['titlelength'] ? intval($parameter['titlelength']) : 40;
  162. $summarylength = $parameter['summarylength'] ? intval($parameter['summarylength']) : 80;
  163. $orderby = isset($parameter['orderby']) && in_array($parameter['orderby'],array('dateline', 'viewnum', 'replynum', 'hot')) ? $parameter['orderby'] : 'dateline';
  164. $picrequired = !empty($parameter['picrequired']) ? 1 : 0;
  165. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  166. $datalist = $list = array();
  167. $wheres = array();
  168. if(!$blogids && !$catid && $_G['setting']['blockmaxaggregationitem']) {
  169. if(($maxid = $this->getmaxid() - $_G['setting']['blockmaxaggregationitem']) > 0) {
  170. $wheres[] = 'b.blogid > '.$maxid;
  171. }
  172. }
  173. if($blogids) {
  174. $wheres[] = 'b.blogid IN ('.dimplode($blogids).')';
  175. }
  176. if($bannedids) {
  177. $wheres[] = 'b.blogid NOT IN ('.dimplode($bannedids).')';
  178. }
  179. if($uids) {
  180. $wheres[] = 'b.uid IN ('.dimplode($uids).')';
  181. }
  182. if($catid && !in_array('0', $catid)) {
  183. $wheres[] = 'b.catid IN ('.dimplode($catid).')';
  184. }
  185. if($hours) {
  186. $timestamp = TIMESTAMP - 3600 * $hours;
  187. $wheres[] = "b.dateline >= '$timestamp'";
  188. }
  189. $tablesql = $fieldsql = '';
  190. if($style['getsummary'] || $picrequired || $style['getpic']) {
  191. if($picrequired) {
  192. $wheres[] = "bf.pic != ''";
  193. }
  194. $tablesql = ' LEFT JOIN '.DB::table('home_blogfield')." bf ON b.blogid = bf.blogid";
  195. $fieldsql = ', bf.pic, b.picflag, bf.message';
  196. }
  197. $wheres[] = "b.friend = '0'";
  198. $wheres[] = "b.status='0'";
  199. $wheresql = $wheres ? implode(' AND ', $wheres) : '1';
  200. $sql = "SELECT b.* $fieldsql FROM ".DB::table('home_blog')." b $tablesql WHERE $wheresql ORDER BY b.$orderby DESC";
  201. $query = DB::query($sql." LIMIT $startrow,$items;");
  202. while($data = DB::fetch($query)) {
  203. if(empty($data['pic'])) {
  204. $data['pic'] = STATICURL.'image/common/nophoto.gif';
  205. $data['picflag'] = '0';
  206. } else {
  207. $data['pic'] = preg_replace('/\.thumb\.jpg$/', '', $data['pic']);
  208. $data['pic'] = 'album/'.$data['pic'];
  209. $data['picflag'] = $data['remote'] == '1' ? '2' : '1';
  210. }
  211. $list[] = array(
  212. 'id' => $data['blogid'],
  213. 'idtype' => 'blogid',
  214. 'title' => cutstr($data['subject'], $titlelength, ''),
  215. 'url' => 'home.php?mod=space&uid='.$data[uid].'&do=blog&id='.$data['blogid'],
  216. 'pic' => $data['pic'],
  217. 'picflag' => $data['picflag'],
  218. 'summary' => $data['message'] ? preg_replace("/&amp;[a-z]+\;/i", '', cutstr(strip_tags($data['message']), $summarylength, '')) : '',
  219. 'fields' => array(
  220. 'fulltitle' => $data['subject'],
  221. 'dateline'=>$data['dateline'],
  222. 'uid'=>$data['uid'],
  223. 'username'=>$data['username'],
  224. 'avatar' => avatar($data['uid'], 'small', true, false, false, $_G['setting']['ucenterurl']),
  225. 'avatar_middle' => avatar($data['uid'], 'middle', true, false, false, $_G['setting']['ucenterurl']),
  226. 'avatar_big' => avatar($data['uid'], 'big', true, false, false, $_G['setting']['ucenterurl']),
  227. 'replynum'=>$data['replynum'],
  228. 'viewnum'=>$data['viewnum'],
  229. 'click1'=>$data['click1'],
  230. 'click2'=>$data['click2'],
  231. 'click3'=>$data['click3'],
  232. 'click4'=>$data['click4'],
  233. 'click5'=>$data['click5'],
  234. 'click6'=>$data['click6'],
  235. 'click7'=>$data['click7'],
  236. 'click8'=>$data['click8'],
  237. )
  238. );
  239. }
  240. return array('html' => '', 'data' => $list);
  241. }
  242. function getmaxid() {
  243. loadcache('databasemaxid');
  244. $data = getglobal('cache/databasemaxid');
  245. if(!isset($data['blog']) || TIMESTAMP - $data['blog']['dateline'] >= 86400) {
  246. $data['blog']['dateline'] = TIMESTAMP;
  247. $data['blog']['id'] = DB::result_first('SELECT MAX(blogid) FROM '.DB::table('home_blog'));
  248. savecache('databasemaxid', $data);
  249. }
  250. return $data['blog']['id'];
  251. }
  252. }
  253. ?>