protected $_configEnd = "/* CONFIG END. DO NOT CHANGE ANYTHING IN OR BEFORE THIS LINE. */\n";
/**
+ * Horde URL to check version information.
+ *
+ * @var string
+ */
+ protected $_versionUrl = 'http://www.horde.org/versions.php';
+
+ /**
* Constructor.
*
* @param string $app The name of the application to be configured.
*/
- public function __construct($app)
+ public function __construct($app = 'horde')
{
$this->_app = $app;
}
/**
+ * Contact Horde servers and get version information.
+ *
+ * @return array Keys are app names, values are arrays with two keys:
+ * 'version' and 'url'.
+ * @throws Horde_Exception
+ * @throws Horde_Http_Client_Exception
+ */
+ public function checkVersions()
+ {
+ if (!Horde_Util::extensionExists('SimpleXML')) {
+ throw new Horde_Exception('SimpleXML not available.');
+ }
+
+ $http = $GLOBALS['injector']->getInstance('Horde_Http_Client')->getClient();
+ $response = $http->get($this->_versionUrl);
+ if ($response->code != 200) {
+ throw new Horde_Exception('Unexpected response from server.');
+ }
+
+ $xml = new SimpleXMLElement($response->getBody());
+ $versions = array();
+
+ foreach ($xml->stable->application as $app) {
+ $versions[strval($app['name'])] = array(
+ 'version' => $app->version,
+ 'url' => $app->url
+ );
+ }
+
+ return $versions;
+ }
+
+ /**
* Reads the application's conf.xml file and builds an associative array
* from its XML tree.
*
$node = $dom->firstChild;
while (!empty($node)) {
if (($node->nodeType == XML_COMMENT_NODE) &&
- ($vers_tag = self::getVersion($node->nodeValue))) {
+ ($vers_tag = $this->getVersion($node->nodeValue))) {
$this->_versionTag = $vers_tag . "\n";
break;
}
*
* @return string The version string or false if not found.
*/
- static public function getVersion($text)
+ public function getVersion($text)
{
// Old CVS tag
if (preg_match('/\$.*?conf\.xml,v .*? .*\$/', $text, $match) ||
return $no_errors;
}
+$hconfig = new Horde_Config();
+
/* Check for versions if requested. */
$versions = array();
if (Horde_Util::getFormData('check_versions')) {
- $http = new HTTP_Request('http://www.horde.org/versions.php');
- $result = $http->sendRequest();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } elseif ($http->getResponseCode() != 200) {
- $notification->push(_("Unexpected response from server, try again later."), 'horde.error');
- } else {
- $dom = DOMDocument::loadXML($http->getResponseBody());
- $stable = $dom->getElementsByTagName('stable');
- if (!$stable->length || !$stable->item(0)->hasChildNodes()) {
- $notification->push(_("Invalid response from server."), 'horde.error');
- } else {
- for ($app = $stable->item(0)->firstChild;
- !empty($app);
- $app = $app->nextSibling) {
- if (!($app instanceof DOMElement)) {
- continue;
- }
- $version = $app->getElementsByTagName('version');
- $url = $app->getElementsByTagName('url');
- $versions[$app->getAttribute('name')] = array(
- 'version' => $version->item(0)->textContent,
- 'url' => $url->item(0)->textContent);
- }
- }
+ try {
+ $versions = $hconfig->checkVersions();
+ } catch (Horde_Exception $e) {
+ $notification->push(_("Could not contact server. Try again later."), 'horde.error');
}
}
$apps[$i]['status'] = _("Missing configuration. You must generate it before using this application.");
} else {
/* A conf.php exists, get the xml version. */
- if (($xml_ver = Horde_Config::getVersion(@file_get_contents($path . '/conf.xml'))) === false) {
+ if (($xml_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.xml'))) === false) {
$apps[$i]['conf'] = $conf_link . $warning . '</a>';
$apps[$i]['status'] = _("No version found in original configuration. Regenerate configuration.");
continue;
}
/* Get the generated php version. */
- if (($php_ver = Horde_Config::getVersion(@file_get_contents($path . '/conf.php'))) === false) {
+ if (($php_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.php'))) === false) {
/* No version found in generated php, suggest regenarating
* just in case. */
$apps[$i]['conf'] = $conf_link . $warning . '</a>';