Skip to content

Commit 5bc6bd5

Browse files
michieldmarianaballa
authored andcommitted
update the new version notification, to use the common methods for VERSION and fetchUrl
1 parent b913896 commit 5bc6bd5

File tree

3 files changed

+22
-56
lines changed

3 files changed

+22
-56
lines changed

public_html/lists/admin/connect.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,7 @@ function pageTitle($page)
799799
//'menulinks' => array(),
800800
//),
801801
);
802-
if(!isSuperUser() || !ALLOW_UPDATER){
803-
// $GLOBALS['pagecategories']['update'] = array(
804-
// 'toplink'=> 'redirecttoupdater',
805-
// 'pages' => array(),
806-
// 'menulinks' => array(),
807-
// );
802+
if(!isSuperUser() || !ALLOW_UPDATER) {
808803
unset($GLOBALS['pagecategories']['system']['pages']['update']);
809804
unset($GLOBALS['pagecategories']['system']['menulinks']['update']);
810805
}

public_html/lists/admin/index.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -524,28 +524,24 @@ function mb_strtolower($string)
524524
echo Info($GLOBALS['I18N']->get('Running in testmode, no emails will be sent. Check your config file.'));
525525
}
526526

527-
if (!strpos(VERSION, 'dev')) {
527+
# if (!DEVVERSION) { ## why not, quite useful to see
528528

529529
$updaterdir = __DIR__ . '/../updater';
530530

531531
include 'updateLib.php';
532+
$updateNotif = checkForUpdate();
533+
$moreInfo = ' <ul><li><a href="https://www.phplist.com/download?utm_source=pl' . VERSION . '&amp;utm_medium=updatedownload&amp;utm_campaign=phpList" title="' . s('Download the new version') . '" target="_blank">' . s('Download the new version') . '</a></li>';
532534

533-
if (showUpdateNotification() && (getCurrentphpListVersion() !== false) && extension_loaded('curl')) {
534-
535-
$updateNotif = checkForUpdate('init.php');
536-
$moreInfo = '<a href="https://www.phplist.com/download?utm_source=pl' . VERSION . '&amp;utm_medium=updatedownload&amp;utm_campaign=phpList" title="' . s('Download the new version') . '" target="_blank">' . s('Download the new version') . '</a>';
537-
538-
if (file_exists($updaterdir) && ALLOW_UPDATER) {
539-
540-
$moreInfo .= s(' or update') . ' <a href="?page=redirecttoupdater" title="' . s('automatic updater') . '">' . s('here.') . '</a>';
541-
}
542-
543-
if ($updateNotif !== '') {
535+
if (file_exists($updaterdir) && ALLOW_UPDATER) {
536+
$moreInfo .= '<li>'.s('or use the %sphpList Updater%s','<a href="?page=update" title="' . s('automatic updater') . '">','</a>');
537+
}
538+
$moreInfo .= '</ul>';
544539

545-
Info($updateNotif . '' . $moreInfo);
546-
}
540+
if ($updateNotif !== '') {
541+
Info($updateNotif . '' . $moreInfo);
547542
}
548-
}
543+
544+
# }
549545

550546
if (version_compare(PHP_VERSION, '5.3.3', '<') && WARN_ABOUT_PHP_SETTINGS) {
551547
Error(s('Your PHP version is out of date. phpList requires PHP version 5.3.3 or higher.'));

public_html/lists/admin/updateLib.php

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,30 @@
11
<?php
2-
/**
3-
* Get Current phpList Version.
4-
*
5-
* @param string $path Production version location
6-
* @return string|bool
7-
*/
8-
function getCurrentphpListVersion($path = '')
9-
{
10-
if (empty($path)) return false;
11-
$version = file_get_contents($path);
12-
$matches = array();
13-
preg_match_all('/define\(\"VERSION\",\"(.*)\"\);/', $version, $matches);
14-
15-
if (isset($matches[1][0])) {
16-
return $matches[1][0];
17-
} else {
18-
return false;
19-
}
20-
}
212

223
/**
234
* Get response from server.
245
*
25-
* @param string $path Production version location
266
* @return mixed
277
* @throws Exception
288
*/
29-
function getResponse($path = '')
9+
function getResponse()
3010
{
3111
$serverUrl = "https://download.phplist.org/version.json";
32-
$updateUrl = $serverUrl . '?version=' . getCurrentphpListVersion($path);
33-
34-
$ch = curl_init();
35-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
36-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
37-
curl_setopt($ch, CURLOPT_URL, $updateUrl);
38-
$responseFromServer = curl_exec($ch);
39-
curl_close($ch);
12+
$updateUrl = $serverUrl . '?version=' . VERSION;
4013

14+
$responseFromServer = fetchUrl($updateUrl,array(),259200); ## cache for three days
4115
$responseFromServer = json_decode($responseFromServer, true);
42-
4316
return $responseFromServer;
4417
}
4518

4619
/**
4720
* Check for update and return a message only if there is an update available.
4821
*
49-
* @param string $path Production version location
5022
* @return string
5123
* @throws Exception
5224
*/
53-
function checkForUpdate($path = '')
25+
function checkForUpdate()
5426
{
55-
$serverResponse = getResponse($path);
27+
$serverResponse = getResponse();
5628
$version = isset($serverResponse['version']) ? $serverResponse['version'] : '';
5729
$enabledNotification = true;
5830

@@ -61,12 +33,13 @@ function checkForUpdate($path = '')
6133
}
6234
$versionString = isset($serverResponse['versionstring']) ? $serverResponse['versionstring'] : '';
6335

64-
if ($version !== '' && $version !== getCurrentphpListVersion($path) && version_compare(getCurrentphpListVersion($path), $version) && $enabledNotification) {
65-
$updateMessage = s('Update to ' . htmlentities($versionString) . ' is available. ');
36+
if ($version !== '' && $version !== VERSION && version_compare(VERSION, $version) && $enabledNotification) {
37+
$updateMessage = s('A new version of phpList is available: %s',htmlentities($versionString));
6638
} else {
6739
$updateMessage = '';
6840
}
6941

42+
## why not just save it as epoch, makes calculations much easier
7043
SaveConfig('lastcheckupdate', date('m/d/Y h:i:s', time()), 0, true);
7144

7245
return $updateMessage;
@@ -104,6 +77,8 @@ function lastTimeCheck()
10477
*/
10578
function showUpdateNotification()
10679
{
80+
# we can show all the time, the fetching is cached for three days
81+
return true;
10782

10883
if (lastTimeCheck()) {
10984

0 commit comments

Comments
 (0)