small cleanup
This commit is contained in:
parent
6c3a52aaec
commit
abd65b0c8a
219
inc/cache.php
219
inc/cache.php
|
@ -1,112 +1,113 @@
|
||||||
<?php
|
<?php
|
||||||
class Cache {
|
|
||||||
private static $cache;
|
class Cache {
|
||||||
public static function init() {
|
private static $cache;
|
||||||
global $config;
|
public static function init() {
|
||||||
|
global $config;
|
||||||
switch($config['cache']['enabled']) {
|
|
||||||
case 'memcached':
|
switch($config['cache']['enabled']) {
|
||||||
self::$cache = new Memcached();
|
case 'memcached':
|
||||||
self::$cache->addServers($config['cache']['memcached']);
|
self::$cache = new Memcached();
|
||||||
break;
|
self::$cache->addServers($config['cache']['memcached']);
|
||||||
case 'php':
|
break;
|
||||||
self::$cache = Array();
|
case 'php':
|
||||||
break;
|
self::$cache = Array();
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
public static function get($key) {
|
|
||||||
global $config, $debug;
|
|
||||||
|
|
||||||
$key = $config['cache']['prefix'] . $key;
|
|
||||||
|
|
||||||
$data = false;
|
|
||||||
switch($config['cache']['enabled']) {
|
|
||||||
case 'memcached':
|
|
||||||
if(!self::$cache)
|
|
||||||
self::init();
|
|
||||||
$data = self::$cache->get($key);
|
|
||||||
break;
|
|
||||||
case 'apc':
|
|
||||||
$data = apc_fetch($key);
|
|
||||||
break;
|
|
||||||
case 'xcache':
|
|
||||||
$data = xcache_get($key);
|
|
||||||
break;
|
|
||||||
case 'php':
|
|
||||||
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// debug
|
|
||||||
if($data && $config['debug']) {
|
|
||||||
$debug['cached'][] = $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
public static function set($key, $value, $expires = false) {
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
$key = $config['cache']['prefix'] . $key;
|
|
||||||
|
|
||||||
if(!$expires)
|
|
||||||
$expires = $config['cache']['timeout'];
|
|
||||||
|
|
||||||
switch($config['cache']['enabled']) {
|
|
||||||
case 'memcached':
|
|
||||||
if(!self::$cache)
|
|
||||||
self::init();
|
|
||||||
self::$cache->set($key, $value, $expires);
|
|
||||||
break;
|
|
||||||
case 'apc':
|
|
||||||
apc_store($key, $value, $expires);
|
|
||||||
break;
|
|
||||||
case 'xcache':
|
|
||||||
xcache_set($key, $value, $expires);
|
|
||||||
break;
|
|
||||||
case 'php':
|
|
||||||
self::$cache[$key] = $value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function delete($key) {
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
$key = $config['cache']['prefix'] . $key;
|
|
||||||
|
|
||||||
switch($config['cache']['enabled']) {
|
|
||||||
case 'memcached':
|
|
||||||
if(!self::$cache)
|
|
||||||
self::init();
|
|
||||||
self::$cache->delete($key);
|
|
||||||
break;
|
|
||||||
case 'apc':
|
|
||||||
apc_delete($key);
|
|
||||||
break;
|
|
||||||
case 'xcache':
|
|
||||||
xcache_unset($key);
|
|
||||||
break;
|
|
||||||
case 'php':
|
|
||||||
unset(self::$cache[$key]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function flush() {
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
switch($config['cache']['enabled']) {
|
|
||||||
case 'memcached':
|
|
||||||
if(!self::$cache)
|
|
||||||
self::init();
|
|
||||||
return self::$cache->flush();
|
|
||||||
case 'apc':
|
|
||||||
return apc_clear_cache('user');
|
|
||||||
case 'php':
|
|
||||||
self::$cache[$key] = Array();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static function get($key) {
|
||||||
|
global $config, $debug;
|
||||||
|
|
||||||
|
$key = $config['cache']['prefix'] . $key;
|
||||||
|
|
||||||
|
$data = false;
|
||||||
|
switch($config['cache']['enabled']) {
|
||||||
|
case 'memcached':
|
||||||
|
if(!self::$cache)
|
||||||
|
self::init();
|
||||||
|
$data = self::$cache->get($key);
|
||||||
|
break;
|
||||||
|
case 'apc':
|
||||||
|
$data = apc_fetch($key);
|
||||||
|
break;
|
||||||
|
case 'xcache':
|
||||||
|
$data = xcache_get($key);
|
||||||
|
break;
|
||||||
|
case 'php':
|
||||||
|
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug
|
||||||
|
if($data && $config['debug']) {
|
||||||
|
$debug['cached'][] = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
public static function set($key, $value, $expires = false) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$key = $config['cache']['prefix'] . $key;
|
||||||
|
|
||||||
|
if(!$expires)
|
||||||
|
$expires = $config['cache']['timeout'];
|
||||||
|
|
||||||
|
switch($config['cache']['enabled']) {
|
||||||
|
case 'memcached':
|
||||||
|
if(!self::$cache)
|
||||||
|
self::init();
|
||||||
|
self::$cache->set($key, $value, $expires);
|
||||||
|
break;
|
||||||
|
case 'apc':
|
||||||
|
apc_store($key, $value, $expires);
|
||||||
|
break;
|
||||||
|
case 'xcache':
|
||||||
|
xcache_set($key, $value, $expires);
|
||||||
|
break;
|
||||||
|
case 'php':
|
||||||
|
self::$cache[$key] = $value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static function delete($key) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$key = $config['cache']['prefix'] . $key;
|
||||||
|
|
||||||
|
switch($config['cache']['enabled']) {
|
||||||
|
case 'memcached':
|
||||||
|
if(!self::$cache)
|
||||||
|
self::init();
|
||||||
|
self::$cache->delete($key);
|
||||||
|
break;
|
||||||
|
case 'apc':
|
||||||
|
apc_delete($key);
|
||||||
|
break;
|
||||||
|
case 'xcache':
|
||||||
|
xcache_unset($key);
|
||||||
|
break;
|
||||||
|
case 'php':
|
||||||
|
unset(self::$cache[$key]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static function flush() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
switch($config['cache']['enabled']) {
|
||||||
|
case 'memcached':
|
||||||
|
if(!self::$cache)
|
||||||
|
self::init();
|
||||||
|
return self::$cache->flush();
|
||||||
|
case 'apc':
|
||||||
|
return apc_clear_cache('user');
|
||||||
|
case 'php':
|
||||||
|
self::$cache[$key] = Array();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,10 @@
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
global $board, $config, $__ip, $debug, $__version;
|
global $board, $config, $__ip, $debug, $__version;
|
||||||
|
|
||||||
|
$error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
|
||||||
|
|
||||||
reset_events();
|
reset_events();
|
||||||
|
|
||||||
if(!defined('PHP_VERSION_ID')) {
|
|
||||||
$version = explode('.', PHP_VERSION);
|
|
||||||
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($_SERVER['REMOTE_ADDR']))
|
if(!isset($_SERVER['REMOTE_ADDR']))
|
||||||
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
||||||
|
|
||||||
|
@ -33,9 +30,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
require 'inc/config.php';
|
require 'inc/config.php';
|
||||||
if (file_exists('inc/instance-config.php')) {
|
if(!file_exists('inc/instance-config.php'))
|
||||||
require 'inc/instance-config.php';
|
$error('Tinyboard is not configured! Create inc/instance-config.php.');
|
||||||
}
|
|
||||||
|
require 'inc/instance-config.php';
|
||||||
|
|
||||||
if(isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
|
if(isset($board['dir']) && file_exists($board['dir'] . '/config.php')) {
|
||||||
require $board['dir'] . '/config.php';
|
require $board['dir'] . '/config.php';
|
||||||
}
|
}
|
||||||
|
@ -137,7 +136,6 @@
|
||||||
$_SERVER['REMOTE_ADDR'] = $m[2];
|
$_SERVER['REMOTE_ADDR'] = $m[2];
|
||||||
|
|
||||||
if(_setlocale(LC_ALL, $config['locale']) === false) {
|
if(_setlocale(LC_ALL, $config['locale']) === false) {
|
||||||
$error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
|
|
||||||
$error('The specified locale (' . $config['locale'] . ') does not exist on your platform!');
|
$error('The specified locale (' . $config['locale'] . ') does not exist on your platform!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,9 +191,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function _syslog($priority, $message) {
|
function _syslog($priority, $message) {
|
||||||
if( isset($_SERVER['REMOTE_ADDR']) &&
|
if(isset($_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'])) {
|
||||||
isset($_SERVER['REQUEST_METHOD']) &&
|
|
||||||
isset($_SERVER['REQUEST_URI'])) {
|
|
||||||
// CGI
|
// CGI
|
||||||
syslog($priority, $message . ' - client: ' . $_SERVER['REMOTE_ADDR'] . ', request: "' . $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . '"');
|
syslog($priority, $message . ' - client: ' . $_SERVER['REMOTE_ADDR'] . ', request: "' . $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . '"');
|
||||||
} else {
|
} else {
|
||||||
|
@ -203,52 +199,55 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadThemeConfig($_theme) {
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
if(!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Load theme information into $theme
|
|
||||||
include $config['dir']['themes'] . '/' . $_theme . '/info.php';
|
|
||||||
return $theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildTheme($theme, $action) {
|
|
||||||
global $config, $_theme;
|
|
||||||
$_theme = $theme;
|
|
||||||
|
|
||||||
$theme = loadThemeConfig($_theme);
|
|
||||||
|
|
||||||
if(file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
|
|
||||||
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
|
|
||||||
$theme['build_function']($action, themeSettings($_theme));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildThemes($action) {
|
function rebuildThemes($action) {
|
||||||
global $config, $_theme;
|
|
||||||
|
|
||||||
// List themes
|
// List themes
|
||||||
$query = query("SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
|
$query = query("SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
|
||||||
while($theme = $query->fetch()) {
|
while($theme = $query->fetch()) {
|
||||||
rebuildTheme($theme['theme'], $action);
|
rebuildTheme($theme['theme'], $action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadThemeConfig($_theme) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if(!file_exists($config['dir']['themes'] . '/' . $_theme . '/info.php'))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Load theme information into $theme
|
||||||
|
include $config['dir']['themes'] . '/' . $_theme . '/info.php';
|
||||||
|
|
||||||
|
return $theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildTheme($theme, $action) {
|
||||||
|
global $config, $_theme;
|
||||||
|
$_theme = $theme;
|
||||||
|
|
||||||
|
$theme = loadThemeConfig($_theme);
|
||||||
|
|
||||||
|
if(file_exists($config['dir']['themes'] . '/' . $_theme . '/theme.php')) {
|
||||||
|
require_once $config['dir']['themes'] . '/' . $_theme . '/theme.php';
|
||||||
|
|
||||||
|
$theme['build_function']($action, themeSettings($_theme));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function themeSettings($theme) {
|
function themeSettings($theme) {
|
||||||
$query = prepare("SELECT `name`, `value` FROM `theme_settings` WHERE `theme` = :theme AND `name` IS NOT NULL");
|
$query = prepare("SELECT `name`, `value` FROM `theme_settings` WHERE `theme` = :theme AND `name` IS NOT NULL");
|
||||||
$query->bindValue(':theme', $theme);
|
$query->bindValue(':theme', $theme);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$settings = Array();
|
$settings = Array();
|
||||||
while($s = $query->fetch()) {
|
while($s = $query->fetch()) {
|
||||||
$settings[$s['name']] = $s['value'];
|
$settings[$s['name']] = $s['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sprintf3($str, $vars, $delim = '%') {
|
function sprintf3($str, $vars, $delim = '%') {
|
||||||
$replaces = array();
|
$replaces = array();
|
||||||
foreach($vars as $k => $v) {
|
foreach($vars as $k => $v) {
|
||||||
|
|
Loading…
Reference in New Issue