Files
cmsPRO/index.php
Jacek Pyziak 9ee4116f50 Refaktoryzacja Faza 0+1: PSR-4 autoloader + Shared/Domain klasy
- Dodano PSR-4 autoloader do wszystkich 6 punktów wejścia
- Shared\: CacheHandler, Helpers, Html, ImageManipulator, Tpl
- Domain\: LanguagesRepository, SettingsRepository, UserRepository
- Stare class.*.php → cienkie wrappery (kompatybilność wsteczna)
- Dodano dokumentację: docs/PROJECT_STRUCTURE.md + pozostałe docs/
- Dodano CLAUDE.md z workflow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 23:43:55 +01:00

233 lines
6.6 KiB
PHP

<?php
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
function __autoload_my_classes( $classname )
{
$q = explode( '\\', $classname );
$c = array_pop( $q );
// 1. Legacy: class.ClassName.php
$f = 'autoload/' . implode( '/', $q ) . '/class.' . $c . '.php';
if ( file_exists( $f ) ) { require_once( $f ); return; }
// 2. PSR-4: ClassName.php
$f = 'autoload/' . implode( '/', $q ) . '/' . $c . '.php';
if ( file_exists( $f ) ) require_once( $f );
}
spl_autoload_register( '__autoload_my_classes' );
date_default_timezone_set( 'Europe/Warsaw' );
require_once 'config.php';
require_once 'libraries/medoo/medoo.php';
session_start();
if ( !isset( $_SESSION['check'] ) )
{
session_regenerate_id();
$_SESSION['check'] = true;
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
}
if ( $_SESSION['ip'] !== $_SERVER['REMOTE_ADDR'] )
{
session_destroy();
header( 'Location: /' );
exit;
}
$mdb = new medoo( [
'database_type' => 'mysql',
'database_name' => $database['name'],
'server' => $database['host'],
'username' => $database['user'],
'password' => $database['password'],
'charset' => 'utf8'
] );
\front\controls\Site::check_url_params();
if ( file_exists( 'plugins/special-actions.php' ) )
include 'plugins/special-actions.php';
if ( !$lang_id = \S::get_session( 'current-lang' ) )
{
$lang_id = \front\factory\Languages::default_language();
\S::set_session( 'current-lang', $lang_id );
}
if ( \S::get('action') == 'htaccess' )
{
\S::htacces( '' );
unlink( 'install.php' );
unlink( 'update.zip' );
header('Location: /');
exit;
}
if ( !$lang = \S::get_session( 'lang-' . $lang_id ) )
{
$lang = \front\factory\Languages::lang_translations( $lang_id );
\S::set_session( 'lang-' . $lang_id, $lang );
}
$settings = \front\factory\Settings::settings_details();
preg_match_all( \front\view\Site::language_pattern, $settings['additional_info'], $language_list );
if ( is_array( $language_list[0] ) ) foreach( $language_list[0] as $language_list_tmp )
{
$language_list_tmp = explode( ':', $language_list_tmp );
$settings['additional_info'] = str_replace( '[LANG:' . $language_list_tmp[1] . ']', $lang[ $language_list_tmp[1] ], $settings['additional_info'] );
}
if ( $settings['visit_counter'] and ! \S::get_session( 'visits' ) and ! \S::is_bot() )
{
$visits = (int)\front\factory\Settings::visit_counter();
$visits_new = $visits+1;
if ( $visits_new > $visits )
{
if ( !$mdb -> count( 'pp_settings', [ 'param' => 'visits' ] ) )
$mdb -> insert( 'pp_settings', [ 'value' => $visits_new, 'param' => 'visits' ] );
else
$mdb -> update( 'pp_settings', [ 'value' => $visits_new ], [ 'param' => 'visits' ] );
\S::set_session( 'visits', $visits_new );
}
}
if ( \S::get( 'a' ) == 'page' and \S::get( 'id' ) )
{
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
\S::set_session( 'page', $page );
}
if ( \S::get( 'devel' ) )
$settings['devel'] = true;
if ( \S::get( 'hash' ) == $settings['update_key'] )
\S::set_session( 'front-devel', true );
if ( file_exists( 'plugins/special-actions-middle.php' ) )
include 'plugins/special-actions-middle.php';
if ( $page['cache'] and !\S::get_session( 'front-devel' ) )
{
$cache_url = $_SERVER['REQUEST_URI'];
$cache_file = \S::cache_file_url( $cache_url );
if ( file_exists( $cache_file ) )
{
$timedif = ( time() - filemtime( $cache_file ));
if ( $timedif < 3600 * 24 )
{
$html = \S::cache_read( $cache_file );
$html = str_replace( ' contenteditable="true"', '', $html );
$html = str_replace( ' alltemplates="true"', '', $html );
echo $html;
exit;
}
}
}
$out = \front\view\Site::show();
if ( !isset( $_COOKIE["cookie_information"] ) )
$out = strrev( implode( strrev( \front\view\Site::cookie_information() . '</body>' ), explode( strrev( '</body>' ), strrev( $out ), 2 ) ) );
if ( $settings['statistic_code'] )
$out = strrev( implode( strrev( $settings['statistic_code'] . '</head>' ), explode( strrev( '</head>' ), strrev( $out ), 2 ) ) );
/* wysyłka newslettera w tle */
if ( !$settings['newsletter_cron'] )
\front\factory\Newsletter::newsletter_send( 1 );
$dom = new DOMDocument('1.0', 'UTF-8');
$dom -> loadHTML( $out, LIBXML_HTML_NOIMPLIED );
$stylesheet = $dom -> getElementsByTagName( 'link' );
$remove = [];
foreach ( $stylesheet as $item )
{
if ( $item -> getAttribute( 'rel' ) == 'stylesheet' and strpos( $item -> getAttribute( 'class' ), 'footer' ) !== false )
$remove[] = $item;
}
foreach ( $remove as $item )
{
$item -> parentNode -> removeChild( $item );
if ( strpos( $item -> getAttribute( 'class' ), 'footer' ) !== false )
{
$body = $dom -> getElementsByTagName( 'body' ) -> item(0);
$body -> appendChild( $item );
}
}
$script = $dom -> getElementsByTagName( 'script' );
$remove = [];
foreach ( $script as $item )
{
if ( $item -> getAttribute( 'class' ) == 'footer' )
$remove[] = $item;
}
foreach ( $remove as $item )
{
$item -> parentNode -> removeChild( $item );
$body = $dom -> getElementsByTagName( 'body' ) -> item(0);
$body -> appendChild( $item );
}
// konwersja obrazków na webp
if ( $settings['generate_webp'] )
{
$images = $dom -> getElementsByTagName( 'img' );
foreach ( $images as $img )
{
$img_src = $img -> getAttribute( 'src' );
if ( $img_src != '' and strpos( $img -> getAttribute( 'class' ), 'nowebp' ) === false )
{
if ( strpos( $img_src, '/' ) === 0 )
$img_src = substr( $img_src, 1, strlen( $img_src ) );
$img_webp = \S::generate_webp_image( $img_src, 85 );
if ( $img_webp !== false and file_exists( $img_webp ) )
{
$img -> setAttribute( 'src', '/' . $img_webp );
$img -> setAttribute( 'src-nowebp', '/' . $img_src );
}
}
}
}
// lazy loading obrazków
if ( $settings['lazy_loading'] )
{
$images = $dom -> getElementsByTagName( 'img' );
foreach ( $images as $img )
{
if ( strpos( $img -> getAttribute( 'class' ), 'nolazy' ) === false )
{
$img -> setAttribute( 'data-src', $img -> getAttribute( 'src' ) );
$img -> setAttribute( 'class', $img -> getAttribute( 'class' ) . ' lozad' );
$img -> removeAttribute( 'src' );
}
}
}
$html = $dom -> saveHTML();
if ( file_exists( 'plugins/special-actions-end.php' ) )
include 'plugins/special-actions-end.php';
if ( $page['cache'] )
\S::cache_write( $cache_url, $cache_file, $html );
if ( !\S::get_session( 'front-devel' ) )
{
$html = str_replace( ' contenteditable="true"', '', $html );
$html = str_replace( ' alltemplates="true"', '', $html );
}
echo $html;
if ( \S::get_session( 'front-devel' ) )
include( 'templates/inline-edit.php' );
?>