Classes

File phpboost/update/Repository.class.php

File phpboost/update/Repository.class.php

 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
/**
 * @package     PHPBoost
 * @subpackage  Update
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2019 03 26
 * @since       PHPBoost 2.0 - 2008 08 17
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
*/

class Repository
{
    private $url = '';
    private $xml = null;

    /**
     * constructor of the class
     * @param $url
     */
    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;
            }
        }
    }

    /**
     * Check Application
     * @param $app
     */
    public function check($app)
    {
        $xpath_query = '//app[@id=\'' . $app->get_id() . '\' and @type=\'' .  $app->get_type() . '\']/version[@language=\'' . $app->get_language() . '\']';
        // can't compare strings with XPath, so we check the version number with PHP.
        if ($this->xml != null)
        {
            $newerVersions = array();
            $versions = $this->xml->xpath($xpath_query);
            $nbVersions = $versions != false ? count($versions) : 0;
            // Retrieves all the available updates for the current application
            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();
            
            // Keep only the first applyable update
            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;
    }

    /**
     * Accessor of url
     */
    public function get_url() { return $this->url; }
}
?>