first commit
This commit is contained in:
91
autoload/class.Tpl.php
Normal file
91
autoload/class.Tpl.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
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 \Tpl;
|
||||
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( '../templates_user/' . $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include '../templates/' . $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 ];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user