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