annotate faptool.php @ 985:31dc100c78d4

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