Files
cmsPRO/updates/versions.php
2026-04-30 23:33:19 +02:00

72 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?
require_once '../config.php';
require_once '../libraries/medoo/medoo.php';
$mdb = new medoo( [
'database_type' => 'mysql',
'database_name' => $database['name'],
'server' => $database['host'],
'username' => $database['user'],
'password' => $database['password'],
'charset' => 'utf8'
] );
$current_ver = 1697; // aktualizowane automatycznie przez build-update.ps1
// 1. Skan filesystem — lista istniejÄ„ââ¬ĹˇÄ˘â‚¬ĹľÄ‚Ă˜Ä˘ââ¬ĹˇĂ¬Ä‚æcych ZIPÄ‚ââ¬ĹľÄ˘â‚¬ĹˇÄ„ąĢ€šw
$versions = [];
for ( $i = 1; $i <= $current_ver; $i++ )
{
$dir = substr( number_format( $i / 1000, 3 ), 0, strlen( number_format( $i / 1000, 3 ) ) - 2 ) . '0';
$version_old = number_format( $i / 1000, 2 );
$version_new = number_format( $i / 1000, 3 );
if ( file_exists( '../updates/' . $dir . '/ver_' . $version_old . '.zip' ) )
$versions[] = $version_old;
if ( file_exists( '../updates/' . $dir . '/ver_' . $version_new . '.zip' ) )
$versions[] = $version_new;
}
$versions = array_unique( $versions );
// 2. Walidacja klucza licencji
$license = $mdb->get( 'pp_update_licenses', '*', [ 'key' => ( $_GET['key'] ?? '' ) ] );
if ( !$license )
die();
// 3. SprawdÄ‚ââ¬ĹľÄ„ââ¬Â¦Ä„ąĹş waÄ‚ââ¬ĹľÄ„ââ¬Â¦Ă„‚ââ¬ĹľÄ‹ĹĄnoÄ‚ââ¬ĹľÄ„ââ¬Â¦Ă„‚Ă˜Ä˘ââ¬ĹˇĂ¬ÄąĹşÄ„ââ¬ĹˇÄ˘â‚¬ĹľÄ‚Ă˜Ä˘ââ¬ĹˇĂ¬Ä‹ââ¬Ë‡ daty
if ( $license['valid_to_date'] && $license['valid_to_date'] < date( 'Y-m-d' ) )
die();
// 4. Auto-discovery: rejestruj nowe ZIPy jako beta
$known = array_flip( $mdb->select( 'pp_update_versions', 'version', [] ) ?: [] );
foreach ( $versions as $ver )
{
if ( !isset( $known[$ver] ) )
{
@$mdb->insert( 'pp_update_versions', [
'version' => $ver,
'channel' => 'beta',
'created_at' => date( 'Y-m-d H:i:s' )
] );
$known[$ver] = true;
}
}
// 5. Filtruj wersje wg kanaÄ‚ââ¬ĹľÄ„ââ¬Â¦Ă„‚Ă˜Ä˘ââ¬ĹˇĂ¬ÄąĂ‡u (beta widzi beta+stable, reszta tylko stable)
$channels = $license['beta'] ? [ 'beta', 'stable' ] : [ 'stable' ];
$allowed = array_flip( $mdb->select( 'pp_update_versions', 'version', [ 'channel' => $channels ] ) ?: [] );
// 6. Wypisz dostÄ„ââ¬ĹˇÄ˘â‚¬ĹľÄ‚Ă˜Ä˘â‚¬ĹľÄ‹Ă˜pne wersje
$valid_to_version = $license['valid_to_version'];
foreach ( $versions as $ver )
{
if ( !isset( $allowed[$ver] ) )
continue;
if ( $valid_to_version && $ver > $valid_to_version )
continue;
echo $ver . PHP_EOL;
}