/** * $data['totalpages'] = $total['total']; $data['perpage'] = $perpage; $data['curpage'] = intval($_INPUT['pp']); $showpages = hg_build_pagelinks($data); * * @param unknown_type $data * @param unknown_type $pageno * @param unknown_type $firstpage * @param unknown_type $lastpage * @param unknown_type $pre * @param unknown_type $next * @param unknown_type $pagenumtag * @param unknown_type $curpagenumtag * @return unknown * @param string type $data['click'] eg $data['onclick'] = 'onclick="return loadingPage(\'module=bulletin&pp=%s\', \'正在加载留言页面\',\'bulletin_content\');"'; */ function hg_build_pagelinks($data = array(), $pageno = 5, $firstpage = "|<", $lastpage = ">|", $pre = "<<", $next = ">>", $pagenumtag = '<a href="%s" %s title="%s">%s</a>', $curpagenumtag = '%s') { if (!trim($pagenumtag)) { $pagenumtag = '<a href="%s" %s title="%s">%s</a>'; } if (!trim($curpagenumtag)) { $curpagenumtag = '%s'; } $results['pages'] = ceil($data['totalpages'] / $data['perpage']); $results['total_page'] = $results['pages'] ? $results['pages'] : 1; $results['current_page'] = $data['curpage'] > 0 ? intval($data['curpage'] / $data['perpage']) + 1 : 1; $prevlink = ""; $nextlink = ""; $showpages_return = array(); if ($results['total_page'] <= 1) { return ''; } else { $data['pagelink'] = str_replace('?&', '?', $data['pagelink']); $last_char = substr($data['pagelink'], -1); switch ($last_char) { case '': $data['pagelink'] .= $_SERVER['PHP_SELF'] . '?'; break; case '?': break; default: $data['pagelink'] .= '&'; break; } $formatpagelink = $data['pagelink'] . "pp="; $showpages_return['showtotal_page'] = $results['total_page']; if ($results['current_page'] > 1) { $start = $data['curpage'] - $data['perpage']; $pagelink = $formatpagelink . $start; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $start); } $prevlink = "<li class='p_p'><a href='" . hg_build_href_link($pagelink) . "' {$onclick} title='上一页'>" . $pre . "</a></li>"; $showpages_return['showprepage'] = $prevlink; } if ($results['current_page'] < $results['total_page']) { $start = $data['curpage'] + $data['perpage']; $pagelink = $formatpagelink . $start; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $start); } $nextlink = "<li class='p_n'><a href='" . hg_build_href_link($pagelink) . "' {$onclick} title='下一页'>" . $next . "</a></li>"; $showpages_return['shownextpage'] = $nextlink; } $minpage = ceil($results['current_page'] - $pageno / 2); $maxpage = floor($results['current_page'] + $pageno / 2); $minpage = $minpage < 0 ? 0 : $minpage; $maxpage = $minpage ? $maxpage : $pageno; $maxpage = $maxpage > $results['total_page'] ? $results['total_page'] : $maxpage; $minpage = $maxpage == $pageno ? 0 : $minpage; $minpage = $maxpage == $maxpage && $results['total_page'] > $pageno ? $maxpage - $pageno : $minpage; for ($i = $minpage; $i < $maxpage; ++$i) { $numberid = $i * $data['perpage']; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $numberid); } $pagenumber = $i + 1; if ($numberid == $data['curpage']) { $pagenumber = sprintf($curpagenumtag, $pagenumber); $onclick = sprintf($data['onclick'], $numberid); $curpage .= "<li id=\"pagelink_{$pagenumber}\"><a href='#' {$onclick} class='pages_current'>{$pagenumber}</a></li>"; } else { if (1) { $url = $formatpagelink . "0"; if ($data['onclick']) { $zero = 0; $onclick = sprintf($data['onclick'], $zero); } $firstlink = "<a href='" . hg_build_href_link($url) . "' {$onclick} title='第一页'>{$firstpage}</a>"; $showpages_return['showfirstpage'] = $firstlink; } if (1) { $url = $formatpagelink . ($results['total_page'] - 1) * $data['perpage']; if ($data['onclick']) { $last = ($results['total_page'] - 1) * $data['perpage']; $onclick = sprintf($data['onclick'], $last); } $lastlink = "<a href='" . hg_build_href_link($url) . "' {$onclick} title='最后一页'>" . $lastpage . "</a>"; $showpages_return['showlastpage'] = $lastlink; } $onclick = sprintf($data['onclick'], $numberid); $pagelink = $formatpagelink . $numberid; $pagelink = sprintf($pagenumtag, hg_build_href_link($pagelink), $onclick, $pagenumber, $pagenumber); $curpage .= "<li id=\"pagelink_{$pagenumber}\">{$pagelink}</li>"; } } if ($results['current_page'] == 1) { unset($showpages_return['showfirstpage']); } else { if ($results['current_page'] == $results['total_page']) { unset($showpages_return['showlastpage']); } } $showpages_return['showpage_nums'] = $curpage; $showpages_return_str = '<div class="pagelink"><ul class="pages"><li class="page_total"><a href="#" style="cursor:default;" onclick="return false;" >共' . $showpages_return['showtotal_page'] . '页/计' . $data['totalpages'] . '条</a></li><li class="p_f">' . $showpages_return['showfirstpage'] . '</li>' . $showpages_return['showprepage'] . '' . $showpages_return['showpage_nums'] . '' . $showpages_return['shownextpage'] . '<li class="p_l">' . $showpages_return['showlastpage'] . '</li></ul></div>'; return $showpages_return_str; } }
/** * $data['totalpages'] = $total['total']; $data['perpage'] = $perpage; $data['curpage'] = intval($_INPUT['pp']); $showpages = hg_build_pagelinks($data); * * @param unknown_type $data * @param unknown_type $pageno * @param unknown_type $firstpage * @param unknown_type $lastpage * @param unknown_type $pre * @param unknown_type $next * @param unknown_type $pagenumtag * @param unknown_type $curpagenumtag * @return unknown * @param string type $data['click'] eg $data['onclick'] = 'onclick="return loadingPage(\'module=bulletin&pp=%s\', \'正在加载留言页面\',\'bulletin_content\');"'; */ function hg_build_pagelinks($data = array(), $pageno = 7, $firstpage = "|<", $lastpage = ">|", $pre = "<<", $next = ">>", $pagenumtag = '<a id="%s" href="%s" %s title="%s" class="page_bur">%s</a>', $curpagenumtag = '%s') { if (!trim($pagenumtag)) { $pagenumtag = '<a id="%s" href="%s" %s title="%s">%s</a>'; } if (!trim($curpagenumtag)) { $curpagenumtag = '%s'; } $results['pages'] = ceil($data['totalpages'] / $data['perpage']); $results['total_page'] = $results['pages'] ? $results['pages'] : 1; $results['current_page'] = $data['curpage'] > 0 ? intval($data['curpage'] / $data['perpage']) + 1 : 1; $prevlink = ""; $nextlink = ""; $showpages_return = array(); if ($results['total_page'] < 1) { return ''; } else { $data['pagelink'] = str_replace('?&', '?', $data['pagelink']); $last_char = substr($data['pagelink'], -1); switch ($last_char) { case '': $data['pagelink'] .= $_SERVER['PHP_SELF'] . '?'; break; case '?': break; default: $data['pagelink'] .= '&'; break; } $formatpagelink = $data['pagelink'] . "pp="; $showpages_return['showtotal_page'] = $results['total_page']; if ($results['current_page'] > 1) { $start = $data['curpage'] - $data['perpage']; $pagelink = $formatpagelink . $start; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $start); $pagelink = 'javascript:void(0);'; } $prevlink = "<span class='page_next'><a id='prepage_" . $start . "' href='" . hg_build_href_link($pagelink) . "' {$onclick} title='上一页'>" . $pre . "</a></span>"; $showpages_return['showprepage'] = $prevlink; } if ($results['current_page'] < $results['total_page']) { $start = $data['curpage'] + $data['perpage']; $pagelink = $formatpagelink . $start; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $start); $pagelink = 'javascript:void(0);'; } $nextlink = "<span class='page_next'><a id='nextpage_" . $start . "' href='" . hg_build_href_link($pagelink) . "' {$onclick} title='下一页'>" . $next . "</a></span>"; $showpages_return['shownextpage'] = $nextlink; } $minpage = intval(ceil($results['current_page'] - $pageno / 2)); $maxpage = floor($results['current_page'] + $pageno / 2); $minpage = $minpage < 0 ? 0 : $minpage; $maxpage = $minpage ? $maxpage : $pageno; $maxpage = $maxpage > $results['total_page'] ? $results['total_page'] : $maxpage; $minpage = $maxpage == $pageno ? 0 : $minpage; $minpage = $maxpage == $maxpage && $results['total_page'] > $pageno ? $maxpage - $pageno : $minpage; for ($i = $minpage; $i < $maxpage; ++$i) { $numberid = $i * $data['perpage']; if ($data['onclick']) { $onclick = sprintf($data['onclick'], $numberid); } $pagenumber = $i + 1; if ($numberid == $data['curpage']) { $pagenumber = sprintf($curpagenumtag, $pagenumber); $onclick = sprintf($data['onclick'], $numberid); $urls = "#"; if ($onclick) { $urls = 'javascript:void(0);'; } //$curpage .= "<span id=\"pagelink_{$pagenumber}\"><a href=\"{$urls}\" id=\"page_{$numberid}\" title=\"{$pagenumber}\" {$onclick} class='pages_current'>{$pagenumber}</a></span>"; $curpage .= "<span id=\"pagelink_{$pagenumber}\" class=\"page_cur\">{$pagenumber}</span>"; } else { if (1) { $url = $formatpagelink . "0"; if ($data['onclick']) { $zero = 0; $onclick = sprintf($data['onclick'], $zero); $url = 'javascript:void(0);'; } $firstlink = "<a id='firstpage_" . $zero . "' href='" . hg_build_href_link($url) . "' {$onclick} title='第一页'>{$firstpage}</a>"; $showpages_return['showfirstpage'] = $firstlink; } if (1) { $url = $formatpagelink . ($results['total_page'] - 1) * $data['perpage']; if ($data['onclick']) { $last = ($results['total_page'] - 1) * $data['perpage']; $onclick = sprintf($data['onclick'], $last); $url = 'javascript:void(0);'; } $lastlink = "<a id='lastpage_" . $last . "' href='" . hg_build_href_link($url) . "' {$onclick} title='最后一页'>" . $lastpage . "</a>"; $showpages_return['showlastpage'] = $lastlink; } $onclick = sprintf($data['onclick'], $numberid); $pagelink = $formatpagelink . $numberid; if ($onclick) { $pagelink = 'javascript:void(0);'; } $pagelink = sprintf($pagenumtag, "page_" . $numberid, hg_build_href_link($pagelink), $onclick, $pagenumber, $pagenumber); $curpage .= "<span id=\"pagelink_{$pagenumber}\">{$pagelink}</span>"; } } if ($results['current_page'] == 1) { unset($showpages_return['showfirstpage']); } else { if ($results['current_page'] == $results['total_page']) { unset($showpages_return['showlastpage']); } } $showpages_return['showpage_nums'] = $curpage; /**扩展每页条数 start**/ /****一并修改了program.class.php中: 对referto进行了urlencode处理 ***/ $changeCountConfig = array(20, 40, 60, 80, 100); $changeCountHtml = ''; foreach ($changeCountConfig as $_count) { $selected = $_count == $data['perpage'] ? 'selected' : ''; if (preg_match('/(?:\\&|\\?)count=\\d+/', $data['pagelink'])) { $dataLink = preg_replace($data['pagelink'], '/(?:\\&|\\?)(count=)\\d+/', '${1}' . $_count); } else { $dataLink = $data['pagelink'] . (substr($data['pagelink'], -1) == '&' ? '' : '&') . 'count=' . $_count; } $_count = '每页' . $_count . '条'; $changeCountHtml .= '<option value="' . $dataLink . '" ' . $selected . '>' . $_count . '</option>'; } $changeCountHtml = '<select style="float:left;vertical-align:middle;margin:0 5px;" onchange="location.href=this.value;">' . $changeCountHtml . '</select>'; /**扩展每页条数 end**/ //$showpages_return_str = '<div align="center" class="hoge_page"><span class="page_all">共' . $showpages_return['showtotal_page'] . '页/计' . $data['totalpages'] . '条</span>' . $changeCountHtml . '<span class="page_next">' . $showpages_return['showfirstpage'] . '</span>' . $showpages_return['showprepage'] . '' . $showpages_return['showpage_nums'] . '' . $showpages_return['shownextpage'] . '<span class="page_next">' . $showpages_return['showlastpage'].'</span></div>'; if ($results['total_page'] == 1) { $showpages_return_str = '<div align="center" class="hoge_page"><span class="page_all">共' . $showpages_return['showtotal_page'] . '页/计' . $data['totalpages'] . '条</span>' . $changeCountHtml . '</div>'; } elseif ($results['total_page'] != 1) { $showpages_return_str = '<div align="center" class="hoge_page"><span class="page_all">共' . $showpages_return['showtotal_page'] . '页/计' . $data['totalpages'] . '条</span>' . $changeCountHtml . '<span class="page_next">' . $showpages_return['showfirstpage'] . '</span>' . $showpages_return['showprepage'] . '' . $showpages_return['showpage_nums'] . '' . $showpages_return['shownextpage'] . '<span class="page_next">' . $showpages_return['showlastpage'] . '</span></div>'; } return $showpages_return_str; } }