Changeset 20208
- Timestamp:
- 2011/02/19 20:54:52 (13 years ago)
- Location:
- branches/version-2_5-dev/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/Smarty/templates/admin/contents/file_manager.tpl
r20116 r20208 31 31 <form name="form1" method="post" action="?" enctype="multipart/form-data"> 32 32 <input type="hidden" name="mode" value="" /> 33 <input type="hidden" name="now_file" value="<!--{$tpl_now_dir}-->" /> 33 <input type="hidden" name="now_file" value="<!--{$tpl_now_dir|h}-->" /> 34 <input type="hidden" name="now_dir" value="<!--{$tpl_now_file|h}-->" /> 34 35 <input type="hidden" name="tree_select_file" value="" /> 35 36 <input type="hidden" name="tree_status" value="" /> 36 37 <input type="hidden" name="select_file" value="" /> 37 38 <div id="admin-contents" class="contents-main"> 38 <div id="contents-filemanager-tree"> 39 <div id="tree"></div> 39 <div id="contents-filemanager-tree"> 40 <div id="tree"></div> 41 </div> 42 <div id="contents-filemanager-right"> 43 <table class="now_dir"> 44 <tr> 45 <th>ファイルのアップロード</th> 46 <td> 47 <!--{if $arrErr.upload_file}--><span class="attention"><!--{$arrErr.upload_file}--></span><!--{/if}--> 48 <input type="file" name="upload_file" size="40" <!--{if $arrErr.upload_file}-->style="background-color:<!--{$smarty.const.ERR_COLOR|h}-->"<!--{/if}-->><a class="btn-normal" href="javascript:;" onclick="setTreeStatus('tree_status');fnModeSubmit('upload','',''); return false;">アップロード</a> 49 </td> 50 </tr> 51 <tr> 52 <th>フォルダ作成</th> 53 <td> 54 <!--{if $arrErr.create_file}--><span class="attention"><!--{$arrErr.create_file}--></span><!--{/if}--> 55 <input type="text" name="create_file" value="" style="width:336px;<!--{if $arrErr.create_file}--> background-color:<!--{$smarty.const.ERR_COLOR|h}--><!--{/if}-->"><a class="btn-normal" href="javascript:;" onclick="setTreeStatus('tree_status');fnModeSubmit('create','',''); return false;">作成</a> 56 </td> 57 </tr> 58 </table> 59 <h2><!--{$tpl_now_dir|h}--></h2> 60 <table class="list"> 61 <tr> 62 <th>ファイル名</th> 63 <th>サイズ</th> 64 <th>更新日付</th> 65 <th class="edit">表示</th> 66 <th>ダウンロード</th> 67 <th class="delete">削除</th> 68 </tr> 69 <!--{if !$tpl_is_top_dir}--> 70 <tr id="parent_dir" onclick="fnSetFormVal('form1', 'select_file', '<!--{$tpl_parent_dir|h}-->');fnSelectFile('parent_dir', '#808080');" onDblClick="setTreeStatus('tree_status');fnDbClick(arrTree, '<!--{$tpl_parent_dir|h}-->', true, '<!--{$tpl_now_dir|h}-->', true)" style=""> 71 <td> 72 <img src="<!--{$TPL_URLPATH}-->img/contents/folder_parent.gif" alt="フォルダ"> .. 73 </td> 74 <td> </td> 75 <td> </td> 76 <td> </td> 77 <td> </td> 78 <td> </td> 79 </tr> 80 <!--{/if}--> 81 <!--{section name=cnt loop=$arrFileList}--> 82 <!--{assign var="id" value="select_file`$smarty.section.cnt.index`"}--> 83 <tr id="<!--{$id}-->" style=""> 84 <td class="file-name" onDblClick="setTreeStatus('tree_status');fnDbClick(arrTree, '<!--{$arrFileList[cnt].file_path|h}-->', <!--{if $arrFileList[cnt].is_dir|h}-->true<!--{else}-->false<!--{/if}-->, '<!--{$tpl_now_dir|h}-->', false)"> 85 <!--{if $arrFileList[cnt].is_dir}--> 86 <img src="<!--{$TPL_URLPATH}-->img/contents/folder_close.gif" alt="フォルダ"> 87 <!--{else}--> 88 <img src="<!--{$TPL_URLPATH}-->img/contents/file.gif"> 89 <!--{/if}--> 90 <!--{$arrFileList[cnt].file_name|h}--> 91 </td> 92 <td class="right"> 93 <!--{$arrFileList[cnt].file_size|number_format}--> 94 </td> 95 <td class="center"> 96 <!--{$arrFileList[cnt].file_time|h}--> 97 </td> 98 <!--{if $arrFileList[cnt].is_dir}--> 99 <td class="center"> 100 <a href="javascript:;" onclick="fnSetFormVal('form1', 'tree_select_file', '<!--{$arrFileList[cnt].file_path}-->');fnSelectFile('<!--{$id}-->', '#808080');fnModeSubmit('move','',''); return false;">表示</a> 101 </td> 102 <!--{else}--> 103 <td class="center"> 104 <a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');fnModeSubmit('view','',''); return false;">表示</a> 105 </td> 106 <!--{/if}--> 107 <!--{if $arrFileList[cnt].is_dir}--> 108 <!--{* ディレクトリはダウンロード不可 *}--> 109 <td class="center">-</td> 110 <!--{else}--> 111 <td class="center"> 112 <a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');setTreeStatus('tree_status');fnModeSubmit('download','',''); return false;">ダウンロード</a> 113 </td> 114 <!--{/if}--> 115 <td class="center"> 116 <a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');setTreeStatus('tree_status');fnModeSubmit('delete','',''); return false;">削除</a> 117 </td> 118 </tr> 119 <!--{/section}--> 120 </table> 121 </div> 40 122 </div> 41 42 <div id="contents-filemanager-right">43 <table class="now_dir">44 <tr>45 <th>ファイルのアップロード</th>46 <td>47 <!--{if $arrErr.upload_file}--><span class="attention"><!--{$arrErr.upload_file}--></span><!--{/if}-->48 <input type="file" name="upload_file" size="40" <!--{if $arrErr.upload_file}-->style="background-color:<!--{$smarty.const.ERR_COLOR|h}-->"<!--{/if}-->><a class="btn-normal" href="javascript:;" onclick="setTreeStatus('tree_status');fnModeSubmit('upload','',''); return false;">アップロード</a>49 </td>50 </tr>51 <tr>52 <th>フォルダ作成</th>53 <td>54 <!--{if $arrErr.create_file}--><span class="attention"><!--{$arrErr.create_file}--></span><!--{/if}-->55 <input type="text" name="create_file" value="" style="width:336px;<!--{if $arrErr.create_file}--> background-color:<!--{$smarty.const.ERR_COLOR|h}--><!--{/if}-->"><a class="btn-normal" href="javascript:;" onclick="setTreeStatus('tree_status');fnModeSubmit('create','',''); return false;">作成</a>56 </td>57 </tr>58 </table>59 60 <h2><!--{$tpl_now_dir|h}--></h2>61 62 <table class="list">63 <tr>64 <th>ファイル名</th>65 <th>サイズ</th>66 <th>更新日付</th>67 <th class="edit">表示</th>68 <th>ダウンロード</th>69 <th class="delete">削除</th>70 </tr>71 <!--{if !$tpl_is_top_dir}-->72 <tr id="parent_dir" onclick="fnSetFormVal('form1', 'select_file', '<!--{$tpl_parent_dir|h}-->');fnSelectFile('parent_dir', '#808080');" onDblClick="setTreeStatus('tree_status');fnDbClick(arrTree, '<!--{$tpl_parent_dir|h}-->', true, '<!--{$tpl_now_dir|h}-->', true)" style="">73 <td>74 <img src="<!--{$TPL_URLPATH}-->img/contents/folder_parent.gif" alt="フォルダ"> ..75 </td>76 <td> </td>77 <td> </td>78 <td> </td>79 <td> </td>80 <td> </td>81 </tr>82 <!--{/if}-->83 <!--{section name=cnt loop=$arrFileList}-->84 <!--{assign var="id" value="select_file`$smarty.section.cnt.index`"}-->85 <tr id="<!--{$id}-->" style="">86 <td class="file-name" onDblClick="setTreeStatus('tree_status');fnDbClick(arrTree, '<!--{$arrFileList[cnt].file_path|h}-->', <!--{if $arrFileList[cnt].is_dir|h}-->true<!--{else}-->false<!--{/if}-->, '<!--{$tpl_now_dir|h}-->', false)">87 <!--{if $arrFileList[cnt].is_dir}-->88 <img src="<!--{$TPL_URLPATH}-->img/contents/folder_close.gif" alt="フォルダ">89 <!--{else}-->90 <img src="<!--{$TPL_URLPATH}-->img/contents/file.gif">91 <!--{/if}-->92 <!--{$arrFileList[cnt].file_name|h}-->93 </td>94 <td class="right"><!--{$arrFileList[cnt].file_size|number_format}--></td>95 <td class="center"><!--{$arrFileList[cnt].file_time|h}--></td>96 <td class="center"><a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');fnModeSubmit('view','',''); return false;">表示</a></td>97 <td class="center"><a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');setTreeStatus('tree_status');fnModeSubmit('download','',''); return false;">ダウンロード</a></td>98 <td class="center"><a href="javascript:;" onclick="fnSetFormVal('form1', 'select_file', '<!--{$arrFileList[cnt].file_path|h}-->');fnSelectFile('<!--{$id}-->', '#808080');setTreeStatus('tree_status');fnModeSubmit('delete','',''); return false;">削除</a></td>99 </tr>100 <!--{/section}-->101 </table>102 </div>103 </div>104 105 123 </form> -
branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php
r20116 r20208 69 69 */ 70 70 function action() { 71 //---- 認証可否の判定 72 $objSess = new SC_Session(); 73 SC_Utils_Ex::sfIsSuccess($objSess); 74 75 // ルートディレクトリ 76 $top_dir = USER_REALDIR; 77 78 $objView = new SC_AdminView(); 79 $objQuery = new SC_Query(); 80 $objFileManager = new SC_Helper_FileManager_Ex(); 81 82 // 現在の階層を取得 TODO 要リファクタリング(MODE if利用) 83 if($this->getMode() != null) { 84 $now_dir = $_POST['now_file']; 85 } else { 86 // 初期表示はルートディレクトリ(user_data/)を表示 87 $now_dir = $top_dir; 88 } 71 // 認証可否の判定 72 SC_Utils_Ex::sfIsSuccess(new SC_Session()); 73 74 // フォーム操作クラス 75 $objFormParam = new SC_FormParam(); 76 // パラメータ情報の初期化 77 $this->lfInitParam($objFormParam); 78 $objFormParam->setParam($this->createSetParam($_POST)); 79 $objFormParam->convParam(); 89 80 90 81 // ファイル管理クラス 91 $objUpFile = new SC_UploadFile($ now_dir, $now_dir);82 $objUpFile = new SC_UploadFile($objFormParam->getValue('now_dir'), $objFormParam->getValue('now_dir')); 92 83 // ファイル情報の初期化 93 84 $this->lfInitFile($objUpFile); 94 85 86 // ファイル操作クラス 87 $objFileManager = new SC_Helper_FileManager_Ex(); 88 95 89 switch($this->getMode()) { 96 97 // ファイル表示 98 90 // フォルダ移動 91 case 'move': 92 $objFormParam = new SC_FormParam(); 93 $this->lfInitParamModeMove($objFormParam); 94 $objFormParam->setParam($this->createSetParam($_POST)); 95 $objFormParam->convParam(); 96 97 $this->arrErr = $objFormParam->checkError(); 98 if (SC_Utils_Ex::isBlank($this->arrErr)) { 99 $now_dir = $this->lfCheckSelectDir($objFormParam, $objFormParam->getValue('tree_select_file')); 100 $objFormParam->setValue('now_dir', $now_dir); 101 } 102 break; 103 104 // ファイル表示 99 105 case 'view': 100 // エラーチェック 101 102 $arrErr = $this->lfErrorCheck(); 103 104 if (empty($arrErr)) { 105 // 選択されたファイルがディレクトリなら移動 106 if(is_dir($_POST['select_file'])) { 107 $now_dir = $this->lfCheckSelectDir($_POST['select_file']); 108 } else { 109 // javascriptで別窓表示(テンプレート側に渡す) 110 // FIXME XSS対策すること 111 $file_url = ereg_replace(USER_REALDIR, "", $_POST['select_file']); 112 $this->tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');"; 113 $now_dir = $this->lfCheckSelectDir(dirname($_POST['select_file'])); 106 $objFormParam = new SC_FormParam(); 107 $this->lfInitParamModeView($objFormParam); 108 $objFormParam->setParam($this->createSetParam($_POST)); 109 $objFormParam->convParam(); 110 111 $this->arrErr = $objFormParam->checkError(); 112 if (SC_Utils_Ex::isBlank($this->arrErr)) { 113 if($this->tryView($objFormParam)){ 114 $file_url = htmlspecialchars(ereg_replace($objFormParam->getValue('top_dir'), "", $objFormParam->getValue('select_file'))); 115 $tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');"; 116 $this->setTplOnLoad($tpl_onload); 114 117 } 115 118 } 116 117 break; 118 119 // ファイルダウンロード 119 break; 120 121 // ファイルダウンロード 120 122 case 'download': 121 122 // エラーチェック 123 $arrErr = $this->lfErrorCheck(); 124 if (empty($arrErr)) { 125 if(is_dir($_POST['select_file'])) { 126 // ディレクトリの場合はjavascriptエラー 127 $arrErr['select_file'] = "※ ディレクトリをダウンロードすることは出来ません。<br/>"; 123 $objFormParam = new SC_FormParam(); 124 $this->lfInitParamModeView($objFormParam); 125 $objFormParam->setParam($this->createSetParam($_POST)); 126 $objFormParam->convParam(); 127 128 $this->arrErr = $objFormParam->checkError(); 129 if (SC_Utils_Ex::isBlank($this->arrErr)) { 130 if(is_dir($objFormParam->getValue('select_file'))) { 131 $dispError = "※ ディレクトリをダウンロードすることは出来ません。<br/>"; 132 $this->setDispError('select_file', $dispError); 128 133 } else { 129 134 // ファイルダウンロード 130 $objFileManager->sfDownloadFile($ _POST['select_file']);135 $objFileManager->sfDownloadFile($objFormParam->getValue('select_file')); 131 136 exit; 132 137 } 133 138 } 134 139 break; 135 140 // ファイル削除 136 141 case 'delete': 137 // エラーチェック 138 $arrErr = $this->lfErrorCheck(); 139 if (empty($arrErr)) { 140 $objFileManager->sfDeleteDir($_POST['select_file']); 141 } 142 break; 143 // ファイル作成 142 $objFormParam = new SC_FormParam(); 143 $this->lfInitParamModeView($objFormParam); 144 $objFormParam->setParam($this->createSetParam($_POST)); 145 $objFormParam->convParam(); 146 147 $this->arrErr = $objFormParam->checkError(); 148 if (SC_Utils_Ex::isBlank($this->arrErr)) { 149 $objFileManager->sfDeleteDir($objFormParam->getValue('select_file')); 150 } 151 break; 152 // ファイル作成 144 153 case 'create': 145 // エラーチェック 146 $arrErr = $this->lfCreateErrorCheck(); 147 if (empty($arrErr)) { 148 $create_dir = ereg_replace("/$", "", $now_dir); 149 // ファイル作成 150 if(!$objFileManager->sfCreateFile($create_dir."/".$_POST['create_file'], 0755)) { 151 // 作成エラー 152 $arrErr['create_file'] = "※ ".$_POST['create_file']."の作成に失敗しました。<br/>"; 154 $objFormParam = new SC_FormParam(); 155 $this->lfInitParamModeCreate($objFormParam); 156 $objFormParam->setParam($this->createSetParam($_POST)); 157 $objFormParam->convParam(); 158 159 $this->arrErr = $objFormParam->checkError(); 160 if (SC_Utils_Ex::isBlank($this->arrErr)) { 161 if(!$this->tryCreateDir($objFileManager, $objFormParam)){ 162 $disp_error = "※ ".htmlspecialchars($objFormParam->getValue('create_file'), ENT_QUOTES)."の作成に失敗しました。<br/>"; 163 $this->setDispError('create_file', $dispError); 153 164 } else { 154 $this->tpl_onload .= "alert('フォルダを作成しました。');"; 165 $tpl_onload = "alert('フォルダを作成しました。');"; 166 $this->setTplOnLoad($tpl_onload); 155 167 } 156 168 } 157 169 break; 158 170 // ファイルアップロード 159 171 case 'upload': 160 172 // 画像保存処理 161 173 $ret = $objUpFile->makeTempFile('upload_file', false); 162 if($ret != "") { 163 $arrErr['upload_file'] = $ret; 174 if (SC_Utils_Ex::isBlank($ret)) { 175 $tpl_onload = "alert('ファイルをアップロードしました。');"; 176 $this->setTplOnLoad($tpl_onload); 164 177 } else { 165 $this->tpl_onload .= "alert('ファイルをアップロードしました。');"; 166 } 167 break; 168 // フォルダ移動 169 case 'move': 170 $now_dir = $this->lfCheckSelectDir($_POST['tree_select_file']); 171 break; 172 // 初期表示 178 $this->setDispError('upload_file', $ret); 179 } 180 break; 181 // 初期表示 173 182 default : 174 183 break; 175 184 } 185 186 // 値をテンプレートに渡す 187 $this->arrParam = $objFormParam->getHashArray(); 188 // 現在の階層がルートディレクトリかどうかテンプレートに渡す 189 $this->setIsTopDir($objFormParam); 190 // 現在の階層より一つ上の階層をテンプレートに渡す 191 $this->setParentDir($objFormParam); 192 // 現在いる階層(表示用)をテンプレートに渡す 193 $this->setDispPath($objFormParam); 194 // 現在のディレクトリ配下のファイル一覧を取得 195 $this->arrFileList = $objFileManager->sfGetFileList($objFormParam->getValue('now_dir')); 196 // 現在の階層のディレクトリをテンプレートに渡す 197 $this->setDispParam('tpl_now_file', $objFormParam->getValue('now_dir')); 198 // ディレクトリツリー表示 199 $this->setDispTree($objFileManager, $objFormParam); 200 } 201 202 /** 203 * デストラクタ. 204 * 205 * @return void 206 */ 207 function destroy() { 208 parent::destroy(); 209 } 210 211 /** 212 * 初期化を行う. 213 * 214 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 215 * @return void 216 */ 217 function lfInitParam(&$objFormParam) { 218 // 共通定義 219 $this->lfInitParamCommon($objFormParam); 220 } 221 222 /** 223 * ディレクトリ移動時、パラメータ定義 224 * 225 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 226 * @return void 227 */ 228 function lfInitParamModeMove(&$objFormParam) { 229 // 共通定義 230 $this->lfInitParamCommon($objFormParam); 231 $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array()); 232 } 233 234 /** 235 * ファイル表示時、パラメータ定義 236 * 237 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 238 * @return void 239 */ 240 function lfInitParamModeView(&$objFormParam) { 241 // 共通定義 242 $this->lfInitParamCommon($objFormParam); 243 $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array("SELECT_CHECK")); 244 } 245 246 /** 247 * ファイル表示時、パラメータ定義 248 * 249 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 250 * @return void 251 */ 252 function lfInitParamModeCreate(&$objFormParam) { 253 // 共通定義 254 $this->lfInitParamCommon($objFormParam); 255 $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array()); 256 $objFormParam->addParam("作成ファイル名", "create_file", MTEXT_LEN, "a", array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD")); 257 } 258 259 /** 260 * ファイル表示時、パラメータ定義 261 * 262 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 263 * @return void 264 */ 265 function lfInitParamCommon(&$objFormParam) { 266 $objFormParam->addParam("ルートディレクトリ", "top_dir", MTEXT_LEN, "a", array()); 267 $objFormParam->addParam("現在の階層ディレクトリ", "now_dir", MTEXT_LEN, "a", array()); 268 $objFormParam->addParam("現在の階層ファイル", "now_file", MTEXT_LEN, "a", array()); 269 $objFormParam->addParam("ツリー選択状態", "tree_status", MTEXT_LEN, "a", array()); 270 $objFormParam->addParam("ツリー選択ディレクトリ", "tree_select_file", MTEXT_LEN, "a", array()); 271 } 272 273 274 /* 275 * ファイル情報の初期化 276 * 277 * @param object $objUpFile SC_UploadFileインスタンス 278 * @return void 279 */ 280 function lfInitFile(&$objUpFile) { 281 $objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false); 282 } 283 284 /** 285 * テンプレートに渡す値を整形する 286 * 287 * @param array $_POST $_POST 288 * @return array $setParam テンプレートに渡す値 289 */ 290 function createSetParam($_POST) { 291 $setParam = $_POST; 292 // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する 293 $setParam['top_dir'] = (strpos(PHP_OS, 'WIN') === false) ? USER_REALDIR : str_replace('\\', '/', USER_REALDIR); 294 // 初期表示はルートディレクトリ(user_data/)を表示 295 if (SC_Utils_Ex::isBlank($this->getMode())) { 296 $setParam['now_dir'] = $setParam['top_dir']; 297 } 298 return $setParam; 299 } 300 301 /** 302 * テンプレートに値を渡す 303 * 304 * @param string $key キー名 305 * @param string $val 値 306 * @return void 307 */ 308 function setDispParam($key, $val){ 309 $this->$key = $val; 310 } 311 312 /** 313 * ディレクトリを作成 314 * 315 * @param object $objFileManager SC_Helper_FileManager_Exインスタンス 316 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 317 * @return boolean ディレクトリ作成できたかどうか 318 */ 319 function tryCreateDir($objFileManager, $objFormParam){ 320 $create_dir_flg = false; 321 $create_dir = ereg_replace("/$", "", $objFormParam->getValue('now_dir')); 322 // ファイル作成 323 if($objFileManager->sfCreateFile($create_dir."/".$objFormParam->getValue('create_file'), 0755)) { 324 $create_dir_flg = true; 325 } 326 return $create_dir_flg; 327 } 328 329 /** 330 * ファイル表示を行う 331 * 332 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 333 * @return boolean ファイル表示するかどうか 334 */ 335 function tryView(&$objFormParam){ 336 $view_flg = false; 337 $now_dir = $this->lfCheckSelectDir($objFormParam, dirname($objFormParam->getValue('select_file'))); 338 $objFormParam->setValue('now_dir', $now_dir); 339 if (!strpos($objFormParam->getValue('select_file'), $objFormParam->getValue('top_dir'))) { 340 $view_flg = true; 341 } 342 return $view_flg; 343 } 344 345 /** 346 * 現在の階層の一つ上の階層のディレクトリをテンプレートに渡す 347 * 348 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 349 * @return void 350 */ 351 function setParentDir($objFormParam){ 352 $parent_dir = $this->lfGetParentDir($objFormParam->getValue('now_dir')); 353 $this->setDispParam('tpl_parent_dir', $parent_dir); 354 } 355 356 /** 357 * 現在の階層のパスをテンプレートに渡す 358 * 359 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 360 * @return void 361 */ 362 function setDispPath($objFormParam){ 363 // TODO JSON で投げて, フロント側で処理した方が良い? 364 $tpl_now_dir = ""; 365 $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $objFormParam->getValue('now_dir'))); 366 for ($i = 0; $i < count($arrNowDir); $i++) { 367 if (!empty($arrNowDir)) { 368 $tpl_now_dir .= $arrNowDir[$i]; 369 if ($i < count($arrNowDir) - 1) { 370 // フロント側で > へエスケープするため, ここでは > を使用 371 $tpl_now_dir .= ' > '; 372 } 373 } 374 } 375 $this->setDispParam('tpl_now_dir', $tpl_now_dir); 376 } 377 378 /** 379 * エラーを表示用の配列に格納 380 * 381 * @param string $key キー名 382 * @param string $value エラー内容 383 * @return void 384 */ 385 function setDispError($key, $value){ 386 // 既にエラーがある場合は、処理しない 387 if (SC_Utils_Ex::isBlank($this->arrErr[$key])) { 388 $this->arrErr[$key] = $value; 389 } 390 } 391 392 /** 393 * javascriptをテンプレートに渡す 394 * 395 * @param string $tpl_onload javascript 396 * @return void 397 */ 398 function setTplOnLoad($tpl_onload){ 399 $this->tpl_onload .= $tpl_onload; 400 } 401 402 /* 403 * 選択ディレクトリがUSER_REALDIR以下かチェック 404 * 405 * @param object $objFormParam SC_FormParamインスタンス 406 * @param string $dir ディレクトリ 407 * @return string $select_dir 選択ディレクトリ 408 */ 409 function lfCheckSelectDir($objFormParam, $dir) { 410 $select_dir = ''; 411 $top_dir = $objFormParam->getValue('top_dir'); 412 // USER_REALDIR以下の場合 413 if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) { 414 // 相対パスがある場合、USER_REALDIRを返す. 415 if (preg_match("@\Q..\E@", $dir) > 0) { 416 $select_dir = $top_dir; 417 // 相対パスがない場合、そのままディレクトリパスを返す. 418 } else { 419 $select_dir= $dir; 420 } 421 // USER_REALDIR以下でない場合、USER_REALDIRを返す. 422 } else { 423 $select_dir = $top_dir; 424 } 425 return $select_dir; 426 } 427 428 /** 429 * 親ディレクトリ取得 430 * 431 * @param string $dir 現在いるディレクトリ 432 * @return string $parent_dir 親ディレクトリ 433 */ 434 function lfGetParentDir($dir) { 435 $parent_dir = ""; 436 $dir = ereg_replace("/$", "", $dir); 437 $arrDir = split('/', $dir); 438 array_pop($arrDir); 439 foreach($arrDir as $val) { 440 $parent_dir .= "$val/"; 441 } 442 $parent_dir = ereg_replace("/$", "", $parent_dir); 443 return $parent_dir; 444 } 445 446 /** 447 * ディレクトリツリー生成 448 * 449 * @param object $objFileManager SC_Helper_FileManager_Exインスタンス 450 * @param SC_FormParam $objFormParam SC_FormParamインスタンス 451 * @return void 452 */ 453 function setDispTree($objFileManager, $objFormParam){ 454 $tpl_onload = ''; 455 // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名 456 $now_dir = $objFormParam->getValue('now_dir'); 457 $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');"; 458 if (!empty($this->tpl_onload)) { 459 $tpl_onload .= $treeView; 460 } else { 461 $tpl_onload = $treeView; 462 } 463 $this->setTplOnLoad($tpl_onload); 464 465 $tpl_javascript = ''; 466 $arrTree = $objFileManager->sfGetFileTree($objFormParam->getValue('top_dir'), $objFormParam->getValue('tree_status')); 467 $tpl_javascript .= "arrTree = new Array();\n"; 468 foreach($arrTree as $arrVal) { 469 $tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].","; 470 if ($arrVal['open']) { 471 $tpl_javascript .= "true);\n"; 472 } else { 473 $tpl_javascript .= "false);\n"; 474 } 475 } 476 $this->setDispParam('tpl_javascript', $tpl_javascript); 477 } 478 479 /** 480 * 現在の階層がルートディレクトリかどうかテンプレートに渡す 481 * 482 * @param object $objFormParam SC_FormParamインスタンス 483 * @return void 484 */ 485 function setIsTopDir($objFormParam){ 176 486 // トップディレクトリか調査 177 487 $is_top_dir = false; 178 488 // 末尾の/をとる 179 $top_dir_check = ereg_replace("/$", "", $ top_dir);180 $now_dir_check = ereg_replace("/$", "", $ now_dir);489 $top_dir_check = ereg_replace("/$", "", $objFormParam->getValue('top_dir')); 490 $now_dir_check = ereg_replace("/$", "", $objFormParam->getValue('now_dir')); 181 491 if($top_dir_check == $now_dir_check) $is_top_dir = true; 182 183 // 現在の階層より一つ上の階層を取得 184 $parent_dir = $this->lfGetParentDir($now_dir); 185 186 // 現在のディレクトリ配下のファイル一覧を取得 187 $this->arrFileList = $objFileManager->sfGetFileList($now_dir); 188 $this->tpl_is_top_dir = $is_top_dir; 189 $this->tpl_parent_dir = $parent_dir; 190 // TODO JSON で投げて, フロント側で処理した方が良い? 191 $this->tpl_now_dir = ""; 192 $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $now_dir)); 193 for ($i = 0; $i < count($arrNowDir); $i++) { 194 if (!empty($arrNowDir)) { 195 $this->tpl_now_dir .= $arrNowDir[$i]; 196 if ($i < count($arrNowDir) - 1) { 197 // フロント側で > へエスケープするため, ここでは > を使用 198 $this->tpl_now_dir .= ' > '; 199 } 200 } 201 } 202 $this->tpl_now_file = basename($now_dir); 203 $this->arrErr = isset($arrErr) ? $arrErr : ""; 204 $this->arrParam = $_POST; 205 206 // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名 207 $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');"; 208 if (!empty($this->tpl_onload)) { 209 $this->tpl_onload .= $treeView; 210 } else { 211 $this->tpl_onload = $treeView; 212 } 213 214 // ツリー配列作成用 javascript 215 if (!isset($_POST['tree_status'])) $_POST['tree_status'] = ""; 216 $arrTree = $objFileManager->sfGetFileTree($top_dir, $_POST['tree_status']); 217 $this->tpl_javascript .= "arrTree = new Array();\n"; 218 foreach($arrTree as $arrVal) { 219 $this->tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].","; 220 if ($arrVal['open']) { 221 $this->tpl_javascript .= "true);\n"; 222 } else { 223 $this->tpl_javascript .= "false);\n"; 224 } 225 } 226 } 227 228 /** 229 * デストラクタ. 230 * 231 * @return void 232 */ 233 function destroy() { 234 parent::destroy(); 235 } 236 237 /* 238 * 関数名:lfErrorCheck() 239 * 説明 :エラーチェック 240 */ 241 function lfErrorCheck() { 242 $objErr = new SC_CheckError($_POST); 243 $objErr->doFunc(array("ファイル", "select_file"), array("SELECT_CHECK")); 244 245 return $objErr->arrErr; 246 } 247 248 /* 249 * 関数名:lfCreateErrorCheck() 250 * 説明 :ファイル作成処理エラーチェック 251 */ 252 function lfCreateErrorCheck() { 253 $objErr = new SC_CheckError($_POST); 254 $objErr->doFunc(array("作成ファイル名", "create_file"), array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD")); 255 256 return $objErr->arrErr; 257 } 258 259 /* 260 * 関数名:lfInitFile() 261 * 説明 :ファイル情報の初期化 262 */ 263 function lfInitFile(&$objUpFile) { 264 $objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false); 265 } 266 267 /* 268 * 関数名:lfCheckSelectDir() 269 * 引数1:ディレクトリ 270 * 説明:選択ディレクトリがUSER_REALDIR以下かチェック 271 */ 272 function lfCheckSelectDir($dir) { 273 $top_dir = USER_REALDIR; 274 // USER_REALDIR以下の場合 275 if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) { 276 // 相対パスがある場合、USER_REALDIRを返す. 277 if (preg_match("@\Q..\E@", $dir) > 0) { 278 return $top_dir; 279 // 相対パスがない場合、そのままディレクトリパスを返す. 280 } else { 281 return $dir; 282 } 283 // USER_REALDIR以下でない場合、USER_REALDIRを返す. 284 } else { 285 return $top_dir; 286 } 287 } 288 289 /* 290 * 関数名:lfGetParentDir() 291 * 引数1 :ディレクトリ 292 * 説明 :親ディレクトリ取得 293 */ 294 function lfGetParentDir($dir) { 295 $dir = ereg_replace("/$", "", $dir); 296 $arrDir = split('/', $dir); 297 array_pop($arrDir); 298 $parent_dir = ""; 299 foreach($arrDir as $val) { 300 $parent_dir .= "$val/"; 301 } 302 $parent_dir = ereg_replace("/$", "", $parent_dir); 303 304 return $parent_dir; 305 } 492 $this->setDispParam('tpl_is_top_dir', $is_top_dir); 493 } 494 306 495 } 307 496 ?>
Note: See TracChangeset
for help on using the changeset viewer.