-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginName.php
256 lines (232 loc) · 8.39 KB
/
PluginName.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*/
/**
* プラグインの基底クラス
*
* @package Plugin
* @author LOCKON CO.,LTD.
* @version $Id: $
*/
class PluginName extends SC_Plugin_Base
{
/**
* コンストラクタ
*
* @param array $arrSelfInfo 自身のプラグイン情報
* @return void
*/
public function __construct(array $arrSelfInfo)
{
// プラグインを有効化したときの初期設定をココに追加する
if($arrSelfInfo["enable"] == 1) {}
}
/**
* インストール
* installはプラグインのインストール時に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin plugin_infoを元にDBに登録されたプラグイン情報(dtb_plugin)
* @return void
*/
public function install($arrPlugin, $objPluginInstaller = null)
{
// htmlディレクトリにファイルを配置。
$src_dir = PLUGIN_UPLOAD_REALDIR . "{$arrPlugin["plugin_code"]}/html/";
$dest_dir = HTML_REALDIR;
SC_Utils::copyDirectory($src_dir, $dest_dir);
}
/**
* アンインストール
* uninstallはアンインストール時に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function uninstall($arrPlugin, $objPluginInstaller = null)
{
// htmlディレクトリのファイルを削除。
$target_dir = HTML_REALDIR;
$source_dir = PLUGIN_UPLOAD_REALDIR . "{$arrPlugin["plugin_code"]}/html/";
self::deleteDirectory($target_dir, $source_dir);
}
/**
* 稼働
* enableはプラグインを有効にした際に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function enable($arrPlugin, $objPluginInstaller = null)
{
// 有効時、プラグイン情報に値を入れたい場合使う
self::updatePlugin($arrPlugin["plugin_code"], array(
"free_field1" => "text1",
"free_field2" => "text2",
"free_field3" => "text3",
"free_field4" => "text4",
));
}
/**
* 停止
* disableはプラグインを無効にした際に実行されます.
* 引数にはdtb_pluginのプラグイン情報が渡されます.
*
* @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
* @return void
*/
public function disable($arrPlugin, $objPluginInstaller = null)
{
// 無効時、プラグイン情報に値を初期化したい場合使う
self::updatePlugin($arrPlugin["plugin_code"], array(
"free_field1" => null,
"free_field2" => null,
"free_field3" => null,
"free_field4" => null,
));
}
/**
* プラグインヘルパーへ, コールバックメソッドを登録します.
*
* @param integer $priority
*/
public function register(SC_Helper_Plugin $objHelperPlugin, $priority)
{
$objHelperPlugin->addAction("loadClassFileChange", array(&$this, "loadClassFileChange"), $priority);
$objHelperPlugin->addAction("prefilterTransform", array(&$this, "prefilterTransform"), $priority);
$objHelperPlugin->addAction("outputfilterTransform", array(&$this, "outputfilterTransform"), $priority);
}
/**
* SC_系のクラスをフックする
*
* @param type $classname
* @param type $classpath
*/
public function loadClassFileChange(&$classname, &$classpath)
{
$base_path = PLUGIN_UPLOAD_REALDIR . basename(__DIR__) . "/data/class/";
}
/**
* テンプレートをフックする
*
* @param string &$source
* @param LC_Page_Ex $objPage
* @param string $filename
* @return void
*/
public function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename)
{
$objTransform = new SC_Helper_Transform($source);
$template_dir = PLUGIN_UPLOAD_REALDIR . basename(__DIR__) . '/data/Smarty/templates/';
switch ($objPage->arrPageLayout['device_type_id']) {
case DEVICE_TYPE_PC:
$template_dir = $template_dir . "default/";
break;
case DEVICE_TYPE_MOBILE:
$template_dir = $template_dir . "mobile/";
break;
case DEVICE_TYPE_SMARTPHONE:
$template_dir = $template_dir . "sphone/";
break;
case DEVICE_TYPE_ADMIN:
default:
// 管理画面編集
$template_admin_dir = $template_dir . "admin/";
if (strpos($filename, "customer/subnavi.tpl") !== false) {
$template_path = 'customer/subnavi.tpl';
$objTransform->select('ul')->appendChild(
file_get_contents($template_admin_dir . $template_path));
}
// ブロック編集
$template_frontparts_dir = $template_dir . "default/frontparts/";
break;
}
$source = $objTransform->getHTML();
}
/**
* テンプレートをフックする
* Smartyの編集はできない
*
* @param string &$source
* @param LC_Page_Ex $objPage
* @param string $filename
* @return void
*/
public function outputfilterTransform(&$source, LC_Page_Ex $objPage, $filename)
{
$objTransform = new SC_Helper_Transform($source);
$template_dir = PLUGIN_UPLOAD_REALDIR . basename(__DIR__) . "/data/Smarty/templates/";
switch ($objPage->arrPageLayout['device_type_id']) {
case DEVICE_TYPE_PC:
break;
case DEVICE_TYPE_MOBILE:
break;
case DEVICE_TYPE_SMARTPHONE:
break;
case DEVICE_TYPE_ADMIN:
default:
break;
}
$source = $objTransform->getHTML();
}
/**
* プラグイン情報更新
*
* @param string $plugin_code
* @param array $free_fields
*/
public static function updatePlugin($plugin_code, array $free_fields){
$objQuery = & SC_Query_Ex::getSingletonInstance();
$objQuery->update("dtb_plugin", $free_fields, "plugin_code = ?", array($plugin_code));
}
/**
* 指定されたパスを比較して再帰的に削除します。
*
* @param string $target_dir 削除対象のディレクトリ
* @param string $source_dir 比較対象のディレクトリ
*/
public static function deleteDirectory($target_dir, $source_dir) {
$dir = opendir($source_dir);
while ($name = readdir($dir)) {
if ($name == '.' || $name == '..') {
continue;
}
$target_path = $target_dir . '/' . $name;
$source_path = $source_dir . '/' . $name;
if (is_file($source_path)) {
if (is_file($target_path)) {
unlink($target_path);
GC_Utils::gfPrintLog("$target_path を削除しました。");
}
} elseif (is_dir($source_path)) {
if (is_dir($target_path)) {
self::deleteDirectory($target_path, $source_path);
}
}
}
closedir($dir);
}
}