<?php
class html_parser {
public function html_parser() {
}
public static function make_pageination($entry_count, $onclick, $current_page = 1, $entries_per_page = 10) {
$max_pages = ceil($entry_count / $entries_per_page);
if($max_pages == 1) return array("content" => '', "mysql" => "");
$ret_entry = '<div class="pagination">';
if($current_page <= 5) $startpage = 1;
else {
$startpage = (int)$current_page-3;
$js_string = str_replace("###page###","1", $onclick);
$link_to_one = '<span class="nav_entry" onClick="' . $js_string . '">1</span>
<span class="nav_points">...</span>';
}
if($current_page > 1) {
$js_string = str_replace("###page###",$current_page-1, $onclick);
$backlink = '<span class="nav_entry" onClick="' . $js_string . '">Zurück</span>';
}
if(($max_pages - 3) <= $current_page) $end_page = $max_pages;
else {
$end_page = $current_page + 3;
$js_string = str_replace("###page###",$max_pages, $onclick);
$link_to_last = '<span class="nav_points">...</span><span class="nav_entry" onClick="' . $js_string . '">' . $max_pages . '</span>';
}
if($current_page < $max_pages) {
$js_string = str_replace("###page###",$current_page+1, $onclick);
$forwardlink = '<span class="nav_entry" onClick="' . $js_string . '">Weiter</span>';
}
$ret_entry .= $backlink . $link_to_one;
for($i = $startpage; $i<=$end_page;$i++) {
$js_string = str_replace("###page###",($i), $onclick);
$ret_entry .= '<span onclick="' . $js_string . '"';
if($i == $current_page) {
$ret_entry .= ' class="nav_entry_current"';
}
else {
$ret_entry .= ' class="nav_entry"';
}
$ret_entry .= '>'.($i) .'</span>';
}
$ret_entry .= $link_to_last . $forwardlink;
$ret_entry .= '</div>';
return $ret_entry;
}