[Svn-src-all:1319] [version-2_5-dev 20208] #1016 コンテンツ管理リファクタリング
kishida
admin @ mail.ec-cube.net
2011年 2月 19日 (土) 20:54:53 JST
Subversion committed to /home/svn/open 20208
http://svn.ec-cube.net/open_trac/changeset/20208
┌────────────────────────────┐
│更新者 : kishida │
│更新日時: 2011-02-19 20:54:52 +0900 (土, 19 2月 2011)│
└────────────────────────────┘
Log:
--------------------------------------------------------
#1016 コンテンツ管理リファクタリング
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
U branches/version-2_5-dev/data/Smarty/templates/admin/contents/file_manager.tpl
U branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php
変更: branches/version-2_5-dev/data/Smarty/templates/admin/contents/file_manager.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/admin/contents/file_manager.tpl 2011-02-19 11:24:28 UTC (rev 20207)
+++ branches/version-2_5-dev/data/Smarty/templates/admin/contents/file_manager.tpl 2011-02-19 11:54:52 UTC (rev 20208)
@@ -30,76 +30,94 @@
</script>
<form name="form1" method="post" action="?" enctype="multipart/form-data">
<input type="hidden" name="mode" value="" />
-<input type="hidden" name="now_file" value="<!--{$tpl_now_dir}-->" />
+<input type="hidden" name="now_file" value="<!--{$tpl_now_dir|h}-->" />
+<input type="hidden" name="now_dir" value="<!--{$tpl_now_file|h}-->" />
<input type="hidden" name="tree_select_file" value="" />
<input type="hidden" name="tree_status" value="" />
<input type="hidden" name="select_file" value="" />
<div id="admin-contents" class="contents-main">
-<div id="contents-filemanager-tree">
- <div id="tree"></div>
+ <div id="contents-filemanager-tree">
+ <div id="tree"></div>
+ </div>
+ <div id="contents-filemanager-right">
+ <table class="now_dir">
+ <tr>
+ <th>ファイルのアップロード</th>
+ <td>
+ <!--{if $arrErr.upload_file}--><span class="attention"><!--{$arrErr.upload_file}--></span><!--{/if}-->
+ <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>
+ </td>
+ </tr>
+ <tr>
+ <th>フォルダ作成</th>
+ <td>
+ <!--{if $arrErr.create_file}--><span class="attention"><!--{$arrErr.create_file}--></span><!--{/if}-->
+ <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>
+ </td>
+ </tr>
+ </table>
+ <h2><!--{$tpl_now_dir|h}--></h2>
+ <table class="list">
+ <tr>
+ <th>ファイル名</th>
+ <th>サイズ</th>
+ <th>更新日付</th>
+ <th class="edit">表示</th>
+ <th>ダウンロード</th>
+ <th class="delete">削除</th>
+ </tr>
+ <!--{if !$tpl_is_top_dir}-->
+ <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="">
+ <td>
+ <img src="<!--{$TPL_URLPATH}-->img/contents/folder_parent.gif" alt="フォルダ"> ..
+ </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <!--{/if}-->
+ <!--{section name=cnt loop=$arrFileList}-->
+ <!--{assign var="id" value="select_file`$smarty.section.cnt.index`"}-->
+ <tr id="<!--{$id}-->" style="">
+ <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)">
+ <!--{if $arrFileList[cnt].is_dir}-->
+ <img src="<!--{$TPL_URLPATH}-->img/contents/folder_close.gif" alt="フォルダ">
+ <!--{else}-->
+ <img src="<!--{$TPL_URLPATH}-->img/contents/file.gif">
+ <!--{/if}-->
+ <!--{$arrFileList[cnt].file_name|h}-->
+ </td>
+ <td class="right">
+ <!--{$arrFileList[cnt].file_size|number_format}-->
+ </td>
+ <td class="center">
+ <!--{$arrFileList[cnt].file_time|h}-->
+ </td>
+ <!--{if $arrFileList[cnt].is_dir}-->
+ <td class="center">
+ <a href="javascript:;" onclick="fnSetFormVal('form1', 'tree_select_file', '<!--{$arrFileList[cnt].file_path}-->');fnSelectFile('<!--{$id}-->', '#808080');fnModeSubmit('move','',''); return false;">表示</a>
+ </td>
+ <!--{else}-->
+ <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>
+ <!--{/if}-->
+ <!--{if $arrFileList[cnt].is_dir}-->
+ <!--{* ディレクトリはダウンロード不可 *}-->
+ <td class="center">-</td>
+ <!--{else}-->
+ <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>
+ <!--{/if}-->
+ <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>
+ </tr>
+ <!--{/section}-->
+ </table>
+ </div>
</div>
-
-<div id="contents-filemanager-right">
- <table class="now_dir">
- <tr>
- <th>ファイルのアップロード</th>
- <td>
- <!--{if $arrErr.upload_file}--><span class="attention"><!--{$arrErr.upload_file}--></span><!--{/if}-->
- <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>
- </td>
- </tr>
- <tr>
- <th>フォルダ作成</th>
- <td>
- <!--{if $arrErr.create_file}--><span class="attention"><!--{$arrErr.create_file}--></span><!--{/if}-->
- <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>
- </td>
- </tr>
- </table>
-
- <h2><!--{$tpl_now_dir|h}--></h2>
-
- <table class="list">
- <tr>
- <th>ファイル名</th>
- <th>サイズ</th>
- <th>更新日付</th>
- <th class="edit">表示</th>
- <th>ダウンロード</th>
- <th class="delete">削除</th>
- </tr>
- <!--{if !$tpl_is_top_dir}-->
- <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="">
- <td>
- <img src="<!--{$TPL_URLPATH}-->img/contents/folder_parent.gif" alt="フォルダ"> ..
- </td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- <!--{/if}-->
- <!--{section name=cnt loop=$arrFileList}-->
- <!--{assign var="id" value="select_file`$smarty.section.cnt.index`"}-->
- <tr id="<!--{$id}-->" style="">
- <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)">
- <!--{if $arrFileList[cnt].is_dir}-->
- <img src="<!--{$TPL_URLPATH}-->img/contents/folder_close.gif" alt="フォルダ">
- <!--{else}-->
- <img src="<!--{$TPL_URLPATH}-->img/contents/file.gif">
- <!--{/if}-->
- <!--{$arrFileList[cnt].file_name|h}-->
- </td>
- <td class="right"><!--{$arrFileList[cnt].file_size|number_format}--></td>
- <td class="center"><!--{$arrFileList[cnt].file_time|h}--></td>
- <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>
- <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>
- <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>
- </tr>
- <!--{/section}-->
- </table>
- </div>
-</div>
-
</form>
変更: branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php 2011-02-19 11:24:28 UTC (rev 20207)
+++ branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php 2011-02-19 11:54:52 UTC (rev 20208)
@@ -68,161 +68,135 @@
* @return void
*/
function action() {
- //---- 認証可否の判定
- $objSess = new SC_Session();
- SC_Utils_Ex::sfIsSuccess($objSess);
+ // 認証可否の判定
+ SC_Utils_Ex::sfIsSuccess(new SC_Session());
- // ルートディレクトリ
- $top_dir = USER_REALDIR;
+ // フォーム操作クラス
+ $objFormParam = new SC_FormParam();
+ // パラメータ情報の初期化
+ $this->lfInitParam($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
- $objView = new SC_AdminView();
- $objQuery = new SC_Query();
- $objFileManager = new SC_Helper_FileManager_Ex();
-
- // 現在の階層を取得 TODO 要リファクタリング(MODE if利用)
- if($this->getMode() != null) {
- $now_dir = $_POST['now_file'];
- } else {
- // 初期表示はルートディレクトリ(user_data/)を表示
- $now_dir = $top_dir;
- }
-
// ファイル管理クラス
- $objUpFile = new SC_UploadFile($now_dir, $now_dir);
+ $objUpFile = new SC_UploadFile($objFormParam->getValue('now_dir'), $objFormParam->getValue('now_dir'));
// ファイル情報の初期化
$this->lfInitFile($objUpFile);
+ // ファイル操作クラス
+ $objFileManager = new SC_Helper_FileManager_Ex();
+
switch($this->getMode()) {
+ // フォルダ移動
+ case 'move':
+ $objFormParam = new SC_FormParam();
+ $this->lfInitParamModeMove($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
+
+ $this->arrErr = $objFormParam->checkError();
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ $now_dir = $this->lfCheckSelectDir($objFormParam, $objFormParam->getValue('tree_select_file'));
+ $objFormParam->setValue('now_dir', $now_dir);
+ }
+ break;
- // ファイル表示
-
+ // ファイル表示
case 'view':
- // エラーチェック
-
- $arrErr = $this->lfErrorCheck();
-
- if (empty($arrErr)) {
- // 選択されたファイルがディレクトリなら移動
- if(is_dir($_POST['select_file'])) {
- $now_dir = $this->lfCheckSelectDir($_POST['select_file']);
- } else {
- // javascriptで別窓表示(テンプレート側に渡す)
- // FIXME XSS対策すること
- $file_url = ereg_replace(USER_REALDIR, "", $_POST['select_file']);
- $this->tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
- $now_dir = $this->lfCheckSelectDir(dirname($_POST['select_file']));
+ $objFormParam = new SC_FormParam();
+ $this->lfInitParamModeView($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
+
+ $this->arrErr = $objFormParam->checkError();
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ if($this->tryView($objFormParam)){
+ $file_url = htmlspecialchars(ereg_replace($objFormParam->getValue('top_dir'), "", $objFormParam->getValue('select_file')));
+ $tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
+ $this->setTplOnLoad($tpl_onload);
}
}
-
break;
- // ファイルダウンロード
+ // ファイルダウンロード
case 'download':
+ $objFormParam = new SC_FormParam();
+ $this->lfInitParamModeView($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
- // エラーチェック
- $arrErr = $this->lfErrorCheck();
- if (empty($arrErr)) {
- if(is_dir($_POST['select_file'])) {
- // ディレクトリの場合はjavascriptエラー
- $arrErr['select_file'] = "※ ディレクトリをダウンロードすることは出来ません。<br/>";
+ $this->arrErr = $objFormParam->checkError();
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ if(is_dir($objFormParam->getValue('select_file'))) {
+ $dispError = "※ ディレクトリをダウンロードすることは出来ません。<br/>";
+ $this->setDispError('select_file', $dispError);
} else {
// ファイルダウンロード
- $objFileManager->sfDownloadFile($_POST['select_file']);
+ $objFileManager->sfDownloadFile($objFormParam->getValue('select_file'));
exit;
}
}
break;
- // ファイル削除
+ // ファイル削除
case 'delete':
- // エラーチェック
- $arrErr = $this->lfErrorCheck();
- if (empty($arrErr)) {
- $objFileManager->sfDeleteDir($_POST['select_file']);
+ $objFormParam = new SC_FormParam();
+ $this->lfInitParamModeView($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
+
+ $this->arrErr = $objFormParam->checkError();
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ $objFileManager->sfDeleteDir($objFormParam->getValue('select_file'));
}
break;
- // ファイル作成
+ // ファイル作成
case 'create':
- // エラーチェック
- $arrErr = $this->lfCreateErrorCheck();
- if (empty($arrErr)) {
- $create_dir = ereg_replace("/$", "", $now_dir);
- // ファイル作成
- if(!$objFileManager->sfCreateFile($create_dir."/".$_POST['create_file'], 0755)) {
- // 作成エラー
- $arrErr['create_file'] = "※ ".$_POST['create_file']."の作成に失敗しました。<br/>";
+ $objFormParam = new SC_FormParam();
+ $this->lfInitParamModeCreate($objFormParam);
+ $objFormParam->setParam($this->createSetParam($_POST));
+ $objFormParam->convParam();
+
+ $this->arrErr = $objFormParam->checkError();
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ if(!$this->tryCreateDir($objFileManager, $objFormParam)){
+ $disp_error = "※ ".htmlspecialchars($objFormParam->getValue('create_file'), ENT_QUOTES)."の作成に失敗しました。<br/>";
+ $this->setDispError('create_file', $dispError);
} else {
- $this->tpl_onload .= "alert('フォルダを作成しました。');";
+ $tpl_onload = "alert('フォルダを作成しました。');";
+ $this->setTplOnLoad($tpl_onload);
}
}
break;
- // ファイルアップロード
+ // ファイルアップロード
case 'upload':
// 画像保存処理
$ret = $objUpFile->makeTempFile('upload_file', false);
- if($ret != "") {
- $arrErr['upload_file'] = $ret;
+ if (SC_Utils_Ex::isBlank($ret)) {
+ $tpl_onload = "alert('ファイルをアップロードしました。');";
+ $this->setTplOnLoad($tpl_onload);
} else {
- $this->tpl_onload .= "alert('ファイルをアップロードしました。');";
+ $this->setDispError('upload_file', $ret);
}
break;
- // フォルダ移動
- case 'move':
- $now_dir = $this->lfCheckSelectDir($_POST['tree_select_file']);
- break;
- // 初期表示
+ // 初期表示
default :
break;
}
- // トップディレクトリか調査
- $is_top_dir = false;
- // 末尾の/をとる
- $top_dir_check = ereg_replace("/$", "", $top_dir);
- $now_dir_check = ereg_replace("/$", "", $now_dir);
- if($top_dir_check == $now_dir_check) $is_top_dir = true;
- // 現在の階層より一つ上の階層を取得
- $parent_dir = $this->lfGetParentDir($now_dir);
-
+ // 値をテンプレートに渡す
+ $this->arrParam = $objFormParam->getHashArray();
+ // 現在の階層がルートディレクトリかどうかテンプレートに渡す
+ $this->setIsTopDir($objFormParam);
+ // 現在の階層より一つ上の階層をテンプレートに渡す
+ $this->setParentDir($objFormParam);
+ // 現在いる階層(表示用)をテンプレートに渡す
+ $this->setDispPath($objFormParam);
// 現在のディレクトリ配下のファイル一覧を取得
- $this->arrFileList = $objFileManager->sfGetFileList($now_dir);
- $this->tpl_is_top_dir = $is_top_dir;
- $this->tpl_parent_dir = $parent_dir;
- // TODO JSON で投げて, フロント側で処理した方が良い?
- $this->tpl_now_dir = "";
- $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $now_dir));
- for ($i = 0; $i < count($arrNowDir); $i++) {
- if (!empty($arrNowDir)) {
- $this->tpl_now_dir .= $arrNowDir[$i];
- if ($i < count($arrNowDir) - 1) {
- // フロント側で > へエスケープするため, ここでは > を使用
- $this->tpl_now_dir .= ' > ';
- }
- }
- }
- $this->tpl_now_file = basename($now_dir);
- $this->arrErr = isset($arrErr) ? $arrErr : "";
- $this->arrParam = $_POST;
-
- // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
- $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
- if (!empty($this->tpl_onload)) {
- $this->tpl_onload .= $treeView;
- } else {
- $this->tpl_onload = $treeView;
- }
-
- // ツリー配列作成用 javascript
- if (!isset($_POST['tree_status'])) $_POST['tree_status'] = "";
- $arrTree = $objFileManager->sfGetFileTree($top_dir, $_POST['tree_status']);
- $this->tpl_javascript .= "arrTree = new Array();\n";
- foreach($arrTree as $arrVal) {
- $this->tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
- if ($arrVal['open']) {
- $this->tpl_javascript .= "true);\n";
- } else {
- $this->tpl_javascript .= "false);\n";
- }
- }
+ $this->arrFileList = $objFileManager->sfGetFileList($objFormParam->getValue('now_dir'));
+ // 現在の階層のディレクトリをテンプレートに渡す
+ $this->setDispParam('tpl_now_file', $objFormParam->getValue('now_dir'));
+ // ディレクトリツリー表示
+ $this->setDispTree($objFileManager, $objFormParam);
}
/**
@@ -234,74 +208,289 @@
parent::destroy();
}
- /*
- * 関数名:lfErrorCheck()
- * 説明 :エラーチェック
+ /**
+ * 初期化を行う.
+ *
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return void
*/
- function lfErrorCheck() {
- $objErr = new SC_CheckError($_POST);
- $objErr->doFunc(array("ファイル", "select_file"), array("SELECT_CHECK"));
+ function lfInitParam(&$objFormParam) {
+ // 共通定義
+ $this->lfInitParamCommon($objFormParam);
+ }
- return $objErr->arrErr;
+ /**
+ * ディレクトリ移動時、パラメータ定義
+ *
+ * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+ * @return void
+ */
+ function lfInitParamModeMove(&$objFormParam) {
+ // 共通定義
+ $this->lfInitParamCommon($objFormParam);
+ $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array());
}
- /*
- * 関数名:lfCreateErrorCheck()
- * 説明 :ファイル作成処理エラーチェック
+ /**
+ * ファイル表示時、パラメータ定義
+ *
+ * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+ * @return void
*/
- function lfCreateErrorCheck() {
- $objErr = new SC_CheckError($_POST);
- $objErr->doFunc(array("作成ファイル名", "create_file"), array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD"));
+ function lfInitParamModeView(&$objFormParam) {
+ // 共通定義
+ $this->lfInitParamCommon($objFormParam);
+ $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array("SELECT_CHECK"));
+ }
- return $objErr->arrErr;
+ /**
+ * ファイル表示時、パラメータ定義
+ *
+ * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+ * @return void
+ */
+ function lfInitParamModeCreate(&$objFormParam) {
+ // 共通定義
+ $this->lfInitParamCommon($objFormParam);
+ $objFormParam->addParam("選択ファイル", "select_file", MTEXT_LEN, "a", array());
+ $objFormParam->addParam("作成ファイル名", "create_file", MTEXT_LEN, "a", array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD"));
}
+ /**
+ * ファイル表示時、パラメータ定義
+ *
+ * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+ * @return void
+ */
+ function lfInitParamCommon(&$objFormParam) {
+ $objFormParam->addParam("ルートディレクトリ", "top_dir", MTEXT_LEN, "a", array());
+ $objFormParam->addParam("現在の階層ディレクトリ", "now_dir", MTEXT_LEN, "a", array());
+ $objFormParam->addParam("現在の階層ファイル", "now_file", MTEXT_LEN, "a", array());
+ $objFormParam->addParam("ツリー選択状態", "tree_status", MTEXT_LEN, "a", array());
+ $objFormParam->addParam("ツリー選択ディレクトリ", "tree_select_file", MTEXT_LEN, "a", array());
+ }
+
+
/*
- * 関数名:lfInitFile()
- * 説明 :ファイル情報の初期化
+ * ファイル情報の初期化
+ *
+ * @param object $objUpFile SC_UploadFileインスタンス
+ * @return void
*/
function lfInitFile(&$objUpFile) {
$objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false);
}
+ /**
+ * テンプレートに渡す値を整形する
+ *
+ * @param array $_POST $_POST
+ * @return array $setParam テンプレートに渡す値
+ */
+ function createSetParam($_POST) {
+ $setParam = $_POST;
+ // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
+ $setParam['top_dir'] = (strpos(PHP_OS, 'WIN') === false) ? USER_REALDIR : str_replace('\\', '/', USER_REALDIR);
+ // 初期表示はルートディレクトリ(user_data/)を表示
+ if (SC_Utils_Ex::isBlank($this->getMode())) {
+ $setParam['now_dir'] = $setParam['top_dir'];
+ }
+ return $setParam;
+ }
+
+ /**
+ * テンプレートに値を渡す
+ *
+ * @param string $key キー名
+ * @param string $val 値
+ * @return void
+ */
+ function setDispParam($key, $val){
+ $this->$key = $val;
+ }
+
+ /**
+ * ディレクトリを作成
+ *
+ * @param object $objFileManager SC_Helper_FileManager_Exインスタンス
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return boolean ディレクトリ作成できたかどうか
+ */
+ function tryCreateDir($objFileManager, $objFormParam){
+ $create_dir_flg = false;
+ $create_dir = ereg_replace("/$", "", $objFormParam->getValue('now_dir'));
+ // ファイル作成
+ if($objFileManager->sfCreateFile($create_dir."/".$objFormParam->getValue('create_file'), 0755)) {
+ $create_dir_flg = true;
+ }
+ return $create_dir_flg;
+ }
+
+ /**
+ * ファイル表示を行う
+ *
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return boolean ファイル表示するかどうか
+ */
+ function tryView(&$objFormParam){
+ $view_flg = false;
+ $now_dir = $this->lfCheckSelectDir($objFormParam, dirname($objFormParam->getValue('select_file')));
+ $objFormParam->setValue('now_dir', $now_dir);
+ if (!strpos($objFormParam->getValue('select_file'), $objFormParam->getValue('top_dir'))) {
+ $view_flg = true;
+ }
+ return $view_flg;
+ }
+
+ /**
+ * 現在の階層の一つ上の階層のディレクトリをテンプレートに渡す
+ *
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return void
+ */
+ function setParentDir($objFormParam){
+ $parent_dir = $this->lfGetParentDir($objFormParam->getValue('now_dir'));
+ $this->setDispParam('tpl_parent_dir', $parent_dir);
+ }
+
+ /**
+ * 現在の階層のパスをテンプレートに渡す
+ *
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return void
+ */
+ function setDispPath($objFormParam){
+ // TODO JSON で投げて, フロント側で処理した方が良い?
+ $tpl_now_dir = "";
+ $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $objFormParam->getValue('now_dir')));
+ for ($i = 0; $i < count($arrNowDir); $i++) {
+ if (!empty($arrNowDir)) {
+ $tpl_now_dir .= $arrNowDir[$i];
+ if ($i < count($arrNowDir) - 1) {
+ // フロント側で > へエスケープするため, ここでは > を使用
+ $tpl_now_dir .= ' > ';
+ }
+ }
+ }
+ $this->setDispParam('tpl_now_dir', $tpl_now_dir);
+ }
+
+ /**
+ * エラーを表示用の配列に格納
+ *
+ * @param string $key キー名
+ * @param string $value エラー内容
+ * @return void
+ */
+ function setDispError($key, $value){
+ // 既にエラーがある場合は、処理しない
+ if (SC_Utils_Ex::isBlank($this->arrErr[$key])) {
+ $this->arrErr[$key] = $value;
+ }
+ }
+
+ /**
+ * javascriptをテンプレートに渡す
+ *
+ * @param string $tpl_onload javascript
+ * @return void
+ */
+ function setTplOnLoad($tpl_onload){
+ $this->tpl_onload .= $tpl_onload;
+ }
+
/*
- * 関数名:lfCheckSelectDir()
- * 引数1:ディレクトリ
- * 説明:選択ディレクトリがUSER_REALDIR以下かチェック
+ * 選択ディレクトリがUSER_REALDIR以下かチェック
+ *
+ * @param object $objFormParam SC_FormParamインスタンス
+ * @param string $dir ディレクトリ
+ * @return string $select_dir 選択ディレクトリ
*/
- function lfCheckSelectDir($dir) {
- $top_dir = USER_REALDIR;
+ function lfCheckSelectDir($objFormParam, $dir) {
+ $select_dir = '';
+ $top_dir = $objFormParam->getValue('top_dir');
// USER_REALDIR以下の場合
- if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) {
+ if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) {
// 相対パスがある場合、USER_REALDIRを返す.
if (preg_match("@\Q..\E@", $dir) > 0) {
- return $top_dir;
+ $select_dir = $top_dir;
// 相対パスがない場合、そのままディレクトリパスを返す.
} else {
- return $dir;
+ $select_dir= $dir;
}
// USER_REALDIR以下でない場合、USER_REALDIRを返す.
} else {
- return $top_dir;
+ $select_dir = $top_dir;
}
+ return $select_dir;
}
- /*
- * 関数名:lfGetParentDir()
- * 引数1 :ディレクトリ
- * 説明 :親ディレクトリ取得
+ /**
+ * 親ディレクトリ取得
+ *
+ * @param string $dir 現在いるディレクトリ
+ * @return string $parent_dir 親ディレクトリ
*/
function lfGetParentDir($dir) {
+ $parent_dir = "";
$dir = ereg_replace("/$", "", $dir);
$arrDir = split('/', $dir);
array_pop($arrDir);
- $parent_dir = "";
foreach($arrDir as $val) {
$parent_dir .= "$val/";
}
$parent_dir = ereg_replace("/$", "", $parent_dir);
-
return $parent_dir;
}
+
+ /**
+ * ディレクトリツリー生成
+ *
+ * @param object $objFileManager SC_Helper_FileManager_Exインスタンス
+ * @param SC_FormParam $objFormParam SC_FormParamインスタンス
+ * @return void
+ */
+ function setDispTree($objFileManager, $objFormParam){
+ $tpl_onload = '';
+ // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
+ $now_dir = $objFormParam->getValue('now_dir');
+ $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
+ if (!empty($this->tpl_onload)) {
+ $tpl_onload .= $treeView;
+ } else {
+ $tpl_onload = $treeView;
+ }
+ $this->setTplOnLoad($tpl_onload);
+
+ $tpl_javascript = '';
+ $arrTree = $objFileManager->sfGetFileTree($objFormParam->getValue('top_dir'), $objFormParam->getValue('tree_status'));
+ $tpl_javascript .= "arrTree = new Array();\n";
+ foreach($arrTree as $arrVal) {
+ $tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
+ if ($arrVal['open']) {
+ $tpl_javascript .= "true);\n";
+ } else {
+ $tpl_javascript .= "false);\n";
+ }
+ }
+ $this->setDispParam('tpl_javascript', $tpl_javascript);
+ }
+
+ /**
+ * 現在の階層がルートディレクトリかどうかテンプレートに渡す
+ *
+ * @param object $objFormParam SC_FormParamインスタンス
+ * @return void
+ */
+ function setIsTopDir($objFormParam){
+ // トップディレクトリか調査
+ $is_top_dir = false;
+ // 末尾の/をとる
+ $top_dir_check = ereg_replace("/$", "", $objFormParam->getValue('top_dir'));
+ $now_dir_check = ereg_replace("/$", "", $objFormParam->getValue('now_dir'));
+ if($top_dir_check == $now_dir_check) $is_top_dir = true;
+ $this->setDispParam('tpl_is_top_dir', $is_top_dir);
+ }
+
}
-?>
+?>
\ No newline at end of file
Svn-src-all メーリングリストの案内