mirror of
https://github.com/Circlepuller/Tinyboard.git
synced 2025-01-16 21:08:30 +01:00
Merge pull request #11 from perdedora/minify
Fix minifyjs, thanks @perdedora
This commit is contained in:
commit
b8f061816e
@ -64,7 +64,7 @@ function loadConfig() {
|
||||
}
|
||||
|
||||
|
||||
if (isset($config['cache_config']) &&
|
||||
if (isset($config['cache_config']) &&
|
||||
$config['cache_config'] &&
|
||||
$config = Cache::get('config_' . $boardsuffix ) ) {
|
||||
$events = Cache::get('events_' . $boardsuffix );
|
||||
@ -83,7 +83,7 @@ function loadConfig() {
|
||||
else {
|
||||
$config = array();
|
||||
|
||||
reset_events();
|
||||
reset_events();
|
||||
|
||||
$arrays = array(
|
||||
'db',
|
||||
@ -309,7 +309,7 @@ function loadConfig() {
|
||||
|
||||
if (is_array($config['anonymous']))
|
||||
$config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])];
|
||||
|
||||
|
||||
if ($config['debug']) {
|
||||
if (!isset($debug)) {
|
||||
$debug = array(
|
||||
@ -349,7 +349,7 @@ function basic_error_function_because_the_other_isnt_loaded_yet($message, $prior
|
||||
'<p class="c">This alternative error page is being displayed because the other couldn\'t be found or hasn\'t loaded yet.</p></body></html>');
|
||||
}
|
||||
|
||||
function fatal_error_handler() {
|
||||
function fatal_error_handler() {
|
||||
if ($error = error_get_last()) {
|
||||
if ($error['type'] === E_ERROR) {
|
||||
if (function_exists('error')) {
|
||||
@ -390,7 +390,7 @@ function define_groups() {
|
||||
define($group_name, $group_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ksort($config['mod']['groups']);
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ function rebuildThemes($action, $boardname = false) {
|
||||
$config = $_config;
|
||||
$board = $_board;
|
||||
|
||||
// Reload the locale
|
||||
// Reload the locale
|
||||
if ($config['locale'] != $current_locale) {
|
||||
$current_locale = $config['locale'];
|
||||
init_locale($config['locale']);
|
||||
@ -445,7 +445,7 @@ function rebuildThemes($action, $boardname = false) {
|
||||
$config = $_config;
|
||||
$board = $_board;
|
||||
|
||||
// Reload the locale
|
||||
// Reload the locale
|
||||
if ($config['locale'] != $current_locale) {
|
||||
$current_locale = $config['locale'];
|
||||
init_locale($config['locale']);
|
||||
@ -593,7 +593,7 @@ function purge($uri) {
|
||||
global $config, $debug;
|
||||
|
||||
// Fix for Unicode
|
||||
$uri = rawurlencode($uri);
|
||||
$uri = rawurlencode($uri);
|
||||
|
||||
$noescape = '/!~*()+:';
|
||||
$noescape = preg_split('//', $noescape);
|
||||
@ -791,7 +791,7 @@ function listBoards($just_uri = false) {
|
||||
$boards[] = $board;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($config['cache']['enabled'])
|
||||
cache::set($cache_name, $boards);
|
||||
|
||||
@ -857,10 +857,10 @@ function displayBan($ban) {
|
||||
$post = new Thread($ban['post'], null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$denied_appeals = array();
|
||||
$pending_appeal = false;
|
||||
|
||||
|
||||
if ($config['ban_appeals']) {
|
||||
$query = query('SELECT `time`, `denied` FROM ``ban_appeals`` WHERE `ban_id` = ' . (int)$ban['id']) or error(db_error());
|
||||
while ($ban_appeal = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
@ -871,7 +871,7 @@ function displayBan($ban) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Show banned page and exit
|
||||
die(
|
||||
Element('page.html', array(
|
||||
@ -897,7 +897,7 @@ function checkBan($board = false) {
|
||||
if (!isset($_SERVER['REMOTE_ADDR'])) {
|
||||
// Server misconfiguration
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event('check-ban', $board))
|
||||
return true;
|
||||
@ -912,7 +912,7 @@ function checkBan($board = false) {
|
||||
|
||||
foreach ($ips as $ip) {
|
||||
$bans = Bans::find($ip, $board, $config['show_modname']);
|
||||
|
||||
|
||||
foreach ($bans as &$ban) {
|
||||
if ($ban['expires'] && $ban['expires'] < time()) {
|
||||
Bans::delete($ban['id']);
|
||||
@ -941,9 +941,9 @@ function checkBan($board = false) {
|
||||
if (time() - $last_time_purged < $config['purge_bans'] )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Bans::purge();
|
||||
|
||||
|
||||
if ($config['cache']['enabled'])
|
||||
cache::set('purged_bans_last', time());
|
||||
}
|
||||
@ -1000,7 +1000,7 @@ function threadExists($id) {
|
||||
|
||||
function insertFloodPost(array $post) {
|
||||
global $board;
|
||||
|
||||
|
||||
$query = prepare('INSERT INTO ``flood`` VALUES (NULL, :ip, :board, :time, :posthash, :filehash, :isreply)');
|
||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
@ -1041,7 +1041,7 @@ function post(array $post) {
|
||||
$query->bindValue(':body', $post['body']);
|
||||
$query->bindValue(':body_nomarkup', $post['body_nomarkup']);
|
||||
$query->bindValue(':time', isset($post['time']) ? $post['time'] : time(), PDO::PARAM_INT);
|
||||
$query->bindValue(':password', $post['password']);
|
||||
$query->bindValue(':password', $post['password']);
|
||||
$query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
if ($post['op'] && $post['mod'] && isset($post['sticky']) && $post['sticky']) {
|
||||
@ -1269,7 +1269,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
||||
$query = prepare('DELETE FROM ``cites`` WHERE (`target_board` = :board AND (`target` = ' . implode(' OR `target` = ', $ids) . ')) OR (`board` = :board AND (`post` = ' . implode(' OR `post` = ', $ids) . '))');
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
if ($config['anti_bump_flood']) {
|
||||
$query = prepare(sprintf("SELECT `time` FROM ``posts_%s`` WHERE (`thread` = :thread OR `id` = :thread) AND `sage` = 0 ORDER BY `time` DESC LIMIT 1", $board['uri']));
|
||||
$query->bindValue(':thread', $thread_id);
|
||||
@ -1281,7 +1281,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
||||
$query->bindValue(':thread', $thread_id);
|
||||
$query->execute() or error(db_error($query));
|
||||
}
|
||||
|
||||
|
||||
if (isset($rebuild) && $rebuild_after) {
|
||||
buildThread($rebuild);
|
||||
buildIndex();
|
||||
@ -1310,7 +1310,7 @@ function clean($pid = false) {
|
||||
$query = prepare(sprintf('SELECT `id` AS `thread_id`, (SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001', $board['uri'], $board['uri']));
|
||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
if ($config['early_404_staged']) {
|
||||
$page = $config['early_404_page'];
|
||||
$iter = 0;
|
||||
@ -1366,7 +1366,7 @@ function index($page, $mod=false) {
|
||||
return false;
|
||||
|
||||
$threads = array();
|
||||
|
||||
|
||||
while ($th = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$thread = new Thread($th, $mod ? '?/' : $config['root'], $mod);
|
||||
|
||||
@ -1417,7 +1417,7 @@ function index($page, $mod=false) {
|
||||
$thread->omitted = $omitted['post_count'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
||||
$thread->omitted_images = $omitted['image_count'] - $num_images;
|
||||
}
|
||||
|
||||
|
||||
$threads[] = $thread;
|
||||
$body .= $thread->build(true);
|
||||
}
|
||||
@ -1632,7 +1632,7 @@ function checkMute() {
|
||||
// Not expired yet
|
||||
error(sprintf($config['error']['youaremuted'], $mute['time'] + $mutetime - time()));
|
||||
} else {
|
||||
// Already expired
|
||||
// Already expired
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1744,8 +1744,8 @@ function buildJavascript() {
|
||||
}
|
||||
}
|
||||
|
||||
if ($config['minify_js']) {
|
||||
$script = JSMin::minify($script);
|
||||
if ($config['minify_js']) {
|
||||
$script = \JSMin\JSMin::minify($script);
|
||||
}
|
||||
|
||||
file_write($config['file_script'], $script);
|
||||
@ -1808,7 +1808,7 @@ function ReverseIPOctets($ip) {
|
||||
|
||||
/**
|
||||
* Convert an IPv4 address to an IPv6 address
|
||||
*
|
||||
*
|
||||
* @param string $ip An IPv4 address
|
||||
* @return string A IPv6 representation of the input
|
||||
*/
|
||||
@ -1873,7 +1873,7 @@ function markup_url($matches) {
|
||||
'rel' => 'nofollow',
|
||||
'target' => '_blank',
|
||||
);
|
||||
|
||||
|
||||
event('markup-url', $link);
|
||||
$link = (array)$link;
|
||||
|
||||
@ -1904,7 +1904,7 @@ function unicodify($body) {
|
||||
|
||||
function extract_modifiers($body) {
|
||||
$modifiers = array();
|
||||
|
||||
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.*?)</tinyboard>@us', $body, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
if (strpos($match[1], 'escape ') === 0)
|
||||
@ -1912,7 +1912,7 @@ function extract_modifiers($body) {
|
||||
$modifiers[$match[1]] = html_entity_decode($match[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $modifiers;
|
||||
}
|
||||
|
||||
@ -1922,12 +1922,12 @@ function remove_modifiers($body) {
|
||||
|
||||
function markup(&$body, $track_cites = false, $op = false) {
|
||||
global $board, $config, $markup_urls;
|
||||
|
||||
|
||||
$modifiers = extract_modifiers($body);
|
||||
|
||||
|
||||
$body = preg_replace('@<tinyboard (?!escape )([\w\s]+)>(.+?)</tinyboard>@us', '', $body);
|
||||
$body = preg_replace('@<(tinyboard) escape ([\w\s]+)>@i', '<$1 $2>', $body);
|
||||
|
||||
|
||||
if (isset($modifiers['raw html']) && $modifiers['raw html'] === '1') {
|
||||
return array();
|
||||
}
|
||||
@ -1965,7 +1965,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
if ($num_links > $config['max_links'])
|
||||
error($config['error']['toomanylinks']);
|
||||
}
|
||||
|
||||
|
||||
if ($config['markup_repair_tidy'])
|
||||
$body = str_replace(' ', ' ', $body);
|
||||
|
||||
@ -1989,21 +1989,21 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
|
||||
$skip_chars = 0;
|
||||
$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) {
|
||||
$cite = $matches[2][0];
|
||||
|
||||
@ -2036,34 +2036,34 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
|
||||
$skip_chars = 0;
|
||||
$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) {
|
||||
@ -2072,27 +2072,27 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
$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`, `slug` 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'] .
|
||||
link_for($cite) . '#' . $cite['id'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index'];
|
||||
}
|
||||
|
||||
|
||||
// Restore old board
|
||||
if ($board['uri'] !== $tmp_board)
|
||||
openBoard($tmp_board);
|
||||
@ -2109,7 +2109,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
if ($cite) {
|
||||
if (isset($cited_posts[$_board][$cite])) {
|
||||
$link = $cited_posts[$_board][$cite];
|
||||
|
||||
|
||||
$replacement = '<a ' .
|
||||
($_board === $board['uri'] ?
|
||||
'onclick="highlightReply(\''.$cite.'\', event);" '
|
||||
@ -2132,7 +2132,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
|
||||
|
||||
$body = preg_replace('/^\s*>.*$/m', '<span class="quote">$0</span>', $body);
|
||||
@ -2187,7 +2187,7 @@ function utf8tohtml($utf8) {
|
||||
}
|
||||
|
||||
function ordutf8($string, &$offset) {
|
||||
$code = ord(substr($string, $offset,1));
|
||||
$code = ord(substr($string, $offset,1));
|
||||
if ($code >= 128) { // otherwise 0xxxxxxx
|
||||
if ($code < 224)
|
||||
$bytesnumber = 2; // 110xxxxx
|
||||
@ -2287,7 +2287,7 @@ function buildThread($id, $return = false, $mod = false) {
|
||||
$noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true);
|
||||
if ($hasnoko50 || file_exists($noko50fn))
|
||||
buildThread50($id, $return, $mod, $thread, $antibot);
|
||||
|
||||
|
||||
file_write($board['dir'] . $config['dir']['res'] . link_for($thread), $body);
|
||||
}
|
||||
}
|
||||
@ -2295,16 +2295,16 @@ function buildThread($id, $return = false, $mod = false) {
|
||||
function buildThread50($id, $return = false, $mod = false, $thread = null, $antibot = false) {
|
||||
global $board, $config, $build_pages;
|
||||
$id = round($id);
|
||||
|
||||
|
||||
if ($antibot)
|
||||
$antibot->reset();
|
||||
|
||||
|
||||
if (!$thread) {
|
||||
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit', $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
$num_images = 0;
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (!isset($thread)) {
|
||||
@ -2312,7 +2312,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
||||
} else {
|
||||
if ($post['files'])
|
||||
$num_images += $post['num_files'];
|
||||
|
||||
|
||||
$thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
|
||||
}
|
||||
}
|
||||
@ -2327,10 +2327,10 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
||||
SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread', $board['uri'], $board['uri']));
|
||||
$count->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||
$count->execute() or error(db_error($count));
|
||||
|
||||
|
||||
$c = $count->fetch();
|
||||
$thread->omitted = $c['num'] - $config['noko50_count'];
|
||||
|
||||
|
||||
$c = $count->fetch();
|
||||
$thread->omitted_images = $c['num'] - $num_images;
|
||||
}
|
||||
@ -2343,13 +2343,13 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
||||
$thread->omitted += count($allPosts) - count($thread->posts);
|
||||
foreach ($allPosts as $index => $post) {
|
||||
if ($index === count($allPosts)-count($thread->posts))
|
||||
break;
|
||||
break;
|
||||
if ($post->files)
|
||||
$thread->omitted_images += $post->num_files;
|
||||
}
|
||||
}
|
||||
|
||||
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
|
||||
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
|
||||
|
||||
$body = Element('thread.html', array(
|
||||
'board' => $board,
|
||||
@ -2363,7 +2363,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
||||
'antibot' => $mod ? false : ($antibot ? $antibot : create_antibot($board['uri'], $id)),
|
||||
'boardlist' => createBoardlist(),
|
||||
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
|
||||
));
|
||||
));
|
||||
|
||||
if ($return) {
|
||||
return $body;
|
||||
@ -2442,7 +2442,7 @@ function hcf($a, $b){
|
||||
$b = $a-$b;
|
||||
$a = $a-$b;
|
||||
}
|
||||
if ($b===(round($b/$a))*$a)
|
||||
if ($b===(round($b/$a))*$a)
|
||||
$gcd=$a;
|
||||
else {
|
||||
for ($i=round($a/2);$i;$i--) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user