annotate faptool.php @ 966:eea2b92287ca

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