Browse Source

Automatically check for Tinyboard updates

pull/40/head
Savetheinternet 12 years ago
parent
commit
bdb05b16d8
  1. 9
      inc/config.php
  2. 10
      inc/display.php
  3. 8
      inc/functions.php
  4. 71
      mod.php

9
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;

10
inc/display.php

@ -342,9 +342,9 @@
$built .= ', ' . $this->filename . ')</span></p>' .
// Thumbnail
'<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
'<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" alt="" /></a>';
} elseif($this->file == 'deleted') {
$built .= '<img src="' . $config['image_deleted'] . '" />';
$built .= '<img src="' . $config['image_deleted'] . '" alt="" />';
}
$built .= $this->postControls();
@ -485,7 +485,7 @@
// Filename
$built .= ', ' . $this->filename . ')</span></p>' .
// Thumbnail
'<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
'<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" alt="" /></a>';
}
$built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
@ -531,9 +531,9 @@
// JavaScript cite
'<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
// Sticky
($this->sticky ? '<img class="icon" title="Sticky" src="' . $config['image_sticky'] . '" />' : '') .
($this->sticky ? '<img class="icon" title="Sticky" src="' . $config['image_sticky'] . '" alt="Sticky" />' : '') .
// Locked
($this->locked ? '<img class="icon" title="Locked" src="' . $config['image_locked'] . '" />' : '') .
($this->locked ? '<img class="icon" title="Locked" src="' . $config['image_locked'] . '" alt="Locked" />' : '') .
// [Reply]
($index ? '<a href="' . $this->root . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $this->id) . '">[Reply]</a>' : '') .

8
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']))

71
mod.php

@ -82,6 +82,7 @@
'Administration' => '',
'Themes' => '',
'Search' => '',
'Update' => '',
'Logout' => ''
);
@ -155,6 +156,9 @@
if($mod['type'] >= $config['mod']['rebuild']) {
$fieldset['Administration'] .= '<li><a href="?/rebuild">Rebuild static files</a></li>';
}
if($mod['type'] >= $config['mod']['rebuild'] && $config['memcached']['enabled']) {
$fieldset['Administration'] .= '<li><a href="?/flush">Clear cache</a></li>';
}
if($mod['type'] >= $config['mod']['show_config']) {
$fieldset['Administration'] .= '<li><a href="?/config">Show configuration</a></li>';
}
@ -173,6 +177,56 @@
'</li>';
}
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'] .= '<li>A newer version of Tinyboard (<strong>' . $latest . '</strong>) is available! See <a href="http://tinyboard.org">http://tinyboard.org/</a> for download instructions.</li>';
}
}
$fieldset['Logout'] .= '<li><a href="?/logout">Logout</a></li>';
// 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'=>'<p style="text-align:center">' . $body . '</p>',
'mod'=>true
));
} elseif(preg_match('/^\/rebuild$/', $query)) {
if($mod['type'] < $config['mod']['rebuild']) error($config['error']['noaccess']);

Loading…
Cancel
Save