Mercurial > hg > fapweb
changeset 986:a8ed8295fcd2
Implement name cropping.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Nov 2014 18:00:03 +0200 |
parents | 31dc100c78d4 |
children | 06e45615b46b |
files | faptool.php |
diffstat | 1 files changed, 52 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/faptool.php Sat Nov 29 17:58:56 2014 +0200 +++ b/faptool.php Sat Nov 29 18:00:03 2014 +0200 @@ -392,7 +392,54 @@ } -function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig = TRUE) +function wtCropFilename($filename, $len) +{ + if ($len !== FALSE && strlen($filename) > $len) + { + $fext = ""; + $dpos = strrpos($filename, "/"); + if (($spos = strrpos($filename, ".")) !== FALSE && + ($dpos === FALSE || $dpos < $spos)) + $fext = substr($filename, $spos); + + if (strlen($fext) >= $len) + $fext = ""; + + return substr($filename, 0, $len - strlen($fext)).$fext; + } + else + return $filename; +} + + +function wtCropFilenamesRec($path, $len) +{ + echo "X: ".$path.", $len\n"; + if ($len === false && $len <= 4) + return FALSE; + + $dir = opendir($path); + while (($dentry = readdir($dir)) !== false) + { + $fname = $path."/".$dentry; + if ($dentry != "." && $dentry != "..") + { + if (is_dir($fname)) + { + wtCropFilenamesRec($fname, $len); + //rename(); + } + else + if (is_file($fname)) + echo "X: ".$fname."\n"; + //rename(); + } + } + closedir($dir); +} + + +function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames) { global $setEntryPath; @@ -420,7 +467,7 @@ if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) return FALSE; - $dstFileBase = $entry["show_id"]."--".($useOrig ? $efile["origname"] : $efile["filename"]); + $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames); if ($edata["class"] == EFILE_ARCHIVE) { @@ -428,6 +475,8 @@ $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) return FALSE; + + wtCropFilenamesRec($dstPath, $cropNames); } else { @@ -727,7 +776,7 @@ foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) { - wtUnpackEntry($compo, $entry, $setPrefix); + wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32); } break;