| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | class SC_Helper_Plugin{ |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * enableかどうかを判別する |
|---|
| 7 | * インスタンス化 |
|---|
| 8 | */ |
|---|
| 9 | public static function load(LC_Page &$lcpage){ |
|---|
| 10 | //データベースからクラス名を読み込む |
|---|
| 11 | $objQuery = new SC_Query(); |
|---|
| 12 | $col = "*"; |
|---|
| 13 | $table = "dtb_plugin"; |
|---|
| 14 | $where = "enable = 1 AND del_flg = 0"; |
|---|
| 15 | $arrRet = $objQuery->select($col, $table, $where); |
|---|
| 16 | $class_name = get_class($lcpage); |
|---|
| 17 | |
|---|
| 18 | // 実行されたぺーじ |
|---|
| 19 | // 現在のページで使用するプラグインが存在するかどうかを検証する |
|---|
| 20 | foreach ($arrRet as $plugins){ |
|---|
| 21 | // プラグインを稼働させるクラス名のリストを取得する |
|---|
| 22 | // プラグインのディレクトリ内の設定ファイルを参照する |
|---|
| 23 | $plugin_name = $plugins['name']; |
|---|
| 24 | $plugin_class_name = $plugins['class_name']; |
|---|
| 25 | require_once DATA_PATH."plugin/{$plugin_name}/{$plugin_class_name}.php"; |
|---|
| 26 | |
|---|
| 27 | $code_str = "\$is_enable = {$plugin_class_name}::is_enable(\$class_name);"; |
|---|
| 28 | eval($code_str); |
|---|
| 29 | if ($is_enable) { |
|---|
| 30 | $arrPluginList[] = $plugin_class_name; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | return $arrPluginList; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public static function preProcess(LC_Page &$lcpage){ |
|---|
| 37 | //プラグインの名前を判別してページ内で有効なプラグインがあれば実行する |
|---|
| 38 | $arrPluginList = SC_Helper_Plugin::load($lcpage); |
|---|
| 39 | if(count($arrPluginList) > 0){ |
|---|
| 40 | foreach ($arrPluginList as $key => $value){ |
|---|
| 41 | $instance = new $value; |
|---|
| 42 | $instance->preProcess($lcpage); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | return $lcpage; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /* 読み込んだプラグインの実行用メソッド |
|---|
| 49 | * |
|---|
| 50 | */ |
|---|
| 51 | public static function process(LC_Page &$lcpage){ |
|---|
| 52 | //プラグインの名前を判別してページ内で有効なプラグインがあれば実行する |
|---|
| 53 | $arrPluginList = SC_Helper_Plugin::load($lcpage); |
|---|
| 54 | if(count($arrPluginList) > 0){ |
|---|
| 55 | foreach ($arrPluginList as $key => $value){ |
|---|
| 56 | $instance = new $value; |
|---|
| 57 | $instance->process($lcpage); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | return $lcpage; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * 稼働中のプラグインを取得する。 |
|---|
| 65 | */ |
|---|
| 66 | public static function getEnablePlugin(){ |
|---|
| 67 | $objQuery = new SC_Query(); |
|---|
| 68 | $col = '*'; |
|---|
| 69 | $table = 'dtb_plugin'; |
|---|
| 70 | $where = 'enable = 1 AND del_flg = 0'; |
|---|
| 71 | $arrRet = $objQuery->select($col,$table,$where); |
|---|
| 72 | return $arrRet; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * インストールされているプラグインを取得する。 |
|---|
| 77 | */ |
|---|
| 78 | public static function getAllPlugin(){ |
|---|
| 79 | $objQuery = new SC_Query(); |
|---|
| 80 | $col = '*'; |
|---|
| 81 | $table = 'dtb_plugin'; |
|---|
| 82 | $where = 'del_flg = 0'; |
|---|
| 83 | $arrRet = $objQuery->select($col,$table,$where); |
|---|
| 84 | return $arrRet; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | public static function getFilesystemPlugins(){ |
|---|
| 89 | $plugin_dir = DATA_PATH."/plugin/"; |
|---|
| 90 | if($dh = opendir($plugin_dir)){ |
|---|
| 91 | while(($file = readdir($dh) !== false)){ |
|---|
| 92 | if(is_dir($plugin_dir."/".$file)){ |
|---|
| 93 | |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|