/** * @brief 取得pageBar * @param string $url URL地址,一般为空! * @param string $attrs URL后接参数 * @return string pageBar的对应HTML代码 */ public function getPageBar($url = '', $attrs = '') { $attr = ''; if ($attrs != '') { $ajax_attr = " {$attrs} "; } $flag = false; if ($url == '') { $flag = true; $url = url::getUri(); $url = preg_replace('/page=\\d?&/', '', $url); $url = preg_replace('/(\\?|&|\\/)page(\\/|=).*/i', '', $url); $mark = '='; if (strpos($url, '?') !== false) { $index = '&page'; } else { $index = '?page'; } } else { $flag = false; $index = ''; $mark = ''; } $baseUrl = "{$url}{$index}{$mark}"; $baseUrl = safe::filter($baseUrl, 'text'); $attr = str_replace('[page]', 1, $attrs); $href = $baseUrl . ($flag ? 1 : ''); $tem = "<div class='pages_bar'><a href='{$href}' {$attr}>首页</a>"; $attr = str_replace('[page]', $this->getIndex() - 1, $attrs); $href = $baseUrl . ($flag ? $this->getIndex() - 1 : ''); if ($this->firstpage > 1) { $tem .= "<a href='{$href}' {$attr}>上一页</a>"; } for ($i = $this->firstpage; $i <= $this->lastpage; $i++) { $attr = str_replace('[page]', $i, $attrs); $href = $baseUrl . ($flag ? $i : ''); if ($i == $this->index) { $tem .= "<a class='current_page' href='{$href}' {$attr}>{$i}</a>"; } else { $tem .= "<a href='{$href}' {$attr}>{$i}</a>"; } } $attr = str_replace('[page]', $this->getIndex() + 1, $attrs); $href = $baseUrl . ($flag ? $this->getIndex() + 1 : ''); if ($this->lastpage < $this->totalpage) { $tem .= "<a href='{$href}' {$attr}>下一页</a>"; } if ($this->totalpage == 0) { $this->index = 1; } $attr = str_replace('[page]', $this->totalpage, $attrs); $href = $baseUrl . ($flag ? $this->totalpage : ''); return $tem . "<a href='{$href}' {$attr}>尾页</a><span>当前第{$this->index}页/共{$this->totalpage}页</span></div>"; }