block_topic.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_topic.php 31470 2012-08-31 03:29:50Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_topic extends discuz_block {
  12. var $setting = array();
  13. function block_topic() {
  14. $this->setting = array(
  15. 'topicids' => array(
  16. 'title' => 'topiclist_topicids',
  17. 'type' => 'text',
  18. 'value' => ''
  19. ),
  20. 'uids' => array(
  21. 'title' => 'topiclist_uids',
  22. 'type' => 'text',
  23. 'value' => ''
  24. ),
  25. 'picrequired' => array(
  26. 'title' => 'topiclist_picrequired',
  27. 'type' => 'radio',
  28. 'default' => '0'
  29. ),
  30. 'orderby' => array(
  31. 'title' => 'topiclist_orderby',
  32. 'type' => 'mradio',
  33. 'value' => array(
  34. array('dateline', 'topiclist_orderby_dateline'),
  35. array('viewnum', 'topiclist_orderby_viewnum')
  36. ),
  37. 'default' => 'dateline'
  38. ),
  39. 'titlelength' => array(
  40. 'title' => 'topiclist_titlelength',
  41. 'type' => 'text',
  42. 'default' => 40
  43. ),
  44. 'summarylength' => array(
  45. 'summary' => 'topiclist_summarylength',
  46. 'type' => 'text',
  47. 'default' => 80
  48. ),
  49. 'startrow' => array(
  50. 'title' => 'topiclist_startrow',
  51. 'type' => 'text',
  52. 'default' => 0
  53. ),
  54. );
  55. }
  56. function name() {
  57. return lang('blockclass', 'blockclass_topic_script_topic');
  58. }
  59. function blockclass() {
  60. return array('topic', lang('blockclass', 'blockclass_portal_topic'));
  61. }
  62. function fields() {
  63. return array(
  64. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  65. 'url' => array('name' => lang('blockclass', 'blockclass_topic_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  66. 'title' => array('name' => lang('blockclass', 'blockclass_topic_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  67. 'pic' => array('name' => lang('blockclass', 'blockclass_topic_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  68. 'summary' => array('name' => lang('blockclass', 'blockclass_topic_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  69. 'uid' => array('name' => lang('blockclass', 'blockclass_topic_field_uid'), 'formtype' => 'text', 'datatype' => 'int'),
  70. 'username' => array('name' => lang('blockclass', 'blockclass_topic_field_username'), 'formtype' => 'text', 'datatype' => 'string'),
  71. 'dateline' => array('name' => lang('blockclass', 'blockclass_topic_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  72. 'viewnum' => array('name' => lang('blockclass', 'blockclass_topic_field_viewnum'), 'formtype' => 'text', 'datatype' => 'int'),
  73. );
  74. }
  75. function getsetting() {
  76. global $_G;
  77. $settings = $this->setting;
  78. return $settings;
  79. }
  80. function getdata($style, $parameter) {
  81. global $_G;
  82. $parameter = $this->cookparameter($parameter);
  83. $topicids = !empty($parameter['topicids']) ? explode(',',$parameter['topicids']) : array();
  84. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  85. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  86. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  87. $titlelength = $parameter['titlelength'] ? intval($parameter['titlelength']) : 40;
  88. $summarylength = $parameter['summarylength'] ? intval($parameter['summarylength']) : 80;
  89. $orderby = isset($parameter['orderby']) && in_array($parameter['orderby'],array('dateline', 'viewnum')) ? $parameter['orderby'] : 'dateline';
  90. $picrequired = !empty($parameter['picrequired']) ? 1 : 0;
  91. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  92. $datalist = $list = array();
  93. $wherearr = array();
  94. if($topicids) {
  95. $wherearr[] = 'topicid IN ('.dimplode($topicids).')';
  96. }
  97. if($bannedids) {
  98. $wherearr[] = 'topicid NOT IN ('.dimplode($bannedids).')';
  99. }
  100. if($uids) {
  101. $wherearr[] = 'uid IN ('.dimplode($uids).')';
  102. }
  103. if($picrequired) {
  104. $wherearr[] = "cover != ''";
  105. }
  106. $wherearr[] = "closed = '0'";
  107. require_once libfile('function/portal');
  108. foreach(C::t('portal_topic')->fetch_all_by_search_where($wherearr, "ORDER BY $orderby DESC", $startrow, $items) as $data) {
  109. if(empty($data['cover'])) {
  110. $data['cover'] = STATICURL.'image/common/nophoto.gif';
  111. $data['picflag'] = '0';
  112. }
  113. $list[] = array(
  114. 'id' => $data['topicid'],
  115. 'idtype' => 'topicid',
  116. 'title' => cutstr($data['title'], $titlelength, ''),
  117. 'url' => !empty($_G['setting']['makehtml']['flag']) && !empty($_G['setting']['makehtml']['topichtmldir']) && !$data['htmlmade'] ? fetch_topic_url($data) : 'portal.php?mod=topic&topic='.$data['name'],
  118. 'pic' => $data['cover'] ? $data['cover'] : '',
  119. 'picflag' => $data['picflag'] ? $data['picflag'] : '',
  120. 'summary' => $data['summary'] ? cutstr($data['summary'], $summarylength, '') : '',
  121. 'fields' => array(
  122. 'fulltitle' => $data['title'],
  123. 'uid'=>$data['uid'],
  124. 'username'=>$data['username'],
  125. 'dateline'=>$data['dateline'],
  126. 'viewnum'=>$data['viewnum'],
  127. )
  128. );
  129. }
  130. return array('html' => '', 'data' => $list);
  131. }
  132. }
  133. ?>