# HG changeset patch # User Matti Hamalainen # Date 1417276803 -7200 # Node ID a8ed8295fcd268bdd7a37b298d40aa5564419d87 # Parent 31dc100c78d4d340a7585eb74d16b1fdeee5db34 Implement name cropping. diff -r 31dc100c78d4 -r a8ed8295fcd2 faptool.php --- 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;