Permalink
Browse files

Update Version Check feature

  • Loading branch information...
1 parent 96750aa commit c9763c1e688100f533638397b274bd9f19757e29 @haraldpdl haraldpdl committed Mar 11, 2010
@@ -10,11 +10,10 @@
Released under the GNU General Public License
*/
-define('ADMIN_INDEX_UPDATE_CHECK_TITLE', 'osCommerce Updates');
-define('ADMIN_INDEX_UPDATE_CHECK_DATE', 'Last Checked on');
+define('ADMIN_INDEX_UPDATE_CHECK_TITLE', 'New Version Checker');
+define('ADMIN_INDEX_UPDATE_CHECK_LAST_DATE_CHECK', 'Last Checked On');
define('ADMIN_INDEX_UPDATE_CHECK_NEVER', 'Never');
define('ADMIN_INDEX_UPDATE_CHECK_NOW', 'Check Now');
-define('TEXT_UPGRADE_AVAILABLE', 'An update for osCommerce is available');
-
+define('TEXT_UPGRADE_AVAILABLE', 'An update for osCommerce Online Merchant is available!');
?>
@@ -14,15 +14,14 @@
define('TABLE_HEADING_VERSION', 'Version');
define('TABLE_HEADING_RELEASED', 'Release Date');
+define('TABLE_HEADING_ACTION', 'Action');
-define('TEXT_RELEASE_NOTES', 'View Release Annoucement / Download');
+define('TEXT_RELEASE_LINK', 'View Release Annoucement');
-define('TITLE_CURRENT_VERSION', 'Currently Running:');
+define('TITLE_INSTALLED_VERSION', 'Installed Version:');
+define('VERSION_RUNNING_LATEST', 'You are running the latest version of osCommerce Online Merchant.');
+define('VERSION_UPGRADES_AVAILABLE', 'A new version is available for download! (osCommerce Online Merchant v%s)');
-define('VERSION_RUNNING_LATEST', 'You are running the latest version of osCommerce');
-define('VERSION_UPGRADES_AVAILABLE', 'A new version of osCommerce is available for download.');
-
-define('ERROR_COULD_NOT_CONNECT', 'Could not connect to osCommerce to check for new versions. Please try again later.');
-
+define('ERROR_COULD_NOT_CONNECT', 'Could not connect to the osCommerce website to check for new versions.');
?>
@@ -43,55 +43,7 @@
}
}
}
-?>
-
-<style>
-.secInfo, .secSuccess, .secWarning, .secError {
- border: 1px solid;
- margin: 10px 0px;
- padding: 5px 10px 5px 50px;
- background-repeat: no-repeat;
- background-position: 10px center;
- border-radius: 10px;
- -moz-border-radius: 10px;
- -webkit-border-radius: 10px;
-}
-
-.secInfo {
- border-color: #00529B;
- background-image: url('images/ms_info.png');
- background: url('images/ms_info.png') no-repeat 10px center, url('images/ms_info_bg.png') repeat-x; /* css3 multiple backgrounds */
- background-color: #BDE5F8;
-}
-
-.secSuccess {
- border-color: #4F8A10;
- background-image: url('images/ms_success.png');
- background: url('images/ms_success.png') no-repeat 10px center, url('images/ms_success_bg.png') repeat-x; /* css3 multiple backgrounds */
- background-color: #DFF2BF;
-}
-
-.secWarning {
- border-color: #9F6000;
- background-color: #FEEFB3;
- background-image: url('images/ms_warning.png');
- background: url('images/ms_warning.png') no-repeat 10px center, url('images/ms_warning_bg.png') repeat-x; /* css3 multiple backgrounds */
- background-color: #FEEFB3;
-}
-
-.secError {
- border-color: #D8000C;
- background-image: url('images/ms_error.png');
- background: url('images/ms_error.png') no-repeat 10px center, url('images/ms_error_bg.png') repeat-x; /* css3 multiple backgrounds */
- background-color: #FFBABA;
-}
-
-.secInfo p, .secSuccess p, .secWarning p, .secError p {
- padding: 2px;
-}
-</style>
-<?php
if (isset($secCheck_messages['error'])) {
echo '<div class="secError">';
@@ -10,32 +10,41 @@
Released under the GNU General Public License
*/
- $last_update_check = LAST_UPDATE_CHECK_TIME;
- $cache_file = DIR_FS_CACHE . '/versions.cache';
- if (!empty($last_update_check)) {
- $date_last_checked = date('F j, Y, H:i:s', $last_update_check);
+ $cache_file = DIR_FS_CACHE . 'oscommerce_version_check.cache';
+ $current_version = trim(implode('', file(DIR_FS_CATALOG . 'includes/version.php')));
+ $new_version = false;
+
+ if (file_exists($cache_file)) {
+ $date_last_checked = tep_datetime_short(date('Y-m-d H:i:s', filemtime($cache_file)));
+
+ $releases = unserialize(implode('', file($cache_file)));
+
+ foreach ($releases as $version) {
+ $version_array = explode('|', $version);
+
+ if (version_compare($current_version, $version_array[0], '<')) {
+ $new_version = true;
+ break;
+ }
+ }
} else {
$date_last_checked = ADMIN_INDEX_UPDATE_CHECK_NEVER;
}
?>
<table border="0" width="100%" cellspacing="0" cellpadding="4">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent"><?php echo ADMIN_INDEX_UPDATE_CHECK_TITLE; ?></td>
- <td class="dataTableHeadingContent"></td>
+ <td class="dataTableHeadingContent" align="right"><?php echo ADMIN_INDEX_UPDATE_CHECK_LAST_DATE_CHECK; ?></td>
</tr>
<?php
- echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);">' .
- ' <td class="dataTableContent" align="left">' . ADMIN_INDEX_UPDATE_CHECK_DATE . ': ' . $date_last_checked . '</td>' .
- ' <td class="dataTableContent" align="right"><a href="' . tep_href_link(FILENAME_VERSION_CHECK) . '">' . ADMIN_INDEX_UPDATE_CHECK_NOW . '</a></td>' .
- ' </tr>';
-
-if (file_exists($cache_file)) {
- $result = unserialize(join('', file($cache_file)));
- if (count($result) > 0) {
- echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);">' .
- ' <td class="dataTableContent" align="left" colspan="2"><strong>' . TEXT_UPGRADE_AVAILABLE . '</strong></td>' .
- ' </tr>';
- }
-}
+ if ($new_version == true) {
+ echo ' <tr>' .
+ ' <td class="messageStackWarning" colspan="2">' . tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . '&nbsp;<strong>' . TEXT_UPGRADE_AVAILABLE . '</strong></td>' .
+ ' </tr>';
+ }
?>
+ <tr class="dataTableRow" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);">
+ <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_VERSION_CHECK) . '">' . ADMIN_INDEX_UPDATE_CHECK_NOW . '</a>'; ?></td>
+ <td class="dataTableContent" align="right"><?php echo $date_last_checked; ?></td>
+ </tr>
</table>
@@ -84,3 +84,47 @@ FORM { display: inline; }
.main { font-family: Verdana, Arial, sans-serif; font-size: 12px; }
.errorText { font-family: Verdana, Arial, sans-serif; font-size: 10px; color: #ff0000; }
+/* new messageStack styles */
+.secInfo, .secSuccess, .secWarning, .secError {
+ border: 1px solid;
+ margin: 10px 0px;
+ padding: 5px 10px 5px 50px;
+ background-repeat: no-repeat;
+ background-position: 10px center;
+ border-radius: 10px;
+ -moz-border-radius: 10px;
+ -webkit-border-radius: 10px;
+}
+
+.secInfo {
+ border-color: #00529B;
+ background-image: url('../images/ms_info.png');
+ background: url('../images/ms_info.png') no-repeat 10px center, url('../images/ms_info_bg.png') repeat-x; /* css3 multiple backgrounds */
+ background-color: #BDE5F8;
+}
+
+.secSuccess {
+ border-color: #4F8A10;
+ background-image: url('../images/ms_success.png');
+ background: url('../images/ms_success.png') no-repeat 10px center, url('../images/ms_success_bg.png') repeat-x; /* css3 multiple backgrounds */
+ background-color: #DFF2BF;
+}
+
+.secWarning {
+ border-color: #9F6000;
+ background-color: #FEEFB3;
+ background-image: url('../images/ms_warning.png');
+ background: url('../images/ms_warning.png') no-repeat 10px center, url('../images/ms_warning_bg.png') repeat-x; /* css3 multiple backgrounds */
+ background-color: #FEEFB3;
+}
+
+.secError {
+ border-color: #D8000C;
+ background-image: url('../images/ms_error.png');
+ background: url('../images/ms_error.png') no-repeat 10px center, url('../images/ms_error_bg.png') repeat-x; /* css3 multiple backgrounds */
+ background-color: #FFBABA;
+}
+
+.secInfo p, .secSuccess p, .secWarning p, .secError p {
+ padding: 2px;
+}
@@ -12,37 +12,72 @@
require('includes/application_top.php');
- $check_version = true;
- $upgrade_versions = array();
- $current_version = trim(file_get_contents(DIR_FS_CATALOG . '/includes/version.php'));
- $major_version = substr($current_version, 0, 1);
- $versions = @file('http://www.oscommerce.com/version/online_merchant/' . $major_version, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- if (is_array($versions) && count($versions) > 0) {
- foreach ($versions as $version) {
- $arrversion = explode('|', $version);
- if ( version_compare($current_version, $arrversion[0], '<') ) {
- $upgrade_versions[] = $arrversion;
+ $current_version = trim(implode('', file(DIR_FS_CATALOG . 'includes/version.php')));
+ $major_version = (int)substr($current_version, 0, 1);
+
+ $releases = null;
+ $new_versions = array();
+ $check_message = array();
+
+ if (function_exists('curl_init')) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, 'http://www.oscommerce.com/version/online_merchant/' . $major_version);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ $response = trim(curl_exec($ch));
+ curl_close($ch);
+
+ if (!empty($response)) {
+ $releases = explode("\n", $response);
+ }
+ } else {
+ if ($fp = @fsockopen('www.oscommerce.com', 80, $errno, $errstr, 30)) {
+ $header = 'GET /version/online_merchant/' . $major_version . ' HTTP/1.0' . "\r\n" .
+ 'Host: www.oscommerce.com' . "\r\n" .
+ 'Connection: close' . "\r\n\r\n";
+
+ fwrite($fp, $header);
+
+ $response = '';
+ while (!feof($fp)) {
+ $response .= fgets($fp, 1024);
+ }
+
+ fclose($fp);
+
+ $response = explode("\r\n\r\n", $response); // split header and content
+
+ if (isset($response[1]) && !empty($response[1])) {
+ $releases = explode("\n", trim($response[1]));
}
}
+ }
- $serialized = serialize($upgrade_versions);
- if ($f = @fopen(DIR_FS_CACHE . '/versions.cache', 'w')) {
+ if (is_array($releases) && !empty($releases)) {
+ $serialized = serialize($releases);
+ if ($f = @fopen(DIR_FS_CACHE . 'oscommerce_version_check.cache', 'w')) {
fwrite ($f, $serialized, strlen($serialized));
fclose($f);
}
- if (count($upgrade_versions) > 0) {
- $messageStack->add(VERSION_UPGRADES_AVAILABLE, 'error');
+ foreach ($releases as $version) {
+ $version_array = explode('|', $version);
+
+ if (version_compare($current_version, $version_array[0], '<')) {
+ $new_versions[] = $version_array;
+ }
+ }
+
+ if (!empty($new_versions)) {
+ $check_message = array('class' => 'secWarning',
+ 'message' => sprintf(VERSION_UPGRADES_AVAILABLE, $new_versions[0][0]));
} else {
- $messageStack->add(VERSION_RUNNING_LATEST, 'success');
+ $check_message = array('class' => 'secSuccess',
+ 'message' => VERSION_RUNNING_LATEST);
}
} else {
- $messageStack->add(ERROR_COULD_NOT_CONNECT, 'error');
+ $check_message = array('class' => 'secError',
+ 'message' => ERROR_COULD_NOT_CONNECT);
}
-
- $last_update_check = time();
- tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $last_update_check . "' where configuration_key = 'LAST_UPDATE_CHECK_TIME'");
-
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html <?php echo HTML_PARAMS; ?>>
@@ -76,47 +111,50 @@
</table></td>
</tr>
<tr>
- <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
- <tr>
- <td><table border="0" cellspacing="0" cellpadding="3">
- <tr>
- <td class="smallText"><b><?php echo TITLE_CURRENT_VERSION; ?></b></td>
- <td class="smallText"><?php echo $current_version; ?></td>
- </tr>
- </table></td>
- </tr>
- </table></td>
+ <td class="smallText"><?php echo TITLE_INSTALLED_VERSION . ' <b>osCommerce Online Merchant v' . $current_version . '</b>'; ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>
<tr>
+ <td><div class="<?php echo $check_message['class']; ?>">
+ <p class="smallText"><?php echo $check_message['message']; ?></p>
+ </div></td>
+ </tr>
+ <tr>
+ <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
+ </tr>
+<?php
+ if (!empty($new_versions)) {
+?>
+ <tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_VERSION; ?></td>
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_RELEASED; ?></td>
- <td class="dataTableHeadingContent"></td>
+ <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
</tr>
-
+
<?php
- if (count($upgrade_versions) > 0 ) {
- foreach ($upgrade_versions as $upgrade) {
+ foreach ($new_versions as $version) {
?>
<tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
- <td class="dataTableContent"><?php echo $upgrade[0]; ?></td>
- <td class="dataTableContent"><?php echo date('F j, Y', mktime(0, 0, 0, substr($upgrade[1], 4, 2), substr($upgrade[1], 6, 2), substr($upgrade[1], 0, 4))); ?></td>
- <td class="dataTableContent"><?php echo '<a href="' . $upgrade[2] . '" target="_blank">' . TEXT_RELEASE_NOTES . '</a>'; ?></td>
+ <td class="dataTableContent"><?php echo '<a href="' . $version[2] . '" target="_blank">osCommerce Online Merchant v' . $version[0] . '</a>'; ?></td>
+ <td class="dataTableContent"><?php echo tep_date_long(substr($version[1], 0, 4) . '-' . substr($version[1], 4, 2) . '-' . substr($version[1], 6, 2)); ?></td>
+ <td class="dataTableContent" align="right"><?php echo '<a href="' . $version[2] . '" target="_blank">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; ?>&nbsp;</td>
</tr>
<?php
}
- }
?>
- </table></td>
+ </table></rd>
</tr>
</table></td>
</tr>
+<?php
+ }
+?>
</table></td>
<!-- body_text_eof //-->
</tr>
@@ -1 +1 @@
-2.2 RC2a
+2.2RC2a

0 comments on commit c9763c1

Please sign in to comment.