123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- if(!DEFINED('EGP'))
- exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
- class html
- {
- var $dir = TPL;
- var $template = null;
- var $data = array();
- var $unitblock = array();
- public $arr;
- public $select_template;
- public function set($name, $var, $unset = false)
- {
- $this->data['['.$name.']'] = $var;
- if($unset)
- unset($this->arr[$name]);
- return NULL;
- }
- public function unit($name, $var = false, $mirror = false)
- {
- $block = str_replace($name, "'\\|".$name."\\|(.*?)\\|_".$name."\\|'si", $name);
- $var = $var ? '\\1' : '';
- $this->unitblock[$block] = $var;
- if($mirror)
- {
- $block = str_replace($name, "'\\|!".$name."\\|(.*?)\\|_!".$name."\\|'si", $name);
- $var = !$var ? '\\1' : '';
- $this->unitblock[$block] = $var;
- }
- return NULL;
- }
- public function nav($name, $link = false)
- {
- $this->get('nav');
- if($link)
- {
- $this->set('link', $link);
- $this->unit('link', 1, 1);
- }else
- $this->unit('link', 0, 1);
- $this->set('name', $name);
- $this->pack('nav');
- return NULL;
- }
- public function get($name, $path = '')
- {
- global $device, $cfg;
- $path_root = $device == '!mobile' ? '' : 'megp/';
- $path = $path_root.$path;
- if($path != '')
- $name = str_replace('//', '/', $path.'/'.$name);
- if(!file_exists($this->dir.'/'.$name.'.html'))
- {
- $route = explode('/', $name);
- $namefile = end($route);
- $dir = $this->dir.str_replace($namefile, '', $name);
- die('Error: html file <u>'.$namefile.'.html</u> not found in: <u>'.$dir.'</u>');
- }
- $this->template = file_get_contents($this->dir.'/'.$name.'.html');
- $this->select_template = $this->template;
- return NULL;
- }
- private function delete()
- {
- unset($this->data);
- unset($this->unitblock);
- $this->select_template = $this->template;
- return NULL;
- }
- public function pack($compile)
- {
- if(isset($this->unitblock))
- {
- $find_preg = array();
- $replace_preg = array();
- foreach($this->unitblock as $key_find => $key_replace)
- {
- $find_preg[] = $key_find;
- $replace_preg[] = $key_replace;
- }
- $this->select_template = preg_replace($find_preg, $replace_preg, $this->select_template);
- }
- $find = array();
- $replace = array();
- if(isset($this->data))
- {
- foreach($this->data as $key_find => $key_replace)
- {
- $find[] = $key_find;
- $replace[] = $key_replace;
- }
- }
- $this->select_template = str_replace($find, $replace, $this->select_template);
- if(isset($this->arr[$compile]))
- $this->arr[$compile] .= $this->select_template;
- else
- $this->arr[$compile] = $this->select_template;
- $this->delete();
- return NULL;
- }
- public function upd($name, $old = array(), $new = array())
- {
- $this->arr[$name] = str_replace($old, $new, $this->arr[$name]);
- return NULL;
- }
- public function unitall($name, $arr = array(), $var = false, $mirror = false)
- {
- $block = str_replace($name, "'\\|".$name."\\|(.*?)\\|_".$name."\\|'si", $name);
- $var = $var ? '\\1' : '';
- $this->unitblock[$block] = $var;
- if($mirror)
- {
- $block = str_replace($name, "'\\|!".$name."\\|(.*?)\\|_!".$name."\\|'si", $name);
- $var = !$var ? '\\1' : '';
- $this->unitblock[$block] = $var;
- }
- if(count($this->unitblock))
- {
- foreach($this->unitblock as $key_find => $key_replace)
- {
- $find_preg[] = $key_find;
- $replace_preg[] = $key_replace;
- }
- $this->arr[$arr] = preg_replace($find_preg, $replace_preg, $this->arr[$arr]);
- }
- return NULL;
- }
- }
- $html = new html;
- ?>
|