'theme', 'E' => 'extension', 'P' => 'plugin'); // Required variables that we need to run the script. $required_vars = array('reqVersion', 'id', 'version', 'appID', 'appVersion'); // Debug flag. $debug = (isset($_GET['debug']) && $_GET['debug'] == 'true') ? true : false; // Array to hold errors for debugging. $errors = array(); // Set OS. get_os_id() can only return an int. $sql['os_id'] = get_os_id(); // Iterate through required variables, and escape/assign them as necessary. foreach ($required_vars as $var) { if (empty($_GET[$var])) { $errors[] = 'Required variable '.$var.' not set.'; // set debug error } } // If we have all of our data, clean it up for our queries. if (empty($errors)) { // We will need our DB in order to perform our query. require_once('includes.php'); // Iterate through required variables, and escape/assign them as necessary. foreach ($required_vars as $var) { $sql[$var] = mysql_real_escape_string($_GET[$var]); } /* * QUERIES * * All of our variables are cleaned. * Now attempt to retrieve update information. */ $os_query = ($sql['os_id']) ? " OR version.OSID = '{$sql['os_id']}' " : ''; // Set up os_id. // Query for possible updates. // // The query sorts by version.vid, which is an auto_increment primary key for that table. // // The reason why this was used is that the version.version column was a varchar and // it was failing to sort correctly in some cases. // // There is a possibility that the version.vid sort could be incorrect, but only in edge // cases where the version was added retroactively, and I've actually _never_ seen such // a case. (It's happened, see bug #334747 -- clouserw) $query = " SELECT main.guid AS extguid, main.type AS exttype, version.version AS extversion, version.uri AS exturi, version.minappver AS appminver, version.maxappver AS appmaxver, applications.guid AS appguid, version.hash AS hash FROM main INNER JOIN version ON main.id = version.id INNER JOIN applications ON version.appid = applications.appid WHERE main.guid = '{$sql['id']}' AND applications.guid = '{$sql['appID']}' AND (version.OSID = 1 {$os_query} ) AND version.approved = 'YES' ORDER BY version.vid DESC LIMIT 1 "; $db->query($query, SQL_INIT, SQL_ASSOC); if (DB::isError($db->record)) { $errors[] = 'MySQL query for item information failed.'; } elseif (empty($db->record)) { $errors[] = 'No matching update for given item/GUID.'; } elseif (NS_CompareVersions($db->record['appminver'],$sql['appVersion'])==1) { $errors[] = 'This update is not compatible with the current client.'; } else { $update = array(); // An update exists. Retrieve it. foreach ($db->record as $key=>$val) { $update[$key] = $val; } $update['exttype'] = $ext_typemap[$update['exttype']]; $tpl->assign('update',$update); } } /* * DEBUG * * If we get here, something went wrong. For testing purposes, we can * optionally display errors based on $_GET['debug']. * * By default, no errors are ever displayed because humans do not read this * script. * * Until there is some sort of API for how clients handle errors, * things should remain this way. */ if ($debug == true) { echo ''; echo ''; echo '
'; echo '';
htmlspecialchars(print_r($_GET));
echo '';
if (!empty($query)) {
echo '';
echo htmlspecialchars($query);
echo '';
}
if (!empty($update)) {
echo '';
htmlspecialchars(print_r($update));
echo '';
}
if (!empty($errors) && is_array($errors)) {
echo '';
htmlspecialchars(print_r($errors));
echo '';
} else {
echo '