update
This commit is contained in:
146
index.php
146
index.php
@@ -9,6 +9,12 @@ function __autoload_my_classes( $classname )
|
||||
|
||||
if ( file_exists( $f ) )
|
||||
require_once( $f );
|
||||
else
|
||||
{
|
||||
$f = 'autoload/' . implode( '/', $q ) . '/' . $c . '.php';
|
||||
if ( file_exists( $f ) )
|
||||
require_once( $f );
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '__autoload_my_classes' );
|
||||
@@ -53,26 +59,71 @@ $mdb = new medoo( [
|
||||
'time_debug' => $database['time_debug']
|
||||
] );
|
||||
|
||||
\front\controls\Site::check_url_params();
|
||||
// check routes
|
||||
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$request_uri = ltrim($parsed_url['path'], '/');
|
||||
$query_string = isset($parsed_url['query']) ? $parsed_url['query'] : '';
|
||||
parse_str($query_string, $query_params);
|
||||
|
||||
if ( !$lang_id = \S::get_session( 'current-lang' ) )
|
||||
if ($request_uri != '')
|
||||
{
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
\S::set_session( 'current-lang', $lang_id );
|
||||
$cache = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'pp_routes:all';
|
||||
$routesCached = $cache->get($cacheKey);
|
||||
|
||||
if ($routesCached === false || $routesCached === null)
|
||||
{
|
||||
$routes = $mdb->select('pp_routes', '*');
|
||||
$cache->set($cacheKey, $routes, 86400);
|
||||
}
|
||||
else
|
||||
{
|
||||
$routes = unserialize($routesCached);
|
||||
}
|
||||
|
||||
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), $destination_params);
|
||||
|
||||
// Merge the destination params with query params from the URL
|
||||
$_GET = array_merge($destination_params, $query_params);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$lang = \S::get_session( 'lang-' . $lang_id ) )
|
||||
\front\App::checkUrlParams();
|
||||
|
||||
$langRepo = new \Domain\Languages\LanguagesRepository( $mdb );
|
||||
|
||||
if ( !$lang_id = \Shared\Helpers\Helpers::get_session( 'current-lang' ) )
|
||||
{
|
||||
$lang = \front\factory\Languages::lang_translations( $lang_id );
|
||||
\S::set_session( 'lang-' . $lang_id, $lang );
|
||||
$lang_id = $langRepo->defaultLanguage();
|
||||
\Shared\Helpers\Helpers::set_session( 'current-lang', $lang_id );
|
||||
}
|
||||
|
||||
$settings = \front\factory\Settings::settings_details();
|
||||
$client = \S::get_session( 'client' );
|
||||
|
||||
if ( \S::get( 'action' ) == 'htaccess' )
|
||||
if ( !$lang = \Shared\Helpers\Helpers::get_session( 'lang-' . $lang_id ) )
|
||||
{
|
||||
\S::htacces( '' );
|
||||
$lang = $langRepo->translations( $lang_id );
|
||||
\Shared\Helpers\Helpers::set_session( 'lang-' . $lang_id, $lang );
|
||||
}
|
||||
|
||||
$settings = ( new \Domain\Settings\SettingsRepository( $mdb ) )->allSettings();
|
||||
$client = \Shared\Helpers\Helpers::get_session( 'client' );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'action' ) == 'htaccess' )
|
||||
{
|
||||
\Shared\Helpers\Helpers::htacces( '' );
|
||||
unlink( 'install.php' );
|
||||
unlink( 'update.zip' );
|
||||
header( 'Location: /' );
|
||||
@@ -91,58 +142,39 @@ if ( $request_uri != '' )
|
||||
}
|
||||
}
|
||||
|
||||
// check routes
|
||||
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$request_uri = ltrim($parsed_url['path'], '/');
|
||||
$query_string = isset($parsed_url['query']) ? $parsed_url['query'] : '';
|
||||
parse_str($query_string, $query_params);
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $mdb );
|
||||
|
||||
if ($request_uri != '')
|
||||
if ( \Shared\Helpers\Helpers::get( 'a' ) == 'page' and \Shared\Helpers\Helpers::get( 'id' ) )
|
||||
{
|
||||
$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), $destination_params);
|
||||
|
||||
// Merge the destination params with query params from the URL
|
||||
$_GET = array_merge($destination_params, $query_params);
|
||||
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$page = $pagesRepo->frontPageDetails( \Shared\Helpers\Helpers::get( 'id' ), $lang_id );
|
||||
\Shared\Helpers\Helpers::set_session( 'page', $page );
|
||||
}
|
||||
|
||||
if ( \S::get( 'a' ) == 'page' and \S::get( 'id' ) )
|
||||
if ( !is_array( $page ) or !(int)$page['id'] )
|
||||
{
|
||||
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
|
||||
\S::set_session( 'page', $page );
|
||||
$page = \Shared\Helpers\Helpers::get_session( 'page' );
|
||||
}
|
||||
|
||||
if ( \S::get( 'devel' ) )
|
||||
if ( !is_array( $page ) or !(int)$page['id'] )
|
||||
{
|
||||
$page = $pagesRepo->frontPageDetails( '', $lang_id );
|
||||
\Shared\Helpers\Helpers::set_session( 'page', $page );
|
||||
}
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get( 'devel' ) )
|
||||
$settings[ 'devel' ] = true;
|
||||
|
||||
$out = \front\view\Site::show();
|
||||
$out = \front\LayoutEngine::show();
|
||||
|
||||
if ( !isset( $_COOKIE[ "cookie_information" ] ) )
|
||||
$out = strrev( implode( strrev( \front\view\Site::cookie_information() . '</body>' ), explode( strrev( '</body>' ), strrev( $out ), 2 ) ) );
|
||||
$out = strrev( implode( strrev( \front\LayoutEngine::cookieInformation() . '</body>' ), explode( strrev( '</body>' ), strrev( $out ), 2 ) ) );
|
||||
|
||||
if ( $settings[ 'statistic_code' ] )
|
||||
$out = strrev( implode( strrev( $settings[ 'statistic_code' ] . '</body>' ), explode( strrev( '</body>' ), strrev( $out ), 2 ) ) );
|
||||
|
||||
/* wysyłka newslettera w tle */
|
||||
\front\factory\Newsletter::newsletter_send( 1 );
|
||||
$newsletterRepo = new \Domain\Newsletter\NewsletterRepository( $mdb );
|
||||
$newsletterRepo->sendQueued( 1, $_SERVER['SERVER_NAME'], !empty( $settings['ssl'] ), $lang['wypisz-sie'] ?? 'Wypisz się' );
|
||||
|
||||
$dom = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$dom -> loadHTML( $out );
|
||||
@@ -199,13 +231,13 @@ if ( $settings[ 'piksel' ] )
|
||||
"track",
|
||||
"ViewCategory", {
|
||||
content_category: "kategoria",
|
||||
content_name: "' . htmlspecialchars( str_replace( '"', '', \front\factory\ShopCategory::category_name( $category[ 'id' ] ) ) ) . '",
|
||||
content_ids: ["' . implode( ',', \shop\Category::get_category_products_id( $category['id'] ) ) . '"],
|
||||
content_name: "' . htmlspecialchars( str_replace( '"', '', ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->categoryName( (int)$category['id'], $lang_id ) ) ) . '",
|
||||
content_ids: ["' . implode( ',', ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->getCategoryProductIds( (int)$category['id'] ) ) . '"],
|
||||
content_type: "product"
|
||||
});';
|
||||
|
||||
if ( \S::get( 'product' ) )
|
||||
$piskel_code .= PHP_EOL . 'fbq( "track", "ViewContent", { content_category: "produkt", content_name: "' . htmlspecialchars( str_replace( '"', '', \front\factory\ShopProduct::product_name( \S::get( 'product' ) ) ) ) . '", content_ids: ["' . \S::get( 'product' ) . '"], content_type: "product" });';
|
||||
if ( \Shared\Helpers\Helpers::get( 'product' ) )
|
||||
$piskel_code .= PHP_EOL . 'fbq( "track", "ViewContent", { content_category: "produkt", content_name: "' . htmlspecialchars( str_replace( '"', '', ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getProductNameCached( (int)\Shared\Helpers\Helpers::get( 'product' ), $lang_id ) ) ) . '", content_ids: ["' . \Shared\Helpers\Helpers::get( 'product' ) . '"], content_type: "product" });';
|
||||
|
||||
$element -> nodeValue = $piskel_code;
|
||||
|
||||
@@ -215,13 +247,13 @@ if ( $settings[ 'piksel' ] )
|
||||
/* end piksel */
|
||||
|
||||
/* meta tagi Facebook */
|
||||
if ( \S::get( 'product' ) )
|
||||
if ( \Shared\Helpers\Helpers::get( 'product' ) )
|
||||
{
|
||||
$url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER[ 'SERVER_NAME' ] );
|
||||
|
||||
$head = $dom -> getElementsByTagName( 'head' ) -> item( 0 );
|
||||
|
||||
$product = \front\factory\ShopProduct::product_details( \S::get( 'product' ), $lang_id );
|
||||
$product = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productDetailsFrontCached( (int)\Shared\Helpers\Helpers::get( 'product' ), $lang_id );
|
||||
$product_image = $product[ 'images' ][ 0 ][ 'src' ];
|
||||
if ( $product_image and file_exists( substr( $product_image, 1, strlen( $product_image ) ) ) )
|
||||
{
|
||||
@@ -252,7 +284,7 @@ if ( \S::get( 'product' ) )
|
||||
|
||||
$node = $head -> appendChild( $dom -> createElement( 'meta' ) );
|
||||
$node -> setAttribute( 'property', 'product:price:amount' );
|
||||
$node -> setAttribute( 'content', $product[ 'price_brutto_promo' ] ? \S::normalize_decimal( $product[ 'price_brutto_promo' ] ) : \S::normalize_decimal( $product[ 'price_brutto' ] ) );
|
||||
$node -> setAttribute( 'content', $product[ 'price_brutto_promo' ] ? \Shared\Helpers\Helpers::normalize_decimal( $product[ 'price_brutto_promo' ] ) : \Shared\Helpers\Helpers::normalize_decimal( $product[ 'price_brutto' ] ) );
|
||||
|
||||
$node = $head -> appendChild( $dom -> createElement( 'meta' ) );
|
||||
$node -> setAttribute( 'property', 'product:price:currency' );
|
||||
@@ -313,7 +345,7 @@ if ( $settings['generate_webp'] )
|
||||
if ( strpos( $img_src, '/' ) === 0 )
|
||||
$img_src = substr( $img_src, 1, strlen( $img_src ) );
|
||||
|
||||
$img_webp = \S::generate_webp_image( $img_src, 85 );
|
||||
$img_webp = \Shared\Helpers\Helpers::generate_webp_image( $img_src, 85 );
|
||||
if ( $img_webp !== false )
|
||||
{
|
||||
$img -> setAttribute( 'src', '/' . $img_webp );
|
||||
@@ -344,4 +376,4 @@ if ( file_exists( 'plugins/special-actions-end.php' ) )
|
||||
include 'plugins/special-actions-end.php';
|
||||
|
||||
echo $html;
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user