Changeset 21807
- Timestamp:
- 2012/05/05 14:35:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_Transform.php
r21775 r21807 72 72 $source 73 73 ); 74 75 // headタグの内側を退避 76 $source = preg_replace_callback( 77 '/(<head[^>]*>)(.+)(<\/head>)/is', 78 array($this, 'lfCaptureHeadTags2Comment'), 79 $source 80 ); 81 74 82 // JavaScript内にSmartyのタグが存在するものを、コメント形式に置換 75 83 $source = preg_replace_callback( … … 78 86 $source 79 87 ); 88 80 89 // HTMLタグ内にSmartyのタグが存在するものを、まず置換する 81 90 $source = preg_replace_callback( … … 84 93 $source 85 94 ); 95 86 96 // 通常のノードに属する部分を、コメント形式に置換 87 97 $source = preg_replace_callback( … … 91 101 ); 92 102 93 // BODYタグの外側は退避させる94 if (preg_match('/^(.*? <body[^>]*>)(.+)(<\/body>.*)$/is', $source, $arrMatches)) {103 // HTMLタグの有無、BODYタグの有無で動作を切り替える 104 if (preg_match('/^(.*?)(<html[^>]*>.+<\/html>)(.*?)$/is', $source, $arrMatches)) { 95 105 $this->header_source = $arrMatches[1]; 96 106 $source = $arrMatches[2]; 97 107 $this->footer_source = $arrMatches[3]; 98 108 } 109 elseif (preg_match('/^.*?<body[^>]*>.+<\/body>.*$/is', $source)) { 110 $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></html>'; 111 } 112 else { 113 $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><body><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></body></html>'; 114 } 99 115 100 $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><body><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></body></html>';101 116 @$this->objDOM->loadHTML($source); 102 117 $this->lfScanChild($this->objDOM); … … 311 326 } elseif ($this->snip_count) { 312 327 $html = $this->objDOM->saveHTML(); 328 $html = preg_replace('/^.*(<html[^>]*>)/s', '$1', $html); 329 $html = preg_replace('/(<\/html>).*$/s', '$1', $html); 313 330 $html = preg_replace('/^.*<\!--TemplateTransformer start-->/s', '', $html); 314 331 $html = preg_replace('/<\!--TemplateTransformer end-->.*$/s', '', $html); 332 $html = preg_replace( 333 '/<\!--TemplateTransformerSnip start-->.*?<\!--TemplateTransformerSnip end-->/s', 334 '', 335 $html 336 ); 315 337 $html = $this->header_source.$html.$this->footer_source; 316 338 $html = str_replace($this->arrSmartyTagsSub, $this->arrSmartyTagsOrg, $html); … … 344 366 * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数 345 367 * 368 * コメント形式への置換 369 * 370 * @param array $arrMatches マッチしたタグの情報 371 * @return string 代わりの文字列 372 */ 373 protected function lfCaptureHeadTags2Comment(array $arrMatches) { 374 $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx); 375 $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[2]; 376 $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag; 377 $this->smarty_tags_idx++; 378 379 // 文字化け防止用のMETAを入れておく 380 $content_type_tag = '<!--TemplateTransformerSnip start-->'; 381 $content_type_tag .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'; 382 $content_type_tag .= '<!--TemplateTransformerSnip end-->'; 383 384 return $arrMatches[1].$content_type_tag.$substitute_tag.$arrMatches[3]; 385 } 386 387 388 /** 389 * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数 390 * 346 391 * HTMLエレメント内部の処理 347 392 * … … 384 429 */ 385 430 protected function lfCaptureSmartyTagsInQuote(array $arrMatches) { 386 $html = preg_replace_callback('/###TEMP(\d{8})###/s', array($this, 'lfCaptureSmartyTags2Value'), $arrMatches[0]); 431 $html = preg_replace_callback( 432 '/###TEMP(\d{8})###/s', 433 array($this, 'lfCaptureSmartyTags2Value'), 434 $arrMatches[0] 435 ); 387 436 return $html; 388 437 }
Note: See TracChangeset
for help on using the changeset viewer.