Skip to content

Commit

Permalink
update the new version notification, to use the common methods for VE…
Browse files Browse the repository at this point in the history
…RSION and fetchUrl
  • Loading branch information
michield authored and marianaballa committed Dec 4, 2020
1 parent b913896 commit 5bc6bd5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 56 deletions.
7 changes: 1 addition & 6 deletions public_html/lists/admin/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,7 @@ function pageTitle($page)
//'menulinks' => array(),
//),
);
if(!isSuperUser() || !ALLOW_UPDATER){
// $GLOBALS['pagecategories']['update'] = array(
// 'toplink'=> 'redirecttoupdater',
// 'pages' => array(),
// 'menulinks' => array(),
// );
if(!isSuperUser() || !ALLOW_UPDATER) {
unset($GLOBALS['pagecategories']['system']['pages']['update']);
unset($GLOBALS['pagecategories']['system']['menulinks']['update']);
}
Expand Down
26 changes: 11 additions & 15 deletions public_html/lists/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,28 +524,24 @@ function mb_strtolower($string)
echo Info($GLOBALS['I18N']->get('Running in testmode, no emails will be sent. Check your config file.'));
}

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

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

include 'updateLib.php';
$updateNotif = checkForUpdate();
$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>';

if (showUpdateNotification() && (getCurrentphpListVersion() !== false) && extension_loaded('curl')) {

$updateNotif = checkForUpdate('init.php');
$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>';

if (file_exists($updaterdir) && ALLOW_UPDATER) {

$moreInfo .= s(' or update') . ' <a href="?page=redirecttoupdater" title="' . s('automatic updater') . '">' . s('here.') . '</a>';
}

if ($updateNotif !== '') {
if (file_exists($updaterdir) && ALLOW_UPDATER) {
$moreInfo .= '<li>'.s('or use the %sphpList Updater%s','<a href="?page=update" title="' . s('automatic updater') . '">','</a>');
}
$moreInfo .= '</ul>';

Info($updateNotif . '' . $moreInfo);
}
if ($updateNotif !== '') {
Info($updateNotif . '' . $moreInfo);
}
}

# }

if (version_compare(PHP_VERSION, '5.3.3', '<') && WARN_ABOUT_PHP_SETTINGS) {
Error(s('Your PHP version is out of date. phpList requires PHP version 5.3.3 or higher.'));
Expand Down
45 changes: 10 additions & 35 deletions public_html/lists/admin/updateLib.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,30 @@
<?php
/**
* Get Current phpList Version.
*
* @param string $path Production version location
* @return string|bool
*/
function getCurrentphpListVersion($path = '')
{
if (empty($path)) return false;
$version = file_get_contents($path);
$matches = array();
preg_match_all('/define\(\"VERSION\",\"(.*)\"\);/', $version, $matches);

if (isset($matches[1][0])) {
return $matches[1][0];
} else {
return false;
}
}

/**
* Get response from server.
*
* @param string $path Production version location
* @return mixed
* @throws Exception
*/
function getResponse($path = '')
function getResponse()
{
$serverUrl = "https://download.phplist.org/version.json";
$updateUrl = $serverUrl . '?version=' . getCurrentphpListVersion($path);

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $updateUrl);
$responseFromServer = curl_exec($ch);
curl_close($ch);
$updateUrl = $serverUrl . '?version=' . VERSION;

$responseFromServer = fetchUrl($updateUrl,array(),259200); ## cache for three days
$responseFromServer = json_decode($responseFromServer, true);

return $responseFromServer;
}

/**
* Check for update and return a message only if there is an update available.
*
* @param string $path Production version location
* @return string
* @throws Exception
*/
function checkForUpdate($path = '')
function checkForUpdate()
{
$serverResponse = getResponse($path);
$serverResponse = getResponse();
$version = isset($serverResponse['version']) ? $serverResponse['version'] : '';
$enabledNotification = true;

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

if ($version !== '' && $version !== getCurrentphpListVersion($path) && version_compare(getCurrentphpListVersion($path), $version) && $enabledNotification) {
$updateMessage = s('Update to ' . htmlentities($versionString) . ' is available. ');
if ($version !== '' && $version !== VERSION && version_compare(VERSION, $version) && $enabledNotification) {
$updateMessage = s('A new version of phpList is available: %s',htmlentities($versionString));
} else {
$updateMessage = '';
}

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

return $updateMessage;
Expand Down Expand Up @@ -104,6 +77,8 @@ function lastTimeCheck()
*/
function showUpdateNotification()
{
# we can show all the time, the fetching is cached for three days
return true;

if (lastTimeCheck()) {

Expand Down

0 comments on commit 5bc6bd5

Please sign in to comment.