http://start.local
http://start.local
with the home directory for browsers /home/start.local/www
, where the starting root file /home/start.local/www/index.php
, which contains only one line: <?load::integration('main.tpl');?>
load::integration()
, to which it passes one parameter - the string 'main.tpl'
.load::integration()
function contains a mechanism that allows the specified template to be processed. More specifically, it allows us to register in the template main.tpl, another template, such as default.tpl, which will contain the result of the execution of mail.tpl. In turn, default.tpl can also specify a higher template (as shown in the figure). If the upstream templates are not specified, then the load::integration()
function will stop building the templates and return the total result of the execution of all templates to the browser./home/start.local/www/.htaccess
one line, like this: php_value auto_prepend_file /home/start.local/bin/lib/config.mdl
# OC: define("OS", getenv("COMSPEC")? ";": ":"); # , - # -. #, dirname, , # - , # , .. /home/start.local/bin ini_set("include_path", ini_get("include_path").OS.dirname(dirname(__FILE__))); # - load.cls require_once 'lib/load.cls'; # - create.cls, require_once 'lib/create.cls'; # - db.cls, #require_once 'lib/db.cls';
/home/start.local/bin/lib/load.cls
) and its load::integration()
function are pre-loaded for all scripts using the config.mdl file. <? class load { static $layout = ''; static $title = ''; static $body = ''; static $path; static $db; static function integration($maket) { # self::$path = self::path(); # //self::$db = new db(); do { $current = self::$layout; ob_start(); require_once "tpl/" .$maket; self::$body = ob_get_clean(); $maket = self::$layout; } while ($current != self::$layout); echo self::$body; } static function path($url='') { $var = (!$url)? dirname(getenv("SCRIPT_NAME")): $url; return explode("/", trim($var, "/\\") ); } } ?>
load::integration()
function contains only 8 significant lines, starting with do {}. The essence of which is to execute the code of our template and save the result of execution in the variable self::$body
. And besides, it is worth checking whether it is necessary to repeat the operation if the starting pattern has been changed. <? load::$layout = 'default.tpl'; load::$title = ' '; ?> <h2> </h2> <p> </p>
load::$layout
, which points to the parent template. And an optional variable load::$title
, which is used in the default.tpl template <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional"> <html> <head> <title><?=load::$title?></title> </head> <body> <table align="center" width="600"> <tr valign="top"> <td width="150"> <? if ( !empty(load::$path[0]) ) { ?> <p><a href="<?=create::file('/', 'main.tpl')?>"></a></p> <? } else { ?> <p>:</p> <? } ?> <p><a href="<?=create::file('/news/', 'page.tpl')?>"></a></p> <p><a href="<?=create::file('/cont/', 'page.tpl')?>"></a></p> </td> <td> <?=load::$body?> </td> </tr> </table> </body> </html>
load::$body
. This variable contains the result of the execution of the main.tpl code, or any other template that the load::$layout
variable specifies as its parent.load::$layout
variable with an indication of the parent template, therefore the load::integration()
function, inside which the whole action with templates occurs, completes its do {} loop and prints the final result i.e. gives the result of execution to the browser. <a href="<?=create::file('/news/', 'page.tpl')?>"></a>
create::file()
function of the create::file()
class should be printed.'/news/'
) and record the call to the first template inside it (this is the second parameter 'page.tpl'
).create::file()
function will be two actions: <a href="/news/"></a>
/home/start.local/www/news/index.php
, with the following content <?load::integration('page.tpl');?>
create::file()
. The code is: <? class create { # static function dir($arr, $dir='') { if ($dir=='') $dir = $_SERVER['DOCUMENT_ROOT']; # chdir($dir); # foreach ($arr as $a) { if ( $a=='' ) continue; if( !is_dir($a.'/') ){ mkdir($a, 0770) or print(" $dir/<b>$a</b><br>"); } chdir($a); $dir .= '/' .$a; } return $dir; } # static function file($path, $template, $content='') { # $path = trim($path, '/'); # $arr = explode('/', $path); # $end = array_pop($arr); # if ( !strpos($end, '.php') ) { # array_push($arr, $end); $end = 'index.php'; $temp[ $path ] = '/'.$path.'/'; $temp[ '' ] = '/'; $path = $temp[ $path ]; } else { $path = '/'.$path; } $dir = self::dir($arr); # # . $fp = fopen($end, "w+") or print (" $dir/<b>$end</b>!"); # $content = $content==''? "<?load::integration('$template');?>": $content; # . fputs($fp, $content); # . fclose ($fp); return $path; } } ?>
create::dir()
functioncreate::file()
function discussedrequire_once
insert.Source: https://habr.com/ru/post/126980/
All Articles