/** 分页列表的设置 @param string $_url : 分页连接代码,格式如:index.php?pid=%d&rn=%d,注意的是pid必须在rn的前面 @param int $_per : record总数 @param int $_pid : 当前页 @param int $_rn : 每页显示数 @param string $_inner : 模板 */ function kc_pagelist($_url = '', $_per, $_pid = 1, $_rn = 20, $_inner = null) { $_count = $_per / $_rn; //总页数 可能非int类型,所以做如下比较并赋值 if ($_per == 0 || $_count == 1) { return; } if ($_pid == null) { $_pid = 1; } if ($_count != (int) $_count) { $_count = (int) $_count + 1; } if ($_pid > $_count) { //如果当前页大于总页数,这个是不现实的.. $_pid = $_count; } $_url = str_replace('RN', $_rn, $_url); $_inner = isset($_inner[0]) ? $_inner : '<p class="k_pagelist">{king:Previous/}{king:Standard/}{king:Next/}{king:Jump/}</p>'; //full $full = ''; for ($i = 1; $i <= $_count; $i++) { $_pid == $i ? $full .= '<strong>' . $i . '</strong>' : ($full .= '<a href="' . kc_formatpath($_url, $i) . '">' . $i . '</a>'); } //select $select = '<select onChange="parent.location=this.options[this.selectedIndex].value">'; for ($i = 1; $i <= $_count; $i++) { $_pid == $i ? $select .= '<option selected="selected">' . $i . '</option>' : ($select .= '<option value="' . kc_formatpath($_url, $i) . '">' . $i . '</option>'); } $select .= '</select>'; //Next $next = $_pid == $_count ? '<span>Next ></span>' : '<a href="' . kc_formatpath($_url, $_pid + 1) . '">Next ></a>'; //Previous $previous = $_pid == 1 ? '<span>< Previous</span>' : '<a href="' . kc_formatpath($_url, $_pid - 1, 5) . '">< Previous</a>'; //Standard $_numr = 5; //每页右侧显示翻页数量 $_numl = 2; //左侧显示2个 $_num = $_numr + $_numl + 1; //合计显示 $sta = $_pid == 1 ? '<strong>1</strong>' : '<a href="' . kc_formatpath($_url, 1) . '">1</a>'; //Page 1 if ($_count >= 2) { //Page 2 $sta .= $_pid == 2 ? '<strong>2</strong>' : '<a href="' . kc_formatpath($_url, 2) . '">2</a>'; } if ($_pid >= $_numl + 4 && $_count > $_num + 3) { $sta .= '<i>...</i>'; } $i_sta = $_pid - $_numl; //开始 $i_end = $_pid + $_numr; //结束 if ($_pid <= $_numl + 2) { //重新设置结束 $i_end = $_num + 2; } if ($_pid >= $_count - $_num + 2) { //重新设置开始 $i_sta = $_count - $_num; } for ($i = $i_sta; $i < $i_end; $i++) { //循环 if ($i >= 3 && $i <= $_count - 2) { $i == $_pid ? $sta .= '<strong>' . $i . '</strong>' : ($sta .= '<a href="' . kc_formatpath($_url, $i) . '">' . $i . '</a>'); // : $sta.='<a href="'.sprintf($_url1,$i,$_rn).'">'.$i.'</a>'; } } if ($_pid + $_numr <= $_count - 2 && $_count - 2 > $_num + 1) { $sta .= '<i>...</i>'; } if ($_count > 3) { $_pid == $_count - 1 ? $sta .= '<strong>' . ($_count - 1) . '</strong>' : ($sta .= '<a href="' . kc_formatpath($_url, $_count - 1) . '">' . ($_count - 1) . '</a>'); } if ($_pid == $_count) { //Page Count if ($_count >= 3) { $sta .= '<strong>' . $_count . '</strong>'; } } else { if ($_count >= 3) { $sta .= '<a href="' . kc_formatpath($_url, $_count) . '">' . $_count . '</a>'; } } //first $_pid == 1 ? $first = '<strong><< First</strong>' : ($first = '<a href="' . kc_formatpath($_url, 1) . '"><< First</a>'); //last $_pid == $_count ? $last = '<strong>Last >></strong>' : ($last = '<a href="' . kc_formatpath($_url, $_count) . '">Last >></a>'); //jump $jump = '<input type="text" size="3" onkeydown="if(event.keyCode==13) {window.location=\'' . kc_formatpath($_url, "'+this.value+'") . '\'; return false;}" />'; //sprintf(str_replace('pid=PID','pid=%s',$_url),"'+this.value+'",$_rn) $tmp = new KC_Template_class(); $tmp->assign('standard', $sta); $tmp->assign('select', $select); $tmp->assign('previous', $previous); //上一个 $tmp->assign('next', $next); //下一个 $tmp->assign('first', $first); //第一个 $tmp->assign('last', $last); //最后一个 $tmp->assign('full', $full); $tmp->assign('jump', $jump); $tmp->assign('pagecount', $_count); $tmp->assign('count', $_per); $tmp->assign('pid', $_pid); $tmp->assign('rn', $_rn); $s = $tmp->output($_inner); return $s; }
/** 输出路径[LIST] @param array $info 列表信息 @param int $is 1输出根相对路径,物理生成,0完整URL路径 @param int $pid 第x页 @return string */ public function pathList($info, $is = 0, $pid = 1) { global $king; //初始化静态变量 $inst = $king->config('inst'); $line = $king->config('rewriteline'); $end = $king->config('rewriteend'); $site = $this->infoSite($info['siteid']); $siteurl = $site['siteurl']; $listid = $info['listid']; $modelid = $info['modelid']; if ($is && (int) $info['nlist'] !== 0) { return False; } //输出静态路径并nlist不等于0的时候,返回 False //0静态1动态2伪静态3不显示4订单、留言类 switch ((int) $modelid) { case 0: //单页面 switch ((int) $info['nlist']) { case 0: if ($info['klistpath'] == '') { //根 $path = $is ? False : $siteurl . $inst; } else { $path = kc_formatPath($info['klistpath'], 1, 1); if (!$is) { $path = $siteurl . $inst . $path; //当输入值为/结尾的时候,也对$path进行二次处理 if (substr($info['klistpath'], -1, 1) == '/') { $path = substr($path, 0, strlen($path) - strlen($king->config('file'))); } } // $path=$is ? $path : $siteurl.$inst.$path; } break; case 1: $path = $info['klistpath'] == '' ? $siteurl . $inst : $siteurl . $inst . "index.php/list{$line}{$listid}{$end}"; break; case 2: $path = $info['klistpath'] == '' ? $siteurl . $inst : $siteurl . $inst . "list{$line}{$listid}{$end}"; break; case 3: $path = "javascript:alert('" . $king->lang->get('portal/error/stop') . "');"; break; } break; case -1: //超级链接 $path = $info['klistpath']; break; default: //自定义模型 switch ((int) $info['nlist']) { case 0: $path = kc_formatpath($info['klistpath'], $pid, $is); $path = $is ? $path : $siteurl . $inst . $path; break; case 1: $path = $siteurl . $inst . "index.php/list{$line}{$listid}{$line}{$pid}{$end}"; break; case 2: $path = $siteurl . $inst . "list{$line}{$listid}{$line}{$pid}{$end}"; break; case 3: $path = "javascript:alert('" . $king->lang->get('portal/error/stopmsg') . "');"; return $path; break; case 4: $path = $siteurl . $inst . "portal/index.php?action=edt&listid={$listid}"; break; } } return $path; }