| Server IP : 172.67.191.97 / Your IP : 104.23.197.208 Web Server : Apache/2.4.63 (Ubuntu) System : Linux adminpruebas-Virtual-Machine 6.14.0-37-generic #37-Ubuntu SMP PREEMPT_DYNAMIC Fri Nov 14 22:10:32 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.4.5 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/pregrados/medicina-veterinaria-zootecnia/libraries/regularlabs/src/ |
Upload File : |
<?php
/**
* @package Regular Labs Library
* @version 23.12.10783
*
* @author Peter van Westen <[email protected]>
* @link https://regularlabs.com
* @copyright Copyright © 2023 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Library;
defined('_JEXEC') or die;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Layout\FileLayout as JFileLayout;
class DownloadKey
{
public static function get(bool $update = true): string
{
$db = DB::get();
$query = DB::getQuery()
->select('extra_query')
->from('#__update_sites')
->where(DB::like(DB::quoteName('extra_query'), 'k=%'))
->where(DB::like(DB::quoteName('location'), '%download.regularlabs.com%'));
$db->setQuery($query);
$key = $db->loadResult();
if ( ! $key)
{
return '';
}
RegEx::match('#k=([a-zA-Z0-9]{8}[A-Z0-9]{8})#', $key, $match);
if ( ! $match[1])
{
return '';
}
$key = $match[1];
if ($update)
{
self::store($key);
}
return $key;
}
public static function getOutputForComponent(
string $extension = 'all',
bool $use_modal = true,
bool $hidden = true,
string $callback = ''
): string
{
$id = 'downloadkey_' . strtolower($extension);
Document::script('regularlabs.script');
Document::script('regularlabs.downloadkey');
return (new JFileLayout(
'regularlabs.form.field.downloadkey',
JPATH_SITE . '/libraries/regularlabs/layouts'
))->render(
[
'id' => $id,
'extension' => strtolower($extension),
'use_modal' => $use_modal,
'hidden' => $hidden,
'callback' => $callback,
'show_label' => true,
]
);
}
public static function isValid(string $key, string $extension = 'all'): string
{
$key = trim($key);
if ( ! self::isValidFormat($key))
{
return json_encode([
'valid' => false,
'active' => false,
]);
}
$cache = new Cache;
$cache->useFiles(1);
if ($cache->exists())
{
return $cache->get();
}
$result = Http::getFromUrl('https://download.regularlabs.com/check_key.php?k=' . $key . '&e=' . $extension);
return $cache->set($result);
}
public static function isValidFormat(string $key): bool
{
$key = trim($key);
if ($key === '')
{
return true;
}
if (strlen($key) != 16)
{
return false;
}
return RegEx::match('^[a-zA-Z0-9]{8}[A-Z0-9]{8}$', $key, $match, 's');
}
public static function store(string $key): bool
{
if ( ! self::isValidFormat($key))
{
return false;
}
$query = DB::getQuery()
->update('#__update_sites')
->set(DB::is('extra_query', ''))
->where(DB::like(DB::quoteName('location'), '%download.regularlabs.com%'));
DB::get()->setQuery($query)->execute();
$extra_query = $key ? 'k=' . $key : '';
$query = DB::getQuery()
->update('#__update_sites')
->set(DB::is('extra_query', $extra_query))
->where(DB::like(DB::quoteName('location'), '%download.regularlabs.com%'))
->where(DB::combine([
DB::like(DB::quoteName('location'), '%&pro=%'),
DB::like(DB::quoteName('location'), '%e=extensionmanager%'),
], 'OR'));
$result = DB::get()->setQuery($query)->execute();
JFactory::getCache()->clean('_system');
return $result;
}
}