国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
8.8KB

  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 DedeCMS.Libraries
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license/v6
  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 DedeCMS.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. {
  43. $this->totalPage = $this->maxPageSize;
  44. }
  45. //限制最大页数
  46. if($this->pageNO > $this->totalPage)
  47. {
  48. $this->pageNO = $this->totalPage;
  49. $this->totalResult = $this->totalPage * $this->pageSize;
  50. }
  51. $this->sourceSql = preg_replace("#LIMIT [0-9,]{1,}#i", '', $this->sourceSql);
  52. if( $this->totalResult==0 )
  53. {
  54. //$this->isQuery = true;
  55. //$this->dsql->Execute('dlist',$this->sourceSql);
  56. //$this->totalResult = $this->dsql->GetTotalRow('dlist');
  57. $countQuery = preg_replace("#SELECT[ \r\n\t](.*)[ \r\n\t]FROM#is","SELECT COUNT(*) as dd FROM", $this->sourceSql);
  58. $row = $this->dsql->GetOne($countQuery);
  59. $this->totalResult = $row['dd'];
  60. $this->sourceSql .= " LIMIT 0,".$this->pageSize;
  61. }
  62. else
  63. {
  64. $this->sourceSql .= " LIMIT ".(($this->pageNO-1) * $this->pageSize).",".$this->pageSize;
  65. }
  66. }
  67. /**
  68. * 获取当前页数据列表
  69. *
  70. * @param array $atts
  71. * @param object $refObj
  72. * @param array $fields
  73. * @return array
  74. */
  75. function GetArcList($atts, $refObj='', $fields=array())
  76. {
  77. $rsArray = array();
  78. $t1 = Exectime();
  79. if(!$this->isQuery)
  80. {
  81. $this->dsql->Execute('dlist', $this->sourceSql);
  82. }
  83. $i = 0;
  84. while($arr=$this->dsql->GetArray('dlist'))
  85. {
  86. $i++;
  87. $arr['filename'] = $arr['arcurl'] = GetFileUrl($arr['id'],$arr['typeid'],$arr['senddate'],$arr['title'],$arr['ismake'],
  88. $arr['arcrank'],$arr['namerule'],$arr['typedir'],$arr['money'],$arr['filename'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  89. $arr['typeurl'] = GetTypeUrl($arr['typeid'],MfTypedir($arr['typedir']),$arr['isdefault'],$arr['defaultname'],
  90. $arr['ispart'],$arr['namerule2'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  91. if($arr['litpic'] == '-' || $arr['litpic'] == '')
  92. {
  93. $arr['litpic'] = 'templets/images/dfpic.gif';
  94. }
  95. if(!preg_match("#^http:\/\/#i", $arr['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  96. {
  97. $arr['litpic'] = $GLOBALS['cfg_mainsite'].$arr['litpic'];
  98. }
  99. $arr['picname'] = $arr['litpic'];
  100. $arr['alttitle'] = $arr['userid']." 的空间";
  101. $arr['face'] = ($arr['face']!='' ? $arr['face'] : 'images/nopic.gif');
  102. if($arr['userid']!='')
  103. {
  104. $arr['spaceurl'] = $GLOBALS['cfg_basehost'].'/member/index.php?uid='.$arr['userid'];
  105. }
  106. else
  107. {
  108. $arr['alttitle'] = $arr['title'];
  109. $arr['spaceurl'] = $arr['arcurl'];
  110. $arr['face'] = $arr['litpic'];
  111. $arr['face'] = str_replace('defaultpic','dfcaicai',$arr['face']);
  112. }
  113. if(!empty($arr['lastpost']))
  114. {
  115. $arr['lastpost'] = MyDate('m-d h:i',$arr['lastpost']);
  116. }
  117. else
  118. {
  119. $arr['lastpost'] = "<a href='../plus/feedback.php?aid={$arr['id']}'>说几句&gt;&gt;</a>";
  120. }
  121. $rsArray[$i] = $arr;
  122. if($i >= $this->pageSize)
  123. {
  124. break;
  125. }
  126. }
  127. $this->dsql->FreeResult('dlist');
  128. $this->queryTime = (Exectime() - $t1);
  129. return $rsArray;
  130. }
  131. /**
  132. * 获得最差或最好的踩踩文章
  133. *
  134. * @param array $atts
  135. * @param object $refObj
  136. * @param array $fields
  137. * @return array
  138. */
  139. function GetSortArc($atts, $refObj='', $fields=array())
  140. {
  141. $arcrow = (empty($atts['row']) ? 12 : $atts['row']);
  142. $order = (empty($atts['order']) ? 'scores' : $atts['order'] );
  143. $orderway = (empty($atts['orderway']) ? 'desc' : $atts['orderway'] );
  144. if(empty($arcrow)) $arcrow = 12;
  145. $query = "SELECT arc.*,tp.typedir,tp.typename,
  146. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  147. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON tp.id = arc.typeid
  148. WHERE arc.arcrank>-1 ORDER BY arc.{$order} $orderway LIMIT 0,$arcrow ";
  149. $rsArray = array();
  150. $cacheFile = DEDEDATA.'/cache/caicai_'.md5($query).'.inc';
  151. $needCache = false;
  152. if(file_exists($cacheFile) && filemtime($cacheFile)-time() < $this->arcCacheTime)
  153. {
  154. $fp = fopen($cacheFile, 'r');
  155. $ids = fread($fp, filesize($cacheFile));
  156. fclose($fp);
  157. $ids = trim($ids);
  158. if( !empty($ids) )
  159. {
  160. $query = "SELECT arc.*,tp.typedir,tp.typename,
  161. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  162. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON tp.id=arc.typeid
  163. WHERE arc.id in($ids) ORDER BY arc.{$order} $orderway ";
  164. }
  165. }
  166. else
  167. {
  168. $needCache = true;
  169. }
  170. $ids = array();
  171. $i = 0;
  172. $this->dsql->Execute('cai',$query);
  173. while($arr=$this->dsql->GetArray('cai'))
  174. {
  175. $i++;
  176. $ids[] = $arr['id'];
  177. $arr['filename'] = $arr['arcurl'] = GetFileUrl($arr['id'],$arr['typeid'],$arr['senddate'],$arr['title'],$arr['ismake'],
  178. $arr['arcrank'],$arr['namerule'],$arr['typedir'],$arr['money'],$arr['filename'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  179. $arr['typeurl'] = GetTypeUrl($arr['typeid'], MfTypedir($arr['typedir']), $arr['isdefault'], $arr['defaultname'],
  180. $arr['ispart'], $arr['namerule2'], $arr['moresite'], $arr['siteurl'], $arr['sitepath']);
  181. if($arr['litpic']=='') $arr['litpic'] = '/static/defaultpic.gif';
  182. if(!preg_match("#^http:\/\/#", $arr['litpic']))
  183. {
  184. $arr['picname'] = $arr['litpic'] = $GLOBALS['cfg_cmsurl'].$arr['litpic'];
  185. }
  186. else
  187. {
  188. $arr['picname'] = $arr['litpic'] = $arr['litpic'];
  189. }
  190. $rsArray[$i] = $arr;
  191. }
  192. $this->dsql->FreeResult('cai');
  193. //写入缓存
  194. if($needCache && count($ids) > 0)
  195. {
  196. $idsstr = join(',', $ids);
  197. file_put_contents($cacheFile, $idsstr);
  198. // $fp = fopen($cacheFile, 'w');
  199. // fwrite($fp, $idsstr);
  200. // fclose($fp);
  201. }
  202. return $rsArray;
  203. }
  204. /**
  205. * 获取顶级栏目列表
  206. *
  207. * @param array $atts
  208. * @param object $refObj
  209. * @param array $fields
  210. * @return array
  211. */
  212. function GetCatalog($atts,$refObj='',$fields=array())
  213. {
  214. $maxrow = (empty($atts['row']) ? 12 : $atts['row']);
  215. $query = "SELECT id,typename FROM `#@__arctype` WHERE reid=0 AND ispart<2 AND channeltype>0 ORDER BY sortrank ASC LIMIT 0,$maxrow ";
  216. $rsArray = array();
  217. $this->dsql->Execute('co',$query);
  218. $i = 0;
  219. while($arr=$this->dsql->GetArray('co'))
  220. {
  221. $i++;
  222. $rsArray[$i] = $arr;
  223. }
  224. $this->dsql->FreeResult('co');
  225. return $rsArray;
  226. }
  227. }//End Class