From bdb05b16d84115067acfce2e9e53c699521bc69c Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 21 May 2011 15:21:45 +1000 Subject: Automatically check for Tinyboard updates --- mod.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'mod.php') 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']); -- cgit v1.3