source: branches/version-2_11-dev/data/class/pages/admin/system/LC_Page_Admin_System_Plugin.php @ 20970

Revision 20970, 10.7 KB checked in by Seasoft, 13 years ago (diff)

#1288 (「-er」カタカナ表記の統一)

  • 現状で混在が発生しているもののみ改修。
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php';
27
28/**
29 * システム情報 のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_System_Plugin extends LC_Page_Admin_Ex {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'system/plugin.tpl';
48        $this->tpl_subno    = 'plugin';
49        $this->tpl_mainno   = 'system';
50        $this->tpl_maintitle = 'システム設定';
51        $this->tpl_subtitle = 'プラグイン管理';
52    }
53
54    /**
55     * Page のプロセス.
56     *
57     * @return void
58     */
59    function process() {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action() {
70        // パラメーター管理クラス
71        $objFormParam = new SC_FormParam_Ex();
72        // パラメーター情報の初期化
73        $this->lfInitParam($objFormParam);
74        $objFormParam->setParam($_POST);
75
76        $mode = $this->getMode();
77
78        switch($mode) {
79        case 'install':
80        case 'uninstall':
81        case 'enable':
82        case 'disable':
83            // エラーチェック
84            $this->arrErr = $objFormParam->checkError();
85
86            if(count($this->arrErr) == 0) {
87                $plugin_id = $objFormParam->getValue('plugin_id');
88                $plugin_code = $objFormParam->getValue('plugin_code');
89
90                // プラグインファイルを読み込み、modeで指定されたメソッドを実行
91                $this->arrErr = $this->lfExecPlugin($plugin_id, $plugin_code, $mode);
92            }
93            break;
94        case 'upload':
95            // プラグイン情報を設定
96            $plugin_code = $this->lfGetPluginCode($_FILES['plugin_file']['name']);
97            $plugin_dir = $this->lfGetPluginDir($plugin_code);
98
99            // ファイルアップロード情報を設定
100            $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $plugin_dir);
101            $this->lfInitUploadFile($objUpFile);
102
103            // エラーチェック
104            $this->arrErr = $this->lfCheckErrorUploadFile($plugin_code, $plugin_dir);
105
106            if(count($this->arrErr) == 0) {
107                // 一時ディレクトリへアップロード
108                $this->arrErr['plugin_file'] = $objUpFile->makeTempFile('plugin_file', false);
109
110                if($this->arrErr['plugin_file'] == "") {
111                    // プラグイン保存ディレクトリへ解凍
112                    $this->arrErr = $this->lfUploadPlugin($objUpFile, $plugin_dir, $plugin_code, $_FILES['plugin_file']['name']);
113
114                    // 完了メッセージアラート設定
115                    if(count($this->arrErr) == 0) {
116                        $this->tpl_onload = "alert('プラグインをアップロードしました。');";
117                    }
118                }
119            }
120            break;
121        case 'up':
122            $this->arrErr = $objFormParam->checkError();
123            if(count($this->arrErr) == 0) {
124                $plugin_id = $objFormParam->getValue('plugin_id');
125                SC_Helper_DB_Ex::sfRankUp("dtb_plugin", "plugin_id", $plugin_id);
126                SC_Response_Ex::reload();
127            }
128            break;
129        case 'down':
130            $this->arrErr = $objFormParam->checkError();
131            if(count($this->arrErr) == 0) {
132                $plugin_id = $objFormParam->getValue('plugin_id');
133                SC_Helper_DB_Ex::sfRankDown("dtb_plugin", "plugin_id", $plugin_id);
134                SC_Response_Ex::reload();
135            }
136            break;
137
138        default:
139            break;
140        }
141
142        // DBからプラグイン情報を取得
143        $this->plugins = SC_Helper_Plugin_Ex::getAllPlugin();
144    }
145
146    /**
147     * デストラクタ.
148     *
149     * @return void
150     */
151    function destroy() {
152        parent::destroy();
153    }
154
155    /**
156     * パラメーター初期化.
157     *
158     * @param object $objFormParam
159     * @return void
160     *
161     */
162    function lfInitParam(&$objFormParam) {
163        $objFormParam->addParam('mode', 'mode', INT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
164        $objFormParam->addParam('plugin_id', 'plugin_id', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
165        $objFormParam->addParam('plugin_code', 'plugin_code', MTEXT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
166    }
167
168    /**
169     * アップロードファイルパラメーター初期化.
170     *
171     * @param object $objUpFile SC_UploadFileのインスタンス.
172     * @return void
173     */
174    function lfInitUploadFile(&$objUpFile) {
175        $objUpFile->addFile("プラグイン", 'plugin_file', array('tar', 'tar.gz'), TEMPLATE_SIZE, true, 0, 0, false);
176    }
177
178    /**
179     * アップロードファイルのエラーチェック.
180     *
181     * @param string $plugin_code
182     * @param string $plugin_dir
183     * @return array エラー情報を格納した連想配列.
184     *
185     */
186    function lfCheckErrorUploadFile($plugin_code, $plugin_dir) {
187        $arrErr = array();
188
189        // プラグイン重複チェック
190        $plugins = SC_Helper_Plugin_Ex::getAllPlugin();
191        foreach($plugins as $val) {
192            if($val['plugin_code'] == $plugin_code) {
193                $arrErr['plugin_file'] = "※ 同名のプラグインがすでに登録されています。<br/>";
194            }
195        }
196
197        return $arrErr;
198    }
199
200    /**
201     * プラグイン名(物理名)を取得する.
202     * (アップロードされたファイル名をプラグイン名(物理名)とする).
203     *
204     * @param string $upload_file_name
205     * @return string プラグイン名(物理名).
206     *
207     */
208    function lfGetPluginCode($upload_file_name) {
209        $array_ext = explode(".", $upload_file_name);
210        return $array_ext[0];
211    }
212
213    /**
214     * プラグイン保存ディレクトリのパスを取得する.
215     *
216     * @param string $plugin_code
217     * @return string プラグイン保存ディレクトリ.
218     *
219     */
220    function lfGetPluginDir($plugin_code) {
221        $plugin_dir = DATA_REALDIR . 'plugin/' . $plugin_code . '/';
222        return $plugin_dir;
223    }
224
225    /**
226     * プラグインファイルのパスを取得する.
227     *
228     * @param string $plugin_code
229     * @return string プラグインファイルパス.
230     */
231    function lfGetPluginFilePath($plugin_code) {
232        $plugin_file_path = $this->lfGetPluginDir($plugin_code) . $plugin_code . '.php';
233        return $plugin_file_path;
234    }
235    /**
236     * プラグインをアップロードする.
237     *
238     * @param object $objUpFile
239     * @param string $plugin_dir
240     * @param string $plugin_code
241     * @param string $plugin_file_name
242     * @return array エラー情報を格納した連想配列.
243     *
244     */
245    function lfUploadPlugin(&$objUpFile, $plugin_dir, $plugin_code, $plugin_file_name) {
246        $arrErr = array();
247
248        // 必須チェック
249        $arrErr = $objUpFile->checkEXISTS('plugin_file');
250
251        if(count($arrErr) == 0) {
252            // プラグイン保存ディレクトリ作成
253            if(file_exists($plugin_dir)) {
254                $arrErr['plugin_file'] = "※ 同名のディレクトリがすでに存在します。<br/>";
255            } else {
256                mkdir($plugin_dir);
257            }
258
259            if(count($arrErr) == 0) {
260                // 一時ディレクトリからプラグイン保存ディレクトリへ移動
261                $objUpFile->moveTempFile();
262
263                // プラグイン保存ディレクトリへ解凍
264                SC_Helper_FileManager_Ex::unpackFile($plugin_dir . $plugin_file_name);
265
266                // プラグイン情報をDB登録
267                $this->lfRegistData($plugin_dir, $plugin_code);
268            }
269        }
270
271        return $arrErr;
272    }
273
274    /**
275     * プラグイン情報をDB登録.
276     *
277     * @param string $plugin_dir
278     * @param string $plugin_code
279     * @return void
280     *
281     */
282    function lfRegistData($plugin_dir, $plugin_code) {
283        $objQuery =& SC_Query_Ex::getSingletonInstance();
284        $sqlval = array();
285
286        $sqlval['plugin_id'] = $objQuery->nextVal('dtb_plugin_plugin_id');
287        $sqlval['plugin_code'] = $plugin_code;
288        $sqlval['rank'] = 1 + $objQuery->max('rank', 'dtb_plugin');
289        $sqlval['status'] = PLUGIN_STATUS_UPLOADED;
290        $sqlval['enable'] = PLUGIN_ENABLE_FALSE;
291        $sqlval['update_date'] = 'now()';
292        $objQuery->insert('dtb_plugin', $sqlval);
293    }
294
295    /**
296     * プラグインファイルを読み込む.
297     *
298     * @param string $plugin_code
299     * @return array エラー情報を格納した連想配列.
300     */
301    function lfRequirePluginFile($plugin_code) {
302        $arrErr = array();
303        $plugin_file_path = $this->lfGetPluginFilePath($plugin_code);
304
305        if(file_exists($plugin_file_path)) {
306            require_once $plugin_file_path;
307        } else {
308            $arrErr['plugin_error'] = "※ " . $plugin_code . ".phpが存在しないため実行できません。<br/>";
309        }
310
311        return $arrErr;
312    }
313
314    /**
315     * プラグインファイルを読み込み、指定されたメソッドを実行する.
316     *
317     * @param integer $plugin_id
318     * @param string $plugin_code
319     * @param string $exec_mode プラグイン実行メソッド名.
320     * @return array エラー情報を格納した連想配列.
321     *
322     */
323    function lfExecPlugin($plugin_id, $plugin_code, $exec_mode) {
324        $arrErr = array();
325
326        // プラグインファイル読み込み
327        $arrErr = $this->lfRequirePluginFile($plugin_code);
328
329        if(count($arrErr) == 0) {
330            $plugin = new $plugin_code();
331            $arrErr = $plugin->$exec_mode($plugin_id);
332        }
333
334        return $arrErr;
335    }
336}
Note: See TracBrowser for help on using the repository browser.