diff --git a/README.md b/README.md index 4292844d..4d0383e5 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -8chan - The infinitely expanding imageboard. +infinity ======================================================== About ------------ -8chan is a fork of vichan, with the difference that 8chan is geared towards allowing users to create their own boards. +infinity is a fork of vichan, with the difference that 8chan is geared towards allowing users to create their own boards. A running instance is at https://8chan.co. -Most things (other than installation) that apply to upstream vichan also apply to 8chan. See their readme for a detailed FAQ: https://github.com/vichan-devel/vichan/blob/master/README.md +Most things (other than installation) that apply to upstream vichan also apply to infinity. See their readme for a detailed FAQ: https://github.com/vichan-devel/vichan/blob/master/README.md -If you are not interested in letting your users make their own boards, install vichan instead of 8chan. +If you are not interested in letting your users make their own boards, install vichan instead of infinity. Because I cannot be bothered to maintain `install.php`, the install process is as such: diff --git a/inc/bans.php b/inc/bans.php index 215ff279..fed34938 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -322,6 +322,17 @@ class Bans { if ($post) { $post['board'] = $board['uri']; + $match_urls = '(?xi)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'; + + $matched = array(); + + preg_match_all("#$match_urls#im", $post['body_nomarkup'], $matched); + + if (isset($matched[0]) && $matched[0]) { + $post['body'] = str_replace($matched[0], '###Link-Removed###', $post['body']); + $post['body_nomarkup'] = str_replace($matched[0], '###Link-Removed###', $post['body_nomarkup']); + } + $query->bindValue(':post', json_encode($post)); } else $query->bindValue(':post', null, PDO::PARAM_NULL); diff --git a/inc/display.php b/inc/display.php index 9561c4b8..929f2a91 100644 --- a/inc/display.php +++ b/inc/display.php @@ -357,9 +357,14 @@ class Post { if (isset($this->files) && $this->files) { $this->files = json_decode($this->files); // Compatibility for posts before individual file hashing - foreach ($this->files as &$file) + foreach ($this->files as $i => &$file) { + if (empty($file)) { + unset($this->files[$i]); + continue; + } if (!isset($file->hash)) $file->hash = $this->filehash; + } } $this->subject = utf8tohtml($this->subject); diff --git a/inc/functions.php b/inc/functions.php index e72708fd..ca58bbfa 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1707,6 +1707,10 @@ function extract_modifiers($body) { return $modifiers; } +function remove_modifiers($body) { + return preg_replace('@(.+?)@usm', '', $body); +} + function markup(&$body, $track_cites = false, $op = false) { global $board, $config, $markup_urls; diff --git a/inc/instance-config.php b/inc/instance-config.php index de7affe2..91d1174c 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -141,6 +141,7 @@ $config['additional_javascript'][] = 'js/thread-stats.js'; $config['additional_javascript'][] = 'js/quote-selection.js'; $config['additional_javascript'][] = 'js/twemoji/twemoji.js'; + $config['additional_javascript'][] = 'js/flag-previews.js'; //$config['font_awesome_css'] = '/netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css'; diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 734a936e..0ac59fdd 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1600,6 +1600,16 @@ function mod_edit_post($board, $edit_raw_html, $postID) { if (isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['body'])) { $trip = isset($_POST['remove_trip']) ? ' `trip` = NULL,' : ''; + + // Remove any modifiers they may have put in + $_POST['body'] = remove_modifiers($_POST['body']); + + // Add back modifiers in the original post + $modifiers = extract_modifiers($post['body_nomarkup']); + foreach ($modifiers as $key => $value) { + $_POST['body'] .= "$value"; + } + if ($edit_raw_html) $query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup, `edited_at` = NOW() WHERE `id` = :id', $board)); else @@ -1657,15 +1667,20 @@ function mod_edit_post($board, $edit_raw_html, $postID) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']); } else { + // Remove modifiers + $post['body_nomarkup'] = remove_modifiers($post['body_nomarkup']); + + $post['body_nomarkup'] = utf8tohtml($post['body_nomarkup']); + $post['body'] = utf8tohtml($post['body']); if ($config['minify_html']) { - $post['body_nomarkup'] = str_replace("\n", ' ', utf8tohtml($post['body_nomarkup'])); - $post['body'] = str_replace("\n", ' ', utf8tohtml($post['body'])); + $post['body_nomarkup'] = str_replace("\n", ' ', $post['body_nomarkup']); + $post['body'] = str_replace("\n", ' ', $post['body']); $post['body_nomarkup'] = str_replace("\r", '', $post['body_nomarkup']); $post['body'] = str_replace("\r", '', $post['body']); $post['body_nomarkup'] = str_replace("\t", ' ', $post['body_nomarkup']); $post['body'] = str_replace("\t", ' ', $post['body']); } - + mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post)); } } diff --git a/js/expand-all-images.js b/js/expand-all-images.js index 82ea6340..6d7b4ca0 100644 --- a/js/expand-all-images.js +++ b/js/expand-all-images.js @@ -23,6 +23,14 @@ onready(function(){ .text(_('Expand all images')) .click(function() { $('a img.post-image').each(function() { + // Don't expand YouTube embeds + if ($(this).parent().parent().hasClass('video-container')) + return; + + // or WEBM + if (/^\/player\.php\?/.test($(this).parent().attr('href'))) + return; + if (!$(this).parent()[0].dataset.expanded) $(this).parent().click(); }); diff --git a/js/flag-previews.js b/js/flag-previews.js new file mode 100644 index 00000000..b9530b17 --- /dev/null +++ b/js/flag-previews.js @@ -0,0 +1,17 @@ +/* + * flag-previews.js - Preview board flags + * + * Copyright (c) 2014 Fredrick Brennan + * +*/ + +$(document).on('ready', function() { + var flag_previews = function() { + if (!$('.flag_preview').length) $('[name=user_flag]').after(''); + + $('.flag_preview').attr('src', "/static/custom-flags/" + board_name + "/" + $(this).val() + '.png'); + } + + $('[name=user_flag]').on('change', flag_previews); + $(window).on('quick-reply', function(){$('[name=user_flag]').on('change', flag_previews)}); +}); diff --git a/tools/hide_bans_links.php b/tools/hide_bans_links.php new file mode 100644 index 00000000..5a8e02a6 --- /dev/null +++ b/tools/hide_bans_links.php @@ -0,0 +1,34 @@ +execute() or error(db_error($query)); +$num_bans = $query->rowCount(); +$iter = 0; + +while ($ban = $query->fetch(PDO::FETCH_ASSOC)) { + $iter++; + + if (!$ban['post']) + continue; + + $match_urls = '(?xi)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'; + + $matched = array(); + + $post = json_decode($ban['post']); + + preg_match_all("#$match_urls#im", $post->body_nomarkup, $matched); + + if (!isset($matched[0]) || !$matched[0]) + continue; + + $post->body = str_replace($matched[0], '###Link-Removed###', $post->body); + $post->body_nomarkup = str_replace($matched[0], '###Link-Removed###', $post->body_nomarkup); + + $update = prepare('UPDATE ``bans`` SET `post` = :post WHERE `id` = :id'); + $update->bindValue(':post', json_encode($post)); + $update->bindValue(':id', $ban['id']); + $update->execute() or error(db_error($update)); + echo "Processed $iter/$num_bans\n"; +}