PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Kaloyan Kirilov  >  Mrasnika's template system  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: An example
Class: Mrasnika's template system
Multi-level object oriented template system
Author: By
Last change:
Date: 11 years ago
Size: 2,713 bytes
 

Contents

Class file image Download
<?
//
// a woriking example of a login box
//

include ('template.class.php');

$html = new Template('./', './errors.log', '__default_messages_and_template__.htmlt');
//
// Template(path_to_the_directory_with_the_template_with_trailing_slash,
// path_to_the_template_error_log,
// template_file_to_be_used_as_default_template - this
// means the this file is loaded and parsed, when
// instansing the Template class
//


// define templates
$html->define('login', 'login.htmlt');
$html->define(array(
   
header=>'header.htmlt',
   
footer=>'footer.htmlt')
    );

//pre-parse templates
$html->extract('header');
$html->extract('footer');
$html->extract('login');

//assign variable
$html->assign('email', 'kaloyan@rousse.bg');

$html->assign(array(
   
last_year=>date('Y'),
   
date=>date('D M-d-Y'),
   
time=>date('H:i:s')
        ));


//get an assigned variable
$time = $html->get_subs('time');

//get a message from templates
$email = $html->get_message('email');


//move messages to assigned variables
$html->message('title', 'html_title');
$html->message(array(
   
company_name=>'company',
   
first_year=>'first_year'
       
));

//parse templates
$html->parse( array(
   
'footer',
   
'header')
    );

//clear template
$html->clear('error');

$_psswrd = 'testpass';
// This is the password, that you
// have to enter in order to log in

if ($_GET[login] || $HTTP_GET_VARS[login]) {
    if ((
$_GET[psswrd]==$_psswrd) || ($HTTP_GET_VARS[psswrd]==$_psswrd)) {
       
        } else {
       
// login failed
       
$html->assign('username',
           
stripSlashes(($_GET[usrnm])?$_GET[usrnm]:$HTTP_GET_VARS[usrnm])
            );
// assign entered username to the
                // username input in 'login.htmlt'
       
       
$html->message( 'error', 'error_access_denied');
           
// assign error_access_denied to the
            // error output in 'login.htmlt'
       
}
    } else {
   
$html->message( 'error', 'error_authorization_required');
       
// assign error_authorization_required to the
        // error output in 'login.htmlt', because the
        // user hasn't logged in yet

   
}




echo
$html->fetch('header');
   
// show header



if ($html->get_subs('error')) {
   
// there's an error with the login box -
    // either wrong password or user
    // authorization is needed.

   
$html->parse('error');
   
$html->parse('login');
   
    echo
$html->fetch('login');
       
// show the login box
   
} else {
   
$html->parse('user_logged');
       
// user is successfully logged
   
   
echo $html->fetch('user_logged');
       
// show the success message
        // from the header template
   
}


echo
$html->fetch('footer');
   
//show footer




// init failed, show error
if ($s = $html->error) {
    echo
"<h1 stryle='color:red;'>$s</h1>";
    }

?>