function strip_query_string_of($aKeys) { $aGET = $_GET; foreach ($aKeys as $key) { if (isset($aGET[$key])) { unset($aGET[$key]); } } return add_to_query_string('', $aGET); }
public function toXhtml() { // step 1: do we have any pages to render? if ($this->totalPages < 1) { return LANG_RENDER_NO_PAGES; } // step 2: do we only have the one page to render? if ($this->totalPages == 1) { return sprintf(LANG_RENDER_SHOWING_ALL_RESULTS, $this->totalResults); } // if we get here, then we have a set of pages to render $totalPages = $this->totalPages; $startPage = 1; $endPage = $totalPages; // do we have too many pages? // we show up to ten pages at a time if ($totalPages > 10) { $startPage = $this->page - 5; if ($startPage < 1) { $startPage = 1; } $endPage = $startPage + 9; if ($endPage > $totalPages) { $endPage = $totalPages; $startPage = $endPage - 9; } } $startRecord = ($this->page - 1) * $this->resultsPerPage + 1; $endRecord = $startRecord + $this->resultsThisPage - 1; // work out our query string $baseQuery = strip_query_string_of(array($this->pageKey)); // build up the list of pages $return = sprintf(LANG_RENDER_SHOWING_RESULTS_OF, $startRecord - $endRecord, $this->totalResults) . ' ' . LANG_RENDER_PAGE_LIST; $append = false; // if we have too many pages, then add a link to the first // page in the list if ($startPage > 1) { $query = add_to_query_string($baseQuery, array($this->pageKey => 1)); $return .= "<a href=\"?{$query}\"><<</a>"; $append = true; } // build up the list of pages for ($i = $startPage; $i <= $endPage; $i++) { if ($append) { $return .= " | "; } $append = true; if ($i == $this->page) { $return .= "<span class=\"currentPage\">" . $i . "</span>"; } else { $query = add_to_query_string($baseQuery, array($this->pageKey => $i)); $return .= "<a href=\"?{$query}\">{$i}</a>"; } } // if we have too many pages, add a link to the last page // in the list if ($endPage < $totalPages) { $return .= " | "; $query = add_to_query_string($baseQuery, array($this->pageKey => $totalPages)); $return .= "<a href=\"?{$query}\">>></a>"; $append = true; } return $return; }