1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
<?php
class Repository
{
private $url = '';
private $xml = null;
public function __construct($url)
{
$this->url = $url;
if (function_exists('simplexml_load_file'))
{
$this->xml = @simplexml_load_file($this->url);
if ($this->xml == false)
{
$this->xml = null;
}
}
}
public function check($app)
{
$xpath_query = '//app[@id=\'' . $app->get_id() . '\' and @type=\'' . $app->get_type() . '\']/version[@language=\'' . $app->get_language() . '\']';
if ($this->xml != null)
{
$newerVersions = array();
$versions = $this->xml->xpath($xpath_query);
$nbVersions = $versions != false ? count($versions) : 0;
for ($i = 0; $i < $nbVersions; $i++)
{
$rep_app = clone($app);
$rep_app->load($versions[$i]);
if (version_compare($app->get_version(), $rep_app->get_version(), '<') > 0)
{
if ($rep_app->check_compatibility())
{
$newerVersions[$rep_app->get_version()] = $i;
}
}
}
$server_configuration = new ServerConfiguration();
if ($server_configuration->has_curl_library() && $app->get_type() == 'kernel')
$NewVersion = count($newerVersions) > 0 ? max(array_keys($newerVersions)) : '';
else
$NewVersion = count($newerVersions) > 0 ? min(array_keys($newerVersions)) : '';
if (!empty($NewVersion))
{
$app->load($versions[$newerVersions[$NewVersion]]);
return $app;
}
}
return null;
}
public function get_url() { return $this->url; }
}
?>