国内流行的内容管理系统(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.

467 lines
14KB

  1. <?php if(!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 会员列表视图类
  4. *
  5. * @version $Id: arc.memberlistview.class.php 1 14:49 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."/dedetemplate.class.php");
  12. $lang_pre_page = '上页';
  13. $lang_next_page = '下页';
  14. $lang_index_page = '首页';
  15. $lang_end_page = '末页';
  16. $lang_record_number = '条记录';
  17. $lang_page = '页';
  18. $lang_total = '共';
  19. /**
  20. * 档案展示类
  21. *
  22. * @package FreeList
  23. * @subpackage DedeCMS.Libraries
  24. * @link https://www.dedebiz.com
  25. */
  26. class MemberListview
  27. {
  28. var $dsql = '';
  29. var $tpl = '';
  30. var $pageNO = 1;
  31. var $totalPage = 0;
  32. var $totalResult = 0;
  33. var $pageSize = 25;
  34. var $getValues = array();
  35. var $sourceSql = '';
  36. var $isQuery = false;
  37. var $randts = 0;
  38. /**
  39. * 用指定的文档ID进行初始化
  40. *
  41. * @access public
  42. * @param string $tplfile 模板文件
  43. * @return void
  44. */
  45. function __construct($tplfile='')
  46. {
  47. $this->sourceSql = '';
  48. $this->pageSize = 25;
  49. $this->queryTime = 0;
  50. $this->getValues = Array();
  51. $this->randts = time();
  52. $this->dsql = $GLOBALS['dsql'];
  53. $this->SetVar('ParseEnv','datalist');
  54. $this->tpl = new DedeTemplate();
  55. if($GLOBALS['cfg_tplcache']=='N')
  56. {
  57. $this->tpl->isCache = false;
  58. }
  59. if($tplfile!='')
  60. {
  61. $this->tpl->LoadTemplate($tplfile);
  62. }
  63. }
  64. //兼容PHP4
  65. function MemberListview($tplfile='')
  66. {
  67. $this->__construct($tplfile);
  68. }
  69. /**
  70. * 设置SQL语句
  71. *
  72. * @access public
  73. * @param string $sql SQL语句
  74. * @return void
  75. */
  76. function SetSource($sql)
  77. {
  78. $this->sourceSql = $sql;
  79. }
  80. /**
  81. * 设置模板
  82. * 如果想要使用模板中指定的pagesize,必须在调用模板后才调用 SetSource($sql)
  83. *
  84. * @access public
  85. * @param string $tplfile 模板文件
  86. * @return void
  87. */
  88. function SetTemplate($tplfile)
  89. {
  90. $this->tpl->LoadTemplate($tplfile);
  91. }
  92. /**
  93. * 设置模板
  94. *
  95. * @access public
  96. * @param string $tplfile 模板文件
  97. * @return void
  98. */
  99. function SetTemplet($tplfile)
  100. {
  101. $this->tpl->LoadTemplate($tplfile);
  102. }
  103. /**
  104. * 对config参数及get参数等进行预处理
  105. *
  106. * @access private
  107. * @return void
  108. */
  109. function PreLoad()
  110. {
  111. global $totalresult,$pageno;
  112. if(empty($pageno) || preg_match("/[^0-9]/", $pageno))
  113. {
  114. $pageno = 1;
  115. }
  116. if(empty($totalresult) || preg_match("/[^0-9]/", $totalresult))
  117. {
  118. $totalresult = 0;
  119. }
  120. $this->pageNO = $pageno;
  121. $this->totalResult = $totalresult;
  122. if(isset($this->tpl->tpCfgs['pagesize']))
  123. {
  124. $this->pageSize = $this->tpl->tpCfgs['pagesize'];
  125. }
  126. $this->totalPage = ceil($this->totalResult/$this->pageSize);
  127. if($this->totalResult==0)
  128. {
  129. //$this->isQuery = true;
  130. //$this->dsql->Execute('mbdl',$this->sourceSql);
  131. //$this->totalResult = $this->dsql->GetTotalRow('mbdl');
  132. $countQuery = preg_replace("/select[ \r\n\t](.*)[ \r\n\t]from/i","Select count(*) as dd From",$this->sourceSql);
  133. $row = $this->dsql->GetOne($countQuery);
  134. $row['dd'] = empty($row['dd']) ? 0 : $row['dd'];
  135. $this->totalResult = $row['dd'];
  136. $this->sourceSql .= " limit 0,".$this->pageSize;
  137. }
  138. else
  139. {
  140. $this->sourceSql .= " limit ".(($this->pageNO-1) * $this->pageSize).",".$this->pageSize;
  141. }
  142. }
  143. /**
  144. * 设置网址的Get参数键值
  145. *
  146. * @access public
  147. * @param string $key 键
  148. * @param string $value 值
  149. * @return void
  150. */
  151. function SetParameter($key, $value)
  152. {
  153. $this->getValues[$key] = $value;
  154. }
  155. /**
  156. * 设置/获取文档相关的各种变量
  157. *
  158. * @access public
  159. * @param string $k 键
  160. * @param string $v 值
  161. * @return void
  162. */
  163. function SetVar($k, $v)
  164. {
  165. global $_vars;
  166. if(!isset($_vars[$k])) $_vars[$k] = $v;
  167. }
  168. /**
  169. * 获取值
  170. *
  171. * @param string $k
  172. * @return string
  173. */
  174. function GetVar($k)
  175. {
  176. global $_vars;
  177. if(isset($_vars[$k])) return $_vars[$k];
  178. else return '';
  179. }
  180. /**
  181. * 获取当前页数据列表
  182. *
  183. * @access public
  184. * @param string $atts 属性
  185. * @param string $refObj 实例化对象
  186. * @param string $fields 字段
  187. * @return array
  188. */
  189. function GetArcList($atts,$refObj='',$fields=array())
  190. {
  191. $attlist = "titlelen=30,infolen=200,imgwidth=120,imgheight=90";
  192. FillAtts($atts,$attlist);
  193. FillFields($atts,$fields,$refObj);
  194. extract($atts, EXTR_OVERWRITE);
  195. $rsArray = array();
  196. //global $_vars;
  197. //$t1 = Exectime();
  198. if(!$this->isQuery)
  199. {
  200. $this->dsql->Execute('mbdl',$this->sourceSql);
  201. }
  202. $i = 0;
  203. while($row = $this->dsql->GetArray('mbdl'))
  204. {
  205. $i++;
  206. if(!isset($row['description'])) $row['description'] = '';
  207. if(!isset($row['color'])) $row['color'] = '';
  208. if(!isset($row['pubdate'])) $row['pubdate'] = $row['senddate'];
  209. //处理一些特殊字段
  210. $row['infos'] = cn_substr($row['description'],$infolen);
  211. $row['id'] = $row['id'];
  212. $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  213. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  214. $row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],
  215. $row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  216. if($row['litpic'] == '-' || $row['litpic'] == '')
  217. {
  218. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.gif';
  219. }
  220. if(!preg_match("/^http:\/\//i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  221. {
  222. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  223. }
  224. $row['picname'] = $row['litpic'];
  225. $row['stime'] = GetDateMK($row['pubdate']);
  226. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  227. $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("/['><]/", "", $row['title'])."'>";
  228. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  229. $row['fulltitle'] = $row['title'];
  230. $row['title'] = cn_substr($row['title'],$titlelen);
  231. if($row['color']!='')
  232. {
  233. $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
  234. }
  235. if(preg_match('/b/', $row['flag']))
  236. {
  237. $row['title'] = "<strong>".$row['title']."</strong>";
  238. }
  239. //$row['title'] = "<b>".$row['title']."</b>";
  240. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  241. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  242. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  243. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  244. $rsArray[$i] = $row;
  245. if($i >= $this->pageSize)
  246. {
  247. break;
  248. }
  249. }
  250. $this->dsql->FreeResult();
  251. //echo "执行时间:".(Exectime() - $t1);
  252. return $rsArray;
  253. }
  254. /**
  255. * 获取分页导航列表
  256. *
  257. * @access public
  258. * @param string $atts 属性
  259. * @param string $refObj 实例化对象
  260. * @param string $fields 字段
  261. * @return string
  262. */
  263. function GetPageList($atts,$refObj='',$fields=array())
  264. {
  265. global $lang_pre_page,$lang_next_page,$lang_index_page,$lang_end_page,$lang_record_number,$lang_page,$lang_total;
  266. $prepage = $nextpage = $geturl= $hidenform = '';
  267. $purl = $this->GetCurUrl();
  268. $prepagenum = $this->pageNO-1;
  269. $nextpagenum = $this->pageNO+1;
  270. if(!isset($atts['listsize']) || preg_match("/[^0-9]/", $atts['listsize']))
  271. {
  272. $atts['listsize'] = 5;
  273. }
  274. if(!isset($atts['listitem']))
  275. {
  276. $atts['listitem'] = "info,index,end,pre,next,pageno";
  277. }
  278. $totalpage = ceil($this->totalResult/$this->pageSize);
  279. //echo " {$totalpage}=={$this->totalResult}=={$this->pageSize}";
  280. //无结果或只有一页的情况
  281. if($totalpage<=1 && $this->totalResult > 0)
  282. {
  283. return "{$lang_total} 1 {$lang_page}/".$this->totalResult.$lang_record_number;
  284. }
  285. if($this->totalResult == 0)
  286. {
  287. return "{$lang_total} 0 {$lang_page}/".$this->totalResult.$lang_record_number;
  288. }
  289. $infos = "<span>{$lang_total} {$totalpage} {$lang_page}/{$this->totalResult}{$lang_record_number}</span> ";
  290. if($this->totalResult!=0)
  291. {
  292. $this->getValues['totalresult'] = $this->totalResult;
  293. }
  294. if(count($this->getValues)>0)
  295. {
  296. foreach($this->getValues as $key=>$value)
  297. {
  298. $value = urlencode($value);
  299. $geturl.="$key=$value"."&";
  300. $hidenform.="<input type='hidden' name='$key' value='$value'>\r\n";
  301. }
  302. }
  303. $purl .= "?".$geturl;
  304. //获得上一页和下一页的链接
  305. if($this->pageNO!=1)
  306. {
  307. $prepage.="<a href='".$purl."pageno=$prepagenum'>$lang_pre_page</a> \r\n";
  308. $indexpage="<a href='".$purl."pageno=1'>$lang_index_page</a> \r\n";
  309. }
  310. else
  311. {
  312. $indexpage="$lang_index_page \r\n";
  313. }
  314. if($this->pageNO!=$totalpage&&$totalpage>1)
  315. {
  316. $nextpage.="<a href='".$purl."pageno=$nextpagenum'>$lang_next_page</a> \r\n";
  317. $endpage="<a href='".$purl."pageno=$totalpage'>$lang_end_page</a> \r\n";
  318. }
  319. else
  320. {
  321. $endpage=" $lang_end_page \r\n";
  322. }
  323. //获得数字链接
  324. $listdd="";
  325. $total_list = $atts['listsize'] * 2 + 1;
  326. if($this->pageNO>=$total_list)
  327. {
  328. $j=$this->pageNO-$atts['listsize'];
  329. $total_list=$this->pageNO+$atts['listsize'];
  330. if($total_list>$totalpage)
  331. {
  332. $total_list=$totalpage;
  333. }
  334. }
  335. else
  336. {
  337. $j=1;
  338. if($total_list>$totalpage) $total_list=$totalpage;
  339. }
  340. for($j;$j<=$total_list;$j++)
  341. {
  342. if($j==$this->pageNO)
  343. {
  344. $listdd.= "<strong>$j</strong> \r\n";
  345. }
  346. else
  347. {
  348. $listdd.="<a href='".$purl."pageno=$j'>".$j."</a> \r\n";
  349. }
  350. }
  351. $plist = "<div class=\"pagelistbox\">\r\n";
  352. //info,index,end,pre,next,pageno,form
  353. if(preg_match("/info/i",$atts['listitem']))
  354. {
  355. $plist .= $infos;
  356. }
  357. if(preg_match("/index/i",$atts['listitem']))
  358. {
  359. $plist .= $indexpage;
  360. }
  361. if(preg_match("/pre/i",$atts['listitem']))
  362. {
  363. $plist .= $prepage;
  364. }
  365. if(preg_match("/pageno/i",$atts['listitem']))
  366. {
  367. $plist .= $listdd;
  368. }
  369. if(preg_match("/next/i",$atts['listitem']))
  370. {
  371. $plist .= $nextpage;
  372. }
  373. if(preg_match("/end/i",$atts['listitem']))
  374. {
  375. $plist .= $endpage;
  376. }
  377. if(preg_match("/form/i",$atts['listitem']))
  378. {
  379. $plist .=" <form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
  380. if($totalpage>$total_list)
  381. {
  382. $plist.="<input type='text' name='pageno' style='padding:0px;width:30px;height:18px'>\r\n";
  383. $plist.="<input type='submit' name='plistgo' value='GO' style='padding:0px;width:30px;height:18px;font-size:11px'>\r\n";
  384. }
  385. $plist .= "</form>\r\n";
  386. }
  387. $plist .= "</div>\r\n";
  388. return $plist;
  389. }
  390. /**
  391. * 获得当前网址
  392. *
  393. * @access public
  394. * @return string
  395. */
  396. function GetCurUrl()
  397. {
  398. if(!empty($_SERVER["REQUEST_URI"]))
  399. {
  400. $nowurl = $_SERVER["REQUEST_URI"];
  401. $nowurls = explode("?",$nowurl);
  402. $nowurl = $nowurls[0];
  403. }
  404. else
  405. {
  406. $nowurl = $_SERVER["PHP_SELF"];
  407. }
  408. return $nowurl;
  409. }
  410. //关闭
  411. function Close()
  412. {
  413. }
  414. /**
  415. * 显示数据
  416. *
  417. * @access public
  418. * @return void
  419. */
  420. function Display()
  421. {
  422. if($this->sourceSql != '') $this->PreLoad();
  423. //在PHP4中,对象引用必须放在display之前,放在其它位置中无效
  424. $this->tpl->SetObject($this);
  425. $this->tpl->Display();
  426. }
  427. /**
  428. * 保存为HTML
  429. *
  430. * @access public
  431. * @param string $filename 文件名称
  432. * @return string
  433. */
  434. function SaveTo($filename)
  435. {
  436. $this->tpl->SaveTo($filename);
  437. }
  438. }//End Class