Refactor product loading logic and update URL routing
- Refactored the product loading logic in the ShopProduct class to improve performance and readability. - Updated the URL routing in the index.php file to handle redirects and routes based on the request URI. - Added a new method in the S class to check if adding a redirect will create a cycle in the redirect map. - Updated the S class to use the new method for adding redirects and generating URL routes. - Removed unnecessary code related to generating .htaccess rules.
This commit is contained in:
38
index.php
38
index.php
@@ -79,6 +79,44 @@ if ( \S::get( 'action' ) == 'htaccess' )
|
||||
exit;
|
||||
}
|
||||
|
||||
// check redirects
|
||||
$request_uri = substr( $_SERVER[ 'REQUEST_URI' ], 1, strlen( $_SERVER[ 'REQUEST_URI' ] ) );
|
||||
if ( $request_uri != '' )
|
||||
{
|
||||
$new_url = $mdb -> get( 'pp_redirects', 'to', [ 'from' => $request_uri ], [ 'ORDER' => [ 'date_add' => 'DESC' ] ] );
|
||||
if ( $new_url['to'] )
|
||||
{
|
||||
header( 'Location: ' . $new_url[ 'to' ], true, 301 );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// check routes
|
||||
$request_uri = ltrim( $_SERVER['REQUEST_URI'], '/' );
|
||||
if ( $request_uri != '' )
|
||||
{
|
||||
$matched = false;
|
||||
|
||||
$routes = $mdb -> select( 'pp_routes', '*' );
|
||||
foreach ( $routes as $route )
|
||||
{
|
||||
$pattern = $route['pattern'];
|
||||
$destination = $route['destination'];
|
||||
|
||||
if ( preg_match("#^" . $pattern . "#", $request_uri, $matches ) )
|
||||
{
|
||||
// Replace placeholders in the destination with matches from the request URI
|
||||
$destination = preg_replace( "#^" . $pattern . "#", $destination, $request_uri );
|
||||
|
||||
// Parse the destination string to extract GET parameters
|
||||
parse_str(parse_url($destination, PHP_URL_QUERY), $_GET);
|
||||
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( \S::get( 'a' ) == 'page' and \S::get( 'id' ) )
|
||||
{
|
||||
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
|
||||
|
||||
Reference in New Issue
Block a user