foreach ($rss->items as $item) { $latest_version = $item['title']; $download_link = $item['link']; //if current version, is older than the latest version, return true for an update is now needed. if (version_compare($version, $latest_version) == '-1') { $update_needed = true; } else { $update_needed = false; } } } if ($_POST['start_upgrade'] == '1') { $GetUpdate = @file_get_contents($download_link); $log = "Downloading new update...\n"; if ($GetUpdate) { if (temp_exists()) { $log .= "Created /202-config/temp/ directory.\n"; $downloadUpdate = @file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/202-config/temp/prosper202_' . $latest_version . '.zip', $GetUpdate); if ($downloadUpdate) { $log .= "Update downloaded and saved!\n"; $zip = @zip_open($_SERVER['DOCUMENT_ROOT'] . '/202-config/temp/prosper202_' . $latest_version . '.zip'); if ($zip) { $log .= "\nUpdate process started...\n"; $log .= "\n-------------------------------------------------------------------------------------\n"; while ($zip_entry = @zip_read($zip)) { $thisFileName = zip_entry_name($zip_entry); if (substr($thisFileName, -1, 1) == '/') { if (is_dir($_SERVER['DOCUMENT_ROOT'] . '/' . $thisFileName)) { $log .= "Directory: /" . $thisFileName . "......updated\n"; } else { if (@mkdir($_SERVER['DOCUMENT_ROOT'] . '/' . $thisFileName, 0755, true)) {
function update_needed() { global $version; $rss = fetch_rss('http://my.tracking202.com/clickserver/currentversion/'); if (isset($rss->items) && 0 != count($rss->items)) { $rss->items = array_slice($rss->items, 0, 1); foreach ($rss->items as $item) { $latest_version = $item['title']; //if current version, is older than the latest version, return true for an update is now needed. if (version_compare($version, $latest_version) == '-1') { if ($item['autoupgrade'] == 'true') { $decimals = explode('.', $latest_version); $versionCount = count($decimals); $lastDecimal = substr($latest_version, strrpos($latest_version, '.') + 1); if ($versionCount == 2) { $calcVersion = $decimals[0] - 1 . '.9.9'; } else { if ($versionCount == 3) { if ($lastDecimal == '1') { if ($decimals[1] == '0') { $calcVersion = $decimals[0] . '.0'; } else { $calcVersion = $decimals[0] . '.' . $decimals[1] . '.0'; } } else { if ($lastDecimal == '0') { $calcVersion = $decimals[0] . '.' . ($decimals[1] - 1) . '.9'; } else { $calcVersion = $decimals[0] . '.' . $decimals[1] . '.' . ($lastDecimal - 1); } } } } if ($calcVersion == $version) { //Auto upgrade without user confirmation $GetUpdate = @file_get_contents($item['link']); if ($GetUpdate) { if (temp_exists()) { $downloadUpdate = @file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/202-config/temp/prosper202_' . $latest_version . '.zip', $GetUpdate); if ($downloadUpdate) { $zip = @zip_open($_SERVER['DOCUMENT_ROOT'] . '/202-config/temp/prosper202_' . $latest_version . '.zip'); if ($zip) { while ($zip_entry = @zip_read($zip)) { $thisFileName = zip_entry_name($zip_entry); if (substr($thisFileName, -1, 1) == '/') { if (is_dir($_SERVER['DOCUMENT_ROOT'] . '/' . $thisFileName)) { } else { if (@mkdir($_SERVER['DOCUMENT_ROOT'] . '/' . $thisFileName, 0755, true)) { } else { } } } else { $contents = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $file_ext = array_pop(explode(".", $thisFileName)); if ($updateThis = @fopen($_SERVER['DOCUMENT_ROOT'] . '/' . $thisFileName, 'wb')) { fwrite($updateThis, $contents); fclose($updateThis); unset($contents); } else { $log .= "Can't update file:" . $thisFileName . "! Operation aborted"; } } $FilesUpdated = true; } zip_close($zip); } } else { $FilesUpdated = false; } } else { $FilesUpdated = false; } } else { $FilesUpdated = false; } if ($FilesUpdated == true) { include_once $_SERVER['DOCUMENT_ROOT'] . '/202-config/functions-upgrade.php'; if (UPGRADE::upgrade_databases(null) == true) { $version = $latest_version; $upgrade_done = true; } else { $upgrade_done = false; } } if ($upgrade_done) { return false; } else { return true; } } else { return true; } } else { return true; } } else { return false; } } } }