From ffcd684bb3b2e02afff0db0ad39c76fbe0492b3b Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 11 Mar 2015 22:12:46 -0400 Subject: [PATCH] Closes #160 Add update checking for Mods for HESK --- admin/admin_settings.php | 161 +++++++++++++++++++++++++++++++++------ language/en/text.php | 3 +- 2 files changed, 141 insertions(+), 23 deletions(-) diff --git a/admin/admin_settings.php b/admin/admin_settings.php index e38d07fe..d08fcb4d 100644 --- a/admin/admin_settings.php +++ b/admin/admin_settings.php @@ -102,49 +102,96 @@ if ( defined('HESK_DEMO') )
- + - + ?> + + -
- : +
+ : - ' . $hesklang['hud'] . ' '; + $cellClass = 'class="success"'; + } elseif ($latest != -1) + { + $cellClass = 'class="warning"'; } - elseif ($latest != -1) + } + ?> + > + + ' . $hesklang['beta'] . ' '; ?> ' . $hesklang['hud'] . ' '; + } + elseif ($latest != -1) + { + // Is this a beta/dev version? + if ( strpos($hesk_settings['hesk_version'], 'beta') || strpos($hesk_settings['hesk_version'], 'dev') || strpos($hesk_settings['hesk_version'], 'RC') ) + { + echo ' ' . $hesklang['beta'] . ' '; ?> ' . $hesklang['hnw'] . ' '; ?> ' . $hesklang['hnw'] . ' '; ?> - - - -
: + + style="padding-left: 10px; padding-bottom: 5px"> + ' . $hesklang['mfh_up_to_date'] . ''; + } else + { + ?> - + - +
@@ -2481,17 +2528,87 @@ function hesk_getLatestVersion() } // END hesk_getLatestVersion() - function hesk_cacheLatestVersion($latest) { - global $hesk_settings; + global $hesk_settings; - @file_put_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest.txt', time() . '|' . $latest); + @file_put_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest.txt', time() . '|' . $latest); - return $latest; + return $latest; } // END hesk_cacheLatestVersion() +function hesk_checkMfhVersion($currentVersion) +{ + if ($latest = hesk_getMfhLatestVersion() ) + { + if ( strlen($latest) > 12 ) + { + return -1; + } + elseif ($latest == $currentVersion) + { + return true; + } + else + { + return $latest; + } + } + else + { + return -1; + } +} + +function hesk_getMfhLatestVersion() +{ + global $hesk_settings; + + // Do we have a cached version file? + if ( file_exists(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt') ) + { + if ( preg_match('/^(\d+)\|([\d.]+)+$/', @file_get_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt'), $matches) && (time() - intval($matches[1])) < 3600 ) + { + return $matches[2]; + } + } + + // No cached file or older than 3600 seconds, try to get an update + $hesk_version_url = 'http://mods-for-hesk.mkochcs.com/latestversion.php'; + + // Try using cURL + if ( function_exists('curl_init') ) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $hesk_version_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6); + $latest = curl_exec($ch); + curl_close($ch); + return hesk_cacheMfhLatestVersion($latest); + } + + // Try using a simple PHP function instead + if ($latest = file_get_contents($hesk_version_url) ) + { + return hesk_cacheMfhLatestVersion($latest); + } + + // Can't check automatically, will need a manual check + return false; +} + +function hesk_cacheMfhLatestVersion($latest) +{ + global $hesk_settings; + + @file_put_contents(HESK_PATH . $hesk_settings['attach_dir'] . '/__latest-mfh.txt', time() . '|' . $latest); + + return $latest; + +} + function hesk_testLanguage($return_options = 0) { diff --git a/language/en/text.php b/language/en/text.php index 1f8d34cc..cd990735 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -22,7 +22,8 @@ $hesklang['_COLLATE']='utf8_unicode_ci'; $hesklang['EMAIL_HR']='------ Reply above this line ------'; // ADDED OR MODIFIED IN Mods for HESK 2.1.0 -$hesklang['e_mfh_settings']='You will not be able to save your settings unless this file is writable by the script (CHMOD to 666)!'; +$hesklang['e_mfh_settings'] = 'You will not be able to save your settings unless this file is writable by the script (CHMOD to 666)!'; +$hesklang['mfh_up_to_date'] = 'Mods for HESK is up to date'; // ADDED OR MODIFIED IN Mods For HESK 2.0.0 $hesklang['saved_ticket_tpl'] = 'Saved Templates';