Changeset 20246 for branches/version-2_5-dev/data/class
- Timestamp:
- 2011/02/20 12:03:00 (15 years ago)
- Location:
- branches/version-2_5-dev/data/class
- Files:
-
- 2 edited
-
SC_CheckError.php (modified) (1 diff)
-
pages/admin/system/LC_Page_Admin_System_Plugin.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/SC_CheckError.php
r20090 r20246 621 621 $errFlag = 1; 622 622 $array_ext = explode(".", $_FILES[$value[1]]['name']); 623 $ext = $array_ext[ count ( $array_ext ) - 1 ];624 $ext = strtolower($ext);625 623 626 624 $strExt = ""; 627 625 628 626 foreach ( $value[2] as $checkExt ){ 627 $ext = ""; 628 629 // チェック拡張子のピリオドの数を取得('tar.gz'の場合1個、'jpg'のように通常は0個) 630 $count_period = substr_count($checkExt, "."); 631 632 if($count_period > 0) { 633 for($i = max(array_keys($array_ext)) - $count_period; $i < count($array_ext); $i++) { 634 $ext .= $array_ext[$i] . "."; 635 } 636 $ext = preg_replace("/.$/", "" ,$ext); 637 } else { 638 $ext = $array_ext[ count ( $array_ext ) - 1 ]; 639 } 640 641 $ext = strtolower($ext); 642 629 643 if ( $ext == $checkExt) { 630 644 $errFlag = 0; -
branches/version-2_5-dev/data/class/pages/admin/system/LC_Page_Admin_System_Plugin.php
r20116 r20246 24 24 // {{{ requires 25 25 require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); 26 require_once(CLASS_EX_REALDIR . "helper_extends/SC_Helper_FileManager_Ex.php"); 26 27 27 28 /** … … 52 53 53 54 /** 54 * フォームパラメータ初期化55 *56 * @return void57 */58 function initForm() {59 $objForm = new SC_FormParam();60 $objForm->addParam('mode', 'mode', INT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));61 $objForm->addParam('plugin_name', 'plugin_name', INT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));62 63 $objForm->setParam($_POST);64 $this->objForm = $objForm;65 }66 67 /**68 55 * Page のプロセス. 69 56 * … … 81 68 */ 82 69 function action() { 70 // 認証可否の判定 83 71 SC_Utils_Ex::sfIsSuccess(new SC_Session); 84 $this->initForm(); 85 switch($this->getMode()) { 86 // PHP INFOを表示 87 case 'install': 88 $name = $this->objForm->getValue('plugin_name'); 89 require_once(DATA_REALDIR.'/plugin/'.$name.'/'.$name.'.php'); 90 $plugin = new $name(); 91 $plugin->install(); 92 break; 93 case 'uninstall': 94 $name = $this->objForm->getValue('plugin_name'); 95 require_once(DATA_REALDIR.'/plugin/'.$name.'/'.$name.'.php'); 96 $plugin = new $name(); 97 $plugin->uninstall(); 98 break; 99 case 'enable': 100 $name = $this->objForm->getValue('plugin_name'); 101 require_once(DATA_REALDIR.'/plugin/'.$name.'/'.$name.'.php'); 102 $plugin = new $name(); 103 $plugin->enable(); 104 105 break; 106 case 'disable': 107 $name = $this->objForm->getValue('plugin_name'); 108 require_once(DATA_REALDIR.'/'.$name.'/'.$name.'.php'); 109 $plugin = new $name(); 110 $plugin->disable(); 111 break; 112 default: 113 $plugins = SC_Helper_Plugin_Ex::getAllPlugin(); 114 $this->plugins = array_merge($plugins, 115 $this->getPluginOnFilesystem($plugins)); 116 break; 117 } 118 119 $this->arrSystemInfo = $this->getSystemInfo(); 120 } 121 122 /* 123 CREATE TABLE dtb_plugin ( 124 plugin_id INT NOT NULL, 125 plugin_name VARCHAR(255) NOT NULL DEFAULT "", 126 enable INT NOT NULL DEFAULT 0, 127 del_flg INT NOT NULL DEFAULT 0, 128 class_name VARCHAR(255) NOT NULL DEFAULT NULL, 129 create_date DATETIME NOT NULL, 130 update_date DATETIME NOT NULL, 131 PRIMARY KEY (plugin_id) 132 ) TYPE=InnoDB; 133 */ 134 135 function getPluginOnFilesystem($existsPlugins){ 136 137 $dir = DATA_REALDIR."plugin/"; 138 $arrPlugins = array(); 139 if($dh = opendir($dir)){ 140 while(($file = readdir($dh)) !== false){ 141 if(!preg_match('/^\\./', $file) && $file !='..' && filetype($dir.$file) == 'dir'){ 142 $arrPlugins[] = array('plugin_name'=>$file,'class_name'=>$file); 143 72 73 // パラメータ管理クラス 74 $objFormParam = new SC_FormParam(); 75 // パラメータ情報の初期化 76 $this->lfInitParam($objFormParam); 77 $objFormParam->setParam($_POST); 78 79 $mode = $this->getMode(); 80 81 switch($mode) { 82 case 'install': 83 case 'uninstall': 84 case 'enable': 85 case 'disable': 86 // エラーチェック 87 $this->arrErr = $objFormParam->checkError(); 88 89 if(count($this->arrErr) == 0) { 90 $plugin_id = $objFormParam->getValue('plugin_id'); 91 $plugin_code = $objFormParam->getValue('plugin_code'); 92 93 // プラグインファイルを読み込み、modeで指定されたメソッドを実行 94 $this->arrErr = $this->lfExecPlugin($plugin_id, $plugin_code, $mode); 95 } 96 break; 97 case 'upload': 98 // プラグイン情報を設定 99 $plugin_code = $this->lfGetPluginCode($_FILES['plugin_file']['name']); 100 $plugin_dir = $this->lfGetPluginDir($plugin_code); 101 102 // ファイルアップロード情報を設定 103 $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_REALDIR, $plugin_dir); 104 $this->lfInitUploadFile($objUpFile); 105 106 // エラーチェック 107 $this->arrErr = $this->lfCheckErrorUploadFile($plugin_code, $plugin_dir); 108 109 if(count($this->arrErr) == 0) { 110 // 一時ディレクトリへアップロード 111 $this->arrErr['plugin_file'] = $objUpFile->makeTempFile('plugin_file', false); 112 113 if($this->arrErr['plugin_file'] == "") { 114 // プラグイン保存ディレクトリへ解凍 115 $this->arrErr = $this->lfUploadPlugin($objUpFile, $plugin_dir, $plugin_code, $_FILES['plugin_file']['name']); 116 117 // 完了メッセージアラート設定 118 if(count($this->arrErr) == 0) { 119 $this->tpl_onload = "alert('プラグインをアップロードしました。');"; 120 } 144 121 } 145 122 } 146 } 147 // var_dump($arrPlugins); 148 return $arrPlugins; 123 break; 124 default: 125 break; 126 } 127 128 // DBからプラグイン情報を取得 129 $this->plugins = SC_Helper_Plugin_Ex::getAllPlugin(); 149 130 } 150 131 … … 159 140 160 141 /** 161 * システム情報を取得する 162 * 163 * @return array 164 */ 165 function getSystemInfo() { 166 $objDB = SC_DB_DBFactory_Ex::getInstance(); 167 168 $arrSystemInfo = array( 169 array('title' => 'EC-CUBE', 'value' => ECCUBE_VERSION), 170 array('title' => 'OS', 'value' => php_uname()), 171 array('title' => 'DBサーバ', 'value' => $objDB->sfGetDBVersion()), 172 array('title' => 'WEBサーバ', 'value' => $_SERVER['SERVER_SOFTWARE']), 173 array('title' => 'PHP', 'value' => phpversion()), 174 array('title' => 'GD', 'value' => extension_loaded('GD') ? 'Loaded' : '--'), 175 ); 176 177 return $arrSystemInfo; 142 * パラメータ初期化. 143 * 144 * @param object $objFormParam 145 * @return void 146 * 147 */ 148 function lfInitParam(&$objFormParam) { 149 $objFormParam->addParam('mode', 'mode', INT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK')); 150 $objFormParam->addParam('plugin_id', 'plugin_id', INT_LEN, '', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 151 $objFormParam->addParam('plugin_code', 'plugin_code', MTEXT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK')); 152 } 153 154 /** 155 * アップロードファイルパラメータ初期化. 156 * 157 * @param object $objUpFile SC_UploadFileのインスタンス. 158 * @return void 159 */ 160 function lfInitUploadFile(&$objUpFile) { 161 $objUpFile->addFile("プラグイン", 'plugin_file', array('tar', 'tar.gz'), TEMPLATE_SIZE, true, 0, 0, false); 162 } 163 164 /** 165 * アップロードファイルのエラーチェック. 166 * 167 * @param string $plugin_code 168 * @param string $plugin_dir 169 * @return array エラー情報を格納した連想配列. 170 * 171 */ 172 function lfCheckErrorUploadFile($plugin_code, $plugin_dir) { 173 $arrErr = array(); 174 175 // プラグイン重複チェック 176 $plugins = SC_Helper_Plugin_Ex::getAllPlugin(); 177 foreach($plugins as $val) { 178 if($val['plugin_code'] == $plugin_code) { 179 $arrErr['plugin_file'] = "※ 同名のプラグインがすでに登録されています。<br/>"; 180 } 181 } 182 183 return $arrErr; 184 } 185 186 /** 187 * プラグイン名(物理名)を取得する. 188 * (アップロードされたファイル名をプラグイン名(物理名)とする). 189 * 190 * @param string $upload_file_name 191 * @return string プラグイン名(物理名). 192 * 193 */ 194 function lfGetPluginCode($upload_file_name) { 195 $array_ext = explode(".", $upload_file_name); 196 return $array_ext[0]; 197 } 198 199 /** 200 * プラグイン保存ディレクトリのパスを取得する. 201 * 202 * @param string $plugin_code 203 * @return string プラグイン保存ディレクトリ. 204 * 205 */ 206 function lfGetPluginDir($plugin_code) { 207 $plugin_dir = DATA_REALDIR . 'plugin/' . $plugin_code . '/'; 208 return $plugin_dir; 209 } 210 211 /** 212 * プラグインファイルのパスを取得する. 213 * 214 * @param string $plugin_code 215 * @return string プラグインファイルパス. 216 */ 217 function lfGetPluginFilePath($plugin_code) { 218 $plugin_file_path = $this->lfGetPluginDir($plugin_code) . $plugin_code . '.php'; 219 return $plugin_file_path; 220 } 221 /** 222 * プラグインをアップロードする. 223 * 224 * @param object $objUpFile 225 * @param string $plugin_dir 226 * @param string $plugin_code 227 * @param string $plugin_file_name 228 * @return array エラー情報を格納した連想配列. 229 * 230 */ 231 function lfUploadPlugin(&$objUpFile, $plugin_dir, $plugin_code, $plugin_file_name) { 232 $arrErr = array(); 233 234 // 必須チェック 235 $arrErr = $objUpFile->checkEXISTS('plugin_file'); 236 237 if(count($arrErr) == 0) { 238 // プラグイン保存ディレクトリ作成 239 if(file_exists($plugin_dir)) { 240 $arrErr['plugin_file'] = "※ 同名のディレクトリがすでに存在します。<br/>"; 241 } else { 242 mkdir($plugin_dir); 243 } 244 245 if(count($arrErr) == 0) { 246 // 一時ディレクトリからプラグイン保存ディレクトリへ移動 247 $objUpFile->moveTempFile(); 248 249 // プラグイン保存ディレクトリへ解凍 250 SC_Helper_FileManager::unpackFile($plugin_dir . $plugin_file_name); 251 252 // プラグイン情報をDB登録 253 $this->lfRegistData($plugin_dir, $plugin_code); 254 } 255 } 256 257 return $arrErr; 258 } 259 260 /** 261 * プラグイン情報をDB登録. 262 * 263 * @param string $plugin_dir 264 * @param string $plugin_code 265 * @return void 266 * 267 */ 268 function lfRegistData($plugin_dir, $plugin_code) { 269 $objQuery =& SC_Query::getSingletonInstance(); 270 $sqlval = array(); 271 272 $sqlval['plugin_id'] = $objQuery->nextVal('dtb_plugin_plugin_id'); 273 $sqlval['plugin_code'] = $plugin_code; 274 $sqlval['status'] = PLUGIN_STATUS_UPLOADED; 275 $sqlval['enable'] = PLUGIN_ENABLE_FALSE; 276 $sqlval['update_date'] = 'now()'; 277 $objQuery->insert('dtb_plugin', $sqlval); 278 } 279 280 /** 281 * プラグインファイルを読み込む. 282 * 283 * @param string $plugin_code 284 * @return array エラー情報を格納した連想配列. 285 */ 286 function lfRequirePluginFile($plugin_code) { 287 $arrErr = array(); 288 $plugin_file_path = $this->lfGetPluginFilePath($plugin_code); 289 290 if(file_exists($plugin_file_path)) { 291 require_once($plugin_file_path); 292 } else { 293 $arrErr['plugin_error'] = "※ " . $plugin_code . ".phpが存在しないため実行できません。<br/>"; 294 } 295 296 return $arrErr; 297 } 298 299 /** 300 * プラグインファイルを読み込み、指定されたメソッドを実行する. 301 * 302 * @param integer $plugin_id 303 * @param string $plugin_code 304 * @param string $exec_mode プラグイン実行メソッド名. 305 * @return array エラー情報を格納した連想配列. 306 * 307 */ 308 function lfExecPlugin($plugin_id, $plugin_code, $exec_mode) { 309 $arrErr = array(); 310 311 // プラグインファイル読み込み 312 $arrErr = $this->lfRequirePluginFile($plugin_code); 313 314 if(count($arrErr) == 0) { 315 $plugin = new $plugin_code(); 316 $arrErr = $plugin->$exec_mode($plugin_id); 317 } 318 319 return $arrErr; 178 320 } 179 321 }
Note: See TracChangeset
for help on using the changeset viewer.
