Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
PHP 5/6. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В. C++. Мастер-класс в задачах и примерах. Авторы: Кузнецов М.В., Симдянов И.В. PHP. Практика создания Web-сайтов (второе издание). Авторы: Кузнецов М.В., Симдянов И.В. Самоучитель MySQL 5. Авторы: Кузнецов М.В., Симдянов И.В. PHP 5. На примерах. Авторы: Кузнецов М.В., Симдянов И.В., Голышев С.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум PHP

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: Поравить код
 
 автор: freeing   (17.02.2010 в 08:38)   письмо автору
 
 

Помогите поправить код, может где-то – что-то можно упростить…

<?php
    
require_once("class/class.configuration.php");

    final class 
template extends configuration
    
{
        function 
__construct()
        {
            
configuration::__construct();

            
$ERRORS = new error();
            
$ERRORS->Request();

            if(!empty(
$ERRORS->name))
            {
                
$this->description = "ERROR ".$ERRORS->name;
                
$this->keywords = "ERROR ".$ERRORS->name;
                
$this->title = "ERROR ".$ERRORS->name;
                
$this->body = "[h4]ERROR ".$ERRORS->code." - ".$ERRORS->name."[/h4]".$ERRORS->detail;

                
$this->filter();
            }
            else
            {
                
$this->tpl();
            }

            if(empty(
$this->url[1][0]))
            {
                if(!empty(
$this->language))
                {
                    
header("Location: ".$this->language.".html");
                }
            }

            
$this->htm();
        }

        private function 
tpl()
        {
            if(!empty(
$this->file_tpl) && file_exists($this->file_tpl) && is_file($this->file_tpl))
            {
                
$tpl = file_get_contents($this->file_tpl);
            }

            
preg_match_all("/<(.*)><(.*)><(.*)>/isU", $tpl, $Array);

            if(!empty(
$Array) && is_array($Array))
            {
                foreach (
$Array[1] as $A)
                {
                    for(
$B = &$Map; $C = strpos($A.".", ".", $C + 1);)
                    {
                        
$B = &$B[substr($A, 0, $C)];
                    }
                }
            }

            if(!empty(
$Map) && is_array($Map))
            {
                
$this->Tree($this->url, $Map, $Array[1], $Array[2], $Array[3]);
            }
    
            if(
is_array($this->History) && is_array($this->Page) && is_array($this->Page_Sub))
            {
                foreach(
$this->History[0] as $A => $B)
                {
                    
$history .= $this->History[1][$A]."/";
                }

                foreach(
$this->History[0] as $A => $B)
                {
                    
$a .= "/".$this->History[1][$A]; $b = $this->http.$this->host.$a.".html";
                    
$this->menu_sub .= "<a href=\"".$b."\">".$this->History[2][$A]."</a> / ";
                }

                foreach(
$this->Page_Sub[0] as $A => $B)
                {
                    
$a = $this->http.$this->host."/".$history.$this->Page_Sub[1][$A].".html";
                    
$this->menu_right .= "<a href=\"".$a."\">".$this->Page_Sub[2][$A]."</a><br>";
                }
    
                foreach(
$this->Page_Sub[0] as $A => $B)
                {
                    
$tpl = $this->root_tpl.$B.".tpl";
                    
$this->menu_right = $history;
    
                    if(!empty(
$tpl) && file_exists($tpl) && is_file($tpl))
                    {
                        
$tpl = file_get_contents($tpl);
    
                        
preg_match_all("/<!-- description\r\n(.*)\r\n-->\r\n<!-- keywords\r\n(.*)\r\n-->\r\n<!-- title\r\n(.*)\r\n-->\r\n<!-- body\r\n(.*)\r\n-->/isU", $tpl, $Array);
    
                        foreach (
$Array[1] as $key => $val)
                        {
                            
$this->description = $Array[1][$key];
                        }
                    }
    
                    
$a = $this->http.$this->host."/".$history.$this->Page_Sub[1][$A].".html";
                    
$b1 .= "<tr><td class=\"sub_td\" ><a href=\"".$a."\">".$this->Page_Sub[2][$A]."</a></td></tr><tr><td>$description<br><br></td></tr>";
                    
$this->body_sub = "<table class=\"sub_table\">".$b1."</table>";
                }
    
                
$TPL = $this->root_tpl.$this->Page[0].".tpl";

                if(!empty(
$TPL) && file_exists($TPL) && is_file($TPL))
                {
                    
$tpl = file_get_contents($TPL);

                    
preg_match_all("/<!-- description\r\n(.*)\r\n-->\r\n<!-- keywords\r\n(.*)\r\n-->\r\n<!-- title\r\n(.*)\r\n-->\r\n<!-- body\r\n(.*)\r\n-->/isU", $tpl, $Array);
    
                    foreach (
$Array[1] as $key => $val)
                    {
                        
$this->description = $Array[1][$key];
                        
$this->keywords = $Array[2][$key];
                        
$this->title = $Array[3][$key];
                        
$this->body = $Array[4][$key];
                    }
                }
            }

            
$this->filter();
        }

        private function 
filter()
        {
            
$this->body = htmlspecialchars($this->body, ENT_QUOTES);
            
$this->body = strip_tags($this->body);
            
$this->body = str_replace("\r\n", "<br>", $this->body);
            
$this->body = $this->BBCode->Replace($this->body, $this->root_tpl);
        }

        private function 
htm()
        {
            if(!empty(
$this->file_htm) && file_exists($this->file_htm) && is_file($this->file_htm))
            {
                
$htm = file_get_contents($this->file_htm);

                
$htm = str_replace("%stylesheet%", $this->http_css, $htm);
                
$htm = str_replace("%icon%", $this->http_ico, $htm);
                
$htm = str_replace("%charset%", $this->charset, $htm);
                
$htm = str_replace("%language%", $this->language, $htm);
                
$htm = str_replace("%description%", $this->description, $htm);
                
$htm = str_replace("%keywords%", $this->keywords, $htm);
                
$htm = str_replace("%javascript%", $this->http_js, $htm);
                
$htm = str_replace("%title%", $this->title, $htm);
                
$htm = str_replace("%menu_up%", $this->menu_up, $htm);
                
$htm = str_replace("%menu_right%", $this->menu_right, $htm);
                
$htm = str_replace("%menu_sub%", $this->menu_sub, $htm);
                
$htm = str_replace("%body%", $this->body, $htm);
                
$htm = str_replace("%body_sub%", $this->body_sub, $htm);

                if(!empty(
$htm) && is_string($htm))
                {
                    print 
$htm;
                }
            }
        }

        private function 
Tree($URI, $Map, $ID, $Name, $Title)
        {
            if(!empty(
$URI) && !empty($Map) && !empty($ID) && !empty($Name) && !empty($Title))
            {
                foreach (
$URI[1] as $URI_ID => $URI_Name)
                {
                    foreach(
$Name as $Name_ID => $Name_Name)
                    {
                        if(
$URI[1][$URI_ID] == $Name_Name)
                        {
                            if(
is_array($Map[$ID[$Name_ID]]))
                            {
                                
$this->History[0][] = $ID[$Name_ID];
                                
$this->History[1][] = $URI_Name;
                                
$this->History[2][] = $Title[$Name_ID];
    
                                
$this->Page[0] = $ID[$Name_ID];
                                
$this->Page[1] = $Name_Name;
                                
$this->Page[2] = $Title[$Name_ID];
    
                                foreach(
$Map[$ID[$Name_ID]] as $MA => $MB)
                                {
                                    foreach(
$ID as $IDA => $IDB)
                                    {
                                        if(
$IDB == $MA)
                                        {
                                            
$A[] = $ID[$IDA]; 
                                            
$B[] = $Name[$IDA];
                                            
$C[] = $Title[$IDA]; 
    
                                            
$this->Page_Sub[0]=$A; 
                                            
$this->Page_Sub[1]=$B;
                                            
$this->Page_Sub[2]=$C; 
                                        }
                                    }
                                }
    
                                
$this->Tree($URI, $Map[$ID[$Name_ID]], $ID, $Name, $Title);
                            }
                            else
                            {
                                
$this->Page[0] = $ID[$Name_ID];
                                
$this->Page[1] = $Name_Name;
                                
$this->Page[2] = $Title[$Name_ID];
                            }
                        }
                    }
                }
            }
        }
    }

    new 
template();
?> 


спасибо!

  Ответить  
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования