|
@ -1312,7 +1312,7 @@ function buildIndex() { |
|
|
for ($page = 1; $page <= $config['max_pages']; $page++) { |
|
|
for ($page = 1; $page <= $config['max_pages']; $page++) { |
|
|
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); |
|
|
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); |
|
|
|
|
|
|
|
|
if ($config['try_smarter'] && isset($build_pages) && count($build_pages) |
|
|
if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages) |
|
|
&& !in_array($page, $build_pages) && is_file($filename)) |
|
|
&& !in_array($page, $build_pages) && is_file($filename)) |
|
|
continue; |
|
|
continue; |
|
|
$content = index($page); |
|
|
$content = index($page); |
|
@ -1360,6 +1360,9 @@ function buildIndex() { |
|
|
$jsonFilename = $board['dir'] . 'catalog.json'; |
|
|
$jsonFilename = $board['dir'] . 'catalog.json'; |
|
|
file_write($jsonFilename, $json); |
|
|
file_write($jsonFilename, $json); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($config['try_smarter']) |
|
|
|
|
|
$build_pages = array(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function buildJavascript() { |
|
|
function buildJavascript() { |
|
@ -1561,6 +1564,9 @@ function markup(&$body, $track_cites = false) { |
|
|
error($config['error']['toomanylinks']); |
|
|
error($config['error']['toomanylinks']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($config['markup_repair_tidy']) |
|
|
|
|
|
$body = str_replace(' ', ' ', $body); |
|
|
|
|
|
|
|
|
if ($config['auto_unicode']) { |
|
|
if ($config['auto_unicode']) { |
|
|
$body = unicodify($body); |
|
|
$body = unicodify($body); |
|
|
|
|
|
|
|
@ -1585,28 +1591,40 @@ function markup(&$body, $track_cites = false) { |
|
|
$skip_chars = 0; |
|
|
$skip_chars = 0; |
|
|
$body_tmp = $body; |
|
|
$body_tmp = $body; |
|
|
|
|
|
|
|
|
|
|
|
$search_cites = array(); |
|
|
|
|
|
foreach ($cites as $matches) { |
|
|
|
|
|
$search_cites[] = '`id` = ' . $matches[2][0]; |
|
|
|
|
|
} |
|
|
|
|
|
$search_cites = array_unique($search_cites); |
|
|
|
|
|
|
|
|
|
|
|
$query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . |
|
|
|
|
|
implode(' OR ', $search_cites), $board['uri'])) or error(db_error()); |
|
|
|
|
|
|
|
|
|
|
|
$cited_posts = array(); |
|
|
|
|
|
while ($cited = $query->fetch(PDO::FETCH_ASSOC)) { |
|
|
|
|
|
$cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach ($cites as $matches) { |
|
|
foreach ($cites as $matches) { |
|
|
$cite = $matches[2][0]; |
|
|
$cite = $matches[2][0]; |
|
|
$query = prepare(sprintf("SELECT `thread`,`id` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri'])); |
|
|
|
|
|
$query->bindValue(':id', $cite); |
|
|
|
|
|
$query->execute() or error(db_error($query)); |
|
|
|
|
|
|
|
|
|
|
|
// preg_match_all is not multibyte-safe |
|
|
// preg_match_all is not multibyte-safe |
|
|
foreach ($matches as &$match) { |
|
|
foreach ($matches as &$match) { |
|
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); |
|
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) { |
|
|
if (isset($cited_posts[$cite])) { |
|
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' . |
|
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' . |
|
|
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' . |
|
|
$config['root'] . $board['dir'] . $config['dir']['res'] . |
|
|
'>>' . $cite . |
|
|
($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' . |
|
|
'</a>'; |
|
|
'>>' . $cite . |
|
|
|
|
|
'</a>'; |
|
|
|
|
|
|
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[3][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[3][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]); |
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]); |
|
|
|
|
|
|
|
|
if ($track_cites && $config['track_cites']) |
|
|
if ($track_cites && $config['track_cites']) |
|
|
$tracked_cites[] = array($board['uri'], $post['id']); |
|
|
$tracked_cites[] = array($board['uri'], $cite); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1620,6 +1638,66 @@ function markup(&$body, $track_cites = false) { |
|
|
$skip_chars = 0; |
|
|
$skip_chars = 0; |
|
|
$body_tmp = $body; |
|
|
$body_tmp = $body; |
|
|
|
|
|
|
|
|
|
|
|
if (isset($cited_posts)) { |
|
|
|
|
|
// Carry found posts from local board >>X links |
|
|
|
|
|
foreach ($cited_posts as $cite => $thread) { |
|
|
|
|
|
$cited_posts[$cite] = $config['root'] . $board['dir'] . $config['dir']['res'] . |
|
|
|
|
|
($thread ? $thread : $cite) . '.html#' . $cite; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$cited_posts = array( |
|
|
|
|
|
$board['uri'] => $cited_posts |
|
|
|
|
|
); |
|
|
|
|
|
} else |
|
|
|
|
|
$cited_posts = array(); |
|
|
|
|
|
|
|
|
|
|
|
$crossboard_indexes = array(); |
|
|
|
|
|
$search_cites_boards = array(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($cites as $matches) { |
|
|
|
|
|
$_board = $matches[2][0]; |
|
|
|
|
|
$cite = @$matches[3][0]; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($search_cites_boards[$_board])) |
|
|
|
|
|
$search_cites_boards[$_board] = array(); |
|
|
|
|
|
$search_cites_boards[$_board][] = $cite; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$tmp_board = $board['uri']; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($search_cites_boards as $_board => $search_cites) { |
|
|
|
|
|
$clauses = array(); |
|
|
|
|
|
foreach ($search_cites as $cite) { |
|
|
|
|
|
if (!$cite || isset($cited_posts[$_board][$cite])) |
|
|
|
|
|
continue; |
|
|
|
|
|
$clauses[] = '`id` = ' . $cite; |
|
|
|
|
|
} |
|
|
|
|
|
$clauses = array_unique($clauses); |
|
|
|
|
|
|
|
|
|
|
|
if ($board['uri'] != $_board) { |
|
|
|
|
|
if (!openBoard($_board)) |
|
|
|
|
|
continue; // Unknown board |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($clauses)) { |
|
|
|
|
|
$cited_posts[$_board] = array(); |
|
|
|
|
|
|
|
|
|
|
|
$query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . |
|
|
|
|
|
implode(' OR ', $clauses), $board['uri'])) or error(db_error()); |
|
|
|
|
|
|
|
|
|
|
|
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) { |
|
|
|
|
|
$cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] . |
|
|
|
|
|
($cite['thread'] ? $cite['thread'] : $cite['id']) . '.html#' . $cite['id']; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Restore old board |
|
|
|
|
|
if ($board['uri'] != $tmp_board) |
|
|
|
|
|
openBoard($tmp_board); |
|
|
|
|
|
|
|
|
foreach ($cites as $matches) { |
|
|
foreach ($cites as $matches) { |
|
|
$_board = $matches[2][0]; |
|
|
$_board = $matches[2][0]; |
|
|
$cite = @$matches[3][0]; |
|
|
$cite = @$matches[3][0]; |
|
@ -1629,43 +1707,35 @@ function markup(&$body, $track_cites = false) { |
|
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); |
|
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Temporarily store board information because it will be overwritten |
|
|
if ($cite) { |
|
|
$tmp_board = $board['uri']; |
|
|
if (isset($cited_posts[$_board][$cite])) { |
|
|
|
|
|
$link = $cited_posts[$_board][$cite]; |
|
|
// Check if the board exists, and load settings |
|
|
|
|
|
if (openBoard($_board)) { |
|
|
$replacement = '<a ' . |
|
|
if ($cite) { |
|
|
($_board == $board['uri'] ? |
|
|
$query = prepare(sprintf("SELECT `thread`,`id` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri'])); |
|
|
'onclick="highlightReply(\''.$cite.'\');" ' |
|
|
$query->bindValue(':id', $cite); |
|
|
: '') . 'href="' . $link . '">' . |
|
|
$query->execute() or error(db_error($query)); |
|
|
'>>>/' . $_board . '/' . $cite . |
|
|
|
|
|
'</a>'; |
|
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) { |
|
|
|
|
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' . |
|
|
|
|
|
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' . |
|
|
|
|
|
'>>>/' . $_board . '/' . $cite . |
|
|
|
|
|
'</a>'; |
|
|
|
|
|
|
|
|
|
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
|
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); |
|
|
|
|
|
|
|
|
|
|
|
if ($track_cites && $config['track_cites']) |
|
|
|
|
|
$tracked_cites[] = array($board['uri'], $post['id']); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
$replacement = '<a href="' . |
|
|
|
|
|
$config['root'] . $board['dir'] . $config['file_index'] . '">' . |
|
|
|
|
|
'>>>/' . $_board . '/' . |
|
|
|
|
|
'</a>'; |
|
|
|
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); |
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); |
|
|
|
|
|
|
|
|
|
|
|
if ($track_cites && $config['track_cites']) |
|
|
|
|
|
$tracked_cites[] = array($_board, $cite); |
|
|
} |
|
|
} |
|
|
|
|
|
} elseif(isset($crossboard_indexes[$_board])) { |
|
|
|
|
|
$replacement = '<a href="' . $crossboard_indexes[$_board] . '">' . |
|
|
|
|
|
'>>>/' . $_board . '/' . |
|
|
|
|
|
'</a>'; |
|
|
|
|
|
$body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); |
|
|
|
|
|
$skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Restore main board settings |
|
|
|
|
|
openBoard($tmp_board); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR); |
|
|
|
|
|
|
|
|
$body = preg_replace("/^\s*>.*$/m", '<span class="quote">$0</span>', $body); |
|
|
$body = preg_replace("/^\s*>.*$/m", '<span class="quote">$0</span>', $body); |
|
|
|
|
|
|
|
|
if ($config['strip_superfluous_returns']) |
|
|
if ($config['strip_superfluous_returns']) |
|
@ -1673,6 +1743,24 @@ function markup(&$body, $track_cites = false) { |
|
|
|
|
|
|
|
|
$body = preg_replace("/\n/", '<br/>', $body); |
|
|
$body = preg_replace("/\n/", '<br/>', $body); |
|
|
|
|
|
|
|
|
|
|
|
if ($config['markup_repair_tidy']) { |
|
|
|
|
|
$tidy = new tidy(); |
|
|
|
|
|
$body = $tidy->repairString($body, array( |
|
|
|
|
|
'doctype' => 'omit', |
|
|
|
|
|
'bare' => true, |
|
|
|
|
|
'literal-attributes' => true, |
|
|
|
|
|
'indent' => false, |
|
|
|
|
|
'show-body-only' => true, |
|
|
|
|
|
'wrap' => 0, |
|
|
|
|
|
'output-bom' => false, |
|
|
|
|
|
'output-html' => true, |
|
|
|
|
|
'newline' => 'LF', |
|
|
|
|
|
'quiet' => true, |
|
|
|
|
|
|
|
|
|
|
|
), 'utf8'); |
|
|
|
|
|
$body = str_replace("\n", '', $body); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $tracked_cites; |
|
|
return $tracked_cites; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -2025,7 +2113,7 @@ function rDNS($ip_addr) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($config['cache']['enabled']) |
|
|
if ($config['cache']['enabled']) |
|
|
cache::set('rdns_' . $ip_addr, $host, 3600); |
|
|
cache::set('rdns_' . $ip_addr, $host); |
|
|
|
|
|
|
|
|
return $host; |
|
|
return $host; |
|
|
} |
|
|
} |
|
@ -2050,7 +2138,7 @@ function DNS($host) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($config['cache']['enabled']) |
|
|
if ($config['cache']['enabled']) |
|
|
cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?', 3600); |
|
|
cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?'); |
|
|
|
|
|
|
|
|
return $ip_addr; |
|
|
return $ip_addr; |
|
|
} |
|
|
} |
|
|