Ignore:
Timestamp:
2012/04/17 17:43:10 (12 years ago)
Author:
shutta
Message:

#1612 不要な関数の削除
SC_UtilsとSC_Helper_FileManager間の重複している(もしくは同機能の)関数の整理。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/util/SC_Utils.php

    r21755 r21757  
    11501150    } 
    11511151 
    1152     // 指定したフォルダ内のファイルを全て削除する 
    1153     function sfDelFile($dir) { 
    1154         if (file_exists($dir)) { 
    1155             $dh = opendir($dir); 
    1156             // フォルダ内のファイルを削除 
    1157             while ($file = readdir($dh)) { 
    1158                 if ($file == '.' or $file == '..') continue; 
    1159                 $del_file = $dir . '/' . $file; 
    1160                 if (is_file($del_file)) { 
    1161                     $ret = unlink($dir . '/' . $file); 
    1162                 } else if (is_dir($del_file)) { 
    1163                     $ret = SC_Utils_Ex::sfDelFile($del_file); 
    1164                 } 
    1165  
    1166                 if (!$ret) { 
    1167                     return $ret; 
    1168                 } 
    1169             } 
    1170  
    1171             // 閉じる 
    1172             closedir($dh); 
    1173  
    1174             // フォルダを削除 
    1175             return rmdir($dir); 
    1176         } 
    1177     } 
    1178  
    11791152    /* 
    11801153     * 関数名:sfWriteFile 
     
    13091282        trigger_error('前方互換用メソッドが使用されました。', E_USER_WARNING); 
    13101283        GC_Utils_Ex::printXMLDeclaration(); 
    1311     } 
    1312  
    1313     /* 
    1314      * 関数名:sfGetFileList() 
    1315      * 説明 :指定パス配下のディレクトリ取得 
    1316      * 引数1 :取得するディレクトリパス 
    1317      */ 
    1318     function sfGetFileList($dir) { 
    1319         $arrFileList = array(); 
    1320         $arrDirList = array(); 
    1321  
    1322         if (is_dir($dir)) { 
    1323             if ($dh = opendir($dir)) { 
    1324                 $cnt = 0; 
    1325                 // 行末の/を取り除く 
    1326                 while (($file = readdir($dh)) !== false) $arrDir[] = $file; 
    1327                 $dir = rtrim($dir, '/'); 
    1328                 // アルファベットと数字でソート 
    1329                 natcasesort($arrDir); 
    1330                 foreach ($arrDir as $file) { 
    1331                     // ./ と ../を除くファイルのみを取得 
    1332                     if ($file != '.' && $file != '..') { 
    1333  
    1334                         $path = $dir.'/'.$file; 
    1335                         // SELECT内の見た目を整えるため指定文字数で切る 
    1336                         $file_name = SC_Utils_Ex::sfCutString($file, FILE_NAME_LEN); 
    1337                         $file_size = SC_Utils_Ex::sfCutString(SC_Utils_Ex::sfGetDirSize($path), FILE_NAME_LEN); 
    1338                         $file_time = date('Y/m/d', filemtime($path)); 
    1339  
    1340                         // ディレクトリとファイルで格納配列を変える 
    1341                         if (is_dir($path)) { 
    1342                             $arrDirList[$cnt]['file_name'] = $file; 
    1343                             $arrDirList[$cnt]['file_path'] = $path; 
    1344                             $arrDirList[$cnt]['file_size'] = $file_size; 
    1345                             $arrDirList[$cnt]['file_time'] = $file_time; 
    1346                             $arrDirList[$cnt]['is_dir'] = true; 
    1347                         } else { 
    1348                             $arrFileList[$cnt]['file_name'] = $file; 
    1349                             $arrFileList[$cnt]['file_path'] = $path; 
    1350                             $arrFileList[$cnt]['file_size'] = $file_size; 
    1351                             $arrFileList[$cnt]['file_time'] = $file_time; 
    1352                             $arrFileList[$cnt]['is_dir'] = false; 
    1353                         } 
    1354                         $cnt++; 
    1355                     } 
    1356                 } 
    1357                 closedir($dh); 
    1358             } 
    1359         } 
    1360  
    1361         // フォルダを先頭にしてマージ 
    1362         return array_merge($arrDirList, $arrFileList); 
    1363     } 
    1364  
    1365     /* 
    1366      * 関数名:sfGetDirSize() 
    1367      * 説明 :指定したディレクトリのバイト数を取得 
    1368      * 引数1 :ディレクトリ 
    1369      */ 
    1370     function sfGetDirSize($dir) { 
    1371         if (file_exists($dir)) { 
    1372             // ディレクトリの場合下層ファイルの総量を取得 
    1373             if (is_dir($dir)) { 
    1374                 $handle = opendir($dir); 
    1375                 while ($file = readdir($handle)) { 
    1376                     // 行末の/を取り除く 
    1377                     $dir = rtrim($dir, '/'); 
    1378                     $path = $dir.'/'.$file; 
    1379                     if ($file != '..' && $file != '.' && !is_dir($path)) { 
    1380                         $bytes += filesize($path); 
    1381                     } else if (is_dir($path) && $file != '..' && $file != '.') { 
    1382                         // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。 
    1383                         $bytes += SC_Utils_Ex::sfGetDirSize($path); 
    1384                     } 
    1385                 } 
    1386             } else { 
    1387                 // ファイルの場合 
    1388                 $bytes = filesize($dir); 
    1389             } 
    1390         } 
    1391         // ディレクトリ(ファイル)が存在しない場合は0byteを返す 
    1392         if ($bytes == '') { 
    1393             $bytes = 0; 
    1394         } 
    1395  
    1396         return $bytes; 
    1397     } 
    1398  
    1399     /* 
    1400      * 関数名:sfGetFileTree() 
    1401      * 説明 :ツリー生成用配列取得(javascriptに渡す用) 
    1402      * 引数1 :ディレクトリ 
    1403      * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
    1404      */ 
    1405     function sfGetFileTree($dir, $tree_status) { 
    1406  
    1407         $cnt = 0; 
    1408         $arrTree = array(); 
    1409         $default_rank = count(explode('/', $dir)); 
    1410  
    1411         // 文末の/を取り除く 
    1412         $dir = rtrim($dir, '/'); 
    1413         // 最上位層を格納(user_data/) 
    1414         if (sfDirChildExists($dir)) { 
    1415             $arrTree[$cnt]['type'] = '_parent'; 
    1416         } else { 
    1417             $arrTree[$cnt]['type'] = '_child'; 
    1418         } 
    1419         $arrTree[$cnt]['path'] = $dir; 
    1420         $arrTree[$cnt]['rank'] = 0; 
    1421         $arrTree[$cnt]['count'] = $cnt; 
    1422         // 初期表示はオープン 
    1423         if ($_POST['mode'] != '') { 
    1424             $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status); 
    1425         } else { 
    1426             $arrTree[$cnt]['open'] = true; 
    1427         } 
    1428         $cnt++; 
    1429  
    1430         sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status); 
    1431  
    1432         return $arrTree; 
    1433     } 
    1434  
    1435     /* 
    1436      * 関数名:sfGetFileTree() 
    1437      * 説明 :ツリー生成用配列取得(javascriptに渡す用) 
    1438      * 引数1 :ディレクトリ 
    1439      * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント) 
    1440      * 引数3 :連番 
    1441      * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
    1442      */ 
    1443     function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) { 
    1444  
    1445         if (file_exists($dir)) { 
    1446             if ($handle = opendir("$dir")) { 
    1447                 while (false !== ($item = readdir($handle))) $arrDir[] = $item; 
    1448                 // アルファベットと数字でソート 
    1449                 natcasesort($arrDir); 
    1450                 foreach ($arrDir as $item) { 
    1451                     if ($item != '.' && $item != '..') { 
    1452                         // 文末の/を取り除く 
    1453                         $dir = rtrim($dir, '/'); 
    1454                         $path = $dir.'/'.$item; 
    1455                         // ディレクトリのみ取得 
    1456                         if (is_dir($path)) { 
    1457                             $arrTree[$cnt]['path'] = $path; 
    1458                             if (sfDirChildExists($path)) { 
    1459                                 $arrTree[$cnt]['type'] = '_parent'; 
    1460                             } else { 
    1461                                 $arrTree[$cnt]['type'] = '_child'; 
    1462                             } 
    1463  
    1464                             // 階層を割り出す 
    1465                             $arrCnt = explode('/', $path); 
    1466                             $rank = count($arrCnt); 
    1467                             $arrTree[$cnt]['rank'] = $rank - $default_rank + 1; 
    1468                             $arrTree[$cnt]['count'] = $cnt; 
    1469                             // フォルダが開いているか 
    1470                             $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status); 
    1471                             $cnt++; 
    1472                             // 下層ディレクトリ取得の為、再帰的に呼び出す 
    1473                             sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status); 
    1474                         } 
    1475                     } 
    1476                 } 
    1477             } 
    1478             closedir($handle); 
    1479         } 
    1480     } 
    1481  
    1482     /* 
    1483      * 関数名:sfDirChildExists() 
    1484      * 説明 :指定したディレクトリ配下にファイルがあるか 
    1485      * 引数1 :ディレクトリ 
    1486      */ 
    1487     function sfDirChildExists($dir) { 
    1488         if (file_exists($dir)) { 
    1489             if (is_dir($dir)) { 
    1490                 $handle = opendir($dir); 
    1491                 while ($file = readdir($handle)) { 
    1492                     // 行末の/を取り除く 
    1493                     $dir = rtrim($dir, '/'); 
    1494                     $path = $dir.'/'.$file; 
    1495                     if ($file != '..' && $file != '.' && is_dir($path)) { 
    1496                         return true; 
    1497                     } 
    1498                 } 
    1499             } 
    1500         } 
    1501  
    1502         return false; 
    1503     } 
    1504  
    1505     /* 
    1506      * 関数名:lfIsFileOpen() 
    1507      * 説明 :指定したファイルが前回開かれた状態にあったかチェック 
    1508      * 引数1 :ディレクトリ 
    1509      * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
    1510      */ 
    1511     function lfIsFileOpen($dir, $tree_status) { 
    1512         $arrTreeStatus = explode('\|', $tree_status); 
    1513         if (in_array($dir, $arrTreeStatus)) { 
    1514             return true; 
    1515         } 
    1516  
    1517         return false; 
    1518     } 
    1519  
    1520     /* 
    1521      * 関数名:sfDownloadFile() 
    1522      * 引数1 :ファイルパス 
    1523      * 説明 :ファイルのダウンロード 
    1524      */ 
    1525     function sfDownloadFile($file) { 
    1526         // ファイルの場合はダウンロードさせる 
    1527         Header('Content-disposition: attachment; filename='.basename($file)); 
    1528         Header('Content-type: application/octet-stream; name='.basename($file)); 
    1529         Header('Cache-Control: '); 
    1530         Header('Pragma: '); 
    1531         echo (sfReadFile($file)); 
    1532     } 
    1533  
    1534     /* 
    1535      * 関数名:sfCreateFile() 
    1536      * 引数1 :ファイルパス 
    1537      * 引数2 :パーミッション 
    1538      * 説明 :ファイル作成 
    1539      */ 
    1540     function sfCreateFile($file, $mode = '') { 
    1541         // 行末の/を取り除く 
    1542         if ($mode != '') { 
    1543             $ret = @mkdir($file, $mode); 
    1544         } else { 
    1545             $ret = @mkdir($file); 
    1546         } 
    1547  
    1548         return $ret; 
    1549     } 
    1550  
    1551     /* 
    1552      * 関数名:sfReadFile() 
    1553      * 引数1 :ファイルパス 
    1554      * 説明 :ファイル読込 
    1555      */ 
    1556     function sfReadFile($filename) { 
    1557         $str = ''; 
    1558         // バイナリモードでオープン 
    1559         $fp = @fopen($filename, 'rb'); 
    1560         //ファイル内容を全て変数に読み込む 
    1561         if ($fp) { 
    1562             $str = @fread($fp, filesize($filename)+1); 
    1563         } 
    1564         @fclose($fp); 
    1565  
    1566         return $str; 
    15671284    } 
    15681285 
     
    19911708    } 
    19921709 
    1993     /** 
    1994      * 指定されたパスの配下を再帰的に削除. 
    1995      * 
    1996      * @param string  $path       削除対象のディレクトリまたはファイルのパス 
    1997      * @param boolean $del_myself $pathそのものを削除するか. true なら削除する. 
    1998      * @return void 
    1999      */ 
    2000     function deleteFile($path, $del_myself = true) { 
    2001         $flg = false; 
    2002         // 対象が存在するかを検証. 
    2003         if (file_exists($path) === false) { 
    2004             GC_Utils_Ex::gfPrintLog($path . ' が存在しません.'); 
    2005         } elseif (is_dir($path)) { 
    2006             // ディレクトリが指定された場合 
    2007             $handle = opendir($path); 
    2008             if (!$handle) { 
    2009                 GC_Utils_Ex::gfPrintLog($path . ' が開けませんでした.'); 
    2010             } 
    2011             while (($item = readdir($handle)) !== false) { 
    2012                 if ($item === '.' || $item === '..') continue; 
    2013                 $cur_path = $path . '/' . $item; 
    2014                 if (is_dir($cur_path)) { 
    2015                     // ディレクトリの場合、再帰処理 
    2016                     $flg = SC_Utils_Ex::deleteFile($cur_path); 
    2017                 } else { 
    2018                     // ファイルの場合、unlink 
    2019                     $flg = @unlink($cur_path); 
    2020                 } 
    2021             } 
    2022             closedir($handle); 
    2023             // ディレクトリを削除 
    2024             GC_Utils_Ex::gfPrintLog($path . ' を削除します.'); 
    2025             if ($del_myself) { 
    2026                 $flg = @rmdir($path); 
    2027             } 
    2028         } else { 
    2029             // ファイルが指定された場合. 
    2030             GC_Utils_Ex::gfPrintLog($path . ' を削除します.'); 
    2031             $flg = @unlink($path); 
    2032         } 
    2033         return $flg; 
    2034     } 
    2035  
    20361710   /** 
    20371711     * コンパイルファイルを削除します. 
     
    20401714    function clearCompliedTemplate() { 
    20411715        // コンパイルファイルの削除処理 
    2042         SC_Utils_Ex::deleteFile(COMPILE_REALDIR, false); 
    2043         SC_Utils_Ex::deleteFile(COMPILE_ADMIN_REALDIR, false); 
    2044         SC_Utils_Ex::deleteFile(SMARTPHONE_COMPILE_REALDIR, false); 
    2045         SC_Utils_Ex::deleteFile(MOBILE_COMPILE_REALDIR, false); 
     1716        SC_Helper_FileManager_Ex::deleteFile(COMPILE_REALDIR, false); 
     1717        SC_Helper_FileManager_Ex::deleteFile(COMPILE_ADMIN_REALDIR, false); 
     1718        SC_Helper_FileManager_Ex::deleteFile(SMARTPHONE_COMPILE_REALDIR, false); 
     1719        SC_Helper_FileManager_Ex::deleteFile(MOBILE_COMPILE_REALDIR, false); 
    20461720    } 
    20471721 
Note: See TracChangeset for help on using the changeset viewer.