forked from leftypol/leftypol
Merge branch 'config' into display-appeal-src-ip
This commit is contained in:
commit
5f1f7319a3
211 changed files with 697 additions and 494 deletions
157
inc/bans.php
157
inc/bans.php
|
@ -5,42 +5,44 @@ use Lifo\IP\CIDR;
|
|||
class Bans {
|
||||
static public function range_to_string($mask) {
|
||||
list($ipstart, $ipend) = $mask;
|
||||
|
||||
|
||||
if (!isset($ipend) || $ipend === false) {
|
||||
// Not a range. Single IP address.
|
||||
$ipstr = inet_ntop($ipstart);
|
||||
return $ipstr;
|
||||
}
|
||||
|
||||
if (strlen($ipstart) != strlen($ipend))
|
||||
|
||||
if (strlen($ipstart) != strlen($ipend)) {
|
||||
return '???'; // What the fuck are you doing, son?
|
||||
|
||||
}
|
||||
|
||||
$range = CIDR::range_to_cidr(inet_ntop($ipstart), inet_ntop($ipend));
|
||||
if ($range !== false)
|
||||
if ($range !== false) {
|
||||
return $range;
|
||||
|
||||
}
|
||||
|
||||
return '???';
|
||||
}
|
||||
|
||||
|
||||
private static function calc_cidr($mask) {
|
||||
$cidr = new CIDR($mask);
|
||||
$range = $cidr->getRange();
|
||||
|
||||
|
||||
return array(inet_pton($range[0]), inet_pton($range[1]));
|
||||
}
|
||||
|
||||
|
||||
public static function parse_time($str) {
|
||||
if (empty($str))
|
||||
return false;
|
||||
|
||||
|
||||
if (($time = @strtotime($str)) !== false)
|
||||
return $time;
|
||||
|
||||
|
||||
if (!preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?mon?t?h?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $str, $matches))
|
||||
return false;
|
||||
|
||||
|
||||
$expire = 0;
|
||||
|
||||
|
||||
if (isset($matches[2])) {
|
||||
// Years
|
||||
$expire += (int)$matches[2]*60*60*24*365;
|
||||
|
@ -69,14 +71,14 @@ class Bans {
|
|||
// Seconds
|
||||
$expire += (int)$matches[14];
|
||||
}
|
||||
|
||||
|
||||
return time() + $expire;
|
||||
}
|
||||
|
||||
|
||||
static public function parse_range($mask) {
|
||||
$ipstart = false;
|
||||
$ipend = false;
|
||||
|
||||
|
||||
if (preg_match('@^(\d{1,3}\.){1,3}([\d*]{1,3})?$@', $mask) && substr_count($mask, '*') == 1) {
|
||||
// IPv4 wildcard mask
|
||||
$parts = explode('.', $mask);
|
||||
|
@ -97,51 +99,52 @@ class Bans {
|
|||
list($ipv4, $bits) = explode('/', $mask);
|
||||
if ($bits > 32)
|
||||
return false;
|
||||
|
||||
|
||||
list($ipstart, $ipend) = self::calc_cidr($mask);
|
||||
} elseif (preg_match('@^[:a-z\d]+/\d+$@i', $mask)) {
|
||||
list($ipv6, $bits) = explode('/', $mask);
|
||||
if ($bits > 128)
|
||||
if ($bits > 128) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
list($ipstart, $ipend) = self::calc_cidr($mask);
|
||||
} else {
|
||||
if (($ipstart = @inet_pton($mask)) === false)
|
||||
return false;
|
||||
} elseif (($ipstart = @inet_pton($mask)) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return array($ipstart, $ipend);
|
||||
}
|
||||
|
||||
|
||||
static public function find($ip, $board = false, $get_mod_info = false) {
|
||||
global $config;
|
||||
|
||||
|
||||
$query = prepare('SELECT ``bans``.*' . ($get_mod_info ? ', `username`' : '') . ' FROM ``bans``
|
||||
' . ($get_mod_info ? 'LEFT JOIN ``mods`` ON ``mods``.`id` = `creator`' : '') . '
|
||||
WHERE
|
||||
(' . ($board !== false ? '(`board` IS NULL OR `board` = :board) AND' : '') . '
|
||||
(`ipstart` = :ip OR (:ip >= `ipstart` AND :ip <= `ipend`)))
|
||||
ORDER BY `expires` IS NULL, `expires` DESC');
|
||||
|
||||
|
||||
if ($board !== false)
|
||||
$query->bindValue(':board', $board, PDO::PARAM_STR);
|
||||
|
||||
|
||||
$query->bindValue(':ip', inet_pton($ip));
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
$ban_list = array();
|
||||
|
||||
|
||||
while ($ban = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($ban['expires'] && ($ban['seen'] || !$config['require_ban_view']) && $ban['expires'] < time()) {
|
||||
self::delete($ban['id']);
|
||||
} else {
|
||||
if ($ban['post'])
|
||||
if ($ban['post']) {
|
||||
$ban['post'] = json_decode($ban['post'], true);
|
||||
}
|
||||
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
|
||||
$ban_list[] = $ban;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $ban_list;
|
||||
}
|
||||
|
||||
|
@ -149,16 +152,18 @@ class Bans {
|
|||
$query = query("SELECT ``bans``.*, `username` FROM ``bans``
|
||||
LEFT JOIN ``mods`` ON ``mods``.`id` = `creator`
|
||||
ORDER BY `created` DESC") or error(db_error());
|
||||
$bans = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
$bans = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($board_access && $board_access[0] == '*') $board_access = false;
|
||||
if ($board_access && $board_access[0] == '*') {
|
||||
$board_access = false;
|
||||
}
|
||||
|
||||
$out ? fputs($out, "[") : print("[");
|
||||
|
||||
$end = end($bans);
|
||||
|
||||
foreach ($bans as &$ban) {
|
||||
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
|
||||
foreach ($bans as &$ban) {
|
||||
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
|
||||
|
||||
$hide_message = false;
|
||||
foreach ($hide_regexes as $regex) {
|
||||
|
@ -182,7 +187,7 @@ class Bans {
|
|||
$ban['single_addr'] = true;
|
||||
}
|
||||
if ($filter_staff || ($board_access !== false && !in_array($ban['board'], $board_access))) {
|
||||
$ban['username'] = '?';
|
||||
$ban['username'] = '?';
|
||||
}
|
||||
if ($filter_ips || ($board_access !== false && !in_array($ban['board'], $board_access))) {
|
||||
@list($ban['mask'], $subnet) = explode("/", $ban['mask']);
|
||||
|
@ -204,24 +209,25 @@ class Bans {
|
|||
}
|
||||
}
|
||||
|
||||
$out ? fputs($out, "]") : print("]");
|
||||
$out ? fputs($out, "]") : print("]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static public function seen($ban_id) {
|
||||
$query = query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
rebuildThemes('bans');
|
||||
}
|
||||
|
||||
static public function purge() {
|
||||
$query = query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error());
|
||||
query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
rebuildThemes('bans');
|
||||
}
|
||||
|
||||
|
||||
static public function purge() {
|
||||
query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error());
|
||||
rebuildThemes('bans');
|
||||
}
|
||||
|
||||
static public function delete($ban_id, $modlog = false, $boards = false, $dont_rebuild = false) {
|
||||
global $config;
|
||||
|
||||
if ($boards && $boards[0] == '*') $boards = false;
|
||||
if ($boards && $boards[0] == '*') {
|
||||
$boards = false;
|
||||
}
|
||||
|
||||
if ($modlog) {
|
||||
$query = query("SELECT `ipstart`, `ipend`, `board` FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
|
@ -230,50 +236,55 @@ class Bans {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($boards !== false && !in_array($ban['board'], $boards))
|
||||
error($config['error']['noaccess']);
|
||||
|
||||
if ($boards !== false && !in_array($ban['board'], $boards)) {
|
||||
error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
$mask = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
|
||||
|
||||
|
||||
modLog("Removed ban #{$ban_id} for " .
|
||||
(filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/$mask\">$mask</a>" : $mask));
|
||||
}
|
||||
|
||||
|
||||
query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error());
|
||||
|
||||
if (!$dont_rebuild) rebuildThemes('bans');
|
||||
|
||||
if (!$dont_rebuild) {
|
||||
rebuildThemes('bans');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static public function new_ban($mask, $reason, $length = false, $ban_board = false, $mod_id = false, $post = false) {
|
||||
global $mod, $pdo, $board;
|
||||
|
||||
|
||||
if ($mod_id === false) {
|
||||
$mod_id = isset($mod['id']) ? $mod['id'] : -1;
|
||||
}
|
||||
|
||||
|
||||
$range = self::parse_range($mask);
|
||||
$mask = self::range_to_string($range);
|
||||
|
||||
|
||||
$query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)");
|
||||
|
||||
|
||||
$query->bindValue(':ipstart', $range[0]);
|
||||
if ($range[1] !== false && $range[1] != $range[0])
|
||||
if ($range[1] !== false && $range[1] != $range[0]) {
|
||||
$query->bindValue(':ipend', $range[1]);
|
||||
else
|
||||
} else {
|
||||
$query->bindValue(':ipend', null, PDO::PARAM_NULL);
|
||||
|
||||
}
|
||||
|
||||
$query->bindValue(':mod', $mod_id);
|
||||
$query->bindValue(':time', time());
|
||||
|
||||
|
||||
if ($reason !== '') {
|
||||
$reason = escape_markup_modifiers($reason);
|
||||
markup($reason);
|
||||
$query->bindValue(':reason', $reason);
|
||||
} else
|
||||
} else {
|
||||
$query->bindValue(':reason', null, PDO::PARAM_NULL);
|
||||
|
||||
}
|
||||
|
||||
if ($length) {
|
||||
if (is_int($length) || ctype_digit($length)) {
|
||||
$length = time() + $length;
|
||||
|
@ -284,20 +295,22 @@ class Bans {
|
|||
} else {
|
||||
$query->bindValue(':expires', null, PDO::PARAM_NULL);
|
||||
}
|
||||
|
||||
if ($ban_board)
|
||||
|
||||
if ($ban_board) {
|
||||
$query->bindValue(':board', $ban_board);
|
||||
else
|
||||
} else {
|
||||
$query->bindValue(':board', null, PDO::PARAM_NULL);
|
||||
|
||||
}
|
||||
|
||||
if ($post) {
|
||||
$post['board'] = $board['uri'];
|
||||
$query->bindValue(':post', json_encode($post));
|
||||
} else
|
||||
} else {
|
||||
$query->bindValue(':post', null, PDO::PARAM_NULL);
|
||||
|
||||
}
|
||||
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
if (isset($mod['id']) && $mod['id'] == $mod_id) {
|
||||
modLog('Created a new ' .
|
||||
($length > 0 ? preg_replace('/^(\d+) (\w+?)s?$/', '$1-$2', until($length)) : 'permanent') .
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
|
||||
/*
|
||||
* On top of the static file caching system, you can enable the additional caching system which is
|
||||
* designed to minimize SQL queries and can significantly increase speed when posting or using the
|
||||
* designed to minimize SQL queries and can significantly increase speed when posting or using the
|
||||
* moderator interface. APC is the recommended method of caching.
|
||||
*
|
||||
* http://tinyboard.org/docs/index.php?p=Config/Cache
|
||||
|
@ -209,22 +209,22 @@
|
|||
// http://www.projecthoneypot.org/httpbl.php
|
||||
// $config['dnsbl'][] = array('<your access key>.%.dnsbl.httpbl.org', function($ip) {
|
||||
// $octets = explode('.', $ip);
|
||||
//
|
||||
//
|
||||
// // days since last activity
|
||||
// if ($octets[1] > 14)
|
||||
// return false;
|
||||
//
|
||||
//
|
||||
// // "threat score" (http://www.projecthoneypot.org/threat_info.php)
|
||||
// if ($octets[2] < 5)
|
||||
// return false;
|
||||
//
|
||||
//
|
||||
// return true;
|
||||
// }, 'dnsbl.httpbl.org'); // hide our access key
|
||||
|
||||
// Skip checking certain IP addresses against blacklists (for troubleshooting or whatever)
|
||||
$config['dnsbl_exceptions'][] = '127.0.0.1';
|
||||
|
||||
// To prevent bump atacks; returns the thread to last position after the last post is deleted.
|
||||
// To prevent bump atacks; returns the thread to last position after the last post is deleted.
|
||||
$config['anti_bump_flood'] = false;
|
||||
|
||||
/*
|
||||
|
@ -768,7 +768,7 @@
|
|||
* 'gd' PHP GD (default). Only handles the most basic image formats (GIF, JPEG, PNG).
|
||||
* GD is a prerequisite for Tinyboard no matter what method you choose.
|
||||
*
|
||||
* 'imagick' PHP's ImageMagick bindings. Fast and efficient, supporting many image formats.
|
||||
* 'imagick' PHP's ImageMagick bindings. Fast and efficient, supporting many image formats.
|
||||
* A few minor bugs. http://pecl.php.net/package/imagick
|
||||
*
|
||||
* 'convert' The command line version of ImageMagick (`convert`). Fixes most of the bugs in
|
||||
|
@ -1170,6 +1170,7 @@
|
|||
$config['error']['fileext'] = _('Unsupported image format.');
|
||||
$config['error']['noboard'] = _('Invalid board!');
|
||||
$config['error']['nonexistant'] = _('Thread specified does not exist.');
|
||||
$config['error']['nopost'] = _('Post specified does not exist.');
|
||||
$config['error']['locked'] = _('Thread locked. You may not reply at this time.');
|
||||
$config['error']['reply_hard_limit'] = _('Thread has reached its maximum reply limit.');
|
||||
$config['error']['image_hard_limit'] = _('Thread has reached its maximum image limit.');
|
||||
|
@ -1776,7 +1777,7 @@
|
|||
|
||||
// event_handler('post', function($post) {
|
||||
// // do something else
|
||||
//
|
||||
//
|
||||
// // return an error (reject post)
|
||||
// return 'Sorry, you cannot post that!';
|
||||
// });
|
||||
|
@ -1991,4 +1992,3 @@
|
|||
|
||||
//Logo location for themes
|
||||
$config['logo'] = 'static/logo.png';
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ function loadConfig() {
|
|||
require_once('tmp/cache/cache_config.php');
|
||||
}
|
||||
|
||||
if (isset($config['cache_config']) &&
|
||||
if (isset($config['cache_config']) &&
|
||||
$config['cache_config'] &&
|
||||
$config = Cache::get('config_' . $boardsuffix ) ) {
|
||||
$events = Cache::get('events_' . $boardsuffix );
|
||||
|
@ -76,7 +76,7 @@ function loadConfig() {
|
|||
else {
|
||||
$config = array();
|
||||
|
||||
reset_events();
|
||||
reset_events();
|
||||
|
||||
$arrays = array(
|
||||
'db',
|
||||
|
@ -309,7 +309,7 @@ function loadConfig() {
|
|||
else if (is_callable($config['anonymous'])){
|
||||
$config['anonymous'] = $config['anonymous']($boardsuffix);
|
||||
}
|
||||
|
||||
|
||||
if ($config['debug']) {
|
||||
if (!isset($debug)) {
|
||||
$debug = array(
|
||||
|
@ -350,7 +350,7 @@ function define_groups() {
|
|||
define($group_name, $group_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ksort($config['mod']['groups']);
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ function rebuildThemes($action, $boardname = false) {
|
|||
$config = $_config;
|
||||
$board = $_board;
|
||||
|
||||
// Reload the locale
|
||||
// Reload the locale
|
||||
if ($config['locale'] != $current_locale) {
|
||||
$current_locale = $config['locale'];
|
||||
init_locale($config['locale']);
|
||||
|
@ -409,7 +409,7 @@ function rebuildThemes($action, $boardname = false) {
|
|||
$config = $_config;
|
||||
$board = $_board;
|
||||
|
||||
// Reload the locale
|
||||
// Reload the locale
|
||||
if ($config['locale'] != $current_locale) {
|
||||
$current_locale = $config['locale'];
|
||||
init_locale($config['locale']);
|
||||
|
@ -561,7 +561,7 @@ function purge($uri) {
|
|||
global $config, $debug;
|
||||
|
||||
// Fix for Unicode
|
||||
$uri = rawurlencode($uri);
|
||||
$uri = rawurlencode($uri);
|
||||
|
||||
$noescape = "/!~*()+:";
|
||||
$noescape = preg_split('//', $noescape);
|
||||
|
@ -757,7 +757,7 @@ function listBoards($just_uri = false) {
|
|||
$boards[] = $board;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($config['cache']['enabled'])
|
||||
cache::set($cache_name, $boards);
|
||||
|
||||
|
@ -823,10 +823,10 @@ function displayBan($ban) {
|
|||
$post = new Thread($ban['post'], null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$denied_appeals = array();
|
||||
$pending_appeal = false;
|
||||
|
||||
|
||||
if ($config['ban_appeals']) {
|
||||
$query = query("SELECT `time`, `denied` FROM ``ban_appeals`` WHERE `ban_id` = " . (int)$ban['id']) or error(db_error());
|
||||
while ($ban_appeal = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
@ -837,7 +837,7 @@ function displayBan($ban) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Show banned page and exit
|
||||
die(
|
||||
Element('page.html', array(
|
||||
|
@ -862,7 +862,7 @@ function checkBan($board = false) {
|
|||
if (!isset($_SERVER['REMOTE_ADDR'])) {
|
||||
// Server misconfiguration
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event('check-ban', $board))
|
||||
return true;
|
||||
|
@ -877,7 +877,7 @@ function checkBan($board = false) {
|
|||
|
||||
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']);
|
||||
|
@ -906,9 +906,9 @@ function checkBan($board = false) {
|
|||
if (time() - $last_time_purged < $config['purge_bans'] )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Bans::purge();
|
||||
|
||||
|
||||
if ($config['cache']['enabled'])
|
||||
cache::set('purged_bans_last', time());
|
||||
}
|
||||
|
@ -965,7 +965,7 @@ function threadExists($id) {
|
|||
|
||||
function insertFloodPost(array $post) {
|
||||
global $board;
|
||||
|
||||
|
||||
$query = prepare("INSERT INTO ``flood`` VALUES (NULL, :ip, :board, :time, :posthash, :filehash, :isreply)");
|
||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
|
@ -1006,7 +1006,7 @@ function post(array $post) {
|
|||
$query->bindValue(':body', $post['body']);
|
||||
$query->bindValue(':body_nomarkup', $post['body_nomarkup']);
|
||||
$query->bindValue(':time', isset($post['time']) ? $post['time'] : time(), PDO::PARAM_INT);
|
||||
$query->bindValue(':password', $post['password']);
|
||||
$query->bindValue(':password', $post['password']);
|
||||
$query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
if ($post['op'] && $post['mod'] && isset($post['sticky']) && $post['sticky']) {
|
||||
|
@ -1186,7 +1186,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||
// Delete posts and maybe replies
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
event('delete', $post);
|
||||
|
||||
|
||||
$thread_id = $post['thread'];
|
||||
if (!$post['thread']) {
|
||||
// Delete thread HTML page
|
||||
|
@ -1287,7 +1287,7 @@ function clean($pid = false) {
|
|||
$query = prepare(sprintf("SELECT `id` AS `thread_id`, (SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri'], $board['uri']));
|
||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($post['reply_count'] < $config['early_404_replies']) {
|
||||
deletePost($post['thread_id'], false, false);
|
||||
|
@ -1326,7 +1326,7 @@ function index($page, $mod=false, $brief = false) {
|
|||
return false;
|
||||
|
||||
$threads = array();
|
||||
|
||||
|
||||
while ($th = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$thread = new Thread($th, $mod ? '?/' : $config['root'], $mod);
|
||||
|
||||
|
@ -1377,7 +1377,7 @@ function index($page, $mod=false, $brief = false) {
|
|||
$thread->omitted = $omitted['post_count'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
||||
$thread->omitted_images = $omitted['image_count'] - $num_images;
|
||||
}
|
||||
|
||||
|
||||
$threads[] = $thread;
|
||||
|
||||
if (!$brief) {
|
||||
|
@ -1594,7 +1594,7 @@ function checkMute() {
|
|||
// Not expired yet
|
||||
error(sprintf($config['error']['youaremuted'], $mute['time'] + $mutetime - time()));
|
||||
} else {
|
||||
// Already expired
|
||||
// Already expired
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1883,8 +1883,8 @@ function wordfilters(&$body) {
|
|||
|
||||
foreach ($config['wordfilters'] as $filter) {
|
||||
if (isset($filter[3]) && $filter[3]) {
|
||||
$refilter = $filter[0];
|
||||
if (strncmp($filter[0], "/", 1) !== 0)
|
||||
$refilter = $filter[0];
|
||||
if (strncmp($filter[0], "/", 1) !== 0)
|
||||
{
|
||||
$refilter = "/.*" . $filter[0] . "/";
|
||||
}
|
||||
|
@ -1895,8 +1895,8 @@ function wordfilters(&$body) {
|
|||
return $match;
|
||||
} else {
|
||||
if (isset($filter[2]) && $filter[2]) {
|
||||
$refilter = $filter[0];
|
||||
if (strncmp($filter[0], "/", 1) !== 0)
|
||||
$refilter = $filter[0];
|
||||
if (strncmp($filter[0], "/", 1) !== 0)
|
||||
{
|
||||
$refilter = "/.*" . $filter[0] . "/";
|
||||
}
|
||||
|
@ -1912,7 +1912,7 @@ function wordfilters(&$body) {
|
|||
}
|
||||
}
|
||||
, $body);
|
||||
} else {
|
||||
} else {
|
||||
if (isset($filter[2]) && $filter[2]) {
|
||||
if (is_callable($filter[1]))
|
||||
$body = preg_replace_callback($filter[0], $filter[1], $body);
|
||||
|
@ -1958,7 +1958,7 @@ function markup_url($matches) {
|
|||
'rel' => 'nofollow',
|
||||
'target' => '_blank',
|
||||
);
|
||||
|
||||
|
||||
event('markup-url', $link);
|
||||
$link = (array)$link;
|
||||
|
||||
|
@ -1993,7 +1993,7 @@ function newline_to_full_stop($body) {
|
|||
|
||||
function extract_modifiers($body) {
|
||||
$modifiers = array();
|
||||
|
||||
|
||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.*?)</tinyboard>@us', $body, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
if (preg_match('/^escape /', $match[1]))
|
||||
|
@ -2001,7 +2001,7 @@ function extract_modifiers($body) {
|
|||
$modifiers[$match[1]] = html_entity_decode($match[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $modifiers;
|
||||
}
|
||||
|
||||
|
@ -2024,10 +2024,10 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
global $board, $config, $markup_urls;
|
||||
|
||||
$modifiers = extract_modifiers($body);
|
||||
|
||||
|
||||
$body = preg_replace('@<tinyboard (?!escape )([\w\s]+)>(.+?)</tinyboard>@us', '', $body);
|
||||
$body = preg_replace('@<(tinyboard) escape ([\w\s]+)>@i', '<$1 $2>', $body);
|
||||
|
||||
|
||||
if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1') {
|
||||
return array();
|
||||
}
|
||||
|
@ -2069,7 +2069,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
error($config['error']['toomanylinks']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($config['markup_repair_tidy'])
|
||||
$body = str_replace(' ', ' ', $body);
|
||||
|
||||
|
@ -2093,21 +2093,21 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
|
||||
$skip_chars = 0;
|
||||
$body_tmp = $body;
|
||||
|
||||
|
||||
$search_cites = array();
|
||||
foreach ($cites as $matches) {
|
||||
$search_cites[] = '`id` = ' . $matches[2][0];
|
||||
}
|
||||
$search_cites = array_unique($search_cites);
|
||||
|
||||
|
||||
$query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' .
|
||||
implode(' OR ', $search_cites), $board['uri'])) or error(db_error());
|
||||
|
||||
|
||||
$cited_posts = array();
|
||||
while ($cited = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false;
|
||||
}
|
||||
|
||||
|
||||
foreach ($cites as $matches) {
|
||||
$cite = $matches[2][0];
|
||||
|
||||
|
@ -2140,34 +2140,34 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
|
||||
$skip_chars = 0;
|
||||
$body_tmp = $body;
|
||||
|
||||
|
||||
if (isset($cited_posts)) {
|
||||
// Carry found posts from local board >>X links
|
||||
foreach ($cited_posts as $cite => $thread) {
|
||||
$cited_posts[$cite] = $config['root'] . $board['dir'] . $config['dir']['res'] .
|
||||
($thread ? $thread : $cite) . '.html#' . $cite;
|
||||
}
|
||||
|
||||
|
||||
$cited_posts = array(
|
||||
$board['uri'] => $cited_posts
|
||||
);
|
||||
} else
|
||||
$cited_posts = array();
|
||||
|
||||
|
||||
$crossboard_indexes = array();
|
||||
$search_cites_boards = array();
|
||||
|
||||
|
||||
foreach ($cites as $matches) {
|
||||
$_board = $matches[2][0];
|
||||
$cite = @$matches[3][0];
|
||||
|
||||
|
||||
if (!isset($search_cites_boards[$_board]))
|
||||
$search_cites_boards[$_board] = array();
|
||||
$search_cites_boards[$_board][] = $cite;
|
||||
}
|
||||
|
||||
|
||||
$tmp_board = $board['uri'];
|
||||
|
||||
|
||||
foreach ($search_cites_boards as $_board => $search_cites) {
|
||||
$clauses = array();
|
||||
foreach ($search_cites as $cite) {
|
||||
|
@ -2176,7 +2176,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
$clauses[] = '`id` = ' . $cite;
|
||||
}
|
||||
$clauses = array_unique($clauses);
|
||||
|
||||
|
||||
if ($board['uri'] != $_board) {
|
||||
if (!openBoard($_board)){
|
||||
if (in_array($_board,array_keys($config['boards_alias']))){
|
||||
|
@ -2191,25 +2191,25 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
else {
|
||||
continue; // Unknown board
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($clauses)) {
|
||||
$cited_posts[$_board] = array();
|
||||
|
||||
|
||||
$query = query(sprintf('SELECT `thread`, `id`, `slug` FROM ``posts_%s`` WHERE ' .
|
||||
implode(' OR ', $clauses), $board['uri'])) or error(db_error());
|
||||
|
||||
|
||||
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] .
|
||||
link_for($cite) . '#' . $cite['id'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index'];
|
||||
}
|
||||
|
||||
|
||||
// Restore old board
|
||||
if ($board['uri'] != $tmp_board)
|
||||
openBoard($tmp_board);
|
||||
|
@ -2285,7 +2285,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||
$code = rtrim(ltrim($code, "\r\n"));
|
||||
|
||||
$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array(" ","	"), htmlspecialchars($code, ENT_COMPAT, "UTF-8", false))."</pre>";
|
||||
|
||||
|
||||
$body = str_replace("<code $id>", $code, $body);
|
||||
}
|
||||
}
|
||||
|
@ -2323,7 +2323,7 @@ function utf8tohtml($utf8) {
|
|||
}
|
||||
|
||||
function ordutf8($string, &$offset) {
|
||||
$code = ord(substr($string, $offset,1));
|
||||
$code = ord(substr($string, $offset,1));
|
||||
if ($code >= 128) { // otherwise 0xxxxxxx
|
||||
if ($code < 224)
|
||||
$bytesnumber = 2; // 110xxxxx
|
||||
|
@ -2387,7 +2387,7 @@ function buildThread($id, $return = false, $mod = false) {
|
|||
// Check if any posts were found
|
||||
if (!isset($thread))
|
||||
error($config['error']['nonexistant']);
|
||||
|
||||
|
||||
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
|
||||
$antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
|
||||
|
||||
|
@ -2438,16 +2438,16 @@ function buildThread($id, $return = false, $mod = false) {
|
|||
function buildThread50($id, $return = false, $mod = false, $thread = null, $antibot = false) {
|
||||
global $board, $config, $build_pages;
|
||||
$id = round($id);
|
||||
|
||||
|
||||
if ($antibot)
|
||||
$antibot->reset();
|
||||
|
||||
|
||||
if (!$thread) {
|
||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
||||
$num_images = 0;
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (!isset($thread)) {
|
||||
|
@ -2455,7 +2455,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||
} else {
|
||||
if ($post['files'])
|
||||
$num_images += $post['num_files'];
|
||||
|
||||
|
||||
$thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
|
||||
}
|
||||
}
|
||||
|
@ -2470,10 +2470,10 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||
SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
||||
$count->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||
$count->execute() or error(db_error($count));
|
||||
|
||||
|
||||
$c = $count->fetch();
|
||||
$thread->omitted = $c['num'] - $config['noko50_count'];
|
||||
|
||||
|
||||
$c = $count->fetch();
|
||||
$thread->omitted_images = $c['num'] - $num_images;
|
||||
}
|
||||
|
@ -2486,13 +2486,13 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||
$thread->omitted += count($allPosts) - count($thread->posts);
|
||||
foreach ($allPosts as $index => $post) {
|
||||
if ($index == count($allPosts)-count($thread->posts))
|
||||
break;
|
||||
break;
|
||||
if ($post->files)
|
||||
$thread->omitted_images += $post->num_files;
|
||||
}
|
||||
}
|
||||
|
||||
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
|
||||
$hasnoko50 = $thread->postCount() >= $config['noko50_min'];
|
||||
|
||||
$body = Element('thread.html', array(
|
||||
'board' => $board,
|
||||
|
@ -2506,7 +2506,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||
'antibot' => $mod ? false : ($antibot ? $antibot : create_antibot($board['uri'], $id)),
|
||||
'boardlist' => createBoardlist($mod),
|
||||
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
|
||||
));
|
||||
));
|
||||
|
||||
if ($return) {
|
||||
return $body;
|
||||
|
@ -2585,7 +2585,7 @@ function hcf($a, $b){
|
|||
$b = $a-$b;
|
||||
$a = $a-$b;
|
||||
}
|
||||
if ($b==(round($b/$a))*$a)
|
||||
if ($b==(round($b/$a))*$a)
|
||||
$gcd=$a;
|
||||
else {
|
||||
for ($i=round($a/2);$i;$i--) {
|
||||
|
@ -2880,7 +2880,7 @@ function process_filenames($file, $board_dir, $multiple, $i){
|
|||
|
||||
if ($multiple)
|
||||
$file['file_id'] .= "-$i";
|
||||
|
||||
|
||||
$file['file'] = $board_dir . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension'];
|
||||
$file['thumb'] = $board_dir . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']);
|
||||
return $file;
|
||||
|
|
|
@ -11,7 +11,7 @@ class Image {
|
|||
public $src, $format, $image, $size;
|
||||
public function __construct($src, $format = false, $size = false) {
|
||||
global $config;
|
||||
|
||||
|
||||
$this->src = $src;
|
||||
$this->format = $format;
|
||||
|
||||
|
@ -25,21 +25,21 @@ class Image {
|
|||
error(_('Unsupported file format: ') . $this->format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->image = new $classname($this, $size);
|
||||
|
||||
if (!$this->image->valid()) {
|
||||
$this->delete();
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
|
||||
|
||||
$this->size = (object)array('width' => $this->image->_width(), 'height' => $this->image->_height());
|
||||
if ($this->size->width < 1 || $this->size->height < 1) {
|
||||
$this->delete();
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function resize($extension, $max_width, $max_height) {
|
||||
global $config;
|
||||
|
||||
|
@ -63,16 +63,16 @@ class Image {
|
|||
error(_('Unsupported file format: ') . $extension);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$thumb = new $classname(false);
|
||||
$thumb->src = $this->src;
|
||||
$thumb->format = $this->format;
|
||||
$thumb->original_width = $this->size->width;
|
||||
$thumb->original_height = $this->size->height;
|
||||
|
||||
|
||||
$x_ratio = $max_width / $this->size->width;
|
||||
$y_ratio = $max_height / $this->size->height;
|
||||
|
||||
|
||||
if (($this->size->width <= $max_width) && ($this->size->height <= $max_height)) {
|
||||
$width = $this->size->width;
|
||||
$height = $this->size->height;
|
||||
|
@ -83,16 +83,16 @@ class Image {
|
|||
$width = ceil($y_ratio * $this->size->width);
|
||||
$height = $max_height;
|
||||
}
|
||||
|
||||
|
||||
$thumb->_resize($this->image->image, $width, $height);
|
||||
|
||||
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
|
||||
public function to($dst) {
|
||||
$this->image->to($dst);
|
||||
}
|
||||
|
||||
|
||||
public function delete() {
|
||||
file_unlink($this->src);
|
||||
}
|
||||
|
@ -115,26 +115,26 @@ class ImageGD {
|
|||
}
|
||||
|
||||
class ImageBase extends ImageGD {
|
||||
public $image, $src, $original, $original_width, $original_height, $width, $height;
|
||||
public $image, $src, $original, $original_width, $original_height, $width, $height;
|
||||
public function valid() {
|
||||
return (bool)$this->image;
|
||||
}
|
||||
|
||||
|
||||
public function __construct($img, $size = false) {
|
||||
if (method_exists($this, 'init'))
|
||||
$this->init();
|
||||
|
||||
|
||||
if ($size && $size[0] > 0 && $size[1] > 0) {
|
||||
$this->width = $size[0];
|
||||
$this->height = $size[1];
|
||||
}
|
||||
|
||||
|
||||
if ($img !== false) {
|
||||
$this->src = $img->src;
|
||||
$this->from();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function _width() {
|
||||
if (method_exists($this, 'width'))
|
||||
return $this->width();
|
||||
|
@ -157,7 +157,7 @@ class ImageBase extends ImageGD {
|
|||
$this->original = &$original;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
|
||||
|
||||
if (method_exists($this, 'resize'))
|
||||
$this->resize();
|
||||
else
|
||||
|
@ -200,31 +200,31 @@ class ImageImagick extends ImageBase {
|
|||
}
|
||||
public function resize() {
|
||||
global $config;
|
||||
|
||||
|
||||
if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '')) {
|
||||
$this->image = new Imagick();
|
||||
$this->image->setFormat('gif');
|
||||
|
||||
|
||||
$keep_frames = array();
|
||||
for ($i = 0; $i < $this->original->getNumberImages(); $i += floor($this->original->getNumberImages() / $config['thumb_keep_animation_frames']))
|
||||
$keep_frames[] = $i;
|
||||
|
||||
|
||||
$i = 0;
|
||||
$delay = 0;
|
||||
foreach ($this->original as $frame) {
|
||||
$delay += $frame->getImageDelay();
|
||||
|
||||
|
||||
if (in_array($i, $keep_frames)) {
|
||||
// $frame->scaleImage($this->width, $this->height, false);
|
||||
$frame->sampleImage($this->width, $this->height);
|
||||
$frame->setImagePage($this->width, $this->height, 0, 0);
|
||||
$frame->setImageDelay($delay);
|
||||
$delay = 0;
|
||||
|
||||
|
||||
$this->image->addImage($frame->getImage());
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->image = clone $this->original;
|
||||
$this->image->scaleImage($this->width, $this->height, false);
|
||||
|
@ -235,15 +235,15 @@ class ImageImagick extends ImageBase {
|
|||
|
||||
class ImageConvert extends ImageBase {
|
||||
public $width, $height, $temp, $gm = false, $gifsicle = false;
|
||||
|
||||
|
||||
public function init() {
|
||||
global $config;
|
||||
|
||||
|
||||
if ($config['thumb_method'] == 'gm' || $config['thumb_method'] == 'gm+gifsicle')
|
||||
$this->gm = true;
|
||||
if ($config['thumb_method'] == 'convert+gifsicle' || $config['thumb_method'] == 'gm+gifsicle')
|
||||
$this->gifsicle = true;
|
||||
|
||||
|
||||
$this->temp = false;
|
||||
}
|
||||
public function get_size($src, $try_gd_first = true) {
|
||||
|
@ -265,7 +265,7 @@ class ImageConvert extends ImageBase {
|
|||
if ($size) {
|
||||
$this->width = $size[0];
|
||||
$this->height = $size[1];
|
||||
|
||||
|
||||
$this->image = true;
|
||||
} else {
|
||||
// mark as invalid
|
||||
|
@ -274,7 +274,7 @@ class ImageConvert extends ImageBase {
|
|||
}
|
||||
public function to($src) {
|
||||
global $config;
|
||||
|
||||
|
||||
if (!$this->temp) {
|
||||
if ($config['strip_exif']) {
|
||||
if($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' .
|
||||
|
@ -306,16 +306,16 @@ class ImageConvert extends ImageBase {
|
|||
}
|
||||
public function resize() {
|
||||
global $config;
|
||||
|
||||
|
||||
if ($this->temp) {
|
||||
// remove old
|
||||
$this->destroy();
|
||||
}
|
||||
|
||||
|
||||
$this->temp = tempnam($config['tmp'], 'convert') . ($config['thumb_ext'] == '' ? '' : '.' . $config['thumb_ext']);
|
||||
|
||||
|
||||
$config['thumb_keep_animation_frames'] = (int)$config['thumb_keep_animation_frames'];
|
||||
|
||||
|
||||
if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
|
||||
if ($this->gifsicle) {
|
||||
if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " .
|
||||
|
@ -380,7 +380,7 @@ class ImageConvert extends ImageBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For when -auto-orient doesn't exist (older versions)
|
||||
static public function jpeg_exif_orientation($src, $exif = false) {
|
||||
if (!$exif) {
|
||||
|
@ -398,16 +398,16 @@ class ImageConvert extends ImageBase {
|
|||
// 8888
|
||||
// 88
|
||||
// 88
|
||||
|
||||
|
||||
return '-flop';
|
||||
case 3:
|
||||
|
||||
|
||||
// 88
|
||||
// 88
|
||||
// 8888
|
||||
// 88
|
||||
// 888888
|
||||
|
||||
|
||||
return '-flip -flop';
|
||||
case 4:
|
||||
// 88
|
||||
|
@ -415,31 +415,31 @@ class ImageConvert extends ImageBase {
|
|||
// 8888
|
||||
// 88
|
||||
// 888888
|
||||
|
||||
|
||||
return '-flip';
|
||||
case 5:
|
||||
// 8888888888
|
||||
// 88 88
|
||||
// 88
|
||||
|
||||
|
||||
return '-rotate 90 -flop';
|
||||
case 6:
|
||||
// 88
|
||||
// 88 88
|
||||
// 8888888888
|
||||
|
||||
|
||||
return '-rotate 90';
|
||||
case 7:
|
||||
// 88
|
||||
// 88 88
|
||||
// 8888888888
|
||||
|
||||
|
||||
return '-rotate "-90" -flop';
|
||||
case 8:
|
||||
// 8888888888
|
||||
// 88 88
|
||||
// 88
|
||||
|
||||
|
||||
return '-rotate "-90"';
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +497,11 @@ class ImageBMP extends ImageBase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class ImageWEBP extends ImageBase {
|
||||
public function from() {
|
||||
$this->image = @imagecreatefromwebp($this->src);
|
||||
}
|
||||
public function to($src) {
|
||||
imagewebp($this->image, $src);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,15 @@ $twig = false;
|
|||
|
||||
function load_twig() {
|
||||
global $twig, $config;
|
||||
|
||||
$cache_dir = "{$config['dir']['template']}/cache/";
|
||||
|
||||
$loader = new Twig_Loader_Filesystem($config['dir']['template']);
|
||||
$loader->setPaths($config['dir']['template']);
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'autoescape' => false,
|
||||
'cache' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')) ?
|
||||
"{$config['dir']['template']}/cache" : false,
|
||||
'cache' => is_writable('templates/') || (is_dir($cache_dir) && is_writable($cache_dir)) ?
|
||||
$cache_dir : false,
|
||||
'debug' => $config['debug']
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
|
||||
|
@ -27,17 +30,17 @@ function load_twig() {
|
|||
|
||||
function Element($templateFile, array $options) {
|
||||
global $config, $debug, $twig, $build_pages;
|
||||
|
||||
|
||||
if (!$twig)
|
||||
load_twig();
|
||||
|
||||
|
||||
if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) {
|
||||
$options['pm'] = create_pm_header();
|
||||
}
|
||||
|
||||
|
||||
if (isset($options['body']) && $config['debug']) {
|
||||
$_debug = $debug;
|
||||
|
||||
|
||||
if (isset($debug['start'])) {
|
||||
$_debug['time']['total'] = '~' . round((microtime(true) - $_debug['start']) * 1000, 2) . 'ms';
|
||||
$_debug['time']['init'] = '~' . round(($_debug['start_debug'] - $_debug['start']) * 1000, 2) . 'ms';
|
||||
|
@ -55,18 +58,17 @@ function Element($templateFile, array $options) {
|
|||
str_replace("\n", '<br/>', utf8tohtml(print_r($_debug, true))) .
|
||||
'</pre>';
|
||||
}
|
||||
|
||||
|
||||
// Read the template file
|
||||
if (@file_get_contents("{$config['dir']['template']}/${templateFile}")) {
|
||||
$body = $twig->render($templateFile, $options);
|
||||
|
||||
|
||||
if ($config['minify_html'] && preg_match('/\.html$/', $templateFile)) {
|
||||
$body = trim(preg_replace("/[\t\r\n]/", '', $body));
|
||||
}
|
||||
|
||||
|
||||
return $body;
|
||||
} else {
|
||||
throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue