source: branches/camp/camp-2_13-plugin/data/class/plugin/SC_Plugin_Util.php @ 22629

Revision 22629, 6.5 KB checked in by Yammy, 11 years ago (diff)

プラグインフックポイント管理機能

refs #2179

  • 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-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// プラグインのユーティリティクラス.
25class SC_Plugin_Util
26{
27
28    /**
29     * 稼働中のプラグインを取得する。
30     */
31    function getEnablePlugin()
32    {
33        $objQuery =& SC_Query_Ex::getSingletonInstance();
34        $col = '*';
35        $table = 'dtb_plugin';
36        $where = 'enable = 1';
37        // XXX 2.11.0 互換のため
38        $arrCols = $objQuery->listTableFields($table);
39        if (in_array('priority', $arrCols)) {
40            $objQuery->setOrder('priority DESC, plugin_id ASC');
41        }
42        $arrRet = $objQuery->select($col,$table,$where);
43
44        // プラグインフックポイントを取得.
45        $max = count($arrRet);
46        for ($i = 0; $i < $max; $i++) {
47            $plugin_id = $arrRet[$i]['plugin_id'];
48            $arrHookPoint = SC_Plugin_Util::getPluginHookPoint($plugin_id);
49            $arrRet[$i]['plugin_hook_point'] = $arrHookPoint;
50        }
51        return $arrRet;
52    }
53
54    /**
55     * インストールされているプラグインを取得する。
56     *
57     * @return array $arrRet インストールされているプラグイン.
58     */
59    function getAllPlugin()
60    {
61        $objQuery =& SC_Query_Ex::getSingletonInstance();
62        $col = '*';
63        $table = 'dtb_plugin';
64        // XXX 2.11.0 互換のため
65        $arrCols = $objQuery->listTableFields($table);
66        if (in_array('priority', $arrCols)) {
67            $objQuery->setOrder('plugin_id ASC');
68        }
69        $arrRet = $objQuery->select($col,$table);
70        return $arrRet;
71    }
72
73    /**
74     * プラグインIDをキーにプラグインを取得する。
75     *
76     * @param int $plugin_id プラグインID.
77     * @return array プラグインの基本情報.
78     */
79    function getPluginByPluginId($plugin_id)
80    {
81        $objQuery =& SC_Query_Ex::getSingletonInstance();
82        $col = '*';
83        $table = 'dtb_plugin';
84        $where = 'plugin_id = ?';
85        $plugin = $objQuery->getRow($col, $table, $where, array($plugin_id));
86        return $plugin;
87    }
88
89
90    /**
91     * プラグインコードをキーにプラグインを取得する。
92     *
93     * @param string $plugin_code プラグインコード.
94     * @return array プラグインの基本情報.
95     */
96    function getPluginByPluginCode($plugin_code)
97    {
98        $objQuery =& SC_Query_Ex::getSingletonInstance();
99        $col = '*';
100        $table = 'dtb_plugin';
101        $where = 'plugin_code = ?';
102        $plugin = $objQuery->getRow($col, $table, $where, array($plugin_code));
103        return $plugin;
104    }
105
106    /**
107     * プラグインIDをキーにプラグインを削除する。
108     *
109     * @param string $plugin_id プラグインID.
110     * @return array プラグインの基本情報.
111     */
112    function deletePluginByPluginId($plugin_id)
113    {
114        $objQuery =& SC_Query_Ex::getSingletonInstance();
115        $where = 'plugin_id = ?';
116        $objQuery->delete('dtb_plugin', $where, array($plugin_id));
117        $objQuery->delete('dtb_plugin_hookpoint', $where, array($plugin_id));
118    }
119
120    /**
121     * プラグインディレクトリの取得
122     *
123     * @return array $arrPluginDirectory
124     */
125    function getPluginDirectory()
126    {
127        $arrPluginDirectory = array();
128        if (is_dir(PLUGIN_UPLOAD_REALDIR)) {
129            if ($dh = opendir(PLUGIN_UPLOAD_REALDIR)) {
130                while (($pluginDirectory = readdir($dh)) !== false) {
131                    $arrPluginDirectory[] = $pluginDirectory;
132                }
133                closedir($dh);
134            }
135        }
136        return $arrPluginDirectory;
137    }
138
139    /**
140     * プラグインIDをキーに, プラグインフックポイントを取得する.
141     *
142     * @param integer $plugin_id
143     * @return array フックポイントの一覧
144     */
145    function getPluginHookPoint($plugin_id)
146    {
147        $objQuery =& SC_Query_Ex::getSingletonInstance();
148        $cols = '*';
149        $from = 'dtb_plugin_hookpoint';
150        $where = 'plugin_id = ? AND use_flg = true';
151        return $objQuery->select($cols, $from, $where, array($plugin_id));
152    }
153
154    function getPluginHookPointList()
155    {
156        $objQuery =& SC_Query_Ex::getSingletonInstance();
157        $objQuery->setOrder('priority DESC');
158        $cols = 'dtb_plugin_hookpoint.*, dtb_plugin.priority, dtb_plugin.plugin_name';
159        $from = 'dtb_plugin_hookpoint LEFT JOIN dtb_plugin USING(plugin_id)';
160        $arrRet = $objQuery->select($cols, $from);
161        $arrList = array();
162        foreach ($arrRet AS $key=>$val) {
163            $arrList[$val['plugin_hookpoint_id']][$val['plugin_id']] = $val;
164        }
165        return $arrList;
166    }
167
168    /**
169     * プラグイン利用に必須のモジュールチェック
170     *
171     * @param string $key  エラー情報を格納するキー
172     * @return array $arrErr エラー情報を格納した連想配列.
173     */
174    function checkExtension($key)
175    {
176        // プラグイン利用に必須のモジュール
177        // 'EC-CUBEバージョン' => array('モジュール名')
178        $arrRequireExtension = array(
179                                     '2.12.0' => array('dom'),
180                                     '2.12.1' => array('dom'),
181                                     '2.12.2' => array('dom')
182                                    );
183        // 必須拡張モジュールのチェック
184        $arrErr = array();
185        if (is_array($arrRequireExtension[ECCUBE_VERSION])) {
186            foreach ($arrRequireExtension[ECCUBE_VERSION] AS $val) {
187                if (!extension_loaded($val)) {
188                    $arrErr[$key] .= "※ プラグインを利用するには、拡張モジュール「${val}」が必要です。<br />";
189                }
190            }
191        }
192        return $arrErr;
193    }
194}
Note: See TracBrowser for help on using the repository browser.