Mercurial > hg > fapweb
annotate faptool.php @ 1028:8f242f756b0b
Add new configuration setting "openmpt123ExtraArgs".
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 19 Nov 2015 20:05:26 +0200 |
parents | 37901bdbc545 |
children | bada991641ba |
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". |
665 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 666 "\n". |
667 " entry <cmd> [args]\n". | |
933 | 668 " status [cid] - List entries for all compos or <cid>.\n". |
966 | 669 " unpack <path> - Create subdirs and copy all entries UNPACKED there.\n". |
991 | 670 " release <path> - Like unpack, but just copies files (does not unpack archives).\n". |
928 | 671 /* |
672 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
673 " (works same as uploading from admin interface)\n". | |
674 " package <lha|zip|rar|7z>\n". | |
675 " Repackages/packages entries (unpacks first if archive),\n". | |
676 " and adds generated infofile.txt to packages.\n". | |
677 */ | |
827 | 678 "\n"; |
935 | 679 } |
680 | |
1005 | 681 |
682 function wtSigHandler($signo) | |
683 { | |
684 global $flagQuit; | |
685 switch ($signo) | |
686 { | |
687 case SIGTERM: | |
688 mgFatal("Received SIGTERM.\n"); | |
689 break; | |
690 | |
691 case SIGQUIT: | |
692 case SIGINT: | |
693 $flagQuit = TRUE; | |
694 break; | |
1013
720078ca799e
Oops, a missing bracket. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
695 } |
1005 | 696 } |
697 | |
698 | |
935 | 699 // |
700 // Main program starts | |
701 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
702 stCheckCLIExec(); |
935 | 703 if ($argc < 2) |
704 { | |
705 wtShowHelp(); | |
827 | 706 exit; |
707 } | |
708 | |
1005 | 709 pcntl_signal(SIGTERM, "wtSigHandler"); |
710 pcntl_signal(SIGHUP, "wtSigHandler"); | |
711 pcntl_signal(SIGQUIT, "wtSigHandler"); | |
712 pcntl_signal(SIGINT, "wtSigHandler"); | |
935 | 713 |
827 | 714 // Try to connect to database |
715 $spec = stGetSetting("sqlDB"); | |
716 if (($db = stConnectSQLDBSpec($spec)) === false) | |
717 die("Could not connect to SQL database '".$spec."'.\n"); | |
718 | |
719 echo "Using database spec '".$spec."'.\n"; | |
720 | |
721 // Fetch non-"hardcoded" settings from SQL database | |
722 stReloadSettings(); | |
723 | |
724 // Set some globals for our benefit | |
922 | 725 $setTermWidth = 75; |
827 | 726 $setEntryPath = stGetSetting("entryPath"); |
727 $setPreviewPath = stGetSetting("previewPath"); | |
728 $setPreviewURL = stGetSetting("previewURL"); | |
729 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 730 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
731 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 732 |
733 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 734 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
735 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 736 { |
922 | 737 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 738 } |
739 | |
740 | |
741 // Act according to specified command | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
742 switch (stCArgLC(1, 3)) |
827 | 743 { |
935 | 744 case "-?": case "--h": |
745 wtShowHelp(); | |
746 exit; | |
747 break; | |
748 | |
884 | 749 case "ini": |
827 | 750 // |
751 // Initialize the data directories etc | |
752 // | |
953 | 753 echo "INFO: Checking for missing directories ...\n"; |
935 | 754 wtInitializeDirs(); |
827 | 755 break; |
756 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
757 case "pro": |
945 | 758 // |
759 // Probe specified files | |
760 // | |
761 if ($argc < 2) | |
762 die("No filename specified.\n"); | |
763 | |
764 if (($finfo = finfo_open()) === false) | |
954 | 765 die("Internal error. Failed to initialize finfo()."); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
766 |
945 | 767 for ($i = 2; $i < $argc; $i++) |
768 { | |
769 // Probe one file | |
770 $filename = $argv[$i]; | |
771 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
772 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
773 | |
774 echo | |
775 "\n". | |
776 "File : ".$filename."\n". | |
777 "Probed : ".$sdata."\n". | |
778 "Mime : ".$smime."\n"; | |
779 | |
954 | 780 if (($info = stProbeFileInfo($filename, TRUE)) !== false) |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
781 { |
945 | 782 $tmp = array(); |
783 foreach ($info as $ikey => $ival) | |
784 $tmp[] = $ikey."='".$ival."'"; | |
785 | |
786 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
787 } |
946 | 788 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
789 |
946 | 790 finfo_close($finfo); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
791 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
792 |
901 | 793 case "cle": |
947 | 794 // |
795 // File cleanup / deletion | |
796 // | |
901 | 797 $doDelete = (stCArgLC(2) == "delete"); |
798 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
799 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
800 { | |
968 | 801 wtPrintCompoHeader($compo); |
802 wtPrintDivider(); | |
901 | 803 |
804 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
805 { | |
806 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
807 { | |
935 | 808 if ($efile["deleted"] != 0) |
901 | 809 { |
810 echo "X"; | |
811 } | |
812 } | |
813 } | |
814 echo "\n"; | |
968 | 815 wtPrintDivider(); |
901 | 816 } |
817 break; | |
818 | |
819 case "ent": | |
820 // | |
821 // Entry files handling | |
822 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
823 $mode = stCArgLC(2, 3); |
901 | 824 switch ($mode) |
825 { | |
826 case "sta": | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
827 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
828 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 829 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
901 | 830 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
831 { | |
968 | 832 wtPrintCompoHeader($compo); |
833 wtPrintDivider(); | |
901 | 834 |
835 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
836 wtHandleEntry($compo, $entry, $mode); | |
837 | |
968 | 838 wtPrintDivider(); |
901 | 839 } |
840 break; | |
841 | |
963 | 842 case "unp": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
843 if (($setPrefix = stCArg(3)) === FALSE) |
963 | 844 die("Unpack needs a destination path.\n"); |
845 | |
846 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
847 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
848 { | |
991 | 849 // wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32, FALSE); |
850 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, FALSE); | |
851 } | |
852 break; | |
853 | |
854 case "rel": | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
855 if (($setPrefix = stCArg(3)) === FALSE) |
991 | 856 die("Releases needs a destination path.\n"); |
857 | |
858 if (!file_exists($setPrefix) || is_dir($setPrefix)) | |
859 { | |
860 // Create new one | |
861 wtMakeDir($setPrefix, 0755); | |
862 | |
863 // Create results.txt if it does not exist | |
864 $resultsFile = stMakePath(FALSE, TRUE, array($setPrefix, "results.txt")); | |
865 if (!file_exists($resultsFile)) | |
866 { | |
867 // Use a header file if it exists | |
868 $resultsHeader = "results.logo"; | |
869 if (file_exists($resultsHeader) && is_file($resultsHeader)) | |
870 $resultsText = file_get_contents($resultsHeader); | |
871 else | |
872 { | |
873 $resultsText = $pageTitle." results"; | |
874 $resultsText .= "\n".str_repeat("=", strlen($resultsText))."-- -\n\n"; | |
875 } | |
876 | |
877 file_put_contents( | |
878 $resultsFile, | |
879 $resultsText.stGetCompoResultsASCIIStr(FALSE, 0) | |
880 ); | |
881 } | |
882 | |
883 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
884 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
885 { | |
886 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, TRUE); | |
887 } | |
963 | 888 } |
889 break; | |
890 | |
901 | 891 case "pac": |
929 | 892 echo "Not implemented. :D\n"; |
901 | 893 break; |
894 | |
895 case "add": | |
929 | 896 echo "Not implemented. :D\n"; |
901 | 897 break; |
898 | |
899 default: | |
900 if ($mode == "") | |
901 die("ERROR! Entry command requires a sub-command argument.\n"); | |
902 else | |
903 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
904 break; | |
905 } | |
906 break; | |
907 | |
884 | 908 case "pre": |
881 | 909 // |
910 // Preview files handling | |
911 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
912 $mode = stCArgLC(2, 3); |
881 | 913 switch ($mode) |
914 { | |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
915 case "gen": |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
916 case "upd": |
881 | 917 case "sta": |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
918 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
919 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 920 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
898 | 921 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 922 { |
968 | 923 wtPrintCompoHeader($compo); |
881 | 924 printf( |
898 | 925 "PrevType : %s\n", |
926 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 927 |
968 | 928 if ($mode == "sta" || $mode == "lis") |
941 | 929 { |
930 printf(" %-3s | %-3s | %-40s |\n", | |
968 | 931 "#ID", "EPV", "Entry name/author"); |
941 | 932 } |
933 | |
968 | 934 wtPrintDivider("-"); |
881 | 935 |
936 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
937 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 938 |
968 | 939 wtPrintDivider("="); |
940 } | |
941 if ($mode == "sta" || $mode == "lis") | |
942 { | |
943 echo "Flags: E = Entry has file, P = Has preview file, V = Generated previews are up to date.\n"; | |
881 | 944 } |
945 break; | |
946 | |
901 | 947 case "add": |
929 | 948 echo "Not implemented. :D\n"; |
901 | 949 break; |
950 | |
881 | 951 default: |
952 if ($mode == "") | |
953 die("ERROR! Previews command requires a sub-command argument.\n"); | |
954 else | |
955 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
956 break; | |
957 } | |
958 break; | |
959 | |
827 | 960 default: |
961 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
962 break; | |
963 } | |
964 | |
941 | 965 /* Dummy |
966 { | |
967 | |
968 } | |
969 */ | |
827 | 970 ?> |