国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

262 行
9.3KB

  1. <?php if (!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 踩踩文档类
  4. *
  5. * @version $Id: arc.caicai.class.php 1 8:59 2010年7月7日Z tianya $
  6. * @package DedeBIZ.Libraries
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(DEDEINC . "/datalistcp.class.php");
  12. require_once(DEDEINC . "/channelunit.func.php");
  13. /**
  14. * 踩踩文档类
  15. *
  16. * @package Caicai
  17. * @subpackage DedeBIZ.Libraries
  18. * @link https://www.dedebiz.com
  19. */
  20. class Caicai extends DataListCP
  21. {
  22. var $maxPageSize = 100;
  23. var $arcCacheTime = 3600;
  24. /**
  25. * 对config参数及get参数等进行预处理
  26. *
  27. * @access public
  28. * @return void
  29. */
  30. function PreLoad()
  31. {
  32. global $totalresult, $pageno;
  33. if (empty($pageno) || preg_match("#[^0-9]#", $pageno)) $pageno = 1;
  34. if (empty($totalresult) || preg_match("#[^0-9]#", $totalresult)) $totalresult = 0;
  35. $this->pageNO = $pageno;
  36. $this->totalResult = $totalresult;
  37. if (isset($this->tpl->tpCfgs['pagesize'])) {
  38. $this->pageSize = $this->tpl->tpCfgs['pagesize'];
  39. }
  40. $this->totalPage = ceil($this->totalResult / $this->pageSize);
  41. if ($this->totalPage > $this->maxPageSize) {
  42. $this->totalPage = $this->maxPageSize;
  43. }
  44. //限制最大页数
  45. if ($this->pageNO > $this->totalPage) {
  46. $this->pageNO = $this->totalPage;
  47. $this->totalResult = $this->totalPage * $this->pageSize;
  48. }
  49. $this->sourceSql = preg_replace("#LIMIT [0-9,]{1,}#i", '', $this->sourceSql);
  50. if ($this->totalResult == 0) {
  51. //$this->isQuery = true;
  52. //$this->dsql->Execute('dlist',$this->sourceSql);
  53. //$this->totalResult = $this->dsql->GetTotalRow('dlist');
  54. $countQuery = preg_replace("#SELECT[ \r\n\t](.*)[ \r\n\t]FROM#is", "SELECT COUNT(*) as dd FROM", $this->sourceSql);
  55. $row = $this->dsql->GetOne($countQuery);
  56. $this->totalResult = $row['dd'];
  57. $this->sourceSql .= " LIMIT 0," . $this->pageSize;
  58. } else {
  59. $this->sourceSql .= " LIMIT " . (($this->pageNO - 1) * $this->pageSize) . "," . $this->pageSize;
  60. }
  61. }
  62. /**
  63. * 获取当前页数据列表
  64. *
  65. * @param array $atts
  66. * @param object $refObj
  67. * @param array $fields
  68. * @return array
  69. */
  70. function GetArcList($atts, $refObj = '', $fields = array())
  71. {
  72. $rsArray = array();
  73. $t1 = Exectime();
  74. if (!$this->isQuery) {
  75. $this->dsql->Execute('dlist', $this->sourceSql);
  76. }
  77. $i = 0;
  78. while ($arr = $this->dsql->GetArray('dlist')) {
  79. $i++;
  80. $arr['filename'] = $arr['arcurl'] = GetFileUrl(
  81. $arr['id'],
  82. $arr['typeid'],
  83. $arr['senddate'],
  84. $arr['title'],
  85. $arr['ismake'],
  86. $arr['arcrank'],
  87. $arr['namerule'],
  88. $arr['typedir'],
  89. $arr['money'],
  90. $arr['filename'],
  91. $arr['moresite'],
  92. $arr['siteurl'],
  93. $arr['sitepath']
  94. );
  95. $arr['typeurl'] = GetTypeUrl(
  96. $arr['typeid'],
  97. MfTypedir($arr['typedir']),
  98. $arr['isdefault'],
  99. $arr['defaultname'],
  100. $arr['ispart'],
  101. $arr['namerule2'],
  102. $arr['moresite'],
  103. $arr['siteurl'],
  104. $arr['sitepath']
  105. );
  106. if ($arr['litpic'] == '-' || $arr['litpic'] == '') {
  107. $arr['litpic'] = 'templets/images/dfpic.gif';
  108. }
  109. if (!preg_match("#^http:\/\/#i", $arr['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  110. $arr['litpic'] = $GLOBALS['cfg_mainsite'] . $arr['litpic'];
  111. }
  112. $arr['picname'] = $arr['litpic'];
  113. $arr['alttitle'] = $arr['userid'] . " 的空间";
  114. $arr['face'] = ($arr['face'] != '' ? $arr['face'] : 'images/nopic.gif');
  115. if ($arr['userid'] != '') {
  116. $arr['spaceurl'] = $GLOBALS['cfg_basehost'] . '/member/index.php?uid=' . $arr['userid'];
  117. } else {
  118. $arr['alttitle'] = $arr['title'];
  119. $arr['spaceurl'] = $arr['arcurl'];
  120. $arr['face'] = $arr['litpic'];
  121. $arr['face'] = str_replace('defaultpic', 'dfcaicai', $arr['face']);
  122. }
  123. if (!empty($arr['lastpost'])) {
  124. $arr['lastpost'] = MyDate('m-d h:i', $arr['lastpost']);
  125. } else {
  126. $arr['lastpost'] = "<a href='../plus/feedback.php?aid={$arr['id']}'>说几句&gt;&gt;</a>";
  127. }
  128. $rsArray[$i] = $arr;
  129. if ($i >= $this->pageSize) {
  130. break;
  131. }
  132. }
  133. $this->dsql->FreeResult('dlist');
  134. $this->queryTime = (Exectime() - $t1);
  135. return $rsArray;
  136. }
  137. /**
  138. * 获得最差或最好的踩踩文章
  139. *
  140. * @param array $atts
  141. * @param object $refObj
  142. * @param array $fields
  143. * @return array
  144. */
  145. function GetSortArc($atts, $refObj = '', $fields = array())
  146. {
  147. $arcrow = (empty($atts['row']) ? 12 : $atts['row']);
  148. $order = (empty($atts['order']) ? 'scores' : $atts['order']);
  149. $orderway = (empty($atts['orderway']) ? 'desc' : $atts['orderway']);
  150. if (empty($arcrow)) $arcrow = 12;
  151. $query = "SELECT arc.*,tp.typedir,tp.typename,
  152. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  153. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON tp.id = arc.typeid
  154. WHERE arc.arcrank>-1 ORDER BY arc.{$order} $orderway LIMIT 0,$arcrow ";
  155. $rsArray = array();
  156. $cacheFile = DEDEDATA . '/cache/caicai_' . md5($query) . '.inc';
  157. $needCache = false;
  158. if (file_exists($cacheFile) && filemtime($cacheFile) - time() < $this->arcCacheTime) {
  159. $fp = fopen($cacheFile, 'r');
  160. $ids = fread($fp, filesize($cacheFile));
  161. fclose($fp);
  162. $ids = trim($ids);
  163. if (!empty($ids)) {
  164. $query = "SELECT arc.*,tp.typedir,tp.typename,
  165. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  166. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON tp.id=arc.typeid
  167. WHERE arc.id in($ids) ORDER BY arc.{$order} $orderway ";
  168. }
  169. } else {
  170. $needCache = true;
  171. }
  172. $ids = array();
  173. $i = 0;
  174. $this->dsql->Execute('cai', $query);
  175. while ($arr = $this->dsql->GetArray('cai')) {
  176. $i++;
  177. $ids[] = $arr['id'];
  178. $arr['filename'] = $arr['arcurl'] = GetFileUrl(
  179. $arr['id'],
  180. $arr['typeid'],
  181. $arr['senddate'],
  182. $arr['title'],
  183. $arr['ismake'],
  184. $arr['arcrank'],
  185. $arr['namerule'],
  186. $arr['typedir'],
  187. $arr['money'],
  188. $arr['filename'],
  189. $arr['moresite'],
  190. $arr['siteurl'],
  191. $arr['sitepath']
  192. );
  193. $arr['typeurl'] = GetTypeUrl(
  194. $arr['typeid'],
  195. MfTypedir($arr['typedir']),
  196. $arr['isdefault'],
  197. $arr['defaultname'],
  198. $arr['ispart'],
  199. $arr['namerule2'],
  200. $arr['moresite'],
  201. $arr['siteurl'],
  202. $arr['sitepath']
  203. );
  204. if ($arr['litpic'] == '') $arr['litpic'] = '/static/defaultpic.gif';
  205. if (!preg_match("#^http:\/\/#", $arr['litpic'])) {
  206. $arr['picname'] = $arr['litpic'] = $GLOBALS['cfg_cmsurl'] . $arr['litpic'];
  207. } else {
  208. $arr['picname'] = $arr['litpic'] = $arr['litpic'];
  209. }
  210. $rsArray[$i] = $arr;
  211. }
  212. $this->dsql->FreeResult('cai');
  213. //写入缓存
  214. if ($needCache && count($ids) > 0) {
  215. $idsstr = join(',', $ids);
  216. file_put_contents($cacheFile, $idsstr);
  217. // $fp = fopen($cacheFile, 'w');
  218. // fwrite($fp, $idsstr);
  219. // fclose($fp);
  220. }
  221. return $rsArray;
  222. }
  223. /**
  224. * 获取顶级栏目列表
  225. *
  226. * @param array $atts
  227. * @param object $refObj
  228. * @param array $fields
  229. * @return array
  230. */
  231. function GetCatalog($atts, $refObj = '', $fields = array())
  232. {
  233. $maxrow = (empty($atts['row']) ? 12 : $atts['row']);
  234. $query = "SELECT id,typename FROM `#@__arctype` WHERE reid=0 AND ispart<2 AND channeltype>0 ORDER BY sortrank ASC LIMIT 0,$maxrow ";
  235. $rsArray = array();
  236. $this->dsql->Execute('co', $query);
  237. $i = 0;
  238. while ($arr = $this->dsql->GetArray('co')) {
  239. $i++;
  240. $rsArray[$i] = $arr;
  241. }
  242. $this->dsql->FreeResult('co');
  243. return $rsArray;
  244. }
  245. }//End Class