1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 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 | /** |
---|
26 | * SmartyテンプレートをDOMを使用して変形させる際に使用するセレクタクラス |
---|
27 | * |
---|
28 | * @package Plugin |
---|
29 | * @author LOCKON CO.,LTD. |
---|
30 | * @version $Id: $ |
---|
31 | */ |
---|
32 | class SC_Plugin_Template_Selector { |
---|
33 | |
---|
34 | var $objTransformer; |
---|
35 | var $arrElements; |
---|
36 | var $current_plugin; |
---|
37 | |
---|
38 | /** |
---|
39 | * コンストラクタ |
---|
40 | * |
---|
41 | * @param SC_Plugin_Template_Transformer $objTransformer SC_Plugin_Template_Transformerオブジェクト |
---|
42 | * @param string $current_plugin プラグイン名 |
---|
43 | * @return void |
---|
44 | */ |
---|
45 | function __construct(SC_Plugin_Template_Transformer $objTransformer, $current_plugin) { |
---|
46 | $this->objTransformer = $objTransformer; |
---|
47 | $this->current_plugin = $current_plugin; |
---|
48 | $this->arrElements = array(); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * 見つかった要素をプロパティに登録 |
---|
54 | * |
---|
55 | * @param integer $elementNo エレメントのインデックス |
---|
56 | * @param array $arrElement インデックスとDOMオブジェクトをペアとした配列 |
---|
57 | * @return void |
---|
58 | */ |
---|
59 | function addElement($elementNo, array &$arrElement) { |
---|
60 | if (!array_key_exists($arrElement[0], $this->arrElements)) { |
---|
61 | $this->arrElements[$arrElement[0]] = array($elementNo, &$arrElement[1]); |
---|
62 | |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * jQueryライクなセレクタを用いてエレメントを検索する |
---|
68 | * |
---|
69 | * @param string $selector セレクタ |
---|
70 | * @param string $index インデックス(指定がある場合) |
---|
71 | * @param boolean $require エレメントが見つからなかった場合、エラーとするか |
---|
72 | * @param string $err_msg エラーメッセージ |
---|
73 | * @param SC_Plugin_Template_Selector $objSelector セレクタオブジェクト |
---|
74 | * @param string $parent_index セレクタ検索時の親要素の位置(子孫要素検索のため) |
---|
75 | * @return SC_Plugin_Template_Selector SC_Plugin_Template_Selectorオブジェクト |
---|
76 | */ |
---|
77 | function find($selector, $index = NULL, $require = true, $err_msg = NULL, SC_Plugin_Template_Selector $objSelector = NULL, $parent_index = NULL) { |
---|
78 | $objSelectorChild = new SC_Plugin_Template_Selector($this->objTransformer, $this->current_plugin); |
---|
79 | foreach ($this->arrElements as $key => &$objElement) { |
---|
80 | $this->objTransformer->find($selector, $index, false, NULL, $objSelectorChild, $objElement[0]); |
---|
81 | } |
---|
82 | if ($require && $objSelectorChild->getFoundCount() == 0) { |
---|
83 | $this->objTransformer->setError( |
---|
84 | $this->current_plugin, |
---|
85 | $selector, |
---|
86 | SC_Plugin_Template_Transformer::ERR_TARGET_ELEMENT_NOT_FOUND, |
---|
87 | $err_msg |
---|
88 | ); |
---|
89 | } |
---|
90 | return $objSelectorChild; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * 要素の前にHTMLを挿入 |
---|
96 | * |
---|
97 | * @param string $html_snip 挿入するHTMLの断片 |
---|
98 | * @return SC_Plugin_Template_Selector SC_Plugin_Template_Selectorオブジェクト |
---|
99 | */ |
---|
100 | function insertBefore($html_snip) { |
---|
101 | foreach ($this->arrElements as $key => $objElement) { |
---|
102 | $this->objTransformer->setTransform('insertBefore', $objElement[0], $html_snip); |
---|
103 | } |
---|
104 | return $this; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | /** |
---|
109 | * 要素の後にHTMLを挿入 |
---|
110 | * |
---|
111 | * @param string $html_snip 挿入するHTMLの断片 |
---|
112 | * @return Plugin_Template_Selector Plugin_Template_Selectorオブジェクト |
---|
113 | */ |
---|
114 | function insertAfter($html_snip) { |
---|
115 | foreach ($this->arrElements as $key => $objElement) { |
---|
116 | $this->objTransformer->setTransform('insertAfter', $objElement[0], $html_snip); |
---|
117 | } |
---|
118 | return $this; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * 要素の末尾にHTMLを挿入 |
---|
123 | * |
---|
124 | * @param string $html_snip 挿入するHTMLの断片 |
---|
125 | * @return SC_Plugin_Template_Selector SC_Plugin_Template_Selectorオブジェクト |
---|
126 | */ |
---|
127 | function appendChild($html_snip) { |
---|
128 | foreach ($this->arrElements as $key => $objElement) { |
---|
129 | $this->objTransformer->setTransform('appendChild', $objElement[0], $html_snip); |
---|
130 | } |
---|
131 | return $this; |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | /** |
---|
136 | * 要素を指定したHTMLに置換 |
---|
137 | * |
---|
138 | * @param string $html_snip 置換後のHTMLの断片 |
---|
139 | * @return SC_Plugin_Template_Selector SC_Plugin_Template_Selectorオブジェクト |
---|
140 | */ |
---|
141 | function replaceChild($html_snip) { |
---|
142 | foreach ($this->arrElements as $key => &$objElement) { |
---|
143 | $this->objTransformer->setTransform('replaceChild', $objElement[0], $html_snip); |
---|
144 | } |
---|
145 | return $this; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | /** |
---|
150 | * findで見つかったエレメントの数を返す |
---|
151 | * |
---|
152 | * @return integer findで見つかったエレメントの数 |
---|
153 | */ |
---|
154 | function getFoundCount() { |
---|
155 | return count($this->arrElements); |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | } |
---|