summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/api.php35
-rw-r--r--inc/cache.php27
-rw-r--r--inc/config.php63
-rw-r--r--inc/display.php7
-rwxr-xr-xinc/functions.php676
-rw-r--r--inc/image.php5
-rw-r--r--inc/lib/geoip/GeoIPv6.datbin1127489 -> 1429913 bytes
-rw-r--r--inc/lib/webm/README.md7
-rw-r--r--inc/lib/webm/ffmpeg.php55
-rw-r--r--inc/lib/webm/posthandler.php19
-rw-r--r--inc/mod/pages.php25
11 files changed, 593 insertions, 326 deletions
diff --git a/inc/api.php b/inc/api.php
index c9608f06..57e4d367 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -33,6 +33,7 @@ class Api {
'sticky' => 'sticky',
'locked' => 'locked',
'bump' => 'last_modified',
+ 'embed' => 'embed',
);
$this->threadsPageFields = array(
@@ -85,11 +86,22 @@ class Api {
}
}
+ private function translateFile($file, $post, &$apiPost) {
+ $this->translateFields($this->fileFields, $file, $apiPost);
+ $apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.'));
+ $dotPos = strrpos($file->file, '.');
+ $apiPost['ext'] = substr($file->file, $dotPos);
+ $apiPost['tim'] = substr($file->file, 0, $dotPos);
+ $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ }
+
private function translatePost($post, $threadsPage = false) {
+ global $config, $board;
$apiPost = array();
$fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
$this->translateFields($fields, $post, $apiPost);
+ if (isset($config['poster_ids']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
if ($threadsPage) return $apiPost;
// Handle country field
@@ -104,16 +116,27 @@ class Api {
}
}
+ if ($config['slugify'] && !$post->thread) {
+ $apiPost['semantic_url'] = $post->slug;
+ }
+
// Handle files
// Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API.
if (isset($post->files) && $post->files && !$threadsPage) {
$file = $post->files[0];
- $this->translateFields($this->fileFields, $file, $apiPost);
- $apiPost['filename'] = substr($file->name, 0, strrpos($file->name, '.'));
- $dotPos = strrpos($file->file, '.');
- $apiPost['ext'] = substr($file->file, $dotPos);
- $apiPost['tim'] = substr($file->file, 0, $dotPos);
- $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ $this->translateFile($file, $post, $apiPost);
+ if (sizeof($post->files) > 1) {
+ $extra_files = array();
+ foreach ($post->files as $i => $f) {
+ if ($i == 0) continue;
+
+ $extra_file = array();
+ $this->translateFile($f, $post, $extra_file);
+
+ $extra_files[] = $extra_file;
+ }
+ $apiPost['extra_files'] = $extra_files;
+ }
}
return $apiPost;
diff --git a/inc/cache.php b/inc/cache.php
index d1200919..852aefa2 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -50,6 +50,17 @@ class Cache {
case 'php':
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
break;
+ case 'fs':
+ $key = str_replace('/', '::', $key);
+ $key = str_replace("\0", '', $key);
+ if (!file_exists('tmp/cache/'.$key)) {
+ $data = false;
+ }
+ else {
+ $data = file_get_contents('tmp/cache/'.$key);
+ $data = json_decode($data, true);
+ }
+ break;
case 'redis':
if (!self::$cache)
self::init();
@@ -87,6 +98,11 @@ class Cache {
case 'xcache':
xcache_set($key, $value, $expires);
break;
+ case 'fs':
+ $key = str_replace('/', '::', $key);
+ $key = str_replace("\0", '', $key);
+ file_put_contents('tmp/cache/'.$key, json_encode($value));
+ break;
case 'php':
self::$cache[$key] = $value;
break;
@@ -113,6 +129,11 @@ class Cache {
case 'xcache':
xcache_unset($key);
break;
+ case 'fs':
+ $key = str_replace('/', '::', $key);
+ $key = str_replace("\0", '', $key);
+ @unlink('tmp/cache/'.$key);
+ break;
case 'php':
unset(self::$cache[$key]);
break;
@@ -134,6 +155,12 @@ class Cache {
case 'php':
self::$cache = array();
break;
+ case 'fs':
+ $files = glob('tmp/cache/*');
+ foreach ($files as $file) {
+ unlink($file);
+ }
+ break;
case 'redis':
if (!self::$cache)
self::init();
diff --git a/inc/config.php b/inc/config.php
index ac4acaa4..d5bdbfe5 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -115,7 +115,7 @@
* http://tinyboard.org/docs/index.php?p=Config/Cache
*/
- $config['cache']['enabled'] = false;
+ $config['cache']['enabled'] = 'php';
// $config['cache']['enabled'] = 'xcache';
// $config['cache']['enabled'] = 'apc';
// $config['cache']['enabled'] = 'memcached';
@@ -137,6 +137,11 @@
// Tinyboard to use.
$config['cache']['redis'] = array('localhost', 6379, '', 1);
+ // EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot.
+ // If you have any lambdas/includes present in your config, you should move them to instance-functions.php
+ // (this file will be explicitly loaded during cache hit, but not during cache miss).
+ $config['cache_config'] = false;
+
/*
* ====================
* Cookie settings
@@ -277,7 +282,8 @@
'file_url',
'json_response',
'user_flag',
- 'no_country'
+ 'no_country',
+ 'tag'
);
// Enable reCaptcha to make spam even harder. Rarely necessary.
@@ -290,6 +296,12 @@
// Ability to lock a board for normal users and still allow mods to post. Could also be useful for making an archive board
$config['board_locked'] = false;
+ // If poster's proxy supplies X-Forwarded-For header, check if poster's real IP is banned.
+ $config['proxy_check'] = false;
+
+ // If poster's proxy supplies X-Forwarded-For header, save it for further inspection and/or filtering.
+ $config['proxy_save'] = false;
+
/*
* Custom filters detect certain posts and reject/ban accordingly. They are made up of a condition and an
* action (for when ALL conditions are met). As every single post has to be put through each filter,
@@ -538,6 +550,9 @@
// When true, the sage won't be displayed
$config['hide_sage'] = false;
+ // Don't display user's email when it's not "sage"
+ $config['hide_email'] = false;
+
// Attach country flags to posts.
$config['country_flags'] = false;
@@ -570,6 +585,9 @@
// Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html
$config['slugify'] = false;
+ // Max size for slugs
+ $config['slug_max_size'] = 80;
+
/*
* ====================
* Ban settings
@@ -610,13 +628,10 @@
$config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>");
- // Highlight PHP code wrapped in <code> tags (PHP 5.3+)
- // $config['markup'][] = array(
- // '/^&lt;code&gt;(.+)&lt;\/code&gt;/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 @@
'<object style="float: left;margin: 10px 20px;" width="%%tb_width%%" height="%%tb_height%%"><param name="movie" value="http://www.dailymotion.com/swf/video/$2"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/$2" width="%%tb_width%%" height="%%tb_height%%" wmode="transparent" allowfullscreen="true" allowscriptaccess="always"></object>'
),
array(
- '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?.+)?$/i',
+ '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?[^\'"<>]+)?$/i',
'<div style="float:left;margin:10px 20px;width:%%tb_width%%px;height:%%tb_height%%px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/$2/$3.swf" width="%%tb_width%%" height="%%tb_height%%" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_$2" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></div>'
),
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'] = '<div class="video-container" data-video="$2">'.
- '<a href="$0" target="_blank" class="file">'.
+ '<a href="https://youtu.be/$2" target="_blank" class="file">'.
'<img style="width:360px;height:270px;" src="//img.youtube.com/vi/$2/0.jpg" class="post-image"/>'.
'</a></div>';
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')) {
+ if (file_exists($fn = 'tmp/cache/locale_' . $boardsuffix ) ) {
+ $config['locale'] = file_get_contents($fn);
+ }
+ else {
+ $config['locale'] = 'en';
+
+ $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];
+ }
+
+ file_put_contents($fn, $config['locale']);
}
- $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];
- }
- if ($config['locale'] != $current_locale) {
- $current_locale = $config['locale'];
- init_locale($config['locale'], $error);
- }
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
- require 'inc/config.php';
+ require 'inc/config.php';
- require 'inc/instance-config.php';
+ require 'inc/instance-config.php';
- if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
- require $board['dir'] . '/config.php';
- }
+ if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
+ require $board['dir'] . '/config.php';
+ }
- if ($config['locale'] != $current_locale) {
- $current_locale = $config['locale'];
- init_locale($config['locale'], $error);
- }
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
- date_default_timezone_set($config['timezone']);
+ if (!isset($config['global_message']))
+ $config['global_message'] = false;
- 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['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['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['dir']['static']))
- $config['dir']['static'] = $config['root'] . 'static/';
+ 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['image_blank']))
- $config['image_blank'] = $config['dir']['static'] . 'blank.gif';
+ 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['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_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_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_stylesheets']))
+ $config['uri_stylesheets'] = $config['root'] . 'stylesheets/';
- 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['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($config['uri_stylesheets']))
- $config['uri_stylesheets'] = $config['root'] . 'stylesheets/';
+ if (!isset($__version))
+ $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
+ $config['version'] = $__version;
- 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['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', '<?php '.
+ '$config = array();'.
+ '$config[\'cache\'] = '.var_export($config['cache'], true).';'.
+ '$config[\'cache_config\'] = true;'.
+ '$config[\'debug\'] = '.var_export($config['debug'], true).';'.
+ 'require_once(\'inc/cache.php\');'
+ );
+
+ $config['cache_config_loaded'] = true;
+
+ Cache::set('config_'.$boardsuffix, $config);
+ Cache::set('events_'.$boardsuffix, $events);
}
if (is_array($config['anonymous']))
$config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])];
-
- if ($config['allow_roll'])
- event_handler('post', 'diceRoller');
-
- event('load-config');
if ($config['debug']) {
if (!isset($debug)) {
@@ -328,8 +385,12 @@ function verbose_error_handler($errno, $errstr, $errfile, $errline) {
function define_groups() {
global $config;
- foreach ($config['mod']['groups'] as $group_value => $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());
+
+ $themes = array();
+
+ while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
+ $themes[] = $theme;
+ }
- while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
+ 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;
+
+ 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));
+ 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 "<code $d>";
+ }, $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 = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
$config['root'] . $board['dir'] . $config['dir']['res'] .
- ($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' .
+ link_for(array('id' => $cite, 'thread' => $cited_posts[$cite])) . '#' . $cite . '">' .
'&gt;&gt;' . $cite .
'</a>';
@@ -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/", '<br/>', $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 = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code))."</pre>";
+
+ $body = str_replace("<code $id>", $code, $body);
+ }
+ }
+
if ($config['markup_repair_tidy']) {
$tidy = new tidy();
$body = str_replace("\t", '&#09;', $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);
-
- $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'])
- ));
+ $hasnoko50 = $thread->postCount() >= $config['noko50_min'];
+ $antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
- 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 [^>]+>.*?<\/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
--- a/inc/lib/geoip/GeoIPv6.dat
+++ b/inc/lib/geoip/GeoIPv6.dat
Binary files 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 @@
<?php
// Glue code for handling a Tinyboard post.
// Portions of this file are derived from Tinyboard code.
-
function postHandler($post) {
global $board, $config;
-
- if ($post->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']);
}