source: branches/version-2_13-dev/data/class/helper/SC_Helper_Transform.php @ 22823

Revision 22823, 25.6 KB checked in by Seasoft, 11 years ago (diff)

#2248 (PHP 警告撲滅 for 2.13.0)

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        if (isset($this->arrSelectElements[$this->search_depth])) {
239            foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
240                $this->lfSetTransform('insertBefore', $objElement[0], $html_snip);
241            }
242        }
243        return $this;
244    }
245
246
247    /**
248     * 要素の後にHTMLを挿入
249     *
250     * @param string $html_snip 挿入するHTMLの断片
251     * @return SC_Helper_Transformオブジェクト
252     */
253    public function insertAfter($html_snip)
254    {
255        if (isset($this->arrSelectElements[$this->search_depth])) {
256            foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
257                $this->lfSetTransform('insertAfter', $objElement[0], $html_snip);
258            }
259        }
260        return $this;
261    }
262
263
264    /**
265     * 要素の先頭にHTMLを挿入
266     *
267     * @param string $html_snip 挿入するHTMLの断片
268     * @return SC_Helper_Transformオブジェクト
269     */
270    public function appendFirst($html_snip)
271    {
272        if (isset($this->arrSelectElements[$this->search_depth])) {
273            foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
274                $this->lfSetTransform('appendFirst', $objElement[0], $html_snip);
275            }
276        }
277        return $this;
278    }
279
280
281    /**
282     * 要素の末尾にHTMLを挿入
283     *
284     * @param string $html_snip 挿入するHTMLの断片
285     * @return SC_Helper_Transformオブジェクト
286     */
287    public function appendChild($html_snip)
288    {
289        if (isset($this->arrSelectElements[$this->search_depth])) {
290            foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) {
291                $this->lfSetTransform('appendChild', $objElement[0], $html_snip);
292            }
293        }
294        return $this;
295    }
296
297
298    /**
299     * 要素を指定したHTMLに置換
300     *
301     * @param string $html_snip 置換後のHTMLの断片
302     * @return SC_Helper_Transformオブジェクト
303     */
304    public function replaceElement($html_snip)
305    {
306        if (isset($this->arrSelectElements[$this->search_depth])) {
307            foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) {
308                $this->lfSetTransform('replaceElement', $objElement[0], $html_snip);
309            }
310        }
311        return $this;
312    }
313
314
315    /**
316     * 要素を削除する
317     *
318     * @return SC_Helper_Transformオブジェクト
319     */
320    public function removeElement()
321    {
322        if (isset($this->arrSelectElements[$this->search_depth])) {
323            foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) {
324                $this->lfSetTransform('replaceElement', $objElement[0], '');
325            }
326        }
327        return $this;
328    }
329
330
331    /**
332     * HTMLに戻して、Transform用に付けたマーカーを削除し、Smartyのタグを復元する
333     *
334     * @return string トランスフォーム済みHTML。まったくトランスフォームが行われなかった場合は元のHTMLを返す。。
335     */
336    public function getHTML()
337    {
338        if (count($this->arrErr)) {
339            // エラーメッセージ組み立て
340            $err_msg = '';
341            foreach ($this->arrErr as $arrErr) {
342                if ($arrErr['err_msg']) {
343                    $err_msg .= '<br />'.$arrErr['err_msg'];
344                } else {
345                    if ($arrErr['type'] == self::ERR_TARGET_ELEMENT_NOT_FOUND) {
346                        $err_msg .= "<br />${arrErr['selector']} が存在しません";
347                    } else {
348                        $err_msg .= '<br />'.print_r($arrErr, true);
349                    }
350                }
351            }
352            // エラー画面表示
353            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'テンプレートの操作に失敗しました。' . $err_msg);
354        } elseif ($this->snip_count) {
355            $html = $this->objDOM->saveHTML();
356            $html = preg_replace('/^.*(<html[^>]*>)/s', '$1', $html);
357            $html = preg_replace('/(<\/html>).*$/s', '$1', $html);
358            $html = preg_replace('/^.*<\!--TemplateTransformer start-->/s', '', $html);
359            $html = preg_replace('/<\!--TemplateTransformer end-->.*$/s', '', $html);
360            $html = preg_replace(
361                '/<\!--TemplateTransformerSnip start-->.*?<\!--TemplateTransformerSnip end-->/s',
362                '',
363                $html
364            );
365            $html = $this->header_source.$html.$this->footer_source;
366            $html = str_replace($this->arrSmartyTagsSub, $this->arrSmartyTagsOrg, $html);
367            return $html;
368        } else {
369            return $this->html_source;
370        }
371    }
372
373
374
375
376    /**
377     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
378     *
379     * コメント形式への置換
380     *
381     * @param array $arrMatches マッチしたタグの情報
382     * @return string 代わりの文字列
383     */
384    protected function lfCaptureSmartyTags2Comment(array $arrMatches)
385    {
386        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
387        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0];
388        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
389        $this->smarty_tags_idx++;
390        return $substitute_tag;
391    }
392
393
394    /**
395     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
396     *
397     * コメント形式への置換
398     *
399     * @param array $arrMatches マッチしたタグの情報
400     * @return string 代わりの文字列
401     */
402    protected function lfCaptureHeadTags2Comment(array $arrMatches)
403    {
404        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
405        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[2];
406        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
407        $this->smarty_tags_idx++;
408
409        // 文字化け防止用のMETAを入れておく
410        $content_type_tag = '<!--TemplateTransformerSnip start-->';
411        $content_type_tag .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
412        $content_type_tag .= '<!--TemplateTransformerSnip end-->';
413
414        return $arrMatches[1].$content_type_tag.$substitute_tag.$arrMatches[3];
415    }
416
417
418    /**
419     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
420     *
421     * HTMLエレメント内部の処理
422     *
423     * @param array $arrMatches マッチしたタグの情報
424     * @return string 代わりの文字列
425     */
426    protected function lfCaptureSmartyTagsInTag(array $arrMatches)
427    {
428        // Smartyタグ内のクォートを処理しやすいよう、いったんダミーのタグに
429        $html = preg_replace_callback('/<\!--{.+?\}-->/s', array($this, 'lfCaptureSmartyTags2Temptag'), $arrMatches[0]);
430        $html = preg_replace_callback('/\"[^"]*?\"/s', array($this, 'lfCaptureSmartyTagsInQuote'), $html);
431        $html = preg_replace_callback('/###TEMP(\d{8})###/s', array($this, 'lfCaptureSmartyTags2Attr'), $html);
432        return $html;
433    }
434
435
436    /**
437     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
438     *
439     * ダミーへの置換実行
440     *
441     * @param array $arrMatches マッチしたタグの情報
442     * @return string 代わりの文字列
443     */
444    protected function lfCaptureSmartyTags2Temptag(array $arrMatches)
445    {
446        $substitute_tag = sprintf('###TEMP%08d###', $this->smarty_tags_idx);
447        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0];
448        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
449        $this->smarty_tags_idx++;
450        return $substitute_tag;
451    }
452
453
454    /**
455     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
456     *
457     * クォート内(=属性値)内にあるSmartyタグ(ダミーに置換済み)を、テキストに置換
458     *
459     * @param array $arrMatches マッチしたタグの情報
460     * @return string 代わりの文字列
461     */
462    protected function lfCaptureSmartyTagsInQuote(array $arrMatches)
463    {
464        $html = preg_replace_callback(
465            '/###TEMP(\d{8})###/s',
466            array($this, 'lfCaptureSmartyTags2Value'),
467            $arrMatches[0]
468        );
469        return $html;
470    }
471
472
473    /**
474     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
475     *
476     * テキストへの置換実行
477     *
478     * @param array $arrMatches マッチしたタグの情報
479     * @return string 代わりの文字列
480     */
481    protected function lfCaptureSmartyTags2Value(array $arrMatches)
482    {
483        $tag_idx = (int)$arrMatches[1];
484        $substitute_tag = sprintf('###%08d###', $tag_idx);
485        $this->arrSmartyTagsSub[$tag_idx] = $substitute_tag;
486        return $substitute_tag;
487    }
488
489
490    /**
491     * DOMの処理の邪魔になるSmartyのタグを代理文字に置換する preg_replace_callback のコールバック関数
492     *
493     * エレメント内部にあって、属性値ではないものを、ダミーの属性として置換
494     *
495     * @param array $arrMatches マッチしたタグの情報
496     * @return string 代わりの文字列
497     */
498    protected function lfCaptureSmartyTags2Attr(array $arrMatches)
499    {
500        $tag_idx = (int)$arrMatches[1];
501        $substitute_tag = sprintf('rel%08d="######"', $tag_idx);
502        $this->arrSmartyTagsSub[$tag_idx] = $substitute_tag;
503        return ' '.$substitute_tag.' '; // 属性はパース時にスペースが詰まるので、こちらにはスペースを入れておく
504    }
505
506
507    /**
508     * DOM Element / Document を走査し、name、class別に分類する
509     *
510     * @param  DOMNode $objDOMElement DOMNodeオブジェクト
511     * @return void
512     */
513    protected function lfScanChild(DOMNode $objDOMElement, $parent_selector = '')
514    {
515        $objNodeList = $objDOMElement->childNodes;
516        if (is_null($objNodeList)) return;
517
518        foreach ($objNodeList as $element) {
519            // DOMElementのみ取り出す
520            if ($element instanceof DOMElement) {
521                $arrAttr = array();
522                $arrAttr[] = $element->tagName;
523                if (method_exists($element, 'getAttribute')) {
524                    // idを持っていればidを付加する
525                    if ($element->hasAttribute('id'))
526                        $arrAttr[] = '#'.$element->getAttribute('id');
527                    // classを持っていればclassを付加する(複数の場合は複数付加する)
528                    if ($element->hasAttribute('class')) {
529                        $arrClasses = preg_split('/\s+/', $element->getAttribute('class'));
530                        foreach ($arrClasses as $classname) $arrAttr[] = '.'.$classname;
531                    }
532                }
533                // 親要素のセレクタを付けてツリーへ登録する
534                $this_selector = $parent_selector.' '.implode('', $arrAttr);
535                $this->arrElementTree[] = array($this_selector, $element);
536                // エレメントが子孫要素を持っていればさらに調べる
537                if ($element->hasChildNodes()) $this->lfScanChild($element, $this_selector);
538            }
539        }
540    }
541
542
543    /**
544     * セレクタ文字列をツリー検索用の正規表現に変換する
545     *
546     * @param string $selector      セレクタ
547     * @param string $parent_index  セレクタ検索時の親要素の位置(子孫要素検索のため)
548     * @return string 正規表現文字列
549     */
550    protected function lfSelector2Regex($selector, $parent_index = NULL)
551    {
552        // jQueryライクなセレクタを正規表現に
553        $selector = preg_replace('/ *> */', ' >', $selector);   // 子セレクタをツリー検索用に 「A >B」の記法にする
554        $regex = '/';
555        if (!is_null($parent_index)) $regex .= preg_quote($this->arrElementTree[$parent_index][0], '/');    // (親要素の指定(絞り込み時)があれば頭に付加する(特殊文字はエスケープ)
556        $arrSelectors = explode(' ', $selector);
557        foreach ($arrSelectors as $sub_selector) {
558            if (preg_match('/^(>?)([\w\-]+)?(#[\w\-]+)?(\.[\w\-]+)*$/', $sub_selector, $arrMatch)) {
559                // 子セレクタ
560                if (isset($arrMatch[1]) && $arrMatch[1]) $regex .= ' ';
561                else $regex .= '.* ';
562                // タグ名
563                if (isset($arrMatch[2]) && $arrMatch[2]) $regex .= preg_quote($arrMatch[2], '/');
564                else $regex .= '([\w\-]+)?';
565                // id
566                if (isset($arrMatch[3]) && $arrMatch[3]) $regex .= preg_quote($arrMatch[3], '/');
567                else $regex .= '(#(\w|\-|#{3}[0-9]{8}#{3})+)?';
568                // class
569                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が付いているかもしれない
570                else $regex .= '(\.(\w|\-|#{3}[0-9]{8}#{3})+)*';
571            }
572        }
573        $regex .= '$/i';
574
575        return $regex;
576    }
577
578
579    /**
580     * 見つかった要素をプロパティに登録
581     *
582     * @param integer $elementNo  エレメントのインデックス
583     * @param array   $arrElement インデックスとDOMオブジェクトをペアとした配列
584     * @return void
585     */
586    protected function lfAddElement($elementNo, array &$arrElement)
587    {
588        if (is_array($this->arrSelectElements[$this->search_depth]) && array_key_exists($arrElement[0], $this->arrSelectElements[$this->search_depth])) {
589            //nop
590        } else {
591            $this->arrSelectElements[$this->search_depth][$arrElement[0]] = array($elementNo, &$arrElement[1]);
592        }
593    }
594
595
596    /**
597     * DOMを用いた変形を実行する
598     *
599     * @param string $mode       実行するメソッドの種類
600     * @param string $target_key 対象のエレメントの完全なセレクタ
601     * @param string $html_snip  HTMLコード
602     * @return boolean
603     */
604    protected function lfSetTransform($mode, $target_key, $html_snip)
605    {
606
607        $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx);
608        $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $html_snip;
609        $this->arrSmartyTagsSub[$this->smarty_tags_idx] = $substitute_tag;
610        $this->smarty_tags_idx++;
611
612        $this->objDOM->createDocumentFragment();
613        $objSnip = $this->objDOM->createDocumentFragment();
614        $objSnip->appendXML($substitute_tag);
615
616        $objElement = false;
617        if (isset($this->arrElementTree[$target_key]) && $this->arrElementTree[$target_key][0]) {
618            $objElement = &$this->arrElementTree[$target_key][1];
619        }
620
621        if (!$objElement) return false;
622
623        try {
624            switch ($mode) {
625                case 'appendFirst':
626                    if ($objElement->hasChildNodes()) {
627                        $objElement->insertBefore($objSnip, $objElement->firstChild);
628                    } else {
629                        $objElement->appendChild($objSnip);
630                    }
631                    break;
632                case 'appendChild':
633                    $objElement->appendChild($objSnip);
634                    break;
635                case 'insertBefore':
636                    if (!is_object($objElement->parentNode)) return false;
637                    $objElement->parentNode->insertBefore($objSnip, $objElement);
638                    break;
639                case 'insertAfter':
640                    if ($objElement->nextSibling) {
641                         $objElement->parentNode->insertBefore($objSnip, $objElement->nextSibling);
642                    } else {
643                         $objElement->parentNode->appendChild($objSnip);
644                    }
645                    break;
646                case 'replaceElement':
647                    if (!is_object($objElement->parentNode)) return false;
648                    $objElement->parentNode->replaceChild($objSnip, $objElement);
649                    break;
650                default:
651                    break;
652            }
653            $this->snip_count++;
654        }
655        catch (Exception $e) {
656            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'テンプレートの操作に失敗しました。');
657        }
658
659        return true;
660    }
661
662
663    /**
664     * セレクタエラーを記録する
665     *
666     * @param string  $selector    セレクタ
667     * @param integer $type        エラーの種類
668     * @param string  $err_msg     エラーメッセージ
669     * @return void
670     */
671    protected function lfSetError($selector, $type, $err_msg = NULL)
672    {
673        $this->arrErr[] = array(
674            'selector'    => $selector,
675            'type'        => $type,
676            'err_msg'     => $err_msg
677        );
678    }
679}
Note: See TracBrowser for help on using the repository browser.