| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2014 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 | public 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 | public 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 | public 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 | public 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 | public 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 | public 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 | * @param integer $use_type 1=有効のみ 2=無効のみ 3=全て |
|---|
| 147 | * @return array フックポイントの一覧 |
|---|
| 148 | */ |
|---|
| 149 | public function getPluginHookPoint($plugin_id, $use_type = 1) |
|---|
| 150 | { |
|---|
| 151 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
|---|
| 152 | $cols = '*'; |
|---|
| 153 | $from = 'dtb_plugin_hookpoint'; |
|---|
| 154 | $where = 'plugin_id = ?'; |
|---|
| 155 | switch ($use_type) { |
|---|
| 156 | case 1: |
|---|
| 157 | $where .= ' AND use_flg = 1'; |
|---|
| 158 | break; |
|---|
| 159 | |
|---|
| 160 | case 2: |
|---|
| 161 | $where .= ' AND use_flg = 0'; |
|---|
| 162 | break; |
|---|
| 163 | |
|---|
| 164 | case 3: |
|---|
| 165 | default: |
|---|
| 166 | break; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | return $objQuery->select($cols, $from, $where, array($plugin_id)); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | * プラグインフックポイントを取得する. |
|---|
| 174 | * |
|---|
| 175 | * @param integer $use_type 1=有効のみ 2=無効のみ 3=全て |
|---|
| 176 | * @return array フックポイントの一覧 |
|---|
| 177 | */ |
|---|
| 178 | public function getPluginHookPointList($use_type = 3) |
|---|
| 179 | { |
|---|
| 180 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
|---|
| 181 | $objQuery->setOrder('hook_point ASC, priority DESC'); |
|---|
| 182 | $cols = 'dtb_plugin_hookpoint.*, dtb_plugin.priority, dtb_plugin.plugin_name'; |
|---|
| 183 | $from = 'dtb_plugin_hookpoint LEFT JOIN dtb_plugin USING(plugin_id)'; |
|---|
| 184 | switch ($use_type) { |
|---|
| 185 | case 1: |
|---|
| 186 | $where = 'enable = 1 AND use_flg = 1'; |
|---|
| 187 | break; |
|---|
| 188 | |
|---|
| 189 | case 2: |
|---|
| 190 | $where = 'enable = 1 AND use_flg = 0'; |
|---|
| 191 | break; |
|---|
| 192 | |
|---|
| 193 | case 3: |
|---|
| 194 | default: |
|---|
| 195 | $where = ''; |
|---|
| 196 | break; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | return $objQuery->select($cols, $from, $where); |
|---|
| 200 | //$arrList = array(); |
|---|
| 201 | //foreach ($arrRet AS $key=>$val) { |
|---|
| 202 | // $arrList[$val['hook_point']][$val['plugin_id']] = $val; |
|---|
| 203 | //} |
|---|
| 204 | //return $arrList; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | /** |
|---|
| 208 | * プラグイン利用に必須のモジュールチェック |
|---|
| 209 | * |
|---|
| 210 | * @param string $key エラー情報を格納するキー |
|---|
| 211 | * @return array $arrErr エラー情報を格納した連想配列. |
|---|
| 212 | */ |
|---|
| 213 | public function checkExtension($key) |
|---|
| 214 | { |
|---|
| 215 | // プラグイン利用に必須のモジュール |
|---|
| 216 | // 'EC-CUBEバージョン' => array('モジュール名') |
|---|
| 217 | $arrRequireExtension = array( |
|---|
| 218 | '2.12.0' => array('dom'), |
|---|
| 219 | '2.12.1' => array('dom'), |
|---|
| 220 | '2.12.2' => array('dom') |
|---|
| 221 | ); |
|---|
| 222 | // 必須拡張モジュールのチェック |
|---|
| 223 | $arrErr = array(); |
|---|
| 224 | if (is_array($arrRequireExtension[ECCUBE_VERSION])) { |
|---|
| 225 | foreach ($arrRequireExtension[ECCUBE_VERSION] AS $val) { |
|---|
| 226 | if (!extension_loaded($val)) { |
|---|
| 227 | $arrErr[$key] .= "※ プラグインを利用するには、拡張モジュール「${val}」が必要です。<br />"; |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | return $arrErr; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | /** |
|---|
| 236 | * フックポイントのON/OFF変更 |
|---|
| 237 | * |
|---|
| 238 | * @param intger $plugin_hookpoint_id フックポイントID |
|---|
| 239 | * @return bolean $use_flg:1=ON、0=OFF |
|---|
| 240 | */ |
|---|
| 241 | public function setPluginHookPointChangeUse($plugin_hookpoint_id, $use_flg = 0) |
|---|
| 242 | { |
|---|
| 243 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
|---|
| 244 | $sqlval['use_flg'] = $use_flg; |
|---|
| 245 | $objQuery->update('dtb_plugin_hookpoint', $sqlval, 'plugin_hookpoint_id = ?', array($plugin_hookpoint_id)); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | /** |
|---|
| 249 | * フックポイントで衝突する可能性のあるプラグインを判定.メッセージを返します. |
|---|
| 250 | * |
|---|
| 251 | * @param int $plugin_id プラグインID |
|---|
| 252 | * @return string $conflict_alert_message メッセージ |
|---|
| 253 | */ |
|---|
| 254 | public function checkConflictPlugin($plugin_id = '') |
|---|
| 255 | { |
|---|
| 256 | // フックポイントを取得します. |
|---|
| 257 | $where = 'T1.hook_point = ? AND NOT T1.plugin_id = ? AND T2.enable = ?'; |
|---|
| 258 | if ($plugin_id > 0) { |
|---|
| 259 | $hookPoints = SC_Plugin_Util::getPluginHookPoint($plugin_id, ''); |
|---|
| 260 | } else { |
|---|
| 261 | $hookPoints = SC_Plugin_Util::getPluginHookPointList(1); |
|---|
| 262 | $where .= ' AND T1.use_flg = 1'; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | $conflict_alert_message = ''; |
|---|
| 266 | $arrConflictPluginName = array(); |
|---|
| 267 | $arrConflictHookPoint = array(); |
|---|
| 268 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
|---|
| 269 | $objQuery->setGroupBy('T1.hook_point, T1.plugin_id, T2.plugin_name'); |
|---|
| 270 | $table = 'dtb_plugin_hookpoint AS T1 LEFT JOIN dtb_plugin AS T2 ON T1.plugin_id = T2.plugin_id'; |
|---|
| 271 | foreach ($hookPoints as $hookPoint) { |
|---|
| 272 | // 競合するプラグインを取得する, |
|---|
| 273 | $conflictPlugins = $objQuery->select('T1.hook_point, T1.plugin_id, T2.plugin_name', $table, $where, array($hookPoint['hook_point'], $hookPoint['plugin_id'], PLUGIN_ENABLE_TRUE)); |
|---|
| 274 | |
|---|
| 275 | // プラグイン名重複を削除する為、専用の配列に格納し直す. |
|---|
| 276 | foreach ($conflictPlugins as $conflictPlugin) { |
|---|
| 277 | // プラグイン名が見つからなければ配列に格納 |
|---|
| 278 | if (!in_array($conflictPlugin['plugin_name'], $arrConflictPluginName)) { |
|---|
| 279 | $arrConflictPluginName[] = $conflictPlugin['plugin_name']; |
|---|
| 280 | } |
|---|
| 281 | // プラグイン名が見つからなければ配列に格納 |
|---|
| 282 | if (!in_array($conflictPlugin['hook_point'], $arrConflictHookPoint)) { |
|---|
| 283 | $arrConflictHookPoint[] = $conflictPlugin['hook_point']; |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | if ($plugin_id > 0) { |
|---|
| 289 | // メッセージをセットします. |
|---|
| 290 | foreach ($arrConflictPluginName as $conflictPluginName) { |
|---|
| 291 | $conflict_alert_message .= '* ' . $conflictPluginName . 'と競合する可能性があります。<br/>'; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | return $conflict_alert_message; |
|---|
| 295 | } else { |
|---|
| 296 | return $arrConflictHookPoint; |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | } |
|---|