VersionNotify.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * This file does the following things:
  4. * 1. Calculate how many major versions back the current installation
  5. * is from the latest release
  6. * 2. Returns the matching icon based on result of 1, as HTML
  7. * 3. Returns the matching tooltip message based on result of 1, as HTML
  8. * (stored in pair of invisible div tags)
  9. * 4. Returns the current version, as HTML (stored in pair of invisible div tags)
  10. */
  11. class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract{
  12. public function versionNotify(){
  13. if(Application_Model_Preference::GetPlanLevel() != 'disabled'){
  14. return "";
  15. }
  16. // retrieve and validate current and latest versions,
  17. $current = Application_Model_Preference::GetAirtimeVersion();
  18. $latest = Application_Model_Preference::GetLatestVersion();
  19. $link = Application_Model_Preference::GetLatestLink();
  20. $currentExploded = explode('.', $current);
  21. $latestExploded = explode('.', $latest);
  22. if(count($currentExploded) != 3 || count($latestExploded) != 3) {
  23. return "";
  24. }
  25. // Calculate the version difference;
  26. // Example: if current = 1.9.5 and latest = 3.0.0, diff = 105
  27. // Note: algorithm assumes the number after 1st dot never goes above 9
  28. $versionDifference = (intval($latestExploded[0]) * 100 + intval($latestExploded[1]) *10 + intval($latestExploded[2]))
  29. - (intval($currentExploded[0]) * 100 + intval($currentExploded[1] *10 + intval($currentExploded[2])));
  30. // Pick icon based on distance this version is to the latest version available
  31. if($versionDifference <= 0) {
  32. // current version is up to date or newer
  33. $class = "uptodate";
  34. } else if($versionDifference < 20) {
  35. // 2 or less major versions back
  36. $class = "update";
  37. } else if($versionDifference < 30) {
  38. // 3 major versions back
  39. $class = "update2";
  40. } else {
  41. // more than 3 major versions back
  42. $class = "outdated";
  43. }
  44. $result = "<div id='version-diff' style='display:none'>" . $versionDifference . "</div>"
  45. . "<div id='version-current' style='display:none'>" . $current . "</div>"
  46. . "<div id='version-latest' style='display:none'>" . $latest . "</div>"
  47. . "<div id='version-link' style='display:none'>" . $link . "</div>"
  48. . "<div id='version-icon' class='" . $class . "'></div>";
  49. return $result;
  50. }
  51. }