From bdb05b16d84115067acfce2e9e53c699521bc69c Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sat, 21 May 2011 15:21:45 +1000
Subject: [PATCH] Automatically check for Tinyboard updates
---
inc/config.php | 9 ++++++-
inc/display.php | 10 ++++----
inc/functions.php | 8 ++++++-
mod.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+), 7 deletions(-)
diff --git a/inc/config.php b/inc/config.php
index 800996c5..7fa9da2d 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -26,8 +26,12 @@
'custom_capcode' => Array(),
'dnsbl' => Array()
);
- // Database stuff
+ // Database stuff
+ // Automatically check if a newer version of Tinyboard is available when an administrator logs in
+ $config['check_updates'] = true;
+ // How often to check for updates
+ $config['check_updates_time'] = 43200; // 12 hours
// SQL driver ("mysql", "pgsql", "sqlite", "dblib", etc)
// http://www.php.net/manual/en/pdo.drivers.php
@@ -46,6 +50,9 @@
// Timeout duration in seconds (not all drivers support this)
$config['db']['timeout'] = 5;
+ // Shows some extra information at the bottom of pages. Good for debugging development.
+ // Also experimental.
+ $config['debug'] = false;
// Optional Memcached server for more cache/optimization (currently at debug state)
$config['memcached']['enabled'] = false;
diff --git a/inc/display.php b/inc/display.php
index 965356da..38ab67a6 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -342,9 +342,9 @@
$built .= ', ' . $this->filename . ')
' .
// Thumbnail
- '';
@@ -531,9 +531,9 @@
// JavaScript cite
''.$this->id.'' .
// Sticky
- ($this->sticky ? '' : '') .
+ ($this->sticky ? '' : '') .
// Locked
- ($this->locked ? '' : '') .
+ ($this->locked ? '' : '') .
// [Reply]
($index ? '[Reply]' : '') .
diff --git a/inc/functions.php b/inc/functions.php
index d3be5d1c..20118599 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -9,7 +9,7 @@
loadConfig();
function loadConfig() {
- global $board, $config, $__ip;
+ global $board, $config, $__ip, $debug;
require 'config.php';
if (file_exists('inc/instance-config.php')) {
@@ -19,6 +19,12 @@
require $board['dir'] . '/config.php';
}
+ if($config['debug']) {
+ if(!isset($debug))
+ $debug = Array('sql');
+ $debug['start'] = time();
+ }
+
if(!isset($config['url_stylesheet']))
$config['url_stylesheet'] = $config['root'] . 'style.css';
if(!isset($config['url_javascript']))
diff --git a/mod.php b/mod.php
index ce486525..4b62a434 100644
--- a/mod.php
+++ b/mod.php
@@ -82,6 +82,7 @@
'Administration' => '',
'Themes' => '',
'Search' => '',
+ 'Update' => '',
'Logout' => ''
);
@@ -155,6 +156,9 @@
if($mod['type'] >= $config['mod']['rebuild']) {
$fieldset['Administration'] .= '
Rebuild static files';
}
+ if($mod['type'] >= $config['mod']['rebuild'] && $config['memcached']['enabled']) {
+ $fieldset['Administration'] .= '
Clear cache';
+ }
if($mod['type'] >= $config['mod']['show_config']) {
$fieldset['Administration'] .= '
Show configuration';
}
@@ -173,6 +177,56 @@
'';
}
+ if($mod['type'] >= ADMIN && $config['check_updates']) {
+ if(!$version = @file_get_contents('.installed'))
+ error('Could not find current version! (Check .installed)');
+ if(isset($_SESSION['update']) && time() - $_SESSION['update']['time'] < $config['check_updates_time']) {
+ $latest = $_SESSION['update']['latest'];
+ } else {
+ $ctx = stream_context_create(array(
+ 'http' => array(
+ 'timeout' => 3
+ )
+ )
+ );
+ $latest = @file_get_contents('http://tinyboard.org/latest.txt', 0, $ctx);
+ if(preg_match('/^v(\d+)\.(\d)\.(\d+)$/', $latest, $m)) {
+ $newer = Array(
+ 'massive' => (int)$m[1],
+ 'major' => (int)$m[2],
+ 'minor' => (int)$m[3]
+ );
+ if(preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $version, $m)) {
+ $current = Array(
+ 'massive' => (int)$m[1],
+ 'major' => (int)$m[2],
+ 'minor' => (int)$m[3]
+ );
+ if(isset($m[4])) {
+ // Development versions are always ahead in the versioning numbers
+ $current['minor'] --;
+ }
+ }
+ // Check if it's newer
+ if( $newer['massive'] > $current['massive'] ||
+ $newer['major'] > $current['major'] ||
+ ($newer['massive'] == $current['massive'] &&
+ $newer['major'] == $current['major'] &&
+ $newer['minor'] > $current['minor']
+ )) {
+ $latest = $latest;
+ } else $latest = false;
+ } else $latest = false;
+
+ $_SESSION['update'] = Array('time' => time(), 'latest' => $latest);
+ }
+
+ if($latest) {
+ $latest = trim($latest);
+ $fieldset['Update'] .= '
A newer version of Tinyboard (' . $latest . ') is available! See http://tinyboard.org/ for download instructions.';
+ }
+ }
+
$fieldset['Logout'] .= '
Logout';
// TODO: Statistics, etc, in the dashboard.
@@ -1374,6 +1428,23 @@
'mod'=>true
)
);
+ } elseif(preg_match('/^\/flush$/', $query)) {
+ if($mod['type'] < $config['mod']['rebuild']) error($config['error']['noaccess']);
+ if(!$config['memcached']['enabled']) error('Memcached is not enabled.');
+
+ if($memcached->flush()) {
+ $body = 'Successfully invalidated all items in the cache.';
+ modLog('Cleared cache');
+ } else {
+ $body = $memcached->getResultMessage();
+ }
+
+ echo Element('page.html', Array(
+ 'config'=>$config,
+ 'title'=>'Flushed',
+ 'body'=>'
' . $body . '
',
+ 'mod'=>true
+ ));
} elseif(preg_match('/^\/rebuild$/', $query)) {
if($mod['type'] < $config['mod']['rebuild']) error($config['error']['noaccess']);