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