diff options
| author | czaks <marcin@6irc.net> | 2013-08-11 17:49:29 -0400 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2013-08-11 17:49:29 -0400 |
| commit | 8534e2cc80bedcaf4645c9b062906c0d3aedf517 (patch) | |
| tree | 6091ee8c012302b80109ddf32014c66b58cb1bdc /inc/functions.php | |
| parent | 500468336e528887db852ae153da89300aefd090 (diff) | |
| parent | a4e97c32ec9d413ea2c77fab61a46c5e6c2cb2d7 (diff) | |
Merge branch 'noko50-new-dev11' of http://github.com/fallenPineapple/Tinyboard
Conflicts:
inc/functions.php
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 113 |
1 files changed, 107 insertions, 6 deletions
diff --git a/inc/functions.php b/inc/functions.php index 5bf1f999..f8957ece 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -108,7 +108,10 @@ function loadConfig() { '|' . str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . preg_quote($config['dir']['res'], '/') . - str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . + '(' . + str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . + str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . + ')' . '|' . preg_quote($config['file_mod'], '/') . '\?\/.+' . ')([#?](.+)?)?$/ui'; @@ -951,6 +954,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { if (!$post['thread']) { // Delete thread HTML page file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); + file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $post['id'])); $antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread'); $antispam_query->bindValue(':board', $board['uri']); @@ -1769,6 +1773,8 @@ function buildThread($id, $return = false, $mod = false) { // Check if any posts were found if (!isset($thread)) error($config['error']['nonexistant']); + + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; $body = Element('thread.html', array( 'board' => $board, @@ -1777,6 +1783,8 @@ function buildThread($id, $return = false, $mod = false) { 'config' => $config, 'id' => $id, 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => false, 'antibot' => $mod ? false : create_antibot($board['uri'], $id), 'boardlist' => createBoardlist($mod), 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) @@ -1785,16 +1793,109 @@ function buildThread($id, $return = false, $mod = false) { if ($config['try_smarter'] && !$mod) $build_pages[] = thread_find_page($id); - if ($return) - return $body; - - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); - // json api $api = new Api(); $json = json_encode($api->translateThread($thread)); $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; file_write($jsonFilename, $json); + + if ($return) { + return $body; + } else { + $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); + if ($hasnoko50 || file_exists($noko50fn)) { + buildThread50($id, $return, $mod, $thread); + } + + file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); + } +} + +function buildThread50($id, $return = false, $mod = false, $thread = null) { + global $board, $config, $build_pages; + $id = round($id); + + if (event('build-thread', $id)) + return; + + 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)) { + $thread = new Thread( + $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], + $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], + $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod + ); + } else { + if ($post['file']) + $num_images++; + + $thread->add(new Post( + $post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], + $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], + $post['filesize'], $post['filename'], $post['ip'], $post['embed'], $mod ? '?/' : $config['root'], $mod) + ); + } + } + + // Check if any posts were found + if (!isset($thread)) + error($config['error']['nonexistant']); + + + if ($query->rowCount() == $config['noko50_count']+1) { + $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `file` 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; + } + + $thread->posts = array_reverse($thread->posts); + } else { + $allPosts = $thread->posts; + + $thread->posts = array_slice($allPosts, -$config['noko50_count']); + $thread->omitted += count($allPosts) - count($thread->posts); + foreach ($allPosts as $index => $post) { + if ($index == count($allPosts)-count($thread->posts)) + break; + if ($post->file) + $thread->omitted_images++; + } + } + + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; + + $body = Element('thread.html', array( + 'board' => $board, + 'thread' => $thread, + 'body' => $thread->build(false, true), + 'config' => $config, + 'id' => $id, + 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => true, + 'antibot' => $mod ? false : create_antibot($board['uri'], $id), + 'boardlist' => createBoardlist($mod), + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) + )); + + if ($return) { + return $body; + } else { + file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); + } } function rrmdir($dir) { |
