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