diff --git a/.gitignore b/.gitignore index 69317f82..281515e9 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,12 @@ Thumbs.db *.orig *~ +# tmp filesystem +/tmp/cache/* +/tmp/locks/* +!/tmp/cache/.gitkeep +!/tmp/locks/.gitkeep + #vichan custom favicon.ico /static/spoiler.png diff --git a/README.md b/README.md index 06efae0a..6e153ab7 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,16 @@ About vichan is a free light-weight, fast, highly configurable and user-friendly imageboard software package. It is written in PHP and has few dependencies. -vichan is a fork of [Tinyboard](http://tinyboard.org/), a great imageboard package, actively -building on it and adding a lot of features and other improvements. +vichan is a fork of (now defunc'd) [Tinyboard](http://github.com/savetheinternet/Tinyboard), +a great imageboard package, actively building on it and adding a lot of features and other +improvements. -Support and announcements: https://int.vichan.net/devel/ +Support and announcements: https://engine.vichan.net/ Requirements ------------ 1. PHP >= 5.4 (we still try to keep compatibility with php 5.3 as much as possible) + PHP 7.0 is explicitly supported. 2. MySQL/MariaDB server 3. [mbstring](http://www.php.net/manual/en/mbstring.installation.php) 4. [PHP GD](http://www.php.net/manual/en/intro.image.php) @@ -41,7 +43,7 @@ If you need help developing a patch, please join our IRC channel. Installation ------------- -1. Download and extract Tinyboard to your web directory or get the latest +1. Download and extract vichan to your web directory or get the latest development version with: git clone git://github.com/vichan-devel/vichan.git @@ -64,7 +66,7 @@ backup your ```inc/instance-config.php```, replace all your files in place (don't remove boards etc.), then put ```inc/instance-config.php``` back and finally run ```install.php```. -To migrate from a Kusaba X board: +To migrate from a Kusaba X board, use http://github.com/vichan-devel/Tinyboard-Migration Support -------- @@ -84,15 +86,12 @@ find support from a variety of sources: vichan is based on a Tinyboard, so both engines have very much in common. These links may be helpful for you as well: -* Tinyboard documentation can be found [here](http://tinyboard.org/docs/). -* You can join Tinyboard's IRC channel for support and general queries: - [irc.datnode.net #tinyboard](irc://irc.datnode.net/tinyboard). -* You may find help at [tinyboard.org](http://tinyboard.org/#help). +* Tinyboard documentation can be found [here](https://web.archive.org/web/20121016074303/http://tinyboard.org/docs/?p=Main_Page). Donations --------- Do you like our work? You can motivate us financially to do better ;) -* Bitcoin: [![tip for next commit](http://tip4commit.com/projects/708.svg)](http://tip4commit.com/projects/708) +* Bitcoin: 1GjZEdLaTQ8JWVFGZW921Yv4x59f9oiZME You can also ask us to develop some feature specially for you <3. Join our IRC channel and ask for a quote (there are a few of us, who work with the codebase diff --git a/banned.php b/banned.php index 57e4a9bc..1bee9115 100644 --- a/banned.php +++ b/banned.php @@ -1,5 +1,6 @@
tags (PHP 5.3+)
- // $config['markup'][] = array(
- // '/^<code>(.+)<\/code>/ms',
- // function($matches) {
- // return highlight_string(html_entity_decode($matches[1]), true);
- // }
- // );
+ // Code markup. This should be set to a regular expression, using tags you want to use. Examples:
+ // "/\[code\](.*?)\[\/code\]/is"
+ // "/```([a-z0-9-]{0,20})\n(.*?)\n?```\n?/s"
+ $config['markup_code'] = false;
// 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
@@ -724,6 +739,11 @@
$config['allowed_ext'][] = 'png';
// $config['allowed_ext'][] = 'svg';
+ // Allowed extensions for OP. Inherits from the above setting if set to false. Otherwise, it overrides both allowed_ext and
+ // allowed_ext_files (filetypes for downloadable files should be set in allowed_ext_files as well). This setting is useful
+ // for creating fileboards.
+ $config['allowed_ext_op'] = false;
+
// Allowed additional file extensions (not images; downloadable files).
// $config['allowed_ext_files'][] = 'txt';
// $config['allowed_ext_files'][] = 'zip';
@@ -737,6 +757,7 @@
$config['file_icons']['default'] = 'file.png';
$config['file_icons']['zip'] = 'zip.png';
$config['file_icons']['webm'] = 'video.png';
+ $config['file_icons']['mp4'] = 'video.png';
// Example: Custom thumbnail for certain file extension.
// $config['file_icons']['extension'] = 'some_file.png';
@@ -1005,7 +1026,7 @@
''
),
array(
- '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?.+)?$/i',
+ '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?[^\'"<>]+)?$/i',
''
),
array(
@@ -1172,9 +1193,20 @@
// Website favicon.
// $config['url_favicon'] = '/favicon.gif';
- // EXPERIMENTAL: Try not to build pages when we shouldn't have to.
+ // Try not to build pages when we shouldn't have to.
$config['try_smarter'] = true;
+ // EXPERIMENTAL: Defer static HTML building to a moment, when a given file is actually accessed.
+ // Warning: This option won't run out of the box. You need to tell your webserver, that a file
+ // for serving 403 and 404 pages is /smart_build.php. Also, you need to turn off indexes.
+ $config['smart_build'] = false;
+
+ // Smart build related: when a file doesn't exist, where should we redirect?
+ $config['page_404'] = '/404.html';
+
+ // Smart build related: extra entrypoints.
+ $config['smart_build_entrypoints'] = array();
+
/*
* ====================
* Mod settings
@@ -1496,6 +1528,13 @@
// Allow OP to remove arbitrary posts in his thread
$config['user_moderation'] = false;
+ // File board. Like 4chan /f/
+ $config['file_board'] = false;
+
+ // Thread tags. Set to false to disable
+ // Example: array('A' => 'Chinese cartoons', 'M' => 'Music', 'P' => 'Pornography');
+ $config['allowed_tags'] = false;
+
/*
* ====================
* Public post search
@@ -1630,6 +1669,6 @@
// Youtube.js embed HTML code
$config['youtube_js_html'] = '';
diff --git a/inc/display.php b/inc/display.php
index 65525ab9..90cf3434 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -354,7 +354,7 @@ class Post {
}
if (isset($this->files) && $this->files)
- $this->files = json_decode($this->files);
+ $this->files = @json_decode($this->files);
$this->subject = utf8tohtml($this->subject);
$this->name = utf8tohtml($this->name);
@@ -404,7 +404,7 @@ class Thread {
}
if (isset($this->files))
- $this->files = json_decode($this->files);
+ $this->files = @json_decode($this->files);
$this->subject = utf8tohtml($this->subject);
$this->name = utf8tohtml($this->name);
@@ -453,7 +453,8 @@ class Thread {
event('show-thread', $this);
- $built = Element('post_thread.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod));
+ $file = ($index && $config['file_board']) ? 'post_thread_fileboard.html' : 'post_thread.html';
+ $built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod));
return $built;
}
diff --git a/inc/functions.php b/inc/functions.php
index f1fb07d7..515e3e55 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -18,8 +18,9 @@ require_once 'inc/template.php';
require_once 'inc/database.php';
require_once 'inc/events.php';
require_once 'inc/api.php';
-require_once 'inc/bans.php';
-require_once 'inc/lib/gettext/gettext.inc';
+if (!extension_loaded('gettext')) {
+ require_once 'inc/lib/gettext/gettext.inc';
+}
// the user is not currently logged in as a moderator
$mod = false;
@@ -29,14 +30,17 @@ mb_internal_encoding('UTF-8');
loadConfig();
function init_locale($locale, $error='error') {
- if (_setlocale(LC_ALL, $locale) === false) {
- $error('The specified locale (' . $locale . ') does not exist on your platform!');
- }
if (extension_loaded('gettext')) {
+ if (setlocale(LC_ALL, $locale) === false) {
+ //$error('The specified locale (' . $locale . ') does not exist on your platform!');
+ }
bindtextdomain('tinyboard', './inc/locale');
bind_textdomain_codeset('tinyboard', 'UTF-8');
textdomain('tinyboard');
} else {
+ if (_setlocale(LC_ALL, $locale) === false) {
+ $error('The specified locale (' . $locale . ') does not exist on your platform!');
+ }
_bindtextdomain('tinyboard', './inc/locale');
_bind_textdomain_codeset('tinyboard', 'UTF-8');
_textdomain('tinyboard');
@@ -46,167 +50,213 @@ $current_locale = 'en';
function loadConfig() {
- global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale;
+ global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale, $events;
$error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
- reset_events();
+ $boardsuffix = isset($board['uri']) ? $board['uri'] : '';
if (!isset($_SERVER['REMOTE_ADDR']))
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
- $arrays = array(
- 'db',
- 'api',
- 'cache',
- 'cookies',
- 'error',
- 'dir',
- 'mod',
- 'spam',
- 'filters',
- 'wordfilters',
- 'custom_capcode',
- 'custom_tripcode',
- 'dnsbl',
- 'dnsbl_exceptions',
- 'remote',
- 'allowed_ext',
- 'allowed_ext_files',
- 'file_icons',
- 'footer',
- 'stylesheets',
- 'additional_javascript',
- 'markup',
- 'custom_pages',
- 'dashboard_links'
- );
+ if (file_exists('tmp/cache/cache_config.php')) {
+ require_once('tmp/cache/cache_config.php');
+ }
+
+
+ if (isset($config['cache_config']) &&
+ $config['cache_config'] &&
+ $config = Cache::get('config_' . $boardsuffix ) ) {
+ $events = Cache::get('events_' . $boardsuffix );
+
+ define_groups();
+
+ if (file_exists('inc/instance-functions.php')) {
+ require_once('inc/instance-functions.php');
+ }
- $config = array();
- foreach ($arrays as $key) {
- $config[$key] = array();
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
}
+ else {
+ $config = array();
+
+ reset_events();
+
+ $arrays = array(
+ 'db',
+ 'api',
+ 'cache',
+ 'cookies',
+ 'error',
+ 'dir',
+ 'mod',
+ 'spam',
+ 'filters',
+ 'wordfilters',
+ 'custom_capcode',
+ 'custom_tripcode',
+ 'dnsbl',
+ 'dnsbl_exceptions',
+ 'remote',
+ 'allowed_ext',
+ 'allowed_ext_files',
+ 'file_icons',
+ 'footer',
+ 'stylesheets',
+ 'additional_javascript',
+ 'markup',
+ 'custom_pages',
+ 'dashboard_links'
+ );
- if (!file_exists('inc/instance-config.php'))
- $error('Tinyboard is not configured! Create inc/instance-config.php.');
+ foreach ($arrays as $key) {
+ $config[$key] = array();
+ }
- // Initialize locale as early as possible
+ if (!file_exists('inc/instance-config.php'))
+ $error('Tinyboard is not configured! Create inc/instance-config.php.');
- $config['locale'] = 'en';
+ // Initialize locale as early as possible
- $configstr = file_get_contents('inc/instance-config.php');
+ // Those calls are expensive. Unfortunately, our cache system is not initialized at this point.
+ // So, we may store the locale in a tmp/ filesystem.
- if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
- $configstr .= file_get_contents($board['dir'] . '/config.php');
+ if (file_exists($fn = 'tmp/cache/locale_' . $boardsuffix ) ) {
+ $config['locale'] = file_get_contents($fn);
}
- $matches = array();
- preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches);
- if ($matches && isset ($matches[2]) && $matches[2]) {
- $matches = $matches[2];
- $config['locale'] = $matches[count($matches)-1];
- }
+ else {
+ $config['locale'] = 'en';
- if ($config['locale'] != $current_locale) {
- $current_locale = $config['locale'];
- init_locale($config['locale'], $error);
- }
+ $configstr = file_get_contents('inc/instance-config.php');
+
+ if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
+ $configstr .= file_get_contents($board['dir'] . '/config.php');
+ }
+ $matches = array();
+ preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches);
+ if ($matches && isset ($matches[2]) && $matches[2]) {
+ $matches = $matches[2];
+ $config['locale'] = $matches[count($matches)-1];
+ }
- require 'inc/config.php';
+ file_put_contents($fn, $config['locale']);
+ }
- require 'inc/instance-config.php';
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
- if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
- require $board['dir'] . '/config.php';
- }
+ require 'inc/config.php';
- if ($config['locale'] != $current_locale) {
- $current_locale = $config['locale'];
- init_locale($config['locale'], $error);
- }
+ require 'inc/instance-config.php';
- date_default_timezone_set($config['timezone']);
+ if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
+ require $board['dir'] . '/config.php';
+ }
- if (!isset($config['global_message']))
- $config['global_message'] = false;
-
- if (!isset($config['post_url']))
- $config['post_url'] = $config['root'] . $config['file_post'];
-
-
- if (!isset($config['referer_match']))
- if (isset($_SERVER['HTTP_HOST'])) {
- $config['referer_match'] = '/^' .
- (preg_match('@^https?://@', $config['root']) ? '' :
- 'https?:\/\/' . $_SERVER['HTTP_HOST']) .
- preg_quote($config['root'], '/') .
- '(' .
- str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) .
- '(' .
- preg_quote($config['file_index'], '/') . '|' .
- str_replace('%d', '\d+', preg_quote($config['file_page'])) .
- ')?' .
- '|' .
- 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_page50'], '/')) . '|' .
- str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' .
- str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) .
- ')' .
- '|' .
- preg_quote($config['file_mod'], '/') . '\?\/.+' .
- ')([#?](.+)?)?$/ui';
- } else {
- // CLI mode
- $config['referer_match'] = '//';
- }
- if (!isset($config['cookies']['path']))
- $config['cookies']['path'] = &$config['root'];
-
- if (!isset($config['dir']['static']))
- $config['dir']['static'] = $config['root'] . 'static/';
-
- if (!isset($config['image_blank']))
- $config['image_blank'] = $config['dir']['static'] . 'blank.gif';
-
- if (!isset($config['image_sticky']))
- $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
- if (!isset($config['image_locked']))
- $config['image_locked'] = $config['dir']['static'] . 'locked.gif';
- if (!isset($config['image_bumplocked']))
- $config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif';
- if (!isset($config['image_deleted']))
- $config['image_deleted'] = $config['dir']['static'] . 'deleted.png';
-
- if (!isset($config['uri_thumb']))
- $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb'];
- elseif (isset($board['dir']))
- $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']);
-
- if (!isset($config['uri_img']))
- $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img'];
- elseif (isset($board['dir']))
- $config['uri_img'] = sprintf($config['uri_img'], $board['dir']);
-
- if (!isset($config['uri_stylesheets']))
- $config['uri_stylesheets'] = $config['root'] . 'stylesheets/';
-
- if (!isset($config['url_stylesheet']))
- $config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css';
- if (!isset($config['url_javascript']))
- $config['url_javascript'] = $config['root'] . $config['file_script'];
- if (!isset($config['additional_javascript_url']))
- $config['additional_javascript_url'] = $config['root'];
- if (!isset($config['uri_flags']))
- $config['uri_flags'] = $config['root'] . 'static/flags/%s.png';
- if (!isset($config['user_flag']))
- $config['user_flag'] = false;
- if (!isset($config['user_flags']))
- $config['user_flags'] = array();
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
+ if (!isset($config['global_message']))
+ $config['global_message'] = false;
+
+ if (!isset($config['post_url']))
+ $config['post_url'] = $config['root'] . $config['file_post'];
+
+
+ if (!isset($config['referer_match']))
+ if (isset($_SERVER['HTTP_HOST'])) {
+ $config['referer_match'] = '/^' .
+ (preg_match('@^https?://@', $config['root']) ? '' :
+ 'https?:\/\/' . $_SERVER['HTTP_HOST']) .
+ preg_quote($config['root'], '/') .
+ '(' .
+ str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) .
+ '(' .
+ preg_quote($config['file_index'], '/') . '|' .
+ str_replace('%d', '\d+', preg_quote($config['file_page'])) .
+ ')?' .
+ '|' .
+ 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_page50'], '/')) . '|' .
+ str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' .
+ str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) .
+ ')' .
+ '|' .
+ preg_quote($config['file_mod'], '/') . '\?\/.+' .
+ ')([#?](.+)?)?$/ui';
+ } else {
+ // CLI mode
+ $config['referer_match'] = '//';
+ }
+ if (!isset($config['cookies']['path']))
+ $config['cookies']['path'] = &$config['root'];
+
+ if (!isset($config['dir']['static']))
+ $config['dir']['static'] = $config['root'] . 'static/';
+
+ if (!isset($config['image_blank']))
+ $config['image_blank'] = $config['dir']['static'] . 'blank.gif';
+
+ if (!isset($config['image_sticky']))
+ $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
+ if (!isset($config['image_locked']))
+ $config['image_locked'] = $config['dir']['static'] . 'locked.gif';
+ if (!isset($config['image_bumplocked']))
+ $config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif';
+ if (!isset($config['image_deleted']))
+ $config['image_deleted'] = $config['dir']['static'] . 'deleted.png';
+
+ if (!isset($config['uri_thumb']))
+ $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb'];
+ elseif (isset($board['dir']))
+ $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']);
+
+ if (!isset($config['uri_img']))
+ $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img'];
+ elseif (isset($board['dir']))
+ $config['uri_img'] = sprintf($config['uri_img'], $board['dir']);
+
+ if (!isset($config['uri_stylesheets']))
+ $config['uri_stylesheets'] = $config['root'] . 'stylesheets/';
+
+ if (!isset($config['url_stylesheet']))
+ $config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css';
+ if (!isset($config['url_javascript']))
+ $config['url_javascript'] = $config['root'] . $config['file_script'];
+ if (!isset($config['additional_javascript_url']))
+ $config['additional_javascript_url'] = $config['root'];
+ if (!isset($config['uri_flags']))
+ $config['uri_flags'] = $config['root'] . 'static/flags/%s.png';
+ if (!isset($config['user_flag']))
+ $config['user_flag'] = false;
+ if (!isset($config['user_flags']))
+ $config['user_flags'] = array();
+
+ if (!isset($__version))
+ $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
+ $config['version'] = $__version;
+
+ if ($config['allow_roll'])
+ event_handler('post', 'diceRoller');
+
+ if (in_array('webm', $config['allowed_ext_files']) ||
+ in_array('mp4', $config['allowed_ext_files']))
+ event_handler('post', 'postHandler');
+ }
// Effectful config processing below:
+ date_default_timezone_set($config['timezone']);
+
if ($config['root_file']) {
chdir($config['root_file']);
}
@@ -219,10 +269,6 @@ function loadConfig() {
if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m))
$_SERVER['REMOTE_ADDR'] = $m[2];
- if (!isset($__version))
- $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
- $config['version'] = $__version;
-
if ($config['verbose_errors']) {
set_error_handler('verbose_error_handler');
error_reporting(E_ALL);
@@ -241,18 +287,29 @@ function loadConfig() {
if ($config['cache']['enabled'])
require_once 'inc/cache.php';
- if (in_array('webm', $config['allowed_ext_files'])) {
+ if (in_array('webm', $config['allowed_ext_files']) ||
+ in_array('mp4', $config['allowed_ext_files']))
require_once 'inc/lib/webm/posthandler.php';
- event_handler('post', 'postHandler');
+
+ event('load-config');
+
+ if ($config['cache_config'] && !isset ($config['cache_config_loaded'])) {
+ file_put_contents('tmp/cache/cache_config.php', ' $group_name)
- defined($group_name) or define($group_name, $group_value, true);
+ foreach ($config['mod']['groups'] as $group_value => $group_name) {
+ $group_name = strtoupper($group_name);
+ if(!defined($group_name)) {
+ define($group_name, $group_value, true);
+ }
+ }
ksort($config['mod']['groups']);
}
@@ -348,9 +409,22 @@ function rebuildThemes($action, $boardname = false) {
$_board = $board;
// List themes
- $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
+ if ($themes = Cache::get("themes")) {
+ // OK, we already have themes loaded
+ }
+ else {
+ $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
- while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
+ $themes = array();
+
+ while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
+ $themes[] = $theme;
+ }
+
+ Cache::set("themes", $themes);
+ }
+
+ foreach ($themes as $theme) {
// Restore them
$config = $_config;
$board = $_board;
@@ -379,7 +453,7 @@ function rebuildThemes($action, $boardname = false) {
// Reload the locale
if ($config['locale'] != $current_locale) {
$current_locale = $config['locale'];
- init_locale($config['locale'], $error);
+ init_locale($config['locale']);
}
}
@@ -411,6 +485,10 @@ function rebuildTheme($theme, $action, $board = false) {
function themeSettings($theme) {
+ if ($settings = Cache::get("theme_settings_".$theme)) {
+ return $settings;
+ }
+
$query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL");
$query->bindValue(':theme', $theme);
$query->execute() or error(db_error($query));
@@ -420,6 +498,8 @@ function themeSettings($theme) {
$settings[$s['name']] = $s['value'];
}
+ Cache::set("theme_settings_".$theme, $settings);
+
return $settings;
}
@@ -475,6 +555,11 @@ function openBoard($uri) {
$board = getBoardInfo($uri);
if ($board) {
setupBoard($board);
+
+ if (function_exists('after_open_board')) {
+ after_open_board();
+ }
+
return true;
}
return false;
@@ -636,6 +721,13 @@ function file_unlink($path) {
}
$ret = @unlink($path);
+
+ if ($config['gzip_static']) {
+ $gzpath = "$path.gz";
+
+ @unlink($gzpath);
+ }
+
if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) {
// Purge cache
if (basename($path) == $config['file_index']) {
@@ -810,12 +902,29 @@ function checkBan($board = false) {
if (event('check-ban', $board))
return true;
- $bans = Bans::find($_SERVER['REMOTE_ADDR'], $board, $config['show_modname']);
+ $ips = array();
+
+ $ips[] = $_SERVER['REMOTE_ADDR'];
+
+ if ($config['proxy_check'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $ips = array_merge($ips, explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']));
+ }
+
+ foreach ($ips as $ip) {
+ $bans = Bans::find($_SERVER['REMOTE_ADDR'], $board, $config['show_modname']);
- foreach ($bans as &$ban) {
- if ($ban['expires'] && $ban['expires'] < time()) {
- Bans::delete($ban['id']);
- if ($config['require_ban_view'] && !$ban['seen']) {
+ foreach ($bans as &$ban) {
+ if ($ban['expires'] && $ban['expires'] < time()) {
+ Bans::delete($ban['id']);
+ if ($config['require_ban_view'] && !$ban['seen']) {
+ if (!isset($_POST['json_response'])) {
+ displayBan($ban);
+ } else {
+ header('Content-Type: text/json');
+ die(json_encode(array('error' => true, 'banned' => true)));
+ }
+ }
+ } else {
if (!isset($_POST['json_response'])) {
displayBan($ban);
} else {
@@ -823,13 +932,6 @@ function checkBan($board = false) {
die(json_encode(array('error' => true, 'banned' => true)));
}
}
- } else {
- if (!isset($_POST['json_response'])) {
- displayBan($ban);
- } else {
- header('Content-Type: text/json');
- die(json_encode(array('error' => true, 'banned' => true)));
- }
}
}
@@ -1004,8 +1106,9 @@ function bumpThread($id) {
if (event('bump', $id))
return true;
- if ($config['try_smarter'])
- $build_pages[] = thread_find_page($id);
+ if ($config['try_smarter']) {
+ $build_pages = array_merge(range(1, thread_find_page($id)), $build_pages);
+ }
$query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL", $board['uri']));
$query->bindValue(':time', time(), PDO::PARAM_INT);
@@ -1085,7 +1188,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
global $board, $config;
// Select post and replies (if thread) in one query
- $query = prepare(sprintf("SELECT `id`,`thread`,`files` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
+ $query = prepare(sprintf("SELECT `id`,`thread`,`files`,`slug` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -1257,6 +1360,10 @@ function index($page, $mod=false) {
$body .= $thread->build(true);
}
+ if ($config['file_board']) {
+ $body = Element('fileboard.html', array('body' => $body, 'mod' => $mod));
+ }
+
return array(
'board' => $board,
'body' => $body,
@@ -1468,56 +1575,65 @@ function checkMute() {
}
}
-function buildIndex() {
+function buildIndex($global_api = "yes") {
global $board, $config, $build_pages;
- $pages = getPages();
- if (!$config['try_smarter'])
- $antibot = create_antibot($board['uri']);
+ if (!$config['smart_build']) {
+ $pages = getPages();
+ if (!$config['try_smarter'])
+ $antibot = create_antibot($board['uri']);
- if ($config['api']['enabled']) {
- $api = new Api();
- $catalog = array();
+ if ($config['api']['enabled']) {
+ $api = new Api();
+ $catalog = array();
+ }
}
for ($page = 1; $page <= $config['max_pages']; $page++) {
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
+ $jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
- if (!$config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages)
- && !in_array($page, $build_pages) && is_file($filename))
+ if ((!$config['api']['enabled'] || $global_api == "skip" || $config['smart_build']) && $config['try_smarter']
+ && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) )
continue;
- $content = index($page);
- if (!$content)
- break;
- // json api
- if ($config['api']['enabled']) {
- $threads = $content['threads'];
- $json = json_encode($api->translatePage($threads));
- $jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
- file_write($jsonFilename, $json);
+ if (!$config['smart_build']) {
+ $content = index($page);
+ if (!$content)
+ break;
- $catalog[$page-1] = $threads;
- }
+ // json api
+ if ($config['api']['enabled']) {
+ $threads = $content['threads'];
+ $json = json_encode($api->translatePage($threads));
+ file_write($jsonFilename, $json);
- if ($config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages)
- && !in_array($page, $build_pages) && is_file($filename))
- continue;
+ $catalog[$page-1] = $threads;
+ }
- if ($config['try_smarter']) {
- $antibot = create_antibot($board['uri'], 0 - $page);
- $content['current_page'] = $page;
- }
- $antibot->reset();
- $content['pages'] = $pages;
- $content['pages'][$page-1]['selected'] = true;
- $content['btn'] = getPageButtons($content['pages']);
- $content['antibot'] = $antibot;
+ if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages)
+ && !empty($build_pages) && !in_array($page, $build_pages) )
+ continue;
- file_write($filename, Element('index.html', $content));
+ if ($config['try_smarter']) {
+ $antibot = create_antibot($board['uri'], 0 - $page);
+ $content['current_page'] = $page;
+ }
+ $antibot->reset();
+ $content['pages'] = $pages;
+ $content['pages'][$page-1]['selected'] = true;
+ $content['btn'] = getPageButtons($content['pages']);
+ $content['antibot'] = $antibot;
+
+ file_write($filename, Element('index.html', $content));
+ }
+ else {
+ file_unlink($filename);
+ file_unlink($jsonFilename);
+ }
}
- if ($page < $config['max_pages']) {
+ if (!$config['smart_build'] && $page < $config['max_pages']) {
for (;$page<=$config['max_pages'];$page++) {
$filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page));
file_unlink($filename);
@@ -1530,14 +1646,22 @@ function buildIndex() {
}
// json api catalog
- if ($config['api']['enabled']) {
- $json = json_encode($api->translateCatalog($catalog));
- $jsonFilename = $board['dir'] . 'catalog.json';
- file_write($jsonFilename, $json);
+ if ($config['api']['enabled'] && $global_api != "skip") {
+ if ($config['smart_build']) {
+ $jsonFilename = $board['dir'] . 'catalog.json';
+ file_unlink($jsonFilename);
+ $jsonFilename = $board['dir'] . 'threads.json';
+ file_unlink($jsonFilename);
+ }
+ else {
+ $json = json_encode($api->translateCatalog($catalog));
+ $jsonFilename = $board['dir'] . 'catalog.json';
+ file_write($jsonFilename, $json);
- $json = json_encode($api->translateCatalog($catalog, true));
- $jsonFilename = $board['dir'] . 'threads.json';
- file_write($jsonFilename, $json);
+ $json = json_encode($api->translateCatalog($catalog, true));
+ $jsonFilename = $board['dir'] . 'threads.json';
+ file_write($jsonFilename, $json);
+ }
}
if ($config['try_smarter'])
@@ -1739,6 +1863,15 @@ function markup(&$body, $track_cites = false) {
if (mysql_version() < 50503)
$body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8');
+ if ($config['markup_code']) {
+ $code_markup = array();
+ $body = preg_replace_callback($config['markup_code'], function($matches) use (&$code_markup) {
+ $d = count($code_markup);
+ $code_markup[] = $matches;
+ return "";
+ }, $body);
+ }
+
foreach ($config['markup'] as $markup) {
if (is_string($markup[1])) {
$body = preg_replace($markup[0], $markup[1], $body);
@@ -1810,7 +1943,7 @@ function markup(&$body, $track_cites = false) {
if (isset($cited_posts[$cite])) {
$replacement = '' .
+ link_for(array('id' => $cite, 'thread' => $cited_posts[$cite])) . '#' . $cite . '">' .
'>>' . $cite .
'';
@@ -1876,12 +2009,12 @@ function markup(&$body, $track_cites = false) {
if (!empty($clauses)) {
$cited_posts[$_board] = array();
- $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' .
+ $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'] .
- ($cite['thread'] ? $cite['thread'] : $cite['id']) . '.html#' . $cite['id'];
+ link_for($cite) . '#' . $cite['id'];
}
}
@@ -1936,7 +2069,19 @@ function markup(&$body, $track_cites = false) {
$body = preg_replace('/\s+$/', '', $body);
$body = preg_replace("/\n/", '
', $body);
-
+
+ // Fix code markup
+ if ($config['markup_code']) {
+ foreach ($code_markup as $id => $val) {
+ $code = isset($val[2]) ? $val[2] : $val[1];
+ $code_lang = isset($val[2]) ? $val[1] : "";
+
+ $code = "".str_replace(array("\n","\t"), array("
"," "), htmlspecialchars($code))."
";
+
+ $body = str_replace("", $code, $body);
+ }
+ }
+
if ($config['markup_repair_tidy']) {
$tidy = new tidy();
$body = str_replace("\t", ' ', $body);
@@ -1954,10 +2099,10 @@ function markup(&$body, $track_cites = false) {
), 'utf8');
$body = str_replace("\n", '', $body);
}
-
+
// replace tabs with 8 spaces
$body = str_replace("\t", ' ', $body);
-
+
return $tracked_cites;
}
@@ -2029,51 +2174,62 @@ function buildThread($id, $return = false, $mod = false) {
cache::delete("thread_{$board['uri']}_{$id}");
}
- $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri']));
- $query->bindValue(':id', $id, PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ if ($config['try_smarter'] && !$mod)
+ $build_pages[] = thread_find_page($id);
- while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
- if (!isset($thread)) {
- $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
- } else {
- $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
+ if (!$config['smart_build'] || $return || $mod) {
+ $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri']));
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
+ if (!isset($thread)) {
+ $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
+ } else {
+ $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
+ }
}
- }
- // Check if any posts were found
- if (!isset($thread))
- error($config['error']['nonexistant']);
+ // Check if any posts were found
+ if (!isset($thread))
+ error($config['error']['nonexistant']);
- $hasnoko50 = $thread->postCount() >= $config['noko50_min'];
- $antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
+ $hasnoko50 = $thread->postCount() >= $config['noko50_min'];
+ $antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
- $body = Element('thread.html', array(
- 'board' => $board,
- 'thread' => $thread,
- 'body' => $thread->build(),
- 'config' => $config,
- 'id' => $id,
- 'mod' => $mod,
- 'hasnoko50' => $hasnoko50,
- 'isnoko50' => false,
- 'antibot' => $antibot,
- 'boardlist' => createBoardlist($mod),
- 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
- ));
-
- if ($config['try_smarter'] && !$mod)
- $build_pages[] = thread_find_page($id);
+ $body = Element('thread.html', array(
+ 'board' => $board,
+ 'thread' => $thread,
+ 'body' => $thread->build(),
+ 'config' => $config,
+ 'id' => $id,
+ 'mod' => $mod,
+ 'hasnoko50' => $hasnoko50,
+ 'isnoko50' => false,
+ 'antibot' => $antibot,
+ 'boardlist' => createBoardlist($mod),
+ 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
+ ));
- // json api
- if ($config['api']['enabled']) {
- $api = new Api();
- $json = json_encode($api->translateThread($thread));
+ // json api
+ if ($config['api']['enabled']) {
+ $api = new Api();
+ $json = json_encode($api->translateThread($thread));
+ $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json';
+ file_write($jsonFilename, $json);
+ }
+ }
+ else {
$jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json';
- file_write($jsonFilename, $json);
+ file_unlink($jsonFilename);
}
- if ($return) {
+ if ($config['smart_build'] && !$return && !$mod) {
+ $noko50fn = $board['dir'] . $config['dir']['res'] . link_for(array('id' => $id), true);
+ file_unlink($noko50fn);
+
+ file_unlink($board['dir'] . $config['dir']['res'] . link_for(array('id' => $id)));
+ } else if ($return) {
return $body;
} else {
$noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true);
@@ -2432,6 +2588,8 @@ function diceRoller($post) {
}
function slugify($post) {
+ global $config;
+
$slug = "";
if (isset($post['subject']) && $post['subject'])
@@ -2447,6 +2605,9 @@ function slugify($post) {
// Transliterate local characters like ΓΌ, I wonder how would it work for weird alphabets :^)
$slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug);
+ // Remove Tinyboard custom markup
+ $slug = preg_replace("/]+>.*?<\/tinyboard>/s", '', $slug);
+
// Downcase everything
$slug = strtolower($slug);
@@ -2459,8 +2620,8 @@ function slugify($post) {
// Strip dashes at the beginning and at the end
$slug = preg_replace('/^-|-$/', '', $slug);
- // Slug should be 200 characters long, at max
- $slug = substr($slug, 0, 200);
+ // Slug should be X characters long, at max (80?)
+ $slug = substr($slug, 0, $config['slug_max_size']);
// Slug is now ready
return $slug;
@@ -2478,17 +2639,26 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false)
$slug = false;
- if ($config['slugify'] && isset($post['thread']) && $post['thread']) {
+ if ($config['slugify'] && ( (isset($post['thread']) && $post['thread']) || !isset ($post['slug']) ) ) {
+ $cvar = "slug_".$b['uri']."_".$id;
if (!$thread) {
- // Oh fuck, we'd better optimize it ASAP
+ $slug = Cache::get($cvar);
- $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri']));
- $query->bindValue(':id', $id, PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ if ($slug === false) {
+ $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri']));
+ $query->bindValue(':id', $id, PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
- $thread = $query->fetch(PDO::FETCH_ASSOC);
+ $thread = $query->fetch(PDO::FETCH_ASSOC);
+
+ $slug = $thread['slug'];
+
+ Cache::set($cvar, $slug);
+ }
+ }
+ else {
+ $slug = $thread['slug'];
}
- $slug = $thread['slug'];
}
elseif ($config['slugify']) {
$slug = $post['slug'];
diff --git a/inc/image.php b/inc/image.php
index 7a68605d..291f3e2a 100644
--- a/inc/image.php
+++ b/inc/image.php
@@ -363,9 +363,10 @@ class ImageConvert extends ImageBase {
$this->height,
escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
- if (strpos($error, "known incorrect sRGB profile") === false) {
+ if (strpos($error, "known incorrect sRGB profile") === false &&
+ strpos($error, "iCCP: Not recognizing known sRGB profile that has been edited") === false) {
$this->destroy();
- error('Failed to resize image!', null, array('convert_error' => $error));
+ error(_('Failed to resize image!')." "._('Details: ').nl2br(htmlspecialchars($error)), null, array('convert_error' => $error));
}
if (!file_exists($this->temp)) {
$this->destroy();
diff --git a/inc/lib/geoip/GeoIPv6.dat b/inc/lib/geoip/GeoIPv6.dat
index 1c2658c5..c2f3f11b 100644
Binary files a/inc/lib/geoip/GeoIPv6.dat and b/inc/lib/geoip/GeoIPv6.dat differ
diff --git a/inc/lib/webm/README.md b/inc/lib/webm/README.md
index dc3394c9..d1c2a52a 100644
--- a/inc/lib/webm/README.md
+++ b/inc/lib/webm/README.md
@@ -30,6 +30,13 @@ If you have an [FFmpeg](https://www.ffmpeg.org/) binary on your server and you w
$config['webm']['ffmpeg_path'] = '/path/to/ffmeg';
$config['webm']['ffprobe_path'] = '/path/to/ffprobe';
+MP4 support
+-----------
+
+MP4 support is available only if you use FFmpeg thumbnailing (see above).
+
+ $config['allowed_ext_files'][] = 'mp4';
+
License
-------
diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php
index edd2c73a..0747b420 100644
--- a/inc/lib/webm/ffmpeg.php
+++ b/inc/lib/webm/ffmpeg.php
@@ -3,60 +3,63 @@
* ffmpeg.php
* A barebones ffmpeg based webm implementation for vichan.
*/
-
function get_webm_info($filename) {
global $board, $config;
-
$filename = escapeshellarg($filename);
$ffprobe = $config['webm']['ffprobe_path'];
$ffprobe_out = array();
$webminfo = array();
-
exec("$ffprobe -v quiet -print_format json -show_format -show_streams $filename", $ffprobe_out);
$ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1);
$webminfo['error'] = is_valid_webm($ffprobe_out);
-
if(empty($webminfo['error'])) {
$webminfo['width'] = $ffprobe_out['streams'][0]['width'];
$webminfo['height'] = $ffprobe_out['streams'][0]['height'];
+ $webminfo['duration'] = $ffprobe_out['format']['duration'];
}
-
return $webminfo;
}
-
function is_valid_webm($ffprobe_out) {
global $board, $config;
-
if (empty($ffprobe_out))
return array('code' => 1, 'msg' => $config['error']['genwebmerror']);
-
- if ($ffprobe_out['format']['format_name'] != 'matroska,webm')
- return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
-
+ $extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION);
+ if ($extension === 'webm') {
+ if ($ffprobe_out['format']['format_name'] != 'matroska,webm')
+ return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
+ } elseif ($extension === 'mp4') {
+ if ($ffprobe_out['streams'][0]['codec_name'] != 'h264' && $ffprobe_out['streams'][1]['codec_name'] != 'aac')
+ return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
+ } else {
+ return array('code' => 1, 'msg' => $config['error']['genwebmerror']);
+ }
if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio']))
return array('code' => 3, 'msg' => $config['error']['webmhasaudio']);
-
- if ($ffprobe_out['streams'][0]['codec_name'] != 'vp8')
- return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
-
if (empty($ffprobe_out['streams'][0]['width']) || (empty($ffprobe_out['streams'][0]['height'])))
return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
-
if ($ffprobe_out['format']['duration'] > $config['webm']['max_length'])
- return array('code' => 4, 'msg' => $config['error']['webmtoolong']);
+ return array('code' => 4, 'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length']));
}
-
-function make_webm_thumbnail($filename, $thumbnail, $width, $height) {
+function make_webm_thumbnail($filename, $thumbnail, $width, $height, $duration) {
global $board, $config;
-
$filename = escapeshellarg($filename);
- $thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you
+ $thumbnailfc = escapeshellarg($thumbnail); // Should be safe by default but you
// can never be too safe.
-
+ $width = escapeshellarg($width);
+ $height = escapeshellarg($height); // Same as above.
$ffmpeg = $config['webm']['ffmpeg_path'];
+ $ret = 0;
$ffmpeg_out = array();
-
- exec("$ffmpeg -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1");
-
- return count($ffmpeg_out);
+ exec("$ffmpeg -strict -2 -ss " . floor($duration / 2) . " -i $filename -v quiet -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnailfc 2>&1", $ffmpeg_out, $ret);
+ // Work around for https://trac.ffmpeg.org/ticket/4362
+ if (filesize($thumbnail) === 0) {
+ // try again with first frame
+ exec("$ffmpeg -y -strict -2 -ss 0 -i $filename -v quiet -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnailfc 2>&1", $ffmpeg_out, $ret);
+ clearstatcache();
+ // failed if no thumbnail size even if ret code 0, ffmpeg is buggy
+ if (filesize($thumbnail) === 0) {
+ $ret = 1;
+ }
+ }
+ return $ret;
}
diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php
index a5b7429b..15c6600d 100644
--- a/inc/lib/webm/posthandler.php
+++ b/inc/lib/webm/posthandler.php
@@ -1,27 +1,22 @@
has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') {
+ if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm' || $file->extension == 'mp4') {
if ($config['webm']['use_ffmpeg']) {
require_once dirname(__FILE__) . '/ffmpeg.php';
$webminfo = get_webm_info($file->file_path);
-
if (empty($webminfo['error'])) {
$file->width = $webminfo['width'];
$file->height = $webminfo['height'];
-
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
$file = webm_set_spoiler($file);
}
else {
$file = set_thumbnail_dimensions($post, $file);
$tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg';
-
- if(false == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight)) {
+ if(0 == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight, $webminfo['duration'])) {
$file->thumb = $file->file_id . '.jpg';
}
else {
@@ -37,7 +32,6 @@ function postHandler($post) {
require_once dirname(__FILE__) . '/videodata.php';
$videoDetails = videoData($file->file_path);
if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
-
// Set thumbnail
$thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm';
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
@@ -53,12 +47,10 @@ function postHandler($post) {
$file->thumb = 'file';
}
unset($videoDetails['frame']);
-
// Set width and height
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
$file->width = $videoDetails['width'];
$file->height = $videoDetails['height'];
-
if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
$file = set_thumbnail_dimensions($post, $file);
}
@@ -66,14 +58,11 @@ function postHandler($post) {
}
}
}
-
function set_thumbnail_dimensions($post,$file) {
global $board, $config;
-
$tn_dimensions = array();
$tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
$tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
-
if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
$file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height)));
$file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width)));
@@ -81,17 +70,13 @@ function set_thumbnail_dimensions($post,$file) {
$file->thumbwidth = $file->width;
$file->thumbheight = $file->height;
}
-
return $file;
}
-
function webm_set_spoiler($file) {
global $board, $config;
-
$file->thumb = 'spoiler';
$size = @getimagesize($config['spoiler_image']);
$file->thumbwidth = $size[0];
$file->thumbheight = $size[1];
-
return $file;
}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 79d1bf51..2c679b20 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -111,7 +111,7 @@ function mod_dashboard() {
$latest = unserialize($_COOKIE['update']);
} else {
$ctx = stream_context_create(array('http' => array('timeout' => 5)));
- if ($code = @file_get_contents('http://tinyboard.org/version.txt', 0, $ctx)) {
+ if ($code = @file_get_contents('http://engine.vichan.net/version.txt', 0, $ctx)) {
$ver = strtok($code, "\n");
if (preg_match('@^// v(\d+)\.(\d+)\.(\d+)\s*?$@', $ver, $matches)) {
@@ -120,7 +120,7 @@ function mod_dashboard() {
'major' => $matches[2],
'minor' => $matches[3]
);
- if (preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) {
+ if (preg_match('/(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) {
$current = array(
'massive' => (int) $matches[1],
'major' => (int) $matches[2],
@@ -1224,7 +1224,10 @@ function mod_move($originBoard, $postID) {
// create the new thread
$newID = post($post);
-
+
+ $op = $post;
+ $op['id'] = $newID;
+
if ($post['has_file']) {
// copy image
foreach ($post['files'] as $i => &$file) {
@@ -1357,14 +1360,14 @@ function mod_move($originBoard, $postID) {
buildIndex();
- header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) .
+ header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard) .
'#' . $botID, true, $config['redirect_http']);
} else {
deletePost($postID);
buildIndex();
openBoard($targetBoard);
- header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']);
+ header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']);
}
}
@@ -2498,10 +2501,14 @@ function mod_theme_configure($theme_name) {
$query->bindValue(':value', $_POST[$conf['name']]);
$query->execute() or error(db_error($query));
}
-
+
$query = prepare("INSERT INTO ``theme_settings`` VALUES(:theme, NULL, NULL)");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
+
+ // Clean cache
+ Cache::delete("themes");
+ Cache::delete("theme_settings_".$theme_name);
$result = true;
$message = false;
@@ -2549,11 +2556,15 @@ function mod_theme_uninstall($theme_name) {
if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']);
-
+
$query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
+ // Clean cache
+ Cache::delete("themes");
+ Cache::delete("theme_settings_".$theme);
+
header('Location: ?/themes', true, $config['redirect_http']);
}
diff --git a/js/ajax.js b/js/ajax.js
index 61d83df2..56f0df5c 100644
--- a/js/ajax.js
+++ b/js/ajax.js
@@ -115,17 +115,10 @@ $(window).ready(function() {
}
},
error: function(xhr, status, er) {
- // An error occured
- do_not_ajax = true;
- $(form).find('input[type="submit"]').each(function() {
- var $replacement = $('');
- $replacement.attr('name', $(this).attr('name'));
- $replacement.val(submit_txt);
- $(this)
- .after($replacement)
- .replaceWith($('').val(submit_txt));
- });
- $(form).submit();
+ console.log(xhr);
+ alert(_('The server took too long to submit your post. Your post was probably still submitted. If it wasn\'t, we might be experiencing issues right now -- please try your post again later. Error information: ') + "");
+ $(form).find('input[type="submit"]').val(submit_txt);
+ $(form).find('input[type="submit"]').removeAttr('disabled');
},
data: formData,
cache: false,
@@ -141,6 +134,7 @@ $(window).ready(function() {
};
setup_form($('form[name="post"]'));
$(window).on('quick-reply', function() {
+ $('form#quick-reply').off('submit');
setup_form($('form#quick-reply'));
});
});
diff --git a/js/catalog-search.js b/js/catalog-search.js
new file mode 100644
index 00000000..17a8edac
--- /dev/null
+++ b/js/catalog-search.js
@@ -0,0 +1,82 @@
+/*
+ * catalog-search.js
+ * - Search and filters threads when on catalog view
+ * - Optional shortcuts 's' and 'esc' to open and close the search.
+ *
+ * Usage:
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/comment-toolbar.js';
+ */
+if (active_page == 'catalog') {
+ onready(function () {
+ 'use strict';
+
+ // 'true' = enable shortcuts
+ var useKeybinds = true;
+
+ // trigger the search 400ms after last keystroke
+ var delay = 400;
+ var timeoutHandle;
+
+ //search and hide none matching threads
+ function filter(search_term) {
+ $('.replies').each(function () {
+ var subject = $(this).children('.intro').text().toLowerCase();
+ var comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase();
+ search_term = search_term.toLowerCase();
+
+ if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) {
+ $(this).parents('div[id="Grid"]>.mix').css('display', 'none');
+ } else {
+ $(this).parents('div[id="Grid"]>.mix').css('display', 'inline-block');
+ }
+ });
+ }
+
+ function searchToggle() {
+ var button = $('#catalog_search_button')[0];
+
+ if (!button.dataset.expanded) {
+ button.dataset.expanded = '1';
+ button.innerText = 'Close';
+ $('.catalog_search').append(' ');
+ $('#search_field').focus();
+ } else {
+ delete button.dataset.expanded;
+ button.innerText = 'Search';
+ $('.catalog_search').children().last().remove();
+ $('div[id="Grid"]>.mix').each(function () { $(this).css('display', 'inline-block'); });
+ }
+ }
+
+ $('.threads').before('[]');
+ $('#catalog_search_button').text('Search');
+
+ $('#catalog_search_button').on('click', searchToggle);
+ $('.catalog_search').on('keyup', 'input#search_field', function (e) {
+ window.clearTimeout(timeoutHandle);
+ timeoutHandle = window.setTimeout(filter, 400, e.target.value);
+ });
+
+ if (useKeybinds) {
+ // 's'
+ $('body').on('keydown', function (e) {
+ if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) {
+ e.preventDefault();
+ if ($('#search_field').length !== 0) {
+ $('#search_field').focus();
+ } else {
+ searchToggle();
+ }
+ }
+ });
+ // 'esc'
+ $('.catalog_search').on('keydown', 'input#search_field', function (e) {
+ if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) {
+ window.clearTimeout(timeoutHandle);
+ searchToggle();
+ }
+ });
+ }
+ });
+}
diff --git a/js/expand-video.js b/js/expand-video.js
index 79872510..08b474c1 100644
--- a/js/expand-video.js
+++ b/js/expand-video.js
@@ -204,13 +204,13 @@ function setupVideo(thumb, url) {
function setupVideosIn(element) {
var thumbs = element.querySelectorAll("a.file");
for (var i = 0; i < thumbs.length; i++) {
- if (/\.webm$/.test(thumbs[i].pathname)) {
+ if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
setupVideo(thumbs[i], thumbs[i].href);
} else {
var m = thumbs[i].search.match(/\bv=([^&]*)/);
if (m != null) {
var url = decodeURIComponent(m[1]);
- if (/\.webm$/.test(url)) setupVideo(thumbs[i], url);
+ if (/\.webm$|\.mp4$/.test(url)) setupVideo(thumbs[i], url);
}
}
}
diff --git a/js/favorites.js b/js/favorites.js
index e325e110..daf7b732 100644
--- a/js/favorites.js
+++ b/js/favorites.js
@@ -54,7 +54,6 @@ if (active_page == 'thread' || active_page == 'index') {
$(document).ready(function(){
var favorites = JSON.parse(localStorage.favorites);
var is_board_favorite = ~$.inArray(board_name, favorites);
- console.log(is_board_favorite);
$('header>h1').append('\u2605');
add_favorites();
diff --git a/js/file-selector.js b/js/file-selector.js
new file mode 100644
index 00000000..207a5ae9
--- /dev/null
+++ b/js/file-selector.js
@@ -0,0 +1,191 @@
+/*
+ * file-selector.js - Add support for drag and drop file selection, and paste from clipbboard on supported browsers.
+ *
+ * Usage:
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/file-selector.js';
+ */
+function init_file_selector(max_images) {
+
+$(document).ready(function () {
+ // add options panel item
+ if (window.Options && Options.get_tab('general')) {
+ Options.extend_tab('general', '');
+
+ $('#file-drag-drop>input').on('click', function() {
+ if ($('#file-drag-drop>input').is(':checked')) {
+ localStorage.file_dragdrop = 'true';
+ } else {
+ localStorage.file_dragdrop = 'false';
+ }
+ });
+
+ if (typeof localStorage.file_dragdrop === 'undefined') localStorage.file_dragdrop = 'true';
+ if (localStorage.file_dragdrop === 'true') $('#file-drag-drop>input').prop('checked', true);
+ }
+});
+
+// disabled by user, or incompatible browser.
+if (localStorage.file_dragdrop == 'false' || !(window.URL.createObjectURL && window.File))
+ return;
+
+// multipost not enabled
+if (typeof max_images == 'undefined') {
+ var max_images = 1;
+}
+
+$(' '+
+'').prependTo('#upload td');
+
+var files = [];
+$('#upload_file').remove(); // remove the original file selector
+$('.dropzone-wrap').css('user-select', 'none').show(); // let jquery add browser specific prefix
+
+function addFile(file) {
+ if (files.length == max_images)
+ return;
+
+ files.push(file);
+ addThumb(file);
+}
+
+function removeFile(file) {
+ files.splice(files.indexOf(file), 1);
+}
+
+function getThumbElement(file) {
+ return $('.tmb-container').filter(function(){return($(this).data('file-ref')==file);});
+}
+
+function addThumb(file) {
+
+ var fileName = (file.name.length < 24) ? file.name : file.name.substr(0, 22) + 'β¦';
+ var fileType = file.type.split('/')[0];
+ var fileExt = file.type.split('/')[1];
+ var $container = $('')
+ .addClass('tmb-container')
+ .data('file-ref', file)
+ .append(
+ $('').addClass('remove-btn').html('β'),
+ $('').addClass('file-tmb'),
+ $('').addClass('tmb-filename').html(fileName)
+ )
+ .appendTo('.file-thumbs');
+
+ var $fileThumb = $container.find('.file-tmb');
+ if (fileType == 'image') {
+ // if image file, generate thumbnail
+ var objURL = window.URL.createObjectURL(file);
+ $fileThumb.css('background-image', 'url('+ objURL +')');
+ } else {
+ $fileThumb.html('' + fileExt.toUpperCase() + '');
+ }
+}
+
+$(document).on('ajax_before_post', function (e, formData) {
+ for (var i=0; i 0) key += i + 1;
+ if (typeof files[i] === 'undefined') break;
+ formData.append(key, files[i]);
+ }
+});
+
+// clear file queue and UI on success
+$(document).on('ajax_after_post', function () {
+ files = [];
+ $('.file-thumbs').empty();
+});
+
+var dragCounter = 0;
+var dropHandlers = {
+ dragenter: function (e) {
+ e.stopPropagation();
+ e.preventDefault();
+
+ if (dragCounter === 0) $('.dropzone').addClass('dragover');
+ dragCounter++;
+ },
+ dragover: function (e) {
+ // needed for webkit to work
+ e.stopPropagation();
+ e.preventDefault();
+ },
+ dragleave: function (e) {
+ e.stopPropagation();
+ e.preventDefault();
+
+ dragCounter--;
+ if (dragCounter === 0) $('.dropzone').removeClass('dragover');
+ },
+ drop: function (e) {
+ e.stopPropagation();
+ e.preventDefault();
+
+ $('.dropzone').removeClass('dragover');
+ dragCounter = 0;
+
+ var fileList = e.originalEvent.dataTransfer.files;
+ for (var i=0; i');
+
+ $fileSelector.on('change', function (e) {
+ if (this.files.length > 0) {
+ for (var i=0; i "+_('Forced anonymity')+"");
+ Options.extend_tab("general", "");
}
else {
selector = '#forced-anon';
diff --git a/js/gallery-view.js b/js/gallery-view.js
new file mode 100644
index 00000000..2d7d85b4
--- /dev/null
+++ b/js/gallery-view.js
@@ -0,0 +1,165 @@
+if (active_page == 'index' || active_page == 'thread')
+$(function(){
+
+ var gallery_view = false;
+
+ $('hr:first').before('');
+ $('#gallery-view a').html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode")).click(function() {
+ gallery_view = !gallery_view;
+ $(this).html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode"));
+ toggle_gview(document);
+ });
+
+ var toggle_gview = function(elem) {
+ if (gallery_view) {
+ $(elem).find('img.post-image').parent().each(function() {
+ this.oldonclick = this.onclick;
+ this.onclick = handle_click;
+ $(this).attr('data-galid', Math.random());
+ });
+ }
+ else {
+ $(elem).find('img.post-image').parent().each(function() {
+ if (this.onclick == handle_click) this.onclick = this.oldonclick;
+ });
+ }
+ };
+
+ $(document).on('new_post', toggle_gview);
+
+ var gallery_opened = false;
+
+ var handle_click = function(e) {
+ e.stopPropagation();
+ e.preventDefault();
+
+ if (!gallery_opened) open_gallery();
+
+ gallery_setimage($(this).attr('data-galid'));
+ };
+
+ var handler, images, active, toolbar;
+
+ var open_gallery = function() {
+ $('body').css('overflow', 'hidden');
+
+ gallery_opened = true;
+
+ handler = $("").hide().appendTo('body').css('text-align', 'left');
+
+ $("").click(close_gallery).appendTo(handler);
+
+ images = $("").appendTo(handler);
+ toolbar = $("").appendTo(handler);
+ active = $("").appendTo(handler);
+
+ active.on('click', function() {
+ close_gallery();
+ });
+
+ $('img.post-image').parent().each(function() {
+ var thumb = $(this).find('img').attr('src');
+
+ var i = $('').appendTo(images);
+ i.attr('src', thumb);
+ i.attr('data-galid-th', $(this).attr('data-galid'));
+
+ i.on('click', function(e) {
+ gallery_setimage($(this).attr('data-galid-th'));
+ });
+ });
+
+ $(" ")
+ .click(close_gallery).appendTo(toolbar);
+
+ $('body').on('keydown.gview', function(e) {
+ if (e.which == 39 || e.which == 40) { // right or down arrow
+ gallery_setimage(+1);
+ e.preventDefault();
+ }
+ else if (e.which == 37 || e.which == 38) { // left or up arrow
+ gallery_setimage(-1);
+ e.preventDefault();
+ }
+ });
+
+ handler.fadeIn(400);
+ };
+
+ var gallery_setimage = function(a) {
+ if (a == +1 || a == -1) {
+ var meth = (a == -1) ? 'prev' : 'next';
+ a = $('#gallery_images img.active')[meth]().attr('data-galid-th');
+ if (!a) return;
+ }
+
+ $('#gallery_images img.active').removeClass('active');
+
+ var thumb = $('#gallery_images [data-galid-th="'+a+'"]');
+ var elem = $('a[data-galid="'+a+'"]');
+
+ thumb.addClass('active');
+
+ var topscroll = thumb.position().top + images.scrollTop();
+ topscroll -= images.height() / 2;
+ topscroll += thumb.height() / 2;
+ images.animate({'scrollTop': topscroll}, 300);
+
+ var img = elem.attr('href');
+
+ active.find('img, video').fadeOut(200, function() { $(this).remove(); });
+
+ var i;
+ if (img.match(/player\.php/)) {
+ img = img.replace(/.*player\.php\?v=|&t=.*/g, '');
+ }
+ if (img.match(/\.webm$|\.mp4$|\.ogv$/i)) { // We are handling video nao
+ i = $('