summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/functions.php')
-rw-r--r--inc/functions.php70
1 files changed, 51 insertions, 19 deletions
diff --git a/inc/functions.php b/inc/functions.php
index 4c3f6a4e..488a4117 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -28,8 +28,25 @@ register_shutdown_function('fatal_error_handler');
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')) {
+ bindtextdomain('tinyboard', './inc/locale');
+ bind_textdomain_codeset('tinyboard', 'UTF-8');
+ textdomain('tinyboard');
+ } else {
+ _bindtextdomain('tinyboard', './inc/locale');
+ _bind_textdomain_codeset('tinyboard', 'UTF-8');
+ _textdomain('tinyboard');
+ }
+}
+$current_locale = 'en';
+
+
function loadConfig() {
- global $board, $config, $__ip, $debug, $__version, $microtime_start;
+ global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale;
$error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
@@ -70,16 +87,43 @@ function loadConfig() {
$config[$key] = array();
}
- require 'inc/config.php';
if (!file_exists('inc/instance-config.php'))
$error('Tinyboard is not configured! Create inc/instance-config.php.');
+ // Initialize locale as early as possible
+
+ $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];
+ }
+
+ if ($config['locale'] != $current_locale) {
+ $current_locale = $config['locale'];
+ init_locale($config['locale'], $error);
+ }
+
+ require 'inc/config.php';
+
require 'inc/instance-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 (!isset($__version))
$__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false;
$config['version'] = $__version;
@@ -124,6 +168,9 @@ function loadConfig() {
if (!isset($config['dir']['static']))
$config['dir']['static'] = $config['root'] . 'static/';
+ if (!isset($config['image_blank']))
+ $config['image_blank'] = $config['dir']['static'] . 'blank.gif';
+
if (!isset($config['image_sticky']))
$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
if (!isset($config['image_locked']))
@@ -174,21 +221,6 @@ function loadConfig() {
if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m))
$_SERVER['REMOTE_ADDR'] = $m[2];
- if ($config['locale'] != 'en') {
- if (_setlocale(LC_ALL, $config['locale']) === false) {
- $error('The specified locale (' . $config['locale'] . ') does not exist on your platform!');
- }
- if (extension_loaded('gettext')) {
- bindtextdomain('tinyboard', './inc/locale');
- bind_textdomain_codeset('tinyboard', 'UTF-8');
- textdomain('tinyboard');
- } else {
- _bindtextdomain('tinyboard', './inc/locale');
- _bind_textdomain_codeset('tinyboard', 'UTF-8');
- _textdomain('tinyboard');
- }
- }
-
if ($config['syslog'])
openlog('tinyboard', LOG_ODELAY, LOG_SYSLOG); // open a connection to sysem logger
@@ -1057,7 +1089,7 @@ function clean() {
$query->execute() or error(db_error($query));
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
- deletePost($post['id']);
+ deletePost($post['id'], false, false);
}
}
@@ -1558,7 +1590,7 @@ function markup_url($matches) {
$markup_urls[] = $url;
$link = (object) array(
- 'href' => $url,
+ 'href' => $config['link_prefix'] . $url,
'text' => $url,
'rel' => 'nofollow',
'target' => '_blank',