- 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>
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
namespace Shared\Tpl;
|
|
|
|
class Tpl
|
|
{
|
|
protected $dir = 'templates/';
|
|
protected $vars = array();
|
|
|
|
function __construct( $dir = null )
|
|
{
|
|
if ( $dir !== null )
|
|
$this->dir = $dir;
|
|
}
|
|
|
|
public static function view( $file, $values = '' )
|
|
{
|
|
$tpl = new self;
|
|
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
|
$tpl->$key = $val;
|
|
return $tpl->render( $file );
|
|
}
|
|
|
|
public function secureHTML( $val )
|
|
{
|
|
$out = stripslashes( $val );
|
|
$out = str_replace( "'", "'", $out );
|
|
$out = str_replace( '"', """, $out );
|
|
$out = str_replace( "<", "<", $out );
|
|
$out = str_replace( ">", ">", $out );
|
|
return $out;
|
|
}
|
|
|
|
public function render( $file )
|
|
{
|
|
if ( file_exists( 'templates_user/' . $file . '.php' ) )
|
|
{
|
|
ob_start();
|
|
include 'templates_user/' . $file . '.php';
|
|
$out = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
return $out;
|
|
}
|
|
else if ( file_exists( 'templates/' . $file . '.php' ) )
|
|
{
|
|
ob_start();
|
|
include 'templates/' . $file . '.php';
|
|
$out = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
return $out;
|
|
}
|
|
else if ( file_exists( $file . '.php' ) )
|
|
{
|
|
ob_start();
|
|
include $file . '.php';
|
|
$out = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
return $out;
|
|
}
|
|
else
|
|
return '<div class="alert alert-danger" role="alert">Nie znaleziono pliku widoku: <b>' . $this->dir . $file . '.php</b>';
|
|
}
|
|
|
|
public function __set( $name, $value )
|
|
{
|
|
$this->vars[ $name ] = $value;
|
|
}
|
|
|
|
public function __get( $name )
|
|
{
|
|
return $this->vars[ $name ];
|
|
}
|
|
}
|