Ignore:
Timestamp:
2012/04/22 13:57:45 (12 years ago)
Author:
sunat134
Message:

#1736 Smartyのコメントはあらかじめ削除するように
#1751 Transform対象のテンプレートに<HTML>タグが含まれる場合に対応

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/helper/SC_Helper_Transform.php

    r21767 r21775  
    3737    protected $arrSelectElements; 
    3838    protected $html_source; 
     39    protected $header_source; 
     40    protected $footer_source; 
    3941    protected $search_depth; 
    4042 
     
    5658        $this->arrSelectElements = array(); 
    5759        $this->html_source = $source; 
     60        $this->header_source = NULL; 
     61        $this->footer_source = NULL; 
    5862        $this->search_depth = 0; 
    5963 
     
    6165            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'テンプレートの文字コードがUTF-8ではありません'); 
    6266        } 
    63  
     67         
     68        // Smartyのコメントを削除 
     69        $source = preg_replace( 
     70            '/<\!--{\*.+?\*\}-->/s', 
     71            '', 
     72            $source 
     73        ); 
    6474        // JavaScript内にSmartyのタグが存在するものを、コメント形式に置換 
    6575        $source = preg_replace_callback( 
     
    8191        ); 
    8292 
     93        // BODYタグの外側は退避させる 
     94        if (preg_match('/^(.*?<body[^>]*>)(.+)(<\/body>.*)$/is', $source, $arrMatches)) { 
     95            $this->header_source = $arrMatches[1]; 
     96            $source = $arrMatches[2]; 
     97            $this->footer_source = $arrMatches[3]; 
     98        } 
     99         
    83100        $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><body><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></body></html>'; 
    84101        @$this->objDOM->loadHTML($source); 
     
    294311        } elseif ($this->snip_count) { 
    295312            $html = $this->objDOM->saveHTML(); 
    296             $html = str_replace($this->arrSmartyTagsSub, $this->arrSmartyTagsOrg, $html); 
    297313            $html = preg_replace('/^.*<\!--TemplateTransformer start-->/s', '', $html); 
    298314            $html = preg_replace('/<\!--TemplateTransformer end-->.*$/s', '', $html); 
     315            $html = $this->header_source.$html.$this->footer_source; 
     316            $html = str_replace($this->arrSmartyTagsSub, $this->arrSmartyTagsOrg, $html); 
    299317            return $html; 
    300318        } else { 
Note: See TracChangeset for help on using the changeset viewer.