release 0.267: front layout/basket fixes and product redirect hardening
This commit is contained in:
@@ -49,46 +49,58 @@ class S
|
||||
return $parts;
|
||||
}
|
||||
|
||||
static function canAddRedirect( $from, $to )
|
||||
static function canAddRedirect( $from, $to, $lang_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$redirects = $mdb -> select( 'pp_redirects', '*' );
|
||||
if ( !$from or !$to or $from === $to )
|
||||
return false;
|
||||
|
||||
$where = [];
|
||||
if ( null !== $lang_id )
|
||||
$where['lang_id'] = $lang_id;
|
||||
|
||||
$redirects = $mdb -> select( 'pp_redirects', [ 'from', 'to' ], $where );
|
||||
|
||||
$redirectMap = [];
|
||||
foreach ( $redirects as $redirect )
|
||||
{
|
||||
$redirectMap[$redirect['from']] = $redirect['to'];
|
||||
if ( !isset( $redirectMap[$redirect['from']] ) )
|
||||
$redirectMap[$redirect['from']] = [];
|
||||
|
||||
if ( !in_array( $redirect['to'], $redirectMap[$redirect['from']], true ) )
|
||||
$redirectMap[$redirect['from']][] = $redirect['to'];
|
||||
}
|
||||
|
||||
// Dodaj nowe przekierowanie do mapy tymczasowo
|
||||
$redirectMap[$from] = $to;
|
||||
if ( !isset( $redirectMap[$from] ) )
|
||||
$redirectMap[$from] = [];
|
||||
|
||||
if ( !in_array( $to, $redirectMap[$from], true ) )
|
||||
$redirectMap[$from][] = $to;
|
||||
|
||||
// Funkcja do sprawdzania cyklu za pomocą DFS
|
||||
$visited = [];
|
||||
$stack = [];
|
||||
|
||||
function hasCycle($current, $target, &$redirectMap, &$visited)
|
||||
$stack = [ $to ];
|
||||
while ( !empty( $stack ) )
|
||||
{
|
||||
if ($current === $target) {
|
||||
return true;
|
||||
}
|
||||
$current = array_pop( $stack );
|
||||
|
||||
if (isset($visited[$current])) {
|
||||
return false;
|
||||
}
|
||||
if ( $current === $from )
|
||||
return false;
|
||||
|
||||
if ( isset( $visited[$current] ) )
|
||||
continue;
|
||||
|
||||
$visited[$current] = true;
|
||||
|
||||
if (isset($redirectMap[$current])) {
|
||||
return hasCycle($redirectMap[$current], $target, $redirectMap, $visited);
|
||||
if ( isset( $redirectMap[$current] ) )
|
||||
{
|
||||
foreach ( $redirectMap[$current] as $next )
|
||||
if ( !isset( $visited[$next] ) )
|
||||
$stack[] = $next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sprawdź, czy istnieje ścieżka z $newTo do $newFrom
|
||||
return !hasCycle($to, $from, $redirectMap, $visited);
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function clear_redis_cache()
|
||||
@@ -1113,3 +1125,4 @@ class S
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user