annotate faptool.php @ 950:527e62f39af6

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