aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php39
1 files changed, 12 insertions, 27 deletions
diff --git a/index.php b/index.php
index 3954be97..90045d60 100644
--- a/index.php
+++ b/index.php
@@ -305,32 +305,6 @@ function setup_login_state() {
305} 305}
306$userIsLoggedIn = setup_login_state(); 306$userIsLoggedIn = setup_login_state();
307 307
308// Checks if an update is available for Shaarli.
309// (at most once a day, and only for registered user.)
310// Output: '' = no new version.
311// other= the available version.
312function checkUpdate()
313{
314 if (!isLoggedIn()) return ''; // Do not check versions for visitors.
315 if (empty($GLOBALS['config']['ENABLE_UPDATECHECK'])) return ''; // Do not check if the user doesn't want to.
316
317 // Get latest version number at most once a day.
318 if (!is_file($GLOBALS['config']['UPDATECHECK_FILENAME']) || (filemtime($GLOBALS['config']['UPDATECHECK_FILENAME'])<time()-($GLOBALS['config']['UPDATECHECK_INTERVAL'])))
319 {
320 $version = shaarli_version;
321 list($headers, $data) = get_http_url('https://raw.githubusercontent.com/shaarli/Shaarli/master/shaarli_version.php', 2);
322 if (strpos($headers[0], '200 OK') !== false) {
323 $version = str_replace(' */ ?>', '', str_replace('<?php /* ', '', $data));
324 }
325 // If failed, never mind. We don't want to bother the user with that.
326 file_put_contents($GLOBALS['config']['UPDATECHECK_FILENAME'],$version); // touch file date
327 }
328 // Compare versions:
329 $newestversion=file_get_contents($GLOBALS['config']['UPDATECHECK_FILENAME']);
330 if (version_compare($newestversion,shaarli_version)==1) return $newestversion;
331 return '';
332}
333
334 308
335// ----------------------------------------------------------------------------------------------- 309// -----------------------------------------------------------------------------------------------
336// Log to text file 310// Log to text file
@@ -657,7 +631,18 @@ class pageBuilder
657 private function initialize() 631 private function initialize()
658 { 632 {
659 $this->tpl = new RainTPL; 633 $this->tpl = new RainTPL;
660 $this->tpl->assign('newversion', escape(checkUpdate())); 634 $this->tpl->assign(
635 'newversion',
636 escape(
637 ApplicationUtils::checkUpdate(
638 shaarli_version,
639 $GLOBALS['config']['UPDATECHECK_FILENAME'],
640 $GLOBALS['config']['UPDATECHECK_INTERVAL'],
641 $GLOBALS['config']['ENABLE_UPDATECHECK'],
642 isLoggedIn()
643 )
644 )
645 );
661 $this->tpl->assign('feedurl', escape(index_url($_SERVER))); 646 $this->tpl->assign('feedurl', escape(index_url($_SERVER)));
662 $searchcrits = ''; // Search criteria 647 $searchcrits = ''; // Search criteria
663 if (!empty($_GET['searchtags'])) { 648 if (!empty($_GET['searchtags'])) {