ShieldofChaos
07-07-2013, 06:38 AM
Hey everyone,
I am stressing out here trying to fix the pagination. Firstly, I just learn some basics of PHP recently so please go easy on me. So here is my problem,
I am currently using CuteNews 1.5.3, and everything works okay so far except for the pagination where it is giving weird errors. I e-mailed the CuteNews team but they haven't got back to me for a long time so I decided to come here and post for help.
Take a look at this example that outline the problem,
[Prev] [1] [2] [3] [4] [Next]
At page 2 of the news, the URL for page 2 is site.com/news.php?start_from=5. If I click on the [PREV] or [1], the URL will remain as site.com/news.php?start_from=5. However [3], [4] and [Next] work perfectly fine.
If I go to page 3 of the news, the URL for page 3 is site.com/news.php?start_from=10. The [PREV] on this page works fine (it allows me to return to page 2) but the [1] URL will remain as site.com/news.php?start_from=10.
This situation goes on for the rest of the page. To sum it up, basically the [1] URL will always be the same as the URL you are currently at. And the [PREV] URL will be the same as the URL you are currently at only if you are at page 2. The ideal URL that I should be getting when I am clicking on [1] or [PREV] will be site.com/news.php?start_from=0.
This is the PHP code that affects the pagination,
// Triggerred by $config_disable_pagination = TRUE
if ($config_disable_pagination == 0)
{
// << Previous & Next >>
$prev_next_msg = $template_prev_next;
//----------------------------------
// Previous link
//----------------------------------
if ($start_from)
{
$prev = $start_from - $number;
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($prev, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_plink', $URL);
$prev_next_msg = preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si", '<a href="'.$URL.'">\\1</a> ', $prev_next_msg);
}
else
{
$prev_next_msg = preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si", "\\1", $prev_next_msg);
$no_prev = true;
}
//----------------------------------
// Pages
//----------------------------------
$pages = '';
if ($number)
{
$pages_count = ceil($count_all / $number);
$pages_start_from = 0;
for($j=1; $j<= $pages_count; $j++)
{
if ( $pages_start_from != $start_from)
{
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($pages_start_from, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_link', $URL);
$pages .= '<a href="'.$URL.'">'.$j.'</a> ';
}
else $pages .= '<strong>'.$j.'</strong> ';
$pages_start_from += $number;
}
}
else
{
$no_next = true;
$no_prev = true;
}
$prev_next_msg = str_replace("{pages}", $pages, $prev_next_msg);
//----------------------------------
// Next link (typo here ... typo there... typos everywhere !)
//----------------------------------
if ($number < $count_all and $i < $count_all)
{
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($i, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_nlink', $URL);
$prev_next_msg = preg_replace("'\[next-link\](.*?)\[/next-link\]'si", '<a href="'.$URL.'">\\1</a>', $prev_next_msg);
}
else
{
$prev_next_msg = preg_replace("'\[next-link\](.*?)\[/next-link\]'si", "\\1", $prev_next_msg);
$no_next = TRUE;
}
if (!$no_prev or !$no_next) echo $prev_next_msg;
}
This is the PHP code that outputs the pagination to my HTML page,
<?php
$number="5";
include("/site/show_news.php");
?>
Does anyone know how to solve it? Thanks!
ADDITIONAL INFORMATION
This is the PHP that forms the URI of the pagination, hope it helps.
// make full URI (left & right parts)
function build_uri($left, $right, $html = 1)
{
global $QUERY_STRING;
$URI = $DDR = array();
list ($left, $adds) = explode(':', $left);
$ix = 0;
$ex = spsep($left);
$uq = spsep($adds);
// Main parameters GET
if ($left && is_array($ex)) foreach ($ex as $v)
{
if (isset($right[$ix]) && $right[$ix]) $URI[ $v ] = $right[$ix];
$ix++;
}
// Enum not present, but in GLOBALS is set
if ($adds && is_array($uq))
foreach ($uq as $v)
if (isset($GLOBALS[$v]) && $GLOBALS[$v]) $URI[ $v ] = $GLOBALS[$v];
// Import at url $QUERY_STRING
$QUERY_STRING = str_replace('&', '&', $QUERY_STRING);
foreach ( spsep($QUERY_STRING, '&') as $qs )
{
list($k, $v) = explode('=', $qs, 2);
if ($k && $v && !isset($URI[$k])) $URI[$k] = $v;
}
// Encode new query
foreach ($URI as $i => $v)
{
$DDR[] = urlencode($i)."=".str_replace('%2C', ',', urlencode($v));
}
$DDU = implode(($html?'&':'&'), $DDR);
if ($DDU == false) return '?c';
// Return true link
return '?'.$DDU;
}
I am stressing out here trying to fix the pagination. Firstly, I just learn some basics of PHP recently so please go easy on me. So here is my problem,
I am currently using CuteNews 1.5.3, and everything works okay so far except for the pagination where it is giving weird errors. I e-mailed the CuteNews team but they haven't got back to me for a long time so I decided to come here and post for help.
Take a look at this example that outline the problem,
[Prev] [1] [2] [3] [4] [Next]
At page 2 of the news, the URL for page 2 is site.com/news.php?start_from=5. If I click on the [PREV] or [1], the URL will remain as site.com/news.php?start_from=5. However [3], [4] and [Next] work perfectly fine.
If I go to page 3 of the news, the URL for page 3 is site.com/news.php?start_from=10. The [PREV] on this page works fine (it allows me to return to page 2) but the [1] URL will remain as site.com/news.php?start_from=10.
This situation goes on for the rest of the page. To sum it up, basically the [1] URL will always be the same as the URL you are currently at. And the [PREV] URL will be the same as the URL you are currently at only if you are at page 2. The ideal URL that I should be getting when I am clicking on [1] or [PREV] will be site.com/news.php?start_from=0.
This is the PHP code that affects the pagination,
// Triggerred by $config_disable_pagination = TRUE
if ($config_disable_pagination == 0)
{
// << Previous & Next >>
$prev_next_msg = $template_prev_next;
//----------------------------------
// Previous link
//----------------------------------
if ($start_from)
{
$prev = $start_from - $number;
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($prev, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_plink', $URL);
$prev_next_msg = preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si", '<a href="'.$URL.'">\\1</a> ', $prev_next_msg);
}
else
{
$prev_next_msg = preg_replace("'\[prev-link\](.*?)\[/prev-link\]'si", "\\1", $prev_next_msg);
$no_prev = true;
}
//----------------------------------
// Pages
//----------------------------------
$pages = '';
if ($number)
{
$pages_count = ceil($count_all / $number);
$pages_start_from = 0;
for($j=1; $j<= $pages_count; $j++)
{
if ( $pages_start_from != $start_from)
{
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($pages_start_from, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_link', $URL);
$pages .= '<a href="'.$URL.'">'.$j.'</a> ';
}
else $pages .= '<strong>'.$j.'</strong> ';
$pages_start_from += $number;
}
}
else
{
$no_next = true;
$no_prev = true;
}
$prev_next_msg = str_replace("{pages}", $pages, $prev_next_msg);
//----------------------------------
// Next link (typo here ... typo there... typos everywhere !)
//----------------------------------
if ($number < $count_all and $i < $count_all)
{
$URL = $PHP_SELF . build_uri('start_from,ucat,archive,subaction,id:comm_start_from', array($i, $ucat, $url_archive, $subaction, $id));
$URL = hook('rewrite_active_news_nlink', $URL);
$prev_next_msg = preg_replace("'\[next-link\](.*?)\[/next-link\]'si", '<a href="'.$URL.'">\\1</a>', $prev_next_msg);
}
else
{
$prev_next_msg = preg_replace("'\[next-link\](.*?)\[/next-link\]'si", "\\1", $prev_next_msg);
$no_next = TRUE;
}
if (!$no_prev or !$no_next) echo $prev_next_msg;
}
This is the PHP code that outputs the pagination to my HTML page,
<?php
$number="5";
include("/site/show_news.php");
?>
Does anyone know how to solve it? Thanks!
ADDITIONAL INFORMATION
This is the PHP that forms the URI of the pagination, hope it helps.
// make full URI (left & right parts)
function build_uri($left, $right, $html = 1)
{
global $QUERY_STRING;
$URI = $DDR = array();
list ($left, $adds) = explode(':', $left);
$ix = 0;
$ex = spsep($left);
$uq = spsep($adds);
// Main parameters GET
if ($left && is_array($ex)) foreach ($ex as $v)
{
if (isset($right[$ix]) && $right[$ix]) $URI[ $v ] = $right[$ix];
$ix++;
}
// Enum not present, but in GLOBALS is set
if ($adds && is_array($uq))
foreach ($uq as $v)
if (isset($GLOBALS[$v]) && $GLOBALS[$v]) $URI[ $v ] = $GLOBALS[$v];
// Import at url $QUERY_STRING
$QUERY_STRING = str_replace('&', '&', $QUERY_STRING);
foreach ( spsep($QUERY_STRING, '&') as $qs )
{
list($k, $v) = explode('=', $qs, 2);
if ($k && $v && !isset($URI[$k])) $URI[$k] = $v;
}
// Encode new query
foreach ($URI as $i => $v)
{
$DDR[] = urlencode($i)."=".str_replace('%2C', ',', urlencode($v));
}
$DDU = implode(($html?'&':'&'), $DDR);
if ($DDU == false) return '?c';
// Return true link
return '?'.$DDU;
}