Quick and dirty fix for - Last 50 post page links - Might not be 100% but some testing will determine that

Also includes "Small fix to noko50"
This commit is contained in:
PupperWoff 2017-05-10 00:48:40 +02:00 committed by discomrade
parent 9ad8b61d78
commit f34d25caf2

View File

@ -446,8 +446,33 @@ class Thread {
$hasnoko50 = $this->postCount() >= $config['noko50_min'];
/* Fix >>## post cites for Last 50 Posts pages:
* - Get minimum post_no in thread, go through all post.body and use regex on links
* - if link is to a post within the thread and shown, alter it to CURRENT_URL#POST_NR
*/
if($isnoko50)
{
$thread_num = $this->posts[0]->id;
$min_post_num = $this->posts[1]->id;
for($i=1; $i<count($this->posts); $i++) {
// Find all post links
preg_match_all('/(href="\/' . $board['uri'] . '\/res\/)([\d]*)(.html#)([\d]*)(")/', $this->posts[$i]->body, $results, PREG_PATTERN_ORDER);
// Build list of links to change
$patterns = array();
$changes = array();
foreach($results[4] as $key => $num) {
if(($num >= $min_post_num) || ($num == $thread_num)) {
$patterns[] = '/' . str_replace('/', '\/', preg_quote($results[0][$key])) . '/';
$changes[] = $results[1][$key] . sprintf($config['file_page50'], $results[2][$key]) . "#" . $results[4][$key] . '"';
}
}
// Update Links
$this->posts[$i]->body = preg_replace($patterns, $changes, $this->posts[$i]->body);
}
}
event('show-thread', $this);
$file = ($index && $config['file_board']) ? 'post_thread_fileboard.html' : 'post_thread.html';
$built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod));