Ignore:
Timestamp:
2007/11/04 22:03:55 (19 years ago)
Author:
naka
Message:

テンプレート管理の修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/util/SC_Utils.php

    r16675 r16677  
    16371637        } 
    16381638    } 
    1639  
     1639     
     1640    /*  
     1641     * 関数名:sfGetFileList() 
     1642     * 説明 :指定パス配下のディレクトリ取得 
     1643     * 引数1 :取得するディレクトリパス 
     1644     */ 
     1645    function sfGetFileList($dir) { 
     1646        $arrFileList = array(); 
     1647        $arrDirList = array(); 
     1648         
     1649        if (is_dir($dir)) { 
     1650            if ($dh = opendir($dir)) {  
     1651                $cnt = 0; 
     1652                // 行末の/を取り除く 
     1653                while (($file = readdir($dh)) !== false) $arrDir[] = $file; 
     1654                $dir = ereg_replace("/$", "", $dir); 
     1655                // アルファベットと数字でソート 
     1656                natcasesort($arrDir); 
     1657                foreach($arrDir as $file) {              
     1658                    // ./ と ../を除くファイルのみを取得 
     1659                    if($file != "." && $file != "..") { 
     1660     
     1661                        $path = $dir."/".$file; 
     1662                        // SELECT内の見た目を整えるため指定文字数で切る 
     1663                        $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN);                        
     1664                        $file_size = SC_Utils::sfCutString(SC_Utils::sfGetDirSize($path), FILE_NAME_LEN); 
     1665                        $file_time = date("Y/m/d", filemtime($path)); 
     1666                         
     1667                        // ディレクトリとファイルで格納配列を変える 
     1668                        if(is_dir($path)) { 
     1669                            $arrDirList[$cnt]['file_name'] = $file; 
     1670                            $arrDirList[$cnt]['file_path'] = $path; 
     1671                            $arrDirList[$cnt]['file_size'] = $file_size; 
     1672                            $arrDirList[$cnt]['file_time'] = $file_time;  
     1673                            $arrDirList[$cnt]['is_dir'] = true; 
     1674                        } else { 
     1675                            $arrFileList[$cnt]['file_name'] = $file; 
     1676                            $arrFileList[$cnt]['file_path'] = $path; 
     1677                            $arrFileList[$cnt]['file_size'] = $file_size; 
     1678                            $arrFileList[$cnt]['file_time'] = $file_time;  
     1679                            $arrFileList[$cnt]['is_dir'] = false; 
     1680                        } 
     1681                        $cnt++; 
     1682                    } 
     1683                } 
     1684                closedir($dh);  
     1685            } 
     1686        } 
     1687     
     1688        // フォルダを先頭にしてマージ 
     1689        return array_merge($arrDirList, $arrFileList); 
     1690    } 
     1691     
     1692    /*  
     1693     * 関数名:sfGetDirSize() 
     1694     * 説明 :指定したディレクトリのバイト数を取得 
     1695     * 引数1 :ディレクトリ 
     1696     */ 
     1697    function sfGetDirSize($dir) { 
     1698        if(file_exists($dir)) { 
     1699            // ディレクトリの場合下層ファイルの総量を取得 
     1700            if (is_dir($dir)) { 
     1701                $handle = opendir($dir);  
     1702                while ($file = readdir($handle)) { 
     1703                    // 行末の/を取り除く 
     1704                    $dir = ereg_replace("/$", "", $dir); 
     1705                    $path = $dir."/".$file; 
     1706                    if ($file != '..' && $file != '.' && !is_dir($path)) {  
     1707                        $bytes += filesize($path);  
     1708                    } else if (is_dir($path) && $file != '..' && $file != '.') { 
     1709                        // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。 
     1710                        $bytes += SC_Utils::sfGetDirSize($path);  
     1711                    }  
     1712                }  
     1713            } else { 
     1714                // ファイルの場合 
     1715                $bytes = filesize($dir); 
     1716            } 
     1717        } 
     1718        // ディレクトリ(ファイル)が存在しない場合は0byteを返す 
     1719        if($bytes == "") $bytes = 0; 
     1720         
     1721        return $bytes; 
     1722    } 
     1723     
     1724    /*  
     1725     * 関数名:sfDeleteDir() 
     1726     * 説明 :指定したディレクトリを削除 
     1727     * 引数1 :削除ファイル 
     1728     */ 
     1729    function sfDeleteDir($dir) { 
     1730        $arrResult = array(); 
     1731        if(file_exists($dir)) { 
     1732            // ディレクトリかチェック 
     1733            if (is_dir($dir)) { 
     1734                if ($handle = opendir("$dir")) { 
     1735                    $cnt = 0; 
     1736                    while (false !== ($item = readdir($handle))) { 
     1737                        if ($item != "." && $item != "..") { 
     1738                            if (is_dir("$dir/$item")) { 
     1739                                sfDeleteDir("$dir/$item"); 
     1740                            } else { 
     1741                                $arrResult[$cnt]['result'] = @unlink("$dir/$item"); 
     1742                                $arrResult[$cnt]['file_name'] = "$dir/$item"; 
     1743                            } 
     1744                        } 
     1745                        $cnt++; 
     1746                    } 
     1747                } 
     1748                closedir($handle); 
     1749                $arrResult[$cnt]['result'] = @rmdir($dir); 
     1750                $arrResult[$cnt]['file_name'] = "$dir/$item"; 
     1751            } else { 
     1752                // ファイル削除 
     1753                $arrResult[0]['result'] = @unlink("$dir"); 
     1754                $arrResult[0]['file_name'] = "$dir";             
     1755            } 
     1756        } 
     1757         
     1758        return $arrResult; 
     1759    } 
     1760     
     1761    /*  
     1762     * 関数名:sfGetFileTree() 
     1763     * 説明 :ツリー生成用配列取得(javascriptに渡す用) 
     1764     * 引数1 :ディレクトリ 
     1765     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
     1766     */ 
     1767    function sfGetFileTree($dir, $tree_status) { 
     1768         
     1769        $cnt = 0; 
     1770        $arrTree = array(); 
     1771        $default_rank = count(split('/', $dir)); 
     1772     
     1773        // 文末の/を取り除く 
     1774        $dir = ereg_replace("/$", "", $dir);     
     1775        // 最上位層を格納(user_data/) 
     1776        if(sfDirChildExists($dir)) { 
     1777            $arrTree[$cnt]['type'] = "_parent"; 
     1778        } else { 
     1779            $arrTree[$cnt]['type'] = "_child";   
     1780        } 
     1781        $arrTree[$cnt]['path'] = $dir; 
     1782        $arrTree[$cnt]['rank'] = 0; 
     1783        $arrTree[$cnt]['count'] = $cnt; 
     1784        // 初期表示はオープン 
     1785        if($_POST['mode'] != '') { 
     1786            $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status); 
     1787        } else { 
     1788            $arrTree[$cnt]['open'] = true; 
     1789        } 
     1790        $cnt++;  
     1791     
     1792        sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status); 
     1793     
     1794        return $arrTree; 
     1795    } 
     1796     
     1797    /*  
     1798     * 関数名:sfGetFileTree() 
     1799     * 説明 :ツリー生成用配列取得(javascriptに渡す用) 
     1800     * 引数1 :ディレクトリ 
     1801     * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント) 
     1802     * 引数3 :連番 
     1803     * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
     1804     */ 
     1805    function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) { 
     1806         
     1807        if(file_exists($dir)) { 
     1808            if ($handle = opendir("$dir")) { 
     1809                while (false !== ($item = readdir($handle))) $arrDir[] = $item;  
     1810                // アルファベットと数字でソート 
     1811                natcasesort($arrDir); 
     1812                foreach($arrDir as $item) { 
     1813                    if ($item != "." && $item != "..") { 
     1814                        // 文末の/を取り除く 
     1815                        $dir = ereg_replace("/$", "", $dir); 
     1816                        $path = $dir."/".$item; 
     1817                        // ディレクトリのみ取得 
     1818                        if (is_dir($path)) { 
     1819                            $arrTree[$cnt]['path'] = $path; 
     1820                            if(sfDirChildExists($path)) { 
     1821                                $arrTree[$cnt]['type'] = "_parent"; 
     1822                            } else { 
     1823                                $arrTree[$cnt]['type'] = "_child";   
     1824                            } 
     1825                             
     1826                            // 階層を割り出す 
     1827                            $arrCnt = split('/', $path); 
     1828                            $rank = count($arrCnt); 
     1829                            $arrTree[$cnt]['rank'] = $rank - $default_rank + 1; 
     1830                            $arrTree[$cnt]['count'] = $cnt; 
     1831                            // フォルダが開いているか 
     1832                            $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status); 
     1833                            $cnt++; 
     1834                            // 下層ディレクトリ取得の為、再帰的に呼び出す 
     1835                            sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status); 
     1836                        } 
     1837                    } 
     1838                } 
     1839            } 
     1840            closedir($handle); 
     1841        } 
     1842    } 
     1843     
     1844    /*  
     1845     * 関数名:sfDirChildExists() 
     1846     * 説明 :指定したディレクトリ配下にファイルがあるか 
     1847     * 引数1 :ディレクトリ 
     1848     */ 
     1849    function sfDirChildExists($dir) { 
     1850        if(file_exists($dir)) { 
     1851            if (is_dir($dir)) { 
     1852                $handle = opendir($dir);  
     1853                while ($file = readdir($handle)) { 
     1854                    // 行末の/を取り除く 
     1855                    $dir = ereg_replace("/$", "", $dir); 
     1856                    $path = $dir."/".$file; 
     1857                    if ($file != '..' && $file != '.' && is_dir($path)) {  
     1858                        return true; 
     1859                    }  
     1860                }  
     1861            } 
     1862        } 
     1863         
     1864        return false; 
     1865    } 
     1866     
     1867    /*  
     1868     * 関数名:lfIsFileOpen() 
     1869     * 説明 :指定したファイルが前回開かれた状態にあったかチェック 
     1870     * 引数1 :ディレクトリ 
     1871     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 
     1872     */ 
     1873    function lfIsFileOpen($dir, $tree_status) { 
     1874        $arrTreeStatus = split('\|', $tree_status); 
     1875        if(in_array($dir, $arrTreeStatus)) { 
     1876            return true; 
     1877        } 
     1878         
     1879        return false; 
     1880    } 
     1881     
     1882    /*  
     1883     * 関数名:sfDownloadFile() 
     1884     * 引数1 :ファイルパス 
     1885     * 説明 :ファイルのダウンロード 
     1886     */ 
     1887    function sfDownloadFile($file) { 
     1888        // ファイルの場合はダウンロードさせる 
     1889        Header("Content-disposition: attachment; filename=".basename($file)); 
     1890        Header("Content-type: application/octet-stream; name=".basename($file)); 
     1891        Header("Cache-Control: "); 
     1892        Header("Pragma: "); 
     1893        echo (sfReadFile($file)); 
     1894    } 
     1895     
     1896    /*  
     1897     * 関数名:sfCreateFile() 
     1898     * 引数1 :ファイルパス 
     1899     * 引数2 :パーミッション 
     1900     * 説明 :ファイル作成 
     1901     */ 
     1902    function sfCreateFile($file, $mode = "") { 
     1903        // 行末の/を取り除く 
     1904        if($mode != "") { 
     1905            $ret = @mkdir($file, $mode); 
     1906        } else { 
     1907            $ret = @mkdir($file); 
     1908        } 
     1909         
     1910        return $ret; 
     1911    } 
     1912     
     1913    /*  
     1914     * 関数名:sfReadFile() 
     1915     * 引数1 :ファイルパス 
     1916     * 説明 :ファイル読込 
     1917     */ 
     1918    function sfReadFile($filename) {  
     1919        $str = "";  
     1920        // バイナリモードでオープン  
     1921        $fp = @fopen($filename, "rb" );  
     1922        //ファイル内容を全て変数に読み込む  
     1923        if($fp) {  
     1924            $str = @fread($fp, filesize($filename)+1);  
     1925        }  
     1926        @fclose($fp); 
     1927     
     1928        return $str;  
     1929    } 
     1930     
    16401931    /* デバッグ用 ------------------------------------------------------------------------------------------------*/ 
    16411932    function sfPrintR($obj) { 
Note: See TracChangeset for help on using the changeset viewer.