国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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