source: branches/camp/camp-2_13-plugin/data/class/helper/SC_Helper_Transform.php @ 22714

Revision 22714, 25.2 KB checked in by Yammy, 11 years ago (diff)

Transform にて処理されたテンプレートの箇所が分かる処理の追加

refs #2188

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * テンプレートをDOM変形するためのヘルパークラス
26 *
27 * @package Helper
28 * @version $Id$
29 */
30class SC_Helper_Transform
31{
32    protected $objDOM;
33    protected $arrSmartyTagsOrg;
34    protected $arrSmartyTagsSub;
35    protected $smarty_tags_idx;
36    protected $arrErr;
37    protected $arrElementTree;
38    protected $arrSelectElements;
39    protected $html_source;
40    protected $header_source;
41    protected $footer_source;
42    protected $search_depth;
43
44    const ERR_TARGET_ELEMENT_NOT_FOUND = 1;
45
46    /**
47     * SmartyのHTMLソースをDOMに変換しておく
48     *
49     * @param string $source 変形対象のテンプレート
50     * @return void
51     */
52    public function __construct($source)
53    {
54        $this->objDOM = new DOMDocument();
55        $this->objDOM->strictErrorChecking = false;
56        $this->snip_count      = 0;
57        $this->smarty_tags_idx = 0;
58        $this->arrErr          = array();
59        $this->arrElementTree  = array();
60        $this->arrSelectElements = array();
61        $this->html_source = $source;
62        $this->header_source = NULL;
63        $this->footer_source = NULL;
64        $this->search_depth = 0;
65
66        $encoding = mb_detect_encoding($source);
67        if (!in_array($encoding, array('ASCII', 'UTF-8'))) {
68            if ($encoding === false) {
69                $encoding = '検出不能';
70            }
71            $msg = 'テンプレートの文字コードが「' . $encoding . '」です。「UTF-8」のみ利用できます。';
72            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, $msg);
73        }
74
75        // Smartyのコメントを削除
76        $source = preg_replace(
77            '/<\!--{\*.+?\*\}-->/s',
78            '',
79            $source
80        );
81
82        // headタグの内側を退避
83        $source = preg_replace_callback(
84            '/(<head[^>]*>)(.+)(<\/head>)/is',
85            array($this, 'lfCaptureHeadTags2Comment'),
86            $source
87        );
88
89        // JavaScript内にSmartyのタグが存在するものを、コメント形式に置換
90        $source = preg_replace_callback(
91            '/<script.+?\/script>/s',
92            array($this, 'lfCaptureSmartyTags2Comment'),
93            $source
94        );
95
96        // HTMLタグ内にSmartyのタグが存在するものを、まず置換する
97        $source = preg_replace_callback(
98            '/<(?:[^<>]*?(?:(<\!--\{.+?\}-->)|(?R))[^<>]*?)*?>/s',
99            array($this, 'lfCaptureSmartyTagsInTag'),
100            $source
101        );
102
103        // 通常のノードに属する部分を、コメント形式に置換
104        $source = preg_replace_callback(
105            '/<\!--{.+?\}-->/s',
106            array($this, 'lfCaptureSmartyTags2Comment'),
107            $source
108        );
109
110        // HTMLタグの有無、BODYタグの有無で動作を切り替える
111        if (preg_match('/^(.*?)(<html[^>]*>.+<\/html>)(.*?)$/is', $source, $arrMatches)) {
112            $this->header_source = $arrMatches[1];
113            $source = $arrMatches[2];
114            $this->footer_source = $arrMatches[3];
115        } elseif (preg_match('/^.*?<body[^>]*>.+<\/body>.*$/is', $source)) {
116            $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></html>';
117        }
118        else {
119            $source = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><html><body><!--TemplateTransformer start-->'.$source.'<!--TemplateTransformer end--></body></html>';
120        }
121
122        @$this->objDOM->loadHTML($source);
123        $this->lfScanChild($this->objDOM);
124    }
125
126
127    /**
128     * jQueryライクなセレクタを用いてエレメントを選択する
129     *
130     * @param string  $selector      セレクタ
131     * @param integer $index         インデックス(指定がある場合)
132     * @param boolean $require       エレメントが見つからなかった場合、エラーとするか
133     * @param string  $err_msg       エラーメッセージ
134     * @return SC_Helper_Transformオブジェクト
135     */
136    public function select($selector, $index = NULL, $require = true, $err_msg = NULL)
137    {
138        $this->arrSelectElements = array();
139        $this->search_depth = 0;
140
141        $regex = $this->lfSelector2Regex($selector);    // セレクタをツリー検索用正規表現に変換
142
143        $cur_idx = 0;
144        // ツリーを初めから全検索する
145        for ($iLoop=0; $iLoop < count($this->arrElementTree); $iLoop++) {
146            if (preg_match($regex, $this->arrElementTree[$iLoop][0])) {
147                // インデックスが指定されていない(見つけたエレメント全て)、もしくは指定されたインデックスなら選択する
148                if (is_null($index) || $cur_idx == $index) {
149                    $this->lfAddElement($iLoop, $this->arrElementTree[$iLoop]);
150                }
151                $cur_idx++;
152            }
153        }
154
155        // 見つからなかった場合エラーとするならエラーを記録する
156        if ($require && $cur_idx == 0) {
157            $this->lfSetError(
158                $selector,
159                self::ERR_TARGET_ELEMENT_NOT_FOUND,
160                $err_msg
161            );
162        }
163
164        return $this;
165    }
166
167
168    /**
169     * jQueryライクなセレクタを用いて、選択したエレメント内をさらに絞り込む
170     *
171     * @param string  $selector      セレクタ
172     * @param integer $index         インデックス(指定がある場合)
173     * @param boolean $require       エレメントが見つからなかった場合、エラーとするか
174     * @param string  $err_msg       エラーメッセージ
175     * @return SC_Helper_Transformオブジェクト
176     */
177    public function find($selector, $index = NULL, $require = true, $err_msg = NULL)
178    {
179        $arrParentElements = $this->arrSelectElements[$this->search_depth];
180        $this->search_depth++;
181        $this->arrSelectElements[$this->search_depth] = array();
182
183        foreach ($arrParentElements as $key => &$objElement) {
184            $regex = $this->lfSelector2Regex($selector, $objElement[0]);    // セレクタをツリー検索用正規表現に変換(親要素のセレクタを頭に付ける)
185
186            $cur_idx = 0;
187            // 親エレメント位置からツリーを検索する
188            for ($iLoop=$objElement[0]; $iLoop < count($this->arrElementTree); $iLoop++) {
189                if (preg_match($regex, $this->arrElementTree[$iLoop][0])) {
190                    // インデックスが指定されていない(見つけたエレメント全て)、もしくは指定されたインデックスなら選択する
191                    if (is_null($index) || $cur_idx == $index) {
192                        $this->lfAddElement($iLoop, $this->arrElementTree[$iLoop]);
193                    }
194                    $cur_idx++;
195                }
196            }
197        }
198
199        // 見つからなかった場合エラーとするならエラーを記録する
200        if ($require && count($this->arrSelectElements[$this->search_depth]) == 0) {
201            $this->lfSetError(
202                $selector,
203                self::ERR_TARGET_ELEMENT_NOT_FOUND,
204                $err_msg
205            );
206        }
207
208        return $this;
209    }
210
211
212    /**
213     * 選択状態を指定数戻す
214     *
215     * @param int $back_num 選択状態を戻す数
216     * @return SC_Helper_Transformオブジェクト
217     */
218    public function end($back_num = 1)
219    {
220        if ($this->search_depth >= $back_num) {
221            $this->search_depth -= $back_num;
222        } else {
223            $this->search_depth = 0;
224        }
225
226        return $this;
227    }
228
229
230    /**
231     * 要素の前にHTMLを挿入
232     *
233     * @param string $html_snip 挿入するHTMLの断片
234     * @return SC_Helper_Transformオブジェクト
235     */
236    public function insertBefore($html_snip)
237    {
238        foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
239            $this->lfSetTransform('insertBefore', $objElement[0], $html_snip);
240        }
241        return $this;
242    }
243
244
245    /**
246     * 要素の後にHTMLを挿入
247     *
248     * @param string $html_snip 挿入するHTMLの断片
249     * @return SC_Helper_Transformオブジェクト
250     */
251    public function insertAfter($html_snip)
252    {
253        foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
254            $this->lfSetTransform('insertAfter', $objElement[0], $html_snip);
255        }
256        return $this;
257    }
258
259
260    /**
261     * 要素の先頭にHTMLを挿入
262     *
263     * @param string $html_snip 挿入するHTMLの断片
264     * @return SC_Helper_Transformオブジェクト
265     */
266    public function appendFirst($html_snip)
267    {
268        foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
269            $this->lfSetTransform('appendFirst', $objElement[0], $html_snip);
270        }
271        return $this;
272    }
273
274
275    /**
276     * 要素の末尾にHTMLを挿入
277     *
278     * @param string $html_snip 挿入するHTMLの断片
279     * @return SC_Helper_Transformオブジェクト
280     */
281    public function appendChild($html_snip)
282    {
283        foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
284            $this->lfSetTransform('appendChild', $objElement[0], $html_snip);
285        }
286        return $this;
287    }
288
289
290    /**
291     * 要素を指定したHTMLに置換
292     *
293     * @param string $html_snip 置換後のHTMLの断片
294     * @return SC_Helper_Transformオブジェクト
295     */
296    public function replaceElement($html_snip)
297    {
298        foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) {
299            $this->lfSetTransform('replaceElement', $objElement[0], $html_snip);
300        }
301        return $this;
302    }
303
304
305    /**
306     * 要素を削除する
307     *
308     * @return SC_Helper_Transformオブジェクト
309     */
310    public function removeElement()
311    {
312        foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) {
313            $this->lfSetTransform('replaceElement', $objElement[0], '');
314        }
315        return $this;
316    }
317
318
319    /**
320     * HTMLに戻して、Transform用に付けたマーカーを削除し、Smartyのタグを復元する
321     *
322     * @return string トランスフォーム済みHTML。まったくトランスフォームが行われなかった場合は元のHTMLを返す。。
323     */
324    public function getHTML()
325    {
326        if (count($this->arrErr)) {
327            // エラーメッセージ組み立て
328            $err_msg = '';
329            foreach ($this->arrErr as $arrErr) {
330                if ($arrErr['err_msg']) {
331                    $err_msg .= '<br />'.$arrErr['err_msg'];
332                } else {
333                    if ($arrErr['type'] == self::ERR_TARGET_ELEMENT_NOT_FOUND) {
334                        $err_msg .= "<br />${arrErr['selector']} が存在しません";
335                    } else {
336                        $err_msg .= '<br />'.print_r($arrErr, true);
337                    }
338                }
339            }
340            // エラー画面表示
341            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'テンプレートの操作に失敗しました。' . $err_msg);
342        } elseif ($this->snip_count) {
343            $html = $this->objDOM->saveHTML();
344            $html = preg_replace('/^.*(<html[^>]*>)/s', '$1', $html);
345            $html = preg_replace('/(<\/html>).*$/s', '$1', $html);
346            $html = preg_replace('/^.*<\!--TemplateTransformer start-->/s', '', $html);
347            $html = preg_replace('/<\!--TemplateTransformer end-->.*$/s', '', $html);
348            $html = preg_replace(
349                '/<\!--TemplateTransformerSnip start-->.*?<\!--TemplateTransformerSnip end-->/s',
350                '',
351                $html
352            );
353            $html = $this->header_source.$html.$this->footer_source;
354            $html = str_replace($this->arrSmartyTagsSub, $this->arrSmartyTagsOrg, $html);
355            return $html;
356        } else {
357            return $this->html_source;
358        }
359    }
360
361
362
363
364    /**
365     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
366     *
367     * コメント形式への置換
368     *
369     * @param array $arrMatches マッチしたタグの情報
370     * @return string 代わりの文字列
371     */
372    protected function lfCaptureSmartyTags2Comment(array $arrMatches)
373    {
374        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
375        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0];
376        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
377        $this->smarty_tags_idx++;
378        return $substitute_tag;
379    }
380
381
382    /**
383     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
384     *
385     * コメント形式への置換
386     *
387     * @param array $arrMatches マッチしたタグの情報
388     * @return string 代わりの文字列
389     */
390    protected function lfCaptureHeadTags2Comment(array $arrMatches)
391    {
392        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
393        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[2];
394        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
395        $this->smarty_tags_idx++;
396
397        // 文字化け防止用のMETAを入れておく
398        $content_type_tag = '<!--TemplateTransformerSnip start-->';
399        $content_type_tag .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
400        $content_type_tag .= '<!--TemplateTransformerSnip end-->';
401
402        return $arrMatches[1].$content_type_tag.$substitute_tag.$arrMatches[3];
403    }
404
405
406    /**
407     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
408     *
409     * HTMLエレメント内部の処理
410     *
411     * @param array $arrMatches マッチしたタグの情報
412     * @return string 代わりの文字列
413     */
414    protected function lfCaptureSmartyTagsInTag(array $arrMatches)
415    {
416        // Smartyタグ内のクォートを処理しやすいよう、いったんダミーのタグに
417        $html = preg_replace_callback('/<\!--{.+?\}-->/s', array($this, 'lfCaptureSmartyTags2Temptag'), $arrMatches[0]);
418        $html = preg_replace_callback('/\"[^"]*?\"/s', array($this, 'lfCaptureSmartyTagsInQuote'), $html);
419        $html = preg_replace_callback('/###TEMP(\d{8})###/s', array($this, 'lfCaptureSmartyTags2Attr'), $html);
420        return $html;
421    }
422
423
424    /**
425     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
426     *
427     * ダミーへの置換実行
428     *
429     * @param array $arrMatches マッチしたタグの情報
430     * @return string 代わりの文字列
431     */
432    protected function lfCaptureSmartyTags2Temptag(array $arrMatches)
433    {
434        $substitute_tag = sprintf('###TEMP%08d###', $this->smarty_tags_idx);
435        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0];
436        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
437        $this->smarty_tags_idx++;
438        return $substitute_tag;
439    }
440
441
442    /**
443     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
444     *
445     * クォート内(=属性値)内にあるSmartyタグ(ダミーに置換済み)を、テキストに置換
446     *
447     * @param array $arrMatches マッチしたタグの情報
448     * @return string 代わりの文字列
449     */
450    protected function lfCaptureSmartyTagsInQuote(array $arrMatches)
451    {
452        $html = preg_replace_callback(
453            '/###TEMP(\d{8})###/s',
454            array($this, 'lfCaptureSmartyTags2Value'),
455            $arrMatches[0]
456        );
457        return $html;
458    }
459
460
461    /**
462     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
463     *
464     * テキストへの置換実行
465     *
466     * @param array $arrMatches マッチしたタグの情報
467     * @return string 代わりの文字列
468     */
469    protected function lfCaptureSmartyTags2Value(array $arrMatches)
470    {
471        $tag_idx = (int)$arrMatches[1];
472        $substitute_tag = sprintf('###%08d###', $tag_idx);
473        $this->arrSmartyTagsSub[$tag_idx] = $substitute_tag;
474        return $substitute_tag;
475    }
476
477
478    /**
479     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
480     *
481     * エレメント内部にあって、属性値ではないものを、ダミーの属性として置換
482     *
483     * @param array $arrMatches マッチしたタグの情報
484     * @return string 代わりの文字列
485     */
486    protected function lfCaptureSmartyTags2Attr(array $arrMatches)
487    {
488        $tag_idx = (int)$arrMatches[1];
489        $substitute_tag = sprintf('rel%08d="######"', $tag_idx);
490        $this->arrSmartyTagsSub[$tag_idx] = $substitute_tag;
491        return ' '.$substitute_tag.' '; // 属性はパース時にスペースが詰まるので、こちらにはスペースを入れておく
492    }
493
494
495    /**
496     * DOM Element / Document を走査し、name、class別に分類する
497     *
498     * @param  DOMNode $objDOMElement DOMNodeオブジェクト
499     * @return void
500     */
501    protected function lfScanChild(DOMNode $objDOMElement, $parent_selector = '')
502    {
503        $objNodeList = $objDOMElement->childNodes;
504        if (is_null($objNodeList)) return;
505
506        foreach ($objNodeList as $element) {
507            // DOMElementのみ取り出す
508            if ($element instanceof DOMElement) {
509                $arrAttr = array();
510                $arrAttr[] = $element->tagName;
511                if (method_exists($element, 'getAttribute')) {
512                    // idを持っていればidを付加する
513                    if ($element->hasAttribute('id'))
514                        $arrAttr[] = '#'.$element->getAttribute('id');
515                    // classを持っていればclassを付加する(複数の場合は複数付加する)
516                    if ($element->hasAttribute('class')) {
517                        $arrClasses = preg_split('/\s+/', $element->getAttribute('class'));
518                        foreach ($arrClasses as $classname) $arrAttr[] = '.'.$classname;
519                    }
520                }
521                // 親要素のセレクタを付けてツリーへ登録する
522                $this_selector = $parent_selector.' '.implode('', $arrAttr);
523                $this->arrElementTree[] = array($this_selector, $element);
524                // エレメントが子孫要素を持っていればさらに調べる
525                if ($element->hasChildNodes()) $this->lfScanChild($element, $this_selector);
526            }
527        }
528    }
529
530
531    /**
532     * セレクタ文字列をツリー検索用の正規表現に変換する
533     *
534     * @param string $selector      セレクタ
535     * @param string $parent_index  セレクタ検索時の親要素の位置(子孫要素検索のため)
536     * @return string 正規表現文字列
537     */
538    protected function lfSelector2Regex($selector, $parent_index = NULL)
539    {
540        // jQueryライクなセレクタを正規表現に
541        $selector = preg_replace('/ *> */', ' >', $selector);   // 子セレクタをツリー検索用に 「A >B」の記法にする
542        $regex = '/';
543        if (!is_null($parent_index)) $regex .= preg_quote($this->arrElementTree[$parent_index][0], '/');    // (親要素の指定(絞り込み時)があれば頭に付加する(特殊文字はエスケープ)
544        $arrSelectors = explode(' ', $selector);
545        foreach ($arrSelectors as $sub_selector) {
546            if (preg_match('/^(>?)([\w\-]+)?(#[\w\-]+)?(\.[\w\-]+)*$/', $sub_selector, $arrMatch)) {
547                // 子セレクタ
548                if (isset($arrMatch[1]) && $arrMatch[1]) $regex .= ' ';
549                else $regex .= '.* ';
550                // タグ名
551                if (isset($arrMatch[2]) && $arrMatch[2]) $regex .= preg_quote($arrMatch[2], '/');
552                else $regex .= '([\w\-]+)?';
553                // id
554                if (isset($arrMatch[3]) && $arrMatch[3]) $regex .= preg_quote($arrMatch[3], '/');
555                else $regex .= '(#(\w|\-|#{3}[0-9]{8}#{3})+)?';
556                // class
557                if (isset($arrMatch[4]) && $arrMatch[4]) $regex .= '(\.(\w|\-|#{3}[0-9]{8}#{3})+)*'.preg_quote($arrMatch[4], '/').'(\.(\w|\-|#{3}[0-9]{8}#{3})+)*'; // class指定の時は前後にもclassが付いているかもしれない
558                else $regex .= '(\.(\w|\-|#{3}[0-9]{8}#{3})+)*';
559            }
560        }
561        $regex .= '$/i';
562
563        return $regex;
564    }
565
566
567    /**
568     * 見つかった要素をプロパティに登録
569     *
570     * @param integer $elementNo  エレメントのインデックス
571     * @param array   $arrElement インデックスとDOMオブジェクトをペアとした配列
572     * @return void
573     */
574    protected function lfAddElement($elementNo, array &$arrElement)
575    {
576        if (is_array($this->arrSelectElements[$this->search_depth]) && array_key_exists($arrElement[0], $this->arrSelectElements[$this->search_depth])) {
577            //nop
578        } else {
579            $this->arrSelectElements[$this->search_depth][$arrElement[0]] = array($elementNo, &$arrElement[1]);
580        }
581
582    }
583
584
585    /**
586     * DOMを用いた変形を実行する
587     *
588     * @param string $mode       実行するメソッドの種類
589     * @param string $target_key 対象のエレメントの完全なセレクタ
590     * @param string $html_snip  HTMLコード
591     * @return boolean
592     */
593    protected function lfSetTransform($mode, $target_key, $html_snip)
594    {
595        if (PLUGIN_DEBUG_MODE) {
596            $html_snip = '<div style="background-color:pink;">' . $html_snip . '</div>';
597        }
598
599        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
600        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $html_snip;
601        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
602        $this->smarty_tags_idx++;
603
604        $this->objDOM->createDocumentFragment();
605        $objSnip = $this->objDOM->createDocumentFragment();
606        $objSnip->appendXML($substitute_tag);
607
608        $objElement = false;
609        if (isset($this->arrElementTree[$target_key]) && $this->arrElementTree[$target_key][0]) {
610            $objElement = &$this->arrElementTree[$target_key][1];
611        }
612
613        if (!$objElement) return false;
614
615        try {
616            switch ($mode) {
617                case 'appendFirst':
618                    if ($objElement->hasChildNodes()) {
619                        $objElement->insertBefore($objSnip, $objElement->firstChild);
620                    } else {
621                        $objElement->appendChild($objSnip);
622                    }
623                    break;
624                case 'appendChild':
625                    $objElement->appendChild($objSnip);
626                    break;
627                case 'insertBefore':
628                    if (!is_object($objElement->parentNode)) return false;
629                    $objElement->parentNode->insertBefore($objSnip, $objElement);
630                    break;
631                case 'insertAfter':
632                    if ($objElement->nextSibling) {
633                         $objElement->parentNode->insertBefore($objSnip, $objElement->nextSibling);
634                    } else {
635                         $objElement->parentNode->appendChild($objSnip);
636                    }
637                    break;
638                case 'replaceElement':
639                    if (!is_object($objElement->parentNode)) return false;
640                    $objElement->parentNode->replaceChild($objSnip, $objElement);
641                    break;
642                default:
643                    break;
644            }
645            $this->snip_count++;
646        }
647        catch (Exception $e) {
648            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'テンプレートの操作に失敗しました。');
649        }
650
651        return true;
652    }
653
654
655    /**
656     * セレクタエラーを記録する
657     *
658     * @param string  $selector    セレクタ
659     * @param integer $type        エラーの種類
660     * @param string  $err_msg     エラーメッセージ
661     * @return void
662     */
663    protected function lfSetError($selector, $type, $err_msg = NULL)
664    {
665        $this->arrErr[] = array(
666            'selector'    => $selector,
667            'type'        => $type,
668            'err_msg'     => $err_msg
669        );
670    }
671}
Note: See TracBrowser for help on using the repository browser.