function _checkVersion() { global $_CONF, $_USER, $_PLUGIN_INFO; // build XML request require_once $_CONF['path'] . 'lib/http/http.php'; $result = ''; $http = new http_class(); $http->timeout = 5; $http->data_timeout = 5; $http->debug = 0; $http->html_debug = 0; $http->user_agent = 'glFusion/' . GVERSION; $url = "http://www.glfusion.org/versions/index.php"; $error = $http->GetRequestArguments($url, $arguments); $arguments["RequestMethod"] = "POST"; $arguments["PostValues"] = array("v" => "v" . GVERSION . PATCHLEVEL); if ($_CONF['send_site_data']) { $arguments["PostValues"]['s'] = $_CONF['site_url']; } $error = $http->Open($arguments); if ($error == "") { $error = $http->SendRequest($arguments); if ($error == "") { for (;;) { $error = $http->ReadReplyBody($body, 1000); if ($error != "" || strlen($body) == 0) { break; } $result = $result . $body; } } } if (!$result) { return array(-1, -1, array()); } // parse XML response $response = xml2array($result); if (isset($response['response'])) { if (isset($response['response']['glfusion'])) { $latest = $response['response']['glfusion']['version']; } else { $latest = 'unknown'; } if (isset($response['response']['glfusion']['date'])) { $releaseDate = $response['response']['glfusion']['date']; } else { $releaseDate = 'unknown'; } } // check glFusion CMS version $current = GVERSION . PATCHLEVEL; list($latestMajor, $latestMinor, $latestRev, $latestExtra) = explode('.', $latest . '....'); list($currentMajor, $currentMinor, $currentRev, $currentExtra) = explode('.', $current . '....'); $glFusionUpToDate = 0; if ($currentMajor >= $latestMajor) { if ($currentMajor > $latestMajor) { $glFusionUpToDate = 2; } else { if ($currentMinor >= $latestMinor) { if ($currentMinor > $latestMinor) { $glFusionUpToDate = 2; } else { if ($currentRev >= $latestRev) { if ($currentRev > $latestRev) { $glFusionUpToDate = 2; } else { if ($currentExtra != '' || $latestExtra != '') { if (strcmp($currentExtra, $latestExtra) == 0) { $glFusionUpToDate = 1; } } else { $glFusionUpToDate = 1; } } } } } } } // run through all our active plugins and see if any are out of date $pluginsUpToDate = 1; $done = 0; if (is_array($response['response']['plugin'])) { foreach ($_PLUGIN_INFO as $iPlugin => $iPluginVer) { $upToDate = 0; foreach ($response['response']['plugin'] as $plugin) { if (strcmp($plugin['name'], $iPlugin) == 0) { if (_upToDate($plugin['version'], $iPluginVer) == 0) { $pluginsUpToDate = 0; $done = 1; break; } } } if ($done) { break; } } } // build data if we need it... $pluginData = array(); $pluginData['glfusioncms']['plugin'] = 'glfusioncms'; $pluginData['glfusioncms']['installed_version'] = $current; $pluginData['glfusioncms']['display_name'] = ''; $pluginData['glfusioncms']['latest_version'] = $latest; $pluginData['glfusioncms']['release_date'] = $releaseDate; $pluginData['glfusioncms']['url'] = ''; if (is_array($response['response']['plugin'])) { foreach ($_PLUGIN_INFO as $iPlugin => $iPluginVer) { $upToDate = 0; $pluginData[$iPlugin]['plugin'] = $iPlugin; $pluginData[$iPlugin]['installed_version'] = $iPluginVer; $pluginData[$iPlugin]['display_name'] = $iPlugin; $pluginData[$iPlugin]['latest_version'] = 0; $pluginData[$iPlugin]['release_date'] = 0; $pluginData[$iPlugin]['url'] = ''; foreach ($response['response']['plugin'] as $plugin) { if (strcmp($plugin['name'], $iPlugin) == 0) { $pluginData[$iPlugin]['display_name'] = $plugin['displayname']; $pluginData[$iPlugin]['latest_version'] = $plugin['version']; $pluginData[$iPlugin]['release_date'] = $plugin['date']; if (isset($plugin['url'])) { $pluginData[$iPlugin]['url'] = $plugin['url']; } } } } } return array($glFusionUpToDate, $pluginsUpToDate, $pluginData); }
function _displayVersionData() { global $_CONF, $_USER, $LANG_UPGRADE, $LANG01, $LANG_FILECHECK, $LANG_ADMIN, $_PLUGIN_INFO; $retval = ''; $upToDate = 0; $classCounter = 0; $pluginInfo = ''; list($upToDate, $pluginsUpToDate, $pluginData) = _checkVersion(); $T = new Template($_CONF['path_layout'] . 'admin'); $T->set_file('page', 'vercheck.thtml'); $menu_arr = array(array('url' => $_CONF['site_admin_url'] . '/vercheck.php', 'text' => $LANG_UPGRADE['recheck']), array('url' => $_CONF['site_admin_url'], 'text' => $LANG_ADMIN['admin_home'])); $retval .= COM_startBlock($LANG_UPGRADE['title'], '', COM_getBlockTemplate('_admin_block', 'header')); $retval .= ADMIN_createMenu($menu_arr, $LANG_UPGRADE['desc'], $_CONF['layout_url'] . '/images/icons/versioncheck.png'); $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer')); switch ($upToDate) { case 0: $alertIcon = $_CONF['layout_url'] . '/images/alert.png'; $statusMsg = $LANG_UPGRADE['upgrade_title']; $statusText = sprintf($LANG_UPGRADE['upgrade'], $pluginData['glfusioncms']['installed_version'], $pluginData['glfusioncms']['latest_version']); break; case 1: $alertIcon = $_CONF['layout_url'] . '/images/check.png'; $statusMsg = $LANG_UPGRADE['uptodate_title']; $statusText = $LANG_UPGRADE['uptodate']; break; case 2: $alertIcon = $_CONF['layout_url'] . '/images/alert.png'; $statusMsg = $LANG_UPGRADE['unknown_title']; $statusText = sprintf($LANG_UPGRADE['unknown'], $pluginData['glfusioncms']['installed_version']); break; default: $alertIcon = $_CONF['layout_url'] . '/images/alert.png'; $statusMsg = $LANG_UPGRADE['error_title']; $statusText = $LANG_UPGRADE['error']; break; } $T->set_var(array('alerticon' => $alertIcon, 'statusmsg' => $statusMsg, 'statustext' => $statusText)); if ($pluginsUpToDate != -1) { $pluginInfo .= '<div style="margin-top:10px;"><h3>' . $LANG_UPGRADE['plugin_title'] . '</h3>'; $dt = new Date('now', $_USER['tzid']); $data_arr = array(); $text_arr = array(); $header_arr = array(array('text' => $LANG_UPGRADE['plugin'], 'field' => 'display_name'), array('text' => $LANG_UPGRADE['installed_version'], 'field' => 'installed_version'), array('text' => $LANG_UPGRADE['latest_version'], 'field' => 'latest_version'), array('text' => $LANG_UPGRADE['notes'], 'field' => 'notes')); asort($pluginData); foreach ($pluginData as $plugin) { if ($plugin['plugin'] == 'glfusioncms') { continue; } $dt->setTimestamp($plugin['release_date']); if ($plugin['latest_version'] == 0) { $upToDate = -1; } else { $upToDate = _upToDate($plugin['latest_version'], $plugin['installed_version']); } switch ($upToDate) { case 0: $notes = sprintf($LANG_UPGRADE['was_released'], $plugin['latest_version'], $dt->format("M d, Y", true)); $class = "notok"; if (strlen($plugin['url']) > 0) { $latest_version = '<a href="' . $plugin['url'] . '" target="_blank">' . $plugin['latest_version'] . '</a>'; } else { $latest_version = $plugin['latest_version']; } break; case 1: $notes = $LANG_UPGRADE['plugin_uptodate']; $class = "yes"; $latest_version = $plugin['latest_version']; break; case 2: $notes = $LANG_UPGRADE['plugin_newer']; $class = "yes"; $latest_version = $plugin['latest_version']; break; default: $notes = $LANG_UPGRADE['no_data']; $class = "ok"; $latest_version = '???'; break; } $data_arr[] = array('display_name' => $plugin['display_name'], 'installed_version' => $plugin['installed_version'], 'latest_version' => '<span class="' . $class . '">' . $latest_version . '</span>', 'url' => $plugin['url'], 'notes' => $notes, 'release_date' => $plugin['release_date'], 'update_available' => $upToDate); } $pluginInfo .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr); $pluginInfo .= '</div>'; } $T->parse('output', 'page'); $retval .= $T->finish($T->get_var('output')); $retval .= $pluginInfo; return $retval; }