Mercurial > hg > fapweb
annotate faptool.php @ 1031:bada991641ba
Cleaning up.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 19 Nov 2015 21:08:40 +0200 |
parents | 8f242f756b0b |
children | ed22a3a3027f |
rev | line source |
---|---|
827 | 1 #!/usr/bin/php |
2 <? | |
943 | 3 // |
4 // FAPWeb - Simple Web-based Demoparty Management System | |
5 // Special entry/preview/etc backend management commandline utility | |
1001 | 6 // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) |
943 | 7 // |
1024
2a96426159f1
Fix configuration file checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
1019
diff
changeset
|
8 if (!file_exists(realpath(dirname(__FILE__))."/mconfig.inc.php")) |
1019
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
9 { |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
10 die( |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
11 "ERROR: Missing site configuration file. Please copy ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
12 "'mconfig.inc.php.example' to 'mconfig.inc.php' and ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
13 "edit it as needed.\n"); |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
14 } |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
15 |
827 | 16 require_once "mconfig.inc.php"; |
17 require_once "msite.inc.php"; | |
18 | |
19 | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
20 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv) |
882 | 21 { |
22 global $setPreviewPath; | |
912 | 23 $isTemp = FALSE; |
882 | 24 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
25 if ($useGfxConv) |
884 | 26 { |
27 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit | |
951 | 28 $tmpFilename = tempnam($setPreviewPath, "tmp"); |
912 | 29 $isTemp = TRUE; |
30 if (wtExec( | |
884 | 31 "/usr/local/bin/gfxconv", |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
32 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename), |
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
33 0) === false) |
912 | 34 return FALSE; |
35 | |
951 | 36 if (!file_exists($tmpFilename)) |
912 | 37 { |
38 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n"; | |
39 return FALSE; | |
40 } | |
884 | 41 } |
42 else | |
951 | 43 $tmpFilename = $inFilename; |
884 | 44 |
45 // Create conversion entity | |
951 | 46 $img = new Imagick($tmpFilename); |
1004 | 47 if ($img === FALSE) |
912 | 48 { |
951 | 49 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; |
912 | 50 return FALSE; |
51 } | |
884 | 52 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
53 if ($outDim !== FALSE) |
884 | 54 { |
963 | 55 // Get dimensions, setup background |
56 $dim = $img->getImageGeometry(); | |
969 | 57 // $img->setBackgroundColor(imagick::COLOR_BLACK); |
963 | 58 $img->setGravity(imagick::GRAVITY_CENTER); |
59 | |
60 // Act based on image size vs. desired size and $thumb mode | |
61 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1]) | |
62 { | |
63 // Image is larger | |
64 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1); | |
969 | 65 $img->setImageExtent($outDim[0], $outDim[1]); |
963 | 66 $img->normalizeImage(); |
67 $img->unsharpMaskImage(0, 0.5, 1, 0.05); | |
68 } | |
69 else | |
70 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1]) | |
71 { | |
72 // Image is smaller than requested dimension(s)? | |
73 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1); | |
969 | 74 $img->setImageExtent($outDim[0], $outDim[1]); |
963 | 75 } |
884 | 76 } |
77 | |
78 $img->setFormat($outFormat); | |
79 $img->setCompressionQuality($outQuality); | |
80 | |
81 $img->stripImage(); | |
82 $img->writeImage($outFilename); | |
83 $img->removeImage(); | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
84 return TRUE; |
882 | 85 } |
86 | |
87 | |
898 | 88 function wtRenderSample($inFilename, $outFilename) |
882 | 89 { |
898 | 90 $sfreq = intval(stGetSetting("sampleFreq")); |
91 $sduration = intval(stGetSetting("sampleDuration")); | |
92 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 93 |
902 | 94 return wtExec( |
898 | 95 "/usr/local/bin/openmpt123" |
96 , | |
954 | 97 "--force --quiet ". |
884 | 98 "--samplerate ".$sfreq." ". |
99 "--channels ".$schannels." ". | |
1026
37901bdbc545
Switch to the official --end-time parameter of openmpt123
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
100 "--end-time ".($sduration)." ". |
1028
8f242f756b0b
Add new configuration setting "openmpt123ExtraArgs".
Matti Hamalainen <ccr@tnsp.org>
parents:
1026
diff
changeset
|
101 stGetSetting("openmpt123ExtraArgs"). |
954 | 102 escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename), |
963 | 103 0); |
882 | 104 } |
105 | |
106 | |
948
1334b93939a3
Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents:
947
diff
changeset
|
107 function wtConvertSample($inFilename, $outFilename, $outOpts) |
882 | 108 { |
898 | 109 $sfreq = intval(stGetSetting("sampleFreq")); |
110 $sduration = intval(stGetSetting("sampleDuration")); | |
111 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 112 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
113 $optStr = ""; |
948
1334b93939a3
Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents:
947
diff
changeset
|
114 foreach ($outOpts as $okey => $oval) |
898 | 115 $optStr .= $okey." ".$oval." "; |
939 | 116 |
902 | 117 return wtExec( |
898 | 118 "/usr/local/bin/avconv", |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
119 "-y -v 1 -t ".intval($sduration)." ". |
898 | 120 "-i ".escapeshellarg($inFilename). |
121 " ".$optStr." -ac ".$schannels. | |
122 " -map_metadata -1 ". | |
123 escapeshellarg($outFilename)); | |
882 | 124 } |
125 | |
126 | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
127 function wtEntryToSource($compo, $inFilename, $edata, $entryFilename, &$outData, &$outFilename, $force) |
882 | 128 { |
963 | 129 // Does compo preview type match this file class? |
130 if ($edata["class"] != $compo["preview_type"]) | |
131 return FALSE; | |
954 | 132 |
969 | 133 switch ($edata["class"]) |
134 { | |
135 case EFILE_AUDIO: $fext = "wav"; break; | |
136 case EFILE_IMAGE: $fext = "png"; break; | |
137 default: | |
138 return FALSE; | |
139 } | |
140 | |
141 $outFilename = stReplaceFileExt($entryFilename, "_preview.".$fext); | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
142 if (!$force && file_exists($outFilename) && filemtime($outFilename) >= filemtime($entryFilename)) |
969 | 143 return TRUE; |
963 | 144 |
969 | 145 printf("GENERATING: %s -> %s\n", $inFilename, $outFilename); |
146 | |
954 | 147 switch ($edata["class"]) |
939 | 148 { |
954 | 149 case EFILE_AUDIO: |
150 if ($edata["mime"] == "audio/x-mod") | |
963 | 151 $res = wtRenderSample($inFilename, $outFilename); |
954 | 152 else |
969 | 153 $res = wtConvertSample($inFilename, $outFilename, |
154 array("-f" => "wav")); | |
954 | 155 break; |
963 | 156 |
954 | 157 case EFILE_IMAGE: |
963 | 158 $res = wtConvertImage( |
159 $inFilename, | |
160 $outFilename, | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
161 FALSE, "PNG", 9, |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
162 FALSE, ($edata["mime"] == "gfx")); |
963 | 163 break; |
939 | 164 } |
963 | 165 |
166 return $res; | |
882 | 167 } |
168 | |
169 | |
902 | 170 function wtUnpackArchiveTo($atype, $filename, $path) |
882 | 171 { |
172 // Check file type before doing anything | |
953 | 173 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n"; |
902 | 174 switch ($atype) |
882 | 175 { |
176 case "LHA": | |
177 $exe = "/usr/bin/lha"; | |
967 | 178 $args = "x ".escapeshellarg($filename); |
882 | 179 break; |
180 | |
181 case "ZIP": | |
182 $exe = "/usr/bin/unzip"; | |
183 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename); | |
184 break; | |
185 | |
898 | 186 case "RAR": |
187 $exe = "/usr/bin/rar"; | |
968 | 188 $args = "x -w".escapeshellarg($path)." ".escapeshellarg($filename); |
189 break; | |
190 | |
191 case "7ZIP": | |
192 $exe = "/usr/bin/7z"; | |
193 $args = "x -o".escapeshellarg($path)." ".escapeshellarg($filename); | |
898 | 194 break; |
195 | |
882 | 196 default: |
902 | 197 echo "Unsupported archive file type: ".$atype."\n"; |
898 | 198 return FALSE; |
882 | 199 } |
200 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
201 // Delete any pre-existing directory |
882 | 202 wtPurgeDir($path); |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
203 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
204 // Create temporary directory for unpacking |
935 | 205 wtMakeDir($path, 0700); |
882 | 206 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
207 // Save current working directory and chdir to target |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
208 $cwd = getcwd(); |
882 | 209 if (!is_dir($path) || chdir($path) === false) |
902 | 210 { |
953 | 211 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n"; |
902 | 212 return FALSE; |
213 } | |
882 | 214 |
215 // Unpack archive | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
216 $ret = wtExec($exe, $args); |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
217 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
218 // Return to stored cwd |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
219 chdir($cwd); |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
220 return $ret; |
902 | 221 } |
222 | |
223 | |
882 | 224 function wtHandleEntryPreview($compo, $entry, $mode) |
225 { | |
941 | 226 global $fileTypeData, $setEntryPath; |
933 | 227 |
228 // Get current preview file(s) data | |
898 | 229 if (!stGetPreviewFileData($compo, $entry, $pdata)) |
230 return FALSE; | |
231 | |
933 | 232 // Get entry file data |
963 | 233 $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]); |
898 | 234 |
235 // Check preview file(s) status | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
236 if ($mode == "sta" || $mode == "lis") |
898 | 237 { |
238 printf(" %03d | %s%s%s | %-40s | %-5s | %s\n", | |
239 $entry["id"], | |
933 | 240 ($efile !== false) ? "E" : ".", |
241 isset($pdata["file"]) ? "P" : ".", | |
242 $pdata["valid"] ? "V" : ".", | |
243 substr($entry["name"]." by ".$entry["author"], 0, 40), | |
898 | 244 isset($pdata["file"]) ? $pdata["file"]["filetype"] : "", |
245 isset($pdata["file"]) ? $pdata["file"]["filename"] : "" | |
246 ); | |
954 | 247 return TRUE; |
898 | 248 } |
249 else | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
250 if ($mode != "gen" && $mode != "upd") |
953 | 251 die("ERROR: Unsupported previews mode ".$mode."\n"); |
933 | 252 |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
253 $force = ($mode == "upd"); |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
254 |
933 | 255 // Check validity of previews |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
256 if ($pdata["valid"] && !$force) |
933 | 257 return TRUE; |
258 | |
259 // Okay, no valid previews .. lets see what we can do .. | |
260 // First, check if we have a source preview file | |
261 if (!isset($pdata["file"])) | |
898 | 262 { |
935 | 263 // No source preview, check if we have entry file either? |
264 if ($efile === false) | |
265 { | |
266 echo | |
267 "INFO: No entry file for ".wtNiceName($compo, $entry, $efile). | |
268 ", can't attempt to generate preview.\n"; | |
269 return FALSE; | |
270 } | |
954 | 271 |
272 // Actual entry filename + path | |
273 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); | |
274 if (!file_exists($filename)) | |
275 { | |
276 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
277 return FALSE; | |
278 } | |
279 | |
935 | 280 // Preview source file does not exist, let's see .. |
963 | 281 $edata = stProbeFileInfo($filename, TRUE); |
282 if ($edata === false) | |
882 | 283 { |
935 | 284 echo |
285 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
286 return FALSE; | |
287 } | |
288 | |
942 | 289 $found = FALSE; |
935 | 290 if ($edata["class"] == EFILE_ARCHIVE) |
291 { | |
292 // Entry is an archive file .. | |
963 | 293 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $efile["filename"])); |
941 | 294 |
295 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false) | |
296 return FALSE; | |
935 | 297 |
941 | 298 // Scan through files ... |
299 $dir = opendir($path); | |
300 while (($dentry = readdir($dir)) !== false) | |
301 { | |
302 $fname = $path."/".$dentry; | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
303 if ($dentry != "." && $dentry != "..") |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
304 { |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
305 if (is_dir($fname)) |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
306 echo "XXX: ".$dentry." :: ".$fname."\n"; |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
307 else |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
308 if (is_file($fname) && |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
309 ($mdata = stProbeFileInfo($fname, TRUE)) !== false && |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
310 ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === true) |
954 | 311 break; |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
312 } |
941 | 313 } |
954 | 314 |
315 // Cleanup | |
941 | 316 closedir($dir); |
317 wtPurgeDir($path); | |
954 | 318 } |
319 else | |
320 if ($edata["class"] == $compo["preview_type"]) | |
321 { | |
322 // Single file | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
323 $found = wtEntryToSource($compo, $filename, $edata, $filename, $pdata, $outFilename, $force); |
954 | 324 } |
969 | 325 |
950 | 326 if (!$found) |
882 | 327 { |
935 | 328 echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; |
329 return FALSE; | |
898 | 330 } |
969 | 331 |
332 $inFilename = $outFilename; | |
898 | 333 } |
969 | 334 else |
335 $inFilename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $pdata["file"]["filename"])); | |
898 | 336 |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
337 // Check validity vs. |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
338 if (!$force) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
339 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
340 $valid = TRUE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
341 $inMTime = filemtime($inFilename); |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
342 foreach ($pdata["files"] as $stype => $sdata) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
343 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
344 if (!file_exists($sdata["file"]) || filemtime($sdata["file"]) < $inMTime) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
345 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
346 $valid = FALSE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
347 break; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
348 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
349 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
350 if ($valid) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
351 return TRUE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
352 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
353 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
354 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
355 // Either we now have a "user specified" source file or |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
356 // a generated source file - in any case, now convert it |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
357 // to the final form(s). |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
358 // |
969 | 359 switch ($compo["preview_type"]) |
941 | 360 { |
963 | 361 case EFILE_AUDIO: |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
362 // Convert to each specified sample type (MP3, Ogg, etc.) |
950 | 363 foreach (stGetSetting("sampleTypes") as $stype => $sopts) |
942 | 364 { |
950 | 365 wtConvertSample( |
366 $inFilename, | |
969 | 367 $pdata["files"][$stype]["file"], |
950 | 368 $sopts |
369 ); | |
942 | 370 } |
371 break; | |
969 | 372 |
963 | 373 case EFILE_IMAGE: |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
374 // Images we convert to bigger image and thumbnail |
969 | 375 wtConvertImage( |
376 $inFilename, | |
377 $pdata["files"]["image"]["file"], | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
378 stGetSetting("previewImageSize"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
379 stGetSetting("previewImageType"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
380 stGetSetting("previewImageQuality"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
381 FALSE, FALSE); |
882 | 382 |
969 | 383 wtConvertImage( |
384 $inFilename, | |
385 $pdata["files"]["thumb"]["file"], | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
386 stGetSetting("previewThumbSize"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
387 stGetSetting("previewThumbType"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
388 stGetSetting("previewThumbQuality"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
389 TRUE, FALSE); |
942 | 390 break; |
941 | 391 } |
963 | 392 |
933 | 393 return TRUE; |
882 | 394 } |
395 | |
396 | |
884 | 397 function wtHandleEntry($compo, $entry, $mode) |
398 { | |
399 } | |
400 | |
401 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
402 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
403 // Crop a filename to specified length |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
404 // |
986 | 405 function wtCropFilename($filename, $len) |
406 { | |
407 if ($len !== FALSE && strlen($filename) > $len) | |
408 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
409 // Check if the filename has a path and attempt |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
410 // to get the filename extension |
986 | 411 $fext = ""; |
412 $dpos = strrpos($filename, "/"); | |
413 if (($spos = strrpos($filename, ".")) !== FALSE && | |
414 ($dpos === FALSE || $dpos < $spos)) | |
415 $fext = substr($filename, $spos); | |
416 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
417 // Is the filename extension too long, if yes, just dump it |
986 | 418 if (strlen($fext) >= $len) |
419 $fext = ""; | |
420 | |
987 | 421 return substr($filename, 0, $len - strlen($fext) - 1).$fext; |
986 | 422 } |
423 else | |
424 return $filename; | |
425 } | |
426 | |
427 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
428 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
429 // Recursively goes through directory/files and subdirectories, |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
430 // cropping file/dir names to specified length. |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
431 // |
986 | 432 function wtCropFilenamesRec($path, $len) |
433 { | |
434 $dir = opendir($path); | |
435 while (($dentry = readdir($dir)) !== false) | |
436 { | |
437 $fname = $path."/".$dentry; | |
987 | 438 $nname = $path."/".wtCropFilename($dentry, $len); |
986 | 439 if ($dentry != "." && $dentry != "..") |
440 { | |
441 if (is_dir($fname)) | |
442 { | |
443 wtCropFilenamesRec($fname, $len); | |
987 | 444 if (rename($fname, $nname) === false) |
445 { | |
446 echo "ERROR: Could not rename DIR '".$fname."' -> '".$nname."'.\n"; | |
447 return FALSE; | |
448 } | |
986 | 449 } |
450 else | |
987 | 451 if (is_file($fname) && rename($fname, $nname) === false) |
452 { | |
453 echo "ERROR: Could not rename FILE '".$fname."' -> '".$nname."'.\n"; | |
454 return FALSE; | |
455 } | |
986 | 456 } |
457 } | |
458 closedir($dir); | |
459 } | |
460 | |
461 | |
991 | 462 function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames, $copyOnly) |
963 | 463 { |
464 global $setEntryPath; | |
465 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
466 // Get latest file for the entry |
963 | 467 if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"])) === false) |
468 { | |
469 echo "INFO: No entry file for ".wtNiceName($compo, $entry, $efile)."\n"; | |
470 return FALSE; | |
471 } | |
472 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
473 // Create source file full path |
963 | 474 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
475 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
476 // Check if the file exists |
963 | 477 if (!file_exists($filename)) |
478 { | |
479 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
480 return FALSE; | |
481 } | |
482 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
483 // Get file data |
963 | 484 $edata = stProbeFileInfo($filename, TRUE); |
485 if ($edata === false) | |
486 { | |
487 echo | |
488 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
489 return FALSE; | |
490 } | |
491 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
492 // Create the destination directory |
963 | 493 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) |
494 return FALSE; | |
495 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
496 // Form the destination path and/or filename |
991 | 497 if ($copyOnly) |
498 $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"]; | |
499 else | |
500 $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames); | |
963 | 501 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
502 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
503 // Handle based on class/type and whether we are just copying or not |
991 | 504 if (!$copyOnly && $edata["class"] == EFILE_ARCHIVE) |
963 | 505 { |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
506 // Entry is an archive file, so unpack it |
963 | 507 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); |
964 | 508 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) |
963 | 509 return FALSE; |
986 | 510 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
511 // Crop the filenames from the unpacked archive, if we need to |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
512 if ($cropNames !== false) |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
513 wtCropFilenamesRec($dstPath, $cropNames); |
963 | 514 } |
515 else | |
516 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
517 // We have a single file (or copyOnly mode) |
963 | 518 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); |
519 if (copy($filename, $dstFilename) === false) | |
520 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
521 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n"; |
963 | 522 return FALSE; |
523 } | |
524 } | |
525 | |
526 return TRUE; | |
527 } | |
528 | |
529 | |
827 | 530 // |
941 | 531 // Misc helper functions |
827 | 532 // |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
533 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
534 function wtNiceName($compo, $entry, $efile = FALSE) |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
535 { |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
536 return sprintf( |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
537 "%d: %s by %s%s", |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
538 $entry["id"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
539 $entry["name"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
540 $entry["author"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
541 ($efile !== false) ? " [".$efile["filename"]." / TYPE: '".$efile["filetype"]."']" : ""); |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
542 } |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
543 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
544 |
941 | 545 function wtExec($exe, $args, $expect = 0) |
546 { | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
547 echo "EXEC: ".$exe." @ ".$args."\n"; |
941 | 548 exec(escapeshellcmd($exe)." ".$args, $output, $code); |
549 if ($code !== $expect) | |
550 { | |
551 echo | |
953 | 552 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n". |
941 | 553 "------------------------------------------------\n". |
554 implode("\n", $output). | |
555 "------------------------------------------------\n"; | |
556 return FALSE; | |
557 } | |
558 return TRUE; | |
559 } | |
560 | |
561 | |
562 function wtExecOrDie($exe, $args) | |
563 { | |
564 if (wtExec($exe, $args) === false) | |
565 die(); | |
566 } | |
567 | |
568 | |
569 function wtPurgeDir($path) | |
570 { | |
942 | 571 if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) |
941 | 572 { |
969 | 573 // echo "PURGING: ".$path."\n"; |
942 | 574 foreach (scandir($path) as $file) |
575 if ($file !== "." && $file !== "..") | |
576 { | |
577 $sub = $path."/".$file; | |
578 if (is_dir($sub)) | |
579 wtPurgeDir($sub); | |
580 else | |
581 unlink($sub); | |
582 } | |
583 rmdir($path); | |
941 | 584 } |
585 } | |
586 | |
587 | |
935 | 588 function wtMakeDir($path, $perm) |
827 | 589 { |
590 if (!file_exists($path)) | |
591 { | |
953 | 592 echo "INFO: Creating ".$path."\n"; |
827 | 593 if (mkdir($path, $perm, TRUE) === false) |
594 die("Could not create directory '".$path."'\n"); | |
595 } | |
596 } | |
597 | |
598 | |
935 | 599 function wtInitializeDirs() |
827 | 600 { |
902 | 601 global |
602 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 603 $setEntryPathPerms, $setPrevPathPerms; |
604 | |
605 echo "Checking for missing directories ...\n"; | |
935 | 606 wtMakeDir($setEntryPath, $setEntryPathPerms); |
607 wtMakeDir($setPreviewPath, $setPrevPathPerms); | |
827 | 608 |
609 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
610 { | |
935 | 611 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); |
612 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); | |
613 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); | |
827 | 614 } |
615 } | |
616 | |
617 | |
968 | 618 function wtPrintCompoHeader($compo) |
619 { | |
620 global $setTermWidth; | |
621 printf("==%'=-".($setTermWidth-2)."s\n", | |
622 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) | |
623 ); | |
624 } | |
625 | |
626 | |
627 function wtPrintDivider($chr = "-") | |
628 { | |
629 global $setTermWidth; | |
630 echo str_repeat($chr, $setTermWidth)."\n"; | |
631 } | |
632 | |
633 | |
935 | 634 function wtShowHelp() |
827 | 635 { |
935 | 636 global $argv; |
827 | 637 echo |
638 "faptool - Do stuff with FAPWeb database\n". | |
1001 | 639 "(C) Copyright 2015 ccr/TNSP\n". |
827 | 640 "\n". |
917 | 641 "Usage: ".$argv[0]." <command> [args]\n". |
642 "Where command is one of following:\n". | |
827 | 643 "\n". |
644 " init\n". | |
645 " Create directories for entries and previews, if needed.\n". | |
646 "\n". | |
928 | 647 /* |
917 | 648 " clean [delete|crap]\n". |
649 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
650 " any old or stale preview files and entry files.\n". | |
651 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
652 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
653 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
654 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 655 "\n". |
928 | 656 */ |
938 | 657 " probe <filename> [filename2 ..]\n". |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
658 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
659 "\n". |
881 | 660 " previews <cmd> [args]\n". |
661 " Where <cmd> is one of:\n". | |
933 | 662 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
663 " generate - Generate preview files that are missing OR out of date.\n". |
928 | 664 " (older then preview source file OR entry file where appropriate)\n". |
901 | 665 "\n". |
666 " entry <cmd> [args]\n". | |
933 | 667 " status [cid] - List entries for all compos or <cid>.\n". |
966 | 668 " unpack <path> - Create subdirs and copy all entries UNPACKED there.\n". |
991 | 669 " release <path> - Like unpack, but just copies files (does not unpack archives).\n". |
1031 | 670 "\n". |
671 " add <cid> <filename> - Add a new entry with file.\n". | |
672 " Entry info + notes for internal use will be prompted.\n". | |
673 " pre <eid> <filename> - Add file as preview for entry id.\n". | |
674 " del <eid> - Delete entry (does not delete files).\n". | |
928 | 675 /* |
1031 | 676 "\n". |
928 | 677 " package <lha|zip|rar|7z>\n". |
678 " Repackages/packages entries (unpacks first if archive),\n". | |
679 " and adds generated infofile.txt to packages.\n". | |
680 */ | |
827 | 681 "\n"; |
935 | 682 } |
683 | |
1005 | 684 |
685 function wtSigHandler($signo) | |
686 { | |
687 global $flagQuit; | |
688 switch ($signo) | |
689 { | |
690 case SIGTERM: | |
691 mgFatal("Received SIGTERM.\n"); | |
692 break; | |
693 | |
694 case SIGQUIT: | |
695 case SIGINT: | |
696 $flagQuit = TRUE; | |
697 break; | |
1013
720078ca799e
Oops, a missing bracket. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
698 } |
1005 | 699 } |
700 | |
701 | |
935 | 702 // |
703 // Main program starts | |
704 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
705 stCheckCLIExec(); |
935 | 706 if ($argc < 2) |
707 { | |
708 wtShowHelp(); | |
827 | 709 exit; |
710 } | |
711 | |
1005 | 712 pcntl_signal(SIGTERM, "wtSigHandler"); |
713 pcntl_signal(SIGHUP, "wtSigHandler"); | |
714 pcntl_signal(SIGQUIT, "wtSigHandler"); | |
715 pcntl_signal(SIGINT, "wtSigHandler"); | |
935 | 716 |
827 | 717 // Try to connect to database |
718 $spec = stGetSetting("sqlDB"); | |
719 if (($db = stConnectSQLDBSpec($spec)) === false) | |
720 die("Could not connect to SQL database '".$spec."'.\n"); | |
721 | |
722 echo "Using database spec '".$spec."'.\n"; | |
723 | |
724 // Fetch non-"hardcoded" settings from SQL database | |
725 stReloadSettings(); | |
726 | |
727 // Set some globals for our benefit | |
922 | 728 $setTermWidth = 75; |
827 | 729 $setEntryPath = stGetSetting("entryPath"); |
730 $setPreviewPath = stGetSetting("previewPath"); | |
731 $setPreviewURL = stGetSetting("previewURL"); | |
732 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 733 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
734 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 735 |
736 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 737 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
738 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 739 { |
922 | 740 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 741 } |
742 | |
743 | |
744 // Act according to specified command | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
745 switch (stCArgLC(1, 3)) |
827 | 746 { |
935 | 747 case "-?": case "--h": |
748 wtShowHelp(); | |
749 exit; | |
750 break; | |
751 | |
884 | 752 case "ini": |
827 | 753 // |
754 // Initialize the data directories etc | |
755 // | |
953 | 756 echo "INFO: Checking for missing directories ...\n"; |
935 | 757 wtInitializeDirs(); |
827 | 758 break; |
759 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
760 case "pro": |
945 | 761 // |
762 // Probe specified files | |
763 // | |
764 if ($argc < 2) | |
765 die("No filename specified.\n"); | |
766 | |
767 if (($finfo = finfo_open()) === false) | |
954 | 768 die("Internal error. Failed to initialize finfo()."); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
769 |
945 | 770 for ($i = 2; $i < $argc; $i++) |
771 { | |
772 // Probe one file | |
773 $filename = $argv[$i]; | |
774 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
775 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
776 | |
777 echo | |
778 "\n". | |
779 "File : ".$filename."\n". | |
780 "Probed : ".$sdata."\n". | |
781 "Mime : ".$smime."\n"; | |
782 | |
954 | 783 if (($info = stProbeFileInfo($filename, TRUE)) !== false) |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
784 { |
945 | 785 $tmp = array(); |
786 foreach ($info as $ikey => $ival) | |
787 $tmp[] = $ikey."='".$ival."'"; | |
788 | |
789 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
790 } |
946 | 791 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
792 |
946 | 793 finfo_close($finfo); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
794 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
795 |
901 | 796 case "cle": |
947 | 797 // |
798 // File cleanup / deletion | |
799 // | |
901 | 800 $doDelete = (stCArgLC(2) == "delete"); |
801 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
802 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
803 { | |
968 | 804 wtPrintCompoHeader($compo); |
805 wtPrintDivider(); | |
901 | 806 |
807 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
808 { | |
809 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
810 { | |
935 | 811 if ($efile["deleted"] != 0) |
901 | 812 { |
813 echo "X"; | |
814 } | |
815 } | |
816 } | |
817 echo "\n"; | |
968 | 818 wtPrintDivider(); |
901 | 819 } |
820 break; | |
821 | |
822 case "ent": | |
823 // | |
824 // Entry files handling | |
825 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
826 $mode = stCArgLC(2, 3); |
901 | 827 switch ($mode) |
828 { | |
829 case "sta": | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
830 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
831 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 832 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
901 | 833 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
834 { | |
968 | 835 wtPrintCompoHeader($compo); |
836 wtPrintDivider(); | |
901 | 837 |
838 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
839 wtHandleEntry($compo, $entry, $mode); | |
840 | |
968 | 841 wtPrintDivider(); |
901 | 842 } |
843 break; | |
844 | |
963 | 845 case "unp": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
846 if (($setPrefix = stCArg(3)) === FALSE) |
963 | 847 die("Unpack needs a destination path.\n"); |
848 | |
849 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
850 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
851 { | |
991 | 852 // wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32, FALSE); |
853 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, FALSE); | |
854 } | |
855 break; | |
856 | |
857 case "rel": | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
858 if (($setPrefix = stCArg(3)) === FALSE) |
991 | 859 die("Releases needs a destination path.\n"); |
860 | |
861 if (!file_exists($setPrefix) || is_dir($setPrefix)) | |
862 { | |
863 // Create new one | |
864 wtMakeDir($setPrefix, 0755); | |
865 | |
866 // Create results.txt if it does not exist | |
867 $resultsFile = stMakePath(FALSE, TRUE, array($setPrefix, "results.txt")); | |
868 if (!file_exists($resultsFile)) | |
869 { | |
870 // Use a header file if it exists | |
871 $resultsHeader = "results.logo"; | |
872 if (file_exists($resultsHeader) && is_file($resultsHeader)) | |
873 $resultsText = file_get_contents($resultsHeader); | |
874 else | |
875 { | |
876 $resultsText = $pageTitle." results"; | |
877 $resultsText .= "\n".str_repeat("=", strlen($resultsText))."-- -\n\n"; | |
878 } | |
879 | |
880 file_put_contents( | |
881 $resultsFile, | |
882 $resultsText.stGetCompoResultsASCIIStr(FALSE, 0) | |
883 ); | |
884 } | |
885 | |
886 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
887 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
888 { | |
889 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, TRUE); | |
890 } | |
963 | 891 } |
892 break; | |
893 | |
901 | 894 case "pac": |
929 | 895 echo "Not implemented. :D\n"; |
901 | 896 break; |
897 | |
898 case "add": | |
929 | 899 echo "Not implemented. :D\n"; |
901 | 900 break; |
901 | |
902 default: | |
903 if ($mode == "") | |
904 die("ERROR! Entry command requires a sub-command argument.\n"); | |
905 else | |
906 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
907 break; | |
908 } | |
909 break; | |
910 | |
884 | 911 case "pre": |
881 | 912 // |
913 // Preview files handling | |
914 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
915 $mode = stCArgLC(2, 3); |
881 | 916 switch ($mode) |
917 { | |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
918 case "gen": |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
919 case "upd": |
881 | 920 case "sta": |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
921 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
922 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 923 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
898 | 924 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 925 { |
968 | 926 wtPrintCompoHeader($compo); |
881 | 927 printf( |
898 | 928 "PrevType : %s\n", |
929 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 930 |
968 | 931 if ($mode == "sta" || $mode == "lis") |
941 | 932 { |
933 printf(" %-3s | %-3s | %-40s |\n", | |
968 | 934 "#ID", "EPV", "Entry name/author"); |
941 | 935 } |
936 | |
968 | 937 wtPrintDivider("-"); |
881 | 938 |
939 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
940 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 941 |
968 | 942 wtPrintDivider("="); |
943 } | |
944 if ($mode == "sta" || $mode == "lis") | |
945 { | |
946 echo "Flags: E = Entry has file, P = Has preview file, V = Generated previews are up to date.\n"; | |
881 | 947 } |
948 break; | |
949 | |
950 default: | |
951 if ($mode == "") | |
952 die("ERROR! Previews command requires a sub-command argument.\n"); | |
953 else | |
954 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
955 break; | |
956 } | |
957 break; | |
958 | |
827 | 959 default: |
960 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
961 break; | |
962 } | |
963 | |
941 | 964 /* Dummy |
965 { | |
966 | |
967 } | |
968 */ | |
827 | 969 ?> |