<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Version;
use Joomla\CMS\Installer\Installer;
use BlackSheepResearch\Component\UserPoints\Site\Problems\SQL;

if (!defined('USERPOINTS_SITE')) {
    define('USERPOINTS_SITE', JPATH_SITE.'/components/com_userpoints');
}
if (!defined('USERPOINTS_ADMIN')) {
    define('USERPOINTS_ADMIN', JPATH_ADMINISTRATOR.'/components/com_userpoints');
}
if (!defined('USERPOINTS_SITE_SRC')) {
    define('USERPOINTS_SITE_SRC', USERPOINTS_SITE.'/src');
}
if (!defined('USERPOINTS_ADMIN_SRC')) {
    define('USERPOINTS_ADMIN_SRC', USERPOINTS_ADMIN.'/src');
}
if (!defined('USERPOINTS_XML')) {
    define('USERPOINTS_XML', USERPOINTS_ADMIN.'/userpoints.xml');
}
if (!defined('USERPOINTS_NUM_VERSION')) {
    $version_xml = Installer::parseXMLInstallFile(USERPOINTS_XML)['version'];
    define('USERPOINTS_NUM_VERSION', $version_xml ? $version_xml : 'unknown');
}
if (!defined("USERPOINTS_SHOW_DEPRECATED_PLUGIN_INSTALL")) {
    DEFINE("USERPOINTS_SHOW_DEPRECATED_PLUGIN_INSTALL", "0");
}
if (!defined('USERPOINTS_LEVEL_BY_RANK')) {
    define('USERPOINTS_LEVEL_BY_RANK', 0);
}
if (!defined('USERPOINTS_LEVEL_BY_MEDAL')) {
    define('USERPOINTS_LEVEL_BY_MEDAL', 1);
}

if (Version::MAJOR_VERSION < 4) {
    if (is_readable(USERPOINTS_SITE_SRC)) {
        \JLoader::registerNamespace('BlackSheepResearch\\Component\\UserPoints\\Site', USERPOINTS_SITE_SRC, false, false, 'psr4');
    }
    if (is_readable(USERPOINTS_ADMIN_SRC)) {
        \JLoader::registerNamespace('BlackSheepResearch\\Component\\UserPoints\\Administrator', USERPOINTS_ADMIN_SRC, false, false, 'psr4');
    }
}

// Get Copyright for Backend
$copyStart = 2016;
$copyNow = date('Y', SQL::unixtime());
$copySite = ($copyStart == $copyNow) ? $copyStart : "$copyStart - $copyNow";
if (!defined('USERPOINTS_COPYRIGHT')) {
    define('USERPOINTS_COPYRIGHT', "&copy; $copySite - Bernard Gilly - Adrien Roussel - Martin Brampton");
}
