1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-30 18:24:29 +01:00

Merge remote-tracking branch 'upstream/master' (vichan-devel)

This commit is contained in:
ctrlcctrlv 2013-08-29 13:43:50 +00:00
commit 2804c6b775
8 changed files with 185 additions and 66 deletions

View File

@ -60,10 +60,8 @@ class Cache {
break; break;
} }
// debug if ($config['debug'])
if ($data !== false && $config['debug']) { $debug['cached'][] = $key . ($data === false ? ' (miss)' : ' (hit)');
$debug['cached'][] = $key;
}
return $data; return $data;
} }
@ -95,10 +93,13 @@ class Cache {
case 'php': case 'php':
self::$cache[$key] = $value; self::$cache[$key] = $value;
break; break;
} }
if ($config['debug'])
$debug['cached'][] = $key . ' (set)';
} }
public static function delete($key) { public static function delete($key) {
global $config; global $config, $debug;
$key = $config['cache']['prefix'] . $key; $key = $config['cache']['prefix'] . $key;
@ -119,6 +120,9 @@ class Cache {
unset(self::$cache[$key]); unset(self::$cache[$key]);
break; break;
} }
if ($config['debug'])
$debug['cached'][] = $key . ' (deleted)';
} }
public static function flush() { public static function flush() {
global $config; global $config;

View File

@ -464,10 +464,10 @@
*/ */
// "Wiki" markup syntax ($config['wiki_markup'] in pervious versions): // "Wiki" markup syntax ($config['wiki_markup'] in pervious versions):
$config['markup'][] = array("/'''([^<]+?)'''/", "<strong>\$1</strong>"); $config['markup'][] = array("/'''(.+?)'''/", "<strong>\$1</strong>");
$config['markup'][] = array("/''([^<]+?)''/", "<em>\$1</em>"); $config['markup'][] = array("/''(.+?)''/", "<em>\$1</em>");
$config['markup'][] = array("/\*\*([^<]+?)\*\*/", "<span class=\"spoiler\">\$1</span>"); $config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = array("/^[ |\t]*==([^<]+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>"); $config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>");
// Highlight PHP code wrapped in <code> tags (PHP 5.3+) // Highlight PHP code wrapped in <code> tags (PHP 5.3+)
// $config['markup'][] = array( // $config['markup'][] = array(
@ -477,6 +477,16 @@
// } // }
// ); // );
// Repair markup with HTML Tidy. This may be slower, but it solves nesting mistakes. Tinyboad, at the
// time of writing this, can not prevent out-of-order markup tags (eg. "**''test**'') without help from
// HTML Tidy.
$config['markup_repair_tidy'] = false;
// Always regenerate markup. This isn't recommended and should only be used for debugging; by default,
// Tinyboard only parses post markup when it needs to, and keeps post-markup HTML in the database. This
// will significantly impact performance when enabled.
$config['always_regenerate_markup'] = false;
/* /*
* ==================== * ====================
* Image settings * Image settings
@ -606,7 +616,7 @@
// Display the aspect ratio of uploaded files. // Display the aspect ratio of uploaded files.
$config['show_ratio'] = false; $config['show_ratio'] = false;
// Display the file's original filename. // Display the file's original filename.
$config['show_filename']= true; $config['show_filename'] = true;
// Display image identification links using regex.info/exif, TinEye and Google Images. // Display image identification links using regex.info/exif, TinEye and Google Images.
$config['image_identification'] = false; $config['image_identification'] = false;

View File

@ -330,6 +330,11 @@ class Post {
$this->modifiers = extract_modifiers($this->body_nomarkup); $this->modifiers = extract_modifiers($this->body_nomarkup);
if ($config['always_regenerate_markup']) {
$this->body = $this->body_nomarkup;
markup($this->body);
}
if ($this->mod) if ($this->mod)
// Fix internal links // Fix internal links
// Very complicated regex // Very complicated regex
@ -430,6 +435,11 @@ class Thread {
$this->modifiers = extract_modifiers($this->body_nomarkup); $this->modifiers = extract_modifiers($this->body_nomarkup);
if ($config['always_regenerate_markup']) {
$this->body = $this->body_nomarkup;
markup($this->body);
}
if ($this->mod) if ($this->mod)
// Fix internal links // Fix internal links
// Very complicated regex // Very complicated regex

View File

@ -9,6 +9,8 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
exit; exit;
} }
$microtime_start = microtime(true);
require_once 'inc/display.php'; require_once 'inc/display.php';
require_once 'inc/template.php'; require_once 'inc/template.php';
require_once 'inc/database.php'; require_once 'inc/database.php';
@ -24,7 +26,7 @@ mb_internal_encoding('UTF-8');
loadConfig(); loadConfig();
function loadConfig() { function loadConfig() {
global $board, $config, $__ip, $debug, $__version; global $board, $config, $__ip, $debug, $__version, $microtime_start;
$error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet'; $error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
@ -82,7 +84,8 @@ function loadConfig() {
if ($config['debug']) { if ($config['debug']) {
if (!isset($debug)) { if (!isset($debug)) {
$debug = array('sql' => array(), 'exec' => array(), 'purge' => array(), 'cached' => array(), 'write' => array()); $debug = array('sql' => array(), 'exec' => array(), 'purge' => array(), 'cached' => array(), 'write' => array());
$debug['start'] = microtime(true); $debug['start'] = $microtime_start;
$debug['start_debug'] = microtime(true);;
} }
} }
@ -647,7 +650,7 @@ function checkBan($board = 0) {
if (event('check-ban', $board)) if (event('check-ban', $board))
return true; return true;
$query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1"); $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board); $query->bindValue(':board', $board);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
@ -1309,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);
@ -1357,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() {
@ -1557,6 +1563,9 @@ function markup(&$body, $track_cites = false) {
if ($num_links > $config['max_links']) if ($num_links > $config['max_links'])
error($config['error']['toomanylinks']); error($config['error']['toomanylinks']);
} }
if ($config['markup_repair_tidy'])
$body = str_replace(' ', ' &nbsp;', $body);
if ($config['auto_unicode']) { if ($config['auto_unicode']) {
$body = unicodify($body); $body = unicodify($body);
@ -1581,29 +1590,41 @@ 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'] .
'&gt;&gt;' . $cite . ($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' .
'</a>'; '&gt;&gt;' . $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);
} }
} }
} }
@ -1616,6 +1637,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];
@ -1626,42 +1707,34 @@ 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];
$replacement = '<a ' .
($_board == $board['uri'] ?
'onclick="highlightReply(\''.$cite.'\');" '
: '') . 'href="' . $link . '">' .
'&gt;&gt;&gt;/' . $_board . '/' . $cite .
'</a>';
// Check if the board exists, and load settings
if (openBoard($_board)) {
if ($cite) {
$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));
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 . '">' .
'&gt;&gt;&gt;/' . $_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'] . '">' .
'&gt;&gt;&gt;/' . $_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]);
}
}
// Restore main board settings if ($track_cites && $config['track_cites'])
openBoard($tmp_board); $tracked_cites[] = array($_board, $cite);
}
} elseif(isset($crossboard_indexes[$_board])) {
$replacement = '<a href="' . $crossboard_indexes[$_board] . '">' .
'&gt;&gt;&gt;/' . $_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]);
}
} }
} }
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
$body = preg_replace("/^\s*&gt;.*$/m", '<span class="quote">$0</span>', $body); $body = preg_replace("/^\s*&gt;.*$/m", '<span class="quote">$0</span>', $body);
@ -1669,7 +1742,25 @@ function markup(&$body, $track_cites = false) {
$body = preg_replace('/\s+$/', '', $body); $body = preg_replace('/\s+$/', '', $body);
$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;
} }
@ -2022,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;
} }
@ -2047,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;
} }

View File

@ -35,7 +35,7 @@ function load_twig() {
} }
function Element($templateFile, array $options) { function Element($templateFile, array $options) {
global $config, $debug, $twig; global $config, $debug, $twig, $build_pages;
if (!$twig) if (!$twig)
load_twig(); load_twig();
@ -47,8 +47,12 @@ function Element($templateFile, array $options) {
if (isset($options['body']) && $config['debug']) { if (isset($options['body']) && $config['debug']) {
if (isset($debug['start'])) { if (isset($debug['start'])) {
$debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms'; $debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms';
$debug['time (initialization)'] = '~' . round(($debug['start_debug'] - $debug['start']) * 1000, 2) . 'ms';
unset($debug['start']); unset($debug['start']);
unset($debug['start_debug']);
} }
if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages))
$debug['build_pages'] = $build_pages;
$debug['included'] = get_included_files(); $debug['included'] = get_included_files();
$debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; $debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB';
$options['body'] .= $options['body'] .=

View File

@ -383,6 +383,7 @@ if (file_exists($config['has_installed'])) {
} }
case 'v0.9.6-dev-13': case 'v0.9.6-dev-13':
query("ALTER TABLE ``antispam`` ADD INDEX `expires` (`expires`)") or error(db_error()); query("ALTER TABLE ``antispam`` ADD INDEX `expires` (`expires`)") or error(db_error());
case 'v0.9.6-dev-14':
case false: case false:
// Update version number // Update version number
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);

View File

@ -684,15 +684,14 @@ if (isset($_POST['delete'])) {
incrementSpamHash($post['antispam_hash']); incrementSpamHash($post['antispam_hash']);
} }
if (isset($post['tracked_cites'])) { if (isset($post['tracked_cites']) && !empty($post['tracked_cites'])) {
$insert_rows = array();
foreach ($post['tracked_cites'] as $cite) { foreach ($post['tracked_cites'] as $cite) {
$query = prepare('INSERT INTO ``cites`` VALUES (:board, :post, :target_board, :target)'); $insert_rows[] = '(' .
$query->bindValue(':board', $board['uri']); $pdo->quote($board['uri']) . ', ' . (int)$id . ', ' .
$query->bindValue(':post', $id, PDO::PARAM_INT); $pdo->quote($cite[0]) . ', ' . (int)$cite[1] . ')';
$query->bindValue(':target_board',$cite[0]);
$query->bindValue(':target', $cite[1], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
} }
query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error());;
} }
if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) { if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) {

View File

@ -29,6 +29,6 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
KEY `thread_id` (`thread`,`id`), KEY `thread_id` (`thread`,`id`),
KEY `time` (`time`), KEY `time` (`time`),
FULLTEXT KEY `body` (`body`), FULLTEXT KEY `body` (`body`),
KEY `ip` (`ip`), KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ; ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;