<?php
/*
 * Software Name: Eorisis Setup
 * Software URI: https://eorisis.com/shop/software/joomla/setup
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace eorisis_setup\framework\lib\core\app;
\defined('_JEXEC') or die;

class config
{
	const SERVER_URI = 'updates.eorisis.net';
	const SERVER_URI_OLD = 'eorisis.com/updates';
	const USER_AGENT = 'eorisis software update';
	const INSTALLER_PLUGIN_NAME = 'eorisis_setup';
	const INSTALLER_PLUGIN_ELEMENT = 'plg_installer_eorisis_setup';
	const EXTENSION_TYPE = 'plugin';

	private static $xml;

	// --------------------------------------------------

	public function __construct() {}

	// --------------------------------------------------

	public static function init()
	{
		static $done = false;
		if ($done)
		{
			return;
		}

		$path = JPATH_PLUGINS.'/installer/'.self::INSTALLER_PLUGIN_NAME.'/'.self::INSTALLER_PLUGIN_NAME.'.xml';
		self::$xml = \eorisis_setup\framework\lib\core\model\xml::element_from_file($path, false);
		$done = true;
	}

	// --------------------------------------------------

	public static function get(string $key, $default = '')
	{
		return \eorisis_setup\framework\lib\core\model\params::xml_attr($key, self::$xml, $default);
	}

	// --------------------------------------------------

	public static function media_destination() : string
	{
		return (string)self::$xml->media['destination'];
	}

	// --------------------------------------------------

	public static function media_uri_relative(bool $jversion_check = false) : string
	{
		// Joomla >= 4 rejects subdirectory in the url in media manager when the site is installed in a subdir
		if ($jversion_check and \version_compare(JVERSION, 4, '>='))
		{
			$uri = '/';
		}
		else
		{
			$uri = \eorisis_setup\framework\lib\core\cms\uri::webroot_relative();
		}

		return $uri.'media/'.self::$xml->media['destination'];
	}
}
