Имам откачени линкове от сорта на
http://сайта.ком/index.php?module=servers&type=game&game=cs1.6&page=4
и искам да ги съкратя до
http://game-stats.eu/servers_type_game_cs1.6_4
или ако имате по добра идея ,че аз друго не измислих.
Но тук идва и проблема ползвам този клас за странициране и не знам как ще стане номера.Ще може ли да ми помогнете ,че вече 2 ден се мъча с някакви вариянти и не успях
http://сайта.ком/index.php?module=servers&type=game&game=cs1.6&page=4
и искам да ги съкратя до
http://game-stats.eu/servers_type_game_cs1.6_4
или ако имате по добра идея ,че аз друго не измислих.
Но тук идва и проблема ползвам този клас за странициране и не знам как ще стане номера.Ще може ли да ми помогнете ,че вече 2 ден се мъча с някакви вариянти и не успях
PHP:
<?php
function pagination($results, $properties = array()) {
$defaultProperties = array(
'get_vars' => array(),
'per_page' => 15,
'per_side' => 4,
'get_name' => 'page'
);
foreach($defaultProperties as $name => $default) { $properties[$name] = (isset($properties[$name])) ? $properties[$name] : $default; }
foreach($properties['get_vars'] as $name => $value) {
if (isset($_GET[$name]) && $name != $properties['get_name']) {
$GETItems[] = $name.'='.$value;
}
}
$type=$_GET['type'];
//-------------------------------------------------------------------------------------------+
if($type=='all'){$l = 'http://game-stats.eu/index.php?module=servers&type='.$type.'';}
//-------------------------------------------------------------------------------------------+
if($type=='game')
{
$games=$_GET['game'];
$l = 'http://game-stats.eu/index.php?module=servers&type='.$type.'&'.$type.'='.$games.'&page=';
}
//-------------------------------------------------------------------------------------------+
if($type=='cat')
{
$cid=(int)($_GET['cid']);
$l = 'http://game-stats.eu/index.php?module=servers&type='.$type.'&'.$type.'='.$cid.'&page=';
}
//-------------------------------------------------------------------------------------------+
if($type=='map')
{
$map=$_GET['map'];
$l = 'http://game-stats.eu/index.php?module=servers&type='.$type.'&'.$type.'='.$map.'&page=';
}
//-------------------------------------------------------------------------------------------+
if($type=='who')
{
$user = $_GET['user'];
$l = 'http://game-stats.eu/index.php?module=servers&type='.$type.'&'.$type.'='.$user.'&page=';
}
//-------------------------------------------------------------------------------------------+
$totalPages = ceil($results / $properties['per_page']);
$currentPage = (isset($_GET[$properties['get_name']]) && $_GET[$properties['get_name']] > 1) ? $_GET[$properties['get_name']] : 1;
$currentPage = ($currentPage > $totalPages) ? $totalPages : $currentPage;
$previousPage = $currentPage - 1;
$nextPage = $currentPage + 1;
// calculate which pages to show
if ($totalPages <= ($properties['per_side'] * 2) + 1) {
$loopStart = 1;
$loopRange = $totalPages;
} else {
$loopStart = $currentPage - $properties['per_side'];
$loopRange = $currentPage + $properties['per_side'];
$loopStart = ($loopStart < 1) ? 1 : $loopStart;
while ($loopRange - $loopStart < $properties['per_side'] * 2) { $loopRange++; }
$loopRange = ($loopRange > $totalPages) ? $totalPages : $loopRange;
while ($loopRange - $loopStart < $properties['per_side'] * 2) { $loopStart--; }
}
// start placing data to output
$output = '';
$output .= '<div class=\'pagination\'>';
// first and previous page
if ($currentPage != 1) {
$output .= '<a href=\''.$l.'1\' class=\'active\'>първа</a>';
$output .= '<a href=\''.$l.$previousPage.'\' class=\'active\'>‹</a>';
} else {
$output .= '<span class=\'inactive\'>първа</span>';
$output .= '<span class=\'inactive\'>‹</span>';
}
/* if ($loopStart > 2) {
$output .= '<a href=\''.$l.'1\' class=\'active\'>1</a><span class=\'inactive\'>...</span>';
} */
// add the pages
for ($p = $loopStart; $p <= $loopRange; $p++) {
if ($p != $currentPage) {
$output .= '<a href=\''.$l.$p.'\' class=\'active\'>'.$p.'</a>';
} else {
$output .= '<span class=\'current\'>'.$p.'</span>';
}
}
/* if ($totalPages - $loopRange > 1) {
$output .= '<span class=\'inactive\'>...</span><a href=\''.$l.$totalPages.'\' class=\'active\'>'.$totalPages.'</a>';
} */
// next and last page
if ($currentPage != $totalPages) {
$output .= '<a href=\''.$l.$nextPage.'\' class=\'active\'>›</a>';
$output .= '<a href=\''.$l.$totalPages.'\' class=\'active\'>последна</a>';
} else {
$output .= '<span class=\'inactive\'>›</span>';
$output .= '<span class=\'inactive\'>последна</span>';
}
$output .= '</div>';
// end of output
return array(
'limit' => array(
'first' => $previousPage * $properties['per_page'],
'second' => $properties['per_page']
),
'output' => $output
);
}