1
0

versioncheck.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * quick script checks whether or not we're running the current release by
  4. * fetching the most recent release data from the site API and comparing it
  5. * to the version we're running here
  6. */
  7. include (dirname(__FILE__) . '/luminous.php');
  8. $URL = 'http://luminous.asgaard.co.uk/index.php/ajax/luminous/version';
  9. $DOWNLOAD_URL = 'http://luminous.asgaard.co.uk/index.php/download';
  10. $cmd_line = PHP_SAPI === 'cli';
  11. $version = LUMINOUS_VERSION;
  12. function urlify($url) {
  13. global $cmd_line;
  14. return $cmd_line? $url : "<a href='$url'>$url</a>";
  15. }
  16. function _echo($string) {
  17. echo wordwrap($string, 79) . "\n";
  18. }
  19. if (!$cmd_line) _echo('<pre>');
  20. if ($version === 'master') {
  21. _echo('You are using a development version, I cannot check how up to date it is.');
  22. _echo('You can download the latest stable release from '
  23. . urlify($DOWNLOAD_URL));
  24. }
  25. else {
  26. _echo('Checking version...');
  27. $ch = curl_init();
  28. curl_setopt($ch, CURLOPT_URL, $URL);
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30. curl_setopt($ch, CURLOPT_USERAGENT, 'Luminous ' . LUMINOUS_VERSION
  31. . ' version check');
  32. $json = curl_exec($ch);
  33. curl_close($ch);
  34. if (!$json) {
  35. _echo('Remote request failed. Try again later or visit '
  36. . urlify($DOWNLOAD_URL) . ' to see what the latest version is');
  37. } else {
  38. $data = json_decode($json, true);
  39. if ($data['release_number'] === $version || 'v' . $data['release_number'] === $version) {
  40. _echo('You are up to date!');
  41. } else {
  42. $output = "You are not up to date: your version is " . $version
  43. . " and the most recent release is " . $data['release_number']
  44. . ", released " . $data['release_date'] . '. '
  45. . ' Visit ' . urlify($DOWNLOAD_URL) . ' to upgrade';
  46. _echo($output);
  47. }
  48. }
  49. }
  50. if (!$cmd_line) _echo('</pre>');