国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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