block_pic.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_pic.php 28299 2012-02-27 08:48:36Z svn_project_zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_pic extends discuz_block {
  12. var $setting = array();
  13. function block_pic() {
  14. $this->setting = array(
  15. 'picids' => array(
  16. 'title' => 'piclist_picids',
  17. 'type' => 'text',
  18. 'value' => ''
  19. ),
  20. 'uids' => array(
  21. 'title' => 'piclist_uids',
  22. 'type' => 'text',
  23. 'value' => ''
  24. ),
  25. 'aids' => array(
  26. 'title' => 'piclist_aids',
  27. 'type' => 'text',
  28. 'value' => ''
  29. ),
  30. 'titlelength' => array(
  31. 'title' => 'piclist_titlelength',
  32. 'type' => 'text',
  33. 'default' => 40
  34. ),
  35. 'orderby' => array(
  36. 'title' => 'piclist_orderby',
  37. 'type' => 'mradio',
  38. 'value' => array(
  39. array('dateline', 'piclist_orderby_dateline'),
  40. array('hot', 'piclist_orderby_hot')
  41. ),
  42. 'default' => 'dateline'
  43. ),
  44. 'hours' => array(
  45. 'title' => 'piclist_hours',
  46. 'type' => 'mradio',
  47. 'value' => array(
  48. array('', 'piclist_hours_nolimit'),
  49. array('1', 'piclist_hours_hour'),
  50. array('24', 'piclist_hours_day'),
  51. array('168', 'piclist_hours_week'),
  52. array('720', 'piclist_hours_month'),
  53. array('8760', 'piclist_hours_year'),
  54. ),
  55. 'default' => ''
  56. ),
  57. 'startrow' => array(
  58. 'title' => 'piclist_startrow',
  59. 'type' => 'text',
  60. 'default' => 0
  61. ),
  62. );
  63. }
  64. function name() {
  65. return lang('blockclass', 'blockclass_pic_script_pic');
  66. }
  67. function blockclass() {
  68. return array('pic', lang('blockclass', 'blockclass_space_pic'));
  69. }
  70. function fields() {
  71. return array(
  72. 'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
  73. 'url' => array('name' => lang('blockclass', 'blockclass_pic_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
  74. 'title' => array('name' => lang('blockclass', 'blockclass_pic_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
  75. 'pic' => array('name' => lang('blockclass', 'blockclass_pic_field_pic'), 'formtype' => 'pic', 'datatype' => 'pic'),
  76. 'summary' => array('name' => lang('blockclass', 'blockclass_pic_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
  77. 'uid' => array('name' => lang('blockclass', 'blockclass_pic_field_uid'), 'formtype' => 'text', 'datatype' => 'int'),
  78. 'username' => array('name' => lang('blockclass', 'blockclass_pic_field_username'), 'formtype' => 'text', 'datatype' => 'string'),
  79. 'dateline' => array('name' => lang('blockclass', 'blockclass_pic_field_dateline'), 'formtype' => 'date', 'datatype' => 'date'),
  80. 'viewnum' => array('name' => lang('blockclass', 'blockclass_pic_field_viewnum'), 'formtype' => 'text', 'datatype' => 'int'),
  81. 'click1' => array('name' => lang('blockclass', 'blockclass_pic_field_click1'), 'formtype' => 'text', 'datatype' => 'int'),
  82. 'click2' => array('name' => lang('blockclass', 'blockclass_pic_field_click2'), 'formtype' => 'text', 'datatype' => 'int'),
  83. 'click3' => array('name' => lang('blockclass', 'blockclass_pic_field_click3'), 'formtype' => 'text', 'datatype' => 'int'),
  84. 'click4' => array('name' => lang('blockclass', 'blockclass_pic_field_click4'), 'formtype' => 'text', 'datatype' => 'int'),
  85. 'click5' => array('name' => lang('blockclass', 'blockclass_pic_field_click5'), 'formtype' => 'text', 'datatype' => 'int'),
  86. 'click6' => array('name' => lang('blockclass', 'blockclass_pic_field_click6'), 'formtype' => 'text', 'datatype' => 'int'),
  87. 'click7' => array('name' => lang('blockclass', 'blockclass_pic_field_click7'), 'formtype' => 'text', 'datatype' => 'int'),
  88. 'click8' => array('name' => lang('blockclass', 'blockclass_pic_field_click8'), 'formtype' => 'text', 'datatype' => 'int'),
  89. );
  90. }
  91. function getsetting() {
  92. global $_G;
  93. $settings = $this->setting;
  94. return $settings;
  95. }
  96. function getdata($style, $parameter) {
  97. global $_G;
  98. $parameter = $this->cookparameter($parameter);
  99. $picids = !empty($parameter['picids']) ? explode(',', $parameter['picids']) : array();
  100. $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array();
  101. $aids = !empty($parameter['aids']) ? explode(',', $parameter['aids']) : array();
  102. $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
  103. $items = isset($parameter['items']) ? intval($parameter['items']) : 10;
  104. $hours = isset($parameter['hours']) ? intval($parameter['hours']) : '';
  105. $titlelength = isset($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
  106. $orderby = isset($parameter['orderby']) && in_array($parameter['orderby'],array('dateline', 'viewnum', 'replynum', 'hot')) ? $parameter['orderby'] : 'dateline';
  107. $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
  108. $list = array();
  109. $wheres = array();
  110. if($picids) {
  111. $wheres[] = 'p.'.DB::field('picid', $picids);
  112. }
  113. if($uids) {
  114. $wheres[] = 'p.'.DB::field('uid', $uids);
  115. }
  116. if($aids) {
  117. $wheres[] = 'p.'.DB::field('albumid', $aids);
  118. }
  119. if($hours) {
  120. $timestamp = TIMESTAMP - 3600 * $hours;
  121. $wheres[] = 'p.'.DB::field('dateline', $timestamp, '>=');
  122. }
  123. if($bannedids) {
  124. $wheres[] = 'p.'.DB::field('picid', $bannedids, 'notin');
  125. }
  126. $wheresql = $wheres ? implode(' AND ', $wheres) : '1';
  127. $query = C::t('home_pic')->fetch_all_by_sql($wheresql." AND a.friend='0'", 'p.'.$orderby.' DESC');
  128. foreach($query as $data) {
  129. $list[] = array(
  130. 'id' => $data['picid'],
  131. 'idtype' => 'picid',
  132. 'title' => cutstr($data['title'], $titlelength, ''),
  133. 'url' => "home.php?mod=space&uid=$data[uid]&do=album&picid=$data[picid]",
  134. 'pic' => $data['remote'] >= 2 ? 'forum/'.$data['filepath'] : 'album/'.$data['filepath'],
  135. 'picflag' => ($data['remote'] == 1 || $data['remote'] == 3) ? '2' : '1',
  136. 'summary' => $data['title'],
  137. 'fields' => array(
  138. 'fulltitle' => $data['title'],
  139. 'uid'=>$data['uid'],
  140. 'username'=>$data['username'],
  141. 'dateline'=>$data['dateline'],
  142. 'replynum'=>$data['replynum'],
  143. 'click1'=>$data['click1'],
  144. 'click2'=>$data['click2'],
  145. 'click3'=>$data['click3'],
  146. 'click4'=>$data['click4'],
  147. 'click5'=>$data['click5'],
  148. 'click6'=>$data['click6'],
  149. 'click7'=>$data['click7'],
  150. 'click8'=>$data['click8'],
  151. )
  152. );
  153. }
  154. return array('html' => '', 'data' => $list);
  155. }
  156. }
  157. ?>