Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_Contents_FileManager.php

Documentation is available at LC_Page_Admin_Contents_FileManager.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 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. // {{{ requires
  25. require_once CLASS_EX_REALDIR 'page_extends/admin/LC_Page_Admin_Ex.php';
  26. require_once CLASS_EX_REALDIR 'helper_extends/SC_Helper_FileManager_Ex.php';
  27.  
  28. /**
  29.  * ファイル管理 のページクラス.
  30.  *
  31.  * @package Page
  32.  * @author LOCKON CO.,LTD.
  33.  * @version $Id: LC_Page_Admin_Contents_FileManager.php 20970 2011-06-10 10:27:24Z Seasoft $
  34.  */
  35. class LC_Page_Admin_Contents_FileManager extends LC_Page_Admin_Ex {
  36.  
  37.     // }}}
  38.     // {{{ functions
  39.  
  40.     /**
  41.      * Page を初期化する.
  42.      *
  43.      * @return void 
  44.      */
  45.     function init({
  46.         parent::init();
  47.         $this->tpl_mainpage 'contents/file_manager.tpl';
  48.         $this->tpl_mainno 'contents';
  49.         $this->tpl_subno 'file';
  50.         $this->tpl_maintitle 'コンテンツ管理';
  51.         $this->tpl_subtitle 'ファイル管理';
  52.  
  53.     }
  54.  
  55.     /**
  56.      * Page のプロセス.
  57.      *
  58.      * @return void 
  59.      */
  60.     function process({
  61.         $this->action();
  62.         $this->sendResponse();
  63.     }
  64.  
  65.     /**
  66.      * Page のアクション.
  67.      *
  68.      * @return void 
  69.      */
  70.     function action({
  71.         // フォーム操作クラス
  72.         $objFormParam new SC_FormParam_Ex();
  73.         // パラメーター情報の初期化
  74.         $this->lfInitParam($objFormParam);
  75.         $objFormParam->setParam($this->createSetParam($_POST));
  76.         $objFormParam->convParam();
  77.  
  78.         // ファイル管理クラス
  79.         $objUpFile new SC_UploadFile_Ex($objFormParam->getValue('now_dir')$objFormParam->getValue('now_dir'));
  80.         // ファイル情報の初期化
  81.         $this->lfInitFile($objUpFile);
  82.  
  83.         // ファイル操作クラス
  84.         $objFileManager new SC_Helper_FileManager_Ex();
  85.  
  86.         switch($this->getMode()) {
  87.         // フォルダ移動
  88.         case 'move':
  89.             $objFormParam new SC_FormParam_Ex();
  90.             $this->lfInitParamModeMove($objFormParam);
  91.             $objFormParam->setParam($this->createSetParam($_POST));
  92.             $objFormParam->convParam();
  93.  
  94.             $this->arrErr $objFormParam->checkError();
  95.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  96.                 $now_dir $this->lfCheckSelectDir($objFormParam$objFormParam->getValue('tree_select_file'));
  97.                 $objFormParam->setValue('now_dir'$now_dir);
  98.             }
  99.             break;
  100.  
  101.         // ファイル表示
  102.         case 'view':
  103.             $objFormParam new SC_FormParam_Ex();
  104.             $this->lfInitParamModeView($objFormParam);
  105.             $objFormParam->setParam($this->createSetParam($_POST));
  106.             $objFormParam->convParam();
  107.  
  108.             $this->arrErr $objFormParam->checkError();
  109.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  110.                 if($this->tryView($objFormParam)){
  111.                     $file_url htmlspecialchars(ereg_replace($objFormParam->getValue('top_dir')""$objFormParam->getValue('select_file')));
  112.                     $tpl_onload "win02('./file_view.php?file="$file_url ."', 'user_data', '600', '400');";
  113.                     $this->setTplOnLoad($tpl_onload);
  114.                 }
  115.             }
  116.             break;
  117.  
  118.         // ファイルダウンロード
  119.         case 'download':
  120.             $objFormParam new SC_FormParam_Ex();
  121.             $this->lfInitParamModeView($objFormParam);
  122.             $objFormParam->setParam($this->createSetParam($_POST));
  123.             $objFormParam->convParam();
  124.  
  125.             $this->arrErr $objFormParam->checkError();
  126.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  127.                 if(is_dir($objFormParam->getValue('select_file'))) {
  128.                     $disp_error "※ ディレクトリをダウンロードすることは出来ません。<br/>";
  129.                     $this->setDispError('select_file'$disp_error);
  130.                 else {
  131.                     // ファイルダウンロード
  132.                     $objFileManager->sfDownloadFile($objFormParam->getValue('select_file'));
  133.                     exit;
  134.                 }
  135.             }
  136.             break;
  137.         // ファイル削除
  138.         case 'delete':
  139.             $objFormParam new SC_FormParam_Ex();
  140.             $this->lfInitParamModeView($objFormParam);
  141.             $objFormParam->setParam($this->createSetParam($_POST));
  142.             $objFormParam->convParam();
  143.  
  144.             $this->arrErr $objFormParam->checkError();
  145.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  146.                 $objFileManager->sfDeleteDir($objFormParam->getValue('select_file'));
  147.             }
  148.             break;
  149.         // ファイル作成
  150.         case 'create':
  151.             $objFormParam new SC_FormParam_Ex();
  152.             $this->lfInitParamModeCreate($objFormParam);
  153.             $objFormParam->setParam($this->createSetParam($_POST));
  154.             $objFormParam->convParam();
  155.  
  156.             $this->arrErr $objFormParam->checkError();
  157.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  158.                 if(!$this->tryCreateDir($objFileManager$objFormParam)){
  159.                     $disp_error "※ ".htmlspecialchars($objFormParam->getValue('create_file')ENT_QUOTES)."の作成に失敗しました。<br/>";
  160.                     $this->setDispError('create_file'$disp_error);
  161.                 else {
  162.                     $tpl_onload "alert('フォルダを作成しました。');";
  163.                     $this->setTplOnLoad($tpl_onload);
  164.                 }
  165.             }
  166.             break;
  167.         // ファイルアップロード
  168.         case 'upload':
  169.             // 画像保存処理
  170.             $ret $objUpFile->makeTempFile('upload_file'false);
  171.             if (SC_Utils_Ex::isBlank($ret)) {
  172.                 $tpl_onload "alert('ファイルをアップロードしました。');";
  173.                 $this->setTplOnLoad($tpl_onload);
  174.             else {
  175.                 $this->setDispError('upload_file'$ret);
  176.             }
  177.             break;
  178.         // 初期表示
  179.         default :
  180.             break;
  181.         }
  182.  
  183.         // 値をテンプレートに渡す
  184.         $this->arrParam $objFormParam->getHashArray();
  185.         // 現在の階層がルートディレクトリかどうかテンプレートに渡す
  186.         $this->setIsTopDir($objFormParam);
  187.         // 現在の階層より一つ上の階層をテンプレートに渡す
  188.         $this->setParentDir($objFormParam);
  189.         // 現在いる階層(表示用)をテンプレートに渡す
  190.         $this->setDispPath($objFormParam);
  191.         // 現在のディレクトリ配下のファイル一覧を取得
  192.         $this->arrFileList $objFileManager->sfGetFileList($objFormParam->getValue('now_dir'));
  193.         // 現在の階層のディレクトリをテンプレートに渡す
  194.         $this->setDispParam('tpl_now_file'$objFormParam->getValue('now_dir'));
  195.         // ディレクトリツリー表示
  196.         $this->setDispTree($objFileManager$objFormParam);
  197.     }
  198.  
  199.     /**
  200.      * デストラクタ.
  201.      *
  202.      * @return void 
  203.      */
  204.     function destroy({
  205.         parent::destroy();
  206.     }
  207.  
  208.     /**
  209.      * 初期化を行う.
  210.      *
  211.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  212.      * @return void 
  213.      */
  214.     function lfInitParam(&$objFormParam{
  215.         // 共通定義
  216.         $this->lfInitParamCommon($objFormParam);
  217.     }
  218.  
  219.     /**
  220.      * ディレクトリ移動時、パラメーター定義
  221.      *
  222.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  223.      * @return void 
  224.      */
  225.     function lfInitParamModeMove(&$objFormParam{
  226.         // 共通定義
  227.         $this->lfInitParamCommon($objFormParam);
  228.         $objFormParam->addParam("選択ファイル""select_file"MTEXT_LEN'a'array());
  229.     }
  230.  
  231.     /**
  232.      * ファイル表示時、パラメーター定義
  233.      *
  234.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  235.      * @return void 
  236.      */
  237.     function lfInitParamModeView(&$objFormParam{
  238.         // 共通定義
  239.         $this->lfInitParamCommon($objFormParam);
  240.         $objFormParam->addParam("選択ファイル""select_file"MTEXT_LEN'a'array("SELECT_CHECK"));
  241.     }
  242.  
  243.     /**
  244.      * ファイル表示時、パラメーター定義
  245.      *
  246.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  247.      * @return void 
  248.      */
  249.     function lfInitParamModeCreate(&$objFormParam{
  250.         // 共通定義
  251.         $this->lfInitParamCommon($objFormParam);
  252.         $objFormParam->addParam("選択ファイル""select_file"MTEXT_LEN'a'array());
  253.         $objFormParam->addParam("作成ファイル名""create_file"MTEXT_LEN'a'array("EXIST_CHECK""FILE_NAME_CHECK_BY_NOUPLOAD"));
  254.     }
  255.  
  256.     /**
  257.      * ファイル表示時、パラメーター定義
  258.      *
  259.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  260.      * @return void 
  261.      */
  262.     function lfInitParamCommon(&$objFormParam{
  263.         $objFormParam->addParam("ルートディレクトリ""top_dir"MTEXT_LEN'a'array());
  264.         $objFormParam->addParam("現在の階層ディレクトリ""now_dir"MTEXT_LEN'a'array());
  265.         $objFormParam->addParam("現在の階層ファイル""now_file"MTEXT_LEN'a'array());
  266.         $objFormParam->addParam("ツリー選択状態""tree_status"MTEXT_LEN'a'array());
  267.         $objFormParam->addParam("ツリー選択ディレクトリ""tree_select_file"MTEXT_LEN'a'array());
  268.     }
  269.  
  270.     /*
  271.      * ファイル情報の初期化
  272.      *
  273.      * @param object $objUpFile SC_UploadFileインスタンス
  274.      * @return void
  275.      */
  276.     function lfInitFile(&$objUpFile{
  277.         $objUpFile->addFile("ファイル"'upload_file'array()FILE_SIZEtrue00false);
  278.     }
  279.  
  280.     /**
  281.      * テンプレートに渡す値を整形する
  282.      *
  283.      * @param array $_POST $_POST
  284.      * @return array $setParam テンプレートに渡す値
  285.      */
  286.     function createSetParam($_POST{
  287.         $setParam $_POST;
  288.         // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
  289.         $setParam['top_dir'(strpos(PHP_OS'WIN'=== falseUSER_REALDIR str_replace('\\''/'USER_REALDIR);
  290.         // 初期表示はルートディレクトリ(user_data/)を表示
  291.         if (SC_Utils_Ex::isBlank($this->getMode())) {
  292.             $setParam['now_dir'$setParam['top_dir'];
  293.         }
  294.         return $setParam;
  295.     }
  296.  
  297.     /**
  298.      * テンプレートに値を渡す
  299.      * 
  300.      * @param string $key キー名
  301.      * @param string $val 
  302.      * @return void 
  303.      */
  304.     function setDispParam($key$val){
  305.         $this->$key $val;
  306.     }
  307.  
  308.     /**
  309.      * ディレクトリを作成
  310.      *
  311.      * @param object $objFileManager SC_Helper_FileManager_Exインスタンス
  312.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  313.      * @return boolean ディレクトリ作成できたかどうか
  314.      */
  315.     function tryCreateDir($objFileManager$objFormParam){
  316.         $create_dir_flg false;
  317.         $create_dir ereg_replace("/$"""$objFormParam->getValue('now_dir'));
  318.         // ファイル作成
  319.         if($objFileManager->sfCreateFile($create_dir."/".$objFormParam->getValue('create_file')0755)) {
  320.             $create_dir_flg true;
  321.         }
  322.         return $create_dir_flg;
  323.     }
  324.  
  325.     /**
  326.      * ファイル表示を行う
  327.      *
  328.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  329.      * @return boolean ファイル表示するかどうか
  330.      */
  331.     function tryView(&$objFormParam){
  332.         $view_flg false;
  333.         $now_dir $this->lfCheckSelectDir($objFormParamdirname($objFormParam->getValue('select_file')));
  334.         $objFormParam->setValue('now_dir'$now_dir);
  335.         if (!strpos($objFormParam->getValue('select_file')$objFormParam->getValue('top_dir'))) {
  336.             $view_flg true;
  337.         }
  338.         return $view_flg;
  339.     }
  340.  
  341.     /**
  342.      * 現在の階層の一つ上の階層のディレクトリをテンプレートに渡す
  343.      *
  344.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  345.      * @return void 
  346.      */
  347.     function setParentDir($objFormParam){
  348.         $parent_dir $this->lfGetParentDir($objFormParam->getValue('now_dir'));
  349.         $this->setDispParam('tpl_parent_dir'$parent_dir);
  350.     }
  351.  
  352.     /**
  353.      * 現在の階層のパスをテンプレートに渡す
  354.      *
  355.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  356.      * @return void 
  357.      */
  358.     function setDispPath($objFormParam){
  359.         $tpl_now_dir "";
  360.         // Windows 環境で DIRECTORY_SEPARATOR が JavaScript に渡るとエスケープ文字と勘違いするので置換
  361.         $html_realdir str_replace(DIRECTORY_SEPARATOR'/'HTML_REALDIR);
  362.         $arrNowDir preg_split('/\//'str_replace($html_realdir''$objFormParam->getValue('now_dir')));
  363.         $this->setDispParam('tpl_now_dir'SC_Utils_Ex::jsonEncode($arrNowDir));
  364.         $this->setDispParam('tpl_file_path'$html_realdir);
  365.     }
  366.  
  367.     /**
  368.      * エラーを表示用の配列に格納
  369.      *
  370.      * @param string $key キー名
  371.      * @param string $value エラー内容
  372.      * @return void 
  373.      */
  374.     function setDispError($key$value){
  375.         // 既にエラーがある場合は、処理しない
  376.         if (SC_Utils_Ex::isBlank($this->arrErr[$key])) {
  377.             $this->arrErr[$key$value;
  378.         }
  379.     }
  380.  
  381.     /**
  382.      * javascriptをテンプレートに渡す
  383.      * 
  384.      * @param string $tpl_onload javascript
  385.      * @return void 
  386.      */
  387.     function setTplOnLoad($tpl_onload){
  388.         $this->tpl_onload .= $tpl_onload;
  389.     }
  390.  
  391.     /*
  392.      * 選択ディレクトリがUSER_REALDIR以下かチェック
  393.      *
  394.      * @param object $objFormParam SC_FormParamインスタンス
  395.      * @param string $dir ディレクトリ
  396.      * @return string $select_dir 選択ディレクトリ
  397.      */
  398.     function lfCheckSelectDir($objFormParam$dir{
  399.         $select_dir '';
  400.         $top_dir $objFormParam->getValue('top_dir');
  401.         // USER_REALDIR以下の場合
  402.         if (preg_match("@^\Q"$top_dir"\E@"$dir0{
  403.             // 相対パスがある場合、USER_REALDIRを返す.
  404.             if (preg_match("@\Q..\E@"$dir0{
  405.                 $select_dir $top_dir;
  406.             // 相対パスがない場合、そのままディレクトリパスを返す.
  407.             else {
  408.                 $select_dir$dir;
  409.             }
  410.         // USER_REALDIR以下でない場合、USER_REALDIRを返す.
  411.         else {
  412.             $select_dir $top_dir;
  413.         }
  414.         return $select_dir;
  415.     }
  416.  
  417.     /**
  418.      * 親ディレクトリ取得
  419.      * 
  420.      * @param string $dir 現在いるディレクトリ
  421.      * @return string $parent_dir 親ディレクトリ
  422.      */
  423.     function lfGetParentDir($dir{
  424.         $parent_dir "";
  425.         $dir ereg_replace("/$"""$dir);
  426.         $arrDir explode('/'$dir);
  427.         array_pop($arrDir);
  428.         foreach($arrDir as $val{
  429.             $parent_dir .= "$val/";
  430.         }
  431.         $parent_dir ereg_replace("/$"""$parent_dir);
  432.         return $parent_dir;
  433.     }
  434.  
  435.     /**
  436.      * ディレクトリツリー生成
  437.      *
  438.      * @param object $objFileManager SC_Helper_FileManager_Exインスタンス
  439.      * @param SC_FormParam $objFormParam SC_FormParamインスタンス
  440.      * @return void 
  441.      */
  442.     function setDispTree($objFileManager$objFormParam){
  443.         $tpl_onload '';
  444.         // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
  445.         $now_dir $objFormParam->getValue('now_dir');
  446.         $treeView "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
  447.         if (!empty($this->tpl_onload)) {
  448.             $tpl_onload .= $treeView;
  449.         else {
  450.             $tpl_onload $treeView;
  451.         }
  452.         $this->setTplOnLoad($tpl_onload);
  453.  
  454.         $tpl_javascript '';
  455.         $arrTree $objFileManager->sfGetFileTree($objFormParam->getValue('top_dir')$objFormParam->getValue('tree_status'));
  456.         $tpl_javascript .= "arrTree = new Array();\n";
  457.         foreach($arrTree as $arrVal{
  458.             $tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
  459.             if ($arrVal['open']{
  460.                 $tpl_javascript .= "true);\n";
  461.             else {
  462.                 $tpl_javascript .= "false);\n";
  463.             }
  464.         }
  465.         $this->setDispParam('tpl_javascript'$tpl_javascript);
  466.     }
  467.  
  468.     /**
  469.      * 現在の階層がルートディレクトリかどうかテンプレートに渡す
  470.      *
  471.      * @param object $objFormParam SC_FormParamインスタンス
  472.      * @return void 
  473.      */
  474.     function setIsTopDir($objFormParam){
  475.         // トップディレクトリか調査
  476.         $is_top_dir false;
  477.         // 末尾の/をとる
  478.         $top_dir_check ereg_replace("/$"""$objFormParam->getValue('top_dir'));
  479.         $now_dir_check ereg_replace("/$"""$objFormParam->getValue('now_dir'));
  480.         if($top_dir_check == $now_dir_check$is_top_dir true;
  481.         $this->setDispParam('tpl_is_top_dir'$is_top_dir);
  482.     }
  483.  
  484. }
  485. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:10 +0900 by Seasoft