PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/uploads/include/arc.caicai.class.php

http://pj-photohost.googlecode.com/
PHP | 242 lines | 192 code | 17 blank | 33 comment | 26 complexity | e9933bfe9ff8d554bf40ecd1a55293ca MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if(!defined('DEDEINC'))
  3. {
  4. exit("Request Error!");
  5. }
  6. require_once(DEDEINC."/datalistcp.class.php");
  7. require_once(DEDEINC."/channelunit.func.php");
  8. class Caicai extends DataListCP
  9. {
  10. var $maxPageSize = 100;
  11. var $arcCacheTime = 3600;
  12. /**
  13. * ?config???get????????
  14. *
  15. */
  16. function PreLoad()
  17. {
  18. global $totalresult,$pageno;
  19. if(empty($pageno) || ereg("[^0-9]",$pageno))
  20. {
  21. $pageno = 1;
  22. }
  23. if(empty($totalresult) || ereg("[^0-9]",$totalresult))
  24. {
  25. $totalresult = 0;
  26. }
  27. $this->pageNO = $pageno;
  28. $this->totalResult = $totalresult;
  29. if(isset($this->tpl->tpCfgs['pagesize'])){
  30. $this->pageSize = $this->tpl->tpCfgs['pagesize'];
  31. }
  32. $this->totalPage = ceil($this->totalResult/$this->pageSize);
  33. if($this->totalPage > $this->maxPageSize)
  34. {
  35. $this->totalPage = $this->maxPageSize;
  36. }
  37. //??????
  38. if($this->pageNO > $this->totalPage)
  39. {
  40. $this->pageNO = $this->totalPage;
  41. $this->totalResult = $this->totalPage * $this->pageSize;
  42. }
  43. $this->sourceSql = ereg_replace("limit [0-9,]{1,}",'',$this->sourceSql);
  44. if($this->totalResult==0)
  45. {
  46. //$this->isQuery = true;
  47. //$this->dsql->Execute('dlist',$this->sourceSql);
  48. //$this->totalResult = $this->dsql->GetTotalRow('dlist');
  49. $countQuery = eregi_replace("select[ \r\n\t](.*)[ \r\n\t]from","Select count(*) as dd From",$this->sourceSql);
  50. $row = $this->dsql->GetOne($countQuery);
  51. $this->totalResult = $row['dd'];
  52. $this->sourceSql .= " limit 0,".$this->pageSize;
  53. }
  54. else
  55. {
  56. $this->sourceSql .= " limit ".(($this->pageNO-1) * $this->pageSize).",".$this->pageSize;
  57. }
  58. }
  59. /**
  60. * ?????????
  61. *
  62. * @param array $atts
  63. * @param object $refObj
  64. * @param array $fields
  65. * @return array
  66. */
  67. function GetArcList($atts,$refObj='',$fields=array())
  68. {
  69. $rsArray = array();
  70. $t1 = Exectime();
  71. if(!$this->isQuery)
  72. {
  73. $this->dsql->Execute('dlist',$this->sourceSql);
  74. }
  75. $i = 0;
  76. while($arr=$this->dsql->GetArray('dlist'))
  77. {
  78. $i++;
  79. $arr['filename'] = $arr['arcurl'] = GetFileUrl($arr['id'],$arr['typeid'],$arr['senddate'],$arr['title'],$arr['ismake'],
  80. $arr['arcrank'],$arr['namerule'],$arr['typedir'],$arr['money'],$arr['filename'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  81. $arr['typeurl'] = GetTypeUrl($arr['typeid'],MfTypedir($arr['typedir']),$arr['isdefault'],$arr['defaultname'],
  82. $arr['ispart'],$arr['namerule2'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  83. if($arr['litpic'] == '-' || $arr['litpic'] == '')
  84. {
  85. $arr['litpic'] = 'images/dfpic.gif';
  86. }
  87. if(!eregi("^http://",$arr['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  88. {
  89. $arr['litpic'] = $GLOBALS['cfg_mainsite'].$arr['litpic'];
  90. }
  91. $arr['picname'] = $arr['litpic'];
  92. $arr['alttitle'] = $arr['userid']." ???";
  93. $arr['face'] = ($arr['face']!='' ? $arr['face'] : 'images/nopic.gif');
  94. if($arr['userid']!='')
  95. {
  96. $arr['spaceurl'] = $GLOBALS['cfg_basehost'].'/member/index.php?uid='.$arr['userid'];
  97. }
  98. else
  99. {
  100. $arr['alttitle'] = $arr['title'];
  101. $arr['spaceurl'] = $arr['arcurl'];
  102. $arr['face'] = $arr['litpic'];
  103. $arr['face'] = str_replace('defaultpic','dfcaicai',$arr['face']);
  104. }
  105. if(!empty($arr['lastpost']))
  106. {
  107. $arr['lastpost'] = MyDate('m-d h:i',$arr['lastpost']);
  108. }
  109. else
  110. {
  111. $arr['lastpost'] = "<a href='../plus/feedback.php?aid={$arr['id']}'>???&gt;&gt;</a>";
  112. }
  113. $rsArray[$i] = $arr;
  114. if($i >= $this->pageSize)
  115. {
  116. break;
  117. }
  118. }
  119. $this->dsql->FreeResult('dlist');
  120. $this->queryTime = (Exectime() - $t1);
  121. return $rsArray;
  122. }
  123. /**
  124. * ????????????
  125. *
  126. * @param array $atts
  127. * @param object $refObj
  128. * @param array $fields
  129. * @return array
  130. */
  131. function GetSortArc($atts,$refObj='',$fields=array())
  132. {
  133. $arcrow = (empty($atts['row']) ? 12 : $atts['row']);
  134. $order = (empty($atts['order']) ? 'scores' : $atts['order'] );
  135. $orderway = (empty($atts['orderway']) ? 'desc' : $atts['orderway'] );
  136. if(empty($arcrow))
  137. {
  138. $arcrow = 12;
  139. }
  140. $query = "Select arc.*,tp.typedir,tp.typename,
  141. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  142. From `#@__archives` arc left join `#@__arctype` tp on tp.id=arc.typeid
  143. where arc.arcrank>-1 order by arc.{$order} $orderway limit 0,$arcrow ";
  144. $rsArray = array();
  145. $cacheFile = DEDEDATA.'/cache/caicai_'.md5($query).'.inc';
  146. $needCache = false;
  147. if(file_exists($cacheFile) && filemtime($cacheFile)-time() < $this->arcCacheTime)
  148. {
  149. $fp = fopen($cacheFile, 'r');
  150. $ids = fread($fp, filesize($cacheFile));
  151. fclose($fp);
  152. $ids = trim($ids);
  153. if( !empty($ids) )
  154. {
  155. $query = "Select arc.*,tp.typedir,tp.typename,
  156. tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  157. From `#@__archives` arc left join `#@__arctype` tp on tp.id=arc.typeid
  158. where arc.id in($ids) order by arc.{$order} $orderway ";
  159. }
  160. }
  161. else
  162. {
  163. $needCache = true;
  164. }
  165. $ids = array();
  166. $i = 0;
  167. $this->dsql->Execute('cai',$query);
  168. while($arr=$this->dsql->GetArray('cai'))
  169. {
  170. $i++;
  171. $ids[] = $arr['id'];
  172. $arr['filename'] = $arr['arcurl'] = GetFileUrl($arr['id'],$arr['typeid'],$arr['senddate'],$arr['title'],$arr['ismake'],
  173. $arr['arcrank'],$arr['namerule'],$arr['typedir'],$arr['money'],$arr['filename'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  174. $arr['typeurl'] = GetTypeUrl($arr['typeid'],MfTypedir($arr['typedir']),$arr['isdefault'],$arr['defaultname'],
  175. $arr['ispart'],$arr['namerule2'],$arr['moresite'],$arr['siteurl'],$arr['sitepath']);
  176. if($arr['litpic']=='')
  177. {
  178. $arr['litpic'] = '/images/defaultpic.gif';
  179. }
  180. if(!eregi("^http://",$arr['litpic']))
  181. {
  182. $arr['picname'] = $arr['litpic'] = $GLOBALS['cfg_cmsurl'].$arr['litpic'];
  183. }
  184. else
  185. {
  186. $arr['picname'] = $arr['litpic'] = $arr['litpic'];
  187. }
  188. $rsArray[$i] = $arr;
  189. }
  190. $this->dsql->FreeResult('cai');
  191. //????
  192. if($needCache && count($ids) > 0)
  193. {
  194. $idsstr = join(',', $ids);
  195. $fp = fopen($cacheFile, 'w');
  196. fwrite($fp, $idsstr);
  197. fclose($fp);
  198. }
  199. return $rsArray;
  200. }
  201. /**
  202. * ????????
  203. *
  204. * @param array $atts
  205. * @param object $refObj
  206. * @param array $fields
  207. * @return array
  208. */
  209. function GetCatalog($atts,$refObj='',$fields=array())
  210. {
  211. $maxrow = (empty($atts['row']) ? 12 : $atts['row']);
  212. $query = "Select id,typename From `#@__arctype` where reid=0 and ispart<2 And channeltype>0 order by sortrank asc limit 0,$maxrow ";
  213. $rsArray = array();
  214. $this->dsql->Execute('co',$query);
  215. $i = 0;
  216. while($arr=$this->dsql->GetArray('co'))
  217. {
  218. $i++;
  219. $rsArray[$i] = $arr;
  220. }
  221. $this->dsql->FreeResult('co');
  222. return $rsArray;
  223. }
  224. }
  225. ?>