source: branches/version-2_11-dev/data/class/helper/SC_Helper_Plugin.php @ 20870

Revision 20870, 5.4 KB checked in by nanasess, 13 years ago (diff)

#494 (プラグイン機能)

  • プラグインの存在チェック, デバックログ出力を追加
  • プラグインのロード順位を指定できるよう修正
  • 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/**
25 * プラグインのヘルパークラス.
26 *
27 * @package Helper
28 * @version $Id$
29 */
30class SC_Helper_Plugin{
31
32    /**
33     * enableかどうかを判別する
34     * インスタンス化
35     */
36    function load(&$lcpage){
37        //データベースからクラス名を読み込む
38        $objQuery = new SC_Query_Ex();
39        $col = "*";
40        $table = "dtb_plugin";
41        $where = "enable = 1 AND del_flg = 0";
42        // XXX 2.11.0 互換のため
43        $arrCols = $objQuery->listTableFields($table);
44        if (in_array('rank', $arrCols)) {
45            $objQuery->setOrder('rank');
46        }
47        $arrRet = $objQuery->select($col, $table, $where);
48        $class_name = get_class($lcpage);
49
50        // 現在のページで使用するプラグインが存在するかどうかを検証する
51        foreach ($arrRet as $plugins){
52            // プラグインを稼働させるクラス名のリストを取得する
53            // プラグインのディレクトリ内の設定ファイルを参照する
54            $plugin_name = $plugins['plugin_name'];
55            $plugin_class_name = $plugins['class_name'];
56            $plugin_path = DATA_REALDIR . "plugin/{$plugin_name}/{$plugin_class_name}.php";
57
58            if (file_exists($plugin_path)) {
59                require_once $plugin_path;
60                if (class_exists($class_name)) {
61                    $code_str = "\$is_enable = {$plugin_class_name}::isEnable(\$class_name);";
62                    eval($code_str);
63                    if ($is_enable) {
64                        $arrPluginList[] = $plugin_class_name;
65                        GC_Utils_Ex::gfDebugLog($class_name . ' で、プラグイン ' . $plugin_name . ' をロードしました');
66                    } else {
67                        GC_Utils_Ex::gfDebugLog($class_name . ' で、プラグイン ' . $plugin_name . ' は無効になっています');
68                    }
69                } else {
70                    GC_Utils_Ex::gfDebugLog('プラグイン ' . $plugin_name . ' の ' . $class_name . ' が見つかりませんでした');
71                }
72            } else {
73                GC_Utils_Ex::gfDebugLog('プラグイン ' . $plugin_name . " が読み込めませんでした。\n"
74                                        . 'Failed opening required ' . $plugin_path);
75            }
76        }
77        return $arrPluginList;
78    }
79
80    function preProcess(&$lcpage){
81        //プラグインの名前を判別してページ内で有効なプラグインがあれば実行する
82        $arrPluginList = SC_Helper_Plugin_Ex::load($lcpage);
83       if(count($arrPluginList) > 0){
84            foreach ($arrPluginList as $key => $value){
85                $instance = new $value;
86                $instance->preProcess($lcpage);
87            }
88        }
89        return $lcpage;
90    }
91
92    /* 読み込んだプラグインの実行用メソッド
93     *
94     */
95    function process(&$lcpage){
96        //プラグインの名前を判別してページ内で有効なプラグインがあれば実行する
97        $arrPluginList = SC_Helper_Plugin_Ex::load($lcpage);
98        if(count($arrPluginList) > 0){
99            foreach ($arrPluginList as $key => $value){
100                $instance = new $value;
101                $instance->process($lcpage);
102            }
103        }
104        return $lcpage;
105    }
106
107    /**
108     * 稼働中のプラグインを取得する。
109     */
110    function getEnablePlugin(){
111        $objQuery = new SC_Query_Ex();
112        $col = '*';
113        $table = 'dtb_plugin';
114        $where = 'enable = 1 AND del_flg = 0';
115        // XXX 2.11.0 互換のため
116        $arrCols = $objQuery->listTableFields($table);
117        if (in_array('rank', $arrCols)) {
118            $objQuery->setOrder('rank DESC');
119        }
120        $arrRet = $objQuery->select($col,$table,$where);
121        return $arrRet;
122    }
123
124    /**
125     * インストールされているプラグインを取得する。
126     */
127    function getAllPlugin(){
128        $objQuery = new SC_Query_Ex();
129        $col = '*';
130        $table = 'dtb_plugin';
131        $where = 'del_flg = 0';
132        // XXX 2.11.0 互換のため
133        $arrCols = $objQuery->listTableFields($table);
134        if (in_array('rank', $arrCols)) {
135            $objQuery->setOrder('rank DESC');
136        }
137        $arrRet = $objQuery->select($col,$table,$where);
138        return $arrRet;
139    }
140
141    function getFilesystemPlugins(){
142        $plugin_dir = DATA_REALDIR."/plugin/";
143        if($dh = opendir($plugin_dir)){
144            while(($file = readdir($dh) !== false)){
145                if(is_dir($plugin_dir."/".$file)){
146                }
147            }
148        }
149    }
150}
Note: See TracBrowser for help on using the repository browser.